2 // This function fetches math. images from the data directory
3 // If not, it obtains the corresponding TeX expression from the cache_tex db table
4 // and uses mimeTeX to create the image file
6 $nomoodlecookie = true; // Because it interferes with caching
8 require_once("../../config.php");
10 $CFG->algebrafilterdir
= "filter/algebra";
11 $CFG->texfilterdir
= "filter/tex";
12 $CFG->algebraimagedir
= "filter/algebra";
14 error_reporting(E_ALL
);
17 if (isset($file)) { // workaround for situations where / syntax doesn't work
18 $pathinfo = '/' . $file;
20 $pathinfo = get_slash_arguments("pix.php");
23 if (! $args = parse_slash_arguments($pathinfo)) {
24 error("No valid arguments supplied");
27 $numargs = count($args);
31 $pathname = "$CFG->dataroot/$CFG->algebraimagedir/$image";
32 $filetype = "image/gif";
34 error("No valid arguments supplied");
38 if (!file_exists($pathname)) {
39 $md5 = str_replace('.gif','',$image);
40 if ($texcache = get_record("cache_filters", "filter", "algebra", "md5key", $md5)) {
41 if (!file_exists("$CFG->dataroot/$CFG->algebraimagedir")) {
42 make_upload_directory($CFG->algebraimagedir
);
45 $texexp = $texcache->rawtext
;
46 $texexp = str_replace('<','<',$texexp);
47 $texexp = str_replace('>','>',$texexp);
48 $texexp = preg_replace('!\r\n?!',' ',$texexp);
49 $texexp = '\Large ' . $texexp;
52 $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
57 $texexp = str_replace('"','\"',$texexp);
58 $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
59 $cmd = str_replace(' ','^ ',$cmd);
60 $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
63 $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
65 default: /// To allow drop-in binaries for other platforms
66 if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
67 echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
68 echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
69 echo "and that it has the right permissions set on it as executable program.\n\n";
70 echo "You can get the latest binaries for your ".PHP_OS
." platform from: \n\n";
71 echo " http://moodle.org/download/mimetex/";
74 $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
77 system($cmd, $status);
81 if (file_exists($pathname)) {
82 $lastmodified = filemtime($pathname);
83 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
84 header("Expires: " . gmdate("D, d M Y H:i:s", time() +
$lifetime) . " GMT");
85 header("Cache-control: max_age = $lifetime"); // a day
87 header("Content-disposition: inline; filename=$image");
88 header("Content-length: ".filesize($pathname));
89 header("Content-type: $filetype");
90 readfile("$pathname");
92 echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
93 echo "Image not found!<br>";
94 echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";