]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showfavorites.php
585b3b75ab8809a6c6ff68c5693d30bee1cb0952
[quix0rs-gnu-social.git] / actions / showfavorites.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
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  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ShowfavoritesAction extends Action
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()
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 favorite notices"), $this->user->nickname);
78         } else {
79             return sprintf(_("%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         return true;
118     }
119
120     /**
121      * Handle a request
122      *
123      * Just show the page. All args already handled.
124      *
125      * @param array $args $_REQUEST data
126      *
127      * @return void
128      */
129
130     function handle($args)
131     {
132         parent::handle($args);
133         $this->showPage();
134     }
135
136     /**
137      * Feeds for the <head> section
138      *
139      * @return void
140      */
141
142     function showFeeds()
143     {
144         $feedurl   = common_local_url('favoritesrss',
145                                       array('nickname' =>
146                                             $this->user->nickname));
147         $feedtitle = sprintf(_('Feed for favorites of %s'),
148                              $this->user->nickname);
149
150         $this->element('link', array('rel' => 'alternate',
151                                      'href' => $feedurl,
152                                      'type' => 'application/rss+xml',
153                                      'title' => $feedtitle));
154     }
155
156     /**
157      * Output document relationship links
158      *
159      * @return void
160      */
161     function showRelationshipLinks()
162     {
163         $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
164                                      $this->page, 'showfavorites', array('nickname' => $this->user->nickname));
165     }
166
167
168     /**
169      * show the personal group nav
170      *
171      * @return void
172      */
173
174     function showLocalNav()
175     {
176         $nav = new PersonalGroupNav($this);
177         $nav->show();
178     }
179
180     /**
181      * Show the replies feed links
182      *
183      * @return void
184      */
185
186     function showExportData()
187     {
188         $feedurl = common_local_url('favoritesrss',
189                                     array('nickname' =>
190                                           $this->user->nickname));
191
192         $fl = new FeedList($this);
193
194         // XXX: I18N
195
196         $fl->show(array(0=>array('href'=> $feedurl,
197                                  'type' => 'rss',
198                                  'version' => 'RSS 1.0',
199                                  'item' => 'Favorites')));
200     }
201
202     /**
203      * Show the content
204      *
205      * A list of notices that this user has marked as a favorite
206      *
207      * @return void
208      */
209
210     function showContent()
211     {
212         $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
213                                                NOTICES_PER_PAGE + 1);
214
215         if (!$notice) {
216             $this->serverError(_('Could not retrieve favorite notices.'));
217             return;
218         }
219
220         $nl = new NoticeList($notice, $this);
221
222         $cnt = $nl->show();
223
224         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
225                           $this->page, 'showfavorites',
226                           array('nickname' => $this->user->nickname));
227     }
228 }