plugin protect_email

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Jean le Chauve

plugin protect_email

Post 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
Last edited by Jean le Chauve on Mon Dec 17, 2012 11:30 am, edited 2 times in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 729
Joined: Tue Nov 21, 2006 5:05 pm
Location: OH, USA

Re: plugin protect_email

Post by JohnnyB »

Thanks Jean!
This is a big help when Editors do not use the smarty {mailto} plugin.
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7754
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: plugin protect_email

Post by Rolf »

Great, thanks!!
Image
- + - + - + - + - + -
Latest CMSMS tutorial: FormBuilder WatchGuard
- + - + - + - + - + -
Did my post help you solving a problem at your (customers) website and it saved you many hours of work?
Great!! Buy me a cup of coffee in return as a small token of appreciation!
User avatar
manuel
Power Poster
Power Poster
Posts: 350
Joined: Fri Nov 30, 2007 9:15 am

Re: plugin protect_email

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
Jean le Chauve

Re: plugin protect_email

Post by Jean le Chauve »

Thanks for your comments
for cmsms 1.10.3 - :
prefilter.protect_email.zip
(1.61 KiB) Downloaded 195 times
for 1.11.1+
1.11.prefilter.protect_email.zip
(1.68 KiB) Downloaded 243 times
Last edited by Jean le Chauve on Tue Aug 28, 2012 8:31 am, edited 2 times in total.
User avatar
manuel
Power Poster
Power Poster
Posts: 350
Joined: Fri Nov 30, 2007 9:15 am

Re: plugin protect_email

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
Jean le Chauve

Re: plugin protect_email

Post by Jean le Chauve »

Dear Manuel,

Perhaps you need evaluate the input :
{eval var=$item->fielddefs.yourInput.value} (listit)
{eval var=$image->comment} (Gallery)
User avatar
manuel
Power Poster
Power Poster
Posts: 350
Joined: Fri Nov 30, 2007 9:15 am

Re: plugin protect_email

Post 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
Do you like your open source cms? Buy from the CMSMS partners || Donate
Jean le Chauve

Re: plugin protect_email

Post by Jean le Chauve »

Great :)
Thank you for pointing this detail.
User avatar
manuel
Power Poster
Power Poster
Posts: 350
Joined: Fri Nov 30, 2007 9:15 am

Re: plugin protect_email

Post by manuel »

Reposting the 1.11 file
Attachments
1.11.prefilter.protect_email.zip
(1.68 KiB) Downloaded 149 times
Do you like your open source cms? Buy from the CMSMS partners || Donate
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: plugin protect_email

Post 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.

:'(
Jean le Chauve

Re: plugin protect_email

Post by Jean le Chauve »

I did not know you could get two extensions :o
I am doing a new regex shortly.
Locked

Return to “Modules/Add-Ons”