diff --git a/core/core.php b/core/core.php index 93d31a4..6397f7c 100644 --- a/core/core.php +++ b/core/core.php @@ -25,11 +25,11 @@ function themeInit($self) Helper::options()->commentsAntiSpam = false; /* 强奸用户关闭检查来源URL */ Helper::options()->commentsCheckReferer = false; - /* 强奸用户强制要求填写邮箱 */ + /* 强奸用户要求填写邮箱 */ Helper::options()->commentsRequireMail = true; - /* 强奸用户强制要求无需填写url */ + /* 强奸用户要求无需填写url */ Helper::options()->commentsRequireURL = false; - /* 强制用户开启评论回复 */ + /* 强制用户评论回复 */ Helper::options()->commentsThreaded = true; /* 强制显示一页12篇文章 */ $self->parameter->pageSize = 12; diff --git a/core/factory.php b/core/factory.php index 833a595..60dacea 100644 --- a/core/factory.php +++ b/core/factory.php @@ -1,5 +1,7 @@ bottom = array('Editor', 'edit'); Typecho_Plugin::factory('admin/write-page.php')->bottom = array('Editor', 'edit'); @@ -12,3 +14,26 @@ class Editor echo ""; } } + + +/* 加强评论拦截功能 */ +Typecho_Plugin::factory('Widget_Feedback')->comment = array('Intercept', 'message'); +class Intercept +{ + public static function message($comment) + { + /* 判断评论内容是否包含敏感词 */ + if (Helper::options()->JSensitiveWords) { + if (_checkSensitiveWords(Helper::options()->JSensitiveWords, $comment['text'])) { + throw new Typecho_Widget_Exception("评论内容包含敏感词汇!", 403); + } + } + /* 判断评论是否至少包含一个中文 */ + if (Helper::options()->JLimitOneChinese === "on") { + if (!preg_match("/\{!\{.{0,}/", $comment['text']) && preg_match("/[\x{4e00}-\x{9fa5}]/u", $comment['text']) == 0) { + throw new Typecho_Widget_Exception("评论至少包含一个中文!", 403); + } + } + return $comment; + } +} diff --git a/core/function.php b/core/function.php index 0af07dc..9b33df4 100644 --- a/core/function.php +++ b/core/function.php @@ -3,7 +3,7 @@ /* 获取主题当前版本号 */ function _getVersion() { - return "5.0.8"; + return "5.0.9"; }; /* 判断是否是手机 */ @@ -296,3 +296,18 @@ function _curl($url) curl_close($ch); return $result; } + +/* 判断敏感词是否在字符串内 */ +function _checkSensitiveWords($words_str, $str) +{ + $words = explode("||", $words_str); + if (empty($words)) { + return false; + } + foreach ($words as $word) { + if (false !== strpos($str, trim($word))) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/functions.php b/functions.php index c68a9fb..0af053e 100644 --- a/functions.php +++ b/functions.php @@ -711,6 +711,27 @@ function themeConfig($form) $JCustomPlayer->setAttribute('class', 'joe_content joe_other'); $form->addInput($JCustomPlayer); + $JSensitiveWords = new Typecho_Widget_Helper_Form_Element_Textarea( + 'JSensitiveWords', + NULL, + '你妈死了 || 傻逼 || 操你妈 || 射你妈一脸', + '评论敏感词(非必填)', + '介绍:用于设置评论敏感词汇,如果用户评论包含这些词汇,则将会禁止评论
+ 例如:你妈死了 || 你妈炸了 || 我是你爹 || 你妈坟头冒烟 (多个使用 || 分隔开)' + ); + $JSensitiveWords->setAttribute('class', 'joe_content joe_other'); + $form->addInput($JSensitiveWords); + + $JLimitOneChinese = new Typecho_Widget_Helper_Form_Element_Select( + 'JLimitOneChinese', + array('off' => '关闭(默认)', 'on' => '开启'), + 'off', + '是否开启评论至少包含一个中文', + '介绍:开启后如果评论内容未包含一个中文,则将会禁止评论
+ 其他:用于屏蔽国外机器人刷的全英文垃圾广告信息' + ); + $JLimitOneChinese->setAttribute('class', 'joe_content joe_other'); + $form->addInput($JLimitOneChinese->multiMode()); $JBaiduToken = new Typecho_Widget_Helper_Form_Element_Text( 'JBaiduToken', diff --git a/index.php b/index.php index 455ceb0..eeed38a 100644 --- a/index.php +++ b/index.php @@ -9,6 +9,23 @@ ?> + +