Merge branch 'm19_MDL-25770_hotpotfix' of git://github.com/danmarsden/moodle into...
[moodle.git] / filter / algebra / pix.php
blob5d51d769743bebc9387db2b6580fc47b8c2c10a6
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/algebra', $filters) === FALSE) {
15 error ('Filter not enabled!');
19 // disable moodle specific debug messages
20 disable_debugging();
22 require_once($CFG->libdir.'/filelib.php');
23 require_once($CFG->dirroot.'/filter/tex/lib.php');
25 $cmd = ''; // Initialise these variables
26 $status = '';
28 //error_reporting(E_ALL);
30 $relativepath = get_file_argument('pix.php');
32 $args = explode('/', trim($relativepath, '/'));
34 if (count($args) == 1) {
35 $image = $args[0];
36 $pathname = $CFG->dataroot.'/filter/algebra/'.$image;
37 } else {
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('&lt;','<',$texexp);
50 $texexp = str_replace('&gt;','>',$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);
60 } else {
61 if (debugging()) {
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>";
65 } else {
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.";