Possible new extension - Email obfuscator
Stash
✭
Is there interest in an extension that takes email addresses and obfuscates them so that spam bots have a harder time harvesting them? I was thinking about doing something like this and wondered if anyone else thinks it's a good idea.
0
This discussion has been closed.
Comments
<?php /* Extension Name: Email Obfuscator Extension Url: http://lussumo.com/docs/ Description: Obfuscates emails in the default formatter Version: 1.0 Author: SirNotAppearingOnThisForum Author Url: N/A */ /* this value can be one of the following: default - hooks only the default formatter all - hooks all of the formatters formatter - hooks only into specified formatter (eg. Html) */ define('EO_HOOK_WHICH_FORMATTER', 'default'); $EmailRegex = "/ (?<=[^A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~]) ( ( ( [A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~] [A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~.]{0,63}? ) | ( \"[^\\\"]{1,62}?\" ) ) @ ( ( [0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3} ) | ( [A-Za-z0-9] [A-Za-z0-9\-.]{0,244}\. [A-Za-z]{2,10} ) ) ) (?=[^\w]) /isx"; $EmailReplace = 'YOUR OBFUSCATION METHOD HERE; \\2 = local, \\5 = domain'; if(@$Context->StringManipulator) { class EmailObfuscator extends StringFormatter { function Parse($str, $obj, $purpose) { if($purpose == FORMAT_STRING_FOR_DISPLAY) return preg_replace($GLOBALS['EmailRegex'], $GLOBALS['EmailReplace'], $str); else return $str; } } $EmailObfuscator = $Context->ObjectFactory->NewObject($Context, 'EmailObfuscator'); if(EO_HOOK_WHICH_FORMATTER == 'default') $Context->StringManipulator->Formatters[$Configuration['DEFAULT_FORMAT_TYPE']]-> AddChildFormatter($EmailObfuscator); else if(EO_HOOK_WHICH_FORMATTER == 'all') { while(list(, $o) = each($Context->StringManipulator->Formatters)) $o->AddChildFormatter($EmailObfuscator); reset($Context->StringManipulator->Formatters); } else if(isset($Context->StringManipulator->Formatters[EO_HOOK_WHICH_FORMATTER])) $Context->StringManipulator->Formatters[EO_HOOK_WHICH_FORMATTER]-> AddChildFormatter($EmailObfuscator); } ?>$EmailReplace = '5';and$EmailReplace = '5';and all the options for the EO_HOOK_WHICH_FORMATTER eg:
defaultandallandHtmlIn fact, when I set it to 5 and Html I end up with my email address being replaced with:
<a href="mailto:5">5<a/>Edit: why is my text coming out bold here?
Is something ballsed up with the code above? Has some essential stuff been stripped out? Is that what's causing my text above to be bold and for the extension to not work?
$EmailReplace = '<a href="mailto:\\2@\\5">clicky</a>';I'm not sure why it's coming out bold, though, I'll look into that...Ah, I see what happened. You misspelled one of your <strong> tags as <stong>, so the html formatter though you had an unclosed <stong> and an orphaned </strong> :-P
Rock on me with the typos :P (that hasn't been the only one to cause trouble today)
<a href="mailto:\\2@\\5">\\2@\\5</a>And this:
<a href="mailto:email@server.com">email@server.com<a/>Gives me this:
<a href="mailto:<a href="mailto:email@server.com">email@server.com</a>"><a href="mailto:email@server.com">email@server.com</a><a/>$EmailReplace = '\\2 AT \\5';