]> git.mjollnir.org Git - moodle.git/commitdiff
NEW EXPERIMENTAL FEATURE: text filters.
authormoodler <moodler>
Mon, 13 Oct 2003 14:11:17 +0000 (14:11 +0000)
committermoodler <moodler>
Mon, 13 Oct 2003 14:11:17 +0000 (14:11 +0000)
This new feature allows arbitrary text filters to be added to
any HTML that is printed (forum posts, resources etc) ... anything
that uses the standard format_text function.

The first one properly supported is the glossary dynamic linking
feature.

config-dist.php
lib/weblib.php
mod/glossary/dynalink.php

index 9fd970ea2afb86d00b78f0ee9e7f93ed5408aa42..71a3866760c50840102cec12b9d63f426ee761da 100644 (file)
@@ -124,6 +124,17 @@ $CFG->directorypermissions = 0777;
 \r
 $CFG->admin = 'admin';\r
 \r
+//=========================================================================\r
+// 7. TEXT FILTERS  (most people can just ignore this setting)\r
+//=========================================================================\r
+// This is a new and experimental feature that allows text filters to \r
+// be used on all printed texts in Moodle.  To add text filters, you\r
+// need to specify the path to a file that contains a standard textfilter.\r
+// The numbers need to start at one and increment up to ten.\r
+// \r
+// eg   $CFG->textfilter1 = "mod/glossary/dynalink.php";\r
+//      $CFG->textfilter2 = "library/librarylib.php";\r
+\r
 \r
 //=========================================================================\r
 // ALL DONE!  To continue installation, visit your main page with a browser\r
index 3b7fcbb31c94495521f2f77b060a84e85d4a8e57..a26c99fbe9f3b83c1fa81d903d6341bb630afdd0 100644 (file)
@@ -460,12 +460,12 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
 /// $text is raw text (originally from a user)
 /// $format is one of the format constants, defined above
 
-    global $CFG;
+    global $CFG, $course;
 
     switch ($format) {
         case FORMAT_HTML:
             replace_smilies($text);
-            return $text;
+            return filter_text($text);
             break;
 
         case FORMAT_PLAIN:
@@ -477,7 +477,8 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
             break;
 
         case FORMAT_WIKI:
-            return wiki_to_html($text);
+            $text = wiki_to_html($text);
+            return filter_text($text);
             break;
 
         default:  // FORMAT_MOODLE or anything else
@@ -487,7 +488,9 @@ function format_text($text, $format=FORMAT_MOODLE, $options=NULL) {
             if (!isset($options->para)) {
                 $options->para=true;
             }
-            return text_to_html($text, $options->smiley, $options->para);
+            $text = text_to_html($text, $options->smiley, $options->para);
+            return filter_text($text);
+
             break;
     }
 }
@@ -520,6 +523,35 @@ function format_text_email($text, $format) {
     }
 }
 
+
+function filter_text($text) {
+/// Given some text in HTML format, this function will pass it 
+/// through any filters that have been defined in $CFG->textfilterx
+/// The variable defines a filepath to a file containing the 
+/// filter function.  The file must contain a variable called 
+/// $textfilter_function which contains the name of the function
+/// with $course->id and $text parameters
+
+    global $CFG, $course;   // A dirty hack right now ... should not be assumed global
+
+    if (empty($course->id)) {
+        return $text;
+    }
+
+    for ($i=1; $i<=10; $i++) {
+        $variable = "textfilter$i";
+        if (empty($CFG->$variable)) {   /// No more filters
+            return $text;
+        }
+        if (is_readable("$CFG->dirroot/".$CFG->$variable)) {
+            include("$CFG->dirroot/".$CFG->$variable);
+            $text = $textfilter_function($course->id, $text);
+        }
+    }
+    return $text;
+}
+
+
 function clean_text($text, $format) {
 /// Given raw text (eg typed in by a user), this function cleans it up 
 /// and removes any nasty tags that could mess up Moodle pages.
@@ -607,14 +639,6 @@ function text_to_html($text, $smiley=true, $para=true) {
 /// Make returns into HTML newlines.
     $text = nl2br($text);
 
-/// Insert links to library pages if Library is being used
-    if (!empty($CFG->librarypath)) {
-        if (file_exists("$CFG->dirroot/$CFG->librarypath/librarylib.php")) {
-            include_once("$CFG->dirroot/$CFG->librarypath/librarylib.php");
-            $text = librarytexttohtml($text);
-        }       
-    }       
-
 /// Turn smileys into images.
     if ($smiley) {
         replace_smilies($text);
index 6345584c1ad037b956ab3951a64bad3d35175b64..ea88a4c3dcbc31be74a68d94f1ce1baa4134d8fa 100644 (file)
@@ -1,5 +1,11 @@
 <?PHP
 
+    $textfilter_function = 'glossary_dynamic_link';
+
+    if (function_exists($textfilter_function)) {
+        return;
+    }
+
     function glossary_dynamic_link($courseid, $text,$glossaryid = NULL) {
     global $CFG;
     static $entries;     // to avoid repeated calls to database