public function action() { $this->db = Typecho_Db::get(); $this->prefix = $this->db->getPrefix(); $this->options = Typecho_Widget::widget('Widget_Options'); $cid = $this->request->cid; if (!$cid) { $this->response->throwJson(array('status' => 0, 'msg' => '请选择喜欢的文章!')); } $likes = Typecho_Cookie::get('__post_likes'); if (empty($likes)) { $likes = array(); } else { $likes = explode(',', $likes); } if (!in_array($cid, $likes)) { $row = $this->db->fetchRow($this->db->select('likesNum')->from('table.contents')->where('cid = ?', $cid)->limit(1)); $this->db->query($this->db->update('table.contents')->rows(array('likesNum' => (int) $row['likesNum'] + 1))->where('cid = ?', $cid)); array_push($likes, $cid); $likes = implode(',', $likes); Typecho_Cookie::set('__post_likes', $likes); //记录查看cookie $this->response->throwJson(array('status' => 1, 'msg' => '成功点赞!')); } $this->response->throwJson(array('status' => 0, 'msg' => '你已经点赞过了!')); }
/** * 插件实现方法 * * @access public * @return void */ public static function setTheme($widget) { $cookie = array('name' => '__typecho_theme', 'expire' => 86400); $options = Typecho_Widget::widget('Widget_Options'); if (isset($widget->request->theme) && $widget->request->isGet()) { if ($widget->request->theme) { $theme = $widget->request->theme; if (static::check($theme)) { Typecho_Cookie::set($cookie['name'], $widget->request->theme, $options->gmtTime + $cookie['expire'], $options->siteUrl); } else { $widget->response->redirect(Typecho_Common::url($widget->request->getPathInfo(), $options->siteUrl)); } } else { Typecho_Cookie::delete($cookie['name']); //直接提交?theme将删除cookie,恢复默认主题 return; } } else { $theme = Typecho_Cookie::get($cookie['name']); if (!$theme) { return; } if (!static::check($theme)) { Typecho_Cookie::delete($cookie['name']); return; } } /** 删除旧主题的相关设置 */ $themeRow = 'theme:' . $options->theme; if (isset($options->{$themeRow})) { $config = unserialize($options->{$themeRow}); $options->{$themeRow} = ''; foreach ($config as $row => $value) { $options->{$row} = ''; } } /** 载入新主题的相关设置 参考var/Widget/Themes/Edit.php */ $themeDir = __TYPECHO_ROOT_DIR__ . __TYPECHO_THEME_DIR__ . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR; $configFile = $themeDir . 'functions.php'; if (file_exists($configFile)) { require_once $configFile; if (function_exists('themeConfig')) { $form = new Typecho_Widget_Helper_Form(); themeConfig($form); $config = $form->getValues(); if ($config) { $options->{'theme:' . $theme} = serialize($config); foreach ($config as $row => $value) { $options->{$row} = $value; } } } } /** 修改$this->options->theme */ $options->theme = $theme; /** 修改$this->_themeDir */ $widget->setThemeDir($themeDir); }
/** * 设定堆栈每一行的值 * * @param string $value 值对应的键值 * @param string $type 提示类型 * @param string $typeFix 兼容老插件 * @return array */ public function set($value, $type = 'notice', $typeFix = 'notice') { $notice = is_array($value) ? array_values($value) : array($value); if (empty($type) && $typeFix) { $type = $typeFix; } Typecho_Cookie::set('__typecho_notice', json_encode($notice), $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl); Typecho_Cookie::set('__typecho_notice_type', $type, $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl); }
/** * 初始化函数 * * @access public * @return void */ public function action() { // protect $this->security->protect(); /** 如果已经登录 */ if ($this->user->hasLogin()) { /** 直接返回 */ $this->response->redirect($this->options->index); } /** 初始化验证类 */ $validator = new Typecho_Validate(); $validator->addRule('name', 'required', _t('请输入用户名')); $validator->addRule('password', 'required', _t('请输入密码')); /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password'))) { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error); $this->response->goBack(); } /** 先验证动态密码 **/ $user = $this->db->fetchRow($this->select()->where('name = ?', $this->request->name)->limit(1)); if ($user['twoFactorAuthKey']) { if ($this->request->twoFactAuth) { if (!$this->widget('Widget_GoogleAuthenticator')->verifyCode($user['twoFactorAuthKey'], $this->request->twoFactAuth, 2)) { $this->widget('Widget_Notice')->set(_t('动态密码不正确')); $this->response->goBack(); } } else { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); $this->response->redirect($this->options->adminUrl . 'login.php?requireTwoFactAuth=yes'); } } /** 开始验证用户 **/ $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0); /** 比对密码 */ if (!$valid) { /** 防止穷举,休眠3秒 */ sleep(3); $this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember); Typecho_Cookie::set('__typecho_remember_name', $this->request->name); $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error'); $this->response->goBack('?referer=' . urlencode($this->request->referer)); } $this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember); /** 跳转验证后地址 */ if (NULL != $this->request->referer) { $this->response->redirect($this->request->referer); } else { if (!$this->user->pass('contributor', true)) { /** 不允许普通用户直接跳转后台 */ $this->response->redirect($this->options->profileUrl); } else { $this->response->redirect($this->options->adminUrl); } } }
/** * 评论处理函数 * * @throws Typecho_Widget_Exception * @throws Exception * @throws Typecho_Exception */ private function comment() { // modified_by_jiangmuzi 2015.09.23 // 必须登录后才可以回复 if (!$this->user->hasLogin()) { $this->widget('Widget_Notice')->set(_t('请先<a href="%s">登录</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success'); $this->response->goBack(); } // end modified // 使用安全模块保护 $this->security->protect(); $comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved'); //检验格式 $validator = new Typecho_Validate(); $validator->addRule('text', 'required', _t('必须填写评论内容')); $comment['text'] = $this->request->text; /** 记录登录用户的id */ $comment['authorId'] = $this->user->uid; if ($error = $validator->run($comment)) { /** 记录文字 */ Typecho_Cookie::set('__some_remember_text', $comment['text']); throw new Typecho_Widget_Exception(implode("\n", $error)); } /** 生成过滤器 */ try { $comment = $this->pluginHandle()->comment($comment, $this->_content); } catch (Typecho_Exception $e) { Typecho_Cookie::set('__some_remember_text', $comment['text']); throw $e; } // modified_by_jiangmuzi 2015.09.23 // 解析@数据 $atArr = $this->searchAt($comment); // end modified /** 添加评论 */ $commentId = $this->insert($comment); Typecho_Cookie::delete('__some_remember_text'); $this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push')); //更新最后评论人及时间 $this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid)); //提醒主题作者 if ($comment['authorId'] != $comment['ownerId']) { $atArr[] = array('uid' => $comment['ownerId'], 'type' => 'comment'); } if (!empty($atArr)) { foreach ($atArr as $v) { $this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']); } } //触发评论积分规则 Widget_Common::credits('reply', null, $commentId); /** 评论完成接口 */ $this->pluginHandle()->finishComment($this); $this->response->goBack('#' . $this->theId); }
/** * 初始化函数 * * @access public * @return void */ public function action() { // protect $this->security->protect(); /** 如果已经登录 */ if ($this->user->hasLogin() || !$this->options->allowRegister) { /** 直接返回 */ $this->response->redirect($this->options->index); } /** 初始化验证类 */ $validator = new Typecho_Validate(); $validator->addRule('name', 'required', _t('必须填写用户名称')); $validator->addRule('name', 'minLength', _t('用户名至少包含2个字符'), 2); $validator->addRule('name', 'maxLength', _t('用户名最多包含32个字符'), 32); $validator->addRule('name', 'xssCheck', _t('请不要在用户名中使用特殊字符')); $validator->addRule('name', array($this, 'nameExists'), _t('用户名已经存在')); $validator->addRule('mail', 'required', _t('必须填写电子邮箱')); $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在')); $validator->addRule('mail', 'email', _t('电子邮箱格式错误')); $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200); /** 如果请求中有password */ if (array_key_exists('password', $_REQUEST)) { $validator->addRule('password', 'required', _t('必须填写密码')); $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18); $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password'); } /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password', 'mail', 'confirm'))) { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail); /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error); $this->response->goBack(); } $hasher = new PasswordHash(8, true); $generatedPassword = Typecho_Common::randString(7); $dataStruct = array('name' => $this->request->name, 'mail' => $this->request->mail, 'screenName' => $this->request->name, 'password' => $hasher->HashPassword($generatedPassword), 'created' => $this->options->gmtTime, 'group' => 'subscriber'); $dataStruct = $this->pluginHandle()->register($dataStruct); $insertId = $this->insert($dataStruct); $this->db->fetchRow($this->select()->where('uid = ?', $insertId)->limit(1), array($this, 'push')); $this->pluginHandle()->finishRegister($this); $this->user->login($this->request->name, $generatedPassword); Typecho_Cookie::delete('__typecho_first_run'); Typecho_Cookie::delete('__typecho_remember_name'); Typecho_Cookie::delete('__typecho_remember_mail'); $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册, 密码为 <strong>%s</strong>', $this->screenName, $generatedPassword), 'success'); $this->response->redirect($this->options->adminUrl); }
/** * 初始化函数 * * @access public * @return void */ public function action() { /** 如果已经登录 */ if ($this->user->hasLogin()) { /** 直接返回 */ $this->response->redirect($this->options->index); } /** 初始化验证类 */ $validator = new Typecho_Validate(); $validator->addRule('name', 'required', _t('请输入用户名')); $validator->addRule('password', 'required', _t('请输入密码')); /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password'))) { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error); $this->response->goBack(); } /** 开始验证用户 **/ $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0); /** 比对密码 */ if (!$valid) { /** 防止穷举,休眠3秒 */ sleep(3); $this->pluginHandle()->loginFail($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember); Typecho_Cookie::set('__typecho_remember_name', $this->request->name); $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error'); $this->response->goBack('?referer=' . urlencode($this->request->referer)); } $this->pluginHandle()->loginSucceed($this->user, $this->request->name, $this->request->password, 1 == $this->request->remember); /** 跳转验证后地址 */ if (NULL != $this->request->referer) { $this->response->redirect($this->request->referer); } else { if (!$this->user->pass('contributor', true)) { /** 不允许普通用户直接跳转后台 */ $this->response->redirect($this->options->siteUrl); } else { $this->response->redirect($this->options->adminUrl); } } }
protected function doLogin() { // protect $this->security->protect(); /** 如果已经登录 */ if ($this->user->hasLogin()) { /** 直接返回 */ $this->response->redirect($this->options->index); } /** 初始化验证类 */ $validator = new Typecho_Validate(); $validator->addRule('name', 'required', _t('请输入用户名')); $validator->addRule('password', 'required', _t('请输入密码')); /** 截获验证异常 */ if ($error = $validator->run($this->request->from('name', 'password'))) { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error); $this->response->goBack(); } /** 开始验证用户 **/ $valid = $this->user->login($this->request->name, $this->request->password, false, 1 == $this->request->remember ? $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600 : 0); /** 比对密码 */ if (!$valid) { /** 防止穷举,休眠3秒 */ sleep(3); Typecho_Cookie::set('__typecho_remember_name', $this->request->name); $this->widget('Widget_Notice')->set(_t('用户名或密码无效'), 'error'); $this->response->goBack('?referer=' . urlencode($this->request->referer)); } $this->widget('Widget_Notice')->set('已成功登录!', 'notice'); //登录积分 Forum_Common::credits('login'); /** 跳转验证后地址 */ $this->response->redirect($this->request->get('redir', $this->options->index)); }
protected function like() { $cid = $this->request->cid; if (!$cid) { $this->response->throwJson(array('status' => 0, 'msg' => '请选择喜欢的文章!')); } $likes = Typecho_Cookie::get('__sis_pls'); if (empty($likes)) { $likes = array(); } else { $likes = explode(',', $likes); } if (!in_array($cid, $likes)) { $db = Typecho_Db::get(); $row = $db->fetchRow($db->select('likesNum')->from('table.contents')->where('cid = ?', $cid)->limit(1)); $db->query($db->update('table.contents')->rows(array('likesNum' => (int) $row['likesNum'] + 1))->where('cid = ?', $cid)); array_push($likes, $cid); $likes = implode(',', $likes); Typecho_Cookie::set('__sis_pls', $likes); //记录查看cookie $this->response->throwJson(array('status' => 1, 'msg' => '成功点赞!')); } $this->response->throwJson(array('status' => 0, 'msg' => '你已经点赞过了!')); }
/** * 远程请求代理 * * @access public * @return void */ public function feed() { $this->user->pass('subscriber'); $client = Typecho_Http_Client::get(); if ($client) { $client->setHeader('User-Agent', $this->options->generator)->send('http://typecho.org/feed/'); /** 匹配内容体 */ $response = $client->getResponseBody(); preg_match_all("/<item>\\s*<title>([^>]*)<\\/title>\\s*<link>([^>]*)<\\/link>\\s*<guid>[^>]*<\\/guid>\\s*<pubDate>([^>]*)<\\/pubDate>/is", $response, $matches); $data = array(); if ($matches) { foreach ($matches[0] as $key => $val) { $data[] = array('title' => $matches[1][$key], 'link' => $matches[2][$key], 'date' => Typecho_I18n::dateWord(strtotime($matches[3][$key]), $this->options->gmtTime + $this->options->timezone)); if ($key > 3) { break; } } } if (!empty($data)) { Typecho_Cookie::set('__typecho_feed', Typecho_Json::encode($data)); } $this->response->throwJson($data); return; } throw new Typecho_Widget_Exception(_t('禁止访问'), 403); }
/** * 评论处理函数 * * @throws Typecho_Widget_Exception * @throws Exception * @throws Typecho_Exception */ private function comment() { // modified_by_jiangmuzi 2015.09.23 // 必须登录后才可以回复 if (!$this->user->hasLogin()) { $this->widget('Widget_Notice')->set(_t('请先<a href="%s">登录</a>', $this->options->someUrl('login', null, false) . '?redir=' . $this->request->getRequestUrl()), NULL, 'success'); $this->response->goBack(); } // end modified // 使用安全模块保护 $this->security->protect(); $comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved'); /** 判断父节点 */ /* if ($parentId = $this->request->filter('int')->get('parent')) { if ($this->options->commentsThreaded && ($parent = $this->db->fetchRow($this->db->select('coid', 'cid')->from('table.comments') ->where('coid = ?', $parentId))) && $this->_content->cid == $parent['cid']) { $comment['parent'] = $parentId; } else { throw new Typecho_Widget_Exception(_t('父级评论不存在')); } }*/ //检验格式 $validator = new Typecho_Validate(); $validator->addRule('text', 'required', _t('必须填写评论内容')); $comment['text'] = $this->request->text; /** 记录登录用户的id */ $comment['authorId'] = $this->user->uid; if ($error = $validator->run($comment)) { /** 记录文字 */ Typecho_Cookie::set('__some_remember_text', $comment['text']); throw new Typecho_Widget_Exception(implode("\n", $error)); } /** 生成过滤器 */ try { $comment = $this->pluginHandle()->comment($comment, $this->_content); } catch (Typecho_Exception $e) { Typecho_Cookie::set('__some_remember_text', $comment['text']); throw $e; } // modified_by_jiangmuzi 2015.09.23 // 解析@数据 $search = $replace = $atMsg = array(); $pattern = "/@([^@^\\s^:]{1,})([\\s\\:\\,\\;]{0,1})/"; preg_match_all($pattern, $comment['text'], $matches); if (!empty($matches[1])) { $matches[1] = array_unique($matches[1]); foreach ($matches[1] as $name) { if (empty($name)) { continue; } $atUser = $this->widget('Widget_Users_Query@name_' . $name, array('name' => $name)); if (!$atUser->have()) { continue; } $search[] = '@' . $name; $replace[] = '<a href="' . $atUser->ucenter . '" target="_blank">@' . $name . '</a>'; //提醒at用户 if ($comment['authorId'] != $atUser->uid && $atUser->uid != $comment['ownerId']) { $atMsg[] = array('uid' => $atUser->uid, 'type' => 'at'); } } if (!empty($search)) { $comment['text'] = str_replace(@$search, @$replace, $comment['text']); } } // end modified /** 添加评论 */ $commentId = $this->insert($comment); Typecho_Cookie::delete('__some_remember_text'); $this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push')); //更新最后评论人及时间 $this->db->query($this->db->update('table.contents')->rows(array('lastUid' => $this->authorId, 'lastComment' => $this->created))->where('cid = ?', $this->cid)); //提醒主题作者 if ($comment['authorId'] != $comment['ownerId']) { $atMsg[] = array('uid' => $comment['ownerId'], 'type' => 'comment'); } if (!empty($atMsg)) { foreach ($atMsg as $v) { $this->widget('Widget_Users_Messages')->addMessage($v['uid'], $commentId, $v['type']); } } //触发评论积分规则 Widget_Common::credits('reply'); /** 评论完成接口 */ $this->pluginHandle()->finishComment($this); $this->response->goBack('#' . $this->theId); }
/** * 独立页处理 * * @access private * @param Typecho_Db_Query $select 查询对象 * @param boolean $hasPushed 是否已经压入队列 * @return void * @throws Typecho_Widget_Exception */ private function singleHandle(Typecho_Db_Query $select, &$hasPushed) { if ('comment_page' == $this->parameter->type) { $params = array(); $matched = Typecho_Router::match($this->request->permalink); if ($matched && $matched instanceof Widget_Archive && $matched->is('single')) { $this->import($matched); $hasPushed = true; return; } } /** 将这两个设置提前是为了保证在调用query的plugin时可以在插件中使用is判断初步归档类型 */ /** 如果需要更细判断,则可以使用singleHandle来实现 */ $this->_archiveSingle = true; /** 默认归档类型 */ $this->_archiveType = 'single'; /** 匹配类型 */ if ('single' != $this->parameter->type) { $select->where('table.contents.type = ?', $this->parameter->type); } /** 如果是单篇文章或独立页面 */ if (isset($this->request->cid)) { $select->where('table.contents.cid = ?', $this->request->filter('int')->cid); } /** 匹配缩略名 */ if (isset($this->request->slug)) { $select->where('table.contents.slug = ?', $this->request->slug); } /** 匹配时间 */ if (isset($this->request->year)) { $year = $this->request->filter('int')->year; $fromMonth = 1; $toMonth = 12; $fromDay = 1; $toDay = 31; if (isset($this->request->month)) { $fromMonth = $this->request->filter('int')->month; $toMonth = $fromMonth; $fromDay = 1; $toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year)); if (isset($this->request->day)) { $fromDay = $this->request->filter('int')->day; $toDay = $fromDay; } } /** 获取起始GMT时间的unix时间戳 */ $from = mktime(0, 0, 0, $fromMonth, $fromDay, $year) - $this->options->timezone + $this->options->serverTimezone; $to = mktime(23, 59, 59, $toMonth, $toDay, $year) - $this->options->timezone + $this->options->serverTimezone; $select->where('table.contents.created > ? AND table.contents.created < ?', $from, $to); } /** 保存密码至cookie */ if ($this->request->isPost() && isset($this->request->protectPassword)) { $this->security->protect(); Typecho_Cookie::set('protectPassword', $this->request->protectPassword, 0); } /** 匹配类型 */ $select->limit(1); $this->query($select); if (!$this->have() || isset($this->request->category) && $this->category != $this->request->category || isset($this->request->directory) && $this->request->directory != implode('/', $this->directory)) { if (!$this->_invokeFromOutside) { /** 对没有索引情况下的判断 */ throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404); } else { $hasPushed = true; return; } } /** 设置模板 */ if ($this->template) { /** 应用自定义模板 */ $this->_themeFile = $this->template; } /** 设置头部feed */ /** RSS 2.0 */ //对自定义首页使用全局变量 if (!$this->_makeSinglePageAsFrontPage) { $this->_feedUrl = $this->feedUrl; /** RSS 1.0 */ $this->_feedRssUrl = $this->feedRssUrl; /** ATOM 1.0 */ $this->_feedAtomUrl = $this->feedAtomUrl; /** 设置标题 */ $this->_archiveTitle = $this->title; /** 设置关键词 */ $this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name')); /** 设置描述 */ $this->_description = $this->description; } /** 设置归档类型 */ $this->_archiveType = $this->type; /** 设置归档缩略名 */ $this->_archiveSlug = 'post' == $this->type || 'attachment' == $this->type ? $this->cid : $this->slug; /** 设置403头 */ if ($this->hidden) { $this->response->setStatus(403); } $hasPushed = true; /** 插件接口 */ $this->pluginHandle()->singleHandle($this, $select); }
/** * 执行函数 * * @access public * @return void */ public function execute() { $select = $this->select(); $this->parameter->setDefault('pageSize=20'); $this->_currentPage = $this->request->get('page', 1); /** 过滤标题 */ if (NULL != ($keywords = $this->request->filter('search')->keywords)) { $select->where('table.comments.text LIKE ?', '%' . $keywords . '%'); } /** 如果具有贡献者以上权限,可以查看所有评论,反之只能查看自己的评论 */ if (!$this->user->pass('editor', true)) { $select->where('table.comments.ownerId = ?', $this->user->uid); } else { if (!isset($this->request->cid)) { if ('on' == $this->request->__some_all_comments) { Typecho_Cookie::set('__some_all_comments', 'on'); } else { if ('off' == $this->request->__some_all_comments) { Typecho_Cookie::set('__some_all_comments', 'off'); } if ('on' != Typecho_Cookie::get('__some_all_comments')) { $select->where('table.comments.ownerId = ?', $this->user->uid); } } } } if (in_array($this->request->status, array('approved', 'waiting', 'spam'))) { $select->where('table.comments.status = ?', $this->request->status); } else { if ('hold' == $this->request->status) { $select->where('table.comments.status <> ?', 'approved'); } else { $select->where('table.comments.status = ?', 'approved'); } } //增加按文章归档功能 if (isset($this->request->cid)) { $select->where('table.comments.cid = ?', $this->request->filter('int')->cid); } $this->_countSql = clone $select; $select->order('table.comments.coid', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize); $this->db->fetchAll($select, array($this, 'push')); }
Typecho_Widget::widget('Widget_User')->to($user); Typecho_Widget::widget('Widget_Security')->to($security); Typecho_Widget::widget('Widget_Menu')->to($menu); /** 初始化上下文 */ $request = $options->request; $response = $options->response; /** 检测是否是第一次登录 */ $currentMenu = $menu->getCurrentMenu(); list($prefixVersion, $suffixVersion) = explode('/', $options->version); $params = parse_url($currentMenu[2]); $adminFile = basename($params['path']); if (!$user->logged && !Typecho_Cookie::get('__some_first_run') && !empty($currentMenu)) { if ('welcome.php' != $adminFile) { $response->redirect(Typecho_Common::url('welcome.php', $options->adminUrl)); } else { Typecho_Cookie::set('__some_first_run', 1); } } else { /** 检测版本是否升级 */ if ($user->pass('administrator', true) && !empty($currentMenu)) { $mustUpgrade = !defined('Typecho_Common::VERSION') || version_compare(str_replace('/', '.', Typecho_Common::VERSION), str_replace('/', '.', $options->version), '>'); if ($mustUpgrade && 'upgrade.php' != $adminFile) { $response->redirect(Typecho_Common::url('upgrade.php', $options->adminUrl)); } else { if (!$mustUpgrade && 'upgrade.php' == $adminFile) { $response->redirect($options->adminUrl); } else { if (!$mustUpgrade && 'welcome.php' == $adminFile && $user->logged) { $response->redirect($options->adminUrl); } }
/** * 增加浏览量 * @params Widget_Archive $archive * @return void */ public static function viewCounter($archive) { if ($archive->is('single')) { $cid = $archive->cid; $views = Typecho_Cookie::get('__post_views'); if (empty($views)) { $views = array(); } else { $views = explode(',', $views); } if (!in_array($cid, $views)) { $db = Typecho_Db::get(); $db->query($db->update('table.contents')->rows(array('viewsNum' => (int) $archive->viewsNum + 1))->where('cid = ?', $cid)); array_push($views, $cid); $views = implode(',', $views); Typecho_Cookie::set('__post_views', $views); //记录查看cookie } } }
public static function twitterLogin($info, $api) { if (!empty($info['screen_name'])) { Typecho_Cookie::set('__typecho_remember_author', $info['screen_name'], time() + 60 * 60 * 24 * 30); } if (!empty($info['url'])) { Typecho_Cookie::set('__typecho_remember_url', $info['url'], time() + 60 * 60 * 24 * 30); } }
/** * 以用户名和密码登录 * * @access public * @param string $name 用户名 * @param string $password 密码 * @param boolean $temporarily 是否为临时登录 * @param integer $expire 过期时间 * @return boolean */ public function login($name, $password, $temporarily = false, $expire = 0) { //插件接口 $result = $this->pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire); if ($loginPluggable) { return $result; } /** 开始验证用户 **/ $user = $this->db->fetchRow($this->db->select()->from('table.users')->where('name = ?', $name)->limit(1)); $hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']); if (!$hashPluggable) { $hashValidate = Typecho_Common::hashValidate($password, $user['password']); } if ($user && $hashValidate) { if (!$temporarily) { $authCode = sha1(Typecho_Common::randString(20)); $user['authCode'] = $authCode; Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire, $this->options->siteUrl); Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire, $this->options->siteUrl); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $user['uid'])); } /** 压入数据 */ $this->push($user); $this->_hasLogin = true; $this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire); return true; } $this->pluginHandle()->loginFail($this, $name, $password, $temporarily, $expire); return false; }
if (!isset($config) && $success && !_r('created')) { $installDb = new Typecho_Db($adapter, _r('dbPrefix')); $installDb->addServer($dbConfig, Typecho_Db::READ | Typecho_Db::WRITE); /** 检测数据库配置 */ try { $installDb->query('SELECT 1=1'); } catch (Typecho_Db_Adapter_Exception $e) { $success = false; echo '<p class="message error">' . _t('对不起,无法连接数据库,请先检查数据库配置再继续进行安装') . '</p>'; } catch (Typecho_Db_Exception $e) { $success = false; echo '<p class="message error">' . _t('安装程序捕捉到以下错误: " %s ". 程序被终止, 请检查您的配置信息.', $e->getMessage()) . '</p>'; } } if ($success) { Typecho_Cookie::set('__typecho_config', base64_encode(serialize(array_merge(array('prefix' => _r('dbPrefix'), 'userName' => _r('userName'), 'userPassword' => _r('userPassword'), 'userMail' => _r('userMail'), 'adapter' => $adapter, 'siteUrl' => _r('userUrl')), $dbConfig)))); if (_r('created')) { header('Location: ./install.php?start'); exit; } /** 初始化配置文件 */ $lines = array_slice(file(__FILE__), 0, 52); $lines[] = "\n/** 定义数据库参数 */\n\$db = new Typecho_Db('{$adapter}', '" . _r('dbPrefix') . "');\n\$db->addServer(" . (!isset($config) ? var_export($dbConfig, true) : $config) . ", Typecho_Db::READ | Typecho_Db::WRITE);\nTypecho_Db::set(\$db);\n"; $contents = implode('', $lines); if (!_engine()) { @file_put_contents('./config.inc.php', $contents); } // 创建一个用于标识的临时文件 $_SESSION['typecho'] = 1; if (!file_exists('./config.inc.php')) { ?>
/** * 验证表单 * * @access public * @return void */ public function validate() { $validator = new Typecho_Validate(); $rules = array(); foreach ($this->_inputs as $name => $input) { $rules[$name] = $input->rules; } $id = md5(implode('"', array_keys($this->_inputs))); /** 表单值 */ $formData = $this->getParams(array_keys($rules)); $error = $validator->run($formData, $rules); if ($error) { /** 利用cookie记录错误 */ Typecho_Cookie::set('__typecho_form_message_' . $id, $error); /** 利用cookie记录表单值 */ Typecho_Cookie::set('__typecho_form_record_' . $id, $formData); } return $error; }
public function action() { // protect $this->security->protect(); /** 如果已经登录 */ if ($this->user->hasLogin()) { /** 直接返回 */ $this->response->redirect($this->options->index); } /** 如果未开启注册 */ if (!$this->options->allowRegister) { /** 直接返回 */ $this->widget('Widget_Notice')->set('未开启注册!', 'error'); $this->response->redirect($this->options->index); } /** 初始化验证类 */ $validator = new Typecho_Validate(); $validator->addRule('captcha', 'required', _t('必须填写验证码')); $validator->addRule('captcha', array($this, 'checkCaptcha'), _t('验证码错误')); $validator->addRule('name', 'required', _t('必须填写用户名称')); $validator->addRule('name', 'minLength', _t('用户名至少包含2个字符'), 2); $validator->addRule('name', 'maxLength', _t('用户名最多包含32个字符'), 32); $validator->addRule('name', 'xssCheck', _t('请不要在用户名中使用特殊字符')); $validator->addRule('name', array($this, 'nameExists'), _t('用户名已经存在')); $validator->addRule('mail', 'required', _t('必须填写电子邮箱')); $validator->addRule('mail', array($this, 'mailExists'), _t('电子邮箱地址已经存在')); $validator->addRule('mail', 'email', _t('电子邮箱格式错误')); $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200); /** 如果请求中有password */ $validator->addRule('password', 'required', _t('必须填写密码')); $validator->addRule('password', 'minLength', _t('为了保证账户安全, 请输入至少六位的密码'), 6); $validator->addRule('password', 'maxLength', _t('为了便于记忆, 密码长度请不要超过十八位'), 18); $validator->addRule('confirm', 'confirm', _t('两次输入的密码不一致'), 'password'); /** 截获验证异常 */ if ($error = $validator->run($this->request->from('captcha', 'name', 'password', 'mail', 'confirm'))) { Typecho_Cookie::set('__typecho_remember_name', $this->request->name); Typecho_Cookie::set('__typecho_remember_mail', $this->request->mail); /** 设置提示信息 */ $this->widget('Widget_Notice')->set($error, 'error'); $this->response->goBack(); } $hasher = new PasswordHash(8, true); //$generatedPassword = Typecho_Common::randString(7); $extend = array(); $inviter = Typecho_Cookie::get('__typecho_inviter'); if (!empty($inviter)) { $inviter = $this->widget('Widget_Users_Query@name_' . $inviter, 'name=' . $inviter); if ($inviter->have()) { $extend['inviter'] = $inviter->name; } Typecho_Cookie::delete('__typecho_inviter'); } $dataStruct = array('name' => $this->request->name, 'mail' => $this->request->mail, 'screenName' => $this->request->name, 'password' => $hasher->HashPassword($this->request->password), 'created' => $this->options->gmtTime, 'group' => 'subscriber', 'extend' => empty($extend) ? '' : serialize($extend)); $insertId = $this->insert($dataStruct); $this->db->fetchRow($this->select()->where('uid = ?', $insertId)->limit(1), array($this, 'push')); $this->user->login($this->request->name, $this->request->password); $params = array('uid' => $this->user->uid, 'confirm' => $this->user->mail, 'name' => $this->user->screenName, 'type' => 'register'); //发送验证信息 Widget_Common::sendVerify($params); //注册积分 Widget_Common::credits('register'); $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册,请及时验证邮件', $this->screenName), 'success'); $this->response->redirect($this->options->index); }
Typecho_Widget::widget('Widget_User')->to($user); Typecho_Widget::widget('Widget_Security')->to($security); Typecho_Widget::widget('Widget_Menu')->to($menu); /** 初始化上下文 */ $request = $options->request; $response = $options->response; /** 检测是否是第一次登录 */ $currentMenu = $menu->getCurrentMenu(); list($prefixVersion, $suffixVersion) = explode('/', $options->version); $params = parse_url($currentMenu[2]); $adminFile = basename($params['path']); if (!$user->logged && !Typecho_Cookie::get('__typecho_first_run') && !empty($currentMenu)) { if ('welcome.php' != $adminFile) { $response->redirect(Typecho_Common::url('welcome.php', $options->adminUrl)); } else { Typecho_Cookie::set('__typecho_first_run', 1); } } else { /** 检测版本是否升级 */ if ($user->pass('administrator', true) && !empty($currentMenu)) { $mustUpgrade = !defined('Typecho_Common::VERSION') || version_compare(str_replace('/', '.', Typecho_Common::VERSION), str_replace('/', '.', $options->version), '>'); if ($mustUpgrade && 'upgrade.php' != $adminFile) { $response->redirect(Typecho_Common::url('upgrade.php', $options->adminUrl)); } else { if (!$mustUpgrade && 'upgrade.php' == $adminFile) { $response->redirect($options->adminUrl); } else { if (!$mustUpgrade && 'welcome.php' == $adminFile && $user->logged) { $response->redirect($options->adminUrl); } }
/** * 执行更新动作 * * @access public * @return void */ public function updatePermalinkSettings() { /** 验证格式 */ if ($this->form()->validate()) { Typecho_Cookie::set('__typecho_form_item_postPattern', $this->request->customPattern); $this->response->goBack(); } $patternValid = $this->checkRule($this->request->postPattern); /** 解析url pattern */ if ('custom' == $this->request->postPattern) { $this->request->postPattern = '/' . ltrim($this->encodeRule($this->request->customPattern), '/'); } $settings = $this->request->from('rewrite'); if (isset($this->request->postPattern) && isset($this->request->pageSuffix)) { $routingTable = $this->options->routingTable; $routingTable['post']['url'] = $this->request->postPattern; $pageValue = false !== ($pos = strrpos($routingTable['page']['url'], '.')) ? substr($routingTable['page']['url'], 0, $pos) : rtrim($routingTable['page']['url'], '/'); $routingTable['page']['url'] = $pageValue . $this->request->pageSuffix; if (isset($routingTable[0])) { unset($routingTable[0]); } $settings['routingTable'] = serialize($routingTable); } foreach ($settings as $name => $value) { $this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name)); } if ($patternValid) { $this->widget('Widget_Notice')->set(_t("设置已经保存"), NULL, 'success'); } else { $this->widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), NULL, 'notice'); } $this->response->goBack(); }
protected function authLogin($uid, $expire = 0) { $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); Typecho_Cookie::set('__some_uid', $uid, $expire); Typecho_Cookie::set('__some_authCode', Typecho_Common::hash($authCode), $expire); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $uid)); }
/** * 以用户名和密码登录 * * @access public * @param string $name 用户名 * @param string $password 密码 * @param boolean $temporarily 是否为临时登录 * @param integer $expire 过期时间 * @return boolean */ public function login($name, $password, $temporarily = false, $expire = 0) { //插件接口 $result = $this->pluginHandle()->trigger($loginPluggable)->login($name, $password, $temporarily, $expire); if ($loginPluggable) { return $result; } /** 开始验证用户 **/ $user = $this->db->fetchRow($this->db->select()->from('table.users')->where((strpos($name, '@') ? 'mail' : 'name') . ' = ?', $name)->limit(1)); if (empty($user)) { return false; } $hashValidate = $this->pluginHandle()->trigger($hashPluggable)->hashValidate($password, $user['password']); if (!$hashPluggable) { if ('$P$' == substr($user['password'], 0, 3)) { $hasher = new PasswordHash(8, true); $hashValidate = $hasher->CheckPassword($password, $user['password']); } else { $hashValidate = Typecho_Common::hashValidate($password, $user['password']); } } if ($user && $hashValidate) { if (!$temporarily) { $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); $user['authCode'] = $authCode; Typecho_Cookie::set('__typecho_uid', $user['uid'], $expire); Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), $expire); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $user['uid'])); } /** 压入数据 */ $this->push($user); $this->_hasLogin = true; $this->pluginHandle()->loginSucceed($this, $name, $password, $temporarily, $expire); return true; } $this->pluginHandle()->loginFail($this, $name, $password, $temporarily, $expire); return false; }
/** * 设置用户登陆状态 */ protected function setUserLogin($uid, $expire = 30243600) { Typecho_Widget::widget('Widget_User')->simpleLogin($uid); $authCode = function_exists('openssl_random_pseudo_bytes') ? bin2hex(openssl_random_pseudo_bytes(16)) : sha1(Typecho_Common::randString(20)); Typecho_Cookie::set('__typecho_uid', $uid, time() + $expire); Typecho_Cookie::set('__typecho_authCode', Typecho_Common::hash($authCode), time() + $expire); //更新最后登录时间以及验证码 $this->db->query($this->db->update('table.users')->expression('logged', 'activated')->rows(array('authCode' => $authCode))->where('uid = ?', $uid)); }
function get_post_view($archive) { $cid = $archive->cid; $db = Typecho_Db::get(); $prefix = $db->getPrefix(); if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) { $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;'); echo 0; return; } $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid)); if ($archive->is('single')) { $views = Typecho_Cookie::get('extend_contents_views'); if (empty($views)) { $views = array(); } else { $views = explode(',', $views); } if (!in_array($cid, $views)) { $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid)); array_push($views, $cid); $views = implode(',', $views); Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie } } echo $row['views']; }
/** * 评论处理函数 * * @throws Typecho_Widget_Exception * @throws Exception * @throws Typecho_Exception */ private function comment() { // 使用安全模块保护 $this->security->protect(); $comment = array('cid' => $this->_content->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'ownerId' => $this->_content->author->uid, 'type' => 'comment', 'status' => !$this->_content->allow('edit') && $this->options->commentsRequireModeration ? 'waiting' : 'approved'); /** 判断父节点 */ if ($parentId = $this->request->filter('int')->get('parent')) { if ($this->options->commentsThreaded && ($parent = $this->db->fetchRow($this->db->select('coid', 'cid')->from('table.comments')->where('coid = ?', $parentId))) && $this->_content->cid == $parent['cid']) { $comment['parent'] = $parentId; } else { throw new Typecho_Widget_Exception(_t('父级评论不存在')); } } //检验格式 $validator = new Typecho_Validate(); $validator->addRule('author', 'required', _t('必须填写用户名')); $validator->addRule('author', 'xssCheck', _t('请不要在用户名中使用特殊字符')); $validator->addRule('author', array($this, 'requireUserLogin'), _t('您所使用的用户名已经被注册,请登录后再次提交')); $validator->addRule('author', 'maxLength', _t('用户名最多包含200个字符'), 200); if ($this->options->commentsRequireMail && !$this->user->hasLogin()) { $validator->addRule('mail', 'required', _t('必须填写电子邮箱地址')); } $validator->addRule('mail', 'email', _t('邮箱地址不合法')); $validator->addRule('mail', 'maxLength', _t('电子邮箱最多包含200个字符'), 200); if ($this->options->commentsRequireUrl && !$this->user->hasLogin()) { $validator->addRule('url', 'required', _t('必须填写个人主页')); } $validator->addRule('url', 'url', _t('个人主页地址格式错误')); $validator->addRule('url', 'maxLength', _t('个人主页地址最多包含200个字符'), 200); $validator->addRule('text', 'required', _t('必须填写评论内容')); $comment['text'] = $this->request->text; /** 对一般匿名访问者,将用户数据保存一个月 */ if (!$this->user->hasLogin()) { /** Anti-XSS */ $comment['author'] = $this->request->filter('trim')->author; $comment['mail'] = $this->request->filter('trim')->mail; $comment['url'] = $this->request->filter('trim')->url; /** 修正用户提交的url */ if (!empty($comment['url'])) { $urlParams = parse_url($comment['url']); if (!isset($urlParams['scheme'])) { $comment['url'] = 'http://' . $comment['url']; } } $expire = $this->options->gmtTime + $this->options->timezone + 30 * 24 * 3600; Typecho_Cookie::set('__typecho_remember_author', $comment['author'], $expire); Typecho_Cookie::set('__typecho_remember_mail', $comment['mail'], $expire); Typecho_Cookie::set('__typecho_remember_url', $comment['url'], $expire); } else { $comment['author'] = $this->user->screenName; $comment['mail'] = $this->user->mail; $comment['url'] = $this->user->url; /** 记录登录用户的id */ $comment['authorId'] = $this->user->uid; } /** 评论者之前须有评论通过了审核 */ if (!$this->options->commentsRequireModeration && $this->options->commentsWhitelist) { if ($this->size($this->select()->where('author = ? AND mail = ? AND status = ?', $comment['author'], $comment['mail'], 'approved'))) { $comment['status'] = 'approved'; } else { $comment['status'] = 'waiting'; } } if ($error = $validator->run($comment)) { /** 记录文字 */ Typecho_Cookie::set('__typecho_remember_text', $comment['text']); throw new Typecho_Widget_Exception(implode("\n", $error)); } /** 生成过滤器 */ try { $comment = $this->pluginHandle()->comment($comment, $this->_content); } catch (Typecho_Exception $e) { Typecho_Cookie::set('__typecho_remember_text', $comment['text']); throw $e; } /** 添加评论 */ $commentId = $this->insert($comment); Typecho_Cookie::delete('__typecho_remember_text'); $this->db->fetchRow($this->select()->where('coid = ?', $commentId)->limit(1), array($this, 'push')); /** 评论完成接口 */ $this->pluginHandle()->finishComment($this); $this->response->goBack('#' . $this->theId); }
/** * 设定堆栈每一行的值 * * @param string $name 值对应的键值 * @param mixed $name 相应的值 * @param string $type 提示类型 * @return array */ public function set($name, $value = NULL, $type = 'notice') { $notice = array(); if (is_array($name)) { foreach ($name as $key => $row) { $notice[$key] = $row; } } else { if (empty($value)) { $notice[] = $name; } else { $notice[$name] = $value; } } $this->noticeType = $type; $this->push($notice); Typecho_Cookie::set('__typecho_notice', $notice, $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl); Typecho_Cookie::set('__typecho_notice_type', $type, $this->widget('Widget_Options')->gmtTime + $this->widget('Widget_Options')->timezone + 86400, $this->widget('Widget_Options')->siteUrl); }
/** * 执行更新动作 * * @access public * @return void */ public function updatePermalinkSettings() { /** 验证格式 */ if ($this->form()->validate()) { Typecho_Cookie::set('__typecho_form_item_postPattern', $this->request->customPattern); $this->response->goBack(); } $patternValid = $this->checkRule($this->request->postPattern); /** 解析url pattern */ if ('custom' == $this->request->postPattern) { $this->request->postPattern = '/' . ltrim($this->encodeRule($this->request->customPattern), '/'); } $settings = defined('__TYPECHO_REWRITE__') ? array() : $this->request->from('rewrite'); if (isset($this->request->postPattern) && isset($this->request->pagePattern)) { $routingTable = $this->options->routingTable; $routingTable['post']['url'] = $this->request->postPattern; $routingTable['page']['url'] = '/' . ltrim($this->encodeRule($this->request->pagePattern), '/'); $routingTable['category']['url'] = '/' . ltrim($this->encodeRule($this->request->categoryPattern), '/'); $routingTable['category_page']['url'] = rtrim($routingTable['category']['url'], '/') . '/[page:digital]/'; if (isset($routingTable[0])) { unset($routingTable[0]); } $settings['routingTable'] = serialize($routingTable); } foreach ($settings as $name => $value) { $this->update(array('value' => $value), $this->db->sql()->where('name = ?', $name)); } if ($patternValid) { $this->widget('Widget_Notice')->set(_t("设置已经保存"), 'success'); } else { $this->widget('Widget_Notice')->set(_t("自定义链接与现有规则存在冲突! 它可能影响解析效率, 建议你重新分配一个规则."), 'notice'); } $this->response->goBack(); }
/** * 执行函数 * * @access public * @return void */ public function execute() { /** 避免重复取数据 */ if ($this->have()) { return; } $handles = array('index' => 'indexHandle', 'index_page' => 'indexHandle', 'archive' => 'archiveEmptyHandle', 'archive_page' => 'archiveEmptyHandle', 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', 'login' => 'loginHandle', 'register' => 'registerHandle', 'activate' => 'activateHandle', 'setting' => 'settingHandle', 'setting_avatar' => 'settingAvatarHandle', 'message' => 'messageHandle', 'credits' => 'creditsHandle', 'forgot' => 'forgotHandle', 'favorite_nodes' => 'favoriteHandle', 'favorite_posts' => 'favoriteHandle', 'ucenter' => 'ucenterHandle', 'ucenter_post' => 'ucenterPostHandle', 'ucenter_post_page' => 'ucenterPostHandle', 'ucenter_reply' => 'ucenterReplyHandle', 'ucenter_reply_page' => 'ucenterReplyHandle'); if (isset($this->request->i) && !empty($this->request->i)) { Typecho_Cookie::set('__some_inviter', $this->request->i); } /** 处理搜索结果跳转 */ 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; // modified_by_jiangmuzi 2015.09.24 $select->order('table.contents.lastComment', Typecho_Db::SORT_DESC)->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize); $this->query($select); }