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