]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showprofiletag.php
People tags -> Lists (only UI changes, for experimentation)
[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         $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->userProfile = Profile::current();
92
93         $stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile);
94
95         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
96                                             NOTICES_PER_PAGE + 1);
97
98         if ($this->page > 1 && $this->notice->N == 0) {
99             // TRANS: Server error when page not found (404).
100             $this->serverError(_('No such page.'), $code = 404);
101         }
102
103         return true;
104     }
105
106     function handle($args)
107     {
108         parent::handle($args);
109
110         if (!$this->peopletag) {
111             // TRANS: Client error displayed trying to perform an action related to a non-existing user.
112             $this->clientError(_('No such user.'));
113             return;
114         }
115
116         $this->showPage();
117     }
118
119     function title()
120     {
121         if ($this->page > 1) {
122             if($this->peopletag->private) {
123                 // TRANS: Title for private people tag timeline.
124                 // TRANS: %1$s is a people tag, %2$s is a page number.
125                 return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
126                                 $this->peopletag->tag, $this->page);
127             }
128
129             $current = common_current_user();
130             if (!empty($current) && $current->id == $this->peopletag->tagger) {
131                 // TRANS: Title for public people tag timeline where the viewer is the tagger.
132                 // TRANS: %1$s is a people tag, %2$s is a page number.
133                 return sprintf(_('Timeline for %1$s list by you, page %2$d'),
134                                 $this->peopletag->tag, $this->page);
135             }
136
137             // TRANS: Title for private people tag timeline.
138             // TRANS: %1$s is a people tag, %2$s is the tagger's nickname, %3$d is a page number.
139             return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
140                                 $this->peopletag->tag,
141                                 $this->tagger->nickname,
142                                 $this->page
143                           );
144         } else {
145             if($this->peopletag->private) {
146                 // TRANS: Title for private people tag timeline.
147                 // TRANS: %s is a people tag.
148                 return sprintf(_('Private timeline of %s list by you'),
149                                 $this->peopletag->tag);
150             }
151
152             $current = common_current_user();
153             if (!empty($current) && $current->id == $this->peopletag->tagger) {
154                 // TRANS: Title for public people tag timeline where the viewer is the tagger.
155                 // TRANS: %s is a people tag.
156                 return sprintf(_('Timeline for %s list by you'),
157                                 $this->peopletag->tag);
158             }
159
160             // TRANS: Title for private people tag timeline.
161             // TRANS: %1$s is a people tag, %2$s is the tagger's nickname.
162             return sprintf(_('Timeline for %1$s list by %2$s'),
163                                 $this->peopletag->tag,
164                                 $this->tagger->nickname
165                           );
166         }
167     }
168
169     function getFeeds()
170     {
171         #XXX: make these actually work
172         return array(new Feed(Feed::RSS2,
173                 common_local_url(
174                     'ApiTimelineList', array(
175                         'user' => $this->tagger->id,
176                         'id' => $this->peopletag->id,
177                         'format' => 'rss'
178                     )
179                 ),
180                 // TRANS: Feed title.
181                 // TRANS: %s is tagger's nickname.
182                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->tagger->nickname)),
183             new Feed(Feed::ATOM,
184                 common_local_url(
185                     'ApiTimelineList', array(
186                         'user' => $this->tagger->id,
187                         'id' => $this->peopletag->id,
188                         'format' => 'atom'
189                     )
190                 ),
191                 // TRANS: Feed title.
192                 // TRANS: %1$s is a people tag, %2$s is tagger's nickname.
193                 sprintf(_('Feed for %1$s list by %2$s (Atom)'),
194                             $this->peopletag->tag, $this->tagger->nickname
195                        )
196               )
197         );
198     }
199
200     function showObjectNav()
201     {
202         $nav = new PeopletagGroupNav($this);
203         $nav->show();
204     }
205
206     function showEmptyListMessage()
207     {
208         // TRANS: Empty list message for people tag timeline.
209         // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
210         $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
211                            $this->peopletag->tag,
212                            $this->tagger->nickname) . ' ';
213
214         if (common_logged_in()) {
215             $current_user = common_current_user();
216             if ($this->tagger->id == $current_user->id) {
217                 // TRANS: Additional empty list message for people tag timeline for currently logged in user tagged tags.
218                 $message .= _('Try tagging more people.');
219             }
220         } else {
221             // TRANS: Additional empty list message for people tag timeline.
222             // TRANS: This message contains Markdown links in the form [description](link).
223             $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
224         }
225
226         $this->elementStart('div', 'guide');
227         $this->raw(common_markup_to_html($message));
228         $this->elementEnd('div');
229     }
230
231     function showContent()
232     {
233         $this->showPeopletag();
234         $this->showNotices();
235     }
236
237     function showPeopletag()
238     {
239         $cur = common_current_user();
240         $tag = new Peopletag($this->peopletag, $cur, $this);
241         $tag->show();
242     }
243
244     function showNotices()
245     {
246         if (Event::handle('StartShowProfileTagContent', array($this))) {
247             $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
248
249             $cnt = $nl->show();
250
251             if (0 == $cnt) {
252                 $this->showEmptyListMessage();
253             }
254
255             $this->pagination($this->page > 1,
256                               $cnt > NOTICES_PER_PAGE,
257                               $this->page,
258                               'showprofiletag',
259                               array('tag' => $this->peopletag->tag,
260                                     'tagger' => $this->tagger->nickname)
261             );
262
263             Event::handle('EndShowProfileTagContent', array($this));
264         }
265     }
266
267     function showSections()
268     {
269         $this->showTagged();
270         if (!$this->peopletag->private) {
271             $this->showSubscribers();
272         }
273         # $this->showStatistics();
274     }
275
276     function showPageTitle()
277     {
278         $this->element('h1', null, $this->title());
279     }
280
281     function showTagged()
282     {
283         $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
284
285         $this->elementStart('div', array('id' => 'entity_tagged',
286                                          'class' => 'section'));
287         if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
288             $title = '';
289
290             $current = common_current_user();
291             if(!empty($current) && $this->peopletag->tagger == $current->id) {
292                 // TRANS: Header on show profile tag page.
293                 // TRANS: %s is a people tag.
294                 $title =  sprintf(_('Listed'), $this->peopletag->tag);
295             } else {
296                 // TRANS: Header on show profile tag page.
297                 // TRANS: %1$s is a people tag, %2$s is a tagger's nickname.
298                 $title = sprintf(_('Listed'),
299                                 $this->peopletag->tag,
300                                 $this->tagger->nickname);
301             }
302
303             $this->element('h2', null, $title);
304
305             $cnt = 0;
306
307             if (!empty($profile)) {
308                 $pml = new ProfileMiniList($profile, $this);
309                 $cnt = $pml->show();
310                 if ($cnt == 0) {
311                     // TRANS: Content of "People tagged x by a user" if there are no tagged users.
312                     $this->element('p', null, _('(None)'));
313                 }
314             }
315
316             if ($cnt > PROFILES_PER_MINILIST) {
317                 $this->elementStart('p');
318                 $this->element('a', array('href' => common_local_url('taggedprofiles',
319                                                                      array('nickname' => $this->tagger->nickname,
320                                                                            'profiletag' => $this->peopletag->tag)),
321                                           'class' => 'more'),
322                                // TRANS: Link for more "People tagged x by a user"
323                                // TRANS: if there are more than the mini list's maximum.
324                                _('Show all'));
325                 $this->elementEnd('p');
326             }
327
328             Event::handle('EndShowTaggedProfilesMiniList', array($this));
329         }
330         $this->elementEnd('div');
331     }
332
333     function showSubscribers()
334     {
335         $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
336
337         $this->elementStart('div', array('id' => 'entity_subscribers',
338                                          'class' => 'section'));
339         if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
340             // TRANS: Header for tag subscribers.
341             $this->element('h2', null, _('Subscribers'));
342
343             $cnt = 0;
344
345             if (!empty($profile)) {
346                 $pml = new ProfileMiniList($profile, $this);
347                 $cnt = $pml->show();
348                 if ($cnt == 0) {
349                     // TRANS: Content of "People following tag x" if there are no subscribed users.
350                     $this->element('p', null, _('(None)'));
351                 }
352             }
353
354             if ($cnt > PROFILES_PER_MINILIST) {
355                 $this->elementStart('p');
356                 $this->element('a', array('href' => common_local_url('profiletagsubscribers',
357                                                                      array('nickname' => $this->tagger->nickname,
358                                                                            'profiletag' => $this->peopletag->tag)),
359                                           'class' => 'more'),
360                                // TRANS: Link for more "People following tag x"
361                                // TRANS: if there are more than the mini list's maximum.
362                                _('All subscribers'));
363                 $this->elementEnd('p');
364             }
365
366             Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
367         }
368         $this->elementEnd('div');
369     }
370 }
371
372 class Peopletag extends PeopletagListItem
373 {
374     function showStart()
375     {
376         $mode = $this->peopletag->private ? 'private' : 'public';
377         $this->out->elementStart('div', array('class' => 'hentry peopletag peopletag-profile mode-'.$mode,
378                                              'id' => 'peopletag-' . $this->peopletag->id));
379     }
380
381     function showEnd()
382     {
383         $this->out->elementEnd('div');
384     }
385
386     function showAvatar()
387     {
388         parent::showAvatar(AVATAR_PROFILE_SIZE);
389     }
390 }