]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tagother.php
Localisation updates for !StatusNet from !translatewiki.net !sntrans
[quix0rs-gnu-social.git] / actions / tagother.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class TagotherAction extends Action
25 {
26     var $profile = null;
27     var $error = null;
28
29     function prepare($args)
30     {
31         parent::prepare($args);
32         if (!common_logged_in()) {
33             $this->clientError(_('Not logged in'), 403);
34             return false;
35         }
36
37         $id = $this->trimmed('id');
38         if (!$id) {
39             $this->clientError(_('No id argument.'));
40             return false;
41         }
42
43         $this->profile = Profile::staticGet('id', $id);
44
45         if (!$this->profile) {
46             $this->clientError(_('No profile with that ID.'));
47             return false;
48         }
49
50         return true;
51     }
52
53     function handle($args)
54     {
55         parent::handle($args);
56         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
57             $this->saveTags();
58         } else {
59             $this->showForm($profile);
60         }
61     }
62
63     function title()
64     {
65         return sprintf(_('Tag %s'), $this->profile->nickname);
66     }
67
68     function showForm($error=null)
69     {
70         $this->error = $error;
71         $this->showPage();
72     }
73
74     function showContent()
75     {
76         $this->elementStart('div', 'entity_profile vcard author');
77         $this->element('h2', null, _('User profile'));
78
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,
87                                     'alt' =>
88                                     ($this->profile->fullname) ? $this->profile->fullname :
89                                     $this->profile->nickname));
90         $this->elementEnd('dd');
91         $this->elementEnd('dl');
92
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');
101
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');
109         }
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');
115         }
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');
125         }
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');
131         }
132         $this->elementEnd('div');
133
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))));
139
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);
144
145         $user = common_current_user();
146
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');
157     }
158
159     function saveTags()
160     {
161         $id = $this->trimmed('id');
162         $tagstring = $this->trimmed('tags');
163         $token = $this->trimmed('token');
164
165         if (!$token || $token != common_session_token()) {
166             $this->showForm(_('There was a problem with your session token.'.
167                               ' Try again, please.'));
168             return;
169         }
170
171         if (is_string($tagstring) && strlen($tagstring) > 0) {
172
173             $tags = array_map('common_canonical_tag',
174                               preg_split('/[\s,]+/', $tagstring));
175
176             foreach ($tags as $tag) {
177                 if (!common_valid_profile_tag($tag)) {
178                     $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
179                     return;
180                 }
181             }
182         } else {
183             $tags = array();
184         }
185
186         $user = common_current_user();
187
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)))
192         {
193             $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
194             return;
195         }
196
197         $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
198
199         if (!$result) {
200             $this->clientError(_('Could not save tags.'));
201             return;
202         }
203
204         $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
205
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,
216                                                                            'tag' => $tag))),
217                                $tag);
218             }
219             $this->elementEnd('p');
220             $this->elementEnd('body');
221             $this->elementEnd('html');
222         } else {
223             common_redirect(common_local_url($action, array('nickname' =>
224                                                             $user->nickname)),
225                             303);
226         }
227     }
228
229     function showPageNotice()
230     {
231         if ($this->error) {
232             $this->element('p', 'error', $this->error);
233         } else {
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');
238         }
239     }
240 }
241