3 * Give a warm greeting to our friendly user
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * List currently logged-in user's bookmakrs
39 * @author Stephane Berube <chimo@chromic.org>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link https://github.com/chimo/BookmarkList
43 class BookmarksAction extends Action
49 * Take arguments for running
51 * This method is called first, and it lets the action class get
52 * all its arguments and validate them. It's also the time
53 * to fetch any relevant data from the database.
55 * Action classes should run parent::prepare($args) as the first
56 * line of this method to make sure the default argument-processing
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
63 function prepare($args)
65 parent::prepare($args);
67 if (common_config('singleuser', 'enabled')) {
68 $nickname = User::singleUserNickname();
71 // $nickname = $this->returnToArgs()[1]['nickname'];
74 $nickname = $this->returnToArgs();
75 $nickname = $nickname[1]['nickname'];
78 $this->user = User::getKV('nickname', $nickname);
81 // TRANS: Client error displayed when trying to display bookmarks for a non-existing user.
82 $this->clientError(_('No such user.'));
86 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
88 $stream = new BookmarksNoticeStream($this->user->id, true);
89 $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
90 NOTICES_PER_PAGE + 1);
92 if($this->page > 1 && $this->notices->N == 0) {
93 throw new ClientException(_('No such page.'), 404);
102 * This is the main method for handling a request. Note that
103 * most preparation should be done in the prepare() method;
104 * by the time handle() is called the action should be
105 * more or less ready to go.
107 * @param array $args $_REQUEST args; handled in prepare()
111 function handle($args)
113 parent::handle($args);
120 * Override this method to show a custom title.
122 * @return string Title of the page
127 if (empty($this->user)) {
128 // TRANS: Page title for sample plugin.
131 // TRANS: Page title for sample plugin. %s is a user nickname.
132 return sprintf(_m('%s\'s bookmarks'), $this->user->nickname);
137 * Feeds for the <head> section
139 * @return array Feed objects to show
143 return array(new Feed(Feed::JSON,
144 common_local_url('ApiTimelineBookmarks',
146 'id' => $this->user->nickname,
148 // TRANS: Feed link text. %s is a username.
149 sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
150 $this->user->nickname)),
152 common_local_url('bookmarksrss',
153 array('nickname' => $this->user->nickname)),
154 // TRANS: Feed link text. %s is a username.
155 sprintf(_('Feed for favorites of %s (RSS 1.0)'),
156 $this->user->nickname)),
158 common_local_url('ApiTimelineBookmarks',
160 'id' => $this->user->nickname,
162 // TRANS: Feed link text. %s is a username.
163 sprintf(_('Feed for favorites of %s (RSS 2.0)'),
164 $this->user->nickname)),
166 common_local_url('ApiTimelineBookmarks',
168 'id' => $this->user->nickname,
169 'format' => 'atom')),
170 // TRANS: Feed link text. %s is a username.
171 sprintf(_('Feed for favorites of %s (Atom)'),
172 $this->user->nickname)));
176 * Show content in the content area
178 * The default StatusNet page has a lot of decorations: menus,
179 * logos, tabs, all that jazz. This method is used to show
180 * content in the content area of the page; it's the main
181 * thing you want to overload.
183 * This method also demonstrates use of a plural localized string.
187 function showContent()
190 $nl = new NoticeList($this->notices, $this);
195 $this->showEmptyList();
198 $this->pagination($this->page > 1,
199 $cnt > NOTICES_PER_PAGE,
200 $this->page, 'bookmarks',
201 array('nickname' => $this->user->nickname));
204 function showEmptyList() {
205 $message = sprintf(_('This is %1$s\'s bookmark stream, but %1$s hasn\'t bookmarked anything yet.'), $this->user->nickname) . ' ';
207 $this->elementStart('div', 'guide');
208 $this->raw(common_markup_to_html($message));
209 $this->elementEnd('div');
213 * Return true if read only.
215 * Some actions only read from the database; others read and write.
216 * The simple database load-balancer built into StatusNet will
217 * direct read-only actions to database mirrors (if they are configured),
218 * and read-write actions to the master database.
220 * This defaults to false to avoid data integrity issues, but you
221 * should make sure to overload it for performance gains.
223 * @param array $args other arguments, if RO/RW status depends on them.
225 * @return boolean is read only action?
227 function isReadOnly($args)