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