]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/all.php
8c22e6f5f076337b5829a791129369beaef2b9db
[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   Evan Prodromou <evan@status.net>
22  * @author   Mike Cochrane <mikec@mikenz.geek.nz>
23  * @author   Robin Millette <millette@controlyourself.ca>
24  * @author   Adrian Lang <mail@adrianlang.de>
25  * @author   Meitar Moscovitz <meitarm@gmail.com>
26  * @author   Sarven Capadisli <csarven@status.net>
27  * @author   Craig Andrews <candrews@integralblue.com>
28  * @author   Jeffery To <jeffery.to@gmail.com>
29  * @author   Zach Copley <zach@controlyourself.ca>
30  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
31  * @link     http://status.net
32  */
33
34 if (!defined('STATUSNET') && !defined('LACONICA')) {
35     exit(1);
36 }
37
38 require_once INSTALLDIR.'/lib/personalgroupnav.php';
39 require_once INSTALLDIR.'/lib/noticelist.php';
40 require_once INSTALLDIR.'/lib/feedlist.php';
41
42 class AllAction extends ProfileAction
43 {
44     var $notice;
45
46     function isReadOnly($args)
47     {
48         return true;
49     }
50
51     function prepare($args)
52     {
53         parent::prepare($args);
54         $cur = common_current_user();
55
56         if (!empty($cur) && $cur->id == $this->user->id) {
57             $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
58         } else {
59             $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
60         }
61
62         if ($this->page > 1 && $this->notice->N == 0) {
63             // TRANS: Server error when page not found (404)
64             $this->serverError(_('No such page'), $code = 404);
65         }
66
67         return true;
68     }
69
70     function handle($args)
71     {
72         parent::handle($args);
73
74         if (!$this->user) {
75             $this->clientError(_('No such user.'));
76             return;
77         }
78
79         $this->showPage();
80     }
81
82     function title()
83     {
84         if ($this->page > 1) {
85             // TRANS: Page title. %1$s is user nickname, %2$d is page number
86             return sprintf(_('%1$s and friends, page %2$d'), $this->user->nickname, $this->page);
87         } else {
88             // TRANS: Page title. %1$s is user nickname
89             return sprintf(_("%s and friends"), $this->user->nickname);
90         }
91     }
92
93     function getFeeds()
94     {
95         return array(
96             new Feed(Feed::RSS1,
97                 common_local_url(
98                     'allrss', array(
99                         'nickname' =>
100                         $this->user->nickname)
101                 ),
102             // TRANS: %1$s is user nickname
103                 sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
104             new Feed(Feed::RSS2,
105                 common_local_url(
106                     'ApiTimelineFriends', array(
107                         'format' => 'rss',
108                         'id' => $this->user->nickname
109                     )
110                 ),
111             // TRANS: %1$s is user nickname
112                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
113             new Feed(Feed::ATOM,
114                 common_local_url(
115                     'ApiTimelineFriends', array(
116                         'format' => 'atom',
117                         'id' => $this->user->nickname
118                     )
119                 ),
120                 // TRANS: %1$s is user nickname
121                 sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))
122         );
123     }
124
125     function showLocalNav()
126     {
127         $nav = new PersonalGroupNav($this);
128         $nav->show();
129     }
130
131     function showEmptyListMessage()
132     {
133         // TRANS: %1$s is 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                 $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
140             } else {
141                 // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@"
142                 $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
143             }
144         } else {
145             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname);
146         }
147
148         $this->elementStart('div', 'guide');
149         $this->raw(common_markup_to_html($message));
150         $this->elementEnd('div');
151     }
152
153     function showContent()
154     {
155         if (Event::handle('StartShowAllContent', array($this))) {
156             $nl = new NoticeList($this->notice, $this);
157
158             $cnt = $nl->show();
159
160             if (0 == $cnt) {
161                 $this->showEmptyListMessage();
162             }
163
164             $this->pagination(
165                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
166                 $this->page, 'all', array('nickname' => $this->user->nickname)
167             );
168
169             Event::handle('EndShowAllContent', array($this));
170         }
171     }
172
173     function showPageTitle()
174     {
175         $user = common_current_user();
176         if ($user && ($user->id == $this->user->id)) {
177             // TRANS: H1 text
178             $this->element('h1', null, _("You and friends"));
179         } else {
180             // TRANS: H1 text. %1$s is user nickname
181             $this->element('h1', null, sprintf(_('%s and friends'), $this->user->nickname));
182         }
183     }
184 }