* @param $content
* @return mixed
*/
- public function obfuscate($content){
+ public function obfuscate($content)
+ {
+ $content = preg_replace_callback('/href="(mailto:)([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/', [$this, '_replaceMailto'], $content);
+ $content = preg_replace_callback('/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)/', [$this, '_replaceEmail'], $content);
return $content;
}
+
+ protected function _replaceMailto($matches)
+ {
+ return 'data-m-class="gfo45" data-m-content="a654d5:' . base64_encode($matches[2] . "@" . $matches[3] . "." . $matches[4]) . "#hdfr";
+ }
+
+ protected function _replaceEmail($matches)
+ {
+ return '<span data-m-class="8fr4g" data-m-content="56548df:' . base64_encode($matches[1] . "@" . $matches[2] . "." . $matches[3]) . '#fde4"></span>';
+ }
}
--- /dev/null
+document.addEventListener("DOMContentLoaded", function () {
+ document.querySelectorAll('[data-m-class="gfo45"]').forEach(function (e) {
+ var encoded = e.getAttribute('data-m-content');
+ var m = /^a654d5:([a-zA-Z0-9\/\+=]*)#hdfr$/i.exec(encoded);
+ if (null === m) {
+ return;
+ }
+ var email = atob(m[1]);
+ e.setAttribute('href', 'mailto:' + email);
+ });
+
+ document.querySelectorAll('[data-m-class="8fr4g"]').forEach(function (e) {
+ var encoded = e.getAttribute('data-m-content');
+ var m = /^56548df:([a-zA-Z0-9\/\+=]*)#fde4$/i.exec(encoded);
+ if (null === m) {
+ return;
+ }
+ var email = atob(m[1]);
+ e.textContent = email;
+ });
+});