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
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 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
78 $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
79 'class' => 'avatar stream',
80 'width' => AVATAR_PROFILE_SIZE,
81 'height' => AVATAR_PROFILE_SIZE,
83 ($this->profile->fullname) ? $this->profile->fullname :
84 $this->profile->nickname));
86 $this->element('a', array('href' => $this->profile->profileurl,
87 'class' => 'external profile nickname'),
88 $this->profile->nickname);
90 if ($this->profile->fullname) {
91 $this->elementStart('div', 'fullname');
92 if ($this->profile->homepage) {
93 $this->element('a', array('href' => $this->profile->homepage),
94 $this->profile->fullname);
96 $this->text($this->profile->fullname);
98 $this->elementEnd('div');
100 if ($this->profile->location) {
101 $this->element('div', 'location', $this->profile->location);
103 if ($this->profile->bio) {
104 $this->element('div', 'bio', $this->profile->bio);
107 $this->elementStart('form', array('method' => 'post',
109 'name' => 'tagother',
110 'action' => $this->selfUrl()));
111 $this->hidden('token', common_session_token());
112 $this->hidden('id', $this->profile->id);
113 $this->input('tags', _('Tags'),
114 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
115 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
117 $this->submit('save', _('Save'));
118 $this->elementEnd('form');
123 $id = $this->trimmed('id');
124 $tagstring = $this->trimmed('tags');
125 $token = $this->trimmed('token');
127 if (!$token || $token != common_session_token()) {
128 $this->showForm(_('There was a problem with your session token.'.
129 ' Try again, please.'));
133 if (is_string($tagstring) && strlen($tagstring) > 0) {
135 $tags = array_map('common_canonical_tag',
136 preg_split('/[\s,]+/', $tagstring));
138 foreach ($tags as $tag) {
139 if (!common_valid_profile_tag($tag)) {
140 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
148 $user = common_current_user();
150 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
151 'subscribed' => $this->profile->id)) &&
152 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
153 'subscribed' => $user->id)))
155 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
159 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
162 $this->clientError(_('Could not save tags.'));
166 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
168 if ($this->boolean('ajax')) {
169 common_start_html('text/xml');
170 $this->elementStart('head');
171 $this->element('title', null, _('Tags'));
172 $this->elementEnd('head');
173 $this->elementStart('body');
174 $this->elementStart('p', 'subtags');
175 foreach ($tags as $tag) {
176 $this->element('a', array('href' => common_local_url($action,
177 array('nickname' => $user->nickname,
181 $this->elementEnd('p');
182 $this->elementEnd('body');
183 $this->elementEnd('html');
185 common_redirect(common_local_url($action, array('nickname' =>
190 function showPageNotice()
193 $this->element('p', 'error', $this->error);
195 $this->elementStart('div', 'instructions');
196 $this->element('p', null,
197 _('Use this form to add tags to your subscribers or subscriptions.'));
198 $this->elementEnd('div');