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