We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15914
    • 145 Posts
    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. rolleyes 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... wink

    {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;
      Kunal Kapoor
      Technical Director
      Limesharp Internet Limited - Effective, Functional, Standards Compliant

      IRC Nick: KingKoopa
      Skype ID: KingKoopa16
      • 32963
      • 1,732 Posts
      Nice snippet.

      You might want to make use of the $modx->regClientStartup() function so you can register the javascript function inside the head tag
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 15914
        • 145 Posts
        Quote from: xwisdom at 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

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

        {EDITED: This has now been done. - Thanks Raymond!}
          Kunal Kapoor
          Technical Director
          Limesharp Internet Limited - Effective, Functional, Standards Compliant

          IRC Nick: KingKoopa
          Skype ID: KingKoopa16
          • 6726
          • 7,075 Posts
          I know Aour had another solution, I’ll notify him maybe he can add to this very useful feature !

          Thanks smiley
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 15914
            • 145 Posts
            Quote from: davidm at 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

            Thanks David.

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



            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.
              Kunal Kapoor
              Technical Director
              Limesharp Internet Limited - Effective, Functional, Standards Compliant

              IRC Nick: KingKoopa
              Skype ID: KingKoopa16
              • 32241
              • 1,495 Posts
              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,
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
                • 4273
                • 356 Posts
                Quote from: Kunal at 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. rolleyes 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... wink

                {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;


                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
                  SMF Bookmark Mod - check it out
                  http://mods.simplemachines.org/index.php?mod=350
                  • 4273
                  • 356 Posts
                  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>
                    SMF Bookmark Mod - check it out
                    http://mods.simplemachines.org/index.php?mod=350
                    • 263
                    • 52 Posts
                    @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.
                      • 70
                      • 23 Posts
                      Quote from: bugsmi0 at 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>

                      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
                        I am but a dwarf in a land of giants... with propellars, calculators, bluetooth and beepers smiley