X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ffavorited.php;h=fd5ff413cbbfd9cc8f0ac478c7aa084a7c0d43ca;hb=5e816d7be208fc24419288234559c78da7391c8b;hp=16bd8f226218b7d32fef632c8d8e17261061389a;hpb=6e856cf7ee2dbfac56cbd669fa1022048c5fb50f;p=quix0rs-gnu-social.git diff --git a/actions/favorited.php b/actions/favorited.php index 16bd8f2262..fd5ff413cb 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -1,108 +1,198 @@ . + * along with this program. If not, see . + * + * @category Public + * @package Laconica + * @author Zach Copley + * @author Evan Prodromou + * @copyright 2008-2009 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ */ -if (!defined('LACONICA')) { exit(1); } - -require_once(INSTALLDIR.'/lib/stream.php'); - -class FavoritedAction extends StreamAction { - - function handle($args) { - parent::handle($args); - - $page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - - common_show_header(_('Favorited timeline'), - array($this, 'show_header'), NULL, - array($this, 'show_top')); - - $this->show_notices($page); - - common_show_footer(); - } - - function show_top() { - $instr = $this->get_instructions(); - $output = common_markup_to_html($instr); - common_element_start('div', 'instructions'); - common_raw($output); - common_element_end('div'); - $this->public_views_menu(); - } - - function show_header() { - return; - } - - function get_instructions() { - return _('Showing most favorited notices from the last week'); - } - - function show_notices($page) { - - // XXX: Make dropoff configurable like tags? - - $qry = - 'SELECT notice_id, sum(exp(-(now() - modified)/864000)) as weight ' . - 'FROM fave GROUP BY notice_id ' . - 'ORDER BY weight DESC'; - - $offset = ($page - 1) * NOTICES_PER_PAGE; - $limit = NOTICES_PER_PAGE + 1; - - if (common_config('db','type') == 'pgsql') { - $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; - } else { - $qry .= ' LIMIT ' . $offset . ', ' . $limit; - } - - // XXX: Figure out how to cache these queries. - - $fave = new Fave; - $fave->query($qry); - - $notice_list = array(); - - while ($fave->fetch()) { - array_push($notice_list, $fave->notice_id); - } - - $notice = new Notice(); - - $notice->query(sprintf('SELECT * FROM notice WHERE id in (%s)', - implode(',', $notice_list))); +if (!defined('LACONICA')) { + exit(1); +} - $cnt = 0; +require_once INSTALLDIR.'/lib/publicgroupnav.php'; +require_once INSTALLDIR.'/lib/noticelist.php'; - if ($notice) { - common_element_start('ul', array('id' => 'notices')); - while ($notice->fetch()) { - $cnt++; - if ($cnt > NOTICES_PER_PAGE) { - break; - } - $this->show_notice($notice); - } - common_element_end('ul'); - } +/** + * List of popular notices + * + * We provide a list of the most popular notices. Popularity + * is measured by + * + * @category Personal + * @package Laconica + * @author Zach Copley + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ - common_pagination($page > 1, $cnt > NOTICES_PER_PAGE, - $page, 'favorited'); - } +class FavoritedAction extends Action +{ + var $page = null; + + /** + * Title of the page + * + * @return string Title of the page + */ + + function title() + { + if ($this->page == 1) { + return _('Popular notices'); + } else { + return sprintf(_('Popular notices, page %d'), $this->page); + } + } + + /** + * Instructions for use + * + * @return instructions for use + */ + + function getInstructions() + { + return _('The most popular notices on the site right now.'); + } + + /** + * Is this page read-only? + * + * @return boolean true + */ + + function isReadOnly() + { + return true; + } + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + * + * @todo move queries from showContent() to here + */ + + function prepare($args) + { + parent::prepare($args); + $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; + + common_set_returnto($this->selfUrl()); + + return true; + } + + /** + * Handle request + * + * Shows a page with list of favorite notices + * + * @param array $args $_REQUEST args; handled in prepare() + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $this->showPage(); + } + + /** + * Show the page notice + * + * Shows instructions for the page + * + * @return void + */ + + function showPageNotice() + { + $instr = $this->getInstructions(); + $output = common_markup_to_html($instr); + + $this->elementStart('div', 'instructions'); + $this->raw($output); + $this->elementEnd('div'); + } + + /** + * Local navigation + * + * This page is part of the public group, so show that. + * + * @return void + */ + + function showLocalNav() + { + $nav = new PublicGroupNav($this); + $nav->show(); + } + + /** + * Content area + * + * Shows the list of popular notices + * + * @return void + */ + + function showContent() + { + $qry = 'SELECT notice.*, '. + 'sum(exp(-(now() - fave.modified) / %s)) as weight ' . + 'FROM notice JOIN fave ON notice.id = fave.notice_id ' . + 'GROUP BY fave.notice_id ' . + 'ORDER BY weight DESC'; + + $offset = ($this->page - 1) * NOTICES_PER_PAGE; + $limit = NOTICES_PER_PAGE + 1; + + if (common_config('db', 'type') == 'pgsql') { + $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset; + } else { + $qry .= ' LIMIT ' . $offset . ', ' . $limit; + } + + $notice = Memcached_DataObject::cachedQuery('Notice', + sprintf($qry, common_config('popular', 'dropoff')), + 600); + + $nl = new NoticeList($notice, $this); + + $cnt = $nl->show(); + + $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, + $this->page, 'favorited'); + } }