update smarty to 3.1.28-dev which fixes a bug where changes in a template are only visible on the second pageload which is annoying for developing
This commit is contained in:
		| @@ -460,10 +460,11 @@ included template. | |||||||
| PLUGINS | PLUGINS | ||||||
| ======= | ======= | ||||||
|  |  | ||||||
| Smarty3 are following the same coding rules as in Smarty2.  | Smarty 3 plugins follow the same coding rules as in Smarty 2.  | ||||||
| The only difference is that the template object is passed as additional third parameter. | The main difference is that the template object is now passed in place of the smarty object.  | ||||||
|  | The smarty object can be still be accessed through $template->smarty. | ||||||
|  |  | ||||||
| smarty_plugintype_name (array $params, object $smarty, object $template) | smarty_plugintype_name (array $params, Smarty_Internal_Template $template) | ||||||
|  |  | ||||||
| The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty 2 internals. | The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty 2 internals. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,169 @@ | |||||||
|  ===== 3.1.27===== (18.06.2015) |  ===== 3.1.28-dev===== (xx.xx.2015) | ||||||
|  |  05.12.2015 | ||||||
|  |   -bugfix {strip} should insert a single space https://github.com/smarty-php/smarty/issues/111 | ||||||
|  |    | ||||||
|  |  25.11.2015 | ||||||
|  |   -bugfix a left delimter like '[%' did fail on [%$var_[%$variable%]%] (forum topic 25798) | ||||||
|  |  | ||||||
|  |  02.11.2015 | ||||||
|  |   - bugfix {include} with variable file name like {include file="foo_`$bar`.tpl"} did fail in 3.1.28-dev https://github.com/smarty-php/smarty/issues/102 | ||||||
|  |  | ||||||
|  |  01.11.2015 | ||||||
|  |   - update config file processing | ||||||
|  |    | ||||||
|  |  31.10.2015 | ||||||
|  |   - bugfix add missing $trusted_dir property to SmartyBC class (forum topic 25751) | ||||||
|  |  | ||||||
|  |  29.10.2015 | ||||||
|  |   - improve template scope handling | ||||||
|  |  | ||||||
|  |  24.10.2015 | ||||||
|  |   - more optimizations of template processing | ||||||
|  |   - bugfix Error when using {include} within {capture} https://github.com/smarty-php/smarty/issues/100 | ||||||
|  |  | ||||||
|  |  21.10.2015 | ||||||
|  |   - move some code into runtime extensions | ||||||
|  |  | ||||||
|  |  18.10.2015 | ||||||
|  |   - optimize filepath normalization | ||||||
|  |   - rework of template inheritance | ||||||
|  |   - speed and size optimizations | ||||||
|  |   - bugfix under HHVM temporary cache file must only be created when caches template was updated | ||||||
|  |   - fix compiled code for new {block} assign attribute | ||||||
|  |   - update code generated by template function call handler | ||||||
|  |  | ||||||
|  |  18.09.2015 | ||||||
|  |   - bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92 | ||||||
|  |    | ||||||
|  |  17.09.2015 | ||||||
|  |   - bugfix {foreach} first attribute was not correctly reset since commit 05a8fa2 of 02.08.2015 https://github.com/smarty-php/smarty/issues/90 | ||||||
|  |  | ||||||
|  |  16.09.2015 | ||||||
|  |   - update compiler by moving no longer needed properties, code optimizations and other | ||||||
|  |  | ||||||
|  |  14.09.2015 | ||||||
|  |   - optimize autoloader | ||||||
|  |   - optimize subtemplate handling | ||||||
|  |   - update template inheritance processing | ||||||
|  |   - move code of {call} processing back into Smarty_Internal_Template class | ||||||
|  |   - improvement invalidate OPCACHE for cleared compiled and cached template files (forum topic 25557) | ||||||
|  |   - bugfix unintended multiple debug windows (forum topic 25699) | ||||||
|  |    | ||||||
|  |  30.08.2015 | ||||||
|  |   - size optimization move some runtime functions into extension | ||||||
|  |   - optimize inline template processing | ||||||
|  |   - optimization merge inheritance child and parent templates into one compiled template file | ||||||
|  |  | ||||||
|  |  29.08.2015 | ||||||
|  |   - improvement convert template inheritance into runtime processing | ||||||
|  |   - bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68 | ||||||
|  |  | ||||||
|  |  23.08.2015 | ||||||
|  |   - introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop | ||||||
|  |   - load seldom used Smarty API methods dynamically to reduce memory footprint | ||||||
|  |   - cache template object of {include} if same template is included several times | ||||||
|  |   - convert debug console processing to object | ||||||
|  |   - use output buffers for better performance and less memory usage | ||||||
|  |   - optimize nocache hash processing | ||||||
|  |   - remove not really needed properties | ||||||
|  |   - optimize rendering | ||||||
|  |   - move caching to Smarty::_cache | ||||||
|  |   - remove properties with redundant content | ||||||
|  |   - optimize Smarty::templateExists() | ||||||
|  |   - optimize use_include_path processing | ||||||
|  |   - relocate properties for size optimization | ||||||
|  |   - remove redundant code | ||||||
|  |   - bugfix compiling super globals like {$smarty.get.foo} did fail in the master branch https://github.com/smarty-php/smarty/issues/77 | ||||||
|  |  | ||||||
|  |  06.08.2015 | ||||||
|  |   - avoid possible circular object references caused by parser/lexer objects | ||||||
|  |   - rewrite compileAll... utility methods | ||||||
|  |   - commit several  internal improvements | ||||||
|  |   - bugfix Smarty failed when compile_id did contain "|" | ||||||
|  |  | ||||||
|  |  03.08.2015 | ||||||
|  |   - rework clear cache methods | ||||||
|  |   - bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing | ||||||
|  |   - improve getIncludePath() to return directory if no file was given | ||||||
|  |  | ||||||
|  |  02.08.2015 | ||||||
|  |   - optimization and code cleanup of {foreach} and {section} compiler | ||||||
|  |   - rework {capture} compiler | ||||||
|  |  | ||||||
|  |  01.08.2015 | ||||||
|  |   - update DateTime object can be instance of DateTimeImmutable since PHP5.5 https://github.com/smarty-php/smarty/pull/75 | ||||||
|  |   - improvement show resource type and start of template source instead of uid on eval: and string: resource (forum topic 25630) | ||||||
|  |  | ||||||
|  |  31.07.2015 | ||||||
|  |   - optimize {foreach} and {section} compiler | ||||||
|  |  | ||||||
|  |  29.07.2015 | ||||||
|  |   - optimize {section} compiler for speed and size of compiled code | ||||||
|  |  | ||||||
|  |  28.07.2015 | ||||||
|  |   - update for PHP 7 compatibility | ||||||
|  |  | ||||||
|  |  26.07.2015 | ||||||
|  |   - improvement impement workaround for HHVM PHP incompatibillity https://github.com/facebook/hhvm/issues/4797 | ||||||
|  |  | ||||||
|  |  25.07.2015 | ||||||
|  |   - bugfix parser did hang on text starting <?something https://github.com/smarty-php/smarty/issues/74 | ||||||
|  |  | ||||||
|  |  20.07.2015 | ||||||
|  |   - bugfix config files got recompiled on each request | ||||||
|  |   - improvement invalidate PHP 5.5 opcache for recompiled and cached templates  https://github.com/smarty-php/smarty/issues/72 | ||||||
|  |  | ||||||
|  |  12.07.2015 | ||||||
|  |   - optimize {extends} compilation | ||||||
|  |  | ||||||
|  |  10.07.2015 | ||||||
|  |   - bugfix force file: resource in demo resource.extendsall.php | ||||||
|  |  | ||||||
|  |  08.07.2015 | ||||||
|  |   - bugfix convert each word of class names to ucfirst in in compiler. (forum topic 25588) | ||||||
|  |  | ||||||
|  |  07.07.2015 | ||||||
|  |   - improvement allow fetch() or display() called on a template object to get output from other template | ||||||
|  |      like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70 | ||||||
|  |   - improvement Added $limit parameter to regex_replace modifier #71 | ||||||
|  |   - new feature multiple indices on file: resource | ||||||
|  |  | ||||||
|  |  06.07.2015 | ||||||
|  |   - optimize {block} compilation | ||||||
|  |   - optimization get rid of __get and __set in source object | ||||||
|  |  | ||||||
|  |  01.07.2015 | ||||||
|  |   - optimize compile check handling | ||||||
|  |   - update {foreach} compiler | ||||||
|  |   - bugfix debugging console did not display string values containing \n, \r or \t correctly https://github.com/smarty-php/smarty/issues/66 | ||||||
|  |   - optimize source resources | ||||||
|  |  | ||||||
|  |  28.06.2015 | ||||||
|  |   - move $smarty->enableSecurity() into Smarty_Security class | ||||||
|  |   - optimize security isTrustedResourceDir() | ||||||
|  |   - move auto load filter methods into extension | ||||||
|  |   - move $smarty->getTemplateVars() into extension | ||||||
|  |   - move getStreamVariable() into extension | ||||||
|  |   - move $smarty->append() and $smarty->appendByRef() into extension | ||||||
|  |   - optimize autoloader | ||||||
|  |   - optimize file path normalization | ||||||
|  |   - bugfix PATH_SEPARATOR was replaced by mistake in autoloader | ||||||
|  |   - remove redundant code | ||||||
|  |  | ||||||
|  |  27.06.2015 | ||||||
|  |   - bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64 | ||||||
|  |   - update $smarty->_realpath for relative path not starting with './' | ||||||
|  |   - update Smarty security with new realpath handling | ||||||
|  |   - update {include_php} with new realpath handling | ||||||
|  |   - move $smarty->loadPlugin() into extension | ||||||
|  |   - minor compiler optimizations | ||||||
|  |   - bugfix allow function plugins with name ending with 'close' https://github.com/smarty-php/smarty/issues/52 | ||||||
|  |   - rework of $smarty->clearCompiledTemplate() and move it to its own extension | ||||||
|  |  | ||||||
|  |  19.06.2015 | ||||||
|  |   - improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59 | ||||||
|  |  | ||||||
|  |  ===== 3.1.27===== (18.06.2015) | ||||||
|  18.06.2015 |  18.06.2015 | ||||||
|   - bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56 |   - bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56 | ||||||
|  |  | ||||||
| @@ -209,8 +374,8 @@ | |||||||
|  - bugfix Debug Console did not include all data from merged compiled subtemplates |  - bugfix Debug Console did not include all data from merged compiled subtemplates | ||||||
|  |  | ||||||
|  04.11.2014 |  04.11.2014 | ||||||
|  - new feature $smarty->debug = true; => overwrite existing Debug Console window (old behaviour) |  - new feature $smarty->debugging = true; => overwrite existing Debug Console window (old behaviour) | ||||||
|                $smarty->debug = 2; => individual Debug Console window by template name |                $smarty->debugging = 2; => individual Debug Console window by template name | ||||||
|   |   | ||||||
|  03.11.2014 |  03.11.2014 | ||||||
|  - bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301) |  - bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301) | ||||||
|   | |||||||
| @@ -25,62 +25,20 @@ class Smarty_Autoloader | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public static $SMARTY_DIR = ''; |     public static $SMARTY_DIR = ''; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Filepath to Smarty internal plugins |      * Filepath to Smarty internal plugins | ||||||
|      * |      * | ||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public static $SMARTY_SYSPLUGINS_DIR = ''; |     public static $SMARTY_SYSPLUGINS_DIR = ''; | ||||||
|     /** |  | ||||||
|      * Array of not existing classes to avoid is_file calls for  already tested classes |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public static $unknown = array(); |  | ||||||
|     /** |     /** | ||||||
|      * Array with Smarty core classes and their filename |      * Array with Smarty core classes and their filename | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public static $rootClasses = array('Smarty'   => 'Smarty.class.php', |     public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',); | ||||||
|                                        'SmartyBC' => 'SmartyBC.class.php', |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     private static $syspluginsClasses = array( |  | ||||||
|         'smarty_config_source'                  => true, |  | ||||||
|         'smarty_security'                       => true, |  | ||||||
|         'smarty_cacheresource'                  => true, |  | ||||||
|         'smarty_compiledresource'               => true, |  | ||||||
|         'smarty_cacheresource_custom'           => true, |  | ||||||
|         'smarty_cacheresource_keyvaluestore'    => true, |  | ||||||
|         'smarty_resource'                       => true, |  | ||||||
|         'smarty_resource_custom'                => true, |  | ||||||
|         'smarty_resource_uncompiled'            => true, |  | ||||||
|         'smarty_resource_recompiled'            => true, |  | ||||||
|         'smarty_template_source'                => true, |  | ||||||
|         'smarty_template_compiled'              => true, |  | ||||||
|         'smarty_template_cached'                => true, |  | ||||||
|         'smarty_template_config'                => true, |  | ||||||
|         'smarty_data'                           => true, |  | ||||||
|         'smarty_variable'                       => true, |  | ||||||
|         'smarty_undefined_variable'             => true, |  | ||||||
|         'smartyexception'                       => true, |  | ||||||
|         'smartycompilerexception'               => true, |  | ||||||
|         'smarty_internal_data'                  => true, |  | ||||||
|         'smarty_internal_template'              => true, |  | ||||||
|         'smarty_internal_templatebase'          => true, |  | ||||||
|         'smarty_internal_resource_file'         => true, |  | ||||||
|         'smarty_internal_resource_extends'      => true, |  | ||||||
|         'smarty_internal_resource_eval'         => true, |  | ||||||
|         'smarty_internal_resource_string'       => true, |  | ||||||
|         'smarty_internal_resource_registered'   => true, |  | ||||||
|         'smarty_internal_extension_codeframe'   => true, |  | ||||||
|         'smarty_internal_extension_config'      => true, |  | ||||||
|         'smarty_internal_filter_handler'        => true, |  | ||||||
|         'smarty_internal_function_call_handler' => true, |  | ||||||
|         'smarty_internal_cacheresource_file'    => true, |  | ||||||
|         'smarty_internal_write_file'    => true, |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Registers Smarty_Autoloader backward compatible to older installations. |      * Registers Smarty_Autoloader backward compatible to older installations. | ||||||
| @@ -95,7 +53,9 @@ class Smarty_Autoloader | |||||||
|         if (!defined('SMARTY_SPL_AUTOLOAD')) { |         if (!defined('SMARTY_SPL_AUTOLOAD')) { | ||||||
|             define('SMARTY_SPL_AUTOLOAD', 0); |             define('SMARTY_SPL_AUTOLOAD', 0); | ||||||
|         } |         } | ||||||
|         if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { |         if (SMARTY_SPL_AUTOLOAD && | ||||||
|  |             set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false | ||||||
|  |         ) { | ||||||
|             $registeredAutoLoadFunctions = spl_autoload_functions(); |             $registeredAutoLoadFunctions = spl_autoload_functions(); | ||||||
|             if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { |             if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { | ||||||
|                 spl_autoload_register(); |                 spl_autoload_register(); | ||||||
| @@ -112,8 +72,9 @@ class Smarty_Autoloader | |||||||
|      */ |      */ | ||||||
|     public static function register($prepend = false) |     public static function register($prepend = false) | ||||||
|     { |     { | ||||||
|         self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . '/'; |         self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR; | ||||||
|         self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/'; |         self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : | ||||||
|  |             self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR; | ||||||
|         if (version_compare(phpversion(), '5.3.0', '>=')) { |         if (version_compare(phpversion(), '5.3.0', '>=')) { | ||||||
|             spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); |             spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend); | ||||||
|         } else { |         } else { | ||||||
| @@ -128,31 +89,36 @@ class Smarty_Autoloader | |||||||
|      */ |      */ | ||||||
|     public static function autoload($class) |     public static function autoload($class) | ||||||
|     { |     { | ||||||
|         // Request for Smarty or already unknown class |  | ||||||
|         if (isset(self::$unknown[$class])) { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         $_class = strtolower($class); |         $_class = strtolower($class); | ||||||
|         if (isset(self::$syspluginsClasses[$_class])) { |  | ||||||
|             $_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class]; |  | ||||||
|             $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; |  | ||||||
|             require_once $file; |  | ||||||
|             return; |  | ||||||
|         } elseif (0 !== strpos($_class, 'smarty_internal_')) { |  | ||||||
|             if (isset(self::$rootClasses[$class])) { |  | ||||||
|                 $file = self::$SMARTY_DIR . self::$rootClasses[$class]; |  | ||||||
|                 require_once $file; |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             self::$unknown[$class] = true; |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; |         $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php'; | ||||||
|  |         if (strpos($_class, 'smarty_internal_') === 0) { | ||||||
|  |             if (strpos($_class, 'smarty_internal_compile_') === 0) { | ||||||
|                 if (is_file($file)) { |                 if (is_file($file)) { | ||||||
|             require_once $file; |                     require $file; | ||||||
|  |                 } | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |             @include $file; | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/', | ||||||
|  |                        $_class, $match)) { | ||||||
|  |             if (!empty($match[3])) { | ||||||
|  |                 @include $file; | ||||||
|  |                 return; | ||||||
|  |             } elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) { | ||||||
|  |                 $file = self::$rootClasses[$_class]; | ||||||
|  |                 require $file; | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         if (0 !== strpos($_class, 'smarty')) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         if (is_file($file)) { | ||||||
|  |             require $file; | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         self::$unknown[$class] = true; |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -44,6 +44,13 @@ class SmartyBC extends Smarty | |||||||
|      */ |      */ | ||||||
|     public $_version = self::SMARTY_VERSION; |     public $_version = self::SMARTY_VERSION; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * This is an array of directories where trusted php scripts reside. | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $trusted_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Initialize new SmartyBC object |      * Initialize new SmartyBC object | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -128,7 +128,7 @@ | |||||||
|             <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> |             <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> | ||||||
|                 <td><h3><font color=blue>${$vars@key}</font></h3> |                 <td><h3><font color=blue>${$vars@key}</font></h3> | ||||||
|                     {if isset($vars['nocache'])}<b>Nocache</b></br>{/if} |                     {if isset($vars['nocache'])}<b>Nocache</b></br>{/if} | ||||||
|                     {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var:10:80 nofilter}{/if} |                     {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if} | ||||||
|                 </td> |                 </td> | ||||||
|                 <td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td> |                 <td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td> | ||||||
|                 <td>{if isset($vars['attributes'])}<h3>Attributes</h3>{$vars['attributes']|debug_print_var nofilter} {/if}</td> |                 <td>{if isset($vars['attributes'])}<h3>Attributes</h3>{$vars['attributes']|debug_print_var nofilter} {/if}</td> | ||||||
| @@ -141,7 +141,7 @@ | |||||||
|         {foreach $config_vars as $vars} |         {foreach $config_vars as $vars} | ||||||
|             <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> |             <tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}"> | ||||||
|                 <td><h3><font color=blue>#{$vars@key}#</font></h3> |                 <td><h3><font color=blue>#{$vars@key}#</font></h3> | ||||||
|                     {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var:10:80 nofilter}{/if} |                     {if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if} | ||||||
|                 </td> |                 </td> | ||||||
|                 <td>{$vars['value']|debug_print_var:10:80 nofilter}</td> |                 <td>{$vars['value']|debug_print_var:10:80 nofilter}</td> | ||||||
|             </tr> |             </tr> | ||||||
| @@ -152,9 +152,9 @@ | |||||||
|     </html> |     </html> | ||||||
| {/capture} | {/capture} | ||||||
| <script type="text/javascript"> | <script type="text/javascript"> | ||||||
|     {$id = ''} |     {$id = '__Smarty__'} | ||||||
|     {if $display_mode}{$id = "$offset$template_name"|md5}{/if} |     {if $display_mode}{$id = "$offset$template_name"|md5}{/if} | ||||||
|     _smarty_console = window.open("", "console{$id}", "width=680,height=600,left={$offset},top={$offset},resizable,scrollbars=yes"); |     _smarty_console = window.open("", "console{$id}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes"); | ||||||
|     _smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}"); |     _smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}"); | ||||||
|     _smarty_console.document.close(); |     _smarty_console.document.close(); | ||||||
| </script> | </script> | ||||||
|   | |||||||
| @@ -24,9 +24,9 @@ | |||||||
|  */ |  */ | ||||||
| function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array()) | function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array()) | ||||||
| { | { | ||||||
|     $_replace = array("\n" => '<i>\n</i>', |     $_replace = array("\n" => '\n', | ||||||
|                       "\r" => '<i>\r</i>', |                       "\r" => '\r', | ||||||
|                       "\t" => '<i>\t</i>' |                       "\t" => '\t' | ||||||
|     ); |     ); | ||||||
|     switch (gettype($var)) { |     switch (gettype($var)) { | ||||||
|         case 'array' : |         case 'array' : | ||||||
|   | |||||||
| @@ -19,10 +19,11 @@ | |||||||
|  * @param string       $string  input string |  * @param string       $string  input string | ||||||
|  * @param string|array $search  regular expression(s) to search for |  * @param string|array $search  regular expression(s) to search for | ||||||
|  * @param string|array $replace string(s) that should be replaced |  * @param string|array $replace string(s) that should be replaced | ||||||
|  |  * @param int          $limit   the maximum number of replacements | ||||||
|  * |  * | ||||||
|  * @return string |  * @return string | ||||||
|  */ |  */ | ||||||
| function smarty_modifier_regex_replace($string, $search, $replace) | function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1) | ||||||
| { | { | ||||||
|     if (is_array($search)) { |     if (is_array($search)) { | ||||||
|         foreach ($search as $idx => $s) { |         foreach ($search as $idx => $s) { | ||||||
| @@ -32,7 +33,7 @@ function smarty_modifier_regex_replace($string, $search, $replace) | |||||||
|         $search = _smarty_regex_replace_check($search); |         $search = _smarty_regex_replace_check($search); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return preg_replace($search, $replace, $string); |     return preg_replace($search, $replace, $string, $limit); | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|   | |||||||
| @@ -115,11 +115,11 @@ function smarty_modifiercompiler_escape($params, $compiler) | |||||||
|  |  | ||||||
|     // could not optimize |escape call, so fallback to regular plugin |     // could not optimize |escape call, so fallback to regular plugin | ||||||
|     if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { |     if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { | ||||||
|         $compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; |         $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; | ||||||
|         $compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; |         $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape'; | ||||||
|     } else { |     } else { | ||||||
|         $compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; |         $compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php'; | ||||||
|         $compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; |         $compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape'; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return 'smarty_modifier_escape(' . join(', ', $params) . ')'; |     return 'smarty_modifier_escape(' . join(', ', $params) . ')'; | ||||||
|   | |||||||
| @@ -34,11 +34,11 @@ function smarty_modifiercompiler_wordwrap($params, $compiler) | |||||||
|     $function = 'wordwrap'; |     $function = 'wordwrap'; | ||||||
|     if (Smarty::$_MBSTRING) { |     if (Smarty::$_MBSTRING) { | ||||||
|         if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { |         if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { | ||||||
|             $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; |             $compiler->parent_compiler->template->compiled->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; | ||||||
|             $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; |             $compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; | ||||||
|         } else { |         } else { | ||||||
|             $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; |             $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'; | ||||||
|             $compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; |             $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap'; | ||||||
|         } |         } | ||||||
|         $function = 'smarty_mb_wordwrap'; |         $function = 'smarty_mb_wordwrap'; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -21,8 +21,8 @@ function smarty_make_timestamp($string) | |||||||
|     if (empty($string)) { |     if (empty($string)) { | ||||||
|         // use "now": |         // use "now": | ||||||
|         return time(); |         return time(); | ||||||
|     } elseif ($string instanceof DateTime) { |     } elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) { | ||||||
|         return $string->getTimestamp(); |         return (int) $string->format('U'); // PHP 5.2 BC | ||||||
|     } elseif (strlen($string) == 14 && ctype_digit($string)) { |     } elseif (strlen($string) == 14 && ctype_digit($string)) { | ||||||
|         // it is mysql timestamp format of YYYYMMDDHHMMSS? |         // it is mysql timestamp format of YYYYMMDDHHMMSS? | ||||||
|         return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), |         return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), | ||||||
|   | |||||||
| @@ -20,9 +20,7 @@ abstract class Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected static $sysplugins = array( |     protected static $sysplugins = array('file' => 'smarty_internal_cacheresource_file.php',); | ||||||
|         'file' => 'smarty_internal_cacheresource_file.php', |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * populate Cached Object with meta data from Resource |      * populate Cached Object with meta data from Resource | ||||||
| @@ -48,10 +46,11 @@ abstract class Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param Smarty_Internal_Template $_template template object |      * @param Smarty_Internal_Template $_template template object | ||||||
|      * @param Smarty_Template_Cached   $cached    cached object |      * @param Smarty_Template_Cached   $cached    cached object | ||||||
|  |      * @param bool                     $update    flag if called because cache update | ||||||
|      * |      * | ||||||
|      * @return boolean true or false if the cached content does not exist |      * @return bool true or false if the cached content does not exist | ||||||
|      */ |      */ | ||||||
|     abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null); |     abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Write the rendered template output to cache |      * Write the rendered template output to cache | ||||||
| @@ -74,8 +73,8 @@ abstract class Smarty_CacheResource | |||||||
|     { |     { | ||||||
|         if ($_template->cached->handler->process($_template)) { |         if ($_template->cached->handler->process($_template)) { | ||||||
|             ob_start(); |             ob_start(); | ||||||
|             $_template->properties['unifunc']($_template); |             $unifunc = $_template->cached->unifunc; | ||||||
|  |             $unifunc($_template); | ||||||
|             return ob_get_clean(); |             return ob_get_clean(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -186,27 +185,24 @@ abstract class Smarty_CacheResource | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // try smarty's cache |         // try smarty's cache | ||||||
|         if (isset($smarty->_cacheresource_handlers[$type])) { |         if (isset($smarty->_cache['cacheresource_handlers'][$type])) { | ||||||
|             return $smarty->_cacheresource_handlers[$type]; |             return $smarty->_cache['cacheresource_handlers'][$type]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // try registered resource |         // try registered resource | ||||||
|         if (isset($smarty->registered_cache_resources[$type])) { |         if (isset($smarty->registered_cache_resources[$type])) { | ||||||
|             // do not cache these instances as they may vary from instance to instance |             // do not cache these instances as they may vary from instance to instance | ||||||
|             return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type]; |             return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type]; | ||||||
|         } |         } | ||||||
|         // try sysplugins dir |         // try sysplugins dir | ||||||
|         if (isset(self::$sysplugins[$type])) { |         if (isset(self::$sysplugins[$type])) { | ||||||
|             $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); |             $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); | ||||||
|             if (!class_exists($cache_resource_class, false)) { |             return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class(); | ||||||
|                 require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type]; |  | ||||||
|             } |  | ||||||
|             return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class(); |  | ||||||
|         } |         } | ||||||
|         // try plugins dir |         // try plugins dir | ||||||
|         $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); |         $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); | ||||||
|         if ($smarty->loadPlugin($cache_resource_class)) { |         if ($smarty->loadPlugin($cache_resource_class)) { | ||||||
|             return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class(); |             return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class(); | ||||||
|         } |         } | ||||||
|         // give up |         // give up | ||||||
|         throw new SmartyException("Unable to load cache resource '{$type}'"); |         throw new SmartyException("Unable to load cache resource '{$type}'"); | ||||||
| @@ -217,12 +213,13 @@ abstract class Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param Smarty $smarty Smarty object |      * @param Smarty $smarty Smarty object | ||||||
|      */ |      */ | ||||||
|     public static function invalidLoadedCache(Smarty $smarty) |     public function invalidLoadedCache(Smarty $smarty) | ||||||
|     { |     { | ||||||
|         foreach ($smarty->template_objects as $tpl) { |         if (isset($smarty->_cache['template_objects'])) { | ||||||
|  |             foreach ($smarty->_cache['template_objects'] as $key => $tpl) { | ||||||
|                 if (isset($tpl->cached)) { |                 if (isset($tpl->cached)) { | ||||||
|                 $tpl->cached->valid = false; |                     unset ($smarty->_cache['template_objects'][$key]); | ||||||
|                 $tpl->cached->processed = false; |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|     public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) |     public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null; |         $_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null; | ||||||
|         $_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null; |         $_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null; | ||||||
|         $path = $cached->source->filepath . $_cache_id . $_compile_id; |         $path = $cached->source->filepath . $_cache_id . $_compile_id; | ||||||
|         $cached->filepath = sha1($path); |         $cached->filepath = sha1($path); | ||||||
|         if ($_template->smarty->cache_locking) { |         if ($_template->smarty->cache_locking) { | ||||||
| @@ -119,10 +119,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param  Smarty_Internal_Template $_template template object |      * @param  Smarty_Internal_Template $_template template object | ||||||
|      * @param  Smarty_Template_Cached   $cached    cached object |      * @param  Smarty_Template_Cached   $cached    cached object | ||||||
|  |      * @param bool                      $update    flag if called because cache update | ||||||
|      * |      * | ||||||
|      * @return boolean                 true or false if the cached content does not exist |      * @return boolean                 true or false if the cached content does not exist | ||||||
|      */ |      */ | ||||||
|     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null) |     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false) | ||||||
|     { |     { | ||||||
|         if (!$cached) { |         if (!$cached) { | ||||||
|             $cached = $_template->cached; |             $cached = $_template->cached; | ||||||
| @@ -130,14 +131,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|         $content = $cached->content ? $cached->content : null; |         $content = $cached->content ? $cached->content : null; | ||||||
|         $timestamp = $cached->timestamp ? $cached->timestamp : null; |         $timestamp = $cached->timestamp ? $cached->timestamp : null; | ||||||
|         if ($content === null || !$timestamp) { |         if ($content === null || !$timestamp) { | ||||||
|             $this->fetch( |             $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp); | ||||||
|                 $_template->cached->filepath, |  | ||||||
|                 $_template->source->name, |  | ||||||
|                 $_template->cache_id, |  | ||||||
|                 $_template->compile_id, |  | ||||||
|                 $content, |  | ||||||
|                 $timestamp |  | ||||||
|             ); |  | ||||||
|         } |         } | ||||||
|         if (isset($content)) { |         if (isset($content)) { | ||||||
|             /** @var Smarty_Internal_Template $_smarty_tpl |             /** @var Smarty_Internal_Template $_smarty_tpl | ||||||
| @@ -145,7 +139,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|              */ |              */ | ||||||
|             $_smarty_tpl = $_template; |             $_smarty_tpl = $_template; | ||||||
|             eval("?>" . $content); |             eval("?>" . $content); | ||||||
|  |             $cached->content = null; | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -162,14 +156,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function writeCachedContent(Smarty_Internal_Template $_template, $content) |     public function writeCachedContent(Smarty_Internal_Template $_template, $content) | ||||||
|     { |     { | ||||||
|         return $this->save( |         return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, $content); | ||||||
|             $_template->cached->filepath, |  | ||||||
|             $_template->source->name, |  | ||||||
|             $_template->cache_id, |  | ||||||
|             $_template->compile_id, |  | ||||||
|             $_template->properties['cache_lifetime'], |  | ||||||
|             $content |  | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -185,14 +172,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|         $timestamp = null; |         $timestamp = null; | ||||||
|         if ($content === null) { |         if ($content === null) { | ||||||
|             $timestamp = null; |             $timestamp = null; | ||||||
|             $this->fetch( |             $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp); | ||||||
|                 $_template->cached->filepath, |  | ||||||
|                 $_template->source->name, |  | ||||||
|                 $_template->cache_id, |  | ||||||
|                 $_template->compile_id, |  | ||||||
|                 $content, |  | ||||||
|                 $timestamp |  | ||||||
|             ); |  | ||||||
|         } |         } | ||||||
|         if (isset($content)) { |         if (isset($content)) { | ||||||
|             return $content; |             return $content; | ||||||
| @@ -210,8 +190,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function clearAll(Smarty $smarty, $exp_time = null) |     public function clearAll(Smarty $smarty, $exp_time = null) | ||||||
|     { |     { | ||||||
|         $this->cache = array(); |  | ||||||
|  |  | ||||||
|         return $this->delete(null, null, null, $exp_time); |         return $this->delete(null, null, null, $exp_time); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -228,32 +206,23 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) |     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) | ||||||
|     { |     { | ||||||
|         $this->cache = array(); |  | ||||||
|         $cache_name = null; |         $cache_name = null; | ||||||
|  |  | ||||||
|         if (isset($resource_name)) { |         if (isset($resource_name)) { | ||||||
|             $_save_stat = $smarty->caching; |             $source = Smarty_Template_Source::load(null, $smarty, $resource_name); | ||||||
|             $smarty->caching = true; |             if ($source->exists) { | ||||||
|             $tpl = new $smarty->template_class($resource_name, $smarty); |                 $cache_name = $source->name; | ||||||
|             $smarty->caching = $_save_stat; |  | ||||||
|  |  | ||||||
|             if ($tpl->source->exists) { |  | ||||||
|                 $cache_name = $tpl->source->name; |  | ||||||
|             } else { |             } else { | ||||||
|                 return 0; |                 return 0; | ||||||
|             } |             } | ||||||
|             // remove from template cache |             // remove from template cache | ||||||
|             if ($smarty->allow_ambiguous_resources) { |             if (isset($smarty->_cache['template_objects'])) { | ||||||
|                 $_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id; |                 foreach ($smarty->_cache['template_objects'] as $key => $_tpl) { | ||||||
|             } else { |                     if (isset($_tpl->cached) && $_tpl->source->uid == $source->uid) { | ||||||
|                 $_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id; |                         unset($smarty->_cache['template_objects'][$key]); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             if (isset($_templateId[150])) { |  | ||||||
|                 $_templateId = sha1($_templateId); |  | ||||||
|             } |             } | ||||||
|             unset($smarty->template_objects[$_templateId]); |  | ||||||
|             // template object no longer needed |  | ||||||
|             unset($tpl); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $this->delete($cache_name, $cache_id, $compile_id, $exp_time); |         return $this->delete($cache_name, $cache_id, $compile_id, $exp_time); | ||||||
|   | |||||||
| @@ -54,7 +54,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) |     public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); |         $cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . | ||||||
|  |             $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id); | ||||||
|  |  | ||||||
|         $this->populateTimestamp($cached); |         $this->populateTimestamp($cached); | ||||||
|     } |     } | ||||||
| @@ -81,10 +82,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param  Smarty_Internal_Template $_template template object |      * @param  Smarty_Internal_Template $_template template object | ||||||
|      * @param  Smarty_Template_Cached   $cached    cached object |      * @param  Smarty_Template_Cached   $cached    cached object | ||||||
|  |      * @param bool                      $update    flag if called because cache update | ||||||
|      * |      * | ||||||
|      * @return boolean                 true or false if the cached content does not exist |      * @return boolean                 true or false if the cached content does not exist | ||||||
|      */ |      */ | ||||||
|     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null) |     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false) | ||||||
|     { |     { | ||||||
|         if (!$cached) { |         if (!$cached) { | ||||||
|             $cached = $_template->cached; |             $cached = $_template->cached; | ||||||
| @@ -121,7 +123,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|     { |     { | ||||||
|         $this->addMetaTimestamp($content); |         $this->addMetaTimestamp($content); | ||||||
|  |  | ||||||
|         return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']); |         return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -162,7 +164,14 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|         if (!$this->purge()) { |         if (!$this->purge()) { | ||||||
|             $this->invalidate(null); |             $this->invalidate(null); | ||||||
|         } |         } | ||||||
|  |         // remove from template cache | ||||||
|  |         if (isset($smarty->_cache['template_objects'])) { | ||||||
|  |             foreach ($smarty->_cache['template_objects'] as $key => $tpl) { | ||||||
|  |                 if (isset($tpl->cached)) { | ||||||
|  |                     unset($smarty->_cache['template_objects'][$key]); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|         return - 1; |         return - 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -183,11 +192,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) |     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) | ||||||
|     { |     { | ||||||
|         $uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id); |         $uid = $this->getTemplateUid($smarty, $resource_name); | ||||||
|         $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id); |         $cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . | ||||||
|  |             $this->sanitize($compile_id); | ||||||
|         $this->delete(array($cid)); |         $this->delete(array($cid)); | ||||||
|         $this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid); |         $this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid); | ||||||
|  |         // remove from template cache | ||||||
|  |         if (isset($resource_name) && isset($smarty->_cache['template_objects'])) { | ||||||
|  |             if (isset($smarty->_cache['template_objects'])) { | ||||||
|  |                 foreach ($smarty->_cache['template_objects'] as $key => $tpl) { | ||||||
|  |                     if ($tpl->source->uid == $uid && isset($tpl->cached)) { | ||||||
|  |                         unset($smarty->_cache['template_objects'][$key]); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|         return - 1; |         return - 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -196,33 +215,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param  Smarty $smarty        Smarty object |      * @param  Smarty $smarty        Smarty object | ||||||
|      * @param  string $resource_name template name |      * @param  string $resource_name template name | ||||||
|      * @param  string $cache_id      cache id |  | ||||||
|      * @param  string $compile_id    compile id |  | ||||||
|      * |      * | ||||||
|      * @return string filepath of cache file |      * @return string filepath of cache file | ||||||
|  |      * @throws \SmartyException | ||||||
|  |      * | ||||||
|      */ |      */ | ||||||
|     protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id) |     protected function getTemplateUid(Smarty $smarty, $resource_name) | ||||||
|     { |     { | ||||||
|         $uid = ''; |  | ||||||
|         if (isset($resource_name)) { |         if (isset($resource_name)) { | ||||||
|             $tpl = new $smarty->template_class($resource_name, $smarty); |             $source = Smarty_Template_Source::load(null, $smarty, $resource_name); | ||||||
|             if ($tpl->source->exists) { |             if ($source->exists) { | ||||||
|                 $uid = $tpl->source->uid; |                 return $source->uid; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // remove from template cache |  | ||||||
|             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])) { |         return ''; | ||||||
|                 $_templateId = sha1($_templateId); |  | ||||||
|             } |  | ||||||
|             unset($smarty->template_objects[$_templateId]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $uid; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -234,12 +240,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     protected function sanitize($string) |     protected function sanitize($string) | ||||||
|     { |     { | ||||||
|         // some poeple smoke bad weed |  | ||||||
|         $string = trim($string, '|'); |         $string = trim($string, '|'); | ||||||
|         if (!$string) { |         if (!$string) { | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return preg_replace('#[^\w\|]+#S', '_', $string); |         return preg_replace('#[^\w\|]+#S', '_', $string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -397,7 +401,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource | |||||||
|             $t[] = 'IVK#COMPILE' . $_compile; |             $t[] = 'IVK#COMPILE' . $_compile; | ||||||
|         } |         } | ||||||
|         $_name .= '#'; |         $_name .= '#'; | ||||||
|         // some poeple smoke bad weed |  | ||||||
|         $cid = trim($cache_id, '|'); |         $cid = trim($cache_id, '|'); | ||||||
|         if (!$cid) { |         if (!$cid) { | ||||||
|             return $t; |             return $t; | ||||||
|   | |||||||
| @@ -30,6 +30,7 @@ class Smarty_Data extends Smarty_Internal_Data | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $dataObjectName = ''; |     public $dataObjectName = ''; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Smarty object |      * Smarty object | ||||||
|      * |      * | ||||||
| @@ -48,6 +49,7 @@ class Smarty_Data extends Smarty_Internal_Data | |||||||
|      */ |      */ | ||||||
|     public function __construct($_parent = null, $smarty = null, $name = null) |     public function __construct($_parent = null, $smarty = null, $name = null) | ||||||
|     { |     { | ||||||
|  |         parent::__construct(); | ||||||
|         self::$count ++; |         self::$count ++; | ||||||
|         $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); |         $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); | ||||||
|         $this->smarty = $smarty; |         $this->smarty = $smarty; | ||||||
|   | |||||||
| @@ -29,14 +29,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|     { |     { | ||||||
|         $_source_file_path = str_replace(':', '.', $_template->source->filepath); |         $_source_file_path = str_replace(':', '.', $_template->source->filepath); | ||||||
|         $_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null; |         $_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null; | ||||||
|         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null; |         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null; | ||||||
|         $_filepath = $_template->source->uid; |         $_filepath = $_template->source->uid; | ||||||
|         // if use_sub_dirs, break file into directories |         // if use_sub_dirs, break file into directories | ||||||
|         if ($_template->smarty->use_sub_dirs) { |         if ($_template->smarty->use_sub_dirs) { | ||||||
|             $_filepath = substr($_filepath, 0, 2) . DS |             $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS . | ||||||
|                 . substr($_filepath, 2, 2) . DS |                 $_filepath; | ||||||
|                 . substr($_filepath, 4, 2) . DS |  | ||||||
|                 . $_filepath; |  | ||||||
|         } |         } | ||||||
|         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; |         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; | ||||||
|         if (isset($_cache_id)) { |         if (isset($_cache_id)) { | ||||||
| @@ -60,7 +58,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|             } |             } | ||||||
|             $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; |             $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; | ||||||
|         } |         } | ||||||
|         $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php'; |         $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . | ||||||
|  |             '.php'; | ||||||
|         $cached->timestamp = $cached->exists = is_file($cached->filepath); |         $cached->timestamp = $cached->exists = is_file($cached->filepath); | ||||||
|         if ($cached->exists) { |         if ($cached->exists) { | ||||||
|             $cached->timestamp = filemtime($cached->filepath); |             $cached->timestamp = filemtime($cached->filepath); | ||||||
| @@ -87,18 +86,23 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|      * |      * | ||||||
|      * @param Smarty_Internal_Template $_template template object |      * @param Smarty_Internal_Template $_template template object | ||||||
|      * @param Smarty_Template_Cached   $cached    cached object |      * @param Smarty_Template_Cached   $cached    cached object | ||||||
|  |      * @param bool                     $update flag if called because cache update | ||||||
|      * |      * | ||||||
|      * @return boolean true or false if the cached content does not exist |      * @return boolean true or false if the cached content does not exist | ||||||
|      */ |      */ | ||||||
|     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null) |     public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false) | ||||||
|     { |     { | ||||||
|         /** @var Smarty_Internal_Template $_smarty_tpl |         /** @var Smarty_Internal_Template $_smarty_tpl | ||||||
|          * used in included file |          * used in included file | ||||||
|          */ |          */ | ||||||
|         $_smarty_tpl = $_template; |         $_smarty_tpl = $_template; | ||||||
|  |         $_template->cached->valid = false; | ||||||
|  |         if ($update && defined('HHVM_VERSION')) { | ||||||
|  |             return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath); | ||||||
|  |         } else { | ||||||
|             return @include $_template->cached->filepath; |             return @include $_template->cached->filepath; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Write the rendered template output to cache |      * Write the rendered template output to cache | ||||||
| @@ -110,8 +114,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function writeCachedContent(Smarty_Internal_Template $_template, $content) |     public function writeCachedContent(Smarty_Internal_Template $_template, $content) | ||||||
|     { |     { | ||||||
|         $obj = new Smarty_Internal_Write_File(); |         if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { | ||||||
|         if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { |             if (function_exists('opcache_invalidate')) { | ||||||
|  |                 opcache_invalidate($_template->cached->filepath); | ||||||
|  |             } | ||||||
|             $cached = $_template->cached; |             $cached = $_template->cached; | ||||||
|             $cached->timestamp = $cached->exists = is_file($cached->filepath); |             $cached->timestamp = $cached->exists = is_file($cached->filepath); | ||||||
|             if ($cached->exists) { |             if ($cached->exists) { | ||||||
| @@ -147,7 +153,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function clearAll(Smarty $smarty, $exp_time = null) |     public function clearAll(Smarty $smarty, $exp_time = null) | ||||||
|     { |     { | ||||||
|         return $this->clear($smarty, null, null, null, $exp_time); |         return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -163,108 +169,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource | |||||||
|      */ |      */ | ||||||
|     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) |     public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time) | ||||||
|     { |     { | ||||||
|         $_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null; |         return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time); | ||||||
|         $_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()) . '/'; |  | ||||||
|         if ($_dir == '/') { //We should never want to delete this! |  | ||||||
|             return 0; |  | ||||||
|         } |  | ||||||
|         $_dir_length = strlen($_dir); |  | ||||||
|         if (isset($_cache_id)) { |  | ||||||
|             $_cache_id_parts = explode('|', $_cache_id); |  | ||||||
|             $_cache_id_parts_count = count($_cache_id_parts); |  | ||||||
|             if ($smarty->use_sub_dirs) { |  | ||||||
|                 foreach ($_cache_id_parts as $id_part) { |  | ||||||
|                     $_dir .= $id_part . DS; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (isset($resource_name)) { |  | ||||||
|             $_save_stat = $smarty->caching; |  | ||||||
|             $smarty->caching = true; |  | ||||||
|             $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) { |  | ||||||
|                 $_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath)); |  | ||||||
|             } else { |  | ||||||
|                 return 0; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $_count = 0; |  | ||||||
|         $_time = time(); |  | ||||||
|         if (file_exists($_dir)) { |  | ||||||
|             $_cacheDirs = new RecursiveDirectoryIterator($_dir); |  | ||||||
|             $_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST); |  | ||||||
|             foreach ($_cache as $_file) { |  | ||||||
|                 if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) { |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
|                 // directory ? |  | ||||||
|                 if ($_file->isDir()) { |  | ||||||
|                     if (!$_cache->isDot()) { |  | ||||||
|                         // delete folder if empty |  | ||||||
|                         @rmdir($_file->getPathname()); |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     $_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length))); |  | ||||||
|                     $_parts_count = count($_parts); |  | ||||||
|                     // check name |  | ||||||
|                     if (isset($resource_name)) { |  | ||||||
|                         if ($_parts[$_parts_count - 1] != $_resourcename_parts) { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     // check compile id |  | ||||||
|                     if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) { |  | ||||||
|                         continue; |  | ||||||
|                     } |  | ||||||
|                     // check cache id |  | ||||||
|                     if (isset($_cache_id)) { |  | ||||||
|                         // count of cache id parts |  | ||||||
|                         $_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset; |  | ||||||
|                         if ($_parts_count < $_cache_id_parts_count) { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
|                         for ($i = 0; $i < $_cache_id_parts_count; $i ++) { |  | ||||||
|                             if ($_parts[$i] != $_cache_id_parts[$i]) { |  | ||||||
|                                 continue 2; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     // expired ? |  | ||||||
|                     if (isset($exp_time)) { |  | ||||||
|                         if ($exp_time < 0) { |  | ||||||
|                             preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match); |  | ||||||
|                             if ($_time < (@filemtime($_file) + $match[1])) { |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|                         } else { |  | ||||||
|                             if ($_time - @filemtime($_file) < $exp_time) { |  | ||||||
|                                 continue; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     $_count += @unlink((string) $_file) ? 1 : 0; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $_count; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -20,12 +20,12 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign | |||||||
|      * Compiles code for the {append} tag |      * Compiles code for the {append} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // the following must be assigned at runtime because it will be overwritten in parent class |         // the following must be assigned at runtime because it will be overwritten in parent class | ||||||
|         $this->required_attributes = array('var', 'value'); |         $this->required_attributes = array('var', 'value'); | ||||||
|   | |||||||
| @@ -16,23 +16,31 @@ | |||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase | ||||||
| { | { | ||||||
|  |     /** | ||||||
|  |      * Valid scope names | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $valid_scopes = array('local'  => true, 'parent' => true, 'root' => true, 'global' => true, | ||||||
|  |                                  'smarty' => true, 'tpl_root' => true); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {assign} tag |      * Compiles code for the {assign} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append |         // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append | ||||||
|         $this->required_attributes = array('var', 'value'); |         $this->required_attributes = array('var', 'value'); | ||||||
|         $this->shorttag_order = array('var', 'value'); |         $this->shorttag_order = array('var', 'value'); | ||||||
|         $this->optional_attributes = array('scope'); |         $this->optional_attributes = array('scope', 'bubble_up'); | ||||||
|         $_nocache = 'null'; |         $_nocache = 'null'; | ||||||
|         $_scope = Smarty::SCOPE_LOCAL; |  | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         // nocache ? |         // nocache ? | ||||||
| @@ -46,39 +54,43 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // scope setup |         // scope setup | ||||||
|  |         $_scope = Smarty::SCOPE_LOCAL; | ||||||
|         if (isset($_attr['scope'])) { |         if (isset($_attr['scope'])) { | ||||||
|             $_attr['scope'] = trim($_attr['scope'], "'\""); |             $_attr['scope'] = trim($_attr['scope'], "'\""); | ||||||
|  |             if (!isset($this->valid_scopes[$_attr['scope']])) { | ||||||
|  |                 $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true); | ||||||
|  |             } | ||||||
|  |             if ($_attr['scope'] != 'local') { | ||||||
|                 if ($_attr['scope'] == 'parent') { |                 if ($_attr['scope'] == 'parent') { | ||||||
|                     $_scope = Smarty::SCOPE_PARENT; |                     $_scope = Smarty::SCOPE_PARENT; | ||||||
|                 } elseif ($_attr['scope'] == 'root') { |                 } elseif ($_attr['scope'] == 'root') { | ||||||
|                     $_scope = Smarty::SCOPE_ROOT; |                     $_scope = Smarty::SCOPE_ROOT; | ||||||
|                 } elseif ($_attr['scope'] == 'global') { |                 } elseif ($_attr['scope'] == 'global') { | ||||||
|                     $_scope = Smarty::SCOPE_GLOBAL; |                     $_scope = Smarty::SCOPE_GLOBAL; | ||||||
|             } else { |                 } elseif ($_attr['scope'] == 'smarty') { | ||||||
|                 $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); |                     $_scope = Smarty::SCOPE_SMARTY; | ||||||
|  |                 } elseif ($_attr['scope'] == 'tpl_root') { | ||||||
|  |                     $_scope = Smarty::SCOPE_TPL_ROOT; | ||||||
|  |                 } | ||||||
|  |                 $_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // compiled output |         // compiled output | ||||||
|         if (isset($parameter['smarty_internal_index'])) { |         if (isset($parameter['smarty_internal_index'])) { | ||||||
|             $output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; |             $output = | ||||||
|  |                 "<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; | ||||||
|         } else { |         } else { | ||||||
|             // implement Smarty2's behaviour of variables assigned by reference |             // implement Smarty2's behaviour of variables assigned by reference | ||||||
|             if ($compiler->template->smarty instanceof SmartyBC) { |             if ($compiler->template->smarty instanceof SmartyBC) { | ||||||
|                 $output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; |                 $output = | ||||||
|                 $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;"; |                     "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; | ||||||
|                 $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);"; |                 $output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;"; | ||||||
|  |                 $output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);"; | ||||||
|             } else { |             } else { | ||||||
|                 $output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);"; |                 $output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);"; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if ($_scope == Smarty::SCOPE_PARENT) { |         $output .= "\n\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, $_attr[var], $_scope);"; | ||||||
|             $output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; |  | ||||||
|         } elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) { |  | ||||||
|             $output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }"; |  | ||||||
|         } |  | ||||||
|         if ($_scope == Smarty::SCOPE_GLOBAL) { |  | ||||||
|             $output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];"; |  | ||||||
|         } |  | ||||||
|         $output .= '?>'; |         $output .= '?>'; | ||||||
|  |  | ||||||
|         return $output; |         return $output; | ||||||
|   | |||||||
| @@ -1,24 +1,20 @@ | |||||||
| <?php | <?php | ||||||
|  | /* | ||||||
| /** |  * This file is part of Smarty. | ||||||
|  * Smarty Internal Plugin Compile Block |  | ||||||
|  * Compiles the {block}{/block} tags |  | ||||||
|  * |  * | ||||||
|  * @package    Smarty |  * (c) 2015 Uwe Tews | ||||||
|  * @subpackage Compiler |  * | ||||||
|  * @author     Uwe Tews |  * For the full copyright and license information, please view the LICENSE | ||||||
|  |  * file that was distributed with this source code. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Smarty Internal Plugin Compile Block Class |  * Smarty Internal Plugin Compile Block Class | ||||||
|  * |  * | ||||||
|  * @package    Smarty |  * @author Uwe Tews <uwe.tews@googlemail.com> | ||||||
|  * @subpackage Compiler |  | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance | ||||||
| { | { | ||||||
|  |  | ||||||
|     const parent = '____SMARTY_BLOCK_PARENT____'; |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -41,7 +37,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase | |||||||
|      * @var array |      * @var array | ||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $option_flags = array('hide', 'append', 'prepend', 'nocache'); |     public $option_flags = array('hide', 'nocache'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
| @@ -49,395 +45,248 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase | |||||||
|      * @var array |      * @var array | ||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('internal_file', 'internal_uid', 'internal_line'); |     public $optional_attributes = array('assign'); | ||||||
|     /** |  | ||||||
|      * nested child block names |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public static $nested_block_names = array(); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * child block source buffer |      * nesting level of block tags | ||||||
|      * |      * | ||||||
|      * @var array |      * @var int | ||||||
|      */ |      */ | ||||||
|     public static $block_data = array(); |     public static $blockTagNestingLevel = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Saved compiler object | ||||||
|  |      * | ||||||
|  |      * @var Smarty_Internal_TemplateCompilerBase | ||||||
|  |      */ | ||||||
|  |     public $compiler = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {block} tag |      * Compiles code for the {block} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                 $args      array with attributes from parser |      * @param  array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler compiler object |      * @param  \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|  |      * @param  array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return boolean true |      * @return bool true | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         if (!isset($compiler->_cache['blockNesting'])) { | ||||||
|  |             $compiler->_cache['blockNesting'] = 0; | ||||||
|  |         } | ||||||
|  |         if ($compiler->_cache['blockNesting'] == 0) { | ||||||
|  |             // make sure that inheritance gets initialized in template code | ||||||
|  |             $this->registerInit($compiler); | ||||||
|  |             $this->option_flags = array('hide', 'nocache', 'append', 'prepend'); | ||||||
|  |         } else { | ||||||
|  |             $this->option_flags = array('hide', 'nocache'); | ||||||
|  |         } | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         $_name = trim($_attr['name'], "\"'"); |         $compiler->_cache['blockNesting'] ++; | ||||||
|  |         $compiler->_cache['blockName'][$compiler->_cache['blockNesting']] = $_attr['name']; | ||||||
|         // existing child must override parent settings |         $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][0] = 'block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true)); | ||||||
|         if (isset($compiler->template->block_data[$_name]) && $compiler->template->block_data[$_name]['mode'] == 'replace') { |         $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = false; | ||||||
|             $_attr['append'] = false; |         $this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer, | ||||||
|             $_attr['prepend'] = false; |                                                  $compiler->template->compiled->has_nocache_code, | ||||||
|  |                                                  $compiler->template->caching)); | ||||||
|  |         // must whole block be nocache ? | ||||||
|  |         if ($compiler->tag_nocache) { | ||||||
|  |             $i = 0; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // check if we process an inheritance child template |  | ||||||
|         if ($compiler->inheritance_child) { |  | ||||||
|             array_unshift(self::$nested_block_names, $_name); |  | ||||||
|             // 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}' 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'; |  | ||||||
|             } |  | ||||||
|             self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter; |  | ||||||
|  |  | ||||||
|             $save = array($_attr, $compiler->inheritance); |  | ||||||
|             $this->openTag($compiler, 'block', $save); |  | ||||||
|             // set flag for {block} tag |  | ||||||
|             $compiler->inheritance = true; |  | ||||||
|             $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); |  | ||||||
|             $compiler->has_code = false; |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         // must merge includes |  | ||||||
|         if ($_attr['nocache'] == true) { |  | ||||||
|             $compiler->tag_nocache = true; |  | ||||||
|         } |  | ||||||
|         $save = array($_attr, $compiler->inheritance, $compiler->parser->current_buffer, $compiler->nocache); |  | ||||||
|         $this->openTag($compiler, 'block', $save); |  | ||||||
|         $compiler->inheritance = true; |  | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|  |         // $compiler->suppressNocacheProcessing = true; | ||||||
|         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); |         if ($_attr['nocache'] === true) { | ||||||
|         $compiler->has_code = false; |             //$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->taglineno); | ||||||
|  |         } | ||||||
|         return true; |         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); | ||||||
|  |         $compiler->template->compiled->has_nocache_code = false; | ||||||
|  |         $compiler->suppressNocacheProcessing = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compile saved child block source |      * Compile saved child block source | ||||||
|      * |      * | ||||||
|      * @param object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase compiler object | ||||||
|      * @param string                                $_name   optional name of child block |      * @param string                                $_name   optional name of child block | ||||||
|      * |      * | ||||||
|      * @return string   compiled code of child block |      * @return string   compiled code of child block | ||||||
|      */ |      */ | ||||||
|     static function compileChildBlock($compiler, $_name = null) |     static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) | ||||||
|     { |     { | ||||||
|         if ($compiler->inheritance_child) { |         if (!isset($compiler->_cache['blockNesting'])) { | ||||||
|             $name1 = Smarty_Internal_Compile_Block::$nested_block_names[0]; |             $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', | ||||||
|             if (isset($compiler->template->block_data[$name1])) { |                                               $compiler->parser->lex->taglineno); | ||||||
|                 //  replace inner block name with generic |  | ||||||
|                 Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source']; |  | ||||||
|                 Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true; |  | ||||||
|         } |         } | ||||||
|             $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); |  | ||||||
|             $compiler->has_code = false; |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         // if called by {$smarty.block.child} we must search the name of enclosing {block} |  | ||||||
|         if ($_name == null) { |  | ||||||
|             $stack_count = count($compiler->_tag_stack); |  | ||||||
|             while (-- $stack_count >= 0) { |  | ||||||
|                 if ($compiler->_tag_stack[$stack_count][0] == 'block') { |  | ||||||
|                     $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'"); |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if ($_name == null) { |  | ||||||
|             $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->lex->taglineno); |  | ||||||
|         } |  | ||||||
|         // undefined child? |  | ||||||
|         if (!isset($compiler->template->block_data[$_name]['source'])) { |  | ||||||
|             $compiler->popTrace(); |  | ||||||
|             return ''; |  | ||||||
|         } |  | ||||||
|         // flag that child is already compile by {$smarty.block.child} inclusion |  | ||||||
|         $compiler->template->block_data[$_name]['compiled'] = true; |  | ||||||
|         $_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, |  | ||||||
|                                              $compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime); |  | ||||||
|         if ($compiler->smarty->debugging) { |  | ||||||
|             Smarty_Internal_Debug::ignore($_tpl); |  | ||||||
|         } |  | ||||||
|         $_tpl->tpl_vars = $compiler->template->tpl_vars; |  | ||||||
|         $_tpl->variable_filters = $compiler->template->variable_filters; |  | ||||||
|         $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; |  | ||||||
|         $_tpl->allow_relative_path = true; |  | ||||||
|         $_tpl->compiler->inheritance = true; |  | ||||||
|         $_tpl->compiler->suppressHeader = true; |  | ||||||
|         $_tpl->compiler->suppressFilter = true; |  | ||||||
|         $_tpl->compiler->suppressTemplatePropertyHeader = true; |  | ||||||
|         $nocache = $compiler->nocache || $compiler->tag_nocache; |  | ||||||
|         if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) { |  | ||||||
|             $_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler)); |  | ||||||
|         } elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') { |  | ||||||
|             $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler) . $compiler->parser->current_buffer->to_smarty_php(); |  | ||||||
|         } elseif ($compiler->template->block_data[$_name]['mode'] == 'append') { |  | ||||||
|             $_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler); |  | ||||||
|         } elseif (!empty($compiler->template->block_data[$_name])) { |  | ||||||
|             $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler); |  | ||||||
|         } |  | ||||||
|         $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']); |  | ||||||
|         $compiler->template->properties['tpl_function'] = array_merge($compiler->template->properties['tpl_function'], $_tpl->properties['tpl_function']); |  | ||||||
|         $compiler->template->variable_filters = $_tpl->variable_filters; |  | ||||||
|         if ($_tpl->has_nocache_code) { |  | ||||||
|             $compiler->template->has_nocache_code = true; |  | ||||||
|         } |  | ||||||
|         foreach ($_tpl->required_plugins as $key => $tmp1) { |  | ||||||
|             if ($compiler->nocache && $compiler->template->caching) { |  | ||||||
|                 $code = 'nocache'; |  | ||||||
|             } else { |  | ||||||
|                 $code = $key; |  | ||||||
|             } |  | ||||||
|             foreach ($tmp1 as $name => $tmp) { |  | ||||||
|                 foreach ($tmp as $type => $data) { |  | ||||||
|                     $compiler->template->required_plugins[$code][$name][$type] = $data; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         unset($_tpl); |  | ||||||
|         $compiler->has_code = true; |         $compiler->has_code = true; | ||||||
|         return $_output; |         $compiler->suppressNocacheProcessing = true; | ||||||
|  |         $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true; | ||||||
|  |         $output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; | ||||||
|  |         return $output; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compile $smarty.block.parent |      * Compile $smarty.block.parent | ||||||
|      * |      * | ||||||
|      * @param object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * @param string                                $_name    optional name of child block |      * @param string                                $_name    optional name of child block | ||||||
|      * |      * | ||||||
|      * @return string   compiled code of child block |      * @return string   compiled code of child block | ||||||
|      */ |      */ | ||||||
|     static function compileParentBlock($compiler, $_name = null) |     static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) | ||||||
|     { |     { | ||||||
|         // if called by {$smarty.block.parent} we must search the name of enclosing {block} |         if (!isset($compiler->_cache['blockNesting'])) { | ||||||
|         if ($_name == null) { |             $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', | ||||||
|             $stack_count = count($compiler->_tag_stack); |                                               $compiler->parser->lex->taglineno); | ||||||
|             while (-- $stack_count >= 0) { |  | ||||||
|                 if ($compiler->_tag_stack[$stack_count][0] == 'block') { |  | ||||||
|                     $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'"); |  | ||||||
|                     break; |  | ||||||
|         } |         } | ||||||
|             } |         $compiler->suppressNocacheProcessing = true; | ||||||
|         } |         $compiler->has_code = true; | ||||||
|         if ($_name == null) { |         $output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; | ||||||
|             $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno); |         return $output; | ||||||
|         } |  | ||||||
|         if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) { |  | ||||||
|             $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno); |  | ||||||
|         } |  | ||||||
|         Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent; |  | ||||||
|         $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); |  | ||||||
|         $compiler->has_code = false; |  | ||||||
|         return; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Process block source |  | ||||||
|      * |  | ||||||
|      * @param        $compiler |  | ||||||
|      * @param string $source source text |  | ||||||
|      */ |  | ||||||
|     static function blockSource($compiler, $source) |  | ||||||
|     { |  | ||||||
|         Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= $source; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Smarty Internal Plugin Compile BlockClose Class |  * Smarty Internal Plugin Compile BlockClose Class | ||||||
|  * |  * | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage Compiler |  | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {/block} tag |      * Compiles code for the {/block} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|  |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return bool true | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block')); | ||||||
|  |         // init block parameter | ||||||
|  |         $_block = $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]; | ||||||
|  |         unset($compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]); | ||||||
|  |         $_block[2] = $_block[3] = 0; | ||||||
|  |         $_name =  trim($_attr['name'], "'\""); | ||||||
|  |         $_assign = isset($_attr['assign']) ? $_attr['assign'] : null; | ||||||
|  |         unset($_attr['assign'], $_attr['name']); | ||||||
|  |         foreach ($_attr as $name => $stat) { | ||||||
|  |             if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) { | ||||||
|  |                 $_block[$name] = is_string($stat) ? trim($stat, "'\"") : $stat; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         $_funcName = $_block[0]; | ||||||
|  |         // get compiled block code | ||||||
|  |         $_functionCode = $compiler->parser->current_buffer; | ||||||
|  |         // setup buffer for template function code | ||||||
|  |         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); | ||||||
|  |  | ||||||
|  |         if ($compiler->template->compiled->has_nocache_code) { | ||||||
|  |             //            $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; | ||||||
|  |             $_block[6] = $_funcNameCaching = $_funcName . '_nocache'; | ||||||
|  |             $output = "<?php\n"; | ||||||
|  |             $output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n"; | ||||||
|  |             $output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$_blockParentStack) {\n"; | ||||||
|  |             $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; | ||||||
|  |             $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; | ||||||
|  |             if (isset($_assign)) { | ||||||
|  |                 $output .= "ob_start();\n"; | ||||||
|  |             } | ||||||
|  |             $output .= "?>\n"; | ||||||
|  |             $compiler->parser->current_buffer->append_subtree($compiler->parser, | ||||||
|  |                                                               new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                                 $output)); | ||||||
|  |             $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); | ||||||
|  |             $output = "<?php\n"; | ||||||
|  |             if (isset($_assign)) { | ||||||
|  |                 $output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n"; | ||||||
|  |             } | ||||||
|  |             $output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; | ||||||
|  |             $output .= "}\n"; | ||||||
|  |             $output .= "/* {/block '{$_name}'} */\n\n"; | ||||||
|  |             $output .= "?>\n"; | ||||||
|  |             $compiler->parser->current_buffer->append_subtree($compiler->parser, | ||||||
|  |                                                               new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                                 $output)); | ||||||
|  |             $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser); | ||||||
|  |             $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); | ||||||
|  |             $this->compiler = $compiler; | ||||||
|  |             $_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", | ||||||
|  |                                                                                      array($this, 'removeNocache'), | ||||||
|  |                                                                                      $_functionCode->to_smarty_php($compiler->parser))); | ||||||
|  |             $this->compiler = null; | ||||||
|  |         } | ||||||
|  |         $output = "<?php\n"; | ||||||
|  |         $output .= "/* {block '{$_name}'}  {$compiler->template->source->type}:{$compiler->template->source->name} */\n"; | ||||||
|  |         $output .= "function {$_funcName}(\$_smarty_tpl, \$_blockParentStack) {\n"; | ||||||
|  |         if (isset($_assign)) { | ||||||
|  |             $output .= "ob_start();\n"; | ||||||
|  |         } | ||||||
|  |         $output .= "?>\n"; | ||||||
|  |         $compiler->parser->current_buffer->append_subtree($compiler->parser, | ||||||
|  |                                                           new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                             $output)); | ||||||
|  |         $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); | ||||||
|  |         $output = "<?php\n"; | ||||||
|  |         if (isset($_assign)) { | ||||||
|  |             $output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n"; | ||||||
|  |         } | ||||||
|  |         $output .= "}\n"; | ||||||
|  |         $output .= "/* {/block '{$_name}'} */\n\n"; | ||||||
|  |         $output .= "?>\n"; | ||||||
|  |         $compiler->parser->current_buffer->append_subtree($compiler->parser, | ||||||
|  |                                                           new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                             $output)); | ||||||
|  |         $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); | ||||||
|  |         // nocache plugins must be copied | ||||||
|  |         if (!empty($compiler->template->compiled->required_plugins['nocache'])) { | ||||||
|  |             foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) { | ||||||
|  |                 foreach ($tmp as $type => $data) { | ||||||
|  |                     $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = | ||||||
|  |                         $data; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         // restore old status | ||||||
|  |         $compiler->template->compiled->has_nocache_code = $_has_nocache_code; | ||||||
|  |         $compiler->tag_nocache = $compiler->nocache; | ||||||
|  |         $compiler->nocache = $_nocache; | ||||||
|  |         $compiler->parser->current_buffer = $_buffer; | ||||||
|  |         $output = "<?php \n"; | ||||||
|  |         if ($compiler->_cache['blockNesting'] == 1) { | ||||||
|  |             $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . | ||||||
|  |                 var_export($_block, true) . ");\n"; | ||||||
|  |         } else { | ||||||
|  |             $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . | ||||||
|  |                 var_export($_block, true) . ", \$_blockParentStack);\n"; | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |         $output .= "?>\n"; | ||||||
|  |         $compiler->_cache['blockNesting'] --; | ||||||
|  |         if ($compiler->_cache['blockNesting'] == 0) { | ||||||
|  |             unset($compiler->_cache['blockNesting']); | ||||||
|  |         } | ||||||
|         $compiler->has_code = true; |         $compiler->has_code = true; | ||||||
|         // check and get attributes |  | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |  | ||||||
|         $saved_data = $this->closeTag($compiler, array('block')); |  | ||||||
|         $_name = trim($saved_data[0]['name'], "\"'"); |  | ||||||
|         // reset flag for {block} tag |  | ||||||
|         $compiler->inheritance = $saved_data[1]; |  | ||||||
|         // check if we process an inheritance child template |  | ||||||
|         if ($compiler->inheritance_child) { |  | ||||||
|             $name1 = Smarty_Internal_Compile_Block::$nested_block_names[0]; |  | ||||||
|             Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= "{$compiler->smarty->left_delimiter}/private_child_block{$compiler->smarty->right_delimiter}"; |  | ||||||
|             array_shift(Smarty_Internal_Compile_Block::$nested_block_names); |  | ||||||
|             if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) { |  | ||||||
|                 $name2 = Smarty_Internal_Compile_Block::$nested_block_names[0]; |  | ||||||
|                 if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) { |  | ||||||
|                     if (isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child']) || !isset($compiler->template->block_data[$name1])) { |  | ||||||
|                         Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source']; |  | ||||||
|                     } else { |  | ||||||
|                         if ($compiler->template->block_data[$name1]['mode'] == 'append') { |  | ||||||
|                             Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source']; |  | ||||||
|                         } elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') { |  | ||||||
|                             Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'] . Smarty_Internal_Compile_Block::$block_data[$name1]['source']; |  | ||||||
|                         } else { |  | ||||||
|                             Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source']; |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 unset(Smarty_Internal_Compile_Block::$block_data[$name1]); |  | ||||||
|                 $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); |  | ||||||
|             } else { |  | ||||||
|                 if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) { |  | ||||||
|                     if (isset($compiler->template->block_data[$name1]) && !isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child'])) { |  | ||||||
|                         if (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !== false) { |  | ||||||
|                             $compiler->template->block_data[$name1]['source'] = |  | ||||||
|                                 str_replace(Smarty_Internal_Compile_Block::parent, Smarty_Internal_Compile_Block::$block_data[$name1]['source'], $compiler->template->block_data[$name1]['source']); |  | ||||||
|                         } elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') { |  | ||||||
|                             $compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source']; |  | ||||||
|                         } elseif ($compiler->template->block_data[$name1]['mode'] == 'append') { |  | ||||||
|                             $compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source']; |  | ||||||
|                         } |  | ||||||
|                     } else { |  | ||||||
|                         $compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source']; |  | ||||||
|                     } |  | ||||||
|                     $compiler->template->block_data[$name1]['mode'] = 'replace'; |  | ||||||
|                     if ($saved_data[0]['append']) { |  | ||||||
|                         $compiler->template->block_data[$name1]['mode'] = 'append'; |  | ||||||
|                     } |  | ||||||
|                     if ($saved_data[0]['prepend']) { |  | ||||||
|                         $compiler->template->block_data[$name1]['mode'] = 'prepend'; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 unset(Smarty_Internal_Compile_Block::$block_data[$name1]); |  | ||||||
|                 $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); |  | ||||||
|             } |  | ||||||
|             $compiler->has_code = false; |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) { |  | ||||||
|             $_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name); |  | ||||||
|         } else { |  | ||||||
|             if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) { |  | ||||||
|                 $_output = ''; |  | ||||||
|             } else { |  | ||||||
|                 $_output = $compiler->parser->current_buffer->to_smarty_php(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (isset($compiler->template->block_data[$_name]['compiled'])) { |  | ||||||
|             unset($compiler->template->block_data[$_name]['compiled']); |  | ||||||
|         } |  | ||||||
|         // reset flags |  | ||||||
|         $compiler->parser->current_buffer = $saved_data[2]; |  | ||||||
|         if ($compiler->nocache) { |  | ||||||
|             $compiler->tag_nocache = true; |  | ||||||
|         } |  | ||||||
|         $compiler->nocache = $saved_data[3]; |  | ||||||
|         // $_output content has already nocache code processed |  | ||||||
|         $compiler->suppressNocacheProcessing = true; |         $compiler->suppressNocacheProcessing = true; | ||||||
|  |         return $output; | ||||||
|         return $_output; |  | ||||||
|     } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|  * Smarty Internal Plugin Compile Child Block Class |      * @param $match | ||||||
|      * |      * | ||||||
|  * @package    Smarty |      * @return mixed | ||||||
|  * @subpackage Compiler |  | ||||||
|      */ |      */ | ||||||
| class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_CompileBase |     function removeNocache($match) | ||||||
|     { |     { | ||||||
|  |         $code = | ||||||
|     /** |             preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", | ||||||
|      * Attribute definition: Overwrites base class. |                          '', $match[0]); | ||||||
|      * |         $code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code); | ||||||
|      * @var array |         return $code; | ||||||
|      * @see Smarty_Internal_CompileBase |  | ||||||
|      */ |  | ||||||
|     public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource'); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Compiles code for the {private_child_block} tag |  | ||||||
|      * |  | ||||||
|      * @param array  $args     array with attributes from parser |  | ||||||
|      * @param object $compiler compiler object |  | ||||||
|      * |  | ||||||
|      * @return boolean true |  | ||||||
|      */ |  | ||||||
|     public function compile($args, $compiler) |  | ||||||
|     { |  | ||||||
|         // check and get attributes |  | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |  | ||||||
|  |  | ||||||
|         // update template with original template resource of {block} |  | ||||||
|         if (trim($_attr['type'], "'") == 'file') { |  | ||||||
|             $compiler->template->template_resource = 'file:' . realpath(trim($_attr['file'], "'")); |  | ||||||
|         } else { |  | ||||||
|             $compiler->template->template_resource = trim($_attr['resource'], "'"); |  | ||||||
|         } |  | ||||||
|         // source object |  | ||||||
|         unset ($compiler->template->source); |  | ||||||
|         $exists = $compiler->template->source->exists; |  | ||||||
|  |  | ||||||
|         // must merge includes |  | ||||||
|         if ($_attr['nocache'] == true) { |  | ||||||
|             $compiler->tag_nocache = true; |  | ||||||
|         } |  | ||||||
|         $save = array($_attr, $compiler->nocache); |  | ||||||
|  |  | ||||||
|         // set trace back to child block |  | ||||||
|         $compiler->pushTrace(trim($_attr['file'], "\"'"), trim($_attr['uid'], "\"'"), $_attr['line'] - $compiler->lex->line); |  | ||||||
|  |  | ||||||
|         $this->openTag($compiler, 'private_child_block', $save); |  | ||||||
|  |  | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |  | ||||||
|         $compiler->has_code = false; |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Plugin Compile Child Block Close Class |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage Compiler |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Compile_Private_Child_Blockclose extends Smarty_Internal_CompileBase |  | ||||||
| { |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Compiles code for the {/private_child_block} tag |  | ||||||
|      * |  | ||||||
|      * @param array  $args     array with attributes from parser |  | ||||||
|      * @param object $compiler compiler object |  | ||||||
|      * |  | ||||||
|      * @return boolean true |  | ||||||
|      */ |  | ||||||
|     public function compile($args, $compiler) |  | ||||||
|     { |  | ||||||
|         // check and get attributes |  | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |  | ||||||
|  |  | ||||||
|         $saved_data = $this->closeTag($compiler, array('private_child_block')); |  | ||||||
|  |  | ||||||
|         // end of child block |  | ||||||
|         $compiler->popTrace(); |  | ||||||
|  |  | ||||||
|         $compiler->nocache = $saved_data[1]; |  | ||||||
|         $compiler->has_code = false; |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('levels'); |     public $optional_attributes = array('levels'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -35,24 +36,25 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {break} tag |      * Compiles code for the {break} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); |         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($_attr['levels'])) { |         if (isset($_attr['levels'])) { | ||||||
|             if (!is_numeric($_attr['levels'])) { |             if (!is_numeric($_attr['levels'])) { | ||||||
|                 $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); |                 $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); | ||||||
|             } |             } | ||||||
|             $_levels = $_attr['levels']; |             $_levels = $_attr['levels']; | ||||||
|         } else { |         } else { | ||||||
| @@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase | |||||||
|             $stack_count --; |             $stack_count --; | ||||||
|         } |         } | ||||||
|         if ($level_count != 0) { |         if ($level_count != 0) { | ||||||
|             $compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno); |             $compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return "<?php break {$_levels};?>"; |         return "<?php break {$_levels};?>"; | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('name'); |     public $required_attributes = array('name'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('name'); |     public $shorttag_order = array('name'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -76,9 +78,11 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase | |||||||
|         //$compiler->suppressNocacheProcessing = true; |         //$compiler->suppressNocacheProcessing = true; | ||||||
|         // was there an assign attribute |         // was there an assign attribute | ||||||
|         if (isset($_assign)) { |         if (isset($_assign)) { | ||||||
|             $_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; |             $_output = | ||||||
|  |                 "<?php ob_start();\n\$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; | ||||||
|         } else { |         } else { | ||||||
|             $_output = "<?php \$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n"; |             $_output = | ||||||
|  |                 "<?php \$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; | ||||||
|         } |         } | ||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('name'); |     public $shorttag_order = array('name'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -35,11 +36,11 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {capture} tag |      * Compiles code for the {capture} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -51,10 +52,31 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase | |||||||
|         $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); |         $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); | ||||||
|         // maybe nocache because of nocache variables |         // maybe nocache because of nocache variables | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|         $_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>"; |         $_output = "<?php \$_smarty_tpl->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>"; | ||||||
|  |  | ||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Compiles code for the {$smarty.capture.xxx} | ||||||
|  |      * | ||||||
|  |      * @param  array                                $args      array with attributes from parser | ||||||
|  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|  |      * @param  array                                $parameter array with compilation parameter | ||||||
|  |      * | ||||||
|  |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|  |      */ | ||||||
|  |     public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|  |     { | ||||||
|  |         // make all lower case | ||||||
|  |         $parameter = array_map('strtolower', $parameter); | ||||||
|  |         $tag = trim($parameter[0], '"\''); | ||||||
|  |         if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) { | ||||||
|  |             $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); | ||||||
|  |         } | ||||||
|  |         return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null"; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -69,11 +91,11 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {/capture} tag |      * Compiles code for the {/capture} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -84,11 +106,11 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase | |||||||
|  |  | ||||||
|         list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); |         list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); | ||||||
|  |  | ||||||
|         $_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n"; |         $_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_cache['capture_stack']);\n"; | ||||||
|         $_output .= "if (!empty(\$_capture_buffer)) {\n"; |         $_output .= "if (!empty(\$_capture_buffer)) {\n"; | ||||||
|         $_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; |         $_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; | ||||||
|         $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; |         $_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; | ||||||
|         $_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n"; |         $_output .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n"; | ||||||
|         $_output .= "} else \$_smarty_tpl->capture_error();?>"; |         $_output .= "} else \$_smarty_tpl->capture_error();?>"; | ||||||
|  |  | ||||||
|         return $_output; |         return $_output; | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('file'); |     public $required_attributes = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -30,30 +31,39 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('file', 'section'); |     public $shorttag_order = array('file', 'section'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('section', 'scope'); |     public $optional_attributes = array('section', 'scope', 'bubble_up'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Valid scope names | ||||||
|  |      *  | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $valid_scopes = array('local'  => true, 'parent' => true, 'root' => true, 'global' => true, | ||||||
|  |                                  'smarty' => true, 'tpl_root' => true); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {config_load} tag |      * Compiles code for the {config_load} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true); |  | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // save possible attributes |         // save possible attributes | ||||||
| @@ -63,18 +73,31 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase | |||||||
|         } else { |         } else { | ||||||
|             $section = 'null'; |             $section = 'null'; | ||||||
|         } |         } | ||||||
|         $scope = 'local'; |         $_scope = Smarty::SCOPE_LOCAL; | ||||||
|         // scope setup |  | ||||||
|         if (isset($_attr['scope'])) { |         if (isset($_attr['scope'])) { | ||||||
|             $_attr['scope'] = trim($_attr['scope'], "'\""); |             $_attr['scope'] = trim($_attr['scope'], "'\""); | ||||||
|             if (isset($_is_legal_scope[$_attr['scope']])) { |             if (!isset($this->valid_scopes[$_attr['scope']])) { | ||||||
|                 $scope = $_attr['scope']; |                 $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true); | ||||||
|             } else { |             } | ||||||
|                 $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno); |             if ($_attr['scope'] != 'local') { | ||||||
|  |                 if ($_attr['scope'] == 'parent') { | ||||||
|  |                     $_scope = Smarty::SCOPE_PARENT; | ||||||
|  |                 } elseif ($_attr['scope'] == 'root') { | ||||||
|  |                     $_scope = Smarty::SCOPE_ROOT; | ||||||
|  |                 } elseif ($_attr['scope'] == 'global') { | ||||||
|  |                     $_scope = Smarty::SCOPE_GLOBAL; | ||||||
|  |                 } elseif ($_attr['scope'] == 'smarty') { | ||||||
|  |                     $_scope = Smarty::SCOPE_SMARTY; | ||||||
|  |                 } elseif ($_attr['scope'] == 'tpl_root') { | ||||||
|  |                     $_scope = Smarty::SCOPE_TPL_ROOT; | ||||||
|  |                 } | ||||||
|  |                 $_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // create config object |         // create config object | ||||||
|         $_output = "<?php  Smarty_Internal_Extension_Config::configLoad(\$_smarty_tpl, $conf_file, $section, '$scope');?>"; |         $_output = | ||||||
|  |             "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n"; | ||||||
|  |  | ||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('levels'); |     public $optional_attributes = array('levels'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -35,24 +36,25 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {continue} tag |      * Compiles code for the {continue} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); |         static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($_attr['levels'])) { |         if (isset($_attr['levels'])) { | ||||||
|             if (!is_numeric($_attr['levels'])) { |             if (!is_numeric($_attr['levels'])) { | ||||||
|                 $compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno); |                 $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); | ||||||
|             } |             } | ||||||
|             $_levels = $_attr['levels']; |             $_levels = $_attr['levels']; | ||||||
|         } else { |         } else { | ||||||
| @@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase | |||||||
|             $stack_count --; |             $stack_count --; | ||||||
|         } |         } | ||||||
|         if ($level_count != 0) { |         if ($level_count != 0) { | ||||||
|             $compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno); |             $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return "<?php continue {$_levels};?>"; |         return "<?php continue {$_levels};?>"; | ||||||
|   | |||||||
| @@ -34,8 +34,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase | |||||||
|         $compiler->tag_nocache = true; |         $compiler->tag_nocache = true; | ||||||
|  |  | ||||||
|         // display debug template |         // display debug template | ||||||
|         $_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>"; |         $_output = "<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n"; | ||||||
|  |         $_output .= "unset(\$_smarty_debug);\n?>"; | ||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Compiler |  * @subpackage Compiler | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inheritance | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
| @@ -24,6 +24,15 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('file'); |     public $required_attributes = array('file'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Array of names of optional attribute required by tag | ||||||
|  |      * use array('_any') if there is no restriction of attributes names | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $optional_attributes = array('extends_resource'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -33,53 +42,93 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase | |||||||
|     public $shorttag_order = array('file'); |     public $shorttag_order = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {extends} tag |      * Compiles code for the {extends} tag extends: resource | ||||||
|      * |      * | ||||||
|      * @param array                                 $args     array with attributes from parser |      * @param array                                 $args     array with attributes from parser | ||||||
|      * @param object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|  |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1); | ||||||
|         } |         } | ||||||
|         if (strpos($_attr['file'], '$_tmp') !== false) { |         if (strpos($_attr['file'], '$_tmp') !== false) { | ||||||
|             $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno); |             $compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1); | ||||||
|         } |         } | ||||||
|  |         // add code to initialize inheritance | ||||||
|         $name = $_attr['file']; |         $this->registerInit($compiler, true); | ||||||
|         /** @var Smarty_Internal_Template $_smarty_tpl |         $file = trim($_attr['file'], '\'"'); | ||||||
|          * used in evaluated code |         if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') { | ||||||
|          */ |             // generate code for each template | ||||||
|         $_smarty_tpl = $compiler->template; |             $files = array_reverse(explode('|', substr($file, 8))); | ||||||
|         eval("\$tpl_name = $name;"); |             $i = 0; | ||||||
|         // create template object |             foreach ($files as $file) { | ||||||
|         $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template); |                 if ($file[0] == '"') { | ||||||
|         // check for recursion |                     $file = trim($file, '".'); | ||||||
|         $uid = $_template->source->uid; |  | ||||||
|         if (isset($compiler->extends_uid[$uid])) { |  | ||||||
|             $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1); |  | ||||||
|         } |  | ||||||
|         $compiler->extends_uid[$uid] = true; |  | ||||||
|         if (empty($_template->source->components)) { |  | ||||||
|             array_unshift($compiler->sources, $_template->source); |  | ||||||
|                 } else { |                 } else { | ||||||
|             foreach ($_template->source->components as $source) { |                     $file = "'{$file}'"; | ||||||
|                 array_unshift($compiler->sources, $source); |  | ||||||
|                 $uid = $source->uid; |  | ||||||
|                 if (isset($compiler->extends_uid[$uid])) { |  | ||||||
|                     $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1); |  | ||||||
|                 } |                 } | ||||||
|                 $compiler->extends_uid[$uid] = true; |                 $i ++; | ||||||
|  |                 if ($i == count($files) && isset($_attr['extends_resource'])) { | ||||||
|  |                     $this->compileEndChild($compiler); | ||||||
|                 } |                 } | ||||||
|  |                 $this->compileInclude($compiler, $file); | ||||||
|             } |             } | ||||||
|         unset ($_template); |             if (!isset($_attr['extends_resource'])) { | ||||||
|         $compiler->inheritance_child = true; |                 $this->compileEndChild($compiler); | ||||||
|         $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); |             } | ||||||
|  |         } else { | ||||||
|  |             $this->compileEndChild($compiler); | ||||||
|  |             $this->compileInclude($compiler, $_attr['file']); | ||||||
|  |         } | ||||||
|  |         $compiler->has_code = false; | ||||||
|         return ''; |         return ''; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Add code for inheritance endChild() method to end of template | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler | ||||||
|  |      */ | ||||||
|  |     private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|  |     { | ||||||
|  |         $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                   "<?php \$_smarty_tpl->ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Add code for including subtemplate to end of template | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler | ||||||
|  |      * @param  string                               $file subtemplate name | ||||||
|  |      */ | ||||||
|  |     private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $file) | ||||||
|  |     { | ||||||
|  |         $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, | ||||||
|  |                                                                                   $compiler->compileTag('include', | ||||||
|  |                                                                                                         array($file, | ||||||
|  |                                                                                                               array('scope' => 'parent')))); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Create source code for {extends} from source components array | ||||||
|  |      * | ||||||
|  |      * @param []\Smarty_Internal_Template_Source $components | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public static function extendsSourceArrayCode($components) | ||||||
|  |     { | ||||||
|  |         $resources = array(); | ||||||
|  |         foreach ($components as $source) { | ||||||
|  |             $resources[] = $source->resource; | ||||||
|  |         } | ||||||
|  |         return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}'; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -34,6 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting++; | ||||||
|         if ($parameter == 0) { |         if ($parameter == 0) { | ||||||
|             $this->required_attributes = array('start', 'to'); |             $this->required_attributes = array('start', 'to'); | ||||||
|             $this->optional_attributes = array('max', 'step'); |             $this->optional_attributes = array('max', 'step'); | ||||||
| @@ -44,7 +45,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase | |||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         $output = "<?php "; |         $output = "<?php\n"; | ||||||
|         if ($parameter == 1) { |         if ($parameter == 1) { | ||||||
|             foreach ($_attr['start'] as $_statement) { |             foreach ($_attr['start'] as $_statement) { | ||||||
|                 if (is_array($_statement['var'])) { |                 if (is_array($_statement['var'])) { | ||||||
| @@ -54,8 +55,8 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase | |||||||
|                     $var = $_statement['var']; |                     $var = $_statement['var']; | ||||||
|                     $index = ''; |                     $index = ''; | ||||||
|                 } |                 } | ||||||
|                 $output .= " \$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;"; |                 $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n"; | ||||||
|                 $output .= " \$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value];\n"; |                 $output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n"; | ||||||
|             } |             } | ||||||
|             if (is_array($_attr['var'])) { |             if (is_array($_attr['var'])) { | ||||||
|                 $var = $_attr['var']['var']; |                 $var = $_attr['var']['var']; | ||||||
| @@ -64,7 +65,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase | |||||||
|                 $var = $_attr['var']; |                 $var = $_attr['var']; | ||||||
|                 $index = ''; |                 $index = ''; | ||||||
|             } |             } | ||||||
|             $output .= "  if ($_attr[ifexp]) { for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n"; |             $output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n"; | ||||||
|         } else { |         } else { | ||||||
|             $_statement = $_attr['start']; |             $_statement = $_attr['start']; | ||||||
|             if (is_array($_statement['var'])) { |             if (is_array($_statement['var'])) { | ||||||
| @@ -148,6 +149,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting--; | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         // must endblock be nocache? |         // must endblock be nocache? | ||||||
| @@ -157,10 +159,11 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase | |||||||
|  |  | ||||||
|         list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse')); |         list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse')); | ||||||
|  |  | ||||||
|         if ($openTag == 'forelse') { |         $output = "<?php }\n"; | ||||||
|             return "<?php }  ?>"; |         if ($openTag != 'forelse') { | ||||||
|         } else { |             $output .= "}\n"; | ||||||
|             return "<?php }} ?>"; |          } | ||||||
|         } |         $output .= "?>\n"; | ||||||
|  |         return $output; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Compiler |  * @subpackage Compiler | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_ForeachSection | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('from', 'item'); |     public $required_attributes = array('from', 'item'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('name', 'key'); |     public $optional_attributes = array('name', 'key'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -38,178 +40,229 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('from', 'item', 'key', 'name'); |     public $shorttag_order = array('from', 'item', 'key', 'name'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * counter | ||||||
|  |      * | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     public $counter = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Name of this tag | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public $tagName = 'foreach'; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Valid properties of $smarty.foreach.name.xxx variable | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Valid properties of $item@xxx variable | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Flag if tag had name attribute | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $isNamed = false; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {foreach} tag |      * Compiles code for the {foreach} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting ++; | ||||||
|  |         // init | ||||||
|  |         $this->isNamed = false; | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         $from = $_attr['from']; |         $from = $_attr['from']; | ||||||
|         $item = $_attr['item']; |         $item = $compiler->getId($_attr['item']); | ||||||
|         if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) { |         if ($item === false) { | ||||||
|             $compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno); |             $item = $compiler->getVariableName($_attr['item']); | ||||||
|         } |         } | ||||||
|  |         $attributes = array('item' => $item); | ||||||
|         if (isset($_attr['key'])) { |         if (isset($_attr['key'])) { | ||||||
|             $key = $_attr['key']; |             $key = $compiler->getId($_attr['key']); | ||||||
|         } else { |             if ($key === false) { | ||||||
|             $key = null; |                 $key = $compiler->getVariableName($_attr['key']); | ||||||
|  |             } | ||||||
|  |             $attributes['key'] = $key; | ||||||
|  |         } | ||||||
|  |         if (isset($_attr['name'])) { | ||||||
|  |             $this->isNamed = true; | ||||||
|  |             $attributes['name'] = $compiler->getId($_attr['name']); | ||||||
|  |         } | ||||||
|  |         foreach ($attributes as $a => $v) { | ||||||
|  |             if ($v === false) { | ||||||
|  |                 $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         $fromName = $compiler->getVariableName($_attr['from']); | ||||||
|  |         if ($fromName) { | ||||||
|  |             foreach (array('item', 'key') as $a) { | ||||||
|  |                 if (isset($attributes[$a]) && $attributes[$a] == $fromName) { | ||||||
|  |                     $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'", | ||||||
|  |                                                       null, true); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $this->openTag($compiler, 'foreach', array('foreach', $compiler->nocache, $item, $key, true)); |         $itemVar = "\$_smarty_tpl->tpl_vars['{$item}']"; | ||||||
|  |         $local = '$__foreach_' . (isset($attributes['name']) ? $attributes['name'] : $attributes['item']) . '_' . | ||||||
|  |             $this->counter ++ . '_'; | ||||||
|  |         $needIteration = false; | ||||||
|  |         // search for used tag attributes | ||||||
|  |         $itemAttr = array(); | ||||||
|  |         $namedAttr = array(); | ||||||
|  |         $this->scanForProperties($attributes, $compiler); | ||||||
|  |         if (!empty($this->matchResults['item'])) { | ||||||
|  |             $itemAttr = $this->matchResults['item']; | ||||||
|  |         } | ||||||
|  |         if (!empty($this->matchResults['named'])) { | ||||||
|  |             $namedAttr = $this->matchResults['named']; | ||||||
|  |         } | ||||||
|  |         if (isset($itemAttr['last'])) { | ||||||
|  |             $needIteration = true; | ||||||
|  |         } | ||||||
|  |         if (isset($namedAttr['last'])) { | ||||||
|  |             $needIteration = true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $keyTerm = ''; | ||||||
|  |         if (isset($itemAttr['key'])) { | ||||||
|  |             $keyTerm = "{$itemVar}->key => "; | ||||||
|  |         } elseif (isset($attributes['key'])) { | ||||||
|  |             $keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => "; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $saveVars = array(); | ||||||
|  |         $restoreVars = array(); | ||||||
|  |         if ($this->isNamed) { | ||||||
|  |             $foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']"; | ||||||
|  |             if (!empty($namedAttr)) { | ||||||
|  |                 $saveVars['saved'] = "isset({$foreachVar}) ? {$foreachVar} : false;"; | ||||||
|  |                 $restoreVars[] = "if ({$local}saved) {\n{$foreachVar} = {$local}saved;\n}\n"; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         foreach (array('item', 'key') as $a) { | ||||||
|  |             if (isset($attributes[$a])) { | ||||||
|  |                 $saveVars['saved_' . $a] = | ||||||
|  |                     "isset(\$_smarty_tpl->tpl_vars['{$attributes[$a]}']) ? \$_smarty_tpl->tpl_vars['{$attributes[$a]}'] : false;"; | ||||||
|  |                 $restoreVars[] = | ||||||
|  |                     "if ({$local}saved_{$a}) {\n\$_smarty_tpl->tpl_vars['{$attributes[$a]}'] = {$local}saved_{$a};\n}\n"; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         $this->openTag($compiler, 'foreach', | ||||||
|  |                        array('foreach', $compiler->nocache, $local, $restoreVars, $itemVar, true)); | ||||||
|         // maybe nocache because of nocache variables |         // maybe nocache because of nocache variables | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|  |  | ||||||
|         if (isset($_attr['name'])) { |  | ||||||
|             $name = trim($_attr['name'], '\'"'); |  | ||||||
|             $has_name = true; |  | ||||||
|             $SmartyVarName = "\$smarty.foreach.{$name}."; |  | ||||||
|         } else { |  | ||||||
|             $has_name = false; |  | ||||||
|         } |  | ||||||
|         $ItemVarName = '$' . trim($item, '\'"') . '@'; |  | ||||||
|         // evaluates which Smarty variables and properties have to be computed |  | ||||||
|          |  | ||||||
|         if ($has_name) { |  | ||||||
|             $useSmartyForeach = $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false; |  | ||||||
|             $useSmartyForeach = ($usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false) || $useSmartyForeach; |  | ||||||
|             $useSmartyForeach = ($usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false) || $useSmartyForeach; |  | ||||||
|             $useSmartyForeach = ($usesSmartyIteration = (!$usesSmartyIndex && ($usesSmartyFirst || $usesSmartyLast)) || strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false) || $useSmartyForeach; |  | ||||||
|             $useSmartyForeach = ($usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false) || $useSmartyForeach; |  | ||||||
|             $useSmartyForeach = ($usesSmartyTotal = $usesSmartyLast ||strpos($compiler->lex->data, $SmartyVarName . 'total') !== false) || $useSmartyForeach; |  | ||||||
|         } else { |  | ||||||
|             $usesSmartyFirst = false; |  | ||||||
|             $usesSmartyLast = false; |  | ||||||
|             $usesSmartyTotal = false; |  | ||||||
|             $usesSmartyShow = false; |  | ||||||
|             $useSmartyForeach = false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $usesPropKey = strpos($compiler->lex->data, $ItemVarName . 'key') !== false; |  | ||||||
|         $usesPropFirst = strpos($compiler->lex->data, $ItemVarName . 'first') !== false; |  | ||||||
|         $usesPropLast =  strpos($compiler->lex->data, $ItemVarName . 'last') !== false; |  | ||||||
|         $usesPropIndex =  strpos($compiler->lex->data, $ItemVarName . 'index') !== false; |  | ||||||
|         $usesPropIteration = (!$usesPropIndex && ($usesPropFirst || $usesPropLast)) || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false; |  | ||||||
|         $usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false; |  | ||||||
|         $usesPropTotal = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false; |  | ||||||
|  |  | ||||||
|         $keyTerm = ''; |  | ||||||
|         if ($usesPropKey) { |  | ||||||
|             $keyTerm = "\$_smarty_tpl->tpl_vars[$item]->key => "; |  | ||||||
|         } elseif ($key != null) { |  | ||||||
|             $keyTerm = "\$_smarty_tpl->tpl_vars[$key]->value => "; |  | ||||||
|         } |  | ||||||
|         // generate output code |         // generate output code | ||||||
|         $output = "<?php\n"; |         $output = "<?php\n"; | ||||||
|         $output .= "\$_from = $from;\n"; |         $output .= "\$_from = $from;\n"; | ||||||
|         $output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n"; |         $output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n"; | ||||||
|         $output .= "settype(\$_from, 'array');\n"; |         $output .= "settype(\$_from, 'array');\n"; | ||||||
|         $output .= "}\n"; |         $output .= "}\n"; | ||||||
|         $output .= "\$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n"; |         foreach ($saveVars as $k => $code) { | ||||||
|         $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = false;\n"; |             $output .= "{$local}{$k} = {$code}\n"; | ||||||
|         if ($key != null) { |  | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n"; |  | ||||||
|         } |         } | ||||||
|         if ($usesPropTotal) { |         $output .= "{$itemVar} = new Smarty_Variable();\n"; | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_count(\$_from);\n"; |         $output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n"; | ||||||
|  |         if (isset($itemAttr['show'])) { | ||||||
|  |             $output .= "{$itemVar}->show = ({$local}total > 0);\n"; | ||||||
|         } |         } | ||||||
|         if ($usesPropIteration) { |         if (isset($itemAttr['total'])) { | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration=0;\n"; |             $output .= "{$itemVar}->total= {$local}total;\n"; | ||||||
|         } |         } | ||||||
|         if ($usesPropIndex) { |         if ($this->isNamed) { | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item]->index=-1;\n"; |  | ||||||
|         } |  | ||||||
|         if ($usesPropShow) { |  | ||||||
|             if ($usesPropTotal) { |  | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n"; |  | ||||||
|             } else { |  | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->_count(\$_from) > 0);\n"; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if ($has_name) { |  | ||||||
|             $prop = array(); |             $prop = array(); | ||||||
|             if ($usesSmartyTotal) { |             if (isset($namedAttr['total'])) { | ||||||
|                 $prop['total'] = "'total' => "; |                 $prop['total'] = "'total' => {$local}total"; | ||||||
|                 $prop['total'] .= $usesSmartyShow ? '$total = ' : ''; |  | ||||||
|                 $prop['total'] .= '$_smarty_tpl->_count($_from)'; |  | ||||||
|             } |             } | ||||||
|             if ($usesSmartyIteration) { |             if (isset($namedAttr['iteration'])) { | ||||||
|                 $prop['iteration'] = "'iteration' => 0"; |                 $prop['iteration'] = "'iteration' => 0"; | ||||||
|             } |             } | ||||||
|             if ($usesSmartyIndex) { |             if (isset($namedAttr['index'])) { | ||||||
|                 $prop['index'] = "'index' => -1"; |                 $prop['index'] = "'index' => -1"; | ||||||
|             } |             } | ||||||
|             if ($usesSmartyShow) { |             if (isset($namedAttr['show'])) { | ||||||
|                 $prop['show'] = "'show' => "; |                 $prop['show'] = "'show' => ({$local}total > 0)"; | ||||||
|                 if ($usesSmartyTotal) { |  | ||||||
|                     $prop['show'] .= "(\$total > 0)"; |  | ||||||
|                 } else { |  | ||||||
|                     $prop['show'] .= "(\$_smarty_tpl->_count(\$_from) > 0)"; |  | ||||||
|             } |             } | ||||||
|             } |             if (!empty($namedAttr)) { | ||||||
|             if ($useSmartyForeach) { |  | ||||||
|                 $_vars = 'array(' . join(', ', $prop) . ')'; |                 $_vars = 'array(' . join(', ', $prop) . ')'; | ||||||
|                 $foreachVar = "'__foreach_{$name}'"; |                 $output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n"; | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar] = new Smarty_Variable({$_vars});\n"; |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         $output .= "foreach (\$_from as {$keyTerm}\$_smarty_tpl->tpl_vars[$item]->value) {\n"; |         $output .= "if ({$local}total) {\n"; | ||||||
|         $output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n"; |         if (isset($attributes['key'])) { | ||||||
|         if ($key != null && $usesPropKey) { |             $output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n"; | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n"; |  | ||||||
|         } |         } | ||||||
|         if ($usesPropIteration) { |         if (isset($namedAttr['first']) || isset($itemAttr['first'])) { | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item]->iteration++;\n"; |             $output .= "{$local}first = true;\n"; | ||||||
|         } |         } | ||||||
|         if ($usesPropIndex) { |         if (isset($itemAttr['iteration'])) { | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item]->index++;\n"; |             $output .= "{$itemVar}->iteration=0;\n"; | ||||||
|         } |         } | ||||||
|         if ($usesPropFirst) { |         if (isset($itemAttr['index'])) { | ||||||
|             if ($usesPropIndex) { |             $output .= "{$itemVar}->index=-1;\n"; | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index == 0;\n"; |         } | ||||||
|             } else { |         if ($needIteration) { | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->iteration == 1;\n"; |             $output .= "{$local}iteration=0;\n"; | ||||||
|  |         } | ||||||
|  |         $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; | ||||||
|  |         if (isset($attributes['key']) && isset($itemAttr['key'])) { | ||||||
|  |             $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($itemAttr['iteration'])) { | ||||||
|  |             $output .= "{$itemVar}->iteration++;\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($itemAttr['index'])) { | ||||||
|  |             $output .= "{$itemVar}->index++;\n"; | ||||||
|  |         } | ||||||
|  |         if ($needIteration) { | ||||||
|  |             $output .= "{$local}iteration++;\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($itemAttr['first'])) { | ||||||
|  |             $output .= "{$itemVar}->first = {$local}first;\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($itemAttr['last'])) { | ||||||
|  |             $output .= "{$itemVar}->last = {$local}iteration == {$local}total;\n"; | ||||||
|  |         } | ||||||
|  |         if ($this->isNamed) { | ||||||
|  |             if (isset($namedAttr['iteration'])) { | ||||||
|  |                 $output .= "{$foreachVar}->value['iteration']++;\n"; | ||||||
|  |             } | ||||||
|  |             if (isset($namedAttr['index'])) { | ||||||
|  |                 $output .= "{$foreachVar}->value['index']++;\n"; | ||||||
|  |             } | ||||||
|  |             if (isset($namedAttr['first'])) { | ||||||
|  |                 $output .= "{$foreachVar}->value['first'] = {$local}first;\n"; | ||||||
|  |             } | ||||||
|  |             if (isset($namedAttr['last'])) { | ||||||
|  |                 $output .= "{$foreachVar}->value['last'] = {$local}iteration == {$local}total;\n"; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if ($usesPropLast) { |         if (isset($namedAttr['first']) || isset($itemAttr['first'])) { | ||||||
|             if ($usesPropIndex) { |             $output .= "{$local}first = false;\n"; | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->index + 1 == \$_smarty_tpl->tpl_vars[$item]->total;\n"; |  | ||||||
|             } else { |  | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration == \$_smarty_tpl->tpl_vars[$item]->total;\n"; |  | ||||||
|         } |         } | ||||||
|         } |         $output .= "{$local}saved_local_item = {$itemVar};\n"; | ||||||
|         if ($has_name) { |  | ||||||
|             if ($usesSmartyIteration) { |  | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration']++;\n"; |  | ||||||
|             } |  | ||||||
|             if ($usesSmartyIndex) { |  | ||||||
|                 $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['index']++;\n"; |  | ||||||
|             } |  | ||||||
|             if ($usesSmartyFirst) { |  | ||||||
|                 if ($usesSmartyIndex) { |  | ||||||
|                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] == 0;\n"; |  | ||||||
|                 } else { |  | ||||||
|                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == 1;\n"; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if ($usesSmartyLast) { |  | ||||||
|                 if ($usesSmartyIndex) { |  | ||||||
|                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] + 1 == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n"; |  | ||||||
|                 } else { |  | ||||||
|                     $output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n"; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $itemName = trim($item,"'\""); |  | ||||||
|         $output .= "\$foreach_{$itemName}_Sav = \$_smarty_tpl->tpl_vars[$item];\n"; |  | ||||||
|         $output .= "?>"; |         $output .= "?>"; | ||||||
|  |  | ||||||
|         return $output; |         return $output; | ||||||
| @@ -228,23 +281,22 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {foreachelse} tag |      * Compiles code for the {foreachelse} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         list($openTag, $nocache, $item, $key, $foo) = $this->closeTag($compiler, array('foreach')); |         list($openTag, $nocache, $local, $restoreVars, $itemVar, $foo) = $this->closeTag($compiler, array('foreach')); | ||||||
|         $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $item, $key, false)); |         $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $restoreVars, $itemVar, false)); | ||||||
|         $itemName = trim($item,"'\""); |  | ||||||
|         $output = "<?php\n"; |         $output = "<?php\n"; | ||||||
|         $output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n"; |         $output .= "{$itemVar} = {$local}saved_local_item;\n"; | ||||||
|         $output .= "}\n"; |         $output .= "}\n"; | ||||||
|         $output .= "if (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>"; |         $output .= "} else {\n?>"; | ||||||
|         return $output; |         return $output; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -261,27 +313,32 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {/foreach} tag |      * Compiles code for the {/foreach} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         $compiler->loopNesting --; | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |  | ||||||
|         // must endblock be nocache? |         // must endblock be nocache? | ||||||
|         if ($compiler->nocache) { |         if ($compiler->nocache) { | ||||||
|             $compiler->tag_nocache = true; |             $compiler->tag_nocache = true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         list($openTag, $compiler->nocache, $item, $key, $restore) = $this->closeTag($compiler, array('foreach', 'foreachelse')); |         list($openTag, $compiler->nocache, $local, $restoreVars, $itemVar, $restore) = | ||||||
|         $itemName = trim($item,"'\""); |             $this->closeTag($compiler, array('foreach', 'foreachelse')); | ||||||
|         $output = "<?php\n"; |         $output = "<?php\n"; | ||||||
|  |  | ||||||
|         if ($restore) { |         if ($restore) { | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n"; |             $output .= "{$itemVar} = {$local}saved_local_item;\n"; | ||||||
|  |             $output .= "}\n"; | ||||||
|         } |         } | ||||||
|         $output .= "}\n?>"; |         $output .= "}\n"; | ||||||
|  |         foreach ($restoreVars as $restore) { | ||||||
|  |             $output .= $restore; | ||||||
|  |         } | ||||||
|  |         $output .= "?>"; | ||||||
|  |  | ||||||
|         return $output; |         return $output; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -45,31 +45,30 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {function} tag |      * Compiles code for the {function} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return boolean true |      * @return bool true | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting++; | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|         unset($_attr['nocache']); |         unset($_attr['nocache']); | ||||||
|         $_name = trim($_attr['name'], "'\""); |         $_name = trim($_attr['name'], "'\""); | ||||||
|         $compiler->parent_compiler->templateProperties['tpl_function'][$_name] = array(); |         $compiler->parent_compiler->template->tpl_function[$_name] = array(); | ||||||
|         $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching); |         $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code, | ||||||
|  |                       $compiler->template->caching); | ||||||
|         $this->openTag($compiler, 'function', $save); |         $this->openTag($compiler, 'function', $save); | ||||||
|         // set flag that we are compiling a template function |  | ||||||
|         $compiler->compiles_template_function = true; |  | ||||||
|         // Init temporary context |         // Init temporary context | ||||||
|         $compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array()); |         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); | ||||||
|         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); |         $compiler->template->compiled->has_nocache_code = false; | ||||||
|         $compiler->template->has_nocache_code = false; |  | ||||||
|         $compiler->template->caching = true; |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -101,15 +100,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting--; | ||||||
|         $this->compiler = $compiler; |         $this->compiler = $compiler; | ||||||
|         $saved_data = $this->closeTag($compiler, array('function')); |         $saved_data = $this->closeTag($compiler, array('function')); | ||||||
|         $_attr = $saved_data[0]; |         $_attr = $saved_data[0]; | ||||||
|         $_name = trim($_attr['name'], "'\""); |         $_name = trim($_attr['name'], "'\""); | ||||||
|         // reset flag that we are compiling a template function |         $compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions; | ||||||
|         $compiler->compiles_template_function = false; |         $compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath; | ||||||
|         $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['called_functions'] = $compiler->called_functions; |         $compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid; | ||||||
|         $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath; |  | ||||||
|         $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['uid'] = $compiler->template->source->uid; |  | ||||||
|         $compiler->called_functions = array(); |         $compiler->called_functions = array(); | ||||||
|         $_parameter = $_attr; |         $_parameter = $_attr; | ||||||
|         unset($_parameter['name']); |         unset($_parameter['name']); | ||||||
| @@ -130,89 +128,71 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase | |||||||
|         } |         } | ||||||
|         $_functionCode = $compiler->parser->current_buffer; |         $_functionCode = $compiler->parser->current_buffer; | ||||||
|         // setup buffer for template function code |         // setup buffer for template function code | ||||||
|         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser); |         $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); | ||||||
|  |  | ||||||
|         $_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}"; |         $_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}"; | ||||||
|         $_funcNameCaching = $_funcName . '_nocache'; |         $_funcNameCaching = $_funcName . '_nocache'; | ||||||
|         if ($compiler->template->has_nocache_code) { |         if ($compiler->template->compiled->has_nocache_code) { | ||||||
|             $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name_caching'] = $_funcNameCaching; |             $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching; | ||||||
|             $output = "<?php\n"; |             $output = "<?php\n"; | ||||||
|             $output .= "/* {$_funcNameCaching} */\n"; |             $output .= "/* {$_funcNameCaching} */\n"; | ||||||
|             $output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; |             $output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; | ||||||
|             $output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n"; |             $output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n"; | ||||||
|             // build plugin include code |  | ||||||
|             if (!empty($compiler->template->required_plugins['compiled'])) { |  | ||||||
|                 foreach ($compiler->template->required_plugins['compiled'] as $tmp) { |  | ||||||
|                     foreach ($tmp as $data) { |  | ||||||
|                         $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n"; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if (!empty($compiler->template->required_plugins['nocache'])) { |  | ||||||
|                 $output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; |  | ||||||
|                 foreach ($compiler->template->required_plugins['nocache'] as $tmp) { |  | ||||||
|                     foreach ($tmp as $data) { |  | ||||||
|                         $output .= "if (!is_callable(\'{$data['function']}\')) require_once \'{$data['file']}\';\n"; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 $output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n"; |  | ||||||
|             } |  | ||||||
|             $output .= "ob_start();\n"; |             $output .= "ob_start();\n"; | ||||||
|  |             $output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n"; | ||||||
|             $output .= $_paramsCode; |             $output .= $_paramsCode; | ||||||
|             $output .= "\$_smarty_tpl->properties['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n"; |             $output .= "\$_smarty_tpl->_cache['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n"; | ||||||
|             $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}"; |             $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}"; | ||||||
|             $output .= "\$params = var_export(\$params, true);\n"; |             $output .= "\$params = var_export(\$params, true);\n"; | ||||||
|             $output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; |             $output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; | ||||||
|             $output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>"; |             $output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>"; | ||||||
|             $output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>"; |             $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>"; | ||||||
|             $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); |             $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); | ||||||
|             $compiler->parser->current_buffer->append_subtree($_functionCode); |             $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); | ||||||
|             $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; |             $output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; | ||||||
|             $output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n"; |             $output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n"; | ||||||
|             $output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n"; |             $output .= "if (!isset(\\\$_smarty_tpl->tpl_vars[\\\$key]) || \\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n"; | ||||||
|             $output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n"; |             $output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n"; | ||||||
|             $output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\";\n?>"; |             $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>"; | ||||||
|             $output .= "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n"; |             $output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n"; | ||||||
|             $output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->properties['saved_tpl_vars']);\n}\n}\n"; |             $output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n"; | ||||||
|             $output .= "/*/ {$_funcName}_nocache */\n\n"; |             $output .= "/*/ {$_funcName}_nocache */\n\n"; | ||||||
|             $output .= "?>\n"; |             $output .= "?>\n"; | ||||||
|             $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); |             $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); | ||||||
|             $_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php())); |             $_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this, | ||||||
|  |                                                                                                                                                                                                                                                                                                           'removeNocache'), $_functionCode->to_smarty_php($compiler->parser))); | ||||||
|         } |         } | ||||||
|         $compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName; |         $compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName; | ||||||
|         $output = "<?php\n"; |         $output = "<?php\n"; | ||||||
|         $output .= "/* {$_funcName} */\n"; |         $output .= "/* {$_funcName} */\n"; | ||||||
|         $output .= "if (!function_exists('{$_funcName}')) {\n"; |         $output .= "if (!function_exists('{$_funcName}')) {\n"; | ||||||
|         $output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n"; |         $output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n"; | ||||||
|         // build plugin include code |  | ||||||
|         if (!empty($compiler->template->required_plugins['nocache'])) { |  | ||||||
|             $compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $compiler->template->required_plugins['nocache']); |  | ||||||
|         } |  | ||||||
|         if (!empty($compiler->template->required_plugins['compiled'])) { |  | ||||||
|             foreach ($compiler->template->required_plugins['compiled'] as $tmp) { |  | ||||||
|                 foreach ($tmp as $data) { |  | ||||||
|                     $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n"; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; |         $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; | ||||||
|         $output .= $_paramsCode; |         $output .= $_paramsCode; | ||||||
|         $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>"; |         $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>"; | ||||||
|         $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); |         $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); | ||||||
|         $compiler->parser->current_buffer->append_subtree($_functionCode); |         $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); | ||||||
|         $output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n"; |         $output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n"; | ||||||
|         $output .= "if (\$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n"; |         $output .= "if (!isset(\$_smarty_tpl->tpl_vars[\$key]) || \$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n"; | ||||||
|         $output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n"; |         $output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n"; | ||||||
|         $output .= "/*/ {$_funcName} */\n\n"; |         $output .= "/*/ {$_funcName} */\n\n"; | ||||||
|         $output .= "?>\n"; |         $output .= "?>\n"; | ||||||
|         $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); |         $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); | ||||||
|         $compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php(); |         $compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); | ||||||
|  |         // nocache plugins must be copied | ||||||
|  |         if (!empty($compiler->template->compiled->required_plugins['nocache'])) { | ||||||
|  |             foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) { | ||||||
|  |                 foreach ($tmp as $type => $data) { | ||||||
|  |                     $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = $data; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|         // restore old buffer |         // restore old buffer | ||||||
|  |  | ||||||
|         $compiler->parser->current_buffer = $saved_data[1]; |         $compiler->parser->current_buffer = $saved_data[1]; | ||||||
|         // restore old status |         // restore old status | ||||||
|         $compiler->template->has_nocache_code = $saved_data[2]; |         $compiler->template->compiled->has_nocache_code = $saved_data[2]; | ||||||
|         $compiler->template->required_plugins = $saved_data[3]; |         $compiler->template->caching = $saved_data[3]; | ||||||
|         $compiler->template->caching = $saved_data[4]; |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -223,7 +203,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     function removeNocache($match) |     function removeNocache($match) | ||||||
|     { |     { | ||||||
|         $code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", '', $match[0]); |         $code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", '', $match[0]); | ||||||
|         $code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code); |         $code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code); | ||||||
|         return $code; |         return $code; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -20,12 +20,13 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {if} tag |      * Compiles code for the {if} tag | ||||||
|      * |      * | ||||||
|      * @param array                                 $args      array with attributes from parser |      * @param array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param array                                 $parameter array with compilation parameter |      * @param array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -34,7 +35,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase | |||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|  |  | ||||||
|         if (!array_key_exists("if condition", $parameter)) { |         if (!array_key_exists("if condition", $parameter)) { | ||||||
|             $compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno); |             $compiler->trigger_template_error("missing if condition", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (is_array($parameter['if condition'])) { |         if (is_array($parameter['if condition'])) { | ||||||
| @@ -55,11 +56,19 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase | |||||||
|                 $_nocache = ''; |                 $_nocache = ''; | ||||||
|             } |             } | ||||||
|             if (is_array($parameter['if condition']['var'])) { |             if (is_array($parameter['if condition']['var'])) { | ||||||
|                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; |                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . | ||||||
|                 $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; |                     "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . | ||||||
|  |                     "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . | ||||||
|  |                     "$_nocache);\n"; | ||||||
|  |                 $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . | ||||||
|  |                     $parameter['if condition']['var']['smarty_internal_index'] . " = " . | ||||||
|  |                     $parameter['if condition']['value'] . ") {?>"; | ||||||
|             } else { |             } else { | ||||||
|                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; |                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . | ||||||
|                 $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; |                     "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . | ||||||
|  |                     "] = new Smarty_Variable(null{$_nocache});"; | ||||||
|  |                 $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . | ||||||
|  |                     $parameter['if condition']['value'] . ") {?>"; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return $_output; |             return $_output; | ||||||
| @@ -81,12 +90,12 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {else} tag |      * Compiles code for the {else} tag | ||||||
|      * |      * | ||||||
|      * @param array                                 $args      array with attributes from parser |      * @param array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param array                                 $parameter array with compilation parameter |      * @param array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); |         list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); | ||||||
|         $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache)); |         $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache)); | ||||||
| @@ -107,12 +116,13 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {elseif} tag |      * Compiles code for the {elseif} tag | ||||||
|      * |      * | ||||||
|      * @param array                                 $args      array with attributes from parser |      * @param array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param array                                 $parameter array with compilation parameter |      * @param array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -120,7 +130,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase | |||||||
|         list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); |         list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); | ||||||
|  |  | ||||||
|         if (!array_key_exists("if condition", $parameter)) { |         if (!array_key_exists("if condition", $parameter)) { | ||||||
|             $compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno); |             $compiler->trigger_template_error("missing elseif condition", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (is_array($parameter['if condition'])) { |         if (is_array($parameter['if condition'])) { | ||||||
| @@ -149,11 +159,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase | |||||||
|             if ($condition_by_assign) { |             if ($condition_by_assign) { | ||||||
|                 $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); |                 $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); | ||||||
|                 if (is_array($parameter['if condition']['var'])) { |                 if (is_array($parameter['if condition']['var'])) { | ||||||
|                     $_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; |                     $_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . | ||||||
|                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; |                         $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . | ||||||
|  |                         $parameter['if condition']['var']['var'] . | ||||||
|  |                         "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . | ||||||
|  |                         $parameter['if condition']['var']['var'] . "$_nocache);\n"; | ||||||
|  |                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . | ||||||
|  |                         $parameter['if condition']['var']['smarty_internal_index'] . " = " . | ||||||
|  |                         $parameter['if condition']['value'] . ") {?>"; | ||||||
|                 } else { |                 } else { | ||||||
|                     $_output = "<?php  } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; |                     $_output = "<?php  } else { if (!isset(\$_smarty_tpl->tpl_vars[" . | ||||||
|                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; |                         $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . | ||||||
|  |                         $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; | ||||||
|  |                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . | ||||||
|  |                         $parameter['if condition']['value'] . ") {?>"; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 return $_output; |                 return $_output; | ||||||
| @@ -172,11 +191,23 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase | |||||||
|             $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); |             $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); | ||||||
|             if ($condition_by_assign) { |             if ($condition_by_assign) { | ||||||
|                 if (is_array($parameter['if condition']['var'])) { |                 if (is_array($parameter['if condition']['var'])) { | ||||||
|                     $_output = $compiler->appendCode($tmp, "<?php  if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"); |                     $_output = $compiler->appendCode($tmp, "<?php  if (!isset(\$_smarty_tpl->tpl_vars[" . | ||||||
|                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; |                                                          $parameter['if condition']['var']['var'] . | ||||||
|  |                                                          "]) || !is_array(\$_smarty_tpl->tpl_vars[" . | ||||||
|  |                                                          $parameter['if condition']['var']['var'] . | ||||||
|  |                                                          "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . | ||||||
|  |                                                          $parameter['if condition']['var']['var'] . "$_nocache);\n"); | ||||||
|  |                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . | ||||||
|  |                         $parameter['if condition']['var']['smarty_internal_index'] . " = " . | ||||||
|  |                         $parameter['if condition']['value'] . ") {?>"; | ||||||
|                 } else { |                 } else { | ||||||
|                     $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"); |                     $_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . | ||||||
|                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; |                                                          $parameter['if condition']['var'] . | ||||||
|  |                                                          "])) \$_smarty_tpl->tpl_vars[" . | ||||||
|  |                                                          $parameter['if condition']['var'] . | ||||||
|  |                                                          "] = new Smarty_Variable(null{$_nocache});"); | ||||||
|  |                     $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . | ||||||
|  |                         $parameter['if condition']['value'] . ") {?>"; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 return $_output; |                 return $_output; | ||||||
| @@ -199,12 +230,12 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {/if} tag |      * Compiles code for the {/if} tag | ||||||
|      * |      * | ||||||
|      * @param array                                 $args      array with attributes from parser |      * @param array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param array                                 $parameter array with compilation parameter |      * @param array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // must endblock be nocache? |         // must endblock be nocache? | ||||||
|         if ($compiler->nocache) { |         if ($compiler->nocache) { | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|      * caching mode to create nocache code but no cache file |      * caching mode to create nocache code but no cache file | ||||||
|      */ |      */ | ||||||
|     const CACHING_NOCACHE_CODE = 9999; |     const CACHING_NOCACHE_CODE = 9999; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -27,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('file'); |     public $required_attributes = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -34,13 +36,15 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('file'); |     public $shorttag_order = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $option_flags = array('nocache', 'inline', 'caching'); |     public $option_flags = array('nocache', 'inline', 'caching', 'bubble_up'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -49,6 +53,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('_any'); |     public $optional_attributes = array('_any'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Valid scope names | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $valid_scopes = array('local'  => true, 'parent' => true, 'root' => true, 'global' => true, | ||||||
|  |                                  'smarty' => true, 'tpl_root' => true); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {include} tag |      * Compiles code for the {include} tag | ||||||
|      * |      * | ||||||
| @@ -64,26 +76,73 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         // save possible attributes |         $hashResourceName = $fullResourceName = $source_resource = $_attr['file']; | ||||||
|         $include_file = $_attr['file']; |         $variable_template = false; | ||||||
|  |         $cache_tpl = false; | ||||||
|  |         // parse resource_name | ||||||
|  |         if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) { | ||||||
|  |             $type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type; | ||||||
|  |             $name = !empty($match[5]) ? $match[5] : $match[6]; | ||||||
|  |             $handler = Smarty_Resource::load($compiler->smarty, $type); | ||||||
|  |             if ($handler->recompiled || $handler->uncompiled) { | ||||||
|  |                 $variable_template = true; | ||||||
|  |             } | ||||||
|  |             if (!$variable_template) { | ||||||
|  |                 if ($type != 'string') { | ||||||
|  |                     $fullResourceName = "{$type}:{$name}"; | ||||||
|  |                     $compiled = $compiler->parent_compiler->template->compiled; | ||||||
|  |                     if (isset($compiled->includes[$fullResourceName])) { | ||||||
|  |                         $compiled->includes[$fullResourceName] ++; | ||||||
|  |                         $cache_tpl = true; | ||||||
|  |                     } else { | ||||||
|  |                         $compiled->includes[$fullResourceName] = 1; | ||||||
|  |                     } | ||||||
|  |                     $fullResourceName = '"' . $fullResourceName . '"'; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if (empty($match[5])) { | ||||||
|  |                 $variable_template = true; | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             $variable_template = true; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         if (isset($_attr['assign'])) { |         if (isset($_attr['assign'])) { | ||||||
|             // output will be stored in a smarty variable instead of being displayed |             // output will be stored in a smarty variable instead of being displayed | ||||||
|             $_assign = $_attr['assign']; |             $_assign = $_attr['assign']; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $_parent_scope = Smarty::SCOPE_LOCAL; |         // scope setup | ||||||
|  |         $_scope = Smarty::SCOPE_LOCAL; | ||||||
|         if (isset($_attr['scope'])) { |         if (isset($_attr['scope'])) { | ||||||
|             $_attr['scope'] = trim($_attr['scope'], "'\""); |             $_attr['scope'] = trim($_attr['scope'], "'\""); | ||||||
|  |             if (!isset($this->valid_scopes[$_attr['scope']])) { | ||||||
|  |                 $compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true); | ||||||
|  |             } | ||||||
|  |             if ($_attr['scope'] != 'local') { | ||||||
|                 if ($_attr['scope'] == 'parent') { |                 if ($_attr['scope'] == 'parent') { | ||||||
|                 $_parent_scope = Smarty::SCOPE_PARENT; |                     $_scope = Smarty::SCOPE_PARENT; | ||||||
|                 } elseif ($_attr['scope'] == 'root') { |                 } elseif ($_attr['scope'] == 'root') { | ||||||
|                 $_parent_scope = Smarty::SCOPE_ROOT; |                     $_scope = Smarty::SCOPE_ROOT; | ||||||
|                 } elseif ($_attr['scope'] == 'global') { |                 } elseif ($_attr['scope'] == 'global') { | ||||||
|                 $_parent_scope = Smarty::SCOPE_GLOBAL; |                     $_scope = Smarty::SCOPE_GLOBAL; | ||||||
|  |                 } elseif ($_attr['scope'] == 'smarty') { | ||||||
|  |                     $_scope = Smarty::SCOPE_SMARTY; | ||||||
|  |                 } elseif ($_attr['scope'] == 'tpl_root') { | ||||||
|  |                     $_scope = Smarty::SCOPE_TPL_ROOT; | ||||||
|  |                 } | ||||||
|  |                 if ($_attr['bubble_up'] === true) { | ||||||
|  |                     $_scope = $_scope + Smarty::SCOPE_BUBBLE_UP; | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         // set flag to cache subtemplate object when called within loop or template name is variable. | ||||||
|  |         if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) { | ||||||
|  |             $_cache_tpl = 'true'; | ||||||
|  |         } else { | ||||||
|  |             $_cache_tpl = 'false'; | ||||||
|  |         } | ||||||
|         // assume caching is off |         // assume caching is off | ||||||
|         $_caching = Smarty::CACHING_OFF; |         $_caching = Smarty::CACHING_OFF; | ||||||
|  |  | ||||||
| @@ -99,31 +158,29 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         // flag if included template code should be merged into caller |         // flag if included template code should be merged into caller | ||||||
|         $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled; |         $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && | ||||||
|  |             !$compiler->template->source->handler->recompiled; | ||||||
|  |  | ||||||
|         if ($merge_compiled_includes && $_attr['inline'] !== true) { |         if ($merge_compiled_includes && $_attr['inline'] !== true) { | ||||||
|             // variable template name ? |             // variable template name ? | ||||||
|             if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2)) || substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0) { |             if ($variable_template) { | ||||||
|                 $merge_compiled_includes = false; |                 $merge_compiled_includes = false; | ||||||
|                 if ($compiler->template->caching) { |                 if ($compiler->template->caching) { | ||||||
|                     // must use individual cache file |                     // must use individual cache file | ||||||
|                     //$_attr['caching'] = 1; |                     //$_attr['caching'] = 1; | ||||||
|                 } |                 } | ||||||
|                 if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) { |  | ||||||
|                     $compiler->trigger_template_error(' variable template file names not allow within {block} tags'); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|             // variable compile_id? |             // variable compile_id? | ||||||
|             if (isset($_attr['compile_id'])) { |             if (isset($_attr['compile_id'])) { | ||||||
|                 if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 || is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0) { |                 if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 || | ||||||
|  |                         is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 || | ||||||
|  |                     substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0 | ||||||
|  |                 ) { | ||||||
|                     $merge_compiled_includes = false; |                     $merge_compiled_includes = false; | ||||||
|                     if ($compiler->template->caching) { |                     if ($compiler->template->caching) { | ||||||
|                         // must use individual cache file |                         // must use individual cache file | ||||||
|                         //$_attr['caching'] = 1; |                         //$_attr['caching'] = 1; | ||||||
|                     } |                     } | ||||||
|                     if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) { |  | ||||||
|                         $compiler->trigger_template_error(' variable compile_id not allow within {block} tags'); |  | ||||||
|                     } |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -167,74 +224,23 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|  |  | ||||||
|         $has_compiled_template = false; |         $has_compiled_template = false; | ||||||
|         if ($merge_compiled_includes) { |         if ($merge_compiled_includes) { | ||||||
|             if ($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache) && $_caching != self::CACHING_NOCACHE_CODE) { |  | ||||||
|                 //                $merge_compiled_includes = false; |  | ||||||
|                 if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) { |  | ||||||
|                     $compiler->trigger_template_error(' invalid caching mode of subtemplate within {block} tags'); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             $c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id; |             $c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id; | ||||||
|             // we must observe different compile_id and caching |             // we must observe different compile_id and caching | ||||||
|             $uid = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); |             $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); | ||||||
|             $tpl_name = null; |             if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) { | ||||||
|  |                 $has_compiled_template = | ||||||
|             /** @var Smarty_Internal_Template $_smarty_tpl |                     $this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash, | ||||||
|              * used in evaluated code |                                                  $c_id); | ||||||
|              */ |  | ||||||
|             $_smarty_tpl = $compiler->template; |  | ||||||
|             eval("\$tpl_name = $include_file;"); |  | ||||||
|             if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) { |  | ||||||
|                 $compiler->smarty->allow_ambiguous_resources = true; |  | ||||||
|                 $tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching); |  | ||||||
|                 // save unique function name |  | ||||||
|                 $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); |  | ||||||
|                 if ($compiler->inheritance) { |  | ||||||
|                     $tpl->compiler->inheritance = true; |  | ||||||
|                 } |  | ||||||
|                 // make sure whole chain gets compiled |  | ||||||
|                 $tpl->mustCompile = true; |  | ||||||
|                 if (!($tpl->source->uncompiled) && $tpl->source->exists) { |  | ||||||
|                     $tpl->compiler->suppressTemplatePropertyHeader = true; |  | ||||||
|                     $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = str_replace(array('.', ','), '_', uniqid(rand(), true)); |  | ||||||
|                     // get compiled code |  | ||||||
|                     $compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler)); |  | ||||||
|                     unset($tpl->compiler); |  | ||||||
|  |  | ||||||
|                     // remove header code |  | ||||||
|                     $compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code); |  | ||||||
|                     if ($tpl->has_nocache_code) { |  | ||||||
|                         // replace nocache_hash |  | ||||||
|                         $compiled_code = str_replace("{$tpl->properties['nocache_hash']}", $compiler->template->properties['nocache_hash'], $compiled_code); |  | ||||||
|                         $compiler->template->has_nocache_code = true; |  | ||||||
|                     } |  | ||||||
|                     $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->properties['unifunc']] = $compiled_code; |  | ||||||
|                     $has_compiled_template = true; |  | ||||||
|                     if (!empty($tpl->required_plugins['compiled'])) { |  | ||||||
|                         foreach ($tpl->required_plugins['compiled'] as $name => $callBack) { |  | ||||||
|                             if (!isset($compiler->template->required_plugins['compiled'][$name])) { |  | ||||||
|                                 $compiler->template->required_plugins['compiled'][$name] = $callBack; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     if (!empty($tpl->required_plugins['nocache'])) { |  | ||||||
|                         foreach ($tpl->required_plugins['nocache'] as $name => $callBack) { |  | ||||||
|                             if (!isset($compiler->template->required_plugins['nocache'][$name])) { |  | ||||||
|                                 $compiler->template->required_plugins['nocache'][$name] = $callBack; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     unset ($tpl); |  | ||||||
|                 } |  | ||||||
|             } else { |             } else { | ||||||
|                 $has_compiled_template = true; |                 $has_compiled_template = true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // delete {include} standard attributes |         // delete {include} standard attributes | ||||||
|         unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']); |         unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']); | ||||||
|         // remaining attributes must be assigned as smarty variable |         // remaining attributes must be assigned as smarty variable | ||||||
|         $_vars_nc = ''; |         $_vars_nc = ''; | ||||||
|         if (!empty($_attr)) { |         if (!empty($_attr)) { | ||||||
|             if ($_parent_scope == Smarty::SCOPE_LOCAL) { |             if ($_scope == Smarty::SCOPE_LOCAL) { | ||||||
|                 $_pairs = array(); |                 $_pairs = array(); | ||||||
|                 // create variables |                 // create variables | ||||||
|                 foreach ($_attr as $key => $value) { |                 foreach ($_attr as $key => $value) { | ||||||
| @@ -243,35 +249,34 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|                 } |                 } | ||||||
|                 $_vars = 'array(' . join(',', $_pairs) . ')'; |                 $_vars = 'array(' . join(',', $_pairs) . ')'; | ||||||
|             } else { |             } else { | ||||||
|                 $compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno); |                 $compiler->trigger_template_error('variable passing not allowed in parent/global scope', null, true); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $_vars = 'array()'; |             $_vars = 'array()'; | ||||||
|         } |         } | ||||||
|         $update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && $_compile_id != '$_smarty_tpl->compile_id'; |         $update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && | ||||||
|  |             $_compile_id != '$_smarty_tpl->compile_id'; | ||||||
|         if ($has_compiled_template && !$call_nocache) { |         if ($has_compiled_template && !$call_nocache) { | ||||||
|             //           if ($has_compiled_template && !$compiler->tag_nocache && !$compiler->nocache) { |             $_output = "<?php\n"; | ||||||
|             // never call inline templates in nocache mode |  | ||||||
|             //$compiler->suppressNocacheProcessing = true; |  | ||||||
|             $_hash = $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash']; |  | ||||||
|             $_output = "<?php /*  Call merged included template \"" . $tpl_name . "\" */\n"; |  | ||||||
|             if ($update_compile_id) { |             if ($update_compile_id) { | ||||||
|                 $_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"); |                 $_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"); | ||||||
|             } |             } | ||||||
|             if (!empty($_vars_nc) && $_caching == 9999 && $_smarty_tpl->caching) { |             if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) { | ||||||
|                 //$compiler->suppressNocacheProcessing = false; |                 //$compiler->suppressNocacheProcessing = false; | ||||||
|                 $_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3); |                 $_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3); | ||||||
|                 //$compiler->suppressNocacheProcessing = true; |                 //$compiler->suppressNocacheProcessing = true; | ||||||
|             } |             } | ||||||
|             if (isset($_assign)) { |             if (isset($_assign)) { | ||||||
|                 $_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n"; |                 $_output .= "ob_start();\n"; | ||||||
|             } else { |             } | ||||||
|                 $_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n"; |             $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n"; | ||||||
|  |             if (isset($_assign)) { | ||||||
|  |                 $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; | ||||||
|             } |             } | ||||||
|             if ($update_compile_id) { |             if ($update_compile_id) { | ||||||
|                 $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); |                 $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); | ||||||
|             } |             } | ||||||
|             $_output .= "/*  End of included template \"" . $tpl_name . "\" */?>\n"; |             $_output .= "?>\n"; | ||||||
|  |  | ||||||
|             return $_output; |             return $_output; | ||||||
|         } |         } | ||||||
| @@ -285,9 +290,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|         } |         } | ||||||
|         // was there an assign attribute |         // was there an assign attribute | ||||||
|         if (isset($_assign)) { |         if (isset($_assign)) { | ||||||
|             $_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope));\n"; |             $_output .= "ob_start();\n"; | ||||||
|         } else { |         } | ||||||
|             $_output .= "echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope);\n"; |         $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n"; | ||||||
|  |         if (isset($_assign)) { | ||||||
|  |             $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; | ||||||
|         } |         } | ||||||
|         if ($update_compile_id) { |         if ($update_compile_id) { | ||||||
|             $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; |             $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; | ||||||
| @@ -295,4 +302,65 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase | |||||||
|         $_output .= "?>\n"; |         $_output .= "?>\n"; | ||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Compile inline sub template | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_SmartyTemplateCompiler $compiler | ||||||
|  |      * @param                                         $fullResourceName | ||||||
|  |      * @param                                         $_caching | ||||||
|  |      * @param                                         $hashResourceName | ||||||
|  |      * @param                                         $t_hash | ||||||
|  |      * @param                                         $c_id | ||||||
|  |      * | ||||||
|  |      * @return bool | ||||||
|  |      */ | ||||||
|  |     public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName, | ||||||
|  |                                           $_caching, $hashResourceName, $t_hash, $c_id) | ||||||
|  |     { | ||||||
|  |         $compiler->smarty->allow_ambiguous_resources = true; | ||||||
|  |         /* @var Smarty_Internal_Template $tpl */ | ||||||
|  |         $tpl = | ||||||
|  |             new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template, | ||||||
|  |                                                    $compiler->template->cache_id, $c_id, $_caching); | ||||||
|  |         if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { | ||||||
|  |             $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid; | ||||||
|  |             if (isset($compiler->template->_inheritance)) { | ||||||
|  |                 $tpl->_inheritance = clone $compiler->template->_inheritance; | ||||||
|  |             } | ||||||
|  |             $tpl->compiled = new Smarty_Template_Compiled(); | ||||||
|  |             $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; | ||||||
|  |             $tpl->loadCompiler(); | ||||||
|  |             // save unique function name | ||||||
|  |             $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] = | ||||||
|  |             $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); | ||||||
|  |             // make sure whole chain gets compiled | ||||||
|  |             $tpl->mustCompile = true; | ||||||
|  |             $compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] = | ||||||
|  |                 $tpl->compiled->nocache_hash; | ||||||
|  |             // get compiled code | ||||||
|  |             $compiled_code = "<?php\n\n"; | ||||||
|  |             $compiled_code .= "/* Start inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n"; | ||||||
|  |             $compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n"; | ||||||
|  |             $compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler); | ||||||
|  |             $compiled_code .= "<?php\n"; | ||||||
|  |             $compiled_code .= "}\n?>\n"; | ||||||
|  |             $compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode); | ||||||
|  |             $compiled_code .= "<?php\n\n"; | ||||||
|  |             $compiled_code .= "/* End inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n"; | ||||||
|  |             $compiled_code .= "?>"; | ||||||
|  |             unset($tpl->compiler); | ||||||
|  |             if ($tpl->compiled->has_nocache_code) { | ||||||
|  |                 // replace nocache_hash | ||||||
|  |                 $compiled_code = | ||||||
|  |                     str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash, | ||||||
|  |                                 $compiled_code); | ||||||
|  |                 $compiler->template->compiled->has_nocache_code = true; | ||||||
|  |             } | ||||||
|  |             $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; | ||||||
|  |             return true; | ||||||
|  |         } else { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('file'); |     public $required_attributes = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('file'); |     public $shorttag_order = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -42,12 +44,13 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {include_php} tag |      * Compiles code for the {include_php} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @throws SmartyException |      * @return string | ||||||
|      * @return string compiled code |      * @throws \SmartyCompilerException | ||||||
|  |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         if (!($compiler->smarty instanceof SmartyBC)) { |         if (!($compiler->smarty instanceof SmartyBC)) { | ||||||
|             throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable"); |             throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable"); | ||||||
| @@ -60,9 +63,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|          */ |          */ | ||||||
|         $_smarty_tpl = $compiler->template; |         $_smarty_tpl = $compiler->template; | ||||||
|         $_filepath = false; |         $_filepath = false; | ||||||
|         eval('$_file = ' . $_attr['file'] . ';'); |         $_file = null; | ||||||
|  |         eval('$_file = @' . $_attr['file'] . ';'); | ||||||
|         if (!isset($compiler->smarty->security_policy) && file_exists($_file)) { |         if (!isset($compiler->smarty->security_policy) && file_exists($_file)) { | ||||||
|             $_filepath = $_file; |             $_filepath = $compiler->smarty->_realpath($_file, true); | ||||||
|         } else { |         } else { | ||||||
|             if (isset($compiler->smarty->security_policy)) { |             if (isset($compiler->smarty->security_policy)) { | ||||||
|                 $_dir = $compiler->smarty->security_policy->trusted_dir; |                 $_dir = $compiler->smarty->security_policy->trusted_dir; | ||||||
| @@ -71,16 +75,16 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|             } |             } | ||||||
|             if (!empty($_dir)) { |             if (!empty($_dir)) { | ||||||
|                 foreach ((array) $_dir as $_script_dir) { |                 foreach ((array) $_dir as $_script_dir) { | ||||||
|                     $_script_dir = rtrim($_script_dir, '/\\') . DS; |                     $_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true); | ||||||
|                     if (file_exists($_script_dir . $_file)) { |                     if (file_exists($_path)) { | ||||||
|                         $_filepath = $_script_dir . $_file; |                         $_filepath = $_path; | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if ($_filepath == false) { |         if ($_filepath == false) { | ||||||
|             $compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno); |             $compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($compiler->smarty->security_policy)) { |         if (isset($compiler->smarty->security_policy)) { | ||||||
| @@ -99,7 +103,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($_assign)) { |         if (isset($_assign)) { | ||||||
|             return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>"; |             return "<?php ob_start();\ninclude{$_once} ('{$_filepath}');\n\$_smarty_tpl->assign({$_assign},ob_get_clean());\n?>"; | ||||||
|         } else { |         } else { | ||||||
|             return "<?php include{$_once} ('{$_filepath}');?>\n"; |             return "<?php include{$_once} ('{$_filepath}');?>\n"; | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('name'); |     public $required_attributes = array('name'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -31,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('name'); |     public $shorttag_order = array('name'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -43,11 +45,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {insert} tag |      * Compiles code for the {insert} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -63,7 +66,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|  |  | ||||||
|         $_output = '<?php '; |         $_output = '<?php '; | ||||||
|         // save possible attributes |         // save possible attributes | ||||||
|         eval('$_name = ' . $_attr['name'] . ';'); |         eval('$_name = @' . $_attr['name'] . ';'); | ||||||
|         if (isset($_attr['assign'])) { |         if (isset($_attr['assign'])) { | ||||||
|             // output will be stored in a smarty variable instead of being displayed |             // output will be stored in a smarty variable instead of being displayed | ||||||
|             $_assign = $_attr['assign']; |             $_assign = $_attr['assign']; | ||||||
| @@ -80,7 +83,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|             $_function = "smarty_insert_{$_name}"; |             $_function = "smarty_insert_{$_name}"; | ||||||
|             $_smarty_tpl = $compiler->template; |             $_smarty_tpl = $compiler->template; | ||||||
|             $_filepath = false; |             $_filepath = false; | ||||||
|             eval('$_script = ' . $_attr['script'] . ';'); |             eval('$_script = @' . $_attr['script'] . ';'); | ||||||
|             if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { |             if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { | ||||||
|                 $_filepath = $_script; |                 $_filepath = $_script; | ||||||
|             } else { |             } else { | ||||||
| @@ -100,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if ($_filepath == false) { |             if ($_filepath == false) { | ||||||
|                 $compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno); |                 $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); | ||||||
|             } |             } | ||||||
|             // code for script file loading |             // code for script file loading | ||||||
|             $_output .= "require_once '{$_filepath}' ;"; |             $_output .= "require_once '{$_filepath}' ;"; | ||||||
|             require_once $_filepath; |             require_once $_filepath; | ||||||
|             if (!is_callable($_function)) { |             if (!is_callable($_function)) { | ||||||
|                 $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno); |                 $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $_filepath = 'null'; |             $_filepath = 'null'; | ||||||
| @@ -115,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase | |||||||
|             if (!is_callable($_function)) { |             if (!is_callable($_function)) { | ||||||
|                 // try plugin |                 // try plugin | ||||||
|                 if (!$_function = $compiler->getPlugin($_name, 'insert')) { |                 if (!$_function = $compiler->getPlugin($_name, 'insert')) { | ||||||
|                     $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno); |                     $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -21,15 +21,16 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase | |||||||
|      * This tag does output the left delimiter |      * This tag does output the left delimiter | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|         // this tag does not return compiled code |         // this tag does not return compiled code | ||||||
|         $compiler->has_code = true; |         $compiler->has_code = true; | ||||||
|   | |||||||
| @@ -28,11 +28,11 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase | |||||||
|      * This tag does not generate compiled output. It only sets a compiler flag. |      * This tag does not generate compiled output. It only sets a compiler flag. | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         $this->openTag($compiler, 'nocache', array($compiler->nocache)); |         $this->openTag($compiler, 'nocache', array($compiler->nocache)); | ||||||
| @@ -58,11 +58,11 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase | |||||||
|      * This tag does not generate compiled output. It only sets a compiler flag. |      * This tag does not generate compiled output. It only sets a compiler flag. | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return bool |      * @return bool | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         // leave nocache mode |         // leave nocache mode | ||||||
|   | |||||||
| @@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi | |||||||
|      * Compiles code for the execution of block plugin |      * Compiles code for the execution of block plugin | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * @param  string                               $tag       name of block plugin |      * @param  string                               $tag       name of block plugin | ||||||
|      * @param  string                               $function  PHP function name |      * @param  string                               $function  PHP function name | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag, $function) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function) | ||||||
|     { |     { | ||||||
|         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { |         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { | ||||||
|             // opening tag of block plugin |             // opening tag of block plugin | ||||||
| @@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi | |||||||
|             // maybe nocache because of nocache variables or nocache plugin |             // maybe nocache because of nocache variables or nocache plugin | ||||||
|             $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |             $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|             // compile code |             // compile code | ||||||
|             $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |             $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; | ||||||
|         } else { |         } else { | ||||||
|             // must endblock be nocache? |             // must endblock be nocache? | ||||||
|             if ($compiler->nocache) { |             if ($compiler->nocache) { | ||||||
| @@ -75,9 +75,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi | |||||||
|                 $mod_pre = $mod_post = ''; |                 $mod_pre = $mod_post = ''; | ||||||
|             } else { |             } else { | ||||||
|                 $mod_pre = ' ob_start(); '; |                 $mod_pre = ' ob_start(); '; | ||||||
|                 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; |                 $mod_post = 'echo ' . | ||||||
|  |                     $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], | ||||||
|  |                                                                              'value'        => 'ob_get_clean()')) . ';'; | ||||||
|             } |             } | ||||||
|             $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |             $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . | ||||||
|  |                 " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . | ||||||
|  |                 " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $output . "\n"; |         return $output . "\n"; | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array(); |     public $required_attributes = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -35,14 +36,14 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co | |||||||
|      * Compiles code for the execution of function plugin |      * Compiles code for the execution of function plugin | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * @param  array  $parameter array with compilation parameter |      * @param  array  $parameter array with compilation parameter | ||||||
|      * @param  string $tag       name of function plugin |      * @param  string $tag       name of function plugin | ||||||
|      * @param  string                               $function PHP function name |      * @param  string                               $function PHP function name | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag, $function) |     public function compile($args, Smarty_Internal_TemplateCompilerBase  $compiler, $parameter, $tag, $function) | ||||||
|     { |     { | ||||||
|         // This tag does create output |         // This tag does create output | ||||||
|         $compiler->has_output = true; |         $compiler->has_output = true; | ||||||
|   | |||||||
| @@ -21,12 +21,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|      * Compiles code for modifier execution |      * Compiles code for modifier execution | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -52,7 +53,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                                 $output = "{$function}({$params})"; |                                 $output = "{$function}({$params})"; | ||||||
|                             } else { |                             } else { | ||||||
|                                 if (is_object($function[0])) { |                                 if (is_object($function[0])) { | ||||||
|                                     $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; |                                     $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . | ||||||
|  |                                         $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; |                                     $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; | ||||||
|                                 } |                                 } | ||||||
| @@ -73,7 +75,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                         // modifiercompiler plugin |                         // modifiercompiler plugin | ||||||
|                         if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { |                         if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { | ||||||
|                             // check if modifier allowed |                             // check if modifier allowed | ||||||
|                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { |                             if (!is_object($compiler->smarty->security_policy) || | ||||||
|  |                                 $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) | ||||||
|  |                             ) { | ||||||
|                                 $plugin = 'smarty_modifiercompiler_' . $modifier; |                                 $plugin = 'smarty_modifiercompiler_' . $modifier; | ||||||
|                                 $output = $plugin($single_modifier, $compiler); |                                 $output = $plugin($single_modifier, $compiler); | ||||||
|                             } |                             } | ||||||
| @@ -85,7 +89,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                         // modifier plugin |                         // modifier plugin | ||||||
|                         if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { |                         if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) { | ||||||
|                             // check if modifier allowed |                             // check if modifier allowed | ||||||
|                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { |                             if (!is_object($compiler->smarty->security_policy) || | ||||||
|  |                                 $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) | ||||||
|  |                             ) { | ||||||
|                                 $output = "{$function}({$params})"; |                                 $output = "{$function}({$params})"; | ||||||
|                             } |                             } | ||||||
|                             $compiler->known_modifier_type[$modifier] = $type; |                             $compiler->known_modifier_type[$modifier] = $type; | ||||||
| @@ -96,7 +102,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                         // PHP function |                         // PHP function | ||||||
|                         if (is_callable($modifier)) { |                         if (is_callable($modifier)) { | ||||||
|                             // check if modifier allowed |                             // check if modifier allowed | ||||||
|                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) { |                             if (!is_object($compiler->smarty->security_policy) || | ||||||
|  |                                 $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) | ||||||
|  |                             ) { | ||||||
|                                 $output = "{$modifier}({$params})"; |                                 $output = "{$modifier}({$params})"; | ||||||
|                             } |                             } | ||||||
|                             $compiler->known_modifier_type[$modifier] = $type; |                             $compiler->known_modifier_type[$modifier] = $type; | ||||||
| @@ -105,21 +113,29 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                         break; |                         break; | ||||||
|                     case 6: |                     case 6: | ||||||
|                         // default plugin handler |                         // default plugin handler | ||||||
|                         if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) { |                         if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || | ||||||
|  |                             (is_callable($compiler->smarty->default_plugin_handler_func) && | ||||||
|  |                                 $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER)) | ||||||
|  |                         ) { | ||||||
|                             $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; |                             $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0]; | ||||||
|                             // check if modifier allowed |                             // check if modifier allowed | ||||||
|                             if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) { |                             if (!is_object($compiler->smarty->security_policy) || | ||||||
|  |                                 $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) | ||||||
|  |                             ) { | ||||||
|                                 if (!is_array($function)) { |                                 if (!is_array($function)) { | ||||||
|                                     $output = "{$function}({$params})"; |                                     $output = "{$function}({$params})"; | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     if (is_object($function[0])) { |                                     if (is_object($function[0])) { | ||||||
|                                         $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; |                                         $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . | ||||||
|  |                                             $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')'; | ||||||
|                                     } else { |                                     } else { | ||||||
|                                         $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; |                                         $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                             if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) { |                             if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || | ||||||
|  |                                 isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) | ||||||
|  |                             ) { | ||||||
|                                 // was a plugin |                                 // was a plugin | ||||||
|                                 $compiler->known_modifier_type[$modifier] = 4; |                                 $compiler->known_modifier_type[$modifier] = 4; | ||||||
|                             } else { |                             } else { | ||||||
| @@ -130,7 +146,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if (!isset($compiler->known_modifier_type[$modifier])) { |             if (!isset($compiler->known_modifier_type[$modifier])) { | ||||||
|                 $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno); |                 $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter | |||||||
|      * Compiles code for the execution of block plugin |      * Compiles code for the execution of block plugin | ||||||
|      * |      * | ||||||
|      * @param  array                                $args      array with attributes from parser |      * @param  array                                $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                $parameter array with compilation parameter |      * @param  array                                $parameter array with compilation parameter | ||||||
|      * @param  string                               $tag       name of block object |      * @param  string                               $tag       name of block object | ||||||
|      * @param  string                               $method    name of method to call |      * @param  string                               $method    name of method to call | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag, $method) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method) | ||||||
|     { |     { | ||||||
|         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { |         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { | ||||||
|             // opening tag of block plugin |             // opening tag of block plugin | ||||||
| @@ -60,7 +60,8 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter | |||||||
|             // maybe nocache because of nocache variables or nocache plugin |             // maybe nocache because of nocache variables or nocache plugin | ||||||
|             $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |             $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|             // compile code |             // compile code | ||||||
|             $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |             $output = | ||||||
|  |                 "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; | ||||||
|         } else { |         } else { | ||||||
|             $base_tag = substr($tag, 0, - 5); |             $base_tag = substr($tag, 0, - 5); | ||||||
|             // must endblock be nocache? |             // must endblock be nocache? | ||||||
| @@ -76,9 +77,13 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter | |||||||
|                 $mod_pre = $mod_post = ''; |                 $mod_pre = $mod_post = ''; | ||||||
|             } else { |             } else { | ||||||
|                 $mod_pre = ' ob_start(); '; |                 $mod_pre = ' ob_start(); '; | ||||||
|                 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; |                 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), | ||||||
|  |                                                             array('modifierlist' => $parameter['modifier_list'], | ||||||
|  |                                                                   'value'        => 'ob_get_clean()')) . ';'; | ||||||
|             } |             } | ||||||
|             $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "  } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |             $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . | ||||||
|  |                 " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . | ||||||
|  |                 $mod_post . "  } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $output . "\n"; |         return $output . "\n"; | ||||||
|   | |||||||
| @@ -28,14 +28,14 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co | |||||||
|      * Compiles code for the execution of function plugin |      * Compiles code for the execution of function plugin | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * @param  string                                      $tag       name of function |      * @param  string                                      $tag       name of function | ||||||
|      * @param  string                                      $method    name of method to call |      * @param  string                                      $method    name of method to call | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag, $method) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|   | |||||||
| @@ -42,10 +42,12 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|         $compiler->has_code = false; |         $compiler->has_code = false; | ||||||
|         if ($_attr['type'] == 'xml') { |         if ($_attr['type'] == 'xml') { | ||||||
|             $compiler->tag_nocache = true; |             $compiler->tag_nocache = true; | ||||||
|             $save = $compiler->template->has_nocache_code; |             $save = $compiler->template->compiled->has_nocache_code; | ||||||
|             $output = addcslashes($_attr['code'], "'\\"); |             $output = addcslashes($_attr['code'], "'\\"); | ||||||
|             $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true))); |             $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . | ||||||
|             $compiler->template->has_nocache_code = $save; |                                                                                                                                                                     $output . | ||||||
|  |                                                                                                                                                                     "';?>", $compiler, true))); | ||||||
|  |             $compiler->template->compiled->has_nocache_code = $save; | ||||||
|             return ''; |             return ''; | ||||||
|         } |         } | ||||||
|         if ($_attr['type'] != 'tag') { |         if ($_attr['type'] != 'tag') { | ||||||
| @@ -54,28 +56,30 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|             } elseif ($compiler->php_handling == Smarty::PHP_QUOTE) { |             } elseif ($compiler->php_handling == Smarty::PHP_QUOTE) { | ||||||
|                 $output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this, |                 $output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this, | ||||||
|                                                                                                                                                               'quote'), $_attr['code']); |                                                                                                                                                               'quote'), $_attr['code']); | ||||||
|                 $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output)); |                 $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output)); | ||||||
|                 return ''; |                 return ''; | ||||||
|             } elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') { |             } elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') { | ||||||
|                 $compiler->tag_nocache = true; |                 $compiler->tag_nocache = true; | ||||||
|                 $save = $compiler->template->has_nocache_code; |                 $save = $compiler->template->compiled->has_nocache_code; | ||||||
|                 $output = addcslashes($_attr['code'], "'\\"); |                 $output = addcslashes($_attr['code'], "'\\"); | ||||||
|                 $compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true))); |                 $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . | ||||||
|                 $compiler->template->has_nocache_code = $save; |                                                                                                                                                                         $output . | ||||||
|  |                                                                                                                                                                         "';?>", $compiler, true))); | ||||||
|  |                 $compiler->template->compiled->has_nocache_code = $save; | ||||||
|                 return ''; |                 return ''; | ||||||
|             } elseif ($compiler->php_handling == Smarty::PHP_ALLOW) { |             } elseif ($compiler->php_handling == Smarty::PHP_ALLOW) { | ||||||
|                 if (!($compiler->smarty instanceof SmartyBC)) { |                 if (!($compiler->smarty instanceof SmartyBC)) { | ||||||
|                     $compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->lex->taglineno); |                     $compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true); | ||||||
|                 } |                 } | ||||||
|                 $compiler->has_code = true; |                 $compiler->has_code = true; | ||||||
|                 return $_attr['code']; |                 return $_attr['code']; | ||||||
|             } else { |             } else { | ||||||
|                 $compiler->trigger_template_error('Illegal $smarty->php_handling value', $compiler->lex->taglineno); |                 $compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $compiler->has_code = true; |             $compiler->has_code = true; | ||||||
|             if (!($compiler->smarty instanceof SmartyBC)) { |             if (!($compiler->smarty instanceof SmartyBC)) { | ||||||
|                 $compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno); |                 $compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', null, true); | ||||||
|             } |             } | ||||||
|             $ldel = preg_quote($compiler->smarty->left_delimiter, '#'); |             $ldel = preg_quote($compiler->smarty->left_delimiter, '#'); | ||||||
|             $rdel = preg_quote($compiler->smarty->right_delimiter, '#'); |             $rdel = preg_quote($compiler->smarty->right_delimiter, '#'); | ||||||
| @@ -84,7 +88,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|                 if ('nocache' == trim($match[2])) { |                 if ('nocache' == trim($match[2])) { | ||||||
|                     $compiler->tag_nocache = true; |                     $compiler->tag_nocache = true; | ||||||
|                 } else { |                 } else { | ||||||
|                     $compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno); |                     $compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", |             return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", | ||||||
| @@ -140,7 +144,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|         if ($lex->phpType == 'unmatched') { |         if ($lex->phpType == 'unmatched') { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         if (($lex->phpType == 'php' || $lex->phpType == 'asp') && ($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)) { |         if (($lex->phpType == 'php' || $lex->phpType == 'asp') && | ||||||
|  |             ($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE) | ||||||
|  |         ) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         $start = $lex->counter + strlen($lex->value); |         $start = $lex->counter + strlen($lex->value); | ||||||
| @@ -167,7 +173,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     while ($close > $pos && $close < $start) { |                     while ($close > $pos && $close < $start) { | ||||||
|                         if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) { |                         if (preg_match('~' . preg_quote($closeTag, '~') . | ||||||
|  |                                        '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) { | ||||||
|                             $close = $match[0][1]; |                             $close = $match[0][1]; | ||||||
|                             $from = $close + strlen($match[0][0]); |                             $from = $close + strlen($match[0][0]); | ||||||
|                         } else { |                         } else { | ||||||
| @@ -190,6 +197,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase | |||||||
|      * Call back function for $php_handling = PHP_QUOTE |      * Call back function for $php_handling = PHP_QUOTE | ||||||
|      * |      * | ||||||
|      */ |      */ | ||||||
|  |     /** | ||||||
|  |      * @param $match | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|     private function quote($match) |     private function quote($match) | ||||||
|     { |     { | ||||||
|         return htmlspecialchars($match[0], ENT_QUOTES); |         return htmlspecialchars($match[0], ENT_QUOTES); | ||||||
|   | |||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('assign'); |     public $optional_attributes = array('assign'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -35,13 +36,13 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|      * Compiles code for generating output from any expression |      * Compiles code for generating output from any expression | ||||||
|      * |      * | ||||||
|      * @param array                                 $args      array with attributes from parser |      * @param array                                 $args      array with attributes from parser | ||||||
|      * @param object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param array                                 $parameter array with compilation parameter |      * @param array                                 $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @throws SmartyException |      * @return string | ||||||
|      * @return string compiled code |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
| @@ -57,7 +58,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|             $output = $parameter['value']; |             $output = $parameter['value']; | ||||||
|             // tag modifier |             // tag modifier | ||||||
|             if (!empty($parameter['modifierlist'])) { |             if (!empty($parameter['modifierlist'])) { | ||||||
|                 $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output)); |                 $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], | ||||||
|  |                                                                                    'value'        => $output)); | ||||||
|             } |             } | ||||||
|             if (!$_attr['nofilter']) { |             if (!$_attr['nofilter']) { | ||||||
|                 // default modifier |                 // default modifier | ||||||
| @@ -74,7 +76,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|                         } |                         } | ||||||
|                         $compiler->default_modifier_list = $modifierlist; |                         $compiler->default_modifier_list = $modifierlist; | ||||||
|                     } |                     } | ||||||
|                     $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output)); |                     $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, | ||||||
|  |                                                                                        'value'        => $output)); | ||||||
|                 } |                 } | ||||||
|                 // autoescape html |                 // autoescape html | ||||||
|                 if ($compiler->template->smarty->escape_html) { |                 if ($compiler->template->smarty->escape_html) { | ||||||
| @@ -82,7 +85,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|                 } |                 } | ||||||
|                 // loop over registered filters |                 // loop over registered filters | ||||||
|                 if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) { |                 if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) { | ||||||
|                     foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) { |                     foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => | ||||||
|  |                              $function) { | ||||||
|                         if (!is_array($function)) { |                         if (!is_array($function)) { | ||||||
|                             $output = "{$function}({$output},\$_smarty_tpl)"; |                             $output = "{$function}({$output},\$_smarty_tpl)"; | ||||||
|                         } elseif (is_object($function[0])) { |                         } elseif (is_object($function[0])) { | ||||||
| @@ -104,13 +108,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 if (isset($compiler->template->variable_filters)) { |                 foreach ($compiler->variable_filters as $filter) { | ||||||
|                     foreach ($compiler->template->variable_filters as $filter) { |                     if (count($filter) == 1 && | ||||||
|                         if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) { |                         ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false | ||||||
|  |                     ) { | ||||||
|                         $output = $result; |                         $output = $result; | ||||||
|                     } else { |                     } else { | ||||||
|                             $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output)); |                         $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), | ||||||
|                         } |                                                                                            'value'        => $output)); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -123,23 +128,23 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * @param string                                $name     name of variable filter |      * @param string                                $name     name of variable filter | ||||||
|      * @param string                                $output   embedded output |      * @param string                                $output   embedded output | ||||||
|      * |      * | ||||||
|      * @return string |      * @return string | ||||||
|      */ |      */ | ||||||
|     private function compile_output_filter($compiler, $name, $output) |     private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output) | ||||||
|     { |     { | ||||||
|         $plugin_name = "smarty_variablefilter_{$name}"; |         $plugin_name = "smarty_variablefilter_{$name}"; | ||||||
|         $path = $compiler->smarty->loadPlugin($plugin_name, false); |         $path = $compiler->smarty->loadPlugin($plugin_name, false); | ||||||
|         if ($path) { |         if ($path) { | ||||||
|             if ($compiler->template->caching) { |             if ($compiler->template->caching) { | ||||||
|                 $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; |                 $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; | ||||||
|                 $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; |                 $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; | ||||||
|             } else { |             } else { | ||||||
|                 $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; |                 $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; | ||||||
|                 $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; |                 $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             // not found |             // not found | ||||||
|   | |||||||
| @@ -28,13 +28,13 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C | |||||||
|      * Compiles code for the execution of a block function |      * Compiles code for the execution of a block function | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * @param  string                                      $tag       name of block function |      * @param  string                                      $tag       name of block function | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag) | ||||||
|     { |     { | ||||||
|         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { |         if (!isset($tag[5]) || substr($tag, - 5) != 'close') { | ||||||
|             // opening tag of block plugin |             // opening tag of block plugin | ||||||
| @@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C | |||||||
|             $function = $tag_info[0]; |             $function = $tag_info[0]; | ||||||
|             // compile code |             // compile code | ||||||
|             if (!is_array($function)) { |             if (!is_array($function)) { | ||||||
|                 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |                 $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; | ||||||
|             } elseif (is_object($function[0])) { |             } elseif (is_object($function[0])) { | ||||||
|                 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |                 $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; | ||||||
|             } else { |             } else { | ||||||
|                 $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; |                 $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>"; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             // must endblock be nocache? |             // must endblock be nocache? | ||||||
| @@ -95,14 +95,22 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C | |||||||
|                 $mod_pre = $mod_post = ''; |                 $mod_pre = $mod_post = ''; | ||||||
|             } else { |             } else { | ||||||
|                 $mod_pre = ' ob_start(); '; |                 $mod_pre = ' ob_start(); '; | ||||||
|                 $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';'; |                 $mod_post = 'echo ' . | ||||||
|  |                     $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], | ||||||
|  |                                                                              'value'        => 'ob_get_clean()')) . ';'; | ||||||
|             } |             } | ||||||
|             if (!is_array($function)) { |             if (!is_array($function)) { | ||||||
|                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . | ||||||
|  |                     " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . | ||||||
|  |                     " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; | ||||||
|             } elseif (is_object($function[0])) { |             } elseif (is_object($function[0])) { | ||||||
|                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . | ||||||
|  |                     " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . | ||||||
|  |                     $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; | ||||||
|             } else { |             } else { | ||||||
|                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>"; |                 $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . | ||||||
|  |                     " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . | ||||||
|  |                     $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>"; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,13 +28,13 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna | |||||||
|      * Compiles code for the execution of a registered function |      * Compiles code for the execution of a registered function | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * @param  string                                      $tag       name of function |      * @param  string                                      $tag       name of function | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter, $tag) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag) | ||||||
|     { |     { | ||||||
|         // This tag does create output |         // This tag does create output | ||||||
|         $compiler->has_output = true; |         $compiler->has_output = true; | ||||||
|   | |||||||
| @@ -20,43 +20,50 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C | |||||||
|      * Compiles code for the special $smarty variables |      * Compiles code for the special $smarty variables | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args     array with attributes from parser |      * @param  array                                       $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase        $compiler compiler object | ||||||
|      * @param                                              $parameter |      * @param                                              $parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); |         $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); | ||||||
|         $compiled_ref = ' '; |         $variable = strtolower($compiler->getId($_index[0])); | ||||||
|         $variable = trim($_index[0], "'"); |         if ($variable === false) { | ||||||
|         if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) { |             $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); | ||||||
|  |         } | ||||||
|  |         if (!isset($compiler->smarty->security_policy) || | ||||||
|  |             $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler) | ||||||
|  |         ) { | ||||||
|             switch ($variable) { |             switch ($variable) { | ||||||
|                 case 'foreach': |                 case 'foreach': | ||||||
|                     $name = trim($_index[1], "'"); |  | ||||||
|                     $foreachVar = "'__foreach_{$name}'"; |  | ||||||
|                     return "(isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null)"; |  | ||||||
|                 case 'section': |                 case 'section': | ||||||
|                     return "\$_smarty_tpl->getVariable('smarty')->value$parameter"; |                     return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index); | ||||||
|                 case 'capture': |                 case 'capture': | ||||||
|                     return "Smarty::\$_smarty_vars$parameter"; |                     if (class_exists('Smarty_Internal_Compile_Capture')) { | ||||||
|  |                         return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); | ||||||
|  |                     } | ||||||
|  |                     return ''; | ||||||
|                 case 'now': |                 case 'now': | ||||||
|                     return 'time()'; |                     return 'time()'; | ||||||
|                 case 'cookies': |                 case 'cookies': | ||||||
|                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { |                     if (isset($compiler->smarty->security_policy) && | ||||||
|  |                         !$compiler->smarty->security_policy->allow_super_globals | ||||||
|  |                     ) { | ||||||
|                         $compiler->trigger_template_error("(secure mode) super globals not permitted"); |                         $compiler->trigger_template_error("(secure mode) super globals not permitted"); | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|                     $compiled_ref = '$_COOKIE'; |                     return '$_COOKIE'; | ||||||
|                     break; |  | ||||||
|  |  | ||||||
|                 case 'get': |                 case 'get': | ||||||
|                 case 'post': |                 case 'post': | ||||||
|                 case 'env': |                 case 'env': | ||||||
|                 case 'server': |                 case 'server': | ||||||
|                 case 'session': |                 case 'session': | ||||||
|                 case 'request': |                 case 'request': | ||||||
|                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { |                     if (isset($compiler->smarty->security_policy) && | ||||||
|  |                         !$compiler->smarty->security_policy->allow_super_globals | ||||||
|  |                     ) { | ||||||
|                         $compiler->trigger_template_error("(secure mode) super globals not permitted"); |                         $compiler->trigger_template_error("(secure mode) super globals not permitted"); | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
| @@ -78,7 +85,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C | |||||||
|                     return "'$_version'"; |                     return "'$_version'"; | ||||||
|  |  | ||||||
|                 case 'const': |                 case 'const': | ||||||
|                     if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) { |                     if (isset($compiler->smarty->security_policy) && | ||||||
|  |                         !$compiler->smarty->security_policy->allow_constants | ||||||
|  |                     ) { | ||||||
|                         $compiler->trigger_template_error("(secure mode) constants not permitted"); |                         $compiler->trigger_template_error("(secure mode) constants not permitted"); | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
| @@ -90,9 +99,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C | |||||||
|  |  | ||||||
|                 case 'config': |                 case 'config': | ||||||
|                     if (isset($_index[2])) { |                     if (isset($_index[2])) { | ||||||
|                         return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)"; |                         return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; | ||||||
|                     } else { |                     } else { | ||||||
|                         return "\$_smarty_tpl->getConfigVariable($_index[1])"; |                         return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])"; | ||||||
|                     } |                     } | ||||||
|                 case 'ldelim': |                 case 'ldelim': | ||||||
|                     $_ldelim = $compiler->smarty->left_delimiter; |                     $_ldelim = $compiler->smarty->left_delimiter; | ||||||
| @@ -114,7 +123,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C | |||||||
|                     $compiled_ref = $compiled_ref . "[$_ind]"; |                     $compiled_ref = $compiled_ref . "[$_ind]"; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |  | ||||||
|             return $compiled_ref; |             return $compiled_ref; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -25,11 +25,11 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase | |||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         if ($_attr['nocache'] === true) { |         if ($_attr['nocache'] === true) { | ||||||
|             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); |             $compiler->trigger_template_error('nocache option not allowed', null, true); | ||||||
|         } |         } | ||||||
|         // this tag does not return compiled code |         // this tag does not return compiled code | ||||||
|         $compiler->has_code = true; |         $compiler->has_code = true; | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Compiler |  * @subpackage Compiler | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase | class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection | ||||||
| { | { | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
| @@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array('name', 'loop'); |     public $required_attributes = array('name', 'loop'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase | |||||||
|      * @see Smarty_Internal_CompileBase |      * @see Smarty_Internal_CompileBase | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array('name', 'loop'); |     public $shorttag_order = array('name', 'loop'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Attribute definition: Overwrites base class. |      * Attribute definition: Overwrites base class. | ||||||
|      * |      * | ||||||
| @@ -38,103 +40,343 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase | |||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array('start', 'step', 'max', 'show'); |     public $optional_attributes = array('start', 'step', 'max', 'show'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * counter | ||||||
|  |      * | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     public $counter = 0; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Name of this tag | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public $tagName = 'section'; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Valid properties of $smarty.section.name.xxx variable | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', | ||||||
|  |                                           'index_prev', 'index_next'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * {section} tag has no item properties | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $itemProperties = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * {section} tag has always name attribute | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $isNamed = true; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles code for the {section} tag |      * Compiles code for the {section} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                 $args     array with attributes from parser |      * @param  array                                 $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param  \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting++; | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |         $attributes = array('name' => $compiler->getId($_attr['name'])); | ||||||
|         $this->openTag($compiler, 'section', array('section', $compiler->nocache)); |         unset($_attr['name']); | ||||||
|  |         foreach ($attributes as $a => $v) { | ||||||
|  |             if ($v === false) { | ||||||
|  |                 $compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         $local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_'; | ||||||
|  |         $sectionVar = "\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']"; | ||||||
|  |         $this->openTag($compiler, 'section', array('section', $compiler->nocache, $local, $sectionVar)); | ||||||
|         // maybe nocache because of nocache variables |         // maybe nocache because of nocache variables | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|  |  | ||||||
|         $output = "<?php "; |         $initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__section_{$attributes['name']}'] : false",); | ||||||
|  |         $initNamedProperty = array(); | ||||||
|         $section_name = $_attr['name']; |         $initFor = array(); | ||||||
|  |         $incFor = array(); | ||||||
|         $output .= "if (isset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name])) unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n"; |         $cmpFor = array(); | ||||||
|         $section_props = "\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]"; |         $propValue = array('index'     => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1, | ||||||
|  |                            'iteration' => "{$local}iteration", | ||||||
|  |  | ||||||
|  |         ); | ||||||
|  |         $propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,); | ||||||
|  |         // search for used tag attributes | ||||||
|  |         $this->scanForProperties($attributes, $compiler); | ||||||
|  |         if (!empty($this->matchResults['named'])) { | ||||||
|  |             $namedAttr = $this->matchResults['named']; | ||||||
|  |         } | ||||||
|  |         $namedAttr['index'] = true; | ||||||
|  |         $output = "<?php\n"; | ||||||
|         foreach ($_attr as $attr_name => $attr_value) { |         foreach ($_attr as $attr_name => $attr_value) { | ||||||
|             switch ($attr_name) { |             switch ($attr_name) { | ||||||
|                 case 'loop': |                 case 'loop': | ||||||
|                     $output .= "{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop); unset(\$_loop);\n"; |                     if (is_numeric($attr_value)) { | ||||||
|  |                         $v = (int) $attr_value; | ||||||
|  |                         $t = 0; | ||||||
|  |                     } else { | ||||||
|  |                         $v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))"; | ||||||
|  |                         $t = 1; | ||||||
|  |                     } | ||||||
|  |                     if (isset($namedAttr['loop'])) { | ||||||
|  |                         $initNamedProperty['loop'] = "'loop' => {$v}"; | ||||||
|  |                         if ($t == 1) { | ||||||
|  |                             $v = "{$sectionVar}->value['loop']"; | ||||||
|  |                         } | ||||||
|  |                     } elseif ($t == 1) { | ||||||
|  |                         $initLocal['loop'] = $v; | ||||||
|  |                         $v = "{$local}loop"; | ||||||
|  |                     } | ||||||
|                     break; |                     break; | ||||||
|  |  | ||||||
|                 case 'show': |                 case 'show': | ||||||
|                     if (is_bool($attr_value)) { |                     if (is_bool($attr_value)) { | ||||||
|                         $show_attr_value = $attr_value ? 'true' : 'false'; |                         $v = $attr_value ? 'true' : 'false'; | ||||||
|  |                         $t = 0; | ||||||
|                     } else { |                     } else { | ||||||
|                         $show_attr_value = "(bool) $attr_value"; |                         $v = "(bool) $attr_value"; | ||||||
|  |                         $t = 3; | ||||||
|                     } |                     } | ||||||
|                     $output .= "{$section_props}['show'] = $show_attr_value;\n"; |  | ||||||
|                     break; |                     break; | ||||||
|  |                 case 'step': | ||||||
|                 case 'name': |                     if (is_numeric($attr_value)) { | ||||||
|                     $output .= "{$section_props}['$attr_name'] = $attr_value;\n"; |                         $v = (int) $attr_value; | ||||||
|  |                         $v = ($v == 0) ? 1 : $v; | ||||||
|  |                         $t = 0; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |                     $initLocal['step'] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value"; | ||||||
|  |                     $v = "{$local}step"; | ||||||
|  |                     $t = 2; | ||||||
|                     break; |                     break; | ||||||
|  |  | ||||||
|                 case 'max': |                 case 'max': | ||||||
|                 case 'start': |                 case 'start': | ||||||
|                     $output .= "{$section_props}['$attr_name'] = (int) $attr_value;\n"; |                     if (is_numeric($attr_value)) { | ||||||
|                     break; |                         $v = (int) $attr_value; | ||||||
|  |                         $t = 0; | ||||||
|                 case 'step': |  | ||||||
|                     $output .= "{$section_props}['$attr_name'] = ((int) $attr_value) == 0 ? 1 : (int) $attr_value;\n"; |  | ||||||
|                         break; |                         break; | ||||||
|                     } |                     } | ||||||
|  |                     $v = "(int)@$attr_value"; | ||||||
|  |                     $t = 3; | ||||||
|  |                     break; | ||||||
|  |             } | ||||||
|  |             if ($t == 3 && $compiler->getId($attr_value)) { | ||||||
|  |                 $t = 1; | ||||||
|  |             } | ||||||
|  |             $propValue[$attr_name] = $v; | ||||||
|  |             $propType[$attr_name] = $t; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!isset($_attr['show'])) { |         if (isset($namedAttr['step'])) { | ||||||
|             $output .= "{$section_props}['show'] = true;\n"; |             $initNamedProperty['step'] = $propValue['step']; | ||||||
|         } |         } | ||||||
|  |         if (isset($namedAttr['iteration'])) { | ||||||
|         if (!isset($_attr['loop'])) { |             $propValue['iteration'] = "{$sectionVar}->value['iteration']"; | ||||||
|             $output .= "{$section_props}['loop'] = 1;\n"; |  | ||||||
|         } |         } | ||||||
|  |         $incFor['iteration'] = "{$propValue['iteration']}++"; | ||||||
|  |         $initFor['iteration'] = "{$propValue['iteration']} = 1"; | ||||||
|  |  | ||||||
|         if (!isset($_attr['max'])) { |         if ($propType['step'] == 0) { | ||||||
|             $output .= "{$section_props}['max'] = {$section_props}['loop'];\n"; |             if ($propValue['step'] == 1) { | ||||||
|  |                 $incFor['index'] = "{$sectionVar}->value['index']++"; | ||||||
|  |             } elseif ($propValue['step'] > 1) { | ||||||
|  |                 $incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}"; | ||||||
|             } else { |             } else { | ||||||
|             $output .= "if ({$section_props}['max'] < 0)\n" . "    {$section_props}['max'] = {$section_props}['loop'];\n"; |                 $incFor['index'] = "{$sectionVar}->value['index'] -= " . - $propValue['step']; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         if (!isset($_attr['step'])) { |  | ||||||
|             $output .= "{$section_props}['step'] = 1;\n"; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (!isset($_attr['start'])) { |  | ||||||
|             $output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n"; |  | ||||||
|         } else { |         } else { | ||||||
|             $output .= "if ({$section_props}['start'] < 0)\n" . "    {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . "    {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n"; |             $incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}"; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $output .= "if ({$section_props}['show']) {\n"; |         if (!isset($propValue['max'])) { | ||||||
|  |             $propValue['max'] = $propValue['loop']; | ||||||
|  |             $propType['max'] = $propType['loop']; | ||||||
|  |         } elseif ($propType['max'] != 0) { | ||||||
|  |             $propValue['max'] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}"; | ||||||
|  |             $propType['max'] = 1; | ||||||
|  |         } else { | ||||||
|  |             if ($propValue['max'] < 0) { | ||||||
|  |                 $propValue['max'] = $propValue['loop']; | ||||||
|  |                 $propType['max'] = $propType['loop']; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         if (!isset($propValue['start'])) { | ||||||
|  |             $start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'], | ||||||
|  |                                 5 => ' - 1'); | ||||||
|  |             if ($propType['loop'] == 0) { | ||||||
|  |                 $start_code[5] = ''; | ||||||
|  |                 $start_code[4] = $propValue['loop'] - 1; | ||||||
|  |             } | ||||||
|  |             if ($propType['step'] == 0) { | ||||||
|  |                 if ($propValue['step'] > 0) { | ||||||
|  |                     $start_code = array(1 => '0'); | ||||||
|  |                     $propType['start'] = 0; | ||||||
|  |                 } else { | ||||||
|  |                     $start_code[1] = $start_code[2] = $start_code[3] = ''; | ||||||
|  |                     $propType['start'] = $propType['loop']; | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 $propType['start'] = 1; | ||||||
|  |             } | ||||||
|  |             $propValue['start'] = join('', $start_code); | ||||||
|  |         } else { | ||||||
|  |             $start_code = array(1  => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", | ||||||
|  |                                 4  => '0', 5 => ' : ', 6 => '-1', 7 => ', ', | ||||||
|  |                                 8  => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ', | ||||||
|  |                                 12 => 'min(', 13 => $propValue['start'], 14 => ', ', | ||||||
|  |                                 15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ', | ||||||
|  |                                 18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1", | ||||||
|  |                                 19 => ')'); | ||||||
|  |             if ($propType['step'] == 0) { | ||||||
|  |                 $start_code[3] = $start_code[5] = $start_code[15] = $start_code[17] = ''; | ||||||
|  |                 if ($propValue['step'] > 0) { | ||||||
|  |                     $start_code[6] = $start_code[18] = ''; | ||||||
|  |                 } else { | ||||||
|  |                     $start_code[4] = $start_code[16] = ''; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             if ($propType['start'] == 0) { | ||||||
|  |                 if ($propType['loop'] == 0) { | ||||||
|  |                     $start_code[8] = $propValue['start'] + $propValue['loop']; | ||||||
|  |                 } | ||||||
|  |                 $propType['start'] = $propType['step'] + $propType['loop']; | ||||||
|  |                 $start_code[1] = ''; | ||||||
|  |                 if ($propValue['start'] < 0) { | ||||||
|  |                     for ($i = 11; $i <= 19; $i ++) { | ||||||
|  |                         $start_code[$i] = ''; | ||||||
|  |                     } | ||||||
|  |                     if ($propType['start'] == 0) { | ||||||
|  |                         $start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] + | ||||||
|  |                                                                                 $propValue['loop'])); | ||||||
|  |                     } | ||||||
|  |                 } else { | ||||||
|  |                     for ($i = 1; $i <= 11; $i ++) { | ||||||
|  |                         $start_code[$i] = ''; | ||||||
|  |                     } | ||||||
|  |                     if ($propType['start'] == 0) { | ||||||
|  |                         $start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] - | ||||||
|  |                             1, $propValue['start'])); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             $propValue['start'] = join('', $start_code); | ||||||
|  |         } | ||||||
|  |         if ($propType['start'] != 0) { | ||||||
|  |             $initLocal['start'] = $propValue['start']; | ||||||
|  |             $propValue['start'] = "{$local}start"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $initFor['index'] = "{$sectionVar}->value['index'] = {$propValue['start']}"; | ||||||
|  |  | ||||||
|         if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) { |         if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) { | ||||||
|             $output .= "    {$section_props}['total'] = {$section_props}['loop'];\n"; |             $propValue['total'] = $propValue['loop']; | ||||||
|  |             $propType['total'] = $propType['loop']; | ||||||
|         } else { |         } else { | ||||||
|             $output .= "    {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n"; |             $propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max']; | ||||||
|  |             if ($propType['total'] == 0) { | ||||||
|  |                 $propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] - | ||||||
|  |                                                    $propValue['start'] : (int) $propValue['start'] + 1) / | ||||||
|  |                                                abs($propValue['step'])), $propValue['max']); | ||||||
|  |             } else { | ||||||
|  |                 $total_code = array(1  => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ", | ||||||
|  |                                     5  => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ', | ||||||
|  |                                     9  => $propValue['start'], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(', | ||||||
|  |                                     14 => $propValue['step'], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",); | ||||||
|  |                 if (!isset($propValue['max'])) { | ||||||
|  |                     $total_code[1] = $total_code[17] = ''; | ||||||
|  |                 } | ||||||
|  |                 if ($propType['loop'] + $propType['start'] == 0) { | ||||||
|  |                     $total_code[5] = $propValue['loop'] - $propValue['start']; | ||||||
|  |                     $total_code[6] = $total_code[7] = ''; | ||||||
|  |                 } | ||||||
|  |                 if ($propType['start'] == 0) { | ||||||
|  |                     $total_code[9] = (int) $propValue['start'] + 1; | ||||||
|  |                     $total_code[10] = ''; | ||||||
|  |                 } | ||||||
|  |                 if ($propType['step'] == 0) { | ||||||
|  |                     $total_code[13] = $total_code[15] = ''; | ||||||
|  |                     if ($propValue['step'] == 1 || $propValue['step'] == - 1) { | ||||||
|  |                         $total_code[2] = $total_code[12] = $total_code[14] = $total_code[16] = ''; | ||||||
|  |                     } elseif ($propValue['step'] < 0) { | ||||||
|  |                         $total_code[14] = - $propValue['step']; | ||||||
|  |                     } | ||||||
|  |                     $total_code[4] = ''; | ||||||
|  |                     if ($propValue['step'] > 0) { | ||||||
|  |                         $total_code[8] = $total_code[9] = $total_code[10] = ''; | ||||||
|  |                     } else { | ||||||
|  |                         $total_code[5] = $total_code[6] = $total_code[7] = $total_code[8] = ''; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 $propValue['total'] = join('', $total_code); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         $output .= "    if ({$section_props}['total'] == 0)\n" . "        {$section_props}['show'] = false;\n" . "} else\n" . "    {$section_props}['total'] = 0;\n"; |  | ||||||
|  |  | ||||||
|         $output .= "if ({$section_props}['show']):\n"; |         if (isset($namedAttr['total'])) { | ||||||
|         $output .= " |             $initNamedProperty['total'] = "'total' => {$propValue['total']}"; | ||||||
|             for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1; |             if ($propType['total'] > 0) { | ||||||
|                  {$section_props}['iteration'] <= {$section_props}['total']; |                 $propValue['total'] = "{$sectionVar}->value['total']"; | ||||||
|                  {$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n"; |             } | ||||||
|         $output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n"; |         } elseif ($propType['total'] > 0) { | ||||||
|         $output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n"; |             $initLocal['total'] = $propValue['total']; | ||||||
|         $output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n"; |             $propValue['total'] = "{$local}total"; | ||||||
|         $output .= "{$section_props}['first']      = ({$section_props}['iteration'] == 1);\n"; |         } | ||||||
|         $output .= "{$section_props}['last']       = ({$section_props}['iteration'] == {$section_props}['total']);\n"; |  | ||||||
|  |  | ||||||
|  |         $cmpFor['iteration'] = "{$propValue['iteration']} <= {$propValue['total']}"; | ||||||
|  |  | ||||||
|  |         foreach ($initLocal as $key => $code) { | ||||||
|  |             $output .= "{$local}{$key} = {$code};\n"; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $_vars = 'array(' . join(', ', $initNamedProperty) . ')'; | ||||||
|  |         $output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n"; | ||||||
|  |         $cond_code = "{$propValue['total']} != 0"; | ||||||
|  |         if ($propType['total'] == 0) { | ||||||
|  |             if ($propValue['total'] == 0) { | ||||||
|  |                 $cond_code = 'false'; | ||||||
|  |             } else { | ||||||
|  |                 $cond_code = 'true'; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         if ($propType['show'] > 0) { | ||||||
|  |             $output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n"; | ||||||
|  |             $output .= "if ({$local}show) {\n"; | ||||||
|  |         } elseif ($propValue['show'] == 'true') { | ||||||
|  |             $output .= "if ({$cond_code}) {\n"; | ||||||
|  |         } else { | ||||||
|  |             $output .= "if (false) {\n"; | ||||||
|  |         } | ||||||
|  |         $jinit = join(', ', $initFor); | ||||||
|  |         $jcmp = join(', ', $cmpFor); | ||||||
|  |         $jinc = join(', ', $incFor); | ||||||
|  |         $output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n"; | ||||||
|  |         if (isset($namedAttr['rownum'])) { | ||||||
|  |             $output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($namedAttr['index_prev'])) { | ||||||
|  |             $output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($namedAttr['index_next'])) { | ||||||
|  |             $output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($namedAttr['first'])) { | ||||||
|  |             $output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n"; | ||||||
|  |         } | ||||||
|  |         if (isset($namedAttr['last'])) { | ||||||
|  |             $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n"; | ||||||
|  |         } | ||||||
|         $output .= "?>"; |         $output .= "?>"; | ||||||
|  |  | ||||||
|         return $output; |         return $output; | ||||||
| @@ -153,19 +395,19 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {sectionelse} tag |      * Compiles code for the {sectionelse} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|  |  | ||||||
|         list($openTag, $nocache) = $this->closeTag($compiler, array('section')); |         list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section')); | ||||||
|         $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache)); |         $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar)); | ||||||
|  |  | ||||||
|         return "<?php endfor; else: ?>"; |         return "<?php }} else {\n ?>"; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -181,26 +423,32 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {/section} tag |      * Compiles code for the {/section} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                $args     array with attributes from parser |      * @param  array                                $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         // check and get attributes |         $compiler->loopNesting--; | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |  | ||||||
|  |  | ||||||
|         // must endblock be nocache? |         // must endblock be nocache? | ||||||
|         if ($compiler->nocache) { |         if ($compiler->nocache) { | ||||||
|             $compiler->tag_nocache = true; |             $compiler->tag_nocache = true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('section', 'sectionelse')); |         list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section', | ||||||
|  |                                                                                                    'sectionelse')); | ||||||
|  |  | ||||||
|  |         $output = "<?php\n"; | ||||||
|         if ($openTag == 'sectionelse') { |         if ($openTag == 'sectionelse') { | ||||||
|             return "<?php endif; ?>"; |             $output .= "}\n"; | ||||||
|         } else { |         } else { | ||||||
|             return "<?php endfor; endif; ?>"; |             $output .= "}\n}\n"; | ||||||
|         } |         } | ||||||
|  |         $output .= "if ({$local}saved) {\n"; | ||||||
|  |         $output .= "{$sectionVar} = {$local}saved;\n"; | ||||||
|  |         $output .= "}\n"; | ||||||
|  |         $output .= "?>"; | ||||||
|  |  | ||||||
|  |         return $output; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -25,10 +25,10 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase | |||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|         $compiler->variable_filter_stack[] = $compiler->template->variable_filters; |         $compiler->variable_filter_stack[] = $compiler->variable_filters; | ||||||
|         $compiler->template->variable_filters = $parameter['modifier_list']; |         $compiler->variable_filters = $parameter['modifier_list']; | ||||||
|         // this tag does not return compiled code |         // this tag does not return compiled code | ||||||
|         $compiler->has_code = false; |         $compiler->has_code = false; | ||||||
|  |  | ||||||
| @@ -53,14 +53,14 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase | |||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         // reset variable filter to previous state |         // reset variable filter to previous state | ||||||
|         if (count($compiler->variable_filter_stack)) { |         if (count($compiler->variable_filter_stack)) { | ||||||
|             $compiler->template->variable_filters = array_pop($compiler->variable_filter_stack); |             $compiler->variable_filters = array_pop($compiler->variable_filter_stack); | ||||||
|         } else { |         } else { | ||||||
|             $compiler->template->variable_filters = array(); |             $compiler->variable_filters = array(); | ||||||
|         } |         } | ||||||
|         // this tag does not return compiled code |         // this tag does not return compiled code | ||||||
|         $compiler->has_code = false; |         $compiler->has_code = false; | ||||||
|   | |||||||
| @@ -20,23 +20,26 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {while} tag |      * Compiles code for the {while} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args      array with attributes from parser |      * @param  array                                       $args      array with attributes from parser | ||||||
|      * @param  object $compiler  compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object | ||||||
|      * @param  array                                       $parameter array with compilation parameter |      * @param  array                                       $parameter array with compilation parameter | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler, $parameter) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting++; | ||||||
|         // check and get attributes |         // check and get attributes | ||||||
|         $_attr = $this->getAttributes($compiler, $args); |         $_attr = $this->getAttributes($compiler, $args); | ||||||
|         $this->openTag($compiler, 'while', $compiler->nocache); |         $this->openTag($compiler, 'while', $compiler->nocache); | ||||||
|  |  | ||||||
|         if (!array_key_exists("if condition", $parameter)) { |         if (!array_key_exists("if condition", $parameter)) { | ||||||
|             $compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno); |             $compiler->trigger_template_error("missing while condition", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // maybe nocache because of nocache variables |         // maybe nocache because of nocache variables | ||||||
|         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; | ||||||
|  |         $_output = "<?php\n"; | ||||||
|         if (is_array($parameter['if condition'])) { |         if (is_array($parameter['if condition'])) { | ||||||
|             if ($compiler->nocache) { |             if ($compiler->nocache) { | ||||||
|                 $_nocache = ',true'; |                 $_nocache = ',true'; | ||||||
| @@ -55,17 +58,24 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase | |||||||
|                 $_nocache = ''; |                 $_nocache = ''; | ||||||
|             } |             } | ||||||
|             if (is_array($parameter['if condition']['var'])) { |             if (is_array($parameter['if condition']['var'])) { | ||||||
|                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n"; |                 $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . | ||||||
|                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>"; |                     "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . | ||||||
|  |                     "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . | ||||||
|  |                     "$_nocache);\n"; | ||||||
|  |                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . | ||||||
|  |                     $parameter['if condition']['var']['smarty_internal_index'] . " = " . | ||||||
|  |                     $parameter['if condition']['value'] . ") {?>"; | ||||||
|             } else { |             } else { | ||||||
|                 $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});"; |                 $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . | ||||||
|                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>"; |                     "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . | ||||||
|  |                     "] = new Smarty_Variable(null{$_nocache});"; | ||||||
|  |                 $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . | ||||||
|  |                     $parameter['if condition']['value'] . ") {?>"; | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             $_output .= "while ({$parameter['if condition']}) {?>"; | ||||||
|          } |          } | ||||||
|  |  | ||||||
|         return $_output; |         return $_output; | ||||||
|         } else { |  | ||||||
|             return "<?php while ({$parameter['if condition']}) {?>"; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -81,18 +91,18 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase | |||||||
|      * Compiles code for the {/while} tag |      * Compiles code for the {/while} tag | ||||||
|      * |      * | ||||||
|      * @param  array                                       $args     array with attributes from parser |      * @param  array                                       $args     array with attributes from parser | ||||||
|      * @param  object $compiler compiler object |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return string compiled code |      * @return string compiled code | ||||||
|      */ |      */ | ||||||
|     public function compile($args, $compiler) |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | ||||||
|     { |     { | ||||||
|  |         $compiler->loopNesting--; | ||||||
|         // must endblock be nocache? |         // must endblock be nocache? | ||||||
|         if ($compiler->nocache) { |         if ($compiler->nocache) { | ||||||
|             $compiler->tag_nocache = true; |             $compiler->tag_nocache = true; | ||||||
|         } |         } | ||||||
|         $compiler->nocache = $this->closeTag($compiler, array('while')); |         $compiler->nocache = $this->closeTag($compiler, array('while')); | ||||||
|  |         return "<?php }?>\n"; | ||||||
|         return "<?php }?>"; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,6 +21,7 @@ abstract class Smarty_Internal_CompileBase | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $required_attributes = array(); |     public $required_attributes = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Array of names of optional attribute required by tag |      * Array of names of optional attribute required by tag | ||||||
|      * use array('_any') if there is no restriction of attributes names |      * use array('_any') if there is no restriction of attributes names | ||||||
| @@ -28,12 +29,14 @@ abstract class Smarty_Internal_CompileBase | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $optional_attributes = array(); |     public $optional_attributes = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Shorttag attribute order defined by its names |      * Shorttag attribute order defined by its names | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $shorttag_order = array(); |     public $shorttag_order = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Array of names of valid option flags |      * Array of names of valid option flags | ||||||
|      * |      * | ||||||
| @@ -68,7 +71,7 @@ abstract class Smarty_Internal_CompileBase | |||||||
|                     $_indexed_attr[$this->shorttag_order[$key]] = $mixed; |                     $_indexed_attr[$this->shorttag_order[$key]] = $mixed; | ||||||
|                 } else { |                 } else { | ||||||
|                     // too many shorthands |                     // too many shorthands | ||||||
|                     $compiler->trigger_template_error('too many shorthand attributes', $compiler->lex->taglineno); |                     $compiler->trigger_template_error('too many shorthand attributes', null, true); | ||||||
|                 } |                 } | ||||||
|                 // named attribute |                 // named attribute | ||||||
|             } else { |             } else { | ||||||
| @@ -90,7 +93,7 @@ abstract class Smarty_Internal_CompileBase | |||||||
|                             $_indexed_attr[$kv['key']] = false; |                             $_indexed_attr[$kv['key']] = false; | ||||||
|                         } |                         } | ||||||
|                     } else { |                     } else { | ||||||
|                         $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $compiler->lex->taglineno); |                         $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", null, true); | ||||||
|                     } |                     } | ||||||
|                     // must be named attribute |                     // must be named attribute | ||||||
|                 } else { |                 } else { | ||||||
| @@ -102,7 +105,7 @@ abstract class Smarty_Internal_CompileBase | |||||||
|         // check if all required attributes present |         // check if all required attributes present | ||||||
|         foreach ($this->required_attributes as $attr) { |         foreach ($this->required_attributes as $attr) { | ||||||
|             if (!array_key_exists($attr, $_indexed_attr)) { |             if (!array_key_exists($attr, $_indexed_attr)) { | ||||||
|                 $compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno); |                 $compiler->trigger_template_error("missing \"" . $attr . "\" attribute", null, true); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // check for not allowed attributes |         // check for not allowed attributes | ||||||
| @@ -110,7 +113,7 @@ abstract class Smarty_Internal_CompileBase | |||||||
|             $tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags); |             $tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags); | ||||||
|             foreach ($_indexed_attr as $key => $dummy) { |             foreach ($_indexed_attr as $key => $dummy) { | ||||||
|                 if (!in_array($key, $tmp_array) && $key !== 0) { |                 if (!in_array($key, $tmp_array) && $key !== 0) { | ||||||
|                     $compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $compiler->lex->taglineno); |                     $compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", null, true); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -162,12 +165,13 @@ abstract class Smarty_Internal_CompileBase | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             // wrong nesting of tags |             // wrong nesting of tags | ||||||
|             $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag"); |             $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . | ||||||
|  |                                               "{$compiler->smarty->right_delimiter} tag"); | ||||||
|  |  | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|         // wrong nesting of tags |         // wrong nesting of tags | ||||||
|         $compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno); |         $compiler->trigger_template_error("unexpected closing tag", null, true); | ||||||
|  |  | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -30,6 +30,7 @@ class Smarty_Internal_Config_File_Compiler | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $parser_class; |     public $parser_class; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Lexer object |      * Lexer object | ||||||
|      * |      * | ||||||
| @@ -100,16 +101,17 @@ class Smarty_Internal_Config_File_Compiler | |||||||
|     public function compileTemplate(Smarty_Internal_Template $template) |     public function compileTemplate(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $this->template = $template; |         $this->template = $template; | ||||||
|         $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->name, $this->template->source->timestamp, $this->template->source->type); |         $this->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, | ||||||
|        // on empty config just return |                                                                                              $this->template->source->getTimeStamp(), | ||||||
|         if ($template->source->content == '') { |                                                                                              $this->template->source->type); | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
|         if ($this->smarty->debugging) { |         if ($this->smarty->debugging) { | ||||||
|             Smarty_Internal_Debug::start_compile($this->template); |             $this->smarty->_debug->start_compile($this->template); | ||||||
|         } |         } | ||||||
|         // init the lexer/parser to compile the config file |         // init the lexer/parser to compile the config file | ||||||
|         $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->content) . "\n", $this); |         /* @var Smarty_Internal_ConfigFileLexer $lex */ | ||||||
|  |         $lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) . | ||||||
|  |                                       "\n", $this); | ||||||
|  |         /* @var Smarty_Internal_ConfigFileParser $parser */ | ||||||
|         $parser = new $this->parser_class($lex, $this); |         $parser = new $this->parser_class($lex, $this); | ||||||
|  |  | ||||||
|         if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { |         if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { | ||||||
| @@ -136,14 +138,16 @@ class Smarty_Internal_Config_File_Compiler | |||||||
|             mb_internal_encoding($mbEncoding); |             mb_internal_encoding($mbEncoding); | ||||||
|         } |         } | ||||||
|         if ($this->smarty->debugging) { |         if ($this->smarty->debugging) { | ||||||
|             Smarty_Internal_Debug::end_compile($this->template); |             $this->smarty->_debug->end_compile($this->template); | ||||||
|         } |         } | ||||||
|         // template header code |         // template header code | ||||||
|         $template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; |         $template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . | ||||||
|  |             strftime("%Y-%m-%d %H:%M:%S") . "\n"; | ||||||
|         $template_header .= "         compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; |         $template_header .= "         compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; | ||||||
|  |  | ||||||
|         $code = '<?php Smarty_Internal_Extension_Config::loadConfigVars($_smarty_tpl, ' . var_export($this->config_data, true) . '); ?>'; |         $code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' . | ||||||
|         return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code); |             var_export($this->config_data, true) . '); ?>'; | ||||||
|  |         return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -13,34 +13,70 @@ | |||||||
|  * |  * | ||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Template |  * @subpackage Template | ||||||
|  |  * | ||||||
|  |  * @method mixed getConfigVars(string $varName = null, bool $searchParents = true) | ||||||
|  |  * @method mixed getStreamVariable(string $variable) | ||||||
|  |  * @method Smarty_Internal_Data clearAssign(mixed $tpl_var) | ||||||
|  |  * @method Smarty_Internal_Data clearAllAssign() | ||||||
|  |  * @method Smarty_Internal_Data clearConfig(string $varName = null) | ||||||
|  |  * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local') | ||||||
|  |  * @property int $scope | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Data | class Smarty_Internal_Data | ||||||
| { | { | ||||||
|  |     /** | ||||||
|  |      * This object type (Smarty = 1, template = 2, data = 4) | ||||||
|  |      * | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     public $_objType = 4; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * name of class used for templates |      * name of class used for templates | ||||||
|      * |      * | ||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $template_class = 'Smarty_Internal_Template'; |     public $template_class = 'Smarty_Internal_Template'; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * template variables |      * template variables | ||||||
|      * |      * | ||||||
|      * @var array |      * @var Smarty_Variable[] | ||||||
|      */ |      */ | ||||||
|     public $tpl_vars = array(); |     public $tpl_vars = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * parent template (if any) |      * parent template (if any) | ||||||
|      * |      * | ||||||
|      * @var Smarty_Internal_Template |      * @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data | ||||||
|      */ |      */ | ||||||
|     public $parent = null; |     public $parent = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * configuration settings |      * configuration settings | ||||||
|      * |      * | ||||||
|      * @var array |      * @var string[] | ||||||
|      */ |      */ | ||||||
|     public $config_vars = array(); |     public $config_vars = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * extension handler | ||||||
|  |      * | ||||||
|  |      * @var Smarty_Internal_Extension_Handler | ||||||
|  |      */ | ||||||
|  |     public $ext = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Smarty_Internal_Data constructor. | ||||||
|  |      * | ||||||
|  |      * Install extension handler | ||||||
|  |      */ | ||||||
|  |     public function __construct() | ||||||
|  |     { | ||||||
|  |         $this->ext = new Smarty_Internal_Extension_Handler(); | ||||||
|  |         $this->ext->objType = $this->_objType; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * assigns a Smarty variable |      * assigns a Smarty variable | ||||||
|      * |      * | ||||||
| @@ -48,7 +84,8 @@ class Smarty_Internal_Data | |||||||
|      * @param  mixed        $value   the value to assign |      * @param  mixed        $value   the value to assign | ||||||
|      * @param  boolean      $nocache if true any output of this variable will be not cached |      * @param  boolean      $nocache if true any output of this variable will be not cached | ||||||
|      * |      * | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for | ||||||
|  |      *                              chaining | ||||||
|      */ |      */ | ||||||
|     public function assign($tpl_var, $value = null, $nocache = false) |     public function assign($tpl_var, $value = null, $nocache = false) | ||||||
|     { |     { | ||||||
| @@ -56,119 +93,53 @@ class Smarty_Internal_Data | |||||||
|             foreach ($tpl_var as $_key => $_val) { |             foreach ($tpl_var as $_key => $_val) { | ||||||
|                 if ($_key != '') { |                 if ($_key != '') { | ||||||
|                     $this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache); |                     $this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache); | ||||||
|  |                     if ($this->_objType == 2 && $this->scope) { | ||||||
|  |                         $this->ext->_updateScope->updateScope($this, $_key); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             if ($tpl_var != '') { |             if ($tpl_var != '') { | ||||||
|                 $this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache); |                 $this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache); | ||||||
|  |                 if ($this->_objType == 2 && $this->scope) { | ||||||
|  |                     $this->ext->_updateScope->updateScope($this, $tpl_var); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * assigns a global Smarty variable |  | ||||||
|      * |  | ||||||
|      * @param  string  $varname the global variable name |  | ||||||
|      * @param  mixed   $value   the value to assign |  | ||||||
|      * @param  boolean $nocache if true any output of this variable will be not cached |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function assignGlobal($varname, $value = null, $nocache = false) |  | ||||||
|     { |  | ||||||
|         if ($varname != '') { |  | ||||||
|             Smarty::$global_tpl_vars[$varname] = new Smarty_Variable($value, $nocache); |  | ||||||
|             $ptr = $this; |  | ||||||
|             while ($ptr instanceof Smarty_Internal_Template) { |  | ||||||
|                 $ptr->tpl_vars[$varname] = clone Smarty::$global_tpl_vars[$varname]; |  | ||||||
|                 $ptr = $ptr->parent; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * assigns values to template variables by reference |  | ||||||
|      * |  | ||||||
|      * @param string   $tpl_var the template variable name |  | ||||||
|      * @param          $value |  | ||||||
|      * @param  boolean $nocache if true any output of this variable will be not cached |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function assignByRef($tpl_var, &$value, $nocache = false) |  | ||||||
|     { |  | ||||||
|         if ($tpl_var != '') { |  | ||||||
|             $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); |  | ||||||
|             $this->tpl_vars[$tpl_var]->value = &$value; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |         return $this; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * appends values to template variables |      * appends values to template variables | ||||||
|      * |      * | ||||||
|  |      * @api  Smarty::append() | ||||||
|  |      * @link http://www.smarty.net/docs/en/api.append.tpl | ||||||
|  |      * | ||||||
|      * @param  array|string $tpl_var                                           the template variable name(s) |      * @param  array|string $tpl_var                                           the template variable name(s) | ||||||
|      * @param  mixed        $value                                             the value to append |      * @param  mixed        $value                                             the value to append | ||||||
|      * @param  boolean      $merge   flag if array elements shall be merged |      * @param  bool         $merge                                             flag if array elements shall be merged | ||||||
|      * @param  boolean      $nocache if true any output of this variable will be not cached |      * @param  bool         $nocache                                           if true any output of this variable will | ||||||
|  |      *                                                                         be not cached | ||||||
|      * |      * | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |      * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty | ||||||
|      */ |      */ | ||||||
|     public function append($tpl_var, $value = null, $merge = false, $nocache = false) |     public function append($tpl_var, $value = null, $merge = false, $nocache = false) | ||||||
|     { |     { | ||||||
|         if (is_array($tpl_var)) { |         return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache); | ||||||
|             // $tpl_var is an array, ignore $value |  | ||||||
|             foreach ($tpl_var as $_key => $_val) { |  | ||||||
|                 if ($_key != '') { |  | ||||||
|                     if (!isset($this->tpl_vars[$_key])) { |  | ||||||
|                         $tpl_var_inst = $this->getVariable($_key, null, true, false); |  | ||||||
|                         if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { |  | ||||||
|                             $this->tpl_vars[$_key] = new Smarty_Variable(null, $nocache); |  | ||||||
|                         } else { |  | ||||||
|                             $this->tpl_vars[$_key] = clone $tpl_var_inst; |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) { |  | ||||||
|                         settype($this->tpl_vars[$_key]->value, 'array'); |  | ||||||
|                     } |  | ||||||
|                     if ($merge && is_array($_val)) { |  | ||||||
|                         foreach ($_val as $_mkey => $_mval) { |  | ||||||
|                             $this->tpl_vars[$_key]->value[$_mkey] = $_mval; |  | ||||||
|                         } |  | ||||||
|                     } else { |  | ||||||
|                         $this->tpl_vars[$_key]->value[] = $_val; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             if ($tpl_var != '' && isset($value)) { |  | ||||||
|                 if (!isset($this->tpl_vars[$tpl_var])) { |  | ||||||
|                     $tpl_var_inst = $this->getVariable($tpl_var, null, true, false); |  | ||||||
|                     if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { |  | ||||||
|                         $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); |  | ||||||
|                     } else { |  | ||||||
|                         $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { |  | ||||||
|                     settype($this->tpl_vars[$tpl_var]->value, 'array'); |  | ||||||
|                 } |  | ||||||
|                 if ($merge && is_array($value)) { |  | ||||||
|                     foreach ($value as $_mkey => $_mval) { |  | ||||||
|                         $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     $this->tpl_vars[$tpl_var]->value[] = $value; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|         return $this; |     /** | ||||||
|  |      * assigns a global Smarty variable | ||||||
|  |      * | ||||||
|  |      * @param  string  $varName the global variable name | ||||||
|  |      * @param  mixed   $value   the value to assign | ||||||
|  |      * @param  boolean $nocache if true any output of this variable will be not cached | ||||||
|  |      * | ||||||
|  |      * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty | ||||||
|  |      */ | ||||||
|  |     public function assignGlobal($varName, $value = null, $nocache = false) | ||||||
|  |     { | ||||||
|  |         return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -178,227 +149,77 @@ class Smarty_Internal_Data | |||||||
|      * @param  mixed   &$value  the referenced value to append |      * @param  mixed   &$value  the referenced value to append | ||||||
|      * @param  boolean $merge   flag if array elements shall be merged |      * @param  boolean $merge   flag if array elements shall be merged | ||||||
|      * |      * | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |      * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty | ||||||
|      */ |      */ | ||||||
|     public function appendByRef($tpl_var, &$value, $merge = false) |     public function appendByRef($tpl_var, &$value, $merge = false) | ||||||
|     { |     { | ||||||
|         if ($tpl_var != '' && isset($value)) { |         return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge); | ||||||
|             if (!isset($this->tpl_vars[$tpl_var])) { |  | ||||||
|                 $this->tpl_vars[$tpl_var] = new Smarty_Variable(); |  | ||||||
|             } |  | ||||||
|             if (!is_array($this->tpl_vars[$tpl_var]->value)) { |  | ||||||
|                 settype($this->tpl_vars[$tpl_var]->value, 'array'); |  | ||||||
|             } |  | ||||||
|             if ($merge && is_array($value)) { |  | ||||||
|                 foreach ($value as $_key => $_val) { |  | ||||||
|                     $this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key]; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 $this->tpl_vars[$tpl_var]->value[] = &$value; |  | ||||||
|             } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|         return $this; |     /** | ||||||
|  |      * assigns values to template variables by reference | ||||||
|  |      * | ||||||
|  |      * @param string   $tpl_var the template variable name | ||||||
|  |      * @param          $value | ||||||
|  |      * @param  boolean $nocache if true any output of this variable will be not cached | ||||||
|  |      * | ||||||
|  |      * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty | ||||||
|  |      */ | ||||||
|  |     public function assignByRef($tpl_var, &$value, $nocache = false) | ||||||
|  |     { | ||||||
|  |         return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Returns a single or all template variables |      * Returns a single or all template variables | ||||||
|      * |      * | ||||||
|      * @param  string  $varname        variable name or null |      * @api  Smarty::getTemplateVars() | ||||||
|      * @param  object  $_ptr           optional pointer to data object |      * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl | ||||||
|      * @param  boolean $search_parents include parent templates? |  | ||||||
|      * |      * | ||||||
|      * @return string  variable value or or array of variables |      * @param  string                                                 $varName       variable name or null | ||||||
|  |      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr          optional pointer to data object | ||||||
|  |      * @param  bool                                                   $searchParents include parent templates? | ||||||
|  |      * | ||||||
|  |      * @return mixed variable value or or array of variables | ||||||
|      */ |      */ | ||||||
|     public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) |     public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true) | ||||||
|     { |     { | ||||||
|         if (isset($varname)) { |         return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents); | ||||||
|             $_var = $this->getVariable($varname, $_ptr, $search_parents, false); |     } | ||||||
|             if (is_object($_var)) { |  | ||||||
|                 return $_var->value; |     /** | ||||||
|             } else { |      * Follow the parent chain an merge template and config variables | ||||||
|                 return null; |      * | ||||||
|  |      * @param \Smarty_Internal_Data|null $data | ||||||
|  |      */ | ||||||
|  |     public function _mergeVars(Smarty_Internal_Data $data = null) | ||||||
|  |     { | ||||||
|  |         if (isset($data)) { | ||||||
|  |             if (!empty($this->tpl_vars)) { | ||||||
|  |                 $data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars); | ||||||
|  |             } | ||||||
|  |             if (!empty($this->config_vars)) { | ||||||
|  |                 $data->config_vars = array_merge($this->config_vars, $data->config_vars); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $_result = array(); |             $data = $this; | ||||||
|             if ($_ptr === null) { |  | ||||||
|                 $_ptr = $this; |  | ||||||
|         } |         } | ||||||
|             while ($_ptr !== null) { |         if (isset($this->parent)) { | ||||||
|                 foreach ($_ptr->tpl_vars AS $key => $var) { |             $this->parent->_mergeVars($data); | ||||||
|                     if (!array_key_exists($key, $_result)) { |  | ||||||
|                         $_result[$key] = $var->value; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 // not found, try at parent |  | ||||||
|                 if ($search_parents) { |  | ||||||
|                     $_ptr = $_ptr->parent; |  | ||||||
|                 } else { |  | ||||||
|                     $_ptr = null; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if ($search_parents && isset(Smarty::$global_tpl_vars)) { |  | ||||||
|                 foreach (Smarty::$global_tpl_vars AS $key => $var) { |  | ||||||
|                     if (!array_key_exists($key, $_result)) { |  | ||||||
|                         $_result[$key] = $var->value; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return $_result; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * clear the given assigned template variable. |      * Handle unknown class methods | ||||||
|      * |      * | ||||||
|      * @param  string|array $tpl_var the template variable(s) to clear |      * @param string $name unknown method-name | ||||||
|      * |      * @param array  $args argument array | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function clearAssign($tpl_var) |  | ||||||
|     { |  | ||||||
|         if (is_array($tpl_var)) { |  | ||||||
|             foreach ($tpl_var as $curr_var) { |  | ||||||
|                 unset($this->tpl_vars[$curr_var]); |  | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             unset($this->tpl_vars[$tpl_var]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * clear all the assigned template variables. |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function clearAllAssign() |  | ||||||
|     { |  | ||||||
|         $this->tpl_vars = array(); |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * load a config file, optionally load just selected sections |  | ||||||
|      * |  | ||||||
|      * @param  string $config_file filename |  | ||||||
|      * @param  mixed  $sections    array of section names, single section or null |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function configLoad($config_file, $sections = null) |  | ||||||
|     { |  | ||||||
|         // load Config class |  | ||||||
|         Smarty_Internal_Extension_Config::configLoad($this, $config_file, $sections); |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * gets the object of a Smarty variable |  | ||||||
|      * |  | ||||||
|      * @param  string  $variable       the name of the Smarty variable |  | ||||||
|      * @param  object  $_ptr           optional pointer to data object |  | ||||||
|      * @param  boolean $search_parents search also in parent data |  | ||||||
|      * @param bool     $error_enable |  | ||||||
|      * |  | ||||||
|      * @return object  the object of the variable |  | ||||||
|      */ |  | ||||||
|     public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true) |  | ||||||
|     { |  | ||||||
|         if ($_ptr === null) { |  | ||||||
|             $_ptr = $this; |  | ||||||
|         } |  | ||||||
|         while ($_ptr !== null) { |  | ||||||
|             if (isset($_ptr->tpl_vars[$variable])) { |  | ||||||
|                 // found it, return it |  | ||||||
|                 return $_ptr->tpl_vars[$variable]; |  | ||||||
|             } |  | ||||||
|             // not found, try at parent |  | ||||||
|             if ($search_parents) { |  | ||||||
|                 $_ptr = $_ptr->parent; |  | ||||||
|             } else { |  | ||||||
|                 $_ptr = null; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (isset(Smarty::$global_tpl_vars[$variable])) { |  | ||||||
|             // found it, return it |  | ||||||
|             return Smarty::$global_tpl_vars[$variable]; |  | ||||||
|         } |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if ($smarty->error_unassigned && $error_enable) { |  | ||||||
|             // force a notice |  | ||||||
|             $x = $$variable; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return new Smarty_Undefined_Variable; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * gets  a config variable |  | ||||||
|      * |  | ||||||
|      * @param  string $variable the name of the config variable |  | ||||||
|      * @param bool    $error_enable |  | ||||||
|      * |  | ||||||
|      * @return mixed  the value of the config variable |  | ||||||
|      */ |  | ||||||
|     public function getConfigVariable($variable, $error_enable = true) |  | ||||||
|     { |  | ||||||
|         return Smarty_Internal_Extension_Config::getConfigVariable($this, $variable, $error_enable = true); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Returns a single or all config variables |  | ||||||
|      * |  | ||||||
|      * @param  string $varname variable name or null |  | ||||||
|      * @param bool    $search_parents |  | ||||||
|      * |  | ||||||
|      * @return string variable value or or array of variables |  | ||||||
|      */ |  | ||||||
|     public function getConfigVars($varname = null, $search_parents = true) |  | ||||||
|     { |  | ||||||
|         return Smarty_Internal_Extension_Config::getConfigVars($this, $varname, $search_parents); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Deassigns a single or all config variables |  | ||||||
|      * |  | ||||||
|      * @param  string $varname variable name or null |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function clearConfig($varname = null) |  | ||||||
|     { |  | ||||||
|         return Smarty_Internal_Extension_Config::clearConfig($this, $varname); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * gets  a stream variable |  | ||||||
|      * |  | ||||||
|      * @param  string $variable the stream of the variable |  | ||||||
|      * |      * | ||||||
|  |      * @return mixed | ||||||
|      * @throws SmartyException |      * @throws SmartyException | ||||||
|      * @return mixed  the value of the stream variable |  | ||||||
|      */ |      */ | ||||||
|     public function getStreamVariable($variable) |     public function __call($name, $args) | ||||||
|     { |     { | ||||||
|         $_result = ''; |         return $this->ext->_callExternalMethod($this, $name, $args); | ||||||
|         $fp = fopen($variable, 'r+'); |  | ||||||
|         if ($fp) { |  | ||||||
|             while (!feof($fp) && ($current_line = fgets($fp)) !== false) { |  | ||||||
|                 $_result .= $current_line; |  | ||||||
|             } |  | ||||||
|             fclose($fp); |  | ||||||
|  |  | ||||||
|             return $_result; |  | ||||||
|         } |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if ($smarty->error_unassigned) { |  | ||||||
|             throw new SmartyException('Undefined stream variable "' . $variable . '"'); |  | ||||||
|         } else { |  | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,44 +21,44 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public static $template_data = array(); |     public $template_data = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * List of uid's which shall be ignored |      * List of uid's which shall be ignored | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public static $ignore_uid = array(); |     public $ignore_uid = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Index of display() and fetch() calls |      * Index of display() and fetch() calls | ||||||
|      * |      * | ||||||
|      * @var int |      * @var int | ||||||
|      */ |      */ | ||||||
|     public static $index = 0; |     public $index = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Counter for window offset |      * Counter for window offset | ||||||
|      * |      * | ||||||
|      * @var int |      * @var int | ||||||
|      */ |      */ | ||||||
|     public static $offset = 0; |     public $offset = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Start logging template |      * Start logging template | ||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template template |      * @param \Smarty_Internal_Template $template template | ||||||
|      * @param null                                $mode true: display   false: fetch  null: subtemolate |      * @param null                      $mode     true: display   false: fetch  null: subtemplate | ||||||
|      */ |      */ | ||||||
|     public static function start_template(Smarty_Internal_Template $template, $mode = null) |     public function start_template(Smarty_Internal_Template $template, $mode = null) | ||||||
|     { |     { | ||||||
|         if (isset($mode)) { |         if (isset($mode)) { | ||||||
|             self::$index ++; |             $this->index ++; | ||||||
|             self::$offset ++; |             $this->offset ++; | ||||||
|             self::$template_data[self::$index] = null; |             $this->template_data[$this->index] = null; | ||||||
|         } |         } | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['start_template_time'] = microtime(true); |         $this->template_data[$this->index][$key]['start_template_time'] = microtime(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -66,11 +66,12 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template cached template |      * @param \Smarty_Internal_Template $template cached template | ||||||
|      */ |      */ | ||||||
|     public static function end_template(Smarty_Internal_Template $template) |     public function end_template(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['total_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_template_time']; |         $this->template_data[$this->index][$key]['total_time'] += | ||||||
|         self::$template_data[self::$index][$key]['properties'] = $template->properties; |             microtime(true) - $this->template_data[$this->index][$key]['start_template_time']; | ||||||
|  |         //$this->template_data[$this->index][$key]['properties'] = $template->properties; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -78,28 +79,29 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template |      * @param \Smarty_Internal_Template $template | ||||||
|      */ |      */ | ||||||
|     public static function start_compile(Smarty_Internal_Template $template) |     public function start_compile(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         static $_is_stringy = array('string' => true, 'eval' => true); |         static $_is_stringy = array('string' => true, 'eval' => true); | ||||||
|         if (!empty($template->compiler->trace_uid)) { |         if (!empty($template->compiler->trace_uid)) { | ||||||
|             $key = $template->compiler->trace_uid; |             $key = $template->compiler->trace_uid; | ||||||
|             if (!isset(self::$template_data[self::$index][$key])) { |             if (!isset($this->template_data[$this->index][$key])) { | ||||||
|                 if (isset($_is_stringy[$template->source->type])) { |                 if (isset($_is_stringy[$template->source->type])) { | ||||||
|                     self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; |                     $this->template_data[$this->index][$key]['name'] = | ||||||
|  |                         '\'' . substr($template->source->name, 0, 25) . '...\''; | ||||||
|                 } else { |                 } else { | ||||||
|                     self::$template_data[self::$index][$key]['name'] = $template->source->filepath; |                     $this->template_data[$this->index][$key]['name'] = $template->source->filepath; | ||||||
|                 } |                 } | ||||||
|                 self::$template_data[self::$index][$key]['compile_time'] = 0; |                 $this->template_data[$this->index][$key]['compile_time'] = 0; | ||||||
|                 self::$template_data[self::$index][$key]['render_time'] = 0; |                 $this->template_data[$this->index][$key]['render_time'] = 0; | ||||||
|                 self::$template_data[self::$index][$key]['cache_time'] = 0; |                 $this->template_data[$this->index][$key]['cache_time'] = 0; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             if (isset(self::$ignore_uid[$template->source->uid])) { |             if (isset($this->ignore_uid[$template->source->uid])) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             $key = self::get_key($template); |             $key = $this->get_key($template); | ||||||
|         } |         } | ||||||
|         self::$template_data[self::$index][$key]['start_time'] = microtime(true); |         $this->template_data[$this->index][$key]['start_time'] = microtime(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -107,18 +109,19 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template |      * @param \Smarty_Internal_Template $template | ||||||
|      */ |      */ | ||||||
|     public static function end_compile(Smarty_Internal_Template $template) |     public function end_compile(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         if (!empty($template->compiler->trace_uid)) { |         if (!empty($template->compiler->trace_uid)) { | ||||||
|             $key = $template->compiler->trace_uid; |             $key = $template->compiler->trace_uid; | ||||||
|         } else { |         } else { | ||||||
|             if (isset(self::$ignore_uid[$template->source->uid])) { |             if (isset($this->ignore_uid[$template->source->uid])) { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             $key = self::get_key($template); |             $key = $this->get_key($template); | ||||||
|         } |         } | ||||||
|         self::$template_data[self::$index][$key]['compile_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; |         $this->template_data[$this->index][$key]['compile_time'] += | ||||||
|  |             microtime(true) - $this->template_data[$this->index][$key]['start_time']; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -126,10 +129,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template |      * @param \Smarty_Internal_Template $template | ||||||
|      */ |      */ | ||||||
|     public static function start_render(Smarty_Internal_Template $template) |     public function start_render(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['start_time'] = microtime(true); |         $this->template_data[$this->index][$key]['start_time'] = microtime(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -137,10 +140,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template |      * @param \Smarty_Internal_Template $template | ||||||
|      */ |      */ | ||||||
|     public static function end_render(Smarty_Internal_Template $template) |     public function end_render(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['render_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; |         $this->template_data[$this->index][$key]['render_time'] += | ||||||
|  |             microtime(true) - $this->template_data[$this->index][$key]['start_time']; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -148,10 +152,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template cached template |      * @param \Smarty_Internal_Template $template cached template | ||||||
|      */ |      */ | ||||||
|     public static function start_cache(Smarty_Internal_Template $template) |     public function start_cache(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['start_time'] = microtime(true); |         $this->template_data[$this->index][$key]['start_time'] = microtime(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -159,10 +163,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template cached template |      * @param \Smarty_Internal_Template $template cached template | ||||||
|      */ |      */ | ||||||
|     public static function end_cache(Smarty_Internal_Template $template) |     public function end_cache(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         $key = self::get_key($template); |         $key = $this->get_key($template); | ||||||
|         self::$template_data[self::$index][$key]['cache_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time']; |         $this->template_data[$this->index][$key]['cache_time'] += | ||||||
|  |             microtime(true) - $this->template_data[$this->index][$key]['start_time']; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -170,7 +175,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template cached template |      * @param \Smarty_Internal_Template $template cached template | ||||||
|      */ |      */ | ||||||
|     public static function register_template(Smarty_Internal_Template $template) |     public function register_template(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -189,14 +194,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * @param Smarty_Internal_Template|Smarty $obj object to debug |      * @param Smarty_Internal_Template|Smarty $obj object to debug | ||||||
|      * @param bool                            $full |      * @param bool                            $full | ||||||
|      */ |      */ | ||||||
|     public static function display_debug($obj, $full = false) |     public function display_debug($obj, $full = false) | ||||||
|     { |     { | ||||||
|         if (!$full) { |         if (!$full) { | ||||||
|             self::$offset ++; |             $this->offset ++; | ||||||
|             $savedIndex = self::$index; |             $savedIndex = $this->index; | ||||||
|             self::$index = 9999; |             $this->index = 9999; | ||||||
|         } |         } | ||||||
|         if ($obj instanceof Smarty) { |         if ($obj->_objType == 1) { | ||||||
|             $smarty = $obj; |             $smarty = $obj; | ||||||
|         } else { |         } else { | ||||||
|             $smarty = $obj->smarty; |             $smarty = $obj->smarty; | ||||||
| @@ -227,7 +232,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|         $debObj->compile_id = null; |         $debObj->compile_id = null; | ||||||
|         $debObj->cache_id = null; |         $debObj->cache_id = null; | ||||||
|         // prepare information of assigned variables |         // prepare information of assigned variables | ||||||
|         $ptr = self::get_debug_vars($obj); |         $ptr = $this->get_debug_vars($obj); | ||||||
|         $_assigned_vars = $ptr->tpl_vars; |         $_assigned_vars = $ptr->tpl_vars; | ||||||
|         ksort($_assigned_vars); |         ksort($_assigned_vars); | ||||||
|         $_config_vars = $ptr->config_vars; |         $_config_vars = $ptr->config_vars; | ||||||
| @@ -235,11 +240,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|         $debugging = $smarty->debugging; |         $debugging = $smarty->debugging; | ||||||
|  |  | ||||||
|         $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); |         $_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj); | ||||||
|         if ($obj instanceof Smarty_Internal_Template) { |         if ($obj->_objType == 2) { | ||||||
|             $_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); |             $_template->assign('template_name', $obj->source->type . ':' . $obj->source->name); | ||||||
|         } |         } | ||||||
|         if ($obj instanceof Smarty || $full) { |         if ($obj->_objType == 1 || $full) { | ||||||
|             $_template->assign('template_data', self::$template_data[self::$index]); |             $_template->assign('template_data', $this->template_data[$this->index]); | ||||||
|         } else { |         } else { | ||||||
|             $_template->assign('template_data', null); |             $_template->assign('template_data', null); | ||||||
|         } |         } | ||||||
| @@ -247,13 +252,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|         $_template->assign('config_vars', $_config_vars); |         $_template->assign('config_vars', $_config_vars); | ||||||
|         $_template->assign('execution_time', microtime(true) - $smarty->start_time); |         $_template->assign('execution_time', microtime(true) - $smarty->start_time); | ||||||
|         $_template->assign('display_mode', $debugging == 2 || !$full); |         $_template->assign('display_mode', $debugging == 2 || !$full); | ||||||
|         $_template->assign('offset', self::$offset * 50); |         $_template->assign('offset', $this->offset * 50); | ||||||
|         echo $_template->fetch(); |         echo $_template->fetch(); | ||||||
|         if (isset($full)) { |         if (isset($full)) { | ||||||
|             self::$index --; |             $this->index --; | ||||||
|         } |         } | ||||||
|         if (!$full) { |         if (!$full) { | ||||||
|             self::$index = $savedIndex; |             $this->index = $savedIndex; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -264,14 +269,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @return StdClass |      * @return StdClass | ||||||
|      */ |      */ | ||||||
|     public static function get_debug_vars($obj) |     public function get_debug_vars($obj) | ||||||
|     { |     { | ||||||
|         $config_vars = array(); |         $config_vars = array(); | ||||||
|         foreach ($obj->config_vars as $key => $var) { |         foreach ($obj->config_vars as $key => $var) { | ||||||
|             $config_vars[$key]['value'] = $var; |             $config_vars[$key]['value'] = $var; | ||||||
|             if ($obj instanceof Smarty_Internal_Template) { |             if ($obj->_objType == 2) { | ||||||
|                 $config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; |                 $config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; | ||||||
|             } elseif ($obj instanceof Smarty_Data) { |             } elseif ($obj->_objType == 4) { | ||||||
|                 $tpl_vars[$key]['scope'] = $obj->dataObjectName; |                 $tpl_vars[$key]['scope'] = $obj->dataObjectName; | ||||||
|             } else { |             } else { | ||||||
|                 $config_vars[$key]['scope'] = 'Smarty object'; |                 $config_vars[$key]['scope'] = 'Smarty object'; | ||||||
| @@ -294,9 +299,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if ($obj instanceof Smarty_Internal_Template) { |             if ($obj->_objType == 2) { | ||||||
|                 $tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; |                 $tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name; | ||||||
|             } elseif ($obj instanceof Smarty_Data) { |             } elseif ($obj->_objType == 4) { | ||||||
|                 $tpl_vars[$key]['scope'] = $obj->dataObjectName; |                 $tpl_vars[$key]['scope'] = $obj->dataObjectName; | ||||||
|             } else { |             } else { | ||||||
|                 $tpl_vars[$key]['scope'] = 'Smarty object'; |                 $tpl_vars[$key]['scope'] = 'Smarty object'; | ||||||
| @@ -304,7 +309,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (isset($obj->parent)) { |         if (isset($obj->parent)) { | ||||||
|             $parent = self::get_debug_vars($obj->parent); |             $parent = $this->get_debug_vars($obj->parent); | ||||||
|             foreach ($parent->tpl_vars as $name => $pvar) { |             foreach ($parent->tpl_vars as $name => $pvar) { | ||||||
|                 if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) { |                 if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) { | ||||||
|                     $tpl_vars[$name]['scope'] = $pvar['scope']; |                     $tpl_vars[$name]['scope'] = $pvar['scope']; | ||||||
| @@ -351,7 +356,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @return string key into $template_data |      * @return string key into $template_data | ||||||
|      */ |      */ | ||||||
|     private static function get_key(Smarty_Internal_Template $template) |     private function get_key(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         static $_is_stringy = array('string' => true, 'eval' => true); |         static $_is_stringy = array('string' => true, 'eval' => true); | ||||||
|         // calculate Uid if not already done |         // calculate Uid if not already done | ||||||
| @@ -359,18 +364,19 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|             $template->source->filepath; |             $template->source->filepath; | ||||||
|         } |         } | ||||||
|         $key = $template->source->uid; |         $key = $template->source->uid; | ||||||
|         if (isset(self::$template_data[self::$index][$key])) { |         if (isset($this->template_data[$this->index][$key])) { | ||||||
|             return $key; |             return $key; | ||||||
|         } else { |         } else { | ||||||
|             if (isset($_is_stringy[$template->source->type])) { |             if (isset($_is_stringy[$template->source->type])) { | ||||||
|                 self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\''; |                 $this->template_data[$this->index][$key]['name'] = | ||||||
|  |                     '\'' . substr($template->source->name, 0, 25) . '...\''; | ||||||
|             } else { |             } else { | ||||||
|                 self::$template_data[self::$index][$key]['name'] = $template->source->filepath; |                 $this->template_data[$this->index][$key]['name'] = $template->source->filepath; | ||||||
|             } |             } | ||||||
|             self::$template_data[self::$index][$key]['compile_time'] = 0; |             $this->template_data[$this->index][$key]['compile_time'] = 0; | ||||||
|             self::$template_data[self::$index][$key]['render_time'] = 0; |             $this->template_data[$this->index][$key]['render_time'] = 0; | ||||||
|             self::$template_data[self::$index][$key]['cache_time'] = 0; |             $this->template_data[$this->index][$key]['cache_time'] = 0; | ||||||
|             self::$template_data[self::$index][$key]['total_time'] = 0; |             $this->template_data[$this->index][$key]['total_time'] = 0; | ||||||
|  |  | ||||||
|             return $key; |             return $key; | ||||||
|         } |         } | ||||||
| @@ -381,13 +387,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param \Smarty_Internal_Template $template |      * @param \Smarty_Internal_Template $template | ||||||
|      */ |      */ | ||||||
|     public static function ignore(Smarty_Internal_Template $template) |     public function ignore(Smarty_Internal_Template $template) | ||||||
|     { |     { | ||||||
|         // calculate Uid if not already done |         // calculate Uid if not already done | ||||||
|         if ($template->source->uid == '') { |         if ($template->source->uid == '') { | ||||||
|             $template->source->filepath; |             $template->source->filepath; | ||||||
|         } |         } | ||||||
|         self::$ignore_uid[$template->source->uid] = true; |         $this->ignore_uid[$template->source->uid] = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -395,7 +401,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data | |||||||
|      * |      * | ||||||
|      * @param Smarty_Internal_Template $_template |      * @param Smarty_Internal_Template $_template | ||||||
|      */ |      */ | ||||||
|     public static function debugUrl(Smarty_Internal_Template $_template) |     public function debugUrl(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         if (isset($_SERVER['QUERY_STRING'])) { |         if (isset($_SERVER['QUERY_STRING'])) { | ||||||
|             $_query_string = $_SERVER['QUERY_STRING']; |             $_query_string = $_SERVER['QUERY_STRING']; | ||||||
|   | |||||||
| @@ -1,127 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Extension |  | ||||||
|  * This file contains the Smarty template extension to create a code frame |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage Template |  | ||||||
|  * @author     Uwe Tews |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Class Smarty_Internal_Extension_CodeFrame |  | ||||||
|  * Create code frame for compiled and cached templates |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Extension_CodeFrame |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * Create code frame for compiled and cached templates |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template |  | ||||||
|      * @param  string                  $content optional template content |  | ||||||
|      * @param  bool                    $cache   flag for cache file |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      */ |  | ||||||
|     public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false) |  | ||||||
|     { |  | ||||||
|         // build property code |  | ||||||
|         $_template->properties['has_nocache_code'] = $_template->has_nocache_code || !empty($_template->required_plugins['nocache']); |  | ||||||
|         $_template->properties['version'] = Smarty::SMARTY_VERSION; |  | ||||||
|         if (!isset($_template->properties['unifunc'])) { |  | ||||||
|             $_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); |  | ||||||
|         } |  | ||||||
|         $properties = $_template->properties; |  | ||||||
|         if (!$cache) { |  | ||||||
|             unset($properties['tpl_function']); |  | ||||||
|             if (!empty($_template->compiler->templateProperties)) { |  | ||||||
|                 $properties['tpl_function'] = $_template->compiler->templateProperties['tpl_function']; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $output = "<?php\n"; |  | ||||||
|         $output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n"; |  | ||||||
|         if ($_template->smarty->direct_access_security) { |  | ||||||
|             $output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n"; |  | ||||||
|         } |  | ||||||
|         $output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ");\n"; |  | ||||||
|         $output .= "/*/%%SmartyHeaderCode%%*/\n"; |  | ||||||
|         $output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n"; |  | ||||||
|         $output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n"; |  | ||||||
|         // include code for plugins |  | ||||||
|         if (!$cache) { |  | ||||||
|             if (!empty($_template->required_plugins['compiled'])) { |  | ||||||
|                 foreach ($_template->required_plugins['compiled'] as $tmp) { |  | ||||||
|                     foreach ($tmp as $data) { |  | ||||||
|                         $file = addslashes($data['file']); |  | ||||||
|                         if (is_Array($data['function'])) { |  | ||||||
|                             $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n"; |  | ||||||
|                         } else { |  | ||||||
|                             $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n"; |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if (!empty($_template->required_plugins['nocache'])) { |  | ||||||
|                 $_template->has_nocache_code = true; |  | ||||||
|                 $output .= "echo '/*%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; "; |  | ||||||
|                 foreach ($_template->required_plugins['nocache'] as $tmp) { |  | ||||||
|                     foreach ($tmp as $data) { |  | ||||||
|                         $file = addslashes($data['file']); |  | ||||||
|                         if (is_Array($data['function'])) { |  | ||||||
|                             $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n"); |  | ||||||
|                         } else { |  | ||||||
|                             $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n"); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|                 $output .= "?>/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/';\n"; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $output .= "?>\n"; |  | ||||||
|         $output = self::appendCode($output, $content); |  | ||||||
|         return self::appendCode($output, "<?php }\n}\n?>"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Create code frame of compiled template function |  | ||||||
|      * |  | ||||||
|      * @param \Smarty_Internal_Template $_template |  | ||||||
|      * @param string                    $content |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      */ |  | ||||||
|     public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '') |  | ||||||
|     { |  | ||||||
|         if (!isset($_template->properties['unifunc'])) { |  | ||||||
|             $_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); |  | ||||||
|         } |  | ||||||
|         $output = "<?php\n"; |  | ||||||
|         $output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n"; |  | ||||||
|         $output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n"; |  | ||||||
|         $output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n"; |  | ||||||
|         $output .= "?>\n" . $content; |  | ||||||
|         $output .= "<?php\n"; |  | ||||||
|         $output .= "/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/\n"; |  | ||||||
|         $output .= "}\n}\n?>"; |  | ||||||
|         return $output; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Append code segments and remove unneeded ?> <?php transitions |  | ||||||
|      * |  | ||||||
|      * @param string $left |  | ||||||
|      * @param string $right |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      */ |  | ||||||
|     public static function appendCode($left, $right) |  | ||||||
|     { |  | ||||||
|         if (preg_match('/\s*\?>$/', $left) && preg_match('/^<\?php\s+/', $right)) { |  | ||||||
|             $left = preg_replace('/\s*\?>$/', "\n", $left); |  | ||||||
|             $left .= preg_replace('/^<\?php\s+/', '', $right); |  | ||||||
|         } else { |  | ||||||
|             $left .= $right; |  | ||||||
|         } |  | ||||||
|         return $left; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,160 +0,0 @@ | |||||||
| <?php |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Extension_Config |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * @param        $obj |  | ||||||
|      * @param        $config_file |  | ||||||
|      * @param null   $sections |  | ||||||
|      * @param string $scope |  | ||||||
|      */ |  | ||||||
|     static function configLoad($obj, $config_file, $sections = null, $scope = 'local') |  | ||||||
|     { |  | ||||||
|         $smarty = isset($obj->smarty) ? $obj->smarty : $obj; |  | ||||||
|         $confObj = new $smarty->template_class($config_file, $smarty, $obj); |  | ||||||
|         $confObj->caching = Smarty::CACHING_OFF; |  | ||||||
|         $confObj->source = Smarty_Template_Config::load($confObj); |  | ||||||
|         $confObj->source->config_sections = $sections; |  | ||||||
|         $confObj->source->scope = $scope; |  | ||||||
|         $confObj->compiled = Smarty_Template_Compiled::load($confObj); |  | ||||||
|         if ($confObj->smarty->debugging) { |  | ||||||
|             Smarty_Internal_Debug::start_render($confObj); |  | ||||||
|         } |  | ||||||
|         $confObj->compiled->render($confObj); |  | ||||||
|         if ($confObj->smarty->debugging) { |  | ||||||
|             Smarty_Internal_Debug::end_render($confObj); |  | ||||||
|         } |  | ||||||
|         if ($obj instanceof Smarty_Internal_Template) { |  | ||||||
|             $obj->properties['file_dependency'][$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->timestamp, $confObj->source->type); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * load config variables |  | ||||||
|      * |  | ||||||
|      * @param mixed  $sections array of section names, single section or null |  | ||||||
|      * @param string $scope    global,parent or local |  | ||||||
|      * |  | ||||||
|      * @throws Exception |  | ||||||
|      */ |  | ||||||
|     static function loadConfigVars($_template, $_config_vars) |  | ||||||
|     { |  | ||||||
|         $scope = $_template->source->scope; |  | ||||||
|         // pointer to scope (local scope is parent of template object |  | ||||||
|         $scope_ptr = $_template->parent; |  | ||||||
|         if ($scope == 'parent') { |  | ||||||
|             if (isset($_template->parent->parent)) { |  | ||||||
|                 $scope_ptr = $_template->parent->parent; |  | ||||||
|             } |  | ||||||
|         } elseif ($scope == 'root' || $scope == 'global') { |  | ||||||
|             while (isset($scope_ptr->parent)) { |  | ||||||
|                 $scope_ptr = $scope_ptr->parent; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // copy global config vars |  | ||||||
|         foreach ($_config_vars['vars'] as $variable => $value) { |  | ||||||
|             if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { |  | ||||||
|                 $scope_ptr->config_vars[$variable] = $value; |  | ||||||
|             } else { |  | ||||||
|                 $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // scan sections |  | ||||||
|         $sections = $_template->source->config_sections; |  | ||||||
|         if (!empty($sections)) { |  | ||||||
|             foreach ((array) $sections as $_template_section) { |  | ||||||
|                 if (isset($_config_vars['sections'][$_template_section])) { |  | ||||||
|                     foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) { |  | ||||||
|                         if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) { |  | ||||||
|                             $scope_ptr->config_vars[$variable] = $value; |  | ||||||
|                         } else { |  | ||||||
|                             $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Returns a single or all config variables |  | ||||||
|      * |  | ||||||
|      * @param  string $varname variable name or null |  | ||||||
|      * @param bool    $search_parents |  | ||||||
|      * |  | ||||||
|      * @return string variable value or or array of variables |  | ||||||
|      */ |  | ||||||
|     static function getConfigVars($obj, $varname = null, $search_parents = true) |  | ||||||
|     { |  | ||||||
|         $_ptr = $obj; |  | ||||||
|         $var_array = array(); |  | ||||||
|         while ($_ptr !== null) { |  | ||||||
|             if (isset($varname)) { |  | ||||||
|                 if (isset($_ptr->config_vars[$varname])) { |  | ||||||
|                     return $_ptr->config_vars[$varname]; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 $var_array = array_merge($_ptr->config_vars, $var_array); |  | ||||||
|             } |  | ||||||
|             // not found, try at parent |  | ||||||
|             if ($search_parents) { |  | ||||||
|                 $_ptr = $_ptr->parent; |  | ||||||
|             } else { |  | ||||||
|                 $_ptr = null; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (isset($varname)) { |  | ||||||
|             return ''; |  | ||||||
|         } else { |  | ||||||
|             return $var_array; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * gets  a config variable |  | ||||||
|      * |  | ||||||
|      * @param  string $variable the name of the config variable |  | ||||||
|      * @param bool    $error_enable |  | ||||||
|      * |  | ||||||
|      * @return mixed  the value of the config variable |  | ||||||
|      */ |  | ||||||
|     static function getConfigVariable($obj, $variable, $error_enable = true) |  | ||||||
|     { |  | ||||||
|         $_ptr = $obj; |  | ||||||
|         while ($_ptr !== null) { |  | ||||||
|             if (isset($_ptr->config_vars[$variable])) { |  | ||||||
|                 // found it, return it |  | ||||||
|                 return $_ptr->config_vars[$variable]; |  | ||||||
|             } |  | ||||||
|             // not found, try at parent |  | ||||||
|             $_ptr = $_ptr->parent; |  | ||||||
|         } |  | ||||||
|         if ($obj->error_unassigned && $error_enable) { |  | ||||||
|             // force a notice |  | ||||||
|             $x = $$variable; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * remove a single or all config variables |  | ||||||
|      * |  | ||||||
|      * @param  string $name variable name or null |  | ||||||
|      * |  | ||||||
|      * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     static function clearConfig($obj, $name = null) |  | ||||||
|     { |  | ||||||
|         if (isset($name)) { |  | ||||||
|             unset($obj->config_vars[$name]); |  | ||||||
|         } else { |  | ||||||
|             $obj->config_vars = array(); |  | ||||||
|         } |  | ||||||
|         return $obj; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,85 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty Resource Extension |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage TemplateResources |  | ||||||
|  * @author     Uwe Tews |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Smarty Resource Extension |  | ||||||
|  * Default template and config file handling |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage TemplateResources |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Extension_DefaultTemplateHandler |  | ||||||
| { |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * get default content from template of config resource handler |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template        $_template |  | ||||||
|      * @param Smarty_Internal_Template_Source $source |  | ||||||
|      * @param  Smarty_Resource                $resObj |  | ||||||
|      */ |  | ||||||
|     static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj) |  | ||||||
|     { |  | ||||||
|         if ($source->isConfig) { |  | ||||||
|             $default_handler = $_template->smarty->default_config_handler_func; |  | ||||||
|         } else { |  | ||||||
|             $default_handler = $_template->smarty->default_template_handler_func; |  | ||||||
|         } |  | ||||||
|         $_content = $_timestamp = null; |  | ||||||
|         $_return = call_user_func_array($default_handler, |  | ||||||
|                                         array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)); |  | ||||||
|         if (is_string($_return)) { |  | ||||||
|             $source->exists = is_file($_return); |  | ||||||
|             if ($source->exists) { |  | ||||||
|                 $source->timestamp = filemtime($_return); |  | ||||||
|             } |  | ||||||
|             $source->filepath = $_return; |  | ||||||
|         } elseif ($_return === true) { |  | ||||||
|             $source->content = $_content; |  | ||||||
|             $source->timestamp = $_timestamp; |  | ||||||
|             $source->exists = true; |  | ||||||
|             $source->recompiled = true; |  | ||||||
|             $source->filepath = false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * register template default handler |  | ||||||
|      * |  | ||||||
|      * @param Smarty $smarty |  | ||||||
|      * @param mixed  $callback |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      */ |  | ||||||
|     static function registerDefaultTemplateHandler(Smarty $smarty, $callback) |  | ||||||
|     { |  | ||||||
|         if (is_callable($callback)) { |  | ||||||
|             $smarty->default_template_handler_func = $callback; |  | ||||||
|         } else { |  | ||||||
|             throw new SmartyException("Default template handler not callable"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * register config default handler |  | ||||||
|      * |  | ||||||
|      * @param Smarty $smarty |  | ||||||
|      * @param mixed  $callback |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      */ |  | ||||||
|     static function registerDefaultConfigHandler(Smarty $smarty, $callback) |  | ||||||
|     { |  | ||||||
|         if (is_callable($callback)) { |  | ||||||
|             $smarty->default_config_handler_func = $callback; |  | ||||||
|         } else { |  | ||||||
|             throw new SmartyException("Default config handler not callable"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,67 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Plugin Filter Handler |  | ||||||
|  * Smarty filter handler class |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  * @author     Uwe Tews |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Class for filter processing |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Filter_Handler |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * Run filters over content |  | ||||||
|      * The filters will be lazy loaded if required |  | ||||||
|      * class name format: Smarty_FilterType_FilterName |  | ||||||
|      * plugin filename format: filtertype.filtername.php |  | ||||||
|      * Smarty2 filter plugins could be used |  | ||||||
|      * |  | ||||||
|      * @param  string                   $type     the type of filter ('pre','post','output') which shall run |  | ||||||
|      * @param  string                   $content  the content which shall be processed by the filters |  | ||||||
|      * @param  Smarty_Internal_Template $template template object |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return string                   the filtered content |  | ||||||
|      */ |  | ||||||
|     public static function runFilter($type, $content, Smarty_Internal_Template $template) |  | ||||||
|     { |  | ||||||
|         $output = $content; |  | ||||||
|         // loop over autoload filters of specified type |  | ||||||
|         if (!empty($template->smarty->autoload_filters[$type])) { |  | ||||||
|             foreach ((array) $template->smarty->autoload_filters[$type] as $name) { |  | ||||||
|                 $plugin_name = "Smarty_{$type}filter_{$name}"; |  | ||||||
|                 if ($template->smarty->loadPlugin($plugin_name)) { |  | ||||||
|                     if (function_exists($plugin_name)) { |  | ||||||
|                         // use loaded Smarty2 style plugin |  | ||||||
|                         $output = $plugin_name($output, $template); |  | ||||||
|                     } elseif (class_exists($plugin_name, false)) { |  | ||||||
|                         // loaded class of filter plugin |  | ||||||
|                         $output = call_user_func(array($plugin_name, 'execute'), $output, $template); |  | ||||||
|                     } |  | ||||||
|                 } else { |  | ||||||
|                     // nothing found, throw exception |  | ||||||
|                     throw new SmartyException("Unable to load filter {$plugin_name}"); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // loop over registerd filters of specified type |  | ||||||
|         if (!empty($template->smarty->registered_filters[$type])) { |  | ||||||
|             foreach ($template->smarty->registered_filters[$type] as $key => $name) { |  | ||||||
|                 if (is_array($template->smarty->registered_filters[$type][$key])) { |  | ||||||
|                     $output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template); |  | ||||||
|                 } else { |  | ||||||
|                     $output = $template->smarty->registered_filters[$type][$key]($output, $template); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // return filtered output |  | ||||||
|         return $output; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,71 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Plugin Function Call Handler |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  * @author     Uwe Tews |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * This class does handles template functions defined with the {function} tag missing in cache file. |  | ||||||
|  * It can happen when the template function was called with the nocache option or within a nocache section. |  | ||||||
|  * The template function will be loaded from it's compiled template file, executed and added to the cache file |  | ||||||
|  * for later use. |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Function_Call_Handler |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * This function handles calls to template functions defined by {function} |  | ||||||
|      * It does create a PHP function at the first call |  | ||||||
|      * |  | ||||||
|      * @param string                   $_name     template function name |  | ||||||
|      * @param Smarty_Internal_Template $_smarty_tpl |  | ||||||
|      * @param string                   $_function PHP function name |  | ||||||
|      * @param array                    $_params   Smarty variables passed as call parameter |  | ||||||
|      * @param bool                     $_nocache  nocache flag |  | ||||||
|      * |  | ||||||
|      * @return bool |  | ||||||
|      */ |  | ||||||
|     public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache) |  | ||||||
|     { |  | ||||||
|         $funcParam = $_smarty_tpl->properties['tpl_function'][$_name]; |  | ||||||
|         if (is_file($funcParam['compiled_filepath'])) { |  | ||||||
|             // read compiled file |  | ||||||
|             $code = file_get_contents($funcParam['compiled_filepath']); |  | ||||||
|             // grab template function |  | ||||||
|             if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) { |  | ||||||
|                 // grab source info from file dependency |  | ||||||
|                 preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1); |  | ||||||
|                 unset($code); |  | ||||||
|                 $output = ''; |  | ||||||
|                 // make PHP function known |  | ||||||
|                 eval($match[0]); |  | ||||||
|                 if (function_exists($_function)) { |  | ||||||
|                     // search cache file template |  | ||||||
|                     $tplPtr = $_smarty_tpl; |  | ||||||
|                     while (!isset($tplPtr->cached) && isset($tplPtr->parent)) { |  | ||||||
|                         $tplPtr = $tplPtr->parent; |  | ||||||
|                     } |  | ||||||
|                     // add template function code to cache file |  | ||||||
|                     if (isset($tplPtr->cached)) { |  | ||||||
|                         $cache = $tplPtr->cached; |  | ||||||
|                         $content = $cache->read($tplPtr); |  | ||||||
|                         if ($content) { |  | ||||||
|                             // check if we must update file dependency |  | ||||||
|                             if (!preg_match("/'{$funcParam['uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) { |  | ||||||
|                                 $content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content); |  | ||||||
|                             } |  | ||||||
|                             $cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n"); |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                     return true; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,46 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty read include path plugin |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  * @author     Monte Ohrt |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Read Include Path Class |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Get_Include_Path |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * Return full file path from PHP include_path |  | ||||||
|      * |  | ||||||
|      * @param  string $filepath filepath |  | ||||||
|      * |  | ||||||
|      * @return string|boolean full filepath or false |  | ||||||
|      */ |  | ||||||
|     public static function getIncludePath($filepath) |  | ||||||
|     { |  | ||||||
|         static $_include_path = null; |  | ||||||
|  |  | ||||||
|         if (function_exists('stream_resolve_include_path')) { |  | ||||||
|             // available since PHP 5.3.2 |  | ||||||
|             return stream_resolve_include_path($filepath); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if ($_include_path === null) { |  | ||||||
|             $_include_path = explode(PATH_SEPARATOR, get_include_path()); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         foreach ($_include_path as $_path) { |  | ||||||
|             if (file_exists($_path . DS . $filepath)) { |  | ||||||
|                 return $_path . DS . $filepath; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -42,10 +42,10 @@ class Smarty_Internal_Nocache_Insert | |||||||
|             $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; |             $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>"; | ||||||
|         } |         } | ||||||
|         $_tpl = $_template; |         $_tpl = $_template; | ||||||
|         while ($_tpl->parent instanceof Smarty_Internal_Template) { |         while (isset($_tpl->parent) && $_tpl->parent->_objType == 2) { | ||||||
|             $_tpl = $_tpl->parent; |             $_tpl = $_tpl->parent; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/"; |         return "/*%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/"; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -17,13 +17,6 @@ | |||||||
| abstract class Smarty_Internal_ParseTree | abstract class Smarty_Internal_ParseTree | ||||||
| { | { | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Parser object |  | ||||||
|      * |  | ||||||
|      * @var object |  | ||||||
|      */ |  | ||||||
|     public $parser; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Buffer content |      * Buffer content | ||||||
|      * |      * | ||||||
| @@ -41,9 +34,21 @@ abstract class Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Return buffer |      * Return buffer | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string buffer content |      * @return string buffer content | ||||||
|      */ |      */ | ||||||
|     abstract public function to_smarty_php(); |     abstract public function to_smarty_php(Smarty_Internal_Templateparser $parser); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Template data object destructor | ||||||
|  |      */ | ||||||
|  |     public function __destruct() | ||||||
|  |     { | ||||||
|  |         $this->data = null; | ||||||
|  |         $this->subtrees = null; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Create parse tree buffer for code fragment |      * Create parse tree buffer for code fragment | ||||||
|      * |      * | ||||||
|      * @param object $parser parser object |  | ||||||
|      * @param string $data content |      * @param string $data content | ||||||
|      */ |      */ | ||||||
|     public function __construct($parser, $data) |     public function __construct($data) | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|         $this->data = $data; |         $this->data = $data; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Return buffer content in parentheses |      * Return buffer content in parentheses | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string content |      * @return string content | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         return sprintf("(%s)", $this->data); |         return sprintf("(%s)", $this->data); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -25,43 +25,45 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree | |||||||
|      */ |      */ | ||||||
|     public function __construct($parser, Smarty_Internal_ParseTree $subtree) |     public function __construct($parser, Smarty_Internal_ParseTree $subtree) | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|         $this->subtrees[] = $subtree; |         $this->subtrees[] = $subtree; | ||||||
|         if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |         if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { | ||||||
|             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); |             $parser->block_nesting_level = count($parser->compiler->_tag_stack); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Append buffer to subtree |      * Append buffer to subtree | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|      * @param Smarty_Internal_ParseTree       $subtree parse tree buffer |      * @param Smarty_Internal_ParseTree       $subtree parse tree buffer | ||||||
|      */ |      */ | ||||||
|     public function append_subtree(Smarty_Internal_ParseTree $subtree) |     public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree) | ||||||
|     { |     { | ||||||
|         $last_subtree = count($this->subtrees) - 1; |         $last_subtree = count($this->subtrees) - 1; | ||||||
|         if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) { |         if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $parser->block_nesting_level) { | ||||||
|             if ($subtree instanceof Smarty_Internal_ParseTree_Code) { |             if ($subtree instanceof Smarty_Internal_ParseTree_Code) { | ||||||
|                 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>'); |                 $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>'); | ||||||
|             } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) { |             } elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) { | ||||||
|                 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>'); |                 $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>'); | ||||||
|             } else { |             } else { | ||||||
|                 $this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data); |                 $this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $this->subtrees[] = $subtree; |             $this->subtrees[] = $subtree; | ||||||
|         } |         } | ||||||
|         if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |         if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { | ||||||
|             $this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack); |             $parser->block_nesting_level = count($parser->compiler->_tag_stack); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Merge subtree buffer content together |      * Merge subtree buffer content together | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string compiled template code |      * @return string compiled template code | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         $code = ''; |         $code = ''; | ||||||
|         foreach ($this->subtrees as $subtree) { |         foreach ($this->subtrees as $subtree) { | ||||||
| @@ -69,15 +71,15 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree | |||||||
|                 $code .= "."; |                 $code .= "."; | ||||||
|             } |             } | ||||||
|             if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { |             if ($subtree instanceof Smarty_Internal_ParseTree_Tag) { | ||||||
|                 $more_php = $subtree->assign_to_var(); |                 $more_php = $subtree->assign_to_var($parser); | ||||||
|             } else { |             } else { | ||||||
|                 $more_php = $subtree->to_smarty_php(); |                 $more_php = $subtree->to_smarty_php($parser); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             $code .= $more_php; |             $code .= $more_php; | ||||||
|  |  | ||||||
|             if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) { |             if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) { | ||||||
|                 $this->parser->compiler->has_variable_string = true; |                 $parser->compiler->has_variable_string = true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Create parse tree buffer with string content |      * Create parse tree buffer with string content | ||||||
|      * |      * | ||||||
|      * @param object $parser parser object |  | ||||||
|      * @param string $data string section |      * @param string $data string section | ||||||
|      */ |      */ | ||||||
|     public function __construct($parser, $data) |     public function __construct($data) | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|         $this->data = $data; |         $this->data = $data; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Return content as double quoted string |      * Return content as double quoted string | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string doubled quoted string |      * @return string doubled quoted string | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         return '"' . $this->data . '"'; |         return '"' . $this->data . '"'; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -29,12 +29,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Create parse tree buffer for Smarty tag |      * Create parse tree buffer for Smarty tag | ||||||
|      * |      * | ||||||
|      * @param object $parser parser object |      * @param \Smarty_Internal_Templateparser $parser parser object | ||||||
|      * @param string                          $data   content |      * @param string                          $data   content | ||||||
|      */ |      */ | ||||||
|     public function __construct($parser, $data) |     public function __construct(Smarty_Internal_Templateparser $parser, $data) | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|         $this->data = $data; |         $this->data = $data; | ||||||
|         $this->saved_block_nesting = $parser->block_nesting_level; |         $this->saved_block_nesting = $parser->block_nesting_level; | ||||||
|     } |     } | ||||||
| @@ -42,9 +41,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Return buffer content |      * Return buffer content | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string content |      * @return string content | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         return $this->data; |         return $this->data; | ||||||
|     } |     } | ||||||
| @@ -52,14 +53,16 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Return complied code that loads the evaluated output of buffer content into a temporary variable |      * Return complied code that loads the evaluated output of buffer content into a temporary variable | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string template code |      * @return string template code | ||||||
|      */ |      */ | ||||||
|     public function assign_to_var() |     public function assign_to_var(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         $var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number); |         $var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number); | ||||||
|         $tmp = $this->parser->compiler->appendCode('<?php ob_start();?>', $this->data); |         $tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data); | ||||||
|         $tmp = $this->parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>"); |         $tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>"); | ||||||
|         $this->parser->compiler->prefix_code[] = sprintf("%s", $tmp); |         $parser->compiler->prefix_code[] = sprintf("%s", $tmp); | ||||||
|  |  | ||||||
|         return $var; |         return $var; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -29,19 +29,18 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Create root of parse tree for template elements |      * Create root of parse tree for template elements | ||||||
|      * |      * | ||||||
|      * @param object $parser parse object |  | ||||||
|      */ |      */ | ||||||
|     public function __construct($parser) |     public function __construct() | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Append buffer to subtree |      * Append buffer to subtree | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|      * @param Smarty_Internal_ParseTree       $subtree |      * @param Smarty_Internal_ParseTree       $subtree | ||||||
|      */ |      */ | ||||||
|     public function append_subtree(Smarty_Internal_ParseTree $subtree) |     public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree) | ||||||
|     { |     { | ||||||
|         if (!empty($subtree->subtrees)) { |         if (!empty($subtree->subtrees)) { | ||||||
|             $this->subtrees = array_merge($this->subtrees, $subtree->subtrees); |             $this->subtrees = array_merge($this->subtrees, $subtree->subtrees); | ||||||
| @@ -52,38 +51,69 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Append array to subtree | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * @param \Smarty_Internal_ParseTree[]    $array | ||||||
|  |      */ | ||||||
|  |     public function append_array(Smarty_Internal_Templateparser $parser, $array = array()) | ||||||
|  |     { | ||||||
|  |         if (!empty($array)) { | ||||||
|  |             $this->subtrees = array_merge($this->subtrees, (array) $array); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Prepend array to subtree | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * @param \Smarty_Internal_ParseTree[]    $array | ||||||
|  |      */ | ||||||
|  |     public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array()) | ||||||
|  |     { | ||||||
|  |         if (!empty($array)) { | ||||||
|  |             $this->subtrees = array_merge((array) $array, $this->subtrees); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Sanitize and merge subtree buffers together |      * Sanitize and merge subtree buffers together | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string template code content |      * @return string template code content | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         $code = ''; |         $code = ''; | ||||||
|         for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) { |         for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) { | ||||||
|             if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) { |             if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) { | ||||||
|                 $subtree = $this->subtrees[$key]->to_smarty_php(); |                 $subtree = $this->subtrees[$key]->to_smarty_php($parser); | ||||||
|                 while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || $this->subtrees[$key + 1]->data == '')) { |                 while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || | ||||||
|  |                         $this->subtrees[$key + 1]->data == '')) { | ||||||
|                     $key ++; |                     $key ++; | ||||||
|                     if ($this->subtrees[$key]->data == '') { |                     if ($this->subtrees[$key]->data == '') { | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|                     $subtree .= $this->subtrees[$key]->to_smarty_php(); |                     $subtree .= $this->subtrees[$key]->to_smarty_php($parser); | ||||||
|                 } |                 } | ||||||
|                 if ($subtree == '') { |                 if ($subtree == '') { | ||||||
|                     continue; |                     continue; | ||||||
|                 } |                 } | ||||||
|                 $code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", $subtree); |                 $code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", | ||||||
|  |                                       $subtree); | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|             if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) { |             if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) { | ||||||
|                 $subtree = $this->subtrees[$key]->to_smarty_php(); |                 $subtree = $this->subtrees[$key]->to_smarty_php($parser); | ||||||
|                 while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || $this->subtrees[$key + 1]->data == '')) { |                 while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || | ||||||
|  |                         $this->subtrees[$key + 1]->data == '')) { | ||||||
|                     $key ++; |                     $key ++; | ||||||
|                     if ($this->subtrees[$key]->data == '') { |                     if ($this->subtrees[$key]->data == '') { | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|                     $subtree = $this->parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php()); |                     $subtree = $parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php($parser)); | ||||||
|                 } |                 } | ||||||
|                 if ($subtree == '') { |                 if ($subtree == '') { | ||||||
|                     continue; |                     continue; | ||||||
| @@ -91,7 +121,7 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree | |||||||
|                 $code .= $subtree; |                 $code .= $subtree; | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
|             $code .= $this->subtrees[$key]->to_smarty_php(); |             $code .= $this->subtrees[$key]->to_smarty_php($parser); | ||||||
|         } |         } | ||||||
|         return $code; |         return $code; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -19,21 +19,21 @@ class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree | |||||||
|     /** |     /** | ||||||
|      * Create template text buffer |      * Create template text buffer | ||||||
|      * |      * | ||||||
|      * @param object $parser parser object |  | ||||||
|      * @param string $data text |      * @param string $data text | ||||||
|      */ |      */ | ||||||
|     public function __construct($parser, $data) |     public function __construct($data) | ||||||
|     { |     { | ||||||
|         $this->parser = $parser; |  | ||||||
|         $this->data = $data; |         $this->data = $data; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Return buffer content |      * Return buffer content | ||||||
|      * |      * | ||||||
|  |      * @param \Smarty_Internal_Templateparser $parser | ||||||
|  |      * | ||||||
|      * @return string text |      * @return string text | ||||||
|      */ |      */ | ||||||
|     public function to_smarty_php() |     public function to_smarty_php(Smarty_Internal_Templateparser $parser) | ||||||
|     { |     { | ||||||
|         return $this->data; |         return $this->data; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -34,30 +34,29 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource | |||||||
|      */ |      */ | ||||||
|     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |     public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | ||||||
|     { |     { | ||||||
|         $uid = sha1(getcwd()); |         $uid = ''; | ||||||
|         $sources = array(); |         $sources = array(); | ||||||
|         $components = explode('|', $source->name); |         $components = explode('|', $source->name); | ||||||
|         $exists = true; |         $exists = true; | ||||||
|         foreach ($components as $component) { |         foreach ($components as $component) { | ||||||
|             $s = Smarty_Resource::source(null, $source->smarty, $component); |             /* @var \Smarty_Template_Source $_s */ | ||||||
|             if ($s->type == 'php') { |             $_s = Smarty_Template_Source::load(null, $source->smarty, $component); | ||||||
|                 throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type"); |             if ($_s->type == 'php') { | ||||||
|  |                 throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type"); | ||||||
|             } |             } | ||||||
|             $sources[$s->uid] = $s; |             $sources[$_s->uid] = $_s; | ||||||
|             $uid .= realpath($s->filepath); |             $uid .= $_s->filepath; | ||||||
|             if ($_template && $_template->smarty->compile_check) { |             if ($_template) { | ||||||
|                 $exists = $exists && $s->exists; |                 $exists = $exists && $_s->exists; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         $source->components = $sources; |         $source->components = $sources; | ||||||
|         $source->filepath = $s->filepath; |         $source->filepath = $_s->filepath; | ||||||
|         $source->uid = sha1($uid); |         $source->uid = sha1($uid); | ||||||
|         if ($_template && $_template->smarty->compile_check) { |  | ||||||
|             $source->timestamp = $s->timestamp; |  | ||||||
|         $source->exists = $exists; |         $source->exists = $exists; | ||||||
|  |         if ($_template) { | ||||||
|  |             $source->timestamp = $_s->timestamp; | ||||||
|         } |         } | ||||||
|         // need the template at getContent() |  | ||||||
|         $source->template = $_template; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -68,10 +67,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource | |||||||
|     public function populateTimestamp(Smarty_Template_Source $source) |     public function populateTimestamp(Smarty_Template_Source $source) | ||||||
|     { |     { | ||||||
|         $source->exists = true; |         $source->exists = true; | ||||||
|         foreach ($source->components as $s) { |         /* @var \Smarty_Template_Source $_s */ | ||||||
|             $source->exists = $source->exists && $s->exists; |         foreach ($source->components as $_s) { | ||||||
|  |             $source->exists = $source->exists && $_s->exists; | ||||||
|         } |         } | ||||||
|         $source->timestamp = $s->timestamp; |         $source->timestamp = $source->exists ? $_s->getTimeStamp() : false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -91,9 +91,10 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource | |||||||
|         $_components = array_reverse($source->components); |         $_components = array_reverse($source->components); | ||||||
|  |  | ||||||
|         $_content = ''; |         $_content = ''; | ||||||
|         foreach ($_components as $_component) { |         /* @var \Smarty_Template_Source $_s */ | ||||||
|  |         foreach ($_components as $_s) { | ||||||
|             // read content |             // read content | ||||||
|             $_content .= $_component->content; |             $_content .= $_s->getContent(); | ||||||
|         } |         } | ||||||
|         return $_content; |         return $_content; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -29,120 +29,83 @@ class Smarty_Internal_Resource_File extends Smarty_Resource | |||||||
|     protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) |     protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) | ||||||
|     { |     { | ||||||
|         $file = $source->name; |         $file = $source->name; | ||||||
|         preg_match('#^(?P<absolute>[\\\/]|[a-zA-Z]:[\\\/])|(\[(?P<index>[^\]]+)\])|(?P<rel>\.[\\\/])#', $file, $fileMatch); |         // absolute file ? | ||||||
|         // save basename |         if ($file[0] == '/' || $file[1] == ':') { | ||||||
|         if (!empty($fileMatch['absolute'])) { |             $file = $source->smarty->_realpath($file, true); | ||||||
|             $file = $this->normalizePath($file); |  | ||||||
|             return is_file($file) ? $file : false; |             return is_file($file) ? $file : false; | ||||||
|         } |         } | ||||||
|         // go relative to a given template? |         // go relative to a given template? | ||||||
|         if (!empty($fileMatch['rel']) && $_template && $_template->parent instanceof Smarty_Internal_Template) { |         if ($file[0] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 && | ||||||
|             if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) { |             preg_match('#^[.]{1,2}[\\\/]#', $file) | ||||||
|  |         ) { | ||||||
|  |             if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && | ||||||
|  |                 !isset($_template->parent->_cache['allow_relative_path']) | ||||||
|  |             ) { | ||||||
|                 throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); |                 throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'"); | ||||||
|             } |             } | ||||||
|             $path = dirname($_template->parent->source->filepath) . DS . $file; |             $path = dirname($_template->parent->source->filepath) . DS . $file; | ||||||
|             // normalize path |             // normalize path | ||||||
|             $path = $this->normalizePath($path); |             $path = $source->smarty->_realpath($path); | ||||||
|             // files relative to a template only get one shot |             // files relative to a template only get one shot | ||||||
|             return is_file($path) ? $path : false; |             return is_file($path) ? $path : false; | ||||||
|         } |         } | ||||||
|  |         // normalize DS | ||||||
|         if ($source->isConfig) { |         if (strpos($file, DS == '/' ? '\\' : '/') !== false) { | ||||||
|             $_directories = $source->smarty->getConfigDir(); |             $file = str_replace(DS == '/' ? '\\' : '/', DS, $file); | ||||||
|         } else { |  | ||||||
|             $_directories = $source->smarty->getTemplateDir(); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         $_directories = $source->smarty->getTemplateDir(null, $source->isConfig); | ||||||
|         // template_dir index? |         // template_dir index? | ||||||
|         if (!empty($fileMatch['index'])) { |         if ($file[0] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) { | ||||||
|             $index = $fileMatch['index']; |             $file = $fileMatch[2]; | ||||||
|             $_directory = null; |             $_indices = explode(',', $fileMatch[1]); | ||||||
|  |             $_index_dirs = array(); | ||||||
|  |             foreach ($_indices as $index) { | ||||||
|  |                 $index = trim($index); | ||||||
|                 // try string indexes |                 // try string indexes | ||||||
|                 if (isset($_directories[$index])) { |                 if (isset($_directories[$index])) { | ||||||
|                 $_directory = $_directories[$index]; |                     $_index_dirs[] = $_directories[$index]; | ||||||
|                 } elseif (is_numeric($index)) { |                 } elseif (is_numeric($index)) { | ||||||
|                     // try numeric index |                     // try numeric index | ||||||
|                     $index = (int) $index; |                     $index = (int) $index; | ||||||
|                     if (isset($_directories[$index])) { |                     if (isset($_directories[$index])) { | ||||||
|                     $_directory = $_directories[$index]; |                         $_index_dirs[] = $_directories[$index]; | ||||||
|                     } else { |                     } else { | ||||||
|                         // try at location index |                         // try at location index | ||||||
|                         $keys = array_keys($_directories); |                         $keys = array_keys($_directories); | ||||||
|                     $_directory = $_directories[$keys[$index]]; |                         if (isset($_directories[$keys[$index]])) { | ||||||
|  |                             $_index_dirs[] = $_directories[$keys[$index]]; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|             if ($_directory) { |  | ||||||
|                 preg_match('#\](.+)$#', $file, $fileMatch); |  | ||||||
|                 $path = $_directory . $fileMatch[1]; |  | ||||||
|                 $path = $this->normalizePath($path); |  | ||||||
|                 if (is_file($path)) { |  | ||||||
|                     return $path; |  | ||||||
|                 } |                 } | ||||||
|             } else { |             } | ||||||
|  |             if (empty($_index_dirs)) { | ||||||
|                 // index not found |                 // index not found | ||||||
|                 return false; |                 return false; | ||||||
|  |             } else { | ||||||
|  |                 $_directories = $_index_dirs; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // relative file name? |         // relative file name? | ||||||
|         foreach ($_directories as $_directory) { |         foreach ($_directories as $_directory) { | ||||||
|             $_filepath = $_directory . $file; |             $path = $_directory . $file; | ||||||
|             $path = $this->normalizePath($_filepath); |  | ||||||
|             if (is_file($path)) { |             if (is_file($path)) { | ||||||
|                 return $path; |                 return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path; | ||||||
|             } |  | ||||||
|             if ($source->smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) { |  | ||||||
|                 // try PHP include_path |  | ||||||
|                 if (function_exists('stream_resolve_include_path')) { |  | ||||||
|                     $_filepath = stream_resolve_include_path($_filepath); |  | ||||||
|                 } else { |  | ||||||
|                     $_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath); |  | ||||||
|                 } |  | ||||||
|                 if ($_filepath !== false) { |  | ||||||
|                     $path = $this->normalizePath($_filepath); |  | ||||||
|                     if (is_file($path)) { |  | ||||||
|                         return $path; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         if (!isset($_index_dirs)) { | ||||||
|             // Could be relative to cwd |             // Could be relative to cwd | ||||||
|         $path = $this->normalizePath(getcwd() . DS . $file); |             $path = $source->smarty->_realpath($file, true); | ||||||
|         return is_file($path) ? $path : false; |             if (is_file($path)) { | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Normalize path |  | ||||||
|      *  - remove /./ and /../ |  | ||||||
|      *  - make it absolute |  | ||||||
|      * |  | ||||||
|      * @param string $path file path |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      */ |  | ||||||
|     public function normalizePath($path) |  | ||||||
|     { |  | ||||||
|         if ($path[0] == '.') { |  | ||||||
|             $path = getcwd() . DS . $path; |  | ||||||
|         } |  | ||||||
|         $path = preg_replace('#[\\\/]+([.][\\\/]+)*#', DS, $path); |  | ||||||
|         while (strrpos($path, '.' . DS) !== false) { |  | ||||||
|             $path = preg_replace('#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', DS, $path); |  | ||||||
|         } |  | ||||||
|                 return $path; |                 return $path; | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|     /** |         // Use include path ? | ||||||
|      * test is file exists and save timestamp |         if ($source->smarty->use_include_path) { | ||||||
|      * |             return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); | ||||||
|      * @param  Smarty_Template_Source $source source object |         } | ||||||
|      * @param  string                 $file   file name |         return false; | ||||||
|      * |  | ||||||
|      * @return bool                   true if file exists |  | ||||||
|      */ |  | ||||||
|     protected function fileExists(Smarty_Template_Source $source, $file) |  | ||||||
|     { |  | ||||||
|         $source->timestamp = is_file($file) ? @filemtime($file) : false; |  | ||||||
|         return $source->exists = !!$source->timestamp; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -156,13 +119,13 @@ class Smarty_Internal_Resource_File extends Smarty_Resource | |||||||
|         $source->filepath = $this->buildFilepath($source, $_template); |         $source->filepath = $this->buildFilepath($source, $_template); | ||||||
|  |  | ||||||
|         if ($source->filepath !== false) { |         if ($source->filepath !== false) { | ||||||
|             if (is_object($source->smarty->security_policy)) { |             if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) { | ||||||
|                 $source->smarty->security_policy->isTrustedResourceDir($source->filepath); |                 $source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig); | ||||||
|             } |             } | ||||||
|             $source->exists = true; |             $source->exists = true; | ||||||
|             $source->uid = sha1($source->filepath); |             $source->uid = sha1($source->filepath); | ||||||
|             if ($source->smarty->compile_check && !isset($source->timestamp)) { |             if ($source->smarty->compile_check == 1) { | ||||||
|                 $source->timestamp = @filemtime($source->filepath); |                 $source->timestamp = filemtime($source->filepath); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $source->timestamp = false; |             $source->timestamp = false; | ||||||
| @@ -177,9 +140,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource | |||||||
|      */ |      */ | ||||||
|     public function populateTimestamp(Smarty_Template_Source $source) |     public function populateTimestamp(Smarty_Template_Source $source) | ||||||
|     { |     { | ||||||
|  |         if (!$source->exists) { | ||||||
|             $source->timestamp = $source->exists = is_file($source->filepath); |             $source->timestamp = $source->exists = is_file($source->filepath); | ||||||
|  |         } | ||||||
|         if ($source->exists) { |         if ($source->exists) { | ||||||
|             $source->timestamp = @filemtime($source->filepath); |             $source->timestamp = filemtime($source->filepath); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -193,13 +158,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource | |||||||
|      */ |      */ | ||||||
|     public function getContent(Smarty_Template_Source $source) |     public function getContent(Smarty_Template_Source $source) | ||||||
|     { |     { | ||||||
|         if ($source->timestamp) { |         if ($source->exists) { | ||||||
|             return file_get_contents($source->filepath); |             return file_get_contents($source->filepath); | ||||||
|         } |         } | ||||||
|         if ($source instanceof Smarty_Config_Source) { |         throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') . | ||||||
|             throw new SmartyException("Unable to read config {$source->type} '{$source->name}'"); |                                   " {$source->type} '{$source->name}'"); | ||||||
|         } |  | ||||||
|         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -24,6 +24,14 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File | |||||||
|      */ |      */ | ||||||
|     protected $short_open_tag; |     protected $short_open_tag; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Resource does implement populateCompiledFilepath() method | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $hasCompiledHandler = true; | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Create a new PHP Resource |      * Create a new PHP Resource | ||||||
|  |  | ||||||
| @@ -43,7 +51,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File | |||||||
|      */ |      */ | ||||||
|     public function getContent(Smarty_Template_Source $source) |     public function getContent(Smarty_Template_Source $source) | ||||||
|     { |     { | ||||||
|         if ($source->timestamp) { |         if ($source->exists) { | ||||||
|             return ''; |             return ''; | ||||||
|         } |         } | ||||||
|         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |         throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); | ||||||
| @@ -64,7 +72,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File | |||||||
|             throw new SmartyException("PHP templates are disabled"); |             throw new SmartyException("PHP templates are disabled"); | ||||||
|         } |         } | ||||||
|         if (!$source->exists) { |         if (!$source->exists) { | ||||||
|             if ($_template->parent instanceof Smarty_Internal_Template) { |             if (isset($_template->parent) && $_template->parent->_objType == 2) { | ||||||
|                 $parent_resource = " in '{$_template->parent->template_resource}'"; |                 $parent_resource = " in '{$_template->parent->template_resource}'"; | ||||||
|             } else { |             } else { | ||||||
|                 $parent_resource = ''; |                 $parent_resource = ''; | ||||||
|   | |||||||
| @@ -76,12 +76,13 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource | |||||||
|     public function getContent(Smarty_Template_Source $source) |     public function getContent(Smarty_Template_Source $source) | ||||||
|     { |     { | ||||||
|         // return template string |         // return template string | ||||||
|         $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty)); |         $content = null; | ||||||
|  |         $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$content, $source->smarty)); | ||||||
|         if (is_bool($t) && !$t) { |         if (is_bool($t) && !$t) { | ||||||
|             throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); |             throw new SmartyException("Unable to read template {$source->type} '{$source->name}'"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $source->content; |         return $content; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -8,11 +8,6 @@ | |||||||
|  * @author     Uwe Tews |  * @author     Uwe Tews | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * @ignore |  | ||||||
|  */ |  | ||||||
| //include 'smarty_internal_parsetree.php'; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Class SmartyTemplateCompiler |  * Class SmartyTemplateCompiler | ||||||
|  * |  * | ||||||
| @@ -35,20 +30,6 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|      */ |      */ | ||||||
|     public $parser_class; |     public $parser_class; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Lexer object |  | ||||||
|      * |  | ||||||
|      * @var object |  | ||||||
|      */ |  | ||||||
|     public $lex; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Parser object |  | ||||||
|      * |  | ||||||
|      * @var object |  | ||||||
|      */ |  | ||||||
|     public $parser; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * array of vars which can be compiled in local scope |      * array of vars which can be compiled in local scope | ||||||
|      * |      * | ||||||
| @@ -56,6 +37,27 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|      */ |      */ | ||||||
|     public $local_var = array(); |     public $local_var = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * array of callbacks called when the normal compile process of template is finished | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $postCompileCallbacks = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * prefix code | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public $prefixCompiledCode = ''; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * postfix code | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public $postfixCompiledCode = ''; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Initialize compiler |      * Initialize compiler | ||||||
|      * |      * | ||||||
| @@ -63,10 +65,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|      * @param string $parser_class class name |      * @param string $parser_class class name | ||||||
|      * @param Smarty $smarty       global instance |      * @param Smarty $smarty       global instance | ||||||
|      */ |      */ | ||||||
|     public function __construct($lexer_class, $parser_class, $smarty) |     public function __construct($lexer_class, $parser_class, Smarty $smarty) | ||||||
|     { |     { | ||||||
|         $this->smarty = $smarty; |         parent::__construct($smarty); | ||||||
|         parent::__construct(); |  | ||||||
|         // get required plugins |         // get required plugins | ||||||
|         $this->lexer_class = $lexer_class; |         $this->lexer_class = $lexer_class; | ||||||
|         $this->parser_class = $parser_class; |         $this->parser_class = $parser_class; | ||||||
| @@ -76,8 +77,10 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|      * method to compile a Smarty template |      * method to compile a Smarty template | ||||||
|      * |      * | ||||||
|      * @param  mixed $_content template source |      * @param  mixed $_content template source | ||||||
|  |      * @param bool   $isTemplateSource | ||||||
|      * |      * | ||||||
|      * @return bool true if compiling succeeded, false if it failed |      * @return bool true if compiling succeeded, false if it failed | ||||||
|  |      * @throws \SmartyCompilerException | ||||||
|      */ |      */ | ||||||
|     protected function doCompile($_content, $isTemplateSource = false) |     protected function doCompile($_content, $isTemplateSource = false) | ||||||
|     { |     { | ||||||
| @@ -85,14 +88,11 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|           tags in the templates are replaces with PHP code, |           tags in the templates are replaces with PHP code, | ||||||
|           then written to compiled files. */ |           then written to compiled files. */ | ||||||
|         // init the lexer/parser to compile the template |         // init the lexer/parser to compile the template | ||||||
|         $this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this); |         $this->parser = | ||||||
|         $this->parser = new $this->parser_class($this->lex, $this); |             new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this), | ||||||
|         if ($isTemplateSource) { |                                     $this); | ||||||
|             $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n"); |         if ($isTemplateSource && $this->template->caching) { | ||||||
|         } |             $this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); | ||||||
|         if ($this->inheritance_child) { |  | ||||||
|             // start state on child templates |  | ||||||
|             $this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); |  | ||||||
|         } |         } | ||||||
|         if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { |         if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { | ||||||
|             $mbEncoding = mb_internal_encoding(); |             $mbEncoding = mb_internal_encoding(); | ||||||
| @@ -103,21 +103,17 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|  |  | ||||||
|         if ($this->smarty->_parserdebug) { |         if ($this->smarty->_parserdebug) { | ||||||
|             $this->parser->PrintTrace(); |             $this->parser->PrintTrace(); | ||||||
|             $this->lex->PrintTrace(); |             $this->parser->lex->PrintTrace(); | ||||||
|         } |         } | ||||||
|         // get tokens from lexer and parse them |         // get tokens from lexer and parse them | ||||||
|         while ($this->lex->yylex() && !$this->abort_and_recompile) { |         while ($this->parser->lex->yylex()) { | ||||||
|             if ($this->smarty->_parserdebug) { |             if ($this->smarty->_parserdebug) { | ||||||
|                 echo "<pre>Line {$this->lex->line} Parsing  {$this->parser->yyTokenName[$this->lex->token]} Token " . |                 echo "<pre>Line {$this->parser->lex->line} Parsing  {$this->parser->yyTokenName[$this->parser->lex->token]} Token " . | ||||||
|                     htmlentities($this->lex->value) . "</pre>"; |                     htmlentities($this->parser->lex->value) . "</pre>"; | ||||||
|             } |             } | ||||||
|             $this->parser->doParse($this->lex->token, $this->lex->value); |             $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if ($this->abort_and_recompile) { |  | ||||||
|             // exit here on abort |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|         // finish parsing process |         // finish parsing process | ||||||
|         $this->parser->doParse(0, 0); |         $this->parser->doParse(0, 0); | ||||||
|         if ($mbEncoding) { |         if ($mbEncoding) { | ||||||
| @@ -127,10 +123,47 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom | |||||||
|         if (count($this->_tag_stack) > 0) { |         if (count($this->_tag_stack) > 0) { | ||||||
|             // get stacked info |             // get stacked info | ||||||
|             list($openTag, $_data) = array_pop($this->_tag_stack); |             list($openTag, $_data) = array_pop($this->_tag_stack); | ||||||
|             $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . "{$this->smarty->right_delimiter} tag"); |             $this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . | ||||||
|  |                                           "{$this->smarty->right_delimiter} tag"); | ||||||
|  |         } | ||||||
|  |         // call post compile callbacks | ||||||
|  |         foreach ($this->postCompileCallbacks as $cb) { | ||||||
|  |             $parameter = $cb; | ||||||
|  |             $parameter[0] = $this; | ||||||
|  |             call_user_func_array($cb[0], $parameter); | ||||||
|         } |         } | ||||||
|         // return compiled code |         // return compiled code | ||||||
|         // return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue); |         return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; | ||||||
|         return $this->parser->retvalue; |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Register a post compile callback | ||||||
|  |      * - when the callback is called after template compiling the compiler object will be inserted as first parameter | ||||||
|  |      * | ||||||
|  |      * @param callback $callback | ||||||
|  |      * @param array    $parameter optional parameter array | ||||||
|  |      * @param string   $key       optional key for callback | ||||||
|  |      * @param bool     $replace   if true replace existing keyed callback | ||||||
|  |      */ | ||||||
|  |     public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false) | ||||||
|  |     { | ||||||
|  |         array_unshift($parameter, $callback); | ||||||
|  |         if (isset($key)) { | ||||||
|  |             if ($replace || !isset($this->postCompileCallbacks[$key])) { | ||||||
|  |                 $this->postCompileCallbacks[$key] = $parameter; | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             $this->postCompileCallbacks[] = $parameter; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Remove a post compile callback | ||||||
|  |      * | ||||||
|  |      * @param string $key callback key | ||||||
|  |      */ | ||||||
|  |     public function unregisterPostCompileCallback($key) | ||||||
|  |     { | ||||||
|  |         unset($this->postCompileCallbacks[$key]); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,12 +14,20 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Template |  * @subpackage Template | ||||||
|  * |  * | ||||||
|  * @property Smarty_Template_Source   $source |  * @property Smarty_Template_Source|Smarty_Template_Config $source | ||||||
|  * @property Smarty_Template_Compiled                      $compiled |  * @property Smarty_Template_Compiled                      $compiled | ||||||
|  * @property Smarty_Template_Cached                        $cached |  * @property Smarty_Template_Cached                        $cached | ||||||
|  |  * @method bool mustCompile() | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | ||||||
| { | { | ||||||
|  |     /** | ||||||
|  |      * This object type (Smarty = 1, template = 2, data = 4) | ||||||
|  |      * | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     public $_objType = 2; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Global smarty instance |      * Global smarty instance | ||||||
|      * |      * | ||||||
| @@ -27,75 +35,47 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|      */ |      */ | ||||||
|     public $smarty = null; |     public $smarty = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Source instance | ||||||
|  |      * | ||||||
|  |      * @var Smarty_Template_Source|Smarty_Template_Config | ||||||
|  |      */ | ||||||
|  |     public $source = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Template resource |      * Template resource | ||||||
|      * |      * | ||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $template_resource = null; |     public $template_resource = null; | ||||||
|     /** |  | ||||||
|      * Saved template Id |  | ||||||
|      * |  | ||||||
|      * @var null|string |  | ||||||
|      */ |  | ||||||
|     public $templateId = null; |  | ||||||
|     /** |     /** | ||||||
|      * flag if compiled template is invalid and must be (re)compiled |      * flag if compiled template is invalid and must be (re)compiled | ||||||
|      * |      * | ||||||
|      * @var bool |      * @var bool | ||||||
|      */ |      */ | ||||||
|     public $mustCompile = null; |     public $mustCompile = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * flag if template does contain nocache code sections |      * Template Id | ||||||
|      * |      * | ||||||
|      * @var bool |      * @var null|string | ||||||
|      */ |      */ | ||||||
|     public $has_nocache_code = false; |     public $templateId = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * special compiled and cached template properties |      * Known template functions | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $properties = array('file_dependency' => array(), |     public $tpl_function = array(); | ||||||
|                                'nocache_hash'    => '', |  | ||||||
|                                'tpl_function'    => array(), |  | ||||||
|     ); |  | ||||||
|     /** |     /** | ||||||
|      * required plugins |      * Scope in which template is rendered | ||||||
|      * |      * | ||||||
|      * @var array |      * @var int | ||||||
|      */ |      */ | ||||||
|     public $required_plugins = array('compiled' => array(), 'nocache' => array()); |     public $scope = 0; | ||||||
|     /** |  | ||||||
|      * blocks for template inheritance |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $block_data = array(); |  | ||||||
|     /** |  | ||||||
|      * variable filters |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $variable_filters = array(); |  | ||||||
|     /** |  | ||||||
|      * optional log of tag/attributes |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $used_tags = array(); |  | ||||||
|     /** |  | ||||||
|      * internal flag to allow relative path in child template blocks |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $allow_relative_path = false; |  | ||||||
|     /** |  | ||||||
|      * internal capture runtime stack |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $_capture_stack = array(0 => array()); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Create template data object |      * Create template data object | ||||||
| @@ -104,13 +84,17 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|      * |      * | ||||||
|      * @param string                                                  $template_resource template resource string |      * @param string                                                  $template_resource template resource string | ||||||
|      * @param Smarty                                                  $smarty            Smarty instance |      * @param Smarty                                                  $smarty            Smarty instance | ||||||
|      * @param Smarty_Internal_Template $_parent           back pointer to parent object with variables or null |      * @param \Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent           back pointer to parent object | ||||||
|  |      *                                                                                   with variables or null | ||||||
|      * @param mixed                                                   $_cache_id         cache   id or null |      * @param mixed                                                   $_cache_id         cache   id or null | ||||||
|      * @param mixed                                                   $_compile_id       compile id or null |      * @param mixed                                                   $_compile_id       compile id or null | ||||||
|      * @param bool                                                    $_caching          use caching? |      * @param bool                                                    $_caching          use caching? | ||||||
|      * @param int                                                     $_cache_lifetime   cache life-time in seconds |      * @param int                                                     $_cache_lifetime   cache life-time in seconds | ||||||
|  |      * | ||||||
|  |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null) |     public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null, | ||||||
|  |                                 $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null) | ||||||
|     { |     { | ||||||
|         $this->smarty = &$smarty; |         $this->smarty = &$smarty; | ||||||
|         // Smarty parameter |         // Smarty parameter | ||||||
| @@ -124,30 +108,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|         $this->parent = $_parent; |         $this->parent = $_parent; | ||||||
|         // Template resource |         // Template resource | ||||||
|         $this->template_resource = $template_resource; |         $this->template_resource = $template_resource; | ||||||
|         // copy block data of template inheritance |         $this->source = Smarty_Template_Source::load($this); | ||||||
|         if ($this->parent instanceof Smarty_Internal_Template) { |         parent::__construct(); | ||||||
|             $this->block_data = $this->parent->block_data; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * fetches rendered template |  | ||||||
|      * |  | ||||||
|      * @throws Exception |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return string rendered template output |  | ||||||
|      */ |  | ||||||
|     public function fetch() |  | ||||||
|     { |  | ||||||
|         return $this->render(true, false, false); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * displays a Smarty template |  | ||||||
|      */ |  | ||||||
|     public function display() |  | ||||||
|     { |  | ||||||
|         $this->render(true, false, true); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -161,53 +123,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|      * @throws SmartyException |      * @throws SmartyException | ||||||
|      * @return string rendered template output |      * @return string rendered template output | ||||||
|      */ |      */ | ||||||
|     public function render($merge_tpl_vars = false, $no_output_filter = true, $display = null) |     public function render($no_output_filter = true, $display = null) | ||||||
|     { |     { | ||||||
|         $parentIsTpl = $this->parent instanceof Smarty_Internal_Template; |         $parentIsTpl = isset($this->parent) && $this->parent->_objType == 2; | ||||||
|         if ($this->smarty->debugging) { |         if ($this->smarty->debugging) { | ||||||
|             Smarty_Internal_Debug::start_template($this, $display); |             $this->smarty->_debug->start_template($this, $display); | ||||||
|         } |  | ||||||
|         $save_tpl_vars = null; |  | ||||||
|         $save_config_vars = null; |  | ||||||
|         // merge all variable scopes into template |  | ||||||
|         if ($merge_tpl_vars) { |  | ||||||
|             // save local variables |  | ||||||
|             $save_tpl_vars = $this->tpl_vars; |  | ||||||
|             $save_config_vars = $this->config_vars; |  | ||||||
|             $ptr_array = array($this); |  | ||||||
|             $ptr = $this; |  | ||||||
|             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); |  | ||||||
|             } |  | ||||||
|             $this->tpl_vars = $tpl_vars; |  | ||||||
|             $this->config_vars = $config_vars; |  | ||||||
|         } |  | ||||||
|         // dummy local smarty variable |  | ||||||
|         if (!isset($this->tpl_vars['smarty'])) { |  | ||||||
|             $this->tpl_vars['smarty'] = new Smarty_Variable; |  | ||||||
|         } |  | ||||||
|         $_smarty_old_error_level = isset($this->smarty->error_reporting) ? error_reporting($this->smarty->error_reporting) : null; |  | ||||||
|         // check URL debugging control |  | ||||||
|         if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') { |  | ||||||
|             Smarty_Internal_Debug::debugUrl($this); |  | ||||||
|         } |  | ||||||
|         if (!isset($this->source)) { |  | ||||||
|             $this->loadSource(); |  | ||||||
|         } |         } | ||||||
|         // checks if template exists |         // checks if template exists | ||||||
|         if (!$this->source->exists) { |         if (!$this->source->exists) { | ||||||
| @@ -218,201 +138,83 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|             } |             } | ||||||
|             throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); |             throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); | ||||||
|         } |         } | ||||||
|  |         // check URL debugging control | ||||||
|  |         if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') { | ||||||
|  |             $this->smarty->_debug->debugUrl($this); | ||||||
|  |         } | ||||||
|         // disable caching for evaluated code |         // disable caching for evaluated code | ||||||
|         if ($this->source->recompiled) { |         if ($this->source->handler->recompiled) { | ||||||
|             $this->caching = false; |             $this->caching = false; | ||||||
|         } |         } | ||||||
|         // read from cache or render |         // read from cache or render | ||||||
|         $isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED; |         $isCacheTpl = | ||||||
|  |             $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED; | ||||||
|         if ($isCacheTpl) { |         if ($isCacheTpl) { | ||||||
|             if (!isset($this->cached)) { |             if (!isset($this->cached)) { | ||||||
|                 $this->loadCached(); |                 $this->loadCached(); | ||||||
|             } |             } | ||||||
|             $this->cached->isCached($this); |             $this->cached->render($this, $no_output_filter); | ||||||
|         } |         } elseif ($this->source->handler->uncompiled) { | ||||||
|         if (!($isCacheTpl) || !$this->cached->valid) { |             $this->source->render($this); | ||||||
|             if ($isCacheTpl) { |         } else { | ||||||
|                 $this->properties['tpl_function'] = array(); |  | ||||||
|             } |  | ||||||
|             // render template (not loaded and not in cache) |  | ||||||
|             if ($this->smarty->debugging) { |  | ||||||
|                 Smarty_Internal_Debug::start_render($this); |  | ||||||
|             } |  | ||||||
|             if (!$this->source->uncompiled) { |  | ||||||
|                 // render compiled code |  | ||||||
|             if (!isset($this->compiled)) { |             if (!isset($this->compiled)) { | ||||||
|                 $this->loadCompiled(); |                 $this->loadCompiled(); | ||||||
|             } |             } | ||||||
|                 $content = $this->compiled->render($this); |             $this->compiled->render($this); | ||||||
|             } else { |  | ||||||
|                 $content = $this->source->renderUncompiled($this); |  | ||||||
|             } |  | ||||||
|             if (!$this->source->recompiled && empty($this->properties['file_dependency'][$this->source->uid])) { |  | ||||||
|                 $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type); |  | ||||||
|             } |  | ||||||
|             if ($parentIsTpl) { |  | ||||||
|                 $this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']); |  | ||||||
|                 //$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']); |  | ||||||
|             } |  | ||||||
|             if ($this->smarty->debugging) { |  | ||||||
|                 Smarty_Internal_Debug::end_render($this); |  | ||||||
|             } |  | ||||||
|             // write to cache when necessary |  | ||||||
|             if (!$this->source->recompiled && $isCacheTpl) { |  | ||||||
|                 if ($this->smarty->debugging) { |  | ||||||
|                     Smarty_Internal_Debug::start_cache($this); |  | ||||||
|                 } |  | ||||||
|                 $this->cached->updateCache($this, $content, $no_output_filter); |  | ||||||
|                 $compile_check = $this->smarty->compile_check; |  | ||||||
|                 $this->smarty->compile_check = false; |  | ||||||
|                 if ($parentIsTpl) { |  | ||||||
|                     $this->properties['tpl_function'] = $this->parent->properties['tpl_function']; |  | ||||||
|                 } |  | ||||||
|                 if (!$this->cached->processed) { |  | ||||||
|                     $this->cached->process($this); |  | ||||||
|                 } |  | ||||||
|                 $this->smarty->compile_check = $compile_check; |  | ||||||
|                 $content = $this->getRenderedTemplateCode(); |  | ||||||
|                 if ($this->smarty->debugging) { |  | ||||||
|                     Smarty_Internal_Debug::end_cache($this); |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 if (!empty($this->properties['nocache_hash']) && !empty($this->parent->properties['nocache_hash'])) { |  | ||||||
|                     // replace nocache_hash |  | ||||||
|                     $content = str_replace("{$this->properties['nocache_hash']}", $this->parent->properties['nocache_hash'], $content); |  | ||||||
|                     $this->parent->has_nocache_code = $this->parent->has_nocache_code || $this->has_nocache_code; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } else { |  | ||||||
|             if ($this->smarty->debugging) { |  | ||||||
|                 Smarty_Internal_Debug::start_cache($this); |  | ||||||
|             } |  | ||||||
|             $content = $this->cached->render($this); |  | ||||||
|             if ($this->smarty->debugging) { |  | ||||||
|                 Smarty_Internal_Debug::end_cache($this); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if ((!$this->caching || $this->has_nocache_code || $this->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) { |  | ||||||
|             $content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $this); |  | ||||||
|         } |  | ||||||
|         if (isset($_smarty_old_error_level)) { |  | ||||||
|             error_reporting($_smarty_old_error_level); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // display or fetch |         // display or fetch | ||||||
|         if ($display) { |         if ($display) { | ||||||
|             if ($this->caching && $this->smarty->cache_modified_check) { |             if ($this->caching && $this->smarty->cache_modified_check) { | ||||||
|                 $this->cached->cacheModifiedCheck($this, $content); |                 $this->smarty->ext->_cachemodify->cacheModifiedCheck($this->cached, $this, | ||||||
|  |                                                                      isset($content) ? $content : ob_get_clean()); | ||||||
|             } else { |             } else { | ||||||
|                 echo $content; |                 if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && | ||||||
|  |                     !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || | ||||||
|  |                         isset($this->smarty->registered_filters['output'])) | ||||||
|  |                 ) { | ||||||
|  |                     echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); | ||||||
|  |                 } else { | ||||||
|  |                     ob_end_flush(); | ||||||
|  |                     flush(); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|             if ($this->smarty->debugging) { |             if ($this->smarty->debugging) { | ||||||
|                 Smarty_Internal_Debug::end_template($this); |                 $this->smarty->_debug->end_template($this); | ||||||
|             } |  | ||||||
|                 // debug output |                 // debug output | ||||||
|             if ($this->smarty->debugging) { |                 $this->smarty->_debug->display_debug($this, true); | ||||||
|                 Smarty_Internal_Debug::display_debug($this, true); |  | ||||||
|             } |  | ||||||
|             if ($merge_tpl_vars) { |  | ||||||
|                 // restore local variables |  | ||||||
|                 $this->tpl_vars = $save_tpl_vars; |  | ||||||
|                 $this->config_vars = $save_config_vars; |  | ||||||
|             } |             } | ||||||
|             return ''; |             return ''; | ||||||
|         } else { |         } else { | ||||||
|             if ($merge_tpl_vars) { |  | ||||||
|                 // restore local variables |  | ||||||
|                 $this->tpl_vars = $save_tpl_vars; |  | ||||||
|                 $this->config_vars = $save_config_vars; |  | ||||||
|             } |  | ||||||
|             if ($this->smarty->debugging) { |             if ($this->smarty->debugging) { | ||||||
|                 Smarty_Internal_Debug::end_template($this); |                 $this->smarty->_debug->end_template($this); | ||||||
|             } |                 if ($this->smarty->debugging == 2 and !$display) { | ||||||
|             if ($this->smarty->debugging == 2 and $display === false) { |                     $this->smarty->_debug->display_debug($this, true); | ||||||
|                 if ($this->smarty->debugging) { |  | ||||||
|                     Smarty_Internal_Debug::display_debug($this, true); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if ($parentIsTpl) { |             if ($parentIsTpl) { | ||||||
|                 $this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']); |                 if (!empty($this->tpl_function)) { | ||||||
|                 foreach ($this->required_plugins as $code => $tmp1) { |                     $this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function); | ||||||
|  |                 } | ||||||
|  |                 foreach ($this->compiled->required_plugins as $code => $tmp1) { | ||||||
|                     foreach ($tmp1 as $name => $tmp) { |                     foreach ($tmp1 as $name => $tmp) { | ||||||
|                         foreach ($tmp as $type => $data) { |                         foreach ($tmp as $type => $data) { | ||||||
|                             $this->parent->required_plugins[$code][$name][$type] = $data; |                             $this->parent->compiled->required_plugins[$code][$name][$type] = $data; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             if (!$no_output_filter && | ||||||
|  |                 (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && | ||||||
|  |                 (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) | ||||||
|  |             ) { | ||||||
|  |                 return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); | ||||||
|  |             } | ||||||
|             // return cache content |             // return cache content | ||||||
|             return $content; |             return null; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * get rendered template content by calling compiled or cached template code |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      * @throws Exception |  | ||||||
|      */ |  | ||||||
|     public function getRenderedTemplateCode() |  | ||||||
|     { |  | ||||||
|         $level = ob_get_level(); |  | ||||||
|         try { |  | ||||||
|             ob_start(); |  | ||||||
|             if (empty($this->properties['unifunc']) || !is_callable($this->properties['unifunc'])) { |  | ||||||
|                 throw new SmartyException("Invalid compiled template for '{$this->template_resource}'"); |  | ||||||
|             } |  | ||||||
|             if (isset($this->smarty->security_policy)) { |  | ||||||
|                 $this->smarty->security_policy->startTemplate($this); |  | ||||||
|             } |  | ||||||
|             array_unshift($this->_capture_stack, array()); |  | ||||||
|             // |  | ||||||
|             // render compiled or saved template code |  | ||||||
|             // |  | ||||||
|             $this->properties['unifunc']($this); |  | ||||||
|             // any unclosed {capture} tags ? |  | ||||||
|             if (isset($this->_capture_stack[0][0])) { |  | ||||||
|                 $this->capture_error(); |  | ||||||
|             } |  | ||||||
|             array_shift($this->_capture_stack); |  | ||||||
|             if (isset($this->smarty->security_policy)) { |  | ||||||
|                 $this->smarty->security_policy->exitTemplate($this); |  | ||||||
|             } |  | ||||||
|             return ob_get_clean(); |  | ||||||
|         } |  | ||||||
|         catch (Exception $e) { |  | ||||||
|             while (ob_get_level() > $level) { |  | ||||||
|                 ob_end_clean(); |  | ||||||
|             } |  | ||||||
|             throw $e; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Returns if the current template must be compiled by the Smarty compiler |  | ||||||
|      * It does compare the timestamps of template source and the compiled templates and checks the force compile |  | ||||||
|      * configuration |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return boolean true if the template must be compiled |  | ||||||
|      */ |  | ||||||
|     public function mustCompile() |  | ||||||
|     { |  | ||||||
|         if (!$this->source->exists) { |  | ||||||
|             if ($this->parent instanceof Smarty_Internal_Template) { |  | ||||||
|                 $parent_resource = " in '$this->parent->template_resource}'"; |  | ||||||
|             } else { |  | ||||||
|                 $parent_resource = ''; |  | ||||||
|             } |  | ||||||
|             throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); |  | ||||||
|         } |  | ||||||
|         if ($this->mustCompile === null) { |  | ||||||
|             $this->mustCompile = (!$this->source->uncompiled && ($this->smarty->force_compile || $this->source->recompiled || $this->compiled->timestamp === false || |  | ||||||
|                     ($this->smarty->compile_check && $this->compiled->timestamp < $this->source->timestamp))); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this->mustCompile; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiles the template |      * Compiles the template | ||||||
|      * If the template is not evaluated the compiled template is saved on disk |      * If the template is not evaluated the compiled template is saved on disk | ||||||
| @@ -431,328 +233,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|      */ |      */ | ||||||
|     public function writeCachedContent($content) |     public function writeCachedContent($content) | ||||||
|     { |     { | ||||||
|         return $this->cached->writeCachedContent($this, $content); |         return $this->smarty->ext->_updateCache->writeCachedContent($this->cached, $this, $content); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Template code runtime function to get subtemplate content |      * Get unique template id | ||||||
|      * |      * | ||||||
|      * @param string  $template       the resource handle of the template file |      * @return string | ||||||
|      * @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 integer $caching        cache mode |  | ||||||
|      * @param integer $cache_lifetime life time of cache data |  | ||||||
|      * @param         $data |  | ||||||
|      * @param int     $parent_scope   scope in which {include} should execute |  | ||||||
|      * |  | ||||||
|      * @returns string template content |  | ||||||
|      */ |      */ | ||||||
|     public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope) |     public function _getTemplateId() | ||||||
|     { |     { | ||||||
|         $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope); |         return isset($this->templateId) ? $this->templateId : $this->templateId = | ||||||
|         return $tpl->render(); |             $this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id); | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Template code runtime function to set up an inline subtemplate |  | ||||||
|      * |  | ||||||
|      * @param string  $template       the resource handle of the template file |  | ||||||
|      * @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 integer $caching        cache mode |  | ||||||
|      * @param integer $cache_lifetime life time of cache data |  | ||||||
|      * @param array   $data           passed parameter template variables |  | ||||||
|      * @param int     $parent_scope   scope in which {include} should execute |  | ||||||
|      * |  | ||||||
|      * @returns object template object |  | ||||||
|      */ |  | ||||||
|     public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope) |  | ||||||
|     { |  | ||||||
|         $_templateId = $this->getTemplateId($template, $cache_id, $compile_id); |  | ||||||
|         // already in template cache? |  | ||||||
|         if (isset($this->smarty->template_objects[$_templateId])) { |  | ||||||
|             // clone cached template object because of possible recursive call |  | ||||||
|             $tpl = clone $this->smarty->template_objects[$_templateId]; |  | ||||||
|             $tpl->parent = $this; |  | ||||||
|             if ((bool) $tpl->caching !== (bool) $caching) { |  | ||||||
|                 unset($tpl->compiled); |  | ||||||
|             } |  | ||||||
|             $tpl->caching = $caching; |  | ||||||
|             $tpl->cache_lifetime = $cache_lifetime; |  | ||||||
|         } else { |  | ||||||
|             $tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime); |  | ||||||
|             $tpl->templateId = $_templateId; |  | ||||||
|         } |  | ||||||
|         // get variables from calling scope |  | ||||||
|         if ($parent_scope == Smarty::SCOPE_LOCAL) { |  | ||||||
|             $tpl->tpl_vars = $this->tpl_vars; |  | ||||||
|             $tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty']; |  | ||||||
|         } elseif ($parent_scope == Smarty::SCOPE_PARENT) { |  | ||||||
|             $tpl->tpl_vars = &$this->tpl_vars; |  | ||||||
|         } elseif ($parent_scope == Smarty::SCOPE_GLOBAL) { |  | ||||||
|             $tpl->tpl_vars = &Smarty::$global_tpl_vars; |  | ||||||
|         } elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) { |  | ||||||
|             $tpl->tpl_vars = &$this->tpl_vars; |  | ||||||
|         } else { |  | ||||||
|             $tpl->tpl_vars = &$scope_ptr->tpl_vars; |  | ||||||
|         } |  | ||||||
|         $tpl->config_vars = $this->config_vars; |  | ||||||
|         if (!empty($data)) { |  | ||||||
|             // set up variable values |  | ||||||
|             foreach ($data as $_key => $_val) { |  | ||||||
|                 $tpl->tpl_vars[$_key] = new Smarty_Variable($_val); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         $tpl->properties['tpl_function'] = $this->properties['tpl_function']; |  | ||||||
|         return $tpl; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Template code runtime function to set up an inline subtemplate |  | ||||||
|      * |  | ||||||
|      * @param string  $template       the resource handle of the template file |  | ||||||
|      * @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 integer $caching        cache mode |  | ||||||
|      * @param integer $cache_lifetime life time of cache data |  | ||||||
|      * @param array   $data           passed parameter template variables |  | ||||||
|      * @param int     $parent_scope   scope in which {include} should execute |  | ||||||
|      * @param string  $hash           nocache hash code |  | ||||||
|      * @param string  $content_func   name of content function |  | ||||||
|      * |  | ||||||
|      * @returns object template content |  | ||||||
|      */ |  | ||||||
|     public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash, $content_func) |  | ||||||
|     { |  | ||||||
|         $tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope); |  | ||||||
|         $tpl->properties['nocache_hash'] = $hash; |  | ||||||
|         if (!isset($this->smarty->template_objects[$tpl->templateId])) { |  | ||||||
|             $this->smarty->template_objects[$tpl->templateId] = $tpl; |  | ||||||
|         } |  | ||||||
|         if ($this->smarty->debugging) { |  | ||||||
|             Smarty_Internal_Debug::start_template($tpl); |  | ||||||
|             Smarty_Internal_Debug::start_render($tpl); |  | ||||||
|         } |  | ||||||
|         $tpl->properties['unifunc'] = $content_func; |  | ||||||
|         $output = $tpl->getRenderedTemplateCode(); |  | ||||||
|         if ($this->smarty->debugging) { |  | ||||||
|             Smarty_Internal_Debug::end_template($tpl); |  | ||||||
|             Smarty_Internal_Debug::end_render($tpl); |  | ||||||
|         } |  | ||||||
|         if (!empty($tpl->properties['file_dependency'])) { |  | ||||||
|             $this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $tpl->properties['file_dependency']); |  | ||||||
|         } |  | ||||||
|         $this->properties['tpl_function'] = $tpl->properties['tpl_function']; |  | ||||||
|         return str_replace($tpl->properties['nocache_hash'], $this->properties['nocache_hash'], $output); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Call template function |  | ||||||
|      * |  | ||||||
|      * @param string                           $name        template function name |  | ||||||
|      * @param object|\Smarty_Internal_Template $_smarty_tpl template object |  | ||||||
|      * @param array                            $params      parameter array |  | ||||||
|      * @param bool                             $nocache     true if called nocache |  | ||||||
|      * |  | ||||||
|      * @throws \SmartyException |  | ||||||
|      */ |  | ||||||
|     public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache) |  | ||||||
|     { |  | ||||||
|         if (isset($_smarty_tpl->properties['tpl_function'][$name])) { |  | ||||||
|             if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) { |  | ||||||
|                 $function = $_smarty_tpl->properties['tpl_function'][$name]['call_name']; |  | ||||||
|             } else { |  | ||||||
|                 if (isset($_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'])) { |  | ||||||
|                     $function = $_smarty_tpl->properties['tpl_function'][$name]['call_name_caching']; |  | ||||||
|                 } else { |  | ||||||
|                     $function = $_smarty_tpl->properties['tpl_function'][$name]['call_name']; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if (function_exists($function)) { |  | ||||||
|                 $function ($_smarty_tpl, $params); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             // try to load template function dynamically |  | ||||||
|             if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) { |  | ||||||
|                 $function ($_smarty_tpl, $params); |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         throw new SmartyException("Unable to find template function '{$name}'"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * This function is executed automatically when a compiled or cached template file is included |  | ||||||
|      * - Decode saved properties from compiled template and cache files |  | ||||||
|      * - Check if compiled or cache file is valid |  | ||||||
|      * |  | ||||||
|      * @param  array $properties special template properties |  | ||||||
|      * @param  bool  $cache      flag if called from cache file |  | ||||||
|      * |  | ||||||
|      * @return bool  flag if compiled or cache file is valid |  | ||||||
|      */ |  | ||||||
|     public function decodeProperties($properties, $cache = false) |  | ||||||
|     { |  | ||||||
|         $properties['version'] = (isset($properties['version'])) ? $properties['version'] : ''; |  | ||||||
|         $is_valid = true; |  | ||||||
|         if (Smarty::SMARTY_VERSION != $properties['version']) { |  | ||||||
|             // new version must rebuild |  | ||||||
|             $is_valid = false; |  | ||||||
|         } elseif ((!$cache && $this->smarty->compile_check || $cache && ($this->smarty->compile_check === true || $this->smarty->compile_check === Smarty::COMPILECHECK_ON)) && !empty($properties['file_dependency'])) { |  | ||||||
|             // check file dependencies at compiled code |  | ||||||
|             foreach ($properties['file_dependency'] as $_file_to_check) { |  | ||||||
|                 if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') { |  | ||||||
|                     if ($this->source->filepath == $_file_to_check[0] && isset($this->source->timestamp)) { |  | ||||||
|                         // do not recheck current template |  | ||||||
|                         $mtime = $this->source->timestamp; |  | ||||||
|                     } else { |  | ||||||
|                         // file and php types can be checked without loading the respective resource handlers |  | ||||||
|                         $mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false; |  | ||||||
|                     } |  | ||||||
|                 } elseif ($_file_to_check[2] == 'string') { |  | ||||||
|                     continue; |  | ||||||
|                 } else { |  | ||||||
|                     $source = Smarty_Resource::source(null, $this->smarty, $_file_to_check[0]); |  | ||||||
|                     $mtime = $source->timestamp; |  | ||||||
|                 } |  | ||||||
|                 if (!$mtime || $mtime > $_file_to_check[1]) { |  | ||||||
|                     $is_valid = false; |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if ($cache) { |  | ||||||
|             // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc |  | ||||||
|             if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && |  | ||||||
|                 $properties['cache_lifetime'] >= 0 && |  | ||||||
|                 (time() > ($this->cached->timestamp + $properties['cache_lifetime'])) |  | ||||||
|             ) { |  | ||||||
|                 $is_valid = false; |  | ||||||
|             } |  | ||||||
|             $this->cached->valid = $is_valid; |  | ||||||
|         } else { |  | ||||||
|             $this->mustCompile = !$is_valid; |  | ||||||
|         } |  | ||||||
|         if ($is_valid) { |  | ||||||
|             $this->has_nocache_code = $properties['has_nocache_code']; |  | ||||||
|             //            $this->properties['nocache_hash'] = $properties['nocache_hash']; |  | ||||||
|             if (isset($properties['cache_lifetime'])) { |  | ||||||
|                 $this->properties['cache_lifetime'] = $properties['cache_lifetime']; |  | ||||||
|             } |  | ||||||
|             if (isset($properties['file_dependency'])) { |  | ||||||
|                 $this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']); |  | ||||||
|             } |  | ||||||
|             if (isset($properties['tpl_function'])) { |  | ||||||
|                 $this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']); |  | ||||||
|             } |  | ||||||
|             $this->properties['version'] = $properties['version']; |  | ||||||
|             $this->properties['unifunc'] = $properties['unifunc']; |  | ||||||
|         } |  | ||||||
|         return $is_valid; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Template code runtime function to create a local Smarty variable for array assignments |  | ||||||
|      * |  | ||||||
|      * @param string $tpl_var template variable name |  | ||||||
|      * @param bool   $nocache cache mode of variable |  | ||||||
|      * @param int    $scope   scope of variable |  | ||||||
|      */ |  | ||||||
|     public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = Smarty::SCOPE_LOCAL) |  | ||||||
|     { |  | ||||||
|         if (!isset($this->tpl_vars[$tpl_var])) { |  | ||||||
|             $this->tpl_vars[$tpl_var] = new Smarty_Variable(array(), $nocache, $scope); |  | ||||||
|         } else { |  | ||||||
|             $this->tpl_vars[$tpl_var] = clone $this->tpl_vars[$tpl_var]; |  | ||||||
|             if ($scope != Smarty::SCOPE_LOCAL) { |  | ||||||
|                 $this->tpl_vars[$tpl_var]->scope = $scope; |  | ||||||
|             } |  | ||||||
|             if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { |  | ||||||
|                 settype($this->tpl_vars[$tpl_var]->value, 'array'); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Template code runtime function to get pointer to template variable array of requested scope |  | ||||||
|      * |  | ||||||
|      * @param  int $scope requested variable scope |  | ||||||
|      * |  | ||||||
|      * @return array array of template variables |  | ||||||
|      */ |  | ||||||
|     public function &getScope($scope) |  | ||||||
|     { |  | ||||||
|         if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) { |  | ||||||
|             return $this->parent->tpl_vars; |  | ||||||
|         } elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) { |  | ||||||
|             $ptr = $this->parent; |  | ||||||
|             while (!empty($ptr->parent)) { |  | ||||||
|                 $ptr = $ptr->parent; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return $ptr->tpl_vars; |  | ||||||
|         } elseif ($scope == Smarty::SCOPE_GLOBAL) { |  | ||||||
|             return Smarty::$global_tpl_vars; |  | ||||||
|         } |  | ||||||
|         $null = null; |  | ||||||
|  |  | ||||||
|         return $null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Get parent or root of template parent chain |  | ||||||
|      * |  | ||||||
|      * @param  int $scope parent or root scope |  | ||||||
|      * |  | ||||||
|      * @return mixed object |  | ||||||
|      */ |  | ||||||
|     public function getScopePointer($scope) |  | ||||||
|     { |  | ||||||
|         if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) { |  | ||||||
|             return $this->parent; |  | ||||||
|         } elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) { |  | ||||||
|             $ptr = $this->parent; |  | ||||||
|             while (!empty($ptr->parent)) { |  | ||||||
|                 $ptr = $ptr->parent; |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return $ptr; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * [util function] counts an array, arrayAccess/traversable or PDOStatement object |  | ||||||
|      * |  | ||||||
|      * @param  mixed $value |  | ||||||
|      * |  | ||||||
|      * @return int   the count for arrays and objects that implement countable, 1 for other objects that don't, and 0 |  | ||||||
|      *               for empty elements |  | ||||||
|      */ |  | ||||||
|     public function _count($value) |  | ||||||
|     { |  | ||||||
|         if (is_array($value) === true || $value instanceof Countable) { |  | ||||||
|             return count($value); |  | ||||||
|         } elseif ($value instanceof IteratorAggregate) { |  | ||||||
|             // Note: getIterator() returns a Traversable, not an Iterator |  | ||||||
|             // thus rewind() and valid() methods may not be present |  | ||||||
|             return iterator_count($value->getIterator()); |  | ||||||
|         } elseif ($value instanceof Iterator) { |  | ||||||
|             return iterator_count($value); |  | ||||||
|         } elseif ($value instanceof PDOStatement) { |  | ||||||
|             return $value->rowCount(); |  | ||||||
|         } elseif ($value instanceof Traversable) { |  | ||||||
|             return iterator_count($value); |  | ||||||
|         } elseif ($value instanceof ArrayAccess) { |  | ||||||
|             if ($value->offsetExists(0)) { |  | ||||||
|                 return 1; |  | ||||||
|             } |  | ||||||
|         } elseif (is_object($value)) { |  | ||||||
|             return count($value); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return 0; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -763,33 +255,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|         throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\""); |         throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\""); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Empty cache for this template |  | ||||||
|      * |  | ||||||
|      * @param integer $exp_time expiration time |  | ||||||
|      * |  | ||||||
|      * @return integer number of cache files deleted |  | ||||||
|      */ |  | ||||||
|     public function clearCache($exp_time = null) |  | ||||||
|     { |  | ||||||
|         Smarty_CacheResource::invalidLoadedCache($this->smarty); |  | ||||||
|  |  | ||||||
|         return $this->cached->handler->clear($this->smarty, $this->template_resource, $this->cache_id, $this->compile_id, $exp_time); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Load source resource |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      */ |  | ||||||
|     public function loadSource() |  | ||||||
|     { |  | ||||||
|         $this->source = Smarty_Template_Source::load($this); |  | ||||||
|         if ($this->smarty->template_resource_caching && !$this->source->recompiled && isset($this->templateId)) { |  | ||||||
|             $this->smarty->template_objects[$this->templateId] = $this; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Load compiled object |      * Load compiled object | ||||||
|      * |      * | ||||||
| @@ -797,9 +262,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|     public function loadCompiled() |     public function loadCompiled() | ||||||
|     { |     { | ||||||
|         if (!isset($this->compiled)) { |         if (!isset($this->compiled)) { | ||||||
|             if (!class_exists('Smarty_Template_Compiled', false)) { |  | ||||||
|                 require SMARTY_SYSPLUGINS_DIR . 'smarty_template_compiled.php'; |  | ||||||
|             } |  | ||||||
|             $this->compiled = Smarty_Template_Compiled::load($this); |             $this->compiled = Smarty_Template_Compiled::load($this); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -811,9 +273,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|     public function loadCached() |     public function loadCached() | ||||||
|     { |     { | ||||||
|         if (!isset($this->cached)) { |         if (!isset($this->cached)) { | ||||||
|             if (!class_exists('Smarty_Template_Cached', false)) { |  | ||||||
|                 require SMARTY_SYSPLUGINS_DIR . 'smarty_template_cached.php'; |  | ||||||
|             } |  | ||||||
|             $this->cached = Smarty_Template_Cached::load($this); |             $this->cached = Smarty_Template_Cached::load($this); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -825,8 +284,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|      */ |      */ | ||||||
|     public function loadCompiler() |     public function loadCompiler() | ||||||
|     { |     { | ||||||
|         $this->smarty->loadPlugin($this->source->compiler_class); |         if (!class_exists($this->source->handler->compiler_class)) { | ||||||
|         $this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty); |             $this->smarty->loadPlugin($this->source->handler->compiler_class); | ||||||
|  |         } | ||||||
|  |         $this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class, | ||||||
|  |                                                                      $this->source->handler->template_parser_class, | ||||||
|  |                                                                      $this->smarty); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -859,7 +322,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|     public function __set($property_name, $value) |     public function __set($property_name, $value) | ||||||
|     { |     { | ||||||
|         switch ($property_name) { |         switch ($property_name) { | ||||||
|             case 'source': |  | ||||||
|             case 'compiled': |             case 'compiled': | ||||||
|             case 'cached': |             case 'cached': | ||||||
|             case 'compiler': |             case 'compiler': | ||||||
| @@ -886,10 +348,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase | |||||||
|     public function __get($property_name) |     public function __get($property_name) | ||||||
|     { |     { | ||||||
|         switch ($property_name) { |         switch ($property_name) { | ||||||
|             case 'source': |  | ||||||
|                 $this->loadSource(); |  | ||||||
|                 return $this->source; |  | ||||||
|  |  | ||||||
|             case 'compiled': |             case 'compiled': | ||||||
|                 $this->loadCompiled(); |                 $this->loadCompiled(); | ||||||
|                 return $this->compiled; |                 return $this->compiled; | ||||||
|   | |||||||
| @@ -13,6 +13,30 @@ | |||||||
|  * |  * | ||||||
|  * @package      Smarty |  * @package      Smarty | ||||||
|  * @subpackage   Template |  * @subpackage   Template | ||||||
|  |  * | ||||||
|  |  * @property Smarty $smarty | ||||||
|  |  * @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null) | ||||||
|  |  * @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null) | ||||||
|  |  * @method array getAutoloadFilters(string $type = null) | ||||||
|  |  * @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name) | ||||||
|  |  * @method string getDebugTemplate() | ||||||
|  |  * @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name) | ||||||
|  |  * @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers) | ||||||
|  |  * @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers) | ||||||
|  |  * @method array getDefaultModifier() | ||||||
|  |  * @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback) | ||||||
|  |  * @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unregisterResource(string $name) | ||||||
|  |  * @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name) | ||||||
|  |  * @method Smarty_Internal_TemplateBase unregisterObject(string $object_name) | ||||||
|  |  * @method object getRegisteredObject(string $object_name) | ||||||
|  |  * @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl) | ||||||
|  |  * @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null) | ||||||
|  |  * @method array getTags(mixed $template = null) | ||||||
|  */ |  */ | ||||||
| abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | ||||||
| { | { | ||||||
| @@ -23,6 +47,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $cache_id = null; |     public $cache_id = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Set this if you want different sets of compiled files for the same |      * Set this if you want different sets of compiled files for the same | ||||||
|      * templates. |      * templates. | ||||||
| @@ -30,12 +55,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $compile_id = null; |     public $compile_id = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * caching enabled |      * caching enabled | ||||||
|      * |      * | ||||||
|      * @var boolean |      * @var boolean | ||||||
|      */ |      */ | ||||||
|     public $caching = false; |     public $caching = false; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * cache lifetime in seconds |      * cache lifetime in seconds | ||||||
|      * |      * | ||||||
| @@ -43,10 +70,52 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | |||||||
|      */ |      */ | ||||||
|     public $cache_lifetime = 3600; |     public $cache_lifetime = 3600; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * universal cache | ||||||
|  |      * | ||||||
|  |      * @var array() | ||||||
|  |      */ | ||||||
|  |     public $_cache = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * fetches a rendered 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 | ||||||
|  |      * | ||||||
|  |      * @throws Exception | ||||||
|  |      * @throws SmartyException | ||||||
|  |      * @return string rendered template output | ||||||
|  |      */ | ||||||
|  |     public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null) | ||||||
|  |     { | ||||||
|  |         $result = $this->_execute($template, $cache_id, $compile_id, $parent, 0); | ||||||
|  |         return $result === null ? ob_get_clean() : $result; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 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->_execute($template, $cache_id, $compile_id, $parent, 1); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * test if cache is valid |      * test if cache is valid | ||||||
|      * |      * | ||||||
|      * @param  string|object $template   the resource handle of the template file or template object |      * @api  Smarty::isCached() | ||||||
|  |      * @link http://www.smarty.net/docs/en/api.is.cached.tpl | ||||||
|  |      * | ||||||
|  |      * @param  null|string|\Smarty_Internal_Template $template   the resource handle of the template file or template object | ||||||
|      * @param  mixed                                 $cache_id   cache id to be used with this template |      * @param  mixed                                 $cache_id   cache id to be used with this template | ||||||
|      * @param  mixed                                 $compile_id compile 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 |      * @param  object                                $parent     next higher level of Smarty variables | ||||||
| @@ -55,503 +124,193 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data | |||||||
|      */ |      */ | ||||||
|     public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) |     public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null) | ||||||
|     { |     { | ||||||
|         if ($template === null && $this instanceof $this->template_class) { |         return $this->_execute($template, $cache_id, $compile_id, $parent, 2); | ||||||
|             $template = $this; |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * fetches a rendered 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 | ||||||
|  |      * @param  string $function  function type 0 = fetch,  1 = display, 2 = isCache | ||||||
|  |      * | ||||||
|  |      * @return mixed | ||||||
|  |      * @throws \Exception | ||||||
|  |      * @throws \SmartyException | ||||||
|  |      */ | ||||||
|  |     private function _execute($template, $cache_id, $compile_id, $parent, $function) | ||||||
|  |     { | ||||||
|  |         $smarty = $this->_objType == 1 ? $this : $this->smarty; | ||||||
|  |         if ($template === null) { | ||||||
|  |             if ($this->_objType != 2) { | ||||||
|  |                 throw new SmartyException($function . '():Missing \'$template\' parameter'); | ||||||
|             } else { |             } else { | ||||||
|             if (!($template instanceof $this->template_class)) { |                 $template = clone $this; | ||||||
|                 if ($parent === null) { |  | ||||||
|                     $parent = $this; |  | ||||||
|             } |             } | ||||||
|                 $smarty = isset($this->smarty) ? $this->smarty : $this; |         } elseif (is_object($template)) { | ||||||
|  |             if (!isset($template->_objType) || $template->_objType != 2) { | ||||||
|  |                 throw new SmartyException($function . '():Template object expected'); | ||||||
|  |             } else { | ||||||
|  |                 /* @var Smarty_Internal_Template $template */ | ||||||
|  |                 $template = clone $template; | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             // get template object | ||||||
|  |             /* @var Smarty_Internal_Template $template */ | ||||||
|             $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); |             $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false); | ||||||
|  |             if ($this->_objType == 1) { | ||||||
|  |                 // set caching in template object | ||||||
|  |                 $template->caching = $this->caching; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         // fetch template content | ||||||
|  |         $level = ob_get_level(); | ||||||
|  |         try { | ||||||
|  |             $_smarty_old_error_level = | ||||||
|  |                 ($this->_objType == 1 && isset($smarty->error_reporting)) ? error_reporting($smarty->error_reporting) : | ||||||
|  |                     null; | ||||||
|  |             if ($function == 2) { | ||||||
|  |                 if ($template->caching) { | ||||||
|                     // return cache status of template |                     // return cache status of template | ||||||
|                     if (!isset($template->cached)) { |                     if (!isset($template->cached)) { | ||||||
|                         $template->loadCached(); |                         $template->loadCached(); | ||||||
|                     } |                     } | ||||||
|         return $template->cached->isCached($template); |                     $result = $template->cached->isCached($template); | ||||||
|     } |                     $template->smarty->_cache['isCached'][$template->_getTemplateId()] = $template; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * creates a data object |  | ||||||
|      * |  | ||||||
|      * @param object $parent next higher level of Smarty variables |  | ||||||
|      * @param string $name   optional data block name |  | ||||||
|      * |  | ||||||
|      * @returns Smarty_Data data object |  | ||||||
|      */ |  | ||||||
|     public function createData($parent = null, $name = null) |  | ||||||
|     { |  | ||||||
|         $dataObj = new Smarty_Data($parent, $this, $name); |  | ||||||
|         if ($this->debugging) { |  | ||||||
|             Smarty_Internal_Debug::register_data($dataObj); |  | ||||||
|         } |  | ||||||
|         return $dataObj; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Get unique template id |  | ||||||
|      * |  | ||||||
|      * @param string     $template_name |  | ||||||
|      * @param null|mixed $cache_id |  | ||||||
|      * @param null|mixed $compile_id |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      */ |  | ||||||
|     public function getTemplateId($template_name, $cache_id = null, $compile_id = null) |  | ||||||
|     { |  | ||||||
|         $cache_id = isset($cache_id) ? $cache_id : $this->cache_id; |  | ||||||
|         $compile_id = isset($compile_id) ? $compile_id : $this->compile_id; |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if ($smarty->allow_ambiguous_resources) { |  | ||||||
|             $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}"; |  | ||||||
|                 } else { |                 } else { | ||||||
|             $_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}"; |                     return false; | ||||||
|                 } |                 } | ||||||
|         if (isset($_templateId[150])) { |             } else { | ||||||
|             $_templateId = sha1($_templateId); |                 ob_start(); | ||||||
|  |                 $template->_mergeVars(); | ||||||
|  |                 if (!empty(Smarty::$global_tpl_vars)) { | ||||||
|  |                     $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars); | ||||||
|  |                 } | ||||||
|  |                 $result = $template->render(false, $function); | ||||||
|  |             } | ||||||
|  |             if (isset($_smarty_old_error_level)) { | ||||||
|  |                 error_reporting($_smarty_old_error_level); | ||||||
|  |             } | ||||||
|  |             return $result; | ||||||
|  |         } | ||||||
|  |         catch (Exception $e) { | ||||||
|  |             while (ob_get_level() > $level) { | ||||||
|  |                 ob_end_clean(); | ||||||
|  |             } | ||||||
|  |             throw $e; | ||||||
|         } |         } | ||||||
|         return $_templateId; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Registers plugin to be used in templates |      * Registers plugin to be used in templates | ||||||
|      * |      * | ||||||
|      * @param  string   $type       plugin type |      * @api  Smarty::registerPlugin() | ||||||
|      * @param  string   $tag        name of template tag |      * @link http://www.smarty.net/docs/en/api.register.plugin.tpl | ||||||
|      * @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 |      * @param  string   $type       plugin type | ||||||
|      *                                      Smarty_Internal_Template) instance for chaining |      * @param  string   $name       name of template tag | ||||||
|  |      * @param  callback $callback   PHP callback to register | ||||||
|  |      * @param  bool     $cacheable  if true (default) this function is cache able | ||||||
|  |      * @param  mixed    $cache_attr caching attributes if any | ||||||
|  |      * | ||||||
|  |      * @return \Smarty|\Smarty_Internal_Template | ||||||
|      * @throws SmartyException              when the plugin tag is invalid |      * @throws SmartyException              when the plugin tag is invalid | ||||||
|      */ |      */ | ||||||
|     public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null) |     public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) | ||||||
|     { |     { | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |         return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr); | ||||||
|         if (isset($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 { |  | ||||||
|             $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (isset($smarty->registered_plugins[$type][$tag])) { |  | ||||||
|             unset($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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (isset($smarty->registered_resources[$type])) { |  | ||||||
|             unset($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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (isset($smarty->registered_cache_resources[$type])) { |  | ||||||
|             unset($smarty->registered_cache_resources[$type]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Registers object to be used in templates |  | ||||||
|      * |  | ||||||
|      * @param          $object_name |  | ||||||
|      * @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 |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or |  | ||||||
|      *                                      Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) |  | ||||||
|     { |  | ||||||
|         // test if allowed methods 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 methods 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 |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (!isset($smarty->registered_objects[$name])) { |  | ||||||
|             throw new SmartyException("'$name' is not a registered object"); |  | ||||||
|         } |  | ||||||
|         if (!is_object($smarty->registered_objects[$name][0])) { |  | ||||||
|             throw new SmartyException("registered '$name' is not an object"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (isset($smarty->registered_objects[$name])) { |  | ||||||
|             unset($smarty->registered_objects[$name]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Registers static classes to be used in templates |  | ||||||
|      * |  | ||||||
|      * @param         $class_name |  | ||||||
|      * @param  string $class_impl the referenced PHP class to register |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or |  | ||||||
|      *                                      Smarty_Internal_Template) instance for chaining |  | ||||||
|      */ |  | ||||||
|     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 |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (is_callable($callback)) { |  | ||||||
|             $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) |  | ||||||
|     { |  | ||||||
|         Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback); |  | ||||||
|         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) |  | ||||||
|     { |  | ||||||
|         Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback); |  | ||||||
|         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) |  | ||||||
|     { |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $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); |  | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |  | ||||||
|         if (isset($smarty->registered_filters[$type][$name])) { |  | ||||||
|             unset($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 |      * load a filter of specified type and name | ||||||
|      * |      * | ||||||
|  |      * @api  Smarty::loadFilter() | ||||||
|  |      * @link http://www.smarty.net/docs/en/api.load.filter.tpl | ||||||
|  |      * | ||||||
|      * @param  string $type filter type |      * @param  string $type filter type | ||||||
|      * @param  string $name filter name |      * @param  string $name filter name | ||||||
|      * |      * | ||||||
|  |      * @return bool | ||||||
|      * @throws SmartyException if filter could not be loaded |      * @throws SmartyException if filter could not be loaded | ||||||
|      */ |      */ | ||||||
|     public function loadFilter($type, $name) |     public function loadFilter($type, $name) | ||||||
|     { |     { | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |         return $this->ext->loadFilter->loadFilter($this, $type, $name); | ||||||
|         $_plugin = "smarty_{$type}filter_{$name}"; |  | ||||||
|         $_filter_name = $_plugin; |  | ||||||
|         if ($smarty->loadPlugin($_plugin)) { |  | ||||||
|             if (class_exists($_plugin, false)) { |  | ||||||
|                 $_plugin = array($_plugin, 'execute'); |  | ||||||
|             } |  | ||||||
|             if (is_callable($_plugin)) { |  | ||||||
|                 $smarty->registered_filters[$type][$_filter_name] = $_plugin; |  | ||||||
|  |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         throw new SmartyException("{$type}filter \"{$name}\" not callable"); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * unload a filter of specified type and name |      * Registers a filter function | ||||||
|  |      * | ||||||
|  |      * @api  Smarty::registerFilter() | ||||||
|  |      * @link http://www.smarty.net/docs/en/api.register.filter.tpl | ||||||
|      * |      * | ||||||
|      * @param  string      $type filter type |      * @param  string      $type filter type | ||||||
|      * @param  string $name filter name |      * @param  callback    $callback | ||||||
|  |      * @param  string|null $name optional filter name | ||||||
|      * |      * | ||||||
|      * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or |      * @return \Smarty|\Smarty_Internal_Template | ||||||
|      *                                      Smarty_Internal_Template) instance for chaining |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     public function unloadFilter($type, $name) |     public function registerFilter($type, $callback, $name = null) | ||||||
|     { |     { | ||||||
|         $smarty = isset($this->smarty) ? $this->smarty : $this; |         return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name); | ||||||
|         $_filter_name = "smarty_{$type}filter_{$name}"; |  | ||||||
|         if (isset($smarty->registered_filters[$type][$_filter_name])) { |  | ||||||
|             unset ($smarty->registered_filters[$type][$_filter_name]); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return $this; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * preg_replace callback to convert camelcase getter/setter to underscore property names |      * Registers object to be used in templates | ||||||
|      * |      * | ||||||
|      * @param  string $match match string |      * @api  Smarty::registerObject() | ||||||
|  |      * @link http://www.smarty.net/docs/en/api.register.object.tpl | ||||||
|      * |      * | ||||||
|      * @return string replacemant |      * @param  string $object_name | ||||||
|  |      * @param  object $object                     the referenced PHP object to register | ||||||
|  |      * @param  array  $allowed_methods_properties list of allowed methods (empty = all) | ||||||
|  |      * @param  bool   $format                     smarty argument format, else traditional | ||||||
|  |      * @param  array  $block_methods              list of block-methods | ||||||
|  |      * | ||||||
|  |      * @return \Smarty|\Smarty_Internal_Template | ||||||
|  |      * @throws \SmartyException | ||||||
|      */ |      */ | ||||||
|     private function replaceCamelcase($match) |     public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, | ||||||
|  |                                    $block_methods = array()) | ||||||
|     { |     { | ||||||
|         return "_" . strtolower($match[1]); |         return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties, | ||||||
|  |                                                           $format, $block_methods); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Handle unknown class methods |      * @param boolean $caching | ||||||
|      * |  | ||||||
|      * @param string $name unknown method-name |  | ||||||
|      * @param array  $args argument array |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      */ |      */ | ||||||
|     public function __call($name, $args) |     public function setCaching($caching) | ||||||
|     { |     { | ||||||
|         static $_prefixes = array('set' => true, 'get' => true); |         $this->caching = $caching; | ||||||
|         static $_resolved_property_name = array(); |     } | ||||||
|         static $_resolved_property_source = array(); |  | ||||||
|  |     /** | ||||||
|         // see if this is a set/get for a property |      * @param int $cache_lifetime | ||||||
|         $first3 = strtolower(substr($name, 0, 3)); |      */ | ||||||
|         if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') { |     public function setCacheLifetime($cache_lifetime) | ||||||
|             if (isset($_resolved_property_name[$name])) { |     { | ||||||
|                 $property_name = $_resolved_property_name[$name]; |         $this->cache_lifetime = $cache_lifetime; | ||||||
|             } 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); |      * @param string $compile_id | ||||||
|                 // convert camel case to underscored name |      */ | ||||||
|                 $property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name); |     public function setCompileId($compile_id) | ||||||
|                 $_resolved_property_name[$name] = $property_name; |     { | ||||||
|             } |         $this->compile_id = $compile_id; | ||||||
|             if (isset($_resolved_property_source[$property_name])) { |     } | ||||||
|                 $status = $_resolved_property_source[$property_name]; |  | ||||||
|             } else { |     /** | ||||||
|                 $status = null; |      * @param string $cache_id | ||||||
|                 if (property_exists($this, $property_name)) { |      */ | ||||||
|                     $status = true; |     public function setCacheId($cache_id) | ||||||
|                 } elseif (property_exists($this->smarty, $property_name)) { |     { | ||||||
|                     $status = false; |         $this->cache_id = $cache_id; | ||||||
|                 } |     } | ||||||
|                 $_resolved_property_source[$property_name] = $status; |  | ||||||
|             } |  | ||||||
|             $smarty = null; |  | ||||||
|             if ($status === true) { |  | ||||||
|                 $smarty = $this; |  | ||||||
|             } elseif ($status === false) { |  | ||||||
|                 $smarty = $this->smarty; |  | ||||||
|             } |  | ||||||
|             if ($smarty) { |  | ||||||
|                 if ($first3 == 'get') { |  | ||||||
|                     return $smarty->$property_name; |  | ||||||
|                 } else { |  | ||||||
|                     return $smarty->$property_name = $args[0]; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             throw new SmartyException("property '$property_name' does not exist."); |  | ||||||
|         } |  | ||||||
|         throw new SmartyException("Call of unknown method '$name'."); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,6 +14,11 @@ | |||||||
|  * |  * | ||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage Compiler |  * @subpackage Compiler | ||||||
|  |  * | ||||||
|  |  * @property Smarty_Internal_SmartyTemplateCompiler $prefixCompiledCode  = '' | ||||||
|  |  * @property Smarty_Internal_SmartyTemplateCompiler $postfixCompiledCode = '' | ||||||
|  |  * @method Smarty_Internal_SmartyTemplateCompiler registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false) | ||||||
|  |  * @method Smarty_Internal_SmartyTemplateCompiler unregisterPostCompileCallback($key) | ||||||
|  */ |  */ | ||||||
| abstract class Smarty_Internal_TemplateCompilerBase | abstract class Smarty_Internal_TemplateCompilerBase | ||||||
| { | { | ||||||
| @@ -25,6 +30,13 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $smarty = null; |     public $smarty = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Parser object | ||||||
|  |      * | ||||||
|  |      * @var Smarty_Internal_Templateparser | ||||||
|  |      */ | ||||||
|  |     public $parser = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * hash for nocache sections |      * hash for nocache sections | ||||||
|      * |      * | ||||||
| @@ -40,11 +52,11 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|     public $suppressNocacheProcessing = false; |     public $suppressNocacheProcessing = false; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * compile tag objects |      * compile tag objects cache | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public static $_tag_objects = array(); |     public $_tag_objects = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * tag stack |      * tag stack | ||||||
| @@ -81,34 +93,6 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $templateProperties = array(); |     public $templateProperties = array(); | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * sources which must be compiled |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $sources = array(); |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * flag that we are inside {block} |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $inheritance = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * flag when compiling inheritance child template |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $inheritance_child = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * uid of templates called by {extends} for recursion check |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public $extends_uid = array(); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * source line offset for error messages |      * source line offset for error messages | ||||||
|      * |      * | ||||||
| @@ -158,27 +142,6 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $forceNocache = false; |     public $forceNocache = false; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * suppress Smarty header code in compiled template |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $suppressHeader = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * suppress template property header code in compiled template |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $suppressTemplatePropertyHeader = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * suppress pre and post filter |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $suppressFilter = false; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * flag if compiled template file shall we written |      * flag if compiled template file shall we written | ||||||
|      * |      * | ||||||
| @@ -186,13 +149,6 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $write_compiled_code = true; |     public $write_compiled_code = true; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * flag if currently a template function is compiled |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $compiles_template_function = false; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * called sub functions from template function |      * called sub functions from template function | ||||||
|      * |      * | ||||||
| @@ -201,11 +157,11 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|     public $called_functions = array(); |     public $called_functions = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * compiled template function code |      * compiled template or block function code | ||||||
|      * |      * | ||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $templateFunctionCode = ''; |     public $blockOrFunctionCode = ''; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * php_handling setting either from Smarty or security |      * php_handling setting either from Smarty or security | ||||||
| @@ -249,13 +205,6 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $tag_nocache = false; |     public $tag_nocache = false; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Flag to restart parsing |  | ||||||
|      * |  | ||||||
|      * @var bool |  | ||||||
|      */ |  | ||||||
|     public $abort_and_recompile = false; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiled tag prefix code |      * Compiled tag prefix code | ||||||
|      * |      * | ||||||
| @@ -291,6 +240,27 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $has_output = false; |     public $has_output = false; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Stack for {setfilter} {/setfilter} | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $variable_filter_stack = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * variable filters for {setfilter} {/setfilter} | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $variable_filters = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Nesting count of looping tags like {foreach}, {for}, {section}, {while} | ||||||
|  |      * | ||||||
|  |      * @var int | ||||||
|  |      */ | ||||||
|  |     public $loopNesting = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Strip preg pattern |      * Strip preg pattern | ||||||
|      * |      * | ||||||
| @@ -298,20 +268,38 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!'; |     public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!'; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * plugin search order | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $plugin_search_order = array('function', 'block', 'compiler', 'class'); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * General storage area for tag compiler plugins | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $_cache = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * method to compile a Smarty template |      * method to compile a Smarty template | ||||||
|      * |      * | ||||||
|      * @param mixed $_content template source |      * @param mixed $_content template source | ||||||
|  |      * @param bool  $isTemplateSource | ||||||
|      * |      * | ||||||
|      * @return bool true if compiling succeeded, false if it failed |      * @return bool true if compiling succeeded, false if it failed | ||||||
|      */ |      */ | ||||||
|     abstract protected function doCompile($_content); |     abstract protected function doCompile($_content, $isTemplateSource = false); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Initialize compiler |      * Initialize compiler | ||||||
|  |      * | ||||||
|  |      * @param Smarty $smarty global instance | ||||||
|      */ |      */ | ||||||
|     public function __construct() |     public function __construct(Smarty $smarty) | ||||||
|     { |     { | ||||||
|  |         $this->smarty = $smarty; | ||||||
|         $this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true)); |         $this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -323,11 +311,42 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler |      * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler | ||||||
|      * |      * | ||||||
|      * @return bool true if compiling succeeded, false if it failed |      * @return bool true if compiling succeeded, false if it failed | ||||||
|  |      * @throws \Exception | ||||||
|      */ |      */ | ||||||
|     public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null) |     public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, | ||||||
|  |                                     Smarty_Internal_TemplateCompilerBase $parent_compiler = null) | ||||||
|     { |     { | ||||||
|  |         // get code frame of compiled template | ||||||
|  |         $_compiled_code = $template->smarty->ext->_codeFrame->create($template, | ||||||
|  |                                                                      $this->compileTemplateSource($template, $nocache, | ||||||
|  |                                                                                                   $parent_compiler), | ||||||
|  |                                                                      $this->postFilter($this->blockOrFunctionCode) . | ||||||
|  |                                                                      join('', $this->mergedSubTemplatesCode)); | ||||||
|  |         return $_compiled_code; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Compile template source and run optional post filter | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Template             $template | ||||||
|  |      * @param null|bool                             $nocache flag if template must be compiled in nocache mode | ||||||
|  |      * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      * @throws \Exception | ||||||
|  |      */ | ||||||
|  |     public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, | ||||||
|  |                                           Smarty_Internal_TemplateCompilerBase $parent_compiler = null) | ||||||
|  |     { | ||||||
|  |         try { | ||||||
|             // save template object in compiler class |             // save template object in compiler class | ||||||
|             $this->template = $template; |             $this->template = $template; | ||||||
|  |             if (property_exists($this->template->smarty, 'plugin_search_order')) { | ||||||
|  |                 $this->plugin_search_order = $this->template->smarty->plugin_search_order; | ||||||
|  |             } | ||||||
|  |             if ($this->smarty->debugging) { | ||||||
|  |                 $this->smarty->_debug->start_compile($this->template); | ||||||
|  |             } | ||||||
|             if (isset($this->template->smarty->security_policy)) { |             if (isset($this->template->smarty->security_policy)) { | ||||||
|                 $this->php_handling = $this->template->smarty->security_policy->php_handling; |                 $this->php_handling = $this->template->smarty->security_policy->php_handling; | ||||||
|             } else { |             } else { | ||||||
| @@ -335,104 +354,96 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|             } |             } | ||||||
|             $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; |             $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; | ||||||
|             $nocache = isset($nocache) ? $nocache : false; |             $nocache = isset($nocache) ? $nocache : false; | ||||||
|         if (empty($template->properties['nocache_hash'])) { |             if (empty($template->compiled->nocache_hash)) { | ||||||
|             $template->properties['nocache_hash'] = $this->nocache_hash; |                 $template->compiled->nocache_hash = $this->nocache_hash; | ||||||
|             } else { |             } else { | ||||||
|             $this->nocache_hash = $template->properties['nocache_hash']; |                 $this->nocache_hash = $template->compiled->nocache_hash; | ||||||
|             } |             } | ||||||
|         $save_source = $this->template->source; |             // flag for nocache sections | ||||||
|         // template header code |  | ||||||
|         $template_header = ''; |  | ||||||
|         if (!$this->suppressHeader) { |  | ||||||
|             $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; |  | ||||||
|             $template_header .= "         compiled from \"" . $this->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); |  | ||||||
|             $this->parent_compiler->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 { |  | ||||||
|                 // flag for nochache sections |  | ||||||
|             $this->nocache = $nocache; |             $this->nocache = $nocache; | ||||||
|             $this->tag_nocache = false; |             $this->tag_nocache = false; | ||||||
|             // reset has nocache code flag |             // reset has nocache code flag | ||||||
|                 $this->template->has_nocache_code = false; |             $this->template->compiled->has_nocache_code = false; | ||||||
|             $this->has_variable_string = false; |             $this->has_variable_string = false; | ||||||
|             $this->prefix_code = array(); |             $this->prefix_code = array(); | ||||||
|                 $_compiled_code = ''; |             // add file dependency | ||||||
|                 // flag for aborting current and start recompile |             $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = | ||||||
|                 $this->abort_and_recompile = false; |                 array($this->template->source->filepath, $this->template->source->getTimeStamp(), | ||||||
|                 // get template source |                       $this->template->source->type); | ||||||
|                 $_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, true); |  | ||||||
|                 } |  | ||||||
|             } 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; |             $this->smarty->_current_file = $this->template->source->filepath; | ||||||
|  |             // get template source | ||||||
|  |             if (!empty($this->template->source->components)) { | ||||||
|  |                 // we have array of inheritance templates by extends: resource | ||||||
|  |                 // generate corresponding source code sequence | ||||||
|  |                 $_content = | ||||||
|  |                     Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); | ||||||
|  |             } else { | ||||||
|  |                 // get template source | ||||||
|  |                 $_content = $this->template->source->getContent(); | ||||||
|  |             } | ||||||
|  |             $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); | ||||||
|  |         } | ||||||
|  |         catch (Exception $e) { | ||||||
|  |             if ($this->smarty->debugging) { | ||||||
|  |                 $this->smarty->_debug->end_compile($this->template); | ||||||
|  |             } | ||||||
|  |             $this->_tag_stack = array(); | ||||||
|  |             $this->_tag_objects = array(); | ||||||
|             // free memory |             // free memory | ||||||
|         unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex); |  | ||||||
|         self::$_tag_objects = array(); |  | ||||||
|         // return compiled code to template object |  | ||||||
|         $merged_code = ''; |  | ||||||
|         if (!empty($this->mergedSubTemplatesCode)) { |  | ||||||
|             foreach ($this->mergedSubTemplatesCode 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) { |  | ||||||
|             $_compiled_code .= $merged_code; |  | ||||||
|         } else { |  | ||||||
|             $_compiled_code = $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code; |  | ||||||
|         } |  | ||||||
|         if (!empty($this->templateFunctionCode)) { |  | ||||||
|             // 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 .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template); |  | ||||||
|             } else { |  | ||||||
|                 $_compiled_code .= $this->templateFunctionCode; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // unset content because template inheritance could have replace source with parent code |  | ||||||
|         unset ($template->source->content); |  | ||||||
|             $this->parent_compiler = null; |             $this->parent_compiler = null; | ||||||
|             $this->template = null; |             $this->template = null; | ||||||
|  |             $this->parser = null; | ||||||
|  |             throw $e; | ||||||
|  |         } | ||||||
|  |         if ($this->smarty->debugging) { | ||||||
|  |             $this->smarty->_debug->end_compile($this->template); | ||||||
|  |         } | ||||||
|  |         $this->parent_compiler = null; | ||||||
|  |         $this->template = null; | ||||||
|  |         $this->parser = null; | ||||||
|         return $_compiled_code; |         return $_compiled_code; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Optionally process compiled code by post filter | ||||||
|  |      * | ||||||
|  |      * @param string $code compiled code | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      * @throws \SmartyException | ||||||
|  |      */ | ||||||
|  |     public function postFilter($code) | ||||||
|  |     { | ||||||
|  |         // run post filter if on code | ||||||
|  |         if (!empty($code) && | ||||||
|  |             (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) | ||||||
|  |         ) { | ||||||
|  |             return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); | ||||||
|  |         } else { | ||||||
|  |             return $code; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Run optional prefilter | ||||||
|  |      * | ||||||
|  |      * @param string $_content template source | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      * @throws \SmartyException | ||||||
|  |      */ | ||||||
|  |     public function preFilter($_content) | ||||||
|  |     { | ||||||
|  |         // run pre filter if required | ||||||
|  |         if ($_content != '' && | ||||||
|  |             ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']))) | ||||||
|  |         ) { | ||||||
|  |             return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); | ||||||
|  |         } else { | ||||||
|  |             return $_content; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compile Tag |      * Compile Tag | ||||||
|      * This is a call back from the lexer/parser |      * This is a call back from the lexer/parser | ||||||
| @@ -478,17 +489,18 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|         $this->has_code = true; |         $this->has_code = true; | ||||||
|         $this->has_output = false; |         $this->has_output = false; | ||||||
|         // log tag/attributes |         // log tag/attributes | ||||||
|         if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) { |         if (isset($this->smarty->_cache['get_used_tags'])) { | ||||||
|             $this->template->used_tags[] = array($tag, $args); |             $this->template->_cache['used_tags'][] = array($tag, $args); | ||||||
|         } |         } | ||||||
|         // check nocache option flag |         // 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) |         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; |             $this->tag_nocache = true; | ||||||
|         } |         } | ||||||
|         // compile the smarty tag (required compile classes to compile the tag are auto loaded) |         // compile the smarty tag (required compile classes to compile the tag are auto loaded) | ||||||
|         if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { |         if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) { | ||||||
|             if (isset($this->parent_compiler->templateProperties['tpl_function'][$tag])) { |             if (isset($this->parent_compiler->template->tpl_function[$tag])) { | ||||||
|                 // template defined by {template} tag |                 // template defined by {template} tag | ||||||
|                 $args['_attr']['name'] = "'" . $tag . "'"; |                 $args['_attr']['name'] = "'" . $tag . "'"; | ||||||
|                 $_output = $this->callTagCompiler('call', $args, $parameter); |                 $_output = $this->callTagCompiler('call', $args, $parameter); | ||||||
| @@ -522,18 +534,23 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                 // check if tag is a registered object |                 // check if tag is a registered object | ||||||
|                 if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) { |                 if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) { | ||||||
|                     $method = $parameter['object_method']; |                     $method = $parameter['object_method']; | ||||||
|                     if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && (empty($this->smarty->registered_objects[$tag][1]) || in_array($method, $this->smarty->registered_objects[$tag][1])) |                     if (!in_array($method, $this->smarty->registered_objects[$tag][3]) && | ||||||
|  |                         (empty($this->smarty->registered_objects[$tag][1]) || | ||||||
|  |                             in_array($method, $this->smarty->registered_objects[$tag][1])) | ||||||
|                     ) { |                     ) { | ||||||
|                         return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); |                         return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method); | ||||||
|                     } elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) { |                     } elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) { | ||||||
|                         return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method); |                         return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, | ||||||
|  |                                                       $method); | ||||||
|                     } else { |                     } else { | ||||||
|                         // throw exception |                         // throw exception | ||||||
|                         $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . $tag . '"', $this->lex->taglineno); |                         $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . | ||||||
|  |                                                       $tag . '"', null, true); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 // check if tag is registered |                 // check if tag is registered | ||||||
|                 foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) { |                 foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) | ||||||
|  |                 { | ||||||
|                     if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) { |                     if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) { | ||||||
|                         // if compiler function plugin call it now |                         // if compiler function plugin call it now | ||||||
|                         if ($plugin_type == Smarty::PLUGIN_COMPILER) { |                         if ($plugin_type == Smarty::PLUGIN_COMPILER) { | ||||||
| @@ -552,20 +569,26 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                             if (!is_array($function)) { |                             if (!is_array($function)) { | ||||||
|                                 return $function($new_args, $this); |                                 return $function($new_args, $this); | ||||||
|                             } elseif (is_object($function[0])) { |                             } elseif (is_object($function[0])) { | ||||||
|                                 return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); |                                 return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->{$function[1]}($new_args, | ||||||
|  |                                                                                                                    $this); | ||||||
|                             } else { |                             } else { | ||||||
|                                 return call_user_func_array($function, array($new_args, $this)); |                                 return call_user_func_array($function, array($new_args, $this)); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                         // compile registered function or block function |                         // compile registered function or block function | ||||||
|                         if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { |                         if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) { | ||||||
|                             return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); |                             return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, | ||||||
|  |                                                           $tag); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 // check plugins from plugins folder |                 // check plugins from plugins folder | ||||||
|                 foreach ($this->smarty->plugin_search_order as $plugin_type) { |                 foreach ($this->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))) { |                     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; |                         $plugin = 'smarty_compiler_' . $tag; | ||||||
|                         if (is_callable($plugin)) { |                         if (is_callable($plugin)) { | ||||||
|                             // convert arguments format for old compiler plugins |                             // convert arguments format for old compiler plugins | ||||||
| @@ -589,8 +612,11 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                         throw new SmartyException("Plugin \"{$tag}\" not callable"); |                         throw new SmartyException("Plugin \"{$tag}\" not callable"); | ||||||
|                     } else { |                     } else { | ||||||
|                         if ($function = $this->getPlugin($tag, $plugin_type)) { |                         if ($function = $this->getPlugin($tag, $plugin_type)) { | ||||||
|                             if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { |                             if (!isset($this->smarty->security_policy) || | ||||||
|                                 return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function); |                                 $this->smarty->security_policy->isTrustedTag($tag, $this) | ||||||
|  |                             ) { | ||||||
|  |                                 return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, | ||||||
|  |                                                               $tag, $function); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| @@ -598,7 +624,7 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                 if (is_callable($this->smarty->default_plugin_handler_func)) { |                 if (is_callable($this->smarty->default_plugin_handler_func)) { | ||||||
|                     $found = false; |                     $found = false; | ||||||
|                     // look for already resolved tags |                     // look for already resolved tags | ||||||
|                     foreach ($this->smarty->plugin_search_order as $plugin_type) { |                     foreach ($this->plugin_search_order as $plugin_type) { | ||||||
|                         if (isset($this->default_handler_plugins[$plugin_type][$tag])) { |                         if (isset($this->default_handler_plugins[$plugin_type][$tag])) { | ||||||
|                             $found = true; |                             $found = true; | ||||||
|                             break; |                             break; | ||||||
| @@ -606,7 +632,7 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                     } |                     } | ||||||
|                     if (!$found) { |                     if (!$found) { | ||||||
|                         // call default handler |                         // call default handler | ||||||
|                         foreach ($this->smarty->plugin_search_order as $plugin_type) { |                         foreach ($this->plugin_search_order as $plugin_type) { | ||||||
|                             if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { |                             if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { | ||||||
|                                 $found = true; |                                 $found = true; | ||||||
|                                 break; |                                 break; | ||||||
| @@ -624,12 +650,14 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                             if (!is_array($function)) { |                             if (!is_array($function)) { | ||||||
|                                 return $function($new_args, $this); |                                 return $function($new_args, $this); | ||||||
|                             } elseif (is_object($function[0])) { |                             } elseif (is_object($function[0])) { | ||||||
|                                 return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this); |                                 return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, | ||||||
|  |                                                                                                               $this); | ||||||
|                             } else { |                             } else { | ||||||
|                                 return call_user_func_array($function, array($new_args, $this)); |                                 return call_user_func_array($function, array($new_args, $this)); | ||||||
|                             } |                             } | ||||||
|                         } else { |                         } else { | ||||||
|                             return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag); |                             return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, | ||||||
|  |                                                           $tag); | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @@ -640,20 +668,36 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                 if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) { |                 if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) { | ||||||
|                     $method = $parameter['object_method']; |                     $method = $parameter['object_method']; | ||||||
|                     if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) { |                     if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) { | ||||||
|                         return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method); |                         return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, | ||||||
|  |                                                       $method); | ||||||
|                     } else { |                     } else { | ||||||
|                         // throw exception |                         // throw exception | ||||||
|                         $this->trigger_template_error('not allowed closing tag method "' . $method . '" in registered object "' . $base_tag . '"', $this->lex->taglineno); |                         $this->trigger_template_error('not allowed closing tag method "' . $method . | ||||||
|  |                                                       '" in registered object "' . $base_tag . '"', null, true); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 // registered block tag ? |                 // registered block tag ? | ||||||
|                 if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) || isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_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); |                     return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); | ||||||
|                 } |                 } | ||||||
|  |                 // registered function tag ? | ||||||
|  |                 if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) { | ||||||
|  |                     return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); | ||||||
|  |                 } | ||||||
|                 // block plugin? |                 // block plugin? | ||||||
|                 if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { |                 if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { | ||||||
|                     return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); |                     return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); | ||||||
|                 } |                 } | ||||||
|  |                 // function plugin? | ||||||
|  |                 if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) { | ||||||
|  |                     if (!isset($this->smarty->security_policy) || | ||||||
|  |                         $this->smarty->security_policy->isTrustedTag($tag, $this) | ||||||
|  |                     ) { | ||||||
|  |                         return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|                 // registered compiler plugin ? |                 // registered compiler plugin ? | ||||||
|                 if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) { |                 if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) { | ||||||
|                     // if compiler function plugin call it now |                     // if compiler function plugin call it now | ||||||
| @@ -665,7 +709,8 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                     if (!is_array($function)) { |                     if (!is_array($function)) { | ||||||
|                         return $function($args, $this); |                         return $function($args, $this); | ||||||
|                     } elseif (is_object($function[0])) { |                     } elseif (is_object($function[0])) { | ||||||
|                         return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args, $this); |                         return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args, | ||||||
|  |                                                                                                                     $this); | ||||||
|                     } else { |                     } else { | ||||||
|                         return call_user_func_array($function, array($args, $this)); |                         return call_user_func_array($function, array($args, $this)); | ||||||
|                     } |                     } | ||||||
| @@ -684,7 +729,7 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|                     throw new SmartyException("Plugin \"{$tag}\" not callable"); |                     throw new SmartyException("Plugin \"{$tag}\" not callable"); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             $this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno); |             $this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -700,12 +745,26 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|         if (strpos($variable, '(') == 0) { |         if (strpos($variable, '(') == 0) { | ||||||
|             // not a variable variable |             // not a variable variable | ||||||
|             $var = trim($variable, '\''); |             $var = trim($variable, '\''); | ||||||
|             $this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache; |             $this->tag_nocache = $this->tag_nocache | | ||||||
|             $this->template->properties['variables'][$var] = $this->tag_nocache | $this->nocache; |                 $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache; | ||||||
|  |             // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; | ||||||
|         } |         } | ||||||
|         return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; |         return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * compile config variable | ||||||
|  |      * | ||||||
|  |      * @param string $variable | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public function compileConfigVariable($variable) | ||||||
|  |     { | ||||||
|  |         // return '$_smarty_tpl->config_vars[' . $variable . ']'; | ||||||
|  |         return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')'; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This method is called from parser to process a text content section |      * This method is called from parser to process a text content section | ||||||
|      * - remove text from inheritance child templates as they may generate output |      * - remove text from inheritance child templates as they may generate output | ||||||
| @@ -718,9 +777,9 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|     public function processText($text) |     public function processText($text) | ||||||
|     { |     { | ||||||
|         if ($this->parser->strip) { |         if ($this->parser->strip) { | ||||||
|             return new Smarty_Internal_ParseTree_Text($this->parser, preg_replace($this->stripRegEx, '', $text)); |             return new Smarty_Internal_ParseTree_Text(preg_replace($this->stripRegEx, ' ', $text)); | ||||||
|         } else { |         } else { | ||||||
|             return new Smarty_Internal_ParseTree_Text($this->parser, $text); |             return new Smarty_Internal_ParseTree_Text($text); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -728,7 +787,7 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      * lazy loads internal compile plugin for tag and calls the compile method |      * lazy loads internal compile plugin for tag and calls the compile method | ||||||
|      * compile objects cached for reuse. |      * compile objects cached for reuse. | ||||||
|      * class name format:  Smarty_Internal_Compile_TagName |      * class name format:  Smarty_Internal_Compile_TagName | ||||||
|      * plugin filename format: Smarty_Internal_Tagname.php |      * plugin filename format: Smarty_Internal_TagName.php | ||||||
|      * |      * | ||||||
|      * @param  string $tag    tag name |      * @param  string $tag    tag name | ||||||
|      * @param  array  $args   list of tag attributes |      * @param  array  $args   list of tag attributes | ||||||
| @@ -740,23 +799,24 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) |     public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) | ||||||
|     { |     { | ||||||
|         // check if tag allowed by security |  | ||||||
|         if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) { |  | ||||||
|         // re-use object if already exists |         // re-use object if already exists | ||||||
|             if (!isset(self::$_tag_objects[$tag])) { |         if (!isset($this->_tag_objects[$tag])) { | ||||||
|             // lazy load internal compiler plugin |             // lazy load internal compiler plugin | ||||||
|                 $class_name = 'Smarty_Internal_Compile_' . $tag; |             $_tag = explode('_', $tag); | ||||||
|                 if ($this->smarty->loadPlugin($class_name)) { |             $_tag = array_map('ucfirst', $_tag); | ||||||
|                     self::$_tag_objects[$tag] = new $class_name; |             $class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag); | ||||||
|  |             if (class_exists($class_name) && | ||||||
|  |                 (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) | ||||||
|  |             ) { | ||||||
|  |                 $this->_tag_objects[$tag] = new $class_name; | ||||||
|             } else { |             } else { | ||||||
|  |                 $this->_tag_objects[$tag] = false; | ||||||
|                 return false; |                 return false; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // compile this tag |         // compile this tag | ||||||
|             return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); |         return $this->_tag_objects[$tag] === false ? false : | ||||||
|         } |             $this->_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3); | ||||||
|         // no internal compile plugin for this tag |  | ||||||
|         return false; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -771,18 +831,24 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|     { |     { | ||||||
|         $function = null; |         $function = null; | ||||||
|         if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |         if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { | ||||||
|             if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { |             if (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { | ||||||
|                 $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; |                 $function = | ||||||
|             } elseif (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { |                     $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; | ||||||
|                 $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]; |             } elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { | ||||||
|                 $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; |                 $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] = | ||||||
|  |                     $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]; | ||||||
|  |                 $function = | ||||||
|  |                     $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { |             if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { | ||||||
|                 $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; |                 $function = | ||||||
|             } elseif (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { |                     $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; | ||||||
|                 $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]; |             } elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { | ||||||
|                 $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; |                 $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] = | ||||||
|  |                     $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]; | ||||||
|  |                 $function = | ||||||
|  |                     $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (isset($function)) { |         if (isset($function)) { | ||||||
| @@ -798,11 +864,15 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|  |  | ||||||
|         if (is_string($file)) { |         if (is_string($file)) { | ||||||
|             if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |             if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { | ||||||
|                 $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file; |                 $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = | ||||||
|                 $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function; |                     $file; | ||||||
|  |                 $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = | ||||||
|  |                     $function; | ||||||
|             } else { |             } else { | ||||||
|                 $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file; |                 $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = | ||||||
|                 $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function; |                     $file; | ||||||
|  |                 $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = | ||||||
|  |                     $function; | ||||||
|             } |             } | ||||||
|             if ($plugin_type == 'modifier') { |             if ($plugin_type == 'modifier') { | ||||||
|                 $this->modifier_plugins[$plugin_name] = true; |                 $this->modifier_plugins[$plugin_name] = true; | ||||||
| @@ -831,17 +901,22 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|         $callback = null; |         $callback = null; | ||||||
|         $script = null; |         $script = null; | ||||||
|         $cacheable = true; |         $cacheable = true; | ||||||
|         $result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)); |         $result = call_user_func_array($this->smarty->default_plugin_handler_func, | ||||||
|  |                                        array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable)); | ||||||
|         if ($result) { |         if ($result) { | ||||||
|             $this->tag_nocache = $this->tag_nocache || !$cacheable; |             $this->tag_nocache = $this->tag_nocache || !$cacheable; | ||||||
|             if ($script !== null) { |             if ($script !== null) { | ||||||
|                 if (is_file($script)) { |                 if (is_file($script)) { | ||||||
|                     if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { |                     if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { | ||||||
|                         $this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script; |                         $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['file'] = | ||||||
|                         $this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback; |                             $script; | ||||||
|  |                         $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['function'] = | ||||||
|  |                             $callback; | ||||||
|                     } else { |                     } else { | ||||||
|                         $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; |                         $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['file'] = | ||||||
|                         $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; |                             $script; | ||||||
|  |                         $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['function'] = | ||||||
|  |                             $callback; | ||||||
|                     } |                     } | ||||||
|                     require_once $script; |                     require_once $script; | ||||||
|                 } else { |                 } else { | ||||||
| @@ -898,16 +973,19 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|         // If the template is not evaluated and we have a nocache section and or a nocache tag |         // If the template is not evaluated and we have a nocache section and or a nocache tag | ||||||
|         if ($is_code && !empty($content)) { |         if ($is_code && !empty($content)) { | ||||||
|             // generate replacement code |             // generate replacement code | ||||||
|             if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) |             if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching && | ||||||
|  |                 !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) | ||||||
|             ) { |             ) { | ||||||
|                 $this->template->has_nocache_code = true; |                 $this->template->compiled->has_nocache_code = true; | ||||||
|                 $_output = addcslashes($content, '\'\\'); |                 $_output = addcslashes($content, '\'\\'); | ||||||
|                 $_output = str_replace("^#^", "'", $_output); |                 $_output = str_replace("^#^", "'", $_output); | ||||||
|                 $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; |                 $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . | ||||||
|  |                     "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; | ||||||
|                 // make sure we include modifier plugins for nocache code |                 // make sure we include modifier plugins for nocache code | ||||||
|                 foreach ($this->modifier_plugins as $plugin_name => $dummy) { |                 foreach ($this->modifier_plugins as $plugin_name => $dummy) { | ||||||
|                     if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { |                     if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier'])) { | ||||||
|                         $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; |                         $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name]['modifier'] = | ||||||
|  |                             $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier']; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
| @@ -923,6 +1001,36 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|         return $_output; |         return $_output; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get Id | ||||||
|  |      * | ||||||
|  |      * @param string $input | ||||||
|  |      * | ||||||
|  |      * @return bool|string | ||||||
|  |      */ | ||||||
|  |     public function getId($input) | ||||||
|  |     { | ||||||
|  |         if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) { | ||||||
|  |             return $match[1]; | ||||||
|  |         } | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Get variable name from string | ||||||
|  |      * | ||||||
|  |      * @param string $input | ||||||
|  |      * | ||||||
|  |      * @return bool|string | ||||||
|  |      */ | ||||||
|  |     public function getVariableName($input) | ||||||
|  |     { | ||||||
|  |         if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { | ||||||
|  |             return $match[1]; | ||||||
|  |         } | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Generate nocache code string |      * Generate nocache code string | ||||||
|      * |      * | ||||||
| @@ -932,47 +1040,8 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      */ |      */ | ||||||
|     public function makeNocacheCode($code) |     public function makeNocacheCode($code) | ||||||
|     { |     { | ||||||
|         return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " . str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; |         return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " . | ||||||
|     } |         str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      *  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 int    $line  line offset to source |  | ||||||
|      * @param bool   $debug false debug end_compile shall not be called |  | ||||||
|      */ |  | ||||||
|     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); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -983,31 +1052,51 @@ abstract class Smarty_Internal_TemplateCompilerBase | |||||||
|      * |      * | ||||||
|      * @param  string   $args    individual error message or null |      * @param  string   $args    individual error message or null | ||||||
|      * @param  string   $line    line-number |      * @param  string   $line    line-number | ||||||
|  |      * @param null|bool $tagline if true the line number of last tag | ||||||
|      * |      * | ||||||
|      * @throws SmartyCompilerException when an unexpected token is found |      * @throws \SmartyCompilerException when an unexpected token is found | ||||||
|      */ |      */ | ||||||
|     public function trigger_template_error($args = null, $line = null) |     public function trigger_template_error($args = null, $line = null, $tagline = null) | ||||||
|     { |     { | ||||||
|  |         $lex = $this->parser->lex; | ||||||
|  |         if ($tagline === true) { | ||||||
|  |             // get line number of Tag | ||||||
|  |             $line = $lex->taglineno; | ||||||
|  |         } elseif (!isset($line)) { | ||||||
|             // get template source line which has error |             // get template source line which has error | ||||||
|         if (!isset($line)) { |             $line = $lex->line; | ||||||
|             $line = $this->lex->line; |         } else { | ||||||
|  |             $line = (int) $line; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (in_array($this->template->source->type, array('eval', 'string'))) { | ||||||
|  |             $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ', | ||||||
|  |                                                                                     strlen($lex->data) > 40 ? | ||||||
|  |                                                                                         substr($lex->data, 0, 40) . | ||||||
|  |                                                                                         '...' : $lex->data)); | ||||||
|  |         } else { | ||||||
|  |             $templateName = $this->template->source->type . ':' . $this->template->source->filepath; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         //        $line += $this->trace_line_offset; |         //        $line += $this->trace_line_offset; | ||||||
|         $match = preg_split("/\n/", $this->lex->data); |         $match = preg_split("/\n/", $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])) . '" '; |         $error_text = | ||||||
|  |             'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . | ||||||
|  |             '"  on line ' . ($line + $this->trace_line_offset) . ' "' . | ||||||
|  |             trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" '; | ||||||
|         if (isset($args)) { |         if (isset($args)) { | ||||||
|             // individual error message |             // individual error message | ||||||
|             $error_text .= $args; |             $error_text .= $args; | ||||||
|         } else { |         } else { | ||||||
|             $expect = array(); |             $expect = array(); | ||||||
|             // expected token from parser |             // expected token from parser | ||||||
|             $error_text .= ' - Unexpected "' . $this->lex->value . '"'; |             $error_text .= ' - Unexpected "' . $lex->value . '"'; | ||||||
|             if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { |             if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { | ||||||
|                 foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { |                 foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { | ||||||
|                     $exp_token = $this->parser->yyTokenName[$token]; |                     $exp_token = $this->parser->yyTokenName[$token]; | ||||||
|                     if (isset($this->lex->smarty_token_names[$exp_token])) { |                     if (isset($lex->smarty_token_names[$exp_token])) { | ||||||
|                         // token type from lexer |                         // token type from lexer | ||||||
|                         $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"'; |                         $expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"'; | ||||||
|                     } else { |                     } else { | ||||||
|                         // otherwise internal token name |                         // otherwise internal token name | ||||||
|                         $expect[] = $this->parser->yyTokenName[$token]; |                         $expect[] = $this->parser->yyTokenName[$token]; | ||||||
|   | |||||||
| @@ -1,11 +1,11 @@ | |||||||
| <?php | <?php | ||||||
| /** | /* | ||||||
|  * Smarty Internal Plugin Templatelexer |  * This file is part of Smarty. | ||||||
|  * This is the lexer to break the template source into tokens |  | ||||||
|  * |  * | ||||||
|  * @package    Smarty |  * (c) 2015 Uwe Tews | ||||||
|  * @subpackage Compiler |  * | ||||||
|  * @author     Uwe Tews |  * For the full copyright and license information, please view the LICENSE | ||||||
|  |  * file that was distributed with this source code. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -13,9 +13,8 @@ | |||||||
|  * This is the template file lexer. |  * This is the template file lexer. | ||||||
|  * It is generated from the smarty_internal_templatelexer.plex file |  * It is generated from the smarty_internal_templatelexer.plex file | ||||||
|  * |  * | ||||||
|  * @package    Smarty |  * | ||||||
|  * @subpackage Compiler |  * @author Uwe Tews <uwe.tews@googlemail.com> | ||||||
|  * @author     Uwe Tews |  | ||||||
|  */ |  */ | ||||||
| class Smarty_Internal_Templatelexer | class Smarty_Internal_Templatelexer | ||||||
| { | { | ||||||
| @@ -156,8 +155,7 @@ class Smarty_Internal_Templatelexer | |||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING', |     public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',); | ||||||
|                                6 => 'CHILDBODY', 7 => 'CHILDBLOCK', 8 => 'CHILDLITERAL'); |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * storage for assembled token patterns |      * storage for assembled token patterns | ||||||
| @@ -174,25 +172,25 @@ class Smarty_Internal_Templatelexer | |||||||
|  |  | ||||||
|     private $yy_global_pattern5 = null; |     private $yy_global_pattern5 = null; | ||||||
|  |  | ||||||
|     private $yy_global_pattern6 = null; |  | ||||||
|  |  | ||||||
|     private $yy_global_pattern7 = null; |  | ||||||
|  |  | ||||||
|     private $yy_global_pattern8 = null; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * token names |      * token names | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $smarty_token_names = array(        // Text for parser error messages |     public $smarty_token_names = array(        // Text for parser error messages | ||||||
|         'NOT'         => '(!,not)', 'OPENP' => '(', 'CLOSEP' => ')', 'OPENB' => '[', 'CLOSEB' => ']', 'PTR' => '->', |                                                'NOT'         => '(!,not)', 'OPENP' => '(', 'CLOSEP' => ')', | ||||||
|         'APTR'        => '=>', 'EQUAL' => '=', 'NUMBER' => 'number', 'UNIMATH' => '+" , "-', 'MATH' => '*" , "/" , "%', |                                                'OPENB'       => '[', 'CLOSEB' => ']', 'PTR' => '->', 'APTR' => '=>', | ||||||
|         'INCDEC'      => '++" , "--', 'SPACE' => ' ', 'DOLLAR' => '$', 'SEMICOLON' => ';', 'COLON' => ':', |                                                'EQUAL'       => '=', 'NUMBER' => 'number', 'UNIMATH' => '+" , "-', | ||||||
|         'DOUBLECOLON' => '::', 'AT' => '@', 'HATCH' => '#', 'QUOTE' => '"', 'BACKTICK' => '`', 'VERT' => '"|" modifier', |                                                'MATH'        => '*" , "/" , "%', 'INCDEC' => '++" , "--', | ||||||
|         'DOT'         => '.', 'COMMA' => '","', 'QMARK' => '"?"', 'ID' => 'id, name', 'TEXT' => 'text', |                                                'SPACE'       => ' ', 'DOLLAR' => '$', 'SEMICOLON' => ';', | ||||||
|         'LDELSLASH'   => '{/..} closing tag', 'LDEL' => '{...} Smarty tag', 'COMMENT' => 'comment', 'AS' => 'as', |                                                'COLON'       => ':', 'DOUBLECOLON' => '::', 'AT' => '@', 'HATCH' => '#', | ||||||
|         'TO'          => 'to', 'PHP' => '"<?php", "<%", "{php}" tag', 'LOGOP' => '"<", "==" ... logical operator', |                                                'QUOTE'       => '"', 'BACKTICK' => '`', 'VERT' => '"|" modifier', | ||||||
|  |                                                'DOT'         => '.', 'COMMA' => '","', 'QMARK' => '"?"', | ||||||
|  |                                                'ID'          => 'id, name', 'TEXT' => 'text', | ||||||
|  |                                                'LDELSLASH'   => '{/..} closing tag', 'LDEL' => '{...} Smarty tag', | ||||||
|  |                                                'COMMENT'     => 'comment', 'AS' => 'as', 'TO' => 'to', | ||||||
|  |                                                'PHP'         => '"<?php", "<%", "{php}" tag', | ||||||
|  |                                                'LOGOP'       => '"<", "==" ... logical operator', | ||||||
|                                                'TLOGOP'      => '"lt", "eq" ... logical operator; "is div by" ... if condition', |                                                'TLOGOP'      => '"lt", "eq" ... logical operator; "is div by" ... if condition', | ||||||
|                                                'SCOND'       => '"is even" ... if condition',); |                                                'SCOND'       => '"is even" ... if condition',); | ||||||
|  |  | ||||||
| @@ -231,7 +229,8 @@ class Smarty_Internal_Templatelexer | |||||||
|      */ |      */ | ||||||
|     public function isAutoLiteral() |     public function isAutoLiteral() | ||||||
|     { |     { | ||||||
|         return $this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false; |         return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? | ||||||
|  |             strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private $_yy_state = 1; |     private $_yy_state = 1; | ||||||
| @@ -246,23 +245,31 @@ class Smarty_Internal_Templatelexer | |||||||
|     public function yypushstate($state) |     public function yypushstate($state) | ||||||
|     { |     { | ||||||
|         if ($this->yyTraceFILE) { |         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); |         array_push($this->_yy_stack, $this->_yy_state); | ||||||
|         $this->_yy_state = $state; |         $this->_yy_state = $state; | ||||||
|         if ($this->yyTraceFILE) { |         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() |     public function yypopstate() | ||||||
|     { |     { | ||||||
|         if ($this->yyTraceFILE) { |         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); |             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); |         $this->_yy_state = array_pop($this->_yy_stack); | ||||||
|         if ($this->yyTraceFILE) { |         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); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -270,14 +277,20 @@ class Smarty_Internal_Templatelexer | |||||||
|     { |     { | ||||||
|         $this->_yy_state = $state; |         $this->_yy_state = $state; | ||||||
|         if ($this->yyTraceFILE) { |         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() |     public function yylex1() | ||||||
|     { |     { | ||||||
|         if (!isset($this->yy_global_pattern1)) { |         if (!isset($this->yy_global_pattern1)) { | ||||||
|             $this->yy_global_pattern1 = "/\G([{][}])|\G(" . $this->ldel . "[*])|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|(<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|([?][>])|([%][>])|(" . $this->ldel . "\\s*php(.*?)" . $this->rdel . ")|(" . $this->ldel . "\\s*[\/]php" . $this->rdel . "))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . ")|\G([\S\s])/isS"; |             $this->yy_global_pattern1 = | ||||||
|  |                 "/\G([{][}])|\G(" . $this->ldel . "[*])|\G((" . $this->ldel . "\\s*php(.*?)" . $this->rdel . ")|(" . | ||||||
|  |                 $this->ldel . "\\s*[\/]php" . $this->rdel . "))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . | ||||||
|  |                 ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel . | ||||||
|  |                 ")|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|(<script\\s+language\\s*=\\s*[\"']?\\s*php\\s*[\"']?\\s*>)|([?][>])|([%][>]))|\G([\S\s])/isS"; | ||||||
|         } |         } | ||||||
|         if ($this->counter >= strlen($this->data)) { |         if ($this->counter >= strlen($this->data)) { | ||||||
|             return false; // end of input |             return false; // end of input | ||||||
| @@ -292,7 +305,8 @@ class Smarty_Internal_Templatelexer | |||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |                     $yymatches = array_filter($yymatches, 'strlen'); | ||||||
|                 } |                 } | ||||||
|                 if (empty($yymatches)) { |                 if (empty($yymatches)) { | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state TEXT'); |                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . | ||||||
|  |                                         substr($this->data, $this->counter, 5) . '... state TEXT'); | ||||||
|                 } |                 } | ||||||
|                 next($yymatches); // skip global match |                 next($yymatches); // skip global match | ||||||
|                 $this->token = key($yymatches); // token number |                 $this->token = key($yymatches); // token number | ||||||
| @@ -351,10 +365,12 @@ class Smarty_Internal_Templatelexer | |||||||
|         $obj->parsePhp($this); |         $obj->parsePhp($this); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r1_15() |     function yy_r1_7() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { |         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; |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|         } else { |         } else { | ||||||
|             $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; |             $this->token = Smarty_Internal_Templateparser::TP_LITERALSTART; | ||||||
| @@ -362,10 +378,12 @@ class Smarty_Internal_Templatelexer | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r1_16() |     function yy_r1_8() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { |         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; |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|         } else { |         } else { | ||||||
|             $this->yypushstate(self::TAG); |             $this->yypushstate(self::TAG); | ||||||
| @@ -373,17 +391,25 @@ class Smarty_Internal_Templatelexer | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r1_17() |     function yy_r1_9() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_TEXT; |         $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r1_18() |     function yy_r1_10() | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $obj = new Smarty_Internal_Compile_Private_Php(); | ||||||
|  |         $obj->parsePhp($this); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     function yy_r1_19() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $to = strlen($this->data); |         $to = strlen($this->data); | ||||||
|         preg_match("~($this->ldel)|([<]script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*[>])|([<][?])|([<][%])|([?][>])|([%][>])~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |         preg_match("~($this->ldel)|(<[?]((php\s+|=)|\s+))|(<[%])|(<[?]xml\s+)|(<script\s+language\s*=\s*[\"']?\s*php\s*[\"']?\s*>)|([?][>])|([%][>])~i", | ||||||
|  |                    $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); | ||||||
|         if (isset($match[ 0 ][ 1 ])) { |         if (isset($match[ 0 ][ 1 ])) { | ||||||
|             $to = $match[ 0 ][ 1 ]; |             $to = $match[ 0 ][ 1 ]; | ||||||
|         } |         } | ||||||
| @@ -394,7 +420,13 @@ class Smarty_Internal_Templatelexer | |||||||
|     public function yylex2() |     public function yylex2() | ||||||
|     { |     { | ||||||
|         if (!isset($this->yy_global_pattern2)) { |         if (!isset($this->yy_global_pattern2)) { | ||||||
|             $this->yy_global_pattern2 = "/\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*[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/](?:(?!block)[0-9]*[a-zA-Z_]\\w*)\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*)/isS"; |             $this->yy_global_pattern2 = | ||||||
|  |                 "/\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*[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . | ||||||
|  |                 "\\s*[\/](?:(?!block)[0-9]*[a-zA-Z_]\\w*)\\s*" . $this->rdel . ")|\G(" . $this->ldel . | ||||||
|  |                 "\\s*[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . | ||||||
|  |                 $this->ldel . "\\s*)/isS"; | ||||||
|         } |         } | ||||||
|         if ($this->counter >= strlen($this->data)) { |         if ($this->counter >= strlen($this->data)) { | ||||||
|             return false; // end of input |             return false; // end of input | ||||||
| @@ -409,7 +441,8 @@ class Smarty_Internal_Templatelexer | |||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |                     $yymatches = array_filter($yymatches, 'strlen'); | ||||||
|                 } |                 } | ||||||
|                 if (empty($yymatches)) { |                 if (empty($yymatches)) { | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state TAG'); |                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . | ||||||
|  |                                         substr($this->data, $this->counter, 5) . '... state TAG'); | ||||||
|                 } |                 } | ||||||
|                 next($yymatches); // skip global match |                 next($yymatches); // skip global match | ||||||
|                 $this->token = key($yymatches); // token number |                 $this->token = key($yymatches); // token number | ||||||
| @@ -495,7 +528,7 @@ class Smarty_Internal_Templatelexer | |||||||
|  |  | ||||||
|         if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] == self::TEXT) { |         if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] == self::TEXT) { | ||||||
|             $this->yypopstate(); |             $this->yypopstate(); | ||||||
|             $this->token = Smarty_Internal_Templateparser::TP_SIMPLEOUTPUT; |             $this->token = Smarty_Internal_Templateparser::TP_SIMPELOUTPUT; | ||||||
|             $this->taglineno = $this->line; |             $this->taglineno = $this->line; | ||||||
|         } else { |         } else { | ||||||
|             $this->value = $this->smarty->left_delimiter; |             $this->value = $this->smarty->left_delimiter; | ||||||
| @@ -524,7 +557,8 @@ class Smarty_Internal_Templatelexer | |||||||
|     public function yylex3() |     public function yylex3() | ||||||
|     { |     { | ||||||
|         if (!isset($this->yy_global_pattern3)) { |         if (!isset($this->yy_global_pattern3)) { | ||||||
|             $this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\\s+(not\\s+)?(odd|even|div)\\s+by))\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\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(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G(" . $this->ldel . "\\s*)|\G([\S\s])/isS"; |             $this->yy_global_pattern3 = "/\G(\\s*" . $this->rdel . ")|\G(" . $this->ldel . | ||||||
|  |                 "\\s*)|\G([\"])|\G('[^'\\\\]*(?:\\\\.[^'\\\\]*)*')|\G([$]smarty\\.block\\.(child|parent))|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(\\s+is\\s+in\\s+)|\G(\\s+as\\s+)|\G(\\s+to\\s+)|\G(\\s+step\\s+)|\G(\\s+instanceof\\s+)|\G(\\s*(([!=][=]{1,2})|([<][=>]?)|([>][=]?)|[&|]{2})\\s*)|\G(\\s+(eq|ne|neq|gt|ge|gte|lt|le|lte|mod|and|or|xor|(is\\s+(not\\s+)?(odd|even|div)\\s+by))\\s+)|\G(\\s+is\\s+(not\\s+)?(odd|even))|\G(([!]\\s*)|(not\\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(([+]|[-]){2})|\G(\\s*([+]|[-])\\s*)|\G(\\s*([*]{1,2}|[%\/^&]|[<>]{2})\\s*)|\G([@])|\G([#])|\G(\\s+[0-9]*[a-zA-Z_][a-zA-Z0-9_\-:]*\\s*[=]\\s*)|\G(([0-9]*[a-zA-Z_]\\w*)?(\\\\[0-9]*[a-zA-Z_]\\w*)+)|\G([0-9]*[a-zA-Z_]\\w*)|\G(\\d+)|\G([`])|\G([|])|\G([.])|\G(\\s*[,]\\s*)|\G(\\s*[;]\\s*)|\G([:]{2})|\G(\\s*[:]\\s*)|\G(\\s*[?]\\s*)|\G(0[xX][0-9a-fA-F]+)|\G(\\s+)|\G([\S\s])/isS"; | ||||||
|         } |         } | ||||||
|         if ($this->counter >= strlen($this->data)) { |         if ($this->counter >= strlen($this->data)) { | ||||||
|             return false; // end of input |             return false; // end of input | ||||||
| @@ -539,7 +573,8 @@ class Smarty_Internal_Templatelexer | |||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |                     $yymatches = array_filter($yymatches, 'strlen'); | ||||||
|                 } |                 } | ||||||
|                 if (empty($yymatches)) { |                 if (empty($yymatches)) { | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state TAGBODY     '); |                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . | ||||||
|  |                                         substr($this->data, $this->counter, 5) . '... state TAGBODY'); | ||||||
|                 } |                 } | ||||||
|                 next($yymatches); // skip global match |                 next($yymatches); // skip global match | ||||||
|                 $this->token = key($yymatches); // token number |                 $this->token = key($yymatches); // token number | ||||||
| @@ -582,172 +617,187 @@ class Smarty_Internal_Templatelexer | |||||||
|     function yy_r3_2() |     function yy_r3_2() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_QUOTE; |         if ($this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ? | ||||||
|         $this->yypushstate(self::DOUBLEQUOTEDSTRING); |             strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false | ||||||
|  |         ) { | ||||||
|  |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|  |         } else { | ||||||
|  |             $this->yypushstate(self::TAG); | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_3() |     function yy_r3_3() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; |         $this->token = Smarty_Internal_Templateparser::TP_QUOTE; | ||||||
|  |         $this->yypushstate(self::DOUBLEQUOTEDSTRING); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_4() |     function yy_r3_4() | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         $this->token = Smarty_Internal_Templateparser::TP_SINGLEQUOTESTRING; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     function yy_r3_5() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; |         $this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT; | ||||||
|         $this->taglineno = $this->line; |         $this->taglineno = $this->line; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_6() |     function yy_r3_7() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; |         $this->token = Smarty_Internal_Templateparser::TP_DOLLARID; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_7() |     function yy_r3_8() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; |         $this->token = Smarty_Internal_Templateparser::TP_DOLLAR; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_8() |     function yy_r3_9() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_ISIN; |         $this->token = Smarty_Internal_Templateparser::TP_ISIN; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_9() |     function yy_r3_10() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_AS; |         $this->token = Smarty_Internal_Templateparser::TP_AS; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_10() |     function yy_r3_11() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_TO; |         $this->token = Smarty_Internal_Templateparser::TP_TO; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_11() |     function yy_r3_12() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_STEP; |         $this->token = Smarty_Internal_Templateparser::TP_STEP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_12() |     function yy_r3_13() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; |         $this->token = Smarty_Internal_Templateparser::TP_INSTANCEOF; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_13() |     function yy_r3_14() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_LOGOP; |         $this->token = Smarty_Internal_Templateparser::TP_LOGOP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_18() |     function yy_r3_19() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_TLOGOP; |         $this->token = Smarty_Internal_Templateparser::TP_TLOGOP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_23() |     function yy_r3_24() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND; |         $this->token = Smarty_Internal_Templateparser::TP_SINGLECOND; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_26() |     function yy_r3_27() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_NOT; |         $this->token = Smarty_Internal_Templateparser::TP_NOT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_29() |     function yy_r3_30() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; |         $this->token = Smarty_Internal_Templateparser::TP_TYPECAST; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_33() |     function yy_r3_34() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_OPENP; |         $this->token = Smarty_Internal_Templateparser::TP_OPENP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_34() |     function yy_r3_35() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; |         $this->token = Smarty_Internal_Templateparser::TP_CLOSEP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_35() |     function yy_r3_36() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_OPENB; |         $this->token = Smarty_Internal_Templateparser::TP_OPENB; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_36() |     function yy_r3_37() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; |         $this->token = Smarty_Internal_Templateparser::TP_CLOSEB; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_37() |     function yy_r3_38() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_PTR; |         $this->token = Smarty_Internal_Templateparser::TP_PTR; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_38() |     function yy_r3_39() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_APTR; |         $this->token = Smarty_Internal_Templateparser::TP_APTR; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_39() |     function yy_r3_40() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_EQUAL; |         $this->token = Smarty_Internal_Templateparser::TP_EQUAL; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_40() |     function yy_r3_41() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_INCDEC; |         $this->token = Smarty_Internal_Templateparser::TP_INCDEC; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_42() |     function yy_r3_43() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; |         $this->token = Smarty_Internal_Templateparser::TP_UNIMATH; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_44() |     function yy_r3_45() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_MATH; |         $this->token = Smarty_Internal_Templateparser::TP_MATH; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_46() |     function yy_r3_47() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_AT; |         $this->token = Smarty_Internal_Templateparser::TP_AT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_47() |     function yy_r3_48() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_HATCH; |         $this->token = Smarty_Internal_Templateparser::TP_HATCH; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_48() |     function yy_r3_49() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         // resolve conflicts with shorttag and right_delimiter starting with '=' |         // 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) { |         if (substr($this->data, $this->counter + strlen($this->value) - 1, $this->rdel_length) == | ||||||
|  |             $this->smarty->right_delimiter | ||||||
|  |         ) { | ||||||
|             preg_match("~\s+~", $this->value, $match); |             preg_match("~\s+~", $this->value, $match); | ||||||
|             $this->value = $match[ 0 ]; |             $this->value = $match[ 0 ]; | ||||||
|             $this->token = Smarty_Internal_Templateparser::TP_SPACE; |             $this->token = Smarty_Internal_Templateparser::TP_SPACE; | ||||||
| @@ -756,94 +806,83 @@ class Smarty_Internal_Templatelexer | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_49() |     function yy_r3_50() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; |         $this->token = Smarty_Internal_Templateparser::TP_NAMESPACE; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_52() |     function yy_r3_53() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_ID; |         $this->token = Smarty_Internal_Templateparser::TP_ID; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_53() |     function yy_r3_54() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_INTEGER; |         $this->token = Smarty_Internal_Templateparser::TP_INTEGER; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_54() |     function yy_r3_55() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; |         $this->token = Smarty_Internal_Templateparser::TP_BACKTICK; | ||||||
|         $this->yypopstate(); |         $this->yypopstate(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_55() |     function yy_r3_56() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_VERT; |         $this->token = Smarty_Internal_Templateparser::TP_VERT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_56() |     function yy_r3_57() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_DOT; |         $this->token = Smarty_Internal_Templateparser::TP_DOT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_57() |     function yy_r3_58() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_COMMA; |         $this->token = Smarty_Internal_Templateparser::TP_COMMA; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_58() |     function yy_r3_59() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; |         $this->token = Smarty_Internal_Templateparser::TP_SEMICOLON; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_59() |     function yy_r3_60() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; |         $this->token = Smarty_Internal_Templateparser::TP_DOUBLECOLON; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_60() |     function yy_r3_61() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_COLON; |         $this->token = Smarty_Internal_Templateparser::TP_COLON; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_61() |     function yy_r3_62() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_QMARK; |         $this->token = Smarty_Internal_Templateparser::TP_QMARK; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_62() |     function yy_r3_63() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_HEX; |         $this->token = Smarty_Internal_Templateparser::TP_HEX; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_63() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_SPACE; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function yy_r3_64() |     function yy_r3_64() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         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_SPACE; | ||||||
|             $this->token = Smarty_Internal_Templateparser::TP_TEXT; |  | ||||||
|         } else { |  | ||||||
|             $this->yypushstate(self::TAG); |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function yy_r3_65() |     function yy_r3_65() | ||||||
| @@ -855,7 +894,9 @@ class Smarty_Internal_Templatelexer | |||||||
|     public function yylex4() |     public function yylex4() | ||||||
|     { |     { | ||||||
|         if (!isset($this->yy_global_pattern4)) { |         if (!isset($this->yy_global_pattern4)) { | ||||||
|             $this->yy_global_pattern4 = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . $this->rdel . ")|\G([\S\s])/isS"; |             $this->yy_global_pattern4 = | ||||||
|  |                 "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . | ||||||
|  |                 $this->rdel . ")|\G([\S\s])/isS"; | ||||||
|         } |         } | ||||||
|         if ($this->counter >= strlen($this->data)) { |         if ($this->counter >= strlen($this->data)) { | ||||||
|             return false; // end of input |             return false; // end of input | ||||||
| @@ -870,7 +911,8 @@ class Smarty_Internal_Templatelexer | |||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |                     $yymatches = array_filter($yymatches, 'strlen'); | ||||||
|                 } |                 } | ||||||
|                 if (empty($yymatches)) { |                 if (empty($yymatches)) { | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state LITERAL'); |                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . | ||||||
|  |                                         substr($this->data, $this->counter, 5) . '... state LITERAL'); | ||||||
|                 } |                 } | ||||||
|                 next($yymatches); // skip global match |                 next($yymatches); // skip global match | ||||||
|                 $this->token = key($yymatches); // token number |                 $this->token = key($yymatches); // token number | ||||||
| @@ -926,7 +968,8 @@ class Smarty_Internal_Templatelexer | |||||||
|     { |     { | ||||||
|  |  | ||||||
|         $to = strlen($this->data); |         $to = strlen($this->data); | ||||||
|         preg_match("~{$this->ldel}[/]?literal{$this->rdel}~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |         preg_match("~{$this->ldel}[/]?literal{$this->rdel}~i", $this->data, $match, PREG_OFFSET_CAPTURE, | ||||||
|  |                    $this->counter); | ||||||
|         if (isset($match[ 0 ][ 1 ])) { |         if (isset($match[ 0 ][ 1 ])) { | ||||||
|             $to = $match[ 0 ][ 1 ]; |             $to = $match[ 0 ][ 1 ]; | ||||||
|         } else { |         } else { | ||||||
| @@ -939,7 +982,12 @@ class Smarty_Internal_Templatelexer | |||||||
|     public function yylex5() |     public function yylex5() | ||||||
|     { |     { | ||||||
|         if (!isset($this->yy_global_pattern5)) { |         if (!isset($this->yy_global_pattern5)) { | ||||||
|             $this->yy_global_pattern5 = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*)|\G(" . $this->ldel . "\\s*)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/isS"; |             $this->yy_global_pattern5 = | ||||||
|  |                 "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . | ||||||
|  |                 $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/])|\G(" . $this->ldel . "\\s*[0-9]*[a-zA-Z_]\\w*)|\G(" . | ||||||
|  |                 $this->ldel . | ||||||
|  |                 "\\s*)|\G([\"])|\G([`][$])|\G([$][0-9]*[a-zA-Z_]\\w*)|\G([$])|\G(([^\"\\\\]*?)((?:\\\\.[^\"\\\\]*?)*?)(?=(" . | ||||||
|  |                 $this->ldel . "|\\$|`\\$|\")))|\G([\S\s])/isS"; | ||||||
|         } |         } | ||||||
|         if ($this->counter >= strlen($this->data)) { |         if ($this->counter >= strlen($this->data)) { | ||||||
|             return false; // end of input |             return false; // end of input | ||||||
| @@ -954,7 +1002,8 @@ class Smarty_Internal_Templatelexer | |||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |                     $yymatches = array_filter($yymatches, 'strlen'); | ||||||
|                 } |                 } | ||||||
|                 if (empty($yymatches)) { |                 if (empty($yymatches)) { | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); |                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . | ||||||
|  |                                         substr($this->data, $this->counter, 5) . '... state DOUBLEQUOTEDSTRING'); | ||||||
|                 } |                 } | ||||||
|                 next($yymatches); // skip global match |                 next($yymatches); // skip global match | ||||||
|                 $this->token = key($yymatches); // token number |                 $this->token = key($yymatches); // token number | ||||||
| @@ -1002,7 +1051,9 @@ class Smarty_Internal_Templatelexer | |||||||
|     function yy_r5_3() |     function yy_r5_3() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { |         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; |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|         } else { |         } else { | ||||||
|             $this->yypushstate(self::TAG); |             $this->yypushstate(self::TAG); | ||||||
| @@ -1013,7 +1064,9 @@ class Smarty_Internal_Templatelexer | |||||||
|     function yy_r5_4() |     function yy_r5_4() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { |         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; |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|         } else { |         } else { | ||||||
|             $this->yypushstate(self::TAG); |             $this->yypushstate(self::TAG); | ||||||
| @@ -1024,7 +1077,9 @@ class Smarty_Internal_Templatelexer | |||||||
|     function yy_r5_5() |     function yy_r5_5() | ||||||
|     { |     { | ||||||
|  |  | ||||||
|         if ($this->smarty->auto_literal && isset($this->value[$this->ldel_length]) ? strpos(" \n\t\r", $this->value[$this->ldel_length]) !== false : false) { |         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; |             $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|         } else { |         } else { | ||||||
|             $this->token = Smarty_Internal_Templateparser::TP_LDEL; |             $this->token = Smarty_Internal_Templateparser::TP_LDEL; | ||||||
| @@ -1075,294 +1130,6 @@ class Smarty_Internal_Templatelexer | |||||||
|         $this->token = Smarty_Internal_Templateparser::TP_TEXT; |         $this->token = Smarty_Internal_Templateparser::TP_TEXT; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public function yylex6() |  | ||||||
|     { |  | ||||||
|         if (!isset($this->yy_global_pattern6)) { |  | ||||||
|             $this->yy_global_pattern6 = "/\G(" . $this->ldel . "\\s*strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]strip\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*block)|\G([\S\s])/isS"; |  | ||||||
|         } |  | ||||||
|         if ($this->counter >= strlen($this->data)) { |  | ||||||
|             return false; // end of input |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         do { |  | ||||||
|             if (preg_match($this->yy_global_pattern6, $this->data, $yymatches, null, $this->counter)) { |  | ||||||
|                 $yysubmatches = $yymatches; |  | ||||||
|                 if (strlen($yysubmatches[0]) < 200) { |  | ||||||
|                     $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |  | ||||||
|                 } else { |  | ||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |  | ||||||
|                 } |  | ||||||
|                 if (empty($yymatches)) { |  | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state CHILDBODY'); |  | ||||||
|                 } |  | ||||||
|                 next($yymatches); // skip global match |  | ||||||
|                 $this->token = key($yymatches); // token number |  | ||||||
|                 $this->value = current($yymatches); // token value |  | ||||||
|                 $r = $this->{'yy_r6_' . $this->token}(); |  | ||||||
|                 if ($r === null) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     // accept this token |  | ||||||
|                     return true; |  | ||||||
|                 } elseif ($r === true) { |  | ||||||
|                     // we have changed state |  | ||||||
|                     // process this token in the new state |  | ||||||
|                     return $this->yylex(); |  | ||||||
|                 } elseif ($r === false) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     if ($this->counter >= strlen($this->data)) { |  | ||||||
|                         return false; // end of input |  | ||||||
|                     } |  | ||||||
|                     // skip this token |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |  | ||||||
|             } |  | ||||||
|             break; |  | ||||||
|         } while (true); |  | ||||||
|     } // end function |  | ||||||
|  |  | ||||||
|     const CHILDBODY = 6; |  | ||||||
|  |  | ||||||
|     function yy_r6_1() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r6_2() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r6_3() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r6_4() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         $to = strlen($this->data); |  | ||||||
|         preg_match("~" . $this->ldel . "\s*(([/])?strip\s*" . $this->rdel . "|block\s+)~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |  | ||||||
|         if (isset($match[0][1])) { |  | ||||||
|             $to = $match[0][1]; |  | ||||||
|         } |  | ||||||
|         $this->value = substr($this->data, $this->counter, $to - $this->counter); |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public function yylex7() |  | ||||||
|     { |  | ||||||
|         if (!isset($this->yy_global_pattern7)) { |  | ||||||
|             $this->yy_global_pattern7 = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*block)|\G(" . $this->ldel . "\\s*[\/]block)|\G(" . $this->ldel . "\\s*[$]smarty\\.block\\.(child|parent))|\G([\S\s])/isS"; |  | ||||||
|         } |  | ||||||
|         if ($this->counter >= strlen($this->data)) { |  | ||||||
|             return false; // end of input |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         do { |  | ||||||
|             if (preg_match($this->yy_global_pattern7, $this->data, $yymatches, null, $this->counter)) { |  | ||||||
|                 $yysubmatches = $yymatches; |  | ||||||
|                 if (strlen($yysubmatches[0]) < 200) { |  | ||||||
|                     $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |  | ||||||
|                 } else { |  | ||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |  | ||||||
|                 } |  | ||||||
|                 if (empty($yymatches)) { |  | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state CHILDBLOCK'); |  | ||||||
|                 } |  | ||||||
|                 next($yymatches); // skip global match |  | ||||||
|                 $this->token = key($yymatches); // token number |  | ||||||
|                 $this->value = current($yymatches); // token value |  | ||||||
|                 $r = $this->{'yy_r7_' . $this->token}(); |  | ||||||
|                 if ($r === null) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     // accept this token |  | ||||||
|                     return true; |  | ||||||
|                 } elseif ($r === true) { |  | ||||||
|                     // we have changed state |  | ||||||
|                     // process this token in the new state |  | ||||||
|                     return $this->yylex(); |  | ||||||
|                 } elseif ($r === false) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     if ($this->counter >= strlen($this->data)) { |  | ||||||
|                         return false; // end of input |  | ||||||
|                     } |  | ||||||
|                     // skip this token |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |  | ||||||
|             } |  | ||||||
|             break; |  | ||||||
|         } while (true); |  | ||||||
|     } // end function |  | ||||||
|  |  | ||||||
|     const CHILDBLOCK = 7; |  | ||||||
|  |  | ||||||
|     function yy_r7_1() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; |  | ||||||
|             $this->yypushstate(self::CHILDLITERAL); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function yy_r7_2() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r7_3() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r7_4() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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_r7_6() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         $to = strlen($this->data); |  | ||||||
|         preg_match("~" . $this->ldel . "\s*(literal\s*" . $this->rdel . "|([/])?block(\s|" . $this->rdel . ")|[\$]smarty\.block\.(child|parent))~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); |  | ||||||
|         if (isset($match[0][1])) { |  | ||||||
|             $to = $match[0][1]; |  | ||||||
|         } |  | ||||||
|         $this->value = substr($this->data, $this->counter, $to - $this->counter); |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public function yylex8() |  | ||||||
|     { |  | ||||||
|         if (!isset($this->yy_global_pattern8)) { |  | ||||||
|             $this->yy_global_pattern8 = "/\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel . ")|\G(" . $this->ldel . "\\s*[\/]literal\\s*" . $this->rdel . ")|\G([\S\s])/isS"; |  | ||||||
|         } |  | ||||||
|         if ($this->counter >= strlen($this->data)) { |  | ||||||
|             return false; // end of input |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         do { |  | ||||||
|             if (preg_match($this->yy_global_pattern8, $this->data, $yymatches, null, $this->counter)) { |  | ||||||
|                 $yysubmatches = $yymatches; |  | ||||||
|                 if (strlen($yysubmatches[0]) < 200) { |  | ||||||
|                     $yymatches = preg_grep("/(.|\s)+/", $yysubmatches); |  | ||||||
|                 } else { |  | ||||||
|                     $yymatches = array_filter($yymatches, 'strlen'); |  | ||||||
|                 } |  | ||||||
|                 if (empty($yymatches)) { |  | ||||||
|                     throw new Exception('Error: lexing failed because a rule matched' . ' an empty string.  Input "' . substr($this->data, $this->counter, 5) . '... state CHILDLITERAL'); |  | ||||||
|                 } |  | ||||||
|                 next($yymatches); // skip global match |  | ||||||
|                 $this->token = key($yymatches); // token number |  | ||||||
|                 $this->value = current($yymatches); // token value |  | ||||||
|                 $r = $this->{'yy_r8_' . $this->token}(); |  | ||||||
|                 if ($r === null) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     // accept this token |  | ||||||
|                     return true; |  | ||||||
|                 } elseif ($r === true) { |  | ||||||
|                     // we have changed state |  | ||||||
|                     // process this token in the new state |  | ||||||
|                     return $this->yylex(); |  | ||||||
|                 } elseif ($r === false) { |  | ||||||
|                     $this->counter += strlen($this->value); |  | ||||||
|                     $this->line += substr_count($this->value, "\n"); |  | ||||||
|                     if ($this->counter >= strlen($this->data)) { |  | ||||||
|                         return false; // end of input |  | ||||||
|                     } |  | ||||||
|                     // skip this token |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
|             } else { |  | ||||||
|                 throw new Exception('Unexpected input at line' . $this->line . ': ' . $this->data[$this->counter]); |  | ||||||
|             } |  | ||||||
|             break; |  | ||||||
|         } while (true); |  | ||||||
|     } // end function |  | ||||||
|  |  | ||||||
|     const CHILDLITERAL = 8; |  | ||||||
|  |  | ||||||
|     function yy_r8_1() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; |  | ||||||
|             $this->yypushstate(self::CHILDLITERAL); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function yy_r8_2() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         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->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; |  | ||||||
|             $this->yypopstate(); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function yy_r8_3() |  | ||||||
|     { |  | ||||||
|  |  | ||||||
|         $to = strlen($this->data); |  | ||||||
|         preg_match("~{$this->ldel}[/]?literal\s*{$this->rdel}~i", $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"); |  | ||||||
|         } |  | ||||||
|         $this->value = substr($this->data, $this->counter, $to - $this->counter); |  | ||||||
|         $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|       |       | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -7,6 +7,7 @@ | |||||||
|  * @subpackage Utilities |  * @subpackage Utilities | ||||||
|  * @author     Uwe Tews |  * @author     Uwe Tews | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * TestInstall class |  * TestInstall class | ||||||
|  * |  * | ||||||
| @@ -19,7 +20,6 @@ class Smarty_Internal_TestInstall | |||||||
|      * diagnose Smarty setup |      * diagnose Smarty setup | ||||||
|      * If $errors is secified, the diagnostic report will be appended to the array, rather than being output. |      * 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 |      * @param  array $errors array to push results into rather than outputting them | ||||||
|      * |      * | ||||||
|      * @return bool   status, true if everything is fine, false else |      * @return bool   status, true if everything is fine, false else | ||||||
| @@ -47,7 +47,7 @@ class Smarty_Internal_TestInstall | |||||||
|                     if ($_stream_resolve_include_path) { |                     if ($_stream_resolve_include_path) { | ||||||
|                         $template_dir = stream_resolve_include_path($_template_dir); |                         $template_dir = stream_resolve_include_path($_template_dir); | ||||||
|                     } else { |                     } else { | ||||||
|                         $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir); |                         $template_dir = $smarty->ext->_getIncludePath->getIncludePath($_template_dir, null, $smarty); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if ($template_dir !== false) { |                     if ($template_dir !== false) { | ||||||
| @@ -58,7 +58,8 @@ class Smarty_Internal_TestInstall | |||||||
|                         continue; |                         continue; | ||||||
|                     } else { |                     } else { | ||||||
|                         $status = false; |                         $status = false; | ||||||
|                         $message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)"; |                         $message = | ||||||
|  |                             "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)"; | ||||||
|                         if ($errors === null) { |                         if ($errors === null) { | ||||||
|                             echo $message . ".\n"; |                             echo $message . ".\n"; | ||||||
|                         } else { |                         } else { | ||||||
| @@ -166,7 +167,7 @@ class Smarty_Internal_TestInstall | |||||||
|                     if ($_stream_resolve_include_path) { |                     if ($_stream_resolve_include_path) { | ||||||
|                         $plugin_dir = stream_resolve_include_path($_plugin_dir); |                         $plugin_dir = stream_resolve_include_path($_plugin_dir); | ||||||
|                     } else { |                     } else { | ||||||
|                         $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir); |                         $plugin_dir = $smarty->ext->_getIncludePath->getIncludePath($_plugin_dir, null, $smarty); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if ($plugin_dir !== false) { |                     if ($plugin_dir !== false) { | ||||||
| @@ -288,7 +289,6 @@ class Smarty_Internal_TestInstall | |||||||
|         // test if all registered config_dir are accessible |         // test if all registered config_dir are accessible | ||||||
|         foreach ($smarty->getConfigDir() as $config_dir) { |         foreach ($smarty->getConfigDir() as $config_dir) { | ||||||
|             $_config_dir = $config_dir; |             $_config_dir = $config_dir; | ||||||
|             $config_dir = realpath($config_dir); |  | ||||||
|             // resolve include_path or fail existence |             // resolve include_path or fail existence | ||||||
|             if (!$config_dir) { |             if (!$config_dir) { | ||||||
|                 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { |                 if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { | ||||||
| @@ -296,7 +296,7 @@ class Smarty_Internal_TestInstall | |||||||
|                     if ($_stream_resolve_include_path) { |                     if ($_stream_resolve_include_path) { | ||||||
|                         $config_dir = stream_resolve_include_path($_config_dir); |                         $config_dir = stream_resolve_include_path($_config_dir); | ||||||
|                     } else { |                     } else { | ||||||
|                         $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir); |                         $config_dir = $smarty->ext->_getIncludePath->getIncludePath($_config_dir, null, $smarty); | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if ($config_dir !== false) { |                     if ($config_dir !== false) { | ||||||
| @@ -358,106 +358,164 @@ class Smarty_Internal_TestInstall | |||||||
|         // test if sysplugins are available |         // test if sysplugins are available | ||||||
|         $source = SMARTY_SYSPLUGINS_DIR; |         $source = SMARTY_SYSPLUGINS_DIR; | ||||||
|         if (is_dir($source)) { |         if (is_dir($source)) { | ||||||
|             $expected = array( |             $expectedSysplugins = array('smartycompilerexception.php'                               => true, | ||||||
|                 "smarty_cacheresource.php"                                  => true, |                                         'smartyexception.php'                                       => true, | ||||||
|                 "smarty_cacheresource_custom.php"                           => true, |                                         'smarty_cacheresource.php'                                  => true, | ||||||
|                 "smarty_cacheresource_keyvaluestore.php"                    => true, |                                         'smarty_cacheresource_custom.php'                           => true, | ||||||
|                 "smarty_data.php"                                           => true, |                                         'smarty_cacheresource_keyvaluestore.php'                    => true, | ||||||
|                 "smarty_internal_cacheresource_file.php"                    => true, |                                         'smarty_data.php'                                           => true, | ||||||
|                 "smarty_internal_compile_append.php"                        => true, |                                         'smarty_internal_cacheresource_file.php'                    => true, | ||||||
|                 "smarty_internal_compile_assign.php"                        => true, |                                         'smarty_internal_compilebase.php'                           => true, | ||||||
|                 "smarty_internal_compile_block.php"                         => true, |                                         'smarty_internal_compile_append.php'                        => true, | ||||||
|                 "smarty_internal_compile_break.php"                         => true, |                                         'smarty_internal_compile_assign.php'                        => true, | ||||||
|                 "smarty_internal_compile_call.php"                          => true, |                                         'smarty_internal_compile_block.php'                         => true, | ||||||
|                 "smarty_internal_compile_capture.php"                       => true, |                                         'smarty_internal_compile_break.php'                         => true, | ||||||
|                 "smarty_internal_compile_config_load.php"                   => true, |                                         'smarty_internal_compile_call.php'                          => true, | ||||||
|                 "smarty_internal_compile_continue.php"                      => true, |                                         'smarty_internal_compile_capture.php'                       => true, | ||||||
|                 "smarty_internal_compile_debug.php"                         => true, |                                         'smarty_internal_compile_config_load.php'                   => true, | ||||||
|                 "smarty_internal_compile_eval.php"                          => true, |                                         'smarty_internal_compile_continue.php'                      => true, | ||||||
|                 "smarty_internal_compile_extends.php"                       => true, |                                         'smarty_internal_compile_debug.php'                         => true, | ||||||
|                 "smarty_internal_compile_for.php"                           => true, |                                         'smarty_internal_compile_eval.php'                          => true, | ||||||
|                 "smarty_internal_compile_foreach.php"                       => true, |                                         'smarty_internal_compile_extends.php'                       => true, | ||||||
|                 "smarty_internal_compile_function.php"                      => true, |                                         'smarty_internal_compile_for.php'                           => true, | ||||||
|                 "smarty_internal_compile_if.php"                            => true, |                                         'smarty_internal_compile_foreach.php'                       => true, | ||||||
|                 "smarty_internal_compile_include.php"                       => true, |                                         'smarty_internal_compile_function.php'                      => true, | ||||||
|                 "smarty_internal_compile_include_php.php"                   => true, |                                         'smarty_internal_compile_if.php'                            => true, | ||||||
|                 "smarty_internal_compile_insert.php"                        => true, |                                         'smarty_internal_compile_include.php'                       => true, | ||||||
|                 "smarty_internal_compile_ldelim.php"                        => true, |                                         'smarty_internal_compile_include_php.php'                   => true, | ||||||
|                 "smarty_internal_compile_nocache.php"                       => true, |                                         'smarty_internal_compile_insert.php'                        => true, | ||||||
|                 "smarty_internal_compile_private_block_plugin.php"          => true, |                                         'smarty_internal_compile_ldelim.php'                        => true, | ||||||
|                 "smarty_internal_compile_private_function_plugin.php"       => true, |                                         'smarty_internal_compile_nocache.php'                       => true, | ||||||
|                 "smarty_internal_compile_private_modifier.php"              => true, |                                         'smarty_internal_compile_private_block_plugin.php'          => true, | ||||||
|                 "smarty_internal_compile_private_object_block_function.php" => true, |                                         'smarty_internal_compile_private_foreachsection.php'        => true, | ||||||
|                 "smarty_internal_compile_private_object_function.php"       => true, |                                         'smarty_internal_compile_private_function_plugin.php'       => true, | ||||||
|                 "smarty_internal_compile_private_print_expression.php"      => true, |                                         'smarty_internal_compile_private_modifier.php'              => true, | ||||||
|                 "smarty_internal_compile_private_registered_block.php"      => true, |                                         'smarty_internal_compile_private_object_block_function.php' => true, | ||||||
|                 "smarty_internal_compile_private_registered_function.php"   => true, |                                         'smarty_internal_compile_private_object_function.php'       => true, | ||||||
|                 "smarty_internal_compile_private_special_variable.php"      => true, |                                         'smarty_internal_compile_private_php.php'                   => true, | ||||||
|                 "smarty_internal_compile_rdelim.php"                        => true, |                                         'smarty_internal_compile_private_print_expression.php'      => true, | ||||||
|                 "smarty_internal_compile_section.php"                       => true, |                                         'smarty_internal_compile_private_registered_block.php'      => true, | ||||||
|                 "smarty_internal_compile_setfilter.php"                     => true, |                                         'smarty_internal_compile_private_registered_function.php'   => true, | ||||||
|                 "smarty_internal_compile_while.php"                         => true, |                                         'smarty_internal_compile_private_special_variable.php'      => true, | ||||||
|                 "smarty_internal_compilebase.php"                           => true, |                                         'smarty_internal_compile_rdelim.php'                        => true, | ||||||
|                 "smarty_internal_config_file_compiler.php"                  => true, |                                         'smarty_internal_compile_section.php'                       => true, | ||||||
|                 "smarty_internal_configfilelexer.php"                       => true, |                                         'smarty_internal_compile_setfilter.php'                     => true, | ||||||
|                 "smarty_internal_configfileparser.php"                      => true, |                                         'smarty_internal_compile_shared_inheritance.php'            => true, | ||||||
|                 "smarty_internal_data.php"                                  => true, |                                         'smarty_internal_compile_while.php'                         => true, | ||||||
|                 "smarty_internal_debug.php"                                 => true, |                                         'smarty_internal_configfilelexer.php'                       => true, | ||||||
|                 "smarty_internal_extension_codeframe.php"                   => true, |                                         'smarty_internal_configfileparser.php'                      => true, | ||||||
|                 "smarty_internal_extension_config.php"                      => true, |                                         'smarty_internal_config_file_compiler.php'                  => true, | ||||||
|                 "smarty_internal_extension_defaulttemplatehandler.php"      => true, |                                         'smarty_internal_data.php'                                  => true, | ||||||
|                 "smarty_internal_filter_handler.php"                        => true, |                                         'smarty_internal_debug.php'                                 => true, | ||||||
|                 "smarty_internal_function_call_handler.php"                 => true, |                                         'smarty_internal_extension_clear.php'                       => true, | ||||||
|                 "smarty_internal_get_include_path.php"                      => true, |                                         'smarty_internal_extension_handler.php'                     => true, | ||||||
|                 "smarty_internal_nocache_insert.php"                        => true, |                                         'smarty_internal_method_addautoloadfilters.php'             => true, | ||||||
|                 "smarty_internal_parsetree.php"                             => true, |                                         'smarty_internal_method_adddefaultmodifiers.php'            => true, | ||||||
|                 "smarty_internal_parsetree_code.php"                        => true, |                                         'smarty_internal_method_append.php'                         => true, | ||||||
|                 "smarty_internal_parsetree_dq.php"                          => true, |                                         'smarty_internal_method_appendbyref.php'                    => true, | ||||||
|                 "smarty_internal_parsetree_dqcontent.php"                   => true, |                                         'smarty_internal_method_assignbyref.php'                    => true, | ||||||
|                 "smarty_internal_parsetree_tag.php"                         => true, |                                         'smarty_internal_method_assignglobal.php'                   => true, | ||||||
|                 "smarty_internal_parsetree_template.php"                    => true, |                                         'smarty_internal_method_clearallassign.php'                 => true, | ||||||
|                 "smarty_internal_parsetree_text.php"                        => true, |                                         'smarty_internal_method_clearallcache.php'                  => true, | ||||||
|                 "smarty_internal_resource_eval.php"                         => true, |                                         'smarty_internal_method_clearassign.php'                    => true, | ||||||
|                 "smarty_internal_resource_extends.php"                      => true, |                                         'smarty_internal_method_clearcache.php'                     => true, | ||||||
|                 "smarty_internal_resource_file.php"                         => true, |                                         'smarty_internal_method_clearcompiledtemplate.php'          => true, | ||||||
|                 "smarty_internal_resource_php.php"                          => true, |                                         'smarty_internal_method_clearconfig.php'                    => true, | ||||||
|                 "smarty_internal_resource_registered.php"                   => true, |                                         'smarty_internal_method_compileallconfig.php'               => true, | ||||||
|                 "smarty_internal_resource_stream.php"                       => true, |                                         'smarty_internal_method_compilealltemplates.php'            => true, | ||||||
|                 "smarty_internal_resource_string.php"                       => true, |                                         'smarty_internal_method_configload.php'                     => true, | ||||||
|                 "smarty_internal_smartytemplatecompiler.php"                => true, |                                         'smarty_internal_method_createdata.php'                     => true, | ||||||
|                 "smarty_internal_template.php"                              => true, |                                         'smarty_internal_method_getautoloadfilters.php'             => true, | ||||||
|                 "smarty_internal_templatebase.php"                          => true, |                                         'smarty_internal_method_getconfigvars.php'                  => true, | ||||||
|                 "smarty_internal_templatecompilerbase.php"                  => true, |                                         'smarty_internal_method_getdebugtemplate.php'               => true, | ||||||
|                 "smarty_internal_templatelexer.php"                         => true, |                                         'smarty_internal_method_getdefaultmodifiers.php'            => true, | ||||||
|                 "smarty_internal_templateparser.php"                        => true, |                                         'smarty_internal_method_getregisteredobject.php'            => true, | ||||||
|                 "smarty_internal_utility.php"                               => true, |                                         'smarty_internal_method_getstreamvariable.php'              => true, | ||||||
|                 "smarty_internal_write_file.php"                            => true, |                                         'smarty_internal_method_gettags.php'                        => true, | ||||||
|                 "smarty_resource.php"                                       => true, |                                         'smarty_internal_method_gettemplatevars.php'                => true, | ||||||
|                 "smarty_resource_custom.php"                                => true, |                                         'smarty_internal_method_loadfilter.php'                     => true, | ||||||
|                 "smarty_resource_recompiled.php"                            => true, |                                         'smarty_internal_method_loadplugin.php'                     => true, | ||||||
|                 "smarty_resource_uncompiled.php"                            => true, |                                         'smarty_internal_method_mustcompile.php'                    => true, | ||||||
|                 "smarty_security.php"                                       => true, |                                         'smarty_internal_method_registercacheresource.php'          => true, | ||||||
|                 "smarty_template_cached.php"                                => true, |                                         'smarty_internal_method_registerclass.php'                  => true, | ||||||
|                 "smarty_template_compiled.php"                              => true, |                                         'smarty_internal_method_registerdefaultconfighandler.php'   => true, | ||||||
|                 "smarty_template_config.php"                                => true, |                                         'smarty_internal_method_registerdefaultpluginhandler.php'   => true, | ||||||
|                 "smarty_template_source.php"                                => true, |                                         'smarty_internal_method_registerdefaulttemplatehandler.php' => true, | ||||||
|                 "smarty_undefined_variable.php"                             => true, |                                         'smarty_internal_method_registerfilter.php'                 => true, | ||||||
|                 "smarty_variable.php"                                       => true, |                                         'smarty_internal_method_registerobject.php'                 => true, | ||||||
|                 "smartycompilerexception.php"                               => true, |                                         'smarty_internal_method_registerplugin.php'                 => true, | ||||||
|                 "smartyexception.php"                                       => true, |                                         'smarty_internal_method_registerresource.php'               => true, | ||||||
|             ); |                                         'smarty_internal_method_setautoloadfilters.php'             => true, | ||||||
|  |                                         'smarty_internal_method_setdebugtemplate.php'               => true, | ||||||
|  |                                         'smarty_internal_method_setdefaultmodifiers.php'            => true, | ||||||
|  |                                         'smarty_internal_method_unloadfilter.php'                   => true, | ||||||
|  |                                         'smarty_internal_method_unregistercacheresource.php'        => true, | ||||||
|  |                                         'smarty_internal_method_unregisterfilter.php'               => true, | ||||||
|  |                                         'smarty_internal_method_unregisterobject.php'               => true, | ||||||
|  |                                         'smarty_internal_method_unregisterplugin.php'               => true, | ||||||
|  |                                         'smarty_internal_method_unregisterresource.php'             => true, | ||||||
|  |                                         'smarty_internal_nocache_insert.php'                        => true, | ||||||
|  |                                         'smarty_internal_parsetree.php'                             => true, | ||||||
|  |                                         'smarty_internal_parsetree_code.php'                        => true, | ||||||
|  |                                         'smarty_internal_parsetree_dq.php'                          => true, | ||||||
|  |                                         'smarty_internal_parsetree_dqcontent.php'                   => true, | ||||||
|  |                                         'smarty_internal_parsetree_tag.php'                         => true, | ||||||
|  |                                         'smarty_internal_parsetree_template.php'                    => true, | ||||||
|  |                                         'smarty_internal_parsetree_text.php'                        => true, | ||||||
|  |                                         'smarty_internal_resource_eval.php'                         => true, | ||||||
|  |                                         'smarty_internal_resource_extends.php'                      => true, | ||||||
|  |                                         'smarty_internal_resource_file.php'                         => true, | ||||||
|  |                                         'smarty_internal_resource_php.php'                          => true, | ||||||
|  |                                         'smarty_internal_resource_registered.php'                   => true, | ||||||
|  |                                         'smarty_internal_resource_stream.php'                       => true, | ||||||
|  |                                         'smarty_internal_resource_string.php'                       => true, | ||||||
|  |                                         'smarty_internal_runtime_cachemodify.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_codeframe.php'                     => true, | ||||||
|  |                                         'smarty_internal_runtime_filterhandler.php'                 => true, | ||||||
|  |                                         'smarty_internal_runtime_foreach.php'                       => true, | ||||||
|  |                                         'smarty_internal_runtime_getincludepath.php'                => true, | ||||||
|  |                                         'smarty_internal_runtime_hhvm.php'                          => true, | ||||||
|  |                                         'smarty_internal_runtime_inheritance.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_iscached.php'                      => true, | ||||||
|  |                                         'smarty_internal_runtime_subtemplate.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_tplfunction.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_updatecache.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_updatescope.php'                   => true, | ||||||
|  |                                         'smarty_internal_runtime_validatecompiled.php'              => true, | ||||||
|  |                                         'smarty_internal_runtime_var.php'                           => true, | ||||||
|  |                                         'smarty_internal_runtime_writefile.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_testinstall.php'                           => true, | ||||||
|  |                                         'smarty_internal_undefined.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, | ||||||
|  |                                         'smarty_template_cached.php'                                => true, | ||||||
|  |                                         'smarty_template_compiled.php'                              => true, | ||||||
|  |                                         'smarty_template_config.php'                                => true, | ||||||
|  |                                         'smarty_template_resource_base.php'                         => true, | ||||||
|  |                                         'smarty_template_source.php'                                => true, | ||||||
|  |                                         'smarty_undefined_variable.php'                             => true, | ||||||
|  |                                         'smarty_variable.php'                                       => true,); | ||||||
|             $iterator = new DirectoryIterator($source); |             $iterator = new DirectoryIterator($source); | ||||||
|             foreach ($iterator as $file) { |             foreach ($iterator as $file) { | ||||||
|                 if (!$file->isDot()) { |                 if (!$file->isDot()) { | ||||||
|                     $filename = $file->getFilename(); |                     $filename = $file->getFilename(); | ||||||
|                     if (isset($expected[$filename])) { |                     if (isset($expectedSysplugins[$filename])) { | ||||||
|                         unset($expected[$filename]); |                         unset($expectedSysplugins[$filename]); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if ($expected) { |             if ($expectedSysplugins) { | ||||||
|                 $status = false; |                 $status = false; | ||||||
|                 $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected)); |                 $message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expectedSysplugins)); | ||||||
|                 if ($errors === null) { |                 if ($errors === null) { | ||||||
|                     echo $message . ".\n"; |                     echo $message . ".\n"; | ||||||
|                 } else { |                 } else { | ||||||
| @@ -482,67 +540,43 @@ class Smarty_Internal_TestInstall | |||||||
|         // test if core plugins are available |         // test if core plugins are available | ||||||
|         $source = SMARTY_PLUGINS_DIR; |         $source = SMARTY_PLUGINS_DIR; | ||||||
|         if (is_dir($source)) { |         if (is_dir($source)) { | ||||||
|             $expected = array( |             $expectedPlugins = | ||||||
|                 "block.textformat.php"                  => true, |                 array('block.textformat.php'                  => true, 'function.counter.php' => true, | ||||||
|                 "function.counter.php"                  => true, |                       'function.cycle.php'                    => true, 'function.fetch.php' => true, | ||||||
|                 "function.cycle.php"                    => true, |                       'function.html_checkboxes.php'          => true, 'function.html_image.php' => true, | ||||||
|                 "function.fetch.php"                    => true, |                       'function.html_options.php'             => true, 'function.html_radios.php' => true, | ||||||
|                 "function.html_checkboxes.php"          => true, |                       'function.html_select_date.php'         => true, 'function.html_select_time.php' => true, | ||||||
|                 "function.html_image.php"               => true, |                       'function.html_table.php'               => true, 'function.mailto.php' => true, | ||||||
|                 "function.html_options.php"             => true, |                       'function.math.php'                     => true, 'modifier.capitalize.php' => true, | ||||||
|                 "function.html_radios.php"              => true, |                       'modifier.date_format.php'              => true, 'modifier.debug_print_var.php' => true, | ||||||
|                 "function.html_select_date.php"         => true, |                       'modifier.escape.php'                   => true, 'modifier.regex_replace.php' => true, | ||||||
|                 "function.html_select_time.php"         => true, |                       'modifier.replace.php'                  => true, 'modifier.spacify.php' => true, | ||||||
|                 "function.html_table.php"               => true, |                       'modifier.truncate.php'                 => true, 'modifiercompiler.cat.php' => true, | ||||||
|                 "function.mailto.php"                   => true, |                       'modifiercompiler.count_characters.php' => true, 'modifiercompiler.count_paragraphs.php' => true, | ||||||
|                 "function.math.php"                     => true, |                       'modifiercompiler.count_sentences.php'  => true, 'modifiercompiler.count_words.php' => true, | ||||||
|                 "modifier.capitalize.php"               => true, |                       'modifiercompiler.default.php'          => true, 'modifiercompiler.escape.php' => true, | ||||||
|                 "modifier.date_format.php"              => true, |                       'modifiercompiler.from_charset.php'     => true, 'modifiercompiler.indent.php' => true, | ||||||
|                 "modifier.debug_print_var.php"          => true, |                       'modifiercompiler.lower.php'            => true, 'modifiercompiler.noprint.php' => true, | ||||||
|                 "modifier.escape.php"                   => true, |                       'modifiercompiler.string_format.php'    => true, 'modifiercompiler.strip.php' => true, | ||||||
|                 "modifier.regex_replace.php"            => true, |                       'modifiercompiler.strip_tags.php'       => true, 'modifiercompiler.to_charset.php' => true, | ||||||
|                 "modifier.replace.php"                  => true, |                       'modifiercompiler.unescape.php'         => true, 'modifiercompiler.upper.php' => true, | ||||||
|                 "modifier.spacify.php"                  => true, |                       'modifiercompiler.wordwrap.php'         => true, 'outputfilter.trimwhitespace.php' => true, | ||||||
|                 "modifier.truncate.php"                 => true, |                       'shared.escape_special_chars.php'       => true, 'shared.literal_compiler_param.php' => true, | ||||||
|                 "modifiercompiler.cat.php"              => true, |                       'shared.make_timestamp.php'             => true, 'shared.mb_str_replace.php' => true, | ||||||
|                 "modifiercompiler.count_characters.php" => true, |                       'shared.mb_unicode.php'                 => true, 'shared.mb_wordwrap.php' => true, | ||||||
|                 "modifiercompiler.count_paragraphs.php" => true, |                       'variablefilter.htmlspecialchars.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); |             $iterator = new DirectoryIterator($source); | ||||||
|             foreach ($iterator as $file) { |             foreach ($iterator as $file) { | ||||||
|                 if (!$file->isDot()) { |                 if (!$file->isDot()) { | ||||||
|                     $filename = $file->getFilename(); |                     $filename = $file->getFilename(); | ||||||
|                     if (isset($expected[$filename])) { |                     if (isset($expectedPlugins[$filename])) { | ||||||
|                         unset($expected[$filename]); |                         unset($expectedPlugins[$filename]); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if ($expected) { |             if ($expectedPlugins) { | ||||||
|                 $status = false; |                 $status = false; | ||||||
|                 $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected)); |                 $message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expectedPlugins)); | ||||||
|                 if ($errors === null) { |                 if ($errors === null) { | ||||||
|                     echo $message . ".\n"; |                     echo $message . ".\n"; | ||||||
|                 } else { |                 } else { | ||||||
|   | |||||||
| @@ -1,303 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Project:     Smarty: the PHP compiling template engine |  | ||||||
|  * File:        smarty_internal_utility.php |  | ||||||
|  * SVN:         $Id: $ |  | ||||||
|  * This library is free software; you can redistribute it and/or |  | ||||||
|  * modify it under the terms of the GNU Lesser General Public |  | ||||||
|  * License as published by the Free Software Foundation; either |  | ||||||
|  * version 2.1 of the License, or (at your option) any later version. |  | ||||||
|  * This library is distributed in the hope that it will be useful, |  | ||||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |  | ||||||
|  * Lesser General Public License for more details. |  | ||||||
|  * You should have received a copy of the GNU Lesser General Public |  | ||||||
|  * License along with this library; if not, write to the Free Software |  | ||||||
|  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA |  | ||||||
|  * For questions, help, comments, discussion, etc., please join the |  | ||||||
|  * Smarty mailing list. Send a blank e-mail to |  | ||||||
|  * smarty-discussion-subscribe@googlegroups.com |  | ||||||
|  * |  | ||||||
|  * @link       http://www.smarty.net/ |  | ||||||
|  * @copyright  2008 New Digital Group, Inc. |  | ||||||
|  * @author     Monte Ohrt <monte at ohrt dot com> |  | ||||||
|  * @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 '<br>', $_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(), "<br><br>"; |  | ||||||
|                     $_error_count ++; |  | ||||||
|                 } |  | ||||||
|                 // free memory |  | ||||||
|                 $smarty->template_objects = array(); |  | ||||||
|                 $_tpl->smarty->template_objects = array(); |  | ||||||
|                 $_tpl = null; |  | ||||||
|                 if ($max_errors !== null && $_error_count == $max_errors) { |  | ||||||
|                     echo '<br><br>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 '<br>', $_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(), "<br><br>"; |  | ||||||
|                     $_error_count ++; |  | ||||||
|                 } |  | ||||||
|                 if ($max_errors !== null && $_error_count == $max_errors) { |  | ||||||
|                     echo '<br><br>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()) . '/'; |  | ||||||
|         if ($_compile_dir == '/') { //We should never want to delete this! |  | ||||||
|             return 0; |  | ||||||
|         } |  | ||||||
|         $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null; |  | ||||||
|         $_dir_sep = $smarty->use_sub_dirs ? '/' : '^'; |  | ||||||
|         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 = str_replace('\\', '/', $_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 = str_replace('\\', '/', (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]) && $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) |  | ||||||
|                         || (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 $template |  | ||||||
|      * |  | ||||||
|      * @throws Exception |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @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; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,88 +0,0 @@ | |||||||
| <?php |  | ||||||
| /** |  | ||||||
|  * Smarty write file plugin |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  * @author     Monte Ohrt |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Smarty Internal Write File Class |  | ||||||
|  * |  | ||||||
|  * @package    Smarty |  | ||||||
|  * @subpackage PluginsInternal |  | ||||||
|  */ |  | ||||||
| class Smarty_Internal_Write_File |  | ||||||
| { |  | ||||||
|     /** |  | ||||||
|      * Writes file in a safe way to disk |  | ||||||
|      * |  | ||||||
|      * @param  string $_filepath complete filepath |  | ||||||
|      * @param  string $_contents file content |  | ||||||
|      * @param  Smarty $smarty    smarty instance |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      * @return boolean true |  | ||||||
|      */ |  | ||||||
|     public function writeFile($_filepath, $_contents, Smarty $smarty) |  | ||||||
|     { |  | ||||||
|         $_error_reporting = error_reporting(); |  | ||||||
|         error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING); |  | ||||||
|         if ($smarty->_file_perms !== null) { |  | ||||||
|             $old_umask = umask(0); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         $_dirpath = dirname($_filepath); |  | ||||||
|         // if subdirs, create dir structure |  | ||||||
|         if ($_dirpath !== '.' && !file_exists($_dirpath)) { |  | ||||||
|             mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // write to tmp file, then move to overt file lock race condition |  | ||||||
|         $_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true)); |  | ||||||
|         if (!file_put_contents($_tmp_file, $_contents)) { |  | ||||||
|             error_reporting($_error_reporting); |  | ||||||
|             throw new SmartyException("unable to write file {$_tmp_file}"); |  | ||||||
|        } |  | ||||||
|  |  | ||||||
|         /* |  | ||||||
|          * Windows' rename() fails if the destination exists, |  | ||||||
|          * Linux' rename() properly handles the overwrite. |  | ||||||
|          * Simply unlink()ing a file might cause other processes |  | ||||||
|          * currently reading that file to fail, but linux' rename() |  | ||||||
|          * seems to be smart enough to handle that for us. |  | ||||||
|          */ |  | ||||||
|         if (Smarty::$_IS_WINDOWS) { |  | ||||||
|             // remove original file |  | ||||||
|             if (is_file($_filepath)) { |  | ||||||
|                 @unlink($_filepath); |  | ||||||
|             } |  | ||||||
|             // rename tmp file |  | ||||||
|             $success = @rename($_tmp_file, $_filepath); |  | ||||||
|         } else { |  | ||||||
|             // rename tmp file |  | ||||||
|             $success = @rename($_tmp_file, $_filepath); |  | ||||||
|             if (!$success) { |  | ||||||
|                 // remove original file |  | ||||||
|                 if (is_file($_filepath)) { |  | ||||||
|                     @unlink($_filepath); |  | ||||||
|                 } |  | ||||||
|                 // rename tmp file |  | ||||||
|                 $success = @rename($_tmp_file, $_filepath); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (!$success) { |  | ||||||
|             error_reporting($_error_reporting); |  | ||||||
|             throw new SmartyException("unable to write file {$_filepath}"); |  | ||||||
|         } |  | ||||||
|         if ($smarty->_file_perms !== null) { |  | ||||||
|             // set file permissions |  | ||||||
|             chmod($_filepath, $smarty->_file_perms); |  | ||||||
|             umask($old_umask); |  | ||||||
|         } |  | ||||||
|         error_reporting($_error_reporting); |  | ||||||
|  |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -29,37 +29,25 @@ abstract class Smarty_Resource | |||||||
|      * @var boolean |      * @var boolean | ||||||
|      */ |      */ | ||||||
|     public $recompiled = false; |     public $recompiled = false; | ||||||
|     /** |  | ||||||
|      * resource handler object |  | ||||||
|      * |  | ||||||
|      * @var Smarty_Resource |  | ||||||
|      */ |  | ||||||
|     public $handler = null; |  | ||||||
|     /** |  | ||||||
|      * cache for Smarty_Template_Source instances |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public static $sources = array(); |  | ||||||
|     /** |  | ||||||
|      * cache for Smarty_Template_Compiled instances |  | ||||||
|      * |  | ||||||
|      * @var array |  | ||||||
|      */ |  | ||||||
|     public static $compileds = array(); |  | ||||||
|     /** |     /** | ||||||
|      * resource types provided by the core |      * resource types provided by the core | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected static $sysplugins = array( |     public static $sysplugins = array('file'    => 'smarty_internal_resource_file.php', | ||||||
|         'file'    => 'smarty_internal_resource_file.php', |  | ||||||
|                                       'string'  => 'smarty_internal_resource_string.php', |                                       'string'  => 'smarty_internal_resource_string.php', | ||||||
|                                       'extends' => 'smarty_internal_resource_extends.php', |                                       'extends' => 'smarty_internal_resource_extends.php', | ||||||
|                                       'stream'  => 'smarty_internal_resource_stream.php', |                                       'stream'  => 'smarty_internal_resource_stream.php', | ||||||
|                                       'eval'    => 'smarty_internal_resource_eval.php', |                                       'eval'    => 'smarty_internal_resource_eval.php', | ||||||
|         'php'     => 'smarty_internal_resource_php.php' |                                       'php'     => 'smarty_internal_resource_php.php'); | ||||||
|     ); |  | ||||||
|  |     /** | ||||||
|  |      * Flag if resource does implement populateCompiledFilepath() method | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $hasCompiledHandler = false; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Name of the Class to compile this resource's contents with |      * Name of the Class to compile this resource's contents with | ||||||
| @@ -84,7 +72,6 @@ abstract class Smarty_Resource | |||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Load template's source into current template object |      * Load template's source into current template object | ||||||
|      * {@internal The loaded source is assigned to $_template->source->content directly.}} |  | ||||||
|      * |      * | ||||||
|      * @param  Smarty_Template_Source $source source object |      * @param  Smarty_Template_Source $source source object | ||||||
|      * |      * | ||||||
| @@ -123,9 +110,15 @@ abstract class Smarty_Resource | |||||||
|     public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) |     public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) | ||||||
|     { |     { | ||||||
|         if ($isConfig) { |         if ($isConfig) { | ||||||
|             return get_class($this) . '#' . $smarty->joined_config_dir . '#' . $resource_name; |             if (!isset($smarty->_joined_config_dir)) { | ||||||
|  |                 $smarty->getTemplateDir(null, true); | ||||||
|  |             } | ||||||
|  |             return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name; | ||||||
|         } else { |         } else { | ||||||
|             return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name; |             if (!isset($smarty->_joined_template_dir)) { | ||||||
|  |                 $smarty->getTemplateDir(); | ||||||
|  |             } | ||||||
|  |             return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -153,42 +146,32 @@ abstract class Smarty_Resource | |||||||
|     public static function load(Smarty $smarty, $type) |     public static function load(Smarty $smarty, $type) | ||||||
|     { |     { | ||||||
|         // try smarty's cache |         // try smarty's cache | ||||||
|         if (isset($smarty->_resource_handlers[$type])) { |         if (isset($smarty->_cache['resource_handlers'][$type])) { | ||||||
|             return $smarty->_resource_handlers[$type]; |             return $smarty->_cache['resource_handlers'][$type]; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // try registered resource |         // try registered resource | ||||||
|         if (isset($smarty->registered_resources[$type])) { |         if (isset($smarty->registered_resources[$type])) { | ||||||
|             if ($smarty->registered_resources[$type] instanceof Smarty_Resource) { |             return $smarty->_cache['resource_handlers'][$type] = | ||||||
|                 $smarty->_resource_handlers[$type] = $smarty->registered_resources[$type]; |                 $smarty->registered_resources[$type] instanceof Smarty_Resource ? $smarty->registered_resources[$type] : | ||||||
|             } else { |                     new Smarty_Internal_Resource_Registered(); | ||||||
|                 $smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Registered(); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             return $smarty->_resource_handlers[$type]; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // try sysplugins dir |         // try sysplugins dir | ||||||
|         if (isset(self::$sysplugins[$type])) { |         if (isset(self::$sysplugins[$type])) { | ||||||
|             $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); |             $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type); | ||||||
|             if (!class_exists($_resource_class, false)) { |             return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); | ||||||
|                 require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type]; |  | ||||||
|             } |  | ||||||
|             return $smarty->_resource_handlers[$type] = new $_resource_class(); |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // try plugins dir |         // try plugins dir | ||||||
|         $_resource_class = 'Smarty_Resource_' . ucfirst($type); |         $_resource_class = 'Smarty_Resource_' . ucfirst($type); | ||||||
|         if ($smarty->loadPlugin($_resource_class)) { |         if ($smarty->loadPlugin($_resource_class)) { | ||||||
|             if (class_exists($_resource_class, false)) { |             if (class_exists($_resource_class, false)) { | ||||||
|                 return $smarty->_resource_handlers[$type] = new $_resource_class(); |                 return $smarty->_cache['resource_handlers'][$type] = new $_resource_class(); | ||||||
|             } else { |             } else { | ||||||
|                 $smarty->registerResource($type, array( |                 $smarty->registerResource($type, | ||||||
|                     "smarty_resource_{$type}_source", |                                           array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp", | ||||||
|                     "smarty_resource_{$type}_timestamp", |                                                 "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted")); | ||||||
|                     "smarty_resource_{$type}_secure", |  | ||||||
|                     "smarty_resource_{$type}_trusted" |  | ||||||
|                 )); |  | ||||||
|                 // give it another try, now that the resource is registered properly |                 // give it another try, now that the resource is registered properly | ||||||
|                 return self::load($smarty, $type); |                 return self::load($smarty, $type); | ||||||
|             } |             } | ||||||
| @@ -201,7 +184,7 @@ abstract class Smarty_Resource | |||||||
|             if (is_object($smarty->security_policy)) { |             if (is_object($smarty->security_policy)) { | ||||||
|                 $smarty->security_policy->isTrustedStream($type); |                 $smarty->security_policy->isTrustedStream($type); | ||||||
|             } |             } | ||||||
|             return $smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Stream();; |             return $smarty->_cache['resource_handlers'][$type] = new Smarty_Internal_Resource_Stream(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         // TODO: try default_(template|config)_handler |         // TODO: try default_(template|config)_handler | ||||||
| @@ -229,38 +212,30 @@ abstract class Smarty_Resource | |||||||
|             // or single character before the colon is not a resource type, but part of the filepath |             // or single character before the colon is not a resource type, but part of the filepath | ||||||
|             $type = $default_resource; |             $type = $default_resource; | ||||||
|             $name = $resource_name; |             $name = $resource_name; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|         return array($name, $type); |         return array($name, $type); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * modify resource_name according to resource handlers specifications |  | ||||||
|      * |  | ||||||
|      * @param  Smarty $smarty        Smarty instance |  | ||||||
|      * @param  string $resource_name resource_name to make unique |  | ||||||
|      * |  | ||||||
|      * @return string unique resource name |  | ||||||
|      */ |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * modify template_resource according to resource handlers specifications |      * modify template_resource according to resource handlers specifications | ||||||
|      * |      * | ||||||
|      * @param  Smarty_Internal_template $template          Smarty instance |      * @param  \Smarty_Internal_Template|\Smarty $obj               Smarty instance | ||||||
|      * @param  string                            $template_resource template_resource to extract resource handler and name of |      * @param  string                            $template_resource template_resource to extract resource handler and name of | ||||||
|      * |      * | ||||||
|      * @return string unique resource name |      * @return string unique resource name | ||||||
|      */ |      */ | ||||||
|     public static function getUniqueTemplateName($template, $template_resource) |     public static function getUniqueTemplateName($obj, $template_resource) | ||||||
|     { |     { | ||||||
|         $smarty = isset($template->smarty) ? $template->smarty : $template; |         $smarty = $obj->_objType == 2 ? $obj->smarty : $obj; | ||||||
|         list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); |         list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type); | ||||||
|         // TODO: optimize for Smarty's internal resource types |         // TODO: optimize for Smarty's internal resource types | ||||||
|         $resource = Smarty_Resource::load($smarty, $type); |         $resource = Smarty_Resource::load($smarty, $type); | ||||||
|         // go relative to a given template? |         // go relative to a given template? | ||||||
|         $_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'); |         $_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'); | ||||||
|         if ($template instanceof Smarty_Internal_Template && $_file_is_dotted && ($template->source->type == 'file' || $template->parent->source->type == 'extends')) { |         if ($obj->_objType == 2 && $_file_is_dotted && | ||||||
|             $name = dirname($template->source->filepath) . DS . $name; |             ($obj->source->type == 'file' || $obj->parent->source->type == 'extends') | ||||||
|  |         ) { | ||||||
|  |             $name = dirname($obj->source->filepath) . DS . $name; | ||||||
|         } |         } | ||||||
|         return $resource->buildUniqueResourceName($smarty, $name); |         return $resource->buildUniqueResourceName($smarty, $name); | ||||||
|     } |     } | ||||||
| @@ -276,7 +251,8 @@ abstract class Smarty_Resource | |||||||
|      * |      * | ||||||
|      * @return Smarty_Template_Source   Source Object |      * @return Smarty_Template_Source   Source Object | ||||||
|      */ |      */ | ||||||
|     public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) |     public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, | ||||||
|  |                                   $template_resource = null) | ||||||
|     { |     { | ||||||
|         return Smarty_Template_Source::load($_template, $smarty, $template_resource); |         return Smarty_Template_Source::load($_template, $smarty, $template_resource); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -23,6 +23,13 @@ abstract class Smarty_Resource_Recompiled extends Smarty_Resource | |||||||
|      */ |      */ | ||||||
|     public $recompiled = true; |     public $recompiled = true; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Resource does implement populateCompiledFilepath() method | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $hasCompiledHandler = true; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * populate Compiled Object with compiled filepath |      * populate Compiled Object with compiled filepath | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -23,6 +23,13 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource | |||||||
|      */ |      */ | ||||||
|     public $uncompiled = true; |     public $uncompiled = true; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Resource does implement populateCompiledFilepath() method | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     public $hasCompiledHandler = true; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Render and output the template (without using the compiler) |      * Render and output the template (without using the compiler) | ||||||
|      * |      * | ||||||
|   | |||||||
| @@ -34,6 +34,7 @@ class Smarty_Security | |||||||
|      * @var integer |      * @var integer | ||||||
|      */ |      */ | ||||||
|     public $php_handling = Smarty::PHP_PASSTHRU; |     public $php_handling = Smarty::PHP_PASSTHRU; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is the list of template directories that are considered secure. |      * This is the list of template directories that are considered secure. | ||||||
|      * $template_dir is in this list implicitly. |      * $template_dir is in this list implicitly. | ||||||
| @@ -41,6 +42,7 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $secure_dir = array(); |     public $secure_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of directories where trusted php scripts reside. |      * This is an array of directories where trusted php scripts reside. | ||||||
|      * {@link $security} is disabled during their inclusion/execution. |      * {@link $security} is disabled during their inclusion/execution. | ||||||
| @@ -48,18 +50,21 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $trusted_dir = array(); |     public $trusted_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * List of regular expressions (PCRE) that include trusted URIs |      * List of regular expressions (PCRE) that include trusted URIs | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $trusted_uri = array(); |     public $trusted_uri = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * List of trusted constants names |      * List of trusted constants names | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $trusted_constants = array(); |     public $trusted_constants = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of trusted static classes. |      * This is an array of trusted static classes. | ||||||
|      * If empty access to all static classes is allowed. |      * If empty access to all static classes is allowed. | ||||||
| @@ -96,6 +101,7 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $trusted_static_properties = array(); |     public $trusted_static_properties = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of trusted PHP functions. |      * This is an array of trusted PHP functions. | ||||||
|      * If empty all functions are allowed. |      * If empty all functions are allowed. | ||||||
| @@ -103,12 +109,8 @@ class Smarty_Security | |||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $php_functions = array( |     public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',); | ||||||
|         'isset', 'empty', |  | ||||||
|         'count', 'sizeof', |  | ||||||
|         'in_array', 'is_array', |  | ||||||
|         'time', |  | ||||||
|     ); |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of trusted PHP modifiers. |      * This is an array of trusted PHP modifiers. | ||||||
|      * If empty all modifiers are allowed. |      * If empty all modifiers are allowed. | ||||||
| @@ -116,11 +118,8 @@ class Smarty_Security | |||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $php_modifiers = array( |     public $php_modifiers = array('escape', 'count', 'nl2br',); | ||||||
|         'escape', |  | ||||||
|         'count', |  | ||||||
|         'nl2br', |  | ||||||
|     ); |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of allowed tags. |      * This is an array of allowed tags. | ||||||
|      * If empty no restriction by allowed_tags. |      * If empty no restriction by allowed_tags. | ||||||
| @@ -128,6 +127,7 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $allowed_tags = array(); |     public $allowed_tags = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of disabled tags. |      * This is an array of disabled tags. | ||||||
|      * If empty no restriction by disabled_tags. |      * If empty no restriction by disabled_tags. | ||||||
| @@ -135,6 +135,7 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $disabled_tags = array(); |     public $disabled_tags = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of allowed modifier plugins. |      * This is an array of allowed modifier plugins. | ||||||
|      * If empty no restriction by allowed_modifiers. |      * If empty no restriction by allowed_modifiers. | ||||||
| @@ -142,6 +143,7 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $allowed_modifiers = array(); |     public $allowed_modifiers = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of disabled modifier plugins. |      * This is an array of disabled modifier plugins. | ||||||
|      * If empty no restriction by disabled_modifiers. |      * If empty no restriction by disabled_modifiers. | ||||||
| @@ -149,12 +151,14 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $disabled_modifiers = array(); |     public $disabled_modifiers = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of disabled special $smarty variables. |      * This is an array of disabled special $smarty variables. | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $disabled_special_smarty_vars = array(); |     public $disabled_special_smarty_vars = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This is an array of trusted streams. |      * This is an array of trusted streams. | ||||||
|      * If empty all streams are allowed. |      * If empty all streams are allowed. | ||||||
| @@ -163,60 +167,70 @@ class Smarty_Security | |||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     public $streams = array('file'); |     public $streams = array('file'); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * + flag if constants can be accessed from template |      * + flag if constants can be accessed from template | ||||||
|      * |      * | ||||||
|      * @var boolean |      * @var boolean | ||||||
|      */ |      */ | ||||||
|     public $allow_constants = true; |     public $allow_constants = true; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * + flag if super globals can be accessed from template |      * + flag if super globals can be accessed from template | ||||||
|      * |      * | ||||||
|      * @var boolean |      * @var boolean | ||||||
|      */ |      */ | ||||||
|     public $allow_super_globals = true; |     public $allow_super_globals = true; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * max template nesting level |      * max template nesting level | ||||||
|      * |      * | ||||||
|      * @var int |      * @var int | ||||||
|      */ |      */ | ||||||
|     public $max_template_nesting = 0; |     public $max_template_nesting = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * current template nesting level |      * current template nesting level | ||||||
|      * |      * | ||||||
|      * @var int |      * @var int | ||||||
|      */ |      */ | ||||||
|     private $_current_template_nesting = 0; |     private $_current_template_nesting = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $resource_dir lookup |      * Cache for $resource_dir lookup | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $_resource_dir = null; |     protected $_resource_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $template_dir lookup |      * Cache for $template_dir lookup | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $_template_dir = null; |     protected $_template_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $config_dir lookup |      * Cache for $config_dir lookup | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $_config_dir = null; |     protected $_config_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $secure_dir lookup |      * Cache for $secure_dir lookup | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $_secure_dir = null; |     protected $_secure_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $php_resource_dir lookup |      * Cache for $php_resource_dir lookup | ||||||
|      * |      * | ||||||
|      * @var array |      * @var array | ||||||
|      */ |      */ | ||||||
|     protected $_php_resource_dir = null; |     protected $_php_resource_dir = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache for $trusted_dir lookup |      * Cache for $trusted_dir lookup | ||||||
|      * |      * | ||||||
| @@ -224,6 +238,20 @@ class Smarty_Security | |||||||
|      */ |      */ | ||||||
|     protected $_trusted_dir = null; |     protected $_trusted_dir = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Cache for include path status | ||||||
|  |      * | ||||||
|  |      * @var bool | ||||||
|  |      */ | ||||||
|  |     protected $_include_path_status = false; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Cache for $_include_array lookup | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     protected $_include_dir = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @param Smarty $smarty |      * @param Smarty $smarty | ||||||
|      */ |      */ | ||||||
| @@ -243,7 +271,9 @@ class Smarty_Security | |||||||
|      */ |      */ | ||||||
|     public function isTrustedPhpFunction($function_name, $compiler) |     public function isTrustedPhpFunction($function_name, $compiler) | ||||||
|     { |     { | ||||||
|         if (isset($this->php_functions) && (empty($this->php_functions) || in_array($function_name, $this->php_functions))) { |         if (isset($this->php_functions) && | ||||||
|  |             (empty($this->php_functions) || in_array($function_name, $this->php_functions)) | ||||||
|  |         ) { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -263,7 +293,9 @@ class Smarty_Security | |||||||
|      */ |      */ | ||||||
|     public function isTrustedStaticClass($class_name, $compiler) |     public function isTrustedStaticClass($class_name, $compiler) | ||||||
|     { |     { | ||||||
|         if (isset($this->static_classes) && (empty($this->static_classes) || in_array($class_name, $this->static_classes))) { |         if (isset($this->static_classes) && | ||||||
|  |             (empty($this->static_classes) || in_array($class_name, $this->static_classes)) | ||||||
|  |         ) { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -301,9 +333,8 @@ class Smarty_Security | |||||||
|                 // fall back |                 // fall back | ||||||
|                 return $this->isTrustedStaticClass($class_name, $compiler); |                 return $this->isTrustedStaticClass($class_name, $compiler); | ||||||
|             } |             } | ||||||
|             if (isset($allowed[$class_name]) |             if (isset($allowed[$class_name]) && | ||||||
|                 && (empty($allowed[$class_name]) |                 (empty($allowed[$class_name]) || in_array($name, $allowed[$class_name])) | ||||||
|                     || in_array($name, $allowed[$class_name])) |  | ||||||
|             ) { |             ) { | ||||||
|                 return true; |                 return true; | ||||||
|             } |             } | ||||||
| @@ -323,7 +354,9 @@ class Smarty_Security | |||||||
|      */ |      */ | ||||||
|     public function isTrustedPhpModifier($modifier_name, $compiler) |     public function isTrustedPhpModifier($modifier_name, $compiler) | ||||||
|     { |     { | ||||||
|         if (isset($this->php_modifiers) && (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))) { |         if (isset($this->php_modifiers) && | ||||||
|  |             (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers)) | ||||||
|  |         ) { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -344,9 +377,11 @@ class Smarty_Security | |||||||
|     public function isTrustedTag($tag_name, $compiler) |     public function isTrustedTag($tag_name, $compiler) | ||||||
|     { |     { | ||||||
|         // check for internal always required tags |         // check for internal always required tags | ||||||
|         if (in_array($tag_name, array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin', 'private_object_block_function', |         if (in_array($tag_name, array('assign', 'call', 'private_filter', 'private_block_plugin', | ||||||
|                                       'private_object_function', 'private_registered_function', 'private_registered_block', 'private_special_variable', 'private_print_expression', 'private_modifier')) |                                       'private_function_plugin', 'private_object_block_function', | ||||||
|         ) { |                                       'private_object_function', 'private_registered_function', | ||||||
|  |                                       'private_registered_block', 'private_special_variable', | ||||||
|  |                                       'private_print_expression', 'private_modifier'))) { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|         // check security settings |         // check security settings | ||||||
| @@ -354,12 +389,12 @@ class Smarty_Security | |||||||
|             if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) { |             if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) { | ||||||
|                 return true; |                 return true; | ||||||
|             } else { |             } else { | ||||||
|                 $compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", $compiler->lex->taglineno); |                 $compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true); | ||||||
|             } |             } | ||||||
|         } elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) { |         } elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) { | ||||||
|             return true; |             return true; | ||||||
|         } else { |         } else { | ||||||
|             $compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", $compiler->lex->taglineno); |             $compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; // should not, but who knows what happens to the compiler in the future? |         return false; // should not, but who knows what happens to the compiler in the future? | ||||||
| @@ -379,7 +414,7 @@ class Smarty_Security | |||||||
|         if (!in_array($var_name, $this->disabled_special_smarty_vars)) { |         if (!in_array($var_name, $this->disabled_special_smarty_vars)) { | ||||||
|             return true; |             return true; | ||||||
|         } else { |         } else { | ||||||
|             $compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", $compiler->lex->taglineno); |             $compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; // should not, but who knows what happens to the compiler in the future? |         return false; // should not, but who knows what happens to the compiler in the future? | ||||||
| @@ -405,12 +440,14 @@ class Smarty_Security | |||||||
|             if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) { |             if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) { | ||||||
|                 return true; |                 return true; | ||||||
|             } else { |             } else { | ||||||
|                 $compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", $compiler->lex->taglineno); |                 $compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null, true); | ||||||
|             } |             } | ||||||
|         } elseif (in_array($modifier_name, $this->allowed_modifiers) && !in_array($modifier_name, $this->disabled_modifiers)) { |         } elseif (in_array($modifier_name, $this->allowed_modifiers) && | ||||||
|  |             !in_array($modifier_name, $this->disabled_modifiers) | ||||||
|  |         ) { | ||||||
|             return true; |             return true; | ||||||
|         } else { |         } else { | ||||||
|             $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", $compiler->lex->taglineno); |             $compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null, true); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return false; // should not, but who knows what happens to the compiler in the future? |         return false; // should not, but who knows what happens to the compiler in the future? | ||||||
| @@ -419,7 +456,7 @@ class Smarty_Security | |||||||
|     /** |     /** | ||||||
|      * Check if constants are enabled or trusted |      * Check if constants are enabled or trusted | ||||||
|      * |      * | ||||||
|      * @param  string $const    contant name |      * @param  string $const    constant name | ||||||
|      * @param  object $compiler compiler object |      * @param  object $compiler compiler object | ||||||
|      * |      * | ||||||
|      * @return bool |      * @return bool | ||||||
| @@ -464,81 +501,70 @@ class Smarty_Security | |||||||
|      * Check if directory of file resource is trusted. |      * Check if directory of file resource is trusted. | ||||||
|      * |      * | ||||||
|      * @param  string   $filepath |      * @param  string   $filepath | ||||||
|  |      * @param null|bool $isConfig | ||||||
|      * |      * | ||||||
|      * @return boolean         true if directory is trusted |      * @return bool true if directory is trusted | ||||||
|      * @throws SmartyException if directory is not trusted |      * @throws \SmartyException if directory is not trusted | ||||||
|      */ |      */ | ||||||
|     public function isTrustedResourceDir($filepath) |     public function isTrustedResourceDir($filepath, $isConfig = null) | ||||||
|     { |     { | ||||||
|         $_template = false; |         if ($this->_include_path_status !== $this->smarty->use_include_path) { | ||||||
|         $_config = false; |             foreach ($this->_include_dir as $directory) { | ||||||
|         $_secure = false; |                 unset($this->_resource_dir[$directory]); | ||||||
|  |             } | ||||||
|         $_template_dir = $this->smarty->getTemplateDir(); |             if ($this->smarty->use_include_path) { | ||||||
|         $_config_dir = $this->smarty->getConfigDir(); |                 $this->_include_dir = array(); | ||||||
|  |                 $_dirs = $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty); | ||||||
|         // check if index is outdated |                 foreach ($_dirs as $directory) { | ||||||
|         if ((!$this->_template_dir || $this->_template_dir !== $_template_dir) |                     $this->_include_dir[] = $directory; | ||||||
|             || (!$this->_config_dir || $this->_config_dir !== $_config_dir) |                     $this->_resource_dir[$directory] = true; | ||||||
|             || (!empty($this->secure_dir) && (!$this->_secure_dir || $this->_secure_dir !== $this->secure_dir)) |                 } | ||||||
|  |             } | ||||||
|  |             $this->_include_path_status = $this->smarty->use_include_path; | ||||||
|  |         } | ||||||
|  |         if ($isConfig !== true && | ||||||
|  |             (!isset($this->smarty->_cache['template_dir_new']) || $this->smarty->_cache['template_dir_new']) | ||||||
|         ) { |         ) { | ||||||
|             $this->_resource_dir = array(); |             $_dir = $this->smarty->getTemplateDir(); | ||||||
|             $_template = true; |             if ($this->_template_dir !== $_dir) { | ||||||
|             $_config = true; |                 foreach ($this->_template_dir as $directory) { | ||||||
|             $_secure = !empty($this->secure_dir); |                     unset($this->_resource_dir[$directory]); | ||||||
|                 } |                 } | ||||||
|  |                 foreach ($_dir as $directory) { | ||||||
|         // rebuild template dir index |  | ||||||
|         if ($_template) { |  | ||||||
|             $this->_template_dir = $_template_dir; |  | ||||||
|             foreach ($_template_dir as $directory) { |  | ||||||
|                 $directory = realpath($directory); |  | ||||||
|                     $this->_resource_dir[$directory] = true; |                     $this->_resource_dir[$directory] = true; | ||||||
|                 } |                 } | ||||||
|  |                 $this->_template_dir = $_dir; | ||||||
|             } |             } | ||||||
|  |             $this->smarty->_cache['template_dir_new'] = false; | ||||||
|         // rebuild config dir index |         } | ||||||
|         if ($_config) { |         if ($isConfig !== false && | ||||||
|             $this->_config_dir = $_config_dir; |             (!isset($this->smarty->_cache['config_dir_new']) || $this->smarty->_cache['config_dir_new']) | ||||||
|             foreach ($_config_dir as $directory) { |         ) { | ||||||
|                 $directory = realpath($directory); |             $_dir = $this->smarty->getConfigDir(); | ||||||
|  |             if ($this->_config_dir !== $_dir) { | ||||||
|  |                 foreach ($this->_config_dir as $directory) { | ||||||
|  |                     unset($this->_resource_dir[$directory]); | ||||||
|  |                 } | ||||||
|  |                 foreach ($_dir as $directory) { | ||||||
|                     $this->_resource_dir[$directory] = true; |                     $this->_resource_dir[$directory] = true; | ||||||
|                 } |                 } | ||||||
|  |                 $this->_config_dir = $_dir; | ||||||
|  |             } | ||||||
|  |             $this->smarty->_cache['config_dir_new'] = false; | ||||||
|  |         } | ||||||
|  |         if ($this->_secure_dir !== (array) $this->secure_dir) { | ||||||
|  |             foreach ($this->_secure_dir as $directory) { | ||||||
|  |                 unset($this->_resource_dir[$directory]); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|         // rebuild secure dir index |  | ||||||
|         if ($_secure) { |  | ||||||
|             $this->_secure_dir = $this->secure_dir; |  | ||||||
|             foreach ((array) $this->secure_dir as $directory) { |             foreach ((array) $this->secure_dir as $directory) { | ||||||
|                 $directory = realpath($directory); |                 $directory = $this->smarty->_realpath($directory . DS, true); | ||||||
|                 $this->_resource_dir[$directory] = true; |                 $this->_resource_dir[$directory] = true; | ||||||
|             } |             } | ||||||
|  |             $this->_secure_dir = (array) $this->secure_dir; | ||||||
|         } |         } | ||||||
|  |         $this->_resource_dir = $this->_checkDir($filepath, $this->_resource_dir); | ||||||
|         $_filepath = realpath($filepath); |  | ||||||
|         $directory = dirname($_filepath); |  | ||||||
|         $_directory = array(); |  | ||||||
|         while (true) { |  | ||||||
|             // remember the directory to add it to _resource_dir in case we're successful |  | ||||||
|             $_directory[$directory] = true; |  | ||||||
|             // test if the directory is trusted |  | ||||||
|             if (isset($this->_resource_dir[$directory])) { |  | ||||||
|                 // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup |  | ||||||
|                 $this->_resource_dir = array_merge($this->_resource_dir, $_directory); |  | ||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|             // abort if we've reached root |  | ||||||
|             if (($pos = strrpos($directory, DS)) === false || !isset($directory[1])) { |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|             // bubble up one level |  | ||||||
|             $directory = substr($directory, 0, $pos); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // give up |  | ||||||
|         throw new SmartyException("directory '{$_filepath}' not allowed by security setting"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Check if URI (e.g. {fetch} or {html_image}) is trusted |      * Check if URI (e.g. {fetch} or {html_image}) is trusted | ||||||
| @@ -587,34 +613,14 @@ class Smarty_Security | |||||||
|  |  | ||||||
|             $this->_trusted_dir = $this->trusted_dir; |             $this->_trusted_dir = $this->trusted_dir; | ||||||
|             foreach ((array) $this->trusted_dir as $directory) { |             foreach ((array) $this->trusted_dir as $directory) { | ||||||
|                 $directory = realpath($directory); |                 $directory = $this->smarty->_realpath($directory . DS, true); | ||||||
|                 $this->_php_resource_dir[$directory] = true; |                 $this->_php_resource_dir[$directory] = true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         $_filepath = realpath($filepath); |         $this->_php_resource_dir = $this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir); | ||||||
|         $directory = dirname($_filepath); |  | ||||||
|         $_directory = array(); |  | ||||||
|         while (true) { |  | ||||||
|             // remember the directory to add it to _resource_dir in case we're successful |  | ||||||
|             $_directory[] = $directory; |  | ||||||
|             // test if the directory is trusted |  | ||||||
|             if (isset($this->_php_resource_dir[$directory])) { |  | ||||||
|                 // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup |  | ||||||
|                 $this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory); |  | ||||||
|  |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|             // abort if we've reached root |  | ||||||
|             if (($pos = strrpos($directory, DS)) === false || !isset($directory[2])) { |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|             // bubble up one level |  | ||||||
|             $directory = substr($directory, 0, $pos); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         throw new SmartyException("directory '{$_filepath}' not allowed by security setting"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Start template processing |      * Start template processing | ||||||
| @@ -633,12 +639,77 @@ class Smarty_Security | |||||||
|     /** |     /** | ||||||
|      * Exit template processing |      * Exit template processing | ||||||
|      * |      * | ||||||
|      * @param $template |      * @internal param $template | ||||||
|      */ |      */ | ||||||
|     public function exitTemplate($template) |     public function exitTemplate() | ||||||
|     { |     { | ||||||
|         if ($this->max_template_nesting > 0) { |         if ($this->max_template_nesting > 0) { | ||||||
|             $this->_current_template_nesting --; |             $this->_current_template_nesting --; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Check if file is inside a valid directory | ||||||
|  |      * | ||||||
|  |      * @param string $filepath | ||||||
|  |      * @param array  $dirs valid directories | ||||||
|  |      * | ||||||
|  |      * @return array | ||||||
|  |      * @throws \SmartyException | ||||||
|  |      */ | ||||||
|  |     private function _checkDir($filepath, $dirs) | ||||||
|  |     { | ||||||
|  |         $directory = dirname($filepath) . DS; | ||||||
|  |         $_directory = array(); | ||||||
|  |         while (true) { | ||||||
|  |             // remember the directory to add it to _resource_dir in case we're successful | ||||||
|  |             $_directory[$directory] = true; | ||||||
|  |             // test if the directory is trusted | ||||||
|  |             if (isset($dirs[$directory])) { | ||||||
|  |                 // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup | ||||||
|  |                 $dirs = array_merge($dirs, $_directory); | ||||||
|  |  | ||||||
|  |                 return $dirs; | ||||||
|  |             } | ||||||
|  |             // abort if we've reached root | ||||||
|  |             if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) { | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |             // bubble up one level | ||||||
|  |             $directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // give up | ||||||
|  |         throw new SmartyException("directory '{$filepath}' not allowed by security setting"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Loads security class and enables security | ||||||
|  |      * | ||||||
|  |      * @param \Smarty                 $smarty | ||||||
|  |      * @param  string|Smarty_Security $security_class if a string is used, it must be class-name | ||||||
|  |      * | ||||||
|  |      * @return \Smarty current Smarty instance for chaining | ||||||
|  |      * @throws \SmartyException when an invalid class name is provided | ||||||
|  |      */ | ||||||
|  |     public static function enableSecurity(Smarty $smarty, $security_class) | ||||||
|  |     { | ||||||
|  |         if ($security_class instanceof Smarty_Security) { | ||||||
|  |             $smarty->security_policy = $security_class; | ||||||
|  |             return; | ||||||
|  |         } elseif (is_object($security_class)) { | ||||||
|  |             throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security."); | ||||||
|  |         } | ||||||
|  |         if ($security_class == null) { | ||||||
|  |             $security_class = $smarty->security_class; | ||||||
|  |         } | ||||||
|  |         if (!class_exists($security_class)) { | ||||||
|  |             throw new SmartyException("Security class '$security_class' is not defined"); | ||||||
|  |         } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) { | ||||||
|  |             throw new SmartyException("Class '$security_class' must extend Smarty_Security."); | ||||||
|  |         } else { | ||||||
|  |             $smarty->security_policy = new $security_class($smarty); | ||||||
|  |         } | ||||||
|  |         return; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,36 +14,8 @@ | |||||||
|  * @subpackage TemplateResources |  * @subpackage TemplateResources | ||||||
|  * @author     Rodney Rehm |  * @author     Rodney Rehm | ||||||
|  */ |  */ | ||||||
| class Smarty_Template_Cached | class Smarty_Template_Cached extends Smarty_Template_Resource_Base | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * Source Filepath |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $filepath = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Source Content |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $content = null; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Source Timestamp |  | ||||||
|      * |  | ||||||
|      * @var integer |  | ||||||
|      */ |  | ||||||
|     public $timestamp = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Source Existence |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $exists = false; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Cache Is Valid |      * Cache Is Valid | ||||||
|      * |      * | ||||||
| @@ -51,13 +23,6 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     public $valid = null; |     public $valid = null; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Cache was processed |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $processed = false; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * CacheResource Handler |      * CacheResource Handler | ||||||
|      * |      * | ||||||
| @@ -65,13 +30,6 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     public $handler = null; |     public $handler = null; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Template Compile Id (Smarty_Internal_Template::$compile_id) |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $compile_id = null; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Template Cache Id (Smarty_Internal_Template::$cache_id) |      * Template Cache Id (Smarty_Internal_Template::$cache_id) | ||||||
|      * |      * | ||||||
| @@ -79,6 +37,13 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     public $cache_id = null; |     public $cache_id = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * saved cache lifetime in seconds | ||||||
|  |      * | ||||||
|  |      * @var integer | ||||||
|  |      */ | ||||||
|  |     public $cache_lifetime = 0; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Id for cache locking |      * Id for cache locking | ||||||
|      * |      * | ||||||
| @@ -100,6 +65,13 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     public $source = null; |     public $source = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Nocache hash codes of processed compiled templates | ||||||
|  |      * | ||||||
|  |      * @var array | ||||||
|  |      */ | ||||||
|  |     public $hashes = array(); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * create Cached Object container |      * create Cached Object container | ||||||
|      * |      * | ||||||
| @@ -109,9 +81,6 @@ class Smarty_Template_Cached | |||||||
|     { |     { | ||||||
|         $this->compile_id = $_template->compile_id; |         $this->compile_id = $_template->compile_id; | ||||||
|         $this->cache_id = $_template->cache_id; |         $this->cache_id = $_template->cache_id; | ||||||
|         if (!isset($_template->source)) { |  | ||||||
|             $_template->loadSource(); |  | ||||||
|         } |  | ||||||
|         $this->source = $_template->source; |         $this->source = $_template->source; | ||||||
|         if (!class_exists('Smarty_CacheResource', false)) { |         if (!class_exists('Smarty_CacheResource', false)) { | ||||||
|             require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php'; |             require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php'; | ||||||
| @@ -126,13 +95,42 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     static function load(Smarty_Internal_Template $_template) |     static function load(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $_template->cached = $cached = new Smarty_Template_Cached($_template); |         $_template->cached = new Smarty_Template_Cached($_template); | ||||||
|         $cached->handler->populate($cached, $_template); |         $_template->cached->handler->populate($_template->cached, $_template); | ||||||
|         // caching enabled ? |         // caching enabled ? | ||||||
|         if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) { |         if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || | ||||||
|             $cached->valid = false; |                 $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->handler->recompiled | ||||||
|  |         ) { | ||||||
|  |             $_template->cached->valid = false; | ||||||
|  |         } | ||||||
|  |         return $_template->cached; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Render cache template | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Template $_template | ||||||
|  |      * @param  bool                     $no_output_filter | ||||||
|  |      * | ||||||
|  |      * @throws \Exception | ||||||
|  |      */ | ||||||
|  |     public function render(Smarty_Internal_Template $_template, $no_output_filter = true) | ||||||
|  |     { | ||||||
|  |         if ($this->isCached($_template)) { | ||||||
|  |             if ($_template->smarty->debugging) { | ||||||
|  |                 $_template->smarty->_debug->start_cache($_template); | ||||||
|  |             } | ||||||
|  |             if (!$this->processed) { | ||||||
|  |                 $this->process($_template); | ||||||
|  |             } | ||||||
|  |             $this->getRenderedTemplateCode($_template); | ||||||
|  |             if ($_template->smarty->debugging) { | ||||||
|  |                 $_template->smarty->_debug->end_cache($_template); | ||||||
|  |             } | ||||||
|  |             return; | ||||||
|  |         } else { | ||||||
|  |             $_template->smarty->ext->_updateCache->updateCache($this, $_template, $no_output_filter); | ||||||
|         } |         } | ||||||
|         return $cached; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -154,11 +152,15 @@ class Smarty_Template_Cached | |||||||
|                 } else { |                 } else { | ||||||
|                     $this->valid = true; |                     $this->valid = true; | ||||||
|                 } |                 } | ||||||
|                 if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)) { |                 if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && | ||||||
|  |                     $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime) | ||||||
|  |                 ) { | ||||||
|                     // lifetime expired |                     // lifetime expired | ||||||
|                     $this->valid = false; |                     $this->valid = false; | ||||||
|                 } |                 } | ||||||
|                 if ($this->valid && $_template->source->timestamp > $this->timestamp) { |                 if ($this->valid && $_template->smarty->compile_check == 1 && | ||||||
|  |                     $_template->source->getTimeStamp() > $this->timestamp | ||||||
|  |                 ) { | ||||||
|                     $this->valid = false; |                     $this->valid = false; | ||||||
|                 } |                 } | ||||||
|                 if ($this->valid || !$_template->smarty->cache_locking) { |                 if ($this->valid || !$_template->smarty->cache_locking) { | ||||||
| @@ -174,7 +176,7 @@ class Smarty_Template_Cached | |||||||
|                 if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) { |                 if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) { | ||||||
|                     // load cache file for the following checks |                     // load cache file for the following checks | ||||||
|                     if ($_template->smarty->debugging) { |                     if ($_template->smarty->debugging) { | ||||||
|                         Smarty_Internal_Debug::start_cache($_template); |                         $_template->smarty->_debug->start_cache($_template); | ||||||
|                     } |                     } | ||||||
|                     if ($this->handler->process($_template, $this) === false) { |                     if ($this->handler->process($_template, $this) === false) { | ||||||
|                         $this->valid = false; |                         $this->valid = false; | ||||||
| @@ -182,7 +184,7 @@ class Smarty_Template_Cached | |||||||
|                         $this->processed = true; |                         $this->processed = true; | ||||||
|                     } |                     } | ||||||
|                     if ($_template->smarty->debugging) { |                     if ($_template->smarty->debugging) { | ||||||
|                         Smarty_Internal_Debug::end_cache($_template); |                         $_template->smarty->_debug->end_cache($_template); | ||||||
|                     } |                     } | ||||||
|                 } else { |                 } else { | ||||||
|                     $this->is_locked = true; |                     $this->is_locked = true; | ||||||
| @@ -191,7 +193,10 @@ class Smarty_Template_Cached | |||||||
|             } else { |             } else { | ||||||
|                 return $this->valid; |                 return $this->valid; | ||||||
|             } |             } | ||||||
|             if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) { |             if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && | ||||||
|  |                 $_template->cached->cache_lifetime >= 0 && | ||||||
|  |                 (time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime)) | ||||||
|  |             ) { | ||||||
|                 $this->valid = false; |                 $this->valid = false; | ||||||
|             } |             } | ||||||
|             if ($_template->smarty->cache_locking) { |             if ($_template->smarty->cache_locking) { | ||||||
| @@ -210,10 +215,11 @@ class Smarty_Template_Cached | |||||||
|      * Process cached template |      * Process cached template | ||||||
|      * |      * | ||||||
|      * @param Smarty_Internal_Template $_template template object |      * @param Smarty_Internal_Template $_template template object | ||||||
|  |      * @param bool                     $update    flag if called because cache update | ||||||
|      */ |      */ | ||||||
|     public function process(Smarty_Internal_Template $_template) |     public function process(Smarty_Internal_Template $_template, $update = false) | ||||||
|     { |     { | ||||||
|         if ($this->handler->process($_template, $this) === false) { |         if ($this->handler->process($_template, $this, $update) === false) { | ||||||
|             $this->valid = false; |             $this->valid = false; | ||||||
|         } |         } | ||||||
|         if ($this->valid) { |         if ($this->valid) { | ||||||
| @@ -223,55 +229,6 @@ class Smarty_Template_Cached | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Render cached template |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template |  | ||||||
|      * |  | ||||||
|      * @return string |  | ||||||
|      * @throws Exception |  | ||||||
|      */ |  | ||||||
|     public function render(Smarty_Internal_Template $_template) |  | ||||||
|     { |  | ||||||
|         if (!$this->processed) { |  | ||||||
|             $this->process($_template); |  | ||||||
|         } |  | ||||||
|         return $_template->getRenderedTemplateCode(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Write this cache object to handler |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template template object |  | ||||||
|      * @param string                   $content   content to cache |  | ||||||
|      * |  | ||||||
|      * @return boolean success |  | ||||||
|      */ |  | ||||||
|     public function write(Smarty_Internal_Template $_template, $content) |  | ||||||
|     { |  | ||||||
|         if (!$_template->source->recompiled) { |  | ||||||
|             if ($this->handler->writeCachedContent($_template, $content)) { |  | ||||||
|                 $this->content = null; |  | ||||||
|                 $this->timestamp = time(); |  | ||||||
|                 $this->exists = true; |  | ||||||
|                 $this->valid = true; |  | ||||||
|                 $this->processed = false; |  | ||||||
|                 if ($_template->smarty->cache_locking) { |  | ||||||
|                     $this->handler->releaseLock($_template->smarty, $this); |  | ||||||
|                 } |  | ||||||
|  |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|             $this->content = null; |  | ||||||
|             $this->timestamp = false; |  | ||||||
|             $this->exists = false; |  | ||||||
|             $this->valid = false; |  | ||||||
|             $this->processed = false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Read cache content from handler |      * Read cache content from handler | ||||||
|      * |      * | ||||||
| @@ -281,123 +238,9 @@ class Smarty_Template_Cached | |||||||
|      */ |      */ | ||||||
|     public function read(Smarty_Internal_Template $_template) |     public function read(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         if (!$_template->source->recompiled) { |         if (!$_template->source->handler->recompiled) { | ||||||
|             return $this->handler->readCachedContent($_template); |             return $this->handler->readCachedContent($_template); | ||||||
|         } |         } | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Sanitize content and write it to cache resource |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template |  | ||||||
|      * @param string                   $content |  | ||||||
|      * @param bool                     $no_output_filter |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException |  | ||||||
|      */ |  | ||||||
|     public function updateCache(Smarty_Internal_Template $_template, $content, $no_output_filter) |  | ||||||
|     { |  | ||||||
|         $_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", $content); |  | ||||||
|         // get non-cached items |  | ||||||
|         preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $content, $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|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', "<?php echo '\$1'; ?>\n", $curr_split); |  | ||||||
|             if (isset($cache_parts[0][$curr_idx])) { |  | ||||||
|                 $_template->properties['has_nocache_code'] = true; |  | ||||||
|                 $output .= $cache_parts[1][$curr_idx]; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (!$no_output_filter && !$_template->has_nocache_code && (isset($_template->smarty->autoload_filters['output']) || isset($_template->smarty->registered_filters['output']))) { |  | ||||||
|             $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template); |  | ||||||
|         } |  | ||||||
|         // write cache file content |  | ||||||
|         $this->writeCachedContent($_template, $output); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Writes the content to cache resource |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template |  | ||||||
|      * @param string                   $content |  | ||||||
|      * |  | ||||||
|      * @return bool |  | ||||||
|      */ |  | ||||||
|     public function writeCachedContent(Smarty_Internal_Template $_template, $content) |  | ||||||
|     { |  | ||||||
|         if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED)) { |  | ||||||
|             // don't write cache file |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|         $_template->properties['cache_lifetime'] = $_template->cache_lifetime; |  | ||||||
|         $_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); |  | ||||||
|         $content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, true); |  | ||||||
|         if (!empty($_template->properties['tpl_function'])) { |  | ||||||
|             foreach ($_template->properties['tpl_function'] as $funcParam) { |  | ||||||
|                 if (is_file($funcParam['compiled_filepath'])) { |  | ||||||
|                     // read compiled file |  | ||||||
|                     $code = file_get_contents($funcParam['compiled_filepath']); |  | ||||||
|                     // grab template function |  | ||||||
|                     if (preg_match("/\/\* {$funcParam['call_name']} \*\/([\S\s]*?)\/\*\/ {$funcParam['call_name']} \*\//", $code, $match)) { |  | ||||||
|                         unset($code); |  | ||||||
|                         $content .= "<?php " . $match[0] . "?>\n"; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return $this->write($_template, $content); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * check client side cache |  | ||||||
|      * |  | ||||||
|      * @param Smarty_Internal_Template $_template |  | ||||||
|      * @param  string                  $content |  | ||||||
|      */ |  | ||||||
|     public function cacheModifiedCheck(Smarty_Internal_Template $_template, $content) |  | ||||||
|     { |  | ||||||
|         $_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 && $this->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', $this->timestamp) . ' GMT'; |  | ||||||
|                     } |  | ||||||
|                     break; |  | ||||||
|  |  | ||||||
|                 default: |  | ||||||
|                     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->timestamp) . ' GMT'); |  | ||||||
|                     break; |  | ||||||
|             } |  | ||||||
|             echo $content; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,48 +9,15 @@ | |||||||
|  * @author     Rodney Rehm |  * @author     Rodney Rehm | ||||||
|  * @property string $content compiled content |  * @property string $content compiled content | ||||||
|  */ |  */ | ||||||
| class Smarty_Template_Compiled | class Smarty_Template_Compiled extends Smarty_Template_Resource_Base | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * Compiled Filepath |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $filepath = null; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Compiled Timestamp |      * nocache hash | ||||||
|      * |  | ||||||
|      * @var integer |  | ||||||
|      */ |  | ||||||
|     public $timestamp = null; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Compiled Existence |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $exists = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Compiled Content Loaded |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $processed = false; |  | ||||||
|     /** |  | ||||||
|      * Code of recompiled template resource |  | ||||||
|      * |      * | ||||||
|      * @var string|null |      * @var string|null | ||||||
|      */ |      */ | ||||||
|     public $code = null; |     public $nocache_hash = null; | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * create Compiled Object container |  | ||||||
|      */ |  | ||||||
|     public function __construct() |  | ||||||
|     { |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * get a Compiled Object of this source |      * get a Compiled Object of this source | ||||||
| @@ -61,11 +28,10 @@ class Smarty_Template_Compiled | |||||||
|      */ |      */ | ||||||
|     static function load($_template) |     static function load($_template) | ||||||
|     { |     { | ||||||
|         if (!isset($_template->source)) { |  | ||||||
|             $_template->loadSource(); |  | ||||||
|         } |  | ||||||
|         // check runtime cache |         // check runtime cache | ||||||
|         if (!$_template->source->recompiled && $_template->smarty->resource_caching) { |         if (!$_template->source->handler->recompiled && | ||||||
|  |             ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) | ||||||
|  |         ) { | ||||||
|             $_cache_key = $_template->source->unique_resource . '#'; |             $_cache_key = $_template->source->unique_resource . '#'; | ||||||
|             if ($_template->caching) { |             if ($_template->caching) { | ||||||
|                 $_cache_key .= 'caching#'; |                 $_cache_key .= 'caching#'; | ||||||
| @@ -76,13 +42,15 @@ class Smarty_Template_Compiled | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         $compiled = new Smarty_Template_Compiled(); |         $compiled = new Smarty_Template_Compiled(); | ||||||
|         if (method_exists($_template->source->handler, 'populateCompiledFilepath')) { |         if ($_template->source->handler->hasCompiledHandler) { | ||||||
|             $_template->source->handler->populateCompiledFilepath($compiled, $_template); |             $_template->source->handler->populateCompiledFilepath($compiled, $_template); | ||||||
|         } else { |         } else { | ||||||
|             $compiled->populateCompiledFilepath($_template); |             $compiled->populateCompiledFilepath($_template); | ||||||
|         } |         } | ||||||
|         // runtime cache |         // runtime cache | ||||||
|         if (!$_template->source->recompiled && $_template->smarty->resource_caching) { |         if (!$_template->source->handler->recompiled && | ||||||
|  |             ($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) | ||||||
|  |         ) { | ||||||
|             $_template->source->compileds[$_cache_key] = $compiled; |             $_template->source->compileds[$_cache_key] = $compiled; | ||||||
|         } |         } | ||||||
|         return $compiled; |         return $compiled; | ||||||
| @@ -95,20 +63,20 @@ class Smarty_Template_Compiled | |||||||
|      **/ |      **/ | ||||||
|     public function populateCompiledFilepath(Smarty_Internal_Template $_template) |     public function populateCompiledFilepath(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null; |         $_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null; | ||||||
|         if ($_template->source->isConfig) { |         if ($_template->source->isConfig) { | ||||||
|             $_flag = '_' . ((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2 |             $_flag = '_' . | ||||||
|                     + (int) $_template->smarty->config_overwrite * 4); |                 ((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2 + | ||||||
|  |                     (int) $_template->smarty->config_overwrite * 4); | ||||||
|         } else { |         } else { | ||||||
|             $_flag = '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2); |             $_flag = | ||||||
|  |                 '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2); | ||||||
|         } |         } | ||||||
|         $_filepath = $_template->source->uid . $_flag; |         $_filepath = $_template->source->uid . $_flag; | ||||||
|         // if use_sub_dirs, break file into directories |         // if use_sub_dirs, break file into directories | ||||||
|         if ($_template->smarty->use_sub_dirs) { |         if ($_template->smarty->use_sub_dirs) { | ||||||
|             $_filepath = substr($_filepath, 0, 2) . DS |             $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS . | ||||||
|                 . substr($_filepath, 2, 2) . DS |                 $_filepath; | ||||||
|                 . substr($_filepath, 4, 2) . DS |  | ||||||
|                 . $_filepath; |  | ||||||
|         } |         } | ||||||
|         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; |         $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^'; | ||||||
|         if (isset($_compile_id)) { |         if (isset($_compile_id)) { | ||||||
| @@ -124,7 +92,7 @@ class Smarty_Template_Compiled | |||||||
|         // set basename if not specified |         // set basename if not specified | ||||||
|         $_basename = $_template->source->handler->getBasename($_template->source); |         $_basename = $_template->source->handler->getBasename($_template->source); | ||||||
|         if ($_basename === null) { |         if ($_basename === null) { | ||||||
|             $_basename = basename(preg_replace('![^\w\/]+!', '_', $_template->source->name)); |             $_basename = basename(preg_replace('![^\w]+!', '_', $_template->source->name)); | ||||||
|         } |         } | ||||||
|         // separate (optional) basename by dot |         // separate (optional) basename by dot | ||||||
|         if ($_basename) { |         if ($_basename) { | ||||||
| @@ -132,9 +100,9 @@ class Smarty_Template_Compiled | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         $this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php'; |         $this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php'; | ||||||
|         $this->timestamp = $this->exists = is_file($this->filepath); |         $this->exists = is_file($this->filepath); | ||||||
|         if ($this->exists) { |         if (!$this->exists) { | ||||||
|             $this->timestamp = @filemtime($this->filepath); |             $this->timestamp = false; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -148,15 +116,18 @@ class Smarty_Template_Compiled | |||||||
|     public function process(Smarty_Internal_Template $_template) |     public function process(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $_smarty_tpl = $_template; |         $_smarty_tpl = $_template; | ||||||
|         if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile) { |         if ($_template->source->handler->recompiled || !$_template->compiled->exists || | ||||||
|  |             $_template->smarty->force_compile || ($_template->smarty->compile_check && | ||||||
|  |                 $_template->source->getTimeStamp() > $_template->compiled->getTimeStamp()) | ||||||
|  |         ) { | ||||||
|             $this->compileTemplateSource($_template); |             $this->compileTemplateSource($_template); | ||||||
|             $compileCheck = $_template->smarty->compile_check; |             $compileCheck = $_template->smarty->compile_check; | ||||||
|             $_template->smarty->compile_check = false; |             $_template->smarty->compile_check = false; | ||||||
|             if ($_template->source->recompiled) { |             if ($_template->source->handler->recompiled) { | ||||||
|                 $level = ob_get_level(); |                 $level = ob_get_level(); | ||||||
|                 ob_start(); |                 ob_start(); | ||||||
|                 try { |                 try { | ||||||
|                     eval("?>" . $this->code); |                     eval("?>" . $this->content); | ||||||
|                 } |                 } | ||||||
|                 catch (Exception $e) { |                 catch (Exception $e) { | ||||||
|                     while (ob_get_level() > $level) { |                     while (ob_get_level() > $level) { | ||||||
| @@ -165,25 +136,46 @@ class Smarty_Template_Compiled | |||||||
|                     throw $e; |                     throw $e; | ||||||
|                 } |                 } | ||||||
|                 ob_get_clean(); |                 ob_get_clean(); | ||||||
|                 $this->code = null; |                 $this->content = null; | ||||||
|             } else { |             } else { | ||||||
|                 include($_template->compiled->filepath); |                 $this->loadCompiledTemplate($_template); | ||||||
|             } |             } | ||||||
|             $_template->smarty->compile_check = $compileCheck; |             $_template->smarty->compile_check = $compileCheck; | ||||||
|         } else { |         } else { | ||||||
|             include($_template->compiled->filepath); |             $_template->mustCompile = true; | ||||||
|  |             @include($_template->compiled->filepath); | ||||||
|             if ($_template->mustCompile) { |             if ($_template->mustCompile) { | ||||||
|                 $this->compileTemplateSource($_template); |                 $this->compileTemplateSource($_template); | ||||||
|                 $compileCheck = $_template->smarty->compile_check; |                 $compileCheck = $_template->smarty->compile_check; | ||||||
|                 $_template->smarty->compile_check = false; |                 $_template->smarty->compile_check = false; | ||||||
|                 include($_template->compiled->filepath); |                 $this->loadCompiledTemplate($_template); | ||||||
|                 $_template->smarty->compile_check = $compileCheck; |                 $_template->smarty->compile_check = $compileCheck; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         $this->unifunc = $_template->properties['unifunc']; |         $_template->smarty->ext->_subTemplate->registerSubTemplates($_template); | ||||||
|  |  | ||||||
|         $this->processed = true; |         $this->processed = true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Load fresh compiled template by including the PHP file | ||||||
|  |      * HHVM requires a work around because of a PHP incompatibility | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Template $_template | ||||||
|  |      */ | ||||||
|  |     private function loadCompiledTemplate(Smarty_Internal_Template $_template) | ||||||
|  |     { | ||||||
|  |         if (function_exists('opcache_invalidate')) { | ||||||
|  |             opcache_invalidate($_template->compiled->filepath); | ||||||
|  |         } | ||||||
|  |         $_smarty_tpl = $_template; | ||||||
|  |         if (defined('HHVM_VERSION')) { | ||||||
|  |             $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->compiled->filepath); | ||||||
|  |         } else { | ||||||
|  |             include($_template->compiled->filepath); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * render compiled template code |      * render compiled template code | ||||||
|      * |      * | ||||||
| @@ -194,12 +186,26 @@ class Smarty_Template_Compiled | |||||||
|      */ |      */ | ||||||
|     public function render(Smarty_Internal_Template $_template) |     public function render(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|  |         if ($_template->smarty->debugging) { | ||||||
|  |             $_template->smarty->_debug->start_render($_template); | ||||||
|  |         } | ||||||
|         if (!$this->processed) { |         if (!$this->processed) { | ||||||
|             $this->process($_template); |             $this->process($_template); | ||||||
|         } |         } | ||||||
|         $_template->properties['unifunc'] = $this->unifunc; |         if (isset($_template->cached)) { | ||||||
|         return $_template->getRenderedTemplateCode(); |             $_template->cached->file_dependency = | ||||||
|  |                 array_merge($_template->cached->file_dependency, $this->file_dependency); | ||||||
|  |         } | ||||||
|  |         $this->getRenderedTemplateCode($_template); | ||||||
|  |         if ($_template->caching && $this->has_nocache_code) { | ||||||
|  |             $_template->cached->hashes[$this->nocache_hash] = true; | ||||||
|  |         } | ||||||
|  |         if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) { | ||||||
|  |             $_template->parent->tpl_function = array_merge($_template->parent->tpl_function, $_template->tpl_function); | ||||||
|  |         } | ||||||
|  |         if ($_template->smarty->debugging) { | ||||||
|  |             $_template->smarty->_debug->end_render($_template); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -212,22 +218,26 @@ class Smarty_Template_Compiled | |||||||
|      */ |      */ | ||||||
|     public function compileTemplateSource(Smarty_Internal_Template $_template) |     public function compileTemplateSource(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         if (!$_template->source->recompiled) { |         $_template->source->compileds = array(); | ||||||
|             $_template->properties['file_dependency'] = array(); |         $this->file_dependency = array(); | ||||||
|         } |         $this->tpl_function = array(); | ||||||
|  |         $this->includes = array(); | ||||||
|  |         $this->nocache_hash = null; | ||||||
|  |         $this->unifunc = null; | ||||||
|         // compile locking |         // compile locking | ||||||
|         if (!$_template->source->recompiled) { |         if (!$_template->source->handler->recompiled) { | ||||||
|             if ($saved_timestamp = $_template->compiled->timestamp) { |             if ($saved_timestamp = $_template->compiled->getTimeStamp()) { | ||||||
|                 touch($_template->compiled->filepath); |                 touch($_template->compiled->filepath); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // call compiler |         // call compiler | ||||||
|         try { |         try { | ||||||
|  |             $_template->loadCompiler(); | ||||||
|             $code = $_template->compiler->compileTemplate($_template); |             $code = $_template->compiler->compileTemplate($_template); | ||||||
|         } |         } | ||||||
|         catch (Exception $e) { |         catch (Exception $e) { | ||||||
|             // restore old timestamp in case of error |             // restore old timestamp in case of error | ||||||
|             if (!$_template->source->recompiled && $saved_timestamp) { |             if (!$_template->source->handler->recompiled && $saved_timestamp) { | ||||||
|                 touch($_template->compiled->filepath, $saved_timestamp); |                 touch($_template->compiled->filepath, $saved_timestamp); | ||||||
|             } |             } | ||||||
|             throw $e; |             throw $e; | ||||||
| @@ -253,18 +263,17 @@ class Smarty_Template_Compiled | |||||||
|      */ |      */ | ||||||
|     public function write(Smarty_Internal_Template $_template, $code) |     public function write(Smarty_Internal_Template $_template, $code) | ||||||
|     { |     { | ||||||
|         if (!$_template->source->recompiled) { |         if (!$_template->source->handler->recompiled) { | ||||||
|             $obj = new Smarty_Internal_Write_File(); |             if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) { | ||||||
|             if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) { |  | ||||||
|                 $this->timestamp = $this->exists = is_file($this->filepath); |                 $this->timestamp = $this->exists = is_file($this->filepath); | ||||||
|                 if ($this->exists) { |                 if ($this->exists) { | ||||||
|                     $this->timestamp = @filemtime($this->filepath); |                     $this->timestamp = filemtime($this->filepath); | ||||||
|                     return true; |                     return true; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             return false; |             return false; | ||||||
|         } else { |         } else { | ||||||
|             $this->code = $code; |             $this->content = $code; | ||||||
|         } |         } | ||||||
|         $this->timestamp = time(); |         $this->timestamp = time(); | ||||||
|         $this->exists = true; |         $this->exists = true; | ||||||
| @@ -280,7 +289,7 @@ class Smarty_Template_Compiled | |||||||
|      */ |      */ | ||||||
|     public function read(Smarty_Internal_Template $_template) |     public function read(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         if (!$_template->source->recompiled) { |         if (!$_template->source->handler->recompiled) { | ||||||
|             return file_get_contents($this->filepath); |             return file_get_contents($this->filepath); | ||||||
|         } |         } | ||||||
|         return isset($this->content) ? $this->content : false; |         return isset($this->content) ? $this->content : false; | ||||||
|   | |||||||
| @@ -14,34 +14,10 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage TemplateResources |  * @subpackage TemplateResources | ||||||
|  * @author     Uwe Tews |  * @author     Uwe Tews | ||||||
|  * @property integer $timestamp Source Timestamp |  * | ||||||
|  * @property boolean $exists    Source Existence |  | ||||||
|  * @property boolean $template  Extended Template reference |  | ||||||
|  * @property string  $content   Source Content |  | ||||||
|  */ |  */ | ||||||
| class Smarty_Template_Config extends Smarty_Template_Source | class Smarty_Template_Config extends Smarty_Template_Source | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * Name of the Class to compile this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $compiler_class = 'Smarty_Internal_Config_File_Compiler'; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Name of the Class to tokenize this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $template_lexer_class = 'Smarty_Internal_Configfilelexer'; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Name of the Class to parse this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $template_parser_class = 'Smarty_Internal_Configfileparser'; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * array of section names, single section or null |      * array of section names, single section or null | ||||||
|      * |      * | ||||||
| @@ -74,7 +50,11 @@ class Smarty_Template_Config extends Smarty_Template_Source | |||||||
|      */ |      */ | ||||||
|     public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) |     public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) | ||||||
|     { |     { | ||||||
|  |         // must clone handler as we change class names | ||||||
|         $this->handler = clone $handler; // Note: prone to circular references |         $this->handler = clone $handler; // Note: prone to circular references | ||||||
|  |         $this->handler->compiler_class = 'Smarty_Internal_Config_File_Compiler'; | ||||||
|  |         $this->handler->template_lexer_class = 'Smarty_Internal_Configfilelexer'; | ||||||
|  |         $this->handler->template_parser_class = 'Smarty_Internal_Configfileparser'; | ||||||
|         $this->resource = $resource; |         $this->resource = $resource; | ||||||
|         $this->type = $type; |         $this->type = $type; | ||||||
|         $this->name = $name; |         $this->name = $name; | ||||||
| @@ -89,30 +69,29 @@ class Smarty_Template_Config extends Smarty_Template_Source | |||||||
|      * @param  Smarty                   $smarty            smarty object |      * @param  Smarty                   $smarty            smarty object | ||||||
|      * @param  string                   $template_resource resource identifier |      * @param  string                   $template_resource resource identifier | ||||||
|      * |      * | ||||||
|      * @return Smarty_Template_Source Source Object |      * @return Smarty_Template_Config Source Object | ||||||
|      * @throws SmartyException |      * @throws SmartyException | ||||||
|      */ |      */ | ||||||
|     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) |     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) | ||||||
|     { |     { | ||||||
|         static $_incompatible_resources = array('extends' => true, 'php' => true); |         static $_incompatible_resources = array('extends' => true, 'php' => true); | ||||||
|         $smarty = $_template->smarty; |  | ||||||
|         $template_resource = $_template->template_resource; |         $template_resource = $_template->template_resource; | ||||||
|         if (empty($template_resource)) { |         if (empty($template_resource)) { | ||||||
|             throw new SmartyException('Missing config name'); |             throw new SmartyException('Missing config name'); | ||||||
|         } |         } | ||||||
|         // parse resource_name, load resource handler |         // parse resource_name, load resource handler | ||||||
|         list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type); |         list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type); | ||||||
|         // make sure configs are not loaded via anything smarty can't handle |         // make sure configs are not loaded via anything smarty can't handle | ||||||
|         if (isset($_incompatible_resources[$type])) { |         if (isset($_incompatible_resources[$type])) { | ||||||
|             throw new SmartyException ("Unable to use resource '{$type}' for config"); |             throw new SmartyException ("Unable to use resource '{$type}' for config"); | ||||||
|         } |         } | ||||||
|         $resource = Smarty_Resource::load($smarty, $type); |         $resource = Smarty_Resource::load($_template->smarty, $type); | ||||||
|         $source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name); |         $source = new Smarty_Template_Config($resource, $_template->smarty, $template_resource, $type, $name); | ||||||
|         $resource->populate($source, $_template); |         $resource->populate($source, $_template); | ||||||
|         if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_config_handler_func)) { |         if (!$source->exists && isset($_template->smarty->default_config_handler_func)) { | ||||||
|             Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resource); |             Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); | ||||||
|         } |         } | ||||||
|         $source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true); |         $source->unique_resource = $resource->buildUniqueResourceName($_template->smarty, $name, true); | ||||||
|         return $source; |         return $source; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,34 +7,10 @@ | |||||||
|  * @package    Smarty |  * @package    Smarty | ||||||
|  * @subpackage TemplateResources |  * @subpackage TemplateResources | ||||||
|  * @author     Rodney Rehm |  * @author     Rodney Rehm | ||||||
|  * @property integer $timestamp Source Timestamp |  * | ||||||
|  * @property boolean $exists    Source Existence |  | ||||||
|  * @property boolean $template  Extended Template reference |  | ||||||
|  * @property string  $content   Source Content |  | ||||||
|  */ |  */ | ||||||
| class Smarty_Template_Source | class Smarty_Template_Source | ||||||
| { | { | ||||||
|     /** |  | ||||||
|      * Name of the Class to compile this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $compiler_class = null; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Name of the Class to tokenize this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $template_lexer_class = null; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Name of the Class to parse this resource's contents with |  | ||||||
|      * |  | ||||||
|      * @var string |  | ||||||
|      */ |  | ||||||
|     public $template_parser_class = null; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Unique Template ID |      * Unique Template ID | ||||||
|      * |      * | ||||||
| @@ -76,6 +52,21 @@ class Smarty_Template_Source | |||||||
|      * @var string |      * @var string | ||||||
|      */ |      */ | ||||||
|     public $filepath = null; |     public $filepath = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Source Timestamp | ||||||
|  |      * | ||||||
|  |      * @var integer | ||||||
|  |      */ | ||||||
|  |     public $timestamp = null; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Source Existence | ||||||
|  |      * | ||||||
|  |      * @var boolean | ||||||
|  |      */ | ||||||
|  |     public $exists = false; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Source File Base name |      * Source File Base name | ||||||
|      * |      * | ||||||
| @@ -86,14 +77,14 @@ class Smarty_Template_Source | |||||||
|     /** |     /** | ||||||
|      * The Components an extended template is made of |      * The Components an extended template is made of | ||||||
|      * |      * | ||||||
|      * @var array |      * @var \Smarty_Template_Source[] | ||||||
|      */ |      */ | ||||||
|     public $components = null; |     public $components = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Resource Handler |      * Resource Handler | ||||||
|      * |      * | ||||||
|      * @var Smarty_Resource |      * @var \Smarty_Resource | ||||||
|      */ |      */ | ||||||
|     public $handler = null; |     public $handler = null; | ||||||
|  |  | ||||||
| @@ -103,32 +94,28 @@ class Smarty_Template_Source | |||||||
|      * @var Smarty |      * @var Smarty | ||||||
|      */ |      */ | ||||||
|     public $smarty = null; |     public $smarty = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Resource is source |      * Resource is source | ||||||
|      * |      * | ||||||
|      * @var bool |      * @var bool | ||||||
|      */ |      */ | ||||||
|     public $isConfig = false; |     public $isConfig = false; | ||||||
|     /** |  | ||||||
|      * Source is bypassing compiler |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $uncompiled = false; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Source must be recompiled on every occasion |  | ||||||
|      * |  | ||||||
|      * @var boolean |  | ||||||
|      */ |  | ||||||
|     public $recompiled = false; |  | ||||||
|     /** |     /** | ||||||
|      * cache for Smarty_Template_Compiled instances |      * cache for Smarty_Template_Compiled instances | ||||||
|      * |      * | ||||||
|      * @var array |      * @var Smarty_Template_Compiled[] | ||||||
|      */ |      */ | ||||||
|     public $compileds = array(); |     public $compileds = array(); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Template source content eventually set by default handler | ||||||
|  |      * | ||||||
|  |      * @var string | ||||||
|  |      */ | ||||||
|  |     public $content = null; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * create Source Object container |      * create Source Object container | ||||||
|      * |      * | ||||||
| @@ -138,18 +125,10 @@ class Smarty_Template_Source | |||||||
|      * @param string          $type     type of resource |      * @param string          $type     type of resource | ||||||
|      * @param string          $name     resource name |      * @param string          $name     resource name | ||||||
|      * |      * | ||||||
|      * @internal param string $unique_resource unique resource name |  | ||||||
|      */ |      */ | ||||||
|     public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) |     public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name) | ||||||
|     { |     { | ||||||
|         $this->handler = $handler; // Note: prone to circular references |         $this->handler = $handler; // Note: prone to circular references | ||||||
|  |  | ||||||
|         $this->recompiled = $handler->recompiled; |  | ||||||
|         $this->uncompiled = $handler->uncompiled; |  | ||||||
|         $this->compiler_class = $handler->compiler_class; |  | ||||||
|         $this->template_lexer_class = $handler->template_lexer_class; |  | ||||||
|         $this->template_parser_class = $handler->template_parser_class; |  | ||||||
|  |  | ||||||
|         $this->smarty = $smarty; |         $this->smarty = $smarty; | ||||||
|         $this->resource = $resource; |         $this->resource = $resource; | ||||||
|         $this->type = $type; |         $this->type = $type; | ||||||
| @@ -167,7 +146,8 @@ class Smarty_Template_Source | |||||||
|      * @return Smarty_Template_Source Source Object |      * @return Smarty_Template_Source Source Object | ||||||
|      * @throws SmartyException |      * @throws SmartyException | ||||||
|      */ |      */ | ||||||
|     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null) |     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, | ||||||
|  |                                 $template_resource = null) | ||||||
|     { |     { | ||||||
|         if ($_template) { |         if ($_template) { | ||||||
|             $smarty = $_template->smarty; |             $smarty = $_template->smarty; | ||||||
| @@ -177,36 +157,51 @@ class Smarty_Template_Source | |||||||
|             throw new SmartyException('Missing template name'); |             throw new SmartyException('Missing template name'); | ||||||
|         } |         } | ||||||
|         // parse resource_name, load resource handler, identify unique resource name |         // parse resource_name, load resource handler, identify unique resource name | ||||||
|         list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_resource_type); |         if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) { | ||||||
|         $resource = Smarty_Resource::load($smarty, $type); |             $type = $match[1]; | ||||||
|  |             $name = $match[2]; | ||||||
|  |         } else { | ||||||
|  |             // no resource given, use default | ||||||
|  |             // or single character before the colon is not a resource type, but part of the filepath | ||||||
|  |             $type = $smarty->default_resource_type; | ||||||
|  |             $name = $template_resource; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         $handler = isset($smarty->_cache['resource_handlers'][$type]) ? | ||||||
|  |             $smarty->_cache['resource_handlers'][$type] : | ||||||
|  |             Smarty_Resource::load($smarty, $type); | ||||||
|         // if resource is not recompiling and resource name is not dotted we can check the source cache |         // if resource is not recompiling and resource name is not dotted we can check the source cache | ||||||
|         if ($smarty->resource_caching && !$resource->recompiled && !(isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'))) { |         if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$handler->recompiled && | ||||||
|             $unique_resource = $resource->buildUniqueResourceName($smarty, $name); |             !(isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/')) | ||||||
|             if (isset($smarty->source_objects[$unique_resource])) { |         ) { | ||||||
|                 return $smarty->source_objects[$unique_resource]; |             $unique_resource = $handler->buildUniqueResourceName($smarty, $name); | ||||||
|  |             if (isset($smarty->_cache['source_objects'][$unique_resource])) { | ||||||
|  |                 return $smarty->_cache['source_objects'][$unique_resource]; | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             $unique_resource = null; |             $unique_resource = null; | ||||||
|         } |         } | ||||||
|         // create new source  object |         // create new source  object | ||||||
|         $source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name); |         $source = new Smarty_Template_Source($handler, $smarty, $template_resource, $type, $name); | ||||||
|         $resource->populate($source, $_template); |         $handler->populate($source, $_template); | ||||||
|         if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_template_handler_func)) { |         if (!$source->exists && isset($_template->smarty->default_template_handler_func)) { | ||||||
|             Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resObj); |             Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source); | ||||||
|         } |         } | ||||||
|         // on recompiling resources we are done |         // on recompiling resources we are done | ||||||
|         if ($smarty->resource_caching && !$resource->recompiled) { |         if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$handler->recompiled) { | ||||||
|             // may by we have already $unique_resource |             // may by we have already $unique_resource | ||||||
|             $is_relative = false; |             $is_relative = false; | ||||||
|             if (!isset($unique_resource)) { |             if (!isset($unique_resource)) { | ||||||
|                 $is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') && |                 $is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') && | ||||||
|                     ($type == 'file' || (isset($_template->parent->source) && $_template->parent->source->type == 'extends')); |                     ($type == 'file' || | ||||||
|                 $unique_resource = $resource->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name); |                         (isset($_template->parent->source) && $_template->parent->source->type == 'extends')); | ||||||
|  |                 $unique_resource = | ||||||
|  |                     $handler->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name); | ||||||
|             } |             } | ||||||
|             $source->unique_resource = $unique_resource; |             $source->unique_resource = $unique_resource; | ||||||
|             // save in runtime cache if not relative |             // save in runtime cache if not relative | ||||||
|             if (!$is_relative) { |             if (!$is_relative) { | ||||||
|                 $smarty->source_objects[$unique_resource] = $source; |                 $smarty->_cache['source_objects'][$unique_resource] = $source; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return $source; |         return $source; | ||||||
| @@ -216,70 +211,57 @@ class Smarty_Template_Source | |||||||
|      * render the uncompiled source |      * render the uncompiled source | ||||||
|      * |      * | ||||||
|      * @param Smarty_Internal_Template $_template template object |      * @param Smarty_Internal_Template $_template template object | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      * @throws \Exception | ||||||
|      */ |      */ | ||||||
|     public function renderUncompiled(Smarty_Internal_Template $_template) |     public function renderUncompiled(Smarty_Internal_Template $_template) | ||||||
|     { |     { | ||||||
|         $level = ob_get_level(); |  | ||||||
|         ob_start(); |  | ||||||
|         try { |  | ||||||
|         $this->handler->renderUncompiled($_template->source, $_template); |         $this->handler->renderUncompiled($_template->source, $_template); | ||||||
|             return ob_get_clean(); |  | ||||||
|     } |     } | ||||||
|         catch (Exception $e) { |  | ||||||
|             while (ob_get_level() > $level) { |     /** | ||||||
|                 ob_end_clean(); |      * Render uncompiled source | ||||||
|  |      * | ||||||
|  |      * @param \Smarty_Internal_Template $_template | ||||||
|  |      */ | ||||||
|  |     public function render(Smarty_Internal_Template $_template) | ||||||
|  |     { | ||||||
|  |         if ($_template->source->handler->uncompiled) { | ||||||
|  |             if ($_template->smarty->debugging) { | ||||||
|  |                 $_template->smarty->_debug->start_render($_template); | ||||||
|  |             } | ||||||
|  |             $this->handler->renderUncompiled($_template->source, $_template); | ||||||
|  |             if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) { | ||||||
|  |                 $_template->parent->tpl_function = | ||||||
|  |                     array_merge($_template->parent->tpl_function, $_template->tpl_function); | ||||||
|  |             } | ||||||
|  |             if ($_template->smarty->debugging) { | ||||||
|  |                 $_template->smarty->_debug->end_render($_template); | ||||||
|             } |             } | ||||||
|             throw $e; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * <<magic>> Generic Setter. |      * Get source time stamp | ||||||
|      * |      * | ||||||
|      * @param  string $property_name valid: timestamp, exists, content, template |      * @return int | ||||||
|      * @param  mixed  $value         new value (is not checked) |  | ||||||
|      * |  | ||||||
|      * @throws SmartyException if $property_name is not valid |  | ||||||
|      */ |      */ | ||||||
|     public function __set($property_name, $value) |     public function getTimeStamp() | ||||||
|     { |     { | ||||||
|         switch ($property_name) { |         if (!isset($this->timestamp)) { | ||||||
|             // regular attributes |  | ||||||
|             case 'timestamp': |  | ||||||
|             case 'exists': |  | ||||||
|             case 'content': |  | ||||||
|                 // required for extends: only |  | ||||||
|             case 'template': |  | ||||||
|                 $this->$property_name = $value; |  | ||||||
|                 break; |  | ||||||
|  |  | ||||||
|             default: |  | ||||||
|                 throw new SmartyException("source property '$property_name' does not exist."); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * <<magic>> Generic getter. |  | ||||||
|      * |  | ||||||
|      * @param  string $property_name valid: timestamp, exists, content |  | ||||||
|      * |  | ||||||
|      * @return mixed |  | ||||||
|      * @throws SmartyException if $property_name is not valid |  | ||||||
|      */ |  | ||||||
|     public function __get($property_name) |  | ||||||
|     { |  | ||||||
|         switch ($property_name) { |  | ||||||
|             case 'timestamp': |  | ||||||
|             case 'exists': |  | ||||||
|             $this->handler->populateTimestamp($this); |             $this->handler->populateTimestamp($this); | ||||||
|  |         } | ||||||
|  |         return $this->timestamp; | ||||||
|  |     } | ||||||
|  |  | ||||||
|                 return $this->$property_name; |     /** | ||||||
|  |      * Get source content | ||||||
|             case 'content': |      * | ||||||
|                 return $this->content = $this->handler->getContent($this); |      * @return string | ||||||
|  |      */ | ||||||
|             default: |     public function getContent() | ||||||
|                 throw new SmartyException("source property '$property_name' does not exist."); |     { | ||||||
|         } |         return isset($this->content) ? $this->content : $this->handler->getContent($this); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,25 +21,17 @@ class Smarty_Variable | |||||||
|      * @var boolean |      * @var boolean | ||||||
|      */ |      */ | ||||||
|     public $nocache = false; |     public $nocache = false; | ||||||
|     /** |  | ||||||
|      * the scope the variable will have  (local,parent or root) |  | ||||||
|      * |  | ||||||
|      * @var int |  | ||||||
|      */ |  | ||||||
|     public $scope = Smarty::SCOPE_LOCAL; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * create Smarty variable object |      * create Smarty variable object | ||||||
|      * |      * | ||||||
|      * @param mixed   $value   the value to assign |      * @param mixed   $value   the value to assign | ||||||
|      * @param boolean $nocache if true any output of this variable will be not cached |      * @param boolean $nocache if true any output of this variable will be not cached | ||||||
|      * @param int     $scope   the scope the variable will have  (local,parent or root) |  | ||||||
|      */ |      */ | ||||||
|     public function __construct($value = null, $nocache = false, $scope = Smarty::SCOPE_LOCAL) |     public function __construct($value = null, $nocache = false) | ||||||
|     { |     { | ||||||
|         $this->value = $value; |         $this->value = $value; | ||||||
|         $this->nocache = $nocache; |         $this->nocache = $nocache; | ||||||
|         $this->scope = $scope; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user