From ab5d8d4e07bb3c8230d0285ef8902ef1979fce51 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 18 Oct 2018 02:39:34 +0200 Subject: Updating Smarty --- .../sysplugins/smarty_internal_runtime_capture.php | 174 +++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 lib/smarty/sysplugins/smarty_internal_runtime_capture.php (limited to 'lib/smarty/sysplugins/smarty_internal_runtime_capture.php') diff --git a/lib/smarty/sysplugins/smarty_internal_runtime_capture.php b/lib/smarty/sysplugins/smarty_internal_runtime_capture.php new file mode 100644 index 0000000..c9dca83 --- /dev/null +++ b/lib/smarty/sysplugins/smarty_internal_runtime_capture.php @@ -0,0 +1,174 @@ +isRegistered) { + $this->register($_template); + } + $this->captureStack[] = array( + $buffer, + $assign, + $append + ); + $this->captureCount++; + ob_start(); + } + + /** + * Register callbacks in template class + * + * @param \Smarty_Internal_Template $_template + */ + private function register(Smarty_Internal_Template $_template) + { + $_template->startRenderCallbacks[] = array( + $this, + 'startRender' + ); + $_template->endRenderCallbacks[] = array( + $this, + 'endRender' + ); + $this->startRender($_template); + $this->isRegistered = true; + } + + /** + * Start render callback + * + * @param \Smarty_Internal_Template $_template + */ + public function startRender(Smarty_Internal_Template $_template) + { + $this->countStack[] = $this->captureCount; + $this->captureCount = 0; + } + + /** + * Close capture section + * + * @param \Smarty_Internal_Template $_template + * + * @throws \SmartyException + */ + public function close(Smarty_Internal_Template $_template) + { + if ($this->captureCount) { + list($buffer, $assign, $append) = array_pop($this->captureStack); + $this->captureCount--; + if (isset($assign)) { + $_template->assign($assign, ob_get_contents()); + } + if (isset($append)) { + $_template->append($append, ob_get_contents()); + } + $this->namedBuffer[ $buffer ] = ob_get_clean(); + } else { + $this->error($_template); + } + } + + /** + * Error exception on not matching {capture}{/capture} + * + * @param \Smarty_Internal_Template $_template + * + * @throws \SmartyException + */ + public function error(Smarty_Internal_Template $_template) + { + throw new SmartyException("Not matching {capture}{/capture} in '{$_template->template_resource}'"); + } + + /** + * Return content of named capture buffer by key or as array + * + * @param \Smarty_Internal_Template $_template + * @param string|null $name + * + * @return string|string[]|null + */ + public function getBuffer(Smarty_Internal_Template $_template, $name = null) + { + if (isset($name)) { + return isset($this->namedBuffer[ $name ]) ? $this->namedBuffer[ $name ] : null; + } else { + return $this->namedBuffer; + } + } + + /** + * End render callback + * + * @param \Smarty_Internal_Template $_template + * + * @throws \SmartyException + */ + public function endRender(Smarty_Internal_Template $_template) + { + if ($this->captureCount) { + $this->error($_template); + } else { + $this->captureCount = array_pop($this->countStack); + } + } +} -- cgit v1.2.3