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