]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsbyuser.php
Merge remote-tracking branch 'statusnet/master'
[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             return false;
96         }
97
98         $this->user = User::staticGet('nickname', $nickname);
99
100         if (!$this->user) {
101             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
102             $this->clientError(_('No such user.'), 404);
103             return false;
104         }
105
106         $this->tagger = $this->user->getProfile();
107
108         if (!$this->tagger) {
109             // TRANS: Error message displayed when referring to a user without a profile.
110             $this->serverError(_('User has no profile.'));
111             return false;
112         }
113
114         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
115
116
117         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
118         $limit  = PEOPLETAGS_PER_PAGE + 1;
119
120         $user = common_current_user();
121         if ($this->arg('public')) {
122             $this->tags = $this->tagger->getLists(false, $offset, $limit);
123         } else if ($this->arg('private')) {
124             if (empty($user)) {
125                 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
126                 $this->clientError(_('Not logged in.'), 403);
127             }
128
129             if ($this->isOwner()) {
130                 $this->tags = $this->tagger->getPrivateTags($offset, $limit);
131             } else {
132                 // TRANS: Client error displayed when trying view another user's private lists.
133                 $this->clientError(_('You cannot view others\' private lists'), 403);
134             }
135         } else {
136             $this->tags = $this->tagger->getLists(common_current_user(), $offset, $limit);
137         }
138         return true;
139     }
140
141     function handle($args)
142     {
143         parent::handle($args);
144
145                 # Post from the tag dropdown; redirect to a GET
146
147                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
148                     common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
149             return;
150                 }
151
152         $this->showPage();
153     }
154
155     function showModeSelector()
156     {
157         $this->elementStart('dl', array('id'=>'filter_tags'));
158         // TRANS: Mode selector label.
159         $this->element('dt', null, _('Mode'));
160         $this->elementStart('dd');
161         $this->elementStart('ul');
162         $this->elementStart('li', array('id' => 'filter_tags_for',
163                                          'class' => 'child_1'));
164         $this->element('a',
165                        array('href' =>
166                              common_local_url('peopletagsforuser',
167                                               array('nickname' => $this->user->nickname))),
168                        // TRANS: Link text to show lists for user %s.
169                        sprintf(_('Lists for %s'), $this->tagger->nickname));
170         $this->elementEnd('li');
171
172         if ($this->isOwner()) {
173             $this->elementStart('li', array('id'=>'filter_tags_item'));
174             $this->elementStart('form', array('name' => 'modeselector',
175                                                'id' => 'form_filter_bymode',
176                                                'action' => common_local_url('peopletagsbyuser',
177                                                     array('nickname' => $this->tagger->nickname)),
178                                                'method' => 'post'));
179             $this->elementStart('fieldset');
180             // TRANS: Fieldset legend.
181             $this->element('legend', null, _('Select tag to filter'));
182
183             $priv = $this->arg('private');
184             $pub  = $this->arg('public');
185
186             if (!$priv && !$pub) {
187                 $priv = $pub = true;
188             }
189             // TRANS: Checkbox label to show private tags.
190             $this->checkbox('private', _m('LABEL','Private'), $priv,
191                                 // TRANS: Checkbox title.
192                                 _('Show private tags.'));
193             // TRANS: Checkbox label to show public tags.
194             $this->checkbox('public', _m('LABEL','Public'), $pub,
195                                 // TRANS: Checkbox title.
196                                 _('Show public tags.'));
197             $this->hidden('nickname', $this->user->nickname);
198             // TRANS: Submit button text for tag filter form.
199             $this->submit('submit', _m('BUTTON','Go'));
200             $this->elementEnd('fieldset');
201             $this->elementEnd('form');
202             $this->elementEnd('li');
203         }
204         $this->elementEnd('ul');
205         $this->elementEnd('dd');
206         $this->elementEnd('dl');
207     }
208
209     function showAnonymousMessage()
210     {
211         $notice =
212           // TRANS: Message displayed for anonymous users on page that displays lists by a user.
213           // TRANS: This message contains Markdown links in the form [description](links).
214           // TRANS: %s is a tagger nickname.
215           sprintf(_('These are lists created by **%s**. ' .
216                     'Lists are how you sort similar ' .
217                     'people on %%%%site.name%%%%, a [micro-blogging]' .
218                     '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
219                     'based on the Free Software [StatusNet](http://status.net/) tool. ' .
220                     'You can easily keep track of what they ' .
221                     'are doing by subscribing to the list\'s timeline.' ), $this->tagger->nickname);
222         $this->elementStart('div', array('id' => 'anon_notice'));
223         $this->raw(common_markup_to_html($notice));
224         $this->elementEnd('div');
225     }
226
227     function showPageNotice()
228     {
229         $this->elementStart('div', 'instructions');
230         $this->showModeSelector();
231         $this->elementEnd('div');
232     }
233
234     function showContent()
235     {
236         #TODO: controls here.
237
238         $pl = new PeopletagList($this->tags, $this);
239         $cnt = $pl->show();
240
241         if ($cnt == 0) {
242             $this->showEmptyListMessage();
243         }
244         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
245                           $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
246     }
247
248     function getSelfUrlArgs()
249     {
250         $args = array();
251         if ($this->arg('private')) {
252             $args['private'] = 1;
253         } else if ($this->arg('public')) {
254             $args['public'] = 1;
255         }
256         $args['nickname'] = $this->trimmed('nickname');
257
258         return $args;
259     }
260
261     function isOwner()
262     {
263         $user = common_current_user();
264         return !empty($user) && $user->id == $this->tagger->id;
265     }
266
267     function showObjectNav()
268     {
269         $nav = new PeopletagNav($this, $this->tagger);
270         $nav->show();
271     }
272
273     function showEmptyListMessage()
274     {
275           // TRANS: Message displayed on page that displays lists by a user when there are none.
276           // TRANS: This message contains Markdown links in the form [description](links).
277           // TRANS: %s is a tagger nickname.
278         $message = sprintf(_('%s has not created any [lists](%%%%doc.lists%%%%) yet.'), $this->tagger->nickname);
279         $this->elementStart('div', 'guide');
280         $this->raw(common_markup_to_html($message));
281         $this->elementEnd('div');
282     }
283
284     function showProfileBlock()
285     {
286         $block = new AccountProfileBlock($this, $this->tagger);
287         $block->show();
288     }
289
290     function showSections()
291     {
292         #TODO: tags with most subscribers
293         #TODO: tags with most "members"
294     }
295 }