From 61ca0d0c6c7ce19be0164fc77ee68d158c9ad8f7 Mon Sep 17 00:00:00 2001 From: rvelices Date: Sun, 23 Jun 2013 19:25:17 +0000 Subject: Smarty EOL style LF svn property git-svn-id: http://piwigo.org/svn/trunk@23485 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/smarty/libs/SmartyBC.class.php | 918 +++++------ .../smarty/libs/plugins/modifiercompiler.cat.php | 58 +- .../plugins/modifiercompiler.count_characters.php | 64 +- .../plugins/modifiercompiler.count_paragraphs.php | 54 +- .../plugins/modifiercompiler.count_sentences.php | 54 +- .../libs/plugins/modifiercompiler.count_words.php | 62 +- .../libs/plugins/modifiercompiler.default.php | 68 +- .../libs/plugins/modifiercompiler.escape.php | 248 +-- .../libs/plugins/modifiercompiler.from_charset.php | 66 +- .../libs/plugins/modifiercompiler.indent.php | 62 +- .../smarty/libs/plugins/modifiercompiler.lower.php | 60 +- .../libs/plugins/modifiercompiler.noprint.php | 48 +- .../plugins/modifiercompiler.string_format.php | 50 +- .../smarty/libs/plugins/modifiercompiler.strip.php | 64 +- .../libs/plugins/modifiercompiler.strip_tags.php | 64 +- .../libs/plugins/modifiercompiler.to_charset.php | 66 +- .../libs/plugins/modifiercompiler.unescape.php | 100 +- .../smarty/libs/plugins/modifiercompiler.upper.php | 58 +- .../libs/plugins/modifiercompiler.wordwrap.php | 90 +- .../sysplugins/smarty_internal_compile_break.php | 152 +- .../smarty_internal_compile_continue.php | 154 +- .../smarty_internal_compile_private_modifier.php | 278 ++-- ...y_internal_compile_private_registered_block.php | 224 +-- ...nternal_compile_private_registered_function.php | 160 +- .../smarty_internal_compile_setfilter.php | 142 +- .../smarty_internal_function_call_handler.php | 110 +- .../smarty_internal_get_include_path.php | 94 +- .../sysplugins/smarty_internal_nocache_insert.php | 106 +- .../libs/sysplugins/smarty_internal_parsetree.php | 788 +++++----- .../sysplugins/smarty_internal_resource_eval.php | 186 +-- .../sysplugins/smarty_internal_templatebase.php | 1620 ++++++++++---------- .../smarty_internal_templatecompilerbase.php | 1338 ++++++++-------- 32 files changed, 3803 insertions(+), 3803 deletions(-) (limited to 'include/smarty') diff --git a/include/smarty/libs/SmartyBC.class.php b/include/smarty/libs/SmartyBC.class.php index f8f0a138f..589dcca27 100644 --- a/include/smarty/libs/SmartyBC.class.php +++ b/include/smarty/libs/SmartyBC.class.php @@ -1,460 +1,460 @@ - - * @author Uwe Tews - * @author Rodney Rehm - * @package Smarty - */ -/** - * @ignore - */ -require(dirname(__FILE__) . '/Smarty.class.php'); - -/** - * Smarty Backward Compatability Wrapper Class - * - * @package Smarty - */ -class SmartyBC extends Smarty { - - /** - * Smarty 2 BC - * @var string - */ - public $_version = self::SMARTY_VERSION; - - /** - * Initialize new SmartyBC object - * - * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) - */ - public function __construct(array $options=array()) - { - parent::__construct($options); - // register {php} tag - $this->registerPlugin('block', 'php', 'smarty_php_tag'); - } - - /** - * wrapper for assign_by_ref - * - * @param string $tpl_var the template variable name - * @param mixed &$value the referenced value to assign - */ - public function assign_by_ref($tpl_var, &$value) - { - $this->assignByRef($tpl_var, $value); - } - - /** - * wrapper for append_by_ref - * - * @param string $tpl_var the template variable name - * @param mixed &$value the referenced value to append - * @param boolean $merge flag if array elements shall be merged - */ - public function append_by_ref($tpl_var, &$value, $merge = false) - { - $this->appendByRef($tpl_var, $value, $merge); - } - - /** - * clear the given assigned template variable. - * - * @param string $tpl_var the template variable to clear - */ - public function clear_assign($tpl_var) - { - $this->clearAssign($tpl_var); - } - - /** - * Registers custom function to be used in templates - * - * @param string $function the name of the template function - * @param string $function_impl the name of the PHP function to register - * @param bool $cacheable - * @param mixed $cache_attrs - */ - public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) - { - $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); - } - - /** - * Unregisters custom function - * - * @param string $function name of template function - */ - public function unregister_function($function) - { - $this->unregisterPlugin('function', $function); - } - - /** - * Registers object to be used in templates - * - * @param string $object name of template object - * @param object $object_impl the referenced PHP object to register - * @param array $allowed list of allowed methods (empty = all) - * @param boolean $smarty_args smarty argument format, else traditional - * @param array $block_functs list of methods that are block format - */ - public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) - { - settype($allowed, 'array'); - settype($smarty_args, 'boolean'); - $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); - } - - /** - * Unregisters object - * - * @param string $object name of template object - */ - public function unregister_object($object) - { - $this->unregisterObject($object); - } - - /** - * Registers block function to be used in templates - * - * @param string $block name of template block - * @param string $block_impl PHP function to register - * @param bool $cacheable - * @param mixed $cache_attrs - */ - public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) - { - $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); - } - - /** - * Unregisters block function - * - * @param string $block name of template function - */ - public function unregister_block($block) - { - $this->unregisterPlugin('block', $block); - } - - /** - * Registers compiler function - * - * @param string $function name of template function - * @param string $function_impl name of PHP function to register - * @param bool $cacheable - */ - public function register_compiler_function($function, $function_impl, $cacheable=true) - { - $this->registerPlugin('compiler', $function, $function_impl, $cacheable); - } - - /** - * Unregisters compiler function - * - * @param string $function name of template function - */ - public function unregister_compiler_function($function) - { - $this->unregisterPlugin('compiler', $function); - } - - /** - * Registers modifier to be used in templates - * - * @param string $modifier name of template modifier - * @param string $modifier_impl name of PHP function to register - */ - public function register_modifier($modifier, $modifier_impl) - { - $this->registerPlugin('modifier', $modifier, $modifier_impl); - } - - /** - * Unregisters modifier - * - * @param string $modifier name of template modifier - */ - public function unregister_modifier($modifier) - { - $this->unregisterPlugin('modifier', $modifier); - } - - /** - * Registers a resource to fetch a template - * - * @param string $type name of resource - * @param array $functions array of functions to handle resource - */ - public function register_resource($type, $functions) - { - $this->registerResource($type, $functions); - } - - /** - * Unregisters a resource - * - * @param string $type name of resource - */ - public function unregister_resource($type) - { - $this->unregisterResource($type); - } - - /** - * Registers a prefilter function to apply - * to a template before compiling - * - * @param callable $function - */ - public function register_prefilter($function) - { - $this->registerFilter('pre', $function); - } - - /** - * Unregisters a prefilter function - * - * @param callable $function - */ - public function unregister_prefilter($function) - { - $this->unregisterFilter('pre', $function); - } - - /** - * Registers a postfilter function to apply - * to a compiled template after compilation - * - * @param callable $function - */ - public function register_postfilter($function) - { - $this->registerFilter('post', $function); - } - - /** - * Unregisters a postfilter function - * - * @param callable $function - */ - public function unregister_postfilter($function) - { - $this->unregisterFilter('post', $function); - } - - /** - * Registers an output filter function to apply - * to a template output - * - * @param callable $function - */ - public function register_outputfilter($function) - { - $this->registerFilter('output', $function); - } - - /** - * Unregisters an outputfilter function - * - * @param callable $function - */ - public function unregister_outputfilter($function) - { - $this->unregisterFilter('output', $function); - } - - /** - * load a filter of specified type and name - * - * @param string $type filter type - * @param string $name filter name - */ - public function load_filter($type, $name) - { - $this->loadFilter($type, $name); - } - - /** - * clear cached content for the given template and cache id - * - * @param string $tpl_file name of template file - * @param string $cache_id name of cache_id - * @param string $compile_id name of compile_id - * @param string $exp_time expiration time - * @return boolean - */ - public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) - { - return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); - } - - /** - * clear the entire contents of cache (all templates) - * - * @param string $exp_time expire time - * @return boolean - */ - public function clear_all_cache($exp_time = null) - { - return $this->clearCache(null, null, null, $exp_time); - } - - /** - * test to see if valid cache exists for this template - * - * @param string $tpl_file name of template file - * @param string $cache_id - * @param string $compile_id - * @return boolean - */ - public function is_cached($tpl_file, $cache_id = null, $compile_id = null) - { - return $this->isCached($tpl_file, $cache_id, $compile_id); - } - - /** - * clear all the assigned template variables. - */ - public function clear_all_assign() - { - $this->clearAllAssign(); - } - - /** - * clears compiled version of specified template resource, - * or all compiled template files if one is not specified. - * This function is for advanced use only, not normally needed. - * - * @param string $tpl_file - * @param string $compile_id - * @param string $exp_time - * @return boolean results of {@link smarty_core_rm_auto()} - */ - public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) - { - return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); - } - - /** - * Checks whether requested template exists. - * - * @param string $tpl_file - * @return boolean - */ - public function template_exists($tpl_file) - { - return $this->templateExists($tpl_file); - } - - /** - * Returns an array containing template variables - * - * @param string $name - * @return array - */ - public function get_template_vars($name=null) - { - return $this->getTemplateVars($name); - } - - /** - * Returns an array containing config variables - * - * @param string $name - * @return array - */ - public function get_config_vars($name=null) - { - return $this->getConfigVars($name); - } - - /** - * load configuration values - * - * @param string $file - * @param string $section - * @param string $scope - */ - public function config_load($file, $section = null, $scope = 'global') - { - $this->ConfigLoad($file, $section, $scope); - } - - /** - * return a reference to a registered object - * - * @param string $name - * @return object - */ - public function get_registered_object($name) - { - return $this->getRegisteredObject($name); - } - - /** - * clear configuration values - * - * @param string $var - */ - public function clear_config($var = null) - { - $this->clearConfig($var); - } - - /** - * trigger Smarty error - * - * @param string $error_msg - * @param integer $error_type - */ - public function trigger_error($error_msg, $error_type = E_USER_WARNING) - { - trigger_error("Smarty error: $error_msg", $error_type); - } - -} - -/** - * Smarty {php}{/php} block function - * - * @param array $params parameter list - * @param string $content contents of the block - * @param object $template template object - * @param boolean &$repeat repeat flag - * @return string content re-formatted - */ -function smarty_php_tag($params, $content, $template, &$repeat) -{ - eval($content); - return ''; -} - + + * @author Uwe Tews + * @author Rodney Rehm + * @package Smarty + */ +/** + * @ignore + */ +require(dirname(__FILE__) . '/Smarty.class.php'); + +/** + * Smarty Backward Compatability Wrapper Class + * + * @package Smarty + */ +class SmartyBC extends Smarty { + + /** + * Smarty 2 BC + * @var string + */ + public $_version = self::SMARTY_VERSION; + + /** + * Initialize new SmartyBC object + * + * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) + */ + public function __construct(array $options=array()) + { + parent::__construct($options); + // register {php} tag + $this->registerPlugin('block', 'php', 'smarty_php_tag'); + } + + /** + * wrapper for assign_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to assign + */ + public function assign_by_ref($tpl_var, &$value) + { + $this->assignByRef($tpl_var, $value); + } + + /** + * wrapper for append_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to append + * @param boolean $merge flag if array elements shall be merged + */ + public function append_by_ref($tpl_var, &$value, $merge = false) + { + $this->appendByRef($tpl_var, $value, $merge); + } + + /** + * clear the given assigned template variable. + * + * @param string $tpl_var the template variable to clear + */ + public function clear_assign($tpl_var) + { + $this->clearAssign($tpl_var); + } + + /** + * Registers custom function to be used in templates + * + * @param string $function the name of the template function + * @param string $function_impl the name of the PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters custom function + * + * @param string $function name of template function + */ + public function unregister_function($function) + { + $this->unregisterPlugin('function', $function); + } + + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object $object_impl the referenced PHP object to register + * @param array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param array $block_functs list of methods that are block format + */ + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + settype($allowed, 'array'); + settype($smarty_args, 'boolean'); + $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); + } + + /** + * Unregisters object + * + * @param string $object name of template object + */ + public function unregister_object($object) + { + $this->unregisterObject($object); + } + + /** + * Registers block function to be used in templates + * + * @param string $block name of template block + * @param string $block_impl PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters block function + * + * @param string $block name of template function + */ + public function unregister_block($block) + { + $this->unregisterPlugin('block', $block); + } + + /** + * Registers compiler function + * + * @param string $function name of template function + * @param string $function_impl name of PHP function to register + * @param bool $cacheable + */ + public function register_compiler_function($function, $function_impl, $cacheable=true) + { + $this->registerPlugin('compiler', $function, $function_impl, $cacheable); + } + + /** + * Unregisters compiler function + * + * @param string $function name of template function + */ + public function unregister_compiler_function($function) + { + $this->unregisterPlugin('compiler', $function); + } + + /** + * Registers modifier to be used in templates + * + * @param string $modifier name of template modifier + * @param string $modifier_impl name of PHP function to register + */ + public function register_modifier($modifier, $modifier_impl) + { + $this->registerPlugin('modifier', $modifier, $modifier_impl); + } + + /** + * Unregisters modifier + * + * @param string $modifier name of template modifier + */ + public function unregister_modifier($modifier) + { + $this->unregisterPlugin('modifier', $modifier); + } + + /** + * Registers a resource to fetch a template + * + * @param string $type name of resource + * @param array $functions array of functions to handle resource + */ + public function register_resource($type, $functions) + { + $this->registerResource($type, $functions); + } + + /** + * Unregisters a resource + * + * @param string $type name of resource + */ + public function unregister_resource($type) + { + $this->unregisterResource($type); + } + + /** + * Registers a prefilter function to apply + * to a template before compiling + * + * @param callable $function + */ + public function register_prefilter($function) + { + $this->registerFilter('pre', $function); + } + + /** + * Unregisters a prefilter function + * + * @param callable $function + */ + public function unregister_prefilter($function) + { + $this->unregisterFilter('pre', $function); + } + + /** + * Registers a postfilter function to apply + * to a compiled template after compilation + * + * @param callable $function + */ + public function register_postfilter($function) + { + $this->registerFilter('post', $function); + } + + /** + * Unregisters a postfilter function + * + * @param callable $function + */ + public function unregister_postfilter($function) + { + $this->unregisterFilter('post', $function); + } + + /** + * Registers an output filter function to apply + * to a template output + * + * @param callable $function + */ + public function register_outputfilter($function) + { + $this->registerFilter('output', $function); + } + + /** + * Unregisters an outputfilter function + * + * @param callable $function + */ + public function unregister_outputfilter($function) + { + $this->unregisterFilter('output', $function); + } + + /** + * load a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + */ + public function load_filter($type, $name) + { + $this->loadFilter($type, $name); + } + + /** + * clear cached content for the given template and cache id + * + * @param string $tpl_file name of template file + * @param string $cache_id name of cache_id + * @param string $compile_id name of compile_id + * @param string $exp_time expiration time + * @return boolean + */ + public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) + { + return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); + } + + /** + * clear the entire contents of cache (all templates) + * + * @param string $exp_time expire time + * @return boolean + */ + public function clear_all_cache($exp_time = null) + { + return $this->clearCache(null, null, null, $exp_time); + } + + /** + * test to see if valid cache exists for this template + * + * @param string $tpl_file name of template file + * @param string $cache_id + * @param string $compile_id + * @return boolean + */ + public function is_cached($tpl_file, $cache_id = null, $compile_id = null) + { + return $this->isCached($tpl_file, $cache_id, $compile_id); + } + + /** + * clear all the assigned template variables. + */ + public function clear_all_assign() + { + $this->clearAllAssign(); + } + + /** + * clears compiled version of specified template resource, + * or all compiled template files if one is not specified. + * This function is for advanced use only, not normally needed. + * + * @param string $tpl_file + * @param string $compile_id + * @param string $exp_time + * @return boolean results of {@link smarty_core_rm_auto()} + */ + public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) + { + return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); + } + + /** + * Checks whether requested template exists. + * + * @param string $tpl_file + * @return boolean + */ + public function template_exists($tpl_file) + { + return $this->templateExists($tpl_file); + } + + /** + * Returns an array containing template variables + * + * @param string $name + * @return array + */ + public function get_template_vars($name=null) + { + return $this->getTemplateVars($name); + } + + /** + * Returns an array containing config variables + * + * @param string $name + * @return array + */ + public function get_config_vars($name=null) + { + return $this->getConfigVars($name); + } + + /** + * load configuration values + * + * @param string $file + * @param string $section + * @param string $scope + */ + public function config_load($file, $section = null, $scope = 'global') + { + $this->ConfigLoad($file, $section, $scope); + } + + /** + * return a reference to a registered object + * + * @param string $name + * @return object + */ + public function get_registered_object($name) + { + return $this->getRegisteredObject($name); + } + + /** + * clear configuration values + * + * @param string $var + */ + public function clear_config($var = null) + { + $this->clearConfig($var); + } + + /** + * trigger Smarty error + * + * @param string $error_msg + * @param integer $error_type + */ + public function trigger_error($error_msg, $error_type = E_USER_WARNING) + { + trigger_error("Smarty error: $error_msg", $error_type); + } + +} + +/** + * Smarty {php}{/php} block function + * + * @param array $params parameter list + * @param string $content contents of the block + * @param object $template template object + * @param boolean &$repeat repeat flag + * @return string content re-formatted + */ +function smarty_php_tag($params, $content, $template, &$repeat) +{ + eval($content); + return ''; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.cat.php b/include/smarty/libs/plugins/modifiercompiler.cat.php index 1cfe6308a..5049c63e5 100644 --- a/include/smarty/libs/plugins/modifiercompiler.cat.php +++ b/include/smarty/libs/plugins/modifiercompiler.cat.php @@ -1,30 +1,30 @@ - - * Name: cat
- * Date: Feb 24, 2003
- * Purpose: catenate a value to a variable
- * Input: string to catenate
- * Example: {$var|cat:"foo"} - * - * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat - * (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_cat($params, $compiler) -{ - return '('.implode(').(', $params).')'; -} - + + * Name: cat
+ * Date: Feb 24, 2003
+ * Purpose: catenate a value to a variable
+ * Input: string to catenate
+ * Example: {$var|cat:"foo"} + * + * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat + * (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_cat($params, $compiler) +{ + return '('.implode(').(', $params).')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.count_characters.php b/include/smarty/libs/plugins/modifiercompiler.count_characters.php index 98e8efa0d..0f269c9fa 100644 --- a/include/smarty/libs/plugins/modifiercompiler.count_characters.php +++ b/include/smarty/libs/plugins/modifiercompiler.count_characters.php @@ -1,33 +1,33 @@ - - * Name: count_characteres
- * Purpose: count the number of characters in a text - * - * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_count_characters($params, $compiler) -{ - if (!isset($params[1]) || $params[1] != 'true') { - return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)'; - } - if (Smarty::$_MBSTRING) { - return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; - } - // no MBString fallback - return 'strlen(' . $params[0] . ')'; -} - + + * Name: count_characteres
+ * Purpose: count the number of characters in a text + * + * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_count_characters($params, $compiler) +{ + if (!isset($params[1]) || $params[1] != 'true') { + return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)'; + } + if (Smarty::$_MBSTRING) { + return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')'; + } + // no MBString fallback + return 'strlen(' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php b/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php index 0e1b0af83..853f98f46 100644 --- a/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php +++ b/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php @@ -1,28 +1,28 @@ - - * Name: count_paragraphs
- * Purpose: count the number of paragraphs in a text - * - * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php - * count_paragraphs (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_count_paragraphs($params, $compiler) -{ - // count \r or \n characters - return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)'; -} - + + * Name: count_paragraphs
+ * Purpose: count the number of paragraphs in a text + * + * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php + * count_paragraphs (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_count_paragraphs($params, $compiler) +{ + // count \r or \n characters + return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.count_sentences.php b/include/smarty/libs/plugins/modifiercompiler.count_sentences.php index 2f517be96..f8d79b3f2 100644 --- a/include/smarty/libs/plugins/modifiercompiler.count_sentences.php +++ b/include/smarty/libs/plugins/modifiercompiler.count_sentences.php @@ -1,28 +1,28 @@ - - * Name: count_sentences - * Purpose: count the number of sentences in a text - * - * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php - * count_sentences (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_count_sentences($params, $compiler) -{ - // find periods, question marks, exclamation marks with a word before but not after. - return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)'; -} - + + * Name: count_sentences + * Purpose: count the number of sentences in a text + * + * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php + * count_sentences (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_count_sentences($params, $compiler) +{ + // find periods, question marks, exclamation marks with a word before but not after. + return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.count_words.php b/include/smarty/libs/plugins/modifiercompiler.count_words.php index e05738c01..f53443e24 100644 --- a/include/smarty/libs/plugins/modifiercompiler.count_words.php +++ b/include/smarty/libs/plugins/modifiercompiler.count_words.php @@ -1,32 +1,32 @@ - - * Name: count_words
- * Purpose: count the number of words in a text - * - * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code -*/ -function smarty_modifiercompiler_count_words($params, $compiler) -{ - if (Smarty::$_MBSTRING) { - // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; - // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 - return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; - } - // no MBString fallback - return 'str_word_count(' . $params[0] . ')'; -} - + + * Name: count_words
+ * Purpose: count the number of words in a text + * + * @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code +*/ +function smarty_modifiercompiler_count_words($params, $compiler) +{ + if (Smarty::$_MBSTRING) { + // return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; + // expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592 + return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)'; + } + // no MBString fallback + return 'str_word_count(' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.default.php b/include/smarty/libs/plugins/modifiercompiler.default.php index 4f831a589..3554964e4 100644 --- a/include/smarty/libs/plugins/modifiercompiler.default.php +++ b/include/smarty/libs/plugins/modifiercompiler.default.php @@ -1,35 +1,35 @@ - - * Name: default
- * Purpose: designate default value for empty variables - * - * @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_default ($params, $compiler) -{ - $output = $params[0]; - if (!isset($params[1])) { - $params[1] = "''"; - } - - array_shift($params); - foreach ($params as $param) { - $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; - } - return $output; -} - + + * Name: default
+ * Purpose: designate default value for empty variables + * + * @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_default ($params, $compiler) +{ + $output = $params[0]; + if (!isset($params[1])) { + $params[1] = "''"; + } + + array_shift($params); + foreach ($params as $param) { + $output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)'; + } + return $output; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.escape.php b/include/smarty/libs/plugins/modifiercompiler.escape.php index f50028bd9..d38d12975 100644 --- a/include/smarty/libs/plugins/modifiercompiler.escape.php +++ b/include/smarty/libs/plugins/modifiercompiler.escape.php @@ -1,125 +1,125 @@ - - * Name: escape
- * Purpose: escape string for output - * - * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) - * @author Rodney Rehm - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_escape($params, $compiler) -{ - static $_double_encode = null; - if ($_double_encode === null) { - $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); - } - - try { - $esc_type = smarty_literal_compiler_param($params, 1, 'html'); - $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); - $double_encode = smarty_literal_compiler_param($params, 3, true); - - if (!$char_set) { - $char_set = Smarty::$_CHARSET; - } - - switch ($esc_type) { - case 'html': - if ($_double_encode) { - return 'htmlspecialchars(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) . ', ' - . var_export($double_encode, true) . ')'; - } else if ($double_encode) { - return 'htmlspecialchars(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) . ')'; - } else { - // fall back to modifier.escape.php - } - - case 'htmlall': - if (Smarty::$_MBSTRING) { - if ($_double_encode) { - // php >=5.2.3 - go native - return 'mb_convert_encoding(htmlspecialchars(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) . ', ' - . var_export($double_encode, true) - . '), "HTML-ENTITIES", ' - . var_export($char_set, true) . ')'; - } else if ($double_encode) { - // php <5.2.3 - only handle double encoding - return 'mb_convert_encoding(htmlspecialchars(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) - . '), "HTML-ENTITIES", ' - . var_export($char_set, true) . ')'; - } else { - // fall back to modifier.escape.php - } - } - - // no MBString fallback - if ($_double_encode) { - // php >=5.2.3 - go native - return 'htmlentities(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) . ', ' - . var_export($double_encode, true) . ')'; - } else if ($double_encode) { - // php <5.2.3 - only handle double encoding - return 'htmlentities(' - . $params[0] .', ENT_QUOTES, ' - . var_export($char_set, true) . ')'; - } else { - // fall back to modifier.escape.php - } - - case 'url': - return 'rawurlencode(' . $params[0] . ')'; - - case 'urlpathinfo': - return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))'; - - case 'quotes': - // escape unescaped single quotes - return 'preg_replace("%(? "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", " "<\/" ))'; - - } - } catch(SmartyException $e) { - // pass through to regular plugin fallback - } - - // could not optimize |escape call, so fallback to regular plugin - if ($compiler->tag_nocache | $compiler->nocache) { - $compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; - $compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; - } else { - $compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; - $compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; - } - return 'smarty_modifier_escape(' . join( ', ', $params ) . ')'; -} - + + * Name: escape
+ * Purpose: escape string for output + * + * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) + * @author Rodney Rehm + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_escape($params, $compiler) +{ + static $_double_encode = null; + if ($_double_encode === null) { + $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); + } + + try { + $esc_type = smarty_literal_compiler_param($params, 1, 'html'); + $char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET); + $double_encode = smarty_literal_compiler_param($params, 3, true); + + if (!$char_set) { + $char_set = Smarty::$_CHARSET; + } + + switch ($esc_type) { + case 'html': + if ($_double_encode) { + return 'htmlspecialchars(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) . ', ' + . var_export($double_encode, true) . ')'; + } else if ($double_encode) { + return 'htmlspecialchars(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) . ')'; + } else { + // fall back to modifier.escape.php + } + + case 'htmlall': + if (Smarty::$_MBSTRING) { + if ($_double_encode) { + // php >=5.2.3 - go native + return 'mb_convert_encoding(htmlspecialchars(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) . ', ' + . var_export($double_encode, true) + . '), "HTML-ENTITIES", ' + . var_export($char_set, true) . ')'; + } else if ($double_encode) { + // php <5.2.3 - only handle double encoding + return 'mb_convert_encoding(htmlspecialchars(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) + . '), "HTML-ENTITIES", ' + . var_export($char_set, true) . ')'; + } else { + // fall back to modifier.escape.php + } + } + + // no MBString fallback + if ($_double_encode) { + // php >=5.2.3 - go native + return 'htmlentities(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) . ', ' + . var_export($double_encode, true) . ')'; + } else if ($double_encode) { + // php <5.2.3 - only handle double encoding + return 'htmlentities(' + . $params[0] .', ENT_QUOTES, ' + . var_export($char_set, true) . ')'; + } else { + // fall back to modifier.escape.php + } + + case 'url': + return 'rawurlencode(' . $params[0] . ')'; + + case 'urlpathinfo': + return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))'; + + case 'quotes': + // escape unescaped single quotes + return 'preg_replace("%(? "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", " "<\/" ))'; + + } + } catch(SmartyException $e) { + // pass through to regular plugin fallback + } + + // could not optimize |escape call, so fallback to regular plugin + if ($compiler->tag_nocache | $compiler->nocache) { + $compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; + $compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; + } else { + $compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR .'modifier.escape.php'; + $compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; + } + return 'smarty_modifier_escape(' . join( ', ', $params ) . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.from_charset.php b/include/smarty/libs/plugins/modifiercompiler.from_charset.php index 93b568a5a..5d6b7889a 100644 --- a/include/smarty/libs/plugins/modifiercompiler.from_charset.php +++ b/include/smarty/libs/plugins/modifiercompiler.from_charset.php @@ -1,34 +1,34 @@ - - * Name: from_charset
- * Purpose: convert character encoding from $charset to internal encoding - * - * @author Rodney Rehm - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_from_charset($params, $compiler) -{ - if (!Smarty::$_MBSTRING) { - // FIXME: (rodneyrehm) shouldn't this throw an error? - return $params[0]; - } - - if (!isset($params[1])) { - $params[1] = '"ISO-8859-1"'; - } - - return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; -} - + + * Name: from_charset
+ * Purpose: convert character encoding from $charset to internal encoding + * + * @author Rodney Rehm + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_from_charset($params, $compiler) +{ + if (!Smarty::$_MBSTRING) { + // FIXME: (rodneyrehm) shouldn't this throw an error? + return $params[0]; + } + + if (!isset($params[1])) { + $params[1] = '"ISO-8859-1"'; + } + + return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.indent.php b/include/smarty/libs/plugins/modifiercompiler.indent.php index 020c4fdb3..26094b7ca 100644 --- a/include/smarty/libs/plugins/modifiercompiler.indent.php +++ b/include/smarty/libs/plugins/modifiercompiler.indent.php @@ -1,32 +1,32 @@ - - * Name: indent
- * Purpose: indent lines of text - * - * @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ - -function smarty_modifiercompiler_indent($params, $compiler) -{ - if (!isset($params[1])) { - $params[1] = 4; - } - if (!isset($params[2])) { - $params[2] = "' '"; - } - return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')'; -} - + + * Name: indent
+ * Purpose: indent lines of text + * + * @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ + +function smarty_modifiercompiler_indent($params, $compiler) +{ + if (!isset($params[1])) { + $params[1] = 4; + } + if (!isset($params[2])) { + $params[2] = "' '"; + } + return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.lower.php b/include/smarty/libs/plugins/modifiercompiler.lower.php index 1845cc1d2..bc3abd727 100644 --- a/include/smarty/libs/plugins/modifiercompiler.lower.php +++ b/include/smarty/libs/plugins/modifiercompiler.lower.php @@ -1,31 +1,31 @@ - - * Name: lower
- * Purpose: convert string to lowercase - * - * @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) - * @author Monte Ohrt - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ - -function smarty_modifiercompiler_lower($params, $compiler) -{ - if (Smarty::$_MBSTRING) { - return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; - } - // no MBString fallback - return 'strtolower(' . $params[0] . ')'; -} - + + * Name: lower
+ * Purpose: convert string to lowercase + * + * @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual) + * @author Monte Ohrt + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ + +function smarty_modifiercompiler_lower($params, $compiler) +{ + if (Smarty::$_MBSTRING) { + return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; + } + // no MBString fallback + return 'strtolower(' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.noprint.php b/include/smarty/libs/plugins/modifiercompiler.noprint.php index 3ca26571a..d7433e985 100644 --- a/include/smarty/libs/plugins/modifiercompiler.noprint.php +++ b/include/smarty/libs/plugins/modifiercompiler.noprint.php @@ -1,25 +1,25 @@ - - * Name: noprint
- * Purpose: return an empty string - * - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_noprint($params, $compiler) -{ - return "''"; -} - + + * Name: noprint
+ * Purpose: return an empty string + * + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_noprint($params, $compiler) +{ + return "''"; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.string_format.php b/include/smarty/libs/plugins/modifiercompiler.string_format.php index 83345977b..5a8d43578 100644 --- a/include/smarty/libs/plugins/modifiercompiler.string_format.php +++ b/include/smarty/libs/plugins/modifiercompiler.string_format.php @@ -1,26 +1,26 @@ - - * Name: string_format
- * Purpose: format strings via sprintf - * - * @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_string_format($params, $compiler) -{ - return 'sprintf(' . $params[1] . ',' . $params[0] . ')'; -} - + + * Name: string_format
+ * Purpose: format strings via sprintf + * + * @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_string_format($params, $compiler) +{ + return 'sprintf(' . $params[1] . ',' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.strip.php b/include/smarty/libs/plugins/modifiercompiler.strip.php index f1d5db045..8d15ca434 100644 --- a/include/smarty/libs/plugins/modifiercompiler.strip.php +++ b/include/smarty/libs/plugins/modifiercompiler.strip.php @@ -1,33 +1,33 @@ - - * Name: strip
- * Purpose: Replace all repeated spaces, newlines, tabs - * with a single space or supplied replacement string.
- * Example: {$var|strip} {$var|strip:" "}
- * Date: September 25th, 2002 - * - * @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ - -function smarty_modifiercompiler_strip($params, $compiler) -{ - if (!isset($params[1])) { - $params[1] = "' '"; - } - return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; -} - + + * Name: strip
+ * Purpose: Replace all repeated spaces, newlines, tabs + * with a single space or supplied replacement string.
+ * Example: {$var|strip} {$var|strip:" "}
+ * Date: September 25th, 2002 + * + * @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ + +function smarty_modifiercompiler_strip($params, $compiler) +{ + if (!isset($params[1])) { + $params[1] = "' '"; + } + return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.strip_tags.php b/include/smarty/libs/plugins/modifiercompiler.strip_tags.php index 296a3a2da..9ba71e3d9 100644 --- a/include/smarty/libs/plugins/modifiercompiler.strip_tags.php +++ b/include/smarty/libs/plugins/modifiercompiler.strip_tags.php @@ -1,33 +1,33 @@ - - * Name: strip_tags
- * Purpose: strip html tags from text - * - * @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_strip_tags($params, $compiler) -{ - if (!isset($params[1])) { - $params[1] = true; - } - if ($params[1] === true) { - return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})"; - } else { - return 'strip_tags(' . $params[0] . ')'; - } -} - + + * Name: strip_tags
+ * Purpose: strip html tags from text + * + * @link http://www.smarty.net/manual/en/language.modifier.strip.tags.php strip_tags (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_strip_tags($params, $compiler) +{ + if (!isset($params[1])) { + $params[1] = true; + } + if ($params[1] === true) { + return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})"; + } else { + return 'strip_tags(' . $params[0] . ')'; + } +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.to_charset.php b/include/smarty/libs/plugins/modifiercompiler.to_charset.php index f5cdf455f..d6c0f296b 100644 --- a/include/smarty/libs/plugins/modifiercompiler.to_charset.php +++ b/include/smarty/libs/plugins/modifiercompiler.to_charset.php @@ -1,34 +1,34 @@ - - * Name: to_charset
- * Purpose: convert character encoding from internal encoding to $charset - * - * @author Rodney Rehm - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_to_charset($params, $compiler) -{ - if (!Smarty::$_MBSTRING) { - // FIXME: (rodneyrehm) shouldn't this throw an error? - return $params[0]; - } - - if (!isset($params[1])) { - $params[1] = '"ISO-8859-1"'; - } - - return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; -} - + + * Name: to_charset
+ * Purpose: convert character encoding from internal encoding to $charset + * + * @author Rodney Rehm + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_to_charset($params, $compiler) +{ + if (!Smarty::$_MBSTRING) { + // FIXME: (rodneyrehm) shouldn't this throw an error? + return $params[0]; + } + + if (!isset($params[1])) { + $params[1] = '"ISO-8859-1"'; + } + + return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.unescape.php b/include/smarty/libs/plugins/modifiercompiler.unescape.php index 4321ff18d..61354926f 100644 --- a/include/smarty/libs/plugins/modifiercompiler.unescape.php +++ b/include/smarty/libs/plugins/modifiercompiler.unescape.php @@ -1,51 +1,51 @@ - - * Name: unescape
- * Purpose: unescape html entities - * - * @author Rodney Rehm - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_unescape($params, $compiler) -{ - if (!isset($params[1])) { - $params[1] = 'html'; - } - if (!isset($params[2])) { - $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; - } else { - $params[2] = "'" . $params[2] . "'"; - } - - switch (trim($params[1], '"\'')) { - case 'entity': - case 'htmlall': - if (Smarty::$_MBSTRING) { - return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; - } - - return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')'; - - case 'html': - return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)'; - - case 'url': - return 'rawurldecode(' . $params[0] . ')'; - - default: - return $params[0]; - } -} - + + * Name: unescape
+ * Purpose: unescape html entities + * + * @author Rodney Rehm + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_unescape($params, $compiler) +{ + if (!isset($params[1])) { + $params[1] = 'html'; + } + if (!isset($params[2])) { + $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\''; + } else { + $params[2] = "'" . $params[2] . "'"; + } + + switch (trim($params[1], '"\'')) { + case 'entity': + case 'htmlall': + if (Smarty::$_MBSTRING) { + return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')'; + } + + return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')'; + + case 'html': + return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)'; + + case 'url': + return 'rawurldecode(' . $params[0] . ')'; + + default: + return $params[0]; + } +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.upper.php b/include/smarty/libs/plugins/modifiercompiler.upper.php index f368e37dc..8611fa870 100644 --- a/include/smarty/libs/plugins/modifiercompiler.upper.php +++ b/include/smarty/libs/plugins/modifiercompiler.upper.php @@ -1,30 +1,30 @@ - - * Name: lower
- * Purpose: convert string to uppercase - * - * @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_upper($params, $compiler) -{ - if (Smarty::$_MBSTRING) { - return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; - } - // no MBString fallback - return 'strtoupper(' . $params[0] . ')'; -} - + + * Name: lower
+ * Purpose: convert string to uppercase + * + * @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_upper($params, $compiler) +{ + if (Smarty::$_MBSTRING) { + return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')' ; + } + // no MBString fallback + return 'strtoupper(' . $params[0] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/plugins/modifiercompiler.wordwrap.php b/include/smarty/libs/plugins/modifiercompiler.wordwrap.php index f6845ad37..8b524f32c 100644 --- a/include/smarty/libs/plugins/modifiercompiler.wordwrap.php +++ b/include/smarty/libs/plugins/modifiercompiler.wordwrap.php @@ -1,46 +1,46 @@ - - * Name: wordwrap
- * Purpose: wrap a string of text at a given length - * - * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) - * @author Uwe Tews - * @param array $params parameters - * @return string with compiled code - */ -function smarty_modifiercompiler_wordwrap($params, $compiler) -{ - if (!isset($params[1])) { - $params[1] = 80; - } - if (!isset($params[2])) { - $params[2] = '"\n"'; - } - if (!isset($params[3])) { - $params[3] = 'false'; - } - $function = 'wordwrap'; - if (Smarty::$_MBSTRING) { - if ($compiler->tag_nocache | $compiler->nocache) { - $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; - $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; - } else { - $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; - $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; - } - $function = 'smarty_mb_wordwrap'; - } - return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')'; -} - + + * Name: wordwrap
+ * Purpose: wrap a string of text at a given length + * + * @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual) + * @author Uwe Tews + * @param array $params parameters + * @return string with compiled code + */ +function smarty_modifiercompiler_wordwrap($params, $compiler) +{ + if (!isset($params[1])) { + $params[1] = 80; + } + if (!isset($params[2])) { + $params[2] = '"\n"'; + } + if (!isset($params[3])) { + $params[3] = 'false'; + } + $function = 'wordwrap'; + if (Smarty::$_MBSTRING) { + if ($compiler->tag_nocache | $compiler->nocache) { + $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; + $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; + } else { + $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR .'shared.mb_wordwrap.php'; + $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; + } + $function = 'smarty_mb_wordwrap'; + } + return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')'; +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php index 259c66e2b..b25bef6c4 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php @@ -1,77 +1,77 @@ - true, 'foreach' => true, 'while' => true, 'section' => true); - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - - if ($_attr['nocache'] === true) { - $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); - } - - if (isset($_attr['levels'])) { - if (!is_numeric($_attr['levels'])) { - $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); - } - $_levels = $_attr['levels']; - } else { - $_levels = 1; - } - $level_count = $_levels; - $stack_count = count($compiler->_tag_stack) - 1; - while ($level_count > 0 && $stack_count >= 0) { - if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { - $level_count--; - } - $stack_count--; - } - if ($level_count != 0) { - $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); - } - $compiler->has_code = true; - return ""; - } - -} - + true, 'foreach' => true, 'while' => true, 'section' => true); + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); + } + + if (isset($_attr['levels'])) { + if (!is_numeric($_attr['levels'])) { + $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); + } + $_levels = $_attr['levels']; + } else { + $_levels = 1; + } + $level_count = $_levels; + $stack_count = count($compiler->_tag_stack) - 1; + while ($level_count > 0 && $stack_count >= 0) { + if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { + $level_count--; + } + $stack_count--; + } + if ($level_count != 0) { + $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); + } + $compiler->has_code = true; + return ""; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php index 4082a93b3..72a5f8653 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php @@ -1,78 +1,78 @@ - true, 'foreach' => true, 'while' => true, 'section' => true); - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - - if ($_attr['nocache'] === true) { - $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); - } - - if (isset($_attr['levels'])) { - if (!is_numeric($_attr['levels'])) { - $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); - } - $_levels = $_attr['levels']; - } else { - $_levels = 1; - } - $level_count = $_levels; - $stack_count = count($compiler->_tag_stack) - 1; - while ($level_count > 0 && $stack_count >= 0) { - if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { - $level_count--; - } - $stack_count--; - } - if ($level_count != 0) { - $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno); - } - $compiler->has_code = true; - return ""; - } - -} - + true, 'foreach' => true, 'while' => true, 'section' => true); + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); + } + + if (isset($_attr['levels'])) { + if (!is_numeric($_attr['levels'])) { + $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); + } + $_levels = $_attr['levels']; + } else { + $_levels = 1; + } + $level_count = $_levels; + $stack_count = count($compiler->_tag_stack) - 1; + while ($level_count > 0 && $stack_count >= 0) { + if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { + $level_count--; + } + $stack_count--; + } + if ($level_count != 0) { + $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno); + } + $compiler->has_code = true; + return ""; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php index 120f3ff10..a33109cc0 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php @@ -1,140 +1,140 @@ -getAttributes($compiler, $args); - $output = $parameter['value']; - // loop over list of modifiers - foreach ($parameter['modifierlist'] as $single_modifier) { - $modifier = $single_modifier[0]; - $single_modifier[0] = $output; - $params = implode(',', $single_modifier); - // check if we know already the type of modifier - if (isset($compiler->known_modifier_type[$modifier])) { - $modifier_types = array($compiler->known_modifier_type[$modifier]); - } else { - $modifier_types = array(1, 2, 3, 4, 5, 6); - } - foreach ($modifier_types as $type) { - switch ($type) { - case 1: - // registered modifier - if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) { - $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; - if (!is_array($function)) { - $output = "{$function}({$params})"; - } else { - if (is_object($function[0])) { - $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; - } else { - $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; - } - } - $compiler->known_modifier_type[$modifier] = $type; - break 2; - } - break; - case 2: - // registered modifier compiler - if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { - $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty); - $compiler->known_modifier_type[$modifier] = $type; - break 2; - } - break; - case 3: - // modifiercompiler plugin - if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { - $plugin = 'smarty_modifiercompiler_' . $modifier; - $output = $plugin($single_modifier, $compiler); - } - $compiler->known_modifier_type[$modifier] = $type; - break 2; - } - break; - case 4: - // modifier plugin - if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { - $output = "{$function}({$params})"; - } - $compiler->known_modifier_type[$modifier] = $type; - break 2; - } - break; - case 5: - // PHP function - if (is_callable($modifier)) { - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) { - $output = "{$modifier}({$params})"; - } - $compiler->known_modifier_type[$modifier] = $type; - break 2; - } - break; - case 6: - // default plugin handler - if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) { - $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { - if (!is_array($function)) { - $output = "{$function}({$params})"; - } else { - if (is_object($function[0])) { - $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; - } else { - $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; - } - } - } - if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { - // was a plugin - $compiler->known_modifier_type[$modifier] = 4; - } else { - $compiler->known_modifier_type[$modifier] = $type; - } - break 2; - } - } - } - if (!isset($compiler->known_modifier_type[$modifier])) { - $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno); - } - } - return $output; - } - -} - +getAttributes($compiler, $args); + $output = $parameter['value']; + // loop over list of modifiers + foreach ($parameter['modifierlist'] as $single_modifier) { + $modifier = $single_modifier[0]; + $single_modifier[0] = $output; + $params = implode(',', $single_modifier); + // check if we know already the type of modifier + if (isset($compiler->known_modifier_type[$modifier])) { + $modifier_types = array($compiler->known_modifier_type[$modifier]); + } else { + $modifier_types = array(1, 2, 3, 4, 5, 6); + } + foreach ($modifier_types as $type) { + switch ($type) { + case 1: + // registered modifier + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) { + $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; + if (!is_array($function)) { + $output = "{$function}({$params})"; + } else { + if (is_object($function[0])) { + $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; + } else { + $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; + } + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 2: + // registered modifier compiler + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { + $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty); + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 3: + // modifiercompiler plugin + if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { + $plugin = 'smarty_modifiercompiler_' . $modifier; + $output = $plugin($single_modifier, $compiler); + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 4: + // modifier plugin + if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { + $output = "{$function}({$params})"; + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 5: + // PHP function + if (is_callable($modifier)) { + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) { + $output = "{$modifier}({$params})"; + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 6: + // default plugin handler + if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) { + $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { + if (!is_array($function)) { + $output = "{$function}({$params})"; + } else { + if (is_object($function[0])) { + $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; + } else { + $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; + } + } + } + if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { + // was a plugin + $compiler->known_modifier_type[$modifier] = 4; + } else { + $compiler->known_modifier_type[$modifier] = $type; + } + break 2; + } + } + } + if (!isset($compiler->known_modifier_type[$modifier])) { + $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno); + } + } + return $output; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_block.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_block.php index 9fed36c3b..f104853a8 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_block.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_block.php @@ -1,113 +1,113 @@ -getAttributes($compiler, $args); - if ($_attr['nocache']) { - $compiler->tag_nocache = true; - } - unset($_attr['nocache']); - if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) { - $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag]; - } else { - $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; - } - // convert attributes into parameter array string - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { - $_value = str_replace("'","^#^",$_value); - $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $_params = 'array(' . implode(",", $_paramsArray) . ')'; - - $this->openTag($compiler, $tag, array($_params, $compiler->nocache)); - // maybe nocache because of nocache variables or nocache plugin - $compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache; - $function = $tag_info[0]; - // compile code - if (!is_array($function)) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; - } else if (is_object($function[0])) { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; - } else { - $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; - } - } else { - // must endblock be nocache? - if ($compiler->nocache) { - $compiler->tag_nocache = true; - } - $base_tag = substr($tag, 0, -5); - // closing tag of block plugin, restore nocache - list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag); - // This tag does create output - $compiler->has_output = true; - if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { - $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; - } else { - $function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; - } - // compile code - if (!isset($parameter['modifier_list'])) { - $mod_pre = $mod_post =''; - } else { - $mod_pre = ' ob_start(); '; - $mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';'; - } - if (!is_array($function)) { - $output = "smarty->_tag_stack);?>"; - } else if (is_object($function[0])) { - $output = "smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; - } else { - $output = "smarty->_tag_stack);?>"; - } - } - return $output . "\n"; - } - -} - +getAttributes($compiler, $args); + if ($_attr['nocache']) { + $compiler->tag_nocache = true; + } + unset($_attr['nocache']); + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) { + $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag]; + } else { + $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; + } + // convert attributes into parameter array string + $_paramsArray = array(); + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { + $_value = str_replace("'","^#^",$_value); + $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(",", $_paramsArray) . ')'; + + $this->openTag($compiler, $tag, array($_params, $compiler->nocache)); + // maybe nocache because of nocache variables or nocache plugin + $compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache; + $function = $tag_info[0]; + // compile code + if (!is_array($function)) { + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + } else if (is_object($function[0])) { + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + } else { + $output = "smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; + } + } else { + // must endblock be nocache? + if ($compiler->nocache) { + $compiler->tag_nocache = true; + } + $base_tag = substr($tag, 0, -5); + // closing tag of block plugin, restore nocache + list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag); + // This tag does create output + $compiler->has_output = true; + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { + $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; + } else { + $function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0]; + } + // compile code + if (!isset($parameter['modifier_list'])) { + $mod_pre = $mod_post =''; + } else { + $mod_pre = ' ob_start(); '; + $mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';'; + } + if (!is_array($function)) { + $output = "smarty->_tag_stack);?>"; + } else if (is_object($function[0])) { + $output = "smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); ".$mod_post."} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; + } else { + $output = "smarty->_tag_stack);?>"; + } + } + return $output . "\n"; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_function.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_function.php index 5058bfbbd..e68a0244d 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_function.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_registered_function.php @@ -1,81 +1,81 @@ -has_output = true; - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - if ($_attr['nocache']) { - $compiler->tag_nocache = true; - } - unset($_attr['nocache']); - if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { - $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag]; - } else { - $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag]; - } - // not cachable? - $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; - // convert attributes into parameter array string - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { - $_value = str_replace("'","^#^",$_value); - $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; - } - } - $_params = 'array(' . implode(",", $_paramsArray) . ')'; - $function = $tag_info[0]; - // compile code - if (!is_array($function)) { - $output = "\n"; - } else if (is_object($function[0])) { - $output = "smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n"; - } else { - $output = "\n"; - } - return $output; - } - -} - +has_output = true; + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + if ($_attr['nocache']) { + $compiler->tag_nocache = true; + } + unset($_attr['nocache']); + if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { + $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag]; + } else { + $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag]; + } + // not cachable? + $compiler->tag_nocache = $compiler->tag_nocache || !$tag_info[1]; + // convert attributes into parameter array string + $_paramsArray = array(); + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } elseif ($compiler->template->caching && in_array($_key,$tag_info[2])) { + $_value = str_replace("'","^#^",$_value); + $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(",", $_paramsArray) . ')'; + $function = $tag_info[0]; + // compile code + if (!is_array($function)) { + $output = "\n"; + } else if (is_object($function[0])) { + $output = "smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n"; + } else { + $output = "\n"; + } + return $output; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_setfilter.php b/include/smarty/libs/sysplugins/smarty_internal_compile_setfilter.php index d1dd90cf8..50b4cab55 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_compile_setfilter.php +++ b/include/smarty/libs/sysplugins/smarty_internal_compile_setfilter.php @@ -1,72 +1,72 @@ -variable_filter_stack[] = $compiler->template->variable_filters; - $compiler->template->variable_filters = $parameter['modifier_list']; - // this tag does not return compiled code - $compiler->has_code = false; - return true; - } - -} - -/** - * Smarty Internal Plugin Compile Setfilterclose Class - * - * @package Smarty - * @subpackage Compiler - */ -class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase { - - /** - * Compiles code for the {/setfilter} tag - * - * This tag does not generate compiled output. It resets variable filter. - * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @return string compiled code - */ - public function compile($args, $compiler) - { - $_attr = $this->getAttributes($compiler, $args); - // reset variable filter to previous state - if (count($compiler->variable_filter_stack)) { - $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack); - } else { - $compiler->template->variable_filters = array(); - } - // this tag does not return compiled code - $compiler->has_code = false; - return true; - } - -} - +variable_filter_stack[] = $compiler->template->variable_filters; + $compiler->template->variable_filters = $parameter['modifier_list']; + // this tag does not return compiled code + $compiler->has_code = false; + return true; + } + +} + +/** + * Smarty Internal Plugin Compile Setfilterclose Class + * + * @package Smarty + * @subpackage Compiler + */ +class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase { + + /** + * Compiles code for the {/setfilter} tag + * + * This tag does not generate compiled output. It resets variable filter. + * + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @return string compiled code + */ + public function compile($args, $compiler) + { + $_attr = $this->getAttributes($compiler, $args); + // reset variable filter to previous state + if (count($compiler->variable_filter_stack)) { + $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack); + } else { + $compiler->template->variable_filters = array(); + } + // this tag does not return compiled code + $compiler->has_code = false; + return true; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_function_call_handler.php b/include/smarty/libs/sysplugins/smarty_internal_function_call_handler.php index 010d63592..fa4b43b2a 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_function_call_handler.php +++ b/include/smarty/libs/sysplugins/smarty_internal_function_call_handler.php @@ -1,55 +1,55 @@ -tpl_vars; - foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}; - foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>"; - if ($_nocache) { - $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!", - "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']); - $_template->smarty->template_functions[$_name]['called_nocache'] = true; - } else { - $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']); - } - $_code .= "tpl_vars = \$saved_tpl_vars;}"; - eval($_code); - } - $_function($_template, $_params); - } - -} - -?> +tpl_vars; + foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}; + foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>"; + if ($_nocache) { + $_code .= preg_replace(array("!<\?php echo \\'/\*%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/|/\*/%%SmartyNocache:{$_template->smarty->template_functions[$_name]['nocache_hash']}%%\*/\\';\?>!", + "!\\\'!"), array('', "'"), $_template->smarty->template_functions[$_name]['compiled']); + $_template->smarty->template_functions[$_name]['called_nocache'] = true; + } else { + $_code .= preg_replace("/{$_template->smarty->template_functions[$_name]['nocache_hash']}/", $_template->properties['nocache_hash'], $_template->smarty->template_functions[$_name]['compiled']); + } + $_code .= "tpl_vars = \$saved_tpl_vars;}"; + eval($_code); + } + $_function($_template, $_params); + } + +} + +?> diff --git a/include/smarty/libs/sysplugins/smarty_internal_get_include_path.php b/include/smarty/libs/sysplugins/smarty_internal_get_include_path.php index 518c406aa..bafb72133 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_get_include_path.php +++ b/include/smarty/libs/sysplugins/smarty_internal_get_include_path.php @@ -1,48 +1,48 @@ - \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_nocache_insert.php b/include/smarty/libs/sysplugins/smarty_internal_nocache_insert.php index faae49af6..64a2b1e1b 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_nocache_insert.php +++ b/include/smarty/libs/sysplugins/smarty_internal_nocache_insert.php @@ -1,53 +1,53 @@ -assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>"; - } else { - $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; - } - $_tpl = $_template; - while ($_tpl->parent instanceof Smarty_Internal_Template) { - $_tpl = $_tpl->parent; - } - return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/"; - } - -} - -?> +assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>"; + } else { + $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; + } + $_tpl = $_template; + while ($_tpl->parent instanceof Smarty_Internal_Template) { + $_tpl = $_tpl->parent; + } + return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/"; + } + +} + +?> diff --git a/include/smarty/libs/sysplugins/smarty_internal_parsetree.php b/include/smarty/libs/sysplugins/smarty_internal_parsetree.php index c9fb1f762..99f4c6566 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_parsetree.php +++ b/include/smarty/libs/sysplugins/smarty_internal_parsetree.php @@ -1,395 +1,395 @@ -parser = $parser; - $this->data = $data; - $this->saved_block_nesting = $parser->block_nesting_level; - } - - /** - * Return buffer content - * - * @return string content - */ - public function to_smarty_php() - { - return $this->data; - } - - /** - * Return complied code that loads the evaluated outout of buffer content into a temporary variable - * - * @return string template code - */ - public function assign_to_var() - { - $var = sprintf('$_tmp%d', ++$this->parser->prefix_number); - $this->parser->compiler->prefix_code[] = sprintf('%s', $this->data, $var); - return $var; - } - -} - -/** - * Code fragment inside a tag. - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_code extends _smarty_parsetree { - - - /** - * Create parse tree buffer for code fragment - * - * @param object $parser parser object - * @param string $data content - */ - public function __construct($parser, $data) - { - $this->parser = $parser; - $this->data = $data; - } - - /** - * Return buffer content in parentheses - * - * @return string content - */ - public function to_smarty_php() - { - return sprintf("(%s)", $this->data); - } - -} - -/** - * Double quoted string inside a tag. - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_doublequoted extends _smarty_parsetree { - - /** - * Create parse tree buffer for double quoted string subtrees - * - * @param object $parser parser object - * @param _smarty_parsetree $subtree parsetree buffer - */ - public function __construct($parser, _smarty_parsetree $subtree) - { - $this->parser = $parser; - $this->subtrees[] = $subtree; - if ($subtree instanceof _smarty_tag) { - $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); - } - } - - /** - * Append buffer to subtree - * - * @param _smarty_parsetree $subtree parsetree buffer - */ - public function append_subtree(_smarty_parsetree $subtree) - { - $last_subtree = count($this->subtrees) - 1; - if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { - if ($subtree instanceof _smarty_code) { - $this->subtrees[$last_subtree]->data .= 'data . ';?>'; - } elseif ($subtree instanceof _smarty_dq_content) { - $this->subtrees[$last_subtree]->data .= 'data . '";?>'; - } else { - $this->subtrees[$last_subtree]->data .= $subtree->data; - } - } else { - $this->subtrees[] = $subtree; - } - if ($subtree instanceof _smarty_tag) { - $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); - } - } - - /** - * Merge subtree buffer content together - * - * @return string compiled template code - */ - public function to_smarty_php() - { - $code = ''; - foreach ($this->subtrees as $subtree) { - if ($code !== "") { - $code .= "."; - } - if ($subtree instanceof _smarty_tag) { - $more_php = $subtree->assign_to_var(); - } else { - $more_php = $subtree->to_smarty_php(); - } - - $code .= $more_php; - - if (!$subtree instanceof _smarty_dq_content) { - $this->parser->compiler->has_variable_string = true; - } - } - return $code; - } - -} - -/** - * Raw chars as part of a double quoted string. - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_dq_content extends _smarty_parsetree { - - - /** - * Create parse tree buffer with string content - * - * @param object $parser parser object - * @param string $data string section - */ - public function __construct($parser, $data) - { - $this->parser = $parser; - $this->data = $data; - } - - /** - * Return content as double quoted string - * - * @return string doubled quoted string - */ - public function to_smarty_php() - { - return '"' . $this->data . '"'; - } - -} - -/** - * Template element - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_template_buffer extends _smarty_parsetree { - - /** - * Array of template elements - * - * @var array - */ - public $subtrees = Array(); - - /** - * Create root of parse tree for template elements - * - * @param object $parser parse object - */ - public function __construct($parser) - { - $this->parser = $parser; - } - - /** - * Append buffer to subtree - * - * @param _smarty_parsetree $subtree - */ - public function append_subtree(_smarty_parsetree $subtree) - { - $this->subtrees[] = $subtree; - } - - /** - * Sanitize and merge subtree buffers together - * - * @return string template code content - */ - public function to_smarty_php() - { - $code = ''; - for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) { - if ($key + 2 < $cnt) { - if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) { - $key = $key + 1; - continue; - } - if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') { - $key = $key + 2; - continue; - } - } - if (substr($code, -1) == '<') { - $subtree = $this->subtrees[$key]->to_smarty_php(); - if (substr($subtree, 0, 1) == '?') { - $code = substr($code, 0, strlen($code) - 1) . '<?' . substr($subtree, 1); - } elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') { - $code = substr($code, 0, strlen($code) - 1) . '<%' . substr($subtree, 1); - } else { - $code .= $subtree; - } - continue; - } - if ($this->parser->asp_tags && substr($code, -1) == '%') { - $subtree = $this->subtrees[$key]->to_smarty_php(); - if (substr($subtree, 0, 1) == '>') { - $code = substr($code, 0, strlen($code) - 1) . '%>' . substr($subtree, 1); - } else { - $code .= $subtree; - } - continue; - } - if (substr($code, -1) == '?') { - $subtree = $this->subtrees[$key]->to_smarty_php(); - if (substr($subtree, 0, 1) == '>') { - $code = substr($code, 0, strlen($code) - 1) . '?>' . substr($subtree, 1); - } else { - $code .= $subtree; - } - continue; - } - $code .= $this->subtrees[$key]->to_smarty_php(); - } - return $code; - } - -} - -/** - * template text - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_text extends _smarty_parsetree { - - - /** - * Create template text buffer - * - * @param object $parser parser object - * @param string $data text - */ - public function __construct($parser, $data) - { - $this->parser = $parser; - $this->data = $data; - } - - /** - * Return buffer content - * - * @return strint text - */ - public function to_smarty_php() - { - return $this->data; - } - -} - -/** - * template linebreaks - * - * @package Smarty - * @subpackage Compiler - * @ignore - */ -class _smarty_linebreak extends _smarty_parsetree { - - /** - * Create buffer with linebreak content - * - * @param object $parser parser object - * @param string $data linebreak string - */ - public function __construct($parser, $data) - { - $this->parser = $parser; - $this->data = $data; - } - - /** - * Return linebrak - * - * @return string linebreak - */ - public function to_smarty_php() - { - return $this->data; - } - -} - +parser = $parser; + $this->data = $data; + $this->saved_block_nesting = $parser->block_nesting_level; + } + + /** + * Return buffer content + * + * @return string content + */ + public function to_smarty_php() + { + return $this->data; + } + + /** + * Return complied code that loads the evaluated outout of buffer content into a temporary variable + * + * @return string template code + */ + public function assign_to_var() + { + $var = sprintf('$_tmp%d', ++$this->parser->prefix_number); + $this->parser->compiler->prefix_code[] = sprintf('%s', $this->data, $var); + return $var; + } + +} + +/** + * Code fragment inside a tag. + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_code extends _smarty_parsetree { + + + /** + * Create parse tree buffer for code fragment + * + * @param object $parser parser object + * @param string $data content + */ + public function __construct($parser, $data) + { + $this->parser = $parser; + $this->data = $data; + } + + /** + * Return buffer content in parentheses + * + * @return string content + */ + public function to_smarty_php() + { + return sprintf("(%s)", $this->data); + } + +} + +/** + * Double quoted string inside a tag. + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_doublequoted extends _smarty_parsetree { + + /** + * Create parse tree buffer for double quoted string subtrees + * + * @param object $parser parser object + * @param _smarty_parsetree $subtree parsetree buffer + */ + public function __construct($parser, _smarty_parsetree $subtree) + { + $this->parser = $parser; + $this->subtrees[] = $subtree; + if ($subtree instanceof _smarty_tag) { + $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); + } + } + + /** + * Append buffer to subtree + * + * @param _smarty_parsetree $subtree parsetree buffer + */ + public function append_subtree(_smarty_parsetree $subtree) + { + $last_subtree = count($this->subtrees) - 1; + if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof _smarty_tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { + if ($subtree instanceof _smarty_code) { + $this->subtrees[$last_subtree]->data .= 'data . ';?>'; + } elseif ($subtree instanceof _smarty_dq_content) { + $this->subtrees[$last_subtree]->data .= 'data . '";?>'; + } else { + $this->subtrees[$last_subtree]->data .= $subtree->data; + } + } else { + $this->subtrees[] = $subtree; + } + if ($subtree instanceof _smarty_tag) { + $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); + } + } + + /** + * Merge subtree buffer content together + * + * @return string compiled template code + */ + public function to_smarty_php() + { + $code = ''; + foreach ($this->subtrees as $subtree) { + if ($code !== "") { + $code .= "."; + } + if ($subtree instanceof _smarty_tag) { + $more_php = $subtree->assign_to_var(); + } else { + $more_php = $subtree->to_smarty_php(); + } + + $code .= $more_php; + + if (!$subtree instanceof _smarty_dq_content) { + $this->parser->compiler->has_variable_string = true; + } + } + return $code; + } + +} + +/** + * Raw chars as part of a double quoted string. + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_dq_content extends _smarty_parsetree { + + + /** + * Create parse tree buffer with string content + * + * @param object $parser parser object + * @param string $data string section + */ + public function __construct($parser, $data) + { + $this->parser = $parser; + $this->data = $data; + } + + /** + * Return content as double quoted string + * + * @return string doubled quoted string + */ + public function to_smarty_php() + { + return '"' . $this->data . '"'; + } + +} + +/** + * Template element + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_template_buffer extends _smarty_parsetree { + + /** + * Array of template elements + * + * @var array + */ + public $subtrees = Array(); + + /** + * Create root of parse tree for template elements + * + * @param object $parser parse object + */ + public function __construct($parser) + { + $this->parser = $parser; + } + + /** + * Append buffer to subtree + * + * @param _smarty_parsetree $subtree + */ + public function append_subtree(_smarty_parsetree $subtree) + { + $this->subtrees[] = $subtree; + } + + /** + * Sanitize and merge subtree buffers together + * + * @return string template code content + */ + public function to_smarty_php() + { + $code = ''; + for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) { + if ($key + 2 < $cnt) { + if ($this->subtrees[$key] instanceof _smarty_linebreak && $this->subtrees[$key + 1] instanceof _smarty_tag && $this->subtrees[$key + 1]->data == '' && $this->subtrees[$key + 2] instanceof _smarty_linebreak) { + $key = $key + 1; + continue; + } + if (substr($this->subtrees[$key]->data, -1) == '<' && $this->subtrees[$key + 1]->data == '' && substr($this->subtrees[$key + 2]->data, -1) == '?') { + $key = $key + 2; + continue; + } + } + if (substr($code, -1) == '<') { + $subtree = $this->subtrees[$key]->to_smarty_php(); + if (substr($subtree, 0, 1) == '?') { + $code = substr($code, 0, strlen($code) - 1) . '<?' . substr($subtree, 1); + } elseif ($this->parser->asp_tags && substr($subtree, 0, 1) == '%') { + $code = substr($code, 0, strlen($code) - 1) . '<%' . substr($subtree, 1); + } else { + $code .= $subtree; + } + continue; + } + if ($this->parser->asp_tags && substr($code, -1) == '%') { + $subtree = $this->subtrees[$key]->to_smarty_php(); + if (substr($subtree, 0, 1) == '>') { + $code = substr($code, 0, strlen($code) - 1) . '%>' . substr($subtree, 1); + } else { + $code .= $subtree; + } + continue; + } + if (substr($code, -1) == '?') { + $subtree = $this->subtrees[$key]->to_smarty_php(); + if (substr($subtree, 0, 1) == '>') { + $code = substr($code, 0, strlen($code) - 1) . '?>' . substr($subtree, 1); + } else { + $code .= $subtree; + } + continue; + } + $code .= $this->subtrees[$key]->to_smarty_php(); + } + return $code; + } + +} + +/** + * template text + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_text extends _smarty_parsetree { + + + /** + * Create template text buffer + * + * @param object $parser parser object + * @param string $data text + */ + public function __construct($parser, $data) + { + $this->parser = $parser; + $this->data = $data; + } + + /** + * Return buffer content + * + * @return strint text + */ + public function to_smarty_php() + { + return $this->data; + } + +} + +/** + * template linebreaks + * + * @package Smarty + * @subpackage Compiler + * @ignore + */ +class _smarty_linebreak extends _smarty_parsetree { + + /** + * Create buffer with linebreak content + * + * @param object $parser parser object + * @param string $data linebreak string + */ + public function __construct($parser, $data) + { + $this->parser = $parser; + $this->data = $data; + } + + /** + * Return linebrak + * + * @return string linebreak + */ + public function to_smarty_php() + { + return $this->data; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_resource_eval.php b/include/smarty/libs/sysplugins/smarty_internal_resource_eval.php index cf2ec3e1c..c025dc26d 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_resource_eval.php +++ b/include/smarty/libs/sysplugins/smarty_internal_resource_eval.php @@ -1,94 +1,94 @@ -uid = $source->filepath = sha1($source->name); - $source->timestamp = false; - $source->exists = true; - } - - /** - * Load template's source from $resource_name into current template object - * - * @uses decode() to decode base64 and urlencoded template_resources - * @param Smarty_Template_Source $source source object - * @return string template source - */ - public function getContent(Smarty_Template_Source $source) - { - return $this->decode($source->name); - } - - /** - * decode base64 and urlencode - * - * @param string $string template_resource to decode - * @return string decoded template_resource - */ - protected function decode($string) - { - // decode if specified - if (($pos = strpos($string, ':')) !== false) { - if (!strncmp($string, 'base64', 6)) { - return base64_decode(substr($string, 7)); - } elseif (!strncmp($string, 'urlencode', 9)) { - return urldecode(substr($string, 10)); - } - } - - return $string; - } - - /** - * modify resource_name according to resource handlers specifications - * - * @param Smarty $smarty Smarty instance - * @param string $resource_name resource_name to make unique - * @return string unique resource name - */ - protected function buildUniqueResourceName(Smarty $smarty, $resource_name) - { - return get_class($this) . '#' .$this->decode($resource_name); - } - - /** - * Determine basename for compiled filename - * - * @param Smarty_Template_Source $source source object - * @return string resource's basename - */ - protected function getBasename(Smarty_Template_Source $source) - { - return ''; - } - -} - +uid = $source->filepath = sha1($source->name); + $source->timestamp = false; + $source->exists = true; + } + + /** + * Load template's source from $resource_name into current template object + * + * @uses decode() to decode base64 and urlencoded template_resources + * @param Smarty_Template_Source $source source object + * @return string template source + */ + public function getContent(Smarty_Template_Source $source) + { + return $this->decode($source->name); + } + + /** + * decode base64 and urlencode + * + * @param string $string template_resource to decode + * @return string decoded template_resource + */ + protected function decode($string) + { + // decode if specified + if (($pos = strpos($string, ':')) !== false) { + if (!strncmp($string, 'base64', 6)) { + return base64_decode(substr($string, 7)); + } elseif (!strncmp($string, 'urlencode', 9)) { + return urldecode(substr($string, 10)); + } + } + + return $string; + } + + /** + * modify resource_name according to resource handlers specifications + * + * @param Smarty $smarty Smarty instance + * @param string $resource_name resource_name to make unique + * @return string unique resource name + */ + protected function buildUniqueResourceName(Smarty $smarty, $resource_name) + { + return get_class($this) . '#' .$this->decode($resource_name); + } + + /** + * Determine basename for compiled filename + * + * @param Smarty_Template_Source $source source object + * @return string resource's basename + */ + protected function getBasename(Smarty_Template_Source $source) + { + return ''; + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_templatebase.php b/include/smarty/libs/sysplugins/smarty_internal_templatebase.php index abd48b799..1cb9bb949 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_templatebase.php +++ b/include/smarty/libs/sysplugins/smarty_internal_templatebase.php @@ -1,811 +1,811 @@ -template_class) { - $template = $this; - } - if (!empty($cache_id) && is_object($cache_id)) { - $parent = $cache_id; - $cache_id = null; - } - if ($parent === null && ($this instanceof Smarty || is_string($template))) { - $parent = $this; - } - // create template object if necessary - $_template = ($template instanceof $this->template_class) - ? $template - : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); - // if called by Smarty object make sure we use current caching status - if ($this instanceof Smarty) { - $_template->caching = $this->caching; - } - // merge all variable scopes into template - if ($merge_tpl_vars) { - // save local variables - $save_tpl_vars = $_template->tpl_vars; - $save_config_vars = $_template->config_vars; - $ptr_array = array($_template); - $ptr = $_template; - while (isset($ptr->parent)) { - $ptr_array[] = $ptr = $ptr->parent; - } - $ptr_array = array_reverse($ptr_array); - $parent_ptr = reset($ptr_array); - $tpl_vars = $parent_ptr->tpl_vars; - $config_vars = $parent_ptr->config_vars; - while ($parent_ptr = next($ptr_array)) { - if (!empty($parent_ptr->tpl_vars)) { - $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars); - } - if (!empty($parent_ptr->config_vars)) { - $config_vars = array_merge($config_vars, $parent_ptr->config_vars); - } - } - if (!empty(Smarty::$global_tpl_vars)) { - $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars); - } - $_template->tpl_vars = $tpl_vars; - $_template->config_vars = $config_vars; - } - // dummy local smarty variable - if (!isset($_template->tpl_vars['smarty'])) { - $_template->tpl_vars['smarty'] = new Smarty_Variable; - } - if (isset($this->smarty->error_reporting)) { - $_smarty_old_error_level = error_reporting($this->smarty->error_reporting); - } - // check URL debugging control - if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') { - if (isset($_SERVER['QUERY_STRING'])) { - $_query_string = $_SERVER['QUERY_STRING']; - } else { - $_query_string = ''; - } - if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) { - if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) { - // enable debugging for this browser session - setcookie('SMARTY_DEBUG', true); - $this->smarty->debugging = true; - } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) { - // disable debugging for this browser session - setcookie('SMARTY_DEBUG', false); - $this->smarty->debugging = false; - } else { - // enable debugging for this page - $this->smarty->debugging = true; - } - } else { - if (isset($_COOKIE['SMARTY_DEBUG'])) { - $this->smarty->debugging = true; - } - } - } - // must reset merge template date - $_template->smarty->merged_templates_func = array(); - // get rendered template - // disable caching for evaluated code - if ($_template->source->recompiled) { - $_template->caching = false; - } - // checks if template exists - if (!$_template->source->exists) { - if ($_template->parent instanceof Smarty_Internal_Template) { - $parent_resource = " in '{$_template->parent->template_resource}'"; - } else { - $parent_resource = ''; - } - throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); - } - // read from cache or render - if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) { - // render template (not loaded and not in cache) - if (!$_template->source->uncompiled) { - $_smarty_tpl = $_template; - if ($_template->source->recompiled) { - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_compile($_template); - } - $code = $_template->compiler->compileTemplate($_template); - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_compile($_template); - } - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_render($_template); - } - try { - ob_start(); - eval("?>" . $code); - unset($code); - } catch (Exception $e) { - ob_get_clean(); - throw $e; - } - } else { - if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) { - $_template->compileTemplateSource(); - } - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_render($_template); - } - if (!$_template->compiled->loaded) { - include($_template->compiled->filepath); - if ($_template->mustCompile) { - // recompile and load again - $_template->compileTemplateSource(); - include($_template->compiled->filepath); - } - $_template->compiled->loaded = true; - } else { - $_template->decodeProperties($_template->compiled->_properties, false); - } - try { - ob_start(); - if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) { - throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'"); - } - array_unshift($_template->_capture_stack,array()); - // - // render compiled template - // - $_template->properties['unifunc']($_template); - // any unclosed {capture} tags ? - if (isset($_template->_capture_stack[0][0])) { - $_template->capture_error(); - } - array_shift($_template->_capture_stack); - } catch (Exception $e) { - ob_get_clean(); - throw $e; - } - } - } else { - if ($_template->source->uncompiled) { - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_render($_template); - } - try { - ob_start(); - $_template->source->renderUncompiled($_template); - } catch (Exception $e) { - ob_get_clean(); - throw $e; - } - } else { - throw new SmartyException("Resource '$_template->source->type' must have 'renderUncompiled' method"); - } - } - $_output = ob_get_clean(); - if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) { - $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type); - } - if ($_template->parent instanceof Smarty_Internal_Template) { - $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']); - foreach ($_template->required_plugins as $code => $tmp1) { - foreach ($tmp1 as $name => $tmp) { - foreach ($tmp as $type => $data) { - $_template->parent->required_plugins[$code][$name][$type] = $data; - } - } - } - } - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_render($_template); - } - // write to cache when nessecary - if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) { - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_cache($_template); - } - $_template->properties['has_nocache_code'] = false; - // get text between non-cached items - $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output); - // get non-cached items - preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts); - $output = ''; - // loop over items, stitch back together - foreach ($cache_split as $curr_idx => $curr_split) { - // escape PHP tags in template content - $output .= preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '', $curr_split); - if (isset($cache_parts[0][$curr_idx])) { - $_template->properties['has_nocache_code'] = true; - // remove nocache tags from cache output - $output .= preg_replace("!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]); - } - } - if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) { - $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template); - } - // rendering (must be done before writing cache file because of {function} nocache handling) - $_smarty_tpl = $_template; - try { - ob_start(); - eval("?>" . $output); - $_output = ob_get_clean(); - } catch (Exception $e) { - ob_get_clean(); - throw $e; - } - // write cache file content - $_template->writeCachedContent($output); - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_cache($_template); - } - } else { - // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output); - if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) { - // replace nocache_hash - $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output); - $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code; - } - } - } else { - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_cache($_template); - } - try { - ob_start(); - array_unshift($_template->_capture_stack,array()); - // - // render cached template - // - $_template->properties['unifunc']($_template); - // any unclosed {capture} tags ? - if (isset($_template->_capture_stack[0][0])) { - $_template->capture_error(); - } - array_shift($_template->_capture_stack); - $_output = ob_get_clean(); - } catch (Exception $e) { - ob_get_clean(); - throw $e; - } - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_cache($_template); - } - } - if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) { - $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template); - } - if (isset($this->error_reporting)) { - error_reporting($_smarty_old_error_level); - } - // display or fetch - if ($display) { - if ($this->caching && $this->cache_modified_check) { - $_isCached = $_template->isCached() && !$_template->has_nocache_code; - $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); - if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) { - switch (PHP_SAPI) { - case 'cgi': // php-cgi < 5.3 - case 'cgi-fcgi': // php-cgi >= 5.3 - case 'fpm-fcgi': // php-fpm >= 5.3.3 - header('Status: 304 Not Modified'); - break; - - case 'cli': - if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) { - $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified'; - } - break; - - default: - header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified'); - break; - } - } else { - switch (PHP_SAPI) { - case 'cli': - if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) { - $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT'; - } - break; - - default: - header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT'); - break; - } - echo $_output; - } - } else { - echo $_output; - } - // debug output - if ($this->smarty->debugging) { - Smarty_Internal_Debug::display_debug($this); - } - if ($merge_tpl_vars) { - // restore local variables - $_template->tpl_vars = $save_tpl_vars; - $_template->config_vars = $save_config_vars; - } - return; - } else { - if ($merge_tpl_vars) { - // restore local variables - $_template->tpl_vars = $save_tpl_vars; - $_template->config_vars = $save_config_vars; - } - // return fetched content - return $_output; - } - } - - /** - * 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->fetch($template, $cache_id, $compile_id, $parent, true); - } - - /** - * test if cache is valid - * - * @param string|object $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) { - return $this->cached->valid; - } - if (!($template instanceof $this->template_class)) { - if ($parent === null) { - $parent = $this; - } - $template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); - } - // return cache status of template - return $template->cached->valid; - } - - /** - * creates a data object - * - * @param object $parent next higher level of Smarty variables - * @returns Smarty_Data data object - */ - public function createData($parent = null) - { - return new Smarty_Data($parent, $this); - } - - /** - * Registers plugin to be used in templates - * - * @param string $type plugin type - * @param string $tag name of template tag - * @param callback $callback PHP callback to register - * @param boolean $cacheable if true (default) this fuction is cachable - * @param array $cache_attr caching attributes if any - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException when the plugin tag is invalid - */ - public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) - { - if (isset($this->smarty->registered_plugins[$type][$tag])) { - throw new SmartyException("Plugin tag \"{$tag}\" already registered"); - } elseif (!is_callable($callback)) { - throw new SmartyException("Plugin \"{$tag}\" not callable"); - } else { - $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr); - } - - return $this; - } - - /** - * Unregister Plugin - * - * @param string $type of plugin - * @param string $tag name of plugin - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unregisterPlugin($type, $tag) - { - if (isset($this->smarty->registered_plugins[$type][$tag])) { - unset($this->smarty->registered_plugins[$type][$tag]); - } - - return $this; - } - - /** - * Registers a resource to fetch a template - * - * @param string $type name of resource type - * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated) - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function registerResource($type, $callback) - { - $this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false); - return $this; - } - - /** - * Unregisters a resource - * - * @param string $type name of resource type - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unregisterResource($type) - { - if (isset($this->smarty->registered_resources[$type])) { - unset($this->smarty->registered_resources[$type]); - } - - return $this; - } - - /** - * Registers a cache resource to cache a template's output - * - * @param string $type name of cache resource type - * @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function registerCacheResource($type, Smarty_CacheResource $callback) - { - $this->smarty->registered_cache_resources[$type] = $callback; - return $this; - } - - /** - * Unregisters a cache resource - * - * @param string $type name of cache resource type - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unregisterCacheResource($type) - { - if (isset($this->smarty->registered_cache_resources[$type])) { - unset($this->smarty->registered_cache_resources[$type]); - } - - return $this; - } - - /** - * Registers object to be used in templates - * - * @param string $object name of template object - * @param object $object_impl the referenced PHP object to register - * @param array $allowed list of allowed methods (empty = all) - * @param boolean $smarty_args smarty argument format, else traditional - * @param array $block_methods list of block-methods - * @param array $block_functs list of methods that are block format - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException if any of the methods in $allowed or $block_methods are invalid - */ - public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) - { - // test if allowed methodes callable - if (!empty($allowed)) { - foreach ((array) $allowed as $method) { - if (!is_callable(array($object_impl, $method))) { - throw new SmartyException("Undefined method '$method' in registered object"); - } - } - } - // test if block methodes callable - if (!empty($block_methods)) { - foreach ((array) $block_methods as $method) { - if (!is_callable(array($object_impl, $method))) { - throw new SmartyException("Undefined method '$method' in registered object"); - } - } - } - // register the object - $this->smarty->registered_objects[$object_name] = - array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods); - return $this; - } - - /** - * return a reference to a registered object - * - * @param string $name object name - * @return object - * @throws SmartyException if no such object is found - */ - public function getRegisteredObject($name) - { - if (!isset($this->smarty->registered_objects[$name])) { - throw new SmartyException("'$name' is not a registered object"); - } - if (!is_object($this->smarty->registered_objects[$name][0])) { - throw new SmartyException("registered '$name' is not an object"); - } - return $this->smarty->registered_objects[$name][0]; - } - - /** - * unregister an object - * - * @param string $name object name - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unregisterObject($name) - { - if (isset($this->smarty->registered_objects[$name])) { - unset($this->smarty->registered_objects[$name]); - } - - return $this; - } - - /** - * Registers static classes to be used in templates - * - * @param string $class name of template class - * @param string $class_impl the referenced PHP class to register - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $class_impl does not refer to an existing class - */ - public function registerClass($class_name, $class_impl) - { - // test if exists - if (!class_exists($class_impl)) { - throw new SmartyException("Undefined class '$class_impl' in register template class"); - } - // register the class - $this->smarty->registered_classes[$class_name] = $class_impl; - return $this; - } - - /** - * Registers a default plugin handler - * - * @param callable $callback class/method name - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultPluginHandler($callback) - { - if (is_callable($callback)) { - $this->smarty->default_plugin_handler_func = $callback; - } else { - throw new SmartyException("Default plugin handler '$callback' not callable"); - } - - return $this; - } - - /** - * Registers a default template handler - * - * @param callable $callback class/method name - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultTemplateHandler($callback) - { - if (is_callable($callback)) { - $this->smarty->default_template_handler_func = $callback; - } else { - throw new SmartyException("Default template handler '$callback' not callable"); - } - - return $this; - } - - /** - * Registers a default template handler - * - * @param callable $callback class/method name - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - * @throws SmartyException if $callback is not callable - */ - public function registerDefaultConfigHandler($callback) - { - if (is_callable($callback)) { - $this->smarty->default_config_handler_func = $callback; - } else { - throw new SmartyException("Default config handler '$callback' not callable"); - } - - return $this; - } - - /** - * Registers a filter function - * - * @param string $type filter type - * @param callback $callback - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function registerFilter($type, $callback) - { - $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback; - return $this; - } - - /** - * Unregisters a filter function - * - * @param string $type filter type - * @param callback $callback - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unregisterFilter($type, $callback) - { - $name = $this->_get_filter_name($callback); - if (isset($this->smarty->registered_filters[$type][$name])) { - unset($this->smarty->registered_filters[$type][$name]); - } - - return $this; - } - - /** - * Return internal filter name - * - * @param callback $function_name - * @return string internal filter name - */ - public function _get_filter_name($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]; - } else { - return $function_name; - } - } - - /** - * load a filter of specified type and name - * - * @param string $type filter type - * @param string $name filter name - * @throws SmartyException if filter could not be loaded - */ - public function loadFilter($type, $name) - { - $_plugin = "smarty_{$type}filter_{$name}"; - $_filter_name = $_plugin; - if ($this->smarty->loadPlugin($_plugin)) { - if (class_exists($_plugin, false)) { - $_plugin = array($_plugin, 'execute'); - } - if (is_callable($_plugin)) { - $this->smarty->registered_filters[$type][$_filter_name] = $_plugin; - return true; - } - } - throw new SmartyException("{$type}filter \"{$name}\" not callable"); - } - - /** - * unload a filter of specified type and name - * - * @param string $type filter type - * @param string $name filter name - * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining - */ - public function unloadFilter($type, $name) - { - $_filter_name = "smarty_{$type}filter_{$name}"; - if (isset($this->smarty->registered_filters[$type][$_filter_name])) { - unset ($this->smarty->registered_filters[$type][$_filter_name]); - } - - return $this; - } - - /** - * preg_replace callback to convert camelcase getter/setter to underscore property names - * - * @param string $match match string - * @return string replacemant - */ - private function replaceCamelcase($match) { - return "_" . strtolower($match[1]); - } - - /** - * Handle unknown class methods - * - * @param string $name unknown method-name - * @param array $args argument array - */ - public function __call($name, $args) - { - static $_prefixes = array('set' => true, 'get' => true); - static $_resolved_property_name = array(); - static $_resolved_property_source = array(); - - // method of Smarty object? - if (method_exists($this->smarty, $name)) { - return call_user_func_array(array($this->smarty, $name), $args); - } - // see if this is a set/get for a property - $first3 = strtolower(substr($name, 0, 3)); - if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') { - if (isset($_resolved_property_name[$name])) { - $property_name = $_resolved_property_name[$name]; - } else { - // try to keep case correct for future PHP 6.0 case-sensitive class methods - // lcfirst() not available < PHP 5.3.0, so improvise - $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); - // convert camel case to underscored name - $property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name); - $_resolved_property_name[$name] = $property_name; - } - if (isset($_resolved_property_source[$property_name])) { - $_is_this = $_resolved_property_source[$property_name]; - } else { - $_is_this = null; - if (property_exists($this, $property_name)) { - $_is_this = true; - } else if (property_exists($this->smarty, $property_name)) { - $_is_this = false; - } - $_resolved_property_source[$property_name] = $_is_this; - } - if ($_is_this) { - if ($first3 == 'get') - return $this->$property_name; - else - return $this->$property_name = $args[0]; - } else if ($_is_this === false) { - if ($first3 == 'get') - return $this->smarty->$property_name; - else - return $this->smarty->$property_name = $args[0]; - } else { - throw new SmartyException("property '$property_name' does not exist."); - return false; - } - } - if ($name == 'Smarty') { - throw new SmartyException("PHP5 requires you to call __construct() instead of Smarty()"); - } - // must be unknown - throw new SmartyException("Call of unknown method '$name'."); - } - -} - +template_class) { + $template = $this; + } + if (!empty($cache_id) && is_object($cache_id)) { + $parent = $cache_id; + $cache_id = null; + } + if ($parent === null && ($this instanceof Smarty || is_string($template))) { + $parent = $this; + } + // create template object if necessary + $_template = ($template instanceof $this->template_class) + ? $template + : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); + // if called by Smarty object make sure we use current caching status + if ($this instanceof Smarty) { + $_template->caching = $this->caching; + } + // merge all variable scopes into template + if ($merge_tpl_vars) { + // save local variables + $save_tpl_vars = $_template->tpl_vars; + $save_config_vars = $_template->config_vars; + $ptr_array = array($_template); + $ptr = $_template; + while (isset($ptr->parent)) { + $ptr_array[] = $ptr = $ptr->parent; + } + $ptr_array = array_reverse($ptr_array); + $parent_ptr = reset($ptr_array); + $tpl_vars = $parent_ptr->tpl_vars; + $config_vars = $parent_ptr->config_vars; + while ($parent_ptr = next($ptr_array)) { + if (!empty($parent_ptr->tpl_vars)) { + $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars); + } + if (!empty($parent_ptr->config_vars)) { + $config_vars = array_merge($config_vars, $parent_ptr->config_vars); + } + } + if (!empty(Smarty::$global_tpl_vars)) { + $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars); + } + $_template->tpl_vars = $tpl_vars; + $_template->config_vars = $config_vars; + } + // dummy local smarty variable + if (!isset($_template->tpl_vars['smarty'])) { + $_template->tpl_vars['smarty'] = new Smarty_Variable; + } + if (isset($this->smarty->error_reporting)) { + $_smarty_old_error_level = error_reporting($this->smarty->error_reporting); + } + // check URL debugging control + if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') { + if (isset($_SERVER['QUERY_STRING'])) { + $_query_string = $_SERVER['QUERY_STRING']; + } else { + $_query_string = ''; + } + if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) { + if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) { + // enable debugging for this browser session + setcookie('SMARTY_DEBUG', true); + $this->smarty->debugging = true; + } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) { + // disable debugging for this browser session + setcookie('SMARTY_DEBUG', false); + $this->smarty->debugging = false; + } else { + // enable debugging for this page + $this->smarty->debugging = true; + } + } else { + if (isset($_COOKIE['SMARTY_DEBUG'])) { + $this->smarty->debugging = true; + } + } + } + // must reset merge template date + $_template->smarty->merged_templates_func = array(); + // get rendered template + // disable caching for evaluated code + if ($_template->source->recompiled) { + $_template->caching = false; + } + // checks if template exists + if (!$_template->source->exists) { + if ($_template->parent instanceof Smarty_Internal_Template) { + $parent_resource = " in '{$_template->parent->template_resource}'"; + } else { + $parent_resource = ''; + } + throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}"); + } + // read from cache or render + if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) { + // render template (not loaded and not in cache) + if (!$_template->source->uncompiled) { + $_smarty_tpl = $_template; + if ($_template->source->recompiled) { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_compile($_template); + } + $code = $_template->compiler->compileTemplate($_template); + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_compile($_template); + } + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_render($_template); + } + try { + ob_start(); + eval("?>" . $code); + unset($code); + } catch (Exception $e) { + ob_get_clean(); + throw $e; + } + } else { + if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) { + $_template->compileTemplateSource(); + } + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_render($_template); + } + if (!$_template->compiled->loaded) { + include($_template->compiled->filepath); + if ($_template->mustCompile) { + // recompile and load again + $_template->compileTemplateSource(); + include($_template->compiled->filepath); + } + $_template->compiled->loaded = true; + } else { + $_template->decodeProperties($_template->compiled->_properties, false); + } + try { + ob_start(); + if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) { + throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'"); + } + array_unshift($_template->_capture_stack,array()); + // + // render compiled template + // + $_template->properties['unifunc']($_template); + // any unclosed {capture} tags ? + if (isset($_template->_capture_stack[0][0])) { + $_template->capture_error(); + } + array_shift($_template->_capture_stack); + } catch (Exception $e) { + ob_get_clean(); + throw $e; + } + } + } else { + if ($_template->source->uncompiled) { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_render($_template); + } + try { + ob_start(); + $_template->source->renderUncompiled($_template); + } catch (Exception $e) { + ob_get_clean(); + throw $e; + } + } else { + throw new SmartyException("Resource '$_template->source->type' must have 'renderUncompiled' method"); + } + } + $_output = ob_get_clean(); + if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) { + $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type); + } + if ($_template->parent instanceof Smarty_Internal_Template) { + $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']); + foreach ($_template->required_plugins as $code => $tmp1) { + foreach ($tmp1 as $name => $tmp) { + foreach ($tmp as $type => $data) { + $_template->parent->required_plugins[$code][$name][$type] = $data; + } + } + } + } + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_render($_template); + } + // write to cache when nessecary + if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_cache($_template); + } + $_template->properties['has_nocache_code'] = false; + // get text between non-cached items + $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output); + // get non-cached items + preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts); + $output = ''; + // loop over items, stitch back together + foreach ($cache_split as $curr_idx => $curr_split) { + // escape PHP tags in template content + $output .= preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '', $curr_split); + if (isset($cache_parts[0][$curr_idx])) { + $_template->properties['has_nocache_code'] = true; + // remove nocache tags from cache output + $output .= preg_replace("!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]); + } + } + if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) { + $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template); + } + // rendering (must be done before writing cache file because of {function} nocache handling) + $_smarty_tpl = $_template; + try { + ob_start(); + eval("?>" . $output); + $_output = ob_get_clean(); + } catch (Exception $e) { + ob_get_clean(); + throw $e; + } + // write cache file content + $_template->writeCachedContent($output); + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_cache($_template); + } + } else { + // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output); + if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) { + // replace nocache_hash + $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output); + $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code; + } + } + } else { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_cache($_template); + } + try { + ob_start(); + array_unshift($_template->_capture_stack,array()); + // + // render cached template + // + $_template->properties['unifunc']($_template); + // any unclosed {capture} tags ? + if (isset($_template->_capture_stack[0][0])) { + $_template->capture_error(); + } + array_shift($_template->_capture_stack); + $_output = ob_get_clean(); + } catch (Exception $e) { + ob_get_clean(); + throw $e; + } + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_cache($_template); + } + } + if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) { + $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template); + } + if (isset($this->error_reporting)) { + error_reporting($_smarty_old_error_level); + } + // display or fetch + if ($display) { + if ($this->caching && $this->cache_modified_check) { + $_isCached = $_template->isCached() && !$_template->has_nocache_code; + $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3); + if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) { + switch (PHP_SAPI) { + case 'cgi': // php-cgi < 5.3 + case 'cgi-fcgi': // php-cgi >= 5.3 + case 'fpm-fcgi': // php-fpm >= 5.3.3 + header('Status: 304 Not Modified'); + break; + + case 'cli': + if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) { + $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified'; + } + break; + + default: + header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified'); + break; + } + } else { + switch (PHP_SAPI) { + case 'cli': + if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) { + $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT'; + } + break; + + default: + header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT'); + break; + } + echo $_output; + } + } else { + echo $_output; + } + // debug output + if ($this->smarty->debugging) { + Smarty_Internal_Debug::display_debug($this); + } + if ($merge_tpl_vars) { + // restore local variables + $_template->tpl_vars = $save_tpl_vars; + $_template->config_vars = $save_config_vars; + } + return; + } else { + if ($merge_tpl_vars) { + // restore local variables + $_template->tpl_vars = $save_tpl_vars; + $_template->config_vars = $save_config_vars; + } + // return fetched content + return $_output; + } + } + + /** + * 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->fetch($template, $cache_id, $compile_id, $parent, true); + } + + /** + * test if cache is valid + * + * @param string|object $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) { + return $this->cached->valid; + } + if (!($template instanceof $this->template_class)) { + if ($parent === null) { + $parent = $this; + } + $template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); + } + // return cache status of template + return $template->cached->valid; + } + + /** + * creates a data object + * + * @param object $parent next higher level of Smarty variables + * @returns Smarty_Data data object + */ + public function createData($parent = null) + { + return new Smarty_Data($parent, $this); + } + + /** + * Registers plugin to be used in templates + * + * @param string $type plugin type + * @param string $tag name of template tag + * @param callback $callback PHP callback to register + * @param boolean $cacheable if true (default) this fuction is cachable + * @param array $cache_attr caching attributes if any + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException when the plugin tag is invalid + */ + public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) + { + if (isset($this->smarty->registered_plugins[$type][$tag])) { + throw new SmartyException("Plugin tag \"{$tag}\" already registered"); + } elseif (!is_callable($callback)) { + throw new SmartyException("Plugin \"{$tag}\" not callable"); + } else { + $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr); + } + + return $this; + } + + /** + * Unregister Plugin + * + * @param string $type of plugin + * @param string $tag name of plugin + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unregisterPlugin($type, $tag) + { + if (isset($this->smarty->registered_plugins[$type][$tag])) { + unset($this->smarty->registered_plugins[$type][$tag]); + } + + return $this; + } + + /** + * Registers a resource to fetch a template + * + * @param string $type name of resource type + * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated) + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function registerResource($type, $callback) + { + $this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false); + return $this; + } + + /** + * Unregisters a resource + * + * @param string $type name of resource type + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unregisterResource($type) + { + if (isset($this->smarty->registered_resources[$type])) { + unset($this->smarty->registered_resources[$type]); + } + + return $this; + } + + /** + * Registers a cache resource to cache a template's output + * + * @param string $type name of cache resource type + * @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function registerCacheResource($type, Smarty_CacheResource $callback) + { + $this->smarty->registered_cache_resources[$type] = $callback; + return $this; + } + + /** + * Unregisters a cache resource + * + * @param string $type name of cache resource type + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unregisterCacheResource($type) + { + if (isset($this->smarty->registered_cache_resources[$type])) { + unset($this->smarty->registered_cache_resources[$type]); + } + + return $this; + } + + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object $object_impl the referenced PHP object to register + * @param array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param array $block_methods list of block-methods + * @param array $block_functs list of methods that are block format + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException if any of the methods in $allowed or $block_methods are invalid + */ + public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + // test if allowed methodes callable + if (!empty($allowed)) { + foreach ((array) $allowed as $method) { + if (!is_callable(array($object_impl, $method))) { + throw new SmartyException("Undefined method '$method' in registered object"); + } + } + } + // test if block methodes callable + if (!empty($block_methods)) { + foreach ((array) $block_methods as $method) { + if (!is_callable(array($object_impl, $method))) { + throw new SmartyException("Undefined method '$method' in registered object"); + } + } + } + // register the object + $this->smarty->registered_objects[$object_name] = + array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods); + return $this; + } + + /** + * return a reference to a registered object + * + * @param string $name object name + * @return object + * @throws SmartyException if no such object is found + */ + public function getRegisteredObject($name) + { + if (!isset($this->smarty->registered_objects[$name])) { + throw new SmartyException("'$name' is not a registered object"); + } + if (!is_object($this->smarty->registered_objects[$name][0])) { + throw new SmartyException("registered '$name' is not an object"); + } + return $this->smarty->registered_objects[$name][0]; + } + + /** + * unregister an object + * + * @param string $name object name + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unregisterObject($name) + { + if (isset($this->smarty->registered_objects[$name])) { + unset($this->smarty->registered_objects[$name]); + } + + return $this; + } + + /** + * Registers static classes to be used in templates + * + * @param string $class name of template class + * @param string $class_impl the referenced PHP class to register + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException if $class_impl does not refer to an existing class + */ + public function registerClass($class_name, $class_impl) + { + // test if exists + if (!class_exists($class_impl)) { + throw new SmartyException("Undefined class '$class_impl' in register template class"); + } + // register the class + $this->smarty->registered_classes[$class_name] = $class_impl; + return $this; + } + + /** + * Registers a default plugin handler + * + * @param callable $callback class/method name + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException if $callback is not callable + */ + public function registerDefaultPluginHandler($callback) + { + if (is_callable($callback)) { + $this->smarty->default_plugin_handler_func = $callback; + } else { + throw new SmartyException("Default plugin handler '$callback' not callable"); + } + + return $this; + } + + /** + * Registers a default template handler + * + * @param callable $callback class/method name + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException if $callback is not callable + */ + public function registerDefaultTemplateHandler($callback) + { + if (is_callable($callback)) { + $this->smarty->default_template_handler_func = $callback; + } else { + throw new SmartyException("Default template handler '$callback' not callable"); + } + + return $this; + } + + /** + * Registers a default template handler + * + * @param callable $callback class/method name + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + * @throws SmartyException if $callback is not callable + */ + public function registerDefaultConfigHandler($callback) + { + if (is_callable($callback)) { + $this->smarty->default_config_handler_func = $callback; + } else { + throw new SmartyException("Default config handler '$callback' not callable"); + } + + return $this; + } + + /** + * Registers a filter function + * + * @param string $type filter type + * @param callback $callback + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function registerFilter($type, $callback) + { + $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback; + return $this; + } + + /** + * Unregisters a filter function + * + * @param string $type filter type + * @param callback $callback + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unregisterFilter($type, $callback) + { + $name = $this->_get_filter_name($callback); + if (isset($this->smarty->registered_filters[$type][$name])) { + unset($this->smarty->registered_filters[$type][$name]); + } + + return $this; + } + + /** + * Return internal filter name + * + * @param callback $function_name + * @return string internal filter name + */ + public function _get_filter_name($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]; + } else { + return $function_name; + } + } + + /** + * load a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + * @throws SmartyException if filter could not be loaded + */ + public function loadFilter($type, $name) + { + $_plugin = "smarty_{$type}filter_{$name}"; + $_filter_name = $_plugin; + if ($this->smarty->loadPlugin($_plugin)) { + if (class_exists($_plugin, false)) { + $_plugin = array($_plugin, 'execute'); + } + if (is_callable($_plugin)) { + $this->smarty->registered_filters[$type][$_filter_name] = $_plugin; + return true; + } + } + throw new SmartyException("{$type}filter \"{$name}\" not callable"); + } + + /** + * unload a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining + */ + public function unloadFilter($type, $name) + { + $_filter_name = "smarty_{$type}filter_{$name}"; + if (isset($this->smarty->registered_filters[$type][$_filter_name])) { + unset ($this->smarty->registered_filters[$type][$_filter_name]); + } + + return $this; + } + + /** + * preg_replace callback to convert camelcase getter/setter to underscore property names + * + * @param string $match match string + * @return string replacemant + */ + private function replaceCamelcase($match) { + return "_" . strtolower($match[1]); + } + + /** + * Handle unknown class methods + * + * @param string $name unknown method-name + * @param array $args argument array + */ + public function __call($name, $args) + { + static $_prefixes = array('set' => true, 'get' => true); + static $_resolved_property_name = array(); + static $_resolved_property_source = array(); + + // method of Smarty object? + if (method_exists($this->smarty, $name)) { + return call_user_func_array(array($this->smarty, $name), $args); + } + // see if this is a set/get for a property + $first3 = strtolower(substr($name, 0, 3)); + if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') { + if (isset($_resolved_property_name[$name])) { + $property_name = $_resolved_property_name[$name]; + } else { + // try to keep case correct for future PHP 6.0 case-sensitive class methods + // lcfirst() not available < PHP 5.3.0, so improvise + $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); + // convert camel case to underscored name + $property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name); + $_resolved_property_name[$name] = $property_name; + } + if (isset($_resolved_property_source[$property_name])) { + $_is_this = $_resolved_property_source[$property_name]; + } else { + $_is_this = null; + if (property_exists($this, $property_name)) { + $_is_this = true; + } else if (property_exists($this->smarty, $property_name)) { + $_is_this = false; + } + $_resolved_property_source[$property_name] = $_is_this; + } + if ($_is_this) { + if ($first3 == 'get') + return $this->$property_name; + else + return $this->$property_name = $args[0]; + } else if ($_is_this === false) { + if ($first3 == 'get') + return $this->smarty->$property_name; + else + return $this->smarty->$property_name = $args[0]; + } else { + throw new SmartyException("property '$property_name' does not exist."); + return false; + } + } + if ($name == 'Smarty') { + throw new SmartyException("PHP5 requires you to call __construct() instead of Smarty()"); + } + // must be unknown + throw new SmartyException("Call of unknown method '$name'."); + } + +} + ?> \ No newline at end of file diff --git a/include/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php b/include/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php index 11fc2144d..c745d294d 100644 --- a/include/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/include/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -1,670 +1,670 @@ -nocache_hash = str_replace('.', '-', uniqid(rand(), true)); - } - - /** - * Method to compile a Smarty template - * - * @param Smarty_Internal_Template $template template object to compile - * @return bool true if compiling succeeded, false if it failed - */ - public function compileTemplate(Smarty_Internal_Template $template) { - if (empty($template->properties['nocache_hash'])) { - $template->properties['nocache_hash'] = $this->nocache_hash; - } else { - $this->nocache_hash = $template->properties['nocache_hash']; - } - // flag for nochache sections - $this->nocache = false; - $this->tag_nocache = false; - // save template object in compiler class - $this->template = $template; - // reset has noche code flag - $this->template->has_nocache_code = false; - $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; - // template header code - $template_header = ''; - if (!$this->suppressHeader) { - $template_header .= "template->source->filepath . "\" */ ?>\n"; - } - - do { - // flag for aborting current and start recompile - $this->abort_and_recompile = false; - // get template source - $_content = $template->source->content; - // run prefilter if required - if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { - $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); - } - // on empty template just return header - if ($_content == '') { - if ($this->suppressTemplatePropertyHeader) { - $code = ''; - } else { - $code = $template_header . $template->createTemplateCodeFrame(); - } - return $code; - } - // call compiler - $_compiled_code = $this->doCompile($_content); - } while ($this->abort_and_recompile); - $this->template->source->filepath = $saved_filepath; - // free memory - unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); - self::$_tag_objects = array(); - // return compiled code to template object - $merged_code = ''; - if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { - foreach ($this->merged_templates as $code) { - $merged_code .= $code; - } - // run postfilter if required on merged code - if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { - $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); - } - } - // run postfilter if required on compiled template code - if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { - $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); - } - if ($this->suppressTemplatePropertyHeader) { - $code = $_compiled_code . $merged_code; - } else { - $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; - } - // unset content because template inheritance could have replace source with parent code - unset ($template->source->content); - return $code; - } - - /** - * Compile Tag - * - * This is a call back from the lexer/parser - * It executes the required compile plugin for the Smarty tag - * - * @param string $tag tag name - * @param array $args array with tag attributes - * @param array $parameter array with compilation parameter - * @return string compiled code - */ - public function compileTag($tag, $args, $parameter = array()) { - // $args contains the attributes parsed and compiled by the lexer/parser - // assume that tag does compile into code, but creates no HTML output - $this->has_code = true; - $this->has_output = false; - // log tag/attributes - if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { - $this->template->used_tags[] = array($tag, $args); - } - // check nocache option flag - if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) - || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)) { - $this->tag_nocache = true; - } - // compile the smarty tag (required compile classes to compile the tag are autoloaded) - if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { - if (isset($this->smarty->template_functions[$tag])) { - // template defined by {template} tag - $args['_attr']['name'] = "'" . $tag . "'"; - $_output = $this->callTagCompiler('call', $args, $parameter); - } - } - if ($_output !== false) { - if ($_output !== true) { - // did we get compiled code - if ($this->has_code) { - // Does it create output? - if ($this->has_output) { - $_output .= "\n"; - } - // return compiled code - return $_output; - } - } - // tag did not produce compiled code - return ''; - } else { - // map_named attributes - if (isset($args['_attr'])) { - foreach ($args['_attr'] as $key => $attribute) { - if (is_array($attribute)) { - $args = array_merge($args, $attribute); - } - } - } - // not an internal compiler tag - if (strlen($tag) < 6 || substr($tag, -5) != 'close') { - // check if tag is a registered object - if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) { - $methode = $parameter['object_methode']; - if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) && - (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) { - return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode); - } elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) { - return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); - } else { - return $this->trigger_template_error('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno); - } - } - // check if tag is registered - foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) { - if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) { - // if compiler function plugin call it now - if ($plugin_type == Smarty::PLUGIN_COMPILER) { - $new_args = array(); - foreach ($args as $key => $mixed) { - if (is_array($mixed)) { - $new_args = array_merge($new_args, $mixed); - } else { - $new_args[$key] = $mixed; - } - } - if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) { - $this->tag_nocache = true; - } - $function = $this->smarty->registered_plugins[$plugin_type][$tag][0]; - if (!is_array($function)) { - return $function($new_args, $this); - } else if (is_object($function[0])) { - return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); - } else { - return call_user_func_array($function, array($new_args, $this)); - } - } - // compile registered function or block function - if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { - return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); - } - } - } - // check plugins from plugins folder - foreach ($this->smarty->plugin_search_order as $plugin_type) { - if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))) { - $plugin = 'smarty_compiler_' . $tag; - if (is_callable($plugin)) { - // convert arguments format for old compiler plugins - $new_args = array(); - foreach ($args as $key => $mixed) { - if (is_array($mixed)) { - $new_args = array_merge($new_args, $mixed); - } else { - $new_args[$key] = $mixed; - } - } - return $plugin($new_args, $this->smarty); - } - if (class_exists($plugin, false)) { - $plugin_object = new $plugin; - if (method_exists($plugin_object, 'compile')) { - return $plugin_object->compile($args, $this); - } - } - throw new SmartyException("Plugin \"{$tag}\" not callable"); - } else { - if ($function = $this->getPlugin($tag, $plugin_type)) { - if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { - return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function); - } - } - } - } - if (is_callable($this->smarty->default_plugin_handler_func)) { - $found = false; - // look for already resolved tags - foreach ($this->smarty->plugin_search_order as $plugin_type) { - if (isset($this->default_handler_plugins[$plugin_type][$tag])) { - $found = true; - break; - } - } - if (!$found) { - // call default handler - foreach ($this->smarty->plugin_search_order as $plugin_type) { - if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { - $found = true; - break; - } - } - } - if ($found) { - // if compiler function plugin call it now - if ($plugin_type == Smarty::PLUGIN_COMPILER) { - $new_args = array(); - foreach ($args as $mixed) { - $new_args = array_merge($new_args, $mixed); - } - $function = $this->default_handler_plugins[$plugin_type][$tag][0]; - if (!is_array($function)) { - return $function($new_args, $this); - } else if (is_object($function[0])) { - return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); - } else { - return call_user_func_array($function, array($new_args, $this)); - } - } else { - return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); - } - } - } - } else { - // compile closing tag of block function - $base_tag = substr($tag, 0, -5); - // check if closing tag is a registered object - if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) { - $methode = $parameter['object_methode']; - if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) { - return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); - } else { - return $this->trigger_template_error('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); - } - } - // registered block tag ? - if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) || isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { - return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); - } - // block plugin? - if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { - return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); - } - // registered compiler plugin ? - if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) { - // if compiler function plugin call it now - $args = array(); - if (!$this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][1]) { - $this->tag_nocache = true; - } - $function = $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0]; - if (!is_array($function)) { - return $function($args, $this); - } else if (is_object($function[0])) { - return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args, $this); - } else { - return call_user_func_array($function, array($args, $this)); - } - } - if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { - $plugin = 'smarty_compiler_' . $tag; - if (is_callable($plugin)) { - return $plugin($args, $this->smarty); - } - if (class_exists($plugin, false)) { - $plugin_object = new $plugin; - if (method_exists($plugin_object, 'compile')) { - return $plugin_object->compile($args, $this); - } - } - throw new SmartyException("Plugin \"{$tag}\" not callable"); - } - } - $this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno); - } - } - - /** - * lazy loads internal compile plugin for tag and calls the compile methode - * - * compile objects cached for reuse. - * class name format: Smarty_Internal_Compile_TagName - * plugin filename format: Smarty_Internal_Tagname.php - * - * @param string $tag tag name - * @param array $args list of tag attributes - * @param mixed $param1 optional parameter - * @param mixed $param2 optional parameter - * @param mixed $param3 optional parameter - * @return string compiled code - */ - public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) { - // re-use object if already exists - if (isset(self::$_tag_objects[$tag])) { - // compile this tag - return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); - } - // lazy load internal compiler plugin - $class_name = 'Smarty_Internal_Compile_' . $tag; - if ($this->smarty->loadPlugin($class_name)) { - // check if tag allowed by security - if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { - // use plugin if found - self::$_tag_objects[$tag] = new $class_name; - // compile this tag - return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); - } - } - // no internal compile plugin for this tag - return false; - } - - /** - * Check for plugins and return function name - * - * @param string $pugin_name name of plugin or function - * @param string $plugin_type type of plugin - * @return string call name of function - */ - public function getPlugin($plugin_name, $plugin_type) { - $function = null; - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { - $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; - } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]; - $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; - } - } else { - if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { - $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; - } else if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]; - $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; - } - } - if (isset($function)) { - if ($plugin_type == 'modifier') { - $this->modifier_plugins[$plugin_name] = true; - } - return $function; - } - // loop through plugin dirs and find the plugin - $function = 'smarty_' . $plugin_type . '_' . $plugin_name; - $file = $this->smarty->loadPlugin($function, false); - - if (is_string($file)) { - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file; - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function; - } else { - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file; - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function; - } - if ($plugin_type == 'modifier') { - $this->modifier_plugins[$plugin_name] = true; - } - return $function; - } - if (is_callable($function)) { - // plugin function is defined in the script - return $function; - } - return false; - } - - /** - * Check for plugins by default plugin handler - * - * @param string $tag name of tag - * @param string $plugin_type type of plugin - * @return boolean true if found - */ - public function getPluginFromDefaultHandler($tag, $plugin_type) { - $callback = null; - $script = null; - $cacheable = true; - $result = call_user_func_array( - $this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable) - ); - if ($result) { - $this->tag_nocache = $this->tag_nocache || !$cacheable; - if ($script !== null) { - if (is_file($script)) { - if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - $this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script; - $this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback; - } else { - $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; - $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; - } - include_once $script; - } else { - $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); - } - } - if (!is_string($callback) && !(is_array($callback) && is_string($callback[0]) && is_string($callback[1]))) { - $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name"); - } - if (is_callable($callback)) { - $this->default_handler_plugins[$plugin_type][$tag] = array($callback, true, array()); - return true; - } else { - $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable"); - } - } - return false; - } - - /** - * Inject inline code for nocache template sections - * - * This method gets the content of each template element from the parser. - * If the content is compiled code and it should be not cached the code is injected - * into the rendered output. - * - * @param string $content content of template element - * @param boolean $is_code true if content is compiled code - * @return string content - */ - public function processNocacheCode($content, $is_code) { - // If the template is not evaluated and we have a nocache section and or a nocache tag - if ($is_code && !empty($content)) { - // generate replacement code - if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && - ($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) { - $this->template->has_nocache_code = true; - $_output = addcslashes($content,'\'\\'); - $_output = str_replace("^#^", "'", $_output); - $_output = "nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; - // make sure we include modifer plugins for nocache code - foreach ($this->modifier_plugins as $plugin_name => $dummy) { - if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { - $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; - } - } - } else { - $_output = $content; - } - } else { - $_output = $content; - } - $this->modifier_plugins = array(); - $this->suppressNocacheProcessing = false; - $this->tag_nocache = false; - return $_output; - } - - /** - * display compiler error messages without dying - * - * If parameter $args is empty it is a parser detected syntax error. - * In this case the parser is called to obtain information about expected tokens. - * - * If parameter $args contains a string this is used as error message - * - * @param string $args individual error message or null - * @param string $line line-number - * @throws SmartyCompilerException when an unexpected token is found - */ - public function trigger_template_error($args = null, $line = null) { - // get template source line which has error - if (!isset($line)) { - $line = $this->lex->line; - } - $match = preg_split("/\n/", $this->lex->data); - $error_text = 'Syntax Error in template "' . $this->template->source->filepath . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]))) . '" '; - if (isset($args)) { - // individual error message - $error_text .= $args; - } else { - // expected token from parser - $error_text .= ' - Unexpected "' . $this->lex->value . '"'; - if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { - foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { - $exp_token = $this->parser->yyTokenName[$token]; - if (isset($this->lex->smarty_token_names[$exp_token])) { - // token type from lexer - $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; - } else { - // otherwise internal token name - $expect[] = $this->parser->yyTokenName[$token]; - } - } - $error_text .= ', expected one of: ' . implode(' , ', $expect); - } - } - throw new SmartyCompilerException($error_text); - } - -} - +nocache_hash = str_replace('.', '-', uniqid(rand(), true)); + } + + /** + * Method to compile a Smarty template + * + * @param Smarty_Internal_Template $template template object to compile + * @return bool true if compiling succeeded, false if it failed + */ + public function compileTemplate(Smarty_Internal_Template $template) { + if (empty($template->properties['nocache_hash'])) { + $template->properties['nocache_hash'] = $this->nocache_hash; + } else { + $this->nocache_hash = $template->properties['nocache_hash']; + } + // flag for nochache sections + $this->nocache = false; + $this->tag_nocache = false; + // save template object in compiler class + $this->template = $template; + // reset has noche code flag + $this->template->has_nocache_code = false; + $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; + // template header code + $template_header = ''; + if (!$this->suppressHeader) { + $template_header .= "template->source->filepath . "\" */ ?>\n"; + } + + do { + // flag for aborting current and start recompile + $this->abort_and_recompile = false; + // get template source + $_content = $template->source->content; + // run prefilter if required + if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { + $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); + } + // on empty template just return header + if ($_content == '') { + if ($this->suppressTemplatePropertyHeader) { + $code = ''; + } else { + $code = $template_header . $template->createTemplateCodeFrame(); + } + return $code; + } + // call compiler + $_compiled_code = $this->doCompile($_content); + } while ($this->abort_and_recompile); + $this->template->source->filepath = $saved_filepath; + // free memory + unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); + self::$_tag_objects = array(); + // return compiled code to template object + $merged_code = ''; + if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { + foreach ($this->merged_templates as $code) { + $merged_code .= $code; + } + // run postfilter if required on merged code + if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { + $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); + } + } + // run postfilter if required on compiled template code + if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { + $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); + } + if ($this->suppressTemplatePropertyHeader) { + $code = $_compiled_code . $merged_code; + } else { + $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; + } + // unset content because template inheritance could have replace source with parent code + unset ($template->source->content); + return $code; + } + + /** + * Compile Tag + * + * This is a call back from the lexer/parser + * It executes the required compile plugin for the Smarty tag + * + * @param string $tag tag name + * @param array $args array with tag attributes + * @param array $parameter array with compilation parameter + * @return string compiled code + */ + public function compileTag($tag, $args, $parameter = array()) { + // $args contains the attributes parsed and compiled by the lexer/parser + // assume that tag does compile into code, but creates no HTML output + $this->has_code = true; + $this->has_output = false; + // log tag/attributes + if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { + $this->template->used_tags[] = array($tag, $args); + } + // check nocache option flag + if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) + || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)) { + $this->tag_nocache = true; + } + // compile the smarty tag (required compile classes to compile the tag are autoloaded) + if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { + if (isset($this->smarty->template_functions[$tag])) { + // template defined by {template} tag + $args['_attr']['name'] = "'" . $tag . "'"; + $_output = $this->callTagCompiler('call', $args, $parameter); + } + } + if ($_output !== false) { + if ($_output !== true) { + // did we get compiled code + if ($this->has_code) { + // Does it create output? + if ($this->has_output) { + $_output .= "\n"; + } + // return compiled code + return $_output; + } + } + // tag did not produce compiled code + return ''; + } else { + // map_named attributes + if (isset($args['_attr'])) { + foreach ($args['_attr'] as $key => $attribute) { + if (is_array($attribute)) { + $args = array_merge($args, $attribute); + } + } + } + // not an internal compiler tag + if (strlen($tag) < 6 || substr($tag, -5) != 'close') { + // check if tag is a registered object + if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_methode'])) { + $methode = $parameter['object_methode']; + if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) && + (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) { + return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $methode); + } elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) { + return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); + } else { + return $this->trigger_template_error('unallowed methode "' . $methode . '" in registered object "' . $tag . '"', $this->lex->taglineno); + } + } + // check if tag is registered + foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) { + if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) { + // if compiler function plugin call it now + if ($plugin_type == Smarty::PLUGIN_COMPILER) { + $new_args = array(); + foreach ($args as $key => $mixed) { + if (is_array($mixed)) { + $new_args = array_merge($new_args, $mixed); + } else { + $new_args[$key] = $mixed; + } + } + if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) { + $this->tag_nocache = true; + } + $function = $this->smarty->registered_plugins[$plugin_type][$tag][0]; + if (!is_array($function)) { + return $function($new_args, $this); + } else if (is_object($function[0])) { + return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); + } else { + return call_user_func_array($function, array($new_args, $this)); + } + } + // compile registered function or block function + if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { + return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); + } + } + } + // check plugins from plugins folder + foreach ($this->smarty->plugin_search_order as $plugin_type) { + if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))) { + $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + // convert arguments format for old compiler plugins + $new_args = array(); + foreach ($args as $key => $mixed) { + if (is_array($mixed)) { + $new_args = array_merge($new_args, $mixed); + } else { + $new_args[$key] = $mixed; + } + } + return $plugin($new_args, $this->smarty); + } + if (class_exists($plugin, false)) { + $plugin_object = new $plugin; + if (method_exists($plugin_object, 'compile')) { + return $plugin_object->compile($args, $this); + } + } + throw new SmartyException("Plugin \"{$tag}\" not callable"); + } else { + if ($function = $this->getPlugin($tag, $plugin_type)) { + if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { + return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function); + } + } + } + } + if (is_callable($this->smarty->default_plugin_handler_func)) { + $found = false; + // look for already resolved tags + foreach ($this->smarty->plugin_search_order as $plugin_type) { + if (isset($this->default_handler_plugins[$plugin_type][$tag])) { + $found = true; + break; + } + } + if (!$found) { + // call default handler + foreach ($this->smarty->plugin_search_order as $plugin_type) { + if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { + $found = true; + break; + } + } + } + if ($found) { + // if compiler function plugin call it now + if ($plugin_type == Smarty::PLUGIN_COMPILER) { + $new_args = array(); + foreach ($args as $mixed) { + $new_args = array_merge($new_args, $mixed); + } + $function = $this->default_handler_plugins[$plugin_type][$tag][0]; + if (!is_array($function)) { + return $function($new_args, $this); + } else if (is_object($function[0])) { + return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); + } else { + return call_user_func_array($function, array($new_args, $this)); + } + } else { + return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); + } + } + } + } else { + // compile closing tag of block function + $base_tag = substr($tag, 0, -5); + // check if closing tag is a registered object + if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_methode'])) { + $methode = $parameter['object_methode']; + if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) { + return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $methode); + } else { + return $this->trigger_template_error('unallowed closing tag methode "' . $methode . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); + } + } + // registered block tag ? + if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) || isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) { + return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); + } + // block plugin? + if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { + return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); + } + // registered compiler plugin ? + if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) { + // if compiler function plugin call it now + $args = array(); + if (!$this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][1]) { + $this->tag_nocache = true; + } + $function = $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0]; + if (!is_array($function)) { + return $function($args, $this); + } else if (is_object($function[0])) { + return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args, $this); + } else { + return call_user_func_array($function, array($args, $this)); + } + } + if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { + $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + return $plugin($args, $this->smarty); + } + if (class_exists($plugin, false)) { + $plugin_object = new $plugin; + if (method_exists($plugin_object, 'compile')) { + return $plugin_object->compile($args, $this); + } + } + throw new SmartyException("Plugin \"{$tag}\" not callable"); + } + } + $this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno); + } + } + + /** + * lazy loads internal compile plugin for tag and calls the compile methode + * + * compile objects cached for reuse. + * class name format: Smarty_Internal_Compile_TagName + * plugin filename format: Smarty_Internal_Tagname.php + * + * @param string $tag tag name + * @param array $args list of tag attributes + * @param mixed $param1 optional parameter + * @param mixed $param2 optional parameter + * @param mixed $param3 optional parameter + * @return string compiled code + */ + public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) { + // re-use object if already exists + if (isset(self::$_tag_objects[$tag])) { + // compile this tag + return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); + } + // lazy load internal compiler plugin + $class_name = 'Smarty_Internal_Compile_' . $tag; + if ($this->smarty->loadPlugin($class_name)) { + // check if tag allowed by security + if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { + // use plugin if found + self::$_tag_objects[$tag] = new $class_name; + // compile this tag + return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); + } + } + // no internal compile plugin for this tag + return false; + } + + /** + * Check for plugins and return function name + * + * @param string $pugin_name name of plugin or function + * @param string $plugin_type type of plugin + * @return string call name of function + */ + public function getPlugin($plugin_name, $plugin_type) { + $function = null; + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { + $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; + } else if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { + $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]; + $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; + } + } else { + if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { + $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; + } else if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { + $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]; + $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; + } + } + if (isset($function)) { + if ($plugin_type == 'modifier') { + $this->modifier_plugins[$plugin_name] = true; + } + return $function; + } + // loop through plugin dirs and find the plugin + $function = 'smarty_' . $plugin_type . '_' . $plugin_name; + $file = $this->smarty->loadPlugin($function, false); + + if (is_string($file)) { + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file; + $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function; + } else { + $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file; + $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function; + } + if ($plugin_type == 'modifier') { + $this->modifier_plugins[$plugin_name] = true; + } + return $function; + } + if (is_callable($function)) { + // plugin function is defined in the script + return $function; + } + return false; + } + + /** + * Check for plugins by default plugin handler + * + * @param string $tag name of tag + * @param string $plugin_type type of plugin + * @return boolean true if found + */ + public function getPluginFromDefaultHandler($tag, $plugin_type) { + $callback = null; + $script = null; + $cacheable = true; + $result = call_user_func_array( + $this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable) + ); + if ($result) { + $this->tag_nocache = $this->tag_nocache || !$cacheable; + if ($script !== null) { + if (is_file($script)) { + if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { + $this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script; + $this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback; + } else { + $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; + $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; + } + include_once $script; + } else { + $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found"); + } + } + if (!is_string($callback) && !(is_array($callback) && is_string($callback[0]) && is_string($callback[1]))) { + $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name"); + } + if (is_callable($callback)) { + $this->default_handler_plugins[$plugin_type][$tag] = array($callback, true, array()); + return true; + } else { + $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable"); + } + } + return false; + } + + /** + * Inject inline code for nocache template sections + * + * This method gets the content of each template element from the parser. + * If the content is compiled code and it should be not cached the code is injected + * into the rendered output. + * + * @param string $content content of template element + * @param boolean $is_code true if content is compiled code + * @return string content + */ + public function processNocacheCode($content, $is_code) { + // If the template is not evaluated and we have a nocache section and or a nocache tag + if ($is_code && !empty($content)) { + // generate replacement code + if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && + ($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) { + $this->template->has_nocache_code = true; + $_output = addcslashes($content,'\'\\'); + $_output = str_replace("^#^", "'", $_output); + $_output = "nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; + // make sure we include modifer plugins for nocache code + foreach ($this->modifier_plugins as $plugin_name => $dummy) { + if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { + $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; + } + } + } else { + $_output = $content; + } + } else { + $_output = $content; + } + $this->modifier_plugins = array(); + $this->suppressNocacheProcessing = false; + $this->tag_nocache = false; + return $_output; + } + + /** + * display compiler error messages without dying + * + * If parameter $args is empty it is a parser detected syntax error. + * In this case the parser is called to obtain information about expected tokens. + * + * If parameter $args contains a string this is used as error message + * + * @param string $args individual error message or null + * @param string $line line-number + * @throws SmartyCompilerException when an unexpected token is found + */ + public function trigger_template_error($args = null, $line = null) { + // get template source line which has error + if (!isset($line)) { + $line = $this->lex->line; + } + $match = preg_split("/\n/", $this->lex->data); + $error_text = 'Syntax Error in template "' . $this->template->source->filepath . '" on line ' . $line . ' "' . htmlspecialchars(trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]))) . '" '; + if (isset($args)) { + // individual error message + $error_text .= $args; + } else { + // expected token from parser + $error_text .= ' - Unexpected "' . $this->lex->value . '"'; + if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { + foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { + $exp_token = $this->parser->yyTokenName[$token]; + if (isset($this->lex->smarty_token_names[$exp_token])) { + // token type from lexer + $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; + } else { + // otherwise internal token name + $expect[] = $this->parser->yyTokenName[$token]; + } + } + $error_text .= ', expected one of: ' . implode(' , ', $expect); + } + } + throw new SmartyCompilerException($error_text); + } + +} + ?> \ No newline at end of file -- cgit v1.2.3