/** * 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; }
/** * Register template functions defined by template * * @param \Smarty|\Smarty_Internal_Template|\Smarty_Internal_TemplateBase $obj * @param array $tplFunctions source information array of template functions defined in template * @param bool $override if true replace existing functions with same name */ public function registerTplFunctions(Smarty_Internal_TemplateBase $obj, $tplFunctions, $override = true) { $obj->tplFunctions = $override ? array_merge($obj->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->tplFunctions); // make sure that the template functions are known in parent templates if ($obj->_isSubTpl()) { $obj->smarty->ext->_tplFunction->registerTplFunctions($obj->parent, $tplFunctions, false); } else { $obj->smarty->tplFunctions = $override ? array_merge($obj->smarty->tplFunctions, $tplFunctions) : array_merge($tplFunctions, $obj->smarty->tplFunctions); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 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; }
/** * Compiles the given snippet block if the content parameter is filled. * @param $params * @param $content * @param Smarty_Internal_TemplateBase $template * @return string */ public static function compileSnippetBlock($params, $content, Smarty_Internal_TemplateBase $template = null) { if ($content === null) { return ''; } if (!empty($params['tag']) && !empty($params['namespace'])) { if (!empty($params['class'])) { $params['class'] .= ' ' . str_replace('/', '_', $params['namespace']); } else { $params['class'] = str_replace('/', '_', $params['namespace']); } } if (!empty($params['tag'])) { $params['tag'] = strtolower($params['tag']); $attr = ''; foreach ($params as $key => $param) { if (in_array($key, array('name', 'tag', 'assign', 'name', 'namespace', 'default', 'force'))) { continue; } $attr .= ' ' . $key . '="' . htmlentities($param, ENT_COMPAT, mb_internal_encoding(), false) . '"'; } $content = htmlentities($content, ENT_COMPAT, mb_internal_encoding(), false); $content = "<{$params['tag']}{$attr}>" . $content . "</{$params['tag']}>"; } if (isset($params['assign'])) { if ($template !== null) { $template->assign($params['assign'], $content); } return ''; } else { return $content; } }
/** * 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; }
/** * Handle unknown class methods * * @param string $name unknown method-name * @param array $args argument array * * @return mixed * @throws SmartyException */ public function __call($name, $args) { // method of Smarty object? if (method_exists($this->smarty, $name)) { return call_user_func_array([$this->smarty, $name], $args); } // parent return parent::__call($name, $args); }
/** * Initialize new Smarty object */ public function __construct() { parent::__construct(); if (is_callable('mb_internal_encoding')) { mb_internal_encoding(Smarty::$_CHARSET); } $this->start_time = microtime(true); if (isset($_SERVER['SCRIPT_NAME'])) { Smarty::$global_tpl_vars['SCRIPT_NAME'] = new Smarty_Variable($_SERVER['SCRIPT_NAME']); } // Check if we're running on windows Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'; // let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8 if (Smarty::$_CHARSET !== 'UTF-8') { Smarty::$_UTF8_MODIFIER = ''; } }
/** * 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; }
/** * 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; }