1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Antispam, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 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 ----------------------------------------- |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | class 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('/^(.*\.)([^.]+\.[^.]+)$/','$2',$b['host']); |
---|
47 | $host = $domain.'.'.$this->server; |
---|
48 | |
---|
49 | if (gethostbyname($host) != $host) { |
---|
50 | $status = substr($domain,0,128); |
---|
51 | return true; |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | private function getLinks($text) |
---|
57 | { |
---|
58 | $res = array(); |
---|
59 | |
---|
60 | # href attribute on "a" tags |
---|
61 | if (preg_match_all('/<a ([^>]+)>/ms', $text, $match, PREG_SET_ORDER)) |
---|
62 | { |
---|
63 | for ($i = 0; $i<count($match); $i++) |
---|
64 | { |
---|
65 | if (preg_match('/href="(http:\/\/[^"]+)"/ms', $match[$i][1], $matches)) { |
---|
66 | $res[] = $matches[1]; |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | return $res; |
---|
72 | } |
---|
73 | } |
---|
74 | ?> |
---|