]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showprofiletag.php
Merge branch '1.0.x' into testing
[quix0rs-gnu-social.git] / actions / showprofiletag.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  *
19  * @category Actions
20  * @package  Actions
21  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
22  * @link     http://status.net
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) {
26     exit(1);
27 }
28
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';
33
34 class ShowprofiletagAction extends Action
35 {
36     var $notice, $tagger, $peopletag;
37
38     function isReadOnly($args)
39     {
40         return true;
41     }
42
43     function prepare($args)
44     {
45         parent::prepare($args);
46
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);
51
52         // Permanent redirect on non-canonical nickname
53
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;
58             }
59             common_redirect(common_local_url('showprofiletag', $args), 301);
60             return false;
61         }
62
63         if (!$tagger) {
64             // TRANS: Client error displayed when a tagger is expected but not provided.
65             $this->clientError(_('No tagger.'), 404);
66             return false;
67         }
68
69         $user = User::staticGet('nickname', $tagger);
70
71         if (!$user) {
72             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
73             $this->clientError(_('No such user.'), 404);
74             return false;
75         }
76
77         $this->tagger = $user->getProfile();
78         $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
79
80         $current = common_current_user();
81         $can_see = !empty($this->peopletag) && (!$this->peopletag->private ||
82                    ($this->peopletag->private && $this->peopletag->tagger === $current->id));
83
84         if (!$can_see) {
85             // TRANS: Client error displayed trying to reference a non-existing people tag.
86             $this->clientError(_('No such people tag.'), 404);
87             return false;
88         }
89
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);
92
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);
96         }
97
98         return true;
99     }
100
101     function handle($args)
102     {
103         parent::handle($args);
104
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.'));
108             return;
109         }
110
111         $this->showPage();
112     }
113
114     function title()
115     {
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);
122             }
123
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);
130             }
131
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,
137                                 $this->page
138                           );
139         } else {
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);
145             }
146
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);
153             }
154
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
160                           );
161         }
162     }
163
164     function getFeeds()
165     {
166         #XXX: make these actually work
167         return array(new Feed(Feed::RSS2,
168                 common_local_url(
169                     'ApiTimelineList', array(
170                         'user' => $this->tagger->id,
171                         'id' => $this->peopletag->id,
172                         'format' => 'rss'
173                     )
174                 ),
175                 // TRANS: Feed title.
176                 // TRANS: %s is tagger's nickname.
177                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)),
178             new Feed(Feed::ATOM,
179                 common_local_url(
180                     'ApiTimelineList', array(
181                         'user' => $this->tagger->id,
182                         'id' => $this->peopletag->id,
183                         'format' => 'atom'
184                     )
185                 ),
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
190                        )
191               )
192         );
193     }
194
195     function showObjectNav()
196     {
197         $nav = new PeopletagGroupNav($this);
198         $nav->show();
199     }
200
201     function showEmptyListMessage()
202     {
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) . ' ';
208
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.');
214             }
215         } else {
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!');
219         }
220
221         $this->elementStart('div', 'guide');
222         $this->raw(common_markup_to_html($message));
223         $this->elementEnd('div');
224     }
225
226     function showContent()
227     {
228         $this->showPeopletag();
229         $this->showNotices();
230     }
231
232     function showPeopletag()
233     {
234         $cur = common_current_user();
235         $tag = new Peopletag($this->peopletag, $cur, $this);
236         $tag->show();
237     }
238
239     function showNotices()
240     {
241         if (Event::handle('StartShowProfileTagContent', array($this))) {
242             $nl = new NoticeList($this->notice, $this);
243
244             $cnt = $nl->show();
245
246             if (0 == $cnt) {
247                 $this->showEmptyListMessage();
248             }
249
250             $this->pagination(
251                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
252                 $this->page, 'showprofiletag', array('tag' => $this->peopletag->tag,
253                                                      'tagger' => $this->tagger->nickname)
254             );
255
256             Event::handle('EndShowProfileTagContent', array($this));
257         }
258     }
259
260     function showSections()
261     {
262         $this->showTagged();
263         if (!$this->peopletag->private) {
264             $this->showSubscribers();
265         }
266         # $this->showStatistics();
267     }
268
269     function showPageTitle()
270     {
271         $this->element('h1', null, $this->title());
272     }
273
274     function showTagged()
275     {
276         $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
277
278         $this->elementStart('div', array('id' => 'entity_tagged',
279                                          'class' => 'section'));
280         if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
281             $title = '';
282
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);
288             } else {
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);
294             }
295
296             $this->element('h2', null, $title);
297
298             $cnt = 0;
299
300             if (!empty($profile)) {
301                 $pml = new ProfileMiniList($profile, $this);
302                 $cnt = $pml->show();
303                 if ($cnt == 0) {
304                     // TRANS: Content of "People tagged x by a user" if there are no tagged users.
305                     $this->element('p', null, _('(None)'));
306                 }
307             }
308
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)),
314                                           'class' => 'more'),
315                                // TRANS: Link for more "People tagged x by a user"
316                                // TRANS: if there are more than the mini list's maximum.
317                                _('Show all'));
318                 $this->elementEnd('p');
319             }
320
321             Event::handle('EndShowTaggedProfilesMiniList', array($this));
322         }
323         $this->elementEnd('div');
324     }
325
326     function showSubscribers()
327     {
328         $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
329
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'));
335
336             $cnt = 0;
337
338             if (!empty($profile)) {
339                 $pml = new ProfileMiniList($profile, $this);
340                 $cnt = $pml->show();
341                 if ($cnt == 0) {
342                     // TRANS: Content of "People following tag x" if there are no subscribed users.
343                     $this->element('p', null, _('(None)'));
344                 }
345             }
346
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)),
352                                           'class' => 'more'),
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');
357             }
358
359             Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
360         }
361         $this->elementEnd('div');
362     }
363 }
364
365 class Peopletag extends PeopletagListItem
366 {
367     function showStart()
368     {
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));
372     }
373
374     function showEnd()
375     {
376         $this->out->elementEnd('div');
377     }
378
379     function showAvatar()
380     {
381         parent::showAvatar(AVATAR_PROFILE_SIZE);
382     }
383 }