]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8897 fixed shell commands in tex and algebra filters; merged from MOODLE_17_STABLE
authorskodak <skodak>
Wed, 14 Mar 2007 11:33:50 +0000 (11:33 +0000)
committerskodak <skodak>
Wed, 14 Mar 2007 11:33:50 +0000 (11:33 +0000)
filter/algebra/algebradebug.php
filter/algebra/filter.php
filter/algebra/pix.php
filter/tex/pix.php
filter/tex/texdebug.php
filter/tex/texed.php

index 75b86bad592d2a00ea57f9dbf7d9b056f4cfd738..467a22a62752a77f2b4f6dc321e386af251db258 100644 (file)
@@ -84,7 +84,7 @@
     }
 
 function algebra2tex($algebra) {
-  Global $CFG;
+  global $CFG;
   $algebra = str_replace('&lt;','<',$algebra);
   $algebra = str_replace('&gt;','>',$algebra);
   $algebra = str_replace('<>','#',$algebra);
@@ -99,9 +99,9 @@ function algebra2tex($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") ) {
-    $algebra = "\"". str_replace('"','\"',$algebra) . "\"";
     $cmd  = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl x/2";
     $test = `$cmd`;
     if ($test != '\frac{x}{2}') {
@@ -117,7 +117,6 @@ function algebra2tex($algebra) {
     }
     $cmd  = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl $algebra";
   } else {      
-    $algebra = escapeshellarg($algebra);
     $cmd  = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl x/2";
     $test = `$cmd`;
     if ($test != '\frac{x}{2}') {
@@ -206,66 +205,66 @@ function outputText($texexp) {
 }
 
 function tex2image($texexp, $md5, $return=false) {
-  global $CFG;
-  $error_message1 = "Your system is not configured to run mimeTeX. ";
-  $error_message1 .= "You need to download the appropriate<br /> executable ";
-  $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
-  $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
-  $error_message1 .= "C source<br /> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
-  $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
-  $error_message1 .= "put the executable into your<br /> moodle/filter/tex/ directory. ";
-  $error_message1 .= "You also need to edit your moodle/filter/algebra/pix.php file<br />";
-  $error_message1 .= ' by adding the line<br /><pre>       case "' . PHP_OS . "\":\n";
-  $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
-  $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
-  $error_message1 .= "</pre>You also need to add this to your algebradebug.php file.";
+    global $CFG;
+    $error_message1 = "Your system is not configured to run mimeTeX. ";
+    $error_message1 .= "You need to download the appropriate<br /> executable ";
+    $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
+    $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
+    $error_message1 .= "C source<br /> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
+    $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
+    $error_message1 .= "put the executable into your<br /> moodle/filter/tex/ directory. ";
+    $error_message1 .= "You also need to edit your moodle/filter/algebra/pix.php file<br />";
+    $error_message1 .= ' by adding the line<br /><pre>       case "' . PHP_OS . "\":\n";
+    $error_message1 .= "           \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+    $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+    $error_message1 .= "</pre>You also need to add this to your algebradebug.php file.";
 
-  if ($texexp) {
-       $texexp = '\Large ' . $texexp;
-       $lifetime = 86400;
-       $image  = $md5 . ".gif";
-       $filetype = 'image/gif';
-       if (!file_exists("$CFG->dataroot/$CFG->algebraimagedir")) {
-          make_upload_directory($CFG->algebraimagedir);
-       }
-       $pathname = "$CFG->dataroot/$CFG->algebraimagedir/$image";
-       if (file_exists($pathname)) {
-         unlink($pathname);
-       } 
-       $commandpath = "";
-       $cmd = "";
-         switch (PHP_OS) {
-       case "Linux":
-         $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux";
-         $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
-       break;
-       case "WINNT":
-       case "WIN32":
-       case "Windows":
-         $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
-         $texexp = str_replace('"','\"',$texexp);
-         $cmd = str_replace(' ','^ ',$commandpath);
-         $cmd .= " ++ -e  \"$pathname\" \"$texexp\"";
-       break;
-       case "Darwin":
-         $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
-         $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
-       break;
-       }
-       if (!$cmd) {
-         if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
-           $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex";
-           $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
-         } else {
-           error($error_message1);
-         }
-       }
-       system($cmd, $status);
-  }
-  if ($return) {
-           return $image;
-  }
-  if ($texexp && file_exists($pathname)) {
+    if ($texexp) {
+        $texexp = '\Large ' . $texexp;
+        $lifetime = 86400;
+        $image  = $md5 . ".gif";
+        $filetype = 'image/gif';
+        if (!file_exists("$CFG->dataroot/$CFG->algebraimagedir")) {
+            make_upload_directory($CFG->algebraimagedir);
+        }
+        $pathname = "$CFG->dataroot/$CFG->algebraimagedir/$image";
+        if (file_exists($pathname)) {
+            unlink($pathname);
+        
+        $commandpath = "";
+        $cmd = "";
+        $texexp = escapeshellarg($texexp);
+        switch (PHP_OS) {
+            case "Linux":
+                $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux";
+                $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" $texexp";
+            break;
+            case "WINNT":
+            case "WIN32":
+            case "Windows":
+                $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
+                $cmd = str_replace(' ','^ ',$commandpath);
+                $cmd .= " ++ -e  \"$pathname\" $texexp";
+            break;
+            case "Darwin":
+                $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
+                $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" $texexp";
+            break;
+        }
+        if (!$cmd) {
+            if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
+                $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex";
+                $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname $texexp";
+            } else {
+                error($error_message1);
+            }
+        }
+        system($cmd, $status);
+    }
+    if ($return) {
+        return $image;
+    }
+    if ($texexp && file_exists($pathname)) {
            $lastmodified = filemtime($pathname);
            header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
            header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
@@ -275,7 +274,7 @@ function tex2image($texexp, $md5, $return=false) {
            header("Content-length: ".filesize($pathname));
            header("Content-type: $filetype");
            readfile("$pathname");
-   } else {
+    } else {
            $ecmd = "$cmd 2>&1";
            echo `$ecmd` . "<br />\n";
            echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
@@ -301,7 +300,7 @@ function tex2image($texexp, $md5, $return=false) {
               echo "mimetex executable $commandpath not found!<br />";
            }
            echo "Image not found!";
-   }
+    }
 }
 
 function slasharguments($texexp, $md5) {
index 0d5e3477365bb9c52a84c16a732302b9a86f46ef..3bb480df46ea31d87fbef6d513bb1ed30843f4d1 100644 (file)
@@ -164,11 +164,10 @@ function algebra_filter ($courseid, $text) {
            $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") ) {
-              $algebra = "\"". str_replace('"','\"',$algebra) . "\"";
               $cmd  = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl $algebra";
            } else {      
-              $algebra = escapeshellarg($algebra);
               $cmd  = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl $algebra";
            }
            $texexp = `$cmd`;
index 56d81639979b0dfd55c1c4afc530614b9812fdcd..ee5eb9456a6dd93ec43d5a264dd1ab2fbb063e46 100644 (file)
             $texexp = str_replace('&gt;','>',$texexp);
             $texexp = preg_replace('!\r\n?!',' ',$texexp);
             $texexp = '\Large ' . $texexp;
+            $texexp = escapeshellarg($texexp);
 
             if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
-                $texexp = str_replace('"','\"',$texexp);
                 $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
                 $cmd = str_replace(' ','^ ',$cmd);
-                $cmd .= " ++ -e  \"$pathname\" -- \"$texexp\"";
+                $cmd .= " ++ -e  \"$pathname\" -- $texexp";
             } else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
 
-                $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- ". escapeshellarg($texexp);
+                $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- $texexp";
 
             } else {                                                           /// Auto-detect the right TeX binary
                 switch (PHP_OS) {
 
                     case "Linux":
-                        $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- ". escapeshellarg($texexp);
+                        $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- $texexp";
                     break;
 
                     case "Darwin":
-                        $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- ". escapeshellarg($texexp);
+                        $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- $texexp";
                     break;
 
                     default:      /// Nothing was found, so tell them how to fix it.
index b98d5fedd55adc001960f119d012cd935fc3eca9..66d39c67516622ddca64ea3f74b2270038196887 100644 (file)
                 $texexp = str_replace('&gt;','>',$texexp);
                 $texexp = preg_replace('!\r\n?!',' ',$texexp);
                 $texexp = '\Large ' . $texexp;
+                $texexp = escapeshellarg($texexp);
 
                 if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
-                    $texexp = str_replace('"','\"',$texexp);
                     $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
                     $cmd = str_replace(' ','^ ',$cmd);
-                    $cmd .= " ++ -e  \"$pathname\" -- \"$texexp\"";
+                    $cmd .= " ++ -e  \"$pathname\" -- $texexp";
                 } else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
 
-                    $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- ". escapeshellarg($texexp);
+                    $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- $texexp";
 
                 } else {                                                           /// Auto-detect the right TeX binary
                     switch (PHP_OS) {
 
                         case "Linux":
-                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- ". escapeshellarg($texexp);
+                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- $texexp";
                         break;
 
                         case "Darwin":
-                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- ". escapeshellarg($texexp);
+                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- $texexp";
                         break;
 
                         case "FreeBSD":
-                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.freebsd\" -e \"$pathname\" ". escapeshellarg($texexp);
+                            $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.freebsd\" -e \"$pathname\" $texexp";
                         break;
 
                         default:      /// Nothing was found, so tell them how to fix it.
index 6120f8c15770e6643b24f48dfe6e9e3feabeb46c..97fe91ad4e2a7e4c13b5a076169d22d72e731e2a 100644 (file)
             }
             $commandpath = "";
             $cmd = "";
+            $texexp = escapeshellarg($texexp);
             switch (PHP_OS) {
                 case "Linux":
                     $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux";           
-                $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
+                    $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" $texexp";
                 break;
                 case "WINNT":
-                    case "WIN32":
-                    case "Windows":
+                case "WIN32":
+                case "Windows":
                     $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
-                $texexp = str_replace('"','\"',$texexp);
-                $cmd = str_replace(' ','^ ',$commandpath);
-                $cmd .= " ++ -e  \"$pathname\" \"$texexp\"";
+                    $cmd = str_replace(' ','^ ',$commandpath);
+                    $cmd .= " ++ -e  \"$pathname\" $texexp";
                 break;
                 case "Darwin":
                     $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
-                $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
+                    $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" $texexp";
                 break;
             }
             if (!$cmd) {
-              if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
-                $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex";
-                $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
-              } else {
-                error($error_message1);
-              }
+                if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {   /// Use the custom binary
+                    $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex";
+                    $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname $texexp";
+                } else {
+                    error($error_message1);
+                }
             }
             system($cmd, $status);
         }
index d20fa9a66f789a5bc43a65c466b3602fa8a3fec5..bbb3c0a46f2c324c975ff484be55db516a13e157 100644 (file)
             make_upload_directory($CFG->teximagedir);
         }
         $pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
+        $texexp = escapeshellarg($texexp);
+
         switch (PHP_OS) {
             case "Linux":
-                system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- ". escapeshellarg($texexp) );
+                system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- $texexp" );
             break;
             case "WINNT":
-                case "WIN32":
-                case "Windows":
-                $texexp = str_replace('"','\"',$texexp);
-            system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e  $pathname -- \"$texexp\"");
+            case "WIN32":
+            case "Windows":
+                system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e  $pathname -- $texexp");
             break;
             case "Darwin":
-                system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- ". escapeshellarg($texexp) );
+                system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- $texexp" );
             break;
         }
         if (file_exists($pathname)) {