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