Subversion Repositories php_antispam

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 daniel-mar 1
<?php
2
 
3
// This is an example of the ViaThinkSoft AntiSpam 3.02
4
// for ViaThinkSoft Sigma as filter plugin (modified $content)
5
// Use it for your website!
6
 
6 daniel-mar 7
include __DIR__ . '/../v3.inc.php'; // AntiSpam v3
8
 
5 daniel-mar 9
// CONFIGURATION
10
 
11
define('CFG_MAKE_MAIL_ADDRESSES_CLICKABLE', true);
12
 
13
// CODE
14
 
6 daniel-mar 15
function alas_js_crypt($text)
5 daniel-mar 16
{
6 daniel-mar 17
        $tmp = '';
18
        for ($i=0; $i<strlen($text); $i++)
5 daniel-mar 19
        {
6 daniel-mar 20
                $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
5 daniel-mar 21
        }
6 daniel-mar 22
        return $tmp;
23
}
5 daniel-mar 24
 
6 daniel-mar 25
function secure_email_triv($email)
26
{
5 daniel-mar 27
        $aus = '';
28
        if ($email != '')
29
        {
30
                $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n";
31
                $aus .= alas_js_crypt($email);
32
                $aus .= '// --></script>';
33
        }
34
        return $aus;
35
}
36
 
37
function getAddrSpec() {
38
        // Ref: http://www.iamcal.com/publish/articles/php/parsing_email/
39
 
40
        $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
41
        $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
42
        $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
43
                '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
44
        $quoted_pair = '\\x5c[\\x00-\\x7f]';
45
        $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
46
        $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
47
        $domain_ref = $atom;
48
        $sub_domain = "($domain_ref|$domain_literal)";
49
        $word = "($atom|$quoted_string)";
50
        $domain = "$sub_domain(\\x2e$sub_domain)*";
51
        $local_part = "$word(\\x2e$word)*";
52
        $addr_spec = "$local_part\\x40$domain";
53
 
54
        return $addr_spec;
55
}
56
 
57
function is_valid_email_address($email){
58
        $addr_spec = getAddrSpec();
59
        return preg_match("!^$addr_spec$!", $email) ? true : false;
60
}
61
 
62
function auto_secure_mail_addresses($content) {
63
        $addr_spec = getAddrSpec();
64
 
65
        // Step 1: Parse links and make them secure
66
 
6 daniel-mar 67
        $content = preg_replace_callback("/<a(.+?)mailto:($addr_spec)(.+?)>(.+?)<\/a>/sm",
68
                function($a) {
5 daniel-mar 69
                        $mailaddr = $a[2];
70
                        $linktext = $a[14]; // Letztes
71
 
72
                        return secure_email($mailaddr, $linktext, is_valid_email_address($linktext));
6 daniel-mar 73
                }, $content); // TODO! Kann Greedy werden!
5 daniel-mar 74
 
75
        // Step 2: Find all further mail addresses, make then clickable and prevent spam bots
76
 
6 daniel-mar 77
        $content = preg_replace_callback("/($addr_spec)/sm", function($a) {
5 daniel-mar 78
                        $mailaddr = $a[1]; // Letztes
79
 
80
                        if (CFG_MAKE_MAIL_ADDRESSES_CLICKABLE) {
81
                                return secure_email($mailaddr, $mailaddr, true);
82
                        } else {
83
                                return secure_email_triv($mailaddr);
84
                        }
6 daniel-mar 85
                }, $content);
5 daniel-mar 86
 
87
        // Output
88
 
89
        return $content;
90
}
91
 
6 daniel-mar 92
if (isset($content)) {
93
        $content = auto_secure_mail_addresses($content);
94
}