Subversion Repositories php_antispam

Rev

Rev 2 | Rev 5 | Go to most recent revision | Details | Compare with Previous | 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
 
3 daniel-mar 6
if (!function_exists('alas_js_crypt'))
2 daniel-mar 7
{
3 daniel-mar 8
        function alas_js_crypt($text)
2 daniel-mar 9
        {
3 daniel-mar 10
                $tmp = '';
11
                for ($i=0; $i<strlen($text); $i++)
2 daniel-mar 12
                {
3 daniel-mar 13
                        $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
2 daniel-mar 14
                }
3 daniel-mar 15
                return $tmp;
2 daniel-mar 16
        }
3 daniel-mar 17
}
2 daniel-mar 18
 
3 daniel-mar 19
if (!function_exists('alas_js_write'))
20
{
21
        function alas_js_write($text)
2 daniel-mar 22
        {
3 daniel-mar 23
                $text = str_replace('\\', '\\\\', $text);
24
                $text = str_replace('"', '\"', $text);
25
                $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
26
                return 'document.write("'.$text.'");';
2 daniel-mar 27
        }
3 daniel-mar 28
}
2 daniel-mar 29
 
3 daniel-mar 30
function secure_email($email, $linktext, $crypt_linktext)
31
{
32
        // No new lines to avoid a JavaScript error!
33
        $linktext = str_replace("\r", ' ', $linktext);
34
        $linktext = str_replace("\n", ' ', $linktext);
35
 
2 daniel-mar 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
}