diff options
| author | BigCoke233 <hi@guhub.cn> | 2020-07-10 22:58:49 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2020-07-10 22:58:49 +0800 |
| commit | 4901b642cd90a9124a4ca5732210707caa030290 (patch) | |
| tree | 5bb5954a5b306e88e5125d4b44a80710c1f146c0 /libs/Comments.php | |
| parent | 39b4e65156bb35e5a23ef1904d16716cd9562ab1 (diff) | |
:zap: Perf: 兼容 typecho 自带反垃圾功能,并优化代码结构
Diffstat (limited to 'libs/Comments.php')
| -rw-r--r-- | libs/Comments.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libs/Comments.php b/libs/Comments.php new file mode 100644 index 0000000..78fd087 --- /dev/null +++ b/libs/Comments.php @@ -0,0 +1,51 @@ +<?php +/** + * Comments.php + * 评论处理 + * + * Author: Eltrac(BigCoke233) + * License: MIT + */ +if (!defined('__TYPECHO_ROOT_DIR__')) exit; +class Comments +{ + /** + * 评论反垃圾 + * from ohmyga233/castle-Typecho-Theme + * + * @access public + */ + public static function AntiSpam($comment) { + if ($comment->options->switch && in_array('html', $comment->options->switch)) { echo '<!--<nocompress>-->'; } + echo '<script>(function(){var a=document.addEventListener?{add:"addEventListener",focus:"focus",load:"DOMContentLoaded"}:{add:"attachEvent",focus:"onfocus",load:"onload"};var c,d,e,f,b=document.getElementById("'.$comment->respondId.'");null!=b&&(c=b.getElementsByTagName("form"),c.length>0&&(d=c[0],e=d.getElementsByTagName("textarea")[0],f=!1,null!=e&&"text"==e.name&&e[a.add](a.focus,function(){if(!f){var a=document.createElement("input");a.type="hidden",a.name="_",d.appendChild(a),f=!0,a.value='.Typecho_Common::shuffleScriptVar($comment->security->getToken($comment->request->getRequestUrl())).'}})))})();</script>'; + if ($comment->options->switch && in_array('html', $comment->options->switch)) { echo '<!--</nocompress>-->'; } + } + + /** + * 获取上级评论人 + */ + public static function getCommentHF($coid){ + $db = Typecho_Db::get(); + $prow = $db->fetchRow($db->select('parent') + ->from('table.comments') + ->where('coid = ? AND status = ?', $coid, 'approved')); + $parent = $prow['parent']; + if ($parent != "0") { + $arow = $db->fetchRow($db->select('text','author','status') + ->from('table.comments') + ->where('coid = ?', $parent)); + $author = $arow['author']; + $status = $arow['status']; + if($author){ + if($status=='approved'){ + $href = '<a class="at" uid="'.$parent.'" href="#li-comment-'.$parent.'">@'.$author.'</a>';; + }else if($status=='waiting'){ + $href = '<a>评论审核中···</a>'; + } + } + echo $href; + } else { + echo ""; + } + } +}
\ No newline at end of file |
