]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showprofiletag.php
Add AtomPub, Twitter-compat. API documentation to doc-src/
[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 ShowstreamAction
28 {
29     var $notice, $peopletag;
30
31     protected function doStreamPreparation()
32     {
33         $tag = common_canonical_tag($this->arg('tag'));
34         try {
35             $this->peopletag = Profile_list::getByPK(array('tagger' => $this->target->getID(), 'tag' => $tag));
36         } catch (NoResultException $e) {
37             // TRANS: Client error displayed trying to reference a non-existing list.
38             throw new ClientException('No such list.');
39         }
40
41         if ($this->peopletag->private && !$this->peopletag->getTagger()->sameAs($this->scoped)) {
42             // TRANS: Client error displayed trying to reference a non-existing list.
43             throw new AuthorizationException('You do not have permission to see this list.');
44         }
45     }
46
47     public function getStream()
48     {
49         return new PeopletagNoticeStream($this->peopletag, $this->scoped);
50     }
51
52     function title()
53     {
54         if ($this->page > 1) {
55             if($this->peopletag->private) {
56                 // TRANS: Title for private list timeline.
57                 // TRANS: %1$s is a list, %2$s is a page number.
58                 return sprintf(_('Private timeline for %1$s list by you, page %2$d'),
59                                 $this->peopletag->tag, $this->page);
60             }
61
62             $current = common_current_user();
63             if (!empty($current) && $current->id == $this->peopletag->tagger) {
64                 // TRANS: Title for public list timeline where the viewer is the tagger.
65                 // TRANS: %1$s is a list, %2$s is a page number.
66                 return sprintf(_('Timeline for %1$s list by you, page %2$d'),
67                                 $this->peopletag->tag, $this->page);
68             }
69
70             // TRANS: Title for private list timeline.
71             // TRANS: %1$s is a list, %2$s is the tagger's nickname, %3$d is a page number.
72             return sprintf(_('Timeline for %1$s list by %2$s, page %3$d'),
73                                 $this->peopletag->tag,
74                                 $this->target->getNickname(),
75                                 $this->page
76                           );
77         } else {
78             if($this->peopletag->private) {
79                 // TRANS: Title for private list timeline.
80                 // TRANS: %s is a list.
81                 return sprintf(_('Private timeline of %s list by you'),
82                                 $this->peopletag->tag);
83             }
84
85             $current = common_current_user();
86             if (!empty($current) && $current->id == $this->peopletag->tagger) {
87                 // TRANS: Title for public list timeline where the viewer is the tagger.
88                 // TRANS: %s is a list.
89                 return sprintf(_('Timeline for %s list by you'),
90                                 $this->peopletag->tag);
91             }
92
93             // TRANS: Title for private list timeline.
94             // TRANS: %1$s is a list, %2$s is the tagger's nickname.
95             return sprintf(_('Timeline for %1$s list by %2$s'),
96                                 $this->peopletag->tag,
97                                 $this->target->getNickname()
98                           );
99         }
100     }
101
102     function getFeeds()
103     {
104         #XXX: make these actually work
105         return array(new Feed(Feed::JSON,
106                 common_local_url(
107                     'ApiTimelineList', array(
108                         'user' => $this->target->id,
109                         'id' => $this->peopletag->id,
110                         'format' => 'as'
111                     )
112                 ),
113                 // TRANS: Feed title.
114                 // TRANS: %s is tagger's nickname.
115                 sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->target->getNickname())),
116                 new Feed(Feed::RSS2,
117                 common_local_url(
118                     'ApiTimelineList', array(
119                         'user' => $this->target->id,
120                         'id' => $this->peopletag->id,
121                         'format' => 'rss'
122                     )
123                 ),
124                 // TRANS: Feed title.
125                 // TRANS: %s is tagger's nickname.
126                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->target->getNickname())),
127             new Feed(Feed::ATOM,
128                 common_local_url(
129                     'ApiTimelineList', array(
130                         'user' => $this->target->id,
131                         'id' => $this->peopletag->id,
132                         'format' => 'atom'
133                     )
134                 ),
135                 // TRANS: Feed title.
136                 // TRANS: %1$s is a list, %2$s is tagger's nickname.
137                 sprintf(_('Feed for %1$s list by %2$s (Atom)'),
138                             $this->peopletag->tag, $this->target->getNickname()
139                        )
140               )
141         );
142     }
143
144     function showObjectNav()
145     {
146         $nav = new PeopletagGroupNav($this);
147         $nav->show();
148     }
149
150     function showEmptyListMessage()
151     {
152         // TRANS: Empty list message for list timeline.
153         // TRANS: %1$s is a list, %2$s is a tagger's nickname.
154         $message = sprintf(_('This is the timeline for %1$s list by %2$s but no one has posted anything yet.'),
155                            $this->peopletag->tag,
156                            $this->target->getNickname()) . ' ';
157
158         if (common_logged_in()) {
159             if ($this->target->sameAs($this->scoped)) {
160                 // TRANS: Additional empty list message for list timeline for currently logged in user tagged tags.
161                 $message .= _('Try tagging more people.');
162             }
163         } else {
164             // TRANS: Additional empty list message for list timeline.
165             // TRANS: This message contains Markdown links in the form [description](link).
166             $message .= _('Why not [register an account](%%%%action.register%%%%) and start following this timeline!');
167         }
168
169         $this->elementStart('div', 'guide');
170         $this->raw(common_markup_to_html($message));
171         $this->elementEnd('div');
172     }
173
174     protected function showContent()
175     {
176         $this->showPeopletag();
177         parent::showContent();
178     }
179
180     function showPeopletag()
181     {
182         $tag = new Peopletag($this->peopletag, $this->scoped, $this);
183         $tag->show();
184     }
185
186     function showNotices()
187     {
188         if (Event::handle('StartShowProfileTagContent', array($this))) {
189             $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
190
191             $cnt = $nl->show();
192
193             if (0 == $cnt) {
194                 $this->showEmptyListMessage();
195             }
196
197             $this->pagination($this->page > 1,
198                               $cnt > NOTICES_PER_PAGE,
199                               $this->page,
200                               'showprofiletag',
201                               array('tag' => $this->peopletag->tag,
202                                     'nickname' => $this->target->getNickname())
203             );
204
205             Event::handle('EndShowProfileTagContent', array($this));
206         }
207     }
208
209     function showSections()
210     {
211         $this->showTagged();
212         if (!$this->peopletag->private) {
213             $this->showSubscribers();
214         }
215         # $this->showStatistics();
216     }
217
218     function showTagged()
219     {
220         $profile = $this->peopletag->getTagged(0, PROFILES_PER_MINILIST + 1);
221
222         $this->elementStart('div', array('id' => 'entity_tagged',
223                                          'class' => 'section'));
224         if (Event::handle('StartShowTaggedProfilesMiniList', array($this))) {
225             $title = '';
226
227             // TRANS: Header on show list page.
228             $this->element('h2', null, _('Listed'));
229
230             $cnt = 0;
231
232             if (!empty($profile)) {
233                 $pml = new ProfileMiniList($profile, $this);
234                 $cnt = $pml->show();
235                 if ($cnt == 0) {
236                     // TRANS: Content of "Listed" page if there are no listed users.
237                     $this->element('p', null, _('(None)'));
238                 }
239             }
240
241             if ($cnt > PROFILES_PER_MINILIST) {
242                 $this->elementStart('p');
243                 $this->element('a', array('href' => common_local_url('taggedprofiles',
244                                                                      array('nickname' => $this->target->getNickname(),
245                                                                            'profiletag' => $this->peopletag->tag)),
246                                           'class' => 'more'),
247                                // TRANS: Link for more "People in list x by a user"
248                                // TRANS: if there are more than the mini list's maximum.
249                                _('Show all'));
250                 $this->elementEnd('p');
251             }
252
253             Event::handle('EndShowTaggedProfilesMiniList', array($this));
254         }
255         $this->elementEnd('div');
256     }
257
258     function showSubscribers()
259     {
260         $profile = $this->peopletag->getSubscribers(0, PROFILES_PER_MINILIST + 1);
261
262         $this->elementStart('div', array('id' => 'entity_subscribers',
263                                          'class' => 'section'));
264         if (Event::handle('StartShowProfileTagSubscribersMiniList', array($this))) {
265             // TRANS: Header for tag subscribers.
266             $this->element('h2', null, _('Subscribers'));
267
268             $cnt = 0;
269
270             if (!empty($profile)) {
271                 $pml = new ProfileMiniList($profile, $this);
272                 $cnt = $pml->show();
273                 if ($cnt == 0) {
274                     // TRANS: Content of "People following tag x" if there are no subscribed users.
275                     $this->element('p', null, _('(None)'));
276                 }
277             }
278
279             // FIXME: link to full list
280
281             Event::handle('EndShowProfileTagSubscribersMiniList', array($this));
282         }
283         $this->elementEnd('div');
284     }
285 }