3 * StatusNet, 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@status.net>
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 class FavoritedSliceAction extends FavoritedAction
37 private $includeUsers = array(), $excludeUsers = array();
40 * Take arguments for running
42 * @param array $args $_REQUEST args
44 * @return boolean success flag
46 * @todo move queries from showContent() to here
48 function prepare($args)
50 parent::prepare($args);
52 $this->slice = $this->arg('slice', 'default');
54 if (Event::handle('SlicedFavoritesGetSettings', array($this->slice, &$data))) {
55 // TRANS: Client exception.
56 throw new ClientException(_m('Unknown favorites slice.'));
58 if (isset($data['include'])) {
59 $this->includeUsers = $data['include'];
61 if (isset($data['exclude'])) {
62 $this->excludeUsers = $data['exclude'];
71 * Shows the list of popular notices
75 function showContent()
77 $slice = $this->sliceWhereClause();
79 return parent::showContent();
82 $weightexpr = common_sql_weight('fave.modified', common_config('popular', 'dropoff'));
83 $cutoff = sprintf("fave.modified > '%s'",
84 common_sql_date(time() - common_config('popular', 'cutoff')));
86 $qry = 'SELECT notice.*, '.
87 $weightexpr . ' as weight ' .
88 'FROM notice JOIN fave ON notice.id = fave.notice_id ' .
89 "WHERE $cutoff AND $slice " .
90 'GROUP BY id,profile_id,uri,content,rendered,url,created,notice.modified,reply_to,is_local,source,notice.conversation ' .
91 'ORDER BY weight DESC';
93 $offset = ($this->page - 1) * NOTICES_PER_PAGE;
94 $limit = NOTICES_PER_PAGE + 1;
96 if (common_config('db', 'type') == 'pgsql') {
97 $qry .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
99 $qry .= ' LIMIT ' . $offset . ', ' . $limit;
102 $notice = Memcached_DataObject::cachedQuery('Notice',
106 $nl = new NoticeList($notice, $this);
111 $this->showEmptyList();
114 $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
115 $this->page, 'favorited');
118 private function sliceWhereClause()
120 $include = $this->nicknamesToIds($this->includeUsers);
121 $exclude = $this->nicknamesToIds($this->excludeUsers);
123 if (count($include) == 1) {
124 return "profile_id = " . intval($include[0]);
125 } else if (count($include) > 1) {
126 return "profile_id IN (" . implode(',', $include) . ")";
127 } else if (count($exclude) == 1) {
128 return "profile_id != " . intval($exclude[0]);
129 } else if (count($exclude) > 1) {
130 return "profile_id NOT IN (" . implode(',', $exclude) . ")";
138 * @param array $nicks array of user nicknames
139 * @return array of profile/user IDs
141 private function nicknamesToIds($nicks)
144 foreach ($nicks as $nick) {
145 // not the most efficient way for a big list!
146 $user = User::staticGet('nickname', $nick);
148 $ids[] = intval($user->id);