]> git.mjollnir.org Git - moodle.git/commitdiff
A proper GUI for filters :-)
authormoodler <moodler>
Sun, 22 Feb 2004 12:17:27 +0000 (12:17 +0000)
committermoodler <moodler>
Sun, 22 Feb 2004 12:17:27 +0000 (12:17 +0000)
Still needs work, but it works fine now.

Later I want to add config pages for each filter, like modules have.

admin/config.html
admin/configure.php
admin/filters.html [new file with mode: 0644]
admin/filters.php [new file with mode: 0644]
admin/index.php
lib/db/mysql.php
lib/db/postgres7.php
lib/weblib.php
version.php

index 5d93556dc83b4e3df95d9d29aa4ce32d7221cc9b..e6e3db38862a89c02d8c3a0cc9cd614a6da84110 100644 (file)
     <?php print_string("configopentogoogle") ?>
     </td>
 </tr>
-<tr valign=top>
-       <td align=right><p>textfilters:</td>
-       <td>
-    <textarea name=textfilters rows=3 cols=30><?php p($config->textfilters) ?></textarea>
-    </td>
-    <td>
-    <?php print_string("configtextfilters") ?>
-    </td>
-</tr>
-<tr valign=top>
-       <td align=right><p>cachetext:</td>
-       <td>
-    <?php 
-       unset($options);
-       $options[10800] = get_string('numhours', '', 3);
-       $options[7200]  = get_string('numhours', '', 2);
-       $options[3600]  = get_string('numhours', '', 1);
-       $options[2700]  = get_string('numminutes', '', 45);
-       $options[1800]  = get_string('numminutes', '', 30);
-       $options[900]   = get_string('numminutes', '', 15);
-       $options[600]   = get_string('numminutes', '', 10);
-       $options[540]   = get_string('numminutes', '',  9);
-       $options[480]   = get_string('numminutes', '',  8);
-       $options[420]   = get_string('numminutes', '',  7);
-       $options[360]   = get_string('numminutes', '',  6);
-       $options[300]   = get_string('numminutes', '',  5);
-       $options[240]   = get_string('numminutes', '',  4);
-       $options[180]   = get_string('numminutes', '',  3);
-       $options[120]   = get_string('numminutes', '',  2);
-       $options[60]    = get_string('numminutes', '',  1);
-       $options[30]    = get_string('numseconds', '',  30);
-       $options[0]     = get_string('no');
-
-       choose_from_menu ($options, "cachetext", $config->cachetext, "", "", "");
-    ?>
-    </td>
-    <td>
-    <?php print_string("configcachetext") ?>
-    </td>
-</tr>
 
 <tr>
     <td colspan=3 align=center>
index d4e4d7e8d8c948d4a7ff8281ddabaa7f55867ded..2b58a26a2998bb3ff1f72b220e8c3b764b7cbd41 100644 (file)
@@ -32,6 +32,8 @@
                            get_string("adminhelplanguage"));
     $table->data[] = array("<b><a href=\"modules.php\">".get_string("managemodules")."</a></b>",
                            get_string("adminhelpmanagemodules"));
+    $table->data[] = array("<b><a href=\"filters.php\">".get_string("managefilters")."</a></b>",
+                           get_string("adminhelpmanagefilters"));
     $table->data[] = array("<b><a href=\"backup.php\">".get_string("backup")."</a></b>",
                            get_string("adminhelpbackup"));
 
diff --git a/admin/filters.html b/admin/filters.html
new file mode 100644 (file)
index 0000000..73cb1b5
--- /dev/null
@@ -0,0 +1,124 @@
+<?php print_simple_box_start("center", "", "$THEME->cellheading"); ?>
+
+<form name="filters" id="filters" method="post" action="filters.php">
+  <table align="center" border="0" cellpadding="5" cellspacing="0">
+    <tr>
+      <td valign="top"><div align="right">
+        <br />
+        <input name="up" type="submit" id="up" value="&uarr;" />
+        <br />
+        <input name="down" type="submit" id="down" value="&darr;" />
+        <br />
+        </div></td>
+      <td valign="top">
+          <?php p($stractive) ?>
+          <br />
+      
+          <select name="iselect" size="20" id="iselect" 
+                  onclick="filters.add.disabled=true;
+                           filters.remove.disabled=false;
+                           filters.uselect.selectedIndex=-1;">
+          <?php 
+              $runscript = "";
+              foreach ($installedfilters as $filter) {
+                  if ($selectedfilter == $filter) {
+                      $selected = " selected ";
+                      $runscript = "eval(\"document.filters.add.disabled=true\");
+                                    eval(\"document.filters.remove.disabled=false\");
+                                    eval(\"document.filters.uselect.selectedIndex=-1\");";
+                  } else {
+                      $selected = "";
+                  }
+                  echo "<option value=\"$filter\" $selected>".$allfilters[$filter]."</option>";
+              }
+          ?>
+          </select></td>
+      <td valign="top">
+        <br />
+        <input name="add" type="submit" id="add" value="&larr;" />
+        <br />
+        <input name="remove" type="submit" id="remove" value="&rarr;" />              
+        <br />
+      </td>
+      <td valign="top">
+          <?php p($strinactive) ?>
+          <br />
+          <select name="uselect" size="20" id="select" 
+                  onclick="filters.add.disabled=false;
+                           filters.remove.disabled=true;
+                           filters.iselect.selectedIndex=-1;">
+          <?php
+              foreach ($uninstalledfilters as $filter) {
+                  if ($selectedfilter == $filter) {
+                      $selected = " selected ";
+                      $runscript = "eval(\"document.filters.add.disabled=false\");
+                                    eval(\"document.filters.remove.disabled=true\");
+                                    eval(\"document.filters.iselect.selectedIndex=-1\");";
+                  } else {
+                      $selected = "";
+                  }
+                  echo "<option value=\"$filter\" $selected>".$allfilters[$filter]."</option>";
+              }
+          ?>
+         </select></td>
+    </tr>
+  </table>
+</form>
+
+<script language="Javascript">
+<!--
+<?php echo $runscript ?>
+
+-->
+</script>
+<?php print_simple_box_end(); ?>
+
+<br />
+<br />
+
+
+<?php print_simple_box_start("center", "", "$THEME->cellheading"); ?>
+
+<form name="options" id="options" method="post" action="filters.php">
+<input type="hidden" name="options" value="1">
+<table cellpadding="20">
+<tr valign=top>
+       <td nowrap="nowrap" align="right"><?php p($strcachetext) ?>:</td>
+       <td>
+    <?php 
+       unset($options);
+       $options[10800] = get_string('numhours', '', 3);
+       $options[7200]  = get_string('numhours', '', 2);
+       $options[3600]  = get_string('numhours', '', 1);
+       $options[2700]  = get_string('numminutes', '', 45);
+       $options[1800]  = get_string('numminutes', '', 30);
+       $options[900]   = get_string('numminutes', '', 15);
+       $options[600]   = get_string('numminutes', '', 10);
+       $options[540]   = get_string('numminutes', '',  9);
+       $options[480]   = get_string('numminutes', '',  8);
+       $options[420]   = get_string('numminutes', '',  7);
+       $options[360]   = get_string('numminutes', '',  6);
+       $options[300]   = get_string('numminutes', '',  5);
+       $options[240]   = get_string('numminutes', '',  4);
+       $options[180]   = get_string('numminutes', '',  3);
+       $options[120]   = get_string('numminutes', '',  2);
+       $options[60]    = get_string('numminutes', '',  1);
+       $options[30]    = get_string('numseconds', '',  30);
+       $options[0]     = get_string('no');
+
+       choose_from_menu ($options, "cachetext", $config->cachetext, "", "", "");
+    ?>
+    </td>
+    <td>
+       <?php p($strconfigcachetext) ?>
+    </td>
+</tr>
+<tr valign=top>
+    <td>&nbsp;</td>
+    <td><input type="submit" value="<?php print_string("savechanges") ?>"></td>
+    <td>&nbsp;</td>
+</tr>
+</table>
+</form>
+
+<?php print_simple_box_end(); ?>
diff --git a/admin/filters.php b/admin/filters.php
new file mode 100644 (file)
index 0000000..1fb7676
--- /dev/null
@@ -0,0 +1,158 @@
+<?PHP // $Id$
+      // Allows the admin to create, delete and rename course categories
+
+    require_once("../config.php");
+
+    optional_variable($iselect);
+    optional_variable($uselect);
+    optional_variable($add);
+    optional_variable($remove);
+    optional_variable($up);
+    optional_variable($down);
+
+
+    if (!isadmin()) {
+        error("Only administrators can use this page!");
+    }
+
+    if (!$site = get_site()) {
+        error("Site isn't defined!");
+    }
+
+/// Print headings
+
+    $stradministration = get_string("administration");
+    $strconfiguration = get_string("configuration");
+    $strmanagefilters = get_string("managefilters");
+    $strversion = get_string("version");
+    $strsettings = get_string("settings");
+    $strup = get_string("up");
+    $strdown = get_string("down");
+    $stractive = get_string("active");
+    $strinactive = get_string("inactive");
+    $strcachetext = get_string("cachetext", "admin");
+    $strconfigcachetext = get_string("configcachetext");
+
+    print_header("$site->shortname: $strmanagefilters", "$site->fullname", 
+                 "<a href=\"index.php\">$stradministration</a> -> ".
+                 "<a href=\"configure.php\">$strconfiguration</a> -> $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();
+
+?>
index 8211578758ab104356d51d285da550aa15416d37..adfc7d7da1520ac9431d20429da3ac2b24b216e5 100644 (file)
                     get_string("adminhelplanguage")."</font><br />";
     $configdata .= "<font size=+1>&nbsp;</font><a href=\"modules.php\">".get_string("managemodules")."</a> - <font size=1>".
                     get_string("adminhelpmanagemodules")."</font><br />";
+    $configdata .= "<font size=+1>&nbsp;</font><a href=\"filters.php\">".get_string("managefilters")."</a> - <font size=1>".
+                    get_string("adminhelpmanagefilters")."</font><br />";
     if (!isset($CFG->disablescheduledbackups)) {
         $configdata .= "<font size=+1>&nbsp;</font><a href=\"backup.php\">".get_string("backup")."</a> - <font size=1>".
                         get_string("adminhelpbackup")."</font><br />";
index 87e2fda7c12b1c1952754fe4056fd92ef439644c..bf1c5ac962999dbddddad1986f209b068136e7e2 100644 (file)
@@ -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;
 
 }
index 5ad03d1a9fbd2654dc93f8b4bef1ede6ca3fc4bd..17f63775f3fd9ee8c0d98a736e46a81dd5a804eb 100644 (file)
@@ -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;
 
 }
index f504b24a65713273b417a0cdcd9e1ec3645a7a27..13b3f88a870427c54fa01eac641ea79110f0f4c9 100644 (file)
@@ -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);
             }
         }
index 68a0851fb2eb57598af5db5836ad691f397fd901..7fa7f7939c402cbc354458a2c4aa6d1536447f5f 100644 (file)
@@ -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