Kunal Kapoor
Full Member
  
Posts: 145
Effective, Functional, Standards Compliant
|
 |
« 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.  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: 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... {EDITED: To include the <script> block of Javascript using $modx->regClientStartup() - Thanks Raymond!}/** * 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
|
|
|
|
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
|
|
|
|
Kunal Kapoor
Full Member
  
Posts: 145
Effective, Functional, Standards Compliant
|
 |
« 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
|
|
|
|
davidm
MODx evangelist
Marketing & Design Team

Posts: 7,026
Software is like sex, it's better when it's free !
|
 |
« 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 
|
|
|
|
|
Logged
|
|
|
|
Kunal Kapoor
Full Member
  
Posts: 145
Effective, Functional, Standards Compliant
|
 |
« 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  Thanks David. This snippet needs to display the email address in an encrypted way (in the source that is) e.g.: <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
|
|
|
|
|
Djamoer
|
 |
« 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
|
 |
« 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.  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: 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... {EDITED: To include the <script> block of Javascript using $modx->regClientStartup() - Thanks Raymond!}/** * 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 
|
|
|
|
|
Logged
|
|
|
|
|
bugsmi0
|
 |
« 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='@'; 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='@'; 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 
|
|
|
|
bugsmi0
|
 |
« 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
|
 |
« 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
|
|
|
|
|