Редакция 2 | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 235 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * Smarty plugin
|
3 | * Smarty plugin
|
4 | * @package Smarty
|
4 | * @package Smarty
|
5 | * @subpackage plugins
|
5 | * @subpackage plugins
|
6 | */
|
6 | */
|
7 | 7 | ||
8 | 8 | ||
9 | /**
|
9 | /**
|
10 | * Smarty debug_print_var modifier plugin
|
10 | * Smarty debug_print_var modifier plugin
|
11 | *
|
11 | *
|
12 | * Type: modifier<br>
|
12 | * Type: modifier<br>
|
13 | * Name: debug_print_var<br>
|
13 | * Name: debug_print_var<br>
|
14 | * Purpose: formats variable contents for display in the console
|
14 | * Purpose: formats variable contents for display in the console
|
15 | * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
|
15 | * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
|
16 | * debug_print_var (Smarty online manual)
|
16 | * debug_print_var (Smarty online manual)
|
17 | * @author Monte Ohrt <monte at ohrt dot com>
|
17 | * @author Monte Ohrt <monte at ohrt dot com>
|
18 | * @param array|object
|
18 | * @param array|object
|
19 | * @param integer
|
19 | * @param integer
|
20 | * @param integer
|
20 | * @param integer
|
21 | * @return string
|
21 | * @return string
|
22 | */
|
22 | */
|
23 | function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) |
23 | function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) |
24 | {
|
24 | {
|
25 | $_replace = array( |
25 | $_replace = array( |
26 | "\n" => '<i>\n</i>', |
26 | "\n" => '<i>\n</i>', |
27 | "\r" => '<i>\r</i>', |
27 | "\r" => '<i>\r</i>', |
28 | "\t" => '<i>\t</i>' |
28 | "\t" => '<i>\t</i>' |
29 | ); |
29 | ); |
30 | 30 | ||
31 | switch (gettype($var)) { |
31 | switch (gettype($var)) { |
32 | case 'array' : |
32 | case 'array' : |
33 | $results = '<b>Array (' . count($var) . ')</b>'; |
33 | $results = '<b>Array (' . count($var) . ')</b>'; |
34 | foreach ($var as $curr_key => $curr_val) { |
34 | foreach ($var as $curr_key => $curr_val) { |
35 | $results .= '<br>' . str_repeat(' ', $depth * 2) |
35 | $results .= '<br>' . str_repeat(' ', $depth * 2) |
36 | . '<b>' . strtr($curr_key, $_replace) . '</b> => ' |
36 | . '<b>' . strtr($curr_key, $_replace) . '</b> => ' |
37 | . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); |
37 | . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); |
38 | $depth--; |
38 | $depth--; |
39 | }
|
39 | }
|
40 | break; |
40 | break; |
41 | case 'object' : |
41 | case 'object' : |
42 | $object_vars = get_object_vars($var); |
42 | $object_vars = get_object_vars($var); |
43 | $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; |
43 | $results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>'; |
44 | foreach ($object_vars as $curr_key => $curr_val) { |
44 | foreach ($object_vars as $curr_key => $curr_val) { |
45 | $results .= '<br>' . str_repeat(' ', $depth * 2) |
45 | $results .= '<br>' . str_repeat(' ', $depth * 2) |
46 | . '<b> ->' . strtr($curr_key, $_replace) . '</b> = ' |
46 | . '<b> ->' . strtr($curr_key, $_replace) . '</b> = ' |
47 | . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); |
47 | . smarty_modifier_debug_print_var($curr_val, ++$depth, $length); |
48 | $depth--; |
48 | $depth--; |
49 | }
|
49 | }
|
50 | break; |
50 | break; |
51 | case 'boolean' : |
51 | case 'boolean' : |
52 | case 'NULL' : |
52 | case 'NULL' : |
53 | case 'resource' : |
53 | case 'resource' : |
54 | if (true === $var) { |
54 | if (true === $var) { |
55 | $results = 'true'; |
55 | $results = 'true'; |
56 | } elseif (false === $var) { |
56 | } elseif (false === $var) { |
57 | $results = 'false'; |
57 | $results = 'false'; |
58 | } elseif (null === $var) { |
58 | } elseif (null === $var) { |
59 | $results = 'null'; |
59 | $results = 'null'; |
60 | } else { |
60 | } else { |
61 | $results = htmlspecialchars((string) $var); |
61 | $results = htmlspecialchars((string) $var); |
62 | }
|
62 | }
|
63 | $results = '<i>' . $results . '</i>'; |
63 | $results = '<i>' . $results . '</i>'; |
64 | break; |
64 | break; |
65 | case 'integer' : |
65 | case 'integer' : |
66 | case 'float' : |
66 | case 'float' : |
67 | $results = htmlspecialchars((string) $var); |
67 | $results = htmlspecialchars((string) $var); |
68 | break; |
68 | break; |
69 | case 'string' : |
69 | case 'string' : |
70 | $results = strtr($var, $_replace); |
70 | $results = strtr($var, $_replace); |
71 | if (strlen($var) > $length ) { |
71 | if (strlen($var) > $length ) { |
72 | $results = substr($var, 0, $length - 3) . '...'; |
72 | $results = substr($var, 0, $length - 3) . '...'; |
73 | }
|
73 | }
|
74 | $results = htmlspecialchars('"' . $results . '"'); |
74 | $results = htmlspecialchars('"' . $results . '"'); |
75 | break; |
75 | break; |
76 | case 'unknown type' : |
76 | case 'unknown type' : |
77 | default : |
77 | default : |
78 | $results = strtr((string) $var, $_replace); |
78 | $results = strtr((string) $var, $_replace); |
79 | if (strlen($results) > $length ) { |
79 | if (strlen($results) > $length ) { |
80 | $results = substr($results, 0, $length - 3) . '...'; |
80 | $results = substr($results, 0, $length - 3) . '...'; |
81 | }
|
81 | }
|
82 | $results = htmlspecialchars($results); |
82 | $results = htmlspecialchars($results); |
83 | }
|
83 | }
|
84 | 84 | ||
85 | return $results; |
85 | return $results; |
86 | }
|
86 | }
|
87 | 87 | ||
88 | /* vim: set expandtab: */
|
88 | /* vim: set expandtab: */
|
89 | 89 | ||
90 | ?>
|
90 | ?>
|
91 | 91 |