Subversion Repositories php_antispam

Rev

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

  1. <?php
  2.  
  3. // This is an example of the ViaThinkSoft AntiSpam 3.02
  4. // for ViaThinkSoft Sigma as filter plugin (modified $content)
  5. // Use it for your website!
  6.  
  7. include __DIR__ . '/../v3.inc.php'; // AntiSpam v3
  8.  
  9. // CONFIGURATION
  10.  
  11. define('CFG_MAKE_MAIL_ADDRESSES_CLICKABLE', true);
  12.  
  13. // CODE
  14.  
  15. function alas_js_crypt($text)
  16. {
  17.         $tmp = '';
  18.         for ($i=0; $i<strlen($text); $i++)
  19.         {
  20.                 $tmp .= 'document.write("&#'.ord(substr($text, $i, 1)).';");';
  21.         }
  22.         return $tmp;
  23. }
  24.  
  25. function secure_email_triv($email)
  26. {
  27.         $aus = '';
  28.         if ($email != '')
  29.         {
  30.                 $aus .= '<script language="JavaScript" type="text/javascript"><!--'."\n";
  31.                 $aus .= alas_js_crypt($email);
  32.                 $aus .= '// --></script>';
  33.         }
  34.         return $aus;
  35. }
  36.  
  37. function getAddrSpec() {
  38.         // Ref: http://www.iamcal.com/publish/articles/php/parsing_email/
  39.  
  40.         $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  41.         $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  42.         $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
  43.                 '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  44.         $quoted_pair = '\\x5c[\\x00-\\x7f]';
  45.         $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
  46.         $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
  47.         $domain_ref = $atom;
  48.         $sub_domain = "($domain_ref|$domain_literal)";
  49.         $word = "($atom|$quoted_string)";
  50.         $domain = "$sub_domain(\\x2e$sub_domain)*";
  51.         $local_part = "$word(\\x2e$word)*";
  52.         $addr_spec = "$local_part\\x40$domain";
  53.  
  54.         return $addr_spec;
  55. }
  56.  
  57. function is_valid_email_address($email){
  58.         $addr_spec = getAddrSpec();
  59.         return preg_match("!^$addr_spec$!", $email) ? true : false;
  60. }
  61.  
  62. function auto_secure_mail_addresses($content) {
  63.         $addr_spec = getAddrSpec();
  64.  
  65.         // Step 1: Parse links and make them secure
  66.  
  67.         $content = preg_replace_callback("/<a(.+?)mailto:($addr_spec)(.+?)>(.+?)<\/a>/sm",
  68.                 function($a) {
  69.                         $mailaddr = $a[2];
  70.                         $linktext = $a[14]; // Letztes
  71.  
  72.                         return secure_email($mailaddr, $linktext, is_valid_email_address($linktext));
  73.                 }, $content); // TODO! Kann Greedy werden!
  74.  
  75.         // Step 2: Find all further mail addresses, make then clickable and prevent spam bots
  76.  
  77.         $content = preg_replace_callback("/($addr_spec)/sm", function($a) {
  78.                         $mailaddr = $a[1]; // Letztes
  79.  
  80.                         if (CFG_MAKE_MAIL_ADDRESSES_CLICKABLE) {
  81.                                 return secure_email($mailaddr, $mailaddr, true);
  82.                         } else {
  83.                                 return secure_email_triv($mailaddr);
  84.                         }
  85.                 }, $content);
  86.  
  87.         // Output
  88.  
  89.         return $content;
  90. }
  91.  
  92. if (isset($content)) {
  93.         $content = auto_secure_mail_addresses($content);
  94. }
  95.