Working version of algebra filter for Unix and Windows

This commit is contained in:
fiedorow 2004-02-17 03:38:48 +00:00
parent 3ce906d64d
commit 1a1de46ae2
7 changed files with 941 additions and 0 deletions

81
filter/algebra/pix.php Normal file
View file

@ -0,0 +1,81 @@
<?PHP // $Id$
// 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");
$CFG->algebrafilterdir = "filter/algebra";
$CFG->algebraimagedir = "filter/algebra";
error_reporting(E_ALL);
$lifetime = 86400;
if (isset($file)) { // workaround for situations where / syntax doesn't work
$pathinfo = '/' . $file;
} else {
$pathinfo = get_slash_arguments("pix.php");
}
if (! $args = parse_slash_arguments($pathinfo)) {
error("No valid arguments supplied");
}
$numargs = count($args);
if ($numargs == 1) {
$image = $args[0];
$pathname = "$CFG->dataroot/$CFG->algebraimagedir/$image";
$filetype = "image/gif";
} else {
error("No valid arguments supplied");
}
if (!file_exists($pathname)) {
$md5 = str_replace('.gif','',$image);
if ($texcache = get_record("cache_filters", "filter", "algebra", "md5key", $md5)) {
if (!file_exists("$CFG->dataroot/$CFG->algebraimagedir")) {
make_upload_directory($CFG->algebraimagedir);
}
$texexp = $texcache->rawtext;
$texexp = str_replace('&lt;','<',$texexp);
$texexp = str_replace('&gt;','>',$texexp);
$texexp = preg_replace('!\r\n?!',' ',$texexp);
$texexp = '\Large ' . $texexp;
switch (PHP_OS) {
case "Linux":
system("$CFG->dirroot/$CFG->algebrafilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp) );
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
system("$CFG->dirroot/$CFG->algebrafilterdir/mimetex.exe -e $pathname \"$texexp\"");
break;
case "Darwin":
system("$CFG->dirroot/$CFG->algebrafilterdir/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;
?>