Пример #1
0
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('网页错误,请返回重试
                              '));
         return false;
     }
     $id = $this->trimmed('profile');
     if (!$id) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Пример #2
0
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         common_set_returnto($_SERVER['REQUEST_URI']);
         if (Event::handle('RedirectToLogin', array($this, null))) {
             common_redirect(common_local_url('login'), 303);
         }
     }
     $id = $this->trimmed('id');
     if (!$id) {
         $this->profile = false;
     } else {
         $this->profile = Profile::staticGet('id', $id);
         if (!$this->profile) {
             // TRANS: Client error displayed when referring to non-existing profile ID.
             $this->clientError(_('No profile with that ID.'));
             return false;
         }
     }
     $current = common_current_user()->getProfile();
     if ($this->profile && !$current->canTag($this->profile)) {
         // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
         $this->clientError(_('You cannot tag this user.'));
     }
     return true;
 }
Пример #3
0
 function prepare($args)
 {
     Action::prepare($args);
     // skip the ProfileAction code and replace it...
     $id = $this->arg('id');
     $this->user = false;
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Error message displayed when referring to a user without a profile.
         $this->serverError(_m('User has no profile.'));
         return false;
     }
     $user = User::staticGet('id', $this->profile->id);
     if ($user) {
         // This is a local user -- send to their regular profile.
         $url = common_local_url('showstream', array('nickname' => $user->nickname));
         common_redirect($url);
         return false;
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     $p = Profile::current();
     if (empty($this->tag)) {
         $stream = new ProfileNoticeStream($this->profile, $p);
     } else {
         $stream = new TaggedProfileNoticeStream($this->profile, $this->tag, $p);
     }
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     return true;
 }
Пример #4
0
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     $cur = common_current_user();
     if (empty($cur)) {
         // TRANS: Client error displayed trying to approve group membership while not logged in.
         $this->clientError(_('Must be logged in.'), 403);
         return false;
     }
     if ($this->arg('profile_id')) {
         $this->profile = Profile::staticGet('id', $this->arg('profile_id'));
     } else {
         // TRANS: Client error displayed trying to approve subscriptionswithout specifying a profile to approve.
         $this->clientError(_('Must specify a profile.'));
         return false;
     }
     $this->request = Subscription_queue::pkeyGet(array('subscriber' => $this->profile->id, 'subscribed' => $cur->id));
     if (empty($this->request)) {
         // TRANS: Client error displayed trying to approve subscription for a non-existing request.
         // TRANS: %s is a user nickname.
         $this->clientError(sprintf(_('%s is not in the moderation queue for your subscriptions.'), $this->profile->nickname), 403);
     }
     $this->approve = (bool) $this->arg('approve');
     $this->cancel = (bool) $this->arg('cancel');
     if (!$this->approve && !$this->cancel) {
         // TRANS: Client error displayed trying to approve/deny subscription.
         $this->clientError(_('Internal error: received neither cancel nor abort.'));
     }
     if ($this->approve && $this->cancel) {
         // TRANS: Client error displayed trying to approve/deny  subscription
         $this->clientError(_('Internal error: received both cancel and abort.'));
     }
     return true;
 }
Пример #5
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         // TRANS: Client error displayed when trying to change user options without specifying a user to work on.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Client error displayed when trying to change user options without specifying an existing user to work on.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Пример #6
0
 function prepare($args)
 {
     parent::prepare($args);
     $this->uri = $this->trimmed('uri');
     $this->uri = self::normalize($this->uri);
     if (self::isWebfinger($this->uri)) {
         $parts = explode('@', substr(urldecode($this->uri), 5));
         if (count($parts) == 2) {
             list($nick, $domain) = $parts;
             // @fixme confirm the domain too
             // @fixme if domain checking is added, ensure that it will not
             //        cause problems with sites that have changed domains!
             $nick = common_canonical_nickname($nick);
             $this->user = User::staticGet('nickname', $nick);
         }
     } else {
         $this->user = User::staticGet('uri', $this->uri);
         if (empty($this->user)) {
             // try and get it by profile url
             $profile = Profile::staticGet('profileurl', $this->uri);
             if (!empty($profile)) {
                 $this->user = User::staticGet('id', $profile->id);
             }
         }
     }
     if (!$this->user) {
         $this->clientError(_('No such user.'), 404);
         return false;
     }
     return true;
 }
Пример #7
0
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed trying a change a subscription while not logged in.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. ' . 'Try again, please.'));
         return false;
     }
     $id = $this->trimmed('profile');
     if (!$id) {
         // TRANS: Client error displayed trying a change a subscription without providing a profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         // TRANS: Client error displayed trying a change a subscription for a non-existant profile ID.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Пример #8
0
 /**
  * Check pre-requisites and instantiate attributes
  *
  * @param Array $args array of arguments (URL, GET, POST)
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     // 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->clientError(_('There was a problem with your session token.' . ' Try again, please.'));
         return false;
     }
     // Only for logged-in users
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     // Profile to subscribe to
     $tagged_id = $this->arg('tagged');
     $this->tagged = Profile::staticGet('id', $tagged_id);
     if (empty($this->tagged)) {
         // TRANS: Client error displayed when referring to a non-existing profile.
         $this->clientError(_('No such profile.'));
         return false;
     }
     $id = $this->arg('peopletag_id');
     $this->peopletag = Profile_list::staticGet('id', $id);
     if (empty($this->peopletag)) {
         // TRANS: Client error displayed trying to reference a non-existing list.
         $this->clientError(_('No such list.'));
         return false;
     }
     return true;
 }
Пример #9
0
 static function saveNew($from, $to, $content, $source)
 {
     $sender = Profile::staticGet('id', $from);
     if (!$sender->hasRight(Right::NEWMESSAGE)) {
         // TRANS: Client exception thrown when a user tries to send a direct message while being banned from sending them.
         throw new ClientException(_('You are banned from sending direct messages.'));
     }
     $msg = new Message();
     $msg->from_profile = $from;
     $msg->to_profile = $to;
     $msg->content = common_shorten_links($content);
     $msg->rendered = common_render_text($content);
     $msg->created = common_sql_now();
     $msg->source = $source;
     $result = $msg->insert();
     if (!$result) {
         common_log_db_error($msg, 'INSERT', __FILE__);
         // TRANS: Message given when a message could not be stored on the server.
         return _('Could not insert message.');
     }
     $orig = clone $msg;
     $msg->uri = common_local_url('showmessage', array('message' => $msg->id));
     $result = $msg->update($orig);
     if (!$result) {
         common_log_db_error($msg, 'UPDATE', __FILE__);
         // TRANS: Message given when a message could not be updated on the server.
         return _('Could not update message with new URI.');
     }
     return $msg;
 }
Пример #10
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->checkSessionToken();
     if (!common_logged_in()) {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->clientError(_('Not logged in.'));
         } else {
             // Redirect to login.
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
                 common_redirect(common_local_url('login'), 303);
             }
         }
         return false;
     }
     $id = $this->trimmed('profileid');
     if (!$id) {
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (!$this->profile) {
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     return true;
 }
Пример #11
0
 /**
  * Load or create an imported profile from Yammer data.
  * 
  * @param object $item loaded JSON data for Yammer importer
  * @return Profile
  */
 function importUser($item)
 {
     $data = $this->prepUser($item);
     $nickname = $data['options']['nickname'];
     $profileId = $this->findImportedUser($data['orig_id']);
     if ($profileId) {
         return Profile::staticGet('id', $profileId);
     } else {
         $user = User::staticGet('nickname', $nickname);
         if ($user) {
             common_log(LOG_WARN, "Copying Yammer profile info onto existing user {$nickname}");
             $profile = $user->getProfile();
             $this->savePropertiesOn($profile, $data['options'], array('fullname', 'homepage', 'bio', 'location'));
         } else {
             $user = User::register($data['options']);
             $profile = $user->getProfile();
         }
         if ($data['avatar']) {
             try {
                 $this->saveAvatar($data['avatar'], $profile);
             } catch (Exception $e) {
                 common_log(LOG_ERR, "Error importing Yammer avatar: " . $e->getMessage());
             }
         }
         $this->recordImportedUser($data['orig_id'], $profile->id);
         return $profile;
     }
 }
Пример #12
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::staticGet('id', $id);
     if (empty($this->gm)) {
         throw new ClientException(_('No such message'), 404);
     }
     $this->group = User_group::staticGet('id', $this->gm->to_group);
     if (empty($this->group)) {
         throw new ServerException(_('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         throw new ClientException(_('Cannot read message.'), 403);
     }
     $this->sender = Profile::staticGet('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         throw new ServerException(_('No sender found.'));
     }
     return true;
 }
Пример #13
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         // TRANS: Client exception thrown when trying to view group private messages without being logged in.
         throw new ClientException(_m('Only logged-in users can view private messages.'), 403);
     }
     $id = $this->trimmed('id');
     $this->gm = Group_message::staticGet('id', $id);
     if (empty($this->gm)) {
         // TRANS: Client exception thrown when trying to view a non-existing group private message.
         throw new ClientException(_m('No such message.'), 404);
     }
     $this->group = User_group::staticGet('id', $this->gm->to_group);
     if (empty($this->group)) {
         // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group.
         throw new ServerException(_m('Group not found.'));
     }
     if (!$this->user->isMember($this->group)) {
         // TRANS: Client exception thrown when trying to view a group private message without being a group member.
         throw new ClientException(_m('Cannot read message.'), 403);
     }
     $this->sender = Profile::staticGet('id', $this->gm->from_profile);
     if (empty($this->sender)) {
         // TRANS: Server exception thrown when trying to view a group private message without a sender.
         throw new ServerException(_m('No sender found.'));
     }
     return true;
 }
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $subscriberId = $this->trimmed('subscriber');
     $this->_subscriber = Profile::staticGet('id', $subscriberId);
     if (empty($this->_subscriber)) {
         // TRANS: Client exception thrown when trying to display a subscription for a non-existing profile ID.
         // TRANS: %d is the non-existing profile ID number.
         throw new ClientException(sprintf(_('No such profile id: %d.'), $subscriberId), 404);
     }
     $subscribedId = $this->trimmed('subscribed');
     $this->_subscribed = Profile::staticGet('id', $subscribedId);
     if (empty($this->_subscribed)) {
         // TRANS: Client exception thrown when trying to display a subscription for a non-existing profile ID.
         // TRANS: %d is the non-existing profile ID number.
         throw new ClientException(sprintf(_('No such profile id: %d.'), $subscribedId), 404);
     }
     $this->_subscription = Subscription::pkeyGet(array('subscriber' => $subscriberId, 'subscribed' => $subscribedId));
     if (empty($this->_subscription)) {
         // TRANS: Client exception thrown when trying to display a subscription for a non-subscribed profile ID.
         // TRANS: %1$d is the non-existing subscriber ID number, $2$d is the ID of the profile that was not subscribed to.
         $msg = sprintf(_('Profile %1$d not subscribed to profile %2$d.'), $subscriberId, $subscribedId);
         throw new ClientException($msg, 404);
     }
     return true;
 }
Пример #15
0
 function showFeedForm($mirror)
 {
     $profile = Profile::staticGet('id', $mirror->subscribed);
     if ($profile) {
         $form = new EditMirrorForm($this, $profile);
         $form->show();
     }
 }
 function hasRight($right)
 {
     $profile = Profile::staticGet($this->id);
     if ($profile) {
         return $profile->hasright($right);
     } else {
         throw new Exception("Missing profile");
     }
 }
Пример #17
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('blockto');
     if (empty($id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a to be blocked user profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing profile.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('blockgroup');
     if (empty($group_id)) {
         // TRANS: Client error displayed trying to block a user from a group while not specifying a group to block a profile from.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while specifying a non-existing group.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while not being an admin user.
         $this->clientError(_('Only an admin can block group members.'), 401);
         return false;
     }
     if (Group_block::isBlocked($this->group, $this->profile)) {
         // TRANS: Client error displayed trying to block a user from a group while user is already blocked from the given group.
         $this->clientError(_('User is already blocked from group.'));
         return false;
     }
     // XXX: could have proactive blocks, but we don't have UI for it.
     if (!$this->profile->isMember($this->group)) {
         // TRANS: Client error displayed trying to block a user from a group while user is not a member of given group.
         $this->clientError(_('User is not a member of group.'));
         return false;
     }
     return true;
 }
Пример #18
0
 function handle($args)
 {
     parent::handle($args);
     if ($this->boolean('ajax')) {
         StatusNet::setApi(true);
     }
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $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;
     }
     /* Use a session token for 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->clientError(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     $other_id = $this->arg('unsubscribeto');
     if (!$other_id) {
         // TRANS: Client error displayed when trying to leave a group without specifying an ID.
         $this->clientError(_('No profile ID in request.'));
         return;
     }
     $other = Profile::staticGet('id', $other_id);
     if (!$other) {
         // TRANS: Client error displayed when trying to leave a non-existing group.
         $this->clientError(_('No profile with that ID.'));
         return;
     }
     $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id, 'subscribed' => $other->id));
     if (empty($this->request)) {
         // TRANS: Client error displayed when trying to approve a non-existing group join request.
         // TRANS: %s is a user nickname.
         $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
     }
     $this->request->abort();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title after unsubscribing from a group.
         $this->element('title', null, _m('TITLE', 'Unsubscribed'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $subscribe = new SubscribeForm($this, $other);
         $subscribe->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)), 303);
     }
 }
Пример #19
0
 function hasRight($right)
 {
     $profile = Profile::staticGet($this->id);
     if ($profile) {
         return $profile->hasright($right);
     } else {
         // TRANS: Exception thrown when a right for a non-existing user profile is checked.
         throw new Exception(_("Missing profile."));
     }
 }
Пример #20
0
 protected function validateProfile($id)
 {
     $id = intval($id);
     $profile = Profile::staticGet('id', $id);
     if ($profile && $profile->id != $this->user->id) {
         return $profile;
     }
     // TRANS: Error message returned to user when setting up feed mirroring, but we were unable to resolve the given URL to a working feed.
     $this->clientError(_m("Invalid profile for mirroring."));
 }
Пример #21
0
 function getMember()
 {
     $member = Profile::staticGet('id', $this->profile_id);
     if (empty($member)) {
         // TRANS: Exception thrown providing an invalid profile ID.
         // TRANS: %s is the invalid profile ID.
         throw new Exception(sprintf(_("Profile ID %s is invalid."), $this->profile_id));
     }
     return $member;
 }
Пример #22
0
 function handle($data)
 {
     assert(is_array($data));
     assert(is_string($data['salmonuri']));
     assert(is_string($data['entry']));
     $actor = Profile::staticGet($data['actor']);
     $salmon = new Salmon();
     $salmon->post($data['salmonuri'], $data['entry'], $actor);
     // @fixme detect failure and attempt to resend
     return true;
 }
 /**
  * Handle the data
  *
  * @param array $data associative array of user & bookmark info from DeliciousBackupImporter::importBookmark()
  *
  * @return boolean success value
  */
 function handle($data)
 {
     $profile = Profile::staticGet('id', $data['profile_id']);
     try {
         $saved = Bookmark::saveNew($profile, $data['title'], $data['url'], $data['tags'], $data['description'], array('created' => $data['created'], 'distribute' => false));
     } catch (ClientException $e) {
         // Most likely a duplicate -- continue on with the rest!
         common_log(LOG_ERR, "Error importing delicious bookmark to {$data['url']}: " . $e->getMessage());
         return true;
     }
     return true;
 }
Пример #24
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('profileid');
     if (empty($id)) {
         // TRANS: Client error displayed when not providing a profile ID on the Make Admin page.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed when specifying an invalid profile ID on the Make Admin page.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('groupid');
     if (empty($group_id)) {
         // TRANS: Client error displayed when not providing a group ID on the Make Admin page.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed when providing an invalid group ID on the Make Admin page.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group) && !$user->hasRight(Right::MAKEGROUPADMIN)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page while not an admin.
         $this->clientError(_('Only an admin can make another user an admin.'), 401);
         return false;
     }
     if ($this->profile->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to make another user admin on the Make Admin page who already is admin.
         // TRANS: %1$s is the user that is already admin, %2$s is the group user is already admin for.
         $this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'), $this->profile->getBestName(), $this->group->getBestName()), 401);
         return false;
     }
     return true;
 }
Пример #25
0
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $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;
     }
     /* Use a session token for 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->clientError(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     $other_id = $this->arg('unsubscribeto');
     if (!$other_id) {
         // TRANS: Client error displayed when trying to unsubscribe without providing a profile ID.
         $this->clientError(_('No profile ID in request.'));
         return;
     }
     $other = Profile::staticGet('id', $other_id);
     if (!$other) {
         // TRANS: Client error displayed when trying to unsubscribe while providing a non-existing profile ID.
         $this->clientError(_('No profile with that ID.'));
         return;
     }
     $result = subs_unsubscribe_to($user, $other);
     if (is_string($result)) {
         $this->clientError($result);
         return;
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for page to unsubscribe.
         $this->element('title', null, _('Unsubscribed'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $subscribe = new SubscribeForm($this, $other);
         $subscribe->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('subscriptions', array('nickname' => $user->nickname)), 303);
     }
 }
Пример #26
0
 function delete()
 {
     $profile = Profile::staticGet('id', $this->user_id);
     $notice = Notice::staticGet('id', $this->notice_id);
     $result = null;
     if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) {
         $result = parent::delete();
         if ($result) {
             Event::handle('EndDisfavorNotice', array($profile, $notice));
         }
     }
     return $result;
 }
 static function cleanup($profile_list)
 {
     $subs = new self();
     $subs->profile_tag_id = $profile_list->id;
     $subs->find();
     while ($subs->fetch()) {
         $profile = Profile::staticGet('id', $subs->profile_id);
         Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
         // Delete anyway
         $subs->delete();
         Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
     }
 }
Пример #28
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->_profile = Profile::staticGet('id', $this->trimmed('profile'));
     if (empty($this->_profile)) {
         // TRANS: Client exception thrown when requesting a favorite feed for a non-existing profile.
         throw new ClientException(_('No such profile.'), 404);
     }
     $offset = ($this->page - 1) * $this->count;
     $limit = $this->count + 1;
     $this->_faves = Fave::byProfile($this->_profile->id, $offset, $limit);
     return true;
 }
Пример #29
0
 function handle_notice($notice)
 {
     $profile = Profile::staticGet($notice->profile_id);
     $this->log(LOG_INFO, "Posting Notice " . $notice->id . " from " . $profile->nickname);
     if (!$notice->is_local) {
         $this->log(LOG_INFO, "Skipping remote notice");
         return "skipped";
     }
     #
     # Build an Atom message from the notice
     #
     $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
     $msg = $profile->nickname . ': ' . $notice->content;
     $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
     $atom .= "<apisource>" . common_config('enjit', 'source') . "</apisource>\n";
     $atom .= "<source>\n";
     $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
     $atom .= "<link href='" . $profile->profileurl . "'/>\n";
     $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
     $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
     $atom .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
     $atom .= "</source>\n";
     $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
     $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
     $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
     $atom .= "<id>" . $notice->uri . "</id>\n";
     $atom .= "<published>" . common_date_w3dtf($notice->created) . "</published>\n";
     $atom .= "<updated>" . common_date_w3dtf($notice->modified) . "</updated>\n";
     $atom .= "</entry>\n";
     $url = common_config('enjit', 'apiurl') . "/submit/" . common_config('enjit', 'apikey');
     $data = "msg={$atom}";
     #
     # POST the message to $config['enjit']['apiurl']
     #
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     # SSL and Debugging options
     #
     # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     # curl_setopt($ch, CURLOPT_VERBOSE, 1);
     $result = curl_exec($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $this->log(LOG_INFO, "Response Code: {$code}");
     curl_close($ch);
     return $code;
 }
Пример #30
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return false;
     }
     $token = $this->trimmed('token');
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $id = $this->trimmed('unblockto');
     if (empty($id)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing a profile.
         $this->clientError(_('No profile specified.'));
         return false;
     }
     $this->profile = Profile::staticGet('id', $id);
     if (empty($this->profile)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing an existing profile.
         $this->clientError(_('No profile with that ID.'));
         return false;
     }
     $group_id = $this->trimmed('unblockgroup');
     if (empty($group_id)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without providing a group.
         $this->clientError(_('No group specified.'));
         return false;
     }
     $this->group = User_group::staticGet('id', $group_id);
     if (empty($this->group)) {
         // TRANS: Client error displayed when trying to unblock a user from a non-existing group.
         $this->clientError(_('No such group.'));
         return false;
     }
     $user = common_current_user();
     if (!$user->isAdmin($this->group)) {
         // TRANS: Client error displayed when trying to unblock a user from a group without being an administrator for the group.
         $this->clientError(_('Only an admin can unblock group members.'), 401);
         return false;
     }
     if (!Group_block::isBlocked($this->group, $this->profile)) {
         // TRANS: Client error displayed when trying to unblock a non-blocked user from a group.
         $this->clientError(_('User is not blocked from group.'));
         return false;
     }
     return true;
 }