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