]> git.mjollnir.org Git - moodle.git/commitdiff
New filter for Email protection ... filters all email addresses in Moodle
authormoodler <moodler>
Thu, 2 Sep 2004 04:14:06 +0000 (04:14 +0000)
committermoodler <moodler>
Thu, 2 Sep 2004 04:14:06 +0000 (04:14 +0000)
text and obfuscates them from spammer's robotic eyes

Thanks Mike Churchward!  http://moodle.org/mod/forum/discuss.php?d=11302

filter/emailprotect/filter.php [new file with mode: 0644]
lang/en/emailprotect.php [new file with mode: 0644]

diff --git a/filter/emailprotect/filter.php b/filter/emailprotect/filter.php
new file mode 100644 (file)
index 0000000..3a61318
--- /dev/null
@@ -0,0 +1,40 @@
+<?PHP // $Id$
+      // This function looks for email addresses in Moodle text and 
+      // hides them using the Moodle obfuscate_text function. 
+      // Original code by Mike Churchward
+
+function emailprotect_filter($courseid, $text) {
+
+/// Do a quick check using stripos to avoid unnecessary work
+    if (strpos($text, '@') === false) {
+        return $text;
+    }
+
+/// There might be an email in here somewhere so continue ...
+    $matches = array();
+
+/// regular expression to define a standard email string.
+    $emailregex = '((?:[\w\.\-])+\@(?:(?:[a-zA-Z\d\-])+\.)+(?:[a-zA-Z\d]{2,4}))';
+
+/// pattern to find a mailto link with the linked text.
+    $pattern = '|(<a\s+href\s*=\s*[\'"]?mailto:)'.$emailregex.'([\'"]?\s*>)'.'(.*)'.'(</a>)|iU';
+    $text = preg_replace_callback($pattern, 'alter_mailto', $text);
+
+/// pattern to find any other email address in the text.
+    $pattern = '/(^|\s+|>)'.$emailregex.'($|\s+|\.\s+|\.$|<)/i';
+    $text = preg_replace_callback($pattern, 'alter_email', $text);
+
+    return $text;
+}
+
+
+function alter_email($matches) {
+    return $matches[1].obfuscate_text($matches[2]).$matches[3];
+}
+
+
+function alter_mailto($matches) {
+    return obfuscate_mailto($matches[2], $matches[4]);
+}
+
+?>
diff --git a/lang/en/emailprotect.php b/lang/en/emailprotect.php
new file mode 100644 (file)
index 0000000..2f013e5
--- /dev/null
@@ -0,0 +1,6 @@
+<?php /// $Id$
+
+$string['filtername'] = "Email Protection";
+
+?>
+