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