예제 #1
0
function textpattern()
{
    global $pretext, $microstart, $prefs, $qcount, $qtime, $production_status, $txptrace, $siteurl, $has_article_tag;
    $has_article_tag = false;
    callback_event('textpattern');
    if ($pretext['status'] == '404') {
        txp_die(gTxt('404_not_found'), '404');
    }
    if ($pretext['status'] == '410') {
        txp_die(gTxt('410_gone'), '410');
    }
    $html = fetch_page_template($pretext['page']);
    if (!$html) {
        txp_die(gTxt('unknown_section'), '404');
    }
    // useful for clean urls with error-handlers
    txp_status_header('200 OK');
    trace_add('[' . gTxt('page') . ': ' . $pretext['page'] . ']');
    set_error_handler("tagErrorHandler");
    $pretext['secondpass'] = false;
    $html = parse($html);
    $pretext['secondpass'] = true;
    trace_add('[ ~~~ ' . gTxt('secondpass') . ' ~~~ ]');
    $html = parse($html);
    // the function so nice, he ran it twice
    $html = $prefs['allow_page_php_scripting'] ? evalString($html) : $html;
    // make sure the page has an article tag if necessary
    if (!$has_article_tag and $production_status != 'live' and (!empty($pretext['id']) or !empty($pretext['c']) or !empty($pretext['q']) or !empty($pretext['pg']))) {
        trigger_error(gTxt('missing_article_tag', array('{page}' => $pretext['page'])));
    }
    restore_error_handler();
    header("Content-type: text/html; charset=utf-8");
    echo $html;
    if (in_array($production_status, array('debug', 'testing'))) {
        $microdiff = getmicrotime() - $microstart;
        echo n, comment('Runtime:    ' . substr($microdiff, 0, 6));
        echo n, comment('Query time: ' . $qtime);
        echo n, comment('Queries: ' . $qcount);
        echo maxMemUsage('end of textpattern()', 1);
        if (!empty($txptrace) and is_array($txptrace)) {
            echo n, comment('txp tag trace: ' . n . join(n, $txptrace) . n);
        }
    }
    callback_event('textpattern_end');
}
예제 #2
0
function txp_die($msg, $status = '503')
{
    // 503 status might discourage search engines from indexing or caching the error message
    //Make it possible to call this function as a tag, e.g. in an article <txp:txp_die status="410" />
    if (is_array($msg)) {
        extract(lAtts(array('msg' => '', 'status' => '503'), $msg));
    }
    // Intentionally incomplete - just the ones we're likely to use
    $codes = array('200' => 'OK', '301' => 'Moved Permanently', '302' => 'Found', '304' => 'Not Modified', '307' => 'Temporary Redirect', '401' => 'Unauthorized', '403' => 'Forbidden', '404' => 'Not Found', '410' => 'Gone', '414' => 'Request-URI Too Long', '500' => 'Internal Server Error', '501' => 'Not Implemented', '503' => 'Service Unavailable');
    if ($status) {
        if (isset($codes[strval($status)])) {
            $status = strval($status) . ' ' . $codes[$status];
        }
        txp_status_header($status);
    }
    $code = '';
    if ($status and $parts = @explode(' ', $status, 2)) {
        $code = @$parts[0];
    }
    global $DB;
    if ($DB and $DB->selected) {
        $out = fetch_page_template('error_' . $code);
        if (empty($out)) {
            $out = fetch_page_template('error_default');
        }
    }
    if (empty($out)) {
        $out = <<<eod
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8" />
   <title>Textpattern Error: <txp:error_status /></title>
</head>
<body>
<p align="center" style="margin-top:4em"><txp:error_message /></p>
</body>
</html>
eod;
    }
    header("Content-type: text/html; charset=utf-8");
    if (is_callable('parse')) {
        $GLOBALS['txp_error_message'] = $msg;
        $GLOBALS['txp_error_status'] = $status;
        $GLOBALS['txp_error_code'] = $code;
        set_error_handler("tagErrorHandler");
        die(parse($out));
    } else {
        $out = preg_replace(array('@<txp:error_status[^>]*/>@', '@<txp:error_message[^>]*/>@'), array($status, $msg), $out);
        die($out);
    }
}