favorited.php 5.33 KB
Newer Older
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
5 6 7 8 9
 * List of popular notices
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
10 11 12 13 14 15
 * 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
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 18 19
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
20 21 22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Public
23
 * @package   StatusNet
24 25
 * @author    Zach Copley <zach@status.net>
 * @author    Evan Prodromou <evan@status.net>
26
 * @copyright 2008-2009 StatusNet, Inc.
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28
 * @link      http://status.net/
29 30
 */

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
32 33 34 35 36
    exit(1);
}

require_once INSTALLDIR.'/lib/publicgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
37

38 39 40 41 42 43 44
/**
 * List of popular notices
 *
 * We provide a list of the most popular notices. Popularity
 * is measured by
 *
 * @category Personal
45
 * @package  StatusNet
46 47
 * @author   Zach Copley <zach@status.net>
 * @author   Evan Prodromou <evan@status.net>
48
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49
 * @link     http://status.net/
50 51
 */
class FavoritedAction extends Action
52
{
53
    var $page = null;
54

55 56 57 58 59 60 61
    /**
     * Title of the page
     *
     * @return string Title of the page
     */

    function title()
62
    {
63
        if ($this->page == 1) {
64
            // TRANS: Page title for first page of favorited notices.
65 66
            return _('Popular notices');
        } else {
67 68
            // TRANS: Page title for all but first page of favorited notices.
            // TRANS: %d is the page number being displayed.
69 70 71
            return sprintf(_('Popular notices, page %d'), $this->page);
        }
    }
72

73 74 75 76 77 78 79
    /**
     * Instructions for use
     *
     * @return instructions for use
     */
    function getInstructions()
    {
80
        // TRANS: Description on page displaying favorited notices.
81 82
        return _('The most popular notices on the site right now.');
    }
83

84 85 86 87 88
    /**
     * Is this page read-only?
     *
     * @return boolean true
     */
89
    function isReadOnly($args)
90 91
    {
        return true;
92
    }
93

94 95 96 97 98 99 100 101 102 103
    /**
     * Take arguments for running
     *
     * @param array $args $_REQUEST args
     *
     * @return boolean success flag
     *
     * @todo move queries from showContent() to here
     */
    function prepare($args)
104
    {
105 106
        parent::prepare($args);
        $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
107

108
        common_set_returnto($this->selfUrl());
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        return true;
    }

    /**
     * Handle request
     *
     * Shows a page with list of favorite notices
     *
     * @param array $args $_REQUEST args; handled in prepare()
     *
     * @return void
     */
    function handle($args)
    {
        parent::handle($args);

        $this->showPage();
    }

    /**
     * Show the page notice
     *
     * Shows instructions for the page
     *
     * @return void
     */
    function showPageNotice()
    {
        $instr  = $this->getInstructions();
139
        $output = common_markup_to_html($instr);
140

141 142 143
        $this->elementStart('div', 'instructions');
        $this->raw($output);
        $this->elementEnd('div');
144
    }
145

146 147
    function showEmptyList()
    {
148
        // TRANS: Text displayed instead of a list when a site does not yet have any favourited notices.
149
        $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
150 151

        if (common_logged_in()) {
152
            // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for logged in users.
153 154 155
            $message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
        }
        else {
156 157
            // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for not logged in users.
            // TRANS: %%action.register%% is a registration link. "[link text](link)" is Mark Down. Do not change the formatting.
158
            $message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
159 160
        }

161
        $this->elementStart('div', 'guide');
162 163
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
164
    }
165

166 167 168 169 170 171 172 173 174
    /**
     * Content area
     *
     * Shows the list of popular notices
     *
     * @return void
     */
    function showContent()
    {
175 176
        $stream = new PopularNoticeStream(Profile::current());
        $notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1);
177

178
        $nl = new NoticeList($notice, $this);
179

180
        $cnt = $nl->show();
181

182 183 184 185
        if ($cnt == 0) {
            $this->showEmptyList();
        }

186 187
        $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                          $this->page, 'favorited');
188
    }
189
}