]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/replies.php
Merge branch 'limitdist' of gitorious.org:~evan/statusnet/evans-mainline into limitdist
[quix0rs-gnu-social.git] / actions / replies.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of replies
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * List of replies
40  *
41  * @category Personal
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47 class RepliesAction extends OwnerDesignAction
48 {
49     var $page = null;
50     var $notice;
51
52     /**
53      * Prepare the object
54      *
55      * Check the input values and initialize the object.
56      * Shows an error page on bad input.
57      *
58      * @param array $args $_REQUEST data
59      *
60      * @return boolean success flag
61      */
62     function prepare($args)
63     {
64         parent::prepare($args);
65
66         $nickname = common_canonical_nickname($this->arg('nickname'));
67
68         $this->user = User::staticGet('nickname', $nickname);
69
70         if (!$this->user) {
71             // TRANS: Client error displayed when trying to reply to a non-exsting user.
72             $this->clientError(_('No such user.'));
73             return false;
74         }
75
76         $profile = $this->user->getProfile();
77
78         if (!$profile) {
79             // TRANS: Server error displayed when trying to reply to a user without a profile.
80             $this->serverError(_('User has no profile.'));
81             return false;
82         }
83
84         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
85
86         common_set_returnto($this->selfUrl());
87
88         $this->notice = $this->user->getReplies(($this->page-1) * NOTICES_PER_PAGE,
89              NOTICES_PER_PAGE + 1);
90
91         if($this->page > 1 && $this->notice->N == 0){
92             // TRANS: Server error when page not found (404)
93             $this->serverError(_('No such page.'),$code=404);
94         }
95
96         return true;
97     }
98
99     /**
100      * Handle a request
101      *
102      * Just show the page. All args already handled.
103      *
104      * @param array $args $_REQUEST data
105      *
106      * @return void
107      */
108     function handle($args)
109     {
110         parent::handle($args);
111         $this->showPage();
112     }
113
114     /**
115      * Title of the page
116      *
117      * Includes name of user and page number.
118      *
119      * @return string title of page
120      */
121     function title()
122     {
123         if ($this->page == 1) {
124             // TRANS: Title for first page of replies for a user.
125             // TRANS: %s is a user nickname.
126             return sprintf(_("Replies to %s"), $this->user->nickname);
127         } else {
128             // TRANS: Title for all but the first page of replies for a user.
129             // TRANS: %1$s is a user nickname, %2$d is a page number.
130             return sprintf(_('Replies to %1$s, page %2$d'),
131                            $this->user->nickname,
132                            $this->page);
133         }
134     }
135
136     /**
137      * Feeds for the <head> section
138      *
139      * @return void
140      */
141     function getFeeds()
142     {
143         return array(new Feed(Feed::RSS1,
144                               common_local_url('repliesrss',
145                                                array('nickname' => $this->user->nickname)),
146                               // TRANS: Link for feed with replies for a user.
147                               // TRANS: %s is a user nickname.
148                               sprintf(_('Replies feed for %s (RSS 1.0)'),
149                                       $this->user->nickname)),
150                      new Feed(Feed::RSS2,
151                               common_local_url('ApiTimelineMentions',
152                                                array(
153                                                     'id' => $this->user->nickname,
154                                                     'format' => 'rss')),
155                               // TRANS: Link for feed with replies for a user.
156                               // TRANS: %s is a user nickname.
157                               sprintf(_('Replies feed for %s (RSS 2.0)'),
158                                       $this->user->nickname)),
159                      new Feed(Feed::ATOM,
160                               common_local_url('ApiTimelineMentions',
161                                                array(
162                                                     'id' => $this->user->nickname,
163                                                     'format' => 'atom')),
164                               // TRANS: Link for feed with replies for a user.
165                               // TRANS: %s is a user nickname.
166                               sprintf(_('Replies feed for %s (Atom)'),
167                                     $this->user->nickname)));
168     }
169
170     /**
171      * Show the content
172      *
173      * A list of notices that are replies to the user, plus pagination.
174      *
175      * @return void
176      */
177     function showContent()
178     {
179         $nl = new NoticeList($this->notice, $this);
180
181         $cnt = $nl->show();
182         if (0 === $cnt) {
183             $this->showEmptyListMessage();
184         }
185
186         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
187                           $this->page, 'replies',
188                           array('nickname' => $this->user->nickname));
189     }
190
191     function showEmptyListMessage()
192     {
193         // TRANS: Empty list message for page with replies for a user.
194         // TRANS: %1$s and %s$s are the user nickname.
195         $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to them yet.'),
196                            $this->user->nickname,
197                            $this->user->nickname) . ' ';
198
199         if (common_logged_in()) {
200             $current_user = common_current_user();
201             if ($this->user->id === $current_user->id) {
202                 // TRANS: Empty list message for page with replies for a user for the logged in user.
203                 // TRANS: This message contains a Markdown link in the form [link text](link).
204                 $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
205             } else {
206                 // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
207                 // TRANS: %1$s, %2$s and %3$s are a user nickname. This message contains a Markdown link in the form [link text](link).
208                 $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) or [post something to them](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname);
209             }
210         }
211         else {
212             // TRANS: Empty list message for page with replies for a user for not logged in users.
213             // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
214             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
215         }
216
217         $this->elementStart('div', 'guide');
218         $this->raw(common_markup_to_html($message));
219         $this->elementEnd('div');
220     }
221
222     function isReadOnly($args)
223     {
224         return true;
225     }
226 }