From 42147e2227dd8167f500f666a7df8ccaf41b8b8d Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 10 Feb 2019 14:51:51 -0800 Subject: [PATCH] Traffic counters tweak. --- e107_handlers/db_debug_class.php | 1259 ++++++++++++++++-------------- e107_handlers/e_db_pdo_class.php | 32 +- 2 files changed, 669 insertions(+), 622 deletions(-) diff --git a/e107_handlers/db_debug_class.php b/e107_handlers/db_debug_class.php index d79b39198..58331ee45 100644 --- a/e107_handlers/db_debug_class.php +++ b/e107_handlers/db_debug_class.php @@ -1,396 +1,418 @@ ''); // Track output buffer level at each time mark - var $aMarkNotes = array(); // Other notes can be added and output... - var $aTimeMarks = array(); // Overall time markers - var $curTimeMark = 'Start'; - var $nTimeMarks = 0; // Provide an array index for time marks. Stablizes 'current' function - var $aGoodQueries = array(); - var $aBadQueries = array(); - var $scbbcodes = array(); - var $scbcount; - var $deprecated_funcs = array(); - var $aLog = array(); // Generalized debug log (only seen during debug) - var $aIncList = array(); // Included files - - function __construct() - { - - - - } - - function e107_db_debug() { - global $eTimingStart; - - $this->aTimeMarks[0]=array( - 'Index' => 0, - 'What' => 'Start', - '%Time' => 0, - '%DB Time' => 0, - '%DB Count' => 0, - 'Time' => ($eTimingStart), - 'DB Time' => 0, - 'DB Count' => 0, - 'Memory' => 0 - ); - - register_shutdown_function('e107_debug_shutdown'); + if(!defined('e107_INIT')) + { + exit; } + + class e107_db_debug + { + + var $aSQLdetails = array(); // DB query analysis (in pieces for further analysis) + var $aDBbyTable = array(); + var $aOBMarks = array(0 => ''); // Track output buffer level at each time mark + var $aMarkNotes = array(); // Other notes can be added and output... + var $aTimeMarks = array(); // Overall time markers + var $curTimeMark = 'Start'; + var $nTimeMarks = 0; // Provide an array index for time marks. Stablizes 'current' function + var $aGoodQueries = array(); + var $aBadQueries = array(); + var $scbbcodes = array(); + var $scbcount; + var $deprecated_funcs = array(); + var $aLog = array(); // Generalized debug log (only seen during debug) + var $aIncList = array(); // Included files + + function __construct() + { + + + } + + function e107_db_debug() + { + + global $eTimingStart; + + $this->aTimeMarks[0] = array( + 'Index' => 0, + 'What' => 'Start', + '%Time' => 0, + '%DB Time' => 0, + '%DB Count' => 0, + 'Time' => ($eTimingStart), + 'DB Time' => 0, + 'DB Count' => 0, + 'Memory' => 0 + ); + + register_shutdown_function('e107_debug_shutdown'); + } + // // Add your new Show function here so it will display in debug output! // - function Show_All() - { - $this->ShowIf('Debug Log', $this->Show_Log()); - $this->ShowIf('Traffic Counters', e107::getSingleton('e107_traffic')->Display()); - $this->ShowIf('Time Analysis', $this->Show_Performance()); - $this->ShowIf('SQL Analysis', $this->Show_SQL_Details()); - $this->ShowIf('Shortcodes / BBCode',$this->Show_SC_BB()); - $this->ShowIf('Paths', $this->Show_PATH()); - $this->ShowIf('Deprecated Function Usage', $this->Show_DEPRECATED()); - - if(E107_DBG_INCLUDES) - { - $this->aIncList = get_included_files(); - } - - $this->ShowIf('Included Files: '.count($this->aIncList), $this->Show_Includes()); - } - - function ShowIf($title,$str) - { - - if(!empty($str)) + function Show_All() { - //e107::getRender()->setStyle('debug'); - echo "

".$title."

"; - echo $str; - //e107::getRender()->tablerender($title, $str); - } - } - function Mark_Time($sMarker) { // Should move to traffic_class? - $timeNow=microtime(); - $nMarks=++$this->nTimeMarks; - - if (!strlen($sMarker)) { - $sMarker = "Mark not set"; - } + $this->ShowIf('Debug Log', $this->Show_Log()); + $this->ShowIf('Traffic Counters', e107::getSingleton('e107_traffic')->Display()); + $this->ShowIf('Time Analysis', $this->Show_Performance()); + $this->ShowIf('SQL Analysis', $this->Show_SQL_Details()); + $this->ShowIf('Shortcodes / BBCode', $this->Show_SC_BB()); + $this->ShowIf('Paths', $this->Show_PATH()); + $this->ShowIf('Deprecated Function Usage', $this->Show_DEPRECATED()); - $srch = array('[',']'); - $repl = array("",""); - - $this->aTimeMarks[$nMarks]=array( - 'Index' => ($this->nTimeMarks), - 'What' => str_replace($srch,$repl,$sMarker), - '%Time' => 0, - '%DB Time' => 0, - '%DB Count' => 0, - 'Time' => $timeNow, - 'DB Time' => 0, - 'DB Count' => 0, - 'Memory' => ((function_exists("memory_get_usage"))? memory_get_usage() : 0) - ); - - $this->aOBMarks[$nMarks]=ob_get_level().'('.ob_get_length().')'; - $this->curTimeMark=$sMarker; - - // Add any desired notes to $aMarkNotes[$nMarks]... e.g. - //global $eTimingStart; - //$this->aMarkNotes[$nMarks] .= "verify start: ".$eTimingStart."
"; - } - - - /** - * @param $query - * @param $rli - * @param $origQryRes - * @param $aTrace - * @param $mytime - * @param $curtable - */ - function Mark_Query($query, $rli, $origQryRes, $aTrace, $mytime, $curtable) - { - // global $sql; - $sql = e107::getDb( $rli); - - // Explain the query, if possible... - list($qtype,$args) = explode(" ", ltrim($query), 2); - - $nFields=0; - $bExplained = FALSE; - $ExplainText = ''; - // Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match - if (!strcasecmp($qtype,'SELECT') || !strcasecmp($qtype,'(SELECT')) - { // It's a SELECT statement - explain it - // $rli should always be set by caller - // $sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli)); - - $sQryRes = $sql->gen("EXPLAIN {$query}"); - - if ($sQryRes) // There's something to explain - { - //$nFields = mysql_num_fields($sQryRes); - $nFields = $sql->columnCount($sQryRes); // mysql_num_fields($sQryRes); - $bExplained = TRUE; - } - } - else - { // Don't run 'EXPLAIN' on other queries - $sQryRes = $origQryRes; // Return from original query could be TRUE or a link resource if success - } - - // Record Basic query info - $sCallingFile = varset($aTrace[2]['file']); - $sCallingLine = varset($aTrace[2]['line']); - - $t = &$this->aSQLdetails[$sql->db_QueryCount()]; - $t['marker'] = $this->curTimeMark; - $t['caller'] = "$sCallingFile($sCallingLine)"; - $t['query'] = $query; - $t['ok'] = ($sQryRes !==false) ? true : false; - $t['error'] = $sQryRes ? '' : $sql->getLastErrorText(); // mysql_error(); - $t['nFields'] = $nFields; - $t['time'] = $mytime; - - if ($bExplained) - { - $bRowHeaders=FALSE; - // while ($row = @mysql_fetch_assoc($sQryRes)) - while ($row = $sql->fetch()) + if(E107_DBG_INCLUDES) { - if (!$bRowHeaders) + $this->aIncList = get_included_files(); + } + + $this->ShowIf('Included Files: ' . count($this->aIncList), $this->Show_Includes()); + } + + function ShowIf($title, $str) + { + + if(!empty($str)) + { + //e107::getRender()->setStyle('debug'); + echo "

" . $title . "

"; + echo $str; + //e107::getRender()->tablerender($title, $str); + } + } + + function Mark_Time($sMarker) + { // Should move to traffic_class? + $timeNow = microtime(); + $nMarks = ++$this->nTimeMarks; + + if(!strlen($sMarker)) + { + $sMarker = "Mark not set"; + } + + $srch = array('[', ']'); + $repl = array("", ""); + + $this->aTimeMarks[$nMarks] = array( + 'Index' => ($this->nTimeMarks), + 'What' => str_replace($srch, $repl, $sMarker), + '%Time' => 0, + '%DB Time' => 0, + '%DB Count' => 0, + 'Time' => $timeNow, + 'DB Time' => 0, + 'DB Count' => 0, + 'Memory' => ((function_exists("memory_get_usage")) ? memory_get_usage() : 0) + ); + + $this->aOBMarks[$nMarks] = ob_get_level() . '(' . ob_get_length() . ')'; + $this->curTimeMark = $sMarker; + + // Add any desired notes to $aMarkNotes[$nMarks]... e.g. + //global $eTimingStart; + //$this->aMarkNotes[$nMarks] .= "verify start: ".$eTimingStart."
"; + } + + + /** + * @param $query + * @param $rli + * @param $origQryRes + * @param $aTrace + * @param $mytime + * @param $curtable + */ + function Mark_Query($query, $rli, $origQryRes, $aTrace, $mytime, $curtable) + { + + // global $sql; + $sql = e107::getDb($rli); + + // Explain the query, if possible... + list($qtype, $args) = explode(" ", ltrim($query), 2); + + unset($args); + $nFields = 0; + $bExplained = false; + $ExplainText = ''; + // Note the subtle bracket in the second comparison! Also, strcasecmp() returns zero on match + if(!strcasecmp($qtype, 'SELECT') || !strcasecmp($qtype, '(SELECT')) + { // It's a SELECT statement - explain it + // $rli should always be set by caller + // $sQryRes = (is_null($rli) ? mysql_query("EXPLAIN {$query}") : mysql_query("EXPLAIN {$query}", $rli)); + + $sQryRes = $sql->gen("EXPLAIN {$query}"); + + if($sQryRes) // There's something to explain { - $bRowHeaders=TRUE; - $t['explain']="".implode("", array_keys($row))."\n"; - } - $t['explain'] .= "".implode(" ", array_values($row))." \n"; - } - } - else - { - $t['explain'] = $ExplainText; - } - - $this->aTimeMarks[$this->nTimeMarks]['DB Time'] += $mytime; - $this->aTimeMarks[$this->nTimeMarks]['DB Count']++; - - if (array_key_exists($curtable, $this->aDBbyTable)) - { - $this->aDBbyTable[$curtable]['DB Time'] += $mytime; - $this->aDBbyTable[$curtable]['DB Count']++; - } - else - { - $this->aDBbyTable[$curtable]['Table'] = $curtable; - $this->aDBbyTable[$curtable]['%DB Time'] = 0; // placeholder - $this->aDBbyTable[$curtable]['%DB Count'] = 0; // placeholder - $this->aDBbyTable[$curtable]['DB Time'] = $mytime; - $this->aDBbyTable[$curtable]['DB Count'] = 1; - } - } - - - - function Show_SQL_Details($force=false) { - global $sql; - // - // Show stats from aSQLdetails array - // - if (!E107_DBG_SQLQUERIES && !E107_DBG_SQLDETAILS && ($force === false)) - { - return false; - } - - - $text=''; - $nQueries=$sql->db_QueryCount(); - - if (!$nQueries) return $text; - - // - // ALWAYS summarize query errors - // - $badCount=0; - $okCount=0; - - foreach ($this->aSQLdetails as $cQuery) - { - if ($cQuery['ok']==1) - { - $okCount++; - } - else - { - $badCount++; - } - } - - if ($badCount) { - $text .= "\n\n"; - $text .= "\n"; - $text .= "\n"; - - foreach ($this->aSQLdetails as $idx => $cQuery) { - if (!$cQuery['ok']) - { - $text .= " - \n\n"; + //$nFields = mysql_num_fields($sQryRes); + $nFields = $sql->columnCount($sQryRes); // mysql_num_fields($sQryRes); + $bExplained = true; } } - $text .= "\n
$badCount Query Errors!
IndexQuery / Error
{$idx} ".$cQuery['query']."
".$cQuery['error']."

\n"; + else + { // Don't run 'EXPLAIN' on other queries + $sQryRes = $origQryRes; // Return from original query could be TRUE or a link resource if success + } + + // Record Basic query info + $sCallingFile = varset($aTrace[2]['file']); + $sCallingLine = varset($aTrace[2]['line']); + + $t = &$this->aSQLdetails[$sql->db_QueryCount()]; + $t['marker'] = $this->curTimeMark; + $t['caller'] = "$sCallingFile($sCallingLine)"; + $t['query'] = $query; + $t['ok'] = ($sQryRes !== false) ? true : false; + $t['error'] = $sQryRes ? '' : $sql->getLastErrorText(); // mysql_error(); + $t['nFields'] = $nFields; + $t['time'] = $mytime; + + if($bExplained) + { + $bRowHeaders = false; + // while ($row = @mysql_fetch_assoc($sQryRes)) + while($row = $sql->fetch()) + { + if(!$bRowHeaders) + { + $bRowHeaders = true; + $t['explain'] = "" . implode("", array_keys($row)) . "\n"; + } + $t['explain'] .= "" . implode(" ", array_values($row)) . " \n"; + } + } + else + { + $t['explain'] = $ExplainText; + } + + $this->aTimeMarks[$this->nTimeMarks]['DB Time'] += $mytime; + $this->aTimeMarks[$this->nTimeMarks]['DB Count']++; + + if(array_key_exists($curtable, $this->aDBbyTable)) + { + $this->aDBbyTable[$curtable]['DB Time'] += $mytime; + $this->aDBbyTable[$curtable]['DB Count']++; + } + else + { + $this->aDBbyTable[$curtable]['Table'] = $curtable; + $this->aDBbyTable[$curtable]['%DB Time'] = 0; // placeholder + $this->aDBbyTable[$curtable]['%DB Count'] = 0; // placeholder + $this->aDBbyTable[$curtable]['DB Time'] = $mytime; + $this->aDBbyTable[$curtable]['DB Count'] = 1; + } } - // - // Optionally list good queries - // - - if ($okCount && E107_DBG_SQLDETAILS) + + function Show_SQL_Details($force = false) { - $text .= "\n\n"; - $text .= "\n"; - $text .= "\n + + global $sql; + // + // Show stats from aSQLdetails array + // + if(!E107_DBG_SQLQUERIES && !E107_DBG_SQLDETAILS && ($force === false)) + { + return false; + } + + + $text = ''; + $nQueries = $sql->db_QueryCount(); + + if(!$nQueries) + { + return $text; + } + + // + // ALWAYS summarize query errors + // + $badCount = 0; + $okCount = 0; + + foreach($this->aSQLdetails as $cQuery) + { + if($cQuery['ok'] == 1) + { + $okCount++; + } + else + { + $badCount++; + } + } + + if($badCount) + { + $text .= "\n
".$this->countLabel($okCount)." Good Queries
IndexQtimeQuery
\n"; + $text .= "\n"; + $text .= "\n"; + + foreach($this->aSQLdetails as $idx => $cQuery) + { + if(!$cQuery['ok']) + { + $text .= " + \n\n"; + } + } + $text .= "\n
$badCount Query Errors!
IndexQuery / Error
{$idx} " . $cQuery['query'] . "
" . $cQuery['error'] . "

\n"; + } + + // + // Optionally list good queries + // + + if($okCount && E107_DBG_SQLDETAILS) + { + $text .= "\n\n"; + $text .= "\n"; + $text .= "\n \n "; - $count = 0; - foreach ($this->aSQLdetails as $idx => $cQuery) - { - if($count > 500) + $count = 0; + foreach($this->aSQLdetails as $idx => $cQuery) { - $text .= ""; // NO LAN - debug only. - break; + if($count > 500) + { + $text .= ""; // NO LAN - debug only. + break; + } + + + if($cQuery['ok']) + { + $text .= " + + \n"; + + $count++; + } } - if ($cQuery['ok']) + $text .= "\n
" . $this->countLabel($okCount) . " Good Queries
IndexQtimeQuery
 (msec) 
Too many queries. Ending...
Too many queries. Ending...
{$idx} " . number_format($cQuery['time'] * 1000.0, 4) . " " . $cQuery['query'] . '
[' . $cQuery['marker'] . " - " . $cQuery['caller'] . "]

\n"; + } + + + // + // Optionally list query details + // + if(E107_DBG_SQLDETAILS) + { + $count = 0; + foreach($this->aSQLdetails as $idx => $cQuery) { - $text .= "{$idx}  - ".number_format($cQuery['time'] * 1000.0, 4)."  - ".$cQuery['query'].'
['.$cQuery['marker']." - ".$cQuery['caller']."]\n"; + $text .= "\n\n"; + $text .= "\n"; + if(isset($cQuery['explain'])) + { + $text .= $cQuery['explain']; + } + if(strlen($cQuery['error'])) + { + $text .= "\n\n"; + } + + $text .= "'; + + $text .= '
" . $idx . ") Query: [" . $cQuery['marker'] . " - " . $cQuery['caller'] . "]
" . $cQuery['query'] . "
Error in query:
" . $cQuery['error'] . "
Query time: " . number_format($cQuery['time'] * 1000.0, 4) . ' (ms)

' . "\n"; + + if($count > 500) + { + $text .= "
Too many queries. Ending...
"; // NO LAN - debug only. + break; + } + $count++; } } - - - $text .= "\n
\n"; + return $text; } - - // - // Optionally list query details - // - if (E107_DBG_SQLDETAILS) + function countLabel($amount) { - $count = 0; - foreach ($this->aSQLdetails as $idx => $cQuery) - { - $text .= "\n\n"; - $text .= "\n"; - if (isset($cQuery['explain'])) { - $text .= $cQuery['explain']; - } - if (strlen($cQuery['error'])) { - $text .= "\n\n"; - } - $text .= "'; - - $text .= '
".$idx.") Query: [".$cQuery['marker']." - ".$cQuery['caller']."]
".$cQuery['query']."
Error in query:
".$cQuery['error']."
Query time: ".number_format($cQuery['time'] * 1000.0, 4).' (ms)

'."\n"; - - if($count > 500) - { - $text .= "
Too many queries. Ending...
"; // NO LAN - debug only. - break; - } - - - $count++; + if($amount < 30) + { + $inc = 'label-success'; } + elseif($amount < 50) + { + $inc = 'label-warning'; + } + elseif($amount > 49) + { + $inc = 'label-danger label-important'; + } + + return "" . $amount . ""; } - return $text; - } - - function countLabel($amount) - { - if($amount < 30) + + function save($log) { - $inc = 'label-success'; - } - elseif($amount < 50) - { - $inc = 'label-warning'; - } - elseif($amount > 49) - { - $inc = 'label-danger label-important'; - } - - return "".$amount.""; - } + e107::getMessage()->addDebug("Saving a log"); - function save($log) - { - e107::getMessage()->addDebug("Saving a log"); + $titles = array_keys($this->aTimeMarks[0]); - $titles = array_keys($this->aTimeMarks[0]); + $text = implode("\t\t\t", $titles) . "\n\n"; - $text = implode("\t\t\t",$titles)."\n\n"; + foreach($this->aTimeMarks as $item) + { + $item['What'] = str_pad($item['What'], 50, " ", STR_PAD_RIGHT); + $text .= implode("\t\t\t", $item) . "\n"; + } + + file_put_contents($log, $text, FILE_APPEND); - foreach($this->aTimeMarks as $item) - { - $item['What'] = str_pad($item['What'],50," ",STR_PAD_RIGHT); - $text .= implode("\t\t\t",$item)."\n"; } - file_put_contents($log, $text, FILE_APPEND); - } - - - private function highlight($label, $value=0,$threshold=0) - { - - if($value > $threshold) + private function highlight($label, $value = 0, $threshold = 0) { - return "".$label.""; + + if($value > $threshold) + { + return "" . $label . ""; + } + + return $label; + } - return $label; - } + function Show_Performance() + { - - function Show_Performance() - { // // Stats by Time Marker // @@ -422,10 +444,10 @@ class e107_db_debug { // Calculate Memory Usage per entry. $prevMem = 0; - foreach($this->aTimeMarks as $k=>$v) + foreach($this->aTimeMarks as $k => $v) { - $prevKey = $k-1; + $prevKey = $k - 1; if(!empty($prevKey)) { @@ -436,7 +458,6 @@ class e107_db_debug { } - while(list($tKey, $tMarker) = each($this->aTimeMarks)) { if(!$bRowHeaders) @@ -465,14 +486,13 @@ class e107_db_debug { } + // $tMem = ($tMarker['Memory'] - $aSum['Memory']); - // $tMem = ($tMarker['Memory'] - $aSum['Memory']); - - $tMem = ($tMarker['Memory']); + $tMem = ($tMarker['Memory']); if($tMem < 0) // Quick Fix for negative numbers. { - // $tMem = 0.0000000001; + // $tMem = 0.0000000001; } $tMarker['Memory'] = ($tMem ? number_format($tMem / 1024.0, 1) : '?'); // display if known @@ -480,12 +500,12 @@ class e107_db_debug { $tUsage = $tMarker['Memory Used']; $tMarker['Memory Used'] = number_format($tUsage / 1024.0, 1); - $tMarker['Memory Used'] = $this->highlight($tMarker['Memory Used'],$tUsage,400000); -/* - if($tUsage > 400000) // Highlight high memory usage. - { - $tMarker['Memory Used'] = "".$tMarker['Memory Used'].""; - }*/ + $tMarker['Memory Used'] = $this->highlight($tMarker['Memory Used'], $tUsage, 400000); + /* + if($tUsage > 400000) // Highlight high memory usage. + { + $tMarker['Memory Used'] = "".$tMarker['Memory Used'].""; + }*/ $aSum['Memory'] = $tMem; @@ -511,7 +531,7 @@ class e107_db_debug { $aSum['DB Time'] += $tMarker['DB Time']; $aSum['DB Count'] += $tMarker['DB Count']; $tMarker['Time'] = number_format($thisDelta * 1000.0, 1); - $tMarker['Time'] = $this->highlight($tMarker['Time'],$thisDelta,.2); + $tMarker['Time'] = $this->highlight($tMarker['Time'], $thisDelta, .2); $tMarker['%Time'] = $totTime ? number_format(100.0 * ($thisDelta / $totTime), 0) : 0; @@ -628,42 +648,47 @@ class e107_db_debug { return $text; } - function logDeprecated(){ - - $back_trace = debug_backtrace(); - - print_r($back_trace); - - $this->deprecated_funcs[] = array ( - 'func' => (isset($back_trace[1]['type']) && ($back_trace[1]['type'] == '::' || $back_trace[1]['type'] == '->') ? $back_trace[1]['class'].$back_trace[1]['type'].$back_trace[1]['function'] : $back_trace[1]['function']), - 'file' => $back_trace[1]['file'], - 'line' => $back_trace[1]['line'] - ); - - } - - function logCode($type, $code, $parm, $details) - { - if (!E107_DBG_BBSC) + function logDeprecated() { - return FALSE; - } - - $this->scbbcodes[$this->scbcount]['type'] = $type; - $this->scbbcodes[$this->scbcount]['code'] = $code; - $this->scbbcodes[$this->scbcount]['parm'] = (string)$parm; - $this->scbbcodes[$this->scbcount]['details'] = $details; - $this->scbcount ++; - } - function Show_SC_BB($force=false) - { - if (!E107_DBG_BBSC && ($force === false)) - { - return false; + $back_trace = debug_backtrace(); + + print_r($back_trace); + + $this->deprecated_funcs[] = array( + 'func' => (isset($back_trace[1]['type']) && ($back_trace[1]['type'] == '::' || $back_trace[1]['type'] == '->') ? $back_trace[1]['class'] . $back_trace[1]['type'] . $back_trace[1]['function'] : $back_trace[1]['function']), + 'file' => $back_trace[1]['file'], + 'line' => $back_trace[1]['line'] + ); + } - $text = " + function logCode($type, $code, $parm, $details) + { + + if(!E107_DBG_BBSC) + { + return false; + } + + $this->scbbcodes[$this->scbcount]['type'] = $type; + $this->scbbcodes[$this->scbcount]['code'] = $code; + $this->scbbcodes[$this->scbcount]['parm'] = (string) $parm; + $this->scbbcodes[$this->scbcount]['details'] = $details; + $this->scbcount++; + + return null; + } + + function Show_SC_BB($force = false) + { + + if(!E107_DBG_BBSC && ($force === false)) + { + return false; + } + + $text = "
@@ -675,36 +700,38 @@ class e107_db_debug { \n"; - $description = array(1=>'Bbcode',2=>'Shortcode',3=>'Wrapper', 4=>'Shortcode Override', -2 => 'Shortcode Failure'); - $style = array(1 => 'label-info', 2=>'label-primary', 3=>'label-warning', 'label-danger', -2 => 'label-danger'); + $description = array(1 => 'Bbcode', 2 => 'Shortcode', 3 => 'Wrapper', 4 => 'Shortcode Override', -2 => 'Shortcode Failure'); + $style = array(1 => 'label-info', 2 => 'label-primary', 3 => 'label-warning', 'label-danger', -2 => 'label-danger'); - foreach($this -> scbbcodes as $codes) - { + foreach($this->scbbcodes as $codes) + { - $type = $codes['type']; + $type = $codes['type']; - $text .= " - - - - + $text .= " + + + + \n"; - } - $text .= "
".($description[$type])."".(isset($codes['code']) ? $codes['code'] : " ")."".($codes['parm'] ? $codes['parm'] : " ")."".($codes['details'] ? $codes['details'] : " ")."
" . ($description[$type]) . "" . (isset($codes['code']) ? $codes['code'] : " ") . "" . ($codes['parm'] ? $codes['parm'] : " ") . "" . ($codes['details'] ? $codes['details'] : " ") . "
"; - return $text; - } + } + $text .= ""; - function Show_PATH($force=false) - { - if (!E107_DBG_PATH && ($force === false)) - { - return FALSE; + return $text; } - - global $e107; - $sql = e107::getDb(); - - $text = " + + function Show_PATH($force = false) + { + + if(!E107_DBG_PATH && ($force === false)) + { + return false; + } + + global $e107; + $sql = e107::getDb(); + + $text = "@@ -717,84 +744,85 @@ class e107_db_debug { \n"; - $inc = array( - 'BOOTSTRAP','HEADERF','FOOTERF','FILE_UPLOADS','FLOODPROTECT','FLOODTIMEOUT','CHARSET', - 'GUESTS_ONLINE','MEMBERS_ONLINE','PAGE_NAME','STANDARDS_MODE','TIMEOFFSET', - 'TOTAL_ONLINE','THEME','THEME_ABS','THEME_LAYOUT', 'THEME_LEGACY','THEME_STYLE','META_OG','META_DESCRIPTION','MPREFIX','VIEWPORT','BODYTAG','CSSORDER' - ); - - $userCon = get_defined_constants(true); - ksort($userCon['user']); - - foreach($userCon['user'] as $k=>$v) - { - if(E107_DBG_ALLERRORS || in_array($k,$inc) || substr($k,0,5) == 'ADMIN' || substr($k,0,2) == 'E_' || substr($k,0,2) == 'e_' || substr($k,0,4) == 'E107' || substr($k,0,4) == 'SITE' || substr($k,0,4) == 'USER' || substr($k,0,4) == 'CORE') + $inc = array( + 'BOOTSTRAP', 'HEADERF', 'FOOTERF', 'FILE_UPLOADS', 'FLOODPROTECT', 'FLOODTIMEOUT', 'CHARSET', + 'GUESTS_ONLINE', 'MEMBERS_ONLINE', 'PAGE_NAME', 'STANDARDS_MODE', 'TIMEOFFSET', + 'TOTAL_ONLINE', 'THEME', 'THEME_ABS', 'THEME_LAYOUT', 'THEME_LEGACY', 'THEME_STYLE', 'META_OG', 'META_DESCRIPTION', 'MPREFIX', 'VIEWPORT', 'BODYTAG', 'CSSORDER' + ); + + $userCon = get_defined_constants(true); + ksort($userCon['user']); + + foreach($userCon['user'] as $k => $v) { - $text .= " + if(E107_DBG_ALLERRORS || in_array($k, $inc) || substr($k, 0, 5) == 'ADMIN' || substr($k, 0, 2) == 'E_' || substr($k, 0, 2) == 'e_' || substr($k, 0, 4) == 'E107' || substr($k, 0, 4) == 'SITE' || substr($k, 0, 4) == 'USER' || substr($k, 0, 4) == 'CORE') + { + $text .= " - - - "; + + + "; + } } - } - - $sess = e107::getSession(); - - $text .= " + + $sess = e107::getSession(); + + $text .= " - + "; - if($_SERVER['E_DEV'] == 'true') - { - $text .= " + if($_SERVER['E_DEV'] == 'true') + { + $text .= " - + "; - } + } - $text .=" + $text .= " - + - + - + - + "; - return $text; - } + return $text; + } - function Show_DEPRECATED($force=false) - { - if (!E107_DBG_DEPRECATED && ($force === false)) + function Show_DEPRECATED($force = false) { - return false; - } - else - { - $text = " + + if(!E107_DBG_DEPRECATED && ($force === false)) + { + return false; + } + else + { + $text = "
@@ -805,178 +833,205 @@ class e107_db_debug { \n"; - foreach($this->deprecated_funcs as $funcs) - { - $text .= " + foreach($this->deprecated_funcs as $funcs) + { + $text .= "\n"; + } + $text .= "
The following deprecated functions were used:
{$funcs['func']}() {$funcs['file']} {$funcs['line']}
"; + + return $text; } - $text .= ""; + } + + + /** + * var_dump to debug log + * + * @param mixed $message + */ + function dump($message, $TraceLev = 1) + { + + ob_start(); + var_dump($message); + $content = ob_get_contents(); + ob_end_clean(); + + $bt = debug_backtrace(); + + $this->aLog[] = array( + 'Message' => $content, + 'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'] . $bt[$TraceLev]['type'] . $bt[$TraceLev]['function'] . '()' : $bt[$TraceLev]['function']) . '()', + 'File' => varset($bt[$TraceLev]['file']), + 'Line' => varset($bt[$TraceLev]['line']) + ); + + // $this->aLog[] = array ('Message' => $content, 'Function' => '', 'File' => '', 'Line' => '' ); + + } + + + /** + * @desc Simple debug-level 'console' log + * Record a "nice" debug message with + * $db_debug->log("message"); + * @param string $message + * @param int $TraceLev + * @return bool true on success , false on error + */ + public function log($message, $TraceLev = 1) + { + + if(is_array($message) || is_object($message)) + { + $message = "
" . print_r($message, true) . "
"; + } + + if(!deftrue('E107_DBG_BASIC') && !deftrue('E107_DBG_ALLERRORS') && !deftrue('E107_DBG_SQLDETAILS') && !deftrue('E107_DBG_NOTICES')) + { + return false; + } + + if($TraceLev) + { + $bt = debug_backtrace(); + $this->aLog[] = array( + 'Message' => $message, + 'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'] . $bt[$TraceLev]['type'] . $bt[$TraceLev]['function'] . '()' : $bt[$TraceLev]['function']) . '()', + 'File' => varset($bt[$TraceLev]['file']), + 'Line' => varset($bt[$TraceLev]['line']) + ); + } + else + { + $this->aLog[] = array( + 'Message' => $message, + 'Function' => '', + 'File' => '', + 'Line' => '' + ); + } + + return true; + } + + /** + * @return bool|string + */ + function Show_Log() + { + + if(empty($this->aLog)) + { + return false; + } + // + // Dump the debug log + // + + $text = "\n\n"; + + $bRowHeaders = false; + + foreach($this->aLog as $curLog) + { + if(!$bRowHeaders) + { + $bRowHeaders = true; + $text .= "\n"; + } + + $text .= "\n"; + } + + $text .= "
" . implode("", array_keys($curLog)) . "
" . implode(" ", array_values($curLog)) . " 

\n"; + + return $text; + } + + function Show_Includes($force = false) + { + + if(!E107_DBG_INCLUDES && ($force === false)) + { + return false; + } + + + $text = "\n"; + $text .= "\n\n"; + $text .= "
" . + implode(" 
", $this->aIncList) . + " 
\n"; + return $text; } } - /** - * var_dump to debug log - * @param mixed $message - */ - function dump($message, $TraceLev= 1) - { - ob_start(); - var_dump($message); - $content = ob_get_contents(); - ob_end_clean(); - - $bt = debug_backtrace(); - - $this->aLog[] = array( - 'Message' => $content, - 'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()', - 'File' => varset($bt[$TraceLev]['file']), - 'Line' => varset($bt[$TraceLev]['line']) - ); - - // $this->aLog[] = array ('Message' => $content, 'Function' => '', 'File' => '', 'Line' => '' ); - - } -// -// Simple debug-level 'console' log -// Record a "nice" debug message with -// $db_debug->log("message"); -// - function log($message,$TraceLev=1) - { - - - - if(is_array($message) || is_object($message)) - { - $message = "
".print_r($message,true)."
"; - } - - if (!deftrue('E107_DBG_BASIC') && !deftrue('E107_DBG_ALLERRORS') && !deftrue('E107_DBG_SQLDETAILS') && !deftrue('E107_DBG_NOTICES')) - { - return false; - } - - if ($TraceLev) - { - $bt = debug_backtrace(); - $this->aLog[] = array ( - 'Message' => $message, - 'Function' => (isset($bt[$TraceLev]['type']) && ($bt[$TraceLev]['type'] == '::' || $bt[$TraceLev]['type'] == '->') ? $bt[$TraceLev]['class'].$bt[$TraceLev]['type'].$bt[$TraceLev]['function'].'()' : $bt[$TraceLev]['function']).'()', - 'File' => varset($bt[$TraceLev]['file']), - 'Line' => varset($bt[$TraceLev]['line']) - ); - } else { - $this->aLog[] = array ( - 'Message' => $message, - 'Function' => '', - 'File' => '', - 'Line' => '' - ); - } - } - - function Show_Log() - { - if (empty($this->aLog)) - { - return FALSE; - } - // - // Dump the debug log - // - - $text = "\n\n"; - - $bRowHeaders=FALSE; - - foreach ($this->aLog as $curLog) - { - if (!$bRowHeaders) - { - $bRowHeaders = true; - $text .= "\n"; - } - - $text .= "\n"; - } - - $text .= "
".implode("", array_keys($curLog))."
".implode(" ", array_values($curLog))." 

\n"; - - return $text; - } - - function Show_Includes($force=false) - { - if (!E107_DBG_INCLUDES && ($force === false)) return false; - - - - $text = "\n"; - $text .= "\n\n"; - $text .= "
". - implode(" 
", $this->aIncList). - " 
\n"; - return $text; - } -} - // // Helper functions (not part of the class) // -function e107_debug_shutdown() -{ - if(e_AJAX_REQUEST) // extra output will break json ajax returns ie. comments + function e107_debug_shutdown() { - return; - } - - - global $error_handler,$e107_Clean_Exit,$In_e107_Footer,$ADMIN_DIRECTORY; - if (isset($e107_Clean_Exit)) return; - if (!isset($In_e107_Footer)) - { - if (defset('ADMIN_AREA')) + if(e_AJAX_REQUEST) // extra output will break json ajax returns ie. comments { - $filewanted=realpath(dirname(__FILE__)).'/../'.$ADMIN_DIRECTORY.'footer.php'; - require_once($filewanted); - } else if (defset('USER_AREA')) - { - $filewanted=realpath(dirname(__FILE__)).'/../'.FOOTERF; - require_once($filewanted); + return; + } + + + global $error_handler, $e107_Clean_Exit, $In_e107_Footer, $ADMIN_DIRECTORY; + if(isset($e107_Clean_Exit)) + { + return; + } + + if(!isset($In_e107_Footer)) + { + if(defset('ADMIN_AREA')) + { + $filewanted = realpath(dirname(__FILE__)) . '/../' . $ADMIN_DIRECTORY . 'footer.php'; + require_once($filewanted); + } + elseif(defset('USER_AREA')) + { + $filewanted = realpath(dirname(__FILE__)) . '/../' . FOOTERF; + require_once($filewanted); + } } - } // // Error while in the footer, or during startup, or during above processing // - if (isset($e107_Clean_Exit)) return; // We've now sent a footer... - + if(isset($e107_Clean_Exit)) + { + return; + } // We've now sent a footer... + // echo isset($In_e107_Footer) ? "In footer" : "In startup".'
'; - while (ob_get_level() > 0) { - ob_end_flush(); - } - - if (isset($error_handler)) - { - if($error_handler->return_errors()) + while(ob_get_level() > 0) { - echo "

PHP Errors:


".$error_handler->return_errors()."
\n"; + ob_end_flush(); + } + + if(isset($error_handler)) + { + if($error_handler->return_errors()) + { + echo "

PHP Errors:


" . $error_handler->return_errors() . "
\n"; + echo ""; + } + } + else + { + echo "e107 Shutdown while no error_handler available!"; echo ""; } - } - else - { - echo "e107 Shutdown while no error_handler available!"; - echo ""; + } -} - -?> \ No newline at end of file diff --git a/e107_handlers/e_db_pdo_class.php b/e107_handlers/e_db_pdo_class.php index dae3c138e..346d553e5 100644 --- a/e107_handlers/e_db_pdo_class.php +++ b/e107_handlers/e_db_pdo_class.php @@ -51,6 +51,8 @@ class e_db_pdo implements e_db private $pdo = true; // using PDO or not. private $pdoBind = false; + private $traffic; + /** * Constructor - gets language options from the cookie or session @@ -58,16 +60,16 @@ class e_db_pdo implements e_db */ public function __construct() { - - global $pref, $db_defaultPrefix; - /* if((PHP_MAJOR_VERSION > 6) || !function_exists('mysql_connect') || (defined('e_PDO') && e_PDO === true)) { $this->pdo = true; } - */e107::getSingleton('e107_traffic')->BumpWho('Create db object', 1); + */ + $this->traffic = e107::getSingleton('e107_traffic'); + + $this->traffic->BumpWho('Create db object', 1); $this->mySQLPrefix = MPREFIX; // Set the default prefix - may be overridden @@ -76,17 +78,7 @@ class e_db_pdo implements e_db $this->mySQLport = intval($port); } - /*$langid = (isset($pref['cookie_name'])) ? 'e107language_'.$pref['cookie_name'] : 'e107language_temp'; - if (isset($pref['user_tracking']) && ($pref['user_tracking'] == 'session')) - { - if (!isset($_SESSION[$langid])) { return; } - $this->mySQLlanguage = $_SESSION[$langid]; - } - else - { - if (!isset($_COOKIE[$langid])) { return; } - $this->mySQLlanguage = $_COOKIE[$langid]; - }*/ + // Detect is already done in language handler, use it if not too early if(defined('e_LANGUAGE')) $this->mySQLlanguage = e107::getLanguage()->e_language; } @@ -196,7 +188,7 @@ class e_db_pdo implements e_db { global $db_ConnectionID, $db_defaultPrefix; - e107::getSingleton('e107_traffic')->BumpWho('db Connect', 1); + $this->traffic->BumpWho('db Connect', 1); $this->mySQLserver = $mySQLserver; $this->mySQLuser = $mySQLuser; @@ -441,8 +433,8 @@ class e_db_pdo implements e_db $e = microtime(); - e107::getSingleton('e107_traffic')->Bump('db_Query', $b, $e); - $mytime = e107::getSingleton('e107_traffic')->TimeDelta($b,$e); + $this->traffic->Bump('db_Query', $b, $e); + $mytime = $this->traffic->TimeDelta($b,$e); $db_time += $mytime; $this->mySQLresult = $sQryRes; @@ -1360,7 +1352,7 @@ class e_db_pdo implements e_db /** @var PDOStatement $resource */ $resource = $this->mySQLresult; $row = $resource->fetch($type); - e107::getSingleton('e107_traffic')->Bump('db_Fetch', $b); + $this->traffic->Bump('db_Fetch', $b); if ($row) { $this->dbError('db_Fetch'); @@ -1453,7 +1445,7 @@ class e_db_pdo implements e_db function close() { $this->provide_mySQLaccess(); - e107::getSingleton('e107_traffic')->BumpWho('db Close', 1); + $this->traffic->BumpWho('db Close', 1); $this->mySQLaccess = NULL; // correct way to do it when using shared links. $this->dbError('dbClose'); }