1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-12 17:44:37 +02:00

Removed old deprecated global $e107_debug. Cleaned up debug_handler.php (e107_debug class)

This commit is contained in:
Cameron
2020-04-26 13:32:18 -07:00
parent 406f74e3a5
commit 326305f5f2
11 changed files with 195 additions and 171 deletions

View File

@@ -30,81 +30,18 @@
// - In either case, create one or more shortcut/abbreviations in $aDebugShortcuts
// to make it easy for dev's to specify the new display item.
//
// USING DEBUG DEFINITIONS
// Since these are Bit Values, **never** test using < or > comparisons. Always
// test using boolean operations, such as
// if (E107_DBG_PATH)
// if (E107_DBG_SQLQUERIES | E107_DBG_SQLDETAILS)
// Since constants are defined for all possible bits, you should never need to use a number value like
// if (E107_DEBUG_LEVEL & 256)
// And there's never a reason to use
// if (E107_DEBUG_LEVEL > 254)
if (!defined('e107_INIT')) { exit; }
//
// If debugging enabled, set it all up
// If no debugging, then E107_DEBUG_LEVEL will be zero
//
if (strstr(e_MENU, "debug") || isset($_COOKIE['e107_debug_level']))
{
$e107_debug = new e107_debug;
// require_once(e_HANDLER.'db_debug_class.php');
//$db_debug = new e107_db_debug;
$db_debug = e107::getDebug();
$e107_debug->set_error_reporting();
$e107_debug_level = $e107_debug->debug_level;
if(!defined('E107_DEBUG_LEVEL'))
{
define('E107_DEBUG_LEVEL', $e107_debug_level);
}
}
elseif (!defined('E107_DEBUG_LEVEL'))
{
define('E107_DEBUG_LEVEL', 0);
}
if(!defined('e_DEBUG'))
{
$e_DEBUG = (E107_DEBUG_LEVEL > 0) ? true: false;
define('e_DEBUG', $e_DEBUG);
}
//
// Define all debug constants -- each one will be zero or a value
// They all have different values and can be 'or'ed together
//
// Basic levels
define('E107_DBG_BASIC', (E107_DEBUG_LEVEL & 1)); // basics: worst php errors, sql errors, log, etc
define('E107_DBG_SQLQUERIES', (E107_DEBUG_LEVEL & 2)); // display all sql queries
define('E107_DBG_TRAFFIC', (E107_DEBUG_LEVEL & 4)); // display traffic counters
define('E107_DBG_FILLIN8', (E107_DEBUG_LEVEL & 8)); // fill in what it is
define('E107_DBG_FILLIN16', (E107_DEBUG_LEVEL & 16)); // fill in what it is
define('E107_DBG_FILLIN32', (E107_DEBUG_LEVEL & 32)); // fill in what it is
define('E107_DBG_FILLIN64', (E107_DEBUG_LEVEL & 64)); // fill in what it is
define('E107_DBG_FILLIN128', (E107_DEBUG_LEVEL & 128)); // fill in what it is
// Gory detail levels
define('E107_DBG_TIMEDETAILS',(E107_DEBUG_LEVEL & 256)); // detailed time profile
define('E107_DBG_SQLDETAILS', (E107_DEBUG_LEVEL & 512)); // detailed sql analysis
define('E107_DBG_PATH', (E107_DEBUG_LEVEL & 1024)); // show e107 predefined paths
define('E107_DBG_BBSC', (E107_DEBUG_LEVEL & 2048)); // Show BBCode/ Shortcode usage in postings
define('E107_DBG_SC', (E107_DEBUG_LEVEL & 4096)); // Dump (inline) SC filenames as used
define('E107_DBG_ERRBACKTRACE', (E107_DEBUG_LEVEL & 8192)); // show backtrace for php errors
define('E107_DBG_DEPRECATED', (E107_DEBUG_LEVEL & 16384)); // Show use of deprecated functions
define('E107_DBG_ALLERRORS', (E107_DEBUG_LEVEL & 32768)); // show ALL php errors (including notices), not just fatal issues
define('E107_DBG_INCLUDES', (E107_DEBUG_LEVEL & 65536)); // show included file list
define('E107_DBG_NOTICES', (E107_DEBUG_LEVEL & 32768)); // show included file list
class e107_debug {
var $debug_level = 1;
//
// DEBUG SHORTCUTS
//
var $aDebugShortcuts = array(
private static $debug_level = 0;
/* DEBUG shortcuts */
private static $aDebugShortcuts = array(
'all' => 255, // all basics
'basic' => 255, // all basics
'b' => 255, // all basics
@@ -129,52 +66,141 @@ class e107_debug {
function __construct()
{
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU, $debug_param) || isset($_COOKIE['e107_debug_level']))
{
$dVals='';
if (!isset($debug_param[1]) || ($debug_param[1]=='')) $debug_param[1] = '=';
if (isset($_COOKIE['e107_debug_level']))
{
$dVals = substr($_COOKIE['e107_debug_level'],6);
}
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU))
{
$dVals = $debug_param[1] == '=' ? $debug_param[2] : 'everything';
}
$aDVal = explode('.',$dVals); // support multiple values, OR'd together
$dVal = 0;
foreach ($aDVal as $curDVal)
{
if (isset($this->aDebugShortcuts[$curDVal]))
{
$dVal |= $this->aDebugShortcuts[$curDVal];
}
else
{
$dVal |= intval($curDVal);
}
}
if (isset($debug_param[3]))
{
if ($debug_param[3] == '+' || $debug_param[3] == 'stick')
{
cookie('e107_debug_level', 'level='.$dVal, time() + 86400);
}
if ($debug_param[3] == '-' || $debug_param[3] == 'unstick')
{
cookie('e107_debug_level', '', time() - 3600);
}
}
$this->debug_level = $dVal;
}
}
public static function activated()
{
if ((strstr(e_MENU, "debug") || isset($_COOKIE['e107_debug_level'])) || deftrue('e_DEBUG')) // ADMIN and getperms('0') are not available at this point.
{
return true;
}
return false;
}
public static function init()
{
if(!self::activated())
{
self::setConstants();
return false;
}
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU, $debug_param) || isset($_COOKIE['e107_debug_level']))
{
$dVals = '';
if (!isset($debug_param[1]) || ($debug_param[1] == '')) $debug_param[1] = '=';
if (isset($_COOKIE['e107_debug_level']))
{
$dVals = substr($_COOKIE['e107_debug_level'], 6);
}
if (preg_match('/debug(=?)(.*?),?(\+|stick|-|unstick|$)/', e_MENU))
{
$dVals = $debug_param[1] == '=' ? $debug_param[2] : 'everything';
}
$aDVal = explode('.', $dVals); // support multiple values, OR'd together
$dVal = 0;
foreach ($aDVal as $curDVal)
{
if (isset(self::$aDebugShortcuts[$curDVal]))
{
$dVal |= self::$aDebugShortcuts[$curDVal];
}
else
{
$dVal |= intval($curDVal);
}
}
if (isset($debug_param[3]))
{
if ($debug_param[3] == '+' || $debug_param[3] == 'stick')
{
cookie('e107_debug_level', 'level=' . $dVal, time() + 86400);
}
if ($debug_param[3] == '-' || $debug_param[3] == 'unstick')
{
cookie('e107_debug_level', '', time() - 3600);
}
}
self::$debug_level = $dVal;
}
self::setConstants();
return true;
}
/**
* Define all debug constants -- each one will be zero or a value
* USING DEBUG DEFINITIONS
* Since these are Bit Values, **never** test using < or > comparisons. Always
* test using boolean operations, such as
* @example if (E107_DBG_PATH)
* @example if (E107_DBG_SQLQUERIES | E107_DBG_SQLDETAILS)
* Since constants are defined for all possible bits, you should never need to use a number value like
* @example if (E107_DEBUG_LEVEL & 256)
* And there's never a reason to use
* if (E107_DEBUG_LEVEL > 254)
*/
private static function setConstants()
{
if(!defined('E107_DEBUG_LEVEL'))
{
define('E107_DEBUG_LEVEL', self::getLevel());
}
// Basic levels
define('E107_DBG_BASIC', (E107_DEBUG_LEVEL & 1)); // basics: worst php errors, sql errors, log, etc
define('E107_DBG_SQLQUERIES', (E107_DEBUG_LEVEL & 2)); // display all sql queries
define('E107_DBG_TRAFFIC', (E107_DEBUG_LEVEL & 4)); // display traffic counters
define('E107_DBG_FILLIN8', (E107_DEBUG_LEVEL & 8)); // fill in what it is
define('E107_DBG_FILLIN16', (E107_DEBUG_LEVEL & 16)); // fill in what it is
define('E107_DBG_FILLIN32', (E107_DEBUG_LEVEL & 32)); // fill in what it is
define('E107_DBG_FILLIN64', (E107_DEBUG_LEVEL & 64)); // fill in what it is
define('E107_DBG_FILLIN128', (E107_DEBUG_LEVEL & 128)); // fill in what it is
// Gory detail levels
define('E107_DBG_TIMEDETAILS',(E107_DEBUG_LEVEL & 256)); // detailed time profile
define('E107_DBG_SQLDETAILS', (E107_DEBUG_LEVEL & 512)); // detailed sql analysis
define('E107_DBG_PATH', (E107_DEBUG_LEVEL & 1024)); // show e107 predefined paths
define('E107_DBG_BBSC', (E107_DEBUG_LEVEL & 2048)); // Show BBCode/ Shortcode usage in postings
define('E107_DBG_SC', (E107_DEBUG_LEVEL & 4096)); // Dump (inline) SC filenames as used
define('E107_DBG_ERRBACKTRACE', (E107_DEBUG_LEVEL & 8192)); // show backtrace for php errors
define('E107_DBG_DEPRECATED', (E107_DEBUG_LEVEL & 16384)); // Show use of deprecated functions
define('E107_DBG_ALLERRORS', (E107_DEBUG_LEVEL & 32768)); // show ALL php errors (including notices), not just fatal issues
define('E107_DBG_INCLUDES', (E107_DEBUG_LEVEL & 65536)); // show included file list
define('E107_DBG_NOTICES', (E107_DEBUG_LEVEL & 32768)); // show included file list
if(!defined('e_DEBUG'))
{
$e_DEBUG = (E107_DEBUG_LEVEL > 0);
define('e_DEBUG', $e_DEBUG);
}
}
public static function getLevel()
{
return self::$debug_level;
}
public static function setLevel($level = 0)
{
self::$debug_level = $level;
}
function set_error_reporting()
{
@@ -183,6 +209,7 @@ class e107_debug {
// Quick debug message logger
// Example: e7debug(__FILE__.__LINE__.": myVar is ".print_r($myVar,TRUE));
/*
function e7debug($message,$TraceLev=1)
{
if (!E107_DEBUG_LEVEL) return;
@@ -192,5 +219,4 @@ function e7debug($message,$TraceLev=1)
$db_debug->log($message,$TraceLev);
}
}
?>
*/