Exemplo n.º 1
0
function adminErrorHandler($errno, $errstr, $errfile, $errline)
{
    global $production_status, $theme, $event, $step;
    if (!error_reporting()) {
        return;
    }
    // When even a minimum environment is missing...
    if (!isset($production_status)) {
        echo '<pre>' . gTxt('internal_error') . ' "' . $errstr . '"' . n . "in {$errfile} at line {$errline}" . '</pre>';
        return;
    }
    if ($production_status == 'live' || $production_status != 'debug' && $errno == E_USER_NOTICE) {
        $backtrace = $msg = '';
    } else {
        $backtrace = '';
        $msg = gTxt('internal_error');
        if (has_privs('debug.verbose')) {
            $msg .= ' "' . $errstr . '"';
        }
        if ($production_status == 'debug') {
            if (has_privs('debug.backtrace')) {
                $msg .= n . "in {$errfile} at line {$errline}";
                $backtrace = join(n, get_caller(5, 1));
            }
        }
    }
    $httpstatus = in_array($errno, array(E_ERROR, E_USER_ERROR)) ? '500' : '200';
    $out = "{$msg}.\n{$backtrace}";
    if (http_accept_format('html')) {
        if (!empty($backtrace)) {
            echo "<pre>{$msg}.</pre>" . n . '<pre style="padding-left: 2em;" class="backtrace"><code>' . txpspecialchars($backtrace) . '</code></pre>';
        } elseif (!empty($msg)) {
            echo is_object($theme) ? $theme->announce(array($out, E_ERROR), true) : "<pre>{$out}</pre>";
        }
        $c = array('in' => '', 'out' => '');
    } elseif (http_accept_format('js')) {
        send_script_response(is_object($theme) && !empty($msg) ? $theme->announce_async(array($out, E_ERROR), true) : "/* {$out} */");
        $c = array('in' => '/* ', 'out' => ' */');
    } elseif (http_accept_format('xml')) {
        send_xml_response(array('http-status' => $httpstatus, 'internal_error' => "{$out}"));
        $c = array('in' => '<!-- ', 'out' => ' -->');
    } else {
        txp_die($msg, 500);
    }
    if ($production_status != 'live' && in_array($errno, array(E_ERROR, E_USER_ERROR))) {
        die($c['in'] . gTxt('get_off_my_lawn', array('{event}' => $event, '{step}' => $step)) . $c['out']);
    }
}
Exemplo n.º 2
0
/**
 * Error handler for admin-side pages.
 *
 * @param   int    $errno
 * @param   string $errstr
 * @param   string $errfile
 * @param   int    $errline
 * @access  private
 * @package Debug
 */
function adminErrorHandler($errno, $errstr, $errfile, $errline)
{
    global $production_status, $theme, $event, $step;
    $error = array();
    if ($production_status == 'testing') {
        $error = array(E_WARNING => 'Warning', E_RECOVERABLE_ERROR => 'Catchable fatal error', E_USER_ERROR => 'User_Error', E_USER_WARNING => 'User_Warning');
    } elseif ($production_status == 'debug') {
        $error = array(E_WARNING => 'Warning', E_NOTICE => 'Notice', E_RECOVERABLE_ERROR => 'Catchable fatal error', E_USER_ERROR => 'User_Error', E_USER_WARNING => 'User_Warning', E_USER_NOTICE => 'User_Notice');
        if (!isset($error[$errno])) {
            $error[$errno] = $errno;
        }
    }
    if (!isset($error[$errno]) || !error_reporting()) {
        return;
    }
    // When even a minimum environment is missing.
    if (!isset($production_status)) {
        echo '<pre dir="auto">' . gTxt('internal_error') . ' "' . $errstr . '"' . n . "in {$errfile} at line {$errline}" . '</pre>';
        return;
    }
    $backtrace = '';
    if (has_privs('debug.verbose')) {
        $msg = $error[$errno] . ' "' . $errstr . '"';
    } else {
        $msg = gTxt('internal_error');
    }
    if ($production_status == 'debug' && has_privs('debug.backtrace')) {
        $msg .= n . "in {$errfile} at line {$errline}";
        $backtrace = join(n, get_caller(5, 1));
    }
    if ($errno == E_ERROR || $errno == E_USER_ERROR) {
        $httpstatus = 500;
    } else {
        $httpstatus = 200;
    }
    $out = "{$msg}.\n{$backtrace}";
    if (http_accept_format('html')) {
        if ($backtrace) {
            echo "<pre dir=\"auto\">{$msg}.</pre>" . n . '<pre class="backtrace" dir="ltr"><code>' . txpspecialchars($backtrace) . '</code></pre>';
        } elseif (is_object($theme)) {
            echo $theme->announce(array($out, E_ERROR), true);
        } else {
            echo "<pre dir=\"auto\">{$out}</pre>";
        }
    } elseif (http_accept_format('js')) {
        if (is_object($theme)) {
            send_script_response($theme->announce_async(array($out, E_ERROR), true));
        } else {
            send_script_response('/* ' . $out . '*/');
        }
    } elseif (http_accept_format('xml')) {
        send_xml_response(array('http-status' => $httpstatus, 'internal_error' => "{$out}"));
    } else {
        txp_die($msg, 500);
    }
}