spam小墙

2013.09.28 2103 人浏览 留言

分享一个//spam小墙

  1. //spam小墙  
  2. class anti_spam {  
  3.     //建立  
  4.     function anti_spam() {  
  5.         if ( !current_user_can('level_0') ) {  
  6.             add_action('template_redirect', array($this, 'w_tb'), 1);  
  7.             add_action('init', array($this, 'gate'), 1);  
  8.             add_action('preprocess_comment', array($this, 'sink'), 1);  
  9.         }  
  10.     }  
  11.    
  12.     //設欄位  
  13.     function w_tb() {  
  14.         if ( is_singular() ) {  
  15.             ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=([\"\'])comment([\"\'])(.+)/textarea>#",  
  16.             "textarea$1name=$2wall$3$4/textarea><textarea name=\"comment\" cols=\"50\" rows=\"4\" style=\"display:none\"></textarea>",$input);') );  
  17.         }  
  18.     }  
  19.    
  20.     //檢查  
  21.     function gate() {  
  22.         ( !emptyempty($_POST['wall']) && emptyempty($_POST['comment']) ) ? $_POST['comment'] = $_POST['wall'] : $_POST['spam_confirmed'] = 1;  
  23.     }  
  24.    
  25.     //處理  
  26.     function sink( $comment ) {  
  27.         if ( !emptyempty($_POST['spam_confirmed']) ) {  
  28.             //方法一:直接擋掉, 將 die(); 前面兩斜線刪除即可.  
  29.             //die();  
  30.             //方法二:標記為spam, 留在資料庫檢查是否誤判.  
  31.             //add_filter('pre_comment_approved', create_function('', 'return "spam";'));  
  32.             /* 
  33.             $is_ping = in_array( $comment['comment_type'], array('pingback', 'trackback') ); 
  34.             $comment['comment_content'] = ( $is_ping ) ? 
  35.             "◎ 這是 Pingback/Trackback, 小牆懷疑這可能是 Spam!\n" . $comment['comment_content'] : 
  36.             "[ 小牆判斷這是Spam! ]\n" . $comment['comment_content']; 
  37.             */  
  38.             // MG12 的處理方法  
  39.             $is_ping = in_array( $comment['comment_type'], array('pingback', 'trackback') );  
  40.             if(!$is_ping) {  
  41.                 die();  
  42.             }  
  43.         }  
  44.         return $comment;  
  45.     }  
  46. }  
  47. new anti_spam();  

文章地址:https://huilang.me/isay/spam-small-wall/

回复本文

您的电子邮箱地址不会被公开。 必填项已用 * 标注

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif