]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/all.php
Assigning my copyrights to the Free Software Foundation
[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  * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
31  * @license  GNU Affero General Public License http://www.gnu.org/licenses/
32  * @link     http://status.net
33  */
34
35 if (!defined('STATUSNET') && !defined('LACONICA')) {
36     exit(1);
37 }
38
39 require_once INSTALLDIR.'/lib/personalgroupnav.php';
40 require_once INSTALLDIR.'/lib/noticelist.php';
41 require_once INSTALLDIR.'/lib/feedlist.php';
42
43 class AllAction extends ProfileAction
44 {
45     var $notice;
46
47     function isReadOnly($args)
48     {
49         return true;
50     }
51
52     function prepare($args)
53     {
54         parent::prepare($args);
55         $cur = common_current_user();
56
57         if (!empty($cur) && $cur->id == $this->user->id) {
58             $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
59         } else {
60             $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
61         }
62
63         if ($this->page > 1 && $this->notice->N == 0) {
64             // TRANS: Server error when page not found (404)
65             $this->serverError(_('No such page.'), $code = 404);
66         }
67
68         return true;
69     }
70
71     function handle($args)
72     {
73         parent::handle($args);
74
75         if (!$this->user) {
76             $this->clientError(_('No such user.'));
77             return;
78         }
79
80         $this->showPage();
81     }
82
83     function title()
84     {
85         if ($this->page > 1) {
86             // TRANS: Page title. %1$s is user nickname, %2$d is page number
87             return sprintf(_('%1$s and friends, page %2$d'), $this->user->nickname, $this->page);
88         } else {
89             // TRANS: Page title. %1$s is user nickname
90             return sprintf(_("%s and friends"), $this->user->nickname);
91         }
92     }
93
94     function getFeeds()
95     {
96         return array(
97             new Feed(Feed::RSS1,
98                 common_local_url(
99                     'allrss', array(
100                         'nickname' =>
101                         $this->user->nickname)
102                 ),
103             // TRANS: %1$s is user nickname
104                 sprintf(_('Feed for friends of %s (RSS 1.0)'), $this->user->nickname)),
105             new Feed(Feed::RSS2,
106                 common_local_url(
107                     'ApiTimelineFriends', array(
108                         'format' => 'rss',
109                         'id' => $this->user->nickname
110                     )
111                 ),
112             // TRANS: %1$s is user nickname
113                 sprintf(_('Feed for friends of %s (RSS 2.0)'), $this->user->nickname)),
114             new Feed(Feed::ATOM,
115                 common_local_url(
116                     'ApiTimelineFriends', array(
117                         'format' => 'atom',
118                         'id' => $this->user->nickname
119                     )
120                 ),
121                 // TRANS: %1$s is user nickname
122                 sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))
123         );
124     }
125
126     function showLocalNav()
127     {
128         $nav = new PersonalGroupNav($this);
129         $nav->show();
130     }
131
132     function showEmptyListMessage()
133     {
134         // TRANS: %1$s is user nickname
135         $message = sprintf(_('This is the timeline for %s and friends but no one has posted anything yet.'), $this->user->nickname) . ' ';
136
137         if (common_logged_in()) {
138             $current_user = common_current_user();
139             if ($this->user->id === $current_user->id) {
140                 $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.');
141             } else {
142                 // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@"
143                 $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);
144             }
145         } else {
146             $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);
147         }
148
149         $this->elementStart('div', 'guide');
150         $this->raw(common_markup_to_html($message));
151         $this->elementEnd('div');
152     }
153
154     function showContent()
155     {
156         if (Event::handle('StartShowAllContent', array($this))) {
157             $nl = new NoticeList($this->notice, $this);
158
159             $cnt = $nl->show();
160
161             if (0 == $cnt) {
162                 $this->showEmptyListMessage();
163             }
164
165             $this->pagination(
166                 $this->page > 1, $cnt > NOTICES_PER_PAGE,
167                 $this->page, 'all', array('nickname' => $this->user->nickname)
168             );
169
170             Event::handle('EndShowAllContent', array($this));
171         }
172     }
173
174     function showPageTitle()
175     {
176         $user = common_current_user();
177         if ($user && ($user->id == $this->user->id)) {
178             // TRANS: H1 text
179             $this->element('h1', null, _("You and friends"));
180         } else {
181             // TRANS: H1 text. %1$s is user nickname
182             $this->element('h1', null, sprintf(_('%s and friends'), $this->user->nickname));
183         }
184     }
185 }