smarty) ? $this->smarty : $this; if (isset($smarty->registered_plugins[$type][$name])) { throw new SmartyException("Plugin tag \"{$name}\" already registered"); } elseif (!is_callable($callback)) { throw new SmartyException("Plugin \"{$name}\" not callable"); } else { $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr); } return $this; } /** * load a filter of specified type and name * NOTE: this method can be safely removed for dynamic loading * * @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) { /* @var Smarty $smarty */ $smarty = isset($this->smarty) ? $this->smarty : $this; if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { throw new SmartyException("Illegal filter type \"{$type}\""); } $_plugin = "smarty_{$type}filter_{$name}"; $_filter_name = $_plugin; if (is_callable($_plugin)) { $smarty->registered_filters[$type][$_filter_name] = $_plugin; return true; } if ($smarty->loadPlugin($_plugin)) { if (class_exists($_plugin, false)) { $_plugin = array($_plugin, 'execute'); } if (is_callable($_plugin)) { $smarty->registered_filters[$type][$_filter_name] = $_plugin; return true; } } throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); } /** * Registers a filter function * NOTE: this method can be safely removed for dynamic loading * * @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) { /* @var Smarty $smarty */ $smarty = isset($this->smarty) ? $this->smarty : $this; if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { throw new SmartyException("Illegal filter type \"{$type}\""); } $name = isset($name) ? $name : $this->_getFilterName($callback); if (!is_callable($callback)) { throw new SmartyException("{$type}filter \"{$name}\" not callable"); } $smarty->registered_filters[$type][$name] = $callback; return $this; } /** * Return internal filter name * * @param callback $function_name * * @return string internal filter name */ public function _getFilterName($function_name) { if (is_array($function_name)) { $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); return $_class_name . '_' . $function_name[1]; } elseif (is_string($function_name)) { return $function_name; } else { return 'closure'; } } /** * Registers object to be used in templates * NOTE: this method can be safely removed for dynamic loading * * @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()) { /* @var Smarty $smarty */ $smarty = isset($this->smarty) ? $this->smarty : $this; // test if allowed methods callable if (!empty($allowed_methods_properties)) { foreach ((array) $allowed_methods_properties as $method) { if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { throw new SmartyException("Undefined method or property '$method' in registered object"); } } } // test if block methods callable if (!empty($block_methods)) { foreach ((array) $block_methods as $method) { if (!is_callable(array($object, $method))) { throw new SmartyException("Undefined method '$method' in registered object"); } } } // register the object $smarty->registered_objects[$object_name] = array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods); return $this; } /** * test if cache is valid * * @api Smarty::isCached() * @link http://www.smarty.net/docs/en/api.is.cached.tpl * * @param 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) { if ($template === null && $this instanceof $this->template_class) { $template = $this; } else { if (!($template instanceof $this->template_class)) { if ($parent === null) { $parent = $this; } /* @var Smarty $smarty */ $smarty = isset($this->smarty) ? $this->smarty : $this; $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); } } // return cache status of template if (!isset($template->cached)) { $template->loadCached(); } return $template->cached->isCached($template); } /** * @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; } }