3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @license GNU Affero General Public License http://www.gnu.org/licenses/
22 * @link http://status.net
25 if (!defined('STATUSNET') && !defined('LACONICA')) {
29 require_once INSTALLDIR.'/lib/profileminilist.php';
30 require_once INSTALLDIR.'/lib/peopletaglist.php';
31 require_once INSTALLDIR.'/lib/noticelist.php';
32 require_once INSTALLDIR.'/lib/feedlist.php';
34 class ShowprofiletagAction extends Action
36 var $notice, $tagger, $peopletag;
38 function isReadOnly($args)
43 function prepare($args)
45 parent::prepare($args);
47 $tagger_arg = $this->arg('tagger');
48 $tag_arg = $this->arg('tag');
49 $tagger = common_canonical_nickname($tagger_arg);
50 $tag = common_canonical_tag($tag_arg);
52 // Permanent redirect on non-canonical nickname
54 if ($tagger_arg != $tagger || $tag_arg != $tag) {
55 $args = array('tagger' => $nickname, 'tag' => $tag);
56 if ($this->page != 1) {
57 $args['page'] = $this->page;
59 common_redirect(common_local_url('showprofiletag', $args), 301);
64 // TRANS: Client error displayed when a tagger is expected but not provided.
65 $this->clientError(_('No tagger.'), 404);
69 $user = User::staticGet('nickname', $tagger);
72 // TRANS: Client error displayed trying to perform an action related to a non-existing user.
73 $this->clientError(_('No such user.'), 404);
77 $this->tagger = $user->getProfile();
78 $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
80 $current = common_current_user();
81 $can_see = !empty($this->peopletag) && (!$this->peopletag->private ||
82 ($this->peopletag->private && $this->peopletag->tagger === $current->id));
85 // TRANS: Client error displayed trying to reference a non-existing people tag.
86 $this->clientError(_('No such people tag.'), 404);
90 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
91 $this->notice = $this->peopletag->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
93 if ($this->page > 1 && $this->notice->N == 0) {
94 // TRANS: Server error when page not found (404).
95 $this->serverError(_('No such page.'), $code = 404);
101 function handle($args)
103 parent::handle($args);
105 if (!$this->peopletag) {
106 // TRANS: Client error displayed trying to perform an action related to a non-existing user.
107 $this->clientError(_('No such user.'));
116 if ($this->page > 1) {
117 if($this->peopletag->private) {
118 // TRANS: Title for private people tag timeline.
119 // TRANS: %1$s is a people tag, %2$s is a page number.
120 return sprintf(_('Private timeline for people tagged %1$s by you, page %2$d'),
121 $this->peopletag->tag, $this->page);
124 $current = common_current_user();
125 if (!empty($current) && $current->id == $this->peopletag->tagger) {
126 // TRANS: Title for public people tag timeline where the viewer is the tagger.
127 // TRANS: %1$s is a people tag, %2$s is a page number.
128 return sprintf(_('Timeline for people tagged %1$s by you, page %2$d'),
129 $this->peopletag->tag, $this->page);
132 // TRANS: Title for private people tag timeline.
133 // TRANS: %1$s is a people tag, %2$s is the tagger's nickname, %3$d is a page number.
134 return sprintf(_('Timeline for people tagged %1$s by %2$s, page %3$d'),
135 $this->peopletag->tag,
136 $this->tagger->nickname,
140 if($this->peopletag->private) {
141 // TRANS: Title for private people tag timeline.
142 // TRANS: %s is a people tag.
143 return sprintf(_('Private timeline of people tagged %s by you'),
144 $this->peopletag->tag);
147 $current = common_current_user();
148 if (!empty($current) && $current->id == $this->peopletag->tagger) {
149 // TRANS: Title for public people tag timeline where the viewer is the tagger.
150 // TRANS: %s is a people tag.
151 return sprintf(_('Timeline for people tagged %s by you'),
152 $this->peopletag->tag);
155 // TRANS: Title for private people tag timeline.
156 // TRANS: %1$s is a people tag, %2$s is the tagger's nickname.
157 return sprintf(_('Timeline for people tagged %1$s by %2$s'),
158 $this->peopletag->tag,
159 $this->tagger->nickname
166 #XXX: make these actually work
167 return array(new Feed(Feed::RSS2,
169 'ApiTimelineList', array(
170 'user' => $this->tagger->id,
171 'id' => $this->peopletag->id,
175 // TRANS: Feed title.
176 // TRANS: %s is tagger's nickname.
177 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)),
180 'ApiTimelineList', array(
181 'user' => $this->tagger->id,
182 'id' => $this->peopletag->id,
186 // TRANS: Feed title.
187 // TRANS: %1$s is a people tag, %2$s is tagger's nickname.
188 sprintf(_('Feed for people tagged %1$s by %2$s (Atom)'),
189 $this->peopletag->tag, $this->tagger->nickname
195 function showObjectNav()
197 $nav = new PeopletagGroupNav($this);
201 function showEmptyListMessage()
203 // TRANS: Empty list message for people tag timeline.
204 // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
205 $message = sprintf(_('This is the timeline for people tagged %1$s by %2$s but no one has posted anything yet.'),
206 $this->peopletag->tag,
207 $this->tagger->nickname) . ' ';
209 if (common_logged_in()) {
210 $current_user = common_current_user();
211 if ($this->tagger->id == $current_user->id) {
212 // TRANS: Additional empty list message for people tag timeline for currently logged in user tagged tags.
213 $message .= _('Try tagging more people.');
216 // TRANS: Additional empty list message for people tag timeline.
217 // TRANS: This message contains Markdown links in the form [description](link).
218 $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
221 $this->elementStart('div', 'guide');
222 $this->raw(common_markup_to_html($message));
223 $this->elementEnd('div');
226 function showContent()
228 $this->showPeopletag();
229 $this->showNotices();
232 function showPeopletag()
234 $cur = common_current_user();
235 $tag = new Peopletag($this->peopletag, $cur, $this);
239 function showNotices()
241 if (Event::handle('StartShowProfileTagContent', array($this))) {
242 $nl = new NoticeList($this->notice, $this);
247 $this->showEmptyListMessage();
251 $this->page > 1, $cnt > NOTICES_PER_PAGE,
252 $this->page, 'showprofiletag', array('tag' => $this->peopletag->tag,
253 'tagger' => $this->tagger->nickname)
256 Event::handle('EndShowProfileTagContent', array($this));
260 function showSections()
263 if (!$this->peopletag->private) {
264 $this->showSubscribers();
266 # $this->showStatistics();
269 function showPageTitle()
271 $this->element('h1', null, $this->title());
274 function showTagged()
276 $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
278 $this->elementStart('div', array('id' => 'entity_tagged',
279 'class' => 'section'));
280 if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
283 $current = common_current_user();
284 if(!empty($current) && $this->peopletag->tagger == $current->id) {
285 // TRANS: Header on show profile tag page.
286 // TRANS: %s is a people tag.
287 $title = sprintf(_('People tagged %s by you'), $this->peopletag->tag);
289 // TRANS: Header on show profile tag page.
290 // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
291 $title = sprintf(_('People tagged %1$s by %2$s'),
292 $this->peopletag->tag,
293 $this->tagger->nickname);
296 $this->element('h2', null, $title);
300 if (!empty($profile)) {
301 $pml = new ProfileMiniList($profile, $this);
304 // TRANS: Content of "People tagged x by a user" if there are no tagged users.
305 $this->element('p', null, _('(None)'));
309 if ($cnt > PROFILES_PER_MINILIST) {
310 $this->elementStart('p');
311 $this->element('a', array('href' => common_local_url('taggedprofiles',
312 array('nickname' => $this->tagger->nickname,
313 'profiletag' => $this->peopletag->tag)),
315 // TRANS: Link for more "People tagged x by a user"
316 // TRANS: if there are more than the mini list's maximum.
318 $this->elementEnd('p');
321 Event::handle('EndShowTaggedProfilesMiniList', array($this));
323 $this->elementEnd('div');
326 function showSubscribers()
328 $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
330 $this->elementStart('div', array('id' => 'entity_subscribers',
331 'class' => 'section'));
332 if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
333 // TRANS: Header for tag subscribers.
334 $this->element('h2', null, _('Subscribers'));
338 if (!empty($profile)) {
339 $pml = new ProfileMiniList($profile, $this);
342 // TRANS: Content of "People following tag x" if there are no subscribed users.
343 $this->element('p', null, _('(None)'));
347 if ($cnt > PROFILES_PER_MINILIST) {
348 $this->elementStart('p');
349 $this->element('a', array('href' => common_local_url('profiletagsubscribers',
350 array('nickname' => $this->tagger->nickname,
351 'profiletag' => $this->peopletag->tag)),
353 // TRANS: Link for more "People following tag x"
354 // TRANS: if there are more than the mini list's maximum.
355 _('All subscribers'));
356 $this->elementEnd('p');
359 Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
361 $this->elementEnd('div');
365 class Peopletag extends PeopletagListItem
369 $mode = $this->peopletag->private ? 'private' : 'public';
370 $this->out->elementStart('div', array('class' => 'hentry peopletag peopletag-profile mode-'.$mode,
371 'id' => 'peopletag-' . $this->peopletag->id));
376 $this->out->elementEnd('div');
379 function showAvatar()
381 parent::showAvatar(AVATAR_PROFILE_SIZE);