]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favorited.php
define LACONICA and accept LACONICA for backwards compatibility
[quix0rs-gnu-social.git] / 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
52 class FavoritedAction extends Action
53 {
54     var $page = null;
55
56     /**
57      * Title of the page
58      *
59      * @return string Title of the page
60      */
61
62     function title()
63     {
64         if ($this->page == 1) {
65             return _('Popular notices');
66         } else {
67             return sprintf(_('Popular notices, page %d'), $this->page);
68         }
69     }
70
71     /**
72      * Instructions for use
73      *
74      * @return instructions for use
75      */
76
77     function getInstructions()
78     {
79         return _('The most popular notices on the site right now.');
80     }
81
82     /**
83      * Is this page read-only?
84      *
85      * @return boolean true
86      */
87
88     function isReadOnly($args)
89     {
90         return true;
91     }
92
93     /**
94      * Take arguments for running
95      *
96      * @param array $args $_REQUEST args
97      *
98      * @return boolean success flag
99      *
100      * @todo move queries from showContent() to here
101      */
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
123     function handle($args)
124     {
125         parent::handle($args);
126
127         $this->showPage();
128     }
129
130     /**
131      * Show the page notice
132      *
133      * Shows instructions for the page
134      *
135      * @return void
136      */
137
138     function showPageNotice()
139     {
140         $instr  = $this->getInstructions();
141         $output = common_markup_to_html($instr);
142
143         $this->elementStart('div', 'instructions');
144         $this->raw($output);
145         $this->elementEnd('div');
146     }
147
148     function showEmptyList()
149     {
150         $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
151
152         if (common_logged_in()) {
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             $message .= sprintf(_('Why not [register an account](%%%%action.%s%%%%) and be the first to add a notice to your favorites!'),
157                                 (!common_config('site','openidonly')) ? 'register' : 'openidlogin');
158         }
159
160         $this->elementStart('div', 'guide');
161         $this->raw(common_markup_to_html($message));
162         $this->elementEnd('div');
163     }
164
165     /**
166      * Local navigation
167      *
168      * This page is part of the public group, so show that.
169      *
170      * @return void
171      */
172
173     function showLocalNav()
174     {
175         $nav = new PublicGroupNav($this);
176         $nav->show();
177     }
178
179     /**
180      * Content area
181      *
182      * Shows the list of popular notices
183      *
184      * @return void
185      */
186
187     function showContent()
188     {
189         if (common_config('db', 'type') == 'pgsql') {
190             $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
191         } else {
192             $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
193         }
194
195         $qry = 'SELECT notice.*, '.
196           $weightexpr . ' as weight ' .
197           'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
198           'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
199           'ORDER BY weight DESC';
200
201         $offset = ($this->page - 1) * NOTICES_PER_PAGE;
202         $limit  = NOTICES_PER_PAGE + 1;
203
204         if (common_config('db', 'type') == 'pgsql') {
205             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
206         } else {
207             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
208         }
209
210         $notice = Memcached_DataObject::cachedQuery('Notice',
211                                                     sprintf($qry, common_config('popular', 'dropoff')),
212                                                     600);
213
214         $nl = new NoticeList($notice, $this);
215
216         $cnt = $nl->show();
217
218         if ($cnt == 0) {
219             $this->showEmptyList();
220         }
221
222         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
223                           $this->page, 'favorited');
224     }
225 }