Rev 5 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | Rev 6 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | 2 | ||
3 | // This is an example of the ViaThinkSoft AntiSpam 3.02 |
3 | // This is an example of the ViaThinkSoft AntiSpam 3.02 |
4 | // for ViaThinkSoft Sigma as filter plugin (modified $content) |
4 | // for ViaThinkSoft Sigma as filter plugin (modified $content) |
5 | // Use it for your website! |
5 | // Use it for your website! |
6 | 6 | ||
- | 7 | include __DIR__ . '/../v3.inc.php'; // AntiSpam v3 |
|
- | 8 | ||
7 | // CONFIGURATION |
9 | // CONFIGURATION |
8 | 10 | ||
9 | define('CFG_MAKE_MAIL_ADDRESSES_CLICKABLE', true); |
11 | define('CFG_MAKE_MAIL_ADDRESSES_CLICKABLE', true); |
10 | 12 | ||
11 | // CODE |
13 | // CODE |
12 | 14 | ||
13 | function secure_email_triv($email) |
- | |
14 | { |
- | |
15 | if (!function_exists('alas_js_crypt')) |
- | |
16 | { |
- | |
17 | function alas_js_crypt($text) |
15 | function alas_js_crypt($text) |
18 | { |
16 | { |
19 | $tmp = ''; |
17 | $tmp = ''; |
20 | for ($i=0; $i<strlen($text); $i++) |
18 | for ($i=0; $i<strlen($text); $i++) |
21 | { |
19 | { |
22 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
20 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
23 | } |
21 | } |
24 | return $tmp; |
22 | return $tmp; |
25 | } |
23 | } |
26 | } |
- | |
27 | 24 | ||
- | 25 | function secure_email_triv($email) |
|
- | 26 | { |
|
28 | $aus = ''; |
27 | $aus = ''; |
29 | if ($email != '') |
28 | if ($email != '') |
30 | { |
29 | { |
31 | $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n"; |
30 | $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n"; |
32 | $aus .= alas_js_crypt($email); |
31 | $aus .= alas_js_crypt($email); |
33 | $aus .= '// --></script>'; |
32 | $aus .= '// --></script>'; |
34 | } |
33 | } |
35 | return $aus; |
34 | return $aus; |
36 | } |
35 | } |
37 | 36 | ||
38 | // PHP-AntiSpam-Funktion "secure_email", Version 3.02 |
- | |
39 | // von Daniel Marschall [www.daniel-marschall.de] |
- | |
40 | - | ||
41 | function secure_email($email, $linktext, $crypt_linktext) |
- | |
42 | { |
- | |
43 | // No new lines to avoid a JavaScript error! |
- | |
44 | $linktext = str_replace("\r", ' ', $linktext); |
- | |
45 | $linktext = str_replace("\n", ' ', $linktext); |
- | |
46 | - | ||
47 | if (!function_exists('alas_js_crypt')) |
- | |
48 | { |
- | |
49 | function alas_js_crypt($text) |
- | |
50 | { |
- | |
51 | $tmp = ''; |
- | |
52 | for ($i=0; $i<strlen($text); $i++) |
- | |
53 | { |
- | |
54 | $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");'; |
- | |
55 | } |
- | |
56 | return $tmp; |
- | |
57 | } |
- | |
58 | } |
- | |
59 | - | ||
60 | if (!function_exists('alas_js_write')) |
- | |
61 | { |
- | |
62 | function alas_js_write($text) |
- | |
63 | { |
- | |
64 | $text = str_replace('\\', '\\\\', $text); |
- | |
65 | $text = str_replace('"', '\"', $text); |
- | |
66 | $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a> |
- | |
67 | return 'document.write("'.$text.'");'; |
- | |
68 | } |
- | |
69 | } |
- | |
70 | - | ||
71 | $aus = ''; |
- | |
72 | if ($email != '') |
- | |
73 | { |
- | |
74 | $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n"; |
- | |
75 | $aus .= alas_js_write('<a href="'); |
- | |
76 | $aus .= alas_js_crypt('mailto:'.$email); |
- | |
77 | $aus .= alas_js_write('">'); |
- | |
78 | $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext); |
- | |
79 | $aus .= alas_js_write('</a>').'// --></script>'; |
- | |
80 | } |
- | |
81 | return $aus; |
- | |
82 | } |
- | |
83 | - | ||
84 | function getAddrSpec() { |
37 | function getAddrSpec() { |
85 | // Ref: http://www.iamcal.com/publish/articles/php/parsing_email/ |
38 | // Ref: http://www.iamcal.com/publish/articles/php/parsing_email/ |
86 | 39 | ||
87 | $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; |
40 | $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; |
88 | $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; |
41 | $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; |
Line 109... | Line 62... | ||
109 | function auto_secure_mail_addresses($content) { |
62 | function auto_secure_mail_addresses($content) { |
110 | $addr_spec = getAddrSpec(); |
63 | $addr_spec = getAddrSpec(); |
111 | 64 | ||
112 | // Step 1: Parse links and make them secure |
65 | // Step 1: Parse links and make them secure |
113 | 66 | ||
114 | if (!function_exists('link_cb_1')) { |
67 | $content = preg_replace_callback("/<a(.+?)mailto:($addr_spec)(.+?)>(.+?)<\/a>/sm", |
115 | function link_cb_1($a) { |
68 | function($a) { |
116 | $mailaddr = $a[2]; |
69 | $mailaddr = $a[2]; |
117 | $linktext = $a[14]; // Letztes |
70 | $linktext = $a[14]; // Letztes |
118 | 71 | ||
119 | return secure_email($mailaddr, $linktext, is_valid_email_address($linktext)); |
72 | return secure_email($mailaddr, $linktext, is_valid_email_address($linktext)); |
120 | } |
- | |
121 | } |
- | |
122 | - | ||
123 | $content = preg_replace_callback("/<a(.+?)mailto:($addr_spec)(.+?)>(.+?)<\/a>/sm", 'link_cb_1', $content); // TODO! Kann Greedy werden! |
73 | }, $content); // TODO! Kann Greedy werden! |
124 | 74 | ||
125 | // Step 2: Find all further mail addresses, make then clickable and prevent spam bots |
75 | // Step 2: Find all further mail addresses, make then clickable and prevent spam bots |
126 | 76 | ||
127 | if (!function_exists('link_cb_2')) { |
77 | $content = preg_replace_callback("/($addr_spec)/sm", function($a) { |
128 | function link_cb_2($a) { |
- | |
129 | $mailaddr = $a[1]; // Letztes |
78 | $mailaddr = $a[1]; // Letztes |
130 | 79 | ||
131 | if (CFG_MAKE_MAIL_ADDRESSES_CLICKABLE) { |
80 | if (CFG_MAKE_MAIL_ADDRESSES_CLICKABLE) { |
132 | return secure_email($mailaddr, $mailaddr, true); |
81 | return secure_email($mailaddr, $mailaddr, true); |
133 | } else { |
82 | } else { |
134 | return secure_email_triv($mailaddr); |
83 | return secure_email_triv($mailaddr); |
135 | } |
84 | } |
136 | } |
85 | }, $content); |
137 | } |
- | |
138 | - | ||
139 | $content = preg_replace_callback("/($addr_spec)/sm", 'link_cb_2', $content); |
- | |
140 | 86 | ||
141 | // Output |
87 | // Output |
142 | 88 | ||
143 | return $content; |
89 | return $content; |
144 | } |
90 | } |
145 | 91 | ||
- | 92 | if (isset($content)) { |
|
146 | $content = auto_secure_mail_addresses($content); |
93 | $content = auto_secure_mail_addresses($content); |
- | 94 | } |