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!');
13 $filters = explode(',', $CFG->textfilters
);
14 if (array_search('filter/algebra', $filters) === FALSE) {
15 error ('Filter not enabled!');
19 // disable moodle specific debug messages
22 require_once($CFG->libdir
.'/filelib.php');
24 $CFG->texfilterdir
= 'filter/tex';
25 $CFG->algebrafilterdir
= 'filter/algebra';
26 $CFG->algebraimagedir
= 'filter/algebra';
29 $cmd = ''; // Initialise these variables
32 //error_reporting(E_ALL);
34 $relativepath = get_file_argument('pix.php');
36 $args = explode('/', trim($relativepath, '/'));
38 if (count($args) == 1) {
40 $pathname = $CFG->dataroot
.'/'.$CFG->algebraimagedir
.'/'.$image;
42 error('No valid arguments supplied');
45 if (!file_exists($pathname)) {
46 $md5 = str_replace('.gif','',$image);
47 if ($texcache = get_record('cache_filters', 'filter', 'algebra', 'md5key', $md5)) {
48 if (!file_exists($CFG->dataroot
.'/'.$CFG->algebraimagedir
)) {
49 make_upload_directory($CFG->algebraimagedir
);
52 $texexp = $texcache->rawtext
;
53 $texexp = str_replace('<','<',$texexp);
54 $texexp = str_replace('>','>',$texexp);
55 $texexp = preg_replace('!\r\n?!',' ',$texexp);
56 $texexp = '\Large ' . $texexp;
57 $texexp = escapeshellarg($texexp);
59 if ((PHP_OS
== "WINNT") ||
(PHP_OS
== "WIN32") ||
(PHP_OS
== "Windows")) {
60 $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
61 $cmd = str_replace(' ','^ ',$cmd);
62 $cmd .= " ++ -e \"$pathname\" -- $texexp";
63 } else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { /// Use the custom binary
65 $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- $texexp";
67 } else { /// Auto-detect the right TeX binary
71 $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- $texexp";
75 $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- $texexp";
78 default: /// Nothing was found, so tell them how to fix it.
80 echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
81 echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
82 echo "and that it has the right permissions set on it as executable program.\n\n";
83 echo "You can get the latest binaries for your ".PHP_OS
." platform from: \n\n";
84 echo " http://moodle.org/download/mimetex/";
86 echo "Mimetex executable was not found,\n";
87 echo "Please turn on debug mode in site configuration to see more info here.";
93 system($cmd, $status);
97 if (file_exists($pathname)) {
98 send_file($pathname, $image);
101 echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
102 echo "Image not found!<br />";
103 echo "Please try the <a href=\"$CFG->wwwroot/$CFG->algebrafilterdir/algebradebug.php\">debugging script</a>";
105 echo "Image not found!<br />";
106 echo "Please try the <a href=\"$CFG->wwwroot/$CFG->algebrafilterdir/algebradebug.php\">debugging script</a><br />";
107 echo "Please turn on debug mode in site configuration to see more info here.";