function saveTags() { $id = $this->trimmed('id'); $tagstring = $this->trimmed('tags'); $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_('There was a problem with your session token.' . ' Try again, please.')); return; } if (is_string($tagstring) && strlen($tagstring) > 0) { $tags = array_map('common_canonical_tag', preg_split('/[\\s,]+/', $tagstring)); foreach ($tags as $tag) { if (!common_valid_profile_tag($tag)) { $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag)); return; } } } else { $tags = array(); } $user = common_current_user(); if (!Subscription::pkeyGet(array('subscriber' => $user->id, 'subscribed' => $this->profile->id)) && !Subscription::pkeyGet(array('subscriber' => $this->profile->id, 'subscribed' => $user->id))) { $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.')); return; } $result = Profile_tag::setTags($user->id, $this->profile->id, $tags); if (!$result) { $this->clientError(_('Could not save tags.')); return; } $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers'; if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, _('Tags')); $this->elementEnd('head'); $this->elementStart('body'); $this->elementStart('p', 'subtags'); foreach ($tags as $tag) { $this->element('a', array('href' => common_local_url($action, array('nickname' => $user->nickname, 'tag' => $tag))), $tag); } $this->elementEnd('p'); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url($action, array('nickname' => $user->nickname))); } }
protected function doPost() { $tagstring = $this->trimmed('tags'); $token = $this->trimmed('token'); if (Event::handle('StartSavePeopletags', array($this, $tagstring))) { $tags = array(); $tag_priv = array(); if (is_string($tagstring) && strlen($tagstring) > 0) { $tags = preg_split('/[\\s,]+/', $tagstring); foreach ($tags as &$tag) { $private = @$tag[0] === '.'; $tag = common_canonical_tag($tag); if (!common_valid_profile_tag($tag)) { // TRANS: Form validation error displayed if a given tag is invalid. // TRANS: %s is the invalid tag. throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag)); } $tag_priv[$tag] = $private; } } $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv); if (!$result) { throw new ServerException('The tags could not be saved.'); } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, _m('TITLE', 'Tags')); $this->elementEnd('head'); $this->elementStart('body'); if ($this->scoped->id == $this->target->id) { $widget = new SelftagsWidget($this, $this->scoped, $this->target); $widget->show(); } else { $widget = new PeopletagsWidget($this, $this->scoped, $this->target); $widget->show(); } $this->elementEnd('body'); $this->endHTML(); } else { // TRANS: Success message if lists are saved. $this->msg = _('Lists saved.'); $this->showForm(); } Event::handle('EndSavePeopletags', array($this, $tagstring)); } }
function setSelfTags($newtags) { return Profile_tag::setTags($this->id, $this->id, $newtags); }
function saveTags() { $id = $this->trimmed('id'); $tagstring = $this->trimmed('tags'); $token = $this->trimmed('token'); if (Event::handle('StartSavePeopletags', array($this, $tagstring))) { 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; } $tags = array(); $tag_priv = array(); if (is_string($tagstring) && strlen($tagstring) > 0) { $tags = preg_split('/[\\s,]+/', $tagstring); foreach ($tags as &$tag) { $private = @$tag[0] === '.'; $tag = common_canonical_tag($tag); if (!common_valid_profile_tag($tag)) { // TRANS: Form validation error displayed if a given tag is invalid. // TRANS: %s is the invalid tag. $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag)); return; } $tag_priv[$tag] = $private; } } $user = common_current_user(); try { $result = Profile_tag::setTags($user->id, $this->profile->id, $tags, $tag_priv); if (!$result) { throw new Exception('The tags could not be saved.'); } } catch (Exception $e) { $this->showForm($e->getMessage()); return false; } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, _m('TITLE', 'Tags')); $this->elementEnd('head'); $this->elementStart('body'); if ($user->id == $this->profile->id) { $widget = new SelftagsWidget($this, $user, $this->profile); $widget->show(); } else { $widget = new PeopletagsWidget($this, $user, $this->profile); $widget->show(); } $this->elementEnd('body'); $this->elementEnd('html'); } else { // TRANS: Success message if lists are saved. $this->error = _('Lists saved.'); $this->showForm(); } Event::handle('EndSavePeopletags', array($this, $tagstring)); } }