Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty debug_print_var modifier plugin
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * Type:     modifier
Chris PeBenito 696b41
 * Name:     debug_print_var
Chris PeBenito 696b41
 * Purpose:  formats variable contents for display in the console
Chris PeBenito 696b41
 * @link http://smarty.php.net/manual/en/language.modifier.debug.print.var.php
Chris PeBenito 696b41
 *          debug_print_var (Smarty online manual)
Chris PeBenito 696b41
 * @param array|object
Chris PeBenito 696b41
 * @param integer
Chris PeBenito 696b41
 * @param integer
Chris PeBenito 696b41
 * @return string
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
    $_replace = array("\n"=>'\n', "\r"=>'\r', "\t"=>'\t');
Chris PeBenito 696b41
    if (is_array($var)) {
Chris PeBenito 696b41
        $results = "Array (".count($var).")";
Chris PeBenito 696b41
        foreach ($var as $curr_key => $curr_val) {
Chris PeBenito 696b41
            $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
Chris PeBenito 696b41
            $results .= "
".str_repeat(' ', $depth*2)."".strtr($curr_key, $_replace)." => $return";
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
    } else if (is_object($var)) {
Chris PeBenito 696b41
        $object_vars = get_object_vars($var);
Chris PeBenito 696b41
        $results = "".get_class($var)." Object (".count($object_vars).")";
Chris PeBenito 696b41
        foreach ($object_vars as $curr_key => $curr_val) {
Chris PeBenito 696b41
            $return = smarty_modifier_debug_print_var($curr_val, $depth+1, $length);
Chris PeBenito 696b41
            $results .= "
".str_repeat(' ', $depth*2)."$curr_key => $return";
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
    } else if (is_resource($var)) {
Chris PeBenito 696b41
        $results = ''.(string)$var.'';
Chris PeBenito 696b41
    } else if (empty($var) && $var != "0") {
Chris PeBenito 696b41
        $results = 'empty';
Chris PeBenito 696b41
    } else {
Chris PeBenito 696b41
        if (strlen($var) > $length ) {
Chris PeBenito 696b41
            $results = substr($var, 0, $length-3).'...';
Chris PeBenito 696b41
        } else {
Chris PeBenito 696b41
            $results = $var;
Chris PeBenito 696b41
        }
Chris PeBenito 696b41
        $results = htmlspecialchars($results);
Chris PeBenito 696b41
        $results = strtr($results, $_replace);
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
    return $results;
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>