adding some strings
[moodle-linuxchix.git] / filter / tex / texed.php
blobbbb3c0a46f2c324c975ff484be55db516a13e157
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 if (empty($CFG->textfilters)) {
11 error ('Filter not enabled!');
12 } else {
13 $filters = explode(',', $CFG->textfilters);
14 if (array_search('filter/tex', $filters) === FALSE) {
15 error ('Filter not enabled!');
19 $CFG->texfilterdir = "filter/tex";
20 $CFG->teximagedir = "filter/tex";
22 error_reporting(E_ALL);
23 $texexp = urldecode($_SERVER['QUERY_STRING']);
24 $texexp = str_replace('formdata=','',$texexp);
26 if ($texexp) {
27 //$texexp = stripslashes($texexp);
28 $lifetime = 86400;
29 $image = md5($texexp) . ".gif";
30 $filetype = 'image/gif';
31 if (!file_exists("$CFG->dataroot/$CFG->teximagedir")) {
32 make_upload_directory($CFG->teximagedir);
34 $pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
35 $texexp = escapeshellarg($texexp);
37 switch (PHP_OS) {
38 case "Linux":
39 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- $texexp" );
40 break;
41 case "WINNT":
42 case "WIN32":
43 case "Windows":
44 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname -- $texexp");
45 break;
46 case "Darwin":
47 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- $texexp" );
48 break;
50 if (file_exists($pathname)) {
51 $lastmodified = filemtime($pathname);
52 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
53 header("Expires: " . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT");
54 header("Cache-control: max_age = $lifetime"); // a day
55 header("Pragma: ");
56 header("Content-disposition: inline; filename=$image");
57 header("Content-length: ".filesize($pathname));
58 header("Content-type: $filetype");
59 readfile("$pathname");
60 } else {
61 echo "Image not found!";
63 exit;
68 <html>
69 <head><title>mimeTeX Previewer</title></head>
70 <body>
71 <p>Now enter your own expression or use the sample provided,
72 press the Submit button, and mimeTeX's rendering should be
73 displayed in the little window immediately below it.
74 <center>
75 <form action="texed.php" method="get"
76 target="inlineframe">
77 <input type="text" name="formdata" size="50"
78 value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt" />
79 <input type="submit" />
80 </form> <br /> <br />
81 <iframe name="inlineframe" align="middle" width="80%" height="100">
82 &lt;p&gt;Something is wrong...&lt;/p&gt;
83 </iframe>
84 </center> <br />
85 </body>
86 </html>