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