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