Dotclear

source: plugins/antispam/filters/class.dc.filter.linkslookup.php @ 1366:e0577ae710f5

Revision 1366:e0577ae710f5, 1.7 KB checked in by Pascal Chevrel <pascal.chevrel@…>, 12 years ago (diff)

Ticket #1526 : antispam, extract https links from comments

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Antispam, a plugin for Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13
14class dcFilterLinksLookup extends dcSpamFilter
15{
16     public $name = 'Links Lookup';
17     
18     private $server = 'multi.surbl.org';
19     
20     protected function setInfo()
21     {
22          $this->description = __('Checks links in comments against surbl.org');
23     }
24     
25     public function getStatusMessage($status,$comment_id)
26     {
27          return sprintf(__('Filtered by %1$s with server %2$s.'),$this->guiLink(),$status);
28     }
29     
30     public function isSpam($type,$author,$email,$site,$ip,$content,$post_id,&$status)
31     {
32          if (!$ip || long2ip(ip2long($ip)) != $ip) {
33               return;
34          }
35         
36          $urls = $this->getLinks($content);
37          array_unshift($urls,$site);
38         
39          foreach ($urls as $u)
40          {
41               $b = parse_url($u);
42               if (!isset($b['host']) || !$b['host']) {
43                    continue;
44               }
45
46               $domain = preg_replace('/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/','$1',$b['host']);
47               $domain_elem = explode(".",$domain);
48
49               $i = count($domain_elem) - 1;
50               $host = $domain_elem[$i];
51               do
52               {
53                    $host = $domain_elem[$i - 1].'.'.$host;
54                    $i--;
55                    if (substr(gethostbyname($host.'.'.$this->server),0,3) == "127" ) 
56                    {
57                         $status = substr($domain,0,128);
58                         return true;
59                    }                   
60               } while ($i > 0);
61          }
62     }
63     
64     private function getLinks($text)
65     {
66          // href attribute on "a" tags is second match
67          preg_match_all('|<a.*?href="(http.*?)"|', $text, $parts);
68
69          return $parts[1];
70     }
71}
72?>
Note: See TracBrowser for help on using the repository browser.

Sites map