diff options
author | Zach Copley <zach@controlyourself.ca> | 2009-02-13 05:42:00 +0000 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2009-02-13 05:42:00 +0000 |
commit | 4b7ee5455f1190c681b5912b84398a1156040d74 (patch) | |
tree | 5cad02b09f2cb8a27b2d0fd18ddff24edc38279d /lib | |
parent | 47e595b092a0d8cd1d26a0170571c013fd992904 (diff) |
We have a FacebookQueueHandler now. The update_facebook.php cron
script is totally deprecated.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/facebookutil.php | 96 | ||||
-rw-r--r-- | lib/util.php | 4 |
2 files changed, 98 insertions, 2 deletions
diff --git a/lib/facebookutil.php b/lib/facebookutil.php index beab51366..e2ad20d19 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -36,7 +36,7 @@ function getFacebookNotices($since) // XXX: What should the limit be? //static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) { - + return Notice::getStreamDirect($qry, 0, 1000, 0, 0, null, $since); } @@ -52,3 +52,97 @@ function updateProfileBox($facebook, $flink, $notice) { $fbaction->updateProfileBox($notice); } +function isFacebookBound($notice, $flink) { + + // If the user does not want to broadcast to Facebook, move along + if (!($flink->noticesync & FOREIGN_NOTICE_SEND == FOREIGN_NOTICE_SEND)) { + common_log(LOG_INFO, "Skipping notice $notice->id " . + 'because user has FOREIGN_NOTICE_SEND bit off.'); + return false; + } + + $success = false; + + // If it's not a reply, or if the user WANTS to send @-replies... + if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) || + ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY)) { + + $success = true; + + // The two condition below are deal breakers: + + // Avoid a loop + if ($notice->source == 'Facebook') { + common_log(LOG_INFO, "Skipping notice $notice->id because its " . + 'source is Facebook.'); + $success = false; + } + + $facebook = getFacebook(); + $fbuid = $flink->foreign_id; + + try { + + // Check to see if the user has given the FB app status update perms + $result = $facebook->api_client-> + users_hasAppPermission('status_update', $fbuid); + + if ($result != 1) { + $user = $flink->getUser(); + $msg = "Can't send notice $notice->id to Facebook " . + "because user $user->nickname hasn't given the " . + 'Facebook app \'status_update\' permission.'; + common_log(LOG_INFO, $msg); + $success = false; + } + + } catch(FacebookRestClientException $e){ + common_log(LOG_ERROR, $e->getMessage()); + $success = false; + } + + } + + return $success; + +} + + +function facebookBroadcastNotice($notice) +{ + $facebook = getFacebook(); + $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE); + $fbuid = $flink->foreign_id; + + if (isFacebookBound($notice, $flink)) { + + $status = null; + + // Get the status 'verb' (prefix) the user has set + try { + $prefix = $facebook->api_client-> + data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid); + + $status = "$prefix $notice->content"; + + } catch(FacebookRestClientException $e) { + common_log(LOG_ERROR, $e->getMessage()); + return false; + } + + // Okay, we're good to go! + + try { + $facebook->api_client->users_setStatus($status, $fbuid, false, true); + updateProfileBox($facebook, $flink, $notice); + } catch(FacebookRestClientException $e) { + common_log(LOG_ERROR, $e->getMessage()); + return false; + + // Should we remove flink if this fails? + } + + } + + return true; +} diff --git a/lib/util.php b/lib/util.php index 031fd0da0..3eeb9fde3 100644 --- a/lib/util.php +++ b/lib/util.php @@ -837,7 +837,7 @@ function common_broadcast_notice($notice, $remote=false) function common_enqueue_notice($notice) { - foreach (array('jabber', 'omb', 'sms', 'public', 'twitter') as $transport) { + foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook') as $transport) { $qi = new Queue_item(); $qi->notice_id = $notice->id; $qi->transport = $transport; @@ -891,6 +891,8 @@ function common_real_broadcast($notice, $remote=false) } } + // XXX: Do a real-time FB broadcast here? + // XXX: broadcast notices to other IM return $success; } |