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('STATUSNET') && !defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 // @todo FIXME: documentation missing.
25 class TagotherAction extends Action
30 function prepare($args)
32 parent::prepare($args);
33 if (!common_logged_in()) {
34 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
35 $this->clientError(_('Not logged in.'), 403);
39 $id = $this->trimmed('id');
41 // TRANS: Client error displayed on user tag page when trying to add tags without providing a user ID.
42 $this->clientError(_('No ID argument.'));
46 $this->profile = Profile::staticGet('id', $id);
48 if (!$this->profile) {
49 // TRANS: Client error displayed on user tag page when trying to add tags providing a non-existing user ID.
50 $this->clientError(_('No profile with that ID.'));
57 function handle($args)
59 parent::handle($args);
60 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
63 $this->showForm($profile);
69 // TRANS: Title for "tag other users" page.
70 // TRANS: %s is the user nickname.
71 return sprintf(_('Tag %s'), $this->profile->nickname);
74 function showForm($error=null)
76 $this->error = $error;
80 function showContent()
82 $this->elementStart('div', 'entity_profile vcard author');
83 // TRANS: Header for user details on "tag other users" page.
84 $this->element('h2', null, _('User profile'));
86 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
87 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
88 'class' => 'photo avatar entity_depiction',
89 'width' => AVATAR_PROFILE_SIZE,
90 'height' => AVATAR_PROFILE_SIZE,
92 ($this->profile->fullname) ? $this->profile->fullname :
93 $this->profile->nickname));
95 $this->element('a', array('href' => $this->profile->profileurl,
96 'class' => 'entity_nickname nickname'),
97 $this->profile->nickname);
99 if ($this->profile->fullname) {
100 $this->element('div', 'fn entity_fn', $this->profile->fullname);
103 if ($this->profile->location) {
104 $this->element('div', 'label entity_location', $this->profile->location);
107 if ($this->profile->homepage) {
108 $this->element('a', array('href' => $this->profile->homepage,
110 'class' => 'url entity_url'),
111 $this->profile->homepage);
114 if ($this->profile->bio) {
115 $this->element('div', 'note entity_note', $this->profile->bio);
118 $this->elementEnd('div');
120 $this->elementStart('form', array('method' => 'post',
121 'id' => 'form_tag_user',
122 'class' => 'form_settings',
123 'name' => 'tagother',
124 'action' => common_local_url('tagother', array('id' => $this->profile->id))));
126 $this->elementStart('fieldset');
127 // TRANS: Fieldset legend on "tag other users" page.
128 $this->element('legend', null, _('Tag user'));
129 $this->hidden('token', common_session_token());
130 $this->hidden('id', $this->profile->id);
132 $user = common_current_user();
134 $this->elementStart('ul', 'form_data');
135 $this->elementStart('li');
136 // TRANS: Field label for inputting tags on "tag other users" page.
137 $this->input('tags', _('Tags'),
138 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
139 // TRANS: Title for input field for inputting tags on "tag other users" page.
140 _('Tags for this user (letters, numbers, -, ., and _), separated by commas or spaces.'));
141 $this->elementEnd('li');
142 $this->elementEnd('ul');
143 // TRANS: Button text for saving tags for other users.
144 $this->submit('save', _m('BUTTON','Save'));
145 $this->elementEnd('fieldset');
146 $this->elementEnd('form');
151 $id = $this->trimmed('id');
152 $tagstring = $this->trimmed('tags');
153 $token = $this->trimmed('token');
155 if (!$token || $token != common_session_token()) {
156 // TRANS: Client error displayed when the session token does not match or is not given.
157 $this->showForm(_('There was a problem with your session token. '.
158 'Try again, please.'));
162 if (is_string($tagstring) && strlen($tagstring) > 0) {
164 $tags = array_map('common_canonical_tag',
165 preg_split('/[\s,]+/', $tagstring));
167 foreach ($tags as $tag) {
168 if (!common_valid_profile_tag($tag)) {
169 // TRANS: Form validation error when entering an invalid tag.
170 // TRANS: %s is the invalid tag.
171 $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
179 $user = common_current_user();
181 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
182 'subscribed' => $this->profile->id)) &&
183 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
184 'subscribed' => $user->id)))
186 // TRANS: Client error on "tag other users" page when tagging a user is not possible because of missing mutual subscriptions.
187 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
191 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
194 // TRANS: Client error on "tag other users" page when saving tags fails server side.
195 $this->clientError(_('Could not save tags.'));
199 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
201 if ($this->boolean('ajax')) {
202 $this->startHTML('text/xml;charset=utf-8');
203 $this->elementStart('head');
204 // TRANS: Title of "tag other users" page.
205 $this->element('title', null, _m('TITLE','Tags'));
206 $this->elementEnd('head');
207 $this->elementStart('body');
208 $this->elementStart('p', 'subtags');
209 foreach ($tags as $tag) {
210 $this->element('a', array('href' => common_local_url($action,
211 array('nickname' => $user->nickname,
215 $this->elementEnd('p');
216 $this->elementEnd('body');
217 $this->elementEnd('html');
219 common_redirect(common_local_url($action, array('nickname' =>
225 function showPageNotice()
228 $this->element('p', 'error', $this->error);
230 $this->elementStart('div', 'instructions');
231 $this->element('p', null,
232 // TRANS: Page notice on "tag other users" page.
233 _('Use this form to add tags to your subscribers or subscriptions.'));
234 $this->elementEnd('div');