From df1c46115b52718ddbc74a46cc11ead3820a6b5d Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 8 Aug 2004 06:57:44 +0000 Subject: [PATCH] Improvement to filters, providing speed boost AND better compatibility with Turck MMCache. Filter function must now have a particular name eg resource_filter where "resource" is the name of the directory that filter.php is in. --- filter/activitynames/filter.php | 6 ------ filter/algebra/filter.php | 13 +------------ filter/censor/filter.php | 10 ---------- filter/mediaplugin/filter.php | 10 ---------- filter/multilang/filter.php | 9 --------- filter/tex/filter.php | 8 -------- lib/weblib.php | 7 +++++-- mod/glossary/filter.php | 8 +------- mod/resource/filter.php | 8 +------- mod/wiki/filter.php | 8 +------- 10 files changed, 9 insertions(+), 78 deletions(-) diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php index b35d748d96..9e52f155c1 100644 --- a/filter/activitynames/filter.php +++ b/filter/activitynames/filter.php @@ -4,12 +4,6 @@ //It's based in the glosssary filter by Williams Castillo //Modifications by stronk7. - $textfilter_function='activitynames_filter'; - - if (function_exists($textfilter_function)) { - return; - } - function activitynames_filter($courseid, $text) { global $CFG; diff --git a/filter/algebra/filter.php b/filter/algebra/filter.php index 704eec8f49..8558684ebf 100644 --- a/filter/algebra/filter.php +++ b/filter/algebra/filter.php @@ -46,17 +46,6 @@ $CFG->algebrafilterdirwin = "filter\\algebra"; } - - -/// These lines are important - the variable must match the name -/// of the actual function below - $textfilter_function='algebra_filter'; - - if (function_exists($textfilter_function)) { - return; - } - - function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="") { // Given the path to a picture file in a course, or a URL, // this function includes the picture in the page. @@ -243,4 +232,4 @@ function algebra_filter ($courseid, $text) { return $text; } -?> \ No newline at end of file +?> diff --git a/filter/censor/filter.php b/filter/censor/filter.php index 2d4705a07d..df769b28bf 100644 --- a/filter/censor/filter.php +++ b/filter/censor/filter.php @@ -12,16 +12,6 @@ // ////////////////////////////////////////////////////////////// -/// These lines are important - the variable must match the name -/// of the actual function below - - $textfilter_function = 'censor_filter'; - - if (function_exists($textfilter_function)) { - return; - } - - /// This is the filtering function itself. It accepts the /// courseid and the text to be filtered (in HTML form). diff --git a/filter/mediaplugin/filter.php b/filter/mediaplugin/filter.php index d38d3f29cd..58a446b0d1 100644 --- a/filter/mediaplugin/filter.php +++ b/filter/mediaplugin/filter.php @@ -12,16 +12,6 @@ // ////////////////////////////////////////////////////////////// -/// These lines are important - the variable must match the name -/// of the actual function below - - $textfilter_function = 'mediaplugin_filter'; - - if (function_exists($textfilter_function)) { - return; - } - - /// This is the filtering function itself. It accepts the /// courseid and the text to be filtered (in HTML form). diff --git a/filter/multilang/filter.php b/filter/multilang/filter.php index bf64f517f3..c736e460ac 100644 --- a/filter/multilang/filter.php +++ b/filter/multilang/filter.php @@ -31,15 +31,6 @@ // // /////////////////////////////////////////////////////////////////////////// -/// These lines are important - the variable must match the name -/// of the actual function below - -$textfilter_function = 'multilang_filter'; - -if (function_exists($textfilter_function)) { - return; -} - /// Given XML multilinguage text, return relevant text according to /// current language. i.e.= diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 0fc204a2c4..f3c69ce064 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -38,14 +38,6 @@ $CFG->texfilterdir = "filter/tex"; -/// These lines are important - the variable must match the name -/// of the actual function below -$textfilter_function='tex_filter'; - -if (function_exists($textfilter_function)) { - return; -} - function string_file_picture_tex($imagefile, $tex= "", $height="", $width="") { // Given the path to a picture file in a course, or a URL, diff --git a/lib/weblib.php b/lib/weblib.php index b0bcfa4189..53703ebc4f 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -704,8 +704,11 @@ function filter_text($text, $courseid=NULL) { $textfilters = explode(',', $CFG->textfilters); foreach ($textfilters as $textfilter) { if (is_readable("$CFG->dirroot/$textfilter/filter.php")) { - include("$CFG->dirroot/$textfilter/filter.php"); - $text = $textfilter_function($courseid, $text); + include_once("$CFG->dirroot/$textfilter/filter.php"); + $functionname = basename($textfilter).'_filter'; + if (function_exists($functionname)) { + $text = $functionname($courseid, $text); + } } } } diff --git a/mod/glossary/filter.php b/mod/glossary/filter.php index d8003a7b22..3544778d4d 100644 --- a/mod/glossary/filter.php +++ b/mod/glossary/filter.php @@ -1,12 +1,6 @@ dirroot.'/mod/wiki/lib.php'); - $textfilter_function='wiki_page_filter'; - - if (function_exists($textfilter_function)) { - return; - } - - function wiki_page_filter($courseid, $text) { + function wiki_filter($courseid, $text) { global $CFG; -- 2.39.5