]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Merge branch '0.7.x' into 0.8.x
[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         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     /**
151      * Output document relationship links
152      *
153      * @return void
154      */
155     function showRelationshipLinks()
156     {
157         $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
158                                      $this->page, 'showstream', array('nickname' => $this->user->nickname));
159     }
160
161     function extraHead()
162     {
163         // for remote subscriptions etc.
164         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
165                                      'content' => common_local_url('xrds', array('nickname' =>
166                                                                                  $this->user->nickname))));
167
168         if ($this->profile->bio) {
169             $this->element('meta', array('name' => 'description',
170                                          'content' => $this->profile->bio));
171         }
172
173         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
174             $id = new Microid('mailto:'.$this->user->email,
175                               $this->selfUrl());
176             $this->element('meta', array('name' => 'microid',
177                                          'content' => $id->toString()));
178         }
179         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
180             $id = new Microid('xmpp:'.$this->user->jabber,
181                               $this->selfUrl());
182             $this->element('meta', array('name' => 'microid',
183                                          'content' => $id->toString()));
184         }
185
186         // See https://wiki.mozilla.org/Microsummaries
187
188         $this->element('link', array('rel' => 'microsummary',
189                                      'href' => common_local_url('microsummary',
190                                                                 array('nickname' => $this->profile->nickname))));
191     }
192
193     function showProfile()
194     {
195         $this->elementStart('div', 'entity_profile vcard author');
196         $this->element('h2', null, _('User profile'));
197
198         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
199         $this->elementStart('dl', 'entity_depiction');
200         $this->element('dt', null, _('Photo'));
201         $this->elementStart('dd');
202         $this->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_PROFILE_SIZE),
203                                     'class' => 'photo avatar',
204                                     'width' => AVATAR_PROFILE_SIZE,
205                                     'height' => AVATAR_PROFILE_SIZE,
206                                     'alt' => $this->profile->nickname));
207         $this->elementEnd('dd');
208
209         $user = User::staticGet('id', $this->profile->id);
210         $cur = common_current_user();
211         if ($cur && $cur->id == $user->id) {
212             $this->elementStart('dd');
213             $this->element('a', array('href' => common_local_url('avatarsettings')), _('Edit Avatar'));
214             $this->elementEnd('dd');
215         }
216
217         $this->elementEnd('dl');
218
219         $this->elementStart('dl', 'entity_nickname');
220         $this->element('dt', null, _('Nickname'));
221         $this->elementStart('dd');
222         $hasFN = ($this->profile->fullname) ? 'nickname url uid' : 'fn nickname url uid';
223         $this->element('a', array('href' => $this->profile->profileurl,
224                                   'rel' => 'me', 'class' => $hasFN),
225                        $this->profile->nickname);
226         $this->elementEnd('dd');
227         $this->elementEnd('dl');
228
229         if ($this->profile->fullname) {
230             $this->elementStart('dl', 'entity_fn');
231             $this->element('dt', null, _('Full name'));
232             $this->elementStart('dd');
233             $this->element('span', 'fn', $this->profile->fullname);
234             $this->elementEnd('dd');
235             $this->elementEnd('dl');
236         }
237
238         if ($this->profile->location) {
239             $this->elementStart('dl', 'entity_location');
240             $this->element('dt', null, _('Location'));
241             $this->element('dd', 'label', $this->profile->location);
242             $this->elementEnd('dl');
243         }
244
245         if ($this->profile->homepage) {
246             $this->elementStart('dl', 'entity_url');
247             $this->element('dt', null, _('URL'));
248             $this->elementStart('dd');
249             $this->element('a', array('href' => $this->profile->homepage,
250                                       'rel' => 'me', 'class' => 'url'),
251                            $this->profile->homepage);
252             $this->elementEnd('dd');
253             $this->elementEnd('dl');
254         }
255
256         if ($this->profile->bio) {
257             $this->elementStart('dl', 'entity_note');
258             $this->element('dt', null, _('Note'));
259             $this->element('dd', 'note', $this->profile->bio);
260             $this->elementEnd('dl');
261         }
262
263         $tags = Profile_tag::getTags($this->profile->id, $this->profile->id);
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         $this->elementEnd('div');
283
284         $this->elementStart('div', 'entity_actions');
285         $this->element('h2', null, _('User actions'));
286         $this->elementStart('ul');
287         $cur = common_current_user();
288
289         if ($cur && $cur->id == $this->profile->id) {
290             $this->elementStart('li', 'entity_edit');
291             $this->element('a', array('href' => common_local_url('profilesettings'),
292                                       'title' => _('Edit profile settings')),
293                            _('Edit'));
294             $this->elementEnd('li');
295         }
296
297         if ($cur) {
298             if ($cur->id != $this->profile->id) {
299                 $this->elementStart('li', 'entity_subscribe');
300                 if ($cur->isSubscribed($this->profile)) {
301                     $usf = new UnsubscribeForm($this, $this->profile);
302                     $usf->show();
303                 } else {
304                     $sf = new SubscribeForm($this, $this->profile);
305                     $sf->show();
306                 }
307                 $this->elementEnd('li');
308             }
309         } else {
310             $this->elementStart('li', 'entity_subscribe');
311             $this->showRemoteSubscribeLink();
312             $this->elementEnd('li');
313         }
314
315         if ($cur && $cur->id != $user->id && $cur->mutuallySubscribed($user)) {
316             $this->elementStart('li', 'entity_send-a-message');
317             $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)),
318                                       'title' => _('Send a direct message to this user')),
319                            _('Message'));
320             $this->elementEnd('li');
321
322             if ($user->email && $user->emailnotifynudge) {
323                 $this->elementStart('li', 'entity_nudge');
324                 $nf = new NudgeForm($this, $user);
325                 $nf->show();
326                 $this->elementEnd('li');
327             }
328         }
329
330         if ($cur && $cur->id != $this->profile->id) {
331             $blocked = $cur->hasBlocked($this->profile);
332             $this->elementStart('li', 'entity_block');
333             if ($blocked) {
334                 $ubf = new UnblockForm($this, $this->profile);
335                 $ubf->show();
336             } else {
337                 $bf = new BlockForm($this, $this->profile);
338                 $bf->show();
339             }
340             $this->elementEnd('li');
341         }
342         $this->elementEnd('ul');
343         $this->elementEnd('div');
344     }
345
346     function showRemoteSubscribeLink()
347     {
348         $url = common_local_url('remotesubscribe',
349                                 array('nickname' => $this->profile->nickname));
350         $this->element('a', array('href' => $url,
351                                   'class' => 'entity_remote_subscribe'),
352                        _('Subscribe'));
353     }
354
355     function showEmptyListMessage()
356     {
357         $message = sprintf(_('This is the timeline for %s but %s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
358
359         if (common_logged_in()) {
360             $current_user = common_current_user();
361             if ($this->user->id === $current_user->id) {
362                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
363             } else {
364                 $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);
365             }
366         }
367         else {
368             $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);
369         }
370
371         $this->elementStart('div', 'guide');
372         $this->raw(common_markup_to_html($message));
373         $this->elementEnd('div');
374     }
375
376     function showNotices()
377     {
378         $notice = empty($this->tag)
379             ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
380             : $this->user->getTaggedNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null, $this->tag);
381
382         $pnl = new ProfileNoticeList($notice, $this);
383         $cnt = $pnl->show();
384         if (0 == $cnt) {
385             $this->showEmptyListMessage();
386         }
387
388         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
389                           'showstream', array('nickname' => $this->user->nickname));
390     }
391
392     function showAnonymousMessage()
393     {
394         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
395             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
396                  'based on the Free Software [Laconica](http://laconi.ca/) tool. ' .
397                  '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
398                  $this->user->nickname, $this->user->nickname);
399         } else {
400             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
401                  'based on the Free Software [Laconica](http://laconi.ca/) tool. '),
402                  $this->user->nickname, $this->user->nickname);
403         }
404         $this->elementStart('div', array('id' => 'anon_notice'));
405         $this->raw(common_markup_to_html($m));
406         $this->elementEnd('div');
407     }
408
409     function showSections()
410     {
411         parent::showSections();
412         $cloud = new PersonalTagCloudSection($this, $this->user);
413         $cloud->show();
414     }
415 }
416
417 // We don't show the author for a profile, since we already know who it is!
418
419 class ProfileNoticeList extends NoticeList
420 {
421     function newListItem($notice)
422     {
423         return new ProfileNoticeListItem($notice, $this->out);
424     }
425 }
426
427 class ProfileNoticeListItem extends NoticeListItem
428 {
429     function showAuthor()
430     {
431         return;
432     }
433 }