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); }
/** * 授权回调地址 */ public function callback() { if (empty($_GET['code'])) { throw new Typecho_Exception(_t('无效请求!')); } //跳转 if (!class_exists('SaeTOAuthV2')) { require_once './saetv2.ex.class.php'; } $saeto_client = new SaeTOAuthV2($this->config->client_id, $this->config->client_secret); //取access_token $access_token = $saeto_client->getAccessToken('code', array('code' => trim($_GET['code']), 'redirect_uri' => $this->config->callback_url)); if (empty($access_token) || !is_array($access_token) || empty($access_token['uid'])) { throw new Typecho_Exception(_t('获取access_token失败,请返回重新授权!')); } $table = $this->db->getPrefix() . self::$tableName; $query = $this->db->query("SELECT * FROM {$table} WHERE openid='{$access_token['uid']}' AND plateform='sina'"); $users_oauth = $this->db->fetchRow($query); if (!empty($users_oauth['uid'])) { //该新浪帐号已经绑定了用户 if (Typecho_Widget::widget('Widget_User')->hasLogin()) { /** 直接返回 */ $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index); } else { //让其直接登陆 $this->setUserLogin($users_oauth['uid']); if (!Typecho_Widget::widget('Widget_User')->pass('contributor', true)) { /** 不允许普通用户直接跳转后台 */ $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl); } else { $this->response->redirect(Typecho_Widget::widget('Widget_Options')->adminUrl); } } exit; } //该新浪帐号未绑定过 /** 如果已经登录 */ if (Typecho_Widget::widget('Widget_User')->hasLogin()) { /** 直接绑定 */ $cookieUid = Typecho_Cookie::get('__typecho_uid'); $this->bindOauthUser($cookieUid, $access_token['uid'], 'sina', $access_token['expires_in']); $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index); } else { //取用户信息 $saetc_client = new SaeTClientV2($this->config->client_id, $this->config->client_secret, $access_token['access_token']); $weibo_user = $saetc_client->show_user_by_id($access_token['uid']); //创建用户 $uid = $this->registerFromWeiboUser($weibo_user); if (!$uid) { throw new Typecho_Exception(_t('创建帐号失败,请联系管理员!')); } $this->setUserLogin($uid); $this->bindOauthUser($uid, $access_token['uid'], 'sina', $access_token['expires_in']); $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl); } //构造用户帐号 exit; }
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; }
/** * 执行函数 * * @access public * @return void */ public function execute() { if (NULL !== Typecho_Cookie::get('__typecho_notice')) { $this->noticeType = Typecho_Cookie::get('__typecho_notice_type'); $this->push(Typecho_Cookie::get('__typecho_notice')); Typecho_Cookie::delete('__typecho_notice', $this->widget('Widget_Options')->siteUrl); Typecho_Cookie::delete('__typecho_notice_type', $this->widget('Widget_Options')->siteUrl); } if (NULL !== Typecho_Cookie::get('__typecho_notice_highlight')) { $this->highlight = Typecho_Cookie::get('__typecho_notice_highlight'); Typecho_Cookie::delete('__typecho_notice_highlight', $this->widget('Widget_Options')->siteUrl); } }
/** * 获取提示消息 */ 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); }
public static function hasLogin() { $cookieUid = Typecho_Cookie::get('__typecho_uid'); if (null !== $cookieUid) { $db = Typecho_Db::get(); $user = $db->fetchRow($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)) { return true; } Typecho_Cookie::delete('__typecho_uid'); Typecho_Cookie::delete('__typecho_authCode'); } return false; }
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' => '你已经点赞过了!')); }
<?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']; ?> → <strong><a href="<?php echo $version['link'];
/** * 执行函数 * * @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')); }
/** * 执行函数 * * @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); }
<?php include 'common.php'; include 'header.php'; $rememberName = Typecho_Cookie::get('__typecho_remember_name'); Typecho_Cookie::delete('__typecho_remember_name'); ?> <div class="body body-950"> <div class="container"> <div class="column-07 start-09 typecho-login"> <h2 class="logo-dark">typecho</h2> <form action="<?php $options->loginAction(); ?> " method="post" name="login"> <fieldset> <?php if (!$user->hasLogin()) { ?> <?php if ($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))) { ?> <div class="message <?php $notice->noticeType(); ?> typecho-radius-topleft typecho-radius-topright typecho-radius-bottomleft typecho-radius-bottomright"> <ul> <?php $notice->lists(); ?> </ul>
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); }
/** * 通用过滤器 * * @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; }
<?php if (!defined('__TYPECHO_ROOT_DIR__')) { exit; } $this->need('header.php'); ?> <style>.user-page .page-title,.user-page footer{display:none;}</style> <?php $rememberName = htmlspecialchars(Typecho_Cookie::get('__typecho_remember_name')); $rememberMail = htmlspecialchars(Typecho_Cookie::get('__typecho_remember_mail')); $notice = Typecho_Cookie::get('__typecho_notice'); if (!empty($notice)) { $notice = json_decode($notice, true); } Typecho_Cookie::delete('__typecho_remember_name'); Typecho_Cookie::delete('__typecho_remember_mail'); ?> <div id="sidebar"> <?php $this->need('user/widget_login.php'); ?> </div> <div class="box" id="main"> <div class="head"> <div class="location"> <a href="<?php $this->options->siteUrl(); ?> "><?php $this->options->title();
<?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>
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']; }
<?php if (!defined('__TYPECHO_ROOT_DIR__')) { exit; } $this->need('header.php'); ?> <style>.user-page .page-title,.user-page footer{display:none;}</style> <?php $rememberName = htmlspecialchars(Typecho_Cookie::get('__some_remember_name')); $rememberMail = htmlspecialchars(Typecho_Cookie::get('__some_remember_mail')); $notice = Typecho_Cookie::get('__some_notice'); if (!empty($notice)) { $notice = json_decode($notice, true); } Typecho_Cookie::delete('__some_remember_name'); Typecho_Cookie::delete('__some_remember_mail'); ?> <div id="sidebar"> <?php $this->need('user/widget_login.php'); ?> </div> <div class="box" id="main"> <div class="head"> <div class="location"> <a href="<?php $this->options->siteUrl(); ?> "><?php $this->options->title();
<?php include 'common.php'; include 'header.php'; include 'menu.php'; $stat = Typecho_Widget::widget('Widget_Stat'); $comments = Typecho_Widget::widget('Widget_Comments_Admin'); $isAllComments = 'on' == $request->get('__some_all_comments') || 'on' == Typecho_Cookie::get('__some_all_comments'); ?> <div class="main"> <div class="body container"> <?php include 'page-title.php'; ?> <div class="row typecho-page-main" role="main"> <div class="col-mb-12 typecho-list"> <div class="clearfix"> <ul class="typecho-option-tabs right"> <?php if ($user->pass('editor', true) && !isset($request->cid)) { ?> <li class="<?php if ($isAllComments) { ?> current<?php } ?> "><a href="<?php echo $request->makeUriByRequest('__some_all_comments=on'); ?> "><?php
<?php include 'common.php'; include 'header.php'; $rememberName = Typecho_Cookie::get('__typecho_remember_name'); $rememberMail = Typecho_Cookie::get('__typecho_remember_mail'); Typecho_Cookie::delete('__typecho_remember_name'); Typecho_Cookie::delete('__typecho_remember_mail'); ?> <div class="body body-950"> <div class="container"> <div class="column-07 start-09 typecho-login"> <h2 class="logo-dark">typecho</h2> <form action="<?php $options->registerAction(); ?> " method="post" name="register"> <fieldset> <?php if (!$user->hasLogin() && $options->allowRegister) { ?> <?php if ($notice->have() && in_array($notice->noticeType, array('success', 'notice', 'error'))) { ?> <div class="message <?php $notice->noticeType(); ?> typecho-radius-topleft typecho-radius-topright typecho-radius-bottomleft typecho-radius-bottomright"> <ul> <?php $notice->lists();
<div class="typecho-install-body"> <form method="post" action="?config" name="config"> <p class="message error"><?php _e('您没有上传 config.inc.php 文件,请您重新安装!'); ?> <button type="submit"><?php _e('重新安装 »'); ?> </button></p> </form> </div> <?php } else { ?> <?php $config = unserialize(base64_decode(Typecho_Cookie::get('__typecho_config'))); $type = explode('_', $config['adapter']); $type = array_pop($type); try { $installDb = new Typecho_Db($config['adapter'], $config['prefix']); $installDb->addServer($config, Typecho_Db::READ | Typecho_Db::WRITE); /** 初始化数据库结构 */ $scripts = file_get_contents('./install/' . $type . '.sql'); $scripts = str_replace('typecho_', $config['prefix'], $scripts); if (isset($config['charset'])) { $scripts = str_replace('%charset%', $config['charset'], $scripts); } $scripts = explode(';', $scripts); foreach ($scripts as $script) { $script = trim($script); if ($script) {
public function bind() { $type = $this->request->get('type'); if (!empty($type) && $this->user->hasLogin()) { $this->unbind($type); exit; } $this->current = 'bind'; $this->auth = Typecho_Cookie::get('__user_auth'); $this->auth = unserialize($this->auth); if (empty($this->auth['openid']) || empty($this->auth['type'])) { $this->widget('Widget_Notice')->set(array('请重新登录!'), 'error'); $this->response->redirect($this->___loginUrl()); } if ($this->request->isPost()) { $do = $this->request->get('do'); if ($do == 'register') { $this->doBindRegister(); } elseif ($do == 'login') { $this->doBindLogin(); } else { Typecho_Cookie::delete('__user_auth'); $this->widget('Widget_Notice')->set(array('请重新登录!'), 'error'); $this->response->redirect($this->___loginUrl()); } } else { $this->_title = '绑定帐号'; $this->render('user/bind.php'); } }
/** * 发送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; } } }
/** * 增加浏览量 * @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 } } }
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>'; } }
/** * 输出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); } }
<?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; ?>
Typecho_Widget::widget('Widget_Init'); /** 注册一个初始化插件 */ Typecho_Plugin::factory('admin/common.php')->begin(); Typecho_Widget::widget('Widget_Options')->to($options); 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 {
/** * 判断用户是否已经登录 * * @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; } }
/** * 显示表单 * * @access public * @return void */ public function render() { $id = md5(implode('"', array_keys($this->_inputs))); /** 恢复表单值 */ if ($record = Typecho_Cookie::get('__typecho_form_record_' . $id)) { $message = Typecho_Cookie::get('__typecho_form_message_' . $id); foreach ($this->_inputs as $name => $input) { $input->value(isset($record[$name]) ? $record[$name] : $input->value); /** 显示错误消息 */ if (isset($message[$name])) { $input->message($message[$name]); } } Typecho_Cookie::delete('__typecho_form_record_' . $id); } parent::render(); Typecho_Cookie::delete('__typecho_form_message_' . $id); }