public function __construct($request, $response, $params = NULL) { parent::__construct($request, $response, $params); $this->_themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/'; /** 初始化皮肤函数 */ $functionsFile = $this->_themeDir . 'functions.php'; if (file_exists($functionsFile)) { require_once $functionsFile; if (function_exists('themeInit')) { themeInit($this); } } }
/** * 执行函数 * * @access public * @return void */ public function execute() { /** 避免重复取数据 */ if ($this->have()) { return; } $handles = array('index' => 'indexHandle', 'index_page' => 'indexHandle', 'archive' => 'error404Handle', 'archive_page' => 'error404Handle', 404 => 'error404Handle', 'single' => 'singleHandle', 'page' => 'singleHandle', 'post' => 'singleHandle', 'attachment' => 'singleHandle', 'comment_page' => 'singleHandle', 'category' => 'categoryHandle', 'category_page' => 'categoryHandle', 'tag' => 'tagHandle', 'tag_page' => 'tagHandle', 'author' => 'authorHandle', 'author_page' => 'authorHandle', 'archive_year' => 'dateHandle', 'archive_year_page' => 'dateHandle', 'archive_month' => 'dateHandle', 'archive_month_page' => 'dateHandle', 'archive_day' => 'dateHandle', 'archive_day_page' => 'dateHandle', 'search' => 'searchHandle', 'search_page' => 'searchHandle'); /** 处理搜索结果跳转 */ if (isset($this->request->s)) { $filterKeywords = $this->request->filter('search')->s; /** 跳转到搜索页 */ if (NULL != $filterKeywords) { $this->response->redirect(Typecho_Router::url('search', array('keywords' => urlencode($filterKeywords)), $this->options->index)); } } /** 自定义首页功能 */ $frontPage = $this->options->frontPage; if (!$this->_invokeByFeed && ('index' == $this->parameter->type || 'index_page' == $this->parameter->type)) { //显示某个页面 if (0 === strpos($frontPage, 'page:')) { // 对某些变量做hack $this->request->setParam('cid', intval(substr($frontPage, 5))); $this->parameter->type = 'page'; $this->_makeSinglePageAsFrontPage = true; } else { if (0 === strpos($frontPage, 'file:')) { // 显示某个文件 $this->setThemeFile(substr($frontPage, 5)); return; } } } if ('recent' != $frontPage && $this->options->frontArchive) { $handles['archive'] = 'indexHandle'; $handles['archive_page'] = 'indexHandle'; $this->_archiveType = 'front'; } /** 初始化分页变量 */ $this->_currentPage = isset($this->request->page) ? $this->request->page : 1; $hasPushed = false; /** select初始化 */ $select = $this->pluginHandle()->trigger($selectPlugged)->select($this); /** 定时发布功能 */ if (!$selectPlugged) { if ('post' == $this->parameter->type || 'page' == $this->parameter->type) { if ($this->user->hasLogin()) { $select = $this->select()->where('table.contents.status = ? OR table.contents.status = ? OR (table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'hidden', 'private', $this->user->uid); } else { $select = $this->select()->where('table.contents.status = ? OR table.contents.status = ?', 'publish', 'hidden'); } } else { if ($this->user->hasLogin()) { $select = $this->select()->where('table.contents.status = ? OR (table.contents.status = ? AND table.contents.authorId = ?)', 'publish', 'private', $this->user->uid); } else { $select = $this->select()->where('table.contents.status = ?', 'publish'); } } $select->where('table.contents.created < ?', $this->options->gmtTime); } /** handle初始化 */ $this->pluginHandle()->handleInit($this, $select); /** 初始化其它变量 */ $this->_feedUrl = $this->options->feedUrl; $this->_feedRssUrl = $this->options->feedRssUrl; $this->_feedAtomUrl = $this->options->feedAtomUrl; $this->_keywords = $this->options->keywords; $this->_description = $this->options->description; if (isset($handles[$this->parameter->type])) { $handle = $handles[$this->parameter->type]; $this->{$handle}($select, $hasPushed); } else { $hasPushed = $this->pluginHandle()->handle($this->parameter->type, $this, $select); } /** 初始化皮肤函数 */ $functionsFile = $this->_themeDir . 'functions.php'; if (!$this->_invokeFromOutside && file_exists($functionsFile)) { require_once $functionsFile; if (function_exists('themeInit')) { themeInit($this); } } /** 如果已经提前压入则直接返回 */ if ($hasPushed) { return; } /** 仅输出文章 */ $this->_countSql = clone $select; $select->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize); $this->query($select); }
public function render() { /** 初始化皮肤函数 */ $functionsFile = $this->_themeDir . 'functions.php'; if (file_exists($functionsFile)) { require_once $functionsFile; if (function_exists('themeInit')) { themeInit($this); } } /** 文件不存在 */ if (!file_exists($this->_themeDir . $this->_themeFile)) { Typecho_Common::error(500); } /** 输出模板 */ require_once $this->_themeDir . $this->_themeFile; }
public function themeInit() { // theme specific initialization // e.g. to load shortcodes // defined in inludes/theme_init.php if (function_exists('themeInit')) { themeInit(); } }