getCode(); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $normalized = str_replace( array("\t", "\n", "\r", "\0", "\x0B"), " ", $message ); if (DEBUG) error_log( "ERROR: ".$errno." ".strip_tags($normalized). " (".$file." on line ".$line.")" ); error(body:$message, backtrace:$e->getTrace()); } /** * Function: error * Displays an error message via direct call or handler. * * Parameters: * $title - The title for the error dialog. * $body - The message for the error dialog. * $backtrace - The trace of the error. * $code - Numeric HTTP status code to set. */ function error($title = "", $body = "", $backtrace = array(), $code = 500)/*: never*/{ # Discard any additional output buffers. while (OB_BASE_LEVEL < ob_get_level()) ob_end_clean(); # Clean the output buffer before we begin. if (ob_get_contents() !== false) ob_clean(); # Attempt to set headers to sane values and send a status code. if (!headers_sent()) { header("Content-Type: text/html; charset=UTF-8"); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 03 Jun 1991 05:30:00 GMT"); # Resend the content encoding header if transparent compression is on. if (CAN_USE_ZLIB and ini_get("zlib.output_compression")) header("Content-Encoding: ".(HTTP_ACCEPT_GZIP ? "gzip" : "deflate")); switch ($code) { case 400: header($_SERVER['SERVER_PROTOCOL']." 400 Bad Request"); break; case 401: header($_SERVER['SERVER_PROTOCOL']." 401 Unauthorized"); break; case 403: header($_SERVER['SERVER_PROTOCOL']." 403 Forbidden"); break; case 404: header($_SERVER['SERVER_PROTOCOL']." 404 Not Found"); break; case 405: header($_SERVER['SERVER_PROTOCOL']." 405 Method Not Allowed"); break; case 409: header($_SERVER['SERVER_PROTOCOL']." 409 Conflict"); break; case 410: header($_SERVER['SERVER_PROTOCOL']." 410 Gone"); break; case 413: header($_SERVER['SERVER_PROTOCOL']." 413 Payload Too Large"); break; case 422: header($_SERVER['SERVER_PROTOCOL']." 422 Unprocessable Entity"); break; case 429: header($_SERVER['SERVER_PROTOCOL']." 429 Too Many Requests"); break; case 431: header($_SERVER['SERVER_PROTOCOL']." 431 Request Header Fields Too Large"); break; case 501: header($_SERVER['SERVER_PROTOCOL']." 501 Not Implemented"); break; case 502: header($_SERVER['SERVER_PROTOCOL']." 502 Bad Gateway"); break; case 503: header($_SERVER['SERVER_PROTOCOL']." 503 Service Unavailable"); break; case 504: header($_SERVER['SERVER_PROTOCOL']." 504 Gateway Timeout"); break; default: header($_SERVER['SERVER_PROTOCOL']." 500 Internal Server Error"); } } # Report in plain text if desirable or necessary because of a deep error. if ( AJAX or !function_exists("__") or !function_exists("_f") or !function_exists("fallback") or !function_exists("fix") or !function_exists("sanitize_html") or !function_exists("logged_in") or !file_exists(INCLUDES_DIR.DIR."config.json.php") or !class_exists("Config") or !method_exists("Config", "current") or !isset(Config::current()->locale) or !isset(Config::current()->chyrp_url) ) exit("ERROR: ".strip_tags($body)); # We need this for the pretty error page. $chyrp_url = fix(Config::current()->chyrp_url, true); # Set fallbacks. fallback($title, __("Error")); fallback($body, __("An unspecified error has occurred.")); fallback($backtrace, array()); # Redact and escape the backtrace for display. foreach ($backtrace as $index => &$trace) { if (!isset($trace["file"]) or !isset($trace["line"])) unset($backtrace[$index]); else $trace["file"] = fix( str_replace(MAIN_DIR.DIR, "", $trace["file"]), false, true ); } #--------------------------------------------- # Output Starts #--------------------------------------------- ?>