kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file bit_error_inc.php

Documentation is available at bit_error_inc.php

  1. <?php
  2. /**
  3.  * Custom ADODB Error Handler. This will be called with the following params
  4.  *
  5.  * @package kernel
  6.  * @subpackage functions
  7.  * @version V3.94  13 Oct 2003  (c) 2000-2003 John Lim (jlim@natsoft.com.my). All rights reserved.
  8.  *  Released under both BSD license and Lesser GPL library license.
  9.  *  Whenever there is any discrepancy between the two licenses,
  10.  *  the BSD license will take precedence.
  11.  *
  12.  *  Set tabs to 4 for best viewing.
  13.  *
  14.  *  Latest version is available at http://php.weblogs.com
  15.  *
  16.  */
  17.  
  18. /**
  19.  * set error handling
  20.  */
  21. if!defined'BIT_INSTALL' &&  !defined'ADODB_ERROR_HANDLER' )  ) {
  22.     define'ADODB_ERROR_HANDLER''bit_error_handler' );
  23. }
  24.  
  25. function bit_log_error$pLogMessage$pSubject$pFatal TRUE {
  26.     // You can prevent sending of error emails by adding define('ERROR_EMAIL', ''); in your config_inc.php
  27.     $errorEmail defined'ERROR_EMAIL' ERROR_EMAIL (!empty$_SERVER['SERVER_ADMIN'$_SERVER['SERVER_ADMIN'NULL);
  28.  
  29.     error_log$pLogMessage );
  30.  
  31.     if( ( !defined'IS_LIVE' || !IS_LIVE ) ) {
  32.         print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
  33.             <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  34.             <head>
  35.                 <title>bitweaver - White Screen of Death</title>
  36.             </head>
  37.             <body style="background:#fff; font-family:monospace;">';
  38. //         print "<h1>Upgrade Beta 1 to Beta 2</h1>If you are getting this error because you just upgraded your bitweaver from Beta 1 to Beta 2, please follow this link to the installer, which will guide you through the upgrade process: <a href='".BIT_ROOT_URL."install/install.php?step=4'>Upgrade Beta 1 to Beta 2</a>";
  39.         print "<h1 style=\"color:#900; font-weight:bold;\">You are running bitweaver in TEST mode</h1>\n";
  40.         print "
  41.             <ul>
  42.                 <li><a href='http://sourceforge.net/tracker/?func=add&amp;group_id=141358&amp;atid=749176'>Click here to log a bug</a>, if this appears to be an error with the application.</li>
  43.                 <li><a href='".BIT_ROOT_URL."install/install.php'>Go here to begin the installation process</a>, if you haven't done so already.</li>
  44.                 <li>To hide this message, please <strong>set the IS_LIVE constant to TRUE</strong> in your kernel/config_inc.php file.</li>
  45.             </ul>
  46.             <hr />
  47.         ";
  48.         print "<pre>".$pLogMessage."</pre>";
  49.         print "<hr />";
  50.         print "</body></html>";
  51.     elseif$errorEmail {
  52.         mail$errorEmail,  "$pSubject"$pLogMessage );
  53.         if( ( defined'AUTO_BUG_SUBMIT' && AUTO_BUG_SUBMIT ) ) {
  54.             mail'bugs@bitweaver.org',"$subject $pSubject",$pLogMessage );
  55.         }
  56.     }
  57.  
  58.     if$pFatal {
  59.         die();
  60.     }
  61. }
  62.  
  63. function bit_error_string$iDBParms {
  64.     global $gBitDb;
  65.     global $gBitUser;
  66.     global $_SERVER;
  67.  
  68.     $separator "\n";
  69.     $indent "  ";
  70.  
  71.     $date date("D M d H:i:s Y")// [Tue Sep 24 12:19:20 2002] [error]
  72.  
  73.     ifisset$gBitUser->mInfo ) ) {
  74.         $acctStr "ID: ".$gBitUser->mInfo['user_id']." - Login: ".$gBitUser->mInfo['login']." - e-mail: ".$gBitUser->mInfo['email'];
  75.     else {
  76.         $acctStr "User unknown";
  77.     }
  78.  
  79.     $info  $indent."[ - ".BIT_MAJOR_VERSION.".".BIT_MINOR_VERSION.".".BIT_SUB_VERSION." ".BIT_LEVEL." - ] [ $date ]".$separator;
  80.     $info .= $indent."-----------------------------------------------------------------------------------------------".$separator;
  81.     $info .= $indent."#### USER AGENT: ".$_SERVER['HTTP_USER_AGENT'].$separator;
  82.     $info .= $indent."#### ACCT: ".$acctStr.$separator;
  83.     $info .= $indent."#### URL: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$separator;
  84.     ifisset($_SERVER['HTTP_REFERER') ) {
  85.         $info .= $indent."#### REFERRER$_SERVER[HTTP_REFERER]".$separator;
  86.     }
  87.     $info .= $indent."#### HOST$_SERVER[HTTP_HOST]".$separator;
  88.     $info .= $indent."#### IP$_SERVER[REMOTE_ADDR]".$separator;
  89.  
  90.     if$gBitDb && isset$php_errormsg ) ) {
  91.         $info .= $indent."#### PHP: ".$php_errormsg.$separator;
  92.     }
  93.  
  94.     if $iDBParms['sql'{
  95.         $badSpace array("\n""\t");
  96.         $info .= $indent."#### SQL: ".str_replace($badSpace' '$iDBParms['sql']).$separator;
  97.         ifis_array$iDBParms['p2') ) {
  98.             $info .= $indent.'['.implode', '$iDBParms['p2').']'.$separator;
  99.         }
  100.     }
  101.  
  102.     $errno ((int)$iDBParms['errno''Errno: '.$iDBParms['errno''');
  103.  
  104.     $info .= $indent."#### ERROR CODE: ".$errno."  Message: ".$iDBParms['db_msg'];
  105.  
  106.     $stackTrace bt9999FALSE );
  107.  
  108.     //multiline expressions matched
  109.     if preg_match_all("/.*adodb_error_handler\([^\}]*\)(.+\}.+)/ms"$stackTrace$match) ) {
  110.         $stackTrace $match[1][0];
  111.     }
  112.  
  113.     $ret $info.$separator.$separator.$stackTrace;
  114.  
  115.     return $ret;
  116. }
  117.  
  118. if (!function_exists('bt')) {    // Make sure another backtrace function does not exist
  119. function bt$levels=9999$iPrint=TRUE {
  120.     $s '';
  121.     if (PHPVERSION(>= 4.3{
  122.  
  123.         $MAXSTRLEN 64;
  124.  
  125.         $traceArr debug_backtrace();
  126.         array_shift($traceArr);
  127.         $tabs sizeof($traceArr)-1;
  128.         $indent '';
  129.         $sClass '';
  130.  
  131.         foreach ($traceArr as $arr{
  132.             $levels -= 1;
  133.             if ($levels 0break;
  134.  
  135.             $args array();
  136.             for ($i=0$i <= $tabs$i++{
  137.                 $indent .= '}';
  138.             }
  139.             $tabs -= 1;
  140.             if isset($arr['class']) ) {
  141.                 $sClass .= $arr['class'].'::';
  142.             }
  143.             if isset($arr['args']) ) {
  144.                 foreach$arr['args'as $v {
  145.                     if (is_null($v) ) {
  146.                         $args['null';
  147.                     elseif (is_array($v)) $args['Array['.sizeof($v).']';
  148.                     elseif (is_object($v)) $args['Object:'.get_class($v);
  149.                     elseif (is_bool($v)) $args[$v 'true' 'false';
  150.                     else {
  151.                         $v = (string) @$v;
  152.                         $str htmlspecialchars(substr($v,0,$MAXSTRLEN));
  153.                         if (strlen($v$MAXSTRLEN$str .= '...';
  154.                         $args[$str;
  155.                     }
  156.                 }
  157.             }
  158.             if!preg_match"*include*"$arr['function'&& !preg_match"*silentlog*"strtolower$arr['function') ) ) {
  159.                 $s .= "\n    ".$indent.'    -> ';
  160.                 $s .= $sClass.$arr['function'].'('.implode(', ',$args).')';
  161.             }
  162.             $s .= "\n    ".$indent;
  163.             $s .= @sprintf(" LINE: %4d, %s"$arr['line'],$arr['file']);
  164.             $indent '';
  165.         }
  166.         $s .= "\n";
  167.         if$iPrint {
  168.             print '<pre>'.$s."</pre>\n";
  169.         }
  170.     }
  171.     return $s;
  172. }
  173. }    // End if function_exists('bt')
  174. // var dump variable in something nicely readable in web browser
  175.  
  176. function vd$iVar {
  177.     print vc$iVar );
  178. }
  179.  
  180.  
  181. // var capture variable in something nicely readable in web browser
  182. function vc$iVar$pHtml=TRUE {
  183.     
  184.     ob_start();
  185.     ifis_object$iVar ) ) {
  186.         ifisset$iVar->mDb ) ) {
  187.             unset(     $iVar->mDb );
  188.         }
  189.     }
  190.  
  191.     // xdebug rocks!
  192.     ifextension_loaded'xdebug' ) ) {
  193.         var_dump$iVar );
  194.     elseif$pHtml && !empty$_SERVER['HTTP_USER_AGENT'&& $_SERVER['HTTP_USER_AGENT'!= 'cron' && ((is_object$iVar && !empty$iVar )) || is_array$iVar )) ) {
  195.         include_onceUTIL_PKG_PATH.'dBug/dBug.php' );
  196.         new dBug$iVar );
  197.     else {
  198.         print '<pre>';
  199.         ifis_object$iVar ) ) {
  200.             var_dump$iVar );
  201.         elseifis_string$iVar && !empty$_SERVER['HTTP_USER_AGENT'&& $_SERVER['HTTP_USER_AGENT'!= 'cron' {
  202.             var_dumphtmlentities$iVar ) );
  203.         else {
  204.             var_dump$iVar );
  205.         }
  206.         print "</pre>\n";
  207.     }
  208.     $ret ob_get_contents();
  209.     ob_end_clean();
  210.     return $ret;
  211. }
  212.  
  213.  
  214. function va$iVar {
  215.     $dbg var_export($iVar1);
  216.     $dbg highlight_string("<?\n"$dbg."\n?>"1);
  217.     echo "<div><span style='background-color:black;color:white;padding:.5ex;font-weight:bold;'>Var Anatomy</div>";
  218.     echo "<div style='border:1px solid black;padding:2ex;background-color:#efe6d6;'>$dbg</div>";
  219. }
  220.  
  221.  
  222. ?>

Documentation generated on Thu, 15 Feb 2007 20:32:54 +0000 by phpDocumentor 1.3.0