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) ? $avatar->displayUrl() : Avatar::defaultImage(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');
93 $this->elementStart('dl', 'entity_nickname');
94 $this->element('dt', null, _('Nickname'));
95 $this->elementStart('dd');
96 $this->element('a', array('href' => $this->profile->profileurl,
97 'class' => 'nickname'),
98 $this->profile->nickname);
99 $this->elementEnd('dd');
100 $this->elementEnd('dl');
102 if ($this->profile->fullname) {
103 $this->elementStart('dl', 'entity_fn');
104 $this->element('dt', null, _('Full name'));
105 $this->elementStart('dd');
106 $this->element('span', 'fn', $this->profile->fullname);
107 $this->elementEnd('dd');
108 $this->elementEnd('dl');
110 if ($this->profile->location) {
111 $this->elementStart('dl', 'entity_location');
112 $this->element('dt', null, _('Location'));
113 $this->element('dd', 'label', $this->profile->location);
114 $this->elementEnd('dl');
116 if ($this->profile->homepage) {
117 $this->elementStart('dl', 'entity_url');
118 $this->element('dt', null, _('URL'));
119 $this->elementStart('dd');
120 $this->element('a', array('href' => $this->profile->homepage,
121 'rel' => 'me', 'class' => 'url'),
122 $this->profile->homepage);
123 $this->elementEnd('dd');
124 $this->elementEnd('dl');
126 if ($this->profile->bio) {
127 $this->elementStart('dl', 'entity_note');
128 $this->element('dt', null, _('Note'));
129 $this->element('dd', 'note', $this->profile->bio);
130 $this->elementEnd('dl');
132 $this->elementEnd('div');
134 $this->elementStart('form', array('method' => 'post',
135 'id' => 'form_tag_user',
136 'class' => 'form_settings',
137 'name' => 'tagother',
138 'action' => common_local_url('tagother', array('id' => $this->profile->id))));
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 $user = common_current_user();
147 $this->elementStart('ul', 'form_data');
148 $this->elementStart('li');
149 $this->input('tags', _('Tags'),
150 ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
151 _('Tags for this user (letters, numbers, -, ., and _), comma- or space- separated'));
152 $this->elementEnd('li');
153 $this->elementEnd('ul');
154 $this->submit('save', _('Save'));
155 $this->elementEnd('fieldset');
156 $this->elementEnd('form');
161 $id = $this->trimmed('id');
162 $tagstring = $this->trimmed('tags');
163 $token = $this->trimmed('token');
165 if (!$token || $token != common_session_token()) {
166 $this->showForm(_('There was a problem with your session token.'.
167 ' Try again, please.'));
171 if (is_string($tagstring) && strlen($tagstring) > 0) {
173 $tags = array_map('common_canonical_tag',
174 preg_split('/[\s,]+/', $tagstring));
176 foreach ($tags as $tag) {
177 if (!common_valid_profile_tag($tag)) {
178 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
186 $user = common_current_user();
188 if (!Subscription::pkeyGet(array('subscriber' => $user->id,
189 'subscribed' => $this->profile->id)) &&
190 !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
191 'subscribed' => $user->id)))
193 $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
197 $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
200 $this->clientError(_('Could not save tags.'));
204 $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
206 if ($this->boolean('ajax')) {
207 $this->startHTML('text/xml;charset=utf-8');
208 $this->elementStart('head');
209 $this->element('title', null, _('Tags'));
210 $this->elementEnd('head');
211 $this->elementStart('body');
212 $this->elementStart('p', 'subtags');
213 foreach ($tags as $tag) {
214 $this->element('a', array('href' => common_local_url($action,
215 array('nickname' => $user->nickname,
219 $this->elementEnd('p');
220 $this->elementEnd('body');
221 $this->elementEnd('html');
223 common_redirect(common_local_url($action, array('nickname' =>
229 function showPageNotice()
232 $this->element('p', 'error', $this->error);
234 $this->elementStart('div', 'instructions');
235 $this->element('p', null,
236 _('Use this form to add tags to your subscribers or subscriptions.'));
237 $this->elementEnd('div');