示例#1
0
function error400($error = 'Invalid formula')
{
    header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
    include '400.php';
}
//ignore_user_abort();
ini_set('max_execution_time', 10);
header('X-Powered-By: S2 Latex Service');
$templater = new Templater(TPL_DIR);
$renderer = new Renderer($templater, TMP_DIR, LATEX_COMMAND, DVISVG_COMMAND, DVIPNG_COMMAND);
if (defined('LOG_DIR')) {
    $renderer->setLogDir(LOG_DIR);
}
$renderer->setDebug($isDebug);
$processor = new Processor($renderer, CACHE_SUCCESS_DIR, CACHE_FAIL_DIR);
$processor->addSVGCommand(SVGO);
$processor->addSVGCommand(GZIP);
try {
    $processor->parseURI(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
} catch (Exception $e) {
    error400($isDebug ? $e->getMessage() : 'Invalid formula');
    die;
}
if ($processor->prepareContent()) {
    $processor->echoContent();
} else {
    error400($isDebug ? $processor->getError() : 'Invalid formula');
}
if (!$isDebug) {
    $processor->saveContent();
}