[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/antispam/filters/ -> class.dc.filter.words.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This is Antispam, a plugin for DotClear. 
   4  # Copyright (c) 2007 Alain Vagner and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  class dcFilterWords extends dcSpamFilter
  24  {
  25      public $has_gui = true;
  26      public $name = 'Bad Words';
  27      
  28      private $style_list = 'height: 200px; overflow: auto; margin-bottom: 1em; ';
  29      private $style_p = 'margin: 1px 0 0 0; padding: 0.2em 0.5em; ';
  30      private $style_global = 'background: #ccff99; ';
  31      
  32      private $con;
  33      private $table;
  34      
  35  	public function __construct(&$core)
  36      {
  37          parent::__construct($core);
  38          $this->con =& $core->con;
  39          $this->table = $core->prefix.'spamrule';
  40      }
  41      
  42  	protected function setInfo()
  43      {
  44          $this->description = __('Words Blacklist');
  45      }
  46      
  47  	public function getStatusMessage($status,$comment_id)
  48      {
  49          return sprintf(__('Filtered by %1$s with word %2$s.'),$this->guiLink(),'<em>'.$status.'</em>');
  50      }
  51      
  52  	public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
  53      {
  54          $str = $author.' '.$email.' '.$site.' '.$content;
  55          
  56          $rs = $this->getRules('word');
  57          
  58          while ($rs->fetch())
  59          {
  60              $word = $rs->rule_content;
  61              
  62              if (substr($word,0,1) == '/' && substr($word,-1,1) == '/') {
  63                  $reg = substr(substr($word,1),0,-1);
  64              } else {
  65                  $reg = preg_quote($word);
  66                  $reg = '(^|\s+|>|<)'.$reg.'(>|<|\s+|\.|$)';
  67              }
  68              
  69              if (preg_match('/'.$reg.'/msiu',$str)) {
  70                  $status = $word;
  71                  return true;
  72              }
  73          }
  74      }
  75      
  76  	public function gui($url)
  77      {
  78          $core =& $this->core;
  79          
  80          # Create list
  81          if (!empty($_POST['createlist']))
  82          {
  83              try {
  84                  $this->defaultWordsList();
  85                  http::redirect($url.'&list=1');
  86              } catch (Exception $e) {
  87                  $core->error->add($e->getMessage());
  88              }
  89          }
  90          
  91          # Adding a word
  92          if (!empty($_POST['swa']))
  93          {
  94              $globalsw = !empty($_POST['globalsw']) && $core->auth->isSuperAdmin();
  95              
  96              try {
  97                  $this->addRule($_POST['swa'],$globalsw);
  98                  http::redirect($url.'&added=1');
  99              } catch (Exception $e) {
 100                  $core->error->add($e->getMessage());
 101              }
 102          }
 103          
 104          # Removing spamwords
 105          if (!empty($_POST['swd']) && is_array($_POST['swd']))
 106          {
 107              try {
 108                  $this->removeRule($_POST['swd']);
 109                  http::redirect($url.'&removed=1');
 110              } catch (Exception $e) {
 111                  $core->error->add($e->getMessage());
 112              }
 113          }
 114          
 115          /* DISPLAY
 116          ---------------------------------------------- */
 117          $res = '';
 118          
 119          if (!empty($_GET['list'])) {
 120              $res .= '<p class="message">'.__('Words have been successfully added.').'</p>';
 121          }
 122          if (!empty($_GET['added'])) {
 123              $res .= '<p class="message">'.__('Word has been successfully added.').'</p>';
 124          }
 125          if (!empty($_GET['removed'])) {
 126              $res .= '<p class="message">'.__('Words have been successfully removed.').'</p>';
 127          }
 128          
 129          $res .=
 130          '<form action="'.html::escapeURL($url).'" method="post">'.
 131          '<fieldset><legend>'.__('Add a word').'</legend>'.
 132          '<p>'.form::field('swa',20,128).' ';
 133          
 134          if ($core->auth->isSuperAdmin()) {
 135              $res .= '<label class="classic">'.form::checkbox('globalsw',1).' '.
 136              __('Global word').'</label> ';
 137          }
 138          
 139          $res .=
 140          '<input type="submit" value="'.__('Add').'"/></p>'.
 141          '</fieldset>'.
 142          '</form>';
 143          
 144          $rs = $this->getRules();
 145          if ($rs->isEmpty())
 146          {
 147              $res .= '<p><strong>'.__('No word in list.').'</strong></p>';
 148          }
 149          else
 150          {
 151              $res .=
 152              '<form action="'.html::escapeURL($url).'" method="post">'.
 153              '<fieldset><legend>' . __('List') . '</legend>'.
 154              '<div style="'.$this->style_list.'">';
 155              
 156              while ($rs->fetch())
 157              {
 158                  $disabled_word = false;
 159                  $p_style = $this->style_p;
 160                  if (!$rs->blog_id) {
 161                      $disabled_word = !$core->auth->isSuperAdmin();
 162                      $p_style .= $this->style_global;
 163                  }
 164                  
 165                  $res .=
 166                  '<p style="'.$p_style.'"><label class="classic">'.
 167                  form::checkbox(array('swd[]'),$rs->rule_id,false,'','',$disabled_word).' '.
 168                  html::escapeHTML($rs->rule_content).
 169                  '</label></p>';
 170              }
 171              
 172              $res .=
 173              '</div>'.
 174              '<p>'.form::hidden(array('spamwords'),1).
 175              '<input class="submit" type="submit" value="' . __('Delete selected words') . '"/></p>'.
 176              '</fieldset></form>';
 177          }
 178          
 179          if ($core->auth->isSuperAdmin())
 180          {
 181              $res .=
 182              '<form action="'.html::escapeURL($url).'" method="post">'.
 183              '<p><input type="submit" value="'.__('Create default wordlist').'" />'.
 184              form::hidden(array('spamwords'),1).
 185              form::hidden(array('createlist'),1).'</p>'.
 186              '</form>';
 187          }
 188          
 189          return $res;
 190      }
 191      
 192  	private function getRules()
 193      {
 194          $strReq = 'SELECT rule_id, blog_id, rule_content '.
 195                  'FROM '.$this->table.' '.
 196                  "WHERE rule_type = 'word' ".
 197                  "AND blog_id = '".$this->con->escape($this->core->blog->id)."' ".
 198                  "OR blog_id IS NULL ".
 199                  'ORDER BY blog_id ASC, rule_content ASC ';
 200          
 201          return $this->con->select($strReq);
 202      }
 203      
 204  	private function addRule($content,$general=false)
 205      {
 206          $strReq = 'SELECT rule_id FROM '.$this->table.' '.
 207                  "WHERE rule_type = 'word' ".
 208                  "AND rule_content = '".$this->con->escape($content)."' ";
 209          $rs = $this->con->select($strReq);
 210          
 211          if (!$rs->isEmpty()) {
 212              throw new Exception(__('This word exists'));
 213          }
 214          
 215          $rs = $this->con->select('SELECT MAX(rule_id) FROM '.$this->table);
 216          $id = (integer) $rs->f(0) + 1;
 217          
 218          $cur = $this->con->openCursor($this->table);
 219          $cur->rule_id = $id;
 220          $cur->rule_type = 'word';
 221          $cur->rule_content = (string) $content;
 222          
 223          if ($general && $this->core->auth->isSuperAdmin()) {
 224              $cur->blog_id = null;
 225          } else {
 226              $cur->blog_id = $this->core->blog->id;
 227          }
 228          
 229          $cur->insert();
 230      }
 231      
 232  	private function removeRule($ids)
 233      {
 234          $strReq = 'DELETE FROM '.$this->table.' ';
 235          
 236          if (is_array($ids)) {
 237              foreach ($ids as &$v) {
 238                  $v = (integer) $v;
 239              }
 240              $strReq .= 'WHERE rule_id IN ('.implode(',',$ids).') ';
 241          } else {
 242              $ids = (integer) $ids;
 243              $strReq .= 'WHERE rule_id = '.$ids.' ';
 244          }
 245          
 246          if (!$this->core->auth->isSuperAdmin()) {
 247              $strReq .= "AND blog_id = '".$this->con->escape($this->core->blog->id)."' ";
 248          }
 249          
 250          $this->con->execute($strReq);
 251      }
 252      
 253  	private function defaultWordsList()
 254      {
 255          $words = array(
 256              '/-credit(\s+|$)/',
 257              '/-digest(\s+|$)/',
 258              '/-loan(\s+|$)/',
 259              '/-online(\s+|$)/',
 260              '4u',
 261              'adipex',
 262              'advicer',
 263              'amazing',
 264              'ambien',
 265              'astonishing',
 266              'baccarat',
 267              'baccarrat',
 268              'blackjack',
 269              'bllogspot',
 270              'bolobomb',
 271              'booker',
 272              'byob',
 273              'car-rental-e-site',
 274              'car-rentals-e-site',
 275              'carisoprodol',
 276              'cash',
 277              'casino',
 278              'casinos',
 279              'chatroom',
 280              'cialis',
 281              'craps',
 282              'credit-card',
 283              'credit-report-4u',
 284              'cwas',
 285              'cyclen',
 286              'cyclobenzaprine',
 287              'dating-e-site',
 288              'day-trading',
 289              'debt',
 290              'digest-',
 291              'discount',
 292              'discreetordering',
 293              'duty-free',
 294              'dutyfree',
 295              'enjoyed',
 296              'estate',
 297              'favourits',
 298              'fioricet',
 299              'flowers-leading-site',
 300              'freenet',
 301              'freenet-shopping',
 302              'funny',
 303              'gambling',
 304              'gamias',
 305              'health-insurancedeals-4u',
 306              'helpful',
 307              'holdem',
 308              'holdempoker',
 309              'holdemsoftware',
 310              'holdemtexasturbowilson',
 311              'hotel-dealse-site',
 312              'hotele-site',
 313              'hotelse-site',
 314              'husband',
 315              'incest',
 316              'insurance-quotesdeals-4u',
 317              'insurancedeals-4u',
 318              'interesting',
 319              'jrcreations',
 320              'levitra',
 321              'macinstruct',
 322              'mortgage',
 323              'nice site',
 324              'online-gambling',
 325              'onlinegambling-4u',
 326              'ottawavalleyag',
 327              'ownsthis',
 328              'palm-texas-holdem-game',
 329              'paxil',
 330              'pharmacy',
 331              'phentermine',
 332              'pills',
 333              'poker',
 334              'poker-chip',
 335              'poze',
 336              'prescription',
 337              'rarehomes',
 338              'refund',
 339              'rental-car-e-site',
 340              'roulette',
 341              'shemale',
 342              'slot',
 343              'slot-machine',
 344              'soma',
 345              'taboo',
 346              'tamiflu',
 347              'teen',
 348              'texas-holdem',
 349              'thorcarlson',
 350              'top-e-site',
 351              'top-site',
 352              'tramadol',
 353              'trim-spa',
 354              'ultram',
 355              'v1h',
 356              'vacuum',
 357              'valeofglamorganconservatives',
 358              'viagra',
 359              'vicodin',
 360              'vioxx',
 361              'xanax',
 362              'zolus'
 363          );
 364          
 365          foreach ($words as $w) {
 366              try {
 367                  $this->addRule($w,true);
 368              } catch (Exception $e) {}
 369          }
 370      }
 371  }
 372  ?>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7