summaryrefslogtreecommitdiff
path: root/lib/facebookutil.php
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-02-13 05:42:00 +0000
committerZach Copley <zach@controlyourself.ca>2009-02-13 05:42:00 +0000
commit4b7ee5455f1190c681b5912b84398a1156040d74 (patch)
tree5cad02b09f2cb8a27b2d0fd18ddff24edc38279d /lib/facebookutil.php
parent47e595b092a0d8cd1d26a0170571c013fd992904 (diff)
We have a FacebookQueueHandler now. The update_facebook.php cron
script is totally deprecated.
Diffstat (limited to 'lib/facebookutil.php')
-rw-r--r--lib/facebookutil.php96
1 files changed, 95 insertions, 1 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;
+}