2008-11-20 16:19:30 +09:00
|
|
|
<?php
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Laconica, the distributed open-source microblogging tool
|
2008-11-20 16:19:30 +09:00
|
|
|
*
|
2009-01-19 22:22:22 +09:00
|
|
|
* List of popular notices
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-11-20 16:19:30 +09:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2009-01-19 22:22:22 +09:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2008-11-20 16:19:30 +09:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2009-01-19 22:22:22 +09:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Public
|
|
|
|
* @package Laconica
|
|
|
|
* @author Zach Copley <zach@controlyourself.ca>
|
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
|
|
|
* @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/
|
2008-11-20 16:19:30 +09:00
|
|
|
*/
|
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
if (!defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR.'/lib/publicgroupnav.php';
|
|
|
|
require_once INSTALLDIR.'/lib/noticelist.php';
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* List of popular notices
|
|
|
|
*
|
|
|
|
* We provide a list of the most popular notices. Popularity
|
|
|
|
* is measured by
|
|
|
|
*
|
|
|
|
* @category Personal
|
|
|
|
* @package Laconica
|
|
|
|
* @author Zach Copley <zach@controlyourself.ca>
|
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://laconi.ca/
|
|
|
|
*/
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
class FavoritedAction extends Action
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2009-01-19 22:22:22 +09:00
|
|
|
var $page = null;
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string Title of the page
|
|
|
|
*/
|
|
|
|
|
|
|
|
function title()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-19 22:22:22 +09:00
|
|
|
if ($this->page == 1) {
|
|
|
|
return _('Popular notices');
|
|
|
|
} else {
|
|
|
|
return sprintf(_('Popular notices, page %d'), $this->page);
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Instructions for use
|
|
|
|
*
|
|
|
|
* @return instructions for use
|
|
|
|
*/
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
function getInstructions()
|
|
|
|
{
|
|
|
|
return _('The most popular notices on the site right now.');
|
|
|
|
}
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Is this page read-only?
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
function isReadOnly()
|
|
|
|
{
|
|
|
|
return true;
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
|
|
|
* @return boolean success flag
|
|
|
|
*
|
|
|
|
* @todo move queries from showContent() to here
|
|
|
|
*/
|
|
|
|
|
|
|
|
function prepare($args)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-19 22:22:22 +09:00
|
|
|
parent::prepare($args);
|
|
|
|
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
|
2009-02-06 09:16:10 +09:00
|
|
|
|
|
|
|
common_set_returnto($this->selfUrl());
|
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
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();
|
2008-12-24 04:19:07 +09:00
|
|
|
$output = common_markup_to_html($instr);
|
2009-01-19 22:22:22 +09:00
|
|
|
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
2009-04-04 05:35:18 +09:00
|
|
|
|
|
|
|
$favorite = new Fave;
|
|
|
|
|
|
|
|
if ($favorite->count()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = _('Favorite notices appear on this page but noone has favorited one yet.') . ' ';
|
|
|
|
|
|
|
|
if (common_logged_in()) {
|
|
|
|
$message .= _('Be the first to add a notice to your favorites by clicking the fave button next to any notice you like.');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$message .= _('Why not [register an account](%%action.register%%) and be the first to add a notice to your favorites!');
|
|
|
|
}
|
|
|
|
|
2009-04-08 06:09:27 +09:00
|
|
|
$this->elementStart('div', 'guide');
|
2009-04-04 05:35:18 +09:00
|
|
|
$this->raw(common_markup_to_html($message));
|
|
|
|
$this->elementEnd('div');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Local navigation
|
|
|
|
*
|
|
|
|
* This page is part of the public group, so show that.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
function showLocalNav()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-19 22:22:22 +09:00
|
|
|
$nav = new PublicGroupNav($this);
|
|
|
|
$nav->show();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-11-21 06:45:57 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
/**
|
|
|
|
* Content area
|
|
|
|
*
|
|
|
|
* Shows the list of popular notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
function showContent()
|
|
|
|
{
|
2009-03-05 00:32:26 +09:00
|
|
|
if (common_config('db', 'type') == 'pgsql') {
|
|
|
|
$weightexpr='sum(exp(-extract(epoch from (now() - fave.modified)) / %s))';
|
|
|
|
} else {
|
|
|
|
$weightexpr='sum(exp(-(now() - fave.modified) / %s))';
|
|
|
|
}
|
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
$qry = 'SELECT notice.*, '.
|
2009-03-05 00:32:26 +09:00
|
|
|
$weightexpr . ' as weight ' .
|
2009-01-19 22:22:22 +09:00
|
|
|
'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
|
2009-03-10 05:24:56 +09:00
|
|
|
'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source ' .
|
2009-01-19 22:22:22 +09:00
|
|
|
'ORDER BY weight DESC';
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
$offset = ($this->page - 1) * NOTICES_PER_PAGE;
|
|
|
|
$limit = NOTICES_PER_PAGE + 1;
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
if (common_config('db', 'type') == 'pgsql') {
|
2008-12-24 04:19:07 +09:00
|
|
|
$qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
|
|
|
|
} else {
|
|
|
|
$qry .= ' LIMIT ' . $offset . ', ' . $limit;
|
|
|
|
}
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-23 03:14:18 +09:00
|
|
|
$notice = Memcached_DataObject::cachedQuery('Notice',
|
|
|
|
sprintf($qry, common_config('popular', 'dropoff')),
|
|
|
|
600);
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
$nl = new NoticeList($notice, $this);
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
$cnt = $nl->show();
|
2008-11-20 16:19:30 +09:00
|
|
|
|
2009-01-19 22:22:22 +09:00
|
|
|
$this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
|
|
|
|
$this->page, 'favorited');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-12-06 07:14:02 +09:00
|
|
|
}
|