]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/all.php
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / actions / all.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @category Actions
20  * @package  Actions
21  * @author   Adrian Lang <mail@adrianlang.de>
22  * @author   Brenda Wallace <shiny@cpan.org>
23  * @author   Brion Vibber <brion@pobox.com>
24  * @author   Craig Andrews <candrews@integralblue.com>
25  * @author   Evan Prodromou <evan@status.net>
26  * @author   Jeffery To <jeffery.to@gmail.com>
27  * @author   Meitar Moscovitz <meitarm@gmail.com>
28  * @author   Mike Cochrane <mikec@mikenz.geek.nz>
29  * @author   Robin Millette <millette@status.net>
30  * @author   Sarven Capadisli <csarven@status.net>
31  * @author   Siebrand Mazeland <s.mazeland@xs4all.nl>
32  * @author   Zach Copley <zach@status.net>
33  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
34  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
35  * @link     http://status.net
36  */
37
38 if (!defined('STATUSNET') && !defined('LACONICA')) {
39     exit(1);
40 }
41
42 require_once INSTALLDIR.'/lib/personalgroupnav.php';
43 require_once INSTALLDIR.'/lib/noticelist.php';
44 require_once INSTALLDIR.'/lib/feedlist.php';
45
46 class AllAction extends ProfileAction
47 {
48     var $notice;
49
50     function isReadOnly($args)
51     {
52         return true;
53     }
54
55     function prepare($args)
56     {
57         parent::prepare($args);
58
59         $stream = new ThreadingInboxNoticeStream($this->user, Profile::current());
60
61         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
62                                             NOTICES_PER_PAGE + 1);
63
64         if ($this->page > 1 && $this->notice->N == 0) {
65             // TRANS: Server error when page not found (404).
66             $this->serverError(_('No such page.'), 404);
67         }
68
69         return true;
70     }
71
72     function handle($args)
73     {
74         parent::handle($args);
75
76         if (!$this->user) {
77             // TRANS: Client error when user not found for an action.
78             $this->clientError(_('No such user.'));
79             return;
80         }
81
82         $this->showPage();
83     }
84
85     function title()
86     {
87         $user = common_current_user();
88         if ($user->id == $this->user->id) {
89             // TRANS: Title of a user's own start page.
90             return _('Home timeline');
91         } else {
92             $profile = $this->user->getProfile();
93             // TRANS: Title of another user's start page.
94             // TRANS: %s is the other user's name.
95             return sprintf(_("%s's home timeline"), $profile->getBestName());
96         }
97     }
98
99     function getFeeds()
100     {
101         return array(
102             new Feed(Feed::RSS1,
103                 common_local_url(
104                     'allrss', array(
105                         'nickname' =>
106                         $this->user->nickname)
107                 ),
108                 // TRANS: %s is user nickname.
109                 sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
110             new Feed(Feed::RSS2,
111                 common_local_url(
112                     'ApiTimelineFriends', array(
113                         'format' => 'rss',
114                         'id' => $this->user->nickname
115                     )
116                 ),
117                 // TRANS: %s is user nickname.
118                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
119             new Feed(Feed::ATOM,
120                 common_local_url(
121                     'ApiTimelineFriends', array(
122                         'format' => 'atom',
123                         'id' => $this->user->nickname
124                     )
125                 ),
126                 // TRANS: %s is user nickname.
127                 sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))
128         );
129     }
130
131     function showEmptyListMessage()
132     {
133         // TRANS: Empty list message. %s is a user nickname.
134         $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->user->nickname) . ' ';
135
136         if (common_logged_in()) {
137             $current_user = common_current_user();
138             if ($this->user->id === $current_user->id) {
139                 // TRANS: Encouragement displayed on logged in user's empty timeline.
140                 // TRANS: This message contains Markdown links. Keep "](" together.
141                 $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
142             } else {
143                 // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@".
144                 // TRANS: This message contains Markdown links. Keep "](" together.
145                 $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from their profile or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
146             }
147         } else {
148             // TRANS: Encoutagement displayed on empty timeline user pages for anonymous users.
149             // TRANS: %s is a user nickname. This message contains Markdown links. Keep "](" together.
150             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
151         }
152
153         $this->elementStart('div', 'guide');
154         $this->raw(common_markup_to_html($message));
155         $this->elementEnd('div');
156     }
157
158     function showContent()
159     {
160         if (Event::handle('StartShowAllContent', array($this))) {
161
162             $profile = null;
163
164             $current_user = common_current_user();
165
166             if (!empty($current_user)) {
167                 $profile = $current_user->getProfile();
168             }
169
170             $nl = new ThreadedNoticeList($this->notice, $this, $profile);
171
172             $cnt = $nl->show();
173
174             if (0 == $cnt) {
175                 $this->showEmptyListMessage();
176             }
177
178             $this->pagination(
179                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
180                 $this->page, 'all', array('nickname' => $this->user->nickname)
181             );
182
183             Event::handle('EndShowAllContent', array($this));
184         }
185     }
186
187     function showSections()
188     {
189         $ibs = new InviteButtonSection($this);
190         $ibs->show();
191         $pop = new PopularNoticeSection($this);
192         $pop->show();
193         //        $pop = new InboxTagCloudSection($this, $this->user);
194         //        $pop->show();
195     }
196 }
197
198 class ThreadingInboxNoticeStream extends ThreadingNoticeStream
199 {
200     function __construct($user, $profile)
201     {
202         parent::__construct(new InboxNoticeStream($user, $profile));
203     }
204 }