]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11561 improved text filter cache resetting when settings change; fixed bug causin...
authorskodak <skodak>
Tue, 25 Dec 2007 10:03:59 +0000 (10:03 +0000)
committerskodak <skodak>
Tue, 25 Dec 2007 10:03:59 +0000 (10:03 +0000)
admin/filter.php
admin/filters.php
admin/settings/misc.php
admin/settings/plugins.php
filter/tex/lib.php
lib/adminlib.php
lib/weblib.php

index 017382d05981d465efb10c7676b0be861c017f80..ce75068ef8385ae9a558a1b176cde0f48c373170 100644 (file)
@@ -51,6 +51,9 @@
                 set_config($name, stripslashes($value));
             }
         }
+
+        reset_text_filters_cache();
+
         redirect($returnurl);
         exit;
     }
index 02144fd65b3fa066c2205b4ae9aac74afa34b4c8..57d6c7c4c2b0ab6a911f2116e99185d65a9da941 100644 (file)
@@ -94,8 +94,9 @@
         break;
     }
 
-    // save and return
+    // save, reset cache and return
     set_config('textfilters', implode(',', $activefilters));
+    reset_text_filters_cache();
     redirect($returnurl);
 
 ?>
index 83861b0a8d29da2aac05b606d333d16f405c9bf2..953bef34aad6f154c4749aea6a717fae4565a350 100644 (file)
@@ -8,7 +8,9 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
     $temp = new admin_settingpage('experimental', get_string('experimental', 'admin'));
     $temp->add(new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0));
     $temp->add(new admin_setting_configcheckbox('smartpix', get_string('smartpix', 'admin'), get_string('configsmartpix', 'admin'), 0));
-    $temp->add(new admin_setting_configcheckbox('enablehtmlpurifier', get_string('enablehtmlpurifier', 'admin'), get_string('configenablehtmlpurifier', 'admin'), 0));
+    $item = new admin_setting_configcheckbox('enablehtmlpurifier', get_string('enablehtmlpurifier', 'admin'), get_string('configenablehtmlpurifier', 'admin'), 0); 
+    $item->set_updatedcallback('reset_text_filters_cache');
+    $temp->add($item);
     $temp->add(new admin_setting_configcheckbox('enablegroupings', get_string('enablegroupings', 'admin'), get_string('configenablegroupings', 'admin'), 0));
 
     $ADMIN->add('misc', $temp);
index af2244ac924d0f6c3d4ddf39ee7f5ee39f53f1d2..f3ff0f7b7a33423c3c90232546126cdbf570b8ae 100644 (file)
@@ -68,9 +68,10 @@ if ($hassiteconfig) {
     // "filtersettings" settingpage
     $temp = new admin_settingpage('managefilters', get_string('filtersettings', 'admin'));
     if ($ADMIN->fulltree) {
-        $temp->add(new admin_setting_managefilters());
-        $temp->add(new admin_setting_heading('managefilterscommonheading', get_string('commonsettings', 'admin'), ''));
-        $temp->add(new admin_setting_configselect('cachetext', get_string('cachetext', 'admin'), get_string('configcachetext', 'admin'), 60, array(604800 => get_string('numdays','',7),
+        $items = array();
+        $items[] = new admin_setting_managefilters();
+        $items[] = new admin_setting_heading('managefilterscommonheading', get_string('commonsettings', 'admin'), '');
+        $items[] = new admin_setting_configselect('cachetext', get_string('cachetext', 'admin'), get_string('configcachetext', 'admin'), 60, array(604800 => get_string('numdays','',7),
                                                                                                                                                86400 => get_string('numdays','',1),
                                                                                                                                                43200 => get_string('numhours','',12),
                                                                                                                                                10800 => get_string('numhours','',3),
@@ -90,13 +91,17 @@ if ($hassiteconfig) {
                                                                                                                                                120 => get_string('numminutes','',2),
                                                                                                                                                60 => get_string('numminutes','',1),
                                                                                                                                                30 => get_string('numseconds','',30),
-                                                                                                                                               0 => get_string('no'))));
-        $temp->add(new admin_setting_configselect('filteruploadedfiles', get_string('filteruploadedfiles', 'admin'), get_string('configfilteruploadedfiles', 'admin'), 0, array('0' => get_string('none'),
+                                                                                                                                               0 => get_string('no')));
+        $items[] = new admin_setting_configselect('filteruploadedfiles', get_string('filteruploadedfiles', 'admin'), get_string('configfilteruploadedfiles', 'admin'), 0, array('0' => get_string('none'),
                                                                                                                                                                                 '1' => get_string('allfiles'),
-                                                                                                                                                                                '2' => get_string('htmlfilesonly'))));
-        $temp->add(new admin_setting_configcheckbox('filtermatchoneperpage', get_string('filtermatchoneperpage', 'admin'), get_string('configfiltermatchoneperpage', 'admin'), 0));
-        $temp->add(new admin_setting_configcheckbox('filtermatchonepertext', get_string('filtermatchonepertext', 'admin'), get_string('configfiltermatchonepertext', 'admin'), 0));
-        $temp->add(new admin_setting_configcheckbox('filterall', get_string('filterall', 'admin'), get_string('configfilterall', 'admin'), 0));
+                                                                                                                                                                                '2' => get_string('htmlfilesonly')));
+        $items[] = new admin_setting_configcheckbox('filtermatchoneperpage', get_string('filtermatchoneperpage', 'admin'), get_string('configfiltermatchoneperpage', 'admin'), 0);
+        $items[] = new admin_setting_configcheckbox('filtermatchonepertext', get_string('filtermatchonepertext', 'admin'), get_string('configfiltermatchonepertext', 'admin'), 0);
+        $items[] = new admin_setting_configcheckbox('filterall', get_string('filterall', 'admin'), get_string('configfilterall', 'admin'), 0);
+        foreach ($items as $item) {
+            $item->set_updatedcallback('reset_text_filters_cache');
+            $temp->add($item);
+        }
     }
     $ADMIN->add('filtersettings', $temp);
 
index 76d6309e1ef31f916308b92b082f2a934985cb02..7eeb949cedd59044cb8e561d37c850464ccb12b7 100644 (file)
@@ -53,6 +53,8 @@ function tex_filter_get_cmd($pathname, $texexp) {
  */
 function filter_tex_updatedcallback($name) {
     global $CFG;
+    reset_text_filters_cache();
+
     if (file_exists("$CFG->dataroot/filter/tex")) {
         remove_dir("$CFG->dataroot/filter/tex");
     }
index 6209cd82d7cb9cdd8de22e7cd596f9c506033dc6..ceb69e82a5abc38741c453498ca6eb9590a6413c 100644 (file)
@@ -1598,15 +1598,6 @@ class admin_setting {
     }
 }
 
-/**
- * Dummy settings class - workaround for keeping empty categories visible
- */
-class admin_setting_dummy extends admin_setting {
-    function admin_setting_dummy() {
-        parent::admin_setting('dummy', 'dummy', 'dummy', NULL);
-    }
-}
-
 /**
  * No setting - just heading and text.
  */
index 8a9b19cb6118b1fd48ea9ac7a8fe6492326af62e..b55943e0906a6d7205c232617489a6eb0cea9a79 100644 (file)
@@ -1580,6 +1580,17 @@ function text_format_name( $key ) {
   return $value;
 }
 
+/**
+ * Resets all data related to filters, called during upgrade or when filter settings change.
+ * @return void
+ */
+function reset_text_filters_cache() {
+    global $CFG;
+
+    delete_records('cache_text');
+    $purifdir = $CFG->dataroot.'/cache/htmlpurifier';
+    remove_dir($purifdir, true);
+}
 
 /** Given a simple string, this function returns the string
  *  processed by enabled string filters if $CFG->filterall is enabled
@@ -1925,15 +1936,18 @@ function clean_text($text, $format=FORMAT_MOODLE) {
 function purify_html($text) {
     global $CFG;
 
+    // this can not be done only once because we sometimes need to reset the cache
+    $cachedir = $CFG->dataroot.'/cache/htmlpurifier/';
+    $status = check_dir_exists($cachedir, true, true);
+
     static $purifier = false;
-    if (!$purifier) {
-        make_upload_directory('cache/htmlpurifier', false);
+    if ($purifier === false) {
         require_once $CFG->libdir.'/htmlpurifier/HTMLPurifier.auto.php';
         $config = HTMLPurifier_Config::createDefault();
         $config->set('Core', 'AcceptFullDocuments', false);
         $config->set('Core', 'Encoding', 'UTF-8');
         $config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
-        $config->set('Cache', 'SerializerPath', $CFG->dataroot.'/cache/htmlpurifier');
+        $config->set('Cache', 'SerializerPath', $cachedir);
         $config->set('URI', 'AllowedSchemes', array('http'=>1, 'https'=>1, 'ftp'=>1, 'irc'=>1, 'nntp'=>1, 'news'=>1, 'rtsp'=>1, 'teamspeak'=>1, 'gopher'=>1, 'mms'=>1));
         $purifier = new HTMLPurifier($config);
     }