1: <?php
2: 3: 4: 5: 6: 7:
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23: function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
24: {
25: $_replace = array("\n" => '<i>\n</i>',
26: "\r" => '<i>\r</i>',
27: "\t" => '<i>\t</i>'
28: );
29:
30: switch (gettype($var)) {
31: case 'array' :
32: $results = '<b>Array (' . count($var) . ')</b>';
33: foreach ($var as $curr_key => $curr_val) {
34: $results .= '<br>' . str_repeat(' ', $depth * 2)
35: . '<b>' . strtr($curr_key, $_replace) . '</b> => '
36: . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
37: $depth --;
38: }
39: break;
40:
41: case 'object' :
42: $object_vars = get_object_vars($var);
43: $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
44: foreach ($object_vars as $curr_key => $curr_val) {
45: $results .= '<br>' . str_repeat(' ', $depth * 2)
46: . '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
47: . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
48: $depth --;
49: }
50: break;
51:
52: case 'boolean' :
53: case 'NULL' :
54: case 'resource' :
55: if (true === $var) {
56: $results = 'true';
57: } elseif (false === $var) {
58: $results = 'false';
59: } elseif (null === $var) {
60: $results = 'null';
61: } else {
62: $results = htmlspecialchars((string) $var);
63: }
64: $results = '<i>' . $results . '</i>';
65: break;
66:
67: case 'integer' :
68: case 'float' :
69: $results = htmlspecialchars((string) $var);
70: break;
71:
72: case 'string' :
73: $results = strtr($var, $_replace);
74: if (Smarty::$_MBSTRING) {
75: if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
76: $results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
77: }
78: } else {
79: if (isset($var[$length])) {
80: $results = substr($var, 0, $length - 3) . '...';
81: }
82: }
83:
84: $results = htmlspecialchars('"' . $results . '"');
85: break;
86:
87: case 'unknown type' :
88: default :
89: $results = strtr((string) $var, $_replace);
90: if (Smarty::$_MBSTRING) {
91: if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
92: $results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
93: }
94: } else {
95: if (strlen($results) > $length) {
96: $results = substr($results, 0, $length - 3) . '...';
97: }
98: }
99:
100: $results = htmlspecialchars($results);
101: }
102:
103: return $results;
104: }
105: