# HG changeset patch # User Dan # Date 1183736750 14400 # Node ID fc9762553a3c1fe62235ae66df7c1709ef0f254a # Parent d6361ccbd2bd1dbab1559c189f5f2e2261cda977 E-mail address mask engine non-Javascript fallback now picks random substitutions for @ and . to make address more unreadable by bots diff -r d6361ccbd2bd -r fc9762553a3c includes/email.php --- a/includes/email.php Fri Jul 06 11:04:38 2007 -0400 +++ b/includes/email.php Fri Jul 06 11:45:50 2007 -0400 @@ -595,7 +595,19 @@ function mask_address($email) { - return str_replace('.', ' ', str_replace('@', ' ', $email)); + $at = array(' (AT) ', ' __AT__ ', ' *AT* ', ' [AT] ', ' ', ' <__AT__> '); + $dot = array(' (DOT) ', ' __DOT__ ', ' *DOT* ', ' [DOT] ', ' ', ' <__DOT__> '); + while(strstr($email, '@')) + { + $my_at = $at[ array_rand($at) ]; + $email = str_replace_once('@', $my_at, $email); + } + while(strstr($email, '.')) + { + $my_dot = $dot[ array_rand($dot) ]; + $email = str_replace_once('.', $my_dot, $email); + } + return $email; } /** diff -r d6361ccbd2bd -r fc9762553a3c includes/functions.php --- a/includes/functions.php Fri Jul 06 11:04:38 2007 -0400 +++ b/includes/functions.php Fri Jul 06 11:45:50 2007 -0400 @@ -2298,6 +2298,31 @@ return false; } +/** + * Replaces the FIRST given occurrence of needle within haystack with thread + * @param string Needle + * @param string Thread + * @param string Haystack + */ + +function str_replace_once($needle, $thread, $haystack) +{ + $needle_len = strlen($needle); + for ( $i = 0; $i < strlen($haystack); $i++ ) + { + $test = substr($haystack, $i, $needle_len); + if ( $test == $needle ) + { + // Got it! + $upto = substr($haystack, 0, $i); + $from = substr($haystack, ( $i + $needle_len )); + $new_haystack = "{$upto}{$thread}{$from}"; + return $new_haystack; + } + } + return $haystack; +} + //die('
Original:  01010101010100101010100101010101011010'."\nProcessed: ".uncompress_bitfield(compress_bitfield('01010101010100101010100101010101011010')).'
'); ?>