I need to run a RegEx on the content of any HTML Pro module before the page loads. I assume the custom code would go into this file: /DesktopModules/HTML/HtmlModule.ascx -- "OnPreRender" looks like a good place to me. Is this the right place/file to modify?
The purpose of the RegEX is to replace email addresses found in the text with a modified version of themselves, to prevent spambots from scraping them. (There used to be some modules available in DNN Store that did that, but they're now discontinued; I've used them before but they slowed the page load times down too much.)
I've done some research but haven't found any usable examples. What I did find isn't enough for me to implement what I want:
- http://www.dnnsoftware.com/answers/what-is-the-best-way-to-programmatically-edit-html-text
- Copy DNN HTML Pro module in content to another module
- Get HTML Module Contents by Module ID in DNN
- https://searchcode.com/codesearch/view/3359238/
Can anyone help me with a starter example of code to do the following:
- Before the content of HTML Pro module is sent to the browser, grab the latest version of HTML content
- Run a Regex.Replace on it
- Proceed with loading the page using the modified HTML content
Right now the section I'm looking at looks like this -- where would I insert that code?
protected override void OnPreRender(System.EventArgs e)
{
if (true && HttpRuntime.Cache.Get("avt.MyTokens2.CorePatched") == "true") {
base.OnPreRender(e);
return;
}
if (Convert.ToBoolean(Settings["MyTokensReplace"]) == true) {
(lblContent.Controls[0] as LiteralControl).Text = Tokenize((lblContent.Controls[0] as LiteralControl).Text, ModuleConfiguration, false, true);
}
base.OnPreRender(e);
}
Thanks for any and all help!