Пример #1
0
 function query($que)
 {
     $t1 = microtime(true);
     global $_SQLDEBUG, $_BACKTRACE;
     if ($_SQLDEBUG) {
         mydump($que);
     }
     if ($_BACKTRACE) {
         mydump(backtrace());
         //debug_print_backtrace();
     }
     if (!($ret = @mysql_query($que, $this->link))) {
         mylog($que, 'dberror');
         mylog(mysql_errno($this->link) . " : " . mysql_error($this->link), 'dberror');
         throw new MysqlException("Error in query {$que}:" . mysql_error($this->link));
     }
     $t2 = microtime(true);
     $time = $t2 - $t1;
     $this->totalQueTime += $time;
     if ($_SQLDEBUG) {
         mydump(sprintf("time: %.05f sec", $time));
     }
     if ($_SQLDEBUG) {
         mydump(sprintf("totaltime: %.05f sec", $this->totalQueTime));
     }
     return $ret;
 }
Пример #2
0
function backtrace($i)
{
    if ($i < 6) {
        return backtrace($i + 1);
    }
    echo $cool;
}
Пример #3
0
/**
    Main Utilities
    
    Helper functions used throughout the system.
    
    @package utility
*/
function bail($msg)
{
    if (is_array($msg)) {
        $msg = array_dump($msg);
    }
    $html = '';
    if (class_exists('Router')) {
        $router = Router::singleton();
        $html .= '
        <h1 style="margin-bottom:0;">' . $router->controller . '</h1>
        <h3 style="margin:4px 0;">Action: ' . $router->action . '</h3>
        <h3 style="margin:4px 0;">Method: ' . $router->method . '</h3>
        <h3 style="margin:6px 0 2px 0;"><u>Params</u></h3></dt> 
        ' . array_dump($router->params()) . '
        ';
    }
    $html .= '
        <h2 style="margin-bottom:2px;">ERROR MESSAGE</h2><pre>' . $msg . '</pre><br>
        <h2 style="margin-bottom:6px;">BACKTRACE</h2>
        ' . backtrace() . '
        ';
    echo $html;
    trigger_error(strip_tags($msg));
    exit;
}
Пример #4
0
function log_warning($str, $file = '', $line = '')
{
    if (empty($file) || empty($line)) {
        $file = backtrace(1, 'file');
        $line = backtrace(1, 'line');
    }
    $GLOBALS['engine_errors']['warning'][] = array('file' => $file, 'line' => $line, 'str' => $str);
}
Пример #5
0
function custom_error_handler($errno, $errstr, $errfile, $errline, $errcontext)
{
    global $EMAIL;
    # If the error is not of a type we were looking for, fall back to default error handler.
    $errno = $errno & error_reporting();
    if ($errno == 0) {
        # Returning false tells PHP to fall back to the default error handler.
        return false;
    }
    # Unless the error is just a warning or notice, let the user know what happened.
    if ($errno != E_WARNING && $errno != E_NOTICE) {
        # Indicate that we had some sort of internal error on the server.
        header('HTTP/1.0 500 Internal Server Error');
        ?>
        <html>
         <head>
          <title>Error</title>
	     </head>
         <body>
          <h1>An unrecoverable error has occured.</h1>
          <h2>An email has been sent to our support team.</h2>
          <h2>We apologize for the inconvenience.</h2>
         </body>
        <html>
<?php 
    }
    $errtype = errno_to_errtype($errno);
    $uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    # NOTE: This is a bit simplified.
    $remote_system = $_SERVER['REMOTE_ADDR'] . ', port ' . $_SERVER['REMOTE_PORT'];
    $date_time = date('Y-m-d H:i:s T');
    $error_message = "\n";
    $error_message .= "Error number: {$errno} ({$errtype})\n";
    $error_message .= "Error string: {$errstr}\n";
    $error_message .= "Error file: {$errfile}\n";
    $error_message .= "Error line: {$errline}\n\n";
    $error_message .= "URI: {$uri}\n";
    $error_message .= "Remote IP: {$remote_system}\n";
    $error_message .= "Date and time: {$date_time}\n\n";
    $error_message .= backtrace();
    $error_message .= "\n";
    $error_message .= dump_globals();
    $error_message .= "\n";
    print '<div style="background:#FFAAAA; border:solid #FF0000 5px"><h3>PHP ERROR</h3><pre>';
    print $error_message;
    print '</pre></div>';
    # Email the error message to the admin(s).
    $subject = "An error occured on the XXXXX web site.";
    $headers = "From: {$EMAIL['from']}\r\n";
    # TODO: Only send email if in production. (Or use a config setting.)
    #	mail($EMAIL['report_errors_to'], $subject, $error_message, $headers);
    # If it's just a warning or a notice, let the program continue.
    if ($errno == E_WARNING || $errno == E_NOTICE) {
        return;
    } else {
        die;
    }
}
Пример #6
0
 function getHTML($message = null)
 {
     $html = '';
     $html .= '<h2>' . get_class($this) . (isset($message) ? ': ' . $message : '') . '</h2>';
     $html .= '<p>' . $this->getMessage() . '</p>';
     $html .= '<p><font color=blue>' . $this->getMyFile() . ':' . $this->getMyLine() . '</font></p>';
     $html .= $this->getDetailedHTML();
     $html .= backtrace($this->shift + 1, $this->getMyTrace());
     return $html;
 }
Пример #7
0
 public function CreateFromException($exception)
 {
     ob_start();
     var_dump($exception->getTrace(), 5);
     $stack = str_replace("\t", "----", str_replace("\n", "<br>", ob_get_clean()));
     $data = "<b>MESSAGE:</b> " . $exception->getMessage() . "<br>";
     $data .= "<b>FILE:</b> " . $exception->getFile() . ", " . $exception->getLine() . "<br>";
     $data .= "<b>CODE:</b> " . get_class($exception) . "<br>";
     $data .= "<br><b>BACK TRACE:</b> " . backtrace();
     return $this->Create()->Text($exception->getMessage())->Tags("error " . get_class($exception))->Data($data)->DataType(DataType::html);
 }
Пример #8
0
function test_file_header($file, $dest_file, $do_include = true)
{
    $file = realpath($file);
    $codehome = dirname(ZESK_ROOT);
    if (begins($file, ZESK_ROOT)) {
        $from_codehome = false;
        $n = strlen(ZESK_ROOT);
    } else {
        if (begins($file, $codehome)) {
            $from_codehome = true;
            $n = strlen($codehome);
        } else {
            backtrace(false);
            echo "{$file} doesn't begin with " . ZESK_ROOT . " or " . $codehome . "\n";
            exit(1);
        }
    }
    $file = substr($file, $n);
    $n = substr_count($dest_file, "/", $n);
    $ndirnames = "dirname(__FILE__)";
    for ($i = 0; $i < $n; $i++) {
        $ndirnames = "dirname(" . $ndirnames . ")";
    }
    $contents = array();
    $contents[] = "#!/usr/bin/env php";
    $contents[] = "<" . "?php";
    $contents[] = "/**";
    $contents[] = " * @version \$URL\$";
    $contents[] = " * @package zesk";
    $contents[] = " * @subpackage test";
    $contents[] = " * @author \$Author\$";
    $contents[] = " * @copyright Copyright &copy; " . date('Y') . ", Market Acumen, Inc.";
    $contents[] = " */";
    if (!$from_codehome) {
        $contents[] = "if (!defined('ZESK_ROOT')) define('ZESK_ROOT', " . $ndirnames . ".'/');";
        $contents[] = "require_once ZESK_ROOT . 'zesk.inc';";
    } else {
        $contents[] = "if (!defined('CODEHOME')) define('CODEHOME', " . $ndirnames . ".'/');";
        $contents[] = "require_once CODEHOME . 'zesk/zesk.inc';";
    }
    $contents[] = "Test_Unit::init();";
    $contents[] = "";
    if ($do_include) {
        if (!$from_codehome) {
            $contents[] = "require_once ZESK_ROOT . '{$file}';";
        } else {
            $contents[] = "require_once CODEHOME . '{$file}';";
        }
        $contents[] = "";
    }
    return $contents;
}
Пример #9
0
 function execute(&$observer)
 {
     if (SC::isEmpty('board_config.econ_disabled')) {
         return TRUE;
     }
     $observer->set('error.code', GENERAL_MESSAGE);
     $observer->set('error.title', 'Econ Disabled');
     $observer->set('error.message', 'The economy of gaia is currently disabled.');
     $observer->set('error.line', __LINE__);
     $observer->set('error.file', __FILE__);
     $observer->set('error.debug', backtrace());
     return FALSE;
 }
Пример #10
0
 /**
  * Execute the model
  * @param Container    The Observer object.
  * @return bool        TRUE if successful, else FALSE.
  * @access public
  */
 function execute(&$observer)
 {
     if (SC::isEmpty('board_config.inventory_disable')) {
         return TRUE;
     }
     $observer->set('error.code', GENERAL_MESSAGE);
     $observer->set('error.title', 'Profile Disabled');
     $observer->set('error.message', 'The profile section of the site is currently disabled.');
     $observer->set('error.line', __LINE__);
     $observer->set('error.file', __FILE__);
     $observer->set('error.debug', backtrace());
     return FALSE;
 }
Пример #11
0
 /**
  * Execute the model
  * @param Container    The Observer object.
  * @return bool        TRUE if successful, else FALSE.
  * @access public
  */
 function execute(&$observer)
 {
     if (SC::isEmpty('board_config.artarena_disable')) {
         return TRUE;
     }
     $observer->set('error.code', GENERAL_MESSAGE);
     $observer->set('error.title', 'Arena Disabled');
     //$observer->set('error.message', 'Testing is now over for Housing Arena. The Housing Arena has been disabled in preparation for a full release. We thank you for helping us and hope you will join us once again when Housing Arena is back up and fully running. All entries submitted during the testing phase will be deleted.');
     $observer->set('error.message', 'The Art Arena is currently disabled. Please check back later');
     $observer->set('error.line', __LINE__);
     $observer->set('error.file', __FILE__);
     $observer->set('error.debug', backtrace());
     return FALSE;
 }
 /**
  * Execute the model
  * @param Container    The Observer object.
  * @return bool        TRUE if successful, else FALSE.
  * @access public
  */
 function execute(&$observer)
 {
     $flux =& FluxCapacitor::create('agent.checkserverloadavg');
     $rs =& $flux->execute();
     if ($rs->isSuccess()) {
         return TRUE;
     }
     $observer->set('error.code', GENERAL_ERROR);
     $observer->set('error.title', 'Server Overload');
     $observer->set('error.message', 'Server is busy due to heavy traffic.<BR/>Please try again in 5 minutes');
     $observer->set('error.line', __LINE__);
     $observer->set('error.file', __FILE__);
     $observer->set('error.debug', backtrace());
     return FALSE;
 }
Пример #13
0
function bail($msg = '')
{
    if (is_array($msg)) {
        $msg = array_dump($msg);
    }
    $html = '';
    $html .= '
				<h2 style="margin-bottom:2px;">ERROR MESSAGE</h2>' . $msg . '<br>
				<h2 style="margin-bottom:6px;">BACKTRACE</h2>
				' . backtrace() . '
				';
    echo $html;
    trigger_error(strip_tags($msg));
    exit;
}
 /**
  * Execute the model
  * @param Container    The Observer object.
  * @return bool        TRUE if successful, else FALSE.
  * @access public
  */
 function execute(&$observer)
 {
     $flux = FluxCapacitor::create('agent.checkboardconfigvar');
     $flux->checkVarNames('avatar_save_disable');
     $rs = $flux->execute();
     $vars = $rs->getVariables();
     if (intval($vars['avatar_save_disable']) == 0) {
         return TRUE;
     }
     $observer->set('error.code', GENERAL_MESSAGE);
     $observer->set('error.title', 'Save Disabled');
     $observer->set('error.message', 'Avatar saving is currently disabled.');
     $observer->set('error.line', __LINE__);
     $observer->set('error.file', __FILE__);
     $observer->set('error.debug', backtrace());
     return FALSE;
 }
Пример #15
0
 function Template($viewroot, $filename) {       // the constructor function
  if ($filename=="") {
   echo "Wrong declaration of new Template. Backtrace:<br>";
   echo backtrace();
   return;
  }
  $this->viewroot = $viewroot."/templates/";
  $this->filename=$this->viewroot.$filename;
  if (is_file($this->filename)) {                                       // load template from file
   $this->template = filestr($this->filename);
   $this->srctemplate = $this->template;
   $this->is_template = 1;
  } else {
   $this->template = $filename ;                                        // if this is not a file - load as raw data
   $this->srctemplate = $this->template;
   $this->is_template = 0;
  }
 }
Пример #16
0
function error_handler($errno, $errmsg, $filename, $linenum)
{
    $dt = date("Y-m-d H:i:s (T)");
    $errortype = array(E_ERROR => "Error", E_WARNING => "Warning", E_PARSE => "Parse Error", E_NOTICE => "Notice", E_CORE_ERROR => "Core Error", E_CORE_WARNING => "Core Warning", E_COMPILE_ERROR => "Compile Error", E_COMPILE_WARNING => "Compile Warning", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice");
    // set of errors for which a var trace will be saved
    //$user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
    $output = <<<EOT
<style type="text/css">
<!-- 
    .red_bold {color:red; font-weight:bold;}
    .error { border: 1px solid grey; color: #000000;}
    .error p.errmsg { font-size: 1em;  background-color: #990033; color: white; margin: 0 0 0 0;}
    .error p.errfile { font-size: .8em; font-style: italic; margin: 0 0 0 20px;}
    .error table.backtrace { }
    .error table.backtrace th { text-align: left; background-color: #339900; color: white}
    .error table.backtrace td {  color: #000000; background-color: #E8E8E8;}
    .error table.backtrace span.function { font-weight: bold; }
    .error table.backtrace span.file { font-size: .8em; font-style: italic; }
    .error table.backtrace span.args { color: #000000; }
-->
</style>
EOT;
    $output .= "<div class=\"error\">";
    $output .= "<p class=\"errmsg\">{$errortype[$errno]} : {$errmsg}</p>\n";
    $output .= "<p class=\"errfile\">in file {$filename} : {$linenum}</p>\n";
    $output .= backtrace();
    $output .= "</div>";
    echo $output;
    // save to the error log, and e-mail it if there is a critical user error
    /*
    error_log($err, 3, "/error.log");
    if ($errno == E_USER_ERROR) {
    mail("*****@*****.**", "Critical User Error", $err);
    }
    */
}
Пример #17
0
 function includes_info()
 {
     backtrace(get_included_files(), 'e', 'Include files');
 }
Пример #18
0
 /**
  * @param string $type
  *
  * @return string
  */
 protected function normalizeType(string $type) : string
 {
     $type = ltrim($type, '\\');
     foreach (self::module()->namespaces as $name => $namespace) {
         if (strpos($type, $namespace->getClassNamespace()) !== false) {
             return $name . substr($type, strlen($namespace->getClassNamespace()) + 1);
         }
     }
     backtrace();
     return null;
 }
Пример #19
0
function errorHandlerLogged($errno, $errstr, $errfile, $errline)
{
    global $errorLog, $_errors;
    switch ($errno) {
        case PM_FATAL:
            if (isset($_errors)) {
                $_errors .= '<hr noshade size=1 width=100%>';
            }
            echo "<div style=\"border: 1 solid #A0A0A0; background-color: #FFFDA0; padding: 5px;\">\n              {$_errors}<dt><b><span style='color:red'>Fatal error </span></b> at {$errfile}:{$errline}</dt>\n              <dd>Description: {$errstr}</dd></div>\n";
            $errorLog->writeLine($errno, $errstr, $errfile, backtrace());
            exit - 1;
        case PM_ERROR:
            $_errors .= "<dt>Error at {$errfile}:{$errline}</dt><dd>Description: {$errstr}</dd>\n";
            $errorLog->writeLine($errno, 'Error: ' . $errstr, $errfile, backtrace());
            break;
        case PM_WARNING:
            $_errors .= "<dt>Warning at {$errfile}:{$errline}</dt><dd>Description: {$errstr}</dd>\n";
            $errorLog->writeLine($errno, 'Warning: ' . $errstr, $errfile, $errline);
            break;
        default:
            if (strpos($errstr, 'Deprecated') === false) {
                $errors .= "<dt>PHP error at {$errfile}:{$errline}</dt><dd>Description: {$errstr}</dd>\n";
                $errorLog->writeLine($errno, 'PHP error: ' . $errstr, $errfile, $errline);
            }
            break;
    }
}
Пример #20
0
function errhandler($type, $msg, $file, $line, $context)
{
    #print "---------------------.";
    #print_r($GLOBALS['backtrace_printed_a_lot']); # just for debugging the reminder-var
    #print ".---------------------";
    switch ($type) {
        case E_ERROR:
        case E_USER_ERROR:
            # php4
            backtrace(false, "ERROR:", $msg, true);
            # DO NOT DISABLE THIS LINE
            break;
        case E_WARNING:
        case E_USER_WARNING:
            # php4
            backtrace(false, "WARNING:", $msg, true);
            # Think before disabling this one
            break;
        case E_NOTICE:
        case E_USER_NOTICE:
            # php4
            # this might be annoying, but usually indicates non-fatal errors...
            backtrace(false, "INFO:", $msg, false);
            print "<b>Hint:</b> use the @ symbol in front of function or brackets to suppress unavoidable errors.<br>";
            break;
        default:
            backtrace(false, "TYPE " . $type . ":", $msg, false);
            print "<b>Hint:</b> lookup the errorcode <a target=_new href='http://php.net/manual/en/ref.errorfunc.php#errorfunc.constants'> HERE </a><br>";
            break;
    }
}
Пример #21
0
/**
 * Clean replacement for die(), outputs a message with debugging info if needed and ends output
 *
 * @param string $text Text to display on error page
 * @param string $title Title to place on web page
 * @param string $file Filename to display
 * @param string $line Line in file to display
 * @param string $sql Any SQL text to display
 */
function die_quietly($text = '', $title = 'Message', $file = '', $line = '', $sql = '')
{
    global $roster;
    if ($roster->pages[0] == 'ajax') {
        ajax_die($text, $title, $file, $line, $sql);
    }
    // die_quitely died quietly
    if (defined('ROSTER_DIED')) {
        echo "<pre>The quiet die function suffered a fatal error. Die information below\n";
        echo "First die data:\n";
        print_r($GLOBALS['die_data']);
        echo "\nSecond die data:\n";
        print_r(func_get_args());
        if (!empty($roster->error->report)) {
            echo "\nPHP Notices/Warnings:\n";
            print_r($roster->error->report);
        }
        exit;
    }
    define('ROSTER_DIED', true);
    $GLOBALS['die_data'] = func_get_args();
    $roster->output['title'] = $title;
    if (!defined('ROSTER_HEADER_INC') && is_array($roster->config)) {
        include_once ROSTER_BASE . 'header.php';
    }
    if (!defined('ROSTER_MENU_INC') && is_array($roster->config)) {
        $roster_menu = new RosterMenu();
        $roster_menu->makeMenu($roster->output['show_menu']);
    }
    if (is_object($roster->db)) {
        $roster->db->close_db();
    }
    echo border('sred', 'start', $title) . '<table class="bodyline" cellspacing="0" cellpadding="0">' . "\n";
    if (!empty($text)) {
        echo "<tr>\n<td class=\"membersRowRight1\" style=\"white-space:normal;\"><div align=\"center\">{$text}</div></td>\n</tr>\n";
    }
    if (!empty($sql)) {
        echo "<tr>\n<td class=\"membersRowRight1\" style=\"white-space:normal;\">SQL:<br />" . sql_highlight($sql) . "</td>\n</tr>\n";
    }
    if (!empty($file)) {
        $file = str_replace(ROSTER_BASE, '', $file);
        echo "<tr>\n<td class=\"membersRowRight1\">File: {$file}</td>\n</tr>\n";
    }
    if (!empty($line)) {
        echo "<tr>\n<td class=\"membersRowRight1\">Line: {$line}</td>\n</tr>\n";
    }
    if ($roster->config['debug_mode'] == 2) {
        echo "<tr>\n<td class=\"membersRowRight1\" style=\"white-space:normal;\">";
        echo backtrace();
        echo "</td>\n</tr>\n";
    }
    echo "</table>\n" . border('sred', 'end');
    if (!defined('ROSTER_FOOTER_INC') && is_array($roster->config)) {
        include_once ROSTER_BASE . 'footer.php';
    }
    exit;
}
Пример #22
0
function find_dir($name)
{
    //ищем директорию, везде где возможно:)
    //приоритет:
    // 1. ищем ее в папке вызвавшего файла
    // 2. ищем в корне сайта (1 и 2 пункт меняются в зависимости от режима работы)
    // 3. ищем в директории admin
    // 4. ищем по Include_path
    // 5. ищем на уровень выше, от вызвавшего файла:)
    // 1.
    $bt = backtrace(1, 'file');
    $path = explode("/", path($bt));
    array_pop($path);
    $dir = implode("/", $path) . "/" . $name;
    $rp = realpath($dir);
    if (is_dir($dir)) {
        return path($rp) . "/";
    }
    // 2.
    $rp = realpath($name);
    if (is_dir($name)) {
        return path($rp) . "/";
    }
    // 3.
    if (is_dir('admin')) {
        //мы на сайте
        $rp = realpath("admin/" . $name);
        if (is_dir("admin/" . $name)) {
            return path($rp) . "/";
        }
    } else {
        //мы в админке
        $rp = realpath("../" . $name);
        if (is_dir("../" . $name)) {
            return path($rp) . "/";
        }
    }
    // 4.
    $inc = getIncludePaths();
    foreach ($inc as $pref) {
        if ($pref == "./") {
            continue;
        }
        if (is_dir($pref . $name)) {
            $rp = realpath($pref . $name);
            return path($rp) . "/";
        }
    }
    // 5.
    array_pop($path);
    $dir = implode("/", $path) . "/" . $name;
    if (is_dir($dir)) {
        $rp = realpath($dir);
        return path($rp) . "/";
    }
    log_notice('Директория "' . $name . '" не найдена', backtrace(1, 'file'), backtrace(1, 'line'));
    return false;
}
Пример #23
0
 /**
  * @param mixed $assertion
  * @param string|null $message
  *
  * @return mixed $assertion
  */
 function debug_assert($assertion, $message = null)
 {
     if (is_callable($assertion)) {
         $assertion = $assertion();
     }
     if (is_string($assertion)) {
         $assertion = eval($assertion);
     }
     if (!$assertion) {
         $handler = assert_options(ASSERT_CALLBACK);
         $message = var_dump_human_compact($message);
         if (null === $handler) {
             $handler = debug_handler_assertion_default_dg();
         }
         /** @var Callable $handler */
         $trace = backtrace(1);
         $file = isset($trace['file']) ? $trace['file'] : '';
         $line = isset($trace['line']) ? $trace['line'] : '';
         $handler($file, $line, $message);
     }
     return $assertion;
 }
Пример #24
0
<div class="titon-inspect">
    <?php 
$backtrace = backtrace($exception);
$class = get_class($exception);
?>

    <div class="debug-head">
        <?php 
if ($backtrace) {
    ?>
            <a href="javascript:;" onclick="return toggleBacktrace();" class="debug-method"><?php 
    echo $class;
    ?>
</a>:
        <?php 
} else {
    ?>
            <span class="debug-method"><?php 
    echo $class;
    ?>
</span>:
        <?php 
}
?>

        <span class="debug-message"><?php 
echo esc($exception->getMessage());
?>
</span>

        <abbr title="<?php