
Comparing changes: https://github.com/smarty-php/smarty/compare/v4.3.1...v4.4.1 It is noticeable that Smarty 4.3.1 does not officially support PHP 8.3. Is only supported with 4.4.0. Remark: During tests with Smarty 4.5.1, it was noticed that the following warning occurs: Deprecated: Using the unregistered function "function_exists" in a template is deprecated and will be removed in a future version. Use Smarty::registerPlugin to explicitly register a custom modifier. As of Smarty 5.X.X, templates must be revised again. The Smarty release 5.0.2 is already officially available. However, integration into FlatPress is not entirely trivial.
55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* {make_nocache} Runtime Methods save(), store()
|
|
*
|
|
* @package Smarty
|
|
* @subpackage PluginsInternal
|
|
* @author Uwe Tews
|
|
*/
|
|
class Smarty_Internal_Runtime_Make_Nocache
|
|
{
|
|
/**
|
|
* Save current variable value while rendering compiled template and inject nocache code to
|
|
* assign variable value in cahed template
|
|
*
|
|
* @param \Smarty_Internal_Template $tpl
|
|
* @param string $var variable name
|
|
*
|
|
* @throws \SmartyException
|
|
*/
|
|
public function save(Smarty_Internal_Template $tpl, $var)
|
|
{
|
|
if (isset($tpl->tpl_vars[ $var ])) {
|
|
$export =
|
|
preg_replace('/^\\\\?Smarty_Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[ $var ], true));
|
|
if (preg_match('/(\w+)::__set_state/', $export, $match)) {
|
|
throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
|
|
}
|
|
echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " .
|
|
addcslashes("\$_smarty_tpl->smarty->ext->_make_nocache->store(\$_smarty_tpl, '{$var}', ", '\\') .
|
|
$export . ");?>\n/*/%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store variable value saved while rendering compiled template in cached template context
|
|
*
|
|
* @param \Smarty_Internal_Template $tpl
|
|
* @param string $var variable name
|
|
* @param array $properties
|
|
*/
|
|
public function store(Smarty_Internal_Template $tpl, $var, $properties)
|
|
{
|
|
// do not overwrite existing nocache variables
|
|
if (!isset($tpl->tpl_vars[ $var ]) || !$tpl->tpl_vars[ $var ]->nocache) {
|
|
$newVar = new Smarty_Variable();
|
|
unset($properties[ 'nocache' ]);
|
|
foreach ($properties as $k => $v) {
|
|
$newVar->$k = $v;
|
|
}
|
|
$tpl->tpl_vars[ $var ] = $newVar;
|
|
}
|
|
}
|
|
}
|