file grademethod.html was added on branch MOODLE_15_STABLE on 2005-07-07 16:00:50...
[moodle.git] / filter / tex / texed.php
blob5d61b11935438b30818c56f1b8b4dd36b0e59c8a
1 <?PHP // $Id$
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->texfilterdir = "filter/tex";
11 $CFG->teximagedir = "filter/tex";
13 error_reporting(E_ALL);
14 $texexp = urldecode($_SERVER['QUERY_STRING']);
15 $texexp = str_replace('formdata=','',$texexp);
17 if ($texexp) {
18 //$texexp = stripslashes($texexp);
19 $lifetime = 86400;
20 $image = md5($texexp) . ".gif";
21 $filetype = 'image/gif';
22 if (!file_exists("$CFG->dataroot/$CFG->teximagedir")) {
23 make_upload_directory($CFG->teximagedir);
25 $pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
26 switch (PHP_OS) {
27 case "Linux":
28 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- ". escapeshellarg($texexp) );
29 break;
30 case "WINNT":
31 case "WIN32":
32 case "Windows":
33 $texexp = str_replace('"','\"',$texexp);
34 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname -- \"$texexp\"");
35 break;
36 case "Darwin":
37 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- ". escapeshellarg($texexp) );
38 break;
40 if (file_exists($pathname)) {
41 $lastmodified = filemtime($pathname);
42 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
43 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
44 header("Cache-control: max_age = $lifetime"); // a day
45 header("Pragma: ");
46 header("Content-disposition: inline; filename=$image");
47 header("Content-length: ".filesize($pathname));
48 header("Content-type: $filetype");
49 readfile("$pathname");
50 } else {
51 echo "Image not found!";
53 exit;
58 <html>
59 <head><title>mimeTeX Previewer</title></head>
60 <body>
61 <p>Now enter your own expression or use the sample provided,
62 press the Submit button, and mimeTeX's rendering should be
63 displayed in the little window immediately below it.
64 <center>
65 <form action="texed.php" method="get"
66 target="inlineframe">
67 <input type="text" name="formdata" size="50"
68 value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
69 <input type="submit">
70 </form> <br /> <br />
71 <iframe name="inlineframe" align="middle" width="80%" height="100">
72 &lt;p&gt;Something is wrong...&lt;/p&gt;
73 </iframe>
74 </center> <br />
75 </body>
76 </html>