Ejemplo n.º 1
0
 /**
  * Add a user to a list (tag someone)
  *
  * @return boolean success
  */
 function handlePost()
 {
     if ($this->auth_user->id != $this->list->tagger) {
         $this->clientError(_('You are not allowed to add members to this list.'), 401, $this->format);
         return false;
     }
     if ($this->user === false) {
         $this->clientError(_('You must specify a member.'), 400, $this->format);
         return false;
     }
     $result = Profile_tag::setTag($this->auth_user->id, $this->user->id, $this->list->tag);
     if (empty($result)) {
         $this->clientError(_('An error occured.'), 500, $this->format);
         return false;
     }
     switch ($this->format) {
         case 'xml':
             $this->showSingleXmlList($this->list);
             break;
         case 'json':
             $this->showSingleJsonList($this->list);
             break;
         default:
             $this->clientError(_('API method not found.'), 404, $this->format);
             return false;
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * Add a user to a list (tag someone)
  *
  * @return boolean success
  */
 function handlePost()
 {
     if ($this->auth_user->id != $this->list->tagger) {
         // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
         $this->clientError(_('You are not allowed to add members to this list.'), 401);
     }
     if (!$this->target instanceof Profile) {
         // TRANS: Client error displayed when trying to modify list members without specifying them.
         $this->clientError(_('You must specify a member.'));
     }
     $result = Profile_tag::setTag($this->auth_user->id, $this->target->id, $this->list->tag);
     if (empty($result)) {
         // TRANS: Client error displayed when an unknown error occurs viewing list members.
         $this->clientError(_('An error occured.'), 500);
     }
     switch ($this->format) {
         case 'xml':
             $this->showSingleXmlList($this->list);
             break;
         case 'json':
             $this->showSingleJsonList($this->list);
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
 }
Ejemplo n.º 3
0
 /**
  * Handle request
  *
  * Does the tagging and returns results.
  *
  * @param Array $args unused.
  *
  * @return void
  */
 function handle($args)
 {
     // Throws exception on error
     $ptag = Profile_tag::setTag($this->user->id, $this->tagged->id, $this->peopletag->tag);
     if (!$ptag) {
         $user = User::staticGet('id', $id);
         if ($user) {
             $this->clientError(sprintf(_('There was an unexpected error while listing %s.'), $user->nickname));
         } else {
             // TRANS: Client error displayed when an unknown error occurs when adding a user to a list.
             // TRANS: %s is a profile URL.
             $this->clientError(sprintf(_('There was a problem listing %s. ' . 'The remote server is probably not responding correctly. ' . 'Please try retrying later.'), $this->profile->profileurl));
         }
         return false;
     }
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title after adding a user to a list.
         $this->element('title', null, _m('TITLE', 'Listed'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $unsubscribe = new UntagButton($this, $this->tagged, $this->peopletag);
         $unsubscribe->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $url = common_local_url('subscriptions', array('nickname' => $this->user->nickname));
         common_redirect($url, 303);
     }
 }
Ejemplo n.º 4
0
 function handle($channel)
 {
     $profile = $this->getProfile($this->other);
     $cur = $this->user->getProfile();
     if (!$profile) {
         // TRANS: Client error displayed trying to perform an action related to a non-existing profile.
         $channel->error($cur, _('No such profile.'));
         return;
     }
     if (!$cur->canTag($profile)) {
         // TRANS: Error displayed when trying to tag a user that cannot be tagged.
         $channel->error($cur, _('You cannot tag this user.'));
         return;
     }
     $privs = array();
     $tags = preg_split('/[\\s,]+/', $this->tags);
     $clean_tags = array();
     foreach ($tags as $tag) {
         $private = @$tag[0] === '.';
         $tag = $clean_tags[] = common_canonical_tag($tag);
         if (!common_valid_profile_tag($tag)) {
             // TRANS: Error displayed if a given tag is invalid.
             // TRANS: %s is the invalid tag.
             $channel->error($cur, sprintf(_('Invalid tag: "%s".'), $tag));
             return;
         }
         $privs[$tag] = $private;
     }
     try {
         foreach ($clean_tags as $tag) {
             Profile_tag::setTag($cur->id, $profile->id, $tag, null, $privs[$tag]);
         }
     } catch (Exception $e) {
         // TRANS: Error displayed if tagging a user fails.
         // TRANS: %1$s is the tagged user, %2$s is the error message (no punctuation).
         $channel->error($cur, sprintf(_('Error tagging %1$s: %2$s'), $profile->nickname, $e->getMessage()));
         return;
     }
     // TRANS: Succes message displayed if tagging a user succeeds.
     // TRANS: %1$s is the tagged user's nickname, %2$s is a list of tags.
     // TRANS: Plural is decided based on the number of tags added (not part of message).
     $channel->output($cur, sprintf(_m('%1$s was tagged %2$s', '%1$s was tagged %2$s', count($clean_tags)), $profile->nickname, implode(_(', '), $clean_tags)));
 }
Ejemplo n.º 5
0
 function handleTag()
 {
     if ($this->activity->target->type == ActivityObject::_LIST) {
         if ($this->activity->objects[0]->type != ActivityObject::PERSON) {
             // TRANS: Client exception.
             throw new ClientException(_m('Not a person object.'));
             return false;
         }
         // this is a peopletag
         $tagged = User::staticGet('uri', $this->activity->objects[0]->id);
         if (empty($tagged)) {
             // TRANS: Client exception.
             throw new ClientException(_m('Unidentified profile being tagged.'));
         }
         if ($tagged->id !== $this->user->id) {
             // TRANS: Client exception.
             throw new ClientException(_m('This user is not the one being tagged.'));
         }
         // save the list
         $tagger = $this->ensureProfile();
         $list = Ostatus_profile::ensureActivityObjectProfile($this->activity->target);
         $ptag = $list->localPeopletag();
         $result = Profile_tag::setTag($ptag->tagger, $tagged->id, $ptag->tag);
         if (!$result) {
             // TRANS: Client exception.
             throw new ClientException(_m('The tag could not be saved.'));
         }
     }
 }