3 * StatusNet, the distributed open-source microblogging tool
5 * People tags by a user
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/peopletaglist.php';
36 class PeopletagsbyuserAction extends OwnerDesignAction
42 function isReadOnly($args)
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');
56 return _('People tags by you');
58 return sprintf(_("People tags by %s"), $this->tagger->nickname);
60 return sprintf(_("People tags by %s, page %d"), $this->tagger->nickname, $this->page);
64 function prepare($args)
66 parent::prepare($args);
68 if ($this->arg('public') && $this->arg('private')) {
69 $this->args['public'] = $this->args['private'] = false;
72 $nickname_arg = $this->arg('nickname');
73 $nickname = common_canonical_nickname($nickname_arg);
75 // Permanent redirect on non-canonical nickname
77 if ($nickname_arg != $nickname) {
78 $args = $this->getSelfUrlArgs();
79 if ($this->arg('page') && $this->arg('page') != 1) {
80 $args['page'] = $this->arg['page'];
82 common_redirect(common_local_url('peopletagsbyuser', $args), 301);
86 $this->user = User::staticGet('nickname', $nickname);
89 $this->clientError(_('No such user.'), 404);
93 $this->tagger = $this->user->getProfile();
96 $this->serverError(_('User has no profile.'));
100 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
103 $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
104 $limit = PEOPLETAGS_PER_PAGE + 1;
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')) {
111 $this->clientError(_('Not logged in'), 403);
114 if ($this->isOwner()) {
115 $this->tags = $this->tagger->getPrivateTags($offset, $limit);
117 $this->clientError(_('You cannot view others\' private people tags'), 403);
120 $this->tags = $this->tagger->getOwnedTags(common_current_user(), $offset, $limit);
125 function handle($args)
127 parent::handle($args);
129 # Post from the tag dropdown; redirect to a GET
131 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
132 common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
139 function showModeSelector()
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'));
149 common_local_url('peopletagsforuser',
150 array('nickname' => $this->user->nickname))),
151 sprintf(_('People tags for %s'), $this->tagger->nickname));
152 $this->elementEnd('li');
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'));
164 $priv = $this->arg('private');
165 $pub = $this->arg('public');
167 if (!$priv && !$pub) {
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');
180 $this->elementEnd('ul');
181 $this->elementEnd('dd');
182 $this->elementEnd('dl');
185 function showAnonymousMessage()
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');
200 function showPageNotice()
202 $this->elementStart('div', 'instructions');
203 $this->showModeSelector();
204 $this->elementEnd('div');
207 function showContent()
209 #TODO: controls here.
211 $pl = new PeopletagList($this->tags, $this);
215 $this->showEmptyListMessage();
217 $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
218 $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
221 function getSelfUrlArgs()
224 if ($this->arg('private')) {
225 $args['private'] = 1;
226 } else if ($this->arg('public')) {
229 $args['nickname'] = $this->trimmed('nickname');
236 $user = common_current_user();
237 return !empty($user) && $user->id == $this->tagger->id;
240 function showEmptyListMessage()
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');
248 function showSections()
250 #TODO: tags with most subscribers
251 #TODO: tags with most "members"