Skip to content

Instantly share code, notes, and snippets.

@CzBiX
Created February 27, 2014 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CzBiX/9245629 to your computer and use it in GitHub Desktop.
Save CzBiX/9245629 to your computer and use it in GitHub Desktop.
Filter spam comment in Typecho, file path: /var/Widget/Feedback.php, line 82
<?php
if(!$this->user->hasLogin()) {
/** 过滤纯英文评论 */
$pattern = '/[\x{4E00}-\x{9FA5}]/u';
if (!preg_match($pattern, $comment['text'], $match)) {
throw new Typecho_Widget_Exception(_t('You should type some Chinese word (like "你好") in your comment to pass the spam-check, thanks for your patience!<br />您的评论中必须包含汉字!<p><a style="color:#FFF; border: 1px solid;text-decoration:none;padding:0px 2px" href="javascript:void(history.back())">点此返回</a></p>'));
}
/** 过滤包含日文的评论 */
$pattern = '/[\x{3040}-\x{31FF}]/u';
if (preg_match($pattern, $comment['text'], $match)) {
throw new Typecho_Widget_Exception(_t('You can not contains Japenese word in your comment to pass the spam-check, thanks for your patience!<br />您的评论中不能包含日文!<p><a style="color:#FFF; border: 1px solid;text-decoration:none;padding:0px 2px" href="javascript:void(history.back())">点此返回</a></p>'));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment