_debug = $debug; self::$_instance->_mailer = $mailer; self::$_instance->_errors = array(); self::$_instance->_errorPage = $errorPage; self::$_instance->_errorPage2 = $errorPage2; self::$_instance->_log = $log; if ($mailer) { ob_start(); set_error_handler(array(self::$_instance, "errorHandler")); set_exception_handler(array(self::$_instance, "exceptionHandler")); } } return self::$_instance; } public static function turnOff() { $instance = self::initialize(); $instance->_isOff = true; } public static function turnOn() { $instance = self::initialize(); $instance->_isOff = false; } public static function setMailer($mailer) { $instance = self::initialize(); $instance->_mailer = $mailer; } public static function setMail($mailto) { $instance = self::initialize(); $instance->_mailto = $mailto; } public function __destruct() { $instance = self::initialize(); $instance->printDebug(); $instance->makeBug(); } public static function clearBug() { $session = Zend_Registry::get('session'); unset($session->lastbug); } public static function writeLog($error) { $instance = self::initialize(); $f = fopen($instance->_log, "a"); fwrite($f, date("Y-m-d, H:i:s") . " - " . $error . "\n"); fclose($f); $log = Zend_Registry::get('log'); $log->err("BugTracker has intercepted an error"); } public static function triggerError($error) { $instance = self::initialize(); ob_start(); echo PHP_EOL; debug_print_backtrace(); echo PHP_EOL . "-----------------------------------------" . PHP_EOL; $instance->_backtrace = ob_get_contents(); ob_end_clean(); // Zend Fix if (stripos($instance->_backtrace, "Loader.php:165") === false and stripos($instance->_backtrace, "Loader.php:160") === false ) { $instance->writeLog($error); $instance->_errors[] = $error; } } public static function errorHandler($errno, $errstr, $errfile, $errline) { $instance = self::initialize(); if ($instance->_isOff) { return; } switch ($errno) { case E_USER_ERROR: case E_CORE_ERROR: case E_COMPILE_ERROR: case E_RECOVERABLE_ERROR: case E_ERROR: $error = "ERROR: [$errno] $errstr (Fatal error in line $errline of file $errfile, PHP " . PHP_VERSION . " (" . PHP_OS . "))"; if (eregi("Smarty", $error)) { die($error); } $instance->triggerError($error); $instance->makeBug(); break; case E_USER_WARNING: case E_CORE_WARNING: case E_COMPILE_WARNING: case E_WARNING: $error = "WARNING: [$errno] $errstr in line $errline of file $errfile"; if (eregi("Smarty", $error)) { die($error); } $instance->triggerError($error); break; case E_PARSE: $error = "PARSE ERROR: [$errno] $errstr in line $errline of file $errfile"; if (eregi("Smarty", $error)) { die($error); } $instance->triggerError($error); $instance->makeBug(); break; case E_USER_NOTICE: case E_NOTICE: $error = "NOTICE: [$errno] $errstr in line $errline of file $errfile"; break; default: $error = "Unknown error type: [$errno] $errstr in line $errline of file $errfile"; break; } } public static function exceptionHandler($e) { $instance = self::initialize(); if ($instance->_isOff) { return; } $error = "Uncaught exception: " . get_class($e) . " - " . $e->getMessage() . ": " . "\n" . $e->getTraceAsString(); $instance->triggerError($error); $instance->makeBug(); } private static function printDebug() { $instance = self::initialize(); $db = Zend_Registry::get('db'); $timer = Zend_Registry::get('timer'); if ($instance->_debug != 0) { echo "

Debug

"; } if ($instance->_debug & 0x0001) { echo '

Timer:

' . PHP_EOL . $timer; } if ($instance->_debug & (0x0010 | 0x0100)) { // db profiler info $profiler = $db->getProfiler(); $totalTime = $profiler->getTotalElapsedSecs(); $queryCount = $profiler->getTotalNumQueries(); echo '

SQL queries

' . PHP_EOL . '
Executed ' . $queryCount .
                ' queries in ' . round($totalTime, 4) . ' seconds' . '
' . PHP_EOL . 'Queries higher than average ( ' . round($totalTime / $queryCount, 4) . ' s )
' . PHP_EOL . ''; if ($profiler->getQueryProfiles()) foreach ($profiler->getQueryProfiles() as $query) { if (($instance->_debug & 0x0100) || $query->getElapsedSecs() > ($totalTime / $queryCount)) echo '' . '' . '' . '' . '' . PHP_EOL; } echo '
' . round($query->getElapsedSecs() / $totalTime, 4) . ' %' . round($query->getElapsedSecs(), 4) . '' . $query->getQuery() . '
'; $profs = ""; if ($profiler->getQueryProfiles()) foreach ($profiler->getQueryProfiles() as $query) { if ($query->getElapsedSecs() > 0.01) $profs .= round($query->getElapsedSecs(), 4) . ": " . $query->getQuery() . PHP_EOL; } $f = fopen($instance->_log . ".db.log", "a"); fwrite($f, $profs); fclose($f); } if ($instance->_debug & 0x1000) { echo '

Superglobalne

' . PHP_EOL . '$_SESSION ' . PHP_EOL; Zend_Debug::dump($_SESSION); echo '$_POST ' . PHP_EOL; Zend_Debug::dump($_POST); echo '$_GET ' . PHP_EOL; Zend_Debug::dump($_GET); } if ($instance->_debug != 0) echo '
'; } private static function prepareBug() { $instance = self::initialize(); $db = Zend_Registry::get('db'); $session = Zend_Registry::get('session'); $timer = Zend_Registry::get('timer'); $msg = "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " URL: "; $msg .= $_SERVER["REQUEST_URI"] . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Remote IP: "; $msg .= $_SERVER["REMOTE_ADDR"] . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " USER AGENT: "; $msg .= $_SERVER["HTTP_USER_AGENT"] . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Session: "; $msg .= Zend_Session::getId() . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Request Time: "; $msg .= $timer->get() . " s." . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Time Limit: "; $msg .= ini_get('max_execution_time') . " s." . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Memory Usage: "; $msg .= memory_get_usage() . " b" . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Memory Peak Usage: "; $msg .= memory_get_peak_usage() . " b" . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Memory Limit: "; $msg .= ini_get('memory_limit') . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Errors" . PHP_EOL . PHP_EOL; foreach ($instance->_errors as $val) { $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= $val . PHP_EOL . PHP_EOL; } $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " Timer:" . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= strip_tags(str_replace("
", PHP_EOL, $timer)); // db profiler info if ($instance->_debug & (0x0010 | 0x0100)) { $profiler = $db->getProfiler(); $totalTime = $profiler->getTotalElapsedSecs(); $queryCount = $profiler->getTotalNumQueries(); $msg .= PHP_EOL . PHP_EOL . "|-----------------------------------------|" . PHP_EOL . PHP_EOL; $msg .= PHP_EOL . PHP_EOL . "SQL queries" . PHP_EOL . 'Executed ' . $queryCount . ' queries in ' . round($totalTime, 4) . ' seconds' . PHP_EOL . 'Queries higher than average ( ' . round($totalTime / $queryCount, 4) . ' s ) ' . PHP_EOL; if ($profiler->getQueryProfiles()) foreach ($profiler->getQueryProfiles() as $query) { if ($query->getElapsedSecs() > ($totalTime / $queryCount)) $msg .= PHP_EOL . round($query->getElapsedSecs() / $totalTime, 4) . ' % - ' . round($query->getElapsedSecs(), 4) . ' - ' . $query->getQuery() . PHP_EOL; } } $msg .= PHP_EOL . "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= ' Superglobalne' . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= strip_tags(htmlspecialchars_decode(Zend_Debug::dump($_POST, '$_POST', false))); $msg .= PHP_EOL . "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= strip_tags(htmlspecialchars_decode(Zend_Debug::dump($_GET, '$_GET', false))); $msg .= PHP_EOL . "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= strip_tags(htmlspecialchars_decode(Zend_Debug::dump($_SESSION, '$_SESSION', false))); $msg .= PHP_EOL . "-----------------------------------------" . PHP_EOL . PHP_EOL; $msg .= " BACKTRACE:" . PHP_EOL . PHP_EOL; $msg .= "-----------------------------------------" . PHP_EOL; $msg .= $instance->_backtrace . PHP_EOL; $from = $_SERVER["SERVER_ADMIN"]; $php = phpversion(); if (isset($_SERVER["SERVER_NAME"])) { $server = $_SERVER["SERVER_NAME"]; } elseif (isset($_ENV["SERVER_NAME"])) { $server = $_ENV["SERVER_NAME"]; } else { $server = $_SERVER["HTTP_HOST"]; } $msg .= $server . " - " . $from . " - PHP: " . $php; return $msg; } private static function makeBug() { $instance = self::initialize(); if (!empty($instance->_errors) and $instance->_mailer) { $msg = $instance->prepareBug(); $from = $_SERVER["SERVER_ADMIN"]; $headers = 'From: ' . $from . "\r\n" . 'Reply-To: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n" . 'Content-type: text/plain; charset=UTF-8'; if (isset($_SERVER["SERVER_NAME"])) { $server = $_SERVER["SERVER_NAME"]; } elseif (isset($_ENV["SERVER_NAME"])) { $server = $_ENV["SERVER_NAME"]; } else { $server = $_SERVER["HTTP_HOST"]; } $bug = array("from" => $from, "headers" => $headers, "title" => $server . " Error log - " . date("Y-m-d, H:i:s"), "msg" => $msg); Zend_Registry::get('session')->lastbug = $bug; $instance->_errors = array(); $instance->redirectToErrorPage(); } else { $instance->returnOutput(); } } public static function send() { $instance = self::initialize(); $session = Zend_Registry::get('session'); if ($session->lastbug) { $a = mail($instance->_mailto, $session->lastbug['title'], $session->lastbug['msg'], $session->lastbug['headers']); unset($session->lastbug); } $instance->redirectToErrorSendPage(); } private static function redirectToErrorPage() { $instance = self::initialize(); ob_end_clean(); $f = explode("/", $_SERVER["SCRIPT_NAME"]); $file = array_pop($f); header("location: http://" . $_SERVER["HTTP_HOST"] . str_replace($file, $instance-> _errorPage, $_SERVER["SCRIPT_NAME"])); exit(); } private static function redirectToErrorSendPage() { $instance = self::initialize(); ob_end_clean(); $f = explode("/", $_SERVER["SCRIPT_NAME"]); $file = array_pop($f); header("location: http://" . $_SERVER["HTTP_HOST"] . str_replace($file, $instance-> _errorPage2, $_SERVER["SCRIPT_NAME"])); exit(); } private static function returnOutput() { $instance = self::initialize(); ob_end_flush(); } } ?> Fatal error: Class 'BugTracker' not found in /home/mojos/domains/mojos.pl/public_html/_includes/_bootstrap.php on line 98