From 828aeff2d69e438d56f0abcd8aa543fc148c1b20 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 22 Feb 2004 12:17:27 +0000 Subject: [PATCH] A proper GUI for filters :-) Still needs work, but it works fine now. Later I want to add config pages for each filter, like modules have. --- admin/config.html | 40 ----------- admin/configure.php | 2 + admin/filters.html | 124 +++++++++++++++++++++++++++++++++ admin/filters.php | 158 +++++++++++++++++++++++++++++++++++++++++++ admin/index.php | 2 + lib/db/mysql.php | 12 ++++ lib/db/postgres7.php | 12 ++++ lib/weblib.php | 5 +- version.php | 2 +- 9 files changed, 313 insertions(+), 44 deletions(-) create mode 100644 admin/filters.html create mode 100644 admin/filters.php diff --git a/admin/config.html b/admin/config.html index 5d93556dc8..e6e3db3886 100644 --- a/admin/config.html +++ b/admin/config.html @@ -410,46 +410,6 @@ - -

textfilters: - - - - - - - - -

cachetext: - - cachetext, "", "", ""); - ?> - - - - - diff --git a/admin/configure.php b/admin/configure.php index d4e4d7e8d8..2b58a26a29 100644 --- a/admin/configure.php +++ b/admin/configure.php @@ -32,6 +32,8 @@ get_string("adminhelplanguage")); $table->data[] = array("".get_string("managemodules")."", get_string("adminhelpmanagemodules")); + $table->data[] = array("".get_string("managefilters")."", + get_string("adminhelpmanagefilters")); $table->data[] = array("".get_string("backup")."", get_string("adminhelpbackup")); diff --git a/admin/filters.html b/admin/filters.html new file mode 100644 index 0000000000..73cb1b5d98 --- /dev/null +++ b/admin/filters.html @@ -0,0 +1,124 @@ +cellheading"); ?> + +

+ + + + + + + +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ + + + +
+
+ + +cellheading"); ?> + +
+ + + + + + + + + + + + +
: + cachetext, "", "", ""); + ?> + + +
 "> 
+
+ + diff --git a/admin/filters.php b/admin/filters.php new file mode 100644 index 0000000000..1fb7676f16 --- /dev/null +++ b/admin/filters.php @@ -0,0 +1,158 @@ +shortname: $strmanagefilters", "$site->fullname", + "$stradministration -> ". + "$strconfiguration -> $strmanagefilters"); + + print_heading($strmanagefilters); + + +/// Make a list of all available filters and the best names for them we can find + $allfilters = array(); + + $filterlocations = array("mod", "filter"); + + foreach ($filterlocations as $filterlocation) { + $plugins = get_list_of_plugins($filterlocation); + foreach ($plugins as $key => $plugin) { + if (is_readable("$CFG->dirroot/$filterlocation/$plugin/filter.php")) { + $name = get_string("filtername", $plugin); + if ($name == "[[filtername]]") { + $name = $plugin; + } + $allfilters["$filterlocation/$plugin"] = $name; + } + } + } + + +/// Make an array of all the currently installed filters + + $installedfilters = array(); + if (!empty($CFG->textfilters)) { + $installedfilters = explode(',',$CFG->textfilters); + + // Do a little cleanup for robustness + foreach ($installedfilters as $key => $installedfilter) { + if (empty($installedfilter)) { + unset($installedfilters[$key]); + set_config("textfilters", implode(',', $installedfilters)); + } + } + } + + $selectedfilter = "none"; + +/// If data submitted, then process and store. + + if (!empty($add) and !empty($uselect)) { + $selectedfilter = $uselect; + if (!in_array($selectedfilter, $installedfilters)) { + $installedfilters[] = $selectedfilter; + set_config("textfilters", implode(',', $installedfilters)); + } + + } else if (!empty($remove) and !empty($iselect)) { + $selectedfilter = $iselect; + foreach ($installedfilters as $key => $installedfilter) { + if ($installedfilter == $selectedfilter) { + unset($installedfilters[$key]); + } + } + set_config("textfilters", implode(',', $installedfilters)); + + } else if ((!empty($up) or !empty($down)) and !empty($iselect)) { + + if (!empty($up)) { + if ($allfilters[$iselect]) { + foreach ($installedfilters as $key => $installedfilter) { + if ($installedfilter == $iselect) { + $movefilter = $key; + break; + } + $swapfilter = $key; + } + } + } + if (!empty($down)) { + if ($allfilters[$iselect]) { + $choosenext = false; + foreach ($installedfilters as $key => $installedfilter) { + if ($choosenext) { + $swapfilter = $key; + break; + } + if ($installedfilter == $iselect) { + $movefilter = $key; + $choosenext = true; + } + } + } + } + if (isset($swapfilter) and isset($movefilter)) { + $tempfilter = $installedfilters[$swapfilter]; + $installedfilters[$swapfilter] = $installedfilters[$movefilter]; + $installedfilters[$movefilter] = $tempfilter; + set_config("textfilters", implode(',', $installedfilters)); + } + $selectedfilter = $iselect; + } + + + +/// Make an array of all the currently uninstalled filters + + $uninstalledfilters = array(); + foreach ($allfilters as $filter => $name) { + $installed = false; + foreach ($installedfilters as $installedfilter) { + if ($installedfilter == $filter) { + $installed = true; + } + } + if (!$installed) { + $uninstalledfilters[] = $filter; + } + } + +/// Print the current form + + include("filters.html"); + + + print_footer(); + +?> diff --git a/admin/index.php b/admin/index.php index 8211578758..adfc7d7da1 100644 --- a/admin/index.php +++ b/admin/index.php @@ -381,6 +381,8 @@ get_string("adminhelplanguage")."
"; $configdata .= " ".get_string("managemodules")." - ". get_string("adminhelpmanagemodules")."
"; + $configdata .= " ".get_string("managefilters")." - ". + get_string("adminhelpmanagefilters")."
"; if (!isset($CFG->disablescheduledbackups)) { $configdata .= " ".get_string("backup")." - ". get_string("adminhelpbackup")."
"; diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 87e2fda7c1..bf1c5ac962 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -695,6 +695,7 @@ function main_upgrade($oldversion=0) { $CFG->textfilters = str_replace("censor.php", "filter.php", $CFG->textfilters); $CFG->textfilters = str_replace("mediaplugin.php", "filter.php", $CFG->textfilters); $CFG->textfilters = str_replace("algebra_filter.php", "filter.php", $CFG->textfilters); + $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters); set_config("textfilters", $CFG->textfilters); } } @@ -703,6 +704,17 @@ function main_upgrade($oldversion=0) { table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email"); } + if ($oldversion < 2004022200) { /// Final renaming I hope. :-) + if (!empty($CFG->textfilters)) { + $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters); + $textfilters = explode(',', $CFG->textfilters); + foreach ($textfilters as $key => $textfilter) { + $textfilters[$key] = trim($textfilter); + } + set_config("textfilters", implode(',',$textfilters)); + } + } + return $result; } diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 5ad03d1a9f..17f63775f3 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -440,6 +440,7 @@ function main_upgrade($oldversion=0) { $CFG->textfilters = str_replace("censor.php", "filter.php", $CFG->textfilters); $CFG->textfilters = str_replace("mediaplugin.php", "filter.php", $CFG->textfilters); $CFG->textfilters = str_replace("algebra_filter.php", "filter.php", $CFG->textfilters); + $CFG->textfilters = str_replace("dynalink.php", "filter.php", $CFG->textfilters); set_config("textfilters", $CFG->textfilters); } } @@ -448,6 +449,17 @@ function main_upgrade($oldversion=0) { table_column("user", "", "emailstop", "integer", "1", "unsigned", "0", "not null", "email"); } + if ($oldversion < 2004022200) { /// Final renaming I hope. :-) + if (!empty($CFG->textfilters)) { + $CFG->textfilters = str_replace("/filter.php", "", $CFG->textfilters); + $textfilters = explode(',', $CFG->textfilters); + foreach ($textfilters as $key => $textfilter) { + $textfilters[$key] = trim($textfilter); + } + set_config("textfilters", implode(',',$textfilters)); + } + } + return $result; } diff --git a/lib/weblib.php b/lib/weblib.php index f504b24a65..13b3f88a87 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -612,9 +612,8 @@ function filter_text($text, $courseid=NULL) { if (!empty($CFG->textfilters)) { $textfilters = explode(',', $CFG->textfilters); foreach ($textfilters as $textfilter) { - $textfilter = trim($textfilter); - if (is_readable($CFG->dirroot.'/'.$textfilter)) { - include($CFG->dirroot.'/'.$textfilter); + if (is_readable("$CFG->dirroot/$textfilter/filter.php")) { + include("$CFG->dirroot/$textfilter/filter.php"); $text = $textfilter_function($courseid, $text); } } diff --git a/version.php b/version.php index 68a0851fb2..7fa7f7939c 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2004022100; // The current version is a date (YYYYMMDDXX) +$version = 2004022200; // The current version is a date (YYYYMMDDXX) $release = "1.2 alpha"; // User-friendly version number -- 2.39.5