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');
23 require_once($CFG->dirroot
.'/filter/tex/lib.php');
25 $cmd = ''; // Initialise these variables
28 //error_reporting(E_ALL);
30 $relativepath = get_file_argument('pix.php');
32 $args = explode('/', trim($relativepath, '/'));
34 if (count($args) == 1) {
36 $pathname = $CFG->dataroot
.'/filter/algebra/'.$image;
38 error('No valid arguments supplied');
41 if (!file_exists($pathname)) {
42 $md5 = str_replace('.gif','',$image);
43 if ($texcache = get_record('cache_filters', 'filter', 'algebra', 'md5key', $md5)) {
44 if (!file_exists($CFG->dataroot
.'/filter/algebra')) {
45 make_upload_directory('filter/algebra');
48 $texexp = $texcache->rawtext
;
49 $texexp = str_replace('<','<',$texexp);
50 $texexp = str_replace('>','>',$texexp);
51 $texexp = preg_replace('!\r\n?!',' ',$texexp);
52 $texexp = '\Large ' . $texexp;
53 $cmd = tex_filter_get_cmd($pathname, $texexp);
54 system($cmd, $status);
58 if (file_exists($pathname)) {
59 send_file($pathname, $image);
62 echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
63 echo "Image not found!<br />";
64 echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
66 echo "Image not found!<br />";
67 echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a><br />";
68 echo "Please turn on debug mode in site configuration to see more info here.";