]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
isReadOnly() now takes arguments
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36 require_once INSTALLDIR.'/lib/noticelist.php';
37 require_once INSTALLDIR.'/lib/profileminilist.php';
38 require_once INSTALLDIR.'/lib/groupminilist.php';
39 require_once INSTALLDIR.'/lib/feedlist.php';
40
41 /**
42  * User profile page
43  *
44  * When I created this page, "show stream" seemed like the best name for it.
45  * Now, it seems like a really bad name.
46  *
47  * It shows a stream of the user's posts, plus lots of profile info, links
48  * to subscriptions and stuff, etc.
49  *
50  * @category Personal
51  * @package  Laconica
52  * @author   Evan Prodromou <evan@controlyourself.ca>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://laconi.ca/
55  */
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
72         if ($this->page == 1) {
73             return $base;
74         } else {
75             return sprintf(_("%s, page %d"),
76                            $base,
77                            $this->page);
78         }
79     }
80
81     function handle($args)
82     {
83
84         // Looks like we're good; start output
85
86         // For YADIS discovery, we also have a <meta> tag
87
88         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
89                                                                    $this->user->nickname)));
90
91         $this->showPage();
92     }
93
94     function showContent()
95     {
96         $this->showProfile();
97         $this->showNotices();
98     }
99
100     function showLocalNav()
101     {
102         $nav = new PersonalGroupNav($this);
103         $nav->show();
104     }
105
106     function showPageNoticeBlock()
107     {
108         return;
109     }
110
111     function getFeeds()
112     {
113         return array(new Feed(Feed::RSS1,
114                               common_local_url('userrss',
115                                                array('nickname' => $this->user->nickname)),
116                               sprintf(_('Notice feed for %s (RSS 1.0)'),
117                                       $this->user->nickname)),
118                      new Feed(Feed::RSS2,
119                               common_local_url('api',
120                                                array('apiaction' => 'statuses',
121                                                      'method' => 'user_timeline',
122                                                      'argument' => $this->user->nickname.'.rss')),
123                               sprintf(_('Notice feed for %s (RSS 2.0)'),
124                                       $this->user->nickname)),
125                      new Feed(Feed::ATOM,
126                               common_local_url('api',
127                                                array('apiaction' => 'statuses',
128                                                      'method' => 'user_timeline',
129                                                      'argument' => $this->user->nickname.'.atom')),
130                               sprintf(_('Notice feed for %s (Atom)'),
131                                       $this->user->nickname)),
132                      new Feed(Feed::FOAF,
133                               common_local_url('foaf', array('nickname' =>
134                                                              $this->user->nickname)),
135                               sprintf(_('FOAF for %s'), $this->user->nickname)));
136     }
137
138     function extraHead()
139     {
140         // for remote subscriptions etc.
141         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
142                                      'content' => common_local_url('xrds', array('nickname' =>
143                                                                                  $this->user->nickname))));
144
145         if ($this->profile->bio) {
146             $this->element('meta', array('name' => 'description',
147                                          'content' => $this->profile->bio));
148         }
149
150         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
151             $id = new Microid('mailto:'.$this->user->email,
152                               $this->selfUrl());
153             $this->element('meta', array('name' => 'microid',
154                                          'content' => $id->toString()));
155         }
156         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
157             $id = new Microid('xmpp:'.$this->user->jabber,
158                               $this->selfUrl());
159             $this->element('meta', array('name' => 'microid',
160                                          'content' => $id->toString()));
161         }
162
163         // See https://wiki.mozilla.org/Microsummaries
164
165         $this->element('link', array('rel' => 'microsummary',
166                                      'href' => common_local_url('microsummary',
167                                                                 array('nickname' => $this->profile->nickname))));
168     }
169
170     function showProfile()
171     {
172         $this->elementStart('div', 'entity_profile vcard author');
173         $this->element('h2', null, _('User profile'));
174
175         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
176         $this->elementStart('dl', 'entity_depiction');
177         $this->element('dt', null, _('Photo'));
178         $this->elementStart('dd');
179         $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
180                                     'class' => 'photo avatar',
181                                     'width' => AVATAR_PROFILE_SIZE,
182                                     'height' => AVATAR_PROFILE_SIZE,
183                                     'alt' => $this->profile->nickname));
184         $this->elementEnd('dd');
185
186         $user = User::staticGet('id', $this->profile->id);
187         $cur = common_current_user();
188         if ($cur && $cur->id == $user->id) {
189             $this->elementStart('dd');
190             $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
191             $this->elementEnd('dd');
192         }
193
194         $this->elementEnd('dl');
195
196         $this->elementStart('dl', 'entity_nickname');
197         $this->element('dt', null, _('Nickname'));
198         $this->elementStart('dd');
199         $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
200         $this->element('a', array('href' => $this->profile->profileurl,
201                                   'rel' => 'me', 'class' => $hasFN),
202                        $this->profile->nickname);
203         $this->elementEnd('dd');
204         $this->elementEnd('dl');
205
206         if ($this->profile->fullname) {
207             $this->elementStart('dl', 'entity_fn');
208             $this->element('dt', null, _('Full name'));
209             $this->elementStart('dd');
210             $this->element('span', 'fn', $this->profile->fullname);
211             $this->elementEnd('dd');
212             $this->elementEnd('dl');
213         }
214
215         if ($this->profile->location) {
216             $this->elementStart('dl', 'entity_location');
217             $this->element('dt', null, _('Location'));
218             $this->element('dd', 'label', $this->profile->location);
219             $this->elementEnd('dl');
220         }
221
222         if ($this->profile->homepage) {
223             $this->elementStart('dl', 'entity_url');
224             $this->element('dt', null, _('URL'));
225             $this->elementStart('dd');
226             $this->element('a', array('href' => $this->profile->homepage,
227                                       'rel' => 'me', 'class' => 'url'),
228                            $this->profile->homepage);
229             $this->elementEnd('dd');
230             $this->elementEnd('dl');
231         }
232
233         if ($this->profile->bio) {
234             $this->elementStart('dl', 'entity_note');
235             $this->element('dt', null, _('Note'));
236             $this->element('dd', 'note', $this->profile->bio);
237             $this->elementEnd('dl');
238         }
239
240         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
241         if (count($tags) > 0) {
242             $this->elementStart('dl', 'entity_tags');
243             $this->element('dt', null, _('Tags'));
244             $this->elementStart('dd');
245             $this->elementStart('ul', 'tags xoxo');
246             foreach ($tags as $tag) {
247                 $this->elementStart('li');
248                 // Avoid space by using raw output.
249                 $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
250                       common_local_url('peopletag', array('tag' => $tag)) .
251                       '">' . $tag . '</a>';
252                 $this->raw($pt);
253                 $this->elementEnd('li');
254             }
255             $this->elementEnd('ul');
256             $this->elementEnd('dd');
257             $this->elementEnd('dl');
258         }
259         $this->elementEnd('div');
260
261         $this->elementStart('div', 'entity_actions');
262         $this->element('h2', null, _('User actions'));
263         $this->elementStart('ul');
264         $cur = common_current_user();
265
266         if ($cur && $cur->id == $this->profile->id) {
267             $this->elementStart('li', 'entity_edit');
268             $this->element('a', array('href' => common_local_url('profilesettings'),
269                                       'title' => _('Edit profile settings')),
270                            _('Edit'));
271             $this->elementEnd('li');
272         }
273
274         if ($cur) {
275             if ($cur->id != $this->profile->id) {
276                 $this->elementStart('li', 'entity_subscribe');
277                 if ($cur->isSubscribed($this->profile)) {
278                     $usf = new UnsubscribeForm($this, $this->profile);
279                     $usf->show();
280                 } else {
281                     $sf = new SubscribeForm($this, $this->profile);
282                     $sf->show();
283                 }
284                 $this->elementEnd('li');
285             }
286         } else {
287             $this->elementStart('li', 'entity_subscribe');
288             $this->showRemoteSubscribeLink();
289             $this->elementEnd('li');
290         }
291
292         if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
293             $this->elementStart('li', 'entity_send-a-message');
294             $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
295                                       'title' => _('Send a direct message to this user')),
296                            _('Message'));
297             $this->elementEnd('li');
298
299             if ($user->email && $user->emailnotifynudge) {
300                 $this->elementStart('li', 'entity_nudge');
301                 $nf = new NudgeForm($this, $user);
302                 $nf->show();
303                 $this->elementEnd('li');
304             }
305         }
306
307         if ($cur && $cur->id != $this->profile->id) {
308             $blocked = $cur->hasBlocked($this->profile);
309             $this->elementStart('li', 'entity_block');
310             if ($blocked) {
311                 $ubf = new UnblockForm($this, $this->profile);
312                 $ubf->show();
313             } else {
314                 $bf = new BlockForm($this, $this->profile);
315                 $bf->show();
316             }
317             $this->elementEnd('li');
318         }
319         $this->elementEnd('ul');
320         $this->elementEnd('div');
321     }
322
323     function showRemoteSubscribeLink()
324     {
325         $url = common_local_url('remotesubscribe',
326                                 array('nickname' => $this->profile->nickname));
327         $this->element('a', array('href' => $url,
328                                   'class' => 'entity_remote_subscribe'),
329                        _('Subscribe'));
330     }
331
332     function showEmptyListMessage()
333     {
334         $message = sprintf(_('This is the timeline for %s but %s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
335
336         if (common_logged_in()) {
337             $current_user = common_current_user();
338             if ($this->user->id === $current_user->id) {
339                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
340             } else {
341                 $message .= sprintf(_('You can try to nudge %s or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%s).'), $this->user->nickname, '@' . $this->user->nickname);
342             }
343         }
344         else {
345             $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);
346         }
347
348         $this->elementStart('div', 'guide');
349         $this->raw(common_markup_to_html($message));
350         $this->elementEnd('div');
351     }
352
353     function showNotices()
354     {
355         $notice = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
356
357         $pnl = new ProfileNoticeList($notice, $this);
358         $cnt = $pnl->show();
359         if (0 == $cnt) {
360             $this->showEmptyListMessage();
361         }
362
363         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
364                           'showstream', array('nickname' => $this->user->nickname));
365     }
366
367     function showAnonymousMessage()
368     {
369         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
370             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
371                  'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
372                  '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
373                  $this->user->nickname, $this->user->nickname);
374         } else {
375             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
376                  'based on the Free Software [Laconica](http://laconi.ca/) tool. '),
377                  $this->user->nickname, $this->user->nickname);
378         }
379         $this->elementStart('div', array('id' => 'anon_notice'));
380         $this->raw(common_markup_to_html($m));
381         $this->elementEnd('div');
382     }
383
384     function showSections()
385     {
386         parent::showSections();
387         $cloud = new PersonalTagCloudSection($this, $this->user);
388         $cloud->show();
389     }
390 }
391
392 // We don't show the author for a profile, since we already know who it is!
393
394 class ProfileNoticeList extends NoticeList
395 {
396     function newListItem($notice)
397     {
398         return new ProfileNoticeListItem($notice, $this->out);
399     }
400 }
401
402 class ProfileNoticeListItem extends NoticeListItem
403 {
404     function showAuthor()
405     {
406         return;
407     }
408 }