]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/favorited.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Favorite / actions / favorited.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of popular notices
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  Public
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * List of popular notices
35  *
36  * We provide a list of the most popular notices. Popularity
37  * is measured by
38  *
39  * @category Personal
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46 class FavoritedAction extends Action
47 {
48     var $page = null;
49
50     /**
51      * Title of the page
52      *
53      * @return string Title of the page
54      */
55
56     function title()
57     {
58         if ($this->page == 1) {
59             // TRANS: Page title for first page of favorited notices.
60             return _('Popular notices');
61         } else {
62             // TRANS: Page title for all but first page of favorited notices.
63             // TRANS: %d is the page number being displayed.
64             return sprintf(_('Popular notices, page %d'), $this->page);
65         }
66     }
67
68     /**
69      * Instructions for use
70      *
71      * @return instructions for use
72      */
73     function getInstructions()
74     {
75         // TRANS: Description on page displaying favorited notices.
76         return _('The most popular notices on the site right now.');
77     }
78
79     /**
80      * Is this page read-only?
81      *
82      * @return boolean true
83      */
84     function isReadOnly(array $args=array())
85     {
86         return true;
87     }
88
89     /**
90      * Take arguments for running
91      *
92      * @param array $args $_REQUEST args
93      *
94      * @return boolean success flag
95      *
96      * @todo move queries from showContent() to here
97      */
98     function prepare(array $args=array())
99     {
100         parent::prepare($args);
101         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
102
103         common_set_returnto($this->selfUrl());
104
105         return true;
106     }
107
108     /**
109      * Handle request
110      *
111      * Shows a page with list of favorite notices
112      *
113      * @param array $args $_REQUEST args; handled in prepare()
114      *
115      * @return void
116      */
117     function handle(array $args=array())
118     {
119         parent::handle($args);
120
121         $this->showPage();
122     }
123
124     /**
125      * Show the page notice
126      *
127      * Shows instructions for the page
128      *
129      * @return void
130      */
131     function showPageNotice()
132     {
133         $instr  = $this->getInstructions();
134         $output = common_markup_to_html($instr);
135
136         $this->elementStart('div', 'instructions');
137         $this->raw($output);
138         $this->elementEnd('div');
139     }
140
141     function showEmptyList()
142     {
143         // TRANS: Text displayed instead of a list when a site does not yet have any favourited notices.
144         $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
145
146         if (common_logged_in()) {
147             // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for logged in users.
148             $message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
149         }
150         else {
151             // TRANS: Additional text displayed instead of a list when a site does not yet have any favourited notices for not logged in users.
152             // TRANS: %%action.register%% is a registration link. "[link text](link)" is Mark Down. Do not change the formatting.
153             $message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
154         }
155
156         $this->elementStart('div', 'guide');
157         $this->raw(common_markup_to_html($message));
158         $this->elementEnd('div');
159     }
160
161     /**
162      * Content area
163      *
164      * Shows the list of popular notices
165      *
166      * @return void
167      */
168     function showContent()
169     {
170         $stream = new PopularNoticeStream(Profile::current());
171         $notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE+1);
172
173         $nl = new NoticeList($notice, $this);
174
175         $cnt = $nl->show();
176
177         if ($cnt == 0) {
178             $this->showEmptyList();
179         }
180
181         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
182                           $this->page, 'favorited');
183     }
184 }