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 {
26 function handle($args) {
28 parent::handle($args);
30 if (!common_logged_in()) {
31 $this->client_error(_('Not logged in'), 403);
35 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
38 $id = $this->trimmed('id');
40 $this->client_error(_('No id argument.'));
43 $profile = Profile::staticGet('id', $id);
45 $this->client_error(_('No profile with that ID.'));
48 $this->show_form($profile);
52 function show_form($profile, $error=null) {
54 $user = common_current_user();
56 common_show_header(_('Tag a person'),
57 null, array($profile, $error), array($this, 'show_top'));
59 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
61 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
62 'class' => 'avatar stream',
63 'width' => AVATAR_PROFILE_SIZE,
64 'height' => AVATAR_PROFILE_SIZE,
66 ($profile->fullname) ? $profile->fullname :
69 common_element('a', array('href' => $profile->profileurl,
70 'class' => 'external profile nickname'),
73 if ($profile->fullname) {
74 common_element_start('div', 'fullname');
75 if ($profile->homepage) {
76 common_element('a', array('href' => $profile->homepage),
79 common_text($profile->fullname);
81 common_element_end('div');
83 if ($profile->location) {
84 common_element('div', 'location', $profile->location);
87 common_element('div', 'bio', $profile->bio);
90 common_element_start('form', array('method' => 'post',
93 'action' => $this->self_url()));
94 common_hidden('token', common_session_token());
95 common_hidden('id', $profile->id);
96 common_input('tags', _('Tags'),
97 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $profile->id)),
98 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
100 common_submit('save', _('Save'));
101 common_element_end('form');
102 common_show_footer();
106 function save_tags() {
108 $id = $this->trimmed('id');
109 $tagstring = $this->trimmed('tags');
110 $token = $this->trimmed('token');
112 if (!$token || $token != common_session_token()) {
113 $this->show_form(_('There was a problem with your session token. Try again, please.'));
117 $profile = Profile::staticGet('id', $id);
120 $this->client_error(_('No such profile.'));
124 if (is_string($tagstring) && strlen($tagstring) > 0) {
126 $tags = array_map('common_canonical_tag',
127 preg_split('/[\s,]+/', $tagstring));
129 foreach ($tags as $tag) {
130 if (!common_valid_profile_tag($tag)) {
131 $this->show_form($profile, sprintf(_('Invalid tag: "%s"'), $tag));
139 $user = common_current_user();
141 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
142 'subscribed' => $profile->id)) &&
143 !Subscription::pkeyGet(array('subscriber' => $profile->id,
144 'subscribed' => $user->id)))
146 $this->client_error(_('You can only tag people you are subscribed to or who are subscribed to you.'));
150 $result = Profile_tag::setTags($user->id, $profile->id, $tags);
153 $this->client_error(_('Could not save tags.'));
157 $action = $user->isSubscribed($profile) ? 'subscriptions' : 'subscribers';
159 if ($this->boolean('ajax')) {
160 common_start_html('text/xml');
161 common_element_start('head');
162 common_element('title', null, _('Tags'));
163 common_element_end('head');
164 common_element_start('body');
165 common_element_start('p', 'subtags');
166 foreach ($tags as $tag) {
167 common_element('a', array('href' => common_local_url($action,
168 array('nickname' => $user->nickname,
172 common_element_end('p');
173 common_element_end('body');
174 common_element_end('html');
176 common_redirect(common_local_url($action, array('nickname' =>
181 function show_top($arr = null) {
182 list($profile, $error) = $arr;
184 common_element('p', 'error', $error);
186 common_element_start('div', 'instructions');
187 common_element('p', null,
188 _('Use this form to add tags to your subscribers or subscriptions.'));
189 common_element_end('div');