]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
8e8b055b4b4749b3a51ad7248963386bb4aecccc
[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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * User profile page
35  *
36  * When I created this page, "show stream" seemed like the best name for it.
37  * Now, it seems like a really bad name.
38  *
39  * It shows a stream of the user's posts, plus lots of profile info, links
40  * to subscriptions and stuff, etc.
41  *
42  * @category Personal
43  * @package  StatusNet
44  * @author   Evan Prodromou <evan@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46  * @link     http://status.net/
47  */
48 class ShowstreamAction extends ProfileAction
49 {
50     var $notice;
51
52     protected function doPreparation()
53     {
54         // showstream requires a nickname
55         $nickname_arg = $this->arg('nickname');
56         $nickname     = common_canonical_nickname($nickname_arg);
57
58         // Permanent redirect on non-canonical nickname
59
60         if ($nickname_arg != $nickname) {
61             $args = array('nickname' => $nickname);
62             if ($this->arg('page') && $this->arg('page') != 1) {
63                 $args['page'] = $this->arg['page'];
64             }
65             common_redirect(common_local_url($this->getActionName(), $args), 301);
66         }
67         $this->user = User::getKV('nickname', $nickname);
68
69         if (!$this->user) {
70             $group = Local_group::getKV('nickname', $nickname);
71             if ($group instanceof Local_group) {
72                 common_redirect($group->getProfile()->getUrl());
73             }
74             // TRANS: Client error displayed when calling a profile action without specifying a user.
75             $this->clientError(_('No such user.'), 404);
76         }
77
78         $this->target = $this->user->getProfile();
79     }
80
81     protected function profileActionPreparation()
82     {
83         $stream = $this->getStream();
84         $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
85
86         if ($this->page > 1 && $this->notice->N == 0) {
87             // TRANS: Client error when page not found (404).
88             $this->clientError(_('No such page.'), 404);
89         }
90     }
91
92     protected function getStream()
93     {
94         if (empty($this->tag)) {
95             $stream = new ProfileNoticeStream($this->target, $this->scoped);
96         } else {
97             $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
98         }
99
100         return $stream;
101     }
102
103
104     function title()
105     {
106         $base = $this->target->getFancyName();
107         if (!empty($this->tag)) {
108             if ($this->page == 1) {
109                 // TRANS: Page title showing tagged notices in one user's timeline.
110                 // TRANS: %1$s is the username, %2$s is the hash tag.
111                 return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
112             } else {
113                 // TRANS: Page title showing tagged notices in one user's timeline.
114                 // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
115                 return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
116             }
117         } else {
118             if ($this->page == 1) {
119                 return $base;
120             } else {
121                 // TRANS: Extended page title showing tagged notices in one user's timeline.
122                 // TRANS: %1$s is the username, %2$d is the page number.
123                 return sprintf(_('Notices by %1$s, page %2$d'),
124                                $base,
125                                $this->page);
126             }
127         }
128     }
129
130     function showContent()
131     {
132         $this->showNotices();
133     }
134
135     function showProfileBlock()
136     {
137         $block = new AccountProfileBlock($this, $this->target);
138         $block->show();
139     }
140
141     function showPageNoticeBlock()
142     {
143         return;
144     }
145
146     function getFeeds()
147     {
148         if (!empty($this->tag)) {
149             return array(new Feed(Feed::RSS1,
150                                   common_local_url('userrss',
151                                                    array('nickname' => $this->target->getNickname(),
152                                                          'tag' => $this->tag)),
153                                   // TRANS: Title for link to notice feed.
154                                   // TRANS: %1$s is a user nickname, %2$s is a hashtag.
155                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
156                                           $this->target->getNickname(), $this->tag)));
157         }
158
159         return array(new Feed(Feed::JSON,
160                               common_local_url('ApiTimelineUser',
161                                                array(
162                                                     'id' => $this->target->getID(),
163                                                     'format' => 'as')),
164                               // TRANS: Title for link to notice feed.
165                               // TRANS: %s is a user nickname.
166                               sprintf(_('Notice feed for %s (Activity Streams JSON)'),
167                                       $this->target->getNickname())),
168                      new Feed(Feed::RSS1,
169                               common_local_url('userrss',
170                                                array('nickname' => $this->target->getNickname())),
171                               // TRANS: Title for link to notice feed.
172                               // TRANS: %s is a user nickname.
173                               sprintf(_('Notice feed for %s (RSS 1.0)'),
174                                       $this->target->getNickname())),
175                      new Feed(Feed::RSS2,
176                               common_local_url('ApiTimelineUser',
177                                                array(
178                                                     'id' => $this->target->getID(),
179                                                     'format' => 'rss')),
180                               // TRANS: Title for link to notice feed.
181                               // TRANS: %s is a user nickname.
182                               sprintf(_('Notice feed for %s (RSS 2.0)'),
183                                       $this->target->getNickname())),
184                      new Feed(Feed::ATOM,
185                               common_local_url('ApiTimelineUser',
186                                                array(
187                                                     'id' => $this->target->getID(),
188                                                     'format' => 'atom')),
189                               // TRANS: Title for link to notice feed.
190                               // TRANS: %s is a user nickname.
191                               sprintf(_('Notice feed for %s (Atom)'),
192                                       $this->target->getNickname())),
193                      new Feed(Feed::FOAF,
194                               common_local_url('foaf', array('nickname' =>
195                                                              $this->target->getNickname())),
196                               // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
197                               // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
198                               sprintf(_('FOAF for %s'), $this->target->getNickname())));
199     }
200
201     function extraHead()
202     {
203         if ($this->target->bio) {
204             $this->element('meta', array('name' => 'description',
205                                          'content' => $this->target->getDescription()));
206         }
207
208         if ($this->target->isLocal() && $this->target->getUser()->emailmicroid && $this->target->getUser()->email && $this->target->getUrl()) {
209             $id = new Microid('mailto:'.$this->target->getUser()->email,
210                               $this->selfUrl());
211             $this->element('meta', array('name' => 'microid',
212                                          'content' => $id->toString()));
213         }
214
215         // See https://wiki.mozilla.org/Microsummaries
216
217         $this->element('link', array('rel' => 'microsummary',
218                                      'href' => common_local_url('microsummary',
219                                                                 array('nickname' => $this->target->getNickname()))));
220
221         $rsd = common_local_url('rsd',
222                                 array('nickname' => $this->target->getNickname()));
223
224         // RSD, http://tales.phrasewise.com/rfc/rsd
225         $this->element('link', array('rel' => 'EditURI',
226                                      'type' => 'application/rsd+xml',
227                                      'href' => $rsd));
228
229         if ($this->page != 1) {
230             $this->element('link', array('rel' => 'canonical',
231                                          'href' => $this->target->getUrl()));
232         }
233     }
234
235     function showEmptyListMessage()
236     {
237         // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
238         $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
239
240         if ($this->scoped instanceof Profile) {
241             if ($this->target->getID() === $this->scoped->getID()) {
242                 // TRANS: Second sentence of empty list message for a stream for the user themselves.
243                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
244             } else {
245                 // 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.
246                 // TRANS: This message contains a Markdown link. Keep "](" together.
247                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
248             }
249         }
250         else {
251             // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
252             // TRANS: This message contains a Markdown link. Keep "](" together.
253             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
254         }
255
256         $this->elementStart('div', 'guide');
257         $this->raw(common_markup_to_html($message));
258         $this->elementEnd('div');
259     }
260
261     function showNotices()
262     {
263         $pnl = new NoticeList($this->notice, $this);
264         $cnt = $pnl->show();
265         if (0 == $cnt) {
266             $this->showEmptyListMessage();
267         }
268
269         $args = array('nickname' => $this->target->getNickname());
270         if (!empty($this->tag))
271         {
272             $args['tag'] = $this->tag;
273         }
274         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
275                           'showstream', $args);
276     }
277
278     function showAnonymousMessage()
279     {
280         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
281             // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
282             // TRANS: This message contains a Markdown link. Keep "](" together.
283             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
284                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
285                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
286                          $this->target->getNickname(), $this->target->getNickname());
287         } else {
288             // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
289             // TRANS: This message contains a Markdown link. Keep "](" together.
290             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
291                            'based on the Free Software [StatusNet](http://status.net/) tool.'),
292                          $this->target->getNickname(), $this->target->getNickname());
293         }
294         $this->elementStart('div', array('id' => 'anon_notice'));
295         $this->raw(common_markup_to_html($m));
296         $this->elementEnd('div');
297     }
298
299     function showSections()
300     {
301         parent::showSections();
302         if (!common_config('performance', 'high')) {
303             $cloud = new PersonalTagCloudSection($this, $this->user);
304             $cloud->show();
305         }
306     }
307
308     function noticeFormOptions()
309     {
310         $options = parent::noticeFormOptions();
311
312         if (!$this->scoped instanceof Profile || $this->scoped->id != $this->target->id) {
313             $options['to_profile'] =  $this->target;
314         }
315
316         return $options;
317     }
318 }