]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsbyuser.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / actions / peopletagsbyuser.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Lists by a user
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Shashi Gowda <connect2shashi@gmail.com>
25  * @copyright 2008-2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/peopletaglist.php';
35
36 class PeopletagsbyuserAction extends Action
37 {
38     var $page = null;
39     var $tagger = null;
40     var $tags = null;
41
42     function isReadOnly($args)
43     {
44         return true;
45     }
46
47     function title()
48     {
49         if ($this->page == 1) {
50             if ($this->isOwner()) {
51                 if ($this->arg('private')) {
52                     // TRANS: Title for lists by a user page for a private tag.
53                     return _('Private lists by you');
54                 } else if ($this->arg('public')) {
55                     // TRANS: Title for lists by a user page for a public tag.
56                     return _('Public lists by you');
57                 }
58                 // TRANS: Title for lists by a user page.
59                 return _('Lists by you');
60             }
61             // TRANS: Title for lists by a user page.
62             // TRANS: %s is a user nickname.
63             return sprintf(_('Lists by %s'), $this->tagger->nickname);
64         } else {
65             // TRANS: Title for lists by a user page.
66             // TRANS: %1$s is a user nickname, %2$d is a page number.
67             return sprintf(_('Lists by %1$s, page %2$d'), $this->tagger->nickname, $this->page);
68         }
69     }
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74
75         if ($this->arg('public') && $this->arg('private')) {
76             $this->args['public'] = $this->args['private'] = false;
77         }
78
79         if (common_config('singleuser', 'enabled')) {
80             $nickname_arg = User::singleUserNickname();
81         } else {
82             $nickname_arg = $this->arg('nickname');
83         }
84
85         $nickname = common_canonical_nickname($nickname_arg);
86
87         // Permanent redirect on non-canonical nickname
88
89         if ($nickname_arg != $nickname) {
90             $args = $this->getSelfUrlArgs();
91             if ($this->arg('page') && $this->arg('page') != 1) {
92                 $args['page'] = $this->arg['page'];
93             }
94             common_redirect(common_local_url('peopletagsbyuser', $args), 301);
95         }
96
97         $this->user = User::getKV('nickname', $nickname);
98
99         if (!$this->user) {
100             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
101             $this->clientError(_('No such user.'), 404);
102         }
103
104         $this->tagger = $this->user->getProfile();
105
106         if (!$this->tagger) {
107             // TRANS: Error message displayed when referring to a user without a profile.
108             $this->serverError(_('User has no profile.'));
109         }
110
111         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
112
113
114         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
115         $limit  = PEOPLETAGS_PER_PAGE + 1;
116
117         $user = common_current_user();
118         if ($this->arg('public')) {
119             $this->tags = $this->tagger->getLists(false, $offset, $limit);
120         } else if ($this->arg('private')) {
121             if (empty($user)) {
122                 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
123                 $this->clientError(_('Not logged in.'), 403);
124             }
125
126             if ($this->isOwner()) {
127                 $this->tags = $this->tagger->getPrivateTags($offset, $limit);
128             } else {
129                 // TRANS: Client error displayed when trying view another user's private lists.
130                 $this->clientError(_('You cannot view others\' private lists'), 403);
131             }
132         } else {
133             $this->tags = $this->tagger->getLists(common_current_user(), $offset, $limit);
134         }
135         return true;
136     }
137
138     function handle($args)
139     {
140         parent::handle($args);
141
142                 # Post from the tag dropdown; redirect to a GET
143
144                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
145                     common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
146                 }
147
148         $this->showPage();
149     }
150
151     function showModeSelector()
152     {
153         $this->elementStart('dl', array('id'=>'filter_tags'));
154         // TRANS: Mode selector label.
155         $this->element('dt', null, _('Mode'));
156         $this->elementStart('dd');
157         $this->elementStart('ul');
158         $this->elementStart('li', array('id' => 'filter_tags_for',
159                                          'class' => 'child_1'));
160         $this->element('a',
161                        array('href' =>
162                              common_local_url('peopletagsforuser',
163                                               array('nickname' => $this->user->nickname))),
164                        // TRANS: Link text to show lists for user %s.
165                        sprintf(_('Lists for %s'), $this->tagger->nickname));
166         $this->elementEnd('li');
167
168         if ($this->isOwner()) {
169             $this->elementStart('li', array('id'=>'filter_tags_item'));
170             $this->elementStart('form', array('name' => 'modeselector',
171                                                'id' => 'form_filter_bymode',
172                                                'action' => common_local_url('peopletagsbyuser',
173                                                     array('nickname' => $this->tagger->nickname)),
174                                                'method' => 'post'));
175             $this->elementStart('fieldset');
176             // TRANS: Fieldset legend.
177             $this->element('legend', null, _('Select tag to filter'));
178
179             $priv = $this->arg('private');
180             $pub  = $this->arg('public');
181
182             if (!$priv && !$pub) {
183                 $priv = $pub = true;
184             }
185             // TRANS: Checkbox label to show private tags.
186             $this->checkbox('private', _m('LABEL','Private'), $priv,
187                                 // TRANS: Checkbox title.
188                                 _('Show private tags.'));
189             // TRANS: Checkbox label to show public tags.
190             $this->checkbox('public', _m('LABEL','Public'), $pub,
191                                 // TRANS: Checkbox title.
192                                 _('Show public tags.'));
193             $this->hidden('nickname', $this->user->nickname);
194             // TRANS: Submit button text for tag filter form.
195             $this->submit('submit', _m('BUTTON','Go'));
196             $this->elementEnd('fieldset');
197             $this->elementEnd('form');
198             $this->elementEnd('li');
199         }
200         $this->elementEnd('ul');
201         $this->elementEnd('dd');
202         $this->elementEnd('dl');
203     }
204
205     function showAnonymousMessage()
206     {
207         $notice =
208           // TRANS: Message displayed for anonymous users on page that displays lists by a user.
209           // TRANS: This message contains Markdown links in the form [description](links).
210           // TRANS: %s is a tagger nickname.
211           sprintf(_('These are lists created by **%s**. ' .
212                     'Lists are how you sort similar ' .
213                     'people on %%%%site.name%%%%, a [micro-blogging]' .
214                     '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
215                     'based on the Free Software [StatusNet](http://status.net/) tool. ' .
216                     'You can easily keep track of what they ' .
217                     'are doing by subscribing to the list\'s timeline.' ), $this->tagger->nickname);
218         $this->elementStart('div', array('id' => 'anon_notice'));
219         $this->raw(common_markup_to_html($notice));
220         $this->elementEnd('div');
221     }
222
223     function showPageNotice()
224     {
225         $this->elementStart('div', 'instructions');
226         $this->showModeSelector();
227         $this->elementEnd('div');
228     }
229
230     function showContent()
231     {
232         #TODO: controls here.
233
234         $pl = new PeopletagList($this->tags, $this);
235         $cnt = $pl->show();
236
237         if ($cnt == 0) {
238             $this->showEmptyListMessage();
239         }
240         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
241                           $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
242     }
243
244     function getSelfUrlArgs()
245     {
246         $args = array();
247         if ($this->arg('private')) {
248             $args['private'] = 1;
249         } else if ($this->arg('public')) {
250             $args['public'] = 1;
251         }
252         $args['nickname'] = $this->trimmed('nickname');
253
254         return $args;
255     }
256
257     function isOwner()
258     {
259         $user = common_current_user();
260         return !empty($user) && $user->id == $this->tagger->id;
261     }
262
263     function showObjectNav()
264     {
265         $nav = new PeopletagNav($this, $this->tagger);
266         $nav->show();
267     }
268
269     function showEmptyListMessage()
270     {
271           // TRANS: Message displayed on page that displays lists by a user when there are none.
272           // TRANS: This message contains Markdown links in the form [description](links).
273           // TRANS: %s is a tagger nickname.
274         $message = sprintf(_('%s has not created any [lists](%%%%doc.lists%%%%) yet.'), $this->tagger->nickname);
275         $this->elementStart('div', 'guide');
276         $this->raw(common_markup_to_html($message));
277         $this->elementEnd('div');
278     }
279
280     function showProfileBlock()
281     {
282         $block = new AccountProfileBlock($this, $this->tagger);
283         $block->show();
284     }
285
286     function showSections()
287     {
288         #TODO: tags with most subscribers
289         #TODO: tags with most "members"
290     }
291 }