init
[garradin.git] / include / libs / template_lite / plugins / modifier.debug_print_var.php
1 <?php
2
3 /*
4 * Smarty plugin
5 * -------------------------------------------------------------
6 * Type: modifier
7 * Name: debug_print_var
8 * Purpose: formats variable contents for display in the console
9 * -------------------------------------------------------------
10 */
11 function tpl_modifier_debug_print_var($var, $depth = 0, $length = 40)
12 {
13 if (is_array($var))
14 {
15 $results = "<b>Array (".count($var).")</b>";
16 foreach ($var as $curr_key => $curr_val)
17 {
18 $return = tpl_modifier_debug_print_var($curr_val, $depth+1, $length);
19 $results .= '<br>\r'.str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
20 }
21 return $results;
22 }
23 else if (is_object($var))
24 {
25 $object_vars = get_object_vars($var);
26 $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
27 foreach ($object_vars as $curr_key => $curr_val)
28 {
29 $return = tpl_modifier_debug_print_var($curr_val, $depth+1, $length);
30 $results .= '<br>\r'.str_repeat('&nbsp;', $depth*2)."<b>$curr_key</b> =&gt; $return";
31 }
32 return $results;
33 }
34 else
35 {
36 if (empty($var) && $var != "0")
37 {
38 return '<i>empty</i>';
39 }
40 if (strlen($var) > $length )
41 {
42 $results = substr($var, 0, $length-3).'...';
43 }
44 else
45 {
46 $results = $var;
47 }
48 $results = preg_replace("![\r\t\n]!", " ", $results);
49 $results = htmlspecialchars($results);
50 return $results;
51 }
52 }
53
54 ?>