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