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