replies.php 8.88 KB
Newer Older
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
5 6 7 8 9
 * List of replies
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
10 11 12 13 14 15 16 17 18 19 20
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * 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 32
    exit(1);
}
33

34 35 36
require_once INSTALLDIR.'/lib/personalgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
37

38 39 40 41
/**
 * List of replies
 *
 * @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 54 55 56 57 58 59 60 61 62

    /**
     * Prepare the object
     *
     * Check the input values and initialize the object.
     * Shows an error page on bad input.
     *
     * @param array $args $_REQUEST data
     *
     * @return boolean success flag
     */
    function prepare($args)
63
    {
64
        parent::prepare($args);
65

66
        $nickname = common_canonical_nickname($this->arg('nickname'));
67

68 69 70
        $this->user = User::staticGet('nickname', $nickname);

        if (!$this->user) {
71
            // TRANS: Client error displayed when trying to reply to a non-exsting user.
72 73
            $this->clientError(_('No such user.'));
            return false;
74
        }
75

76
        $profile = $this->user->getProfile();
77

78
        if (!$profile) {
79
            // TRANS: Error message displayed when referring 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 89 90 91 92
        $stream = new ReplyNoticeStream($this->user->id,
                                        Profile::current());

        $this->notice = $stream->getNotices(($this->page-1) * NOTICES_PER_PAGE,
                                            NOTICES_PER_PAGE + 1);
93 94

        if($this->page > 1 && $this->notice->N == 0){
95
            // TRANS: Server error when page not found (404)
96
            $this->serverError(_('No such page.'),$code=404);
97 98
        }

99 100
        return true;
    }
101

102 103 104 105 106 107 108 109 110 111 112 113 114
    /**
     * Handle a request
     *
     * Just show the page. All args already handled.
     *
     * @param array $args $_REQUEST data
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);
        $this->showPage();
115
    }
116

117 118 119 120 121 122 123 124
    /**
     * Title of the page
     *
     * Includes name of user and page number.
     *
     * @return string title of page
     */
    function title()
125
    {
126
        if ($this->page == 1) {
127 128
            // TRANS: Title for first page of replies for a user.
            // TRANS: %s is a user nickname.
129 130
            return sprintf(_("Replies to %s"), $this->user->nickname);
        } else {
131 132
            // TRANS: Title for all but the first page of replies for a user.
            // TRANS: %1$s is a user nickname, %2$d is a page number.
133
            return sprintf(_('Replies to %1$s, page %2$d'),
Evan Prodromou's avatar
Evan Prodromou committed
134
                           $this->user->nickname,
135 136
                           $this->page);
        }
137
    }
Evan Prodromou's avatar
Evan Prodromou committed
138

139 140 141 142 143
    /**
     * Feeds for the <head> section
     *
     * @return void
     */
144
    function getFeeds()
145
    {
146 147 148 149 150 151 152 153 154 155
        return array(new Feed(Feed::JSON,
                              common_local_url('ApiTimelineMentions',
                                               array(
                                                    'id' => $this->user->nickname,
                                                    'format' => 'as')),
                              // TRANS: Link for feed with replies for a user.
                              // TRANS: %s is a user nickname.
                              sprintf(_('Replies feed for %s (Activity Streams JSON)'),
                                      $this->user->nickname)),
                     new Feed(Feed::RSS1,
156 157
                              common_local_url('repliesrss',
                                               array('nickname' => $this->user->nickname)),
158 159
                              // TRANS: Link for feed with replies for a user.
                              // TRANS: %s is a user nickname.
160 161 162 163 164 165 166
                              sprintf(_('Replies feed for %s (RSS 1.0)'),
                                      $this->user->nickname)),
                     new Feed(Feed::RSS2,
                              common_local_url('ApiTimelineMentions',
                                               array(
                                                    'id' => $this->user->nickname,
                                                    'format' => 'rss')),
167 168
                              // TRANS: Link for feed with replies for a user.
                              // TRANS: %s is a user nickname.
169 170 171 172 173 174 175
                              sprintf(_('Replies feed for %s (RSS 2.0)'),
                                      $this->user->nickname)),
                     new Feed(Feed::ATOM,
                              common_local_url('ApiTimelineMentions',
                                               array(
                                                    'id' => $this->user->nickname,
                                                    'format' => 'atom')),
176 177
                              // TRANS: Link for feed with replies for a user.
                              // TRANS: %s is a user nickname.
178 179
                              sprintf(_('Replies feed for %s (Atom)'),
                                    $this->user->nickname)));
180
    }
181

182 183 184 185 186 187 188 189 190
    /**
     * Show the content
     *
     * A list of notices that are replies to the user, plus pagination.
     *
     * @return void
     */
    function showContent()
    {
191
        $nl = new NoticeList($this->notice, $this);
192

193
        $cnt = $nl->show();
194 195 196
        if (0 === $cnt) {
            $this->showEmptyListMessage();
        }
197

198 199 200
        $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                          $this->page, 'replies',
                          array('nickname' => $this->user->nickname));
201
    }
202

203 204
    function showEmptyListMessage()
    {
205 206 207 208 209
        // TRANS: Empty list message for page with replies for a user.
        // TRANS: %1$s and %s$s are the user nickname.
        $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to them yet.'),
                           $this->user->nickname,
                           $this->user->nickname) . ' ';
210 211 212 213

        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
214 215
                // TRANS: Empty list message for page with replies for a user for the logged in user.
                // TRANS: This message contains a Markdown link in the form [link text](link).
216 217
                $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).');
            } else {
218 219
                // TRANS: Empty list message for page with replies for a user for all logged in users but the user themselves.
                // TRANS: %1$s, %2$s and %3$s are a user nickname. This message contains a Markdown link in the form [link text](link).
220
                $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);
221 222 223
            }
        }
        else {
224 225
            // TRANS: Empty list message for page with replies for a user for not logged in users.
            // TRANS: %1$s is a user nickname. This message contains a Markdown link in the form [link text](link).
226
            $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
227 228 229 230 231 232 233
        }

        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }

234
    function isReadOnly($args)
235 236 237
    {
        return true;
    }
238
}