From 3d4d35f4d725a94f5f3186aed11dc25b4fe93de3 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Thu, 13 Mar 2014 20:32:39 +0000 Subject: [PATCH 01/17] - bugfix clearXxx() change of 27.1.2014 did not work when specifing cache_id or compile_id (forum topic 24868 and 24867) --- change_log.txt | 3 +++ libs/sysplugins/smarty_internal_cacheresource_file.php | 2 +- libs/sysplugins/smarty_internal_utility.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/change_log.txt b/change_log.txt index 64fd1f87..c80eaeb3 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 13.03.2014 + - bugfix clearXxx() change of 27.1.2014 did not work when specifing cache_id or compile_id (forum topic 24868 and 24867) + ===== 3.1.17 ===== 08.03.2014 - bugfix relative file path {include} within {block} of child templates did throw exception on first call (Issue 177) diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index ad728340..1b51d8ce 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -139,7 +139,7 @@ $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; $_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0; - $_dir = realpath($smarty->getCacheDir()); + $_dir = realpath($smarty->getCacheDir()) . '/'; $_dir_length = strlen($_dir); if (isset($_cache_id)) { $_cache_id_parts = explode('|', $_cache_id); diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 55509ded..5bd881cb 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -182,7 +182,7 @@ class Smarty_Internal_Utility */ public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty) { - $_compile_dir = realpath($smarty->getCompileDir()); + $_compile_dir = realpath($smarty->getCompileDir()).'/'; $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; if (isset($resource_name)) { From ad62b0b2f8afde3d665315664a6b4e522162baab Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sat, 15 Mar 2014 21:43:04 +0000 Subject: [PATCH 02/17] - bugfix Smarty_CacheResource_Keyvaluestore did use different keys on read/writes and clearCache() calls (Issue 169) --- change_log.txt | 3 +++ libs/sysplugins/smarty_cacheresource_keyvaluestore.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index c80eaeb3..bad241da 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 15.03.2014 + - bugfix Smarty_CacheResource_Keyvaluestore did use different keys on read/writes and clearCache() calls (Issue 169) + 13.03.2014 - bugfix clearXxx() change of 27.1.2014 did not work when specifing cache_id or compile_id (forum topic 24868 and 24867) diff --git a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php index 0b927aab..1c7c7814 100644 --- a/libs/sysplugins/smarty_cacheresource_keyvaluestore.php +++ b/libs/sysplugins/smarty_cacheresource_keyvaluestore.php @@ -54,7 +54,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) { $cached->filepath = $_template->source->uid - . '#' . $this->sanitize($cached->source->name) + . '#' . $this->sanitize($cached->source->resource) . '#' . $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); From 45fc4cd7294bb2a209cf0df2ed951397950c4835 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Mon, 17 Mar 2014 19:04:48 +0000 Subject: [PATCH 03/17] - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) --- change_log.txt | 3 ++ .../smarty_internal_templatelexer.php | 54 +++++++++---------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/change_log.txt b/change_log.txt index bad241da..10426670 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 17.03.2014 + - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) + 15.03.2014 - bugfix Smarty_CacheResource_Keyvaluestore did use different keys on read/writes and clearCache() calls (Issue 169) diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 1661166d..82a00fab 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -230,7 +230,7 @@ class Smarty_Internal_Templatelexer function yy_r1_4($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_STRIPON; @@ -239,7 +239,7 @@ class Smarty_Internal_Templatelexer function yy_r1_5($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; @@ -248,7 +248,7 @@ class Smarty_Internal_Templatelexer function yy_r1_6($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; @@ -258,7 +258,7 @@ class Smarty_Internal_Templatelexer function yy_r1_7($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELIF; @@ -269,7 +269,7 @@ class Smarty_Internal_Templatelexer function yy_r1_9($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; @@ -280,7 +280,7 @@ class Smarty_Internal_Templatelexer function yy_r1_10($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; @@ -291,7 +291,7 @@ class Smarty_Internal_Templatelexer function yy_r1_11($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; @@ -302,7 +302,7 @@ class Smarty_Internal_Templatelexer function yy_r1_12($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; @@ -313,7 +313,7 @@ class Smarty_Internal_Templatelexer function yy_r1_13($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; @@ -811,7 +811,7 @@ class Smarty_Internal_Templatelexer function yy_r2_70($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELIF; @@ -822,7 +822,7 @@ class Smarty_Internal_Templatelexer function yy_r2_72($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; @@ -833,7 +833,7 @@ class Smarty_Internal_Templatelexer function yy_r2_73($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; @@ -844,7 +844,7 @@ class Smarty_Internal_Templatelexer function yy_r2_74($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; @@ -855,7 +855,7 @@ class Smarty_Internal_Templatelexer function yy_r2_75($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; @@ -938,7 +938,7 @@ class Smarty_Internal_Templatelexer function yy_r3_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; @@ -948,7 +948,7 @@ class Smarty_Internal_Templatelexer function yy_r3_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; @@ -1074,7 +1074,7 @@ class Smarty_Internal_Templatelexer function yy_r4_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELIF; @@ -1085,7 +1085,7 @@ class Smarty_Internal_Templatelexer function yy_r4_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; @@ -1096,7 +1096,7 @@ class Smarty_Internal_Templatelexer function yy_r4_4($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; @@ -1107,7 +1107,7 @@ class Smarty_Internal_Templatelexer function yy_r4_5($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; @@ -1118,7 +1118,7 @@ class Smarty_Internal_Templatelexer function yy_r4_6($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_TEXT; } else { $this->token = Smarty_Internal_Templateparser::TP_LDEL; @@ -1236,7 +1236,7 @@ class Smarty_Internal_Templatelexer function yy_r5_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { return false; } else { $this->token = Smarty_Internal_Templateparser::TP_STRIPON; @@ -1245,7 +1245,7 @@ class Smarty_Internal_Templatelexer function yy_r5_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { return false; } else { $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; @@ -1254,7 +1254,7 @@ class Smarty_Internal_Templatelexer function yy_r5_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { return false; } else { $this->yypopstate(); @@ -1346,7 +1346,7 @@ class Smarty_Internal_Templatelexer function yy_r6_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; } else { $this->yypopstate(); @@ -1356,7 +1356,7 @@ class Smarty_Internal_Templatelexer function yy_r6_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; } else { $this->yypopstate(); @@ -1366,7 +1366,7 @@ class Smarty_Internal_Templatelexer function yy_r6_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; } else { $this->yypopstate(); From d82d54bffdfc7b1053df5898f0b62dabca70a15f Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Mon, 17 Mar 2014 21:57:15 +0000 Subject: [PATCH 04/17] fix line endings --- libs/sysplugins/smarty_internal_parsetree.php | 786 ++++---- .../smarty_internal_templatebase.php | 1644 ++++++++-------- .../smarty_internal_templatecompilerbase.php | 1618 ++++++++-------- libs/sysplugins/smarty_internal_utility.php | 1646 ++++++++--------- 4 files changed, 2847 insertions(+), 2847 deletions(-) diff --git a/libs/sysplugins/smarty_internal_parsetree.php b/libs/sysplugins/smarty_internal_parsetree.php index 03518657..10920b90 100644 --- a/libs/sysplugins/smarty_internal_parsetree.php +++ b/libs/sysplugins/smarty_internal_parsetree.php @@ -1,393 +1,393 @@ -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', ++Smarty_Internal_Templateparser::$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', ++Smarty_Internal_Templateparser::$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; + } + +} diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 7447940b..4720716f 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -1,822 +1,822 @@ -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) { - $code = $_template->compiler->compileTemplate($_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(); - $code = file_get_contents($_template->compiled->filepath); - eval("?>" . $code); - unset($code); - $_template->compiled->loaded = true; - $_template->compiled->isCompiled = true; - } - 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(); - $code = file_get_contents($_template->compiled->filepath); - eval("?>" . $code); - unset($code); - $_template->compiled->isCompiled = true; - } - $_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|<\?|\?>)/', "\n", $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($_template); - } - 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)) && !property_exists($object_impl, $method)) { - throw new SmartyException("Undefined method or property '$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; - } elseif (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]; - } elseif ($_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) { + $code = $_template->compiler->compileTemplate($_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(); + $code = file_get_contents($_template->compiled->filepath); + eval("?>" . $code); + unset($code); + $_template->compiled->loaded = true; + $_template->compiled->isCompiled = true; + } + 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(); + $code = file_get_contents($_template->compiled->filepath); + eval("?>" . $code); + unset($code); + $_template->compiled->isCompiled = true; + } + $_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|<\?|\?>)/', "\n", $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($_template); + } + 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)) && !property_exists($object_impl, $method)) { + throw new SmartyException("Undefined method or property '$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; + } elseif (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]; + } elseif ($_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'."); + } + +} diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index fcfb25ef..fa5de5e9 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -1,809 +1,809 @@ -nocache_hash = str_replace(array('.',','), '-', uniqid(rand(), true)); - } - - /** - * Method to compile a Smarty template - * - * @param Smarty_Internal_Template $template template object to compile - * @param bool $nocache true is shall be compiled in nocache mode - * @return bool true if compiling succeeded, false if it failed - */ - public function compileTemplate(Smarty_Internal_Template $template, $nocache = false) - { - 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 = $nocache; - $this->tag_nocache = false; - // save template object in compiler class - $this->template = $template; - // reset has nocache code flag - $this->template->has_nocache_code = false; - $save_source = $this->template->source; - // template header code - $template_header = ''; - if (!$this->suppressHeader) { - $template_header .= "template->source->filepath . "\" */ ?>\n"; - } - - if (empty($this->template->source->components)) { - $this->sources = array($template->source); - } else { - // we have array of inheritance templates by extends: resource - $this->sources = array_reverse($template->source->components); - } - $loop = 0; - // the $this->sources array can get additional elements while compiling by the {extends} tag - while ($this->template->source = array_shift($this->sources)) { - $this->smarty->_current_file = $this->template->source->filepath; - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_compile($this->template); - } - $no_sources = count($this->sources); - if ($loop || $no_sources) { - $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); - } - $loop++; - if ($no_sources) { - $this->inheritance_child = true; - } else { - $this->inheritance_child = false; - } - do { - $_compiled_code = ''; - // flag for aborting current and start recompile - $this->abort_and_recompile = false; - // get template source - $_content = $this->template->source->content; - if ($_content != '') { - // run prefilter if required - if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { - $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); - } - // call compiler - $_compiled_code = $this->doCompile($_content); - } - } while ($this->abort_and_recompile); - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_compile($this->template); - } - } - // restore source - $this->template->source = $save_source; - unset($save_source); - $this->smarty->_current_file = $this->template->source->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 compiled template code - if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { - $_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 null; - } 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); - } elseif (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_COMPILER && $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); - } elseif (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); - } elseif (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']; - } elseif (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']; - } elseif (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->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 modifier 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; - } - - /** - * push current file and line offset on stack for tracing {block} source lines - * - * @param string $file new filename - * @param string $uid uid of file - * @param string $debug false debug end_compile shall not be called - * @param int $line line offset to source - */ - public function pushTrace($file, $uid, $line, $debug = true) - { - if ($this->smarty->debugging && $debug) { - Smarty_Internal_Debug::end_compile($this->template); - } - array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset)); - $this->trace_filepath = $this->smarty->_current_file = $file; - $this->trace_uid = $uid; - $this->trace_line_offset = $line ; - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_compile($this->template); - } - } - - /** - * restore file and line offset - * - */ - public function popTrace() - { - if ($this->smarty->debugging) { - Smarty_Internal_Debug::end_compile($this->template); - } - $r = array_pop($this->trace_stack); - $this->smarty->_current_file = $r[0]; - $this->trace_filepath = $r[1]; - $this->trace_uid = $r[2]; - $this->trace_line_offset = $r[3]; - if ($this->smarty->debugging) { - Smarty_Internal_Debug::start_compile($this->template); - } - } - - /** - * 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; - } -// $line += $this->trace_line_offset; - $match = preg_split("/\n/", $this->lex->data); - $error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . 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); - } - } - $e = new SmartyCompilerException($error_text); - $e->line = $line; - $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); - $e->desc = $args; - $e->template = $this->template->source->filepath; - throw $e; - } - -} +nocache_hash = str_replace(array('.',','), '-', uniqid(rand(), true)); + } + + /** + * Method to compile a Smarty template + * + * @param Smarty_Internal_Template $template template object to compile + * @param bool $nocache true is shall be compiled in nocache mode + * @return bool true if compiling succeeded, false if it failed + */ + public function compileTemplate(Smarty_Internal_Template $template, $nocache = false) + { + 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 = $nocache; + $this->tag_nocache = false; + // save template object in compiler class + $this->template = $template; + // reset has nocache code flag + $this->template->has_nocache_code = false; + $save_source = $this->template->source; + // template header code + $template_header = ''; + if (!$this->suppressHeader) { + $template_header .= "template->source->filepath . "\" */ ?>\n"; + } + + if (empty($this->template->source->components)) { + $this->sources = array($template->source); + } else { + // we have array of inheritance templates by extends: resource + $this->sources = array_reverse($template->source->components); + } + $loop = 0; + // the $this->sources array can get additional elements while compiling by the {extends} tag + while ($this->template->source = array_shift($this->sources)) { + $this->smarty->_current_file = $this->template->source->filepath; + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_compile($this->template); + } + $no_sources = count($this->sources); + if ($loop || $no_sources) { + $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); + } + $loop++; + if ($no_sources) { + $this->inheritance_child = true; + } else { + $this->inheritance_child = false; + } + do { + $_compiled_code = ''; + // flag for aborting current and start recompile + $this->abort_and_recompile = false; + // get template source + $_content = $this->template->source->content; + if ($_content != '') { + // run prefilter if required + if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { + $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); + } + // call compiler + $_compiled_code = $this->doCompile($_content); + } + } while ($this->abort_and_recompile); + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_compile($this->template); + } + } + // restore source + $this->template->source = $save_source; + unset($save_source); + $this->smarty->_current_file = $this->template->source->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 compiled template code + if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { + $_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 null; + } 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); + } elseif (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_COMPILER && $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); + } elseif (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); + } elseif (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']; + } elseif (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']; + } elseif (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->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 modifier 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; + } + + /** + * push current file and line offset on stack for tracing {block} source lines + * + * @param string $file new filename + * @param string $uid uid of file + * @param string $debug false debug end_compile shall not be called + * @param int $line line offset to source + */ + public function pushTrace($file, $uid, $line, $debug = true) + { + if ($this->smarty->debugging && $debug) { + Smarty_Internal_Debug::end_compile($this->template); + } + array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset)); + $this->trace_filepath = $this->smarty->_current_file = $file; + $this->trace_uid = $uid; + $this->trace_line_offset = $line ; + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_compile($this->template); + } + } + + /** + * restore file and line offset + * + */ + public function popTrace() + { + if ($this->smarty->debugging) { + Smarty_Internal_Debug::end_compile($this->template); + } + $r = array_pop($this->trace_stack); + $this->smarty->_current_file = $r[0]; + $this->trace_filepath = $r[1]; + $this->trace_uid = $r[2]; + $this->trace_line_offset = $r[3]; + if ($this->smarty->debugging) { + Smarty_Internal_Debug::start_compile($this->template); + } + } + + /** + * 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; + } +// $line += $this->trace_line_offset; + $match = preg_split("/\n/", $this->lex->data); + $error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . 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); + } + } + $e = new SmartyCompilerException($error_text); + $e->line = $line; + $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); + $e->desc = $args; + $e->template = $this->template->source->filepath; + throw $e; + } + +} diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 5bd881cb..82f200df 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -1,823 +1,823 @@ - - * @author Uwe Tews - * @package Smarty - * @subpackage PluginsInternal - * @version 3-SVN$Rev: 3286 $ - */ - -/** - * Utility class - * - * @package Smarty - * @subpackage Security - */ -class Smarty_Internal_Utility -{ - /** - * private constructor to prevent calls creation of new instances - */ - final private function __construct() - { - // intentionally left blank - } - - /** - * Compile all template files - * - * @param string $extension template file name extension - * @param bool $force_compile force all to recompile - * @param int $time_limit set maximum execution time - * @param int $max_errors set maximum allowed errors - * @param Smarty $smarty Smarty instance - * @return integer number of template files compiled - */ - public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty) - { - // switch off time limit - if (function_exists('set_time_limit')) { - @set_time_limit($time_limit); - } - $smarty->force_compile = $force_compile; - $_count = 0; - $_error_count = 0; - // loop over array of template directories - foreach ($smarty->getTemplateDir() as $_dir) { - $_compileDirs = new RecursiveDirectoryIterator($_dir); - $_compile = new RecursiveIteratorIterator($_compileDirs); - foreach ($_compile as $_fileinfo) { - $_file = $_fileinfo->getFilename(); - if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; - if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue; - if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { - $_template_file = $_file; - } else { - $_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file; - } - echo '
', $_dir, '---', $_template_file; - flush(); - $_start_time = microtime(true); - try { - $_tpl = $smarty->createTemplate($_template_file,null,null,null,false); - if ($_tpl->mustCompile()) { - $_tpl->compileTemplateSource(); - $_count++; - echo ' compiled in ', microtime(true) - $_start_time, ' seconds'; - flush(); - } else { - echo ' is up to date'; - flush(); - } - } catch (Exception $e) { - echo 'Error: ', $e->getMessage(), "

"; - $_error_count++; - } - // free memory - $smarty->template_objects = array(); - $_tpl->smarty->template_objects = array(); - $_tpl = null; - if ($max_errors !== null && $_error_count == $max_errors) { - echo '

too many errors'; - exit(); - } - } - } - - return $_count; - } - - /** - * Compile all config files - * - * @param string $extension config file name extension - * @param bool $force_compile force all to recompile - * @param int $time_limit set maximum execution time - * @param int $max_errors set maximum allowed errors - * @param Smarty $smarty Smarty instance - * @return integer number of config files compiled - */ - public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty) - { - // switch off time limit - if (function_exists('set_time_limit')) { - @set_time_limit($time_limit); - } - $smarty->force_compile = $force_compile; - $_count = 0; - $_error_count = 0; - // loop over array of template directories - foreach ($smarty->getConfigDir() as $_dir) { - $_compileDirs = new RecursiveDirectoryIterator($_dir); - $_compile = new RecursiveIteratorIterator($_compileDirs); - foreach ($_compile as $_fileinfo) { - $_file = $_fileinfo->getFilename(); - if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; - if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue; - if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { - $_config_file = $_file; - } else { - $_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file; - } - echo '
', $_dir, '---', $_config_file; - flush(); - $_start_time = microtime(true); - try { - $_config = new Smarty_Internal_Config($_config_file, $smarty); - if ($_config->mustCompile()) { - $_config->compileConfigSource(); - $_count++; - echo ' compiled in ', microtime(true) - $_start_time, ' seconds'; - flush(); - } else { - echo ' is up to date'; - flush(); - } - } catch (Exception $e) { - echo 'Error: ', $e->getMessage(), "

"; - $_error_count++; - } - if ($max_errors !== null && $_error_count == $max_errors) { - echo '

too many errors'; - exit(); - } - } - } - - return $_count; - } - - /** - * Delete compiled template file - * - * @param string $resource_name template name - * @param string $compile_id compile id - * @param integer $exp_time expiration time - * @param Smarty $smarty Smarty instance - * @return integer number of template files deleted - */ - public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty) - { - $_compile_dir = realpath($smarty->getCompileDir()).'/'; - $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; - $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; - if (isset($resource_name)) { - $_save_stat = $smarty->caching; - $smarty->caching = false; - $tpl = new $smarty->template_class($resource_name, $smarty); - $smarty->caching = $_save_stat; - - // remove from template cache - $tpl->source; // have the template registered before unset() - if ($smarty->allow_ambiguous_resources) { - $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; - } else { - $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; - } - if (isset($_templateId[150])) { - $_templateId = sha1($_templateId); - } - unset($smarty->template_objects[$_templateId]); - - if ($tpl->source->exists) { - $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath)); - $_resource_part_1_length = strlen($_resource_part_1); - } else { - return 0; - } - - $_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1); - $_resource_part_2_length = strlen($_resource_part_2); - } - $_dir = $_compile_dir; - if ($smarty->use_sub_dirs && isset($_compile_id)) { - $_dir .= $_compile_id . $_dir_sep; - } - if (isset($_compile_id)) { - $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep; - $_compile_id_part_length = strlen($_compile_id_part); - } - $_count = 0; - try { - $_compileDirs = new RecursiveDirectoryIterator($_dir); - // NOTE: UnexpectedValueException thrown for PHP >= 5.3 - } catch (Exception $e) { - return 0; - } - $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); - foreach ($_compile as $_file) { - if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) - continue; - - $_filepath = (string) $_file; - - if ($_file->isDir()) { - if (!$_compile->isDot()) { - // delete folder if empty - @rmdir($_file->getPathname()); - } - } else { - $unlink = false; - if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) - && (!isset($resource_name) - || (isset($_filepath[$_resource_part_1_length]) - && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0) - || (isset($_filepath[$_resource_part_2_length]) - && substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) { - if (isset($exp_time)) { - if (time() - @filemtime($_filepath) >= $exp_time) { - $unlink = true; - } - } else { - $unlink = true; - } - } - - if ($unlink && @unlink($_filepath)) { - $_count++; - } - } - } - // clear compiled cache - Smarty_Resource::$sources = array(); - Smarty_Resource::$compileds = array(); - - return $_count; - } - - /** - * Return array of tag/attributes of all tags used by an template - * - * @param Smarty_Internal_Template $templae template object - * @return array of tag/attributes - */ - public static function getTags(Smarty_Internal_Template $template) - { - $template->smarty->get_used_tags = true; - $template->compileTemplateSource(); - - return $template->used_tags; - } - - /** - * diagnose Smarty setup - * - * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. - * - * @param Smarty $smarty Smarty instance to test - * @param array $errors array to push results into rather than outputting them - * @return bool status, true if everything is fine, false else - */ - public static function testInstall(Smarty $smarty, &$errors=null) - { - $status = true; - - if ($errors === null) { - echo "
\n";
-            echo "Smarty Installation test...\n";
-            echo "Testing template directory...\n";
-        }
-
-        $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
-
-        // test if all registered template_dir are accessible
-        foreach ($smarty->getTemplateDir() as $template_dir) {
-            $_template_dir = $template_dir;
-            $template_dir = realpath($template_dir);
-            // resolve include_path or fail existence
-            if (!$template_dir) {
-                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
-                    // try PHP include_path
-                    if ($_stream_resolve_include_path) {
-                        $template_dir = stream_resolve_include_path($_template_dir);
-                    } else {
-                        $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir);
-                    }
-
-                    if ($template_dir !== false) {
-                        if ($errors === null) {
-                            echo "$template_dir is OK.\n";
-                        }
-
-                        continue;
-                    } else {
-                        $status = false;
-                        $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
-                        if ($errors === null) {
-                            echo $message . ".\n";
-                        } else {
-                            $errors['template_dir'] = $message;
-                        }
-
-                        continue;
-                    }
-                } else {
-                    $status = false;
-                    $message = "FAILED: $_template_dir does not exist";
-                    if ($errors === null) {
-                        echo $message . ".\n";
-                    } else {
-                        $errors['template_dir'] = $message;
-                    }
-
-                    continue;
-                }
-            }
-
-            if (!is_dir($template_dir)) {
-                $status = false;
-                $message = "FAILED: $template_dir is not a directory";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['template_dir'] = $message;
-                }
-            } elseif (!is_readable($template_dir)) {
-                $status = false;
-                $message = "FAILED: $template_dir is not readable";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['template_dir'] = $message;
-                }
-            } else {
-                if ($errors === null) {
-                    echo "$template_dir is OK.\n";
-                }
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing compile directory...\n";
-        }
-
-        // test if registered compile_dir is accessible
-        $__compile_dir = $smarty->getCompileDir();
-        $_compile_dir = realpath($__compile_dir);
-        if (!$_compile_dir) {
-            $status = false;
-            $message = "FAILED: {$__compile_dir} does not exist";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['compile_dir'] = $message;
-            }
-        } elseif (!is_dir($_compile_dir)) {
-            $status = false;
-            $message = "FAILED: {$_compile_dir} is not a directory";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['compile_dir'] = $message;
-            }
-        } elseif (!is_readable($_compile_dir)) {
-            $status = false;
-            $message = "FAILED: {$_compile_dir} is not readable";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['compile_dir'] = $message;
-            }
-        } elseif (!is_writable($_compile_dir)) {
-            $status = false;
-            $message = "FAILED: {$_compile_dir} is not writable";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['compile_dir'] = $message;
-            }
-        } else {
-            if ($errors === null) {
-                echo "{$_compile_dir} is OK.\n";
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing plugins directory...\n";
-        }
-
-        // test if all registered plugins_dir are accessible
-        // and if core plugins directory is still registered
-        $_core_plugins_dir = realpath(dirname(__FILE__) .'/../plugins');
-        $_core_plugins_available = false;
-        foreach ($smarty->getPluginsDir() as $plugin_dir) {
-            $_plugin_dir = $plugin_dir;
-            $plugin_dir = realpath($plugin_dir);
-            // resolve include_path or fail existence
-            if (!$plugin_dir) {
-                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
-                    // try PHP include_path
-                    if ($_stream_resolve_include_path) {
-                        $plugin_dir = stream_resolve_include_path($_plugin_dir);
-                    } else {
-                        $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
-                    }
-
-                    if ($plugin_dir !== false) {
-                        if ($errors === null) {
-                            echo "$plugin_dir is OK.\n";
-                        }
-
-                        continue;
-                    } else {
-                        $status = false;
-                        $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
-                        if ($errors === null) {
-                            echo $message . ".\n";
-                        } else {
-                            $errors['plugins_dir'] = $message;
-                        }
-
-                        continue;
-                    }
-                } else {
-                    $status = false;
-                    $message = "FAILED: $_plugin_dir does not exist";
-                    if ($errors === null) {
-                        echo $message . ".\n";
-                    } else {
-                        $errors['plugins_dir'] = $message;
-                    }
-
-                    continue;
-                }
-            }
-
-            if (!is_dir($plugin_dir)) {
-                $status = false;
-                $message = "FAILED: $plugin_dir is not a directory";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['plugins_dir'] = $message;
-                }
-            } elseif (!is_readable($plugin_dir)) {
-                $status = false;
-                $message = "FAILED: $plugin_dir is not readable";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['plugins_dir'] = $message;
-                }
-            } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
-                $_core_plugins_available = true;
-                if ($errors === null) {
-                    echo "$plugin_dir is OK.\n";
-                }
-            } else {
-                if ($errors === null) {
-                    echo "$plugin_dir is OK.\n";
-                }
-            }
-        }
-        if (!$_core_plugins_available) {
-            $status = false;
-            $message = "WARNING: Smarty's own libs/plugins is not available";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } elseif (!isset($errors['plugins_dir'])) {
-                $errors['plugins_dir'] = $message;
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing cache directory...\n";
-        }
-
-        // test if all registered cache_dir is accessible
-        $__cache_dir = $smarty->getCacheDir();
-        $_cache_dir = realpath($__cache_dir);
-        if (!$_cache_dir) {
-            $status = false;
-            $message = "FAILED: {$__cache_dir} does not exist";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['cache_dir'] = $message;
-            }
-        } elseif (!is_dir($_cache_dir)) {
-            $status = false;
-            $message = "FAILED: {$_cache_dir} is not a directory";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['cache_dir'] = $message;
-            }
-        } elseif (!is_readable($_cache_dir)) {
-            $status = false;
-            $message = "FAILED: {$_cache_dir} is not readable";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['cache_dir'] = $message;
-            }
-        } elseif (!is_writable($_cache_dir)) {
-            $status = false;
-            $message = "FAILED: {$_cache_dir} is not writable";
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['cache_dir'] = $message;
-            }
-        } else {
-            if ($errors === null) {
-                echo "{$_cache_dir} is OK.\n";
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing configs directory...\n";
-        }
-
-        // test if all registered config_dir are accessible
-        foreach ($smarty->getConfigDir() as $config_dir) {
-            $_config_dir = $config_dir;
-            $config_dir = realpath($config_dir);
-            // resolve include_path or fail existence
-            if (!$config_dir) {
-                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
-                    // try PHP include_path
-                    if ($_stream_resolve_include_path) {
-                        $config_dir = stream_resolve_include_path($_config_dir);
-                    } else {
-                        $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir);
-                    }
-
-                    if ($config_dir !== false) {
-                        if ($errors === null) {
-                            echo "$config_dir is OK.\n";
-                        }
-
-                        continue;
-                    } else {
-                        $status = false;
-                        $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
-                        if ($errors === null) {
-                            echo $message . ".\n";
-                        } else {
-                            $errors['config_dir'] = $message;
-                        }
-
-                        continue;
-                    }
-                } else {
-                    $status = false;
-                    $message = "FAILED: $_config_dir does not exist";
-                    if ($errors === null) {
-                        echo $message . ".\n";
-                    } else {
-                        $errors['config_dir'] = $message;
-                    }
-
-                    continue;
-                }
-            }
-
-            if (!is_dir($config_dir)) {
-                $status = false;
-                $message = "FAILED: $config_dir is not a directory";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['config_dir'] = $message;
-                }
-            } elseif (!is_readable($config_dir)) {
-                $status = false;
-                $message = "FAILED: $config_dir is not readable";
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['config_dir'] = $message;
-                }
-            } else {
-                if ($errors === null) {
-                    echo "$config_dir is OK.\n";
-                }
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing sysplugin files...\n";
-        }
-        // test if sysplugins are available
-        $source = SMARTY_SYSPLUGINS_DIR;
-        if (is_dir($source)) {
-            $expected = array(
-                "smarty_cacheresource.php" => true,
-                "smarty_cacheresource_custom.php" => true,
-                "smarty_cacheresource_keyvaluestore.php" => true,
-                "smarty_config_source.php" => true,
-                "smarty_internal_cacheresource_file.php" => true,
-                "smarty_internal_compile_append.php" => true,
-                "smarty_internal_compile_assign.php" => true,
-                "smarty_internal_compile_block.php" => true,
-                "smarty_internal_compile_break.php" => true,
-                "smarty_internal_compile_call.php" => true,
-                "smarty_internal_compile_capture.php" => true,
-                "smarty_internal_compile_config_load.php" => true,
-                "smarty_internal_compile_continue.php" => true,
-                "smarty_internal_compile_debug.php" => true,
-                "smarty_internal_compile_eval.php" => true,
-                "smarty_internal_compile_extends.php" => true,
-                "smarty_internal_compile_for.php" => true,
-                "smarty_internal_compile_foreach.php" => true,
-                "smarty_internal_compile_function.php" => true,
-                "smarty_internal_compile_if.php" => true,
-                "smarty_internal_compile_include.php" => true,
-                "smarty_internal_compile_include_php.php" => true,
-                "smarty_internal_compile_insert.php" => true,
-                "smarty_internal_compile_ldelim.php" => true,
-                "smarty_internal_compile_nocache.php" => true,
-                "smarty_internal_compile_private_block_plugin.php" => true,
-                "smarty_internal_compile_private_function_plugin.php" => true,
-                "smarty_internal_compile_private_modifier.php" => true,
-                "smarty_internal_compile_private_object_block_function.php" => true,
-                "smarty_internal_compile_private_object_function.php" => true,
-                "smarty_internal_compile_private_print_expression.php" => true,
-                "smarty_internal_compile_private_registered_block.php" => true,
-                "smarty_internal_compile_private_registered_function.php" => true,
-                "smarty_internal_compile_private_special_variable.php" => true,
-                "smarty_internal_compile_rdelim.php" => true,
-                "smarty_internal_compile_section.php" => true,
-                "smarty_internal_compile_setfilter.php" => true,
-                "smarty_internal_compile_while.php" => true,
-                "smarty_internal_compilebase.php" => true,
-                "smarty_internal_config.php" => true,
-                "smarty_internal_config_file_compiler.php" => true,
-                "smarty_internal_configfilelexer.php" => true,
-                "smarty_internal_configfileparser.php" => true,
-                "smarty_internal_data.php" => true,
-                "smarty_internal_debug.php" => true,
-                "smarty_internal_filter_handler.php" => true,
-                "smarty_internal_function_call_handler.php" => true,
-                "smarty_internal_get_include_path.php" => true,
-                "smarty_internal_nocache_insert.php" => true,
-                "smarty_internal_parsetree.php" => true,
-                "smarty_internal_resource_eval.php" => true,
-                "smarty_internal_resource_extends.php" => true,
-                "smarty_internal_resource_file.php" => true,
-                "smarty_internal_resource_registered.php" => true,
-                "smarty_internal_resource_stream.php" => true,
-                "smarty_internal_resource_string.php" => true,
-                "smarty_internal_smartytemplatecompiler.php" => true,
-                "smarty_internal_template.php" => true,
-                "smarty_internal_templatebase.php" => true,
-                "smarty_internal_templatecompilerbase.php" => true,
-                "smarty_internal_templatelexer.php" => true,
-                "smarty_internal_templateparser.php" => true,
-                "smarty_internal_utility.php" => true,
-                "smarty_internal_write_file.php" => true,
-                "smarty_resource.php" => true,
-                "smarty_resource_custom.php" => true,
-                "smarty_resource_recompiled.php" => true,
-                "smarty_resource_uncompiled.php" => true,
-                "smarty_security.php" => true,
-            );
-            $iterator = new DirectoryIterator($source);
-            foreach ($iterator as $file) {
-                if (!$file->isDot()) {
-                    $filename = $file->getFilename();
-                    if (isset($expected[$filename])) {
-                        unset($expected[$filename]);
-                    }
-                }
-            }
-            if ($expected) {
-                $status = false;
-                $message = "FAILED: files missing from libs/sysplugins: ". join(', ', array_keys($expected));
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['sysplugins'] = $message;
-                }
-            } elseif ($errors === null) {
-                echo "... OK\n";
-            }
-        } else {
-            $status = false;
-            $message = "FAILED: ". SMARTY_SYSPLUGINS_DIR .' is not a directory';
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['sysplugins_dir_constant'] = $message;
-            }
-        }
-
-        if ($errors === null) {
-            echo "Testing plugin files...\n";
-        }
-        // test if core plugins are available
-        $source = SMARTY_PLUGINS_DIR;
-        if (is_dir($source)) {
-            $expected = array(
-                "block.textformat.php" => true,
-                "function.counter.php" => true,
-                "function.cycle.php" => true,
-                "function.fetch.php" => true,
-                "function.html_checkboxes.php" => true,
-                "function.html_image.php" => true,
-                "function.html_options.php" => true,
-                "function.html_radios.php" => true,
-                "function.html_select_date.php" => true,
-                "function.html_select_time.php" => true,
-                "function.html_table.php" => true,
-                "function.mailto.php" => true,
-                "function.math.php" => true,
-                "modifier.capitalize.php" => true,
-                "modifier.date_format.php" => true,
-                "modifier.debug_print_var.php" => true,
-                "modifier.escape.php" => true,
-                "modifier.regex_replace.php" => true,
-                "modifier.replace.php" => true,
-                "modifier.spacify.php" => true,
-                "modifier.truncate.php" => true,
-                "modifiercompiler.cat.php" => true,
-                "modifiercompiler.count_characters.php" => true,
-                "modifiercompiler.count_paragraphs.php" => true,
-                "modifiercompiler.count_sentences.php" => true,
-                "modifiercompiler.count_words.php" => true,
-                "modifiercompiler.default.php" => true,
-                "modifiercompiler.escape.php" => true,
-                "modifiercompiler.from_charset.php" => true,
-                "modifiercompiler.indent.php" => true,
-                "modifiercompiler.lower.php" => true,
-                "modifiercompiler.noprint.php" => true,
-                "modifiercompiler.string_format.php" => true,
-                "modifiercompiler.strip.php" => true,
-                "modifiercompiler.strip_tags.php" => true,
-                "modifiercompiler.to_charset.php" => true,
-                "modifiercompiler.unescape.php" => true,
-                "modifiercompiler.upper.php" => true,
-                "modifiercompiler.wordwrap.php" => true,
-                "outputfilter.trimwhitespace.php" => true,
-                "shared.escape_special_chars.php" => true,
-                "shared.literal_compiler_param.php" => true,
-                "shared.make_timestamp.php" => true,
-                "shared.mb_str_replace.php" => true,
-                "shared.mb_unicode.php" => true,
-                "shared.mb_wordwrap.php" => true,
-                "variablefilter.htmlspecialchars.php" => true,
-            );
-            $iterator = new DirectoryIterator($source);
-            foreach ($iterator as $file) {
-                if (!$file->isDot()) {
-                    $filename = $file->getFilename();
-                    if (isset($expected[$filename])) {
-                        unset($expected[$filename]);
-                    }
-                }
-            }
-            if ($expected) {
-                $status = false;
-                $message = "FAILED: files missing from libs/plugins: ". join(', ', array_keys($expected));
-                if ($errors === null) {
-                    echo $message . ".\n";
-                } else {
-                    $errors['plugins'] = $message;
-                }
-            } elseif ($errors === null) {
-                echo "... OK\n";
-            }
-        } else {
-            $status = false;
-            $message = "FAILED: ". SMARTY_PLUGINS_DIR .' is not a directory';
-            if ($errors === null) {
-                echo $message . ".\n";
-            } else {
-                $errors['plugins_dir_constant'] = $message;
-            }
-        }
-
-        if ($errors === null) {
-            echo "Tests complete.\n";
-            echo "
\n"; - } - - return $status; - } - -} + + * @author Uwe Tews + * @package Smarty + * @subpackage PluginsInternal + * @version 3-SVN$Rev: 3286 $ + */ + +/** + * Utility class + * + * @package Smarty + * @subpackage Security + */ +class Smarty_Internal_Utility +{ + /** + * private constructor to prevent calls creation of new instances + */ + final private function __construct() + { + // intentionally left blank + } + + /** + * Compile all template files + * + * @param string $extension template file name extension + * @param bool $force_compile force all to recompile + * @param int $time_limit set maximum execution time + * @param int $max_errors set maximum allowed errors + * @param Smarty $smarty Smarty instance + * @return integer number of template files compiled + */ + public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty) + { + // switch off time limit + if (function_exists('set_time_limit')) { + @set_time_limit($time_limit); + } + $smarty->force_compile = $force_compile; + $_count = 0; + $_error_count = 0; + // loop over array of template directories + foreach ($smarty->getTemplateDir() as $_dir) { + $_compileDirs = new RecursiveDirectoryIterator($_dir); + $_compile = new RecursiveIteratorIterator($_compileDirs); + foreach ($_compile as $_fileinfo) { + $_file = $_fileinfo->getFilename(); + if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; + if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue; + if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { + $_template_file = $_file; + } else { + $_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file; + } + echo '
', $_dir, '---', $_template_file; + flush(); + $_start_time = microtime(true); + try { + $_tpl = $smarty->createTemplate($_template_file,null,null,null,false); + if ($_tpl->mustCompile()) { + $_tpl->compileTemplateSource(); + $_count++; + echo ' compiled in ', microtime(true) - $_start_time, ' seconds'; + flush(); + } else { + echo ' is up to date'; + flush(); + } + } catch (Exception $e) { + echo 'Error: ', $e->getMessage(), "

"; + $_error_count++; + } + // free memory + $smarty->template_objects = array(); + $_tpl->smarty->template_objects = array(); + $_tpl = null; + if ($max_errors !== null && $_error_count == $max_errors) { + echo '

too many errors'; + exit(); + } + } + } + + return $_count; + } + + /** + * Compile all config files + * + * @param string $extension config file name extension + * @param bool $force_compile force all to recompile + * @param int $time_limit set maximum execution time + * @param int $max_errors set maximum allowed errors + * @param Smarty $smarty Smarty instance + * @return integer number of config files compiled + */ + public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty) + { + // switch off time limit + if (function_exists('set_time_limit')) { + @set_time_limit($time_limit); + } + $smarty->force_compile = $force_compile; + $_count = 0; + $_error_count = 0; + // loop over array of template directories + foreach ($smarty->getConfigDir() as $_dir) { + $_compileDirs = new RecursiveDirectoryIterator($_dir); + $_compile = new RecursiveIteratorIterator($_compileDirs); + foreach ($_compile as $_fileinfo) { + $_file = $_fileinfo->getFilename(); + if (substr(basename($_fileinfo->getPathname()),0,1) == '.' || strpos($_file, '.svn') !== false) continue; + if (!substr_compare($_file, $extension, - strlen($extension)) == 0) continue; + if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { + $_config_file = $_file; + } else { + $_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file; + } + echo '
', $_dir, '---', $_config_file; + flush(); + $_start_time = microtime(true); + try { + $_config = new Smarty_Internal_Config($_config_file, $smarty); + if ($_config->mustCompile()) { + $_config->compileConfigSource(); + $_count++; + echo ' compiled in ', microtime(true) - $_start_time, ' seconds'; + flush(); + } else { + echo ' is up to date'; + flush(); + } + } catch (Exception $e) { + echo 'Error: ', $e->getMessage(), "

"; + $_error_count++; + } + if ($max_errors !== null && $_error_count == $max_errors) { + echo '

too many errors'; + exit(); + } + } + } + + return $_count; + } + + /** + * Delete compiled template file + * + * @param string $resource_name template name + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @param Smarty $smarty Smarty instance + * @return integer number of template files deleted + */ + public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty) + { + $_compile_dir = realpath($smarty->getCompileDir()).'/'; + $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; + $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; + if (isset($resource_name)) { + $_save_stat = $smarty->caching; + $smarty->caching = false; + $tpl = new $smarty->template_class($resource_name, $smarty); + $smarty->caching = $_save_stat; + + // remove from template cache + $tpl->source; // have the template registered before unset() + if ($smarty->allow_ambiguous_resources) { + $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; + } else { + $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; + } + if (isset($_templateId[150])) { + $_templateId = sha1($_templateId); + } + unset($smarty->template_objects[$_templateId]); + + if ($tpl->source->exists) { + $_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath)); + $_resource_part_1_length = strlen($_resource_part_1); + } else { + return 0; + } + + $_resource_part_2 = str_replace('.php','.cache.php',$_resource_part_1); + $_resource_part_2_length = strlen($_resource_part_2); + } + $_dir = $_compile_dir; + if ($smarty->use_sub_dirs && isset($_compile_id)) { + $_dir .= $_compile_id . $_dir_sep; + } + if (isset($_compile_id)) { + $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep; + $_compile_id_part_length = strlen($_compile_id_part); + } + $_count = 0; + try { + $_compileDirs = new RecursiveDirectoryIterator($_dir); + // NOTE: UnexpectedValueException thrown for PHP >= 5.3 + } catch (Exception $e) { + return 0; + } + $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($_compile as $_file) { + if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) + continue; + + $_filepath = (string) $_file; + + if ($_file->isDir()) { + if (!$_compile->isDot()) { + // delete folder if empty + @rmdir($_file->getPathname()); + } + } else { + $unlink = false; + if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) + && (!isset($resource_name) + || (isset($_filepath[$_resource_part_1_length]) + && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0) + || (isset($_filepath[$_resource_part_2_length]) + && substr_compare($_filepath, $_resource_part_2, -$_resource_part_2_length, $_resource_part_2_length) == 0))) { + if (isset($exp_time)) { + if (time() - @filemtime($_filepath) >= $exp_time) { + $unlink = true; + } + } else { + $unlink = true; + } + } + + if ($unlink && @unlink($_filepath)) { + $_count++; + } + } + } + // clear compiled cache + Smarty_Resource::$sources = array(); + Smarty_Resource::$compileds = array(); + + return $_count; + } + + /** + * Return array of tag/attributes of all tags used by an template + * + * @param Smarty_Internal_Template $templae template object + * @return array of tag/attributes + */ + public static function getTags(Smarty_Internal_Template $template) + { + $template->smarty->get_used_tags = true; + $template->compileTemplateSource(); + + return $template->used_tags; + } + + /** + * diagnose Smarty setup + * + * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. + * + * @param Smarty $smarty Smarty instance to test + * @param array $errors array to push results into rather than outputting them + * @return bool status, true if everything is fine, false else + */ + public static function testInstall(Smarty $smarty, &$errors=null) + { + $status = true; + + if ($errors === null) { + echo "
\n";
+            echo "Smarty Installation test...\n";
+            echo "Testing template directory...\n";
+        }
+
+        $_stream_resolve_include_path = function_exists('stream_resolve_include_path');
+
+        // test if all registered template_dir are accessible
+        foreach ($smarty->getTemplateDir() as $template_dir) {
+            $_template_dir = $template_dir;
+            $template_dir = realpath($template_dir);
+            // resolve include_path or fail existence
+            if (!$template_dir) {
+                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
+                    // try PHP include_path
+                    if ($_stream_resolve_include_path) {
+                        $template_dir = stream_resolve_include_path($_template_dir);
+                    } else {
+                        $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir);
+                    }
+
+                    if ($template_dir !== false) {
+                        if ($errors === null) {
+                            echo "$template_dir is OK.\n";
+                        }
+
+                        continue;
+                    } else {
+                        $status = false;
+                        $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
+                        if ($errors === null) {
+                            echo $message . ".\n";
+                        } else {
+                            $errors['template_dir'] = $message;
+                        }
+
+                        continue;
+                    }
+                } else {
+                    $status = false;
+                    $message = "FAILED: $_template_dir does not exist";
+                    if ($errors === null) {
+                        echo $message . ".\n";
+                    } else {
+                        $errors['template_dir'] = $message;
+                    }
+
+                    continue;
+                }
+            }
+
+            if (!is_dir($template_dir)) {
+                $status = false;
+                $message = "FAILED: $template_dir is not a directory";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['template_dir'] = $message;
+                }
+            } elseif (!is_readable($template_dir)) {
+                $status = false;
+                $message = "FAILED: $template_dir is not readable";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['template_dir'] = $message;
+                }
+            } else {
+                if ($errors === null) {
+                    echo "$template_dir is OK.\n";
+                }
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing compile directory...\n";
+        }
+
+        // test if registered compile_dir is accessible
+        $__compile_dir = $smarty->getCompileDir();
+        $_compile_dir = realpath($__compile_dir);
+        if (!$_compile_dir) {
+            $status = false;
+            $message = "FAILED: {$__compile_dir} does not exist";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['compile_dir'] = $message;
+            }
+        } elseif (!is_dir($_compile_dir)) {
+            $status = false;
+            $message = "FAILED: {$_compile_dir} is not a directory";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['compile_dir'] = $message;
+            }
+        } elseif (!is_readable($_compile_dir)) {
+            $status = false;
+            $message = "FAILED: {$_compile_dir} is not readable";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['compile_dir'] = $message;
+            }
+        } elseif (!is_writable($_compile_dir)) {
+            $status = false;
+            $message = "FAILED: {$_compile_dir} is not writable";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['compile_dir'] = $message;
+            }
+        } else {
+            if ($errors === null) {
+                echo "{$_compile_dir} is OK.\n";
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing plugins directory...\n";
+        }
+
+        // test if all registered plugins_dir are accessible
+        // and if core plugins directory is still registered
+        $_core_plugins_dir = realpath(dirname(__FILE__) .'/../plugins');
+        $_core_plugins_available = false;
+        foreach ($smarty->getPluginsDir() as $plugin_dir) {
+            $_plugin_dir = $plugin_dir;
+            $plugin_dir = realpath($plugin_dir);
+            // resolve include_path or fail existence
+            if (!$plugin_dir) {
+                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) {
+                    // try PHP include_path
+                    if ($_stream_resolve_include_path) {
+                        $plugin_dir = stream_resolve_include_path($_plugin_dir);
+                    } else {
+                        $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
+                    }
+
+                    if ($plugin_dir !== false) {
+                        if ($errors === null) {
+                            echo "$plugin_dir is OK.\n";
+                        }
+
+                        continue;
+                    } else {
+                        $status = false;
+                        $message = "FAILED: $_plugin_dir does not exist (and couldn't be found in include_path either)";
+                        if ($errors === null) {
+                            echo $message . ".\n";
+                        } else {
+                            $errors['plugins_dir'] = $message;
+                        }
+
+                        continue;
+                    }
+                } else {
+                    $status = false;
+                    $message = "FAILED: $_plugin_dir does not exist";
+                    if ($errors === null) {
+                        echo $message . ".\n";
+                    } else {
+                        $errors['plugins_dir'] = $message;
+                    }
+
+                    continue;
+                }
+            }
+
+            if (!is_dir($plugin_dir)) {
+                $status = false;
+                $message = "FAILED: $plugin_dir is not a directory";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['plugins_dir'] = $message;
+                }
+            } elseif (!is_readable($plugin_dir)) {
+                $status = false;
+                $message = "FAILED: $plugin_dir is not readable";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['plugins_dir'] = $message;
+                }
+            } elseif ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
+                $_core_plugins_available = true;
+                if ($errors === null) {
+                    echo "$plugin_dir is OK.\n";
+                }
+            } else {
+                if ($errors === null) {
+                    echo "$plugin_dir is OK.\n";
+                }
+            }
+        }
+        if (!$_core_plugins_available) {
+            $status = false;
+            $message = "WARNING: Smarty's own libs/plugins is not available";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } elseif (!isset($errors['plugins_dir'])) {
+                $errors['plugins_dir'] = $message;
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing cache directory...\n";
+        }
+
+        // test if all registered cache_dir is accessible
+        $__cache_dir = $smarty->getCacheDir();
+        $_cache_dir = realpath($__cache_dir);
+        if (!$_cache_dir) {
+            $status = false;
+            $message = "FAILED: {$__cache_dir} does not exist";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['cache_dir'] = $message;
+            }
+        } elseif (!is_dir($_cache_dir)) {
+            $status = false;
+            $message = "FAILED: {$_cache_dir} is not a directory";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['cache_dir'] = $message;
+            }
+        } elseif (!is_readable($_cache_dir)) {
+            $status = false;
+            $message = "FAILED: {$_cache_dir} is not readable";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['cache_dir'] = $message;
+            }
+        } elseif (!is_writable($_cache_dir)) {
+            $status = false;
+            $message = "FAILED: {$_cache_dir} is not writable";
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['cache_dir'] = $message;
+            }
+        } else {
+            if ($errors === null) {
+                echo "{$_cache_dir} is OK.\n";
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing configs directory...\n";
+        }
+
+        // test if all registered config_dir are accessible
+        foreach ($smarty->getConfigDir() as $config_dir) {
+            $_config_dir = $config_dir;
+            $config_dir = realpath($config_dir);
+            // resolve include_path or fail existence
+            if (!$config_dir) {
+                if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
+                    // try PHP include_path
+                    if ($_stream_resolve_include_path) {
+                        $config_dir = stream_resolve_include_path($_config_dir);
+                    } else {
+                        $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir);
+                    }
+
+                    if ($config_dir !== false) {
+                        if ($errors === null) {
+                            echo "$config_dir is OK.\n";
+                        }
+
+                        continue;
+                    } else {
+                        $status = false;
+                        $message = "FAILED: $_config_dir does not exist (and couldn't be found in include_path either)";
+                        if ($errors === null) {
+                            echo $message . ".\n";
+                        } else {
+                            $errors['config_dir'] = $message;
+                        }
+
+                        continue;
+                    }
+                } else {
+                    $status = false;
+                    $message = "FAILED: $_config_dir does not exist";
+                    if ($errors === null) {
+                        echo $message . ".\n";
+                    } else {
+                        $errors['config_dir'] = $message;
+                    }
+
+                    continue;
+                }
+            }
+
+            if (!is_dir($config_dir)) {
+                $status = false;
+                $message = "FAILED: $config_dir is not a directory";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['config_dir'] = $message;
+                }
+            } elseif (!is_readable($config_dir)) {
+                $status = false;
+                $message = "FAILED: $config_dir is not readable";
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['config_dir'] = $message;
+                }
+            } else {
+                if ($errors === null) {
+                    echo "$config_dir is OK.\n";
+                }
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing sysplugin files...\n";
+        }
+        // test if sysplugins are available
+        $source = SMARTY_SYSPLUGINS_DIR;
+        if (is_dir($source)) {
+            $expected = array(
+                "smarty_cacheresource.php" => true,
+                "smarty_cacheresource_custom.php" => true,
+                "smarty_cacheresource_keyvaluestore.php" => true,
+                "smarty_config_source.php" => true,
+                "smarty_internal_cacheresource_file.php" => true,
+                "smarty_internal_compile_append.php" => true,
+                "smarty_internal_compile_assign.php" => true,
+                "smarty_internal_compile_block.php" => true,
+                "smarty_internal_compile_break.php" => true,
+                "smarty_internal_compile_call.php" => true,
+                "smarty_internal_compile_capture.php" => true,
+                "smarty_internal_compile_config_load.php" => true,
+                "smarty_internal_compile_continue.php" => true,
+                "smarty_internal_compile_debug.php" => true,
+                "smarty_internal_compile_eval.php" => true,
+                "smarty_internal_compile_extends.php" => true,
+                "smarty_internal_compile_for.php" => true,
+                "smarty_internal_compile_foreach.php" => true,
+                "smarty_internal_compile_function.php" => true,
+                "smarty_internal_compile_if.php" => true,
+                "smarty_internal_compile_include.php" => true,
+                "smarty_internal_compile_include_php.php" => true,
+                "smarty_internal_compile_insert.php" => true,
+                "smarty_internal_compile_ldelim.php" => true,
+                "smarty_internal_compile_nocache.php" => true,
+                "smarty_internal_compile_private_block_plugin.php" => true,
+                "smarty_internal_compile_private_function_plugin.php" => true,
+                "smarty_internal_compile_private_modifier.php" => true,
+                "smarty_internal_compile_private_object_block_function.php" => true,
+                "smarty_internal_compile_private_object_function.php" => true,
+                "smarty_internal_compile_private_print_expression.php" => true,
+                "smarty_internal_compile_private_registered_block.php" => true,
+                "smarty_internal_compile_private_registered_function.php" => true,
+                "smarty_internal_compile_private_special_variable.php" => true,
+                "smarty_internal_compile_rdelim.php" => true,
+                "smarty_internal_compile_section.php" => true,
+                "smarty_internal_compile_setfilter.php" => true,
+                "smarty_internal_compile_while.php" => true,
+                "smarty_internal_compilebase.php" => true,
+                "smarty_internal_config.php" => true,
+                "smarty_internal_config_file_compiler.php" => true,
+                "smarty_internal_configfilelexer.php" => true,
+                "smarty_internal_configfileparser.php" => true,
+                "smarty_internal_data.php" => true,
+                "smarty_internal_debug.php" => true,
+                "smarty_internal_filter_handler.php" => true,
+                "smarty_internal_function_call_handler.php" => true,
+                "smarty_internal_get_include_path.php" => true,
+                "smarty_internal_nocache_insert.php" => true,
+                "smarty_internal_parsetree.php" => true,
+                "smarty_internal_resource_eval.php" => true,
+                "smarty_internal_resource_extends.php" => true,
+                "smarty_internal_resource_file.php" => true,
+                "smarty_internal_resource_registered.php" => true,
+                "smarty_internal_resource_stream.php" => true,
+                "smarty_internal_resource_string.php" => true,
+                "smarty_internal_smartytemplatecompiler.php" => true,
+                "smarty_internal_template.php" => true,
+                "smarty_internal_templatebase.php" => true,
+                "smarty_internal_templatecompilerbase.php" => true,
+                "smarty_internal_templatelexer.php" => true,
+                "smarty_internal_templateparser.php" => true,
+                "smarty_internal_utility.php" => true,
+                "smarty_internal_write_file.php" => true,
+                "smarty_resource.php" => true,
+                "smarty_resource_custom.php" => true,
+                "smarty_resource_recompiled.php" => true,
+                "smarty_resource_uncompiled.php" => true,
+                "smarty_security.php" => true,
+            );
+            $iterator = new DirectoryIterator($source);
+            foreach ($iterator as $file) {
+                if (!$file->isDot()) {
+                    $filename = $file->getFilename();
+                    if (isset($expected[$filename])) {
+                        unset($expected[$filename]);
+                    }
+                }
+            }
+            if ($expected) {
+                $status = false;
+                $message = "FAILED: files missing from libs/sysplugins: ". join(', ', array_keys($expected));
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['sysplugins'] = $message;
+                }
+            } elseif ($errors === null) {
+                echo "... OK\n";
+            }
+        } else {
+            $status = false;
+            $message = "FAILED: ". SMARTY_SYSPLUGINS_DIR .' is not a directory';
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['sysplugins_dir_constant'] = $message;
+            }
+        }
+
+        if ($errors === null) {
+            echo "Testing plugin files...\n";
+        }
+        // test if core plugins are available
+        $source = SMARTY_PLUGINS_DIR;
+        if (is_dir($source)) {
+            $expected = array(
+                "block.textformat.php" => true,
+                "function.counter.php" => true,
+                "function.cycle.php" => true,
+                "function.fetch.php" => true,
+                "function.html_checkboxes.php" => true,
+                "function.html_image.php" => true,
+                "function.html_options.php" => true,
+                "function.html_radios.php" => true,
+                "function.html_select_date.php" => true,
+                "function.html_select_time.php" => true,
+                "function.html_table.php" => true,
+                "function.mailto.php" => true,
+                "function.math.php" => true,
+                "modifier.capitalize.php" => true,
+                "modifier.date_format.php" => true,
+                "modifier.debug_print_var.php" => true,
+                "modifier.escape.php" => true,
+                "modifier.regex_replace.php" => true,
+                "modifier.replace.php" => true,
+                "modifier.spacify.php" => true,
+                "modifier.truncate.php" => true,
+                "modifiercompiler.cat.php" => true,
+                "modifiercompiler.count_characters.php" => true,
+                "modifiercompiler.count_paragraphs.php" => true,
+                "modifiercompiler.count_sentences.php" => true,
+                "modifiercompiler.count_words.php" => true,
+                "modifiercompiler.default.php" => true,
+                "modifiercompiler.escape.php" => true,
+                "modifiercompiler.from_charset.php" => true,
+                "modifiercompiler.indent.php" => true,
+                "modifiercompiler.lower.php" => true,
+                "modifiercompiler.noprint.php" => true,
+                "modifiercompiler.string_format.php" => true,
+                "modifiercompiler.strip.php" => true,
+                "modifiercompiler.strip_tags.php" => true,
+                "modifiercompiler.to_charset.php" => true,
+                "modifiercompiler.unescape.php" => true,
+                "modifiercompiler.upper.php" => true,
+                "modifiercompiler.wordwrap.php" => true,
+                "outputfilter.trimwhitespace.php" => true,
+                "shared.escape_special_chars.php" => true,
+                "shared.literal_compiler_param.php" => true,
+                "shared.make_timestamp.php" => true,
+                "shared.mb_str_replace.php" => true,
+                "shared.mb_unicode.php" => true,
+                "shared.mb_wordwrap.php" => true,
+                "variablefilter.htmlspecialchars.php" => true,
+            );
+            $iterator = new DirectoryIterator($source);
+            foreach ($iterator as $file) {
+                if (!$file->isDot()) {
+                    $filename = $file->getFilename();
+                    if (isset($expected[$filename])) {
+                        unset($expected[$filename]);
+                    }
+                }
+            }
+            if ($expected) {
+                $status = false;
+                $message = "FAILED: files missing from libs/plugins: ". join(', ', array_keys($expected));
+                if ($errors === null) {
+                    echo $message . ".\n";
+                } else {
+                    $errors['plugins'] = $message;
+                }
+            } elseif ($errors === null) {
+                echo "... OK\n";
+            }
+        } else {
+            $status = false;
+            $message = "FAILED: ". SMARTY_PLUGINS_DIR .' is not a directory';
+            if ($errors === null) {
+                echo $message . ".\n";
+            } else {
+                $errors['plugins_dir_constant'] = $message;
+            }
+        }
+
+        if ($errors === null) {
+            echo "Tests complete.\n";
+            echo "
\n"; + } + + return $status; + } + +} From 7dec7d9963f4a0c15832ed382e6f903296821b45 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Tue, 18 Mar 2014 18:22:33 +0000 Subject: [PATCH 05/17] - revert change of 17.03.2014 --- change_log.txt | 5 +- .../smarty_internal_templatelexer.php | 1136 +++++++++-------- 2 files changed, 573 insertions(+), 568 deletions(-) diff --git a/change_log.txt b/change_log.txt index 10426670..552f1ab7 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,8 @@ ===== trunk ===== - 17.03.2014 + 18.03.2014 + - revert change of 17.03.2014 + +17.03.2014 - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) 15.03.2014 diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 82a00fab..1fc294ec 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -1,106 +1,106 @@ 'TEXT', 2 => 'SMARTY', 3 => 'LITERAL', 4 => 'DOUBLEQUOTEDSTRING', 5 => 'CHILDBODY'); - public $smarty_token_names = array ( // Text for parser error messages - 'IDENTITY' => '===', - 'NONEIDENTITY' => '!==', - 'EQUALS' => '==', - 'NOTEQUALS' => '!=', - 'GREATEREQUAL' => '(>=,ge)', - 'LESSEQUAL' => '(<=,le)', - 'GREATERTHAN' => '(>,gt)', - 'LESSTHAN' => '(<,lt)', - 'MOD' => '(%,mod)', - 'NOT' => '(!,not)', - 'LAND' => '(&&,and)', - 'LOR' => '(||,or)', - 'LXOR' => 'xor', - 'OPENP' => '(', - 'CLOSEP' => ')', - 'OPENB' => '[', - 'CLOSEB' => ']', - 'PTR' => '->', - 'APTR' => '=>', - 'EQUAL' => '=', - 'NUMBER' => 'number', - 'UNIMATH' => '+" , "-', - 'MATH' => '*" , "/" , "%', - 'INCDEC' => '++" , "--', - 'SPACE' => ' ', - 'DOLLAR' => '$', - 'SEMICOLON' => ';', - 'COLON' => ':', - 'DOUBLECOLON' => '::', - 'AT' => '@', - 'HATCH' => '#', - 'QUOTE' => '"', - 'BACKTICK' => '`', - 'VERT' => '|', - 'DOT' => '.', - 'COMMA' => '","', - 'ANDSYM' => '"&"', - 'QMARK' => '"?"', - 'ID' => 'identifier', - 'TEXT' => 'text', - 'FAKEPHPSTARTTAG' => 'Fake PHP start tag', - 'PHPSTARTTAG' => 'PHP start tag', - 'PHPENDTAG' => 'PHP end tag', - 'LITERALSTART' => 'Literal start', - 'LITERALEND' => 'Literal end', - 'LDELSLASH' => 'closing tag', - 'COMMENT' => 'comment', - 'AS' => 'as', - 'TO' => 'to', - ); - - - function __construct($data,$compiler) - { -// $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data); - $this->data = $data; - $this->counter = 0; - $this->line = 1; - $this->smarty = $compiler->smarty; - $this->compiler = $compiler; - $this->ldel = preg_quote($this->smarty->left_delimiter,'/'); - $this->ldel_length = strlen($this->smarty->left_delimiter); - $this->rdel = preg_quote($this->smarty->right_delimiter,'/'); - $this->rdel_length = strlen($this->smarty->right_delimiter); - $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; - $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; - $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; - } - - public function PrintTrace() - { - $this->yyTraceFILE = fopen('php://output', 'w'); - $this->yyTracePrompt = '
'; - } + /** + * Smarty Internal Plugin Templatelexer + * + * This is the lexer to break the template source into tokens + * @package Smarty + * @subpackage Compiler + * @author Uwe Tews + */ + /** + * Smarty Internal Plugin Templatelexer + */ + class Smarty_Internal_Templatelexer + { + public $data; + public $counter; + public $token; + public $value; + public $node; + public $line; + public $taglineno; + public $state = 1; + private $heredoc_id_stack = Array(); + public $yyTraceFILE; + public $yyTracePrompt; + public $state_name = array (1 => 'TEXT', 2 => 'SMARTY', 3 => 'LITERAL', 4 => 'DOUBLEQUOTEDSTRING', 5 => 'CHILDBODY'); + public $smarty_token_names = array ( // Text for parser error messages + 'IDENTITY' => '===', + 'NONEIDENTITY' => '!==', + 'EQUALS' => '==', + 'NOTEQUALS' => '!=', + 'GREATEREQUAL' => '(>=,ge)', + 'LESSEQUAL' => '(<=,le)', + 'GREATERTHAN' => '(>,gt)', + 'LESSTHAN' => '(<,lt)', + 'MOD' => '(%,mod)', + 'NOT' => '(!,not)', + 'LAND' => '(&&,and)', + 'LOR' => '(||,or)', + 'LXOR' => 'xor', + 'OPENP' => '(', + 'CLOSEP' => ')', + 'OPENB' => '[', + 'CLOSEB' => ']', + 'PTR' => '->', + 'APTR' => '=>', + 'EQUAL' => '=', + 'NUMBER' => 'number', + 'UNIMATH' => '+" , "-', + 'MATH' => '*" , "/" , "%', + 'INCDEC' => '++" , "--', + 'SPACE' => ' ', + 'DOLLAR' => '$', + 'SEMICOLON' => ';', + 'COLON' => ':', + 'DOUBLECOLON' => '::', + 'AT' => '@', + 'HATCH' => '#', + 'QUOTE' => '"', + 'BACKTICK' => '`', + 'VERT' => '|', + 'DOT' => '.', + 'COMMA' => '","', + 'ANDSYM' => '"&"', + 'QMARK' => '"?"', + 'ID' => 'identifier', + 'TEXT' => 'text', + 'FAKEPHPSTARTTAG' => 'Fake PHP start tag', + 'PHPSTARTTAG' => 'PHP start tag', + 'PHPENDTAG' => 'PHP end tag', + 'LITERALSTART' => 'Literal start', + 'LITERALEND' => 'Literal end', + 'LDELSLASH' => 'closing tag', + 'COMMENT' => 'comment', + 'AS' => 'as', + 'TO' => 'to', + ); + function __construct($data,$compiler) + { + // $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data); + $this->data = $data; + $this->counter = 0; + $this->line = 1; + $this->smarty = $compiler->smarty; + $this->compiler = $compiler; + $this->ldel = preg_quote($this->smarty->left_delimiter,'/'); + $this->ldel_length = strlen($this->smarty->left_delimiter); + $this->rdel = preg_quote($this->smarty->right_delimiter,'/'); + $this->rdel_length = strlen($this->smarty->right_delimiter); + $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; + $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; + $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; + } + + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '
'; + } + + private $_yy_state = 1; private $_yy_stack = array(); @@ -142,7 +142,7 @@ class Smarty_Internal_Templatelexer } - + public function yylex1() { $tokenMap = array ( @@ -220,160 +220,160 @@ class Smarty_Internal_Templatelexer function yy_r1_1($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } function yy_r1_2($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COMMENT; - } + $this->token = Smarty_Internal_Templateparser::TP_COMMENT; + } function yy_r1_4($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPON; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPON; + } + } function yy_r1_5($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; + } + } function yy_r1_6($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; - $this->yypushstate(self::LITERAL); - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); + } + } function yy_r1_7($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_9($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_10($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_11($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_12($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_13($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r1_14($yy_subpatterns) { - if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; - } elseif ($this->value == 'token = Smarty_Internal_Templateparser::TP_XMLTAG; - } else { - $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; - $this->value = substr($this->value, 0, 2); - } - } + if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; + } elseif ($this->value == 'token = Smarty_Internal_Templateparser::TP_XMLTAG; + } else { + $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; + $this->value = substr($this->value, 0, 2); + } + } function yy_r1_15($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; + } function yy_r1_16($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } function yy_r1_17($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; + } function yy_r1_18($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + } function yy_r1_19($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/{$this->ldel}|<\?|\?>|<%|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } - + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/{$this->ldel}|<\?|\?>|<%|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + public function yylex2() { $tokenMap = array ( @@ -500,377 +500,377 @@ class Smarty_Internal_Templatelexer function yy_r2_1($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; - $this->yypushstate(self::DOUBLEQUOTEDSTRING); - } + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; + $this->yypushstate(self::DOUBLEQUOTEDSTRING); + } function yy_r2_2($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; - } + $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; + } function yy_r2_3($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; - $this->taglineno = $this->line; - } + $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; + $this->taglineno = $this->line; + } function yy_r2_5($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; - } + $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; + } function yy_r2_6($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_RDEL; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_RDEL; + $this->yypopstate(); + } function yy_r2_7($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISIN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISIN; + } function yy_r2_8($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_AS; - } + $this->token = Smarty_Internal_Templateparser::TP_AS; + } function yy_r2_9($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TO; - } + $this->token = Smarty_Internal_Templateparser::TP_TO; + } function yy_r2_10($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_STEP; - } + $this->token = Smarty_Internal_Templateparser::TP_STEP; + } function yy_r2_11($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; - } + $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; + } function yy_r2_12($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_IDENTITY; - } + $this->token = Smarty_Internal_Templateparser::TP_IDENTITY; + } function yy_r2_13($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY; - } + $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY; + } function yy_r2_14($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_EQUALS; - } + $this->token = Smarty_Internal_Templateparser::TP_EQUALS; + } function yy_r2_15($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS; - } + $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS; + } function yy_r2_17($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL; + } function yy_r2_19($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL; + } function yy_r2_21($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN; - } + $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN; + } function yy_r2_22($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN; - } + $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN; + } function yy_r2_23($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_MOD; - } + $this->token = Smarty_Internal_Templateparser::TP_MOD; + } function yy_r2_24($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NOT; - } + $this->token = Smarty_Internal_Templateparser::TP_NOT; + } function yy_r2_25($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LAND; - } + $this->token = Smarty_Internal_Templateparser::TP_LAND; + } function yy_r2_26($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LOR; - } + $this->token = Smarty_Internal_Templateparser::TP_LOR; + } function yy_r2_27($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LXOR; - } + $this->token = Smarty_Internal_Templateparser::TP_LXOR; + } function yy_r2_28($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISODDBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISODDBY; + } function yy_r2_29($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY; + } function yy_r2_30($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISODD; - } + $this->token = Smarty_Internal_Templateparser::TP_ISODD; + } function yy_r2_31($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD; + } function yy_r2_32($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY; + } function yy_r2_33($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY; + } function yy_r2_34($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISEVEN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISEVEN; + } function yy_r2_35($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN; + } function yy_r2_36($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY; + } function yy_r2_37($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY; + } function yy_r2_38($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; - } + $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; + } function yy_r2_42($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_OPENP; - } + $this->token = Smarty_Internal_Templateparser::TP_OPENP; + } function yy_r2_43($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; - } + $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; + } function yy_r2_44($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_OPENB; - } + $this->token = Smarty_Internal_Templateparser::TP_OPENB; + } function yy_r2_45($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; - } + $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; + } function yy_r2_46($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PTR; - } + $this->token = Smarty_Internal_Templateparser::TP_PTR; + } function yy_r2_47($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_APTR; - } + $this->token = Smarty_Internal_Templateparser::TP_APTR; + } function yy_r2_48($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_EQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_EQUAL; + } function yy_r2_49($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INCDEC; - } + $this->token = Smarty_Internal_Templateparser::TP_INCDEC; + } function yy_r2_50($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; - } + $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; + } function yy_r2_52($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_MATH; - } + $this->token = Smarty_Internal_Templateparser::TP_MATH; + } function yy_r2_54($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_AT; - } + $this->token = Smarty_Internal_Templateparser::TP_AT; + } function yy_r2_55($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_HATCH; - } + $this->token = Smarty_Internal_Templateparser::TP_HATCH; + } function yy_r2_56($yy_subpatterns) { - // resolve conflicts with shorttag and right_delimiter starting with '=' - if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) { - preg_match("/\s+/",$this->value,$match); - $this->value = $match[0]; - $this->token = Smarty_Internal_Templateparser::TP_SPACE; - } else { - $this->token = Smarty_Internal_Templateparser::TP_ATTR; - } - } + // resolve conflicts with shorttag and right_delimiter starting with '=' + if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) { + preg_match("/\s+/",$this->value,$match); + $this->value = $match[0]; + $this->token = Smarty_Internal_Templateparser::TP_SPACE; + } else { + $this->token = Smarty_Internal_Templateparser::TP_ATTR; + } + } function yy_r2_57($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ID; - } + $this->token = Smarty_Internal_Templateparser::TP_ID; + } function yy_r2_58($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INTEGER; - } + $this->token = Smarty_Internal_Templateparser::TP_INTEGER; + } function yy_r2_59($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; + $this->yypopstate(); + } function yy_r2_60($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_VERT; - } + $this->token = Smarty_Internal_Templateparser::TP_VERT; + } function yy_r2_61($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOT; - } + $this->token = Smarty_Internal_Templateparser::TP_DOT; + } function yy_r2_62($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COMMA; - } + $this->token = Smarty_Internal_Templateparser::TP_COMMA; + } function yy_r2_63($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; - } + $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; + } function yy_r2_64($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; - } + $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; + } function yy_r2_65($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COLON; - } + $this->token = Smarty_Internal_Templateparser::TP_COLON; + } function yy_r2_66($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ANDSYM; - } + $this->token = Smarty_Internal_Templateparser::TP_ANDSYM; + } function yy_r2_67($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QMARK; - } + $this->token = Smarty_Internal_Templateparser::TP_QMARK; + } function yy_r2_68($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_HEX; - } + $this->token = Smarty_Internal_Templateparser::TP_HEX; + } function yy_r2_69($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SPACE; - } + $this->token = Smarty_Internal_Templateparser::TP_SPACE; + } function yy_r2_70($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r2_72($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r2_73($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r2_74($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r2_75($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r2_76($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } - + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + public function yylex3() { $tokenMap = array ( @@ -938,71 +938,71 @@ class Smarty_Internal_Templatelexer function yy_r3_1($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; - $this->yypushstate(self::LITERAL); - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); + } + } function yy_r3_2($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; - $this->yypopstate(); - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; + $this->yypopstate(); + } + } function yy_r3_3($yy_subpatterns) { - if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; - } else { - $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; - $this->value = substr($this->value, 0, 2); - } - } + if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; + } else { + $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; + $this->value = substr($this->value, 0, 2); + } + } function yy_r3_4($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; + } function yy_r3_5($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; + } function yy_r3_6($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + } function yy_r3_7($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } else { - $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_LITERAL; - } - + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_LITERAL; + } + public function yylex4() { $tokenMap = array ( @@ -1074,104 +1074,104 @@ class Smarty_Internal_Templatelexer function yy_r4_1($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r4_3($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r4_4($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r4_5($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r4_6($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } function yy_r4_7($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; + $this->yypopstate(); + } function yy_r4_8($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; - $this->value = substr($this->value,0,-1); - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; + $this->value = substr($this->value,0,-1); + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } function yy_r4_9($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; - } + $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; + } function yy_r4_10($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } function yy_r4_11($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } function yy_r4_15($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } - + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + public function yylex5() { $tokenMap = array ( @@ -1236,52 +1236,52 @@ class Smarty_Internal_Templatelexer function yy_r5_1($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - return false; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPON; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + return false; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPON; + } + } function yy_r5_2($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - return false; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + return false; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; + } + } function yy_r5_3($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - return false; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + return false; + } else { + $this->yypopstate(); + return true; + } + } function yy_r5_4($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/".$this->ldel."\s*((\/)?strip\s*".$this->rdel."|block\s+)/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - return false; - } - + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/".$this->ldel."\s*((\/)?strip\s*".$this->rdel."|block\s+)/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } + return false; + } + public function yylex6() { $tokenMap = array ( @@ -1346,51 +1346,53 @@ class Smarty_Internal_Templatelexer function yy_r6_1($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } function yy_r6_2($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } function yy_r6_3($yy_subpatterns) { - if ($this->smarty->auto_literal && (strlen($this->value) > $this->ldel_length)) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } function yy_r6_5($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/".$this->ldel."\s*((\/)?block(\s|".$this->rdel.")|[\$]smarty\.block\.(child|parent)\s*".$this->rdel.")/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } + if ($this->mbstring_overload) { + $to = mb_strlen($this->data,'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/".$this->ldel."\s*((\/)?block(\s|".$this->rdel.")|[\$]smarty\.block\.(child|parent)\s*".$this->rdel.")/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); + } else { + $this->value = substr($this->data,$this->counter,$to-$this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } -} + } + + \ No newline at end of file From 478db521c9c666a55cbb779680f0129e0dc65326 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Thu, 20 Mar 2014 22:07:26 +0000 Subject: [PATCH 06/17] - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) --- change_log.txt | 3 + .../smarty_internal_templatelexer.php | 1654 +++++++++-------- 2 files changed, 875 insertions(+), 782 deletions(-) diff --git a/change_log.txt b/change_log.txt index 552f1ab7..a87db3fe 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 20.03.2014 + - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) + 18.03.2014 - revert change of 17.03.2014 diff --git a/libs/sysplugins/smarty_internal_templatelexer.php b/libs/sysplugins/smarty_internal_templatelexer.php index 1fc294ec..8803222e 100644 --- a/libs/sysplugins/smarty_internal_templatelexer.php +++ b/libs/sysplugins/smarty_internal_templatelexer.php @@ -1,106 +1,105 @@ 'TEXT', 2 => 'SMARTY', 3 => 'LITERAL', 4 => 'DOUBLEQUOTEDSTRING', 5 => 'CHILDBODY'); - public $smarty_token_names = array ( // Text for parser error messages - 'IDENTITY' => '===', - 'NONEIDENTITY' => '!==', - 'EQUALS' => '==', - 'NOTEQUALS' => '!=', - 'GREATEREQUAL' => '(>=,ge)', - 'LESSEQUAL' => '(<=,le)', - 'GREATERTHAN' => '(>,gt)', - 'LESSTHAN' => '(<,lt)', - 'MOD' => '(%,mod)', - 'NOT' => '(!,not)', - 'LAND' => '(&&,and)', - 'LOR' => '(||,or)', - 'LXOR' => 'xor', - 'OPENP' => '(', - 'CLOSEP' => ')', - 'OPENB' => '[', - 'CLOSEB' => ']', - 'PTR' => '->', - 'APTR' => '=>', - 'EQUAL' => '=', - 'NUMBER' => 'number', - 'UNIMATH' => '+" , "-', - 'MATH' => '*" , "/" , "%', - 'INCDEC' => '++" , "--', - 'SPACE' => ' ', - 'DOLLAR' => '$', - 'SEMICOLON' => ';', - 'COLON' => ':', - 'DOUBLECOLON' => '::', - 'AT' => '@', - 'HATCH' => '#', - 'QUOTE' => '"', - 'BACKTICK' => '`', - 'VERT' => '|', - 'DOT' => '.', - 'COMMA' => '","', - 'ANDSYM' => '"&"', - 'QMARK' => '"?"', - 'ID' => 'identifier', - 'TEXT' => 'text', - 'FAKEPHPSTARTTAG' => 'Fake PHP start tag', - 'PHPSTARTTAG' => 'PHP start tag', - 'PHPENDTAG' => 'PHP end tag', - 'LITERALSTART' => 'Literal start', - 'LITERALEND' => 'Literal end', - 'LDELSLASH' => 'closing tag', - 'COMMENT' => 'comment', - 'AS' => 'as', - 'TO' => 'to', - ); +/** + * Smarty Internal Plugin Templatelexer + * This is the lexer to break the template source into tokens + * + * @package Smarty + * @subpackage Compiler + * @author Uwe Tews + */ +/** + * Smarty Internal Plugin Templatelexer + */ +class Smarty_Internal_Templatelexer +{ + public $data; + public $counter; + public $token; + public $value; + public $node; + public $line; + public $taglineno; + public $state = 1; + private $heredoc_id_stack = Array(); + public $yyTraceFILE; + public $yyTracePrompt; + public $state_name = array(1 => 'TEXT', 2 => 'SMARTY', 3 => 'LITERAL', 4 => 'DOUBLEQUOTEDSTRING', 5 => 'CHILDBODY'); + public $smarty_token_names = array( // Text for parser error messages + 'IDENTITY' => '===', + 'NONEIDENTITY' => '!==', + 'EQUALS' => '==', + 'NOTEQUALS' => '!=', + 'GREATEREQUAL' => '(>=,ge)', + 'LESSEQUAL' => '(<=,le)', + 'GREATERTHAN' => '(>,gt)', + 'LESSTHAN' => '(<,lt)', + 'MOD' => '(%,mod)', + 'NOT' => '(!,not)', + 'LAND' => '(&&,and)', + 'LOR' => '(||,or)', + 'LXOR' => 'xor', + 'OPENP' => '(', + 'CLOSEP' => ')', + 'OPENB' => '[', + 'CLOSEB' => ']', + 'PTR' => '->', + 'APTR' => '=>', + 'EQUAL' => '=', + 'NUMBER' => 'number', + 'UNIMATH' => '+" , "-', + 'MATH' => '*" , "/" , "%', + 'INCDEC' => '++" , "--', + 'SPACE' => ' ', + 'DOLLAR' => '$', + 'SEMICOLON' => ';', + 'COLON' => ':', + 'DOUBLECOLON' => '::', + 'AT' => '@', + 'HATCH' => '#', + 'QUOTE' => '"', + 'BACKTICK' => '`', + 'VERT' => '|', + 'DOT' => '.', + 'COMMA' => '","', + 'ANDSYM' => '"&"', + 'QMARK' => '"?"', + 'ID' => 'identifier', + 'TEXT' => 'text', + 'FAKEPHPSTARTTAG' => 'Fake PHP start tag', + 'PHPSTARTTAG' => 'PHP start tag', + 'PHPENDTAG' => 'PHP end tag', + 'LITERALSTART' => 'Literal start', + 'LITERALEND' => 'Literal end', + 'LDELSLASH' => 'closing tag', + 'COMMENT' => 'comment', + 'AS' => 'as', + 'TO' => 'to', + ); - function __construct($data,$compiler) - { - // $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data); - $this->data = $data; - $this->counter = 0; - $this->line = 1; - $this->smarty = $compiler->smarty; - $this->compiler = $compiler; - $this->ldel = preg_quote($this->smarty->left_delimiter,'/'); - $this->ldel_length = strlen($this->smarty->left_delimiter); - $this->rdel = preg_quote($this->smarty->right_delimiter,'/'); - $this->rdel_length = strlen($this->smarty->right_delimiter); - $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; - $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; - $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; - } + function __construct($data, $compiler) + { + // $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data); + $this->data = $data; + $this->counter = 0; + $this->line = 1; + $this->smarty = $compiler->smarty; + $this->compiler = $compiler; + $this->ldel = preg_quote($this->smarty->left_delimiter, '/'); + $this->ldel_length = strlen($this->smarty->left_delimiter); + $this->rdel = preg_quote($this->smarty->right_delimiter, '/'); + $this->rdel_length = strlen($this->smarty->right_delimiter); + $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; + $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; + $this->mbstring_overload = ini_get('mbstring.func_overload') & 2; + } - public function PrintTrace() - { - $this->yyTraceFILE = fopen('php://output', 'w'); - $this->yyTracePrompt = '
'; - } + public function PrintTrace() + { + $this->yyTraceFILE = fopen('php://output', 'w'); + $this->yyTracePrompt = '
'; + } - private $_yy_state = 1; private $_yy_stack = array(); @@ -112,85 +111,82 @@ public function yypushstate($state) { if ($this->yyTraceFILE) { - fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); } array_push($this->_yy_stack, $this->_yy_state); $this->_yy_state = $state; if ($this->yyTraceFILE) { - fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); } } public function yypopstate() { - if ($this->yyTraceFILE) { - fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); - } - $this->_yy_state = array_pop($this->_yy_stack); if ($this->yyTraceFILE) { - fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + } + $this->_yy_state = array_pop($this->_yy_stack); + if ($this->yyTraceFILE) { + fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); } - } public function yybegin($state) { - $this->_yy_state = $state; + $this->_yy_state = $state; if ($this->yyTraceFILE) { - fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); + fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt, isset($this->state_name[$this->_yy_state]) ? $this->state_name[$this->_yy_state] : $this->_yy_state); } } - - public function yylex1() { - $tokenMap = array ( - 1 => 0, - 2 => 1, - 4 => 0, - 5 => 0, - 6 => 0, - 7 => 1, - 9 => 0, - 10 => 0, - 11 => 0, - 12 => 0, - 13 => 0, - 14 => 0, - 15 => 0, - 16 => 0, - 17 => 0, - 18 => 0, - 19 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 0, + 2 => 1, + 4 => 0, + 5 => 0, + 6 => 0, + 7 => 1, + 9 => 0, + 10 => 0, + 11 => 0, + 12 => 0, + 13 => 0, + 14 => 0, + 15 => 0, + 16 => 0, + 17 => 0, + 18 => 0, + 19 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(\\{\\})|\G(".$this->ldel."\\*([\S\s]*?)\\*".$this->rdel.")|\G(".$this->ldel."\\s*strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*setfilter\\s+)|\G(".$this->ldel."\\s*\/)|\G(".$this->ldel."\\s*)|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(\\s*".$this->rdel.")|\G(<%)|\G(%>)|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(\\{\\})|\G(" . $this->ldel . "\\*([\S\s]*?)\\*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*setfilter\\s+)|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(\\s*" . $this->rdel . ")|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state TEXT'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state TEXT'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r1_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -199,278 +195,293 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const TEXT = 1; + function yy_r1_1($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + function yy_r1_2($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COMMENT; - } + $this->token = Smarty_Internal_Templateparser::TP_COMMENT; + } + function yy_r1_4($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPON; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPON; + } + } + function yy_r1_5($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; + } + } + function yy_r1_6($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; - $this->yypushstate(self::LITERAL); + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); } - } + } + function yy_r1_7($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_9($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_10($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_11($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSETFILTER; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_12($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_13($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r1_14($yy_subpatterns) { - if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; - } elseif ($this->value == 'token = Smarty_Internal_Templateparser::TP_XMLTAG; - } else { - $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; - $this->value = substr($this->value, 0, 2); - } - } + if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; + } elseif ($this->value == 'token = Smarty_Internal_Templateparser::TP_XMLTAG; + } else { + $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; + $this->value = substr($this->value, 0, 2); + } + } + function yy_r1_15($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; + } + function yy_r1_16($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + function yy_r1_17($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; + } + function yy_r1_18($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + } + function yy_r1_19($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/{$this->ldel}|<\?|\?>|<%|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + if ($this->mbstring_overload) { + $to = mb_strlen($this->data, 'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/{$this->ldel}|<\?|\?>|<%|%>/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data, $this->counter, $to - $this->counter, 'latin1'); + } else { + $this->value = substr($this->data, $this->counter, $to - $this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } - public function yylex2() { - $tokenMap = array ( - 1 => 0, - 2 => 0, - 3 => 1, - 5 => 0, - 6 => 0, - 7 => 0, - 8 => 0, - 9 => 0, - 10 => 0, - 11 => 0, - 12 => 0, - 13 => 0, - 14 => 0, - 15 => 1, - 17 => 1, - 19 => 1, - 21 => 0, - 22 => 0, - 23 => 0, - 24 => 0, - 25 => 0, - 26 => 0, - 27 => 0, - 28 => 0, - 29 => 0, - 30 => 0, - 31 => 0, - 32 => 0, - 33 => 0, - 34 => 0, - 35 => 0, - 36 => 0, - 37 => 0, - 38 => 3, - 42 => 0, - 43 => 0, - 44 => 0, - 45 => 0, - 46 => 0, - 47 => 0, - 48 => 0, - 49 => 0, - 50 => 1, - 52 => 1, - 54 => 0, - 55 => 0, - 56 => 0, - 57 => 0, - 58 => 0, - 59 => 0, - 60 => 0, - 61 => 0, - 62 => 0, - 63 => 0, - 64 => 0, - 65 => 0, - 66 => 0, - 67 => 0, - 68 => 0, - 69 => 0, - 70 => 1, - 72 => 0, - 73 => 0, - 74 => 0, - 75 => 0, - 76 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 0, + 2 => 0, + 3 => 1, + 5 => 0, + 6 => 0, + 7 => 0, + 8 => 0, + 9 => 0, + 10 => 0, + 11 => 0, + 12 => 0, + 13 => 0, + 14 => 0, + 15 => 1, + 17 => 1, + 19 => 1, + 21 => 0, + 22 => 0, + 23 => 0, + 24 => 0, + 25 => 0, + 26 => 0, + 27 => 0, + 28 => 0, + 29 => 0, + 30 => 0, + 31 => 0, + 32 => 0, + 33 => 0, + 34 => 0, + 35 => 0, + 36 => 0, + 37 => 0, + 38 => 3, + 42 => 0, + 43 => 0, + 44 => 0, + 45 => 0, + 46 => 0, + 47 => 0, + 48 => 0, + 49 => 0, + 50 => 1, + 52 => 1, + 54 => 0, + 55 => 0, + 56 => 0, + 57 => 0, + 58 => 0, + 59 => 0, + 60 => 0, + 61 => 0, + 62 => 0, + 63 => 0, + 64 => 0, + 65 => 0, + 66 => 0, + 67 => 0, + 68 => 0, + 69 => 0, + 70 => 1, + 72 => 0, + 73 => 0, + 74 => 0, + 75 => 0, + 76 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G(\\$)|\G(\\s*".$this->rdel.")|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*===\\s*)|\G(\\s*!==\\s*)|\G(\\s*==\\s*|\\s+eq\\s+)|\G(\\s*!=\\s*|\\s*<>\\s*|\\s+(ne|neq)\\s+)|\G(\\s*>=\\s*|\\s+(ge|gte)\\s+)|\G(\\s*<=\\s*|\\s+(le|lte)\\s+)|\G(\\s*>\\s*|\\s+gt\\s+)|\G(\\s*<\\s*|\\s+lt\\s+)|\G(\\s+mod\\s+)|\G(!\\s*|not\\s+)|\G(\\s*&&\\s*|\\s*and\\s+)|\G(\\s*\\|\\|\\s*|\\s*or\\s+)|\G(\\s*xor\\s+)|\G(\\s+is\\s+odd\\s+by\\s+)|\G(\\s+is\\s+not\\s+odd\\s+by\\s+)|\G(\\s+is\\s+odd)|\G(\\s+is\\s+not\\s+odd)|\G(\\s+is\\s+even\\s+by\\s+)|\G(\\s+is\\s+not\\s+even\\s+by\\s+)|\G(\\s+is\\s+even)|\G(\\s+is\\s+not\\s+even)|\G(\\s+is\\s+div\\s+by\\s+)|\G(\\s+is\\s+not\\s+div\\s+by\\s+)|\G(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|\G(\\s*\\(\\s*)|\G(\\s*\\))|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*->\\s*)|\G(\\s*=>\\s*)|\G(\\s*=\\s*)|\G(\\+\\+|--)|\G(\\s*(\\+|-)\\s*)|\G(\\s*(\\*|\/|%)\\s*)|\G(@)|\G(#)|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*=\\s*)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G(`)|\G(\\|)|\G(\\.)|\G(\\s*,\\s*)|\G(\\s*;)|\G(::)|\G(\\s*:\\s*)|\G(\\s*&\\s*)|\G(\\s*\\?\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*\/)|\G(".$this->ldel."\\s*)|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(\")|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G(\\$)|\G(\\s*" . $this->rdel . ")|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*===\\s*)|\G(\\s*!==\\s*)|\G(\\s*==\\s*|\\s+eq\\s+)|\G(\\s*!=\\s*|\\s*<>\\s*|\\s+(ne|neq)\\s+)|\G(\\s*>=\\s*|\\s+(ge|gte)\\s+)|\G(\\s*<=\\s*|\\s+(le|lte)\\s+)|\G(\\s*>\\s*|\\s+gt\\s+)|\G(\\s*<\\s*|\\s+lt\\s+)|\G(\\s+mod\\s+)|\G(!\\s*|not\\s+)|\G(\\s*&&\\s*|\\s*and\\s+)|\G(\\s*\\|\\|\\s*|\\s*or\\s+)|\G(\\s*xor\\s+)|\G(\\s+is\\s+odd\\s+by\\s+)|\G(\\s+is\\s+not\\s+odd\\s+by\\s+)|\G(\\s+is\\s+odd)|\G(\\s+is\\s+not\\s+odd)|\G(\\s+is\\s+even\\s+by\\s+)|\G(\\s+is\\s+not\\s+even\\s+by\\s+)|\G(\\s+is\\s+even)|\G(\\s+is\\s+not\\s+even)|\G(\\s+is\\s+div\\s+by\\s+)|\G(\\s+is\\s+not\\s+div\\s+by\\s+)|\G(\\((int(eger)?|bool(ean)?|float|double|real|string|binary|array|object)\\)\\s*)|\G(\\s*\\(\\s*)|\G(\\s*\\))|\G(\\[\\s*)|\G(\\s*\\])|\G(\\s*->\\s*)|\G(\\s*=>\\s*)|\G(\\s*=\\s*)|\G(\\+\\+|--)|\G(\\s*(\\+|-)\\s*)|\G(\\s*(\\*|\/|%)\\s*)|\G(@)|\G(#)|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*=\\s*)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G(`)|\G(\\|)|\G(\\.)|\G(\\s*,\\s*)|\G(\\s*;)|\G(::)|\G(\\s*:\\s*)|\G(\\s*&\\s*)|\G(\\s*\\?\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state SMARTY'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state SMARTY'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r2_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -479,436 +490,499 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const SMARTY = 2; + function yy_r2_1($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; - $this->yypushstate(self::DOUBLEQUOTEDSTRING); - } + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; + $this->yypushstate(self::DOUBLEQUOTEDSTRING); + } + function yy_r2_2($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; - } + $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; + } + function yy_r2_3($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; - $this->taglineno = $this->line; - } + $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; + $this->taglineno = $this->line; + } + function yy_r2_5($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; - } + $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; + } + function yy_r2_6($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_RDEL; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_RDEL; + $this->yypopstate(); + } + function yy_r2_7($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISIN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISIN; + } + function yy_r2_8($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_AS; - } + $this->token = Smarty_Internal_Templateparser::TP_AS; + } + function yy_r2_9($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TO; - } + $this->token = Smarty_Internal_Templateparser::TP_TO; + } + function yy_r2_10($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_STEP; - } + $this->token = Smarty_Internal_Templateparser::TP_STEP; + } + function yy_r2_11($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; - } + $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; + } + function yy_r2_12($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_IDENTITY; - } + $this->token = Smarty_Internal_Templateparser::TP_IDENTITY; + } + function yy_r2_13($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY; - } + $this->token = Smarty_Internal_Templateparser::TP_NONEIDENTITY; + } + function yy_r2_14($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_EQUALS; - } + $this->token = Smarty_Internal_Templateparser::TP_EQUALS; + } + function yy_r2_15($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS; - } + $this->token = Smarty_Internal_Templateparser::TP_NOTEQUALS; + } + function yy_r2_17($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_GREATEREQUAL; + } + function yy_r2_19($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_LESSEQUAL; + } + function yy_r2_21($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN; - } + $this->token = Smarty_Internal_Templateparser::TP_GREATERTHAN; + } + function yy_r2_22($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN; - } + $this->token = Smarty_Internal_Templateparser::TP_LESSTHAN; + } + function yy_r2_23($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_MOD; - } + $this->token = Smarty_Internal_Templateparser::TP_MOD; + } + function yy_r2_24($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_NOT; - } + $this->token = Smarty_Internal_Templateparser::TP_NOT; + } + function yy_r2_25($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LAND; - } + $this->token = Smarty_Internal_Templateparser::TP_LAND; + } + function yy_r2_26($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LOR; - } + $this->token = Smarty_Internal_Templateparser::TP_LOR; + } + function yy_r2_27($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_LXOR; - } + $this->token = Smarty_Internal_Templateparser::TP_LXOR; + } + function yy_r2_28($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISODDBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISODDBY; + } + function yy_r2_29($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTODDBY; + } + function yy_r2_30($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISODD; - } + $this->token = Smarty_Internal_Templateparser::TP_ISODD; + } + function yy_r2_31($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTODD; + } + function yy_r2_32($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISEVENBY; + } + function yy_r2_33($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVENBY; + } + function yy_r2_34($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISEVEN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISEVEN; + } + function yy_r2_35($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTEVEN; + } + function yy_r2_36($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISDIVBY; + } + function yy_r2_37($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY; - } + $this->token = Smarty_Internal_Templateparser::TP_ISNOTDIVBY; + } + function yy_r2_38($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; - } + $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; + } + function yy_r2_42($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_OPENP; - } + $this->token = Smarty_Internal_Templateparser::TP_OPENP; + } + function yy_r2_43($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; - } + $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; + } + function yy_r2_44($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_OPENB; - } + $this->token = Smarty_Internal_Templateparser::TP_OPENB; + } + function yy_r2_45($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; - } + $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; + } + function yy_r2_46($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PTR; - } + $this->token = Smarty_Internal_Templateparser::TP_PTR; + } + function yy_r2_47($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_APTR; - } + $this->token = Smarty_Internal_Templateparser::TP_APTR; + } + function yy_r2_48($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_EQUAL; - } + $this->token = Smarty_Internal_Templateparser::TP_EQUAL; + } + function yy_r2_49($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INCDEC; - } + $this->token = Smarty_Internal_Templateparser::TP_INCDEC; + } + function yy_r2_50($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; - } + $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; + } + function yy_r2_52($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_MATH; - } + $this->token = Smarty_Internal_Templateparser::TP_MATH; + } + function yy_r2_54($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_AT; - } + $this->token = Smarty_Internal_Templateparser::TP_AT; + } + function yy_r2_55($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_HATCH; - } + $this->token = Smarty_Internal_Templateparser::TP_HATCH; + } + function yy_r2_56($yy_subpatterns) { - // resolve conflicts with shorttag and right_delimiter starting with '=' - if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) { - preg_match("/\s+/",$this->value,$match); - $this->value = $match[0]; - $this->token = Smarty_Internal_Templateparser::TP_SPACE; - } else { - $this->token = Smarty_Internal_Templateparser::TP_ATTR; - } - } + // resolve conflicts with shorttag and right_delimiter starting with '=' + if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == $this->smarty->right_delimiter) { + preg_match("/\s+/", $this->value, $match); + $this->value = $match[0]; + $this->token = Smarty_Internal_Templateparser::TP_SPACE; + } else { + $this->token = Smarty_Internal_Templateparser::TP_ATTR; + } + } + function yy_r2_57($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ID; - } + $this->token = Smarty_Internal_Templateparser::TP_ID; + } + function yy_r2_58($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_INTEGER; - } + $this->token = Smarty_Internal_Templateparser::TP_INTEGER; + } + function yy_r2_59($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; + $this->yypopstate(); + } + function yy_r2_60($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_VERT; - } + $this->token = Smarty_Internal_Templateparser::TP_VERT; + } + function yy_r2_61($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOT; - } + $this->token = Smarty_Internal_Templateparser::TP_DOT; + } + function yy_r2_62($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COMMA; - } + $this->token = Smarty_Internal_Templateparser::TP_COMMA; + } + function yy_r2_63($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; - } + $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; + } + function yy_r2_64($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; - } + $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; + } + function yy_r2_65($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_COLON; - } + $this->token = Smarty_Internal_Templateparser::TP_COLON; + } + function yy_r2_66($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ANDSYM; - } + $this->token = Smarty_Internal_Templateparser::TP_ANDSYM; + } + function yy_r2_67($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QMARK; - } + $this->token = Smarty_Internal_Templateparser::TP_QMARK; + } + function yy_r2_68($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_HEX; - } + $this->token = Smarty_Internal_Templateparser::TP_HEX; + } + function yy_r2_69($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_SPACE; - } + $this->token = Smarty_Internal_Templateparser::TP_SPACE; + } + function yy_r2_70($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r2_72($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r2_73($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r2_74($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r2_75($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r2_76($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } - - public function yylex3() { - $tokenMap = array ( - 1 => 0, - 2 => 0, - 3 => 0, - 4 => 0, - 5 => 0, - 6 => 0, - 7 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 0, + 2 => 0, + 3 => 0, + 4 => 0, + 5 => 0, + 6 => 0, + 7 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(".$this->ldel."\\s*literal\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/literal\\s*".$this->rdel.")|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(<%)|\G(%>)|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/literal\\s*" . $this->rdel . ")|\G(<\\?(?:php\\w+|=|[a-zA-Z]+)?)|\G(\\?>)|\G(<%)|\G(%>)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state LITERAL'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state LITERAL'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r3_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -917,134 +991,139 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const LITERAL = 3; + function yy_r3_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; - $this->yypushstate(self::LITERAL); - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; + $this->yypushstate(self::LITERAL); + } + } + function yy_r3_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; - $this->yypopstate(); - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LITERALEND; + $this->yypopstate(); + } + } + function yy_r3_3($yy_subpatterns) { - if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; + if (in_array($this->value, Array('token = Smarty_Internal_Templateparser::TP_PHPSTARTTAG; } else { - $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; - $this->value = substr($this->value, 0, 2); + $this->token = Smarty_Internal_Templateparser::TP_FAKEPHPSTARTTAG; + $this->value = substr($this->value, 0, 2); } - } + } + function yy_r3_4($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_PHPENDTAG; + } + function yy_r3_5($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPSTARTTAG; + } + function yy_r3_6($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; - } + $this->token = Smarty_Internal_Templateparser::TP_ASPENDTAG; + } + function yy_r3_7($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } else { - $this->compiler->trigger_template_error ("missing or misspelled literal closing tag"); - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_LITERAL; - } + if ($this->mbstring_overload) { + $to = mb_strlen($this->data, 'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/{$this->ldel}\/?literal{$this->rdel}|<\?|<%|\?>|%>/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } else { + $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data, $this->counter, $to - $this->counter, 'latin1'); + } else { + $this->value = substr($this->data, $this->counter, $to - $this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_LITERAL; + } - public function yylex4() { - $tokenMap = array ( - 1 => 1, - 3 => 0, - 4 => 0, - 5 => 0, - 6 => 0, - 7 => 0, - 8 => 0, - 9 => 0, - 10 => 0, - 11 => 3, - 15 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 1, + 3 => 0, + 4 => 0, + 5 => 0, + 6 => 0, + 7 => 0, + 8 => 0, + 9 => 0, + 10 => 0, + 11 => 3, + 15 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(".$this->ldel."\\s*(if|elseif|else if|while)\\s+)|\G(".$this->ldel."\\s*for\\s+)|\G(".$this->ldel."\\s*foreach(?![^\s]))|\G(".$this->ldel."\\s*\/)|\G(".$this->ldel."\\s*)|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(".$this->ldel."|\\$|`\\$|\")))|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(" . $this->ldel . "\\s*(if|elseif|else if|while)\\s+)|\G(" . $this->ldel . "\\s*for\\s+)|\G(" . $this->ldel . "\\s*foreach(?![^\s]))|\G(" . $this->ldel . "\\s*\/)|\G(" . $this->ldel . "\\s*)|\G(\")|\G(`\\$)|\G(\\$[0-9]*[a-zA-Z_]\\w*)|\G(\\$)|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r4_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -1053,160 +1132,169 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const DOUBLEQUOTEDSTRING = 4; + function yy_r4_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELIF; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELIF; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r4_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOR; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r4_4($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELFOREACH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r4_5($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r4_6($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } else { - $this->token = Smarty_Internal_Templateparser::TP_LDEL; - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } else { + $this->token = Smarty_Internal_Templateparser::TP_LDEL; + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + } + function yy_r4_7($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_QUOTE; - $this->yypopstate(); - } + $this->token = Smarty_Internal_Templateparser::TP_QUOTE; + $this->yypopstate(); + } + function yy_r4_8($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; - $this->value = substr($this->value,0,-1); - $this->yypushstate(self::SMARTY); - $this->taglineno = $this->line; - } + $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; + $this->value = substr($this->value, 0, - 1); + $this->yypushstate(self::SMARTY); + $this->taglineno = $this->line; + } + function yy_r4_9($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; - } + $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; + } + function yy_r4_10($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + function yy_r4_11($yy_subpatterns) { - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } + function yy_r4_15($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_TEXT; - } + if ($this->mbstring_overload) { + $to = mb_strlen($this->data, 'latin1'); + } else { + $to = strlen($this->data); + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data, $this->counter, $to - $this->counter, 'latin1'); + } else { + $this->value = substr($this->data, $this->counter, $to - $this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_TEXT; + } - public function yylex5() { - $tokenMap = array ( - 1 => 0, - 2 => 0, - 3 => 0, - 4 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 0, + 2 => 0, + 3 => 0, + 4 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(".$this->ldel."\\s*strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*\/strip\\s*".$this->rdel.")|\G(".$this->ldel."\\s*block)|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*\/strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*block)|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state CHILDBODY'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state CHILDBODY'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r5_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -1215,108 +1303,110 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const CHILDBODY = 5; + function yy_r5_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - return false; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPON; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + return false; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPON; + } + } + function yy_r5_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - return false; - } else { - $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + return false; + } else { + $this->token = Smarty_Internal_Templateparser::TP_STRIPOFF; + } + } + function yy_r5_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - return false; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + return false; + } else { + $this->yypopstate(); + return true; + } + } + function yy_r5_4($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/".$this->ldel."\s*((\/)?strip\s*".$this->rdel."|block\s+)/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - return false; - } + if ($this->mbstring_overload) { + $to = mb_strlen($this->data, 'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/" . $this->ldel . "\s*((\/)?strip\s*" . $this->rdel . "|block\s+)/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data, $this->counter, $to - $this->counter, 'latin1'); + } else { + $this->value = substr($this->data, $this->counter, $to - $this->counter); + } + return false; + } - public function yylex6() { - $tokenMap = array ( - 1 => 0, - 2 => 0, - 3 => 1, - 5 => 0, - ); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + $tokenMap = array( + 1 => 0, + 2 => 0, + 3 => 1, + 5 => 0, + ); + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } - $yy_global_pattern = "/\G(".$this->ldel."\\s*block)|\G(".$this->ldel."\\s*\/block)|\G(".$this->ldel."\\s*[$]smarty\\.block\\.(child|parent))|\G([\S\s])/iS"; + $yy_global_pattern = "/\G(" . $this->ldel . "\\s*block)|\G(" . $this->ldel . "\\s*\/block)|\G(" . $this->ldel . "\\s*[$]smarty\\.block\\.(child|parent))|\G([\S\s])/iS"; do { - if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter,2000000000,'latin1'), $yymatches) : preg_match($yy_global_pattern,$this->data, $yymatches, null, $this->counter)) { + if ($this->mbstring_overload ? preg_match($yy_global_pattern, mb_substr($this->data, $this->counter, 2000000000, 'latin1'), $yymatches) : preg_match($yy_global_pattern, $this->data, $yymatches, null, $this->counter)) { $yysubmatches = $yymatches; $yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns - if (!count($yymatches)) { + if (! count($yymatches)) { throw new Exception('Error: lexing failed because a rule matched' . - ' an empty string. Input "' . substr($this->data, - $this->counter, 5) . '... state CHILDBLOCK'); + ' an empty string. Input "' . substr($this->data, + $this->counter, 5) . '... state CHILDBLOCK'); } next($yymatches); // skip global match $this->token = key($yymatches); // token number if ($tokenMap[$this->token]) { // extract sub-patterns for passing to lex function $yysubmatches = array_slice($yysubmatches, $this->token + 1, - $tokenMap[$this->token]); + $tokenMap[$this->token]); } else { $yysubmatches = array(); } $this->value = current($yymatches); // token value $r = $this->{'yy_r6_' . $this->token}($yysubmatches); if ($r === null) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); // accept this token return true; @@ -1325,74 +1415,74 @@ // process this token in the new state return $this->yylex(); } elseif ($r === false) { - $this->counter += ($this->mbstring_overload ? mb_strlen($this->value,'latin1'): strlen($this->value)); + $this->counter += ($this->mbstring_overload ? mb_strlen($this->value, 'latin1') : strlen($this->value)); $this->line += substr_count($this->value, "\n"); - if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data,'latin1'): strlen($this->data))) { + if ($this->counter >= ($this->mbstring_overload ? mb_strlen($this->data, 'latin1') : strlen($this->data))) { return false; // end of input } // skip this token continue; - } } else { + } + } else { throw new Exception('Unexpected input at line' . $this->line . - ': ' . $this->data[$this->counter]); + ': ' . $this->data[$this->counter]); } break; } while (true); - } // end function - const CHILDBLOCK = 6; + function yy_r6_1($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } + function yy_r6_2($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } + function yy_r6_3($yy_subpatterns) { - if ($this->smarty->auto_literal && ($this->mbstring_overload ? (mb_strpos(" \n\t\r",mb_substr($this->value,$this->ldel_length,1,'latin1'),0,'latin1') !== false) : (strpos(" \n\t\r",substr($this->value,$this->ldel_length,1)) !== false))) { - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } else { - $this->yypopstate(); - return true; - } - } + if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } else { + $this->yypopstate(); + return true; + } + } + function yy_r6_5($yy_subpatterns) { - if ($this->mbstring_overload) { - $to = mb_strlen($this->data,'latin1'); - } else { - $to = strlen($this->data); - } - preg_match("/".$this->ldel."\s*((\/)?block(\s|".$this->rdel.")|[\$]smarty\.block\.(child|parent)\s*".$this->rdel.")/",$this->data,$match,PREG_OFFSET_CAPTURE,$this->counter); - if (isset($match[0][1])) { - $to = $match[0][1]; - } - if ($this->mbstring_overload) { - $this->value = mb_substr($this->data,$this->counter,$to-$this->counter,'latin1'); - } else { - $this->value = substr($this->data,$this->counter,$to-$this->counter); - } - $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; - } - - } - - \ No newline at end of file + if ($this->mbstring_overload) { + $to = mb_strlen($this->data, 'latin1'); + } else { + $to = strlen($this->data); + } + preg_match("/" . $this->ldel . "\s*((\/)?block(\s|" . $this->rdel . ")|[\$]smarty\.block\.(child|parent)\s*" . $this->rdel . ")/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); + if (isset($match[0][1])) { + $to = $match[0][1]; + } + if ($this->mbstring_overload) { + $this->value = mb_substr($this->data, $this->counter, $to - $this->counter, 'latin1'); + } else { + $this->value = substr($this->data, $this->counter, $to - $this->counter); + } + $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; + } +} From 474e863af1997bc1d50a20e1a5a33b7cc7daeb6a Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Mon, 24 Mar 2014 18:52:29 +0000 Subject: [PATCH 07/17] - bugfix using a {foreach} property like @iteration could fail when used in inheritance parent templates (Issue 182) --- change_log.txt | 3 +++ .../smarty_internal_compile_foreach.php | 25 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/change_log.txt b/change_log.txt index a87db3fe..8a411902 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 24.03.2014 + - bugfix using a {foreach} property like @iteration could fail when used in inheritance parent templates (Issue 182) + 20.03.2014 - bugfix $smarty->auto_literal and mbsting.func_overload 2, 6 or 7 did fail (forum topic 24899) diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index 7d138398..06ef00cd 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -49,7 +49,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase */ public function compile($args, $compiler, $parameter) { - $tpl = $compiler->template; // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -80,12 +79,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase $ItemVarName = '$' . trim($item, '\'"') . '@'; // evaluates which Smarty variables and properties have to be computed if ($has_name) { - $usesSmartyFirst = strpos($tpl->source->content, $SmartyVarName . 'first') !== false; - $usesSmartyLast = strpos($tpl->source->content, $SmartyVarName . 'last') !== false; - $usesSmartyIndex = strpos($tpl->source->content, $SmartyVarName . 'index') !== false; - $usesSmartyIteration = strpos($tpl->source->content, $SmartyVarName . 'iteration') !== false; - $usesSmartyShow = strpos($tpl->source->content, $SmartyVarName . 'show') !== false; - $usesSmartyTotal = strpos($tpl->source->content, $SmartyVarName . 'total') !== false; + $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false; + $usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false; + $usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false; + $usesSmartyIteration = strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false; + $usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false; + $usesSmartyTotal = strpos($compiler->lex->data, $SmartyVarName . 'total') !== false; } else { $usesSmartyFirst = false; $usesSmartyLast = false; @@ -93,12 +92,12 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase $usesSmartyShow = false; } - $usesPropFirst = $usesSmartyFirst || strpos($tpl->source->content, $ItemVarName . 'first') !== false; - $usesPropLast = $usesSmartyLast || strpos($tpl->source->content, $ItemVarName . 'last') !== false; - $usesPropIndex = $usesPropFirst || strpos($tpl->source->content, $ItemVarName . 'index') !== false; - $usesPropIteration = $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'iteration') !== false; - $usesPropShow = strpos($tpl->source->content, $ItemVarName . 'show') !== false; - $usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($tpl->source->content, $ItemVarName . 'total') !== false; + $usesPropFirst = $usesSmartyFirst || strpos($compiler->lex->data, $ItemVarName . 'first') !== false; + $usesPropLast = $usesSmartyLast || strpos($compiler->lex->data, $ItemVarName . 'last') !== false; + $usesPropIndex = $usesPropFirst || strpos($compiler->lex->data, $ItemVarName . 'index') !== false; + $usesPropIteration = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false; + $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false; + $usesPropTotal = $usesSmartyTotal || $usesSmartyShow || $usesPropShow || $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false; // generate output code $output = "tpl_vars[$item] = new Smarty_Variable; \$_smarty_tpl->tpl_vars[$item]->_loop = false;\n"; From 58982caf27b299f0b217877eb1ce8a5ec11e2ea7 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Wed, 26 Mar 2014 20:33:03 +0000 Subject: [PATCH 08/17] - bugfix Smart_Resource_Custom should not lowercase the resource name (Issue 183) --- change_log.txt | 3 +++ libs/sysplugins/smarty_resource_custom.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index 8a411902..27fcc358 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 26.03.2014 + - bugfix Smart_Resource_Custom should not lowercase the resource name (Issue 183) + 24.03.2014 - bugfix using a {foreach} property like @iteration could fail when used in inheritance parent templates (Issue 182) diff --git a/libs/sysplugins/smarty_resource_custom.php b/libs/sysplugins/smarty_resource_custom.php index bf5c4ea6..e2aadabf 100644 --- a/libs/sysplugins/smarty_resource_custom.php +++ b/libs/sysplugins/smarty_resource_custom.php @@ -48,7 +48,7 @@ abstract class Smarty_Resource_Custom extends Smarty_Resource */ public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null) { - $source->filepath = strtolower($source->type . ':' . $source->name); + $source->filepath = $source->type . ':' . $source->name; $source->uid = sha1($source->type . ':' . $source->name); $mtime = $this->fetchTimestamp($source->name); From 79d67afb0fd63bb2ada5c8f57190007a3f1da296 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Fri, 4 Apr 2014 23:38:36 +0000 Subject: [PATCH 09/17] - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 182) --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index 27fcc358..cf8094c9 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 05.04.2014 + - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 182) + 26.03.2014 - bugfix Smart_Resource_Custom should not lowercase the resource name (Issue 183) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index a3edac7d..5ec25a30 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -70,7 +70,7 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { /** * @deprecated in favor of Smarty::$_DATE_FORMAT */ - define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); + define('SMARTY_RESOURCE_DATE_FORMAT', '%b %-e, %Y'); } /** From 668bc167178af7f281f2cd93acae370d184ebdf7 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sun, 6 Apr 2014 18:50:39 +0000 Subject: [PATCH 10/17] - bugfix template inheritance fail when using custom resource after patch of 8.3.2014 (Issue 187) --- change_log.txt | 3 +++ libs/sysplugins/smarty_internal_compile_block.php | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/change_log.txt b/change_log.txt index cf8094c9..7ce66e1e 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== + 06.04.2014 + - bugfix template inheritance fail when using custom resource after patch of 8.3.2014 (Issue 187) + 05.04.2014 - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 182) diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 377288df..02546c0b 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -84,7 +84,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase $this->template->block_data[$_name]['source'] = ''; // build {block} for child block self::$block_data[$_name]['source'] = - "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}'" . + "{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" . " uid='{$compiler->template->source->uid}' line={$compiler->lex->line}"; if ($_attr['nocache']) { self::$block_data[$_name]['source'] .= ' nocache'; @@ -361,7 +361,7 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil * @var array * @see Smarty_Internal_CompileBase */ - public $required_attributes = array('name', 'file', 'uid', 'line'); + public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource'); /** @@ -377,7 +377,11 @@ class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_Compil $_attr = $this->getAttributes($compiler, $args); // update template with original template resource of {block} - $compiler->template->template_resource = realpath(trim($_attr['file'], "'")); + if (trim($_attr['type'], "'") == 'file') { + $compiler->template->template_resource = realpath(trim($_attr['file'], "'")); + } else { + $compiler->template->template_resource = trim($_attr['resource'], "'"); + } // source object unset ($compiler->template->source); $exists = $compiler->template->source->exists; From 00c919dcc22cee807a8efb916787900ce6478767 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sun, 6 Apr 2014 19:06:32 +0000 Subject: [PATCH 11/17] bugfix update of composer file (Issue 168 and 184) --- change_log.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/change_log.txt b/change_log.txt index 7ce66e1e..ee351f36 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== trunk ===== 06.04.2014 - bugfix template inheritance fail when using custom resource after patch of 8.3.2014 (Issue 187) + - bugfix update of composer file (Issue 168 and 184) 05.04.2014 - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 182) From f67473f0852ecf86e67eebe9cb6bfadac321454f Mon Sep 17 00:00:00 2001 From: "monte.ohrt" Date: Mon, 7 Apr 2014 18:30:41 +0000 Subject: [PATCH 12/17] update to 3.1.18 --- change_log.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/change_log.txt b/change_log.txt index ee351f36..b198e6a4 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,5 @@ ===== trunk ===== + ===== 3.1.18 ===== 06.04.2014 - bugfix template inheritance fail when using custom resource after patch of 8.3.2014 (Issue 187) - bugfix update of composer file (Issue 168 and 184) From a613394887169fa685fd0bd539642ee7f46024b3 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Mon, 7 Apr 2014 19:57:42 +0000 Subject: [PATCH 13/17] Update dev version number to 3.1.19-dev --- change_log.txt | 6 ++++-- libs/Smarty.class.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/change_log.txt b/change_log.txt index b198e6a4..49c7f6fa 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,7 @@ - ===== trunk ===== - ===== 3.1.18 ===== + ===== 3.1.19-dev ===== (xx.xx.2014) + + + ===== 3.1.18 ===== (07.04.2014) 06.04.2014 - bugfix template inheritance fail when using custom resource after patch of 8.3.2014 (Issue 187) - bugfix update of composer file (Issue 168 and 184) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 5ec25a30..93bebbee 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -113,7 +113,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = 'Smarty-3.1-DEV'; + const SMARTY_VERSION = 'Smarty-3.1.19-dev'; /** * define variable scopes From 608dddc19a18595a9804636b25669450577947cc Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Fri, 18 Apr 2014 08:09:38 +0000 Subject: [PATCH 14/17] --- change_log.txt | 5 ++++- libs/Smarty.class.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/change_log.txt b/change_log.txt index 49c7f6fa..d55b11e0 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.19-dev ===== (xx.xx.2014) + + 18.04.2014 + - revert bugfxx of 5.4.2015 because %-e date formart is not supported on all oprearting systems ===== 3.1.18 ===== (07.04.2014) @@ -7,7 +10,7 @@ - bugfix update of composer file (Issue 168 and 184) 05.04.2014 - - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 182) + - bugfix default date format leads to extra spaces when displaying dates with single digit days (Issue 165) 26.03.2014 - bugfix Smart_Resource_Custom should not lowercase the resource name (Issue 183) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 93bebbee..32f64123 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -70,7 +70,7 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { /** * @deprecated in favor of Smarty::$_DATE_FORMAT */ - define('SMARTY_RESOURCE_DATE_FORMAT', '%b %-e, %Y'); + define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); } /** From d6c14829967001a798da28576fbb0adb2409559a Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Fri, 18 Apr 2014 08:13:32 +0000 Subject: [PATCH 15/17] fixed typos --- change_log.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/change_log.txt b/change_log.txt index d55b11e0..b8475ced 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,7 @@ ===== 3.1.19-dev ===== (xx.xx.2014) 18.04.2014 - - revert bugfxx of 5.4.2015 because %-e date formart is not supported on all oprearting systems + - revert bugfix of 5.4.2015 because %-e date format is not supported on all operating systems ===== 3.1.18 ===== (07.04.2014) From 8658b04c863ab2ad1de2a7af47778a35715ab1e9 Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sat, 19 Apr 2014 11:42:11 +0000 Subject: [PATCH 16/17] bugfix calling createTemplate(template, data) with empty data array caused notice of array to string conversion (Issue 189) --- change_log.txt | 2 + libs/Smarty.class.php | 4 +- .../smarty_internal_templatebase.php | 1644 ++++++++--------- 3 files changed, 826 insertions(+), 824 deletions(-) diff --git a/change_log.txt b/change_log.txt index b8475ced..d09bdb99 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,6 @@ ===== 3.1.19-dev ===== (xx.xx.2014) + 19.04.2014 + - bugfix calling createTemplate(template, data) with empty data array caused notice of array to string conversion (Issue 189) 18.04.2014 - revert bugfix of 5.4.2015 because %-e date format is not supported on all operating systems diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 32f64123..e320a6b7 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1220,11 +1220,11 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) { - if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) { + if ($cache_id !== null && (is_object($cache_id) || is_array($cache_id))) { $parent = $cache_id; $cache_id = null; } - if (!empty($parent) && is_array($parent)) { + if ($parent !== null && is_array($parent)) { $data = $parent; $parent = null; } else { diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 4720716f..131e1870 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -1,822 +1,822 @@ -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) { - $code = $_template->compiler->compileTemplate($_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(); - $code = file_get_contents($_template->compiled->filepath); - eval("?>" . $code); - unset($code); - $_template->compiled->loaded = true; - $_template->compiled->isCompiled = true; - } - 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(); - $code = file_get_contents($_template->compiled->filepath); - eval("?>" . $code); - unset($code); - $_template->compiled->isCompiled = true; - } - $_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|<\?|\?>)/', "\n", $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($_template); - } - 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)) && !property_exists($object_impl, $method)) { - throw new SmartyException("Undefined method or property '$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; - } elseif (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]; - } elseif ($_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 ($cache_id !== null && 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) { + $code = $_template->compiler->compileTemplate($_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(); + $code = file_get_contents($_template->compiled->filepath); + eval("?>" . $code); + unset($code); + $_template->compiled->loaded = true; + $_template->compiled->isCompiled = true; + } + 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(); + $code = file_get_contents($_template->compiled->filepath); + eval("?>" . $code); + unset($code); + $_template->compiled->isCompiled = true; + } + $_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|<\?|\?>)/', "\n", $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($_template); + } + 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)) && !property_exists($object_impl, $method)) { + throw new SmartyException("Undefined method or property '$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; + } elseif (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]; + } elseif ($_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'."); + } + +} From c7071d9d2c126f493fa208ba838660a17b1c6fea Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sat, 19 Apr 2014 13:53:20 +0000 Subject: [PATCH 17/17] - bugfix clearCompiledTemplate() did not delete files on WINDOWS when a compile_id was specified --- change_log.txt | 1 + libs/sysplugins/smarty_internal_utility.php | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/change_log.txt b/change_log.txt index d09bdb99..a59f3df1 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,6 +1,7 @@ ===== 3.1.19-dev ===== (xx.xx.2014) 19.04.2014 - bugfix calling createTemplate(template, data) with empty data array caused notice of array to string conversion (Issue 189) + - bugfix clearCompiledTemplate() did not delete files on WINDOWS when a compile_id was specified 18.04.2014 - revert bugfix of 5.4.2015 because %-e date format is not supported on all operating systems diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 82f200df..1e33ed67 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -184,7 +184,7 @@ class Smarty_Internal_Utility { $_compile_dir = realpath($smarty->getCompileDir()).'/'; $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; - $_dir_sep = $smarty->use_sub_dirs ? DS : '^'; + $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; if (isset($resource_name)) { $_save_stat = $smarty->caching; $smarty->caching = false; @@ -218,7 +218,7 @@ class Smarty_Internal_Utility $_dir .= $_compile_id . $_dir_sep; } if (isset($_compile_id)) { - $_compile_id_part = $_compile_dir . $_compile_id . $_dir_sep; + $_compile_id_part = str_replace('\\','/',$_compile_dir . $_compile_id . $_dir_sep); $_compile_id_part_length = strlen($_compile_id_part); } $_count = 0; @@ -233,7 +233,7 @@ class Smarty_Internal_Utility if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) continue; - $_filepath = (string) $_file; + $_filepath = str_replace('\\','/',(string) $_file); if ($_file->isDir()) { if (!$_compile->isDot()) { @@ -242,7 +242,7 @@ class Smarty_Internal_Utility } } else { $unlink = false; - if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) + if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && $a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) && (!isset($resource_name) || (isset($_filepath[$_resource_part_1_length]) && substr_compare($_filepath, $_resource_part_1, -$_resource_part_1_length, $_resource_part_1_length) == 0)