Esempio n. 1
0
 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' => '你已经点赞过了!'));
 }
Esempio n. 2
0
 /**
  * 设置前缀 
  * 
  * @param string $url
  * @access public
  * @return void
  */
 public static function setPrefix($url)
 {
     self::$_prefix = md5($url);
     $parsed = parse_url($url);
     /** 在路径后面强制加上斜杠 */
     self::$_path = empty($parsed['path']) ? '/' : Typecho_Common::url(NULL, $parsed['path']);
 }
Esempio n. 3
0
 /**
  * 初始化函数
  *
  * @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);
         }
     }
 }
Esempio n. 4
0
 /**
  * 设定堆栈每一行的值
  *
  * @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);
 }
Esempio n. 5
0
function getReadMode($icon = false)
{
    $class = Typecho_Cookie::get('read-mode', 'day');
    if ($icon) {
        $class = $class == 'day' ? 'fa fa-sun-o' : 'fa fa-moon-o';
    } else {
        $class = 'day' == $class ? '' : 'night-mode';
    }
    echo $class;
}
Esempio n. 6
0
 /**
  * 评论处理函数
  *
  * @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);
 }
Esempio n. 7
0
/**
 * 获取提示消息
 */
function getNotice()
{
    $notice = Typecho_Cookie::get('__typecho_notice');
    if (empty($notice)) {
        echo "''";
        return;
    }
    $notice = json_decode($notice, true);
    $rs = array('msg' => $notice[0], 'type' => Typecho_Cookie::get('__typecho_notice_type'));
    Typecho_Cookie::delete('__typecho_notice');
    Typecho_Cookie::delete('__typecho_notice_type');
    echo json_encode($rs);
}
Esempio n. 8
0
 /**
  * 初始化函数
  *
  * @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);
 }
Esempio n. 9
0
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 对变量赋值 */
     $options = $this->widget('Widget_Options');
     /** 语言包初始化 */
     if ($options->lang && $options->lang != 'zh_CN') {
         $dir = defined('__TYPECHO_LANG_DIR__') ? __TYPECHO_LANG_DIR__ : __TYPECHO_ROOT_DIR__ . '/usr/langs';
         Typecho_I18n::setLang($dir . '/' . $options->lang . '.mo');
     }
     /** cookie初始化 */
     Typecho_Cookie::setPrefix($options->rootUrl);
     /** 初始化charset */
     Typecho_Common::$charset = $options->charset;
     /** 初始化exception */
     Typecho_Common::$exceptionHandle = 'Widget_ExceptionHandle';
     /** 设置路径 */
     if (defined('__TYPECHO_PATHINFO_ENCODING__')) {
         $pathInfo = $this->request->getPathInfo(__TYPECHO_PATHINFO_ENCODING__, $options->charset);
     } else {
         $pathInfo = $this->request->getPathInfo();
     }
     Typecho_Router::setPathInfo($pathInfo);
     /** 初始化路由器 */
     Typecho_Router::setRoutes($options->routingTable);
     /** 初始化插件 */
     Typecho_Plugin::init($options->plugins);
     /** 初始化回执 */
     $this->response->setCharset($options->charset);
     $this->response->setContentType($options->contentType);
     /** 默认时区 */
     if (function_exists("ini_get") && !ini_get("date.timezone") && function_exists("date_default_timezone_set")) {
         @date_default_timezone_set('UTC');
     }
     /** 初始化时区 */
     Typecho_Date::setTimezoneOffset($options->timezone);
     /** 开始会话, 减小负载只针对后台打开session支持 */
     // modified_by_jiangmuzi 2015.09.23
     // 开始会话
     @session_start();
     // end modified
     /** 监听缓冲区 */
     ob_start();
 }
Esempio n. 10
0
 /**
  * 初始化函数
  *
  * @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);
         }
     }
 }
Esempio n. 11
0
 /**
  * 入口函数,初始化路由器
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     /** 对变量赋值 */
     $options = $this->widget('Widget_Options');
     /** cookie初始化 */
     Typecho_Cookie::setPrefix($options->siteUrl);
     /** 初始化charset */
     Typecho_Common::$charset = $options->charset;
     /** 初始化exception */
     Typecho_Common::$exceptionHandle = 'Widget_ExceptionHandle';
     /** 设置路径 */
     if (defined('__TYPECHO_PATHINFO_ENCODING__')) {
         $pathInfo = $this->request->getPathInfo(__TYPECHO_PATHINFO_ENCODING__, $options->charset);
     } else {
         $pathInfo = $this->request->getPathInfo();
     }
     Typecho_Router::setPathInfo($pathInfo);
     /** 初始化路由器 */
     Typecho_Router::setRoutes($options->routingTable);
     /** 初始化插件 */
     Typecho_Plugin::init($options->plugins);
     /** 初始化回执 */
     $this->response->setCharset($options->charset);
     $this->response->setContentType($options->contentType);
     /** 默认时区 */
     if (function_exists("ini_get") && !ini_get("date.timezone") && function_exists("date_default_timezone_set")) {
         @date_default_timezone_set('UTC');
     }
     /** 初始化时区 */
     Typecho_Date::setTimezoneOffset($options->timezone);
     /** 开始会话, 减小负载只针对后台打开session支持 */
     if ($this->widget('Widget_User')->hasLogin()) {
         @session_start();
     }
     /** 监听缓冲区 */
     ob_start();
 }
Esempio n. 12
0
 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' => '你已经点赞过了!'));
 }
Esempio n. 13
0
 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));
 }
Esempio n. 14
0
<script>
    (function () {
        $(document).ready(function() {
            // 处理消息机制
            (function () {
                var prefix = '<?php 
echo Typecho_Cookie::getPrefix();
?>
',
                    cookies = {
                        notice      :   $.cookie(prefix + '__typecho_notice'),
                        noticeType  :   $.cookie(prefix + '__typecho_notice_type'),
                        highlight   :   $.cookie(prefix + '__typecho_notice_highlight')
                    },
                    path = '<?php 
echo Typecho_Cookie::getPath();
?>
';

                if (!!cookies.notice && 'success|notice|error'.indexOf(cookies.noticeType) >= 0) {
                    var head = $('.typecho-head-nav'),
                        p = $('<div class="message popup ' + cookies.noticeType + '">'
                        + '<ul><li>' + $.parseJSON(cookies.notice).join('</li><li>') 
                        + '</li></ul></div>'), offset = 0;

                    if (head.length > 0) {
                        p.insertAfter(head);
                        offset = head.outerHeight();
                    } else {
                        p.prependTo(document.body);
                    }
Esempio n. 15
0
 /**
  * 通用过滤器
  *
  * @access public
  * @param array $value 需要过滤的行数据
  * @return array
  * @throws Typecho_Widget_Exception
  */
 public function filter(array $value)
 {
     /** 取出所有分类 */
     $value['categories'] = $this->db->fetchAll($this->db->select()->from('table.metas')->join('table.relationships', 'table.relationships.mid = table.metas.mid')->where('table.relationships.cid = ?', $value['cid'])->where('table.metas.type = ?', 'category')->order('table.metas.order', Typecho_Db::SORT_ASC), array($this->widget('Widget_Metas_Category_List'), 'filter'));
     $value['category'] = NULL;
     $value['directory'] = array();
     /** 取出第一个分类作为slug条件 */
     if (!empty($value['categories'])) {
         $value['category'] = $value['categories'][0]['slug'];
         $value['directory'] = $this->widget('Widget_Metas_Category_List')->getAllParents($value['categories'][0]['mid']);
         $value['directory'][] = $value['category'];
     }
     $value['date'] = new Typecho_Date($value['created']);
     /** 生成日期 */
     $value['year'] = $value['date']->year;
     $value['month'] = $value['date']->month;
     $value['day'] = $value['date']->day;
     /** 生成访问权限 */
     $value['hidden'] = false;
     /** 获取路由类型并判断此类型在路由表中是否存在 */
     $type = $value['type'];
     $routeExists = NULL != Typecho_Router::get($type);
     $tmpSlug = $value['slug'];
     $tmpCategory = $value['category'];
     $tmpDirectory = $value['directory'];
     $value['slug'] = urlencode($value['slug']);
     $value['category'] = urlencode($value['category']);
     $value['directory'] = implode('/', array_map('urlencode', $value['directory']));
     /** 生成静态路径 */
     $value['pathinfo'] = $routeExists ? Typecho_Router::url($type, $value) : '#';
     /** 生成静态链接 */
     $value['permalink'] = Typecho_Common::url($value['pathinfo'], $this->options->index);
     /** 处理附件 */
     if ('attachment' == $type) {
         $content = @unserialize($value['text']);
         //增加数据信息
         $value['attachment'] = new Typecho_Config($content);
         $value['attachment']->isImage = in_array($content['type'], array('jpg', 'jpeg', 'gif', 'png', 'tiff', 'bmp'));
         $value['attachment']->url = Widget_Upload::attachmentHandle($value);
         if ($value['attachment']->isImage) {
             $value['text'] = '<img src="' . $value['attachment']->url . '" alt="' . $value['title'] . '" />';
         } else {
             $value['text'] = '<a href="' . $value['attachment']->url . '" title="' . $value['title'] . '">' . $value['title'] . '</a>';
         }
     }
     /** 处理Markdown **/
     $value['isMarkdown'] = 0 === strpos($value['text'], '<!--markdown-->');
     if ($value['isMarkdown']) {
         $value['text'] = substr($value['text'], 15);
     }
     /** 生成聚合链接 */
     /** RSS 2.0 */
     $value['feedUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedUrl) : '#';
     /** RSS 1.0 */
     $value['feedRssUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedRssUrl) : '#';
     /** ATOM 1.0 */
     $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url($type, $value, $this->options->feedAtomUrl) : '#';
     $value['slug'] = $tmpSlug;
     $value['category'] = $tmpCategory;
     $value['directory'] = $tmpDirectory;
     /** 处理密码保护流程 */
     if (!empty($value['password']) && $value['password'] !== Typecho_Cookie::get('protectPassword') && $value['authorId'] != $this->user->uid && !$this->user->pass('editor', true)) {
         $value['hidden'] = true;
         /** 抛出错误 */
         if ($this->request->isPost() && isset($this->request->protectPassword)) {
             throw new Typecho_Widget_Exception(_t('对不起,您输入的密码错误'), 403);
         }
     }
     $value = $this->pluginHandle(__CLASS__)->filter($value, $this);
     /** 如果访问权限被禁止 */
     if ($value['hidden']) {
         $value['text'] = '<form class="protected" action="' . $this->security->getTokenUrl($value['permalink']) . '" method="post">' . '<p class="word">' . _t('请输入密码访问') . '</p>' . '<p><input type="password" class="text" name="protectPassword" />
         <input type="submit" class="submit" value="' . _t('提交') . '" /></p>' . '</form>';
         $value['title'] = _t('此内容被密码保护');
         $value['tags'] = array();
         $value['commentsNum'] = 0;
     }
     return $value;
 }
Esempio n. 16
0
 function showButton()
 {
     if (Typecho_Cookie::get('oauth_access_token') && Typecho_Cookie::get('oauth_access_token_secret')) {
         echo '<p><input type="checkbox" checked="" value="yes" id="post_to_twitter" name="post_to_twitter"/><label for="post_to_twitter">同时把留言更新到你的 Twitter</label></p>';
     } else {
         echo '<p><a href="?connect_to_twitter=yes"><img src="http://s3.amazonaws.com/static.whitleymedia/twitconnect.png" /></a></p>';
     }
 }
Esempio n. 17
0
 /**
  * 设置用户登陆状态
  */
 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));
 }
Esempio n. 18
0
 /**
  * 发送pingback
  * <code>
  * $this->sendPingbacks(365);
  * </code>
  *
  * @access public
  * @param integer $cid 内容id
  * @param array $trackback trackback的url
  * @return void
  */
 public function sendPing($cid, array $trackback = NULL)
 {
     $this->user->pass('contributor');
     if ($client = Typecho_Http_Client::get()) {
         try {
             $input = array('do' => 'ping', 'cid' => $cid);
             if (!empty($trackback)) {
                 $input['trackback'] = $trackback;
             }
             $client->setCookie('__typecho_uid', Typecho_Cookie::get('__typecho_uid'), 0, $this->options->siteUrl)->setCookie('__typecho_authCode', Typecho_Cookie::get('__typecho_authCode'), 0, $this->options->siteUrl)->setHeader('User-Agent', $this->options->generator)->setTimeout(3)->setData($input)->setIp('127.0.0.1')->send(Typecho_Common::url('/action/service', $this->options->index));
         } catch (Typecho_Http_Client_Exception $e) {
             return;
         }
     }
 }
Esempio n. 19
0
<?php

include 'common.php';
if ($user->hasLogin()) {
    $response->redirect($options->adminUrl);
}
$rememberName = htmlspecialchars(Typecho_Cookie::get('__typecho_remember_name'));
Typecho_Cookie::delete('__typecho_remember_name');
$bodyClass = 'body-100';
include 'header.php';
?>
<div class="typecho-login-wrap">
    <div class="typecho-login">
        <h1><a href="http://typecho.org" class="i-logo">Typecho</a></h1>
        <form action="<?php 
$options->loginAction();
?>
" method="post" name="login" role="form">
            <p>
                <label for="name" class="sr-only"><?php 
_e('用户名');
?>
</label>
                <input type="text" id="name" name="name" value="<?php 
echo $rememberName;
?>
" placeholder="<?php 
_e('用户名');
?>
" class="text-l w-100" autofocus />
            </p>
Esempio n. 20
0
 /**
  * 判断用户是否已经登录
  *
  * @access public
  * @return boolean
  */
 public function hasLogin()
 {
     if (NULL !== $this->_hasLogin) {
         return $this->_hasLogin;
     } else {
         $cookieUid = Typecho_Cookie::get('__typecho_uid');
         if (NULL !== $cookieUid) {
             /** 验证登陆 */
             $user = $this->db->fetchRow($this->db->select()->from('table.users')->where('uid = ?', intval($cookieUid))->limit(1));
             $cookieAuthCode = Typecho_Cookie::get('__typecho_authCode');
             if ($user && Typecho_Common::hashValidate($user['authCode'], $cookieAuthCode)) {
                 $this->_user = $user;
                 return $this->_hasLogin = true;
             }
             $this->logout();
         }
         return $this->_hasLogin = false;
     }
 }
Esempio n. 21
0
 /**
  * 执行函数
  *
  * @access public
  * @return void
  */
 public function execute()
 {
     if (!$this->parameter->parentId) {
         return;
     }
     $commentsAuthor = Typecho_Cookie::get('__typecho_remember_author');
     $commentsMail = Typecho_Cookie::get('__typecho_remember_mail');
     $select = $this->select()->where('table.comments.cid = ?', $this->parameter->parentId)->where('table.comments.status = ? OR (table.comments.author = ? AND table.comments.mail = ? AND table.comments.status = ?)', 'approved', $commentsAuthor, $commentsMail, 'waiting');
     $threadedSelect = NULL;
     if ($this->options->commentsShowCommentOnly) {
         $select->where('table.comments.type = ?', 'comment');
     }
     $select->order('table.comments.coid', 'ASC');
     $this->db->fetchAll($select, array($this, 'push'));
     /** 需要输出的评论列表 */
     $outputComments = array();
     /** 如果开启评论回复 */
     if ($this->options->commentsThreaded) {
         foreach ($this->stack as $coid => &$comment) {
             /** 取出父节点 */
             $parent = $comment['parent'];
             /** 如果存在父节点 */
             if (0 != $parent && isset($this->stack[$parent])) {
                 /** 如果当前节点深度大于最大深度, 则将其挂接在父节点上 */
                 if ($comment['levels'] >= $this->options->commentsMaxNestingLevels) {
                     $comment['levels'] = $this->stack[$parent]['levels'];
                     $parent = $this->stack[$parent]['parent'];
                     // 上上层节点
                     $comment['parent'] = $parent;
                 }
                 /** 计算子节点顺序 */
                 $comment['order'] = isset($this->_threadedComments[$parent]) ? count($this->_threadedComments[$parent]) + 1 : 1;
                 /** 如果是子节点 */
                 $this->_threadedComments[$parent][$coid] = $comment;
             } else {
                 $outputComments[$coid] = $comment;
             }
         }
         $this->stack = $outputComments;
     }
     /** 评论排序 */
     if ('DESC' == $this->options->commentsOrder) {
         $this->stack = array_reverse($this->stack, true);
         $this->_threadedComments = array_map('array_reverse', $this->_threadedComments);
     }
     /** 评论总数 */
     $this->_total = count($this->stack);
     /** 对评论进行分页 */
     if ($this->options->commentsPageBreak) {
         if ('last' == $this->options->commentsPageDisplay && !$this->parameter->commentPage) {
             $this->_currentPage = ceil($this->_total / $this->options->commentsPageSize);
         } else {
             $this->_currentPage = $this->parameter->commentPage ? $this->parameter->commentPage : 1;
         }
         /** 截取评论 */
         $this->stack = array_slice($this->stack, ($this->_currentPage - 1) * $this->options->commentsPageSize, $this->options->commentsPageSize);
         /** 评论置位 */
         $this->row = current($this->stack);
         $this->length = count($this->stack);
     }
     reset($this->stack);
 }
Esempio n. 22
0
    ?>
")
    .script("<?php 
    echo $resUrl . 'js/diff.js';
    ?>
")
<?php 
}
?>
    .wait(function() {

        $(function() {
            // 处理消息机制
            (function () {
                var prefix = '<?php 
echo Typecho_Cookie::getPrefix();
?>
',
                    cookies = {
                        notice      :   $.cookie(prefix + '__typecho_notice'),
                        noticeType  :   $.cookie(prefix + '__typecho_notice_type'),
                        highlight   :   $.cookie(prefix + '__typecho_notice_highlight')
                    },
                    path = '<?php 
$parts = parse_url($this->options->siteUrl);
echo empty($parts['path']) ? '/' : $parts['path'];
?>
';

                if (!!cookies.notice && 'success|notice|error'.indexOf(cookies.noticeType) >= 0) {
                    var head = $('.typecho-head-nav'),
Esempio n. 23
0
 /**
  * 输出cookie记忆别名
  *
  * @access public
  * @param string $cookieName 已经记忆的cookie名称
  * @param boolean $return 是否返回
  * @return string
  */
 public function remember($cookieName, $return = false)
 {
     $cookieName = strtolower($cookieName);
     if (!in_array($cookieName, array('author', 'mail', 'url'))) {
         return '';
     }
     $value = Typecho_Cookie::get('__typecho_remember_' . $cookieName);
     if ($return) {
         return $value;
     } else {
         echo htmlspecialchars($value);
     }
 }
Esempio n. 24
0
 /**
  * 设置前缀 
  * 
  * @param string $prefix 
  * @access public
  * @return void
  */
 public static function setPrefix($prefix)
 {
     self::$_prefix = md5($prefix);
 }
Esempio n. 25
0
<?php

include 'common.php';
if ($user->hasLogin() || !$options->allowRegister) {
    $response->redirect($options->siteUrl);
}
$rememberName = htmlspecialchars(Typecho_Cookie::get('__typecho_remember_name'));
$rememberMail = htmlspecialchars(Typecho_Cookie::get('__typecho_remember_mail'));
Typecho_Cookie::delete('__typecho_remember_name');
Typecho_Cookie::delete('__typecho_remember_mail');
$bodyClass = 'body-100';
include 'header.php';
?>
<div class="typecho-login-wrap">
    <div class="typecho-login">
        
        <form action="<?php 
$options->registerAction();
?>
" method="post" name="register" role="form">
            <p>
                <label for="name" class="sr-only"><?php 
_e('用户名');
?>
</label>
                <input type="text" id="name" name="name" placeholder="<?php 
_e('用户名');
?>
" value="<?php 
echo $rememberName;
?>
Esempio n. 26
0
                    <?php 
    }
    ?>
                    <?php 
}
?>
                    <!--<li><a href="<?php 
$options->adminUrl('profile.php');
?>
"><?php 
_e('更新我的资料');
?>
</a></li>-->
                </ul>
                <?php 
$version = Typecho_Cookie::get('__typecho_check_version');
?>
                <?php 
if ($version && $version['available']) {
    ?>
                <div class="update-check">
                    <p class="message notice">
                        <?php 
    _e('您当前使用的版本是');
    ?>
 <?php 
    echo $version['current'];
    ?>
 &rarr;
                        <strong><a href="<?php 
    echo $version['link'];
Esempio n. 27
0
 /**
  * 执行函数
  *
  * @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'));
 }
Esempio n. 28
0
 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));
 }
Esempio n. 29
0
 /**
  * 执行更新动作
  *
  * @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();
 }
Esempio n. 30
0
 /**
  * 远程请求代理
  *
  * @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);
 }