Exemplo n.º 1
0
 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;
 }
 function connectNewUser()
 {
     $nickname = $this->trimmed('nickname');
     $password = $this->trimmed('password');
     if (!common_check_user($nickname, $password)) {
         // TRANS: Form validation error displayed when connecting an existing user to a Twitter user fails because
         // TRANS: the provided username and/or password are incorrect.
         $this->showForm(_m('Invalid username or password.'));
         return;
     }
     $user = User::staticGet('nickname', $nickname);
     if (!empty($user)) {
         common_debug('TwitterBridge Plugin - ' . "Legit user to connect to Twitter: {$nickname}");
     }
     $result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token);
     save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
     if (!$result) {
         // TRANS: Server error displayed connecting a user to a Twitter user has failed.
         $this->serverError(_m('Error connecting user to Twitter.'));
         return;
     }
     common_debug('TwitterBridge Plugin - ' . "Connected Twitter user {$this->twuid} to local user {$user->id}");
     common_set_user($user);
     common_real_login(true);
     $this->goHome($user->nickname);
 }
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
 function connectNewUser()
 {
     $nickname = $this->trimmed('nickname');
     $password = $this->trimmed('password');
     if (!common_check_user($nickname, $password)) {
         $this->showForm(_('Invalid username or password.'));
         return;
     }
     $user = User::staticGet('nickname', $nickname);
     if (!empty($user)) {
         common_debug('TwitterBridge Plugin - ' . "Legit user to connect to Twitter: {$nickname}");
     }
     $result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token);
     save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
     if (!$result) {
         $this->serverError(_('Error connecting user to Twitter.'));
         return;
     }
     common_debug('TwitterBridge Plugin - ' . "Connected Twitter user {$this->twuid} to local user {$user->id}");
     common_set_user($user);
     common_real_login(true);
     $this->goHome($user->nickname);
 }
 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;
 }
Exemplo n.º 6
0
 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 connectNewUser()
 {
     $nickname = $this->trimmed('nickname');
     $password = $this->trimmed('password');
     if (!common_check_user($nickname, $password)) {
         // TRANS: Form validation error displayed when connecting an existing user to a Twitter user fails because
         // TRANS: the provided username and/or password are incorrect.
         throw new ClientException(_m('Invalid username or password.'));
     }
     $user = User::getKV('nickname', $nickname);
     if ($user instanceof User) {
         common_debug('TwitterBridge Plugin - ' . "Legit user to connect to Twitter: {$nickname}");
     }
     // throws exception on failure
     $this->saveForeignLink($user->id, $this->twuid, $this->access_token);
     save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
     common_debug('TwitterBridge Plugin - ' . "Connected Twitter user {$this->twuid} to local user {$user->id}");
     common_set_user($user);
     common_real_login(true);
     $this->goHome($user->nickname);
 }
Exemplo n.º 8
0
 /**
  * Associate a Twitter account with the user's account
  *
  * Validates post input; verifies it against Twitter; and if
  * successful stores in the database.
  *
  * @return void
  */
 function addTwitterAccount()
 {
     $screen_name = $this->trimmed('twitter_username');
     $password = $this->trimmed('twitter_password');
     $noticesync = $this->boolean('noticesync');
     $replysync = $this->boolean('replysync');
     $friendsync = $this->boolean('friendsync');
     if (!Validate::string($screen_name, array('min_length' => 1, 'max_length' => 15, 'format' => VALIDATE_NUM . VALIDATE_ALPHA . '_'))) {
         $this->showForm(_('Username must have only numbers, ' . 'upper- and lowercase letters, ' . 'and underscore (_). 15 chars max.'));
         return;
     }
     if (!$this->verifyCredentials($screen_name, $password)) {
         $this->showForm(_('Could not verify your Twitter credentials!'));
         return;
     }
     $twit_user = twitter_user_info($screen_name, $password);
     if (!$twit_user) {
         $this->showForm(sprintf(_('Unable to retrieve account information ' . 'For "%s" from Twitter.'), $screen_name));
         return;
     }
     if (!save_twitter_user($twit_user->id, $screen_name)) {
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     $user = common_current_user();
     $flink = new Foreign_link();
     $flink->user_id = $user->id;
     $flink->foreign_id = $twit_user->id;
     $flink->service = TWITTER_SERVICE;
     $flink->credentials = $password;
     $flink->created = common_sql_now();
     $flink->set_flags($noticesync, $replysync, $friendsync);
     $flink_id = $flink->insert();
     if (!$flink_id) {
         common_log_db_error($flink, 'INSERT', __FILE__);
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     if ($friendsync) {
         save_twitter_friends($user, $twit_user->id, $screen_name, $password);
     }
     $this->showForm(_('Twitter settings saved.'), true);
 }