Jul 05, 2009, 09:28 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Read what MODx Developers say: MODx Dev. Blogs
Pages: [1]   Go Down
  Print  
Author Topic: [Snippet] EmailCloak - Cloaks email addresses using Javascript.  (Read 9197 times)
0 Members and 1 Guest are viewing this topic.
Kunal Kapoor
Full Member
***
Posts: 145


Effective, Functional, Standards Compliant


WWW
« on: Jan 23, 2006, 09:10 AM »

Hello fellow MODx-ers. I've been using MODx for a while now and have finally got something to contribute. I must admit, this is the first time I've ever contributed to an Open Source project, so please be gentle. Roll Eyes It's a snippet which allows email addresses to be cloaked or hidden from SPAM bots. Of course, this method is not foolproof, in fact:

Quote

I cannot see any other alternatives to this yet, and the code is very raw. If anyone can think of any improvements, I'm all open to suggestions. One feature I quite like is that you can set a page ID using $spage to make the link direct to a contact form in case Javascript is disabled.

Anyways, here is the code. This is still a work in progress though. Remember, be gentle... Wink

{EDITED: To include the <script> block of Javascript using $modx->regClientStartup() - Thanks Raymond!}

Code:
/**
 * EmailCloak
 * Cloaks any given email address.
 *
 * Code reworked by Kunal Kapoor.
 * Main credits go to Shawn K. Hall from this website address: http://tinyurl.com/9zouq
 */

///////////////////////////////////
//  <-----  USAGE  ----->
///////////////////////////////////
// To use this snippet, type this in your document content:
// [[EmailCloak? &saddress=`youremail@address.com` &scaption=`Email Me`]]
//
// OPTIONAL: You can include &stitle if you want to include a title attribute in your <a> tag.
// OPTIONAL: You can include $spage to the id of the page of your contact
//           form in case Javascript is not enabled.
// You MUST include both a &saddress and &scaption to include the link on your page.
//
// The script is provided without any warranty and is not a failsafe method of SPAM proofing your
// email address. For more information, visit http://tinyurl.com/9zouq
///////////////////////////////////
///////////////////////////////////
 
//variables
  $eaddress= "";  $sdomain= "";  $aextra = "";

//begin parsing
  list($eaddress, $sdomain)= split('@', $saddress);
  list($sdomain, $aextra) = split('\?', $sdomain);
  $sdomain = ereg_replace('\.', '#', $sdomain);

//create the js address
  $smailme = "mailMe('".urlencode( $sdomain );
  if($aextra != "" ){
    $smailme .= "?" . urlencode( $aextra );
  }
  $smailme .= "','" . urlencode( $eaddress ) . "')";

//build the js events
  $sbuild =" onmouseover=\"javascript: this.href=$smailme;\"";
  $sbuild.=" onfocus=\"javascript: this.href=$smailme;\"";

//if there is not $spage defined, use the current page id in case javascript is not enabled
  if ($spage == "") { $spage = "[~[*id*]~]"; }

//build up $thejavascript by including the javascript first, then stick it in the <head>
  $thejavascript  = "<script type=\"text/javascript\">";
  $thejavascript .= "  function mailMe(sDom, sUser){";
  $thejavascript .= "    return(\"mail\"+\"to:\"+sUser+\"@\"+sDom.replace(/%23/g,\".\"));";
  $thejavascript .= "  }";
  $thejavascript .= "</script>";
  $modx->regClientScript($thejavascript);

//return
  $theresult = "<a href=\"$spage\"$sbuild title=\"$stitle\">$scaption</a>";
  return $theresult;
« Last Edit: Jan 23, 2006, 09:32 AM by Kunal Kapoor » Logged

Kunal Kapoor
Technical Director
Limesharp Internet Limited - Effective, Functional, Standards Compliant

IRC Nick: KingKoopa
Skype ID: KingKoopa16
xwisdom
Foundation
*
Posts: 1,732



« Reply #1 on: Jan 23, 2006, 09:17 AM »

Nice snippet.

You might want to make use of the $modx->regClientStartup() function so you can register the javascript function inside the head tag
Logged

xWisdom
www.xwisdomhtml.com
The fear of the Lord is the beginning of wisdom:
MODx Co-Founder - Create and do more with less.
Kunal Kapoor
Full Member
***
Posts: 145


Effective, Functional, Standards Compliant


WWW
« Reply #2 on: Jan 23, 2006, 09:20 AM »

Nice snippet.

You might want to make use of the $modx->regClientStartup() function so you can register the javascript function inside the head tag

*Hops off to Documentation to learn how to do that!*

{EDITED: This has now been done. - Thanks Raymond!}
« Last Edit: Jan 23, 2006, 09:33 AM by Kunal Kapoor » Logged

Kunal Kapoor
Technical Director
Limesharp Internet Limited - Effective, Functional, Standards Compliant

IRC Nick: KingKoopa
Skype ID: KingKoopa16
davidm
MODx evangelist
Marketing & Design Team
*
Posts: 7,026


Software is like sex, it's better when it's free !


WWW
« Reply #3 on: Jan 23, 2006, 09:43 AM »

I know Aour had another solution, I'll notify him maybe he can add to this very useful feature !

Thanks Smiley
Logged

.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez ŕ l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accčs pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.67 - PHP 5.2.8 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net
Kunal Kapoor
Full Member
***
Posts: 145


Effective, Functional, Standards Compliant


WWW
« Reply #4 on: Jan 23, 2006, 09:50 AM »

I know Aour had another solution, I'll notify him maybe he can add to this very useful feature !

Thanks Smiley

Thanks David.

This snippet needs to display the email address in an encrypted way (in the source that is) e.g.:

Code:
<a href="email@address.com">email@address.com</a>

We need to encrypt what is between the <a..> </a> tags if $scaption isn't given. $scaption needs to default to the email address if a caption is not supplied. But whatever it is replaced with, must be invisible (although, we cannot really say this will always work) to SPAMbots.

*Phew* I hope that made sense.

Ah well, will plod on.
Logged

Kunal Kapoor
Technical Director
Limesharp Internet Limited - Effective, Functional, Standards Compliant

IRC Nick: KingKoopa
Skype ID: KingKoopa16
Djamoer
Emeritus
******
Posts: 1,495

No one can limit a man other than the man himself.


WWW
« Reply #5 on: Jan 23, 2006, 11:04 AM »

I just add this to the repository listing, hope this snippet can be maintained to ensure stability and for future update as well.

Thanks for sharing this great snippet with us.

Sincerely,
Logged

bugsmi0
Sr. Member
****
Posts: 356


« Reply #6 on: Apr 13, 2006, 05:01 PM »

Hello fellow MODx-ers. I've been using MODx for a while now and have finally got something to contribute. I must admit, this is the first time I've ever contributed to an Open Source project, so please be gentle. Roll Eyes It's a snippet which allows email addresses to be cloaked or hidden from SPAM bots. Of course, this method is not foolproof, in fact:

Quote

I cannot see any other alternatives to this yet, and the code is very raw. If anyone can think of any improvements, I'm all open to suggestions. One feature I quite like is that you can set a page ID using $spage to make the link direct to a contact form in case Javascript is disabled.

Anyways, here is the code. This is still a work in progress though. Remember, be gentle... Wink

{EDITED: To include the <script> block of Javascript using $modx->regClientStartup() - Thanks Raymond!}

Code:
/**
 * EmailCloak
 * Cloaks any given email address.
 *
 * Code reworked by Kunal Kapoor.
 * Main credits go to Shawn K. Hall from this website address: http://tinyurl.com/9zouq
 */

///////////////////////////////////
//  <-----  USAGE  ----->
///////////////////////////////////
// To use this snippet, type this in your document content:
// [[EmailCloak? &saddress=`youremail@address.com` &scaption=`Email Me`]]
//
// OPTIONAL: You can include &stitle if you want to include a title attribute in your <a> tag.
// OPTIONAL: You can include $spage to the id of the page of your contact
//           form in case Javascript is not enabled.
// You MUST include both a &saddress and &scaption to include the link on your page.
//
// The script is provided without any warranty and is not a failsafe method of SPAM proofing your
// email address. For more information, visit http://tinyurl.com/9zouq
///////////////////////////////////
///////////////////////////////////
 
//variables
  $eaddress= "";  $sdomain= "";  $aextra = "";

//begin parsing
  list($eaddress, $sdomain)= split('@', $saddress);
  list($sdomain, $aextra) = split('\?', $sdomain);
  $sdomain = ereg_replace('\.', '#', $sdomain);

//create the js address
  $smailme = "mailMe('".urlencode( $sdomain );
  if($aextra != "" ){
    $smailme .= "?" . urlencode( $aextra );
  }
  $smailme .= "','" . urlencode( $eaddress ) . "')";

//build the js events
  $sbuild =" onmouseover=\"javascript: this.href=$smailme;\"";
  $sbuild.=" onfocus=\"javascript: this.href=$smailme;\"";

//if there is not $spage defined, use the current page id in case javascript is not enabled
  if ($spage == "") { $spage = "[~[*id*]~]"; }

//build up $thejavascript by including the javascript first, then stick it in the <head>
  $thejavascript  = "<script type=\"text/javascript\">";
  $thejavascript .= "  function mailMe(sDom, sUser){";
  $thejavascript .= "    return(\"mail\"+\"to:\"+sUser+\"@\"+sDom.replace(/%23/g,\".\"));";
  $thejavascript .= "  }";
  $thejavascript .= "</script>";
  $modx->regClientScript($thejavascript);

//return
  $theresult = "<a href=\"$spage\"$sbuild title=\"$stitle\">$scaption</a>";
  return $theresult;

does anyone know that when these codes are put in the post, it's next to impossible to hightlight and copy ? is this suppose to be that way ?  Would be better if we could highlight it all within the post without copying the entire template  Grin
Logged

bugsmi0
Sr. Member
****
Posts: 356


« Reply #7 on: Apr 13, 2006, 05:10 PM »

is the email cloak snippet more secure than this one ?

<script type='text/javascript'>

   var tg='<';
   var name='myemail';
   var at='&#x040;';
   var host1='mydomai';
   var host2='n.com';
   var text='Contact Us';
   document.write(tg+'a hr'+'ef=mai'+'lto:'+name);
   document.write(at+host1+host2+'>'+text+tg+'/a>');

</script>
Logged

abbeyroad
Member
**
Posts: 52


« Reply #8 on: Apr 14, 2006, 12:15 PM »

@bugsmi0:
To highlight and copy code from forums:

Place the mouse pointer at the beginning of the code you would like to copy. Click once with left mouse button.
Now go to the end of the code, using the scroll-bar if neccessary, and click again, whilst holding down the shift key and Bob's yer uncle - all the code is selected.
Logged
24jedi
Jr. Member
*
Posts: 22


« Reply #9 on: May 19, 2006, 11:46 PM »

is the email cloak snippet more secure than this one ?

<script type='text/javascript'>

   var tg='<';
   var name='myemail';
   var at='&#x040;';
   var host1='mydomai';
   var host2='n.com';
   var text='Contact Us';
   document.write(tg+'a hr'+'ef=mai'+'lto:'+name);
   document.write(at+host1+host2+'>'+text+tg+'/a>');

</script>

Where would I use this code ?
I presume it would be a chunk and then add the chunck variable to the body section where and email adress would normally be written. Is this correct ??

Thanks
Don
Logged

I am but a dwarf in a land of giants... with propellars, calculators, bluetooth and beepers Smiley
bugsmi0
Sr. Member
****
Posts: 356


« Reply #10 on: May 23, 2006, 06:36 PM »

you could do that using a chunk, yep, also the email snippet can be used too but I was curious which is more secure
Logged

rthrash
Foundation
*
Posts: 10,471



WWW
« Reply #11 on: Jun 21, 2006, 09:41 AM »

Any plans on making this work more than once per page?
Logged

MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
persepolis
Member
**
Posts: 62



« Reply #12 on: Jul 03, 2006, 06:26 PM »

That works really great but I have one question:
How to append a subject ?

///////////////////////////////////
//  <-----  USAGE  ----->
///////////////////////////////////
// To use this snippet, type this in your document content:
//

1. [[EmailCloak? &saddress=`youremail@address.com\?subject=Test` &scaption=`Email Me`]]

leads to the following result:

onmouseover=\"javascript: this.href=letter('address%23comsubjec','youremail')

2. [[EmailCloak? &saddress=`youremail@address.com\?subject` &scaption=`Email Me`]]

leads to the following result:

onmouseover=\"javascript: this.href=letter('address%23comsubject','youremail')
Logged
chrison600
Jr. Member
*
Posts: 43


« Reply #13 on: Dec 17, 2008, 05:12 PM »

I'm trying to use this snippet and it doesn't seem to be working. Is it something that got broken after a new version release? I prefer to use this snippet vs that developed by Cyberk (http://modxcms.com/forums/index.php/topic,2552.0.html) because it also obfuscates the content of the link text.

Help?

Chris
Logged
chrison600
Jr. Member
*
Posts: 43


« Reply #14 on: Dec 18, 2008, 10:23 AM »

Disregard my previous post. I implemented the Email Obfuscation Plug-In by floh.

Thanks for MODx!!

Chris
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF | SMF © 2006-2008, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!