We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

showfavorites.php 7.62 KB
Newer Older
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
Evan Prodromou's avatar
Evan Prodromou committed
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/>.
Evan Prodromou's avatar
Evan Prodromou committed
21 22
 *
 * @category  Personal
23
 * @package   StatusNet
24
 * @author    Evan Prodromou <evan@status.net>
25
 * @copyright 2008-2009 StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
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')) {
Evan Prodromou's avatar
Evan Prodromou committed
31 32
    exit(1);
}
33

Evan Prodromou's avatar
Evan Prodromou committed
34 35 36
require_once INSTALLDIR.'/lib/personalgroupnav.php';
require_once INSTALLDIR.'/lib/noticelist.php';
require_once INSTALLDIR.'/lib/feedlist.php';
37

Evan Prodromou's avatar
Evan Prodromou committed
38 39 40 41
/**
 * List of replies
 *
 * @category Personal
42
 * @package  StatusNet
43
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
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/
Evan Prodromou's avatar
Evan Prodromou committed
46
 */
47

48
class ShowfavoritesAction extends OwnerDesignAction
Evan Prodromou's avatar
Evan Prodromou committed
49 50 51 52 53 54
{
    /** User we're getting the faves of */
    var $user = null;
    /** Page of the faves we're on */
    var $page = null;

Evan Prodromou's avatar
Evan Prodromou committed
55 56 57 58 59 60
    /**
     * Is this a read-only page?
     *
     * @return boolean true
     */

61
    function isReadOnly($args)
Evan Prodromou's avatar
Evan Prodromou committed
62 63 64 65
    {
        return true;
    }

Evan Prodromou's avatar
Evan Prodromou committed
66 67 68 69 70 71 72 73 74
    /**
     * Title of the page
     *
     * Includes name of user and page number.
     *
     * @return string title of page
     */

    function title()
75
    {
Evan Prodromou's avatar
Evan Prodromou committed
76
        if ($this->page == 1) {
77
            return sprintf(_('%s\'s favorite notices'), $this->user->nickname);
Evan Prodromou's avatar
Evan Prodromou committed
78
        } else {
79
            return sprintf(_('%1$s\'s favorite notices, page %2$d'),
Evan Prodromou's avatar
Evan Prodromou committed
80 81 82 83
                           $this->user->nickname,
                           $this->page);
        }
    }
84

Evan Prodromou's avatar
Evan Prodromou committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    /**
     * 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)
    {
        parent::prepare($args);
99

100
        $nickname = common_canonical_nickname($this->arg('nickname'));
101

Evan Prodromou's avatar
Evan Prodromou committed
102 103 104
        $this->user = User::staticGet('nickname', $nickname);

        if (!$this->user) {
105
            $this->clientError(_('No such user.'));
Evan Prodromou's avatar
Evan Prodromou committed
106
            return false;
107
        }
108

Evan Prodromou's avatar
Evan Prodromou committed
109
        $this->page = $this->trimmed('page');
110

Evan Prodromou's avatar
Evan Prodromou committed
111 112
        if (!$this->page) {
            $this->page = 1;
113
        }
114

115
        common_set_returnto($this->selfUrl());
116

117 118 119 120 121
        $cur = common_current_user();

        if (!empty($cur) && $cur->id == $this->user->id) {

            // Show imported/gateway notices as well as local if
122
            // the user is looking at their own favorites
123

124 125
            $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE,
                                                   NOTICES_PER_PAGE + 1);
126
        } else {
127 128
            $this->notice = $this->user->favoriteNotices(false, ($this->page-1)*NOTICES_PER_PAGE,
                                                   NOTICES_PER_PAGE + 1);
129 130 131 132 133 134 135 136
        }

        if (empty($this->notice)) {
            $this->serverError(_('Could not retrieve favorite notices.'));
            return;
        }

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

Evan Prodromou's avatar
Evan Prodromou committed
141 142
        return true;
    }
143

Evan Prodromou's avatar
Evan Prodromou committed
144 145 146 147 148 149 150 151 152
    /**
     * Handle a request
     *
     * Just show the page. All args already handled.
     *
     * @param array $args $_REQUEST data
     *
     * @return void
     */
153

Evan Prodromou's avatar
Evan Prodromou committed
154 155 156 157
    function handle($args)
    {
        parent::handle($args);
        $this->showPage();
158
    }
159

Evan Prodromou's avatar
Evan Prodromou committed
160 161 162
    /**
     * Feeds for the <head> section
     *
163
     * @return array Feed objects to show
Evan Prodromou's avatar
Evan Prodromou committed
164 165
     */

166
    function getFeeds()
167
    {
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        return array(new Feed(Feed::RSS1,
                              common_local_url('favoritesrss',
                                               array('nickname' => $this->user->nickname)),
                              sprintf(_('Feed for favorites of %s (RSS 1.0)'),
                                      $this->user->nickname)),
                     new Feed(Feed::RSS2,
                              common_local_url('ApiTimelineFavorites',
                                               array(
                                                    'id' => $this->user->nickname,
                                                    'format' => 'rss')),
                              sprintf(_('Feed for favorites of %s (RSS 2.0)'),
                                      $this->user->nickname)),
                     new Feed(Feed::ATOM,
                              common_local_url('ApiTimelineFavorites',
                                               array(
                                                    'id' => $this->user->nickname,
                                                    'format' => 'atom')),
                              sprintf(_('Feed for favorites of %s (Atom)'),
                                      $this->user->nickname)));
187
    }
188

Evan Prodromou's avatar
Evan Prodromou committed
189 190 191 192 193
    /**
     * show the personal group nav
     *
     * @return void
     */
194

Evan Prodromou's avatar
Evan Prodromou committed
195 196 197 198
    function showLocalNav()
    {
        $nav = new PersonalGroupNav($this);
        $nav->show();
199
    }
200

201 202 203 204 205 206 207
    function showEmptyListMessage()
    {
        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
                $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.');
            } else {
208
                $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
209 210 211
            }
        }
        else {
212
            $message = sprintf(_('%s hasn\'t added any favorite notices yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname);
213 214 215 216 217 218 219
        }

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

Evan Prodromou's avatar
Evan Prodromou committed
220 221 222 223 224 225 226
    /**
     * Show the content
     *
     * A list of notices that this user has marked as a favorite
     *
     * @return void
     */
227

Evan Prodromou's avatar
Evan Prodromou committed
228 229
    function showContent()
    {
230
        $nl = new FavoritesNoticeList($this->notice, $this);
Evan Prodromou's avatar
Evan Prodromou committed
231 232

        $cnt = $nl->show();
233
        if (0 == $cnt) {
234
            $this->showEmptyListMessage();
235
        }
236

Evan Prodromou's avatar
Evan Prodromou committed
237 238 239
        $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
                          $this->page, 'showfavorites',
                          array('nickname' => $this->user->nickname));
240
    }
241 242 243 244

    function showPageNotice() {
        $this->element('p', 'instructions', _('This is a way to share what you like.'));
    }
245
}
246

247 248 249 250 251 252 253 254 255 256 257 258
class FavoritesNoticeList extends NoticeList
{
    function newListItem($notice)
    {
        return new FavoritesNoticeListItem($notice, $this->out);
    }
}

// All handled by superclass
class FavoritesNoticeListItem extends DoFollowListItem
{
}