//:Emailfiltering on your output - output filtering with the options below - Mailto links can be encrypted by a Javascript //:usage: [[EmailFilter]] // You can configure the output filtering with the options below. // Tip: Mailto links can be encrypted by a Javascript function. // To make use of this option, one needs to add the PHP code // register_frontend_modfiles('js'); // into the
section of the index.php of your template. // Without this modification, only the @ character in the mailto part will be replaced. // Basic Email Configuration: // Filter Email addresses in text 0 = no, 1 = yes - default 1 $filter_settings['email_filter'] = '1'; // Filter Email addresses in mailto links 0 = no, 1 = yes - default 1 $filter_settings['mailto_filter'] = '1'; // Email Replacements, replace the '@' and the '.' by default (at) and (dot) $filter_settings['at_replacement'] = '(at)'; $filter_settings['dot_replacement'] = '(dot)'; // No need to change stuff underneatch unless you know what you are doing. // work out the defined output filter mode: possible output filter modes: [0], 1, 2, 3, 6, 7 // 2^0 * (0.. disable, 1.. enable) filtering of mail addresses in text // 2^1 * (0.. disable, 1.. enable) filtering of mail addresses in mailto links // 2^2 * (0.. disable, 1.. enable) Javascript mailto encryption (only if mailto filtering enabled) // only filter output if we are supposed to if($filter_settings['email_filter'] != '1' && $filter_settings['mailto_filter'] != '1'){ // nothing to do ... return true; } // check if non mailto mail addresses needs to be filtered $output_filter_mode = ($filter_settings['email_filter'] == '1') ? 1 : 0; // 0|1 // check if mailto mail addresses needs to be filtered if($filter_settings['mailto_filter'] == '1') { $output_filter_mode = $output_filter_mode + 2; // 0|2 // check if Javascript mailto encryption is enabled (call register_frontend_functions in the template) $search_pattern = '/<.*src=\".*\/mdcr.js.*>/iU'; if(preg_match($search_pattern, $wb_page_data)) { $output_filter_mode = $output_filter_mode + 4; // 0|4 } } // define some constants so we do not call the database in the callback function again define('OUTPUT_FILTER_MODE', (int) $output_filter_mode); define('OUTPUT_FILTER_AT_REPLACEMENT', $filter_settings['at_replacement']); define('OUTPUT_FILTER_DOT_REPLACEMENT', $filter_settings['dot_replacement']); // function to filter mail addresses embedded in text or mailto links before outputing them on the frontend if (!function_exists('filter_mail_addresses')) { function filter_mail_addresses($match) { // check if required output filter mode is defined if(!(defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE') && defined('OUTPUT_FILTER_MODE'))) { return $match[0]; } $search = array('@', '.'); $replace = array(OUTPUT_FILTER_AT_REPLACEMENT ,OUTPUT_FILTER_DOT_REPLACEMENT); // check if the match contains the expected number of subpatterns (6|8) if(count($match) == 8) { /** OUTPUT FILTER FOR EMAIL ADDRESSES EMBEDDED IN TEXT **/ // 1.. text mails only, 3.. text mails + mailto (no JS), 7 text mails + mailto (JS) if(!in_array(OUTPUT_FILTER_MODE, array(1,3,7))) return $match[0]; // do not filter mail addresses included in input tags ( -1; $i--) { if(preg_match('#[FZXK0-9]#', $email_address[$i], $characters)) { $encrypted_email .= $email_address[$i]; } else { $encrypted_email .= chr((ord($email_address[$i]) -97 + $shift) % 26 + 97); } } $encrypted_email .= chr($shift + 97); // build the encrypted Javascript mailto link $mailto_link = "" .$match[5] .""; return $mailto_link; } else { /** DO NOT USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/ // as minimum protection, replace replace @ in the mailto part by (at) // dots are not transformed as this would transform my.name@domain.com into: my(dot)name(at)domain(dot)com // rebuild the mailto link from the subpatterns (at the missing characters " and ") return $match[1] .str_replace('@', OUTPUT_FILTER_AT_REPLACEMENT, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .''; // if you want to protect both, @ and dots, comment out the line above and remove the comment from the line below // return $match[1] .str_replace($search, $replace, $match[2]) .$match[3] .'"' .$match[4] .$match[5] .''; } } // number of subpatterns do not match the requirements ... do nothing return $match[0]; } } // first search part to find all mailto email addresses $pattern = '#(]*>)(.*?)'; // second part to find all non mailto email addresses $pattern .= '|(value\s*=\s*"|\')??\b([A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4})\b#i'; // Sub 1:\b(