2012-07-04 01:23:08 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty plugin
|
2014-09-07 07:38:28 -04:00
|
|
|
*
|
|
|
|
* @package Smarty
|
2012-07-04 01:23:08 -04:00
|
|
|
* @subpackage Debug
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty debug_print_var modifier plugin
|
|
|
|
* Type: modifier<br>
|
|
|
|
* Name: debug_print_var<br>
|
|
|
|
* Purpose: formats variable contents for display in the console
|
|
|
|
*
|
2014-09-07 07:38:28 -04:00
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>
|
|
|
|
*
|
|
|
|
* @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
|
2012-07-04 01:23:08 -04:00
|
|
|
*/
|
2014-09-07 07:38:28 -04:00
|
|
|
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
2012-07-04 01:23:08 -04:00
|
|
|
{
|
|
|
|
$_replace = array("\n" => '<i>\n</i>',
|
2014-09-07 07:38:28 -04:00
|
|
|
"\r" => '<i>\r</i>',
|
|
|
|
"\t" => '<i>\t</i>'
|
|
|
|
);
|
2012-07-04 01:23:08 -04:00
|
|
|
|
|
|
|
switch (gettype($var)) {
|
|
|
|
case 'array' :
|
|
|
|
$results = '<b>Array (' . count($var) . ')</b>';
|
|
|
|
foreach ($var as $curr_key => $curr_val) {
|
|
|
|
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
2014-09-07 07:38:28 -04:00
|
|
|
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
|
|
|
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
|
|
|
$depth --;
|
|
|
|
}
|
2012-07-04 01:23:08 -04:00
|
|
|
break;
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
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)
|
2014-09-07 07:38:28 -04:00
|
|
|
. '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
|
|
|
|
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
|
|
|
$depth --;
|
|
|
|
}
|
2012-07-04 01:23:08 -04:00
|
|
|
break;
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
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);
|
2014-09-07 07:38:28 -04:00
|
|
|
}
|
2012-07-04 01:23:08 -04:00
|
|
|
$results = '<i>' . $results . '</i>';
|
|
|
|
break;
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
case 'integer' :
|
|
|
|
case 'float' :
|
|
|
|
$results = htmlspecialchars((string) $var);
|
|
|
|
break;
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
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;
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
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) . '...';
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 07:38:28 -04:00
|
|
|
|
2012-07-04 01:23:08 -04:00
|
|
|
$results = htmlspecialchars($results);
|
2014-09-07 07:38:28 -04:00
|
|
|
}
|
2012-07-04 01:23:08 -04:00
|
|
|
|
|
|
|
return $results;
|
2014-09-07 07:38:28 -04:00
|
|
|
}
|