Subversion Repositories php_antispam

Rev

Rev 2 | Rev 5 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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. if (!function_exists('alas_js_crypt'))
  7. {
  8.         function alas_js_crypt($text)
  9.         {
  10.                 $tmp = '';
  11.                 for ($i=0; $i<strlen($text); $i++)
  12.                 {
  13.                         $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
  14.                 }
  15.                 return $tmp;
  16.         }
  17. }
  18.  
  19. if (!function_exists('alas_js_write'))
  20. {
  21.         function alas_js_write($text)
  22.         {
  23.                 $text = str_replace('\\', '\\\\', $text);
  24.                 $text = str_replace('"', '\"', $text);
  25.                 $text = str_replace('/', '\/', $text); // W3C Validation </a> -> <\/a>
  26.                 return 'document.write("'.$text.'");';
  27.         }
  28. }
  29.  
  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.  
  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. }
  49.