]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/all.php
bab59a7d03da2163d20b678995ccc5b7cb2ff9c6
[quix0rs-gnu-social.git] / actions / all.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008-2011, 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     var $mode = 'conversation';
50
51     function isReadOnly($args)
52     {
53         return true;
54     }
55
56     function prepare($args)
57     {
58         parent::prepare($args);
59
60         $this->mode = $this->trimmed('mode', 'conversation');
61
62         if ($this->mode == 'stream') {
63             $stream = new InboxNoticeStream($this->user, Profile::current());
64         } else {
65             $stream = new ThreadingInboxNoticeStream($this->user, Profile::current());
66         }
67
68         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
69                                             NOTICES_PER_PAGE + 1);
70
71         if ($this->page > 1 && $this->notice->N == 0) {
72             // TRANS: Server error when page not found (404).
73             $this->serverError(_('No such page.'), 404);
74         }
75
76         return true;
77     }
78
79     function handle($args)
80     {
81         parent::handle($args);
82
83         if (!$this->user) {
84             // TRANS: Client error when user not found for an action.
85             $this->clientError(_('No such user.'));
86             return;
87         }
88
89         $this->showPage();
90     }
91
92     function title()
93     {
94         $user = common_current_user();
95         if (!empty($user) && $user->id == $this->user->id) {
96             // TRANS: Title of a user's own start page.
97             return _('Home timeline');
98         } else {
99             $profile = $this->user->getProfile();
100             // TRANS: Title of another user's start page.
101             // TRANS: %s is the other user's name.
102             return sprintf(_("%s's home timeline"), $profile->getBestName());
103         }
104     }
105
106     function getFeeds()
107     {
108         return array(
109             new Feed(Feed::JSON,
110                 common_local_url(
111                     'ApiTimelineFriends', array(
112                         'format' => 'as',
113                         'id' => $this->user->nickname
114                     )
115                 ),
116                 // TRANS: %s is user nickname.
117                 sprintf(_('Feed for friends of %s (Activity Streams JSON)'), $this->user->nickname)),
118             new Feed(Feed::RSS1,
119                 common_local_url(
120                     'allrss', array(
121                         'nickname' =>
122                         $this->user->nickname)
123                 ),
124                 // TRANS: %s is user nickname.
125                 sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
126             new Feed(Feed::RSS2,
127                 common_local_url(
128                     'ApiTimelineFriends', array(
129                         'format' => 'rss',
130                         'id' => $this->user->nickname
131                     )
132                 ),
133                 // TRANS: %s is user nickname.
134                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
135             new Feed(Feed::ATOM,
136                 common_local_url(
137                     'ApiTimelineFriends', array(
138                         'format' => 'atom',
139                         'id' => $this->user->nickname
140                     )
141                 ),
142                 // TRANS: %s is user nickname.
143                 sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))
144         );
145     }
146
147     function showEmptyListMessage()
148     {
149         // TRANS: Empty list message. %s is a user nickname.
150         $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->user->nickname) . ' ';
151
152         if (common_logged_in()) {
153             $current_user = common_current_user();
154             if ($this->user->id === $current_user->id) {
155                 // TRANS: Encouragement displayed on logged in user's empty timeline.
156                 // TRANS: This message contains Markdown links. Keep "](" together.
157                 $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
158             } else {
159                 // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@".
160                 // TRANS: This message contains Markdown links. Keep "](" together.
161                 $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);
162             }
163         } else {
164             // TRANS: Encouragement displayed on empty timeline user pages for anonymous users.
165             // TRANS: %s is a user nickname. This message contains Markdown links. Keep "](" together.
166             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
167         }
168
169         $this->elementStart('div', 'guide');
170         $this->raw(common_markup_to_html($message));
171         $this->elementEnd('div');
172     }
173
174     function showContent()
175     {
176         if (Event::handle('StartShowAllContent', array($this))) {
177
178             $profile = null;
179
180             $current_user = common_current_user();
181
182             if (!empty($current_user)) {
183                 $profile = $current_user->getProfile();
184             }
185
186             if ($this->mode == 'stream') {
187                 $nl = new NoticeList($this->notice, $this);
188             } else {
189                 $nl = new ThreadedNoticeList($this->notice, $this, $profile);
190             }
191
192             $cnt = $nl->show();
193
194             if (0 == $cnt) {
195                 $this->showEmptyListMessage();
196             }
197
198             $this->pagination(
199                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
200                 $this->page, 'all', array('nickname' => $this->user->nickname)
201             );
202
203             Event::handle('EndShowAllContent', array($this));
204         }
205     }
206
207     function showSections()
208     {
209         // Show invite button, as long as site isn't closed, and
210         // we have a logged in user.
211         if (!common_config('site', 'closed') && common_logged_in()) {
212             if (!common_config('site', 'private')) {
213                 $ibs = new InviteButtonSection(
214                     $this,
215                     // TRANS: Button text for inviting more users to the StatusNet instance.
216                     // TRANS: Less business/enterprise-oriented language for public sites.
217                     _m('BUTTON', 'Send invite')
218                 );
219             } else {
220                 $ibs = new InviteButtonSection($this);
221             }
222             $ibs->show();
223         }
224         // XXX: make this a little more convenient
225
226         if (!common_config('performance', 'high')) {
227             $pop = new PopularNoticeSection($this);
228             $pop->show();
229             $pop = new InboxTagCloudSection($this, $this->user);
230             $pop->show();
231         }
232     }
233 }
234
235 class ThreadingInboxNoticeStream extends ThreadingNoticeStream
236 {
237     function __construct($user, $profile)
238     {
239         parent::__construct(new InboxNoticeStream($user, $profile));
240     }
241 }