File: filter.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (69 lines) | stat: -rw-r--r-- 2,969 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php // $Id: filter.php,v 1.5 2006/03/26 06:28:50 moodler Exp $
    //
    // This function provides automatic linking to data contents of text
    // fields where these fields have autolink enabled.
    //
    // Original code by Williams, Stronk7, Martin D.
    // Modified for data module by Vy-Shane SF.

    function data_filter($courseid, $text) {
        global $CFG;

        static $nothingtodo;
        static $contentlist;

        if (!empty($nothingtodo)) {   // We've been here in this page already
            return $text;
        }

        // if we don't have a courseid, we can't run the query, so
        if (empty($courseid)) {
            return $text;
        }
        
        // Create a list of all the resources to search for. It may be cached already.
        if (empty($contentlist)) {
            // We look for text field contents only, and only if the field has
            // autolink enabled (param1).
            $sql = 'SELECT DISTINCT(dc.id) AS contentid, ' .
                   'dr.id AS recordid, ' .
                   'dc.content AS content, ' .
                   'd.id AS dataid ' .
                        'FROM '.$CFG->prefix.'data AS d, ' .
                        $CFG->prefix.'data_fields AS df, ' .
                        $CFG->prefix.'data_records AS dr, ' .
                        $CFG->prefix.'data_content AS dc ' .
                            "WHERE (d.course = '$courseid' or d.course = '".SITEID."')" .
                            'AND d.id = df.dataid ' .
                            'AND df.id = dc.fieldid ' .
                            'AND d.id = dr.dataid ' .
                            'AND dr.id = dc.recordid ' .
                            "AND df.type = 'text' " .
                            'AND df.param1 = 1';
            
            if (!$datacontents = get_records_sql($sql)) {
                return $text;
            }
            
            $contentlist = array();
            
            foreach ($datacontents as $datacontent) {
                $currentcontent = trim($datacontent->content);
                $strippedcontent = strip_tags($currentcontent);
                
                if (!empty($strippedcontent)) {
                    $contentlist[] = new filterobject(
                                            $currentcontent,
                                            '<a class="data autolink" title="'.
                                            $strippedcontent.'" href="'.
                                            $CFG->wwwroot.'/mod/data/view.php?d='. $datacontent->dataid .
                                            '&rid='. $datacontent->recordid .'" target="'.
                                            $CFG->framename.'">',
                                            '</a>', false, true);
                }
            } // End foreach
        }
        return  filter_phrases($text, $contentlist);  // Look for all these links in the text
    }

?>