2010-09-30 22:46:32 +01:00
|
|
|
<?php
|
2019-09-11 08:12:49 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-09-30 22:46:32 +01:00
|
|
|
/**
|
|
|
|
* List of popular notices
|
|
|
|
*
|
|
|
|
* @category Public
|
2019-09-11 08:12:49 +01:00
|
|
|
* @package GNUsocial
|
2010-09-30 22:46:32 +01:00
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
2019-09-11 08:12:49 +01:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2010-09-30 22:46:32 +01:00
|
|
|
*/
|
|
|
|
|
2019-09-11 08:12:49 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2010-09-30 22:46:32 +01:00
|
|
|
|
|
|
|
class FavoritedSliceAction extends FavoritedAction
|
|
|
|
{
|
2019-09-11 08:12:49 +01:00
|
|
|
private $includeUsers = [];
|
|
|
|
private $excludeUsers = [];
|
2010-09-30 22:46:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Take arguments for running
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST args
|
|
|
|
*
|
|
|
|
* @return boolean success flag
|
|
|
|
*
|
|
|
|
* @todo move queries from showContent() to here
|
|
|
|
*/
|
2019-09-11 08:12:49 +01:00
|
|
|
public function prepare(array $args = [])
|
2010-09-30 22:46:32 +01:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
$this->slice = $this->arg('slice', 'default');
|
|
|
|
$data = array();
|
|
|
|
if (Event::handle('SlicedFavoritesGetSettings', array($this->slice, &$data))) {
|
2010-10-01 21:15:26 +01:00
|
|
|
// TRANS: Client exception.
|
2010-09-30 22:46:32 +01:00
|
|
|
throw new ClientException(_m('Unknown favorites slice.'));
|
|
|
|
}
|
|
|
|
if (isset($data['include'])) {
|
|
|
|
$this->includeUsers = $data['include'];
|
|
|
|
}
|
|
|
|
if (isset($data['exclude'])) {
|
|
|
|
$this->excludeUsers = $data['exclude'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content area
|
|
|
|
*
|
|
|
|
* Shows the list of popular notices
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-09-11 08:12:49 +01:00
|
|
|
public function showContent()
|
2010-09-30 22:46:32 +01:00
|
|
|
{
|
|
|
|
$slice = $this->sliceWhereClause();
|
|
|
|
if (!$slice) {
|
|
|
|
return parent::showContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
$weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
|
2019-09-11 08:12:49 +01:00
|
|
|
$cutoff = sprintf(
|
|
|
|
"fave.modified > TIMESTAMP '%s'",
|
|
|
|
common_sql_date(time() - common_config('popular', 'cutoff'))
|
|
|
|
);
|
2010-09-30 22:46:32 +01:00
|
|
|
|
|
|
|
$offset = ($this->page - 1) * NOTICES_PER_PAGE;
|
|
|
|
$limit = NOTICES_PER_PAGE + 1;
|
|
|
|
|
2019-09-11 08:12:49 +01:00
|
|
|
$qry = 'SELECT notice.*, ' . $weightexpr . ' AS weight ' .
|
|
|
|
'FROM notice INNER JOIN fave ON notice.id = fave.notice_id ' .
|
|
|
|
'WHERE ' . $cutoff . ' AND ' . $slice . ' ' .
|
|
|
|
'GROUP BY id, profile_id, uri, content, rendered, url, created, notice.modified, reply_to, is_local, source, notice.conversation ' .
|
|
|
|
'ORDER BY weight DESC LIMIT ' . $limit . ' OFFSET ' . $offset;
|
2010-09-30 22:46:32 +01:00
|
|
|
|
2019-09-11 08:12:49 +01:00
|
|
|
$notice = Memcached_DataObject::cachedQuery('Notice', $qry, 600);
|
2010-09-30 22:46:32 +01:00
|
|
|
|
|
|
|
$nl = new NoticeList($notice, $this);
|
|
|
|
|
|
|
|
$cnt = $nl->show();
|
|
|
|
|
|
|
|
if ($cnt == 0) {
|
|
|
|
$this->showEmptyList();
|
|
|
|
}
|
|
|
|
|
2019-09-11 08:12:49 +01:00
|
|
|
$this->pagination(
|
|
|
|
$this->page > 1,
|
|
|
|
$cnt > NOTICES_PER_PAGE,
|
|
|
|
$this->page,
|
|
|
|
'favorited'
|
|
|
|
);
|
2010-09-30 22:46:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function sliceWhereClause()
|
|
|
|
{
|
|
|
|
$include = $this->nicknamesToIds($this->includeUsers);
|
|
|
|
$exclude = $this->nicknamesToIds($this->excludeUsers);
|
|
|
|
|
|
|
|
if (count($include) == 1) {
|
|
|
|
return "profile_id = " . intval($include[0]);
|
2019-09-11 08:12:49 +01:00
|
|
|
} elseif (count($include) > 1) {
|
2010-09-30 22:46:32 +01:00
|
|
|
return "profile_id IN (" . implode(',', $include) . ")";
|
2019-09-11 08:12:49 +01:00
|
|
|
} elseif (count($exclude) === 1) {
|
2010-09-30 22:46:32 +01:00
|
|
|
return "profile_id != " . intval($exclude[0]);
|
2019-09-11 08:12:49 +01:00
|
|
|
} elseif (count($exclude) > 1) {
|
2010-09-30 22:46:32 +01:00
|
|
|
return "profile_id NOT IN (" . implode(',', $exclude) . ")";
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param array $nicks array of user nicknames
|
|
|
|
* @return array of profile/user IDs
|
|
|
|
*/
|
|
|
|
private function nicknamesToIds($nicks)
|
|
|
|
{
|
|
|
|
$ids = array();
|
|
|
|
foreach ($nicks as $nick) {
|
|
|
|
// not the most efficient way for a big list!
|
2013-08-18 12:04:58 +01:00
|
|
|
$user = User::getKV('nickname', $nick);
|
2010-09-30 22:46:32 +01:00
|
|
|
if ($user) {
|
|
|
|
$ids[] = intval($user->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
}
|