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 $this->clientError(_('Not logged in.'), 403);
38 $id = $this->trimmed('id');
40 $this->clientError(_('No ID argument.'));
44 $this->profile = Profile::staticGet('id', $id);
46 if (!$this->profile) {
47 $this->clientError(_('No profile with that ID.'));
54 function handle($args)
56 parent::handle($args);
57 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
60 $this->showForm($profile);
66 return sprintf(_('Tag %s'), $this->profile->nickname);
69 function showForm($error=null)
71 $this->error = $error;
75 function showContent()
77 $this->elementStart('div', 'entity_profile vcard author');
78 $this->element('h2', null, _('User profile'));
80 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
81 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
82 'class' => 'photo avatar entity_depiction',
83 'width' => AVATAR_PROFILE_SIZE,
84 'height' => AVATAR_PROFILE_SIZE,
86 ($this->profile->fullname) ? $this->profile->fullname :
87 $this->profile->nickname));
89 $this->element('a', array('href' => $this->profile->profileurl,
90 'class' => 'entity_nickname nickname'),
91 $this->profile->nickname);
93 if ($this->profile->fullname) {
94 $this->element('div', 'fn entity_fn', $this->profile->fullname);
97 if ($this->profile->location) {
98 $this->element('div', 'label entity_location', $this->profile->location);
101 if ($this->profile->homepage) {
102 $this->element('a', array('href' => $this->profile->homepage,
104 'class' => 'url entity_url'),
105 $this->profile->homepage);
108 if ($this->profile->bio) {
109 $this->element('div', 'note entity_note', $this->profile->bio);
112 $this->elementEnd('div');
114 $this->elementStart('form', array('method' => 'post',
115 'id' => 'form_tag_user',
116 'class' => 'form_settings',
117 'name' => 'tagother',
118 'action' => common_local_url('tagother', array('id' => $this->profile->id))));
120 $this->elementStart('fieldset');
121 $this->element('legend', null, _('Tag user'));
122 $this->hidden('token', common_session_token());
123 $this->hidden('id', $this->profile->id);
125 $user = common_current_user();
127 $this->elementStart('ul', 'form_data');
128 $this->elementStart('li');
129 $this->input('tags', _('Tags'),
130 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
131 _('Tags for this user (letters, numbers, -, ., and _), separated by commas or spaces.'));
132 $this->elementEnd('li');
133 $this->elementEnd('ul');
134 $this->submit('save', _m('BUTTON','Save'));
135 $this->elementEnd('fieldset');
136 $this->elementEnd('form');
141 $id = $this->trimmed('id');
142 $tagstring = $this->trimmed('tags');
143 $token = $this->trimmed('token');
145 if (!$token || $token != common_session_token()) {
146 $this->showForm(_('There was a problem with your session token. '.
147 'Try again, please.'));
151 if (is_string($tagstring) && strlen($tagstring) > 0) {
153 $tags = array_map('common_canonical_tag',
154 preg_split('/[\s,]+/', $tagstring));
156 foreach ($tags as $tag) {
157 if (!common_valid_profile_tag($tag)) {
158 // TRANS: Form validation error when entering an invalid tag.
159 // TRANS: %s is the invalid tag.
160 $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
168 $user = common_current_user();
170 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
171 'subscribed' => $this->profile->id)) &&
172 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
173 'subscribed' => $user->id)))
175 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
179 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
182 $this->clientError(_('Could not save tags.'));
186 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
188 if ($this->boolean('ajax')) {
189 $this->startHTML('text/xml;charset=utf-8');
190 $this->elementStart('head');
191 $this->element('title', null, _('Tags'));
192 $this->elementEnd('head');
193 $this->elementStart('body');
194 $this->elementStart('p', 'subtags');
195 foreach ($tags as $tag) {
196 $this->element('a', array('href' => common_local_url($action,
197 array('nickname' => $user->nickname,
201 $this->elementEnd('p');
202 $this->elementEnd('body');
203 $this->elementEnd('html');
205 common_redirect(common_local_url($action, array('nickname' =>
211 function showPageNotice()
214 $this->element('p', 'error', $this->error);
216 $this->elementStart('div', 'instructions');
217 $this->element('p', null,
218 _('Use this form to add tags to your subscribers or subscriptions.'));
219 $this->elementEnd('div');