Created
October 14, 2014 15:11
-
-
Save tillsanders/1becd1b864462db7d052 to your computer and use it in GitHub Desktop.
Obfuscating Mailtos in Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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]; | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
span.inyourfacespambot { | |
@extend a; | |
cursor: pointer; | |
span { | |
display: none; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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