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:You sit Joe Cracker down with the code for an hour or so and he’ll correct his RegEx-capable parsing spider to decode even this.

/** * 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=`[email protected]` &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;
Nice snippet.
You might want to make use of the $modx->regClientStartup() function so you can register the javascript function inside the head tag
I know Aour had another solution, I’ll notify him maybe he can add to this very useful feature !
Thanks
<a href="[email protected]">[email protected]</a>
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:
You sit Joe Cracker down with the code for an hour or so and he’ll correct his RegEx-capable parsing spider to decode even this.
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=`[email protected]` &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;
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>
