GDPR privacy disclaimer
This form will send me your email address and your IP address.
If you don't want that, don't use this form!
Hide your email address on CMSMS web pages
Previous article Next articleA prefilter file that will automaticly hide an email address at your CMS Made Simple™ site from email harvesting bots that scrap webpages, looking for email addresses.
This method is based on the protect_email prefilter posted in the CMSMS forum by Jean le Chauve.
It converts:
<a href="mailto:you@website.com?subject=Test">Send Mail</a>
<a class="test" href="mailto:you@website.com">Test</a>
<a href="mailto:You@Website.com" class="test">you@website.com</a>
you@website.com
into something like:
It doesn't convert excisting mailto Smarty tags:
How to use
Create a file named prefilter.hash_email.php and store it in the CMSMS [root_url]/assets/plugins/ folder.
The content of the file is:
/**
* -----------------------------------------------------------------------------
* https://www.cmscanbesimple.org/blog/hide-your-email-address-on-cmsms-web-pages
* File: prefilter.hash_email.php
* Type: prefilter
* Purpose: Automaticly hide email addresses found in the content
* -----------------------------------------------------------------------------
*/
function smarty_prefilter_hash_email($tpl_output, $smarty)
{
$result = explode(':', $smarty->_current_file);
if (count($result) > 0)
{
if ($result[0] != 'cms_stylesheet' AND $result[0] != 'stylesheet')
{
$patterns = array ('#<a.+href\s*=\s*["\']mailto:\s*([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})\b\??[^"\']*["\'][^>]*>([^<]+)</a>#iU',
'#([a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4})\b(?!\?|&|"|\'])#iU');
$replace = array ('{mailto address="$1" text="$2" encode="javascript"}',
'{mailto address="$0" text="$0" encode="javascript"}');
$tpl_output = preg_replace($patterns, $replace, $tpl_output);
}
}
return $tpl_output;
}
?>
Comment Form
ReviewManager
ReviewManager
3 Comments
Fixed: PHP Warning: Parameter 2 to smarty_prefilter_hash_email() expected to be a reference, value given in /home/.../public_html/www.website.com/lib/smarty/sysplugins/smarty_internal_runtime_filterhandler.php on line 57
Sadly it a small bug in core, introduced during the beta cycle.
You are the first one noticing it (just after release 2.2.2...)
Anyway fixed in SVN.
Will see if I can create a work around for this tutorial!
Does this no longer work as of cmsms version 2.2.x? Emails seem to be plain text after upgrading to 2.2.x. Thanks!