function filter_tex_get_cmd($pathname, $texexp) { $texexp = filter_tex_sanitize_formula($texexp); $texexp = escapeshellarg($texexp); $executable = filter_tex_get_executable(false); if (PHP_OS == "WINNT" || PHP_OS == "WIN32" || PHP_OS == "Windows") { $executable = str_replace(' ', '^ ', $executable); return "{$executable} ++ -e \"{$pathname}\" -- {$texexp}"; } else { return "\"{$executable}\" -e \"{$pathname}\" -- {$texexp}"; } }
function tex2image($texexp, $md5, $return = false) { global $CFG; if (!$texexp) { echo 'No tex expresion specified'; return; } $texexp = '\\Large ' . $texexp; $image = $md5 . ".gif"; $filetype = 'image/gif'; if (!file_exists("{$CFG->dataroot}/filter/algebra")) { make_upload_directory("filter/algebra"); } $pathname = "{$CFG->dataroot}/filter/algebra/{$image}"; if (file_exists($pathname)) { unlink($pathname); } $commandpath = filter_tex_get_executable(true); $cmd = filter_tex_get_cmd($pathname, $texexp); system($cmd, $status); if ($return) { return $image; } if (file_exists($pathname)) { send_file($pathname, $image); } else { $ecmd = "{$cmd} 2>&1"; echo `{$ecmd}` . "<br />\n"; echo "The shell command<br />{$cmd}<br />returned status = {$status}<br />\n"; if ($status == 4) { echo "Status corresponds to illegal instruction<br />\n"; } else { if ($status == 11) { echo "Status corresponds to bus error<br />\n"; } else { if ($status == 22) { echo "Status corresponds to abnormal termination<br />\n"; } } } if (file_exists($commandpath)) { echo "File size of mimetex executable {$commandpath} is " . filesize($commandpath) . "<br />"; echo "The file permissions are: " . decoct(fileperms($commandpath)) . "<br />"; if (function_exists("md5_file")) { echo "The md5 checksum of the file is " . md5_file($commandpath) . "<br />"; } else { $handle = fopen($commandpath, "rb"); $contents = fread($handle, 16384); fclose($handle); echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br />"; } } else { echo "mimetex executable {$commandpath} not found!<br />"; } echo "Image not found!"; } }
function tex2image($texexp, $return=false) { global $CFG; if (!$texexp) { echo 'No tex expresion specified'; return; } $image = md5($texexp) . ".gif"; $filetype = 'image/gif'; if (!file_exists("$CFG->dataroot/filter/tex")) { make_upload_directory("filter/tex"); } $pathname = "$CFG->dataroot/filter/tex/$image"; if (file_exists($pathname)) { unlink($pathname); } $texexp = '\Large '.$texexp; $commandpath = filter_tex_get_executable(true); $cmd = filter_tex_get_cmd($pathname, $texexp); system($cmd, $status); if ($return) { return $image; } if (file_exists($pathname)) { send_file($pathname, $image); } else if (debugging()) { $ecmd = "$cmd 2>&1"; echo `$ecmd` . "<br />\n"; echo "The shell command<br />$cmd<br />returned status = $status<br />\n"; if ($status == 4) { echo "Status corresponds to illegal instruction<br />\n"; } else if ($status == 11) { echo "Status corresponds to bus error<br />\n"; } else if ($status == 22) { echo "Status corresponds to abnormal termination<br />\n"; } if (file_exists($commandpath)) { echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br />"; echo "The file permissions are: " . decoct(fileperms($commandpath)) . "<br />"; if (function_exists("md5_file")) { echo "The md5 checksum of the file is " . md5_file($commandpath) . "<br />"; } else { $handle = fopen($commandpath,"rb"); $contents = fread($handle,16384); fclose($handle); echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br />"; } } else { echo "mimetex executable $commandpath not found!<br />"; } echo "Image not found!"; } else { echo "Can not output detailed information due to security concerns, please turn on debug mode first."; } }