Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

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

Email obfuscation


6 Posts   576 Views


28 July 2012 at 10:49am Community Member, 3 Posts

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.


28 July 2012 at 1:22pm Forum Moderator, 5511 Posts

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.


28 July 2012 at 1:56pm (Last edited: 28 July 2012 2:07pm), Community Member, 3 Posts

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.


28 July 2012 at 2:38pm Forum Moderator, 5511 Posts

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)


28 July 2012 at 3:11pm Community Member, 3 Posts

Thanks for the pointers.


30 July 2012 at 8:28am (Last edited: 30 August 2012 8:51am), Community Member, 57 Posts

@Puzzling: to obfuscate mailto links, you may want to try my [url=]cwsoft-shortcode[/url] 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.