]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/replies.php
Merge branch 'master' of gitorious.org:social/mainline
[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-2011 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 Action
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(array $args=array())
63     {
64         parent::prepare($args);
65
66         $nickname = common_canonical_nickname($this->arg('nickname'));
67
68         $this->user = User::getKV('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         }
74
75         $profile = $this->user->getProfile();
76
77         if (!$profile) {
78             // TRANS: Error message displayed when referring to a user without a profile.
79             $this->serverError(_('User has no profile.'));
80         }
81
82         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
83
84         common_set_returnto($this->selfUrl());
85
86         $stream = new ReplyNoticeStream($this->user->id,
87                                         Profile::current());
88
89         $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE,
90                                             NOTICES_PER_PAGE + 1);
91
92         if($this->page > 1 && $this->notice->N == 0){
93             // TRANS: Client error when page not found (404)
94             $this->clientError(_('No such page.'), 404);
95         }
96
97         return true;
98     }
99
100     /**
101      * Handle a request
102      *
103      * Just show the page. All args already handled.
104      *
105      * @param array $args $_REQUEST data
106      *
107      * @return void
108      */
109     function handle(array $args=array())
110     {
111         parent::handle($args);
112         $this->showPage();
113     }
114
115     /**
116      * Title of the page
117      *
118      * Includes name of user and page number.
119      *
120      * @return string title of page
121      */
122     function title()
123     {
124         if ($this->page == 1) {
125             // TRANS: Title for first page of replies for a user.
126             // TRANS: %s is a user nickname.
127             return sprintf(_("Replies to %s"), $this->user->nickname);
128         } else {
129             // TRANS: Title for all but the first page of replies for a user.
130             // TRANS: %1$s is a user nickname, %2$d is a page number.
131             return sprintf(_('Replies to %1$s, page %2$d'),
132                            $this->user->nickname,
133                            $this->page);
134         }
135     }
136
137     /**
138      * Feeds for the <head> section
139      *
140      * @return void
141      */
142     function getFeeds()
143     {
144         return array(new Feed(Feed::JSON,
145                               common_local_url('ApiTimelineMentions',
146                                                array(
147                                                     'id' => $this->user->nickname,
148                                                     'format' => 'as')),
149                               // TRANS: Link for feed with replies for a user.
150                               // TRANS: %s is a user nickname.
151                               sprintf(_('Replies feed for %s (Activity Streams JSON)'),
152                                       $this->user->nickname)),
153                      new Feed(Feed::RSS1,
154                               common_local_url('repliesrss',
155                                                array('nickname' => $this->user->nickname)),
156                               // TRANS: Link for feed with replies for a user.
157                               // TRANS: %s is a user nickname.
158                               sprintf(_('Replies feed for %s (RSS 1.0)'),
159                                       $this->user->nickname)),
160                      new Feed(Feed::RSS2,
161                               common_local_url('ApiTimelineMentions',
162                                                array(
163                                                     'id' => $this->user->nickname,
164                                                     'format' => 'rss')),
165                               // TRANS: Link for feed with replies for a user.
166                               // TRANS: %s is a user nickname.
167                               sprintf(_('Replies feed for %s (RSS 2.0)'),
168                                       $this->user->nickname)),
169                      new Feed(Feed::ATOM,
170                               common_local_url('ApiTimelineMentions',
171                                                array(
172                                                     'id' => $this->user->nickname,
173                                                     'format' => 'atom')),
174                               // TRANS: Link for feed with replies for a user.
175                               // TRANS: %s is a user nickname.
176                               sprintf(_('Replies feed for %s (Atom)'),
177                                     $this->user->nickname)));
178     }
179
180     /**
181      * Show the content
182      *
183      * A list of notices that are replies to the user, plus pagination.
184      *
185      * @return void
186      */
187     function showContent()
188     {
189         $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
190
191         $cnt = $nl->show();
192         if (0 === $cnt) {
193             $this->showEmptyListMessage();
194         }
195
196         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
197                           $this->page, 'replies',
198                           array('nickname' => $this->user->nickname));
199     }
200
201     function showEmptyListMessage()
202     {
203         // TRANS: Empty list message for page with replies for a user.
204         // TRANS: %1$s and %s$s are the user nickname.
205         $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to them yet.'),
206                            $this->user->nickname,
207                            $this->user->nickname) . ' ';
208
209         if (common_logged_in()) {
210             $current_user = common_current_user();
211             if ($this->user->id === $current_user->id) {
212                 // TRANS: Empty list message for page with replies for a user for the logged in user.
213                 // TRANS: This message contains a Markdown link in the form [link text](link).
214                 $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
215             } else {
216                 // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
217                 // TRANS: %1$s, %2$s and %3$s are a user nickname. This message contains a Markdown link in the form [link text](link).
218                 $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);
219             }
220         }
221         else {
222             // TRANS: Empty list message for page with replies for a user for not logged in users.
223             // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
224             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
225         }
226
227         $this->elementStart('div', 'guide');
228         $this->raw(common_markup_to_html($message));
229         $this->elementEnd('div');
230     }
231
232     function isReadOnly(array $args=array())
233     {
234         return true;
235     }
236 }