]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
83ac496cad8b4b559a8c9c27b5a04d872593bc66
[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/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  StatusNet
52  * @author   Evan Prodromou <evan@status.net>
53  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
54  * @link     http://status.net/
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         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(_("%s, page %d"),
79                            $base,
80                            $this->page);
81         }
82     }
83
84     function handle($args)
85     {
86
87         // Looks like we're good; start output
88
89         // For YADIS discovery, we also have a <meta> tag
90
91         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
92                                                                    $this->user->nickname)));
93
94         $this->showPage();
95     }
96
97     function showContent()
98     {
99         $this->showProfile();
100         $this->showNotices();
101     }
102
103     function showLocalNav()
104     {
105         $nav = new PersonalGroupNav($this);
106         $nav->show();
107     }
108
109     function showPageNoticeBlock()
110     {
111         return;
112     }
113
114     function getFeeds()
115     {
116         if (!empty($this->tag)) {
117             return array(new Feed(Feed::RSS1,
118                                   common_local_url('userrss',
119                                                    array('nickname' => $this->user->nickname,
120                                                          'tag' => $this->tag)),
121                                   sprintf(_('Notice feed for %s tagged %s (RSS 1.0)'),
122                                           $this->user->nickname, $this->tag)));
123         }
124
125         return array(new Feed(Feed::RSS1,
126                               common_local_url('userrss',
127                                                array('nickname' => $this->user->nickname)),
128                               sprintf(_('Notice feed for %s (RSS 1.0)'),
129                                       $this->user->nickname)),
130                      new Feed(Feed::RSS2,
131                               common_local_url('api',
132                                                array('apiaction' => 'statuses',
133                                                      'method' => 'user_timeline',
134                                                      'argument' => $this->user->nickname.'.rss')),
135                               sprintf(_('Notice feed for %s (RSS 2.0)'),
136                                       $this->user->nickname)),
137                      new Feed(Feed::ATOM,
138                               common_local_url('api',
139                                                array('apiaction' => 'statuses',
140                                                      'method' => 'user_timeline',
141                                                      'argument' => $this->user->nickname.'.atom')),
142                               sprintf(_('Notice feed for %s (Atom)'),
143                                       $this->user->nickname)),
144                      new Feed(Feed::FOAF,
145                               common_local_url('foaf', array('nickname' =>
146                                                              $this->user->nickname)),
147                               sprintf(_('FOAF for %s'), $this->user->nickname)));
148     }
149
150     function extraHead()
151     {
152         // for remote subscriptions etc.
153         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
154                                      'content' => common_local_url('xrds', array('nickname' =>
155                                                                                  $this->user->nickname))));
156
157         if ($this->profile->bio) {
158             $this->element('meta', array('name' => 'description',
159                                          'content' => $this->profile->bio));
160         }
161
162         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
163             $id = new Microid('mailto:'.$this->user->email,
164                               $this->selfUrl());
165             $this->element('meta', array('name' => 'microid',
166                                          'content' => $id->toString()));
167         }
168         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
169             $id = new Microid('xmpp:'.$this->user->jabber,
170                               $this->selfUrl());
171             $this->element('meta', array('name' => 'microid',
172                                          'content' => $id->toString()));
173         }
174
175         // See https://wiki.mozilla.org/Microsummaries
176
177         $this->element('link', array('rel' => 'microsummary',
178                                      'href' => common_local_url('microsummary',
179                                                                 array('nickname' => $this->profile->nickname))));
180     }
181
182     function showProfile()
183     {
184         $this->showProfileData();
185         $this->showEntityActions();
186     }
187
188     function showProfileData()
189     {
190         if (Event::handle('StartShowLargeProfileSection', array(&$this, &$this->profile))) {
191
192             $this->elementStart('div', 'entity_profile vcard author');
193             $this->element('h2', null, _('User profile'));
194
195             if (Event::handle('StartShowLargeProfileElements', array(&$this, &$this->profile))) {
196
197                 $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
198                 $this->elementStart('dl', 'entity_depiction');
199                 $this->element('dt', null, _('Photo'));
200                 $this->elementStart('dd');
201                 $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
202                                             'class' => 'photo avatar',
203                                             'width' => AVATAR_PROFILE_SIZE,
204                                             'height' => AVATAR_PROFILE_SIZE,
205                                             'alt' => $this->profile->nickname));
206                 $this->elementEnd('dd');
207
208                 $user = User::staticGet('id', $this->profile->id);
209                 $cur = common_current_user();
210                 if ($cur && $cur->id == $user->id) {
211                     $this->elementStart('dd');
212                     $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
213                     $this->elementEnd('dd');
214                 }
215
216                 $this->elementEnd('dl');
217
218                 $this->elementStart('dl', 'entity_nickname');
219                 $this->element('dt', null, _('Nickname'));
220                 $this->elementStart('dd');
221                 $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
222                 $this->element('a', array('href' => $this->profile->profileurl,
223                                           'rel' => 'me', 'class' => $hasFN),
224                                $this->profile->nickname);
225                 $this->elementEnd('dd');
226                 $this->elementEnd('dl');
227
228                 if ($this->profile->fullname) {
229                     $this->elementStart('dl', 'entity_fn');
230                     $this->element('dt', null, _('Full name'));
231                     $this->elementStart('dd');
232                     $this->element('span', 'fn', $this->profile->fullname);
233                     $this->elementEnd('dd');
234                     $this->elementEnd('dl');
235                 }
236
237                 if ($this->profile->location) {
238                     $this->elementStart('dl', 'entity_location');
239                     $this->element('dt', null, _('Location'));
240                     $this->element('dd', 'label', $this->profile->location);
241                     $this->elementEnd('dl');
242                 }
243
244                 if ($this->profile->homepage) {
245                     $this->elementStart('dl', 'entity_url');
246                     $this->element('dt', null, _('URL'));
247                     $this->elementStart('dd');
248                     $this->element('a', array('href' => $this->profile->homepage,
249                                               'rel' => 'me', 'class' => 'url'),
250                                    $this->profile->homepage);
251                     $this->elementEnd('dd');
252                     $this->elementEnd('dl');
253                 }
254
255                 if ($this->profile->bio) {
256                     $this->elementStart('dl', 'entity_note');
257                     $this->element('dt', null, _('Note'));
258                     $this->element('dd', 'note', $this->profile->bio);
259                     $this->elementEnd('dl');
260                 }
261
262                 $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
263
264                 if (count($tags) > 0) {
265                     $this->elementStart('dl', 'entity_tags');
266                     $this->element('dt', null, _('Tags'));
267                     $this->elementStart('dd');
268                     $this->elementStart('ul', 'tags xoxo');
269                     foreach ($tags as $tag) {
270                         $this->elementStart('li');
271                         // Avoid space by using raw output.
272                         $pt = '<span class="mark_hash">#</span><a rel="tag" href="' .
273                           common_local_url('peopletag', array('tag' => $tag)) .
274                           '">' . $tag . '</a>';
275                         $this->raw($pt);
276                         $this->elementEnd('li');
277                     }
278                     $this->elementEnd('ul');
279                     $this->elementEnd('dd');
280                     $this->elementEnd('dl');
281                 }
282
283                 Event::handle('EndShowLargeProfileElements', array(&$this, &$this->profile));
284             }
285
286             $this->elementEnd('div');
287             Event::handle('EndShowLargeProfileSection', array(&$this, &$this->profile));
288         }
289     }
290
291     function showEntityActions()
292     {
293         if (Event::handle('StartShowLargeEntityActionsSection', array(&$this, &$this->profile))) {
294
295             $this->elementStart('div', 'entity_actions');
296             $this->element('h2', null, _('User actions'));
297             $this->elementStart('ul');
298
299             if (Event::handle('StartShowLargeEntityActionsElements', array(&$this, &$this->profile))) {
300                 if (empty($cur)) { // not logged in
301                     $this->elementStart('li', 'entity_subscribe');
302                     $this->showRemoteSubscribeLink();
303                     $this->elementEnd('li');
304                 } else {
305                     if ($cur->id == $this->profile->id) { // your own page
306                         $this->elementStart('li', 'entity_edit');
307                         $this->element('a', array('href' => common_local_url('profilesettings'),
308                                                   'title' => _('Edit profile settings')),
309                                        _('Edit'));
310                         $this->elementEnd('li');
311                     } else { // someone else's page
312
313                         // subscribe/unsubscribe button
314
315                         $this->elementStart('li', 'entity_subscribe');
316
317                         if ($cur->isSubscribed($this->profile)) {
318                             $usf = new UnsubscribeForm($this, $this->profile);
319                             $usf->show();
320                         } else {
321                             $sf = new SubscribeForm($this, $this->profile);
322                             $sf->show();
323                         }
324                         $this->elementEnd('li');
325
326                         if ($cur->mutuallySubscribed($user)) {
327
328                             // message
329
330                             $this->elementStart('li', 'entity_send-a-message');
331                             $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
332                                                       'title' => _('Send a direct message to this user')),
333                                            _('Message'));
334                             $this->elementEnd('li');
335
336                             // nudge
337
338                             if ($user->email && $user->emailnotifynudge) {
339                                 $this->elementStart('li', 'entity_nudge');
340                                 $nf = new NudgeForm($this, $user);
341                                 $nf->show();
342                                 $this->elementEnd('li');
343                             }
344                         }
345
346                         // block/unblock
347
348                         $blocked = $cur->hasBlocked($this->profile);
349                         $this->elementStart('li', 'entity_block');
350                         if ($blocked) {
351                             $ubf = new UnblockForm($this, $this->profile,
352                                                    array('action' => 'showstream',
353                                                          'nickname' => $this->profile->nickname));
354                             $ubf->show();
355                         } else {
356                             $bf = new BlockForm($this, $this->profile,
357                                                 array('action' => 'showstream',
358                                                       'nickname' => $this->profile->nickname));
359                             $bf->show();
360                         }
361                         $this->elementEnd('li');
362                     }
363                 }
364
365                 Event::handle('EndShowLargeEntityActionsElements', array(&$this, &$this->profile));
366             }
367
368             $this->elementEnd('ul');
369             $this->elementEnd('div');
370
371             Event::handle('EndShowLargeEntityActionsSection', array(&$this, &$this->profile));
372         }
373     }
374
375     function showRemoteSubscribeLink()
376     {
377         $url = common_local_url('remotesubscribe',
378                                 array('nickname' => $this->profile->nickname));
379         $this->element('a', array('href' => $url,
380                                   'class' => 'entity_remote_subscribe'),
381                        _('Subscribe'));
382     }
383
384     function showEmptyListMessage()
385     {
386         $message = sprintf(_('This is the timeline for %s but %s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
387
388         if (common_logged_in()) {
389             $current_user = common_current_user();
390             if ($this->user->id === $current_user->id) {
391                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
392             } else {
393                 $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);
394             }
395         }
396         else {
397             $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);
398         }
399
400         $this->elementStart('div', 'guide');
401         $this->raw(common_markup_to_html($message));
402         $this->elementEnd('div');
403     }
404
405     function showNotices()
406     {
407         $notice = empty($this->tag)
408           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
409             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
410
411         $pnl = new ProfileNoticeList($notice, $this);
412         $cnt = $pnl->show();
413         if (0 == $cnt) {
414             $this->showEmptyListMessage();
415         }
416
417         $args = array('nickname' => $this->user->nickname);
418         if (!empty($this->tag))
419         {
420             $args['tag'] = $this->tag;
421         }
422         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
423                           'showstream', $args);
424     }
425
426     function showAnonymousMessage()
427     {
428         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
429             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
430                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
431                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
432                          $this->user->nickname, $this->user->nickname);
433         } else {
434             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
435                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
436                          $this->user->nickname, $this->user->nickname);
437         }
438         $this->elementStart('div', array('id' => 'anon_notice'));
439         $this->raw(common_markup_to_html($m));
440         $this->elementEnd('div');
441     }
442
443     function showSections()
444     {
445         parent::showSections();
446         $cloud = new PersonalTagCloudSection($this, $this->user);
447         $cloud->show();
448     }
449 }
450
451 // We don't show the author for a profile, since we already know who it is!
452
453 class ProfileNoticeList extends NoticeList
454 {
455     function newListItem($notice)
456     {
457         return new ProfileNoticeListItem($notice, $this->out);
458     }
459 }
460
461 class ProfileNoticeListItem extends NoticeListItem
462 {
463     function showAuthor()
464     {
465         return;
466     }
467 }