]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into prefillbookmark
[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     function isReadOnly($args)
59     {
60         return true;
61     }
62
63     function title()
64     {
65         $base = $this->profile->getFancyName();
66         if (!empty($this->tag)) {
67             if ($this->page == 1) {
68                 // TRANS: Page title showing tagged notices in one user's stream.
69                 // TRANS: %1$s is the username, %2$s is the hash tag.
70                 return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
71             } else {
72                 // TRANS: Page title showing tagged notices in one user's stream.
73                 // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
74                 return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
75             }
76         } else {
77             if ($this->page == 1) {
78                 return $base;
79             } else {
80                 // TRANS: Extended page title showing tagged notices in one user's stream.
81                 // TRANS: %1$s is the username, %2$d is the page number.
82                 return sprintf(_('Notices by %1$s, page %2$d'),
83                                $base,
84                                $this->page);
85             }
86         }
87     }
88
89     function handle($args)
90     {
91         // Looks like we're good; start output
92
93         // For YADIS discovery, we also have a <meta> tag
94
95         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
96                                                                    $this->user->nickname)));
97
98         $this->showPage();
99     }
100
101     function showContent()
102     {
103         $this->showNotices();
104     }
105
106     function showProfileBlock()
107     {
108         $block = new AccountProfileBlock($this, $this->profile);
109         $block->show();
110     }
111
112     function showPageNoticeBlock()
113     {
114         return;
115     }
116
117     function getFeeds()
118     {
119         if (!empty($this->tag)) {
120             return array(new Feed(Feed::RSS1,
121                                   common_local_url('userrss',
122                                                    array('nickname' => $this->user->nickname,
123                                                          'tag' => $this->tag)),
124                                   // TRANS: Title for link to notice feed.
125                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
126                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
127                                           $this->user->nickname, $this->tag)));
128         }
129
130         return array(new Feed(Feed::RSS1,
131                               common_local_url('userrss',
132                                                array('nickname' => $this->user->nickname)),
133                               // TRANS: Title for link to notice feed.
134                               // TRANS: %s is a user nickname.
135                               sprintf(_('Notice feed for %s (RSS 1.0)'),
136                                       $this->user->nickname)),
137                      new Feed(Feed::RSS2,
138                               common_local_url('ApiTimelineUser',
139                                                array(
140                                                     'id' => $this->user->id,
141                                                     'format' => 'rss')),
142                               // TRANS: Title for link to notice feed.
143                               // TRANS: %s is a user nickname.
144                               sprintf(_('Notice feed for %s (RSS 2.0)'),
145                                       $this->user->nickname)),
146                      new Feed(Feed::ATOM,
147                               common_local_url('ApiTimelineUser',
148                                                array(
149                                                     'id' => $this->user->id,
150                                                     'format' => 'atom')),
151                               // TRANS: Title for link to notice feed.
152                               // TRANS: %s is a user nickname.
153                               sprintf(_('Notice feed for %s (Atom)'),
154                                       $this->user->nickname)),
155                      new Feed(Feed::FOAF,
156                               common_local_url('foaf', array('nickname' =>
157                                                              $this->user->nickname)),
158                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
159                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
160                               sprintf(_('FOAF for %s'), $this->user->nickname)));
161     }
162
163     function extraHead()
164     {
165         // for remote subscriptions etc.
166         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
167                                      'content' => common_local_url('xrds', array('nickname' =>
168                                                                                  $this->user->nickname))));
169
170         if ($this->profile->bio) {
171             $this->element('meta', array('name' => 'description',
172                                          'content' => $this->profile->bio));
173         }
174
175         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
176             $id = new Microid('mailto:'.$this->user->email,
177                               $this->selfUrl());
178             $this->element('meta', array('name' => 'microid',
179                                          'content' => $id->toString()));
180         }
181
182         // See https://wiki.mozilla.org/Microsummaries
183
184         $this->element('link', array('rel' => 'microsummary',
185                                      'href' => common_local_url('microsummary',
186                                                                 array('nickname' => $this->profile->nickname))));
187
188         $rsd = common_local_url('rsd',
189                                 array('nickname' => $this->profile->nickname));
190
191         // RSD, http://tales.phrasewise.com/rfc/rsd
192         $this->element('link', array('rel' => 'EditURI',
193                                      'type' => 'application/rsd+xml',
194                                      'href' => $rsd));
195     }
196
197     function showEmptyListMessage()
198     {
199         // TRANS: First sentence of empty list message for a stream. $1%s is a user nickname.
200         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->user->nickname) . ' ';
201
202         if (common_logged_in()) {
203             $current_user = common_current_user();
204             if ($this->user->id === $current_user->id) {
205                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
206                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
207             } else {
208                 // TRANS: Second sentence of empty  list message for a non-self stream. %1$s is a user nickname, %2$s is a part of a URL.
209                 // TRANS: This message contains a Markdown link. Keep "](" together.
210                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->user->nickname, '@' . $this->user->nickname);
211             }
212         }
213         else {
214             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
215             // TRANS: This message contains a Markdown link. Keep "](" together.
216             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
217         }
218
219         $this->elementStart('div', 'guide');
220         $this->raw(common_markup_to_html($message));
221         $this->elementEnd('div');
222     }
223
224     function showNotices()
225     {
226         $notice = empty($this->tag)
227           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
228             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
229
230         $pnl = null;
231         if (Event::handle('ShowStreamNoticeList', array($notice, $this, &$pnl))) {
232             $pnl = new ProfileNoticeList($notice, $this);
233         }
234         $cnt = $pnl->show();
235         if (0 == $cnt) {
236             $this->showEmptyListMessage();
237         }
238
239         $args = array('nickname' => $this->user->nickname);
240         if (!empty($this->tag))
241         {
242             $args['tag'] = $this->tag;
243         }
244         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
245                           'showstream', $args);
246     }
247
248     function showAnonymousMessage()
249     {
250         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
251             // TRANS: Announcement for anonymous users showing a stream if site registrations are open.
252             // TRANS: This message contains a Markdown link. Keep "](" together.
253             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
254                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
255                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
256                          $this->user->nickname, $this->user->nickname);
257         } else {
258             // TRANS: Announcement for anonymous users showing a stream if site registrations are closed or invite only.
259             // TRANS: This message contains a Markdown link. Keep "](" together.
260             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
261                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
262                          $this->user->nickname, $this->user->nickname);
263         }
264         $this->elementStart('div', array('id' => 'anon_notice'));
265         $this->raw(common_markup_to_html($m));
266         $this->elementEnd('div');
267     }
268
269     function showSections()
270     {
271         parent::showSections();
272         $cloud = new PersonalTagCloudSection($this, $this->user);
273         $cloud->show();
274     }
275
276     function noticeFormOptions()
277     {
278         $options = parent::noticeFormOptions();
279         $cur = common_current_user();
280
281         if (empty($cur) || $cur->id != $this->profile->id) {
282             $options['to_profile'] =  $this->profile;
283         }
284
285         return $options;
286     }
287 }
288
289 // We don't show the author for a profile, since we already know who it is!
290
291 /**
292  * Slightly modified from standard list; the author & avatar are hidden
293  * in CSS. We used to remove them here too, but as it turns out that
294  * confuses the inline reply code... and we hide them in CSS anyway
295  * since realtime updates come through in original form.
296  *
297  * Remaining customization right now is for the repeat marker, where
298  * it'll list who the original poster was instead of who did the repeat
299  * (since the repeater is you, and the repeatee isn't shown!)
300  * This will remain inconsistent if realtime updates come through,
301  * since those'll get rendered as a regular NoticeListItem.
302  */
303 class ProfileNoticeList extends NoticeList
304 {
305     function newListItem($notice)
306     {
307         return new ProfileNoticeListItem($notice, $this->out);
308     }
309 }
310
311 class ProfileNoticeListItem extends DoFollowListItem
312 {
313     /**
314      * show a link to the author of repeat
315      *
316      * @return void
317      */
318     function showRepeat()
319     {
320         if (!empty($this->repeat)) {
321
322             // FIXME: this code is almost identical to default; need to refactor
323
324             $attrs = array('href' => $this->profile->profileurl,
325                            'class' => 'url');
326
327             if (!empty($this->profile->fullname)) {
328                 $attrs['title'] = $this->profile->getFancyName();
329             }
330
331             $this->out->elementStart('span', 'repeat');
332
333             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
334
335             // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
336             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
337
338             $this->out->elementEnd('span');
339         }
340     }
341 }