Exemple #1
0
function subs_subscribe_user($user, $other_nickname)
{
    $other = User::staticGet('nickname', $other_nickname);
    if (!$other) {
        return _('No such user.');
    }
    return subs_subscribe_to($user, $other);
}
Exemple #2
0
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
         return;
     }
     # CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $other_id = $this->arg('subscribeto');
     $other = User::staticGet('id', $other_id);
     if (!$other) {
         $this->clientError(_('Not a local user.'));
         return;
     }
     $result = subs_subscribe_to($user, $other);
     if ($result != true) {
         $this->clientError($result);
         return;
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Subscribed'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $unsubscribe = new UnsubscribeForm($this, $other->getProfile());
         $unsubscribe->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)));
     }
 }
Exemple #3
0
 function sendInvitations()
 {
     # CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('表单错误,请重试'));
         return;
     }
     $user = common_current_user();
     $profile = $user->getProfile();
     $bestname = $profile->getBestName();
     $sitename = common_config('site', 'name');
     $personal = $this->trimmed('personal');
     $addresses = explode("\n", $this->trimmed('addresses'));
     foreach ($addresses as $email) {
         $email = trim($email);
         if (!Validate::email($email, common_config('email', 'check_domain'))) {
             $this->showForm(sprintf(_('邮件地址格式错误: %s'), $email));
             return;
         }
     }
     $this->already = array();
     $this->subbed = array();
     foreach ($addresses as $email) {
         $email = common_canonical_email($email);
         $other = User::staticGet('email', $email);
         if ($other) {
             if ($user->isSubscribed($other)) {
                 $this->already[] = $other;
             } else {
                 subs_subscribe_to($user, $other);
                 $this->subbed[] = $other;
             }
         } else {
             $this->sent[] = $email;
             $this->sendInvitation($email, $user, $personal);
         }
     }
     $this->mode = 'sent';
     $this->showPage();
 }
Exemple #4
0
function newSub($i)
{
    global $userprefix;
    $f = rand(0, $i - 1);
    $fromnick = sprintf('%s%d', $userprefix, $f);
    $from = User::staticGet('nickname', $fromnick);
    if (empty($from)) {
        throw new Exception("Can't find user '{$fromnick}'.");
    }
    $t = rand(0, $i - 1);
    if ($t == $f) {
        $t++;
        if ($t > $i - 1) {
            $t = 0;
        }
    }
    $tunic = sprintf('%s%d', $userprefix, $t);
    $to = User::staticGet('nickname', $tunic);
    if (empty($to)) {
        throw new Exception("Can't find user '{$tunic}'.");
    }
    subs_subscribe_to($from, $to);
    $from->free();
    $to->free();
}
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
         return;
     }
     if (empty($this->other)) {
         $this->clientError(_('Could not follow user: User not found.'), 403, $this->format);
         return;
     }
     if ($this->user->isSubscribed($this->other)) {
         $errmsg = sprintf(_('Could not follow user: %s is already on your list.'), $this->other->nickname);
         $this->clientError($errmsg, 403, $this->format);
         return;
     }
     $result = subs_subscribe_to($this->user, $this->other);
     if (is_string($result)) {
         $this->clientError($result, 403, $this->format);
         return;
     }
     $this->initDocument($this->format);
     $this->showProfile($this->other, $this->format);
     $this->endDocument($this->format);
 }
Exemple #6
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;
}
Exemple #7
0
 function emailChanged()
 {
     $invites = new Invitation();
     $invites->address = $this->email;
     $invites->address_type = 'email';
     if ($invites->find()) {
         while ($invites->fetch()) {
             $other = User::staticGet($invites->user_id);
             subs_subscribe_to($other, $this);
         }
     }
 }
Exemple #8
0
 function sendInvitations()
 {
     if (Event::handle('StartSendInvitations', array(&$this))) {
         // CSRF protection
         $token = $this->trimmed('token');
         if (!$token || $token != common_session_token()) {
             // TRANS: Client error displayed when the session token does not match or is not given.
             $this->showForm(_('There was a problem with your session token. Try again, please.'));
             return;
         }
         $user = common_current_user();
         $profile = $user->getProfile();
         $bestname = $profile->getBestName();
         $sitename = common_config('site', 'name');
         $personal = $this->trimmed('personal');
         $addresses = explode("\n", $this->trimmed('addresses'));
         foreach ($addresses as $email) {
             $email = trim($email);
             $valid = null;
             try {
                 if (Event::handle('StartValidateUserEmail', array(null, $email, &$valid))) {
                     $valid = Validate::email($email, common_config('email', 'check_domain'));
                     Event::handle('EndValidateUserEmail', array(null, $email, &$valid));
                 }
                 if ($valid) {
                     if (Event::handle('StartValidateEmailInvite', array($user, $email, &$valid))) {
                         $valid = true;
                         Event::handle('EndValidateEmailInvite', array($user, $email, &$valid));
                     }
                 }
                 if (!$valid) {
                     // TRANS: Form validation message when providing an e-mail address that does not validate.
                     // TRANS: %s is an invalid e-mail address.
                     $this->showForm(sprintf(_('Invalid email address: %s.'), $email));
                     return;
                 }
             } catch (ClientException $e) {
                 $this->showForm($e->getMessage());
                 return;
             }
         }
         $this->already = array();
         $this->subbed = array();
         foreach ($addresses as $email) {
             $email = common_canonical_email($email);
             $other = User::staticGet('email', $email);
             if ($other) {
                 if ($user->isSubscribed($other)) {
                     $this->already[] = $other;
                 } else {
                     subs_subscribe_to($user, $other);
                     $this->subbed[] = $other;
                 }
             } else {
                 $this->sent[] = $email;
                 $this->sendInvitation($email, $user, $personal);
             }
         }
         $this->mode = 'sent';
         $this->showPage();
         Event::handle('EndSendInvitations', array($this));
     }
 }
Exemple #9
0
 function sendInvitations()
 {
     # CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $user = common_current_user();
     $profile = $user->getProfile();
     $bestname = $profile->getBestName();
     $sitename = common_config('site', 'name');
     $personal = $this->trimmed('personal');
     $addresses = explode("\n", $this->trimmed('addresses'));
     foreach ($addresses as $email) {
         $email = trim($email);
         if (!Validate::email($email, common_config('email', 'check_domain'))) {
             // TRANS: Form validation message when providing an e-mail address that does not validate.
             // TRANS: %s is an invalid e-mail address.
             $this->showForm(sprintf(_('Invalid email address: %s.'), $email));
             return;
         }
     }
     $this->already = array();
     $this->subbed = array();
     foreach ($addresses as $email) {
         $email = common_canonical_email($email);
         $other = User::staticGet('email', $email);
         if ($other) {
             if ($user->isSubscribed($other)) {
                 $this->already[] = $other;
             } else {
                 subs_subscribe_to($user, $other);
                 $this->subbed[] = $other;
             }
         } else {
             $this->sent[] = $email;
             $this->sendInvitation($email, $user, $personal);
         }
     }
     $this->mode = 'sent';
     $this->showPage();
 }
 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;
 }