We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36516
    • 179 Posts
    Here's an one that's had me stuck for a while now:

    I have an email TV which I'm passing as a snippet parameter. The snippet retrieves and can print out the email address just fine, but for some reason if I look for the @ sign, using anything like strpos() or even explode($email, '@'), it finds nothing and spits out nothing in the case of the former and the full string in one chunk in the case of the latter.

    If someone can shed light on how this confirmed string might otherwise have encoded the @ sign, I'd appreciate it!

    I believe I also tried a basic text TV, with no success.

    Thanks.
      • 36516
      • 179 Posts
      I've now discovered that any string operations I perform on the variable $email, passed as a parameter to the snippet using the [[+email]] placeholder, actually appear to be acting on the string "[[+email]]" rather than the string "[email protected]" which is what appears when using echo.

      How can that possibly make sense? Could modx be messing with my code in the background, intercepting my attempts to interact with the original string?
        • 3749
        • 24,544 Posts
        Can you paste the code (both the snippet tag and the snippet)?


        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 36516
          • 179 Posts
          Here's the snippet call (it bundles an email address into javascript to prevent it appearing in plain text in the HTML):

          [[!spamProofEmail? &email=`[[+email]]` &linktext=`Email [[+firstname]]`]]


          ...where [ [+email] ] can be any email address. I've experimented with different variable, parameter and placeholder names just in case I was stepping on something else along the way - no luck.

          The snippet (the first and only interesting part):

          if ( isset($email) )
          {
            $parts = explode( '@', (string)$email );
            $name = $parts[0];
            $domain = $parts[1];
          }


          Explode() is unable to find the '@' sign. Echoing $email at the beginning prints the email address correctly, but echoing urlencode($email) results in "%5B%5B%2Bemail%5D%5D" which is "[ [+email] ]"!

          Thanks for your help. [ed. note: davidsmith last edited this post 14 years, 6 months ago.]
            • 3749
            • 24,544 Posts
            The [[+email]] placeholder tag hasn't been processed at the time the snippet runs, so you're actually passing the tag rather than the email address in the property. When you echo the variable, you're actually echoing the [[+email]] tag, which appears to work because the that tag is later processed to display the email address.

            As an aside, most good email forms like SPForm and FormIt don't obfuscate email addresses, they don't display them but rather look them up or get them from the properties array.


            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODX info for everyone: http://bobsguides.com/modx.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 36516
              • 179 Posts
              Ok, thanks for the explanation - makes good sense.

              In that case, perhaps if I explain my intention you could suggest a workaround. I write a simple snippet for the sole purpose of cutting an email address string into parts, in order to print them on the screen amongst a prepared javascript... script, the purpose of which is to essentially hide the email address from bots by preventing it appearing in plain text.

              I suppose the significance here is that the email address isn't being captured from users, but instead it being entered as content in the manager, requiring a snippet call.

              As I type this I'm thinking I should probably rework my snippet as an output filter. I presume output filters work differently and therefore the value of the placeholder will be available to my snippet as planned. In which case, my next question is: can you pass additional parameters to a snipper being used as an output filter? My research into the subject so far hasn't made that very clear.

              Thanks again for you help.

              [EDIT:] It appears in the documentation that you can give the output modifier snippet one value in backticks, which is then made available in the snippet as "options" - plural. Does that imply you can indeed send more than one value, and if so, what's the syntax?

              Using this method I no longer need to pass the email address as a parameter because it's the subject, but to build an email link I might want to allow the snippet to present custom anchor text, so I'd need an optional parameter. [ed. note: davidsmith last edited this post 14 years, 6 months ago.]
                • 3749
                • 24,544 Posts
                Yes, you can definitely pass parameters to an output modifier, but I wonder if a plugin attached to OnParseDocument (before tags are processed) or OnWebPagePrerender (after tags are processed) wouldn't be a better route. Then users wouldn't have to remember to add the modifier.

                You could search for email addresses with preg_match, modify them, and then do a search and replace.

                FYI, I think there may already be some email obfuscation extras for Revolution. I know there are for Evolution. There's a good chance that the Evo ones would work in Revo with little or no modification.

                http://modx.com/extras/package/emoemailobfuscation


                http://modx.com/extras/package/emaillinkobfuscator



                ---------------------------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
                MODX info for everyone: http://bobsguides.com/modx.html

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 36516
                  • 179 Posts
                  Ah. Well. That's a much better plan. And it sounds like the work's been done for me! Thanks very much, yet again - most helpful.
                    • 36516
                    • 179 Posts
                    Turns out there is indeed a Revo plugin for this. Not only that, but it's someone's translation of your first Evo suggestion above!

                    [EDIT:] Forgot the URL: http://modx.com/extras/package/nospam

                    [EDIT 2:] ...and it was released yesterday. Is this a coincidence? [ed. note: davidsmith last edited this post 14 years, 6 months ago.]
                      • 3749
                      • 24,544 Posts
                      Beats me. wink

                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting