db = Typecho_Db::get(); /** 初始化常用组件 */ $this->options = $this->widget('Widget_Options'); } /** * 初始化函数 * * @access public * @return void */ public function execute() { /** 设置参数默认值 */ $this->parameter->setDefault('format=Y-m&type=month&limit=0'); $resource = $this->db->query($this->db->select('created')->from('table.contents') ->where('type = ?', 'post') ->where('table.contents.status = ?', 'publish') ->where('table.contents.created < ?', $this->options->gmtTime) ->order('table.contents.created', Typecho_Db::SORT_DESC)); $offset = $this->options->timezone - $this->options->serverTimezone; $result = array(); while ($post = $this->db->fetchRow($resource)) { $timeStamp = $post['created'] + $offset; $date = date($this->parameter->format, $timeStamp); if (isset($result[$date])) { $result[$date]['count'] ++; } else { $result[$date]['year'] = date('Y', $timeStamp); $result[$date]['month'] = date('m', $timeStamp); $result[$date]['day'] = date('d', $timeStamp); $result[$date]['date'] = $date; $result[$date]['count'] = 1; } } if ($this->parameter->limit > 0) { $result = array_slice($result, 0, $this->parameter->limit); } foreach ($result as $row) { $row['permalink'] = Typecho_Router::url('archive_' . $this->parameter->type, $row, $this->widget('Widget_Options')->index); $this->push($row); } } }