_execute($template, $cache_id, $compile_id, $parent, 0); return $result === null ? ob_get_clean() : $result; } /** * displays a Smarty template * * @param string $template the resource handle of the template file or template object * @param mixed $cache_id cache id to be used with this template * @param mixed $compile_id compile id to be used with this template * @param object $parent next higher level of Smarty variables */ public function display($template = null, $cache_id = null, $compile_id = null, $parent = null) { // display template $this->_execute($template, $cache_id, $compile_id, $parent, 1); } /** * test if cache is valid * * @api Smarty::isCached() * @link http://www.smarty.net/docs/en/api.is.cached.tpl * * @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object * @param mixed $cache_id cache id to be used with this template * @param mixed $compile_id compile id to be used with this template * @param object $parent next higher level of Smarty variables * * @return boolean cache status */ public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) { return $this->_execute($template, $cache_id, $compile_id, $parent, 2); } /** * fetches a rendered Smarty template * * @param string $template the resource handle of the template file or template object * @param mixed $cache_id cache id to be used with this template * @param mixed $compile_id compile id to be used with this template * @param object $parent next higher level of Smarty variables * @param string $function function type 0 = fetch, 1 = display, 2 = isCache * * @return mixed * @throws \Exception * @throws \SmartyException */ private function _execute($template, $cache_id, $compile_id, $parent, $function) { $smarty = $this->_getSmartyObj(); $saveVars = true; if ($template === null) { if (!$this->_isTplObj()) { throw new SmartyException($function . '():Missing \'$template\' parameter'); } else { $template = $this; } } elseif (is_object($template)) { /* @var Smarty_Internal_Template $template */ if (!isset($template->_objType) || !$template->_isTplObj()) { throw new SmartyException($function . '():Template object expected'); } } else { // get template object $saveVars = false; $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent ? $parent : $this, false); if ($this->_objType == 1) { // set caching in template object $template->caching = $this->caching; } } // fetch template content $level = ob_get_level(); try { $_smarty_old_error_level = isset($smarty->error_reporting) ? error_reporting($smarty->error_reporting) : null; if ($this->_objType == 2) { /* @var Smarty_Internal_Template $this */ $template->tplFunctions = $this->tplFunctions; $template->inheritance = $this->inheritance; } /* @var Smarty_Internal_Template $parent */ if (isset($parent->_objType) && ($parent->_objType == 2) && !empty($parent->tplFunctions)) { $template->tplFunctions = array_merge($parent->tplFunctions, $template->tplFunctions); } if ($function == 2) { if ($template->caching) { // return cache status of template if (!isset($template->cached)) { $template->loadCached(); } $result = $template->cached->isCached($template); Smarty_Internal_Template::$isCacheTplObj[ $template->_getTemplateId() ] = $template; } else { return false; } } else { if ($saveVars) { $savedTplVars = $template->tpl_vars; $savedConfigVars = $template->config_vars; } ob_start(); $template->_mergeVars(); if (!empty(Smarty::$global_tpl_vars)) { $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars); } $result = $template->render(false, $function); $template->_cleanUp(); if ($saveVars) { $template->tpl_vars = $savedTplVars; $template->config_vars = $savedConfigVars; } else { if (!$function && !isset(Smarty_Internal_Template::$tplObjCache[ $template->templateId ])) { $template->parent = null; $template->tpl_vars = $template->config_vars = array(); Smarty_Internal_Template::$tplObjCache[ $template->templateId ] = $template; } } } if (isset($_smarty_old_error_level)) { error_reporting($_smarty_old_error_level); } return $result; } catch (Exception $e) { while (ob_get_level() > $level) { ob_end_clean(); } if (isset($_smarty_old_error_level)) { error_reporting($_smarty_old_error_level); } throw $e; } } /** * Registers plugin to be used in templates * * @api Smarty::registerPlugin() * @link http://www.smarty.net/docs/en/api.register.plugin.tpl * * @param string $type plugin type * @param string $name name of template tag * @param callback $callback PHP callback to register * @param bool $cacheable if true (default) this function is cache able * @param mixed $cache_attr caching attributes if any * * @return \Smarty|\Smarty_Internal_Template * @throws SmartyException when the plugin tag is invalid */ public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) { return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr); } /** * load a filter of specified type and name * * @api Smarty::loadFilter() * @link http://www.smarty.net/docs/en/api.load.filter.tpl * * @param string $type filter type * @param string $name filter name * * @return bool * @throws SmartyException if filter could not be loaded */ public function loadFilter($type, $name) { return $this->ext->loadFilter->loadFilter($this, $type, $name); } /** * Registers a filter function * * @api Smarty::registerFilter() * @link http://www.smarty.net/docs/en/api.register.filter.tpl * * @param string $type filter type * @param callback $callback * @param string|null $name optional filter name * * @return \Smarty|\Smarty_Internal_Template * @throws \SmartyException */ public function registerFilter($type, $callback, $name = null) { return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name); } /** * Registers object to be used in templates * * @api Smarty::registerObject() * @link http://www.smarty.net/docs/en/api.register.object.tpl * * @param string $object_name * @param object $object the referenced PHP object to register * @param array $allowed_methods_properties list of allowed methods (empty = all) * @param bool $format smarty argument format, else traditional * @param array $block_methods list of block-methods * * @return \Smarty|\Smarty_Internal_Template * @throws \SmartyException */ public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array()) { return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties, $format, $block_methods); } /** * @param boolean $caching */ public function setCaching($caching) { $this->caching = $caching; } /** * @param int $cache_lifetime */ public function setCacheLifetime($cache_lifetime) { $this->cache_lifetime = $cache_lifetime; } /** * @param string $compile_id */ public function setCompileId($compile_id) { $this->compile_id = $compile_id; } /** * @param string $cache_id */ public function setCacheId($cache_id) { $this->cache_id = $cache_id; } }