]> _ Git - cubist_cms-back.git/commitdiff
wip #2983 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2019 13:33:04 +0000 (15:33 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2019 13:33:04 +0000 (15:33 +0200)
src/app/Middleware/EmailObfuscate.php
src/public/emailobfuscator/emailobfuscator.js [new file with mode: 0644]

index 9094f3f6f6f413b0ea8c10e7b61776a4f0eeff40..38f1394919b2d0704c1a047d48d23c62c69ffeeb 100644 (file)
@@ -29,7 +29,20 @@ class EmailObfuscate
      * @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>';
+    }
 }
diff --git a/src/public/emailobfuscator/emailobfuscator.js b/src/public/emailobfuscator/emailobfuscator.js
new file mode 100644 (file)
index 0000000..5096e5a
--- /dev/null
@@ -0,0 +1,21 @@
+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;
+    });
+});