1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
<?PHP // $Id: pix.php,v 1.13.10.1 2006/08/14 06:22:15 skodak Exp $
// This function fetches math. images from the data directory
// If not, it obtains the corresponding TeX expression from the cache_tex db table
// and uses mimeTeX to create the image file
$nomoodlecookie = true; // Because it interferes with caching
require_once('../../config.php');
if (empty($CFG->textfilters)) {
error ('Filter not enabled!');
} else {
$filters = explode(',', $CFG->textfilters);
if (array_search('filter/algebra', $filters) === FALSE) {
error ('Filter not enabled!');
}
}
require_once($CFG->libdir.'/filelib.php');
$CFG->texfilterdir = 'filter/tex';
$CFG->algebrafilterdir = 'filter/algebra';
$CFG->algebraimagedir = 'filter/algebra';
$cmd = ''; // Initialise these variables
$status = '';
//error_reporting(E_ALL);
$relativepath = get_file_argument('pix.php');
$args = explode('/', trim($relativepath, '/'));
if (count($args) == 1) {
$image = $args[0];
$pathname = $CFG->dataroot.'/'.$CFG->algebraimagedir.'/'.$image;
} else {
error('No valid arguments supplied');
}
if (!file_exists($pathname)) {
$md5 = str_replace('.gif','',$image);
if ($texcache = get_record('cache_filters', 'filter', 'algebra', 'md5key', $md5)) {
if (!file_exists($CFG->dataroot.'/'.$CFG->algebraimagedir)) {
make_upload_directory($CFG->algebraimagedir);
}
$texexp = $texcache->rawtext;
$texexp = str_replace('<','<',$texexp);
$texexp = str_replace('>','>',$texexp);
$texexp = preg_replace('!\r\n?!',' ',$texexp);
$texexp = '\Large ' . $texexp;
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
$texexp = str_replace('"','\"',$texexp);
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
$cmd = str_replace(' ','^ ',$cmd);
$cmd .= " ++ -e \"$pathname\" -- \"$texexp\"";
} else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { /// Use the custom binary
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- ". escapeshellarg($texexp);
} else { /// Auto-detect the right TeX binary
switch (PHP_OS) {
case "Linux":
$cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" -- ". escapeshellarg($texexp);
break;
case "Darwin":
$cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" -- ". escapeshellarg($texexp);
break;
default: /// Nothing was found, so tell them how to fix it.
if ($CFG->debug > 7) {
echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
echo "and that it has the right permissions set on it as executable program.\n\n";
echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n";
echo " http://moodle.org/download/mimetex/";
} else {
echo "Mimetex executable was not found,\n";
echo "Please turn on debug mode in site configuration to see more info here.";
}
die;
break;
}
}
system($cmd, $status);
}
}
if (file_exists($pathname)) {
send_file($pathname, $image);
} else {
if ($CFG->debug > 7) {
echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
echo "Image not found!<br />";
echo "Please try the <a href=\"$CFG->wwwroot/$CFG->algebrafilterdir/algebradebug.php\">debugging script</a>";
} else {
echo "Image not found!<br />";
echo "Please try the <a href=\"$CFG->wwwroot/$CFG->algebrafilterdir/algebradebug.php\">debugging script</a><br />";
echo "Please turn on debug mode in site configuration to see more info here.";
}
}
?>
|