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)); }
/** * 通用过滤器 * * @access public * @param array $value 需要过滤的行数据 * @return array */ public function filter(array $value) { //生成静态链接 $routeExists = NULL != Typecho_Router::get('author'); $value['permalink'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->index) : '#'; /** 生成聚合链接 */ /** RSS 2.0 */ $value['feedUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedUrl) : '#'; /** RSS 1.0 */ $value['feedRssUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedRssUrl) : '#'; /** ATOM 1.0 */ $value['feedAtomUrl'] = $routeExists ? Typecho_Router::url('author', $value, $this->options->feedAtomUrl) : '#'; // modified_by_jiangmuzi 2015.09.22 $avatar = Forum_Common::parseUserAvatar($value['uid']); $value = array_merge($value, $avatar); $value['ucenter'] = $this->options->someUrl('ucenter', array('u' => $value['name']), false); // end modified $value = $this->pluginHandle(__CLASS__)->filter($value, $this); return $value; }
<li><?php $archives->tags(','); ?> • </li> <?php } ?> <li><a href="<?php $archives->author->ucenter(); ?> "><?php $archives->author->name(); ?> </a> • </li> <li><span><?php echo Forum_Common::formatTime($archives->created, 'Y-m-d H:i:s'); ?> </span></li> <?php if ($archives->lastUid) { ?> <li> • 最后回复来自:<strong><a href="<?php $archives->lastAuthor->ucenter(); ?> "><?php $archives->lastAuthor->name(); ?> </a></strong></li> <?php } ?>
"></a> </div> <h1 class="post-title"><?php $this->title(); ?> </h1> <ul class="post-meta"> <li><a href="<?php $this->author->ucenter(); ?> "><?php $this->author(); ?> </a> · </li> <li><span><?php echo Forum_Common::formatTime($this->created); ?> </span> · </li> <li><span><?php $this->viewsNum(); _e('次点击'); ?> </span></li> <?php if ($this->user->hasLogin() && $this->user->uid == $this->author->uid) { ?> <li> · <span><a href="<?php $this->options->index('publish?cid=' . $this->cid); ?> "><?php _e('编辑');
<li><?php $posts->tags(','); ?> • </li> <?php } ?> <li><a href="<?php $posts->author->ucenter(); ?> "><?php $posts->author->name(); ?> </a> • </li> <li><span><?php echo Forum_Common::formatTime($posts->created, 'Y-m-d H:i:s'); ?> </span></li> <?php if ($posts->lastUid) { ?> <li> • 最后回复来自:<strong><a href="<?php $posts->lastAuthor->ucenter(); ?> "><?php $posts->lastAuthor->name(); ?> </a></strong></li> <?php } ?>
?> <a class="fade fr" href="#">取消当前头像</a></div> <div class="cell"> <div class="field"> <label>当前头像</label> <p class="m0"> <img class="avatar vab mr10" width="96" src="<?php echo Forum_Common::avatar($this->user->uid, 96); ?> " align="default"> <img class="avatar vab mr10" width="48" src="<?php echo Forum_Common::avatar($this->user->uid, 48); ?> " align="default"> <img class="avatar vab mr10" width="32" src="<?php echo Forum_Common::avatar($this->user->uid, 32); ?> " align="default"> </p> </div> <div class="field"> <label> </label> <p><a class="btn" href="<?php $this->options->someUrl('setting_avatar'); ?> "><?php _e('上传新头像'); ?> </a></p> </div> </div>
/** * 上传头像 * @param array $file * @return boolean|multitype:string unknown number Ambigous <string, unknown> Ambigous <Ambigous, string, mixed> */ private function uploadAvatar($file) { if (empty($file['name'])) { return false; } $ext = $this->getSafeName($file['name']); if (!Widget_Upload::checkFileType(strtolower($ext)) || Typecho_Common::isAppEngine()) { return false; } $options = Typecho_Widget::widget('Widget_Options'); $path = Forum_Common::getAvatarPath($this->user->uid); $realPath = Typecho_Common::url($path, defined('__TYPECHO_UPLOAD_ROOT_DIR__') ? __TYPECHO_UPLOAD_ROOT_DIR__ : __TYPECHO_ROOT_DIR__); //创建上传目录 if (!is_dir($realPath)) { if (!$this->makeAvatarDir($realPath)) { return false; } } //获取文件名 $fileName = $this->user->uid . '.' . $ext; $realPath = $realPath . '/' . $fileName; if (isset($file['tmp_name'])) { //移动上传文件 if (!@move_uploaded_file($file['tmp_name'], $realPath)) { return false; } } else { if (isset($file['bytes'])) { //直接写入文件 if (!file_put_contents($realPath, $file['bytes'])) { return false; } } else { return false; } } if (!isset($file['size'])) { $file['size'] = filesize($realPath); } //返回相对存储路径 return array('name' => $file['name'], 'path' => $path, 'file' => $path . $fileName, 'size' => $file['size'], 'type' => $ext, 'mime' => Typecho_Common::mimeContentType($realPath)); }
?> <?php while ($comments->next()) { ?> <div class="cell" style="background-color: #EDF3F5;"><?php _e('回复了'); ?> <a href="<?php $comments->permalink(); ?> "><?php $comments->title(); ?> </a> <span class="fr"><?php echo Forum_Common::formatTime($comments->created); ?> </span> </div> <div class="cell"><?php $comments->content(); ?> </div> <?php } ?> <?php } else { ?> <div class="cell"> <p class="aligncenter fade"><?php
public function footer() { $nodetags = Forum_Common::allNodeTags(); $topicNode = isset($this->currentTag['parent']) ? $this->currentTag['parent'] != 0 ? $this->currentTag['parent'] : $this->currentTag['mid'] : 0; $html = <<<EOT <script src="{$this->options->themeUrl('codemirror/codemirror.js', 'default')}"></script> <script src="{$this->options->themeUrl('codemirror/markdown.js', 'default')}"></script> <script src="{$this->options->themeUrl('js/jquery.tagsinput.min.js', 'default')}"></script> <script> //编辑器 var pubEditor = CodeMirror.fromTextArea(document.getElementById("topic_content"), { lineNumbers: true, mode: "markdown", theme: "neo", indentUnit: 4, lineWrapping: true }); //实时统计并控制内容字数 pubEditor.on('change', function(cm, change) { var text = cm.getValue(); var max = 20000; var remaining = max - text.length; var r = \$("#content_remaining"); r.html(remaining); }); //实时统计并控制标题字数 \$("#topic_title").keyup(function(e) { var s = \$("#topic_title"); var text = s.val() var max = 120; var remaining = max - text.length; var r = \$("#title_remaining"); r.html(remaining); }); //切换标签 \$('#topic-node').on('change',function(){ \tvar that = \$(this); mid = that.data('mid'),select = that.val(); \tif(select == mid){ \t return false; \t} \tthat.data('mid',select); \tsetRecTags(select); }); function setRecTags(mid){ \tvar nodes = {$nodetags},html='<strong>推荐标签:</strong>'; \tif(nodes[mid]!==undefined){ \t\t\$.each(nodes[mid] ,function(id,tags){ \t\t html += '<a class="tag" href="#'+tags.slug+'">'+tags.name+'</a>'; \t\t}); \t}else{ \t\t//html='<strong>暂无推荐</strong>' \t} \t\$('#topic-hot-tags').html(html); } //设置默认 \$('#topic-node').val({$topicNode}); setRecTags({$topicNode}); //标签 \$('#tagsInput').tagsInput({ \twidth:'auto', \theight:'auto', \tdefaultText : '请输入标签名' }); \$(document).on('click','#topic-hot-tags a',function(){ \tvar tag = \$(this).text(); \$('#tagsInput').addTag(tag); return false; }); function prevTopic(){ \tvar box = \$("#topic_preview_box"); \tvar preview = \$("#topic_preview"); \tif (preview.length == 0) { box.append('<div class="inner" id="topic_preview"></div>'); preview = \$("#topic_preview"); } \tvar md = pubEditor.getValue(); \tif(md=='') return false; \t\$.post( window.siteUrl+"publish/preview", { 'md' : md }, function( data ) { preview.html('<div class="post-content">' + data + '</div>'); }); } </script> EOT; echo $html; }
protected function doRegister() { // 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); } //用户操作类 $users = $this->widget('Widget_Abstract_Users'); /** 初始化验证类 */ $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($users, 'nameExists'), _t('用户名已经存在')); $validator->addRule('mail', 'required', _t('必须填写电子邮箱')); $validator->addRule('mail', array($users, '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('__some_inviter'); if (!empty($inviter)) { $extend['inviter'] = $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 = $users->insert($dataStruct); //$insertId = 4; $this->db->fetchRow($users->select()->where('uid = ?', $insertId)->limit(1), array($users, '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'); //发送验证信息 Forum_Common::sendVerify($params); //注册积分 Forum_Common::credits('register'); $this->widget('Widget_Notice')->set(_t('用户 <strong>%s</strong> 已经成功注册,请及时验证邮件', $users->screenName), 'success'); $this->response->redirect($this->options->index); }
<link rel="stylesheet" href="<?php $this->options->themeUrl('css/style.css'); ?> "> <!--[if lt IE 9]> <script src="//cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> <script src="//cdn.staticfile.org/respond.js/1.3.0/respond.min.js"></script> <![endif]--> <!-- 通过自有函数输出HTML头部信息 --> <?php $this->header(); ?> <script> window.notice = <?php Forum_Common::getNotice(); ?> ; window.siteUrl = '<?php $this->options->siteUrl(); ?> '; </script> </head> <body> <!--[if lt IE 8]> <div class="browsehappy" role="dialog"><?php _e('当前网页 <strong>不支持</strong> 你正在使用的浏览器. 为了正常的访问, 请 <a href="http://browsehappy.com/">升级你的浏览器</a>'); ?> .</div> <![endif]-->
} ?> <?php if ($this->type == 'at') { ?> <div class="cell" style="background-color: #EDF3F5;"> <a href="<?php $this->author->ucenter(); ?> " target="_blank"><?php $this->author->name(); ?> </a> <?php _e('在'); _e(Forum_Common::formatTime($this->created)); _e('回复中@你:'); ?> <a href="<?php $this->permalink(); ?> " target="_blank"><?php _e('查看'); ?> </a> </div> <div class="cell"> <?php $this->content(); ?> </div>
} else { ?> <!-- 页面为其他页时 --> <?php $this->archiveTitle(' » ', '', ''); ?> <?php } ?> </div> </div> <article class="cell post page" itemscope itemtype="http://schema.org/BlogPosting"> <h1 class="post-title"><?php $this->title(); ?> </h1> <div class="post-content"> <?php $this->content(); ?> </div> </article> <div class="inner"><?php _e('最后更新:'); echo Forum_Common::formatTime($this->modified, 'Y-m-d H:i:s'); ?> </div> </div> </div><!-- end #main--> <?php $this->need('footer.php');