summaryrefslogtreecommitdiff
path: root/lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-10-18 02:39:34 +0200
committeremkael <emkael@tlen.pl>2018-10-18 02:39:42 +0200
commitab5d8d4e07bb3c8230d0285ef8902ef1979fce51 (patch)
tree0b955e585cb2fdbc7207392a5f2c97d610b6a5bc /lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php
parentc055ce2ab60c6582bad3e5babcb1d00384fde78a (diff)
Updating Smarty
Diffstat (limited to 'lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php')
-rw-r--r--lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php b/lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php
new file mode 100644
index 0000000..5306914
--- /dev/null
+++ b/lib/smarty/sysplugins/smarty_internal_runtime_make_nocache.php
@@ -0,0 +1,54 @@
+<?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;
+ }
+ }
+}