[ 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.linkslookup.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 dcFilterLinksLookup extends dcSpamFilter
  24  {
  25      public $name = 'Links Lookup';
  26      
  27      private $server = 'multi.surbl.org';
  28      
  29  	protected function setInfo()
  30      {
  31          $this->description = __('Checks links in comments against surbl.org');
  32      }
  33      
  34  	public function getStatusMessage($status,$comment_id)
  35      {
  36          return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status);
  37      }
  38      
  39  	public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
  40      {
  41          if (!$ip || long2ip(ip2long($ip)) != $ip) {
  42              return;
  43          }
  44          
  45          $urls = $this->getLinks($content);
  46          array_unshift($urls,$site);
  47          
  48          foreach ($urls as $u)
  49          {
  50              $b = parse_url($u);
  51              if (!isset($b['host']) || !$b['host']) {
  52                  continue;
  53              }
  54              
  55              $domain = preg_replace('/^(.*\.)([^.]+\.[^.]+)$/','$2',$b['host']);
  56              $host = $domain.'.'.$this->server;
  57              
  58              if (gethostbyname($host) != $host) {
  59                  $status = substr($domain,0,128);
  60                  return true;
  61              }
  62          }
  63      }
  64      
  65  	private function getLinks($text)
  66      {
  67          $res = array();
  68          
  69          # href attribute on "a" tags
  70          if (preg_match_all('/<a ([^>]+)>/ms', $text, $match, PREG_SET_ORDER))
  71          {
  72              for ($i = 0; $i<count($match); $i++)
  73              {
  74                  if (preg_match('/href="(http:\/\/[^"]+)"/ms', $match[$i][1], $matches)) {
  75                      $res[] = $matches[1];
  76                  }
  77              }
  78          }
  79          
  80          return $res;
  81      }
  82  }
  83  ?>


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