home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / smarty / xoops_plugins / modifier.debug_print_var.php < prev    next >
Encoding:
PHP Script  |  2006-09-04  |  2.1 KB  |  65 lines

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * Smarty debug_print_var modifier plugin
  10.  * 
  11.  * Modified version of the default smarty plug-in that prevents endless looping when dealing with assigned
  12.  * objects
  13.  * 
  14.  * 
  15.  *
  16.  * Type:     modifier<br>
  17.  * Name:     debug_print_var<br>
  18.  * Purpose:  formats variable contents for display in the console
  19.  * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
  20.  *          debug_print_var (Smarty online manual)
  21.  * @param array|object
  22.  * @param integer
  23.  * @param integer
  24.  * @return string
  25.  */
  26. function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
  27. {
  28.     $_replace = array("\n"=>'<i>\n</i>', "\r"=>'<i>\r</i>', "\t"=>'<i>\t</i>');
  29.     if (is_array($var)) {
  30.         $results = "<b>Array (".count($var).")</b>";
  31.         foreach ($var as $curr_key => $curr_val) {
  32.             $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  33.             $results .= "<br>".str_repeat(' ', $depth*2)."<b>".strtr($curr_key, $_replace)."</b> => $return";
  34.         }
  35.     } else if (is_object($var)) {
  36.         $object_vars = get_object_vars($var);
  37.         $results = "<b>".get_class($var)." Object (".count($object_vars).")</b>";
  38.         foreach ($object_vars as $curr_key => $curr_val) {
  39.             if ( is_object( $curr_val ) ) {
  40.                 $return ='[object ' . get_class( $curr_val ) . ']';
  41.             } else {
  42.                 $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
  43.             }
  44.             $results .= "<br>".str_repeat(' ', $depth*2)."<b>$curr_key</b> => $return";
  45.         }
  46.     } else if (is_resource($var)) {
  47.         $results = '<i>'.(string)$var.'</i>';
  48.     } else if (empty($var) && $var != "0") {
  49.         $results = '<i>empty</i>';
  50.     } else {
  51.         if (strlen($var) > $length ) {
  52.             $results = substr($var, 0, $length-3).'...';
  53.         } else {
  54.             $results = $var;
  55.         }
  56.         $results = htmlspecialchars($results);
  57.         $results = strtr($results, $_replace);
  58.     }
  59.     return $results;
  60. }
  61.  
  62. /* vim: set expandtab: */
  63.  
  64. ?>
  65.