function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice instanceof Notice) { try { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to attentions for user " . $flink->user_id); try { Attention::saveNew($notice, $flink->getProfile()); } catch (Exception $e) { // Log the exception, but make sure we don't bail out, we // still have a queue item to remove here-after. common_log(LOG_ERR, "Failed adding notice {$notice->id} to attentions for user {$flink->user_id}: " . $e->getMessage()); } } catch (NoResultException $e) { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver); } } return true; }
/** * Handler method * * @param array $args is ignored since it's now passed in in prepare() */ function handle($args) { parent::handle($args); $data = $this->facebook->getSignedRequest(); if (isset($data['user_id'])) { $fbuid = $data['user_id']; $flink = Foreign_link::getByForeignID($fbuid, FACEBOOK_SERVICE); $user = $flink->getUser(); // Remove the link to Facebook $result = $flink->delete(); if (!$result) { common_log_db_error($flink, 'DELETE', __FILE__); common_log(LOG_WARNING, sprintf('Unable to delete Facebook foreign link ' . 'for %s (%d), fbuid %d', $user->nickname, $user->id, $fbuid), __FILE__); return; } common_log(LOG_INFO, sprintf('Facebook callback: %s (%d), fbuid %d has deauthorized ' . 'the Facebook application.', $user->nickname, $user->id, $fbuid), __FILE__); // Warn the user about being locked out of their account // if we can. if (empty($user->password) && !empty($user->email)) { Facebookclient::emailWarn($user); } else { common_log(LOG_WARNING, sprintf('%s (%d), fbuid %d has deauthorized his/her Facebook ' . 'connection but hasn\'t set a password so s/he ' . 'is locked out.', $user->nickname, $user->id, $fbuid), __FILE__); } } else { if (!empty($data)) { common_log(LOG_WARNING, sprintf('Facebook called the deauthorize callback ' . ' but didn\'t provide a user ID.'), __FILE__); } else { // It probably wasn't Facebook that hit this action, // so redirect to the public timeline common_redirect(common_local_url('public'), 303); } } }
function handle($args) { parent::handle($args); $secret = common_config('facebook', 'secret'); $sig = ''; ksort($_POST); foreach ($_POST as $key => $val) { if (substr($key, 0, 7) == 'fb_sig_') { $sig .= substr($key, 7) . '=' . $val; } } $sig .= $secret; $verify = md5($sig); if ($verify == $this->arg('fb_sig')) { $flink = Foreign_link::getByForeignID($this->arg('fb_sig_user'), 2); common_debug("Removing foreign link to Facebook - local user ID: {$flink->user_id}, Facebook ID: {$flink->foreign_id}"); $result = $flink->delete(); if (!$result) { common_log_db_error($flink, 'DELETE', __FILE__); $this->serverError(_('Couldn\'t remove Facebook user.')); return; } } else { # Someone bad tried to remove facebook link? common_log(LOG_ERR, "Someone from {$_SERVER['REMOTE_ADDR']} " . 'unsuccessfully tried to remove a foreign link to Facebook!'); } }
function prepare($argarray) { parent::prepare($argarray); $this->facebook = getFacebook(); $this->fbuid = $this->facebook->require_login(); $this->action = $this->trimmed('action'); $app_props = $this->facebook->api_client->Admin_getAppProperties(array('canvas_name', 'application_name')); $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; $this->app_name = $app_props['application_name']; $this->flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); return true; }
function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice) { $flink = Foreign_link::getByForeignID(TWITTER_SERVICE, $receiver); if ($flink) { // @fixme this should go through more regular channels? Inbox::insertNotice($flink->user_id, $notice->id); } } return true; }
function handle($data) { // JSON object with Twitter data $status = $data['status']; // Twitter user ID this incoming data belongs to. $receiver = $data['for_user']; $importer = new TwitterImport(); $notice = $importer->importStatus($status); if ($notice) { $flink = Foreign_link::getByForeignID($receiver, TWITTER_SERVICE); if ($flink) { common_log(LOG_DEBUG, "TweetInQueueHandler - Got flink so add notice " . $notice->id . " to inbox " . $flink->user_id); // @fixme this should go through more regular channels? Inbox::insertNotice($flink->user_id, $notice->id); } else { common_log(LOG_DEBUG, "TweetInQueueHandler - No flink found for foreign user " . $receiver); } } return true; }
function save_twitter_friends($user, $twitter_id, $screen_name, $password) { $friends = retreive_twitter_friends($twitter_id, $screen_name, $password); if (is_null($friends)) { common_debug("Twitter bridge - Couldn't get friends data from Twitter."); return false; } foreach ($friends as $friend) { $friend_name = $friend->screen_name; $friend_id = $friend->id; // Update or create the Foreign_user record if (!save_twitter_user($friend_id, $friend_name)) { return false; } // Check to see if there's a related local user $flink = Foreign_link::getByForeignID($friend_id, 1); if ($flink) { // Get associated user and subscribe her $friend_user = User::staticGet('id', $flink->user_id); subs_subscribe_to($user, $friend_user); common_debug("Twitter bridge - subscribed {$friend_user->nickname} to {$user->nickname}."); } } return true; }
function saveStatusMentions($notice, $status) { $mentions = array(); if (empty($status->entities) || empty($status->entities->user_mentions)) { return; } foreach ($status->entities->user_mentions as $mention) { $flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE); if (!empty($flink)) { $user = User::staticGet('id', $flink->user_id); if (!empty($user)) { $reply = new Reply(); $reply->notice_id = $notice->id; $reply->profile_id = $user->id; $reply->modified = $notice->created; common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}"); $id = $reply->insert(); } } } }
function subscribeTwitterFriends($flink) { $friends = $this->fetchTwitterFriends($flink); if (empty($friends)) { common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}."); return false; } $user = $flink->getUser(); foreach ($friends as $friend) { $friend_name = $friend->screen_name; $friend_id = (int) $friend->id; // Update or create the Foreign_user record for each // Twitter friend if (!save_twitter_user($friend_id, $friend_name)) { common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}."); continue; } // Check to see if there's a related local user $friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE); if (!empty($friend_flink)) { // Get associated user and subscribe her $friend_user = User::staticGet('id', $friend_flink->user_id); if (!empty($friend_user)) { $result = subs_subscribe_to($user, $friend_user); if ($result === true) { common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_user->nickname} to {$user->nickname}."); } else { common_debug($this->name() . ' - Tried subscribing ' . "{$friend_user->nickname} to {$user->nickname} - " . $result); } } } } return true; }
function tryLogin() { common_debug('TwitterBridge Plugin - ' . "Trying login for Twitter user {$this->twuid}."); $flink = Foreign_link::getByForeignID($this->twuid, TWITTER_SERVICE); if (!empty($flink)) { $user = $flink->getUser(); if (!empty($user)) { common_debug('TwitterBridge Plugin - ' . "Logged in Twitter user {$flink->foreign_id} as user {$user->id} ({$user->nickname})"); common_set_user($user); common_real_login(true); $this->goHome($user->nickname); } } else { common_debug('TwitterBridge Plugin - ' . "No flink found for twuid: {$this->twuid} - new user"); $this->showForm(null, $this->bestNewNickname()); } }
function tryLogin() { common_debug("Trying Facebook Login..."); $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE); if ($flink) { $user = $flink->getUser(); if (!empty($user)) { common_debug("Logged in Facebook user {$flink->foreign_id} as user {$user->id} ({$user->nickname})"); common_set_user($user); common_real_login(true); $this->goHome($user->nickname); } } else { common_debug("No flink found for fbuid: {$this->fbuid}"); $this->showForm(null, $this->bestNewNickname()); } }
function subscribeTwitterFriends(Foreign_link $flink) { try { $profile = $flink->getProfile(); } catch (NoResultException $e) { common_log(LOG_WARNING, 'Foreign_link has no matching local profile for local ID: ' . $flink->user_id); } $friends = $this->fetchTwitterFriends($flink); if (empty($friends)) { common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}."); return false; } foreach ($friends as $friend) { $friend_name = $friend->screen_name; $friend_id = (int) $friend->id; // Update or create the Foreign_user record for each // Twitter friend if (!save_twitter_user($friend_id, $friend_name)) { common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}."); continue; } // Check to see if there's a related local user and try to subscribe try { $friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE); // Get associated user and subscribe her $friend_profile = $friend_flink->getProfile(); Subscription::start($profile, $friend_profile); common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_profile->nickname} to {$profile->nickname}."); } catch (NoResultException $e) { // either no foreign link for this friend's foreign ID or no profile found on local ID. } catch (Exception $e) { common_debug($this->name() . ' - Tried and failed subscribing ' . "{$friend_profile->nickname} to {$profile->nickname} - " . $e->getMessage()); } } return true; }
function saveStatusMentions($notice, $status) { $mentions = array(); if (empty($status->entities) || empty($status->entities->user_mentions)) { return; } foreach ($status->entities->user_mentions as $mention) { try { $flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE); $user = $flink->getUser(); $reply = new Reply(); $reply->notice_id = $notice->id; $reply->profile_id = $user->id; $reply->modified = $notice->created; common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}"); $id = $reply->insert(); } catch (NoSuchUserException $e) { common_log(LOG_WARNING, 'No local user found for Foreign_link with id: ' . $mention->id); } catch (NoResultException $e) { common_log(LOG_WARNING, 'No foreign link or profile found for Foreign_link with id: ' . $mention->id); } } }
function tryLogin() { $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); if (!empty($flink)) { $user = $flink->getUser(); if (!empty($user)) { common_log(LOG_INFO, sprintf('Logged in Facebook user %s as user %d (%s)', $this->fbuid, $user->nickname, $user->id), __FILE__); common_set_user($user); common_real_login(true); // clear out the stupid cookie setcookie('fb_access_token', '', time() - 3600); // one hour ago $this->goHome($user->nickname); } } else { $this->showForm(null, $this->bestNewNickname()); } }
function tryLogin() { common_debug(sprintf('Trying login for Facebook user %s', $this->fbuid), __FILE__); $flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_SERVICE); if (!empty($flink)) { $user = $flink->getUser(); if (!empty($user)) { common_log(LOG_INFO, sprintf('Logged in Facebook user %s as user %d (%s)', $this->fbuid, $user->nickname, $user->id), __FILE__); common_set_user($user); common_real_login(true); $this->goHome($user->nickname); } } else { common_debug(sprintf('No flink found for fbuid: %s - new user', $this->fbuid), __FILE__); $this->showForm(null, $this->bestNewNickname()); } }
function subscribeTwitterFriends($flink) { $friends = $this->fetchTwitterFriends($flink); if (empty($friends)) { common_debug($this->name() . ' - Couldn\'t get friends from Twitter for ' . "Twitter user {$flink->foreign_id}."); return false; } $profile = $flink->getProfile(); foreach ($friends as $friend) { $friend_name = $friend->screen_name; $friend_id = (int) $friend->id; // Update or create the Foreign_user record for each // Twitter friend if (!save_twitter_user($friend_id, $friend_name)) { common_log(LOG_WARNING, $this->name() . " - Couldn't save {$screen_name}'s friend, {$friend_name}."); continue; } // Check to see if there's a related local user $friend_flink = Foreign_link::getByForeignID($friend_id, TWITTER_SERVICE); if (!empty($friend_flink)) { // Get associated user and subscribe her $friend_profile = Profile::getKV('id', $friend_flink->user_id); if ($friend_profile instanceof Profile) { try { $other = Profile::getKV('id', $invites->user_id); Subscription::start($profile, $friend_profile); common_log(LOG_INFO, $this->name() . ' - Subscribed ' . "{$friend_profile->nickname} to {$profile->nickname}."); } catch (Exception $e) { common_debug($this->name() . ' - Tried and failed subscribing ' . "{$friend_profile->nickname} to {$profile->nickname} - " . $e->getMessage()); } } } } return true; }
protected function tryLogin() { common_debug('TwitterBridge Plugin - ' . "Trying login for Twitter user {$this->twuid}."); try { $flink = Foreign_link::getByForeignID($this->twuid, TWITTER_SERVICE); $user = $flink->getUser(); common_debug('TwitterBridge Plugin - ' . "Logged in Twitter user {$flink->foreign_id} as user {$user->id} ({$user->nickname})"); common_set_user($user); common_real_login(true); $this->goHome($user->nickname); } catch (NoResultException $e) { // Either no Foreign_link was found or not the user connected to it. // Let's just continue to allow creating or logging in as a new user. } common_debug("TwitterBridge Plugin - No flink found for twuid: {$this->twuid} - new user"); // FIXME: what do we want to do here? I forgot return; throw new ServerException(_m('No foreign link found for Twitter user')); }