I manage a site based on XOOPS and one of my users was concerned about the potential for email addresses to be harvested. I've since introduced a hack to convert email addresses into images on the fly. This works both for tagged emails in articles and for the emails displayed in the user's profile. For an example
check this link.Basically there are four elements to this hack.
1. a php script to generate the image
2. an update to module.textsanitiser.php
3. an update to userinfo.php
4. an update to the userinfo template
The image generation script is pretty rough. I'm not a professional and I make no promises as to how well this might work for you. I called it swirl.php and put it in the include folder.
/* script adapted by Rob Stockley from example published at
* http://nz2.php.net/manual/en/function.imagestring.php
* by brooks dot boyd at gmail dot com
*/
if (($_GET['l1'] != "")&&($_GET['l2'] != "")) {
$msg = $_GET['l1'].'@'.$_GET['l2'];
// you need to make sure this font file exists
$font = '/usr/share/fonts/truetype/ttf-bitstream-vera/VeraMono.ttf';
if ($_GET['l3'] != "") {
$size = $_GET['l3'];
if ($size > 16) $size = 16;
if ($size < 8) $size = 8;
} else {
$size = 8;
}
// top, right, bottom, left
$padding = array($size/2, 2, $size/2, 2);
$textbox = imageTTFBbox($size, 0, $font, $msg);
$textwidth = abs($textbox[4] - $textbox[0]);
$totalwidth = $textwidth + $padding[1] + $padding[3];
$textheight = abs($textbox[5] - $textbox[1]);
$totalheight = $textheight + $padding[0] + $padding[2];
if ($textbox[1] > $textbox[3]) {
$textorigin = array($padding[3], ($totalheight - $padding[2] - $textbox[1]));
} else {
$textorigin = array($padding[3], ($totalheight - $padding[2] - $textbox[3]));
}
$im = imagecreatetruecolor($totalwidth,$totalheight);
imagealphablending($im, FALSE);
imagesavealpha($im, TRUE);
// Create some colors
$white = imagecolorallocatealpha($im, 255, 255, 255, 100);
$grey = imagecolorallocatealpha($im, 128, 128, 128, 100);
$black = imagecolorallocatealpha($im, 0, 0, 0, 0);
// Add the text with a shadow
imagefilledrectangle ($im, 0, 0, $totalwidth, $totalheight, $white); # Make transparent
imagettftext($im, $size, 0, $textorigin[0]+1, $textorigin[1]+1, $grey, $font, $msg);
imagettftext($im, $size, 0, $textorigin[0], $textorigin[1], $black, $font, $msg);
// create a blank image to copy into
$dest = imagecreatetruecolor($totalwidth,$totalheight);
imagealphablending($dest, FALSE);
imagesavealpha($dest, TRUE);
imagefilledrectangle ($dest, 0, 0, $totalwidth, $totalheight, $white); # Make transparent
// make it wavy
$yperiod = $size*3;
$yamp = min($padding[0], $padding[2])-1;
for ($i = 1; $i < $totalwidth; $i++) {
imagecopy($dest, $im, $i, $off, $i, 0, 1, $totalheight);
$off = sin($i/$yperiod)*$yamp;
}
} else {
$im = imagecreatetruecolor(1,1);
imagealphablending($im, FALSE);
imagesavealpha($im, TRUE);
$bg = imagecolorallocatealpha($im, 255, 0, 0, 125);
imagefilledrectangle ($im, 0, 0, 1, 1, $bg); # Make transparent
}
header('Content-type: image/jpg');
imagepng($dest);
imagedestroy($im);
imagedestroy($dest);
?>
Next I modified module.textsanitiser.php to tie in the email tags. I haven't modified the textbox to include font size though. Users can add that manually if required. The default size 8 works well on my site.
// The following changed by Rob Stockley to include image emails
//$patterns[] = "/[email]([^;<>*()"']*)[/email]/sU";
//$replacements[] = '\1';
$patterns[] = "/[email]([^;<>*()"'@]*)@([^;<>*()"'@]*)[/email]/sU";
$replacements[] = '
/include/swirl.php?l1=\1&l2=\2">';
$patterns[] = "/[email=(['"]?)([0-9]*)\1]([^;<>*()"'@]*)@([^;<>*()"'@]*)[/email]/sU";
$replacements[] = '
.XOOPS_URL.'/include/swirl.php?l1=\3&l2=\4&l3=\2">';
Next I had to modify userinfo.php. I chose to add a new smarty tag user_email_img to the template rather than delete teh existing code for emails. This way I can roll back the change (if required) simply by updating the template.
// added by Rob 25 May 07 to incorporate image emails
list($e_name, $e_domain) = explode("@", $thisUser->getVar('email'));
$e_img = '
.XOOPS_URL.'/include/swirl.php?l1='.$e_name.'&l2='.$e_domain.'">';
if ($thisUser->getVar('user_viewemail') == 1) {
$xoopsTpl->assign('user_email', $thisUser->getVar('email', 'E'));
$xoopsTpl->assign('user_email_img', $e_img); //added by Rob
} else {
if (is_object($xoopsUser)) {
// All admins will be allowed to see emails, even those that are not allowed to edit users (I think it's ok like this)
if ($xoopsUserIsAdmin || ($xoopsUser->getVar("uid") == $thisUser->getVar("uid"))) {
$xoopsTpl->assign('user_email', $thisUser->getVar('email', 'E'));
$xoopsTpl->assign('user_email_img', $e_img); // added by Rob
} else {
$xoopsTpl->assign('user_email', ' ');
$xoopsTpl->assign('user_email_img', ' '); //added by Rob
}
}
}
The last change was done through the XOOPS site admin pages. Under the system templates I editted system_userinfo.html and switched to the new user_email_img tag about half way down.
I know this approach is not bullet proof but it has satisfied my users for the moment. I hope someone else finds it of use.
Rob