/**
  * Notify remote users when their notices get de-favorited.
  *
  * @param Profile $profile Profile person doing the de-faving
  * @param Notice  $notice  Notice being favored
  *
  * @return hook return value
  */
 function onEndDisfavorNotice(Profile $profile, Notice $notice)
 {
     $flink = Foreign_link::getByUserID($profile->id, TWITTER_SERVICE);
     // twitter service
     if (empty($flink)) {
         return true;
     }
     if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
         $this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
         return true;
     }
     $status_id = twitter_status_id($notice);
     if (empty($status_id)) {
         return true;
     }
     try {
         $token = TwitterOAuthClient::unpackToken($flink->credentials);
         $client = new TwitterOAuthClient($token->key, $token->secret);
         $client->favoritesDestroy($status_id);
     } catch (Exception $e) {
         common_log(LOG_ERR, "Error attempting to unfavorite bridged notice on Twitter: " . $e->getMessage());
     }
     return true;
 }
Exemple #2
0
/**
 * Pull any extra information from a notice that we should transfer over
 * to Twitter beyond the notice text itself.
 *
 * @param Notice $notice
 * @return array of key-value pairs for Twitter update submission
 * @access private
 */
function twitter_update_params($notice)
{
    $params = array();
    if ($notice->lat || $notice->lon) {
        $params['lat'] = $notice->lat;
        $params['long'] = $notice->lon;
    }
    if (!empty($notice->reply_to) && is_twitter_notice($notice->reply_to)) {
        $reply = Notice::staticGet('id', $notice->reply_to);
        $params['in_reply_to_status_id'] = twitter_status_id($reply);
    }
    return $params;
}
 /**
  * Notify remote users when their notices get de-favorited.
  *
  * @param Profile $profile Profile person doing the de-faving
  * @param Notice  $notice  Notice being favored
  *
  * @return hook return value
  */
 function onEndDisfavorNotice(Profile $profile, Notice $notice)
 {
     $flink = Foreign_link::getByUserID($profile->id, TWITTER_SERVICE);
     // twitter service
     if (empty($flink)) {
         return true;
     }
     if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
         $this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
         return true;
     }
     $status_id = twitter_status_id($notice);
     if (empty($status_id)) {
         return true;
     }
     $token = TwitterOAuthClient::unpackToken($flink->credentials);
     $client = new TwitterOAuthClient($token->key, $token->secret);
     $client->favoritesDestroy($status_id);
     return true;
 }
 public function onEndShowHeadElements(Action $action)
 {
     if ($action instanceof ShowNoticeAction) {
         // Showing a notice
         $notice = Notice::getKV('id', $action->arg('notice'));
         try {
             $flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE);
             $fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE);
         } catch (NoResultException $e) {
             return true;
         }
         $statusId = twitter_status_id($notice);
         if ($notice instanceof Notice && $notice->isLocal() && $statusId) {
             $tweetUrl = 'https://twitter.com/' . $fuser->nickname . '/status/' . $statusId;
             $action->element('link', array('rel' => 'syndication', 'href' => $tweetUrl));
         }
     }
     if (!$action instanceof AttachmentAction) {
         return true;
     }
     /* Twitter card support. See https://dev.twitter.com/docs/cards */
     /* @fixme: should we display twitter cards only for attachments posted
      *         by local users ? Seems mandatory to display twitter:creator
      *
      * Author: jbfavre
      */
     switch ($action->attachment->mimetype) {
         case 'image/pjpeg':
         case 'image/jpeg':
         case 'image/jpg':
         case 'image/png':
         case 'image/gif':
             $action->element('meta', array('name' => 'twitter:card', 'content' => 'photo'), null);
             $action->element('meta', array('name' => 'twitter:url', 'content' => common_local_url('attachment', array('attachment' => $action->attachment->id))), null);
             $action->element('meta', array('name' => 'twitter:image', 'content' => $action->attachment->url));
             $action->element('meta', array('name' => 'twitter:title', 'content' => $action->attachment->title));
             $ns = new AttachmentNoticeSection($action);
             $notices = $ns->getNotices();
             $noticeArray = $notices->fetchAll();
             // Should not have more than 1 notice for this attachment.
             if (count($noticeArray) != 1) {
                 break;
             }
             $post = $noticeArray[0];
             try {
                 $flink = Foreign_link::getByUserID($post->profile_id, TWITTER_SERVICE);
                 $fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE);
                 $action->element('meta', array('name' => 'twitter:creator', 'content' => '@' . $fuser->nickname));
             } catch (NoResultException $e) {
                 // no foreign link and/or user for Twitter on this profile ID
             }
             break;
         default:
             break;
     }
     return true;
 }