From: moodler Date: Mon, 13 Oct 2003 14:11:17 +0000 (+0000) Subject: NEW EXPERIMENTAL FEATURE: text filters. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e67b9e31e52c792f010fbd5caeafe5df14bc02ed;p=moodle.git NEW EXPERIMENTAL FEATURE: text filters. 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. --- diff --git a/config-dist.php b/config-dist.php index 9fd970ea2a..71a3866760 100644 --- a/config-dist.php +++ b/config-dist.php @@ -124,6 +124,17 @@ $CFG->directorypermissions = 0777; $CFG->admin = 'admin'; +//========================================================================= +// 7. TEXT FILTERS (most people can just ignore this setting) +//========================================================================= +// This is a new and experimental feature that allows text filters to +// be used on all printed texts in Moodle. To add text filters, you +// need to specify the path to a file that contains a standard textfilter. +// The numbers need to start at one and increment up to ten. +// +// eg $CFG->textfilter1 = "mod/glossary/dynalink.php"; +// $CFG->textfilter2 = "library/librarylib.php"; + //========================================================================= // ALL DONE! To continue installation, visit your main page with a browser diff --git a/lib/weblib.php b/lib/weblib.php index 3b7fcbb31c..a26c99fbe9 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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); diff --git a/mod/glossary/dynalink.php b/mod/glossary/dynalink.php index 6345584c1a..ea88a4c3dc 100644 --- a/mod/glossary/dynalink.php +++ b/mod/glossary/dynalink.php @@ -1,5 +1,11 @@