URGENT: Infinite loop error with Smarty {debug} and $gCms

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
peedub

URGENT: Infinite loop error with Smarty {debug} and $gCms

Post by peedub »

I'm trying to debug a problem I'm having with Smarty tags not working in the Cataloger module - http://forum.cmsmadesimple.org/index.ph ... 011.0.html - and it seems I have run into something bigger.

If I put {debug} into my template (page template or Cataloger template) it gives an error:
Smarty Debug Console
included templates & config files (load time in seconds)

no templates included
assigned template variables

{$SCRIPT_NAME}  "/cmsmadesimple/index.php"
{$app_name} "CMS"
{$content_id} "15"
{$count} 8
{$encoding} "UTF-8"
{$friendly_position} "1"
{$gCms}
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 559777 bytes) in C:\xampplite\htdocs\cmsmadesimple\lib\smarty\plugins\modifier.debug_print_var.php on line 47
So it would seem that the problem with the {debug} Smarty tag lies within cmsmadesimple\lib\smarty\plugins\modifier.debug_print_var.php and something to do with {$gCms}

Here is the code from that file, lines 37 and 47 are outline with comments (colour coded orange), the Fatal error above switches between lines 37 and 47 from time to time:

Code: Select all

<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty debug_print_var modifier plugin
 *
 * 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
 * @return string
 */
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{
    $_replace = array(
        "\n" => '<i>\n</i>',
        "\r" => '<i>\r</i>',
        "\t" => '<i>\t</i>'
    );

    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> => '
/* ----------------------- LINE 37 --- */
                    . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
/* ----------------------- END LINE 37 --- */
                    $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> = '
/* ----------------------- LINE 47 --- */
                    . smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
/* ----------------------- END LINE 47 --- */
                    $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: */

?>

Can somebody please try putting {debug} into the top of their page template and let me know if the same error appears for you too? Include your CMSMS version.

I am currently using the latest version of CMSMS - 1.2.3 Black Rock
Last edited by peedub on Thu Mar 06, 2008 1:50 am, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: URGENT: Infinite loop error with Smarty {debug} and $gCms

Post by calguy1000 »

use {get_template_vars} instead of {debug} the $gCms object is very large....
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
peedub

Infinite loop error with Smarty {debug} and $gCms

Post by peedub »

Oh, I understand. Thanks for the tip Calguy.

Is it at all possible to get {debug} to work though? Or does it just show the exact same info as {get_template_vars} ?

Cheers
Locked

Return to “CMSMS Core”