Index: weblib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/weblib.php,v
retrieving revision 1.1088
diff -c -r1.1088 weblib.php
*** weblib.php	16 Jun 2008 16:39:28 -0000	1.1088
--- weblib.php	17 Jun 2008 08:06:31 -0000
***************
*** 1345,1350 ****
--- 1345,1352 ----
      global $CFG, $COURSE, $DB;
  
      static $croncache = array();
+     
+     $hashstr = '';
  
      if ($text === '') {
          return ''; // no need to do any filters and cleaning
***************
*** 1372,1386 ****
      if (!isset($options->newlines)) {
          $options->newlines=true;
      }
! 
!     if (empty($courseid)) {
!         $courseid = $COURSE->id;
      }
  
      if (!empty($CFG->cachetext) and empty($options->nocache)) {
!         $time = time() - $CFG->cachetext;
!         $md5key = md5($text.'-'.(int)$courseid.'-'.current_language().'-'.(int)$format.(int)$options->trusttext.(int)$options->noclean.(int)$options->smiley.(int)$options->filter.(int)$options->para.(int)$options->newlines);
  
          if (defined('FULLME') and FULLME == 'cron') {
              if (isset($croncache[$md5key])) {
                  return $croncache[$md5key];
--- 1374,1401 ----
      if (!isset($options->newlines)) {
          $options->newlines=true;
      }
!     if(empty($courseid)){
!         $couseid = $COURSE->id;
      }
  
+     if (!empty($CFG->textfilters)) {
+         require_once($CFG->libdir.'/filterlib.php');
+         $textfilters = explode(',', $CFG->textfilters);
+         foreach ($textfilters as $textfilter) {
+             if (is_readable($CFG->dirroot .'/'. $textfilter .'/filter.php')) {
+                 include_once($CFG->dirroot .'/'. $textfilter .'/filter.php');
+                 $classname = basename($textfilter).'_filter';
+                 $obj = new $classname($courseid, $format, $options);
+                 filter_base::addfilter($classname, $obj);
+                 $hashstr .= $obj->hash();
+             }
+         }
+     }
      if (!empty($CFG->cachetext) and empty($options->nocache)) {
!         $hashstr .= $text.'-'.(int)$courseid.'-'.current_language().'-'.(int)$format.(int)$options->trusttext.(int)$options->noclean.(int)$options->smiley.(int)$options->filter.(int)$options->para.(int)$options->newlines;
  
+         $time = time() - $CFG->cachetext;
+         $md5key = md5($hashstr); 
          if (defined('FULLME') and FULLME == 'cron') {
              if (isset($croncache[$md5key])) {
                  return $croncache[$md5key];
***************
*** 1431,1437 ****
                  $text = clean_text($text, FORMAT_HTML);
              }
              if ($options->filter) {
!                 $text = filter_text($text, $courseid);
              }
              break;
  
--- 1446,1452 ----
                  $text = clean_text($text, FORMAT_HTML);
              }
              if ($options->filter) {
!                 $text = filter_base::filter($text);
              }
              break;
  
***************
*** 1460,1466 ****
              }
  
              if ($options->filter) {
!                 $text = filter_text($text, $courseid);
              }
              break;
  
--- 1475,1481 ----
              }
  
              if ($options->filter) {
!                 $text = filter_base::filter($text);
              }
              break;
  
***************
*** 1471,1477 ****
              }
  
              if ($options->filter) {
!                 $text = filter_text($text, $courseid);
              }
              break;
      }
--- 1486,1492 ----
              }
  
              if ($options->filter) {
!                 $text = filter_base::filter($text);
              }
              break;
      }
Index: filterlib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/filterlib.php,v
retrieving revision 1.25
diff -c -r1.25 filterlib.php
*** filterlib.php	6 Jun 2008 09:15:33 -0000	1.25
--- filterlib.php	17 Jun 2008 08:06:31 -0000
***************
*** 1,6 ****
--- 1,35 ----
  <?php // $Id: filterlib.php,v 1.25 2008/06/06 09:15:33 jmg324 Exp $
        // Contains special functions that are particularly useful to filters
  
+ abstract class filter_base{
+     public static $filters = array();
+     protected $courseid;
+     protected $format;
+     protected $options;
+     function __construct($courseid, $format, $options){
+         $this->courseid = $courseid;
+         $this->format = $format;
+         $this->options = $options;
+     }
+     public static function addfilter($classname, $obj) {
+         if (empty(self::$filters[$classname])){
+             self::$filters[$classname] = $obj;
+             return true;
+         } else {
+             return false;
+         }
+     }
+     public static function filter($text){
+         foreach (self::$filters as $n=>$v) {
+             $text = $v->dofilter($text); 
+         }
+         return $text;
+     }
+     public function hash(){
+         return __CLASS__;
+     }
+     abstract function dofilter($text);
+ }
  
  /**
   * This is just a little object to define a phrase and some instructions 
