X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FFacebook%2Ffacebookutil.php;h=fb70c51bc542efbb1d3f27adc7b07efb7d2e4742;hb=6c77d86b7f39c35eac0fcc3f13c0beba3e694318;hp=e52a3deaef3b3079f8c5d79c0a9e172eebc89315;hpb=777ca74500025c616ae689f9a92b3233cf8466f7;p=quix0rs-gnu-social.git diff --git a/plugins/Facebook/facebookutil.php b/plugins/Facebook/facebookutil.php index e52a3deaef..fb70c51bc5 100644 --- a/plugins/Facebook/facebookutil.php +++ b/plugins/Facebook/facebookutil.php @@ -17,6 +17,10 @@ * along with this program. If not, see . */ +if (!defined('STATUSNET')) { + exit(1); +} + require_once INSTALLDIR . '/plugins/Facebook/facebook/facebook.php'; require_once INSTALLDIR . '/plugins/Facebook/facebookaction.php'; require_once INSTALLDIR . '/lib/noticelist.php'; @@ -45,13 +49,11 @@ function getFacebook() } function isFacebookBound($notice, $flink) { - if (empty($flink)) { return false; } // Avoid a loop - if ($notice->source == 'Facebook') { common_log(LOG_INFO, "Skipping notice $notice->id because its " . 'source is Facebook.'); @@ -59,7 +61,6 @@ 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.'); @@ -68,14 +69,12 @@ function isFacebookBound($notice, $flink) { // If it's not a reply, or if the user WANTS to send @-replies, // then, yeah, it can go to Facebook. - if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) || ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY)) { return true; } return false; - } function facebookBroadcastNotice($notice) @@ -87,16 +86,12 @@ function facebookBroadcastNotice($notice) ); if (isFacebookBound($notice, $flink)) { - // Okay, we're good to go, update the FB status - $fbuid = $flink->foreign_id; $user = $flink->getUser(); try { - // Check permissions - common_debug( 'FacebookPlugin - checking for publish_stream permission for user ' . "$user->nickname ($user->id), Facebook UID: $fbuid" @@ -105,7 +100,6 @@ function facebookBroadcastNotice($notice) // NOTE: $facebook->api_client->users_hasAppPermission('publish_stream', $fbuid) // has been returning bogus results, so we're using FQL to check for // publish_stream permission now - $fql = "SELECT publish_stream FROM permissions WHERE uid = $fbuid"; $result = $facebook->api_client->fql_query($fql); @@ -147,12 +141,11 @@ function facebookBroadcastNotice($notice) common_debug( "FacebookPlugin - $user->nickname ($user->id), Facebook UID: $fbuid " .'does NOT have status_update permission. Facebook ' - . 'returned: ' . var_export($can_publish, true) + . 'returned: ' . var_export($canPublish, true) ); } // Post to Facebook - if ($notice->hasAttachments() && $canPublish == 1) { publishStream($notice, $user, $fbuid); } elseif ($canUpdate == 1 || $canPublish == 1) { @@ -165,7 +158,6 @@ function facebookBroadcastNotice($notice) } // Finally, attempt to update the user's profile box - if ($canPublish == 1 || $canUpdate == 1) { updateProfileBox($facebook, $flink, $notice, $user); } @@ -192,7 +184,7 @@ function handleFacebookError($e, $notice, $flink) . "\"%s\" (Notice details: nickname=%s, user ID=%d, Facebook ID=%d, notice content=\"%s\"). " . "Removing notice from the Facebook queue for safety."; common_log( - LOG_ERROR, sprintf( + LOG_ERR, sprintf( $msg, $notice->id, $errmsg, @@ -229,10 +221,10 @@ function handleFacebookError($e, $notice, $flink) default: $msg = "FacebookPlugin - Facebook returned an error we don't know how to deal with while trying to " . "post notice %d. Error code: %d, error message: \"%s\". (Notice details: " - . "nickname=%s, user ID=%d, Facebook ID=%d, notice content=\"%s\"). Re-queueing " - . "notice, and will try to send again later."; + . "nickname=%s, user ID=%d, Facebook ID=%d, notice content=\"%s\"). Removing notice " + . "from the Facebook queue for safety."; common_log( - LOG_ERROR, sprintf( + LOG_ERR, sprintf( $msg, $notice->id, $code, @@ -243,8 +235,7 @@ function handleFacebookError($e, $notice, $flink) $notice->content ) ); - // Re-queue and try again later - return false; + return true; // dequeue break; } } @@ -257,11 +248,9 @@ function statusUpdate($notice, $user, $fbuid) . "Facebook UID: $fbuid" ); - $text = formatNotice($notice, $user, $fbuid); - $facebook = getFacebook(); $result = $facebook->api_client->users_setStatus( - $text, + $notice->content, $fbuid, false, true @@ -285,20 +274,17 @@ function publishStream($notice, $user, $fbuid) . "Facebook UID: $fbuid" ); - $text = formatNotice($notice, $user, $fbuid); $fbattachment = format_attachments($notice->attachments()); $facebook = getFacebook(); $facebook->api_client->stream_publish( - $text, + $notice->content, $fbattachment, null, null, $fbuid ); - common_debug('Facebook returned: ' . var_export($result, true)); - common_log( LOG_INFO, "FacebookPlugin - Posted notice $notice->id as a stream " @@ -307,39 +293,6 @@ function publishStream($notice, $user, $fbuid) ); } - -function formatNotice($notice, $user, $fbuid) -{ - // Get the status 'verb' the user has set, if any - - common_debug( - "FacebookPlugin - Looking to see if $user->nickname ($user->id), " - . "Facebook UID: $fbuid has set a verb for Facebook posting..." - ); - - $facebook = getFacebook(); - $verb = trim( - $facebook->api_client->data_getUserPreference( - FACEBOOK_NOTICE_PREFIX, - $fbuid - ) - ); - - common_debug("Facebook returned " . var_export($verb, true)); - - $text = null; - - if (!empty($verb)) { - common_debug("FacebookPlugin - found a verb: $verb"); - $text = trim($verb) . ' ' . $notice->content; - } else { - common_debug("FacebookPlugin - no verb found."); - $text = $notice->content; - } - - return $text; -} - function updateProfileBox($facebook, $flink, $notice, $user) { $facebook = getFacebook(); @@ -350,9 +303,11 @@ function updateProfileBox($facebook, $flink, $notice, $user) { $flink ); + $fbuid = $flink->foreign_id; + common_debug( 'FacebookPlugin - Attempting to update profile box with ' - . "content from notice $notice->id for $user->nickname ($user->id)" + . "content from notice $notice->id for $user->nickname ($user->id), " . "Facebook UID: $fbuid" ); @@ -449,7 +404,6 @@ function remove_facebook_app($flink) common_log(LOG_WARNING, $msg); } - } /** @@ -460,7 +414,6 @@ function remove_facebook_app($flink) * * @return boolean success flag */ - function mail_facebook_app_removed($user) { $profile = $user->getProfile(); @@ -484,5 +437,4 @@ function mail_facebook_app_removed($user) common_switch_locale(); return mail_to_user($user, $subject, $body); - }