Subversion Repositories php_antispam

Rev

Rev 5 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
// PHP-AntiSpam-Funktion "secure_email", Version 3.06 of 2022-01-09
3
// PHP-AntiSpam-Funktion "secure_email", Version 3.1 of 2022-01-09
4
// by Daniel Marschall [www.daniel-marschall.de], ViaThinkSoft
4
// by Daniel Marschall [www.daniel-marschall.de], ViaThinkSoft
5
// License: Apache 2.0 License
5
// License: Apache 2.0 License
6
 
6
 
7
if (!function_exists('alas_js_crypt'))
7
class VtsAntiSpam3 {
8
{
8
 
9
        function alas_js_crypt($text)
9
        private function alas_js_crypt($text)
10
        {
10
        {
11
                $tmp = '';
11
                $tmp = '';
12
                for ($i=0; $i<strlen($text); $i++)
12
                for ($i=0; $i<strlen($text); $i++)
13
                {
13
                {
14
                        $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
14
                        $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
15
                }
15
                }
16
                return $tmp;
16
                return $tmp;
17
        }
17
        }
18
}
-
 
19
 
18
 
20
if (!function_exists('alas_js_write'))
-
 
21
{
-
 
22
        function alas_js_write($text)
19
        private function alas_js_write($text)
23
        {
20
        {
24
                $text = str_replace('\\', '\\\\', $text);
21
                $text = str_replace('\\', '\\\\', $text);
25
                $text = str_replace('"', '\"', $text);
22
                $text = str_replace('"', '\"', $text);
26
                $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
23
                $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
27
                return 'document.write("'.$text.'");';
24
                return 'document.write("'.$text.'");';
28
        }
25
        }
29
}
-
 
30
 
26
 
31
function secure_email($email, $linktext, $crypt_linktext, $css_class='')
27
        public function secure_email($email, $linktext, $crypt_linktext, $css_class='')
32
{
28
        {
33
        // No new lines to avoid a JavaScript error!
29
                // No new lines to avoid a JavaScript error!
34
        $linktext = str_replace("\r", ' ', $linktext);
30
                $linktext = str_replace("\r", ' ', $linktext);
35
        $linktext = str_replace("\n", ' ', $linktext);
31
                $linktext = str_replace("\n", ' ', $linktext);
36
 
32
 
37
        $aus = '';
33
                $aus = '';
38
        if ($email != '')
34
                if ($email != '')
39
        {
35
                {
40
                $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5
36
                        $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5
41
                $aus .= alas_js_write('<a ');
37
                        $aus .= $this->alas_js_write('<a ');
42
                if ($css_class != '') $aus .= alas_js_write('class="'.$css_class.'" ');
38
                        if ($css_class != '') $aus .= $this->alas_js_write('class="'.$css_class.'" ');
43
                $aus .= alas_js_write('href="');
39
                        $aus .= $this->alas_js_write('href="');
44
                $aus .= alas_js_crypt('mailto:'.$email);
40
                        $aus .= $this->alas_js_crypt('mailto:'.$email);
45
                $aus .= alas_js_write('">');
41
                        $aus .= $this->alas_js_write('">');
46
                $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext);
42
                        $aus .= $crypt_linktext ? $this->alas_js_crypt($linktext) : $this->alas_js_write($linktext);
47
                $aus .= alas_js_write('</a>').'// --></script>';
43
                        $aus .= $this->alas_js_write('</a>').'// --></script>';
48
        }
44
                }
49
 
45
 
50
        return $aus.'<noscript>Please enable JavaScript to display this email address.</noscript>';
46
                return $aus.'<noscript>Please enable JavaScript to display this email address.</noscript>';
51
}
47
        }
-
 
48
 
-
 
49
}
-
 
50
 
-
 
51
# ------------------------------------------------------------------------------
-
 
52
 
-
 
53
function secure_email($email, $linktext, $crypt_linktext, $css_class='') {
-
 
54
        $antispam = new VtsAntiSpam3();
-
 
55
        $res = $antispam->secure_email($email, $linktext, $crypt_linktext);
-
 
56
        return $res;
-
 
57
}
-
 
58