smarty icon indicating copy to clipboard operation
smarty copied to clipboard

using php function time in template should display a warning

Open shadowwa opened this issue 9 months ago • 3 comments

Fixes #1114

shadowwa avatar Mar 16 '25 14:03 shadowwa

How about libs/sysplugins/smarty_internal_templatecompilerbase.php:662:

                    if (
                        !$this->smarty->loadPlugin('smarty_modifiercompiler_' . $name)
                        && !isset($this->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$name])
                        && !in_array($name, ['time', 'join', 'is_array', 'in_array', 'count'])
                    ) {
                        trigger_error('Using unregistered function "' . $name . '" in a template is deprecated and will be ' .
                            'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                            'a custom modifier.', E_USER_DEPRECATED);
                    }

wisskid avatar Mar 17 '25 08:03 wisskid

I don't get it, this is the modification I proposed.

Edit: did you mean libs/sysplugins/smarty_internal_compile_private_modifier.php:112 ?:

                                if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
                                    trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
                                        'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                                        'a custom modifier.', E_USER_DEPRECATED);
                                }

To be honest I don't know what is the use of this part of code. Not only it does not change the behaviour of displaying a warning or not for time() but it contrary to libs/sysplugins/smarty_internal_templatecompilerbase.php:662 it does not check against 'count' and currently usage of {count($var)} or {$var|count} in template work correctly without deprecation warnings

shadowwa avatar Mar 17 '25 09:03 shadowwa

Sorry, my bad. Copied the wrong reference. I meant to reference this: libs/sysplugins/smarty_internal_compile_private_modifier.php:112:

if (!is_object($compiler->smarty->security_policy)
                                || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
                            ) {
                                if (!in_array($modifier, ['time', 'join', 'is_array', 'in_array'])) {
                                    trigger_error('Using unregistered function "' . $modifier . '" in a template is deprecated and will be ' .
                                        'removed in a future release. Use Smarty::registerPlugin to explicitly register ' .
                                        'a custom modifier.', E_USER_DEPRECATED);
                                }
                                $output = "{$modifier}({$params})";
                            }

wisskid avatar Mar 17 '25 09:03 wisskid