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 (65 lines) | stat: -rwxr-xr-x 2,548 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
<?PHP // $Id: filter.php,v 1.12 2005/05/06 17:57:08 stronk7 Exp $
    //This function provides automatic linking to
    //wiki pages when its page title is found inside every Moodle text
    //It's based in the glosssary filter by Williams Castillo
    //Modifications by mchurch. Enjoy! :-)

    require_once($CFG->dirroot.'/mod/wiki/lib.php');

    function wiki_filter($courseid, $text) {

        global $CFG;

        static $nothingtodo;
        static $wikipagelist;

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

        if (empty($courseid)) {
            $courseid = SITEID;
        }

/// Create a list of all the wikis to search for.  It may be cached already.

        if (empty($wikipagelist)) {

        /// Get all wikis for this course.
            if (!$wikis = wiki_get_course_wikis($courseid)) {
                $nothingtodo = true;
                return $text;
            }

            $wikipagelist = array();

        /// Walk through each wiki, and get entries.
            foreach ($wikis as $wiki) {
                if ($wiki_entries = wiki_get_entries($wiki)) {
                
                /// Walk through each entry and get the pages.
                    foreach ($wiki_entries as $wiki_entry) {
                        if ($wiki_pages = get_records('wiki_pages', 'wiki', $wiki_entry->id, 'pagename, version DESC')) {
                        /// Walk through each page and filter.
                            $wikientries = array();
                            foreach ($wiki_pages as $wiki_page) {
                                if (!in_array($wiki_page->pagename, $wikientries)) {
                                    $startlink = '<a class="wiki autolink" title="Wiki" href="'
                                            .$CFG->wwwroot.'/mod/wiki/view.php?wid='.$wiki->id
                                            .'&amp;userid='.$wiki_entry->userid
                                            .'&amp;groupid='.$wiki_entry->groupid
                                            .'&amp;page='.$wiki_page->pagename.'">';
                                    $wikipagelist[] = new filterobject($wiki_page->pagename, $startlink, '</a>', false, true);
                                    $wikientries[] = $wiki_page->pagename;
                                }
                            }
                        }
                    }
                }
            }
        }

        return filter_phrases($text, $wikipagelist);
    }

?>