3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL')) { exit(1); }
22 class TagprofileAction extends FormAction
26 protected $target = null;
27 protected $form = 'TagProfile';
29 protected function doPreparation()
31 $id = $this->trimmed('id');
32 $uri = $this->trimmed('uri');
34 $this->target = Profile::getKV('id', $id);
36 if (!$this->target instanceof Profile) {
37 // TRANS: Client error displayed when referring to non-existing profile ID.
38 $this->clientError(_('No profile with that ID.'));
40 } elseif (!empty($uri)) {
41 $this->target = Profile::fromUri($uri);
43 // TRANS: Client error displayed when trying to tag a user but no ID or profile is provided.
44 $this->clientError(_('No profile identifier provided.'));
47 if (!$this->scoped->canTag($this->target)) {
48 // TRANS: Client error displayed when trying to tag a user that cannot be tagged.
49 $this->clientError(_('You cannot tag this user.'));
52 $this->formOpts = $this->target;
59 if (!$this->target instanceof Profile) {
60 // TRANS: Title for list form when not on a profile page.
61 return _('List a profile');
63 // TRANS: Title for list form when on a profile page.
64 // TRANS: %s is a profile nickname.
65 return sprintf(_m('ADDTOLIST','List %s'), $this->target->getNickname());
68 function showContent()
70 $this->elementStart('div', 'entity_profile h-card');
71 // TRANS: Header in list form.
72 $this->element('h2', null, _('User profile'));
74 $avatarUrl = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
75 $this->element('img', array('src' => $avatarUrl,
76 'class' => 'u-photo avatar entity_depiction',
77 'width' => AVATAR_PROFILE_SIZE,
78 'height' => AVATAR_PROFILE_SIZE,
79 'alt' => $this->target->getBestName()));
81 $this->element('a', array('href' => $this->target->getUrl(),
82 'class' => 'entity_nickname p-nickname'),
83 $this->target->getNickname());
84 if ($this->target->fullname) {
85 $this->element('div', 'p-name entity_fn', $this->target->fullname);
88 if ($this->target->location) {
89 $this->element('div', 'p-locality label entity_location', $this->target->location);
92 if ($this->target->homepage) {
93 $this->element('a', array('href' => $this->target->homepage,
95 'class' => 'u-url entity_url'),
96 $this->target->homepage);
99 if ($this->target->bio) {
100 $this->element('div', 'p-note entity_note', $this->target->bio);
103 $this->elementEnd('div');
105 if (Event::handle('StartShowTagProfileForm', array($this, $this->target))) {
106 parent::showContent();
107 Event::handle('EndShowTagProfileForm', array($this, $this->target));
111 protected function doPost()
113 $tagstring = $this->trimmed('tags');
114 $token = $this->trimmed('token');
116 if (Event::handle('StartSavePeopletags', array($this, $tagstring))) {
120 if (is_string($tagstring) && strlen($tagstring) > 0) {
122 $tags = preg_split('/[\s,]+/', $tagstring);
124 foreach ($tags as &$tag) {
125 $private = @$tag[0] === '.';
127 $tag = common_canonical_tag($tag);
128 if (!common_valid_profile_tag($tag)) {
129 // TRANS: Form validation error displayed if a given tag is invalid.
130 // TRANS: %s is the invalid tag.
131 throw new ClientException(sprintf(_('Invalid tag: "%s".'), $tag));
134 $tag_priv[$tag] = $private;
138 $result = Profile_tag::setTags($this->scoped->getID(), $this->target->getID(), $tags, $tag_priv);
140 throw new ServerException('The tags could not be saved.');
143 if ($this->boolean('ajax')) {
144 $this->startHTML('text/xml;charset=utf-8');
145 $this->elementStart('head');
146 $this->element('title', null, _m('TITLE','Tags'));
147 $this->elementEnd('head');
148 $this->elementStart('body');
150 if ($this->scoped->id == $this->target->id) {
151 $widget = new SelftagsWidget($this, $this->scoped, $this->target);
154 $widget = new PeopletagsWidget($this, $this->scoped, $this->target);
158 $this->elementEnd('body');
161 // TRANS: Success message if lists are saved.
162 $this->msg = _('Lists saved.');
166 Event::handle('EndSavePeopletags', array($this, $tagstring));