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 $this->elementStart('div', 'entity_profile vcard author');
77 $this->element('h2', null, _('User profile'));
79 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
80 $this->elementStart('dl', 'entity_depiction');
81 $this->element('dt', null, _('Photo'));
82 $this->elementStart('dd');
83 $this->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_PROFILE_SIZE),
84 'class' => 'photo avatar',
85 'width' => AVATAR_PROFILE_SIZE,
86 'height' => AVATAR_PROFILE_SIZE,
88 ($this->profile->fullname) ? $this->profile->fullname :
89 $this->profile->nickname));
90 $this->elementEnd('dd');
91 $this->elementEnd('dl');
94 $this->elementStart('dl', 'entity_nickname');
95 $this->element('dt', null, _('Nickname'));
96 $this->elementStart('dd');
97 $this->element('a', array('href' => $this->profile->profileurl,
98 'class' => 'nickname'),
99 $this->profile->nickname);
100 $this->elementEnd('dd');
101 $this->elementEnd('dl');
103 if ($this->profile->fullname) {
104 $this->elementStart('dl', 'entity_fn');
105 $this->element('dt', null, _('Full name'));
106 $this->elementStart('dd');
107 $this->element('span', 'fn', $this->profile->fullname);
108 $this->elementEnd('dd');
109 $this->elementEnd('dl');
111 if ($this->profile->location) {
112 $this->elementStart('dl', 'entity_location');
113 $this->element('dt', null, _('Location'));
114 $this->element('dd', 'location', $this->profile->location);
115 $this->elementEnd('dl');
117 if ($this->profile->homepage) {
118 $this->elementStart('dl', 'entity_url');
119 $this->element('dt', null, _('URL'));
120 $this->elementStart('dd');
121 $this->element('a', array('href' => $this->profile->homepage,
122 'rel' => 'me', 'class' => 'url'),
123 $this->profile->homepage);
124 $this->elementEnd('dd');
125 $this->elementEnd('dl');
127 if ($this->profile->bio) {
128 $this->elementStart('dl', 'entity_note');
129 $this->element('dt', null, _('Note'));
130 $this->element('dd', 'note', $this->profile->bio);
131 $this->elementEnd('dl');
133 $this->elementEnd('div');
135 $this->elementStart('form', array('method' => 'post',
136 'id' => 'form_tag_user',
137 'class' => 'form_settings',
138 'name' => 'tagother',
139 'action' => $this->selfUrl()));
140 $this->elementStart('fieldset');
141 $this->element('legend', null, _('Tag user'));
142 $this->hidden('token', common_session_token());
143 $this->hidden('id', $this->profile->id);
145 $this->elementStart('ul', 'form_data');
146 $this->elementStart('li');
147 $this->input('tags', _('Tags'),
148 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
149 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
150 $this->elementEnd('li');
151 $this->elementEnd('ul');
152 $this->submit('save', _('Save'));
153 $this->elementEnd('fieldset');
154 $this->elementEnd('form');
159 $id = $this->trimmed('id');
160 $tagstring = $this->trimmed('tags');
161 $token = $this->trimmed('token');
163 if (!$token || $token != common_session_token()) {
164 $this->showForm(_('There was a problem with your session token.'.
165 ' Try again, please.'));
169 if (is_string($tagstring) && strlen($tagstring) > 0) {
171 $tags = array_map('common_canonical_tag',
172 preg_split('/[\s,]+/', $tagstring));
174 foreach ($tags as $tag) {
175 if (!common_valid_profile_tag($tag)) {
176 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
184 $user = common_current_user();
186 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
187 'subscribed' => $this->profile->id)) &&
188 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
189 'subscribed' => $user->id)))
191 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
195 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
198 $this->clientError(_('Could not save tags.'));
202 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
204 if ($this->boolean('ajax')) {
205 $this->startHTML('text/xml');
206 $this->elementStart('head');
207 $this->element('title', null, _('Tags'));
208 $this->elementEnd('head');
209 $this->elementStart('body');
210 $this->elementStart('p', 'subtags');
211 foreach ($tags as $tag) {
212 $this->element('a', array('href' => common_local_url($action,
213 array('nickname' => $user->nickname,
217 $this->elementEnd('p');
218 $this->elementEnd('body');
219 $this->elementEnd('html');
221 common_redirect(common_local_url($action, array('nickname' =>
226 function showPageNotice()
229 $this->element('p', 'error', $this->error);
231 $this->elementStart('div', 'instructions');
232 $this->element('p', null,
233 _('Use this form to add tags to your subscribers or subscriptions.'));
234 $this->elementEnd('div');