Fix for case when $CFG->dirroot contains spaces, especially for Windows
This commit is contained in:
@@ -163,6 +163,19 @@ function outputText($texexp) {
|
||||
|
||||
function tex2image($texexp, $md5) {
|
||||
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;
|
||||
@@ -175,22 +188,29 @@ function tex2image($texexp, $md5) {
|
||||
if (file_exists($pathname)) {
|
||||
unlink($pathname);
|
||||
}
|
||||
$windows = 0;
|
||||
$commandpath = "";
|
||||
$cmd = "";
|
||||
switch (PHP_OS) {
|
||||
case "Linux":
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
|
||||
$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":
|
||||
$windows = 1;
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
|
||||
$commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = str_replace(' ','^ ',$commandpath);
|
||||
$cmd .= " ++ -e \"$pathname\" \"$texexp\"";
|
||||
break;
|
||||
case "Darwin":
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
|
||||
$commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
|
||||
$cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
}
|
||||
if (!$cmd) {
|
||||
error($error_message1);
|
||||
}
|
||||
system($cmd, $status);
|
||||
}
|
||||
if ($texexp && file_exists($pathname)) {
|
||||
@@ -204,10 +224,8 @@ function tex2image($texexp, $md5) {
|
||||
header("Content-type: $filetype");
|
||||
readfile("$pathname");
|
||||
} else {
|
||||
if (!$windows) {
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br>\n";
|
||||
}
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br>\n";
|
||||
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
|
||||
if ($status == 4) {
|
||||
echo "Status corresponds to illegal instruction<br>\n";
|
||||
@@ -216,6 +234,15 @@ function tex2image($texexp, $md5) {
|
||||
} else if ($status == 22) {
|
||||
echo "Status corresponds to abnormal termination<br>\n";
|
||||
}
|
||||
if (file_exists($commandpath)) {
|
||||
echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br>";
|
||||
$handle = fopen($commandpath,"rb");
|
||||
$contents = fread($handle,16384);
|
||||
fclose($handle);
|
||||
echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br>";
|
||||
} else {
|
||||
echo "mimetex executable $commandpath not found!<br>";
|
||||
}
|
||||
echo "Image not found!";
|
||||
}
|
||||
}
|
||||
@@ -224,17 +251,6 @@ function tex2image($texexp, $md5) {
|
||||
<html>
|
||||
<head><title>Algebra Filter Debugger</title></head>
|
||||
<body>
|
||||
<?PHP
|
||||
require_once("../../config.php");
|
||||
$filename = "$CFG->dirroot/filter/algebra/pix.php";
|
||||
$PHP_OS = PHP_OS;
|
||||
$handle = fopen($filename,"r");
|
||||
$contents = fread($handle, filesize($filename));
|
||||
fclose($handle);
|
||||
if (!strpos($contents,'case "'. $PHP_OS . '":')) {
|
||||
echo "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
|
||||
}
|
||||
?>
|
||||
<p>Please enter an algebraic expression <b>without</b> any surrounding @@ into
|
||||
the text box below. (Click <a href="#help">here for help.</a>)
|
||||
<form action="algebradebug.php" method="get"
|
||||
|
||||
+19
-16
@@ -49,30 +49,32 @@
|
||||
$texexp = '\Large ' . $texexp;
|
||||
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\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
case "WINNT":
|
||||
case "WIN32":
|
||||
case "Windows":
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
|
||||
$cmd = str_replace(' ','^ ',$cmd);
|
||||
$cmd .= " ++ -e \"$pathname\" \"$texexp\"";
|
||||
break;
|
||||
case "Darwin":
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
|
||||
break;
|
||||
default: /// To allow drop-in binaries for other platforms
|
||||
if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
|
||||
echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
|
||||
echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
|
||||
echo "and that it has the right permissions set on it as executable program.\n\n";
|
||||
echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n";
|
||||
echo " http://moodle.org/download/mimetex/";
|
||||
exit;
|
||||
}
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
|
||||
$cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
default: /// To allow drop-in binaries for other platforms
|
||||
if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
|
||||
echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
|
||||
echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
|
||||
echo "and that it has the right permissions set on it as executable program.\n\n";
|
||||
echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n";
|
||||
echo " http://moodle.org/download/mimetex/";
|
||||
exit;
|
||||
}
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
|
||||
break;
|
||||
}
|
||||
system($cmd, $status);
|
||||
system($cmd, $status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +90,8 @@
|
||||
readfile("$pathname");
|
||||
} else {
|
||||
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
|
||||
echo "Image not found!";
|
||||
echo "Image not found!<br>";
|
||||
echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
Binary file not shown.
+8
-5
@@ -48,18 +48,20 @@
|
||||
$texexp = '\Large ' . $texexp;
|
||||
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\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
case "WINNT":
|
||||
case "WIN32":
|
||||
case "Windows":
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
|
||||
$cmd = str_replace(' ','^ ',$cmd);
|
||||
$cmd .= " ++ -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\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
default: /// To allow drop-in binaries for other platforms
|
||||
default: /// To allow drop-in binaries for other platforms
|
||||
if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
|
||||
echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
|
||||
echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
|
||||
@@ -87,7 +89,8 @@
|
||||
readfile("$pathname");
|
||||
} else {
|
||||
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
|
||||
echo "Image not found!";
|
||||
echo "Image not found!<br>";
|
||||
echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a>";
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
+38
-22
@@ -74,6 +74,19 @@ function outputText($texexp) {
|
||||
|
||||
function tex2image($texexp) {
|
||||
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/tex/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 texdebug.php file.";
|
||||
|
||||
if ($texexp) {
|
||||
$texexp = '\Large ' . $texexp;
|
||||
$lifetime = 86400;
|
||||
@@ -86,22 +99,29 @@ function tex2image($texexp) {
|
||||
if (file_exists($pathname)) {
|
||||
unlink($pathname);
|
||||
}
|
||||
$windows = 0;
|
||||
$commandpath = "";
|
||||
$cmd = "";
|
||||
switch (PHP_OS) {
|
||||
case "Linux":
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
|
||||
$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":
|
||||
$windows = 1;
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
|
||||
$commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
|
||||
$texexp = str_replace('"','\"',$texexp);
|
||||
$cmd = str_replace(' ','^ ',$commandpath);
|
||||
$cmd .= " ++ -e \"$pathname\" \"$texexp\"";
|
||||
break;
|
||||
case "Darwin":
|
||||
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
|
||||
$commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
|
||||
$cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
|
||||
break;
|
||||
}
|
||||
if (!$cmd) {
|
||||
error($error_message1);
|
||||
}
|
||||
system($cmd, $status);
|
||||
}
|
||||
if ($texexp && file_exists($pathname)) {
|
||||
@@ -115,10 +135,8 @@ function tex2image($texexp) {
|
||||
header("Content-type: $filetype");
|
||||
readfile("$pathname");
|
||||
} else {
|
||||
if (!$windows) {
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br>\n";
|
||||
}
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br>\n";
|
||||
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
|
||||
if ($status == 4) {
|
||||
echo "Status corresponds to illegal instruction<br>\n";
|
||||
@@ -127,6 +145,15 @@ function tex2image($texexp) {
|
||||
} else if ($status == 22) {
|
||||
echo "Status corresponds to abnormal termination<br>\n";
|
||||
}
|
||||
if (file_exists($commandpath)) {
|
||||
echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br>";
|
||||
$handle = fopen($commandpath,"rb");
|
||||
$contents = fread($handle,16384);
|
||||
fclose($handle);
|
||||
echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br>";
|
||||
} else {
|
||||
echo "mimetex executable $commandpath not found!<br>";
|
||||
}
|
||||
echo "Image not found!";
|
||||
}
|
||||
}
|
||||
@@ -135,24 +162,13 @@ function tex2image($texexp) {
|
||||
<html>
|
||||
<head><title>TeX Filter Debugger</title></head>
|
||||
<body>
|
||||
<?PHP
|
||||
require_once("../../config.php");
|
||||
$filename = "$CFG->dirroot/filter/tex/pix.php";
|
||||
$PHP_OS = PHP_OS;
|
||||
$handle = fopen($filename,"r");
|
||||
$contents = fread($handle, filesize($filename));
|
||||
fclose($handle);
|
||||
if (!strpos($contents,'case "'. $PHP_OS . '":')) {
|
||||
echo "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
|
||||
}
|
||||
?>
|
||||
<p>Please enter an algebraic expression <b>without</b> any surrounding $$ into
|
||||
the text box below. (Click <a href="#help">here for help.</a>)
|
||||
<form action="texdebug.php" method="get"
|
||||
target="inlineframe">
|
||||
<center>
|
||||
<input type="text" name="tex" size=50
|
||||
value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
|
||||
value="f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
|
||||
</center>
|
||||
<ol>
|
||||
<li>First click on this button <input type="submit" name="ShowDB" value="Show DB Entry">
|
||||
|
||||
Reference in New Issue
Block a user