• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: plugin protect_email
PostPosted: Fri Aug 10, 2012 8:40 am 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
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:
<?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&amp;cc=cc1@bidule.fr&amp;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&lt; (http://www.cmsmadesimple.fr/forum) &gt;</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.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Fri Aug 24, 2012 10:49 am 
Offline
Dev Team Member
Dev Team Member

Joined: Tue Nov 21, 2006 5:05 pm
Posts: 731
Location: OH, USA
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.
--


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Fri Aug 24, 2012 2:54 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7657
Location: The Netherlands
Great, thanks!!

_________________
Image

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Fri Aug 24, 2012 3:19 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 349
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
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Tue Aug 28, 2012 8:22 am 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Thanks for your comments
for cmsms 1.10.3 - :
Attachment:
prefilter.protect_email.zip [1.61 KiB]
Downloaded 118 times

for 1.11.1+
Attachment:
1.11.prefilter.protect_email.zip [1.68 KiB]
Downloaded 156 times


Last edited by Jean le Chauve on Tue Aug 28, 2012 8:31 am, edited 2 times in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Wed Nov 07, 2012 10:13 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 349
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
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Thu Nov 08, 2012 2:08 am 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Dear Manuel,

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


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Thu Nov 08, 2012 3:38 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 349
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
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Thu Nov 08, 2012 5:52 pm 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
Great :)
Thank you for pointing this detail.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Tue Oct 07, 2014 6:07 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 349
Reposting the 1.11 file


Attachments:
1.11.prefilter.protect_email.zip [1.68 KiB]
Downloaded 89 times

_________________
Do you like your open source cms? Buy from the CMSMS partners || Donate
(or at least share some knowledge :D >> See some of my stuff )
Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Thu Oct 16, 2014 1:35 am 
Offline
Power Poster
Power Poster

Joined: Sat Jan 22, 2005 11:19 am
Posts: 463
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.

:'(


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: plugin protect_email
PostPosted: Thu Oct 16, 2014 8:49 am 
Offline
Power Poster
Power Poster

Joined: Thu Mar 01, 2007 9:44 am
Posts: 253
Location: Belgique
I did not know you could get two extensions :o
I am doing a new regex shortly.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting