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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Email obfuscation


Go to End


6 Posts   1359 Views

Avatar
Puzzling

Community Member, 3 Posts

28 July 2012 at 10:49am

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.

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2012 at 1:22pm

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.

Avatar
Puzzling

Community Member, 3 Posts

28 July 2012 at 1:56pm

Edited: 28/07/2012 2:07pm

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.

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2012 at 2:38pm

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)

Avatar
Puzzling

Community Member, 3 Posts

28 July 2012 at 3:11pm

Thanks for the pointers.

Avatar
cwsoft

Community Member, 57 Posts

30 July 2012 at 8:28am

Edited: 30/08/2012 8:51am

@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