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 // TRANS: Title for people tags by a user page for a private tag.
53 return _('Private people tags by you');
54 } else if ($this->arg('public')) {
55 // TRANS: Title for people tags by a user page for a public tag.
56 return _('Public people tags by you');
58 // TRANS: Title for people tags by a user page.
59 return _('People tags by you');
61 // TRANS: Title for people tags by a user page.
62 // TRANS: %s is a user nickname.
63 return sprintf(_('People tags by %s'), $this->tagger->nickname);
65 // TRANS: Title for people tags by a user page.
66 // TRANS: %1$s is a user nickname, %2$d is a page number.
67 return sprintf(_('People tags by %1$s, page %2$d'), $this->tagger->nickname, $this->page);
71 function prepare($args)
73 parent::prepare($args);
75 if ($this->arg('public') && $this->arg('private')) {
76 $this->args['public'] = $this->args['private'] = false;
79 $nickname_arg = $this->arg('nickname');
80 $nickname = common_canonical_nickname($nickname_arg);
82 // Permanent redirect on non-canonical nickname
84 if ($nickname_arg != $nickname) {
85 $args = $this->getSelfUrlArgs();
86 if ($this->arg('page') && $this->arg('page') != 1) {
87 $args['page'] = $this->arg['page'];
89 common_redirect(common_local_url('peopletagsbyuser', $args), 301);
93 $this->user = User::staticGet('nickname', $nickname);
96 // TRANS: Client error displayed trying to perform an action related to a non-existing user.
97 $this->clientError(_('No such user.'), 404);
101 $this->tagger = $this->user->getProfile();
103 if (!$this->tagger) {
104 // TRANS: Server error displayed when a user has no profile.
105 $this->serverError(_('User has no profile.'));
109 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
112 $offset = ($this->page-1) * PEOPLETAGS_PER_PAGE;
113 $limit = PEOPLETAGS_PER_PAGE + 1;
115 $user = common_current_user();
116 if ($this->arg('public')) {
117 $this->tags = $this->tagger->getOwnedTags(false, $offset, $limit);
118 } else if ($this->arg('private')) {
120 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
121 $this->clientError(_('Not logged in.'), 403);
124 if ($this->isOwner()) {
125 $this->tags = $this->tagger->getPrivateTags($offset, $limit);
127 // TRANS: Client error displayed when trying view another user's private people tags.
128 $this->clientError(_('You cannot view others\' private people tags'), 403);
131 $this->tags = $this->tagger->getOwnedTags(common_current_user(), $offset, $limit);
136 function handle($args)
138 parent::handle($args);
140 # Post from the tag dropdown; redirect to a GET
142 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
143 common_redirect(common_local_url('peopletagsbyuser', $this->getSelfUrlArgs()), 303);
150 function showModeSelector()
152 $this->elementStart('dl', array('id'=>'filter_tags'));
153 // TRANS: Mode selector label.
154 $this->element('dt', null, _('Mode'));
155 $this->elementStart('dd');
156 $this->elementStart('ul');
157 $this->elementStart('li', array('id' => 'filter_tags_for',
158 'class' => 'child_1'));
161 common_local_url('peopletagsforuser',
162 array('nickname' => $this->user->nickname))),
163 // TRANS: Link text to show people tags for user %s.
164 sprintf(_('People tags for %s'), $this->tagger->nickname));
165 $this->elementEnd('li');
167 if ($this->isOwner()) {
168 $this->elementStart('li', array('id'=>'filter_tags_item'));
169 $this->elementStart('form', array('name' => 'modeselector',
170 'id' => 'form_filter_bymode',
171 'action' => common_local_url('peopletagsbyuser',
172 array('nickname' => $this->tagger->nickname)),
173 'method' => 'post'));
174 $this->elementStart('fieldset');
175 // TRANS: Fieldset legend.
176 $this->element('legend', null, _('Select tag to filter'));
178 $priv = $this->arg('private');
179 $pub = $this->arg('public');
181 if (!$priv && !$pub) {
184 // TRANS: Checkbox label to show private tags.
185 $this->checkbox('private', _m('LABEL','Private'), $priv,
186 // TRANS: Checkbox title.
187 _('Show private tags.'));
188 // TRANS: Checkbox label to show public tags.
189 $this->checkbox('public', _m('LABEL','Public'), $pub,
190 // TRANS: Checkbox title.
191 _('Show public tags.'));
192 $this->hidden('nickname', $this->user->nickname);
193 // TRANS: Submit button text for tag filter form.
194 $this->submit('submit', _m('BUTTON','Go'));
195 $this->elementEnd('fieldset');
196 $this->elementEnd('form');
197 $this->elementEnd('li');
199 $this->elementEnd('ul');
200 $this->elementEnd('dd');
201 $this->elementEnd('dl');
204 function showAnonymousMessage()
207 // TRANS: Message displayed for anonymous users on page that displays people tags by a user.
208 // TRANS: This message contains Markdown links in the form [description](links).
209 // TRANS: %s is a tagger nickname.
210 sprintf(_('These are people tags created by **%s**. ' .
211 'People tags are how you sort similar ' .
212 'people on %%%%site.name%%%%, a [micro-blogging]' .
213 '(http://en.wikipedia.org/wiki/Micro-blogging) service ' .
214 'based on the Free Software [StatusNet](http://status.net/) tool. ' .
215 'You can easily keep track of what they ' .
216 'are doing by subscribing to the tag\'s timeline.' ), $this->tagger->nickname);
217 $this->elementStart('div', array('id' => 'anon_notice'));
218 $this->raw(common_markup_to_html($notice));
219 $this->elementEnd('div');
222 function showPageNotice()
224 $this->elementStart('div', 'instructions');
225 $this->showModeSelector();
226 $this->elementEnd('div');
229 function showContent()
231 #TODO: controls here.
233 $pl = new PeopletagList($this->tags, $this);
237 $this->showEmptyListMessage();
239 $this->pagination($this->page > 1, $cnt > PEOPLETAGS_PER_PAGE,
240 $this->page, 'peopletagsbyuser', $this->getSelfUrlArgs());
243 function getSelfUrlArgs()
246 if ($this->arg('private')) {
247 $args['private'] = 1;
248 } else if ($this->arg('public')) {
251 $args['nickname'] = $this->trimmed('nickname');
258 $user = common_current_user();
259 return !empty($user) && $user->id == $this->tagger->id;
262 function showEmptyListMessage()
264 // TRANS: Message displayed on page that displays people tags by a user when there are none.
265 // TRANS: This message contains Markdown links in the form [description](links).
266 // TRANS: %s is a tagger nickname.
267 $message = sprintf(_('%s has not created any [people tags](%%%%doc.tags%%%%) yet.'), $this->tagger->nickname);
268 $this->elementStart('div', 'guide');
269 $this->raw(common_markup_to_html($message));
270 $this->elementEnd('div');
273 function showSections()
275 #TODO: tags with most subscribers
276 #TODO: tags with most "members"