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.

Template Questions /

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

email spam protection rewrite


Go to End


4 Posts   1908 Views

Avatar
innoweb

Community Member, 9 Posts

7 January 2014 at 11:29am

Edited: 07/01/2014 11:30am

Hi guys,

I have built a module that replaces all email addresses on the website with a link to a contact form for spam protection.

<a href="/link/to/contact/form/with/encoded/email/address" title="E-Mail not shown if javascript is disabled." rel="nofollow" class="contact replacetext">[E-Mail via form]</a>

This link is then reversed to a mailto-link using javascript.

In SS2.4 and 3 I used to do the replacement in the forTemplate() method of the DBField classes (Varchar, Text, HTMLVarchar, HTMLText). This way all emails shown on the website were replaced and I was still able to use $Field.RAW where the email address had to stay.
Now in SS3.1 the RAW doesn't work anymore, meaning that the email addresses still get re-written.

Does anyone have an idea why RAW does behave this way in SS3.1?
Can anyone give me a hint where to do the rewrite other than the forTemplate() method of the DBField classes? Is there a way to somehow inject something like a rewrite_hash_links or something similar to shortcodes?

Thank you very much!

Avatar
innoweb

Community Member, 9 Posts

13 January 2014 at 6:59pm

bump. anyone?

Avatar
Willr

Forum Moderator, 5523 Posts

16 January 2014 at 8:37pm

I assume because the default casting has changed from Text to HTMLText. You can register your own parser to alter the object - http://api.silverstripe.org/3.1/class-TextParser.html

Avatar
innoweb

Community Member, 9 Posts

17 January 2014 at 11:41am

Hi Will,
Thanks for your reply.
Unfortunately this is not the solution I'm after. First you would need to call the parser in the templates for every field, second it would only work for Text/HTMLText fields and not for Varchar/HTMLVarchar.
What I had before SS3.1 was a solution where EVERY email address anywhere on the website was replaced (apart from hard coded ones in the templates).
I agree that this is probably because of the default casting. But it is still strange that RAW results in the value being converted to xml anyway. But that's probably because the surrounding template is converted to xml by the default casting later on. Is there a way to prevent this from happening in order to get the RAW to be really RAW?
Or maybe there is a way to change the behavior not of the db fields but the template parsing?
Thank you very much.