]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
08f8a3e80e434527fc6dad3653b59773c59d1c25
[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. %1$s is the username, %2$s is the hash tag.
69                 return sprintf(_('%1$s tagged %2$s'), $base, $this->tag);
70             } else {
71                 // TRANS: Page title showing tagged notices in one user's stream.
72                 // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
73                 return sprintf(_('%1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
74             }
75         } else {
76             if ($this->page == 1) {
77                 return $base;
78             } else {
79                 // TRANS: Extended page title showing tagged notices in one user's stream.
80                 // TRANS: %1$s is the username, %2$d is the page number.
81                 return sprintf(_('%1$s, page %2$d'),
82                                $base,
83                                $this->page);
84             }
85         }
86     }
87
88     function handle($args)
89     {
90         // Looks like we're good; start output
91
92         // For YADIS discovery, we also have a <meta> tag
93
94         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
95                                                                    $this->user->nickname)));
96
97         $this->showPage();
98     }
99
100     function showContent()
101     {
102         $this->showNotices();
103     }
104
105     function showObjectNav()
106     {
107         $nav = new SubGroupNav($this, $this->user);
108         $nav->show();
109     }
110
111     function showProfileBlock()
112     {
113         $block = new AccountProfileBlock($this, $this->profile);
114         $block->show();
115     }
116
117     function showPageNoticeBlock()
118     {
119         return;
120     }
121
122     function getFeeds()
123     {
124         if (!empty($this->tag)) {
125             return array(new Feed(Feed::RSS1,
126                                   common_local_url('userrss',
127                                                    array('nickname' => $this->user->nickname,
128                                                          'tag' => $this->tag)),
129                                   // TRANS: Title for link to notice feed.
130                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
131                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
132                                           $this->user->nickname, $this->tag)));
133         }
134
135         return array(new Feed(Feed::RSS1,
136                               common_local_url('userrss',
137                                                array('nickname' => $this->user->nickname)),
138                               // TRANS: Title for link to notice feed.
139                               // TRANS: %s is a user nickname.
140                               sprintf(_('Notice feed for %s (RSS 1.0)'),
141                                       $this->user->nickname)),
142                      new Feed(Feed::RSS2,
143                               common_local_url('ApiTimelineUser',
144                                                array(
145                                                     'id' => $this->user->id,
146                                                     'format' => 'rss')),
147                               // TRANS: Title for link to notice feed.
148                               // TRANS: %s is a user nickname.
149                               sprintf(_('Notice feed for %s (RSS 2.0)'),
150                                       $this->user->nickname)),
151                      new Feed(Feed::ATOM,
152                               common_local_url('ApiTimelineUser',
153                                                array(
154                                                     'id' => $this->user->id,
155                                                     'format' => 'atom')),
156                               sprintf(_('Notice feed for %s (Atom)'),
157                                       $this->user->nickname)),
158                      new Feed(Feed::FOAF,
159                               common_local_url('foaf', array('nickname' =>
160                                                              $this->user->nickname)),
161                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
162                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
163                               sprintf(_('FOAF for %s'), $this->user->nickname)));
164     }
165
166     function extraHead()
167     {
168         // for remote subscriptions etc.
169         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
170                                      'content' => common_local_url('xrds', array('nickname' =>
171                                                                                  $this->user->nickname))));
172
173         if ($this->profile->bio) {
174             $this->element('meta', array('name' => 'description',
175                                          'content' => $this->profile->bio));
176         }
177
178         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
179             $id = new Microid('mailto:'.$this->user->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->profile->nickname))));
190
191         $rsd = common_local_url('rsd',
192                                 array('nickname' => $this->profile->nickname));
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
200     function showEmptyListMessage()
201     {
202         // TRANS: First sentence of empty list message for a stream. $1%s is a user nickname.
203         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->user->nickname) . ' ';
204
205         if (common_logged_in()) {
206             $current_user = common_current_user();
207             if ($this->user->id === $current_user->id) {
208                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
209                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
210             } else {
211                 // 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.
212                 // TRANS: This message contains a Markdown link. Keep "](" together.
213                 $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);
214             }
215         }
216         else {
217             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
218             // TRANS: This message contains a Markdown link. Keep "](" together.
219             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
220         }
221
222         $this->elementStart('div', 'guide');
223         $this->raw(common_markup_to_html($message));
224         $this->elementEnd('div');
225     }
226
227     function showNotices()
228     {
229         $notice = empty($this->tag)
230           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
231             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
232
233         $pnl = null;
234         if (Event::handle('ShowStreamNoticeList', array($notice, $this, &$pnl))) {
235             $pnl = new ProfileNoticeList($notice, $this);
236         }
237         $cnt = $pnl->show();
238         if (0 == $cnt) {
239             $this->showEmptyListMessage();
240         }
241
242         $args = array('nickname' => $this->user->nickname);
243         if (!empty($this->tag))
244         {
245             $args['tag'] = $this->tag;
246         }
247         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
248                           'showstream', $args);
249     }
250
251     function showAnonymousMessage()
252     {
253         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
254             // TRANS: Announcement for anonymous users showing a stream if site registrations are open.
255             // TRANS: This message contains a Markdown link. Keep "](" together.
256             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
257                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
258                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
259                          $this->user->nickname, $this->user->nickname);
260         } else {
261             // TRANS: Announcement for anonymous users showing a stream if site registrations are closed or invite only.
262             // TRANS: This message contains a Markdown link. Keep "](" together.
263             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
264                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
265                          $this->user->nickname, $this->user->nickname);
266         }
267         $this->elementStart('div', array('id' => 'anon_notice'));
268         $this->raw(common_markup_to_html($m));
269         $this->elementEnd('div');
270     }
271
272     function showSections()
273     {
274         parent::showSections();
275         $cloud = new PersonalTagCloudSection($this, $this->user);
276         $cloud->show();
277     }
278 }
279
280 // We don't show the author for a profile, since we already know who it is!
281
282 class ProfileNoticeList extends NoticeList
283 {
284     function newListItem($notice)
285     {
286         return new ProfileNoticeListItem($notice, $this->out);
287     }
288 }
289
290 class ProfileNoticeListItem extends DoFollowListItem
291 {
292     function showAuthor()
293     {
294         return;
295     }
296
297     /**
298      * show a link to the author of repeat
299      *
300      * @return void
301      */
302     function showRepeat()
303     {
304         if (!empty($this->repeat)) {
305
306             // FIXME: this code is almost identical to default; need to refactor
307
308             $attrs = array('href' => $this->profile->profileurl,
309                            'class' => 'url');
310
311             if (!empty($this->profile->fullname)) {
312                 $attrs['title'] = $this->profile->getFancyName();
313             }
314
315             $this->out->elementStart('span', 'repeat');
316
317             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
318
319             // TRANS: Link to the author of a repeated notice. %s is a linked nickname.
320             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
321
322             $this->out->elementEnd('span');
323         }
324     }
325 }