Commit 616b9a38 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2554 functions_debug should follow guidelines

Showing with 77 additions and 94 deletions
+77 -94
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
----------------------------------------------------------------------*/ ----------------------------------------------------------------------*/
# This file must be the first include on your page. // This file must be the first include on your page.
/* used for tracking of generation-time */ /* used for tracking of generation-time */
{ {
...@@ -61,34 +61,34 @@ ...@@ -61,34 +61,34 @@
*/ */
class Print_a_class { class Print_a_class {
# this can be changed to FALSE if you don't like the fancy string formatting // this can be changed to FALSE if you don't like the fancy string formatting
var $look_for_leading_tabs = TRUE; var $look_for_leading_tabs = TRUE;
var $output; var $output;
var $iterations; var $iterations;
var $key_bg_color = '1E32C8'; var $key_bg_color = '1E32C8';
var $value_bg_color = 'DDDDEE'; var $value_bg_color = 'DDDDEE';
var $fontsize = '8pt'; var $fontsize = '8pt';
var $keyalign = 'center'; var $keyalign = 'center';
var $fontfamily = 'Verdana'; var $fontfamily = 'Verdana';
var $export_flag; var $export_flag;
var $show_object_vars; var $show_object_vars;
var $export_dumper_path = 'http://tools.www.mdc.xmc.de/print_a_dumper/print_a_dumper.php'; var $export_dumper_path = 'http://tools.www.mdc.xmc.de/print_a_dumper/print_a_dumper.php';
# i'm still working on the dumper! don't use it now /* i'm still working on the dumper! don't use it now
# put the next line into the print_a_dumper.php file (optional) * put the next line into the print_a_dumper.php file (optional)
# print htmlspecialchars( stripslashes ( $_POST['array'] ) ); * print htmlspecialchars( stripslashes ( $_POST['array'] ) ); */
var $export_hash; var $export_hash;
/*! /*!
* \brief Print_a_class constructor * \brief Print_a_class constructor
*/ */
function Print_a_class() { function __construct()
{
$this->export_hash = uniqid(''); $this->export_hash = uniqid('');
} }
/*! /*! recursive function!
* recursive function!
* if print_a() was called with a fourth parameter (1 or 2) * if print_a() was called with a fourth parameter (1 or 2)
* and you click on the table a window opens with only the output of print_a() in it * and you click on the table a window opens with only the output of print_a() in it
* 1 = serialized array * 1 = serialized array
...@@ -110,16 +110,17 @@ class Print_a_class { ...@@ -110,16 +110,17 @@ class Print_a_class {
* *
* \param boolean $key_bg_colo false * \param boolean $key_bg_colo false
*/ */
function print_a($array, $iteration = FALSE, $key_bg_color = FALSE) { function print_a($array, $iteration = FALSE, $key_bg_color = FALSE)
{
$key_bg_color or $key_bg_color = $this->key_bg_color; $key_bg_color or $key_bg_color = $this->key_bg_color;
if( !$iteration && isset($this->export_flag) ) { if (!$iteration && isset($this->export_flag)) {
$this->output .= '<form id="pa_form_'.$this->export_hash.'" action="'.$this->export_dumper_path.'?mode='.$this->export_flag.'" method="post" target="_blank"><input name="array" type="hidden" value="'.htmlspecialchars( serialize( $array ) ).'"></form>'; $this->output .= '<form id="pa_form_'.$this->export_hash.'" action="'.$this->export_dumper_path.'?mode='.$this->export_flag.'" method="post" target="_blank"><input name="array" type="hidden" value="'.htmlspecialchars( serialize( $array ) ).'"></form>';
} }
# lighten up the background color for the key td's =) // lighten up the background color for the key td's =)
if( $iteration ) { if ($iteration) {
for($i=0; $i<6; $i+=2) { for ($i = 0; $i < 6; $i += 2) {
$c = substr( $key_bg_color, $i, 2 ); $c = substr( $key_bg_color, $i, 2 );
$c = hexdec( $c ); $c = hexdec( $c );
( $c += 15 ) > 255 and $c = 255; ( $c += 15 ) > 255 and $c = 255;
...@@ -129,18 +130,17 @@ class Print_a_class { ...@@ -129,18 +130,17 @@ class Print_a_class {
$key_bg_color = $tmp_key_bg_color; $key_bg_color = $tmp_key_bg_color;
} }
# build a single table ... may be nested // build a single table ... may be nested
$this->output .= '<table summary="" style="border:none;" cellspacing="1" '.( !$iteration && $this->export_flag ? 'onClick="document.getElementById(\'pa_form_'.$this->export_hash.'\').submit();" )' : '' ).'>'; $this->output .= '<table style="border:none;" cellspacing="1" '.( !$iteration && $this->export_flag ? 'onClick="document.getElementById(\'pa_form_'.$this->export_hash.'\').submit();" )' : '' ).'>';
foreach( $array as $key => $value ) { foreach ($array as $key => $value) {
$value_style = 'color:black;'; $value_style = 'color:black;';
$key_style = 'color:white;'; $key_style = 'color:white;';
$type = gettype( $value ); $type = gettype($value);
# print $type.'<br />';
# change the color and format of the value // change the color and format of the value
switch( $type ) { switch ($type) {
case 'array': case 'array':
break; break;
...@@ -165,14 +165,14 @@ class Print_a_class { ...@@ -165,14 +165,14 @@ class Print_a_class {
break; break;
case 'string': case 'string':
if( $this->look_for_leading_tabs && preg_match('/^\t/m', $value) ) { if ($this->look_for_leading_tabs && preg_match('/^\t/m', $value)) {
$search = array('/\t/', "/\n/"); $search = array('/\t/', "/\n/");
$replace = array('&nbsp;&nbsp;&nbsp;','<br />'); $replace = array('&nbsp;&nbsp;&nbsp;','<br />');
$value = preg_replace( $search, $replace, htmlspecialchars( $value ) ); $value = preg_replace( $search, $replace, htmlspecialchars($value));
$value_style = 'color:black;border:1px gray dotted;'; $value_style = 'color:black;border:1px gray dotted;';
} else { } else {
$value_style = 'color:black;'; $value_style = 'color:black;';
$value = nl2br( htmlspecialchars( $value ) ); $value = nl2br(htmlspecialchars($value));
} }
break; break;
} }
...@@ -184,15 +184,15 @@ class Print_a_class { ...@@ -184,15 +184,15 @@ class Print_a_class {
$this->output .= '<td nowrap="nowrap" style="background-color:#'.$this->value_bg_color.';font: '.$this->fontsize.' '.$this->fontfamily.'; color:black;">'; $this->output .= '<td nowrap="nowrap" style="background-color:#'.$this->value_bg_color.';font: '.$this->fontsize.' '.$this->fontfamily.'; color:black;">';
# value output // value output
if($type == 'array') { if ($type == 'array') {
if(count($value)){ if (count($value)) {
$this->print_a( $value, TRUE, $key_bg_color ); $this->print_a( $value, TRUE, $key_bg_color );
}else{ } else {
$this->output .= '<div style="color:blue;">Array (empty)</div>'; $this->output .= '<div style="color:blue;">Array (empty)</div>';
} }
} elseif($type == 'object') { } elseif ($type == 'object') {
if( $this->show_object_vars ) { if ($this->show_object_vars) {
$this->print_a( get_object_vars( $value ), TRUE, $key_bg_color ); $this->print_a( get_object_vars( $value ), TRUE, $key_bg_color );
} else { } else {
$this->output .= '<div style="'.$value_style.'">OBJECT - '.get_class($value).'</div>'; $this->output .= '<div style="'.$value_style.'">OBJECT - '.get_class($value).'</div>';
...@@ -219,23 +219,27 @@ class Print_a_class { ...@@ -219,23 +219,27 @@ class Print_a_class {
* *
* \param boolean $export_flag false * \param boolean $export_flag false
*/ */
function print_a( $array, $return_mode = FALSE, $show_object_vars = FALSE, $export_flag = FALSE ) { function print_a($array, $return_mode = FALSE, $show_object_vars = FALSE, $export_flag = FALSE )
$e= error_reporting (0); {
if( is_array( $array ) or is_object( $array ) ) { $e = error_reporting(0);
if (is_array($array) or is_object($array)) {
$pa = new Print_a_class; $pa = new Print_a_class;
$show_object_vars and $pa->show_object_vars = TRUE; if ($show_object_vars) {
$export_flag and $pa->export_flag = $export_flag; $pa->show_object_vars = TRUE;
}
if ($export_flag) {
$pa->export_flag = $export_flag;
}
$pa->print_a( $array ); $pa->print_a($array);
# $output = $pa->output; unset($pa);
$output = &$pa->output; $output = &$pa->output;
} else { } else {
$output = '<span style="color:red;font-size:small;">print_a( '.gettype( $array ).' )</span>'; $output = '<span style="color:red;font-size:small;">print_a( '.gettype( $array ).' )</span>';
} }
error_reporting ($e); error_reporting ($e);
if($return_mode) { if ($return_mode) {
return $output; return $output;
} else { } else {
print $output; print $output;
...@@ -243,13 +247,14 @@ function print_a( $array, $return_mode = FALSE, $show_object_vars = FALSE, $expo ...@@ -243,13 +247,14 @@ function print_a( $array, $return_mode = FALSE, $show_object_vars = FALSE, $expo
} }
} }
function _script_globals() { function _script_globals()
{
global $GLOBALS_initial_count; global $GLOBALS_initial_count;
$varcount = 0; $varcount = 0;
foreach($GLOBALS as $GLOBALS_current_key => $GLOBALS_current_value) { foreach ($GLOBALS as $GLOBALS_current_key => $GLOBALS_current_value) {
if(++$varcount > $GLOBALS_initial_count) { if (++$varcount > $GLOBALS_initial_count) {
/* die wollen wir nicht! */ /* die wollen wir nicht! */
if ($GLOBALS_current_key != 'HTTP_SESSION_VARS' && $GLOBALS_current_key != '_SESSION') { if ($GLOBALS_current_key != 'HTTP_SESSION_VARS' && $GLOBALS_current_key != '_SESSION') {
$script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value; $script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value;
...@@ -263,14 +268,15 @@ function _script_globals() { ...@@ -263,14 +268,15 @@ function _script_globals() {
/*! /*!
* \brief Show the runtime * \brief Show the runtime
*/ */
function show_runtime() { function show_runtime()
{
$MICROTIME_END = microtime(); $MICROTIME_END = microtime();
$MICROTIME_START = explode(' ', $GLOBALS['MICROTIME_START']); $MICROTIME_START = explode(' ', $GLOBALS['MICROTIME_START']);
$MICROTIME_END = explode(' ', $MICROTIME_END); $MICROTIME_END = explode(' ', $MICROTIME_END);
$GENERATIONSEC = $MICROTIME_END[1] - $MICROTIME_START[1]; $GENERATIONSEC = $MICROTIME_END[1] - $MICROTIME_START[1];
$GENERATIONMSEC = $MICROTIME_END[0] - $MICROTIME_START[0]; $GENERATIONMSEC = $MICROTIME_END[0] - $MICROTIME_START[0];
$GENERATIONTIME = substr($GENERATIONSEC + $GENERATIONMSEC, 0, 8); $GENERATIONTIME = substr($GENERATIONSEC + $GENERATIONMSEC, 0, 8);
return '<span style="color:red;font-weight:normal;font-size:9px;">(runtime: '.$GENERATIONTIME.' sec)</span>'; return '<span style="color:red;font-weight:normal;font-size:9px;">(runtime: '.$GENERATIONTIME.' sec)</span>';
} }
...@@ -282,8 +288,11 @@ function show_runtime() { ...@@ -282,8 +288,11 @@ function show_runtime() {
* show_vars(1) shows all * show_vars(1) shows all
* show_vars(,1) shows object properties in addition * show_vars(,1) shows object properties in addition
*/ */
function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE) { function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE)
if(isset($GLOBALS['no_vars'])) return; {
if (isset($GLOBALS['no_vars'])) {
return;
}
$script_globals = _script_globals(); $script_globals = _script_globals();
print ' print '
...@@ -305,20 +314,21 @@ function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE) { ...@@ -305,20 +314,21 @@ function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE) {
'; ';
$vars_arr['script_globals'] = array('global script variables', '#7ACCC8'); $vars_arr['script_globals'] = array('global script variables', '#7ACCC8');
$vars_arr['_GET'] = array('$_GET', '#7DA7D9');
$vars_arr['_POST'] = array('$_POST', '#F49AC1'); $vars_arr['_GET'] = array('$_GET', '#7DA7D9');
$vars_arr['_FILES'] = array('$_POST FILES', '#82CA9C'); $vars_arr['_POST'] = array('$_POST', '#F49AC1');
$vars_arr['_FILES'] = array('$_POST FILES', '#82CA9C');
$vars_arr['_SESSION'] = array('$_SESSION', '#FCDB26'); $vars_arr['_SESSION'] = array('$_SESSION', '#FCDB26');
$vars_arr['_COOKIE'] = array('$_COOKIE', '#A67C52'); $vars_arr['_COOKIE'] = array('$_COOKIE', '#A67C52');
if($show_all_vars) { if ($show_all_vars) {
$vars_arr['_SERVER'] = array('SERVER', '#A186BE'); $vars_arr['_SERVER'] = array('SERVER', '#A186BE');
$vars_arr['_ENV'] = array('ENV', '#7ACCC8'); $vars_arr['_ENV'] = array('ENV', '#7ACCC8');
} }
foreach($vars_arr as $vars_name => $vars_data) { foreach ($vars_arr as $vars_name => $vars_data) {
if($vars_name != 'script_globals') global $$vars_name; if ($vars_name != 'script_globals') global $$vars_name;
if($$vars_name) { if ($$vars_name) {
print '<div class="vars-container" style="background-color:'.$vars_data[1].';"><span class="varsname">'.$vars_data[0].'</span><br />'; print '<div class="vars-container" style="background-color:'.$vars_data[1].';"><span class="varsname">'.$vars_data[0].'</span><br />';
print_a($$vars_name, FALSE, $show_object_vars, FALSE ); print_a($$vars_name, FALSE, $show_object_vars, FALSE );
print '</div>'; print '</div>';
...@@ -326,31 +336,4 @@ function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE) { ...@@ -326,31 +336,4 @@ function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE) {
} }
print '</div>'; print '</div>';
} }
/*!
* \brief Prints sql strings
*
* \param string $sql_string
*
* \param boolean $simple_mode FALSE
*/
function pre($sql_string, $simple_mode = FALSE) {
if(!$simple_mode) {
# erste leere Zeile im SQL lschen
$sql_string = preg_replace('/\^s+/m','', $sql_string);
# letze leere Zeile im SQL lschen
$sql_string = preg_replace('/\s+$/m','', $sql_string);
# kleinste Anzahl von fhrenden TABS zhlen
preg_match_all('/^\t+/m', $sql_string, $matches);
$minTabCount = strlen(min($matches[0]));
# und entfernen
$sql_string = preg_replace('/^\t{'.$minTabCount.'}/m', '', $sql_string);
}
print '<pre>'.$sql_string.'</pre>';
}
?> ?>
  • bmortier @bmortier

    mentioned in issue #855

    By Côme Chilliet on 2017-09-02T15:01:32 (imported from GitLab)

    ·

    mentioned in issue #855

    By Côme Chilliet on 2017-09-02T15:01:32 (imported from GitLab)

    Toggle commit list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment