]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/replies.php
.inc.php please ...
[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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * List of replies
34  *
35  * @category Personal
36  * @package  StatusNet
37  * @author   Evan Prodromou <evan@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  */
41 class RepliesAction extends ManagedAction
42 {
43     var $page = null;
44     var $notice;
45
46     protected function doPreparation()
47     {
48         $nickname = common_canonical_nickname($this->arg('nickname'));
49
50         $this->user = User::getKV('nickname', $nickname);
51
52         if (!$this->user instanceof User) {
53             // TRANS: Client error displayed when trying to reply to a non-exsting user.
54             $this->clientError(_('No such user.'));
55         }
56
57         $this->target = $this->user->getProfile();
58
59         if (!$this->target instanceof Profile) {
60             // TRANS: Error message displayed when referring to a user without a profile.
61             $this->serverError(_('User has no profile.'));
62         }
63
64         $this->page = $this->int('page') ?: 1;
65
66         common_set_returnto($this->selfUrl());
67
68         $stream = new ReplyNoticeStream($this->target->getID(), $this->scoped);
69
70         $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE,
71                                             NOTICES_PER_PAGE + 1);
72
73         if ($this->page > 1 && $this->notice->N == 0) {
74             // TRANS: Client error when page not found (404)
75             $this->clientError(_('No such page.'), 404);
76         }
77     }
78
79     /**
80      * Title of the page
81      *
82      * Includes name of user and page number.
83      *
84      * @return string title of page
85      */
86     function title()
87     {
88         if ($this->page == 1) {
89             // TRANS: Title for first page of replies for a user.
90             // TRANS: %s is a user nickname.
91             return sprintf(_("Replies to %s"), $this->target->getNickname());
92         } else {
93             // TRANS: Title for all but the first page of replies for a user.
94             // TRANS: %1$s is a user nickname, %2$d is a page number.
95             return sprintf(_('Replies to %1$s, page %2$d'),
96                            $this->target->getNickname(),
97                            $this->page);
98         }
99     }
100
101     /**
102      * Feeds for the <head> section
103      *
104      * @return void
105      */
106     function getFeeds()
107     {
108         return array(new Feed(Feed::JSON,
109                               common_local_url('ApiTimelineMentions',
110                                                array(
111                                                     'id' => $this->target->getNickname(),
112                                                     'format' => 'as')),
113                               // TRANS: Link for feed with replies for a user.
114                               // TRANS: %s is a user nickname.
115                               sprintf(_('Replies feed for %s (Activity Streams JSON)'),
116                                       $this->user->nickname)),
117                      new Feed(Feed::RSS1,
118                               common_local_url('repliesrss',
119                                                array('nickname' => $this->target->getNickname())),
120                               // TRANS: Link for feed with replies for a user.
121                               // TRANS: %s is a user nickname.
122                               sprintf(_('Replies feed for %s (RSS 1.0)'),
123                                       $this->target->getNickname())),
124                      new Feed(Feed::RSS2,
125                               common_local_url('ApiTimelineMentions',
126                                                array(
127                                                     'id' => $this->target->getNickname(),
128                                                     'format' => 'rss')),
129                               // TRANS: Link for feed with replies for a user.
130                               // TRANS: %s is a user nickname.
131                               sprintf(_('Replies feed for %s (RSS 2.0)'),
132                                       $this->target->getNickname())),
133                      new Feed(Feed::ATOM,
134                               common_local_url('ApiTimelineMentions',
135                                                array(
136                                                     'id' => $this->target->getNickname(),
137                                                     'format' => 'atom')),
138                               // TRANS: Link for feed with replies for a user.
139                               // TRANS: %s is a user nickname.
140                               sprintf(_('Replies feed for %s (Atom)'),
141                                     $this->target->getNickname())));
142     }
143
144     function showContent()
145     {
146         $nl = new PrimaryNoticeList($this->notice, $this, array('show_n'=>NOTICES_PER_PAGE));
147
148         $cnt = $nl->show();
149         if (0 === $cnt) {
150             $this->showEmptyListMessage();
151         }
152
153         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
154                           $this->page, 'replies',
155                           array('nickname' => $this->target->getNickname()));
156     }
157
158     function showEmptyListMessage()
159     {
160         // TRANS: Empty list message for page with replies for a user.
161         // TRANS: %1$s is the user nickname.
162         $message = sprintf(_('This is the timeline showing replies to %1$s but no notices have arrived yet.'), $this->target->getNickname());
163         $message .= ' ';    // Spacing between this sentence and the next.
164
165         if (common_logged_in()) {
166             if ($this->target->getID() === $this->scoped->getID()) {
167                 // TRANS: Empty list message for page with replies for a user for the logged in user.
168                 // TRANS: This message contains a Markdown link in the form [link text](link).
169                 $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
170             } else {
171                 // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
172                 // TRANS: %1$s is a user nickname and %2$s is the same but with a prepended '@' character. This message contains a Markdown link in the form [link text](link).
173                 $message .= sprintf(_('You can try to [nudge %1$s](../%1$s) or [post something to them](%%%%action.newnotice%%%%?content=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
174             }
175         } else {
176             // TRANS: Empty list message for page with replies for a user for not logged in users.
177             // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
178             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
179         }
180
181         $this->elementStart('div', 'guide');
182         $this->raw(common_markup_to_html($message));
183         $this->elementEnd('div');
184     }
185
186     public function isReadOnly(array $args = array())
187     {
188         return true;
189     }
190 }