Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug function is broken #922

Closed
JordyThijsRB-Media opened this issue Dec 28, 2023 · 1 comment · Fixed by #923
Closed

Debug function is broken #922

JordyThijsRB-Media opened this issue Dec 28, 2023 · 1 comment · Fixed by #923
Milestone

Comments

@JordyThijsRB-Media
Copy link

JordyThijsRB-Media commented Dec 28, 2023

Hi,
Currently the debug function ({debug}) is broken, because the COMPILECHECK_ON and CACHING_OFF constants from the Smarty class are called using the wrong namespace (The backslash should be dropped). The path to debug.tpl is also wrong (the "../" needs to be removed). This is the fixed version of display_debug():

    public function display_debug($obj, $full = false)
    {
        if (!$full) {
            $this->offset++;
            $savedIndex = $this->index;
            $this->index = 9999;
        }
        $smarty = $obj->getSmarty();
        // create fresh instance of smarty for displaying the debug console
        // to avoid problems if the application did overload the Smarty class
        $debObj = new Smarty();
        // copy the working dirs from application
        $debObj->setCompileDir($smarty->getCompileDir());
        $debObj->compile_check = Smarty::COMPILECHECK_ON;
        $debObj->security_policy = null;
        $debObj->debugging = false;
        $debObj->debugging_ctrl = 'NONE';
        $debObj->error_reporting = E_ALL & ~E_NOTICE;
        $debObj->debug_tpl = $smarty->debug_tpl ?? 'file:' . __DIR__ . '/debug.tpl';
        $debObj->registered_resources = array();
        $debObj->escape_html = true;
        $debObj->caching = Smarty::CACHING_OFF;
        // prepare information of assigned variables
        $ptr = $this->get_debug_vars($obj);
        $_assigned_vars = $ptr->tpl_vars;
        ksort($_assigned_vars);
        $_config_vars = $ptr->config_vars;
        ksort($_config_vars);
        $debugging = $smarty->debugging;
        $templateName = $obj->getSource()->type . ':' . $obj->getSource()->name;
        $displayMode = $debugging === 2 || !$full;
        $offset = $this->offset * 50;
        $_template = $debObj->doCreateTemplate($debObj->debug_tpl);
        if ($obj instanceof Template) {
            $_template->assign('template_name', $templateName);
        } elseif ($obj instanceof Smarty || $full) {
            $_template->assign('template_data', $this->template_data[$this->index]);
        } else {
            $_template->assign('template_data', null);
        }
        $_template->assign('assigned_vars', $_assigned_vars);
        $_template->assign('config_vars', $_config_vars);
        $_template->assign('execution_time', microtime(true) - $smarty->start_time);
        $_template->assign('targetWindow', $displayMode ? md5("$offset$templateName") : '__Smarty__');
        $_template->assign('offset', $offset);
        echo $_template->fetch();
        if (isset($full)) {
            $this->index--;
        }
        if (!$full) {
            $this->index = $savedIndex;
        }
    }

The FQN is also wrong in the debug.tpl, but there it's the other way around. {Smarty::SMARTY_VERSION} should be {Smarty\Smarty::SMARTY_VERSION}.

@wisskid
Copy link
Contributor

wisskid commented Dec 29, 2023

@JordyThijsRB-Media thanks! Care to make it into Smarty's wall of fame by making a PR to fix this?

@wisskid wisskid added this to the 5.0 milestone Dec 29, 2023
wisskid added a commit that referenced this issue Jan 1, 2024
wisskid added a commit that referenced this issue Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants