function tex_filter_get_cmd($pathname, $texexp) { $texexp = escapeshellarg($texexp); $executable = tex_filter_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 = tex_filter_get_executable(true); $cmd = tex_filter_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!"; } }