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