]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Merge branch '0.9.x' of gitorious.org:statusnet/mainline into 1.0.x
[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('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36 require_once INSTALLDIR.'/lib/userprofile.php';
37 require_once INSTALLDIR.'/lib/noticelist.php';
38 require_once INSTALLDIR.'/lib/profileminilist.php';
39 require_once INSTALLDIR.'/lib/groupminilist.php';
40 require_once INSTALLDIR.'/lib/feedlist.php';
41
42 /**
43  * User profile page
44  *
45  * When I created this page, "show stream" seemed like the best name for it.
46  * Now, it seems like a really bad name.
47  *
48  * It shows a stream of the user's posts, plus lots of profile info, links
49  * to subscriptions and stuff, etc.
50  *
51  * @category Personal
52  * @package  StatusNet
53  * @author   Evan Prodromou <evan@status.net>
54  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
55  * @link     http://status.net/
56  */
57 class ShowstreamAction extends ProfileAction
58 {
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     function title()
65     {
66         $base = $this->profile->getFancyName();
67         if (!empty($this->tag)) {
68             if ($this->page == 1) {
69                 // TRANS: Page title showing tagged notices in one user's stream. Param 1 is the username, 2 is the hash tag.
70                 return sprintf(_('%1$s tagged %2$s'), $base, $this->tag);
71             } else {
72                 // TRANS: Page title showing tagged notices in one user's stream. Param 1 is the username, 2 is the hash tag, 3 is the page number.
73                 return sprintf(_('%1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
74             }
75         } else {
76             if ($this->page == 1) {
77                 return $base;
78             } else {
79                 // TRANS: Extended page title showing tagged notices in one user's stream. Param 1 is the username, param 2 is the page number.
80                 return sprintf(_('%1$s, page %2$d'),
81                                $base,
82                                $this->page);
83             }
84         }
85     }
86
87     function handle($args)
88     {
89         // Looks like we're good; start output
90
91         // For YADIS discovery, we also have a <meta> tag
92
93         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
94                                                                    $this->user->nickname)));
95
96         $this->showPage();
97     }
98
99     function showContent()
100     {
101         $this->showProfile();
102         $this->showNotices();
103     }
104
105     function showLocalNav()
106     {
107         $nav = new PersonalGroupNav($this);
108         $nav->show();
109     }
110
111     function showPageNoticeBlock()
112     {
113         return;
114     }
115
116     function getFeeds()
117     {
118         if (!empty($this->tag)) {
119             return array(new Feed(Feed::RSS1,
120                                   common_local_url('userrss',
121                                                    array('nickname' => $this->user->nickname,
122                                                          'tag' => $this->tag)),
123                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
124                                           $this->user->nickname, $this->tag)));
125         }
126
127         return array(new Feed(Feed::RSS1,
128                               common_local_url('userrss',
129                                                array('nickname' => $this->user->nickname)),
130                               sprintf(_('Notice feed for %s (RSS 1.0)'),
131                                       $this->user->nickname)),
132                      new Feed(Feed::RSS2,
133                               common_local_url('ApiTimelineUser',
134                                                array(
135                                                     'id' => $this->user->id,
136                                                     'format' => 'rss')),
137                               sprintf(_('Notice feed for %s (RSS 2.0)'),
138                                       $this->user->nickname)),
139                      new Feed(Feed::ATOM,
140                               common_local_url('ApiTimelineUser',
141                                                array(
142                                                     'id' => $this->user->id,
143                                                     'format' => 'atom')),
144                               sprintf(_('Notice feed for %s (Atom)'),
145                                       $this->user->nickname)),
146                      new Feed(Feed::FOAF,
147                               common_local_url('foaf', array('nickname' =>
148                                                              $this->user->nickname)),
149                               sprintf(_('FOAF for %s'), $this->user->nickname)));
150     }
151
152     function extraHead()
153     {
154         // for remote subscriptions etc.
155         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
156                                      'content' => common_local_url('xrds', array('nickname' =>
157                                                                                  $this->user->nickname))));
158
159         if ($this->profile->bio) {
160             $this->element('meta', array('name' => 'description',
161                                          'content' => $this->profile->bio));
162         }
163
164         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
165             $id = new Microid('mailto:'.$this->user->email,
166                               $this->selfUrl());
167             $this->element('meta', array('name' => 'microid',
168                                          'content' => $id->toString()));
169         }
170
171         // See https://wiki.mozilla.org/Microsummaries
172
173         $this->element('link', array('rel' => 'microsummary',
174                                      'href' => common_local_url('microsummary',
175                                                                 array('nickname' => $this->profile->nickname))));
176
177         $rsd = common_local_url('rsd',
178                                 array('nickname' => $this->profile->nickname));
179
180         // RSD, http://tales.phrasewise.com/rfc/rsd
181         $this->element('link', array('rel' => 'EditURI',
182                                      'type' => 'application/rsd+xml',
183                                      'href' => $rsd));
184     }
185
186     function showProfile()
187     {
188         $profile = new UserProfile($this, $this->user, $this->profile);
189         $profile->show();
190     }
191
192     function showEmptyListMessage()
193     {
194         $message = sprintf(_('This is the timeline for %1$s but %2$s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
195
196         if (common_logged_in()) {
197             $current_user = common_current_user();
198             if ($this->user->id === $current_user->id) {
199                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
200             } else {
201                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->user->nickname, '@' . $this->user->nickname);
202             }
203         }
204         else {
205             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
206         }
207
208         $this->elementStart('div', 'guide');
209         $this->raw(common_markup_to_html($message));
210         $this->elementEnd('div');
211     }
212
213     function showNotices()
214     {
215         $notice = empty($this->tag)
216           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
217             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
218
219         $pnl = null;
220         if (Event::handle('ShowStreamNoticeList', array($notice, $this, &$pnl))) {
221             $pnl = new ProfileNoticeList($notice, $this);
222         }
223         $cnt = $pnl->show();
224         if (0 == $cnt) {
225             $this->showEmptyListMessage();
226         }
227
228         $args = array('nickname' => $this->user->nickname);
229         if (!empty($this->tag))
230         {
231             $args['tag'] = $this->tag;
232         }
233         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
234                           'showstream', $args);
235     }
236
237     function showAnonymousMessage()
238     {
239         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
240             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
241                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
242                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
243                          $this->user->nickname, $this->user->nickname);
244         } else {
245             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
246                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
247                          $this->user->nickname, $this->user->nickname);
248         }
249         $this->elementStart('div', array('id' => 'anon_notice'));
250         $this->raw(common_markup_to_html($m));
251         $this->elementEnd('div');
252     }
253
254     function showSections()
255     {
256         parent::showSections();
257         $cloud = new PersonalTagCloudSection($this, $this->user);
258         $cloud->show();
259     }
260 }
261
262 // We don't show the author for a profile, since we already know who it is!
263
264 class ProfileNoticeList extends NoticeList
265 {
266     function newListItem($notice)
267     {
268         return new ProfileNoticeListItem($notice, $this->out);
269     }
270 }
271
272 class ProfileNoticeListItem extends DoFollowListItem
273 {
274     function showAuthor()
275     {
276         return;
277     }
278
279     /**
280      * show a link to the author of repeat
281      *
282      * @return void
283      */
284
285     function showRepeat()
286     {
287         if (!empty($this->repeat)) {
288
289             // FIXME: this code is almost identical to default; need to refactor
290
291             $attrs = array('href' => $this->profile->profileurl,
292                            'class' => 'url');
293
294             if (!empty($this->profile->fullname)) {
295                 $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
296             }
297
298             $this->out->elementStart('span', 'repeat');
299
300             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
301
302             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
303
304             $this->out->elementEnd('span');
305         }
306     }
307 }