]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showprofiletag.php
Merge branch '1.0.x' into 1.1.x
[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, $userProfile;
37
38     function isReadOnly($args)
39     {
40         return true;
41     }
42
43     function prepare($args)
44     {
45         parent::prepare($args);
46
47         if (common_config('singleuser', 'enabled')) {
48             $tagger_arg = User::singleUserNickname();
49         } else {
50             $tagger_arg = $this->arg('tagger');
51         }
52         $tag_arg = $this->arg('tag');
53         $tagger = common_canonical_nickname($tagger_arg);
54         $tag = common_canonical_tag($tag_arg);
55
56         // Permanent redirect on non-canonical nickname
57
58         if ($tagger_arg != $tagger || $tag_arg != $tag) {
59             $args = array('tagger' => $nickname, 'tag' => $tag);
60             if ($this->page != 1) {
61                 $args['page'] = $this->page;
62             }
63             common_redirect(common_local_url('showprofiletag', $args), 301);
64             return false;
65         }
66
67         if (!$tagger) {
68             // TRANS: Client error displayed when a tagger is expected but not provided.
69             $this->clientError(_('No tagger.'), 404);
70             return false;
71         }
72
73         $user = User::staticGet('nickname', $tagger);
74
75         if (!$user) {
76             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
77             $this->clientError(_('No such user.'), 404);
78             return false;
79         }
80
81         $this->tagger = $user->getProfile();
82         $this->peopletag = Profile_list::pkeyGet(array('tagger' => $user->id, 'tag' => $tag));
83
84         $current = common_current_user();
85         $can_see = !empty($this->peopletag) && (!$this->peopletag->private ||
86                    ($this->peopletag->private && $this->peopletag->tagger === $current->id));
87
88         if (!$can_see) {
89             // TRANS: Client error displayed trying to reference a non-existing list.
90             $this->clientError(_('No such list.'), 404);
91             return false;
92         }
93
94         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
95         $this->userProfile = Profile::current();
96
97         $stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile);
98
99         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
100                                             NOTICES_PER_PAGE + 1);
101
102         if ($this->page > 1 && $this->notice->N == 0) {
103             // TRANS: Server error when page not found (404).
104             $this->serverError(_('No such page.'), $code = 404);
105         }
106
107         return true;
108     }
109
110     function handle($args)
111     {
112         parent::handle($args);
113
114         if (!$this->peopletag) {
115             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
116             $this->clientError(_('No such user.'));
117             return;
118         }
119
120         $this->showPage();
121     }
122
123     function title()
124     {
125         if ($this->page > 1) {
126             if($this->peopletag->private) {
127                 // TRANS: Title for private list timeline.
128                 // TRANS: %1$s is a list, %2$s is a page number.
129                 return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
130                                 $this->peopletag->tag, $this->page);
131             }
132
133             $current = common_current_user();
134             if (!empty($current) && $current->id == $this->peopletag->tagger) {
135                 // TRANS: Title for public list timeline where the viewer is the tagger.
136                 // TRANS: %1$s is a list, %2$s is a page number.
137                 return sprintf(_('Timeline for %1$s list by you, page %2$d'),
138                                 $this->peopletag->tag, $this->page);
139             }
140
141             // TRANS: Title for private list timeline.
142             // TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number.
143             return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
144                                 $this->peopletag->tag,
145                                 $this->tagger->nickname,
146                                 $this->page
147                           );
148         } else {
149             if($this->peopletag->private) {
150                 // TRANS: Title for private list timeline.
151                 // TRANS: %s is a list.
152                 return sprintf(_('Private timeline of %s list by you'),
153                                 $this->peopletag->tag);
154             }
155
156             $current = common_current_user();
157             if (!empty($current) && $current->id == $this->peopletag->tagger) {
158                 // TRANS: Title for public list timeline where the viewer is the tagger.
159                 // TRANS: %s is a list.
160                 return sprintf(_('Timeline for %s list by you'),
161                                 $this->peopletag->tag);
162             }
163
164             // TRANS: Title for private list timeline.
165             // TRANS: %1$s is a list, %2$s is the tagger's nickname.
166             return sprintf(_('Timeline for %1$s list by %2$s'),
167                                 $this->peopletag->tag,
168                                 $this->tagger->nickname
169                           );
170         }
171     }
172
173     function getFeeds()
174     {
175         #XXX: make these actually work
176         return array(new Feed(Feed::JSON,
177                 common_local_url(
178                     'ApiTimelineList', array(
179                         'user' => $this->tagger->id,
180                         'id' => $this->peopletag->id,
181                         'format' => 'as'
182                     )
183                 ),
184                 // TRANS: Feed title.
185                 // TRANS: %s is tagger's nickname.
186                 sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->tagger->nickname)),
187                 new Feed(Feed::RSS2,
188                 common_local_url(
189                     'ApiTimelineList', array(
190                         'user' => $this->tagger->id,
191                         'id' => $this->peopletag->id,
192                         'format' => 'rss'
193                     )
194                 ),
195                 // TRANS: Feed title.
196                 // TRANS: %s is tagger's nickname.
197                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)),
198             new Feed(Feed::ATOM,
199                 common_local_url(
200                     'ApiTimelineList', array(
201                         'user' => $this->tagger->id,
202                         'id' => $this->peopletag->id,
203                         'format' => 'atom'
204                     )
205                 ),
206                 // TRANS: Feed title.
207                 // TRANS: %1$s is a list, %2$s is tagger's nickname.
208                 sprintf(_('Feed for %1$s list by %2$s (Atom)'),
209                             $this->peopletag->tag, $this->tagger->nickname
210                        )
211               )
212         );
213     }
214
215     function showObjectNav()
216     {
217         $nav = new PeopletagGroupNav($this);
218         $nav->show();
219     }
220
221     function showEmptyListMessage()
222     {
223         // TRANS: Empty list message for list timeline.
224         // TRANS: %1$s is a list, %2$s is a tagger's nickname.
225         $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
226                            $this->peopletag->tag,
227                            $this->tagger->nickname) . ' ';
228
229         if (common_logged_in()) {
230             $current_user = common_current_user();
231             if ($this->tagger->id == $current_user->id) {
232                 // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
233                 $message .= _('Try tagging more people.');
234             }
235         } else {
236             // TRANS: Additional empty list message for list timeline.
237             // TRANS: This message contains Markdown links in the form [description](link).
238             $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
239         }
240
241         $this->elementStart('div', 'guide');
242         $this->raw(common_markup_to_html($message));
243         $this->elementEnd('div');
244     }
245
246     function showContent()
247     {
248         $this->showPeopletag();
249         $this->showNotices();
250     }
251
252     function showPeopletag()
253     {
254         $cur = common_current_user();
255         $tag = new Peopletag($this->peopletag, $cur, $this);
256         $tag->show();
257     }
258
259     function showNotices()
260     {
261         if (Event::handle('StartShowProfileTagContent', array($this))) {
262             $nl = new NoticeList($this->notice, $this);
263
264             $cnt = $nl->show();
265
266             if (0 == $cnt) {
267                 $this->showEmptyListMessage();
268             }
269
270             $this->pagination($this->page > 1,
271                               $cnt > NOTICES_PER_PAGE,
272                               $this->page,
273                               'showprofiletag',
274                               array('tag' => $this->peopletag->tag,
275                                     'tagger' => $this->tagger->nickname)
276             );
277
278             Event::handle('EndShowProfileTagContent', array($this));
279         }
280     }
281
282     function showSections()
283     {
284         $this->showTagged();
285         if (!$this->peopletag->private) {
286             $this->showSubscribers();
287         }
288         # $this->showStatistics();
289     }
290
291     function showPageTitle()
292     {
293         $this->element('h1', null, $this->title());
294     }
295
296     function showTagged()
297     {
298         $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
299
300         $this->elementStart('div', array('id' => 'entity_tagged',
301                                          'class' => 'section'));
302         if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
303             $title = '';
304
305             // TRANS: Header on show list page.
306             $this->element('h2', null, _('Listed'));
307
308             $cnt = 0;
309
310             if (!empty($profile)) {
311                 $pml = new ProfileMiniList($profile, $this);
312                 $cnt = $pml->show();
313                 if ($cnt == 0) {
314                     // TRANS: Content of "Listed" page if there are no listed users.
315                     $this->element('p', null, _('(None)'));
316                 }
317             }
318
319             if ($cnt > PROFILES_PER_MINILIST) {
320                 $this->elementStart('p');
321                 $this->element('a', array('href' => common_local_url('taggedprofiles',
322                                                                      array('nickname' => $this->tagger->nickname,
323                                                                            'profiletag' => $this->peopletag->tag)),
324                                           'class' => 'more'),
325                                // TRANS: Link for more "People in list x by a user"
326                                // TRANS: if there are more than the mini list's maximum.
327                                _('Show all'));
328                 $this->elementEnd('p');
329             }
330
331             Event::handle('EndShowTaggedProfilesMiniList', array($this));
332         }
333         $this->elementEnd('div');
334     }
335
336     function showSubscribers()
337     {
338         $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
339
340         $this->elementStart('div', array('id' => 'entity_subscribers',
341                                          'class' => 'section'));
342         if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
343             // TRANS: Header for tag subscribers.
344             $this->element('h2', null, _('Subscribers'));
345
346             $cnt = 0;
347
348             if (!empty($profile)) {
349                 $pml = new ProfileMiniList($profile, $this);
350                 $cnt = $pml->show();
351                 if ($cnt == 0) {
352                     // TRANS: Content of "People following tag x" if there are no subscribed users.
353                     $this->element('p', null, _('(None)'));
354                 }
355             }
356
357             // FIXME: link to full list
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 }