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