Page 1 of 1

plugin protect_email

Posted: Fri Aug 10, 2012 8:40 am
by Jean le Chauve
I created a plugin that modifies all email addresses entered by an editor in his equivalent smarty {mailto address="adress@domaine.tld" encode="javascript"}

Code: Select all

<?php
#CMS - CMS Made Simple
#(c)2004 by Ted Kulp (wishy@users.sf.net)
#This project's homepage is: http://www.cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


# Put this file into the 'plugins' directory and name it 'prefilter.protect_email.php'
# The plugin encode all email adresses into javascript
#
# It convert :
# <a href='mailto:someone@example.com?Subject=Hello%20again'> Send Mail</a></p>
# <a href="mailto:chose@bidule.fr?subject=Coucou&cc=cc1@bidule.fr&bcc=cc2@bidule.fr">ici</a></p>
# <a class="test" href="mailto:blabla@truc.com">double</a></p>
# <a href="mailto:BLAbla@truc.com" class="test">test</a>
# seul@domaine.com
#
# It does not convert {mailto address="nom@domaine.com" text="smarty" encode="javascript"}
#
# Requirements : cmsms 1.11 svn 8200+

function smarty_prefilter_protect_email($tpl_output, &$template)
{
	$smarty = $template->smarty;
	$result = explode(':', $smarty->_current_file);
	if (count($result) > 0)
	{
		if( startswith($result[0],'tmp_') ) $result[0] = 'template';
		if ($result[0] == 'content' || $result[0] == 'globalcontent' || $result[0] == 'template' || strlen($result[0]) == '40')
		// evaluated template a disparu depuis cmsms 1.10.3 et a été remplacé par une string de 40 caractères
		// Si un global content block pose problème, vous empêcher le plugin d'y entrer en ajoutant && $result[1] != 'nom du GCB' dans la condition ci-dessus
		{		
			$patterns = array ('#<a.+href=["\']mailto:([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');
			// Vous pouvez remplacer la valeur de text : {mailto address="$1" text="email" encode=javascript}
			// et utiliser d'autres attributs : {mailto address="$1" text="email" encode="hex" subject="Hello to you!"}
			// voir doc smarty : http://www.smarty.net/docs/en/language.function.mailto.tpl
			$replace = array ('{mailto address="$1" text="$2" encode="javascript"}', '{mailto address="$0" text="$1" encode="javascript"}');
			$tpl_output = preg_replace($patterns, $replace, $tpl_output);		
		}
	}	
    return $tpl_output;		
}

function smarty_cms_about_prefilter_protect_email()
{
	?>
	<p>Author: Jean le Chauve< (http://www.cmsmadesimple.fr/forum) ></p>
	<p>Version: 1.0</p>
	<p>
	Change History:<br/>
	None
	</p>
	<?php
}
?>
It seems to do its job, but it is impossible to display help because it does not appear in the list of plugins
/admin/listtags.php line 147 :
if( $rec['type'] == 'prefilter' || $rec['type'] == 'postfilter' ) continue;

Fixed in 1.11.1 Thanks Robert

Re: plugin protect_email

Posted: Fri Aug 24, 2012 10:49 am
by JohnnyB
Thanks Jean!
This is a big help when Editors do not use the smarty {mailto} plugin.

Re: plugin protect_email

Posted: Fri Aug 24, 2012 2:54 pm
by Rolf
Great, thanks!!

Re: plugin protect_email

Posted: Fri Aug 24, 2012 3:19 pm
by manuel
Dear Jean,

nicccce, no matter how many times i explain how to use the "protect e-mail" item in the custom drop down in TinyMCE, nobody seems to remember to use it when they add an e-mail address...

Very useful indeed!

Greetings,
Manuel

Re: plugin protect_email

Posted: Tue Aug 28, 2012 8:22 am
by Jean le Chauve
Thanks for your comments
for cmsms 1.10.3 - :
prefilter.protect_email.zip
(1.61 KiB) Downloaded 426 times
for 1.11.1+
1.11.prefilter.protect_email.zip
(1.68 KiB) Downloaded 459 times

Re: plugin protect_email

Posted: Wed Nov 07, 2012 10:13 pm
by manuel
Dear Jean,

I seem to notice that e-mail addresses entered in the Listit2, Gallery or MCFactory generated modules don't get the special treatment.
The news module content however does get processed correctly...

Greetings,
Manuel

Re: plugin protect_email

Posted: Thu Nov 08, 2012 2:08 am
by Jean le Chauve
Dear Manuel,

Perhaps you need evaluate the input :
{eval var=$item->fielddefs.yourInput.value} (listit)
{eval var=$image->comment} (Gallery)

Re: plugin protect_email

Posted: Thu Nov 08, 2012 3:38 pm
by manuel
Dear Jean,

Spot-on, I should have thought about this! :)

you can even drop the var=
{eval $item->fielddefs.yourInput.value}
{eval $image->comment}

Greetings,
Manuel

Re: plugin protect_email

Posted: Thu Nov 08, 2012 5:52 pm
by Jean le Chauve
Great :)
Thank you for pointing this detail.

Re: plugin protect_email

Posted: Tue Oct 07, 2014 6:07 pm
by manuel
Reposting the 1.11 file

Re: plugin protect_email

Posted: Thu Oct 16, 2014 1:35 am
by psy
Was keen to use this plugin but found a bug. It only supports email address with one extension, eg .fr or .com

Nothing is returned if the email address has two extensions, eg .com.au or .co.uk

it's back to the mailto plugin for now.

:'(

Re: plugin protect_email

Posted: Thu Oct 16, 2014 8:49 am
by Jean le Chauve
I did not know you could get two extensions :o
I am doing a new regex shortly.