From 7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 12 May 2012 17:57:41 -0700 Subject: some important stuff we'll need --- .../libs/plugins/modifier.debug_print_var.php | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 lib/smarty/libs/plugins/modifier.debug_print_var.php (limited to 'lib/smarty/libs/plugins/modifier.debug_print_var.php') diff --git a/lib/smarty/libs/plugins/modifier.debug_print_var.php b/lib/smarty/libs/plugins/modifier.debug_print_var.php new file mode 100644 index 000000000..fa44100e8 --- /dev/null +++ b/lib/smarty/libs/plugins/modifier.debug_print_var.php @@ -0,0 +1,105 @@ + + * Name: debug_print_var
+ * Purpose: formats variable contents for display in the console + * + * @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 + */ +function smarty_modifier_debug_print_var ($var, $depth = 0, $length = 40) +{ + $_replace = array("\n" => '\n', + "\r" => '\r', + "\t" => '\t' + ); + + switch (gettype($var)) { + case 'array' : + $results = 'Array (' . count($var) . ')'; + 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); + $depth--; + } + break; + + case 'object' : + $object_vars = get_object_vars($var); + $results = '' . get_class($var) . ' Object (' . count($object_vars) . ')'; + 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); + $depth--; + } + break; + + case 'boolean' : + case 'NULL' : + case 'resource' : + if (true === $var) { + $results = 'true'; + } elseif (false === $var) { + $results = 'false'; + } elseif (null === $var) { + $results = 'null'; + } else { + $results = htmlspecialchars((string) $var); + } + $results = '' . $results . ''; + break; + + case 'integer' : + case 'float' : + $results = htmlspecialchars((string) $var); + break; + + 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])) { + $results = substr($var, 0, $length - 3) . '...'; + } + } + + $results = htmlspecialchars('"' . $results . '"'); + break; + + 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) . '...'; + } + } else { + if (strlen($results) > $length) { + $results = substr($results, 0, $length - 3) . '...'; + } + } + + $results = htmlspecialchars($results); + } + + return $results; +} + +?> \ No newline at end of file -- cgit v1.2.3