From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- lib/smarty/plugins/modifier.debug_print_var.php | 104 ++++++++++++------------ 1 file changed, 51 insertions(+), 53 deletions(-) (limited to 'lib/smarty/plugins/modifier.debug_print_var.php') diff --git a/lib/smarty/plugins/modifier.debug_print_var.php b/lib/smarty/plugins/modifier.debug_print_var.php index fa44100..78397d0 100644 --- a/lib/smarty/plugins/modifier.debug_print_var.php +++ b/lib/smarty/plugins/modifier.debug_print_var.php @@ -1,56 +1,62 @@ - * Name: debug_print_var
+ * Type: modifier + * Name: debug_print_var * Purpose: formats variable contents for display in the console * - * @author Monte Ohrt + * @author Monte Ohrt + * * @param array|object $var variable to be formatted - * @param integer $depth maximum recursion depth if $var is an array - * @param integer $length maximum string length if $var is a string - * @return string + * @param int $max maximum recursion depth if $var is an array or object + * @param int $length maximum string length if $var is a string + * @param int $depth actual recursion depth + * @param array $objects processed objects in actual depth to prevent recursive object processing + * + * @return string */ -function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) +function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array()) { - $_replace = array("\n" => '\n', - "\r" => '\r', - "\t" => '\t' - ); - + $_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t'); switch (gettype($var)) { - case 'array' : + case 'array': $results = 'Array (' . count($var) . ')'; + if ($depth === $max) { + break; + } foreach ($var as $curr_key => $curr_val) { - $results .= '
' . str_repeat(' ', $depth * 2) - . '' . strtr($curr_key, $_replace) . ' => ' - . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); + $results .= '
' . str_repeat(' ', $depth * 2) . '' . strtr($curr_key, $_replace) . + ' => ' . + smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects); $depth--; - } + } break; - - case 'object' : + case 'object': $object_vars = get_object_vars($var); $results = '' . get_class($var) . ' Object (' . count($object_vars) . ')'; + if (in_array($var, $objects)) { + $results .= ' called recursive'; + break; + } + if ($depth === $max) { + break; + } + $objects[] = $var; foreach ($object_vars as $curr_key => $curr_val) { - $results .= '
' . str_repeat(' ', $depth * 2) - . ' ->' . strtr($curr_key, $_replace) . ' = ' - . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); + $results .= '
' . str_repeat(' ', $depth * 2) . ' ->' . strtr($curr_key, $_replace) . + ' = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects); $depth--; - } + } break; - - case 'boolean' : - case 'NULL' : - case 'resource' : + case 'boolean': + case 'NULL': + case 'resource': if (true === $var) { $results = 'true'; } elseif (false === $var) { @@ -58,34 +64,30 @@ function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) } elseif (null === $var) { $results = 'null'; } else { - $results = htmlspecialchars((string) $var); - } + $results = htmlspecialchars((string)$var); + } $results = '' . $results . ''; break; - - case 'integer' : - case 'float' : - $results = htmlspecialchars((string) $var); + case 'integer': + case 'float': + $results = htmlspecialchars((string)$var); break; - - case 'string' : + case 'string': $results = strtr($var, $_replace); if (Smarty::$_MBSTRING) { if (mb_strlen($var, Smarty::$_CHARSET) > $length) { $results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...'; } } else { - if (isset($var[$length])) { + if (isset($var[ $length ])) { $results = substr($var, 0, $length - 3) . '...'; } } - - $results = htmlspecialchars('"' . $results . '"'); + $results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET); break; - - case 'unknown type' : - default : - $results = strtr((string) $var, $_replace); + case 'unknown type': + default: + $results = strtr((string)$var, $_replace); if (Smarty::$_MBSTRING) { if (mb_strlen($results, Smarty::$_CHARSET) > $length) { $results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...'; @@ -95,11 +97,7 @@ function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) $results = substr($results, 0, $length - 3) . '...'; } } - - $results = htmlspecialchars($results); - } - + $results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET); + } return $results; -} - -?> \ No newline at end of file +} -- cgit v1.2.3