]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/tagother.php
Update translator documentation.
[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 // @todo FIXME: documentation missing.
25 class TagotherAction extends Action
26 {
27     var $profile = null;
28     var $error = null;
29
30     function prepare($args)
31     {
32         parent::prepare($args);
33         if (!common_logged_in()) {
34             // TRANS: Client error displayed on user tag page when trying to add tags while not logged in.
35             $this->clientError(_('Not logged in.'), 403);
36             return false;
37         }
38
39         $id = $this->trimmed('id');
40         if (!$id) {
41             // TRANS: Client error displayed on user tag page when trying to add tags without providing a user ID.
42             $this->clientError(_('No ID argument.'));
43             return false;
44         }
45
46         $this->profile = Profile::staticGet('id', $id);
47
48         if (!$this->profile) {
49             // TRANS: Client error displayed on user tag page when trying to add tags providing a non-existing user ID.
50             $this->clientError(_('No profile with that ID.'));
51             return false;
52         }
53
54         return true;
55     }
56
57     function handle($args)
58     {
59         parent::handle($args);
60         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
61             $this->saveTags();
62         } else {
63             $this->showForm($profile);
64         }
65     }
66
67     function title()
68     {
69         // TRANS: Title for "tag other users" page.
70         // TRANS: %s is the user nickname.
71         return sprintf(_('Tag %s'), $this->profile->nickname);
72     }
73
74     function showForm($error=null)
75     {
76         $this->error = $error;
77         $this->showPage();
78     }
79
80     function showContent()
81     {
82         $this->elementStart('div', 'entity_profile vcard author');
83         // TRANS: Header for user details on "tag other users" page.
84         $this->element('h2', null, _('User profile'));
85
86         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
87         $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
88                                     'class' => 'photo avatar entity_depiction',
89                                     'width' => AVATAR_PROFILE_SIZE,
90                                     'height' => AVATAR_PROFILE_SIZE,
91                                     'alt' =>
92                                     ($this->profile->fullname) ? $this->profile->fullname :
93                                     $this->profile->nickname));
94
95         $this->element('a', array('href' => $this->profile->profileurl,
96                                   'class' => 'entity_nickname nickname'),
97                        $this->profile->nickname);
98
99         if ($this->profile->fullname) {
100             $this->element('div', 'fn entity_fn', $this->profile->fullname);
101         }
102
103         if ($this->profile->location) {
104             $this->element('div', 'label entity_location', $this->profile->location);
105         }
106
107         if ($this->profile->homepage) {
108             $this->element('a', array('href' => $this->profile->homepage,
109                                       'rel' => 'me',
110                                       'class' => 'url entity_url'),
111                            $this->profile->homepage);
112         }
113
114         if ($this->profile->bio) {
115             $this->element('div', 'note entity_note', $this->profile->bio);
116         }
117
118         $this->elementEnd('div');
119
120         $this->elementStart('form', array('method' => 'post',
121                                            'id' => 'form_tag_user',
122                                            'class' => 'form_settings',
123                                            'name' => 'tagother',
124                                            'action' => common_local_url('tagother', array('id' => $this->profile->id))));
125
126         $this->elementStart('fieldset');
127         // TRANS: Fieldset legend on "tag other users" page.
128         $this->element('legend', null, _('Tag user'));
129         $this->hidden('token', common_session_token());
130         $this->hidden('id', $this->profile->id);
131
132         $user = common_current_user();
133
134         $this->elementStart('ul', 'form_data');
135         $this->elementStart('li');
136         // TRANS: Field label for inputting tags on "tag other users" page.
137         $this->input('tags', _('Tags'),
138                      ($this->arg('tags')) ? $this->arg('tags') : implode(' ', Profile_tag::getTags($user->id, $this->profile->id)),
139                      // TRANS: Title for input field for inputting tags on "tag other users" page.
140                      _('Tags for this user (letters, numbers, -, ., and _), separated by commas or spaces.'));
141         $this->elementEnd('li');
142         $this->elementEnd('ul');
143         // TRANS: Button text for saving tags for other users.
144         $this->submit('save', _m('BUTTON','Save'));
145         $this->elementEnd('fieldset');
146         $this->elementEnd('form');
147     }
148
149     function saveTags()
150     {
151         $id = $this->trimmed('id');
152         $tagstring = $this->trimmed('tags');
153         $token = $this->trimmed('token');
154
155         if (!$token || $token != common_session_token()) {
156             $this->showForm(_('There was a problem with your session token. '.
157                               'Try again, please.'));
158             return;
159         }
160
161         if (is_string($tagstring) && strlen($tagstring) > 0) {
162
163             $tags = array_map('common_canonical_tag',
164                               preg_split('/[\s,]+/', $tagstring));
165
166             foreach ($tags as $tag) {
167                 if (!common_valid_profile_tag($tag)) {
168                     // TRANS: Form validation error when entering an invalid tag.
169                     // TRANS: %s is the invalid tag.
170                     $this->showForm(sprintf(_('Invalid tag: "%s".'), $tag));
171                     return;
172                 }
173             }
174         } else {
175             $tags = array();
176         }
177
178         $user = common_current_user();
179
180         if (!Subscription::pkeyGet(array('subscriber' => $user->id,
181                                          'subscribed' => $this->profile->id)) &&
182             !Subscription::pkeyGet(array('subscriber' => $this->profile->id,
183                                          'subscribed' => $user->id)))
184         {
185             // TRANS: Client error on "tag other users" page when tagging a user is not possible because of missing mutual subscriptions.
186             $this->clientError(_('You can only tag people you are subscribed to or who are subscribed to you.'));
187             return;
188         }
189
190         $result = Profile_tag::setTags($user->id, $this->profile->id, $tags);
191
192         if (!$result) {
193             // TRANS: Client error on "tag other users" page when saving tags fails server side.
194             $this->clientError(_('Could not save tags.'));
195             return;
196         }
197
198         $action = $user->isSubscribed($this->profile) ? 'subscriptions' : 'subscribers';
199
200         if ($this->boolean('ajax')) {
201             $this->startHTML('text/xml;charset=utf-8');
202             $this->elementStart('head');
203             // TRANS: Title of "tag other users" page.
204             $this->element('title', null, _m('TITLE','Tags'));
205             $this->elementEnd('head');
206             $this->elementStart('body');
207             $this->elementStart('p', 'subtags');
208             foreach ($tags as $tag) {
209                 $this->element('a', array('href' => common_local_url($action,
210                                                                      array('nickname' => $user->nickname,
211                                                                            'tag' => $tag))),
212                                $tag);
213             }
214             $this->elementEnd('p');
215             $this->elementEnd('body');
216             $this->elementEnd('html');
217         } else {
218             common_redirect(common_local_url($action, array('nickname' =>
219                                                             $user->nickname)),
220                             303);
221         }
222     }
223
224     function showPageNotice()
225     {
226         if ($this->error) {
227             $this->element('p', 'error', $this->error);
228         } else {
229             $this->elementStart('div', 'instructions');
230             $this->element('p', null,
231                            // TRANS: Page notice on "tag other users" page.
232                            _('Use this form to add tags to your subscribers or subscriptions.'));
233             $this->elementEnd('div');
234         }
235     }
236 }