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