]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showfavorites.php
9734496bac891c8f0decade759b85b8a3631a4d9
[quix0rs-gnu-social.git] / actions / showfavorites.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of replies
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 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/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * List of replies
40  *
41  * @category Personal
42  * @package  StatusNet
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/
46  */
47
48 class ShowfavoritesAction extends OwnerDesignAction
49 {
50     /** User we're getting the faves of */
51     var $user = null;
52     /** Page of the faves we're on */
53     var $page = null;
54
55     /**
56      * Is this a read-only page?
57      *
58      * @return boolean true
59      */
60
61     function isReadOnly($args)
62     {
63         return true;
64     }
65
66     /**
67      * Title of the page
68      *
69      * Includes name of user and page number.
70      *
71      * @return string title of page
72      */
73
74     function title()
75     {
76         if ($this->page == 1) {
77             return sprintf(_("%s's favorite notices"), $this->user->nickname);
78         } else {
79             return sprintf(_("%s's favorite notices, page %d"),
80                            $this->user->nickname,
81                            $this->page);
82         }
83     }
84
85     /**
86      * Prepare the object
87      *
88      * Check the input values and initialize the object.
89      * Shows an error page on bad input.
90      *
91      * @param array $args $_REQUEST data
92      *
93      * @return boolean success flag
94      */
95
96     function prepare($args)
97     {
98         parent::prepare($args);
99
100         $nickname = common_canonical_nickname($this->arg('nickname'));
101
102         $this->user = User::staticGet('nickname', $nickname);
103
104         if (!$this->user) {
105             $this->clientError(_('No such user.'));
106             return false;
107         }
108
109         $this->page = $this->trimmed('page');
110
111         if (!$this->page) {
112             $this->page = 1;
113         }
114
115         common_set_returnto($this->selfUrl());
116
117         $cur = common_current_user();
118
119         if (!empty($cur) && $cur->id == $this->user->id) {
120
121             // Show imported/gateway notices as well as local if
122             // the user is looking at his own favorites
123
124             $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
125                                                    NOTICES_PER_PAGE + 1, true);
126         } else {
127             $this->notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
128                                                    NOTICES_PER_PAGE + 1, false);
129         }
130
131         if (empty($this->notice)) {
132             $this->serverError(_('Could not retrieve favorite notices.'));
133             return;
134         }
135
136         if($this->page > 1 && $this->notice->N == 0){
137             $this->serverError(_('No such page'),$code=404);
138         }
139
140         return true;
141     }
142
143     /**
144      * Handle a request
145      *
146      * Just show the page. All args already handled.
147      *
148      * @param array $args $_REQUEST data
149      *
150      * @return void
151      */
152
153     function handle($args)
154     {
155         parent::handle($args);
156         $this->showPage();
157     }
158
159     /**
160      * Feeds for the <head> section
161      *
162      * @return array Feed objects to show
163      */
164
165     function getFeeds()
166     {
167         $feedurl   = common_local_url('favoritesrss',
168                                       array('nickname' =>
169                                             $this->user->nickname));
170         $feedtitle = sprintf(_('Feed for favorites of %s'),
171                              $this->user->nickname);
172
173         return array(new Feed(Feed::RSS1, $feedurl, $feedtitle));
174     }
175
176     /**
177      * show the personal group nav
178      *
179      * @return void
180      */
181
182     function showLocalNav()
183     {
184         $nav = new PersonalGroupNav($this);
185         $nav->show();
186     }
187
188     function showEmptyListMessage()
189     {
190         if (common_logged_in()) {
191             $current_user = common_current_user();
192             if ($this->user->id === $current_user->id) {
193                 $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.');
194             } else {
195                 $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
196             }
197         }
198         else {
199             $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.%s%%%%) and then post something interesting they would add to their favorites :)'),
200                                $this->user->nickname,
201                                (!common_config('site','openidonly')) ? 'register' : 'openidlogin');
202         }
203
204         $this->elementStart('div', 'guide');
205         $this->raw(common_markup_to_html($message));
206         $this->elementEnd('div');
207     }
208
209     /**
210      * Show the content
211      *
212      * A list of notices that this user has marked as a favorite
213      *
214      * @return void
215      */
216
217     function showContent()
218     {
219         $nl = new NoticeList($this->notice, $this);
220
221         $cnt = $nl->show();
222         if (0 == $cnt) {
223             $this->showEmptyListMessage();
224         }
225
226         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
227                           $this->page, 'showfavorites',
228                           array('nickname' => $this->user->nickname));
229     }
230
231     function showPageNotice() {
232         $this->element('p', 'instructions', _('This is a way to share what you like.'));
233     }
234 }
235