protected static function Run()
{
// Get the RenderedPage (if applicable)
if (ob_get_length()) {
QErrorHandler::$RenderedPage = ob_get_contents();
ob_clean();
}
// Setup the FileLinesArray
if (is_file(QErrorHandler::$Filename)) {
QErrorHandler::$FileLinesArray = file(QErrorHandler::$Filename);
} else {
if (strpos(QErrorHandler::$Filename, 'eval()') !== false) {
QErrorHandler::$FileLinesArray = array('File listing unavailable; eval()\'d code');
} else {
QErrorHandler::$FileLinesArray = array('File Not Found: ' . QErrorHandler::$Filename);
}
}
// Set up the MessageBody
if (QErrorHandler::$AdditionalMessage) {
QErrorHandler::$MessageBody = htmlentities(QErrorHandler::$AdditionalMessage) . '<br/>' . htmlentities(QErrorHandler::$Message);
} else {
QErrorHandler::$MessageBody = htmlentities(QErrorHandler::$Message);
}
QErrorHandler::$MessageBody = str_replace(" ", " ", str_replace("\n", "<br/>\n", QErrorHandler::$MessageBody));
QErrorHandler::$MessageBody = str_replace(": ", ": ", QErrorHandler::$MessageBody);
// Figure Out DateTime (and if we are logging, the filename of the error log)
$strMicrotime = microtime();
$strParts = explode(' ', $strMicrotime);
$strMicrotime = substr($strParts[0], 2);
$intTimestamp = $strParts[1];
QErrorHandler::$DateTimeOfError = date('l, F j Y, g:i:s.' . $strMicrotime . ' A T', $intTimestamp);
QErrorHandler::$IsoDateTimeOfError = date('Y-m-d H:i:s T', $intTimestamp);
if (defined('__ERROR_LOG__') && __ERROR_LOG__ && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) {
QErrorHandler::$FileNameOfError = sprintf('qcodo_error_%s_%s.html', date('Y-m-d_His', $intTimestamp), $strMicrotime);
}
// Cleanup
unset($strMicrotime);
unset($strParts);
unset($strMicrotime);
unset($intTimestamp);
// Generate the Error Dump
if (!ob_get_level()) {
ob_start();
}
if (QApplication::$CliMode) {
require __QCODO_CORE__ . '/assets/error_dump_cli.inc.php';
} else {
require __QCODO_CORE__ . '/assets/error_dump.inc.php';
}
// Do We Log???
if (defined('__ERROR_LOG__') && __ERROR_LOG__ && defined('ERROR_LOG_FLAG') && ERROR_LOG_FLAG) {
// Log to File in __ERROR_LOG__
$strContents = ob_get_contents();
QApplication::MakeDirectory(__ERROR_LOG__, 0777);
$strFileName = sprintf('%s/%s', __ERROR_LOG__, QErrorHandler::$FileNameOfError);
file_put_contents($strFileName, $strContents);
@chmod($strFileName, 0666);
}
if (QApplication::$RequestMode == QRequestMode::Ajax) {
if (defined('ERROR_FRIENDLY_AJAX_MESSAGE') && ERROR_FRIENDLY_AJAX_MESSAGE) {
// Reset the Buffer
while (ob_get_level()) {
ob_end_clean();
}
// Setup the Friendly Response
header('Content-Type: text/xml');
$strToReturn = '<controls/><commands><command>alert("' . str_replace('"', '\\"', ERROR_FRIENDLY_AJAX_MESSAGE) . '");</command></commands>';
if (QApplication::$EncodingType) {
printf("<?xml version=\"1.0\" encoding=\"%s\"?><response>%s</response>\r\n", QApplication::$EncodingType, $strToReturn);
} else {
printf("<?xml version=\"1.0\"?><response>%s</response>\r\n", $strToReturn);
}
return false;
}
} else {
if (!QApplication::$CliMode) {
header("HTTP/1.1 500 Internal Server Error");
}
if (defined('ERROR_FRIENDLY_PAGE_PATH') && ERROR_FRIENDLY_PAGE_PATH && !QApplication::$CliMode) {
// Reset the Buffer
while (ob_get_level()) {
ob_end_clean();
}
require ERROR_FRIENDLY_PAGE_PATH;
}
}
exit;
}