We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Protect e-mail

    • 9995
    • 1,613 Posts
    Is it possible to protect e-mail on your site for Evo?
    I see there is a plug-in for Revolution.

    https://github.com/wshawn/ObfuscateEmail/blob/master/obfuscateEmail.php

    When I add a plug-in to Evo and paste the code with "OnWebPagePreRender" nothing happens.

    Probably some code needs to be changed for Evo like: $output = &$modx->resource->_output; ??

    Here full code:
    function email_regex()
    {
    
    $atom = "[-!#$%&'*+/=?^_`{|}~0-9A-Za-z]+";
    $email_half = $atom . '(?:\\.' . $atom . ')*';
    $email = $email_half . '@' . $email_half;
    $email_regex = '<(' . $email . ')>';
    return $email_regex;
    }
    function replaceEntities($matches)
    {
    $address = html_entity_decode($matches[1]);
    $replaced = '';
    for ($i = 0; $i < strlen($address); $i++) {
    $char = $address[$i];
    $r = rand(0, 100);
    # roughly 10% raw, 45% hex, 45% dec
    if ($r > 90) {
    $replaced .= $char;
    }
    else if ($r < 45) {
    $replaced .= '&#x' . dechex(ord($char)) . ';';
    }
    else
    {
    $replaced .= '&#' . ord($char) . ';';
    }
    }
    return $replaced;
    }
    $output = &$modx->resource->_output;
    $output = preg_replace_callback(email_regex(), "replaceEntities", $output);
    $output = preg_replace_callback('/(mailto:)/', "replaceEntities", $output);

    This question has been answered by breezer. See the first response.

      Evolution user, I like the back-end speed and simplicity smiley
    • discuss.answer
      • 4041
      • 788 Posts
      Change the last few lines like so and give it a try:

      $output = $modx->documentOutput;
      $output = preg_replace_callback(email_regex(), "replaceEntities", $output);
      $output = preg_replace_callback('/(mailto:)/', "replaceEntities", $output);
      $modx->documentOutput = $output;
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 36416
        • 589 Posts
        Quote from: fourroses666 at Jan 21, 2015, 09:34 AM
        Is it possible to protect e-mail on your site for Evo?

        Yes: https://github.com/Jako/emo
          • 9995
          • 1,613 Posts
          @breezer, that works smiley

          @eoler, works asswell smiley

          going to use one of them as default from now.

          [ed. note: fourroses666 last edited this post 11 years, 8 months ago.]
            Evolution user, I like the back-end speed and simplicity smiley