Exemplo n.º 1
0
function displayLocalisedErrorPage($message, $errorNumber, $errorData)
{
    if (defined('DOCVERT_ERROR_OCCURED')) {
        define('DOCVERT_RECURSIVE_ERROR', true);
    }
    define('DOCVERT_ERROR_OCCURED', true);
    if (!headers_sent()) {
        header('HTTP/1.1 ' . $errorNumber);
        header('Status: ' . $errorNumber);
    }
    $pageType = 'unknown';
    if (substr($errorNumber, 0, 1) == '2') {
        $title = '&error-ok;';
        $pageType = 'good';
    } else {
        $title = '&error-error;';
        $pageType = 'bad';
    }
    if (!defined('DOCVERT_CLIENT_TYPE')) {
        $errorMessage = '&error-programming-error-docvert-client-type;';
        $errorMessage = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $errorMessage);
        die($errorMessage);
    }
    switch (DOCVERT_CLIENT_TYPE) {
        case 'web':
            $head = '<style type="text/css">body{font-family:sans-serif;} h1{font-size:large;} h2{font-size:medium} h3{font-size:small} .windowTitle{color:white;margin:0px;padding:5px;font-size:small} .bad {background:#ffeeee; border:solid 2px red} .bad .windowTitle {background:red} .good {background:#eeffee;border: solid 2px #bbccbb} .good .windowTitle {background:#006600} .footer {margin-top:0px;padding:4px;font-size:small} .bad .footer {background:#ffcccc} .bad .footer .divider {color:#ffcccc} .good .footer {background:#ccffcc} .good .footer .divider {color:#ccffccc} .standardAdvice {margin:30px 0px 0px 0px; padding: 0px 0px 10px 15px;} </style>';
            $body = '<div class="' . $pageType . '">' . "\n";
            $body .= '    <h1 class="windowTitle">Docvert: ' . $title . ' ' . $errorNumber . '</h1>' . "\n";
            $body .= '    <div style="padding:10px">' . "\n";
            $body .= '	' . $message . "\n";
            $body .= '    </div>' . "\n";
            $body .= '    &error-footer;' . "\n";
            $body .= '</div>' . "\n";
            $template = getXHTMLTemplate();
            $template = str_replace('{{title}}', $title, $template);
            $template = str_replace('{{head}}', $head, $template);
            $template = str_replace('{{body}}', $body, $template);
            $template = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $template);
            if ($errorData) {
                foreach ($errorData as $key => $value) {
                    $template = str_replace('&dynamic-' . $key . ';', revealXml($value), $template);
                }
            }
            die($template);
            break;
        case 'command line':
            $message = preg_replace_callback('/\\&(.*?)\\;/s', 'replaceLanguagePlaceholder', $message);
            if ($errorData) {
                foreach ($errorData as $key => $value) {
                    $message = str_replace('&dynamic-' . $key . ';', revealXml($value), $message);
                }
            }
            $endOfBlockElements = array('</p>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>', '</li>', '</blockquote>');
            $message = str_replace($endOfBlockElements, "\n", $message);
            $message = preg_replace('/<.*?>/s', '', $message);
            $message = str_replace('&lt;', '<', $message);
            $message = str_replace('&gt;', '>', $message);
            $message = str_replace('&amp;', '&', $message);
            $message .= "\n";
            $message = trim($message) . "\n";
            if ($pageType == 'bad') {
                file_put_contents("php://stderr", $message);
            } else {
                print $message;
            }
            die;
            break;
    }
}
Exemplo n.º 2
0
function applyPipeline($contentPath, $pipelineToUse, $autoPipeline, $previewDirectory, $skipAheadToDocbook = false)
{
    if (!trim($contentPath)) {
        webServiceError('&error-no-content-xml-found;');
    }
    if (!file_exists($contentPath)) {
        webServiceError('Unable to find ' . revealXml(basename($contentPath)) . ' file in "' . revealXml(dirname($contentPath)) . '"');
    }
    $contentDirectory = dirname($contentPath);
    $pipelineDirectory = DOCVERT_DIR . 'pipeline' . DIRECTORY_SEPARATOR . $pipelineToUse . DIRECTORY_SEPARATOR;
    $pipelinePath = $pipelineDirectory . 'pipeline.xml';
    if (!file_exists($pipelinePath)) {
        webServiceError('&error-no-pipeline-found;', 500, array('pipelinePath' => $pipelinePath));
    }
    $pipelineString = file_get_contents($pipelinePath);
    $pipelineString = removeXmlDeclaration($pipelineString);
    $pipelineString = trim($pipelineString);
    if (strpos($pipelineString, '<autopipeline') !== false) {
        $autoPipelineString = substr($pipelineString, strpos($pipelineString, '<autopipeline>') + 14);
        $autoPipelineString = substr($autoPipelineString, 0, strpos($autoPipelineString, '</autopipeline>'));
        $autoPipelinesDirectory = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'auto-pipelines' . DIRECTORY_SEPARATOR;
        $chosenAutoPipeline = $autoPipeline;
        if (!trim($chosenAutoPipeline)) {
            $defaultAutoPipelines = glob($autoPipelinesDirectory . '*.default.xml');
            if (count($defaultAutoPipelines) == 1) {
                $chosenAutoPipeline = substringBefore($defaultAutoPipelines[0], '.xml');
            }
            $chosenAutoPipeline = str_replace($autoPipelinesDirectory, '', $chosenAutoPipeline);
        }
        $chosenAutoPipeline = str_replace('.default', '', $chosenAutoPipeline);
        if (strpos($chosenAutoPipeline, '.') === true || strpos($chosenAutoPipeline, '/') === true || strpos($chosenAutoPipeline, '\\') === true) {
            webServiceError('&error-pipeline-error;', 400, array('chosenAutoPipeline' => $chosenAutoPipeline));
        }
        $autoPipelinePath = $autoPipelinesDirectory . $chosenAutoPipeline . '.xml';
        if (!trim($chosenAutoPipeline)) {
            webServiceError('error-autopipeline-empty;', 400);
        } elseif (!file_exists($autoPipelinePath)) {
            $autoPipelinePath = $autoPipelinesDirectory . $chosenAutoPipeline . '.default.xml';
            if (!file_exists($autoPipelinePath)) {
                webServiceError('&error-autopipeline-not-found; ' . revealXml($chosenAutoPipeline), 400);
            }
        }
        $pipelineString = file_get_contents($autoPipelinePath);
        if (stripos($pipelineString, '{{custom-stages}}') === false) {
            webServiceError('&error-autopipeline-missing-placeholder; ' . revealXml($autoPipelinePath));
        }
        $pipelineString = str_replace('{{custom-stages}}', $autoPipelineString, $pipelineString);
    }
    $pipelineString = substr($pipelineString, strpos($pipelineString, '<pipeline>') + 10);
    $pipelineString = substr($pipelineString, 0, strpos($pipelineString, '</pipeline>'));
    if ($skipAheadToDocbook) {
        $toDocbookPartOfPipelinePattern = "/.*?ToDocBook[^>]*?>/s";
        $pipelineString = preg_replace($toDocbookPartOfPipelinePattern, '', $pipelineString);
    }
    $pipelineStages = xmlStringToArray($pipelineString);
    $currentXml = file_get_contents($contentPath);
    $currentXml = fixImagePaths($currentXml);
    $pipelineSettings = array("pipeline" => $pipelineToUse, "autopipeline" => $autoPipeline);
    processAPipelineLevel($pipelineStages, $currentXml, $pipelineDirectory, $contentDirectory, $previewDirectory, $pipelineSettings);
    $testResultsPath = $contentDirectory . DIRECTORY_SEPARATOR . 'test.html';
    if (file_exists($testResultsPath)) {
        $title = 'Document Unit Tests';
        $body = file_get_contents($testResultsPath) . "\n";
        $template = getXHTMLTemplate();
        $template = str_replace('{{title}}', $title, $template);
        $template = str_replace('{{body}}', '<h1>Document Notices</h1>' . "\n" . '<p class="timestamp"><span class="time">' . date('r') . '</span></p>' . $body, $template);
        $template = str_replace('{{head}}', '<style type="text/css"> body {font-size:small} .note{background:#eeeeff;border:solid 1px #9999ff; padding:10px;margin-bottom:10px} .error{background:#ffeeee;border: solid 1px red; padding:10px;margin-bottom:10px} h1{font-size:medium;} p {margin-top:0px;} .error h1{margin:0px;padding:0px;}  .timestamp {font-size:x-small;color:#999999} .validation{background:#eeeeff; border: solid 1px blue; padding:10px;margin-bottom:10px} p {margin:0px;} .warning {background:#eeeeff; border: solid 1px blue; padding:10px;margin-bottom:10px} </style>', $template);
        file_put_contents($testResultsPath, $template);
    }
    $stylesXmlPath = $contentDirectory . DIRECTORY_SEPARATOR . 'styles.xml';
    if (file_exists($stylesXmlPath)) {
        silentlyUnlink($stylesXmlPath);
    }
}