File: filter.php

package info (click to toggle)
moodle 1.4.4.dfsg.1-3sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 57,876 kB
  • ctags: 29,496
  • sloc: php: 271,617; sql: 5,084; xml: 702; perl: 638; sh: 403; java: 283; makefile: 42; pascal: 21
file content (40 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?PHP // $Id: filter.php,v 1.1.4.1 2004/09/11 13:29:29 moodler Exp $
      // 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]);
}

?>