Exemplo n.º 1
0
 static function getByNickname($nickname, $service)
 {
     if (empty($nickname) || empty($service)) {
         return null;
     } else {
         $fuser = new Foreign_user();
         $fuser->service = $service;
         $fuser->nickname = $nickname;
         $fuser->limit(1);
         $result = $fuser->find(true);
         return empty($result) ? null : $fuser;
     }
 }
Exemplo n.º 2
0
 static function getByNickname($nickname, $service)
 {
     if (empty($nickname) || empty($service)) {
         throw new ServerException('Empty nickname or service for Foreign_user::getByNickname');
     }
     $fuser = new Foreign_user();
     $fuser->service = $service;
     $fuser->nickname = $nickname;
     $fuser->limit(1);
     if (!$fuser->find(true)) {
         throw new NoResultException($fuser);
     }
     return $fuser;
 }
Exemplo n.º 3
0
function save_twitter_user($twitter_id, $screen_name)
{
    // Check to see whether the Twitter user is already in the system,
    // and update its screen name and uri if so.
    try {
        $fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
        // Delete old record if Twitter user changed screen name
        if ($fuser->nickname != $screen_name) {
            $oldname = $fuser->nickname;
            $fuser->delete();
            common_log(LOG_INFO, sprintf('Twitter bridge - Updated nickname (and URI) ' . 'for Twitter user %1$d - %2$s, was %3$s.', $fuser->id, $screen_name, $oldname));
        }
    } catch (NoResultException $e) {
        // No old users exist for this id
        // Kill any old, invalid records for this screen name
        // XXX: Is this really only supposed to be run if the above getForeignUser fails?
        try {
            $fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
            $fuser->delete();
            common_log(LOG_INFO, sprintf('Twitter bridge - deteted old record for Twitter ' . 'screen name "%s" belonging to Twitter ID %d.', $screen_name, $fuser->id));
        } catch (NoResultException $e) {
            // No old users exist for this screen_name
        }
    }
    return add_twitter_user($twitter_id, $screen_name);
}
Exemplo n.º 4
0
 function getForeignUser()
 {
     $fuser = new Foreign_user();
     $fuser->service = $this->service;
     $fuser->id = $this->foreign_id;
     $fuser->limit(1);
     if ($fuser->find(true)) {
         return $fuser;
     }
     return null;
 }
Exemplo n.º 5
0
 static function getForeignUser($id, $service)
 {
     $fuser = new Foreign_user();
     $fuser->whereAdd("service = {$service}");
     $fuser->whereAdd("id = {$id}");
     $fuser->limit(1);
     if ($fuser->find()) {
         $fuser->fetch();
         return $fuser;
     }
     return null;
 }
Exemplo n.º 6
0
function save_twitter_user($twitter_id, $screen_name)
{
    // Check to see whether the Twitter user is already in the system,
    // and update its screen name and uri if so.
    $fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
    if (!empty($fuser)) {
        $result = true;
        // Delete old record if Twitter user changed screen name
        if ($fuser->nickname != $screen_name) {
            $oldname = $fuser->nickname;
            $fuser->delete();
            common_log(LOG_INFO, sprintf('Twitter bridge - Updated nickname (and URI) ' . 'for Twitter user %1$d - %2$s, was %3$s.', $fuser->id, $screen_name, $oldname));
        }
    }
    return add_twitter_user($twitter_id, $screen_name);
}
Exemplo n.º 7
0
function save_twitter_user($twitter_id, $screen_name)
{
    // Check to see whether the Twitter user is already in the system,
    // and update its screen name and uri if so.
    $fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
    if (!empty($fuser)) {
        // Delete old record if Twitter user changed screen name
        if ($fuser->nickname != $screen_name) {
            $oldname = $fuser->nickname;
            $fuser->delete();
            common_log(LOG_INFO, sprintf('Twitter bridge - Updated nickname (and URI) ' . 'for Twitter user %1$d - %2$s, was %3$s.', $fuser->id, $screen_name, $oldname));
        }
    } else {
        // Kill any old, invalid records for this screen name
        $fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
        if (!empty($fuser)) {
            $fuser->delete();
            common_log(LOG_INFO, sprintf('Twitter bridge - deteted old record for Twitter ' . 'screen name "%s" belonging to Twitter ID %d.', $screen_name, $fuser->id));
        }
    }
    return add_twitter_user($twitter_id, $screen_name);
}
Exemplo n.º 8
0
function save_twitter_user($twitter_id, $screen_name)
{
    // Check to see whether the Twitter user is already in the system,
    // and update its screen name and uri if so.
    $fuser = Foreign_user::getForeignUser($twitter_id, 1);
    if ($fuser) {
        // Only update if Twitter screen name has changed
        if ($fuser->nickname != $screen_name) {
            common_debug('Twitter bridge - Updated nickname (and URI) for Twitter user ' . "{$fuser->id} to {$screen_name}, was {$fuser->nickname}");
            return update_twitter_user($fuser, $twitter_id, $screen_name);
        }
    } else {
        return add_twitter_user($twitter_id, $screen_name);
    }
    return true;
}
Exemplo n.º 9
0
 public function onEndShowHeadElements(Action $action)
 {
     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];
             $flink = Foreign_link::getByUserID($post->profile_id, TWITTER_SERVICE);
             if ($flink) {
                 // Our local user has registered Twitter Gateway
                 $fuser = Foreign_user::getForeignUser($flink->foreign_id, TWITTER_SERVICE);
                 if ($fuser) {
                     // Got nickname for local user's Twitter account
                     $action->element('meta', array('name' => 'twitter:creator', 'content' => '@' . $fuser->nickname));
                 }
             }
             break;
         default:
             break;
     }
     return true;
 }
Exemplo n.º 10
0
 function getForeignUser()
 {
     $fuser = new Foreign_user();
     $fuser->service = $this->service;
     $fuser->id = $this->foreign_id;
     $fuser->limit(1);
     if (!$fuser->find(true)) {
         throw new NoResultException($fuser);
     }
     return $fuser;
 }
Exemplo n.º 11
0
 static function addFacebookUser($fbuser)
 {
     // remove any existing, possibly outdated, record
     try {
         $fuser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
         $result = $fuser->delete();
         if ($result != false) {
             common_log(LOG_INFO, sprintf('Removed old Facebook user: %s, fbuid %d', $fbuid->name, $fbuid->id), __FILE__);
         }
     } catch (NoResultException $e) {
         // no old foreign users exist for this id
     }
     $fuser = new Foreign_user();
     $fuser->nickname = $fbuser->username;
     $fuser->uri = $fbuser->link;
     $fuser->id = $fbuser->id;
     $fuser->service = FACEBOOK_SERVICE;
     $fuser->created = common_sql_now();
     $result = $fuser->insert();
     if (empty($result)) {
         common_log(LOG_WARNING, sprintf('Failed to add new Facebook user: %s, fbuid %d', $fbuser->username, $fbuser->id), __FILE__);
         common_log_db_error($fuser, 'INSERT', __FILE__);
     } else {
         common_log(LOG_INFO, sprintf('Added new Facebook user: %s, fbuid %d', $fbuser->name, $fbuser->id), __FILE__);
     }
     return $result;
 }
Exemplo n.º 12
0
 static function addFacebookUser($fbuser)
 {
     // remove any existing, possibly outdated, record
     $luser = Foreign_user::getForeignUser($fbuser['id'], FACEBOOK_SERVICE);
     if (!empty($luser)) {
         $result = $luser->delete();
         if ($result != false) {
             common_log(LOG_INFO, sprintf('Removed old Facebook user: %s, fbuid %d', $fbuid['name'], $fbuid['id']), __FILE__);
         }
     }
     $fuser = new Foreign_user();
     $fuser->nickname = $fbuser['name'];
     $fuser->uri = $fbuser['link'];
     $fuser->id = $fbuser['id'];
     $fuser->service = FACEBOOK_SERVICE;
     $fuser->created = common_sql_now();
     $result = $fuser->insert();
     if (empty($result)) {
         common_log(LOG_WARNING, sprintf('Failed to add new Facebook user: %s, fbuid %d', $fbuser['name'], $fbuser['id']), __FILE__);
         common_log_db_error($fuser, 'INSERT', __FILE__);
     } else {
         common_log(LOG_INFO, sprintf('Added new Facebook user: %s, fbuid %d', $fbuser['name'], $fbuser['id']), __FILE__);
     }
     return $result;
 }
Exemplo n.º 13
0
 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;
 }