Subversion Repositories php_antispam

Rev

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

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