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