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 class TagotherAction extends Action
29 function prepare($args)
31 parent::prepare($args);
32 if (!common_logged_in()) {
33 $this->clientError(_('Not logged in.'), 403);
37 $id = $this->trimmed('id');
39 $this->clientError(_('No ID argument.'));
43 $this->profile = Profile::staticGet('id', $id);
45 if (!$this->profile) {
46 $this->clientError(_('No profile with that ID.'));
53 function handle($args)
55 parent::handle($args);
56 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
59 $this->showForm($profile);
65 return sprintf(_('Tag %s'), $this->profile->nickname);
68 function showForm($error=null)
70 $this->error = $error;
74 function showContent()
76 $this->elementStart('div', 'entity_profile vcard author');
77 $this->element('h2', null, _('User profile'));
79 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
80 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
81 'class' => 'photo avatar entity_depiction',
82 'width' => AVATAR_PROFILE_SIZE,
83 'height' => AVATAR_PROFILE_SIZE,
85 ($this->profile->fullname) ? $this->profile->fullname :
86 $this->profile->nickname));
88 $this->element('a', array('href' => $this->profile->profileurl,
89 'class' => 'entity_nickname nickname'),
90 $this->profile->nickname);
92 if ($this->profile->fullname) {
93 $this->element('div', 'fn entity_fn', $this->profile->fullname);
96 if ($this->profile->location) {
97 $this->element('div', 'label entity_location', $this->profile->location);
100 if ($this->profile->homepage) {
101 $this->element('a', array('href' => $this->profile->homepage,
103 'class' => 'url entity_url'),
104 $this->profile->homepage);
107 if ($this->profile->bio) {
108 $this->element('div', 'note entity_note', $this->profile->bio);
111 $this->elementEnd('div');
113 $this->elementStart('form', array('method' => 'post',
114 'id' => 'form_tag_user',
115 'class' => 'form_settings',
116 'name' => 'tagother',
117 'action' => common_local_url('tagother', array('id' => $this->profile->id))));
119 $this->elementStart('fieldset');
120 $this->element('legend', null, _('Tag user'));
121 $this->hidden('token', common_session_token());
122 $this->hidden('id', $this->profile->id);
124 $user = common_current_user();
126 $this->elementStart('ul', 'form_data');
127 $this->elementStart('li');
128 $this->input('tags', _('Tags'),
129 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
130 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
131 $this->elementEnd('li');
132 $this->elementEnd('ul');
133 $this->submit('save', _('Save'));
134 $this->elementEnd('fieldset');
135 $this->elementEnd('form');
140 $id = $this->trimmed('id');
141 $tagstring = $this->trimmed('tags');
142 $token = $this->trimmed('token');
144 if (!$token || $token != common_session_token()) {
145 $this->showForm(_('There was a problem with your session token. '.
146 'Try again, please.'));
150 if (is_string($tagstring) && strlen($tagstring) > 0) {
152 $tags = array_map('common_canonical_tag',
153 preg_split('/[\s,]+/', $tagstring));
155 foreach ($tags as $tag) {
156 if (!common_valid_profile_tag($tag)) {
157 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
165 $user = common_current_user();
167 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
168 'subscribed' => $this->profile->id)) &&
169 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
170 'subscribed' => $user->id)))
172 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
176 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
179 $this->clientError(_('Could not save tags.'));
183 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
185 if ($this->boolean('ajax')) {
186 $this->startHTML('text/xml;charset=utf-8');
187 $this->elementStart('head');
188 $this->element('title', null, _('Tags'));
189 $this->elementEnd('head');
190 $this->elementStart('body');
191 $this->elementStart('p', 'subtags');
192 foreach ($tags as $tag) {
193 $this->element('a', array('href' => common_local_url($action,
194 array('nickname' => $user->nickname,
198 $this->elementEnd('p');
199 $this->elementEnd('body');
200 $this->elementEnd('html');
202 common_redirect(common_local_url($action, array('nickname' =>
208 function showPageNotice()
211 $this->element('p', 'error', $this->error);
213 $this->elementStart('div', 'instructions');
214 $this->element('p', null,
215 _('Use this form to add tags to your subscribers or subscriptions.'));
216 $this->elementEnd('div');