+function fb_queue_hook(&$a,&$b) {
+
+ require_once('include/queue_fn.php');
+ if((! is_array($b)) || (! count($b)))
+ return;
+ foreach($b as $x) {
+ if($b['network'] !== NETWORK_FACEBOOK)
+ continue;
+ $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid`
+ WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1",
+ intval($x['cid'])
+ );
+ if(! count($r))
+ continue;
+
+ $user = $r[0];
+
+ $appid = get_config('facebook', 'appid' );
+ $secret = get_config('facebook', 'appsecret' );
+
+ if($appid && $secret) {
+ $fb_post = intval(get_pconfig($user['uid'],'facebook','post'));
+ $fb_token = get_pconfig($user['uid'],'facebook','access_token');
+
+ if($fb_post && $fb_token) {
+ logger('facebook_queue: able to post');
+ require_once('library/facebook.php');
+
+ $z = unserialize($x['content']);
+ $item = $z['item'];
+ $j = post_url($z['url'],$z['post']);
+
+ $retj = json_decode($j);
+ if($retj->id) {
+ q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1",
+ dbesc('fb::' . $retj->id),
+ intval($item['id'])
+ );
+ logger('facebook queue: success: ' . $j);
+ remove_queue_item($x['id']);
+ }
+ else {
+ logger('facebook_queue: failed: ' . $j);
+ update_queue_time($x['id']);
+ }
+ }
+ }
+ }
+}
+