Jump to:

10845 Posts in 2513 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » Email obfuscation

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 489 Views
  • Puzzling
    Avatar
    Community Member
    3 Posts

    Email obfuscation Link to this post

    I'm new to SS. We're trying to use 2.4.7 on a small site.

    I want to add a module to perform email obfuscation in my page controller. The method used by the hide-email module by Simon Wade is roughly what I want to use but that module did not work well for me. In that module, he basically does three things

    1) Replace the mailto: link with an obfuscated bit of javascript that writes the correct text into the document using document.write.
    2) Create and support a noscript option sending the user to a controller that issues a redirect to the mailto link
    3) Inserts the supporting JS in the content.

    The problem I`m running into is that the substitutions above are performed before the data is written to the DB. I think other issues, likely related to being on a later version of SS (2.4.7), seem to further mangle things. I'd prefer to have the control flow rewrite the content immediately prior to display leaving the data in the DB unmodified. Unfortunately, I cannot find an appropriate hook point (like an onBeforeView). Am I missing something? I suppose I could also look to do something in my theme but that just feels wrong.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Email obfuscation Link to this post

    I recommend creating a new getter on your Page, or member which returns obfuscated email (this functionality is built it) This assumes you have a field called 'Email'

    public function getObfuscatedEmail() {
    return Email::obfuscate($this->Email);
    }

    Email::obfuscate() takes one of 3 options - 'visible', 'direction', 'hex'. Consult the documentation for more information on those.

  • Puzzling
    Avatar
    Community Member
    3 Posts

    Re: Email obfuscation Link to this post

    Thanks. I was aware of the Email::obfuscate functionality although I had missed the hex option. My concern is that I just want to insert a mailto: anchor/link into the text and then arrange things so the data flow scans the text for such links and replaces them as part of the presentation process. If I add a new Email object then I don't think I can easily embed it in the middle of my text, can I?

    If there is a method on ContentController that is used to retrieve the text for display (possibly created by the ORM), then I could just override it in my Page.php to call the parent and then mangle the text. I just can't seem to locate that method.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Email obfuscation Link to this post

    If I add a new Email object then I don't think I can easily embed it in the middle of my text, can I?

    If you want to embed things in the middle of your code see 'Shortcodes'

    SS does allow you to define a get{$Field} function on the object in order for you to define, process or alter any field. For instance if you're outputting $Content which comes from the Content database object your page can define a getContent() function in order to alter that behaviour. However this does alter it everywhere $Content is used so may cause side effects (hence my previous suggestion of creating a new function that wraps the actual database value)

  • Puzzling
    Avatar
    Community Member
    3 Posts

    Re: Email obfuscation Link to this post

    Thanks for the pointers.

  • cwsoft
    Avatar
    Community Member
    55 Posts

    Re: Email obfuscation Link to this post

    @Puzzling: to obfuscate mailto links, you may want to try my cwsoft-shortcode module. It encrypts the mailto part with a simple Javascript Caesar chippher and can be invoked from inside WYSIWYG editor field. For SilverStripe 2.4.x you need to check out the 2.x branch or use an older tag, as the latest version in the master branch was updated to SilverStripe 3.0.

    Cheers

    489 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.