|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * TeKit Plugin |
| 4 | + * |
| 5 | + * @copyright Copyright (c) 2013 Binjoo (http://binjoo.net) |
| 6 | + * @license GNU General Public License 2.0 |
| 7 | + * |
| 8 | + */ |
| 9 | +class TeKit_Contents extends Widget_Abstract_Contents implements Widget_Interface_Do { |
| 10 | + public function __construct($request, $response, $params = NULL) { |
| 11 | + parent::__construct($request, $response, $params); |
| 12 | + } |
| 13 | + /** |
| 14 | + * 清空堆栈信息 |
| 15 | + */ |
| 16 | + private function clearPush(){ |
| 17 | + $this->row = array(); |
| 18 | + $this->length = 0; |
| 19 | + $this->stack = array(); |
| 20 | + return $this; |
| 21 | + } |
| 22 | + |
| 23 | + public function push(array $value) { |
| 24 | + //$value = $this->filter($value); |
| 25 | + return parent::push($value); |
| 26 | + } |
| 27 | + |
| 28 | + public function Random($number = 10){ |
| 29 | + $sql = $this->select() |
| 30 | + ->where('table.contents.status = ?', 'publish') |
| 31 | + ->where('table.contents.created <= ?', $this->options->gmtTime) |
| 32 | + ->where('table.contents.type = ?', 'post') |
| 33 | + ->limit($number) |
| 34 | + ->order('RAND()'); |
| 35 | + $this->clearPush()->db->fetchAll($sql, array($this, 'push')); |
| 36 | + return $this; |
| 37 | + } |
| 38 | + |
| 39 | + public function MostCommented($number = 10){ |
| 40 | + $sql = $this->select() |
| 41 | + ->where('table.contents.status = ?', 'publish') |
| 42 | + ->where('table.contents.type = ?', 'post') |
| 43 | + ->where('table.contents.created <= ?', $this->options->gmtTime) |
| 44 | + ->limit($number) |
| 45 | + ->order('commentsNum',Typecho_Db::SORT_DESC); |
| 46 | + $this->clearPush()->db->fetchAll($sql, array($this, 'push')); |
| 47 | + return $this; |
| 48 | + } |
| 49 | + |
| 50 | + public function HistoryToday($number = 10){ |
| 51 | + $year = date('Y', $this->options->gmtTime); |
| 52 | + $month = date('m', $this->options->gmtTime); |
| 53 | + $day = date('j', $this->options->gmtTime); |
| 54 | + |
| 55 | + $sql = $this->select() |
| 56 | + ->where('table.contents.status = ?', 'publish') |
| 57 | + ->where('table.contents.created <= ?', $this->options->gmtTime) |
| 58 | + ->where('year(FROM_UNIXTIME(table.contents.created)) <> ?', $year) |
| 59 | + ->where('month(FROM_UNIXTIME(table.contents.created)) = ?', $month) |
| 60 | + ->where('day(FROM_UNIXTIME(table.contents.created)) = ?', $day) |
| 61 | + ->where('table.contents.type = ?', 'post') |
| 62 | + ->limit($number) |
| 63 | + ->order('table.contents.created', Typecho_Db::SORT_DESC); |
| 64 | + $this->clearPush()->db->fetchAll($sql, array($this, 'push')); |
| 65 | + return $this; |
| 66 | + } |
| 67 | + |
| 68 | + public function HistoryTomonth($number = 10){ |
| 69 | + $year = date('Y', $this->options->gmtTime); |
| 70 | + $month = date('m', $this->options->gmtTime); |
| 71 | + |
| 72 | + $sql = $this->select() |
| 73 | + ->where('table.contents.status = ?', 'publish') |
| 74 | + ->where('table.contents.created <= ?', $this->options->gmtTime) |
| 75 | + ->where('year(FROM_UNIXTIME(table.contents.created)) <> ?', $year) |
| 76 | + ->where('month(FROM_UNIXTIME(table.contents.created)) = ?', $month) |
| 77 | + ->where('table.contents.type = ?', 'post') |
| 78 | + ->limit($number) |
| 79 | + ->order('table.contents.created', Typecho_Db::SORT_DESC); |
| 80 | + $this->clearPush()->db->fetchAll($sql, array($this, 'push')); |
| 81 | + return $this; |
| 82 | + } |
| 83 | + |
| 84 | + public function action() {} |
| 85 | +} |
0 commit comments