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