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 (61 lines) | stat: -rw-r--r-- 2,240 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
<?php // $Id: filter.php,v 1.16 2006/01/11 15:11:00 stronk7 Exp $
    //This function provides automatic linking to
    //activities when its name (title) is found inside every Moodle text
    //It's based in the glosssary filter by Williams Castillo
    //Modifications by stronk7.

    function activitynames_filter($courseid, $text) {

        global $CFG;

        static $activitylist;

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

        /// It may be cached

        if (empty($activitylist)) {

            $course = get_record("course","id",$courseid);
            $modinfo = unserialize($course->modinfo);

            if (!empty($modinfo)) {

                $activitylist = array();      /// We will store all the activities here

                //Sort modinfo by name length
                usort($modinfo,'comparemodulenamesbylength');

                foreach ($modinfo as $activity) {
                    //Exclude labels and hidden items
                    if ($activity->mod != "label" && $activity->visible) {
                        $title = trim(strip_tags(urldecode($activity->name)));
                        /// Avoid empty or unlinkable activity names
                        if (!empty($title)) {
                            $title = str_replace('"', "'", $title);
                            $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" target=\"$CFG->framename\">";
                            $currentname = urldecode($activity->name);
                            if ($currentname = trim($currentname)) {
                                $activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                            }
                        }
                    }
                }
            }
        }

        return $text = filter_phrases ($text, $activitylist);
    }



    //This function is used to order module names from longer to shorter
    function comparemodulenamesbylength($a, $b)  {
        if (strlen($a->name) == strlen($b->name)) {
            return 0;
        }
        return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
    }
?>