]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Fix some ProfileAction stuff, add function profileActionPreparation
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User profile page
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36 require_once INSTALLDIR.'/lib/noticelist.php';
37 require_once INSTALLDIR.'/lib/profileminilist.php';
38 require_once INSTALLDIR.'/lib/groupminilist.php';
39 require_once INSTALLDIR.'/lib/feedlist.php';
40
41 /**
42  * User profile page
43  *
44  * When I created this page, "show stream" seemed like the best name for it.
45  * Now, it seems like a really bad name.
46  *
47  * It shows a stream of the user's posts, plus lots of profile info, links
48  * to subscriptions and stuff, etc.
49  *
50  * @category Personal
51  * @package  StatusNet
52  * @author   Evan Prodromou <evan@status.net>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://status.net/
55  */
56 class ShowstreamAction extends ProfileAction
57 {
58     var $notice;
59
60     protected function profileActionPreparation()
61     {
62         if (empty($this->tag)) {
63             $stream = new ProfileNoticeStream($this->target, $this->scoped);
64         } else {
65             $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
66         }
67
68         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
69
70         return true;
71     }
72
73
74     function title()
75     {
76         $base = $this->target->getFancyName();
77         if (!empty($this->tag)) {
78             if ($this->page == 1) {
79                 // TRANS: Page title showing tagged notices in one user's timeline.
80                 // TRANS: %1$s is the username, %2$s is the hash tag.
81                 return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
82             } else {
83                 // TRANS: Page title showing tagged notices in one user's timeline.
84                 // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
85                 return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
86             }
87         } else {
88             if ($this->page == 1) {
89                 return $base;
90             } else {
91                 // TRANS: Extended page title showing tagged notices in one user's timeline.
92                 // TRANS: %1$s is the username, %2$d is the page number.
93                 return sprintf(_('Notices by %1$s, page %2$d'),
94                                $base,
95                                $this->page);
96             }
97         }
98     }
99
100     function showContent()
101     {
102         $this->showNotices();
103     }
104
105     function showProfileBlock()
106     {
107         $block = new AccountProfileBlock($this, $this->target);
108         $block->show();
109     }
110
111     function showPageNoticeBlock()
112     {
113         return;
114     }
115
116     function getFeeds()
117     {
118         if (!empty($this->tag)) {
119             return array(new Feed(Feed::RSS1,
120                                   common_local_url('userrss',
121                                                    array('nickname' => $this->target->getNickname(),
122                                                          'tag' => $this->tag)),
123                                   // TRANS: Title for link to notice feed.
124                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
125                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
126                                           $this->target->getNickname(), $this->tag)));
127         }
128
129         return array(new Feed(Feed::JSON,
130                               common_local_url('ApiTimelineUser',
131                                                array(
132                                                     'id' => $this->user->id,
133                                                     'format' => 'as')),
134                               // TRANS: Title for link to notice feed.
135                               // TRANS: %s is a user nickname.
136                               sprintf(_('Notice feed for %s (Activity Streams JSON)'),
137                                       $this->target->getNickname())),
138                      new Feed(Feed::RSS1,
139                               common_local_url('userrss',
140                                                array('nickname' => $this->target->getNickname())),
141                               // TRANS: Title for link to notice feed.
142                               // TRANS: %s is a user nickname.
143                               sprintf(_('Notice feed for %s (RSS 1.0)'),
144                                       $this->target->getNickname())),
145                      new Feed(Feed::RSS2,
146                               common_local_url('ApiTimelineUser',
147                                                array(
148                                                     'id' => $this->user->id,
149                                                     'format' => 'rss')),
150                               // TRANS: Title for link to notice feed.
151                               // TRANS: %s is a user nickname.
152                               sprintf(_('Notice feed for %s (RSS 2.0)'),
153                                       $this->target->getNickname())),
154                      new Feed(Feed::ATOM,
155                               common_local_url('ApiTimelineUser',
156                                                array(
157                                                     'id' => $this->user->id,
158                                                     'format' => 'atom')),
159                               // TRANS: Title for link to notice feed.
160                               // TRANS: %s is a user nickname.
161                               sprintf(_('Notice feed for %s (Atom)'),
162                                       $this->target->getNickname())),
163                      new Feed(Feed::FOAF,
164                               common_local_url('foaf', array('nickname' =>
165                                                              $this->target->getNickname())),
166                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
167                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
168                               sprintf(_('FOAF for %s'), $this->target->getNickname())));
169     }
170
171     function extraHead()
172     {
173         if ($this->target->bio) {
174             $this->element('meta', array('name' => 'description',
175                                          'content' => $this->target->getDescription()));
176         }
177
178         if ($this->target->isLocal() && $this->target->getUser()->emailmicroid && $this->target->getUser()->email && $this->target->getUrl()) {
179             $id = new Microid('mailto:'.$this->target->getUser()->email,
180                               $this->selfUrl());
181             $this->element('meta', array('name' => 'microid',
182                                          'content' => $id->toString()));
183         }
184
185         // See https://wiki.mozilla.org/Microsummaries
186
187         $this->element('link', array('rel' => 'microsummary',
188                                      'href' => common_local_url('microsummary',
189                                                                 array('nickname' => $this->target->getNickname()))));
190
191         $rsd = common_local_url('rsd',
192                                 array('nickname' => $this->target->getNickname()));
193
194         // RSD, http://tales.phrasewise.com/rfc/rsd
195         $this->element('link', array('rel' => 'EditURI',
196                                      'type' => 'application/rsd+xml',
197                                      'href' => $rsd));
198
199         if ($this->page != 1) {
200             $this->element('link', array('rel' => 'canonical',
201                                          'href' => $this->target->getUrl()));
202         }
203     }
204
205     function showEmptyListMessage()
206     {
207         // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
208         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->nickname) . ' ';
209
210         if (common_logged_in()) {
211             $current_user = common_current_user();
212             if ($this->user->id === $current_user->id) {
213                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
214                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
215             } else {
216                 // TRANS: Second sentence of empty  list message for a non-self timeline. %1$s is a user nickname, %2$s is a part of a URL.
217                 // TRANS: This message contains a Markdown link. Keep "](" together.
218                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->nickname, '@' . $this->target->nickname);
219             }
220         }
221         else {
222             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
223             // TRANS: This message contains a Markdown link. Keep "](" together.
224             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->nickname);
225         }
226
227         $this->elementStart('div', 'guide');
228         $this->raw(common_markup_to_html($message));
229         $this->elementEnd('div');
230     }
231
232     function showNotices()
233     {
234         $pnl = null;
235         if (Event::handle('ShowStreamNoticeList', array($this->notice, $this, &$pnl))) {
236             $pnl = new ProfileNoticeList($this->notice, $this);
237         }
238         $cnt = $pnl->show();
239         if (0 == $cnt) {
240             $this->showEmptyListMessage();
241         }
242
243         $args = array('nickname' => $this->target->nickname);
244         if (!empty($this->tag))
245         {
246             $args['tag'] = $this->tag;
247         }
248         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
249                           'showstream', $args);
250     }
251
252     function showAnonymousMessage()
253     {
254         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
255             // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
256             // TRANS: This message contains a Markdown link. Keep "](" together.
257             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
258                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
259                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
260                          $this->target->nickname, $this->target->nickname);
261         } else {
262             // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
263             // TRANS: This message contains a Markdown link. Keep "](" together.
264             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
265                            'based on the Free Software [StatusNet](http://status.net/) tool.'),
266                          $this->target->nickname, $this->target->nickname);
267         }
268         $this->elementStart('div', array('id' => 'anon_notice'));
269         $this->raw(common_markup_to_html($m));
270         $this->elementEnd('div');
271     }
272
273     function showSections()
274     {
275         parent::showSections();
276         if (!common_config('performance', 'high')) {
277             $cloud = new PersonalTagCloudSection($this, $this->user);
278             $cloud->show();
279         }
280     }
281
282     function noticeFormOptions()
283     {
284         $options = parent::noticeFormOptions();
285
286         if (!$this->scoped instanceof Profile || $this->scoped->id != $this->target->id) {
287             $options['to_profile'] =  $this->target;
288         }
289
290         return $options;
291     }
292 }
293
294 // We don't show the author for a profile, since we already know who it is!
295
296 /**
297  * Slightly modified from standard list; the author & avatar are hidden
298  * in CSS. We used to remove them here too, but as it turns out that
299  * confuses the inline reply code... and we hide them in CSS anyway
300  * since realtime updates come through in original form.
301  *
302  * Remaining customization right now is for the repeat marker, where
303  * it'll list who the original poster was instead of who did the repeat
304  * (since the repeater is you, and the repeatee isn't shown!)
305  * This will remain inconsistent if realtime updates come through,
306  * since those'll get rendered as a regular NoticeListItem.
307  */
308 class ProfileNoticeList extends NoticeList
309 {
310     function newListItem($notice)
311     {
312         return new ProfileNoticeListItem($notice, $this->out);
313     }
314 }
315
316 class ProfileNoticeListItem extends DoFollowListItem
317 {
318     /**
319      * show a link to the author of repeat
320      *
321      * @return void
322      */
323     function showRepeat()
324     {
325         if (!empty($this->repeat)) {
326
327             // FIXME: this code is almost identical to default; need to refactor
328
329             $attrs = array();
330             if (!empty($this->target->fullname)) {
331                 $attrs['title'] = $this->target->getFullname();
332             }
333
334             try {
335                 $attrs = array('href' => $this->target->getUrl(),
336                                'class' => 'url');
337                 $text_tag = 'a';
338             } catch (InvalidUrlException $e) {
339                 $text_tag = 'abbr';
340             }
341
342             $this->out->elementStart('span', 'repeat');
343             $text_link = XMLStringer::estring($text_tag, $attrs, $this->target->getNickname());
344             // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
345             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
346             $this->out->elementEnd('span');
347         }
348     }
349 }