Automatically generated installer lang files
[moodle.git] / filter / algebra / pix.php
blob8172b7822269f2156fae418be1a93a58ef2400c7
1 <?php
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
20 $status = '';
22 $relativepath = get_file_argument();
24 $args = explode('/', trim($relativepath, '/'));
26 if (count($args) == 1) {
27 $image = $args[0];
28 $pathname = $CFG->dataroot.'/filter/algebra/'.$image;
29 } else {
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('&lt;','<',$texexp);
42 $texexp = str_replace('&gt;','>',$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);
52 } else {
53 if (debugging()) {
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>";
57 } else {
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.";