]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x
[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/userprofile.php';
37 require_once INSTALLDIR.'/lib/noticelist.php';
38 require_once INSTALLDIR.'/lib/profileminilist.php';
39 require_once INSTALLDIR.'/lib/groupminilist.php';
40 require_once INSTALLDIR.'/lib/feedlist.php';
41
42 /**
43  * User profile page
44  *
45  * When I created this page, "show stream" seemed like the best name for it.
46  * Now, it seems like a really bad name.
47  *
48  * It shows a stream of the user's posts, plus lots of profile info, links
49  * to subscriptions and stuff, etc.
50  *
51  * @category Personal
52  * @package  StatusNet
53  * @author   Evan Prodromou <evan@status.net>
54  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
55  * @link     http://status.net/
56  */
57 class ShowstreamAction extends ProfileAction
58 {
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     function title()
65     {
66         $base = $this->profile->getFancyName();
67         if (!empty($this->tag)) {
68             if ($this->page == 1) {
69                 // TRANS: Page title showing tagged notices in one user's stream. %1$s is the username, %2$s is the hash tag.
70                 return sprintf(_('%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, %1$d is the page number.
74                 return sprintf(_('%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(_('%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->showProfile();
104         $this->showNotices();
105     }
106
107     function showLocalNav()
108     {
109         $nav = new PersonalGroupNav($this);
110         $nav->show();
111     }
112
113     function showPageNoticeBlock()
114     {
115         return;
116     }
117
118     function getFeeds()
119     {
120         if (!empty($this->tag)) {
121             return array(new Feed(Feed::RSS1,
122                                   common_local_url('userrss',
123                                                    array('nickname' => $this->user->nickname,
124                                                          'tag' => $this->tag)),
125                                   // TRANS: Title for link to notice feed.
126                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
127                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
128                                           $this->user->nickname, $this->tag)));
129         }
130
131         return array(new Feed(Feed::RSS1,
132                               common_local_url('userrss',
133                                                array('nickname' => $this->user->nickname)),
134                               // TRANS: Title for link to notice feed.
135                               // TRANS: %s is a user nickname.
136                               sprintf(_('Notice feed for %s (RSS 1.0)'),
137                                       $this->user->nickname)),
138                      new Feed(Feed::RSS2,
139                               common_local_url('ApiTimelineUser',
140                                                array(
141                                                     'id' => $this->user->id,
142                                                     'format' => 'rss')),
143                               // TRANS: Title for link to notice feed.
144                               // TRANS: %s is a user nickname.
145                               sprintf(_('Notice feed for %s (RSS 2.0)'),
146                                       $this->user->nickname)),
147                      new Feed(Feed::ATOM,
148                               common_local_url('ApiTimelineUser',
149                                                array(
150                                                     'id' => $this->user->id,
151                                                     'format' => 'atom')),
152                               sprintf(_('Notice feed for %s (Atom)'),
153                                       $this->user->nickname)),
154                      new Feed(Feed::FOAF,
155                               common_local_url('foaf', array('nickname' =>
156                                                              $this->user->nickname)),
157                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
158                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
159                               sprintf(_('FOAF for %s'), $this->user->nickname)));
160     }
161
162     function extraHead()
163     {
164         // for remote subscriptions etc.
165         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
166                                      'content' => common_local_url('xrds', array('nickname' =>
167                                                                                  $this->user->nickname))));
168
169         if ($this->profile->bio) {
170             $this->element('meta', array('name' => 'description',
171                                          'content' => $this->profile->bio));
172         }
173
174         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
175             $id = new Microid('mailto:'.$this->user->email,
176                               $this->selfUrl());
177             $this->element('meta', array('name' => 'microid',
178                                          'content' => $id->toString()));
179         }
180         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
181             $id = new Microid('xmpp:'.$this->user->jabber,
182                               $this->selfUrl());
183             $this->element('meta', array('name' => 'microid',
184                                          'content' => $id->toString()));
185         }
186
187         // See https://wiki.mozilla.org/Microsummaries
188
189         $this->element('link', array('rel' => 'microsummary',
190                                      'href' => common_local_url('microsummary',
191                                                                 array('nickname' => $this->profile->nickname))));
192
193         $rsd = common_local_url('rsd',
194                                 array('nickname' => $this->profile->nickname));
195
196         // RSD, http://tales.phrasewise.com/rfc/rsd
197         $this->element('link', array('rel' => 'EditURI',
198                                      'type' => 'application/rsd+xml',
199                                      'href' => $rsd));
200     }
201
202     function showProfile()
203     {
204         $profile = new UserProfile($this, $this->user, $this->profile);
205         $profile->show();
206     }
207
208     function showEmptyListMessage()
209     {
210         // TRANS: First sentence of empty list message for a stream. $1%s is a user nickname.
211         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->user->nickname) . ' ';
212
213         if (common_logged_in()) {
214             $current_user = common_current_user();
215             if ($this->user->id === $current_user->id) {
216                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
217                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
218             } else {
219                 // 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.
220                 // TRANS: This message contains a Markdown link. Keep "](" together.
221                 $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);
222             }
223         }
224         else {
225             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
226             // TRANS: This message contains a Markdown link. Keep "](" together.
227             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
228         }
229
230         $this->elementStart('div', 'guide');
231         $this->raw(common_markup_to_html($message));
232         $this->elementEnd('div');
233     }
234
235     function showNotices()
236     {
237         $notice = empty($this->tag)
238           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
239             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
240
241         $pnl = null;
242         if (Event::handle('ShowStreamNoticeList', array($notice, $this, &$pnl))) {
243             $pnl = new ProfileNoticeList($notice, $this);
244         }
245         $cnt = $pnl->show();
246         if (0 == $cnt) {
247             $this->showEmptyListMessage();
248         }
249
250         $args = array('nickname' => $this->user->nickname);
251         if (!empty($this->tag))
252         {
253             $args['tag'] = $this->tag;
254         }
255         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
256                           'showstream', $args);
257     }
258
259     function showAnonymousMessage()
260     {
261         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
262             // TRANS: Announcement for anonymous users showing a stream if site registrations are open.
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                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
267                          $this->user->nickname, $this->user->nickname);
268         } else {
269             // TRANS: Announcement for anonymous users showing a stream if site registrations are closed or invite only.
270             // TRANS: This message contains a Markdown link. Keep "](" together.
271             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
272                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
273                          $this->user->nickname, $this->user->nickname);
274         }
275         $this->elementStart('div', array('id' => 'anon_notice'));
276         $this->raw(common_markup_to_html($m));
277         $this->elementEnd('div');
278     }
279
280     function showSections()
281     {
282         parent::showSections();
283         $cloud = new PersonalTagCloudSection($this, $this->user);
284         $cloud->show();
285     }
286 }
287
288 // We don't show the author for a profile, since we already know who it is!
289
290 class ProfileNoticeList extends NoticeList
291 {
292     function newListItem($notice)
293     {
294         return new ProfileNoticeListItem($notice, $this->out);
295     }
296 }
297
298 class ProfileNoticeListItem extends DoFollowListItem
299 {
300     function showAuthor()
301     {
302         return;
303     }
304
305     /**
306      * show a link to the author of repeat
307      *
308      * @return void
309      */
310     function showRepeat()
311     {
312         if (!empty($this->repeat)) {
313
314             // FIXME: this code is almost identical to default; need to refactor
315
316             $attrs = array('href' => $this->profile->profileurl,
317                            'class' => 'url');
318
319             if (!empty($this->profile->fullname)) {
320                 $attrs['title'] = $this->getFancyName();
321             }
322
323             $this->out->elementStart('span', 'repeat');
324
325             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
326
327             // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
328             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
329
330             $this->out->elementEnd('span');
331         }
332     }
333 }