3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
24 class TagotherAction extends Action
27 function handle($args)
30 parent::handle($args);
32 if (!common_logged_in()) {
33 $this->client_error(_('Not logged in'), 403);
37 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
40 $id = $this->trimmed('id');
42 $this->client_error(_('No id argument.'));
45 $profile = Profile::staticGet('id', $id);
47 $this->client_error(_('No profile with that ID.'));
50 $this->show_form($profile);
54 function show_form($profile, $error=null)
57 $user = common_current_user();
59 common_show_header(_('Tag a person'),
60 null, array($profile, $error), array($this, 'show_top'));
62 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
64 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
65 'class' => 'avatar stream',
66 'width' => AVATAR_PROFILE_SIZE,
67 'height' => AVATAR_PROFILE_SIZE,
69 ($profile->fullname) ? $profile->fullname :
72 common_element('a', array('href' => $profile->profileurl,
73 'class' => 'external profile nickname'),
76 if ($profile->fullname) {
77 common_element_start('div', 'fullname');
78 if ($profile->homepage) {
79 common_element('a', array('href' => $profile->homepage),
82 common_text($profile->fullname);
84 common_element_end('div');
86 if ($profile->location) {
87 common_element('div', 'location', $profile->location);
90 common_element('div', 'bio', $profile->bio);
93 common_element_start('form', array('method' => 'post',
96 'action' => $this->self_url()));
97 common_hidden('token', common_session_token());
98 common_hidden('id', $profile->id);
99 common_input('tags', _('Tags'),
100 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $profile->id)),
101 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
103 common_submit('save', _('Save'));
104 common_element_end('form');
105 common_show_footer();
112 $id = $this->trimmed('id');
113 $tagstring = $this->trimmed('tags');
114 $token = $this->trimmed('token');
116 if (!$token || $token != common_session_token()) {
117 $this->show_form(_('There was a problem with your session token. Try again, please.'));
121 $profile = Profile::staticGet('id', $id);
124 $this->client_error(_('No such profile.'));
128 if (is_string($tagstring) && strlen($tagstring) > 0) {
130 $tags = array_map('common_canonical_tag',
131 preg_split('/[\s,]+/', $tagstring));
133 foreach ($tags as $tag) {
134 if (!common_valid_profile_tag($tag)) {
135 $this->show_form($profile, sprintf(_('Invalid tag: "%s"'), $tag));
143 $user = common_current_user();
145 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
146 'subscribed' => $profile->id)) &&
147 !Subscription::pkeyGet(array('subscriber' => $profile->id,
148 'subscribed' => $user->id)))
150 $this->client_error(_('You can only tag people you are subscribed to or who are subscribed to you.'));
154 $result = Profile_tag::setTags($user->id, $profile->id, $tags);
157 $this->client_error(_('Could not save tags.'));
161 $action = $user->isSubscribed($profile) ? 'subscriptions' : 'subscribers';
163 if ($this->boolean('ajax')) {
164 common_start_html('text/xml');
165 common_element_start('head');
166 common_element('title', null, _('Tags'));
167 common_element_end('head');
168 common_element_start('body');
169 common_element_start('p', 'subtags');
170 foreach ($tags as $tag) {
171 common_element('a', array('href' => common_local_url($action,
172 array('nickname' => $user->nickname,
176 common_element_end('p');
177 common_element_end('body');
178 common_element_end('html');
180 common_redirect(common_local_url($action, array('nickname' =>
185 function show_top($arr = null)
187 list($profile, $error) = $arr;
189 common_element('p', 'error', $error);
191 common_element_start('div', 'instructions');
192 common_element('p', null,
193 _('Use this form to add tags to your subscribers or subscriptions.'));
194 common_element_end('div');