]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/peopletagsbyuser.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / actions / peopletagsbyuser.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * People tags 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-2009 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 OwnerDesignAction
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                     return _('Private people tags by you');
53                 } else if ($this->arg('public')) {
54                     return _('Public people tags by you');
55                 }
56                 return _('People tags by you');
57             }
58             return sprintf(_("People tags by %s"), $this->tagger->nickname);
59         } else {
60             return sprintf(_("People tags by %s, page %d"), $this->tagger->nickname, $this->page);
61         }
62     }
63
64     function prepare($args)
65     {
66         parent::prepare($args);
67
68         if ($this->arg('public') && $this->arg('private')) {
69             $this->args['public'] = $this->args['private'] = false;
70         }
71
72         $nickname_arg = $this->arg('nickname');
73         $nickname = common_canonical_nickname($nickname_arg);
74
75         // Permanent redirect on non-canonical nickname
76
77         if ($nickname_arg != $nickname) {
78             $args = $this->getSelfUrlArgs();
79             if ($this->arg('page') && $this->arg('page') != 1) {
80                 $args['page'] = $this->arg['page'];
81             }
82             common_redirect(common_local_url('peopletagsbyuser', $args), 301);
83             return false;
84         }
85
86         $this->user = User::staticGet('nickname', $nickname);
87
88         if (!$this->user) {
89             $this->clientError(_('No such user.'), 404);
90             return false;
91         }
92
93         $this->tagger = $this->user->getProfile();
94
95         if (!$this->tagger) {
96             $this->serverError(_('User has no profile.'));
97             return false;
98         }
99
100         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
101
102
103         $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
104         $limit  = PEOPLETAGS_PER_PAGE + 1;
105
106         $user = common_current_user();
107         if ($this->arg('public')) {
108             $this->tags = $this->tagger->getOwnedTags(false, $offset, $limit);
109         } else if ($this->arg('private')) {
110             if (empty($user)) {
111                 $this->clientError(_('Not logged in'), 403);
112             }
113
114             if ($this->isOwner()) {
115                 $this->tags = $this->tagger->getPrivateTags($offset, $limit);
116             } else {
117                 $this->clientError(_('You cannot view others\' private people tags'), 403);
118             }
119         } else {
120             $this->tags = $this->tagger->getOwnedTags(common_current_user(), $offset, $limit);
121         }
122         return true;
123     }
124
125     function handle($args)
126     {
127         parent::handle($args);
128
129                 # Post from the tag dropdown; redirect to a GET
130
131                 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
132                     common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
133             return;
134                 }
135
136         $this->showPage();
137     }
138
139     function showModeSelector()
140     {
141         $this->elementStart('dl', array('id'=>'filter_tags'));
142         $this->element('dt', null, _('Mode'));
143         $this->elementStart('dd');
144         $this->elementStart('ul');
145         $this->elementStart('li', array('id' => 'filter_tags_for',
146                                          'class' => 'child_1'));
147         $this->element('a',
148                        array('href' =>
149                              common_local_url('peopletagsforuser',
150                                               array('nickname' => $this->user->nickname))),
151                        sprintf(_('People tags for %s'), $this->tagger->nickname));
152         $this->elementEnd('li');
153
154         if ($this->isOwner()) {
155             $this->elementStart('li', array('id'=>'filter_tags_item'));
156             $this->elementStart('form', array('name' => 'modeselector',
157                                                'id' => 'form_filter_bymode',
158                                                'action' => common_local_url('peopletagsbyuser',
159                                                     array('nickname' => $this->tagger->nickname)),
160                                                'method' => 'post'));
161             $this->elementStart('fieldset');
162             $this->element('legend', null, _('Select tag to filter'));
163
164             $priv = $this->arg('private');
165             $pub  = $this->arg('public');
166
167             if (!$priv && !$pub) {
168                 $priv = $pub = true;
169             }
170             $this->checkbox('private', _m('Private'), $priv,
171                                 _m('Show private tags'));
172             $this->checkbox('public', _m('Public'), $pub,
173                                 _m('Show public tags'));
174             $this->hidden('nickname', $this->user->nickname);
175             $this->submit('submit', _('Go'));
176             $this->elementEnd('fieldset');
177             $this->elementEnd('form');
178             $this->elementEnd('li');
179         }
180         $this->elementEnd('ul');
181         $this->elementEnd('dd');
182         $this->elementEnd('dl');
183     }
184
185     function showAnonymousMessage()
186     {
187         $notice =
188           sprintf(_('These are people tags created by **%s**. ' .
189                     'People tags are how you sort similar ' .
190                     'people on %%%%site.name%%%%, a [micro-blogging]' .
191                     '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
192                     'based on the Free Software [StatusNet](http://status.net/) tool. ' .
193                     'You can easily keep track of what they ' .
194                     'are doing by subscribing to the tag\'s timeline.' ), $this->tagger->nickname);
195         $this->elementStart('div', array('id' => 'anon_notice'));
196         $this->raw(common_markup_to_html($notice));
197         $this->elementEnd('div');
198     }
199
200     function showPageNotice()
201     {
202         $this->elementStart('div', 'instructions');
203         $this->showModeSelector();
204         $this->elementEnd('div');
205     }
206
207     function showContent()
208     {
209         #TODO: controls here.
210
211         $pl = new PeopletagList($this->tags, $this);
212         $cnt = $pl->show();
213
214         if ($cnt == 0) {
215             $this->showEmptyListMessage();
216         }
217         $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
218                           $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
219     }
220
221     function getSelfUrlArgs()
222     {
223         $args = array();
224         if ($this->arg('private')) {
225             $args['private'] = 1;
226         } else if ($this->arg('public')) {
227             $args['public'] = 1;
228         }
229         $args['nickname'] = $this->trimmed('nickname');
230
231         return $args;
232     }
233
234     function isOwner()
235     {
236         $user = common_current_user();
237         return !empty($user) && $user->id == $this->tagger->id;
238     }
239
240     function showEmptyListMessage()
241     {
242         $message = sprintf(_('%s has not created any [people tags](%%%%doc.tags%%%%) yet.'), $this->tagger->nickname);
243         $this->elementStart('div', 'guide');
244         $this->raw(common_markup_to_html($message));
245         $this->elementEnd('div');
246     }
247
248     function showSections()
249     {
250         #TODO: tags with most subscribers
251         #TODO: tags with most "members"
252     }
253 }