]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showfavorites.php
Merge branch '0.8.x' into userdesign
[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 OwnerDesignAction
49 {
50     /** Page of the faves we're on */
51     var $page = null;
52
53     /**
54      * Is this a read-only page?
55      *
56      * @return boolean true
57      */
58
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     /**
65      * Title of the page
66      *
67      * Includes name of user and page number.
68      *
69      * @return string title of page
70      */
71
72     function title()
73     {
74         if ($this->page == 1) {
75             return sprintf(_("%s's favorite notices"), $this->user->nickname);
76         } else {
77             return sprintf(_("%s's favorite notices, page %d"),
78                            $this->user->nickname,
79                            $this->page);
80         }
81     }
82
83     /**
84      * Prepare the object
85      *
86      * Check the input values and initialize the object.
87      * Shows an error page on bad input.
88      *
89      * @param array $args $_REQUEST data
90      *
91      * @return boolean success flag
92      */
93
94     function prepare($args)
95     {
96         parent::prepare($args);
97
98         $nickname = common_canonical_nickname($this->arg('nickname'));
99
100         $this->user = User::staticGet('nickname', $nickname);
101
102         if (!$this->user) {
103             $this->clientError(_('No such user.'));
104             return false;
105         }
106
107         $this->page = $this->trimmed('page');
108
109         if (!$this->page) {
110             $this->page = 1;
111         }
112
113         common_set_returnto($this->selfUrl());
114
115         return true;
116     }
117
118     /**
119      * Handle a request
120      *
121      * Just show the page. All args already handled.
122      *
123      * @param array $args $_REQUEST data
124      *
125      * @return void
126      */
127
128     function handle($args)
129     {
130         parent::handle($args);
131         $this->showPage();
132     }
133
134     /**
135      * Feeds for the <head> section
136      *
137      * @return array Feed objects to show
138      */
139
140     function getFeeds()
141     {
142         $feedurl   = common_local_url('favoritesrss',
143                                       array('nickname' =>
144                                             $this->user->nickname));
145         $feedtitle = sprintf(_('Feed for favorites of %s'),
146                              $this->user->nickname);
147
148         return array(new Feed(Feed::RSS1, $feedurl, $feedtitle));
149     }
150
151     /**
152      * Output document relationship links
153      *
154      * @return void
155      */
156     function showRelationshipLinks()
157     {
158         $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
159                                      $this->page, 'showfavorites', array('nickname' => $this->user->nickname));
160     }
161
162     /**
163      * show the personal group nav
164      *
165      * @return void
166      */
167
168     function showLocalNav()
169     {
170         $nav = new PersonalGroupNav($this);
171         $nav->show();
172     }
173
174     function showEmptyListMessage()
175     {
176         if (common_logged_in()) {
177             $current_user = common_current_user();
178             if ($this->user->id === $current_user->id) {
179                 $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.');
180             } else {
181                 $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
182             }
183         }
184         else {
185             $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to thier favorites :)'), $this->user->nickname);
186         }
187
188         $this->elementStart('div', 'guide');
189         $this->raw(common_markup_to_html($message));
190         $this->elementEnd('div');
191     }
192
193     /**
194      * Show the content
195      *
196      * A list of notices that this user has marked as a favorite
197      *
198      * @return void
199      */
200
201     function showContent()
202     {
203         $notice = $this->user->favoriteNotices(($this->page-1)*NOTICES_PER_PAGE,
204                                                NOTICES_PER_PAGE + 1);
205
206         if (!$notice) {
207             $this->serverError(_('Could not retrieve favorite notices.'));
208             return;
209         }
210
211         $nl = new NoticeList($notice, $this);
212
213         $cnt = $nl->show();
214         if (0 == $cnt) {
215             $this->showEmptyListMessage();
216         }
217
218         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
219                           $this->page, 'showfavorites',
220                           array('nickname' => $this->user->nickname));
221     }
222
223     function showPageNotice() {
224         $this->element('p', 'instructions', _('This is a way to share what you like.'));
225     }
226 }
227