3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
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/
47 class ShowfavoritesAction extends Action
49 /** User we're getting the faves of */
51 /** Page of the faves we're on */
55 * Is this a read-only page?
57 * @return boolean true
59 function isReadOnly($args)
67 * Includes name of user and page number.
69 * @return string title of page
73 if ($this->page == 1) {
74 // TRANS: Title for first page of favourite notices of a user.
75 // TRANS: %s is the user for whom the favourite notices are displayed.
76 return sprintf(_('%s\'s favorite notices'), $this->user->nickname);
78 // TRANS: Title for all but the first page of favourite notices of a user.
79 // TRANS: %1$s is the user for whom the favourite notices are displayed, %2$d is the page number.
80 return sprintf(_('%1$s\'s favorite notices, page %2$d'),
81 $this->user->nickname,
89 * Check the input values and initialize the object.
90 * Shows an error page on bad input.
92 * @param array $args $_REQUEST data
94 * @return boolean success flag
96 function prepare($args)
98 parent::prepare($args);
100 $nickname = common_canonical_nickname($this->arg('nickname'));
102 $this->user = User::getKV('nickname', $nickname);
105 // TRANS: Client error displayed when trying to display favourite notices for a non-existing user.
106 $this->clientError(_('No such user.'));
109 $this->page = $this->trimmed('page');
115 common_set_returnto($this->selfUrl());
117 $cur = common_current_user();
119 if (!empty($cur) && $cur->id == $this->user->id) {
121 // Show imported/gateway notices as well as local if
122 // the user is looking at their own favorites
124 $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE,
125 NOTICES_PER_PAGE + 1);
127 $this->notice = $this->user->favoriteNotices(false, ($this->page-1)*NOTICES_PER_PAGE,
128 NOTICES_PER_PAGE + 1);
131 if (empty($this->notice)) {
132 // TRANS: Server error displayed when favourite notices could not be retrieved from the database.
133 $this->serverError(_('Could not retrieve favorite notices.'));
136 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);
147 * Just show the page. All args already handled.
149 * @param array $args $_REQUEST data
153 function handle($args)
155 parent::handle($args);
160 * Feeds for the <head> section
162 * @return array Feed objects to show
166 return array(new Feed(Feed::JSON,
167 common_local_url('ApiTimelineFavorites',
169 'id' => $this->user->nickname,
171 // TRANS: Feed link text. %s is a username.
172 sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
173 $this->user->nickname)),
175 common_local_url('favoritesrss',
176 array('nickname' => $this->user->nickname)),
177 // TRANS: Feed link text. %s is a username.
178 sprintf(_('Feed for favorites of %s (RSS 1.0)'),
179 $this->user->nickname)),
181 common_local_url('ApiTimelineFavorites',
183 'id' => $this->user->nickname,
185 // TRANS: Feed link text. %s is a username.
186 sprintf(_('Feed for favorites of %s (RSS 2.0)'),
187 $this->user->nickname)),
189 common_local_url('ApiTimelineFavorites',
191 'id' => $this->user->nickname,
192 'format' => 'atom')),
193 // TRANS: Feed link text. %s is a username.
194 sprintf(_('Feed for favorites of %s (Atom)'),
195 $this->user->nickname)));
198 function showEmptyListMessage()
200 if (common_logged_in()) {
201 $current_user = common_current_user();
202 if ($this->user->id === $current_user->id) {
203 // TRANS: Text displayed instead of favourite notices for the current logged in user that has no favourites.
204 $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.');
206 // TRANS: Text displayed instead of favourite notices for a user that has no favourites while logged in.
207 // TRANS: %s is a username.
208 $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
212 // TRANS: Text displayed instead of favourite notices for a user that has no favourites while not logged in.
213 // TRANS: %s is a username, %%%%action.register%%%% is a link to the user registration page.
214 // TRANS: (link text)[link] is a Mark Down link.
215 $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);
218 $this->elementStart('div', 'guide');
219 $this->raw(common_markup_to_html($message));
220 $this->elementEnd('div');
226 * A list of notices that this user has marked as a favorite
230 function showContent()
232 $nl = new FavoritesNoticeList($this->notice, $this);
236 $this->showEmptyListMessage();
239 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
240 $this->page, 'showfavorites',
241 array('nickname' => $this->user->nickname));
244 function showPageNotice() {
245 // TRANS: Page notice for show favourites page.
246 $this->element('p', 'instructions', _('This is a way to share what you like.'));
250 class FavoritesNoticeList extends NoticeList
252 function newListItem($notice)
254 return new FavoritesNoticeListItem($notice, $this->out);
258 // All handled by superclass
259 class FavoritesNoticeListItem extends DoFollowListItem