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); }
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); }
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); }
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; }
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; }
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; }
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; }
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; }