Subversion Repositories php_antispam

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 daniel-mar 1
<?php
2
 
3
// PHP-AntiSpam-Funktion "secure_email", Version 3.06 of 2022-01-09
4
// by Daniel Marschall [www.daniel-marschall.de], ViaThinkSoft
5
// License: Apache 2.0 License
6
 
7
if (!function_exists('alas_js_crypt'))
8
{
9
        function alas_js_crypt($text)
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
}
19
 
20
if (!function_exists('alas_js_write'))
21
{
22
        function alas_js_write($text)
23
        {
24
                $text = str_replace('\\', '\\\\', $text);
25
                $text = str_replace('"', '\"', $text);
26
                $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
27
                return 'document.write("'.$text.'");';
28
        }
29
}
30
 
31
function secure_email($email, $linktext, $crypt_linktext, $css_class='')
32
{
33
        // No new lines to avoid a JavaScript error!
34
        $linktext = str_replace("\r", ' ', $linktext);
35
        $linktext = str_replace("\n", ' ', $linktext);
36
 
37
        $aus = '';
38
        if ($email != '')
39
        {
40
                $aus .= '<script><!--'."\n"; // type="text/javascript" is not necessary in HTML5
41
                $aus .= alas_js_write('<a ');
42
                if ($css_class != '') $aus .= alas_js_write('class="'.$css_class.'" ');
43
                $aus .= alas_js_write('href="');
44
                $aus .= alas_js_crypt('mailto:'.$email);
45
                $aus .= alas_js_write('">');
46
                $aus .= $crypt_linktext ? alas_js_crypt($linktext) : alas_js_write($linktext);
47
                $aus .= alas_js_write('</a>').'// --></script>';
48
        }
49
 
50
        return $aus.'<noscript>Please enable JavaScript to display this email address.</noscript>';
3 daniel-mar 51
}