/** * Top articles last 24 hours */ public function getTop($limit) { global $config; $key = 'top100'; if ($config['use_cron'] && ($cache = Cache::get($key))) { return array_slice($cache, 0, $limit); } $today = strtotime('today'); $top100 = self::$dbh->getAll("SELECT url, count(*) AS hits FROM access_log WHERE view = 1 AND log_on > {$today} GROUP BY url ORDER BY hits DESC LIMIT 0,100"); $objs = $cph = array(); foreach ($top100 as &$top) { $obj = Ctrl::fetchData($top['url']); if (!is_object($obj) || !isset($obj->subject)) { continue; } $pub_on = $obj->pub_on < $today ? $today : $obj->pub_on; $live = $_SERVER['REQUEST_TIME'] - $pub_on; $obj->cph = $top['hits'] * 3600 / $live; // clicks per hour $objs[] = $obj; $cph[] = $obj->cph; } array_multisort($cph, SORT_DESC, $objs); return array_slice($objs, 0, $limit); }
public function index() { $limit = isset($this->params[0]) ? $this->params[0] : 7; $news = $this->model->getNews($limit); $ret = array(); foreach ($news as &$new) { $folder = Folder::getById($new['folder_id']); $uri = $folder->path . '/' . $new['slug'] . '.htm'; $obj = Ctrl::fetchData($uri); if (!is_object($obj) || !isset($obj->subject)) { continue; } $ret[] = $obj; } return $ret; }
public function rss() { setlocale(LC_ALL, 'en_US'); $limit = 10; $ret = array(); foreach ($this->folder->subFolders as $s) { $path = Folder::path($s); $uri = $path . '/last/' . $limit; $ret += Ctrl::fetchData($uri); } krsort($ret); return array_splice($ret, 0, $limit); }