|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?PHP 00002 // This function fetches math. images from the data directory 00003 // If not, it obtains the corresponding TeX expression from the cache_tex db table 00004 // and uses mimeTeX to create the image file 00005 00006 // disable moodle specific debug messages and any errors in output 00007 define('NO_DEBUG_DISPLAY', true); 00008 define('NO_MOODLE_COOKIES', true); // Because it interferes with caching 00009 00010 require_once('../../config.php'); 00011 00012 if (!filter_is_enabled('filter/tex')) { 00013 print_error('filternotenabled'); 00014 } 00015 00016 require_once($CFG->libdir.'/filelib.php'); 00017 require_once($CFG->dirroot.'/filter/tex/lib.php'); 00018 require_once($CFG->dirroot.'/filter/tex/latex.php'); 00019 00020 $cmd = ''; // Initialise these variables 00021 $status = ''; 00022 00023 $relativepath = get_file_argument(); 00024 00025 $args = explode('/', trim($relativepath, '/')); 00026 00027 if (count($args) == 1) { 00028 $image = $args[0]; 00029 $pathname = $CFG->dataroot.'/filter/tex/'.$image; 00030 } else { 00031 print_error('invalidarguments', 'error'); 00032 } 00033 00034 if (!file_exists($pathname)) { 00035 $md5 = str_replace(".{$CFG->filter_tex_convertformat}",'',$image); 00036 if ($texcache = $DB->get_record('cache_filters', array('filter'=>'tex', 'md5key'=>$md5))) { 00037 if (!file_exists($CFG->dataroot.'/filter/tex')) { 00038 make_upload_directory('filter/tex'); 00039 } 00040 00041 // try and render with latex first 00042 $latex = new latex(); 00043 $density = $CFG->filter_tex_density; 00044 $background = $CFG->filter_tex_latexbackground; 00045 $texexp = $texcache->rawtext; // the entities are now decoded before inserting to DB 00046 $latex_path = $latex->render($texexp, $md5, 12, $density, $background); 00047 if ($latex_path) { 00048 copy($latex_path, $pathname); 00049 $latex->clean_up($md5); 00050 00051 } else { 00052 // failing that, use mimetex 00053 $texexp = $texcache->rawtext; 00054 $texexp = str_replace('<', '<', $texexp); 00055 $texexp = str_replace('>', '>', $texexp); 00056 $texexp = preg_replace('!\r\n?!', ' ', $texexp); 00057 $texexp = '\Large '.$texexp; 00058 $cmd = filter_tex_get_cmd($pathname, $texexp); 00059 system($cmd, $status); 00060 } 00061 } 00062 } 00063 00064 if (file_exists($pathname)) { 00065 send_file($pathname, $image); 00066 } else { 00067 if (debugging()) { 00068 echo "The shell command<br />$cmd<br />returned status = $status<br />\n"; 00069 echo "Image not found!<br />"; 00070 echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a>"; 00071 } else { 00072 echo "Image not found!<br />"; 00073 echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a><br />"; 00074 echo "Please turn on debug mode in site configuration to see more info here."; 00075 } 00076 }