1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<?php /** * Smarty plugin * @package Smarty * @subpackage plugins */
/** * Smarty debug_print_var modifier plugin * * Gallery modification: Filter all (hashed) passwords in smarty's debug output. * * 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 * @param string * @return string */ function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40, $parentKey='') { $_replace = array( "\n" => '<i>\n</i>', "\r" => '<i>\r</i>', "\t" => '<i>\t</i>' );
if (!is_array($var) && !is_object($var) && stristr($parentKey, 'password') !== false) { $var = '[Not shown in debug output]'; }
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, $curr_key); $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, $curr_key); $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: */
?>
|