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 // disable moodle specific debug messages and any errors in output
7 define('NO_DEBUG_DISPLAY', true);
8 define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
10 require_once('../../config.php');
12 if (!filter_is_enabled('algebra')) {
13 print_error('filternotenabled');
16 require_once($CFG->libdir
.'/filelib.php');
17 require_once($CFG->dirroot
.'/filter/tex/lib.php');
19 $cmd = ''; // Initialise these variables
22 $relativepath = get_file_argument();
24 $args = explode('/', trim($relativepath, '/'));
26 if (count($args) == 1) {
28 $pathname = $CFG->dataroot
.'/filter/algebra/'.$image;
30 print_error('invalidarguments', 'error');
33 if (!file_exists($pathname)) {
34 $md5 = str_replace('.gif','',$image);
35 if ($texcache = $DB->get_record('cache_filters', array('filter'=>'algebra', 'md5key'=>$md5))) {
36 if (!file_exists($CFG->dataroot
.'/filter/algebra')) {
37 make_upload_directory('filter/algebra');
40 $texexp = $texcache->rawtext
;
41 $texexp = str_replace('<','<',$texexp);
42 $texexp = str_replace('>','>',$texexp);
43 $texexp = preg_replace('!\r\n?!',' ',$texexp);
44 $texexp = '\Large ' . $texexp;
45 $cmd = filter_tex_get_cmd($pathname, $texexp);
46 system($cmd, $status);
50 if (file_exists($pathname)) {
51 send_file($pathname, $image);
54 echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
55 echo "Image not found!<br />";
56 echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
58 echo "Image not found!<br />";
59 echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a><br />";
60 echo "Please turn on debug mode in site configuration to see more info here.";