Index: activitynames/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/activitynames/filter.php,v
retrieving revision 1.23
diff -c -r1.23 filter.php
*** activitynames/filter.php	31 May 2008 18:05:44 -0000	1.23
--- activitynames/filter.php	17 Jun 2008 08:07:07 -0000
***************
*** 1,35 ****
! <?php // $Id: filter.php,v 1.23 2008/05/31 18:05:44 skodak Exp $
      //This function provides automatic linking to
      //activities when its name (title) is found inside every Moodle text
      //It's based in the glosssary filter by Williams Castillo
      //Modifications by stronk7.
  
!     function activitynames_filter($courseid, $text) {
!         global $CFG, $COURSE, $DB;
! 
!         // Trivial-cache - keyed on $cachedcourseid
!         static $activitylist = null;
!         static $cachedcourseid;
! 
          if (empty($courseid)) {
!             $courseid = SITEID;
          }
  
          // Initialise/invalidate our trivial cache if dealing with a different course
!         if (!isset($cachedcourseid) || $cachedcourseid !== (int)$courseid) {
!             $activitylist = null;
          } 
!         $cachedcourseid = (int)$courseid;
  
          /// It may be cached
  
!         if (is_null($activitylist)) {
!             $activitylist = array();
  
!             if ($COURSE->id == $courseid) {
                  $course = $COURSE;
              } else {
!                 $course = $DB->get_record("course", array("id"=>$courseid));
              }
  
              if (!isset($course->modinfo)) {
--- 1,39 ----
! <?php // $Id: filter.php,v 1.22 2008/01/24 20:33:54 skodak Exp $
      //This function provides automatic linking to
      //activities when its name (title) is found inside every Moodle text
      //It's based in the glosssary filter by Williams Castillo
      //Modifications by stronk7.
  
! class activitynames_filter extends filter_base{
!     private $activitylist;
!     private $cachedcourseid;
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
          if (empty($courseid)) {
!             $this->courseid = SITEID;
          }
+         $this->activitylist = null;
+         $this->cachedcourseid = null;
+     }
+ 
+     function dofilter($text) {
+         global $CFG, $COURSE;
  
          // Initialise/invalidate our trivial cache if dealing with a different course
!         if (!isset($this->cachedcourseid) || $this->cachedcourseid !== (int)$this->courseid) {
!             $this->activitylist = null;
          } 
!         $this->cachedcourseid = (int)$this->courseid;
  
          /// It may be cached
  
!         if (is_null($this->activitylist)) {
!             $this->activitylist = array();
  
!             if ($COURSE->id == $this->courseid) {
                  $course = $COURSE;
              } else {
!                 $course = get_record('course', 'id', $this->courseid);
              }
  
              if (!isset($course->modinfo)) {
***************
*** 41,47 ****
  
              if (!empty($modinfo)) {
  
!                 $activitylist = array();      /// We will store all the activities here
  
                  //Sort modinfo by name length
                  usort($modinfo, 'comparemodulenamesbylength');
--- 45,51 ----
  
              if (!empty($modinfo)) {
  
!                 $this->activitylist = array();      /// We will store all the activities here
  
                  //Sort modinfo by name length
                  usort($modinfo, 'comparemodulenamesbylength');
***************
*** 55,61 ****
                              $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>";
                              $currentname = urldecode($activity->name);
                              if ($currentname = trim($currentname)) {
!                                 $activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                              }
                          }
                      }
--- 59,65 ----
                              $href_tag_begin = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->wwwroot/mod/$activity->mod/view.php?id=$activity->cm\" $CFG->frametarget>";
                              $currentname = urldecode($activity->name);
                              if ($currentname = trim($currentname)) {
!                                 $this->activitylist[] = new filterobject($currentname, $href_tag_begin, '</a>', false, true);
                              }
                          }
                      }
***************
*** 63,82 ****
              }
          }
  
!         if ($activitylist) {
!             return $text = filter_phrases ($text, $activitylist);
          } else {
              return $text;
          }
      }
  
  
! 
!     //This function is used to order module names from longer to shorter
!     function comparemodulenamesbylength($a, $b)  {
!         if (strlen($a->name) == strlen($b->name)) {
!             return 0;
!         }
!         return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
      }
  ?>
--- 67,87 ----
              }
          }
  
!         if ($this->activitylist) {
!             $text = filter_phrases ($text, $this->activitylist);
!             return $text;
          } else {
              return $text;
          }
      }
+ }
  
  
! //This function is used to order module names from longer to shorter
! function comparemodulenamesbylength($a, $b)  {
!     if (strlen($a->name) == strlen($b->name)) {
!         return 0;
      }
+     return (strlen($a->name) < strlen($b->name)) ? 1 : -1;
+ }
  ?>
Index: algebra/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/algebra/filter.php,v
retrieving revision 1.26
diff -c -r1.26 filter.php
*** algebra/filter.php	31 May 2008 18:05:42 -0000	1.26
--- algebra/filter.php	17 Jun 2008 08:07:08 -0000
***************
*** 84,99 ****
    return $output;
  }
  
! 
! function algebra_filter ($courseid, $text) {
!     global $CFG, $DB;
! 
!     /// Do a quick check using stripos to avoid unnecessary wor
!     if (!preg_match('/<algebra/i',$text) && !strstr($text,'@@')) {
!         return $text;
      }
  
! #    //restrict filtering to forum 130 (Maths Tools on moodle.org)
  #    $scriptname = $_SERVER['SCRIPT_NAME'];
  #    if (!strstr($scriptname,'/forum/')) {
  #        return $text;
--- 84,102 ----
    return $output;
  }
  
! class algebra_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
      }
+     function dofilter($text){
+         global $CFG, $DB;
+ 
+         /// Do a quick check using stripos to avoid unnecessary wor
+         if (!preg_match('/<algebra/i',$text) && !strstr($text,'@@')) {
+             return $text;
+         }
  
! //restrict filtering to forum 130 (Maths Tools on moodle.org)
  #    $scriptname = $_SERVER['SCRIPT_NAME'];
  #    if (!strstr($scriptname,'/forum/')) {
  #        return $text;
***************
*** 102,108 ****
  #        $parent = forum_get_post_full($_GET['reply']);
  #        $discussion = $DB->get_record("forum_discussions",array("id"=>$parent->discussion));
  #    } else if (strstr($scriptname,'discuss.php')) {
! #        $discussion = $DB->get_record("forum_discussions", array("id"=>$_GET['d']));
  #    } else {
  #        return $text;
  #    }
--- 105,111 ----
  #        $parent = forum_get_post_full($_GET['reply']);
  #        $discussion = $DB->get_record("forum_discussions",array("id"=>$parent->discussion));
  #    } else if (strstr($scriptname,'discuss.php')) {
! #        $discussion = $DB->get_record("forum_discussions",array("id"=>$_GET['d']));
  #    } else {
  #        return $text;
  #    }
***************
*** 111,235 ****
  #    }
  
  
!     $text .= ' ';
  
!     preg_match_all('/@(@@+)([^@])/',$text,$matches);
!     for ($i=0;$i<count($matches[0]);$i++) {
!         $replacement = str_replace('@','&#x00040;',$matches[1][$i]).$matches[2][$i];
!         $text = str_replace($matches[0][$i],$replacement,$text);
!     }
  
!     // <algebra> some algebraic input expression </algebra>
!     // or @@ some algebraic input expression @@
  
!     preg_match_all('/<algebra>(.+?)<\/algebra>|@@(.+?)@@/is', $text, $matches);
!     for ($i=0; $i<count($matches[0]); $i++) {
!         $algebra = $matches[1][$i] . $matches[2][$i];
!         $algebra = str_replace('<nolink>','',$algebra);
!         $algebra = str_replace('</nolink>','',$algebra);
!         $algebra = str_replace('<span class="nolink">','',$algebra);
!         $algebra = str_replace('</span>','',$algebra);
!         $align = "middle";
!         if (preg_match('/^align=bottom /',$algebra)) {
!           $align = "text-bottom";
!           $algebra = preg_replace('/^align=bottom /','',$algebra);
!         } else if (preg_match('/^align=top /',$algebra)) {
!           $align = "text-top";
!           $algebra = preg_replace('/^align=top /','',$algebra);
!         }
!         $md5 =  md5($algebra);
!         $filename =  $md5  . ".gif";
!         if (! $texcache = $DB->get_record("cache_filters", array("filter"=>"algebra", "md5key"=>$md5))) {
!            $algebra = str_replace('&lt;','<',$algebra);
!            $algebra = str_replace('&gt;','>',$algebra);
!            $algebra = str_replace('<>','#',$algebra);
!            $algebra = str_replace('<=','%',$algebra);
!            $algebra = str_replace('>=','!',$algebra);
!            $algebra = preg_replace('/([=><%!#] *)-/',"\$1 zeroplace -",$algebra);
!            $algebra = str_replace('delta','zdelta',$algebra);
!            $algebra = str_replace('beta','bita',$algebra);
!            $algebra = str_replace('theta','thita',$algebra);
!            $algebra = str_replace('zeta','zita',$algebra);
!            $algebra = str_replace('eta','xeta',$algebra);
!            $algebra = str_replace('epsilon','zepslon',$algebra);
!            $algebra = str_replace('upsilon','zupslon',$algebra);
!            $algebra = preg_replace('!\r\n?!',' ',$algebra);
!            $algebra = escapeshellarg($algebra);
!            if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
!               $cmd  = "cd $CFG->dirroot\\filter\\algebra & algebra2tex.pl $algebra";
!            } else {
!               $cmd  = "cd $CFG->dirroot/filter/algebra; ./algebra2tex.pl $algebra";
!            }
!            $texexp = `$cmd`;
!            if (preg_match('/parsehilight/',$texexp)) {
!              $text = str_replace( $matches[0][$i],"<b>Syntax error:</b> " . $texexp,$text);
!            } else if ($texexp) {
!               $texexp = str_replace('zeroplace','',$texexp);
!               $texexp = str_replace('#','\not= ',$texexp);
!               $texexp = str_replace('%','\leq ',$texexp);
!               $texexp = str_replace('!','\geq ',$texexp);
!               $texexp = str_replace('\left{','{',$texexp);
!               $texexp = str_replace('\right}','}',$texexp);
!               $texexp = str_replace('\fun',' ',$texexp);
!               $texexp = str_replace('infty','\infty',$texexp);
!               $texexp = str_replace('alpha','\alpha',$texexp);
!               $texexp = str_replace('gamma','\gamma',$texexp);
!               $texexp = str_replace('iota','\iota',$texexp);
!               $texexp = str_replace('kappa','\kappa',$texexp);
!               $texexp = str_replace('lambda','\lambda',$texexp);
!               $texexp = str_replace('mu','\mu',$texexp);
!               $texexp = str_replace('nu','\nu',$texexp);
!               $texexp = str_replace('xi','\xi',$texexp);
!               $texexp = str_replace('rho','\rho',$texexp);
!               $texexp = str_replace('sigma','\sigma',$texexp);
!               $texexp = str_replace('tau','\tau',$texexp);
!               $texexp = str_replace('phi','\phi',$texexp);
!               $texexp = str_replace('chi','\chi',$texexp);
!               $texexp = str_replace('psi','\psi',$texexp);
!               $texexp = str_replace('omega','\omega',$texexp);
!               $texexp = str_replace('zdelta','\delta',$texexp);
!               $texexp = str_replace('bita','\beta',$texexp);
!               $texexp = str_replace('thita','\theta',$texexp);
!               $texexp = str_replace('zita','\zeta',$texexp);
!               $texexp = str_replace('xeta','\eta',$texexp);
!               $texexp = str_replace('zepslon','\epsilon',$texexp);
!               $texexp = str_replace('zupslon','\upsilon',$texexp);
!               $texexp = str_replace('\mbox{logten}','\mbox{log}_{10}',$texexp);
!               $texexp = str_replace('\mbox{acos}','\mbox{cos}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{asin}','\mbox{sin}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{atan}','\mbox{tan}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{asec}','\mbox{sec}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{acsc}','\mbox{csc}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{acot}','\mbox{cot}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{acosh}','\mbox{cosh}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{asinh}','\mbox{sinh}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{atanh}','\mbox{tanh}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{asech}','\mbox{sech}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{acsch}','\mbox{csch}^{-1}',$texexp);
!               $texexp = str_replace('\mbox{acoth}','\mbox{coth}^{-1}',$texexp);
!               //$texexp = preg_replace('/\\\frac{(.+?)}{\\\left\((.+?)\\\right\)}/s','\frac{'."\$1}{\$2}",$texexp);
!               $texexp = preg_replace('/\\\sqrt{(.+?),(.+?)}/s','\sqrt['. "\$2]{\$1}",$texexp);
!               $texexp = preg_replace('/\\\mbox{abs}\\\left\((.+?)\\\right\)/s',"|\$1|",$texexp);
!               $texexp = preg_replace('/\\\log\\\left\((.+?),(.+?)\\\right\)/s','\log_{'. "\$2}\\left(\$1\\right)",$texexp);
!               $texexp = preg_replace('/(\\\cos|\\\sin|\\\tan|\\\sec|\\\csc|\\\cot)([h]*)\\\left\((.+?),(.+?)\\\right\)/s',"\$1\$2^{". "\$4}\\left(\$3\\right)",$texexp);
!               $texexp = preg_replace('/\\\int\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\int_'. "{\$2}^{\$3}\$1 ",$texexp);
!               $texexp = preg_replace('/\\\int\\\left\((.+?d[a-z])\\\right\)/s','\int '. "\$1 ",$texexp);
!               $texexp = preg_replace('/\\\lim\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\lim_'. "{\$2\\to \$3}\$1 ",$texexp);
!               $texcache->filter = 'algebra';
!               $texcache->version = 1;
!               $texcache->md5key = $md5;
!               $texcache->rawtext = $texexp;
!               $texcache->timemodified = time();
!               $DB->insert_record("cache_filters",$texcache, false);
!               $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text);
!            } else {
!               $text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
!            }
!         } else {
!            $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texcache->rawtext), $text);
          }
      }
-     return $text;
  }
  
  ?>
--- 114,239 ----
  #    }
  
  
!         $text .= ' ';
  
!         preg_match_all('/@(@@+)([^@])/',$text,$matches);
!         for ($i=0;$i<count($matches[0]);$i++) {
!             $replacement = str_replace('@','&#x00040;',$matches[1][$i]).$matches[2][$i];
!             $text = str_replace($matches[0][$i],$replacement,$text);
!         }
  
!         // <algebra> some algebraic input expression </algebra>
!         // or @@ some algebraic input expression @@
  
!         preg_match_all('/<algebra>(.+?)<\/algebra>|@@(.+?)@@/is', $text, $matches);
!         for ($i=0; $i<count($matches[0]); $i++) {
!             $algebra = $matches[1][$i] . $matches[2][$i];
!             $algebra = str_replace('<nolink>','',$algebra);
!             $algebra = str_replace('</nolink>','',$algebra);
!             $algebra = str_replace('<span class="nolink">','',$algebra);
!             $algebra = str_replace('</span>','',$algebra);
!             $align = "middle";
!             if (preg_match('/^align=bottom /',$algebra)) {
!               $align = "text-bottom";
!               $algebra = preg_replace('/^align=bottom /','',$algebra);
!             } else if (preg_match('/^align=top /',$algebra)) {
!               $align = "text-top";
!               $algebra = preg_replace('/^align=top /','',$algebra);
!             }
!             $md5 =  md5($algebra);
!             $filename =  $md5  . ".gif";
!             if (! $texcache = $DB->get_record("cache_filters",array("filter"=>"algebra", "md5key"=>$md5))) {
!                $algebra = str_replace('&lt;','<',$algebra);
!                $algebra = str_replace('&gt;','>',$algebra);
!                $algebra = str_replace('<>','#',$algebra);
!                $algebra = str_replace('<=','%',$algebra);
!                $algebra = str_replace('>=','!',$algebra);
!                $algebra = preg_replace('/([=><%!#] *)-/',"\$1 zeroplace -",$algebra);
!                $algebra = str_replace('delta','zdelta',$algebra);
!                $algebra = str_replace('beta','bita',$algebra);
!                $algebra = str_replace('theta','thita',$algebra);
!                $algebra = str_replace('zeta','zita',$algebra);
!                $algebra = str_replace('eta','xeta',$algebra);
!                $algebra = str_replace('epsilon','zepslon',$algebra);
!                $algebra = str_replace('upsilon','zupslon',$algebra);
!                $algebra = preg_replace('!\r\n?!',' ',$algebra);
!                $algebra = escapeshellarg($algebra);
!                if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
!                   $cmd  = "cd $CFG->dirroot\\filter\\algebra & algebra2tex.pl $algebra";
!                } else {
!                   $cmd  = "cd $CFG->dirroot/filter/algebra; ./algebra2tex.pl $algebra";
!                }
!                $texexp = `$cmd`;
!                if (preg_match('/parsehilight/',$texexp)) {
!                  $text = str_replace( $matches[0][$i],"<b>Syntax error:</b> " . $texexp,$text);
!                } else if ($texexp) {
!                   $texexp = str_replace('zeroplace','',$texexp);
!                   $texexp = str_replace('#','\not= ',$texexp);
!                   $texexp = str_replace('%','\leq ',$texexp);
!                   $texexp = str_replace('!','\geq ',$texexp);
!                   $texexp = str_replace('\left{','{',$texexp);
!                   $texexp = str_replace('\right}','}',$texexp);
!                   $texexp = str_replace('\fun',' ',$texexp);
!                   $texexp = str_replace('infty','\infty',$texexp);
!                   $texexp = str_replace('alpha','\alpha',$texexp);
!                   $texexp = str_replace('gamma','\gamma',$texexp);
!                   $texexp = str_replace('iota','\iota',$texexp);
!                   $texexp = str_replace('kappa','\kappa',$texexp);
!                   $texexp = str_replace('lambda','\lambda',$texexp);
!                   $texexp = str_replace('mu','\mu',$texexp);
!                   $texexp = str_replace('nu','\nu',$texexp);
!                   $texexp = str_replace('xi','\xi',$texexp);
!                   $texexp = str_replace('rho','\rho',$texexp);
!                   $texexp = str_replace('sigma','\sigma',$texexp);
!                   $texexp = str_replace('tau','\tau',$texexp);
!                   $texexp = str_replace('phi','\phi',$texexp);
!                   $texexp = str_replace('chi','\chi',$texexp);
!                   $texexp = str_replace('psi','\psi',$texexp);
!                   $texexp = str_replace('omega','\omega',$texexp);
!                   $texexp = str_replace('zdelta','\delta',$texexp);
!                   $texexp = str_replace('bita','\beta',$texexp);
!                   $texexp = str_replace('thita','\theta',$texexp);
!                   $texexp = str_replace('zita','\zeta',$texexp);
!                   $texexp = str_replace('xeta','\eta',$texexp);
!                   $texexp = str_replace('zepslon','\epsilon',$texexp);
!                   $texexp = str_replace('zupslon','\upsilon',$texexp);
!                   $texexp = str_replace('\mbox{logten}','\mbox{log}_{10}',$texexp);
!                   $texexp = str_replace('\mbox{acos}','\mbox{cos}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{asin}','\mbox{sin}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{atan}','\mbox{tan}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{asec}','\mbox{sec}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{acsc}','\mbox{csc}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{acot}','\mbox{cot}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{acosh}','\mbox{cosh}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{asinh}','\mbox{sinh}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{atanh}','\mbox{tanh}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{asech}','\mbox{sech}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{acsch}','\mbox{csch}^{-1}',$texexp);
!                   $texexp = str_replace('\mbox{acoth}','\mbox{coth}^{-1}',$texexp);
!                   //$texexp = preg_replace('/\\\frac{(.+?)}{\\\left\((.+?)\\\right\)}/s','\frac{'."\$1}{\$2}",$texexp);
!                   $texexp = preg_replace('/\\\sqrt{(.+?),(.+?)}/s','\sqrt['. "\$2]{\$1}",$texexp);
!                   $texexp = preg_replace('/\\\mbox{abs}\\\left\((.+?)\\\right\)/s',"|\$1|",$texexp);
!                   $texexp = preg_replace('/\\\log\\\left\((.+?),(.+?)\\\right\)/s','\log_{'. "\$2}\\left(\$1\\right)",$texexp);
!                   $texexp = preg_replace('/(\\\cos|\\\sin|\\\tan|\\\sec|\\\csc|\\\cot)([h]*)\\\left\((.+?),(.+?)\\\right\)/s',"\$1\$2^{". "\$4}\\left(\$3\\right)",$texexp);
!                   $texexp = preg_replace('/\\\int\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\int_'. "{\$2}^{\$3}\$1 ",$texexp);
!                   $texexp = preg_replace('/\\\int\\\left\((.+?d[a-z])\\\right\)/s','\int '. "\$1 ",$texexp);
!                   $texexp = preg_replace('/\\\lim\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\lim_'. "{\$2\\to \$3}\$1 ",$texexp);
!                   $texcache->filter = 'algebra';
!                   $texcache->version = 1;
!                   $texcache->md5key = $md5;
!                   $texcache->rawtext = $texexp;
!                   $texcache->timemodified = time();
!                   $DB->insert_record("cache_filters", $texcache, false);
!                   $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text);
!                } else {
!                   $text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
!                }
!             } else {
!                $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texcache->rawtext), $text);
!             }
          }
+         return $text;
      }
  }
  
  ?>
Index: censor/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/censor/filter.php,v
retrieving revision 1.12
diff -c -r1.12 filter.php
*** censor/filter.php	13 Nov 2007 20:03:27 -0000	1.12
--- censor/filter.php	17 Jun 2008 08:07:08 -0000
***************
*** 9,45 ****
  //
  //////////////////////////////////////////////////////////////
  
! /// This is the filtering function itself.  It accepts the 
! /// courseid and the text to be filtered (in HTML form).
! 
! function censor_filter($courseid, $text) {
! 
!     static $words;
!     global $CFG;
! 
!     if (!isset($CFG->filter_censor_badwords)) {
!         set_config( 'filter_censor_badwords','' );
      }
! 
!     if (empty($words)) {
!         $words = array();
!         // if no user-specified words, use default list from language pack
!         if (empty($CFG->filter_censor_badwords)) {
!             $badwords = explode(',',get_string('badwords','censor') );
!         }
!         else {
!             $badwords = explode(',', $CFG->filter_censor_badwords );
          }
!         foreach ($badwords as $badword) {
!             $badword = trim($badword);
!             // See MDL-3964 for explanation of leaving the badword in the span title 
!             $words[] = new filterobject($badword, '<span class="censoredtext" title="'.$badword.'">', '</span>', 
!                                         false, false, str_pad('',strlen($badword),'*'));
          }
      }
  
!     return filter_phrases($text, $words);  // Look for all these words in the text
! }
  
  
  ?>
--- 9,68 ----
  //
  //////////////////////////////////////////////////////////////
  
! /// This is the filtering class. It accepts the courseid and 
! /// options to be filtered (In HTML form).
! class censor_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
      }
!     function canseecensor(){
!         $cansee = false;
!         $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
!         if (has_capability('moodle/site:doanything', $context)){
!             $cansee = true; 
          }
!         return $cansee;
!     }
!     function hash(){
!         $cap = "mod/filter:censor";
!         $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
!         if (has_capability('moodle/site:doanything', $context)){
!             $cap = "mod/filter:seecensor";
          }
+         return $cap;
      }
+     function dofilter($text){
+         static $words;
+         global $CFG;
  
!         if (!isset($CFG->filter_censor_badwords)) {
!             set_config( 'filter_censor_badwords','' );
!         }
  
+         if (empty($words)) {
+             $words = array();
+             if (empty($CFG->filter_censor_badwords)) {
+                 $badwords = explode(',',get_string('badwords','censor') );
+             }
+             else {
+                 $badwords = explode(',', $CFG->filter_censor_badwords );
+             }
+             foreach ($badwords as $badword) {
+                 $badword = trim($badword);
+                 if($this->canseecensor()){
+                     $words[] = new filterobject($badword, '<span
+                             title"'.$badword.'">', '</span>', false,
+                             false, $badword);
+                 } else {
+                     $words[] = new filterobject($badword, '<span
+                             class="censoredtext"
+                             title="'.$badword.'">', '</span>', 
+                                                 false, false, str_pad('',strlen($badword),'*'));
+                 }
+             }
+         }
+         return filter_phrases($text, $words);
+     }
+ }
  
  ?>
Index: emailprotect/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/emailprotect/filter.php,v
retrieving revision 1.2
diff -c -r1.2 filter.php
*** emailprotect/filter.php	30 Mar 2007 21:10:15 -0000	1.2
--- emailprotect/filter.php	17 Jun 2008 08:07:08 -0000
***************
*** 1,43 ****
  <?PHP // $Id: filter.php,v 1.2 2007/03/30 21:10:15 skodak Exp $
!       // This function looks for email addresses in Moodle text and 
        // hides them using the Moodle obfuscate_text function. 
        // Original code by Mike Churchward
  
! function emailprotect_filter($courseid, $text) {
! 
!     
!     if (!empty($CFG->formatstring)) {
!         return $text;
      }
!                                             
! /// Do a quick check using stripos to avoid unnecessary work
!     if (strpos($text, '@') === false) {
          return $text;
      }
- 
- /// There might be an email in here somewhere so continue ...
-     $matches = array();
- 
- /// regular expression to define a standard email string.
-     $emailregex = '((?:[\w\.\-])+\@(?:(?:[a-zA-Z\d\-])+\.)+(?:[a-zA-Z\d]{2,4}))';
- 
- /// pattern to find a mailto link with the linked text.
-     $pattern = '|(<a\s+href\s*=\s*[\'"]?mailto:)'.$emailregex.'([\'"]?\s*>)'.'(.*)'.'(</a>)|iU';
-     $text = preg_replace_callback($pattern, 'alter_mailto', $text);
- 
- /// pattern to find any other email address in the text.
-     $pattern = '/(^|\s+|>)'.$emailregex.'($|\s+|\.\s+|\.$|<)/i';
-     $text = preg_replace_callback($pattern, 'alter_email', $text);
- 
-     return $text;
  }
  
- 
  function alter_email($matches) {
      return $matches[1].obfuscate_text($matches[2]).$matches[3];
  }
  
- 
  function alter_mailto($matches) {
      return obfuscate_mailto($matches[2], $matches[4]);
  }
--- 1,44 ----
  <?PHP // $Id: filter.php,v 1.2 2007/03/30 21:10:15 skodak Exp $
!       // This class looks for email addresses in Moodle text and 
        // hides them using the Moodle obfuscate_text function. 
        // Original code by Mike Churchward
  
! class emailprotect_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
      }
!     function dofilter($text){
!         if (!empty($CFG->formatstring)) {
!             return $text;
!         }
!                                                 
!     /// Do a quick check using stripos to avoid unnecessary work
!         if (strpos($text, '@') === false) {
!             return $text;
!         }
! 
!     /// There might be an email in here somewhere so continue ...
!         $matches = array();
! 
!     /// regular expression to define a standard email string.
!         $emailregex = '((?:[\w\.\-])+\@(?:(?:[a-zA-Z\d\-])+\.)+(?:[a-zA-Z\d]{2,4}))';
! 
!     /// pattern to find a mailto link with the linked text.
!         $pattern = '|(<a\s+href\s*=\s*[\'"]?mailto:)'.$emailregex.'([\'"]?\s*>)'.'(.*)'.'(</a>)|iU';
!         $text = preg_replace_callback($pattern, 'alter_mailto', $text);
! 
!     /// pattern to find any other email address in the text.
!         $pattern = '/(^|\s+|>)'.$emailregex.'($|\s+|\.\s+|\.$|<)/i';
!         $text = preg_replace_callback($pattern, 'alter_email', $text);
! 
          return $text;
      }
  }
  
  function alter_email($matches) {
      return $matches[1].obfuscate_text($matches[2]).$matches[3];
  }
  
  function alter_mailto($matches) {
      return obfuscate_mailto($matches[2], $matches[4]);
  }
Index: mediaplugin/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/mediaplugin/filter.php,v
retrieving revision 1.42
diff -c -r1.42 filter.php
*** mediaplugin/filter.php	19 Dec 2007 17:35:26 -0000	1.42
--- mediaplugin/filter.php	17 Jun 2008 08:07:08 -0000
***************
*** 17,101 ****
  
  require_once($CFG->libdir.'/filelib.php');
  
  
! function mediaplugin_filter($courseid, $text) {
!     global $CFG;
!     static $eolas_fix_applied = false;
! 
!     // You should never modify parameters passed to a method or function, it's BAD practice. Create a copy instead.
!     // The reason is that you must always be able to refer to the original parameter that was passed.
!     // For this reason, I changed $text = preg_replace(..,..,$text) into $newtext = preg.... (NICOLAS CONNAULT)
!     // Thanks to Pablo Etcheverry for pointing this out! MDL-10177
! 
!     // We're using the UFO technique for flash to attain XHTML Strict 1.0
!     // See: http://www.bobbyvandersluis.com/ufo/
!     if (!is_string($text)) {
!         // non string data can not be filtered anyway
!         return $text;
!     }
!     $newtext = $text; // fullclone is slow and not needed here
! 
!     if ($CFG->filter_mediaplugin_enable_mp3) {
!         $search = '/<a.*?href="([^<]+\.mp3)"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_swf) {
!         $search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_flv) {
!         $search = '/<a.*?href="([^<]+\.flv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_mov) {
!         $search = '/<a.*?href="([^<]+\.mov)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_wmv) {
!         $search = '/<a.*?href="([^<]+\.wmv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_mpg) {
!         $search = '/<a.*?href="([^<]+\.mpe?g)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_avi) {
!         $search = '/<a.*?href="([^<]+\.avi)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_ram) {
!         $search = '/<a.*?href="([^<]+\.ram)"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
!     }
! 
!     if ($CFG->filter_mediaplugin_enable_rpm) {
!         $search = '/<a.*?href="([^<]+\.rpm)"[^>]*>.*?<\/a>/is';
!         $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
      }
- 
-     if ($CFG->filter_mediaplugin_enable_rm) {
-         $search = '/<a.*?href="([^<]+\.rm)"[^>]*>.*?<\/a>/is';
-         $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
-     }
- 
-     if (is_null($newtext) or $newtext === $text) {
-         // error or not filtered
-         return $text;
-     }
-     
-     if (!$eolas_fix_applied) {
-         $newtext .= '<script defer="defer" src="' . $CFG->wwwroot . '/filter/mediaplugin/eolas_fix.js" type="text/javascript">// <![CDATA[ ]]></script>';
-         $eolas_fix_applied = true;
-     }
- 
-     return $newtext;
  }
  
  ///===========================
--- 17,105 ----
  
  require_once($CFG->libdir.'/filelib.php');
  
+ class mediaplugin_filter extends filter_base{
+     private $eolas_fix_applied;
+     function __construct($courseid, $format, $options){
+         parent::__construct($courseid, $format, $options);
+         $this->eolas_fix_applied = false;
+     }
+     function dofilter($text){
+         global $CFG;
+         // You should never modify parameters passed to a method or function, it's BAD practice. Create a copy instead.
+         // The reason is that you must always be able to refer to the original parameter that was passed.
+         // For this reason, I changed $text = preg_replace(..,..,$text) into $newtext = preg.... (NICOLAS CONNAULT)
+         // Thanks to Pablo Etcheverry for pointing this out! MDL-10177
+ 
+         // We're using the UFO technique for flash to attain XHTML Strict 1.0
+         // See: http://www.bobbyvandersluis.com/ufo/
+         if (!is_string($text)) {
+             // non string data can not be filtered anyway
+             return $text;
+         }
+         $newtext = $text; // fullclone is slow and not needed here
+ 
+         if ($CFG->filter_mediaplugin_enable_mp3) {
+             $search = '/<a.*?href="([^<]+\.mp3)"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_mp3_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_swf) {
+             $search = '/<a.*?href="([^<]+\.swf)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_swf_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_flv) {
+             $search = '/<a.*?href="([^<]+\.flv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_flv_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_mov) {
+             $search = '/<a.*?href="([^<]+\.mov)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_wmv) {
+             $search = '/<a.*?href="([^<]+\.wmv)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_mpg) {
+             $search = '/<a.*?href="([^<]+\.mpe?g)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_qt_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_avi) {
+             $search = '/<a.*?href="([^<]+\.avi)(\?d=([\d]{1,3}%?)x([\d]{1,3}%?))?"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_wmp_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_ram) {
+             $search = '/<a.*?href="([^<]+\.ram)"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_rpm) {
+             $search = '/<a.*?href="([^<]+\.rpm)"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
+         }
+ 
+         if ($CFG->filter_mediaplugin_enable_rm) {
+             $search = '/<a.*?href="([^<]+\.rm)"[^>]*>.*?<\/a>/is';
+             $newtext = preg_replace_callback($search, 'mediaplugin_filter_real_callback', $newtext);
+         }
+ 
+         if (is_null($newtext) or $newtext === $text) {
+             // error or not filtered
+             return $text;
+         }
+         
+         if (!$this->eolas_fix_applied) {
+             $newtext .= '<script defer="defer" src="' . $CFG->wwwroot . '/filter/mediaplugin/eolas_fix.js" type="text/javascript">// <![CDATA[ ]]></script>';
+             $this->eolas_fix_applied = true;
+         }
  
!         return $newtext;
      }
  }
  
  ///===========================
Index: multilang/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/multilang/filter.php,v
retrieving revision 1.20
diff -c -r1.20 filter.php
*** multilang/filter.php	19 Jun 2007 17:24:34 -0000	1.20
--- multilang/filter.php	17 Jun 2008 08:07:09 -0000
***************
*** 36,67 ****
  // Following new syntax is not compatible with old one:
  //   <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
  
! function multilang_filter($courseid, $text) {
!     global $CFG;
! 
!     // [pj] I don't know about you but I find this new implementation funny :P
!     // [skodak] I was laughing while rewriting it ;-)
!     // [nicolasconnault] Should support inverted attributes: <span class="multilang" lang="en"> (Doesn't work curently)
!     // [skodak] it supports it now, though it is slower - any better idea? 
! 
!     if (empty($text) or is_numeric($text)) {
!         return $text;
!     }
! 
!     if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
!         // new syntax
!         $search = '/(<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)(\s*<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)+/is';
!     } else {
!         // old syntax
!         $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)+/is';
!     }
! 
!     $result = preg_replace_callback($search, 'multilang_filter_impl', $text);
! 
!     if (is_null($result)) {
!         return $text; //error during regex processing (too many nested spans?)
!     } else {
!         return $result;
      }
  }
  
--- 36,73 ----
  // Following new syntax is not compatible with old one:
  //   <span lang="XX" class="multilang">one lang</span><span lang="YY" class="multilang">another language</span>
  
! class multilang_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
!     }
! 
!     function dofilter($text) {
!         global $CFG;
! 
!         // [pj] I don't know about you but I find this new implementation funny :P
!         // [skodak] I was laughing while rewriting it ;-)
!         // [nicolasconnault] Should support inverted attributes: <span class="multilang" lang="en"> (Doesn't work curently)
!         // [skodak] it supports it now, though it is slower - any better idea? 
! 
!         if (empty($text) or is_numeric($text)) {
!             return $text;
!         }
! 
!         if (empty($CFG->filter_multilang_force_old) and !empty($CFG->filter_multilang_converted)) {
!             // new syntax
!             $search = '/(<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)(\s*<span(\s+lang="[a-zA-Z0-9_-]+"|\s+class="multilang"){2}\s*>.*?<\/span>)+/is';
!         } else {
!             // old syntax
!             $search = '/(<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)(\s*<(?:lang|span) lang="[a-zA-Z0-9_-]*".*?>.*?<\/(?:lang|span)>)+/is';
!         }
! 
!         $result = preg_replace_callback($search, 'multilang_filter_impl', $text);
! 
!         if (is_null($result)) {
!             return $text; //error during regex processing (too many nested spans?)
!         } else {
!             return $result;
!         }
      }
  }
  
Index: tex/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/tex/filter.php,v
retrieving revision 1.23
diff -c -r1.23 filter.php
*** tex/filter.php	2 Jun 2008 08:47:10 -0000	1.23
--- tex/filter.php	17 Jun 2008 08:07:09 -0000
***************
*** 91,103 ****
      return $output;
  }
  
! function tex_filter ($courseid, $text) {
!     global $CFG, $DB;
! 
!     /// Do a quick check using stripos to avoid unnecessary work
!     if (!preg_match('/<tex/i',$text) and !strstr($text,'$$') and !strstr($text,'\\[') and !preg_match('/\[tex/i',$text)) { //added one more tag (dlnsk)
!         return $text;
      }
  
  #    //restrict filtering to forum 130 (Maths Tools on moodle.org)
  #    $scriptname = $_SERVER['SCRIPT_NAME'];
--- 91,108 ----
      return $output;
  }
  
! class tex_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
      }
+     function dofilter ($text) {
+ 
+         global $CFG, $DB;
+ 
+         /// Do a quick check using stripos to avoid unnecessary work
+         if (!preg_match('/<tex/i',$text) and !strstr($text,'$$') and !strstr($text,'\\[') and !preg_match('/\[tex/i',$text)) { //added one more tag (dlnsk)
+             return $text;
+         }
  
  #    //restrict filtering to forum 130 (Maths Tools on moodle.org)
  #    $scriptname = $_SERVER['SCRIPT_NAME'];
***************
*** 115,162 ****
  #    if ($discussion->forum != 130) {
  #        return $text;
  #    }
!     $text .= ' ';
!     preg_match_all('/\$(\$\$+?)([^\$])/s',$text,$matches);
!     for ($i=0;$i<count($matches[0]);$i++) {
!         $replacement = str_replace('$','&#x00024;',$matches[1][$i]).$matches[2][$i];
!         $text = str_replace($matches[0][$i],$replacement,$text);
!     }
! 
!     // <tex> TeX expression </tex>
!     // or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
!     // or $$ TeX expression $$
!     // or \[ TeX expression \]          // original tag of MathType and TeXaide (dlnsk)
!     // or [tex] TeX expression [/tex]   // somtime it's more comfortable than <tex> (dlnsk)
!     preg_match_all('/<tex(?:\s+alt=["\'](.*?)["\'])?>(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches);
!     for ($i=0; $i<count($matches[0]); $i++) {
!         $texexp = $matches[2][$i] . $matches[3][$i] . $matches[4][$i] . $matches[5][$i];
!         $alt = $matches[1][$i];
!         $texexp = str_replace('<nolink>','',$texexp);
!         $texexp = str_replace('</nolink>','',$texexp);
!         $texexp = str_replace('<span class="nolink">','',$texexp);
!         $texexp = str_replace('</span>','',$texexp);
!         $texexp = eregi_replace("<br[[:space:]]*\/?>", '', $texexp);  //dlnsk
!         $align = "middle";
!         if (preg_match('/^align=bottom /',$texexp)) {
!           $align = "text-bottom";
!           $texexp = preg_replace('/^align=bottom /','',$texexp);
!         } else if (preg_match('/^align=top /',$texexp)) {
!           $align = "text-top";
!           $texexp = preg_replace('/^align=top /','',$texexp);
          }
!         $md5 = md5($texexp);
!         if (! $texcache = $DB->get_record("cache_filters", array("filter"=>"tex", "md5key"=>$md5))) {
!             $texcache->filter = 'tex';
!             $texcache->version = 1;
!             $texcache->md5key = $md5;
!             $texcache->rawtext = $texexp;
!             $texcache->timemodified = time();
!             $DB->insert_record("cache_filters",$texcache, false);
          }
!         $filename = $md5 . ".gif";
!         $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text);
      }
-     return $text;
  }
  
  ?>
--- 120,168 ----
  #    if ($discussion->forum != 130) {
  #        return $text;
  #    }
!         $text .= ' ';
!         preg_match_all('/\$(\$\$+?)([^\$])/s',$text,$matches);
!         for ($i=0;$i<count($matches[0]);$i++) {
!             $replacement = str_replace('$','&#x00024;',$matches[1][$i]).$matches[2][$i];
!             $text = str_replace($matches[0][$i],$replacement,$text);
          }
! 
!         // <tex> TeX expression </tex>
!         // or <tex alt="My alternative text to be used instead of the TeX form"> TeX expression </tex>
!         // or $$ TeX expression $$
!         // or \[ TeX expression \]          // original tag of MathType and TeXaide (dlnsk)
!         // or [tex] TeX expression [/tex]   // somtime it's more comfortable than <tex> (dlnsk)
!         preg_match_all('/<tex(?:\s+alt=["\'](.*?)["\'])?>(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches);
!         for ($i=0; $i<count($matches[0]); $i++) {
!             $texexp = $matches[2][$i] . $matches[3][$i] . $matches[4][$i] . $matches[5][$i];
!             $alt = $matches[1][$i];
!             $texexp = str_replace('<nolink>','',$texexp);
!             $texexp = str_replace('</nolink>','',$texexp);
!             $texexp = str_replace('<span class="nolink">','',$texexp);
!             $texexp = str_replace('</span>','',$texexp);
!             $texexp = eregi_replace("<br[[:space:]]*\/?>", '', $texexp);  //dlnsk
!             $align = "middle";
!             if (preg_match('/^align=bottom /',$texexp)) {
!               $align = "text-bottom";
!               $texexp = preg_replace('/^align=bottom /','',$texexp);
!             } else if (preg_match('/^align=top /',$texexp)) {
!               $align = "text-top";
!               $texexp = preg_replace('/^align=top /','',$texexp);
!             }
!             $md5 = md5($texexp);
!             if (! $texcache = $DB->get_record("cache_filters", array("filter"=>"tex", "md5key"=>$md5))) {
!                 $texcache->filter = 'tex';
!                 $texcache->version = 1;
!                 $texcache->md5key = $md5;
!                 $texcache->rawtext = $texexp;
!                 $texcache->timemodified = time();
!                 $DB->insert_record("cache_filters", $texcache, false);
!             }
!             $filename = $md5 . ".gif";
!             $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text);
          }
!         return $text;
      }
  }
  
  ?>
Index: tidy/filter.php
===================================================================
RCS file: /cvsroot/moodle/moodle/filter/tidy/filter.php,v
retrieving revision 1.2
diff -c -r1.2 filter.php
*** tidy/filter.php	3 Apr 2007 08:43:30 -0000	1.2
--- tidy/filter.php	17 Jun 2008 08:07:09 -0000
***************
*** 1,6 ****
  <?php
        
! // This function looks for text including markup and
  // applies tidy's repair function to it.
  // Tidy is a HTML clean and
  // repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
--- 1,6 ----
  <?php
        
! // This class looks for text including markup and
  // applies tidy's repair function to it.
  // Tidy is a HTML clean and
  // repair utility, which is currently available for PHP 4.3.x and PHP 5 as a
***************
*** 11,47 ****
  // If you want to know what you can set in $tidyoptions and what their default
  // values are, see http://php.net/manual/en/function.tidy-get-config.php.
        
! /**
! * @author Hannes Gassert <hannes at mediagonal dot ch>
! * @param        int            course id
! * @param        string         text to be filtered
! */
! function tidy_filter($courseid, $text) {
!        
! /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
! /// proprietary markup.
!     $tidyoptions = array(             
!              'output-xhtml' => true,
!              'show-body-only' => true,
!              'tidy-mark' => false,
!              'drop-proprietary-attributes' => true,
!              'drop-font-tags' => true,
!              'drop-empty-paras' => true,
!              'indent' => true,
!              'quiet' => true,
!     );
!     
! /// Do a quick check using strpos to avoid unnecessary work
!     if (strpos($text, '<') === false) {
!         return $text;
      }
  
!     
! /// If enabled: run tidy over the entire string
!     if (function_exists('tidy_repair_string')){
!         $text = tidy_repair_string($text, $tidyoptions, 'utf8');
!     }
  
!     return $text;
  }
  ?>
--- 11,52 ----
  // If you want to know what you can set in $tidyoptions and what their default
  // values are, see http://php.net/manual/en/function.tidy-get-config.php.
        
! class tidy_filter extends filter_base{
!     function __construct($courseid, $format, $options){
!         parent::__construct($courseid, $format, $options);
      }
  
!     /**
!     * @author Hannes Gassert <hannes at mediagonal dot ch>
!     * @param        string         text to be filtered
!     */
!     function dofilter($text) {
!            
!     /// Configuration for tidy. Feel free to tune for your needs, e.g. to allow
!     /// proprietary markup.
!         $tidyoptions = array(             
!                  'output-xhtml' => true,
!                  'show-body-only' => true,
!                  'tidy-mark' => false,
!                  'drop-proprietary-attributes' => true,
!                  'drop-font-tags' => true,
!                  'drop-empty-paras' => true,
!                  'indent' => true,
!                  'quiet' => true,
!         );
!         
!     /// Do a quick check using strpos to avoid unnecessary work
!         if (strpos($text, '<') === false) {
!             return $text;
!         }
! 
!         
!     /// If enabled: run tidy over the entire string
!         if (function_exists('tidy_repair_string')){
!             $text = tidy_repair_string($text, $tidyoptions, 'utf8');
!         }
  
!         return $text;
!     }
  }
  ?>
