Dotclear

source: plugins/antispam/filters/class.dc.filter.linkslookup.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 1.9 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

Line 
1<?php
2/**
3 * @brief antispam, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
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            $b = parse_url($u);
41            if (!isset($b['host']) || !$b['host']) {
42                continue;
43            }
44
45            $domain      = preg_replace('/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/', '$1', $b['host']);
46            $domain_elem = explode(".", $domain);
47
48            $i = count($domain_elem) - 1;
49            if ($i == 0) {
50                // "domain" is 1 word long, don't check it
51                return;
52            }
53            $host = $domain_elem[$i];
54            do {
55                $host = $domain_elem[$i - 1] . '.' . $host;
56                $i--;
57                if (substr(gethostbyname($host . '.' . $this->server), 0, 3) == "127") {
58                    $status = substr($domain, 0, 128);
59                    return true;
60                }
61            } while ($i > 0);
62        }
63    }
64
65    private function getLinks($text)
66    {
67        // href attribute on "a" tags is second match
68        preg_match_all('|<a.*?href="(http.*?)"|', $text, $parts);
69
70        return $parts[1];
71    }
72}
Note: See TracBrowser for help on using the repository browser.

Sites map