]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/actions/bookmarks.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Bookmark / actions / bookmarks.php
1 <?php
2 /**
3  * Give a warm greeting to our friendly user
4  *
5  * PHP version 5
6  *
7  * @category Bookmark
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2009, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * List currently logged-in user's bookmakrs
36  *
37  * @category Bookmark
38  * @package  StatusNet
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
42  */
43 class BookmarksAction extends Action
44 {
45     var $user = null;
46     var $gc   = null;
47
48     /**
49      * Take arguments for running
50      *
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.
54      *
55      * Action classes should run parent::prepare($args) as the first
56      * line of this method to make sure the default argument-processing
57      * happens.
58      *
59      * @param array $args $_REQUEST args
60      *
61      * @return boolean success flag
62      */
63     function prepare(array $args=array())
64     {
65         parent::prepare($args);
66
67         if (common_config('singleuser', 'enabled')) {
68             $nickname = User::singleUserNickname();
69         } else {
70             // PHP 5.4
71             // $nickname = $this->returnToArgs()[1]['nickname'];
72
73             // PHP < 5.4
74             $nickname = $this->returnToArgs();
75             $nickname = $nickname[1]['nickname'];
76         }
77
78         $this->user = User::getKV('nickname', $nickname);
79
80         if (!$this->user) {
81             // TRANS: Client error displayed when trying to display bookmarks for a non-existing user.
82             $this->clientError(_('No such user.'));
83         }
84
85         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
86
87         $stream = new BookmarksNoticeStream($this->user->id, true);
88         $this->notices = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
89                                                 NOTICES_PER_PAGE + 1); 
90
91         if($this->page > 1 && $this->notices->N == 0) {
92             throw new ClientException(_('No such page.'), 404);
93         }
94
95         return true;
96     }
97
98     /**
99      * Handle request
100      *
101      * This is the main method for handling a request. Note that
102      * most preparation should be done in the prepare() method;
103      * by the time handle() is called the action should be
104      * more or less ready to go.
105      *
106      * @param array $args $_REQUEST args; handled in prepare()
107      *
108      * @return void
109      */
110     function handle(array $args=array())
111     {
112         parent::handle($args);
113         $this->showPage();
114     }
115
116     /**
117      * Title of this page
118      *
119      * Override this method to show a custom title.
120      *
121      * @return string Title of the page
122      */
123     function title()
124     {
125
126         if (empty($this->user)) {
127             // TRANS: Page title for sample plugin.
128             return _m('Log in');
129         } else {
130             // TRANS: Page title for sample plugin. %s is a user nickname.
131             return sprintf(_m('%s\'s bookmarks'), $this->user->nickname);
132         }
133     }
134
135     /**
136      * Feeds for the <head> section
137      *
138      * @return array Feed objects to show
139      */
140     function getFeeds()
141     {
142         return array(new Feed(Feed::JSON,
143                               common_local_url('ApiTimelineBookmarks',
144                                                array(
145                                                     'id' => $this->user->nickname,
146                                                     'format' => 'as')),
147                               // TRANS: Feed link text. %s is a username.
148                               sprintf(_('Feed for bookmarks of %s (Activity Streams JSON)'),
149                                       $this->user->nickname)),
150                      new Feed(Feed::RSS1,
151                               common_local_url('bookmarksrss',
152                                                array('nickname' => $this->user->nickname)),
153                               // TRANS: Feed link text. %s is a username.
154                               sprintf(_('Feed for bookmarks of %s (RSS 1.0)'),
155                                       $this->user->nickname)),
156                      new Feed(Feed::RSS2,
157                               common_local_url('ApiTimelineBookmarks',
158                                                array(
159                                                     'id' => $this->user->nickname,
160                                                     'format' => 'rss')),
161                               // TRANS: Feed link text. %s is a username.
162                               sprintf(_('Feed for bookmarks of %s (RSS 2.0)'),
163                                       $this->user->nickname)),
164                      new Feed(Feed::ATOM,
165                               common_local_url('ApiTimelineBookmarks',
166                                                array(
167                                                     'id' => $this->user->nickname,
168                                                     'format' => 'atom')),
169                               // TRANS: Feed link text. %s is a username.
170                               sprintf(_('Feed for bookmarks of %s (Atom)'),
171                                       $this->user->nickname)));
172     }
173
174     /**
175      * Show content in the content area
176      *
177      * The default StatusNet page has a lot of decorations: menus,
178      * logos, tabs, all that jazz. This method is used to show
179      * content in the content area of the page; it's the main
180      * thing you want to overload.
181      *
182      * This method also demonstrates use of a plural localized string.
183      *
184      * @return void
185      */
186     function showContent()
187     {
188
189         $nl = new NoticeList($this->notices, $this);
190
191         $cnt = $nl->show();
192
193         if ($cnt == 0) {
194             $this->showEmptyList();
195         }
196
197         $this->pagination($this->page > 1,
198                 $cnt > NOTICES_PER_PAGE,
199                 $this->page, 'bookmarks',
200                 array('nickname' => $this->user->nickname));
201     }
202
203     function showEmptyList() {
204         $message = sprintf(_('This is %1$s\'s bookmark stream, but %1$s hasn\'t bookmarked anything yet.'), $this->user->nickname) . ' ';
205
206         $this->elementStart('div', 'guide');
207         $this->raw(common_markup_to_html($message));
208         $this->elementEnd('div');
209     }
210
211     /**
212      * Return true if read only.
213      *
214      * Some actions only read from the database; others read and write.
215      * The simple database load-balancer built into StatusNet will
216      * direct read-only actions to database mirrors (if they are configured),
217      * and read-write actions to the master database.
218      *
219      * This defaults to false to avoid data integrity issues, but you
220      * should make sure to overload it for performance gains.
221      *
222      * @param array $args other arguments, if RO/RW status depends on them.
223      *
224      * @return boolean is read only action?
225      */
226     function isReadOnly(array $args=array())
227     {
228         return true;
229     }
230 }