]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favorited.php
public is readonly
[quix0rs-gnu-social.git] / actions / favorited.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Zach Copley <zach@controlyourself.ca>
25  * @author    Evan Prodromou <evan@controlyourself.ca>
26  * @copyright 2008-2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!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  Laconica
46  * @author   Zach Copley <zach@controlyourself.ca>
47  * @author   Evan Prodromou <evan@controlyourself.ca>
48  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49  * @link     http://laconi.ca/
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()
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         return true;
108     }
109
110     /**
111      * Handle request
112      *
113      * Shows a page with list of favorite notices
114      *
115      * @param array $args $_REQUEST args; handled in prepare()
116      *
117      * @return void
118      */
119
120     function handle($args)
121     {
122         parent::handle($args);
123
124         $this->showPage();
125     }
126
127     /**
128      * Show the page notice
129      *
130      * Shows instructions for the page
131      *
132      * @return void
133      */
134
135     function showPageNotice()
136     {
137         $instr  = $this->getInstructions();
138         $output = common_markup_to_html($instr);
139
140         $this->elementStart('div', 'instructions');
141         $this->raw($output);
142         $this->elementEnd('div');
143     }
144
145     /**
146      * Local navigation
147      *
148      * This page is part of the public group, so show that.
149      *
150      * @return void
151      */
152
153     function showLocalNav()
154     {
155         $nav = new PublicGroupNav($this);
156         $nav->show();
157     }
158
159     /**
160      * Content area
161      *
162      * Shows the list of popular notices
163      *
164      * @return void
165      */
166
167     function showContent()
168     {
169         $qry = 'SELECT notice.*, '.
170           'sum(exp(-(now() - fave.modified) / %s)) as weight ' .
171           'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
172           'GROUP BY fave.notice_id ' .
173           'ORDER BY weight DESC';
174
175         $offset = ($this->page - 1) * NOTICES_PER_PAGE;
176         $limit  = NOTICES_PER_PAGE + 1;
177
178         if (common_config('db', 'type') == 'pgsql') {
179             $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
180         } else {
181             $qry .= ' LIMIT ' . $offset . ', ' . $limit;
182         }
183
184         $notice = Memcached_DataObject::cachedQuery('Notice',
185                                                     sprintf($qry, common_config('popular', 'dropoff')),
186                                                     600);
187
188         $nl = new NoticeList($notice, $this);
189
190         $cnt = $nl->show();
191
192         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
193                           $this->page, 'favorited');
194     }
195 }