]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showfavorites.php
Changed @id to @class for notices ul
[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      * Title of the page
57      *
58      * Includes name of user and page number.
59      *
60      * @return string title of page
61      */
62
63     function title()
64     {
65         if ($this->page == 1) {
66             return sprintf(_("%s favorite notices"), $this->user->nickname);
67         } else {
68             return sprintf(_("%s favorite notices, page %d"),
69                            $this->user->nickname,
70                            $this->page);
71         }
72     }
73
74     /**
75      * Prepare the object
76      *
77      * Check the input values and initialize the object.
78      * Shows an error page on bad input.
79      *
80      * @param array $args $_REQUEST data
81      *
82      * @return boolean success flag
83      */
84
85     function prepare($args)
86     {
87         parent::prepare($args);
88
89         $nickname = common_canonical_nickname($this->arg('nickname'));
90
91         $this->user = User::staticGet('nickname', $nickname);
92
93         if (!$this->user) {
94             $this->clientError(_('No such user.'));
95             return false;
96         }
97
98         $this->page = $this->trimmed('page');
99
100         if (!$this->page) {
101             $this->page = 1;
102         }
103
104         return true;
105     }
106
107     /**
108      * Handle a request
109      *
110      * Just show the page. All args already handled.
111      *
112      * @param array $args $_REQUEST data
113      *
114      * @return void
115      */
116
117     function handle($args)
118     {
119         parent::handle($args);
120         $this->showPage();
121     }
122
123     /**
124      * Feeds for the <head> section
125      *
126      * @return void
127      */
128
129     function showFeeds()
130     {
131         $feedurl   = common_local_url('favoritesrss',
132                                       array('nickname' =>
133                                             $this->user->nickname));
134         $feedtitle = sprintf(_('Feed for favorites of %s'),
135                              $this->user->nickname);
136
137         $this->element('link', array('rel' => 'alternate',
138                                      'href' => $feedurl,
139                                      'type' => 'application/rss+xml',
140                                      'title' => $feedtitle));
141     }
142
143     /**
144      * show the personal group nav
145      *
146      * @return void
147      */
148
149     function showLocalNav()
150     {
151         $nav = new PersonalGroupNav($this);
152         $nav->show();
153     }
154
155     /**
156      * Show the replies feed links
157      *
158      * @return void
159      */
160
161     function showExportData()
162     {
163         $feedurl = common_local_url('favoritesrss',
164                                     array('nickname' =>
165                                           $this->user->nickname));
166
167         $fl = new FeedList($this);
168
169         // XXX: I18N
170
171         $fl->show(array(0=>array('href'=> $feedurl,
172                                  'type' => 'rss',
173                                  'version' => 'RSS 1.0',
174                                  'item' => 'Favorites')));
175     }
176
177     /**
178      * Show the content
179      *
180      * A list of notices that this user has marked as a favorite
181      *
182      * @return void
183      */
184
185     function showContent()
186     {
187         $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
188                                                NOTICES_PER_PAGE + 1);
189
190         if (!$notice) {
191             $this->serverError(_('Could not retrieve favorite notices.'));
192             return;
193         }
194
195         $nl = new NoticeList($notice, $this);
196
197         $cnt = $nl->show();
198
199         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
200                           $this->page, 'showfavorites',
201                           array('nickname' => $this->user->nickname));
202     }
203 }