MyBB Hacks

Full Version: Sorting by facebook likes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
You're doing basically what you did before (send a query for every single thread), which will net you the same performance issues as before (eg 1000 roundtrips).
But if you don't care, well...

(10-16-2011 06:01 AM)duhol Wrote: [ -> ]Is it good for now? I dont know how to get "total_count" from file content.
From your previous code, you parsed the XML, I would presume the same?
This is my code. Maybe it doesnt wise solution, but works. No facebook database errors, no my database errors, take about 8 minutes for 1000 threads.
So, I have to leave it that way and you dont want to tell me about other way.

PHP Code:
<?php

function task_top_fb($task)
{

	global $mybb, $db, $lang;
	$threads = array();
	// Update thread likes
	$query = $db->query("
		SELECT tid
		FROM ".TABLE_PREFIX."threads
		GROUP BY tid
	");
	while($thread = $db->fetch_array($query))
	{
			$url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=http://www.sentens.pl/showthread.php?tid=".$thread['tid'];
			$xml = file_get_contents($url);
			$xml = simplexml_load_string($xml);
			foreach( $xml -> link_stat as $l)
			{
				$l -> total_count;
				$total = $l -> total_count;
				$db->update_query("threads", array('likes' => "{$total}"), "tid='{$thread['tid']}'", 1, true);
			}
	}
	add_task_log($task, "Zadanie aktualizacji ilosci 'lubie to' zostalo wykonane. :P");
}
?>

(10-16-2011 08:58 PM)duhol Wrote: [ -> ]you dont want to tell me about other way.
I already told you.  I'm not going to implement it for you though.
Pages: 1 2
Reference URL's