Hide your email address on CMSMS web pages

  Previous article Next article  

Hide your email address on CMSMS web pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.3
  Last updated: 30-05-2016
  Comments: 2

A 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=Hello%20friend'>Send Mail</a>
<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:

<script type="text/javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%79%6f%75%40%77%65%62%73%69%74%65%2e%63%6f%6d%22%20%3e%53%6d%61%72%74%79%20%74%61%67%3c%2f%61%3e%27%29%3b'))</script>

It doesn't convert excisting mailto Smarty tags:

{mailto address='you@website.com' text='Smarty tag' encode='javascript'}

A2 Webhosting CMS Made Simple

  How to use

Create a file named prefilter.hash_email.php and store it in the CMSMS [root_url]/plugins/ folder.
The content of the file is:

<?php
/**
 * -----------------------------------------------------------------------------
 * http://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;      
}
?>

A2 Webhosting CMS Made Simple

  Comments

  Click here to leave a comment






This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)
  « Enter the CAPTCHA code (lower case)

Your IP address will be stored on submit. I reserve the right to change or delete your response without notice!
In case of abuse your IP address will be blocked!


Can I have your attention for a moment?

Did this tutorial help you solving a problem at your (clients) website and it saved you many hours of work? Great!!
Consider buying Rolf a cup of coffee in return! [ Click here ]


  2 Comments

CMS Made Simple 2.2.2 - Tutorials, tips and tricks - CMSMS 2.2.2

Hide your email address on CMSMS web pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1.3
  Last updated: 30-05-2016
  Comments: 2

A2 Webhosting CMS Made Simple