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