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