Пример #1
0
 function showTags()
 {
     $user = common_current_user();
     if (!empty($user)) {
         if ($user->id == $this->profile->id) {
             $tags = new SelftagsWidget($this->out, $user, $this->profile);
             $tags->show();
         } else {
             if ($user->getProfile()->canTag($this->profile)) {
                 $tags = new PeopletagsWidget($this->out, $user, $this->profile);
                 $tags->show();
             }
         }
     }
 }
 function showTags()
 {
     $cur = common_current_user();
     $self_tags = new SelftagsWidget($this->out, $this->profile, $this->profile);
     $self_tags->show();
     if ($cur) {
         // don't show self-tags again
         if ($cur->id != $this->profile->id && $cur->getProfile()->canTag($this->profile)) {
             $tags = new PeopletagsWidget($this->out, $cur, $this->profile);
             $tags->show();
         }
     }
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
 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));
     }
 }