Subversion Repositories php_antispam

Rev

Rev 5 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. // PHP-AntiSpam-Funktion "secure_email", Version 3.1 of 2022-01-09
  4. // by Daniel Marschall [www.daniel-marschall.de], ViaThinkSoft
  5. // License: Apache 2.0 License
  6.  
  7. class VtsAntiSpam3 {
  8.  
  9.         private 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.         private function alas_js_write($text)
  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.  
  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);
  32.  
  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>';
  47.         }
  48.  
  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.  
  59.