Here's yet another way to obfuscate emails. Setting aside the question of whether it works and how long it might work, on this particular site we wanted the site-wide but weak protection that this provides. Most of the existing obfuscation techniques are parts of modules, but here the more reliable (and potentially efficient?) mechanism is to do all your obfuscation at once at the theme level. In this case, the emails were being exposed by the civicrm module in the profiles.
So here it is in two parts:
1. In the template.php file, add these two functions:
function _phptemplate_encode_mailto($mail) {
$link = 'document.write(\'' . $mail . '\');';
$js_encode = ''; for ($x = 0; $x < strlen($link); $x++) {
$js_encode .= '%' . bin2hex($link{$x});
}
$link = '
eval(unescape(\''.$js_encode.'\'))
';
$link .= ''.str_replace(array('@','.'),array(' at ',' dot '),$mail). '';
return $link;
}
function phptemplate_safemail($text) {
if (strpos($text, '@') === FALSE)
return $text;
// Split at and so that we can avoid encoding addresses in link text.
$t = preg_replace(":(
$a = explode("\001", $t);
$n = count($a);
for ($i = 0; $i < $n; ++$i) {
if (preg_match('/^(]*)mailto:([^@]+@[-.a-z0-9]+)(.*)/i', $a[$i], $m)) {