diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-02-27 02:31:51 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-02-27 02:31:51 +0000 |
commit | 75bb450a6ece6b2e30ad4c148083b7192d7d7224 (patch) | |
tree | 6b3e6c0da5baa7ba7e736e79a4b49a83918f25c9 /include/smarty/libs/plugins/modifier.debug_print_var.php | |
parent | 01687607ec04f32ca03370456c112b64f66ca599 (diff) |
- first smarty use ... (in admin.php and admin plugins page)
git-svn-id: http://piwigo.org/svn/trunk@2216 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/smarty/libs/plugins/modifier.debug_print_var.php')
-rw-r--r-- | include/smarty/libs/plugins/modifier.debug_print_var.php | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/include/smarty/libs/plugins/modifier.debug_print_var.php b/include/smarty/libs/plugins/modifier.debug_print_var.php new file mode 100644 index 000000000..e4f7bc0cc --- /dev/null +++ b/include/smarty/libs/plugins/modifier.debug_print_var.php @@ -0,0 +1,90 @@ +<?php +/** + * Smarty plugin + * @package Smarty + * @subpackage plugins + */ + + +/** + * Smarty debug_print_var modifier plugin + * + * Type: modifier<br> + * Name: debug_print_var<br> + * Purpose: formats variable contents for display in the console + * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php + * debug_print_var (Smarty online manual) + * @author Monte Ohrt <monte at ohrt dot com> + * @param array|object + * @param integer + * @param integer + * @return string + */ +function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) +{ + $_replace = array( + "\n" => '<i>\n</i>', + "\r" => '<i>\r</i>', + "\t" => '<i>\t</i>' + ); + + switch (gettype($var)) { + case 'array' : + $results = '<b>Array (' . count($var) . ')</b>'; + foreach ($var as $curr_key => $curr_val) { + $results .= '<br>' . str_repeat(' ', $depth * 2) + . '<b>' . strtr($curr_key, $_replace) . '</b> => ' + . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); + $depth--; + } + break; + case 'object' : + $object_vars = get_object_vars($var); + $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; + foreach ($object_vars as $curr_key => $curr_val) { + $results .= '<br>' . str_repeat(' ', $depth * 2) + . '<b> ->' . strtr($curr_key, $_replace) . '</b> = ' + . 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 = '<i>' . $results . '</i>'; + break; + case 'integer' : + case 'float' : + $results = htmlspecialchars((string) $var); + break; + case 'string' : + $results = strtr($var, $_replace); + if (strlen($var) > $length ) { + $results = substr($var, 0, $length - 3) . '...'; + } + $results = htmlspecialchars('"' . $results . '"'); + break; + case 'unknown type' : + default : + $results = strtr((string) $var, $_replace); + if (strlen($results) > $length ) { + $results = substr($results, 0, $length - 3) . '...'; + } + $results = htmlspecialchars($results); + } + + return $results; +} + +/* vim: set expandtab: */ + +?> |