Skip to content

Instantly share code, notes, and snippets.

@tillsanders
Created October 14, 2014 15:11
Show Gist options
  • Save tillsanders/1becd1b864462db7d052 to your computer and use it in GitHub Desktop.
Save tillsanders/1becd1b864462db7d052 to your computer and use it in GitHub Desktop.
Obfuscating Mailtos in Laravel 4
$(document).ready(function() {
// Hidden Mailtos
$('span.inyourfacespambot').click(function() {
var str = $(this).text();
var re = /^(.+?@).*@(.*)$/gmi;
var m;
while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
document.location.href = 'mailto:' + m[1] + m[2];
}
});
});
span.inyourfacespambot {
@extend a;
cursor: pointer;
span {
display: none;
}
}
Blade::extend(function($view, $compiler)
{
$pattern = $compiler->createMatcher('hiddenmailto');
return preg_replace($pattern, '$1<span class="inyourfacespambot"><?php echo substr($2, 0, strpos($2, "@") + 1); ?><span>thisspambotissostupid.com doesntexist@</span><?php echo substr($2, strpos($2, "@") + 1); ?></span>', $view);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment