/** * Return array of tag/attributes of all tags used by an template * * @api Smarty::getTags() * @link http://www.smarty.net/docs/en/api.get.tags.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param null|string|Smarty_Internal_Template $template * * @return array of tag/attributes * @throws \SmartyException */ public function getTags(Smarty_Internal_TemplateBase $obj, $template = null) { /* @var Smarty $smarty */ $smarty = $obj->_getSmartyObj(); if ($obj->_isTplObj() && !isset($template)) { $tpl = clone $obj; } elseif (isset($template) && $template->_isTplObj()) { $tpl = clone $template; } elseif (isset($template) && is_string($template)) { /* @var Smarty_Internal_Template $tpl */ $tpl = new $smarty->template_class($template, $smarty); // checks if template exists if (!$tpl->source->exists) { throw new SmartyException("Unable to load template {$tpl->source->type} '{$tpl->source->name}'"); } } if (isset($tpl)) { $tpl->smarty = clone $tpl->smarty; $tpl->smarty->_cache['get_used_tags'] = true; $tpl->_cache['used_tags'] = array(); $tpl->smarty->merge_compiled_includes = false; $tpl->smarty->disableSecurity(); $tpl->caching = false; $tpl->loadCompiler(); $tpl->compiler->compileTemplate($tpl); return $tpl->_cache['used_tags']; } throw new SmartyException("Missing template specification"); }
/** * Registers a resource to fetch a template * * @api Smarty::unregisterCacheResource() * @link http://www.smarty.net/docs/en/api.unregister.cacheresource.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param $name * * @return \Smarty|\Smarty_Internal_Template */ public function unregisterCacheResource(Smarty_Internal_TemplateBase $obj, $name) { $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_cache_resources[$name])) { unset($smarty->registered_cache_resources[$name]); } return $obj; }
/** * Registers plugin to be used in templates * * @api Smarty::unregisterPlugin() * @link http://www.smarty.net/docs/en/api.unregister.plugin.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $type plugin type * @param string $name name of template tag * * @return \Smarty|\Smarty_Internal_Template */ public function unregisterPlugin(Smarty_Internal_TemplateBase $obj, $type, $name) { $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_plugins[$type][$name])) { unset($smarty->registered_plugins[$type][$name]); } return $obj; }
/** * Registers plugin to be used in templates * * @api Smarty::unregisterObject() * @link http://www.smarty.net/docs/en/api.unregister.object.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $object_name name of object * * @return \Smarty|\Smarty_Internal_Template */ public function unregisterObject(Smarty_Internal_TemplateBase $obj, $object_name) { $smarty = $obj->_getSmartyObj(); if (isset($smarty->registered_objects[$object_name])) { unset($smarty->registered_objects[$object_name]); } return $obj; }
/** * set the debug template * * @api Smarty::setDebugTemplate() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $tpl_name * * @return \Smarty|\Smarty_Internal_Template * @throws SmartyException if file is not readable */ public function setDebugTemplate(Smarty_Internal_TemplateBase $obj, $tpl_name) { $smarty = $obj->_getSmartyObj(); if (!is_readable($tpl_name)) { throw new SmartyException("Unknown file '{$tpl_name}'"); } $smarty->debug_tpl = $tpl_name; return $obj; }
/** * Get autoload filters * * @api Smarty::getAutoloadFilters() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $type type of filter to get auto loads * for. Defaults to all autoload * filters * * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type * was specified */ public function getAutoloadFilters(Smarty_Internal_TemplateBase $obj, $type = null) { $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); return isset($smarty->autoload_filters[$type]) ? $smarty->autoload_filters[$type] : array(); } return $smarty->autoload_filters; }
/** * Add default modifiers * * @api Smarty::addDefaultModifiers() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param array|string $modifiers modifier or list of modifiers * to add * * @return \Smarty|\Smarty_Internal_Template */ public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers) { $smarty = $obj->_getSmartyObj(); if (is_array($modifiers)) { $smarty->default_modifiers = array_merge($smarty->default_modifiers, $modifiers); } else { $smarty->default_modifiers[] = $modifiers; } return $obj; }
/** * Registers a default plugin handler * * @api Smarty::registerDefaultPluginHandler() * @link http://www.smarty.net/docs/en/api.register.default.plugin.handler.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param callable $callback class/method name * * @return \Smarty|\Smarty_Internal_Template * @throws SmartyException if $callback is not callable */ public function registerDefaultPluginHandler(Smarty_Internal_TemplateBase $obj, $callback) { $smarty = $obj->_getSmartyObj(); if (is_callable($callback)) { $smarty->default_plugin_handler_func = $callback; } else { throw new SmartyException("Default plugin handler '{$callback}' not callable"); } return $obj; }
/** * creates a data object * * @api Smarty::createData() * @link http://www.smarty.net/docs/en/api.create.data.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param \Smarty_Internal_Template|\Smarty_Internal_Data|\Smarty_Data|\Smarty $parent next higher level of Smarty * variables * @param string $name optional data block name * * @returns Smarty_Data data object */ public function createData(Smarty_Internal_TemplateBase $obj, Smarty_Internal_Data $parent = null, $name = null) { /* @var Smarty $smarty */ $smarty = $obj->_getSmartyObj(); $dataObj = new Smarty_Data($parent, $smarty, $name); if ($smarty->debugging) { Smarty_Internal_Debug::register_data($dataObj); } return $dataObj; }
/** * return a reference to a registered object * * @api Smarty::getRegisteredObject() * @link http://www.smarty.net/docs/en/api.get.registered.object.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $object_name object name * * @return object * @throws \SmartyException if no such object is found */ public function getRegisteredObject(Smarty_Internal_TemplateBase $obj, $object_name) { $smarty = $obj->_getSmartyObj(); if (!isset($smarty->registered_objects[$object_name])) { throw new SmartyException("'{$object_name}' is not a registered object"); } if (!is_object($smarty->registered_objects[$object_name][0])) { throw new SmartyException("registered '{$object_name}' is not an object"); } return $smarty->registered_objects[$object_name][0]; }
/** * Registers static classes to be used in templates * * @api Smarty::registerClass() * @link http://www.smarty.net/docs/en/api.register.class.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $class_name * @param string $class_impl the referenced PHP class to * register * * @return \Smarty|\Smarty_Internal_Template * @throws \SmartyException */ public function registerClass(Smarty_Internal_TemplateBase $obj, $class_name, $class_impl) { $smarty = $obj->_getSmartyObj(); // test if exists if (!class_exists($class_impl)) { throw new SmartyException("Undefined class '{$class_impl}' in register template class"); } // register the class $smarty->registered_classes[$class_name] = $class_impl; return $obj; }
/** * Registers a filter function * * @api Smarty::registerFilter() * * @link http://www.smarty.net/docs/en/api.register.filter.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @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(Smarty_Internal_TemplateBase $obj, $type, $callback, $name = null) { $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($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 $obj; }
/** * Registers plugin to be used in templates * * @api Smarty::registerPlugin() * @link http://www.smarty.net/docs/en/api.register.plugin.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @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(Smarty_Internal_TemplateBase $obj, $type, $name, $callback, $cacheable = true, $cache_attr = null) { $smarty = $obj->_getSmartyObj(); 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 $obj; }
/** * Set autoload filters * * @api Smarty::setAutoloadFilters() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param array $filters filters to load automatically * @param string $type "pre", "output", … specify the * filter type to set. Defaults to * none treating $filters' keys as * the appropriate types * * @return \Smarty|\Smarty_Internal_Template */ public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) { $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); $smarty->autoload_filters[$type] = (array) $filters; } else { foreach ((array) $filters as $type => $value) { $this->_checkFilterType($type); } $smarty->autoload_filters = (array) $filters; } return $obj; }
/** * load a filter of specified type and name * * @api Smarty::unloadFilter() * * @link http://www.smarty.net/docs/en/api.unload.filter.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $type filter type * @param string $name filter name * * @return bool */ public function unloadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) { $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); if (isset($smarty->registered_filters[$type])) { $_filter_name = "smarty_{$type}filter_{$name}"; if (isset($smarty->registered_filters[$type][$_filter_name])) { unset($smarty->registered_filters[$type][$_filter_name]); if (empty($smarty->registered_filters[$type])) { unset($smarty->registered_filters[$type]); } } } return $obj; }
/** * Unregisters a filter function * * @api Smarty::unregisterFilter() * * @link http://www.smarty.net/docs/en/api.unregister.filter.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $type filter type * @param callback|string $callback * * @return \Smarty|\Smarty_Internal_Template */ public function unregisterFilter(Smarty_Internal_TemplateBase $obj, $type, $callback) { $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($type); if (isset($smarty->registered_filters[$type])) { $name = is_string($callback) ? $callback : $this->_getFilterName($callback); if (isset($smarty->registered_filters[$type][$name])) { unset($smarty->registered_filters[$type][$name]); if (empty($smarty->registered_filters[$type])) { unset($smarty->registered_filters[$type]); } } } return $obj; }
/** * load a filter of specified type and name * * @api Smarty::loadFilter() * * @link http://www.smarty.net/docs/en/api.load.filter.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $type filter type * @param string $name filter name * * @return bool * @throws SmartyException if filter could not be loaded */ public function loadFilter(Smarty_Internal_TemplateBase $obj, $type, $name) { $smarty = $obj->_getSmartyObj(); $this->_checkFilterType($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"); }
/** * Add autoload filters * * @api Smarty::setAutoloadFilters() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param array $filters filters to load automatically * @param string $type "pre", "output", … specify the * filter type to set. Defaults to * none treating $filters' keys as * the appropriate types * * @return \Smarty|\Smarty_Internal_Template */ public function addAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null) { $smarty = $obj->_getSmartyObj(); if ($type !== null) { $this->_checkFilterType($type); if (!empty($smarty->autoload_filters[$type])) { $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $filters); } else { $smarty->autoload_filters[$type] = (array) $filters; } } else { foreach ((array) $filters as $type => $value) { $this->_checkFilterType($type); if (!empty($smarty->autoload_filters[$type])) { $smarty->autoload_filters[$type] = array_merge($smarty->autoload_filters[$type], (array) $value); } else { $smarty->autoload_filters[$type] = (array) $value; } } } return $obj; }
/** * Registers object to be used in templates * * @api Smarty::registerObject() * @link http://www.smarty.net/docs/en/api.register.object.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @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(Smarty_Internal_TemplateBase $obj, $object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array()) { $smarty = $obj->_getSmartyObj(); // 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, (bool) $format, (array) $block_methods); return $obj; }
/** * Registers a resource to fetch a template * * @api Smarty::registerCacheResource() * @link http://www.smarty.net/docs/en/api.register.cacheresource.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $name name of resource type * @param \Smarty_CacheResource $resource_handler * * @return \Smarty|\Smarty_Internal_Template */ public function registerCacheResource(Smarty_Internal_TemplateBase $obj, $name, Smarty_CacheResource $resource_handler) { $smarty = $obj->_getSmartyObj(); $smarty->registered_cache_resources[$name] = $resource_handler; return $obj; }
/** * Get default modifiers * * @api Smarty::getDefaultModifiers() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * * @return array list of default modifiers */ public function getDefaultModifiers(Smarty_Internal_TemplateBase $obj) { $smarty = $obj->_getSmartyObj(); return $smarty->default_modifiers; }
/** * Set default modifiers * * @api Smarty::setDefaultModifiers() * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param array|string $modifiers modifier or list of modifiers * to set * * @return \Smarty|\Smarty_Internal_Template */ public function setDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers) { $smarty = $obj->_getSmartyObj(); $smarty->default_modifiers = (array) $modifiers; return $obj; }
/** * Registers a resource to fetch a template * * @api Smarty::registerResource() * @link http://www.smarty.net/docs/en/api.register.resource.tpl * * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj * @param string $name name of resource type * @param Smarty_Resource|array $resource_handler or instance of * Smarty_Resource, or * array of callbacks to * handle resource * (deprecated) * * @return \Smarty|\Smarty_Internal_Template */ public function registerResource(Smarty_Internal_TemplateBase $obj, $name, $resource_handler) { $smarty = $obj->_getSmartyObj(); $smarty->registered_resources[$name] = $resource_handler instanceof Smarty_Resource ? $resource_handler : array($resource_handler, false); return $obj; }