1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
<?PHP // $Id: texed.php,v 1.4.10.1 2006/08/14 06:22:15 skodak Exp $
// This function fetches math. images from the data directory
// If not, it obtains the corresponding TeX expression from the cache_tex db table
// and uses mimeTeX to create the image file
$nomoodlecookie = true; // Because it interferes with caching
require_once("../../config.php");
if (empty($CFG->textfilters)) {
error ('Filter not enabled!');
} else {
$filters = explode(',', $CFG->textfilters);
if (array_search('filter/tex', $filters) === FALSE) {
error ('Filter not enabled!');
}
}
$CFG->texfilterdir = "filter/tex";
$CFG->teximagedir = "filter/tex";
error_reporting(E_ALL);
$texexp = urldecode($_SERVER['QUERY_STRING']);
$texexp = str_replace('formdata=','',$texexp);
if ($texexp) {
//$texexp = stripslashes($texexp);
$lifetime = 86400;
$image = md5($texexp) . ".gif";
$filetype = 'image/gif';
if (!file_exists("$CFG->dataroot/$CFG->teximagedir")) {
make_upload_directory($CFG->teximagedir);
}
$pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
switch (PHP_OS) {
case "Linux":
system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- ". escapeshellarg($texexp) );
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname -- \"$texexp\"");
break;
case "Darwin":
system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- ". escapeshellarg($texexp) );
break;
}
if (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");
header("Cache-control: max_age = $lifetime"); // a day
header("Pragma: ");
header("Content-disposition: inline; filename=$image");
header("Content-length: ".filesize($pathname));
header("Content-type: $filetype");
readfile("$pathname");
} else {
echo "Image not found!";
}
exit;
}
?>
<html>
<head><title>mimeTeX Previewer</title></head>
<body>
<p>Now enter your own expression or use the sample provided,
press the Submit button, and mimeTeX's rendering should be
displayed in the little window immediately below it.
<center>
<form action="texed.php" method="get"
target="inlineframe">
<input type="text" name="formdata" size="50"
value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
<input type="submit">
</form> <br /> <br />
<iframe name="inlineframe" align="middle" width="80%" height="100">
<p>Something is wrong...</p>
</iframe>
</center> <br />
</body>
</html>
|