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