3 * Laconica, the distributed open-source microblogging tool
5 * List of popular notices
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.
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.
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/>.
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/
31 if (!defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/publicgroupnav.php';
36 require_once INSTALLDIR.'/lib/noticelist.php';
39 * List of popular notices
41 * We provide a list of the most popular notices. Popularity
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/
52 class FavoritedAction extends Action
59 * @return string Title of the page
64 if ($this->page == 1) {
65 return _('Popular notices');
67 return sprintf(_('Popular notices, page %d'), $this->page);
72 * Instructions for use
74 * @return instructions for use
77 function getInstructions()
79 return _('The most popular notices on the site right now.');
83 * Is this page read-only?
85 * @return boolean true
88 function isReadOnly($args)
94 * Take arguments for running
96 * @param array $args $_REQUEST args
98 * @return boolean success flag
100 * @todo move queries from showContent() to here
103 function prepare($args)
105 parent::prepare($args);
106 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
108 common_set_returnto($this->selfUrl());
116 * Shows a page with list of favorite notices
118 * @param array $args $_REQUEST args; handled in prepare()
123 function handle($args)
125 parent::handle($args);
131 * Show the page notice
133 * Shows instructions for the page
138 function showPageNotice()
140 $instr = $this->getInstructions();
141 $output = common_markup_to_html($instr);
143 $this->elementStart('div', 'instructions');
145 $this->elementEnd('div');
148 function showEmptyList()
150 $message = _('Favorite notices appear on this page but no one has favorited one yet.') . ' ';
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.');
156 $message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
159 $this->elementStart('div', 'guide');
160 $this->raw(common_markup_to_html($message));
161 $this->elementEnd('div');
167 * This page is part of the public group, so show that.
172 function showLocalNav()
174 $nav = new PublicGroupNav($this);
181 * Shows the list of popular notices
186 function showContent()
188 if (common_config('db', 'type') == 'pgsql') {
189 $weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
191 $weightexpr='sum(exp(-(now() - fave.modified) / %s))';
194 $qry = 'SELECT notice.*, '.
195 $weightexpr . ' as weight ' .
196 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
197 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
198 'ORDER BY weight DESC';
200 $offset = ($this->page - 1) * NOTICES_PER_PAGE;
201 $limit = NOTICES_PER_PAGE + 1;
203 if (common_config('db', 'type') == 'pgsql') {
204 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
206 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
209 $notice = Memcached_DataObject::cachedQuery('Notice',
210 sprintf($qry, common_config('popular', 'dropoff')),
213 $nl = new NoticeList($notice, $this);
218 $this->showEmptyList();
221 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
222 $this->page, 'favorited');