예제 #1
4
function facebookBroadcastNotice($notice)
{
    $facebook = getFacebook();
    $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE);
    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}");
            // 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);
            $canPublish = 0;
            if (!empty($result)) {
                $canPublish = $result[0]['publish_stream'];
            }
            if ($canPublish == 1) {
                common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'has publish_stream permission.');
            } else {
                common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'does NOT have publish_stream permission. Facebook ' . 'returned: ' . var_export($result, true));
            }
            common_debug('FacebookPlugin - checking for status_update permission for user ' . "{$user->nickname} ({$user->id}), Facebook UID: {$fbuid}. ");
            $canUpdate = $facebook->api_client->users_hasAppPermission('status_update', $fbuid);
            if ($canUpdate == 1) {
                common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'has status_update permission.');
            } else {
                common_debug("FacebookPlugin - {$user->nickname} ({$user->id}), Facebook UID: {$fbuid} " . 'does NOT have status_update permission. Facebook ' . 'returned: ' . var_export($canPublish, true));
            }
            // Post to Facebook
            if ($notice->hasAttachments() && $canPublish == 1) {
                publishStream($notice, $user, $fbuid);
            } elseif ($canUpdate == 1 || $canPublish == 1) {
                statusUpdate($notice, $user, $fbuid);
            } else {
                $msg = "FacebookPlugin - Not sending notice {$notice->id} to Facebook " . "because user {$user->nickname} has not given the " . 'Facebook app \'status_update\' or \'publish_stream\' permission.';
                common_log(LOG_WARNING, $msg);
            }
            // Finally, attempt to update the user's profile box
            if ($canPublish == 1 || $canUpdate == 1) {
                updateProfileBox($facebook, $flink, $notice, $user);
            }
        } catch (FacebookRestClientException $e) {
            return handleFacebookError($e, $notice, $flink);
        }
    }
    return true;
}
예제 #2
0
파일: core.php 프로젝트: wistel/wordpress
 public static function updateStatistics($eventCategory, $eventAction, $timeBand)
 {
     $globalSettings = get_option("wpXSG_global", new globalSettings());
     if ($globalSettings->sendStats) {
         global $wp_version;
         $postCountLabel = dataAccess::getPostCountBand();
         $postData = array('v' => 1, 'tid' => 'UA-679276-7', 'cid' => get_option('wpXSG_MapId'), 't' => 'event', 'ec' => $eventCategory, 'ea' => $eventAction, 'ev' => 1, 'cd1' => get_bloginfo('url'), 'cd2' => $wp_version, 'cd3' => self::pluginVersion(), 'cd4' => PHP_VERSION, 'cd5' => $postCountLabel, 'cd6' => $timeBand);
         $url = 'https://ssl.google-analytics.com/collect';
         try {
             $response = wp_remote_post($url, array('method' => 'POST', 'body' => $postData));
         } catch (Exception $e) {
             statusUpdate("sendStats : " . $e->getMessage());
         }
     }
 }