MENU

Hide your email address on CMSMS web pages

  Previous article Next article  

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'}

  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:

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

Buy Me A Coffee


  Comment Form

ReviewManager

Click here to open the form

ReviewManager

  3 Comments

Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Hide your email address on CMSMS web pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.7
  Last updated: 23-06-2018
  Comments: 3
  http://cms.ms/4oRh


Buy Me A Coffee




Advertisement


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!