diff --git a/include/smarty/INHERITANCE_RELEASE_NOTES.txt b/include/smarty/INHERITANCE_RELEASE_NOTES.txt
index 8b2c64a1b..c415c4ccd 100644
--- a/include/smarty/INHERITANCE_RELEASE_NOTES.txt
+++ b/include/smarty/INHERITANCE_RELEASE_NOTES.txt
@@ -1,3 +1,14 @@
+3.1.31-dev
+New tags for inheritance parent and child
+{block_parent} == {$smarty.block.parent}
+{block_child} == {$smarty.block.child}
+
+Since 3.1.28 you can mix inheritance by extends resource with the {extends} tag.
+A template called by extends resource can extend a subtemplate or chain buy the {extends} tag.
+Since 3.1.31 this feature can be turned off by setting the new Smarty property Smarty::$extends_recursion to false.
+
+
+3.1.28
Starting with version 3.1.28 template inheritance is no longer a compile time process.
All {block} tag parent/child relations are resolved at run time.
This does resolve all known existing restrictions (see below).
@@ -5,7 +16,7 @@ This does resolve all known existing restrictions (see below).
The $smarty::$inheritance_merge_compiled_includes property has been removed.
Any access to it is ignored.
-This does enable some new features:
+New features:
Any code outside root {block} tags in child templates is now executed but any output will be ignored.
@@ -31,7 +42,16 @@ Any code outside root {block} tags in child templates is now executed but any ou
{/if}
{/block}
+{block} tags can have variable names.
+ {block $foo}
+ ....
+ {/block}
+
+Starting with 3.1.28 you can mix inheritance by extends resource with the {extends} tag.
+A template called by extends resource can extend a subtemplate or chain buy the {extends} tag.
+
+NOTE There is a BC break. If you used the extends resource {extends} tags have been ignored.
THE FOLLOWING RESTRICTIONS ARE NO LONGER EXISTING:
In Smarty 3.1 template inheritance is a compile time process. All the extending of {block} tags
diff --git a/include/smarty/LICENSE b/include/smarty/LICENSE
new file mode 100644
index 000000000..fb8ca6c6f
--- /dev/null
+++ b/include/smarty/LICENSE
@@ -0,0 +1,179 @@
+Smarty: the PHP compiling template engine
+
+ 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 below for more details.
+
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/include/smarty/NEW_FEATURES.txt b/include/smarty/NEW_FEATURES.txt
index 1a51c71d9..adbc1099b 100644
--- a/include/smarty/NEW_FEATURES.txt
+++ b/include/smarty/NEW_FEATURES.txt
@@ -2,6 +2,114 @@
This file contains a brief description of new features which have been added to Smarty 3.1
+Smarty 3.1.31
+ New tags for inheritance parent and child
+ =========================================
+ {block_parent} == {$smarty.block.parent}
+ {block_child} == {$smarty.block.child}
+
+Smarty 3.1.30
+
+ Loop optimization {foreach} and {section}
+ =========================================
+ Smarty does optimize the {foreach} and {section} loops by removing code for not needed loop
+ properties.
+ The compiler collects needed properties by scanning the current template for $item@property,
+ $smarty.foreach.name.property and $smarty.section.name.property.
+ The compiler does not know if additional properties will be needed outside the current template scope.
+ Additional properties can be generated by adding them with the property attribute.
+
+ Example:
+ index.tpl
+ {foreach $from as $item properties=[iteration, index]}
+ {include 'sub.tpl'}
+ {$item.total}
+ {/foreach}
+
+ sub.tpl
+ {$item.index} {$item.iteration} {$item.total}
+
+ In above example code for the 'total' property is automatically generated as $item.total is used in
+ index.tpl. Code for 'iteration' and 'index' must be added with properties=[iteration, index].
+
+ New tag {make_nocache}
+ ======================
+ Syntax: {make_nocache $foo}
+
+ This tag makes a variable which does exists normally only while rendering the compiled template
+ available in the cached template for use in not cached expressions.
+
+ Expample:
+ {foreach from=$list item=item}
+
{$item.name} {make_nocache $item}{if $current==$item.id} ACTIVE{/if}
+ {/foreach}
+
+ The {foreach} loop is rendered while processing the compiled template, but $current is a nocache
+ variable. Normally the {if $current==$item.id} would fail as the $item variable is unkown in the
+ cached template. {make_nocache $item} does make the current $item value known in thee cached template.
+
+ {make_nocache} is ignored when caching is disabled or the variable does exists as nocache variable.
+
+ NOTE: if the variable value does contain objects these must have the __set_state method implemented.
+
+
+ Scope Attributes
+ ================
+ The scope handling has been updated to cover all cases of variable assignments in templates.
+
+ The tags {assign}, {append} direct assignments like {$foo = ...}, {$foo[...]= ...} support
+ the following optional scope attributes:
+ scope='parent' - the variable will be assigned in the current template and if the template
+ was included by {include} the calling template
+ scope='tpl_root' - the variable will be assigned in the outermost root template called by $smarty->display()
+ or $smarty->fetch() and is bubbled up all {include} sub-templates to the current template.
+ scope='smarty' - the variable will be assigned in the Smarty object and is bubbled up all {include} sub-templates
+ to the current template.
+ scope='global' - the variable will be assigned as Smarty object global variable and is bubbled up all {include}
+ sub-templates to the current template.
+ scope='root' - the variable will be assigned if a data object was used for variable definitions in the data
+ object or in the Smarty object otherwise and is bubbled up all {include} sub-templates to the
+ current template.
+ scope='local' - this scope has only a meaning if the tag is called within a template {function}.
+ The variable will be assigned in the local scope of the template function and the
+ template which did call the template function.
+
+
+ The {config_load} tag supports all of the above except the global scope.
+
+ The scope attribute can be used also with the {include} tag.
+ Supported scope are parent, tpl_root, smarty, global and root.
+ A scope used together with the {include} tag will cause that with some exceptions any variable
+ assignment within that sub-template will update/assign the variable in other scopes according
+ to the above rules. It does include also variables assigned by plugins, tags supporting the assign=foo
+ attribute and direct assignments in {if} and {while} like {if $foo=$bar}.
+ Excluded are the key and value variables of {foreach}, {for} loop variables , variables passed by attributes
+ in {include} and direct increments/decrements like {$foo++}, {$foo--}
+
+ Note: The scopes should be used only to the extend really need. If a variable value assigned in an included
+ sub-template should be returned to the calling sub-template just use {$foo='bar' scope='parent'}.
+ Use scopes only with variables for which it's realy needed. Avoid general scope settings with the
+ {include} tag as it can have a performance impact.
+
+ The {assign}, {append}, {config_load} and {$foo...=...} tags have a new option flag 'noscope'.Thi
+ Example: {$foo='bar' noscope} This will assign $foo only in the current template and any scope settings
+ at {include} is ignored.
+
+
+ Caching
+ =======
+ Caching does now observe the template_dir setting and will create separate cache files if required
+
+ Compiled Templates
+ ==================
+ The template_dir setting is now encoded in the uid of the file name.
+ The content of the compiled template may depend on the template_dir search order
+ {include .... inline} is used or $smarty->merge_compiled_includes is enabled
+
+ APC
+ ===
+ If APC is enabled force an apc_compile_file() when compiled or cached template was updated
+
Smarty 3.1.28
OPCACHE
@@ -32,7 +140,7 @@ Smarty 3.1.28
The template_dir array is searched in the order of the indices. (Could be used to change the default search order)
Example:
$smarty->display('[1],[0]foo.bar');
-
+
Filter support
==============
Optional filter names
@@ -47,7 +155,7 @@ Smarty 3.1.28
If you register multiple closures register each with a unique filter name.
- $smarty->registerFilter('pre', function($source) {return $source;}, 'closure_1');
- $smarty->registerFilter('pre', function($source) {return $source;}, 'closure_2');
-
+
Smarty 3.1.22
@@ -120,7 +228,7 @@ Smarty 3.1.22
Debugging
=========
The layout of the debug window has been changed for better readability
-
+
New class constants
Smarty::DEBUG_OFF
Smarty::DEBUG_ON
@@ -129,5 +237,3 @@ Smarty 3.1.22
Smarty::DEBUG_INDIVIDUAL will create for each display() and fetch() call an individual debug window.
- .
-
diff --git a/include/smarty/change_log.txt b/include/smarty/change_log.txt
index dadc5d17d..1d42b0a76 100644
--- a/include/smarty/change_log.txt
+++ b/include/smarty/change_log.txt
@@ -1,11 +1,348 @@
- ===== 3.1.29 ===== (21.12.2015)
+===== 3.1.31 ===== (14.12.2016)
+ 23.11.2016
+ - move template object cache into static variables
+
+ 19.11.2016
+ - bugfix inheritance root child templates containing nested {block}{/block} could call sub-bock content from parent
+ template https://github.com/smarty-php/smarty/issues/317
+ - change version checking
+
+ 11.11.2016
+ - bugfix when Smarty is using a cached template object on Smarty::fetch() or Smarty::isCached() the inheritance data
+ must be removed https://github.com/smarty-php/smarty/issues/312
+ - smaller speed optimization
+
+ 08.11.2016
+ - add bootstrap file to load and register Smarty_Autoloader. Change composer.json to make it known to composer
+
+ 07.11.2016
+ - optimization of lexer speed https://github.com/smarty-php/smarty/issues/311
+
+ 27.10.2016
+ - bugfix template function definitions array has not been cached between Smarty::fetch() and Smarty::display() calls
+ https://github.com/smarty-php/smarty/issues/301
+
+ 23.10.2016
+ - improvement/bugfix when Smarty::fetch() is called on a template object the inheritance and tplFunctions property
+ should be copied to the called template object
+
+ 21.10.2016
+ - bugfix for compile locking touched timestamp of old compiled file was not restored on compilation error https://github.com/smarty-php/smarty/issues/308
+
+ 20.10.2016
+ - bugfix nocache code was not removed in cache file when subtemplate did contain PHP short tags in text but no other
+ nocache code https://github.com/smarty-php/smarty/issues/300
+
+ 19.10.2016
+ - bugfix {make_nocache $var} did fail when variable value did contain '\' https://github.com/smarty-php/smarty/issues/305
+ - bugfix {make_nocache $var} remove spaces from variable value https://github.com/smarty-php/smarty/issues/304
+
+ 12.10.2016
+ - bugfix {include} with template names including variable or constants could fail after bugfix from
+ 28.09.2016 https://github.com/smarty-php/smarty/issues/302
+
+ 08.10.2016
+ - optimization move runtime extension for template functions into Smarty objects
+
+ 29.09.2016
+ - improvement new Smarty::$extends_recursion property to disable execution of {extends} in templates called by extends resource
+ https://github.com/smarty-php/smarty/issues/296
+
+ 28.09.2016
+ - bugfix the generated code for calling a subtemplate must pass the template resource name in single quotes https://github.com/smarty-php/smarty/issues/299
+ - bugfix nocache hash was not removed for tags in subtemplates https://github.com/smarty-php/smarty/issues/300
+
+ 27.09.2016
+ - bugfix when Smarty does use an internally cached template object on Smarty::fetch() calls
+ the template and config variables must be cleared https://github.com/smarty-php/smarty/issues/297
+
+ 20.09.2016
+ - bugfix some $smarty special template variables are no longer accessed as real variable.
+ using them on calls like {if isset($smarty.foo)} or {if empty($smarty.foo)} will fail
+ http://www.smarty.net/forums/viewtopic.php?t=26222
+ - temporary fix for https://github.com/smarty-php/smarty/issues/293 main reason still under investigation
+ - improvement new tags {block_parent} {block_child} in template inheritance
+
+ 19.09.2016
+ - optimization clear compiled and cached folder completely on detected version change
+ - cleanup convert cache resource file method clear into runtime extension
+
+ 15.09.2016
+ - bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
+ - bugfix function plugins called with assign attribute like {foo assign='bar'} did not output returned content because
+ because assumption was made that it was assigned to a variable https://github.com/smarty-php/smarty/issues/292
+ - bugfix calling $smarty->isCached() on a not existing cache file with $smarty->cache_locking = true; could cause a 10 second delay http://www.smarty.net/forums/viewtopic.php?t=26282
+ - improvement make Smarty::clearCompiledTemplate() on custom resource independent from changes of templateId computation
+
+ 11.09.2016
+ - improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288
+ - improvement move often used code snippets into methods
+ - performance Smarty::configLoad() did load unneeded template source object
+
+ 09.09.2016
+ - bugfix/optimization {foreach} did not execute the {foreachelse} when iterating empty objects https://github.com/smarty-php/smarty/pull/287
+ - bugfix {foreach} must keep the @properties when restoring a saved $item variable as the properties might be used outside {foreach} https://github.com/smarty-php/smarty/issues/267
+ - improvement {foreach} observe {break n} and {continue n} nesting levels when restoring saved $item and $key variables
+
+ 08.09.2016
+ - bugfix implement wrapper for removed method getConfigVariable() https://github.com/smarty-php/smarty/issues/286
+
+ 07.09.2016
+ - bugfix using nocache like attribute with value true like {plugin nocache=true} did not work https://github.com/smarty-php/smarty/issues/285
+ - bugfix uppercase TRUE, FALSE and NULL did not work when security was enabled https://github.com/smarty-php/smarty/issues/282
+ - bugfix when {foreach} was looping over an object the total property like {$item@total} did always return 1 https://github.com/smarty-php/smarty/issues/281
+ - bugfix {capture}{/capture} did add in 3.1.30 unintended additional blank lines https://github.com/smarty-php/smarty/issues/268
+
+ 01.09.2016
+ - performance require_once should be called only once for shared plugins https://github.com/smarty-php/smarty/issues/280
+
+ 26.08.2016
+ - bugfix change of 23.08.2016 failed on linux when use_include_path = true
+
+ 23.08.2016
+ - bugfix remove constant DS as shortcut for DIRECTORY_SEPARATOR as the user may have defined it to something else https://github.com/smarty-php/smarty/issues/277
+
+ 20.08-2016
+ - bugfix {config_load ... scope="global"} shall not throw an arror but fallback to scope="smarty" https://github.com/smarty-php/smarty/issues/274
+ - bugfix {make_nocache} failed when using composer autoloader https://github.com/smarty-php/smarty/issues/275
+
+ 14.08.2016
+ - bugfix $smarty_>debugging = true; did E_NOTICE messages when {eval} tag was used https://github.com/smarty-php/smarty/issues/266
+ - bugfix Class 'Smarty_Internal_Runtime_ValidateCompiled' not found when upgrading from some older Smarty versions with existing
+ compiled or cached template files https://github.com/smarty-php/smarty/issues/269
+ - optimization remove unneeded call to update acopes when {assign} scope and template scope was local (default)
+
+===== 3.1.30 ===== (07.08.2016)
+
+ 07.08.2016
+ - bugfix update of 04.08.2016 was incomplete
+
+ 05.08.2016
+ - bugfix compiling of templates failed when the Smarty delimiter did contain '/' https://github.com/smarty-php/smarty/issues/264
+ - updated error checking at template and config default handler
+
+ 04.08.2016
+ - improvement move template function source parameter into extension
+
+ 26.07.2016
+ - optimization unneeded loading of compiled resource
+
+ 24.07.2016
+ - regression this->addPluginsDir('/abs/path/to/dir') adding absolute path without trailing '/' did fail https://github.com/smarty-php/smarty/issues/260
+
+ 23.07.2016
+ - bugfix setTemplateDir('/') and setTemplateDir('') did create wrong absolute filepath https://github.com/smarty-php/smarty/issues/245
+ - optimization of filepath normalization
+ - improvement remove double function declaration in plugin shared.escape_special_cars.php https://github.com/smarty-php/smarty/issues/229
+
+ 19.07.2016
+ - bugfix multiple {include} with relative filepath within {block}{/block} could fail https://github.com/smarty-php/smarty/issues/246
+ - bugfix {math} shell injection vulnerability patch provided by Tim Weber
+
+ 18.07.2016
+ - bugfix {foreach} if key variable and item@key attribute have been used both the key variable was not updated https://github.com/smarty-php/smarty/issues/254
+ - bugfix modifier on plugins like {plugin|modifier ... } did fail when the plugin does return an array https://github.com/smarty-php/smarty/issues/228
+ - bugfix avoid opcache_invalidate to result in ErrorException when opcache.restrict_api is not empty https://github.com/smarty-php/smarty/pull/244
+ - bugfix multiple {include} with relative filepath within {block}{/block} could fail https://github.com/smarty-php/smarty/issues/246
+
+ 14.07.2016
+ - bugfix wrong parameter on compileAllTemplates() and compileAllConfig() https://github.com/smarty-php/smarty/issues/231
+
+ 13.07.2016
+ - bugfix PHP 7 compatibility on registered compiler plugins https://github.com/smarty-php/smarty/issues/241
+ - update testInstall() https://github.com/smarty-php/smarty/issues/248https://github.com/smarty-php/smarty/issues/248
+ - bugfix enable debugging could fail when template objects did already exists https://github.com/smarty-php/smarty/issues/237
+ - bugfix template function data should be merged when loading subtemplate https://github.com/smarty-php/smarty/issues/240
+ - bugfix wrong parameter on compileAllTemplates() https://github.com/smarty-php/smarty/issues/231
+
+ 12.07.2016
+ - bugfix {foreach} item variable must be created also on empty from array https://github.com/smarty-php/smarty/issues/238 and https://github.com/smarty-php/smarty/issues/239
+ - bugfix enableSecurity() must init cache flags https://github.com/smarty-php/smarty/issues/247
+
+ 27.05.2016
+ - bugfix/improvement of compileAlltemplates() follow symlinks in template folder (PHP >= 5.3.1) https://github.com/smarty-php/smarty/issues/224
+ clear internal cache and expension handler for each template to avoid possible conflicts https://github.com/smarty-php/smarty/issues/231
+
+ 16.05.2016
+ - optimization {foreach} compiler and processing
+ - broken PHP 5.3 and 5.4 compatibility
+
+ 15.05.2016
+ - optimization and cleanup of resource code
+
+ 10.05.2016
+ - optimization of inheritance processing
+
+ 07.05.2016
+ -bugfix Only variables should be assigned by reference https://github.com/smarty-php/smarty/issues/227
+
+ 02.05.2016
+ - enhancement {block} tag names can now be variable https://github.com/smarty-php/smarty/issues/221
+
+ 01.05.2016
+ - bugfix same relative filepath at {include} called from template in different folders could display wrong sub-template
+
+ 29.04.2016
+ - bugfix {strip} remove space on linebreak between html tags https://github.com/smarty-php/smarty/issues/213
+
+ 24.04.2016
+ - bugfix nested {include} with relative file path could fail when called in {block} ... {/block} https://github.com/smarty-php/smarty/issues/218
+
+ 14.04.2016
+ - bugfix special variable {$smarty.capture.name} was not case sensitive on name https://github.com/smarty-php/smarty/issues/210
+ - bugfix the default template handler must calculate the source uid https://github.com/smarty-php/smarty/issues/205
+
+ 13.04.2016
+ - bugfix template inheritance status must be saved when calling sub-templates https://github.com/smarty-php/smarty/issues/215
+
+ 27.03.2016
+ - bugfix change of 11.03.2016 cause again {capture} data could not been seen in other templates with {$smarty.capture.name} https://github.com/smarty-php/smarty/issues/153
+
+ 11.03.2016
+ - optimization of capture and security handling
+ - improvement $smarty->clearCompiledTemplate() should return on recompiled or uncompiled resources
+
+ 10.03.2016
+ - optimization of resource processing
+
+ 09.03.2016
+ - improvement rework of 'scope' attribute handling see see NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/194
+ https://github.com/smarty-php/smarty/issues/186 https://github.com/smarty-php/smarty/issues/179
+ - bugfix correct Autoloader update of 2.3.2014 https://github.com/smarty-php/smarty/issues/199
+
+ 04.03.2016
+ - bugfix change from 01.03.2016 will cause $smarty->isCached(..) failure if called multiple time for same template
+ (forum topic 25935)
+
+ 02.03.2016
+ - revert autoloader optimizations because of unexplainable warning when using plugins https://github.com/smarty-php/smarty/issues/199
+
+ 01.03.2016
+ - bugfix template objects must be cached on $smarty->fetch('foo.tpl) calls incase the template is fetched
+ multiple times (forum topic 25909)
+
+ 25.02.2016
+ - bugfix wrong _realpath with 4 or more parent-directories https://github.com/smarty-php/smarty/issues/190
+ - optimization of _realpath
+ - bugfix instanceof expression in template code must be treated as value https://github.com/smarty-php/smarty/issues/191
+
+ 20.02.2016
+ - bugfix {strip} must keep space between hmtl tags. Broken by changes of 10.2.2016 https://github.com/smarty-php/smarty/issues/184
+ - new feature/bugfix {foreach}{section} add 'properties' attribute to force compilation of loop properties
+ see NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/189
+
+ 19.02.2016
+ - revert output buffer flushing on display, echo content again because possible problems when PHP files had
+ characters (newline} after ?> at file end https://github.com/smarty-php/smarty/issues/187
+
+ 14.02.2016
+ - new tag {make_nocache} read NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/110
+ - optimization of sub-template processing
+ - bugfix using extendsall as default resource and {include} inside {block} tags could produce unexpected results https://github.com/smarty-php/smarty/issues/183
+ - optimization of tag attribute compiling
+ - optimization make compiler tag object cache static for higher compilation speed
+
+ 11.02.2016
+ - improvement added KnockoutJS comments to trimwhitespace outputfilter https://github.com/smarty-php/smarty/issues/82
+ https://github.com/smarty-php/smarty/pull/181
+
+ 10.02.2016
+ - bugfix {strip} must keep space on output creating smarty tags within html tags https://github.com/smarty-php/smarty/issues/177
+ - bugfix wrong precedence on special if conditions like '$foo is ... by $bar' could cause wrong code https://github.com/smarty-php/smarty/issues/178
+ - improvement because of ambiguities the inline constant support has been removed from the $foo.bar syntax https://github.com/smarty-php/smarty/issues/149
+ - bugfix other {strip} error with output tags between hmtl https://github.com/smarty-php/smarty/issues/180
+
+ 09.02.2016
+ - move some code from parser into compiler
+ - reformat all code for unique style
+ - update/bugfix scope attribute handling reworked. Read the newfeatures.txt file
+
+ 05.02.2016
+ - improvement internal compiler changes
+
+ 01.02.2016
+ - bugfix {foreach} compilation failed when $smarty->merge_compiled_includes = true and pre-filters are used.
+
+ 29.01.2016
+ - bugfix implement replacement code for _tag_stack property https://github.com/smarty-php/smarty/issues/151
+
+ 28.01.2016
+ - bugfix allow windows network filepath or wrapper (forum topic 25876) https://github.com/smarty-php/smarty/issues/170
+ - bugfix if fetch('foo.tpl') is called on a template object the $parent parameter should default to the calling template object https://github.com/smarty-php/smarty/issues/152
+
+ 27.01.2016
+ - revert bugfix compiling {section} did create warning
+ - bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
+ update of yesterdays fix
+ - bugfix string resource could inject code at {block} or inline subtemplates through PHP comments https://github.com/smarty-php/smarty/issues/157
+ - bugfix output filters did not observe nocache code flhttps://github.com/smarty-php/smarty/issues/154g https://github.com/smarty-php/smarty/issues/160
+ - bugfix {extends} with relative file path did not work https://github.com/smarty-php/smarty/issues/154
+ https://github.com/smarty-php/smarty/issues/158
+ - bugfix {capture} data could not been seen in other templates with {$smarty.capture.name} https://github.com/smarty-php/smarty/issues/153
+
+ 26.01.2016
+ - improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169
+ - bugfix compiling {section} did create warning
+ - bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
+
+ 02.01.2016
+ - update scope handling
+ - optimize block plugin compiler
+ - improvement runtime checks if registered block plugins are callable
+
+ 01.01.2016
+ - remove Smarty::$resource_cache_mode property
+
+ 31.12.2015
+ - optimization of {assign}, {if} and {while} compiled code
+
+ 30.12.2015
+ - bugfix plugin names starting with "php" did not compile https://github.com/smarty-php/smarty/issues/147
+
+ 29.12.2015
+ - bugfix Smarty::error_reporting was not observed when display() or fetch() was called on template objects https://github.com/smarty-php/smarty/issues/145
+
+ 28.12.2015
+ - optimization of {foreach} code size and processing
+
+ 27.12.2015
+ - improve inheritance code
+ - update external methods
+ - code fixes
+ - PHPdoc updates
+
+ 25.12.2015
+ - compile {block} tag code and its processing into classes
+ - optimization replace hhvm extension by inline code
+ - new feature If ACP is enabled force an apc_compile_file() when compiled or cached template was updated
+
+ 24.12.2015
+ - new feature Compiler does now observe the template_dir setting and will create separate compiled files if required
+ - bugfix post filter did fail on template inheritance https://github.com/smarty-php/smarty/issues/144
+
+ 23.12.2015
+ - optimization move internal method decodeProperties back into template object
+ - optimization move subtemplate processing back into template object
+ - new feature Caching does now observe the template_dir setting and will create separate cache files if required
+
+ 22.12.2015
+ - change $xxx_dir properties from private to protected in case Smarty class gets extended
+ - code optimizations
+
+ 21.12.2015
+ - bugfix a filepath starting with '/' or '\' on windows should normalize to the root dir
+ of current working drive https://github.com/smarty-php/smarty/issues/134
+ - optimization of filepath normalization
+ - bugfix {strip} must remove all blanks between html tags https://github.com/smarty-php/smarty/issues/136
+
+ ===== 3.1.29 ===== (21.12.2015)
21.12.2015
- optimization improve speed of filetime checks on extends and extendsall resource
20.12.2015
- bugfix failure when the default resource type was set to 'extendsall' https://github.com/smarty-php/smarty/issues/123
- update compilation of Smarty special variables
- - bugfix add addition check for OS type on normalizaition of file path https://github.com/smarty-php/smarty/issues/134
+ - bugfix add addition check for OS type on normalization of file path https://github.com/smarty-php/smarty/issues/134
- bugfix the source uid of the extendsall resource must contain $template_dir settings https://github.com/smarty-php/smarty/issues/123
19.12.2015
@@ -15,7 +352,7 @@
- improvement make sure that compiled and cache templates never can contain a trailing '?>?
18.12.2015
- - bugfix regression when modifier parameter was follow by math https://github.com/smarty-php/smarty/issues/132
+ - bugfix regression when modifier parameter was followed by math https://github.com/smarty-php/smarty/issues/132
17.12.2015
- bugfix {$smarty.capture.nameFail} did lowercase capture name https://github.com/smarty-php/smarty/issues/135
diff --git a/include/smarty/libs/Autoloader.php b/include/smarty/libs/Autoloader.php
index 7d0c388a6..d3b039caa 100644
--- a/include/smarty/libs/Autoloader.php
+++ b/include/smarty/libs/Autoloader.php
@@ -11,11 +11,12 @@
* @package Smarty
* @author Uwe Tews
* Usage:
- * require_once '...path/Autoloader.php';
- * Smarty_Autoloader::register();
- * $smarty = new Smarty();
- * Note: This autoloader is not needed if you use Composer.
- * Composer will automatically add the classes of the Smarty package to it common autoloader.
+ * require_once '...path/Autoloader.php';
+ * Smarty_Autoloader::register();
+ * or
+ * include '...path/bootstarp.php';
+ *
+ * $smarty = new Smarty();
*/
class Smarty_Autoloader
{
@@ -24,14 +25,14 @@ class Smarty_Autoloader
*
* @var string
*/
- public static $SMARTY_DIR = '';
+ public static $SMARTY_DIR = null;
/**
* Filepath to Smarty internal plugins
*
* @var string
*/
- public static $SMARTY_SYSPLUGINS_DIR = '';
+ public static $SMARTY_SYSPLUGINS_DIR = null;
/**
* Array with Smarty core classes and their filename
@@ -57,7 +58,7 @@ class Smarty_Autoloader
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
- if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
+ if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
spl_autoload_register();
}
} else {
@@ -89,36 +90,21 @@ class Smarty_Autoloader
*/
public static function autoload($class)
{
+ if ($class[ 0 ] !== 'S' && strpos($class, 'Smarty') !== 0) {
+ return;
+ }
$_class = strtolower($class);
- $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
- if (strpos($_class, 'smarty_internal_') === 0) {
- if (strpos($_class, 'smarty_internal_compile_') === 0) {
- if (is_file($file)) {
- require $file;
- }
- return;
+ if (isset(self::$rootClasses[ $_class ])) {
+ $file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
+ if (is_file($file)) {
+ include $file;
}
- @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;
+ } else {
+ $file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
+ if (is_file($file)) {
+ include $file;
}
}
- if (0 !== strpos($_class, 'smarty')) {
- return;
- }
- if (is_file($file)) {
- require $file;
- return;
- }
return;
}
}
diff --git a/include/smarty/libs/Smarty.class.php b/include/smarty/libs/Smarty.class.php
index a029f942e..57eedfb93 100644
--- a/include/smarty/libs/Smarty.class.php
+++ b/include/smarty/libs/Smarty.class.php
@@ -21,28 +21,21 @@
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
- * @copyright 2015 New Digital Group, Inc.
- * @copyright 2015 Uwe Tews
+ * @copyright 2016 New Digital Group, Inc.
+ * @copyright 2016 Uwe Tews
* @author Monte Ohrt
* @author Uwe Tews
* @author Rodney Rehm
* @package Smarty
- * @version 3.1.29
+ * @version 3.1.31
*/
-/**
- * define shorthand directory separator constant
- */
-if (!defined('DS')) {
- define('DS', DIRECTORY_SEPARATOR);
-}
-
/**
* set SMARTY_DIR to absolute path to Smarty library files.
* Sets SMARTY_DIR only if user application has not already defined it.
*/
if (!defined('SMARTY_DIR')) {
- define('SMARTY_DIR', dirname(__FILE__) . DS);
+ define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
/**
@@ -50,10 +43,10 @@ if (!defined('SMARTY_DIR')) {
* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
*/
if (!defined('SMARTY_SYSPLUGINS_DIR')) {
- define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
+ define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR);
}
if (!defined('SMARTY_PLUGINS_DIR')) {
- define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
+ define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DIRECTORY_SEPARATOR);
}
if (!defined('SMARTY_MBSTRING')) {
define('SMARTY_MBSTRING', function_exists('mb_get_info'));
@@ -73,23 +66,16 @@ if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
}
/**
- * Try loading the Smarty_Internal_Data class
- * If we fail we must load Smarty's autoloader.
- * Otherwise we may have a global autoloader like Composer
+ * Load Smarty_Autoloader
*/
-if (!class_exists('Smarty_Autoloader', false)) {
- if (!class_exists('Smarty_Internal_Data', true)) {
- require_once dirname(__FILE__) . '/Autoloader.php';
- Smarty_Autoloader::registerBC();
- }
+if (!class_exists('Smarty_Autoloader')) {
+ include __DIR__ . '/bootstrap.php';
}
/**
* Load always needed external class files
*/
-if (!class_exists('Smarty_Internal_Data', false)) {
- require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
-}
+require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php';
@@ -97,17 +83,21 @@ require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_variable.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_source.php';
require_once SMARTY_SYSPLUGINS_DIR . 'smarty_template_resource_base.php';
+require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php';
/**
* This is the main Smarty class
*
* @package Smarty
*
+ * The following methods will be dynamically loaded by the extension handler when they are called.
+ * They are located in a corresponding Smarty_Internal_Method_xxxx class
+ *
* @method int clearAllCache(int $exp_time = null, string $type = null)
* @method int clearCache(string $template_name, string $cache_id = null, string $compile_id = null, int $exp_time = null, string $type = null)
- * @method int compileAllTemplates(Smarty $smarty, string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
- * @method int compileAllConfig(Smarty $smarty, string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
- *
+ * @method int compileAllTemplates(string $extension = '.tpl', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
+ * @method int compileAllConfig(string $extension = '.conf', bool $force_compile = false, int $time_limit = 0, int $max_errors = null)
+ * @method int clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null)
*/
class Smarty extends Smarty_Internal_TemplateBase
{
@@ -118,12 +108,12 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
- const SMARTY_VERSION = '3.1.29';
+ const SMARTY_VERSION = '3.1.31';
/**
* define variable scopes
*/
- const SCOPE_LOCAL = 0;
+ const SCOPE_LOCAL = 1;
const SCOPE_PARENT = 2;
@@ -135,8 +125,6 @@ class Smarty extends Smarty_Internal_TemplateBase
const SCOPE_GLOBAL = 32;
- const SCOPE_BUBBLE_UP = 64;
-
/**
* define caching modes
*/
@@ -206,6 +194,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Resource caching modes
+ * (not used since 3.1.30)
*/
const RESOURCE_CACHE_OFF = 0;
@@ -288,7 +277,21 @@ class Smarty extends Smarty_Internal_TemplateBase
*
* @var array
*/
- private $template_dir = array('./templates/');
+ protected $template_dir = array('./templates/');
+
+ /**
+ * flags for normalized template directory entries
+ *
+ * @var array
+ */
+ protected $_processedTemplateDir = array();
+
+ /**
+ * flag if template_dir is normalized
+ *
+ * @var bool
+ */
+ public $_templateDirNormalized = false;
/**
* joined template directory string used in cache keys
@@ -297,6 +300,27 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public $_joined_template_dir = null;
+ /**
+ * config directory
+ *
+ * @var array
+ */
+ protected $config_dir = array('./configs/');
+
+ /**
+ * flags for normalized template directory entries
+ *
+ * @var array
+ */
+ protected $_processedConfigDir = array();
+
+ /**
+ * flag if config_dir is normalized
+ *
+ * @var bool
+ */
+ public $_configDirNormalized = false;
+
/**
* joined config directory string used in cache keys
*
@@ -330,28 +354,42 @@ class Smarty extends Smarty_Internal_TemplateBase
*
* @var string
*/
- private $compile_dir = './templates_c/';
+ protected $compile_dir = './templates_c/';
+
+ /**
+ * flag if template_dir is normalized
+ *
+ * @var bool
+ */
+ public $_compileDirNormalized = false;
/**
* plugins directory
*
* @var array
*/
- private $plugins_dir = null;
+ protected $plugins_dir = array();
+
+ /**
+ * flag if plugins_dir is normalized
+ *
+ * @var bool
+ */
+ public $_pluginsDirNormalized = false;
/**
* cache directory
*
* @var string
*/
- private $cache_dir = './cache/';
+ protected $cache_dir = './cache/';
/**
- * config directory
+ * flag if template_dir is normalized
*
- * @var array
+ * @var bool
*/
- private $config_dir = array('./configs/');
+ public $_cacheDirNormalized = false;
/**
* force template compiling?
@@ -388,6 +426,15 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public $merge_compiled_includes = false;
+ /*
+ * flag for behaviour when extends: resource and {extends} tag are used simultaneous
+ * if false disable execution of {extends} in templates called by extends resource.
+ * (behaviour as versions < 3.1.28)
+ *
+ * @var boolean
+ */
+ public $extends_recursion = true;
+
/**
* force cache file creation
*
@@ -562,13 +609,6 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public $default_config_type = 'file';
- /**
- * enable resource caching
- *
- * @var bool
- */
- public $resource_cache_mode = 1;
-
/**
* check If-Modified-Since headers
*
@@ -674,23 +714,30 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public $_debug = null;
+ /**
+ * Directory separator
+ *
+ * @var string
+ */
+ public $ds = DIRECTORY_SEPARATOR;
+
/**
* removed properties
*
* @var string[]
*/
- private static $obsoleteProperties = array('resource_caching', 'template_resource_caching',
- 'direct_access_security', '_dir_perms', '_file_perms',
- 'plugin_search_order', 'inheritance_merge_compiled_includes');
+ private $obsoleteProperties = array('resource_caching', 'template_resource_caching', 'direct_access_security',
+ '_dir_perms', '_file_perms', 'plugin_search_order',
+ 'inheritance_merge_compiled_includes', 'resource_cache_mode',);
/**
- * List of private properties which will call getter/setter ona direct access
+ * List of private properties which will call getter/setter on a direct access
*
- * @var array
+ * @var string[]
*/
- private static $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
- 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
- 'cache_dir' => 'CacheDir',);
+ private $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
+ 'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
+ 'cache_dir' => 'CacheDir',);
/**#@-*/
@@ -699,19 +746,19 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function __construct()
{
+ $this->_clearTemplateCache();
parent::__construct();
if (is_callable('mb_internal_encoding')) {
mb_internal_encoding(Smarty::$_CHARSET);
}
$this->start_time = microtime(true);
- if (isset($_SERVER['SCRIPT_NAME'])) {
- Smarty::$global_tpl_vars['SCRIPT_NAME'] = new Smarty_Variable($_SERVER['SCRIPT_NAME']);
+ if (isset($_SERVER[ 'SCRIPT_NAME' ])) {
+ Smarty::$global_tpl_vars[ 'SCRIPT_NAME' ] = new Smarty_Variable($_SERVER[ 'SCRIPT_NAME' ]);
}
// Check if we're running on windows
Smarty::$_IS_WINDOWS = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
-
// let PCRE (preg_*) treat strings as ISO-8859-1 if we're not dealing with UTF-8
if (Smarty::$_CHARSET !== 'UTF-8') {
Smarty::$_UTF8_MODIFIER = '';
@@ -732,31 +779,6 @@ class Smarty extends Smarty_Internal_TemplateBase
return $source->exists;
}
- /**
- * Returns a single or all global variables
- *
- * @param string $varname variable name or null
- *
- * @return string variable value or or array of variables
- */
- public function getGlobal($varname = null)
- {
- if (isset($varname)) {
- if (isset(self::$global_tpl_vars[$varname])) {
- return self::$global_tpl_vars[$varname]->value;
- } else {
- return '';
- }
- } else {
- $_result = array();
- foreach (self::$global_tpl_vars AS $key => $var) {
- $_result[$key] = $var->value;
- }
-
- return $_result;
- }
- }
-
/**
* Loads security class and enables security
*
@@ -793,12 +815,14 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function setTemplateDir($template_dir, $isConfig = false)
{
- $type = $isConfig ? 'config_dir' : 'template_dir';
- $joined = '_joined_' . $type;
- $this->{$type} = (array) $template_dir;
- $this->{$joined} = join(' # ', $this->{$type});
- $this->_cache[$type . '_new'] = true;
- $this->_cache[$type] = false;
+ if ($isConfig) {
+ $this->config_dir = array();
+ $this->_processedConfigDir = array();
+ } else {
+ $this->template_dir = array();
+ $this->_processedTemplateDir = array();
+ }
+ $this->addTemplateDir($template_dir, null, $isConfig);
return $this;
}
@@ -813,16 +837,36 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function addTemplateDir($template_dir, $key = null, $isConfig = false)
{
- $type = $isConfig ? 'config_dir' : 'template_dir';
- $joined = '_joined_' . $type;
- if (!isset($this->_cache[$type])) {
- $this->{$type} = (array) $this->{$type};
- $this->{$joined} = join(' # ', $this->{$type});
- $this->_cache[$type . '_new'] = true;
- $this->_cache[$type] = false;
+ if ($isConfig) {
+ $processed = &$this->_processedConfigDir;
+ $dir = &$this->config_dir;
+ $this->_configDirNormalized = false;
+ } else {
+ $processed = &$this->_processedTemplateDir;
+ $dir = &$this->template_dir;
+ $this->_templateDirNormalized = false;
+ }
+ if (is_array($template_dir)) {
+ foreach ($template_dir as $k => $v) {
+ if (is_int($k)) {
+ // indexes are not merged but appended
+ $dir[] = $v;
+ } else {
+ // string indexes are overridden
+ $dir[ $k ] = $v;
+ unset($processed[ $key ]);
+ }
+ }
+ } else {
+ if ($key !== null) {
+ // override directory at specified index
+ $dir[ $key ] = $template_dir;
+ unset($processed[ $key ]);
+ } else {
+ // append new directory
+ $dir[] = $template_dir;
+ }
}
- $this->{$joined} .= ' # ' . join(' # ', (array) $template_dir);
- $this->_addDir($type, $template_dir, $key);
return $this;
}
@@ -836,24 +880,18 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function getTemplateDir($index = null, $isConfig = false)
{
- $type = $isConfig ? 'config_dir' : 'template_dir';
- if (!isset($this->_cache[$type])) {
- $joined = '_joined_' . $type;
- $this->{$type} = (array) $this->{$type};
- $this->{$joined} = join(' # ', $this->{$type});
- $this->_cache[$type] = false;
+ if ($isConfig) {
+ $dir = &$this->config_dir;
+ } else {
+ $dir = &$this->template_dir;
}
- if ($this->_cache[$type] == false) {
- foreach ($this->{$type} as $k => $v) {
- $this->{$type}[$k] = $this->_realpath($v . DS, true);
- }
- $this->_cache[$type . '_new'] = true;
- $this->_cache[$type] = true;
+ if ($isConfig ? !$this->_configDirNormalized : !$this->_templateDirNormalized) {
+ $this->_nomalizeTemplateConfig($isConfig);
}
if ($index !== null) {
- return isset($this->{$type}[$index]) ? $this->{$type}[$index] : null;
+ return isset($dir[ $index ]) ? $dir[ $index ] : null;
}
- return $this->{$type};
+ return $dir;
}
/**
@@ -903,28 +941,24 @@ class Smarty extends Smarty_Internal_TemplateBase
public function setPluginsDir($plugins_dir)
{
$this->plugins_dir = (array) $plugins_dir;
- if (isset($this->_cache['plugins_dir'])) {
- unset($this->_cache['plugins_dir']);
- }
+ $this->_pluginsDirNormalized = false;
return $this;
}
/**
* Adds directory of plugin files
*
- * @param $plugins_dir
+ * @param null|array $plugins_dir
*
* @return Smarty current Smarty instance for chaining
*/
public function addPluginsDir($plugins_dir)
{
- if (!isset($this->plugins_dir)) {
- $this->plugins_dir = array(SMARTY_PLUGINS_DIR);
- }
- $this->plugins_dir = array_merge((array) $this->plugins_dir, (array) $plugins_dir);
- if (isset($this->_cache['plugins_dir'])) {
- unset($this->_cache['plugins_dir']);
+ if (empty($this->plugins_dir)) {
+ $this->plugins_dir[] = SMARTY_PLUGINS_DIR;
}
+ $this->plugins_dir = array_merge($this->plugins_dir, (array) $plugins_dir);
+ $this->_pluginsDirNormalized = false;
return $this;
}
@@ -935,25 +969,24 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function getPluginsDir()
{
- if (!isset($this->_cache['plugins_dir'])) {
- if (!isset($this->plugins_dir)) {
- $this->plugins_dir = array(SMARTY_PLUGINS_DIR);
- } else {
- $plugins_dir = (array) $this->plugins_dir;
- $this->plugins_dir = array();
- foreach ($plugins_dir as $v) {
- $this->plugins_dir[] = $this->_realpath($v . DS, true);
- }
- $this->plugins_dir = array_unique($this->plugins_dir);
+ if (empty($this->plugins_dir)) {
+ $this->plugins_dir[] = SMARTY_PLUGINS_DIR;
+ $this->_pluginsDirNormalized = false;
+ }
+ if (!$this->_pluginsDirNormalized) {
+ if (!is_array($this->plugins_dir)) {
+ $this->plugins_dir = (array) $this->plugins_dir;
}
- $this->_cache['plugin_files'] = array();
- $this->_cache['plugins_dir'] = true;
+ foreach ($this->plugins_dir as $k => $v) {
+ $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
+ }
+ $this->_cache[ 'plugin_files' ] = array();
+ $this->_pluginsDirNormalized = true;
}
return $this->plugins_dir;
}
/**
- * Set compile directory
*
* @param string $compile_dir directory to store compiled templates in
*
@@ -961,11 +994,8 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function setCompileDir($compile_dir)
{
- $this->compile_dir = $this->_realpath($compile_dir . DS, true);
- if (!isset(Smarty::$_muted_directories[$this->compile_dir])) {
- Smarty::$_muted_directories[$this->compile_dir] = null;
- }
- $this->_cache['compile_dir'] = true;
+ $this->_normalizeDir('compile_dir', $compile_dir);
+ $this->_compileDirNormalized = true;
return $this;
}
@@ -976,12 +1006,9 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function getCompileDir()
{
- if (!isset($this->_cache['compile_dir'])) {
- $this->compile_dir = $this->_realpath($this->compile_dir . DS, true);
- if (!isset(Smarty::$_muted_directories[$this->compile_dir])) {
- Smarty::$_muted_directories[$this->compile_dir] = null;
- }
- $this->_cache['compile_dir'] = true;
+ if (!$this->_compileDirNormalized) {
+ $this->_normalizeDir('compile_dir', $this->compile_dir);
+ $this->_compileDirNormalized = true;
}
return $this->compile_dir;
}
@@ -995,11 +1022,8 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function setCacheDir($cache_dir)
{
- $this->cache_dir = $this->_realpath($cache_dir . DS, true);
- if (!isset(Smarty::$_muted_directories[$this->cache_dir])) {
- Smarty::$_muted_directories[$this->cache_dir] = null;
- }
- $this->_cache['cache_dir'] = true;
+ $this->_normalizeDir('cache_dir', $cache_dir);
+ $this->_cacheDirNormalized = true;
return $this;
}
@@ -1010,47 +1034,54 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function getCacheDir()
{
- if (!isset($this->_cache['cache_dir'])) {
- $this->cache_dir = $this->_realpath($this->cache_dir . DS, true);
- if (!isset(Smarty::$_muted_directories[$this->cache_dir])) {
- Smarty::$_muted_directories[$this->cache_dir] = null;
- }
- $this->_cache['cache_dir'] = true;
+ if (!$this->_cacheDirNormalized) {
+ $this->_normalizeDir('cache_dir', $this->cache_dir);
+ $this->_cacheDirNormalized = true;
}
return $this->cache_dir;
}
/**
- * add directories to given property name
+ * Normalize and set directory string
*
- * @param string $dirName directory property name
- * @param string|array $dir directory string or array of strings
- * @param mixed $key optional key
+ * @param string $dirName cache_dir or compile_dir
+ * @param string $dir filepath of folder
*/
- private function _addDir($dirName, $dir, $key = null)
+ private function _normalizeDir($dirName, $dir)
{
- $rp = $this->_cache[$dirName];
- if (is_array($dir)) {
- foreach ($dir as $k => $v) {
- $path = $rp ? $this->_realpath($v . DS, true) : $v;
- if (is_int($k)) {
- // indexes are not merged but appended
- $this->{$dirName}[] = $path;
- } else {
- // string indexes are overridden
- $this->{$dirName}[$k] = $path;
- }
- }
+ $this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . $this->ds, true);
+ if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) {
+ Smarty::$_muted_directories[ $this->{$dirName} ] = null;
+ }
+ }
+
+ /**
+ * Normalize template_dir or config_dir
+ *
+ * @param bool $isConfig true for config_dir
+ *
+ */
+ private function _nomalizeTemplateConfig($isConfig)
+ {
+ if ($isConfig) {
+ $processed = &$this->_processedConfigDir;
+ $dir = &$this->config_dir;
} else {
- $path = $rp ? $this->_realpath($dir . DS, true) : $dir;
- if ($key !== null) {
- // override directory at specified index
- $this->{$dirName}[$key] = $path;
- } else {
- // append new directory
- $this->{$dirName}[] = $path;
+ $processed = &$this->_processedTemplateDir;
+ $dir = &$this->template_dir;
+ }
+ if (!is_array($dir)) {
+ $dir = (array) $dir;
+ }
+ foreach ($dir as $k => $v) {
+ if (!isset($processed[ $k ])) {
+ $dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
+ $processed[ $k ] = true;
}
}
+ $isConfig ? $this->_configDirNormalized = true : $this->_templateDirNormalized = true;
+ $isConfig ? $this->_joined_config_dir = join('#', $this->config_dir) :
+ $this->_joined_template_dir = join('#', $this->template_dir);
}
/**
@@ -1076,27 +1107,34 @@ class Smarty extends Smarty_Internal_TemplateBase
} else {
$data = null;
}
- if ($this->caching &&
- isset($this->_cache['isCached'][$_templateId = $this->_getTemplateId($template, $cache_id, $compile_id)])
- ) {
- $tpl = $do_clone ? clone $this->_cache['isCached'][$_templateId] : $this->_cache['isCached'][$_templateId];
- $tpl->parent = $parent;
- $tpl->tpl_vars = array();
- $tpl->config_vars = array();
+ if (!$this->_templateDirNormalized) {
+ $this->_nomalizeTemplateConfig(false);
+ }
+ $_templateId = $this->_getTemplateId($template, $cache_id, $compile_id);
+ $tpl = null;
+ if ($this->caching && isset(Smarty_Internal_Template::$isCacheTplObj[ $_templateId ])) {
+ $tpl = $do_clone ? clone Smarty_Internal_Template::$isCacheTplObj[ $_templateId ] :
+ Smarty_Internal_Template::$isCacheTplObj[ $_templateId ];
+ $tpl->inheritance = null;
+ $tpl->tpl_vars = $tpl->config_vars = array();
+ } else if (!$do_clone && isset(Smarty_Internal_Template::$tplObjCache[ $_templateId ])) {
+ $tpl = clone Smarty_Internal_Template::$tplObjCache[ $_templateId ];
+ $tpl->inheritance = null;
+ $tpl->tpl_vars = $tpl->config_vars = array();
} else {
/* @var Smarty_Internal_Template $tpl */
- $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id, null, null);
+ $tpl = new $this->template_class($template, $this, null, $cache_id, $compile_id, null, null);
+ $tpl->templateId = $_templateId;
}
if ($do_clone) {
$tpl->smarty = clone $tpl->smarty;
- } elseif ($parent === null) {
- $tpl->parent = $this;
}
+ $tpl->parent = $parent ? $parent : $this;
// fill data if present
if (!empty($data) && is_array($data)) {
// set up variable values
foreach ($data as $_key => $_val) {
- $tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
+ $tpl->tpl_vars[ $_key ] = new Smarty_Variable($_val);
}
}
if ($this->debugging || $this->debugging_ctrl == 'URL') {
@@ -1128,26 +1166,31 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* Get unique template id
*
- * @param string $template_name
- * @param null|mixed $cache_id
- * @param null|mixed $compile_id
- * @param null $caching
+ * @param string $template_name
+ * @param null|mixed $cache_id
+ * @param null|mixed $compile_id
+ * @param null $caching
+ * @param \Smarty_Internal_Template $template
*
* @return string
*/
- public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null)
+ public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null,
+ Smarty_Internal_Template $template = null)
{
+ $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
+ $template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
$caching = (int) ($caching === null ? $this->caching : $caching);
- if ($this->allow_ambiguous_resources) {
+ if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) {
$_templateId =
- Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}#{$caching}";
+ Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) .
+ "#{$cache_id}#{$compile_id}#{$caching}";
} else {
$_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}";
}
- if (isset($_templateId[150])) {
+ if (isset($_templateId[ 150 ])) {
$_templateId = sha1($_templateId);
}
return $_templateId;
@@ -1158,36 +1201,66 @@ class Smarty extends Smarty_Internal_TemplateBase
* - remove /./ and /../
* - make it absolute if required
*
- * @param string $path file path
- * @param bool $realpath leave $path relative
+ * @param string $path file path
+ * @param bool $realpath if true - convert to absolute
+ * false - convert to relative
+ * null - keep as it is but remove /./ /../
*
* @return string
*/
public function _realpath($path, $realpath = null)
{
- static $pattern = null;
- static $nds = null;
- if ($pattern == null) {
- $nds = DS == '/' ? '\\' : '/';
- $ds = '\\' . DS;
- $pattern =
- "#([{$ds}]+[^{$ds}]+[{$ds}]+[.]([{$ds}]+[.])*[.][{$ds}]+([.][{$ds}]+)*)|([{$ds}]+([.][{$ds}]+)+)|[{$ds}]{2,}#";
+ $nds = $this->ds == '/' ? '\\' : '/';
+ // normalize $this->ds
+ $path = str_replace($nds, $this->ds, $path);
+ preg_match('%^(?(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?(?:[[:print:]]*))$%',
+ $path, $parts);
+ $path = $parts[ 'path' ];
+ if ($parts[ 'root' ] == '\\') {
+ $parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
+ } else {
+ if ($realpath !== null && !$parts[ 'root' ]) {
+ $path = getcwd() . $this->ds . $path;
+ }
}
- // normalize DS
- if (strpos($path, $nds) !== false) {
- $path = str_replace($nds, DS, $path);
+ // remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
+ $path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#', $this->ds, $path);
+ // resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
+ if (strpos($path, '..' . $this->ds) != false &&
+ preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#', $path, $match)
+ ) {
+ $counts = array();
+ foreach ($match[ 0 ] as $m) {
+ $counts[] = (int) ((strlen($m) - 1) / 3);
+ }
+ sort($counts);
+ foreach ($counts as $count) {
+ $path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
+ '}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#',
+ $this->ds, $path);
+ }
}
- if ($realpath === true && (($path[0] !== '/' && DS == '/') || ($path[1] !== ':' && DS != '/'))) {
- $path = getcwd() . DS . $path;
- }
- while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) {
- $path = preg_replace($pattern, DS, $path);
- }
- if ($realpath === false && ($path[0] == '/' || $path[1] == ':')) {
- $path = str_ireplace(getcwd(), '.', $path);
- }
- return $path;
+ return $parts[ 'root' ] . $path;
+ }
+
+ /**
+ * Empty template objects cache
+ */
+ public function _clearTemplateCache()
+ {
+ Smarty_Internal_Template::$isCacheTplObj = array();
+ Smarty_Internal_Template::$tplObjCache = array();
+ }
+
+ /**
+ * Get Smarty object
+ *
+ * @return Smarty
+ */
+ public function _getSmartyObj()
+ {
+ return $this;
}
/**
@@ -1328,14 +1401,6 @@ class Smarty extends Smarty_Internal_TemplateBase
Smarty_Internal_TestInstall::testInstall($this, $errors);
}
- /**
- * Class destructor
- */
- public function __destruct()
- {
- $i = 0;// intentionally left blank
- }
-
/**
* <> Generic getter.
* Calls the appropriate getter function.
@@ -1347,15 +1412,17 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function __get($name)
{
-
- if (isset(self::$accessMap[$name])) {
- $method = 'get' . self::$accessMap[$name];
+ if (isset($this->accessMap[ $name ])) {
+ $method = 'get' . $this->accessMap[ $name ];
return $this->{$method}();
- } elseif (in_array($name, self::$obsoleteProperties)) {
+ } elseif (isset($this->_cache[ $name ])) {
+ return $this->_cache[ $name ];
+ } elseif (in_array($name, $this->obsoleteProperties)) {
return null;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
}
+ return null;
}
/**
@@ -1368,10 +1435,10 @@ class Smarty extends Smarty_Internal_TemplateBase
*/
public function __set($name, $value)
{
- if (isset(self::$accessMap[$name])) {
- $method = 'set' . self::$accessMap[$name];
+ if (isset($this->accessMap[ $name ])) {
+ $method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value);
- } elseif (in_array($name, self::$obsoleteProperties)) {
+ } elseif (in_array($name, $this->obsoleteProperties)) {
return;
} else {
if (is_object($value) && method_exists($value, $name)) {
@@ -1393,17 +1460,17 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param $errline
* @param $errcontext
*
- * @return boolean
+ * @return bool|void
*/
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
$_is_muted_directory = false;
// add the SMARTY_DIR to the list of muted directories
- if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) {
+ if (!isset(Smarty::$_muted_directories[ SMARTY_DIR ])) {
$smarty_dir = realpath(SMARTY_DIR);
if ($smarty_dir !== false) {
- Smarty::$_muted_directories[SMARTY_DIR] =
+ Smarty::$_muted_directories[ SMARTY_DIR ] =
array('file' => $smarty_dir, 'length' => strlen($smarty_dir),);
}
}
@@ -1415,17 +1482,16 @@ class Smarty extends Smarty_Internal_TemplateBase
$file = realpath($key);
if ($file === false) {
// this directory does not exist, remove and skip it
- unset(Smarty::$_muted_directories[$key]);
+ unset(Smarty::$_muted_directories[ $key ]);
continue;
}
$dir = array('file' => $file, 'length' => strlen($file),);
}
- if (!strncmp($errfile, $dir['file'], $dir['length'])) {
+ if (!strncmp($errfile, $dir[ 'file' ], $dir[ 'length' ])) {
$_is_muted_directory = true;
break;
}
}
-
// pass to next error handler if this error did not occur inside SMARTY_DIR
// or the error was within smarty but masked to be ignored
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
@@ -1436,6 +1502,7 @@ class Smarty extends Smarty_Internal_TemplateBase
return false;
}
}
+ return;
}
/**
diff --git a/include/smarty/libs/SmartyBC.class.php b/include/smarty/libs/SmartyBC.class.php
index 1dd529c9c..3955e4f24 100644
--- a/include/smarty/libs/SmartyBC.class.php
+++ b/include/smarty/libs/SmartyBC.class.php
@@ -31,7 +31,7 @@
require_once(dirname(__FILE__) . '/Smarty.class.php');
/**
- * Smarty Backward Compatability Wrapper Class
+ * Smarty Backward Compatibility Wrapper Class
*
* @package Smarty
*/
@@ -54,11 +54,10 @@ class SmartyBC extends Smarty
/**
* Initialize new SmartyBC object
*
- * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
*/
- public function __construct(array $options = array())
+ public function __construct()
{
- parent::__construct($options);
+ parent::__construct();
}
/**
@@ -108,7 +107,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters custom function
+ * Unregister custom function
*
* @param string $function name of template function
*/
@@ -129,7 +128,8 @@ class SmartyBC extends Smarty
* @throws SmartyException
* @internal param array $block_functs list of methods that are block format
*/
- public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
+ public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true,
+ $block_methods = array())
{
settype($allowed, 'array');
settype($smarty_args, 'boolean');
@@ -137,7 +137,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters object
+ * Unregister object
*
* @param string $object name of template object
*/
@@ -160,7 +160,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters block function
+ * Unregister block function
*
* @param string $block name of template function
*/
@@ -182,7 +182,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters compiler function
+ * Unregister compiler function
*
* @param string $function name of template function
*/
@@ -203,7 +203,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters modifier
+ * Unregister modifier
*
* @param string $modifier name of template modifier
*/
@@ -224,7 +224,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters a resource
+ * Unregister a resource
*
* @param string $type name of resource
*/
@@ -245,7 +245,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters a prefilter function
+ * Unregister a prefilter function
*
* @param callable $function
*/
@@ -266,7 +266,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters a postfilter function
+ * Unregister a postfilter function
*
* @param callable $function
*/
@@ -287,7 +287,7 @@ class SmartyBC extends Smarty
}
/**
- * Unregisters an outputfilter function
+ * Unregister an outputfilter function
*
* @param callable $function
*/
diff --git a/include/smarty/libs/bootstrap.php b/include/smarty/libs/bootstrap.php
new file mode 100644
index 000000000..32096087f
--- /dev/null
+++ b/include/smarty/libs/bootstrap.php
@@ -0,0 +1,17 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/*
+ * Load and register Smarty Autoloader
+ */
+if (!class_exists('Smarty_Autoloader')) {
+ require __DIR__ . '/Autoloader.php';
+}
+Smarty_Autoloader::register();
diff --git a/include/smarty/libs/plugins/block.textformat.php b/include/smarty/libs/plugins/block.textformat.php
index abf544939..e2c5e3de4 100644
--- a/include/smarty/libs/plugins/block.textformat.php
+++ b/include/smarty/libs/plugins/block.textformat.php
@@ -38,6 +38,9 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
if (is_null($content)) {
return;
}
+ if (Smarty::$_MBSTRING && !is_callable('smarty_mb_wordwrap')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
+ }
$style = null;
$indent = 0;
@@ -83,14 +86,15 @@ function smarty_block_textformat($params, $content, $template, &$repeat)
continue;
}
// convert mult. spaces & special chars to single space
- $_paragraph = preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER), array(' ', ''), $_paragraph);
+ $_paragraph =
+ preg_replace(array('!\s+!' . Smarty::$_UTF8_MODIFIER, '!(^\s+)|(\s+$)!' . Smarty::$_UTF8_MODIFIER),
+ array(' ', ''), $_paragraph);
// indent first line
if ($indent_first > 0) {
$_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph;
}
// wordwrap sentences
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php');
$_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
} else {
$_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut);
diff --git a/include/smarty/libs/plugins/function.counter.php b/include/smarty/libs/plugins/function.counter.php
index 4da85a14e..bcc8f498c 100644
--- a/include/smarty/libs/plugins/function.counter.php
+++ b/include/smarty/libs/plugins/function.counter.php
@@ -25,53 +25,48 @@ function smarty_function_counter($params, $template)
{
static $counters = array();
- $name = (isset($params['name'])) ? $params['name'] : 'default';
- if (!isset($counters[$name])) {
- $counters[$name] = array(
- 'start' => 1,
- 'skip' => 1,
- 'direction' => 'up',
- 'count' => 1
- );
+ $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default';
+ if (!isset($counters[ $name ])) {
+ $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1);
}
- $counter =& $counters[$name];
+ $counter =& $counters[ $name ];
- if (isset($params['start'])) {
- $counter['start'] = $counter['count'] = (int) $params['start'];
+ if (isset($params[ 'start' ])) {
+ $counter[ 'start' ] = $counter[ 'count' ] = (int) $params[ 'start' ];
}
- if (!empty($params['assign'])) {
- $counter['assign'] = $params['assign'];
+ if (!empty($params[ 'assign' ])) {
+ $counter[ 'assign' ] = $params[ 'assign' ];
}
- if (isset($counter['assign'])) {
- $template->assign($counter['assign'], $counter['count']);
+ if (isset($counter[ 'assign' ])) {
+ $template->assign($counter[ 'assign' ], $counter[ 'count' ]);
}
- if (isset($params['print'])) {
- $print = (bool) $params['print'];
+ if (isset($params[ 'print' ])) {
+ $print = (bool) $params[ 'print' ];
} else {
- $print = empty($counter['assign']);
+ $print = empty($counter[ 'assign' ]);
}
if ($print) {
- $retval = $counter['count'];
+ $retval = $counter[ 'count' ];
} else {
$retval = null;
}
- if (isset($params['skip'])) {
- $counter['skip'] = $params['skip'];
+ if (isset($params[ 'skip' ])) {
+ $counter[ 'skip' ] = $params[ 'skip' ];
}
- if (isset($params['direction'])) {
- $counter['direction'] = $params['direction'];
+ if (isset($params[ 'direction' ])) {
+ $counter[ 'direction' ] = $params[ 'direction' ];
}
- if ($counter['direction'] == "down") {
- $counter['count'] -= $counter['skip'];
+ if ($counter[ 'direction' ] == "down") {
+ $counter[ 'count' ] -= $counter[ 'skip' ];
} else {
- $counter['count'] += $counter['skip'];
+ $counter[ 'count' ] += $counter[ 'skip' ];
}
return $retval;
diff --git a/include/smarty/libs/plugins/function.cycle.php b/include/smarty/libs/plugins/function.cycle.php
index 8dc5cd9d5..a76d49aed 100644
--- a/include/smarty/libs/plugins/function.cycle.php
+++ b/include/smarty/libs/plugins/function.cycle.php
@@ -48,58 +48,56 @@ function smarty_function_cycle($params, $template)
{
static $cycle_vars;
- $name = (empty($params['name'])) ? 'default' : $params['name'];
- $print = (isset($params['print'])) ? (bool) $params['print'] : true;
- $advance = (isset($params['advance'])) ? (bool) $params['advance'] : true;
- $reset = (isset($params['reset'])) ? (bool) $params['reset'] : false;
+ $name = (empty($params[ 'name' ])) ? 'default' : $params[ 'name' ];
+ $print = (isset($params[ 'print' ])) ? (bool) $params[ 'print' ] : true;
+ $advance = (isset($params[ 'advance' ])) ? (bool) $params[ 'advance' ] : true;
+ $reset = (isset($params[ 'reset' ])) ? (bool) $params[ 'reset' ] : false;
- if (!isset($params['values'])) {
- if (!isset($cycle_vars[$name]['values'])) {
+ if (!isset($params[ 'values' ])) {
+ if (!isset($cycle_vars[ $name ][ 'values' ])) {
trigger_error("cycle: missing 'values' parameter");
return;
}
} else {
- if (isset($cycle_vars[$name]['values'])
- && $cycle_vars[$name]['values'] != $params['values']
- ) {
- $cycle_vars[$name]['index'] = 0;
+ if (isset($cycle_vars[ $name ][ 'values' ]) && $cycle_vars[ $name ][ 'values' ] != $params[ 'values' ]) {
+ $cycle_vars[ $name ][ 'index' ] = 0;
}
- $cycle_vars[$name]['values'] = $params['values'];
+ $cycle_vars[ $name ][ 'values' ] = $params[ 'values' ];
}
- if (isset($params['delimiter'])) {
- $cycle_vars[$name]['delimiter'] = $params['delimiter'];
- } elseif (!isset($cycle_vars[$name]['delimiter'])) {
- $cycle_vars[$name]['delimiter'] = ',';
+ if (isset($params[ 'delimiter' ])) {
+ $cycle_vars[ $name ][ 'delimiter' ] = $params[ 'delimiter' ];
+ } elseif (!isset($cycle_vars[ $name ][ 'delimiter' ])) {
+ $cycle_vars[ $name ][ 'delimiter' ] = ',';
}
- if (is_array($cycle_vars[$name]['values'])) {
- $cycle_array = $cycle_vars[$name]['values'];
+ if (is_array($cycle_vars[ $name ][ 'values' ])) {
+ $cycle_array = $cycle_vars[ $name ][ 'values' ];
} else {
- $cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']);
+ $cycle_array = explode($cycle_vars[ $name ][ 'delimiter' ], $cycle_vars[ $name ][ 'values' ]);
}
- if (!isset($cycle_vars[$name]['index']) || $reset) {
- $cycle_vars[$name]['index'] = 0;
+ if (!isset($cycle_vars[ $name ][ 'index' ]) || $reset) {
+ $cycle_vars[ $name ][ 'index' ] = 0;
}
- if (isset($params['assign'])) {
+ if (isset($params[ 'assign' ])) {
$print = false;
- $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
+ $template->assign($params[ 'assign' ], $cycle_array[ $cycle_vars[ $name ][ 'index' ] ]);
}
if ($print) {
- $retval = $cycle_array[$cycle_vars[$name]['index']];
+ $retval = $cycle_array[ $cycle_vars[ $name ][ 'index' ] ];
} else {
$retval = null;
}
if ($advance) {
- if ($cycle_vars[$name]['index'] >= count($cycle_array) - 1) {
- $cycle_vars[$name]['index'] = 0;
+ if ($cycle_vars[ $name ][ 'index' ] >= count($cycle_array) - 1) {
+ $cycle_vars[ $name ][ 'index' ] = 0;
} else {
- $cycle_vars[$name]['index'] ++;
+ $cycle_vars[ $name ][ 'index' ] ++;
}
}
diff --git a/include/smarty/libs/plugins/function.fetch.php b/include/smarty/libs/plugins/function.fetch.php
index 3506d4a8d..cb60dd918 100644
--- a/include/smarty/libs/plugins/function.fetch.php
+++ b/include/smarty/libs/plugins/function.fetch.php
@@ -24,31 +24,31 @@
*/
function smarty_function_fetch($params, $template)
{
- if (empty($params['file'])) {
+ if (empty($params[ 'file' ])) {
trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE);
return;
}
// strip file protocol
- if (stripos($params['file'], 'file://') === 0) {
- $params['file'] = substr($params['file'], 7);
+ if (stripos($params[ 'file' ], 'file://') === 0) {
+ $params[ 'file' ] = substr($params[ 'file' ], 7);
}
- $protocol = strpos($params['file'], '://');
+ $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) {
- $protocol = strtolower(substr($params['file'], 0, $protocol));
+ $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
}
if (isset($template->smarty->security_policy)) {
if ($protocol) {
// remote resource (or php stream, …)
- if (!$template->smarty->security_policy->isTrustedUri($params['file'])) {
+ if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) {
return;
}
} else {
// local file
- if (!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) {
+ if (!$template->smarty->security_policy->isTrustedResourceDir($params[ 'file' ])) {
return;
}
}
@@ -57,26 +57,26 @@ function smarty_function_fetch($params, $template)
$content = '';
if ($protocol == 'http') {
// http fetch
- if ($uri_parts = parse_url($params['file'])) {
+ if ($uri_parts = parse_url($params[ 'file' ])) {
// set defaults
- $host = $server_name = $uri_parts['host'];
+ $host = $server_name = $uri_parts[ 'host' ];
$timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine " . Smarty::SMARTY_VERSION;
$referer = "";
- $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/';
- $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : '';
+ $uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/';
+ $uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : '';
$_is_proxy = false;
- if (empty($uri_parts['port'])) {
+ if (empty($uri_parts[ 'port' ])) {
$port = 80;
} else {
- $port = $uri_parts['port'];
+ $port = $uri_parts[ 'port' ];
}
- if (!empty($uri_parts['user'])) {
- $user = $uri_parts['user'];
+ if (!empty($uri_parts[ 'user' ])) {
+ $user = $uri_parts[ 'user' ];
}
- if (!empty($uri_parts['pass'])) {
- $pass = $uri_parts['pass'];
+ if (!empty($uri_parts[ 'pass' ])) {
+ $pass = $uri_parts[ 'pass' ];
}
// loop through parameters, setup headers
foreach ($params as $param_key => $param_value) {
@@ -163,7 +163,7 @@ function smarty_function_fetch($params, $template)
return;
} else {
if ($_is_proxy) {
- fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n");
+ fputs($fp, 'GET ' . $params[ 'file' ] . " HTTP/1.0\r\n");
} else {
fputs($fp, "GET $uri HTTP/1.0\r\n");
}
@@ -195,10 +195,10 @@ function smarty_function_fetch($params, $template)
fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2);
- $content = $csplit[1];
+ $content = $csplit[ 1 ];
- if (!empty($params['assign_headers'])) {
- $template->assign($params['assign_headers'], preg_split("!\r\n!", $csplit[0]));
+ if (!empty($params[ 'assign_headers' ])) {
+ $template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
}
}
} else {
@@ -207,14 +207,14 @@ function smarty_function_fetch($params, $template)
return;
}
} else {
- $content = @file_get_contents($params['file']);
+ $content = @file_get_contents($params[ 'file' ]);
if ($content === false) {
- throw new SmartyException("{fetch} cannot read resource '" . $params['file'] . "'");
+ throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
}
}
- if (!empty($params['assign'])) {
- $template->assign($params['assign'], $content);
+ if (!empty($params[ 'assign' ])) {
+ $template->assign($params[ 'assign' ], $content);
} else {
return $content;
}
diff --git a/include/smarty/libs/plugins/function.html_checkboxes.php b/include/smarty/libs/plugins/function.html_checkboxes.php
index d78680368..04ce45733 100644
--- a/include/smarty/libs/plugins/function.html_checkboxes.php
+++ b/include/smarty/libs/plugins/function.html_checkboxes.php
@@ -45,7 +45,9 @@
*/
function smarty_function_html_checkboxes($params, $template)
{
- require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
$name = 'checkbox';
$values = null;
@@ -90,19 +92,21 @@ function smarty_function_html_checkboxes($params, $template)
if (method_exists($_sel, "__toString")) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
- trigger_error("html_checkboxes: selected attribute contains an object of class '" . get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_checkboxes: selected attribute contains an object of class '" .
+ get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
}
- $selected[$_sel] = true;
+ $selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
- trigger_error("html_checkboxes: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_checkboxes: selected attribute is an object of class '" . get_class($_val) .
+ "' without __toString() method", E_USER_NOTICE);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
@@ -110,7 +114,8 @@ function smarty_function_html_checkboxes($params, $template)
break;
case 'checkboxes':
- trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING);
+ trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead',
+ E_USER_WARNING);
$options = (array) $_val;
break;
@@ -122,9 +127,10 @@ function smarty_function_html_checkboxes($params, $template)
case 'disabled':
case 'readonly':
- if (!empty($params['strict'])) {
+ if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
- trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
+ trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
+ E_USER_NOTICE);
}
if ($_val === true || $_val === $_key) {
@@ -153,23 +159,28 @@ function smarty_function_html_checkboxes($params, $template)
if (isset($options)) {
foreach ($options as $_key => $_val) {
- $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
+ $_html_result[] =
+ smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
+ $label_ids, $escape);
}
} else {
foreach ($values as $_i => $_key) {
- $_val = isset($output[$_i]) ? $output[$_i] : '';
- $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
+ $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
+ $_html_result[] =
+ smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
+ $label_ids, $escape);
}
}
- if (!empty($params['assign'])) {
- $template->assign($params['assign'], $_html_result);
+ if (!empty($params[ 'assign' ])) {
+ $template->assign($params[ 'assign' ], $_html_result);
} else {
return implode("\n", $_html_result);
}
}
-function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape = true)
+function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels,
+ $label_ids, $escape = true)
{
$_output = '';
@@ -177,7 +188,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if (method_exists($value, "__toString")) {
$value = (string) $value->__toString();
} else {
- trigger_error("html_options: value is an object of class '" . get_class($value) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: value is an object of class '" . get_class($value) .
+ "' without __toString() method", E_USER_NOTICE);
return '';
}
@@ -189,7 +201,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if (method_exists($output, "__toString")) {
$output = (string) $output->__toString();
} else {
- trigger_error("html_options: output is an object of class '" . get_class($output) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: output is an object of class '" . get_class($output) .
+ "' without __toString() method", E_USER_NOTICE);
return '';
}
@@ -199,7 +212,8 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
if ($labels) {
if ($label_ids) {
- $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value));
+ $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
+ $name . '_' . $value));
$_output .= '';
} else {
$_output .= '';
@@ -219,7 +233,7 @@ function smarty_function_html_checkboxes_output($name, $value, $output, $selecte
}
if (is_array($selected)) {
- if (isset($selected[$value])) {
+ if (isset($selected[ $value ])) {
$_output .= ' checked="checked"';
}
} elseif ($value === $selected) {
diff --git a/include/smarty/libs/plugins/function.html_image.php b/include/smarty/libs/plugins/function.html_image.php
index 5037e8bd1..6da8fc544 100644
--- a/include/smarty/libs/plugins/function.html_image.php
+++ b/include/smarty/libs/plugins/function.html_image.php
@@ -38,7 +38,9 @@
*/
function smarty_function_html_image($params, $template)
{
- require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
$alt = '';
$file = '';
@@ -48,7 +50,7 @@ function smarty_function_html_image($params, $template)
$prefix = '';
$suffix = '';
$path_prefix = '';
- $basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '';
+ $basedir = isset($_SERVER[ 'DOCUMENT_ROOT' ]) ? $_SERVER[ 'DOCUMENT_ROOT' ] : '';
foreach ($params as $_key => $_val) {
switch ($_key) {
case 'file':
@@ -90,26 +92,26 @@ function smarty_function_html_image($params, $template)
return;
}
- if ($file[0] == '/') {
+ if ($file[ 0 ] == '/') {
$_image_path = $basedir . $file;
} else {
$_image_path = $file;
}
// strip file protocol
- if (stripos($params['file'], 'file://') === 0) {
- $params['file'] = substr($params['file'], 7);
+ if (stripos($params[ 'file' ], 'file://') === 0) {
+ $params[ 'file' ] = substr($params[ 'file' ], 7);
}
- $protocol = strpos($params['file'], '://');
+ $protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) {
- $protocol = strtolower(substr($params['file'], 0, $protocol));
+ $protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
}
if (isset($template->smarty->security_policy)) {
if ($protocol) {
// remote resource (or php stream, …)
- if (!$template->smarty->security_policy->isTrustedUri($params['file'])) {
+ if (!$template->smarty->security_policy->isTrustedUri($params[ 'file' ])) {
return;
}
} else {
@@ -120,7 +122,7 @@ function smarty_function_html_image($params, $template)
}
}
- if (!isset($params['width']) || !isset($params['height'])) {
+ if (!isset($params[ 'width' ]) || !isset($params[ 'height' ])) {
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
if (!$_image_data = @getimagesize($_image_path)) {
if (!file_exists($_image_path)) {
@@ -138,26 +140,27 @@ function smarty_function_html_image($params, $template)
}
}
- if (!isset($params['width'])) {
- $width = $_image_data[0];
+ if (!isset($params[ 'width' ])) {
+ $width = $_image_data[ 0 ];
}
- if (!isset($params['height'])) {
- $height = $_image_data[1];
+ if (!isset($params[ 'height' ])) {
+ $height = $_image_data[ 1 ];
}
}
- if (isset($params['dpi'])) {
- if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) {
+ if (isset($params[ 'dpi' ])) {
+ if (strstr($_SERVER[ 'HTTP_USER_AGENT' ], 'Mac')) {
// FIXME: (rodneyrehm) wrong dpi assumption
// don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011.
$dpi_default = 72;
} else {
$dpi_default = 96;
}
- $_resize = $dpi_default / $params['dpi'];
+ $_resize = $dpi_default / $params[ 'dpi' ];
$width = round($width * $_resize);
$height = round($height * $_resize);
}
- return $prefix . ' ' . $suffix;
+ return $prefix . ' ' . $suffix;
}
diff --git a/include/smarty/libs/plugins/function.html_options.php b/include/smarty/libs/plugins/function.html_options.php
index 7ec3e065c..bc8f36e0b 100644
--- a/include/smarty/libs/plugins/function.html_options.php
+++ b/include/smarty/libs/plugins/function.html_options.php
@@ -35,7 +35,9 @@
*/
function smarty_function_html_options($params)
{
- require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
$name = null;
$values = null;
@@ -72,19 +74,21 @@ function smarty_function_html_options($params)
if (method_exists($_sel, "__toString")) {
$_sel = smarty_function_escape_special_chars((string) $_sel->__toString());
} else {
- trigger_error("html_options: selected attribute contains an object of class '" . get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: selected attribute contains an object of class '" .
+ get_class($_sel) . "' without __toString() method", E_USER_NOTICE);
continue;
}
} else {
$_sel = smarty_function_escape_special_chars((string) $_sel);
}
- $selected[$_sel] = true;
+ $selected[ $_sel ] = true;
}
} elseif (is_object($_val)) {
if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
- trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: selected attribute is an object of class '" . get_class($_val) .
+ "' without __toString() method", E_USER_NOTICE);
}
} else {
$selected = smarty_function_escape_special_chars((string) $_val);
@@ -96,9 +100,10 @@ function smarty_function_html_options($params)
case 'disabled':
case 'readonly':
- if (!empty($params['strict'])) {
+ if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
- trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
+ trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
+ E_USER_NOTICE);
}
if ($_val === true || $_val === $_key) {
@@ -134,7 +139,7 @@ function smarty_function_html_options($params)
}
} else {
foreach ($values as $_i => $_key) {
- $_val = isset($output[$_i]) ? $output[$_i] : '';
+ $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
$_html_result .= smarty_function_html_options_optoutput($_key, $_val, $selected, $id, $class, $_idx);
}
}
@@ -142,7 +147,9 @@ function smarty_function_html_options($params)
if (!empty($name)) {
$_html_class = !empty($class) ? ' class="' . $class . '"' : '';
$_html_id = !empty($id) ? ' id="' . $id . '"' : '';
- $_html_result = '' . "\n" . $_html_result . ' ' . "\n";
+ $_html_result =
+ '' . "\n" . $_html_result .
+ ' ' . "\n";
}
return $_html_result;
@@ -154,7 +161,7 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$_key = smarty_function_escape_special_chars($key);
$_html_result = '__toString());
} else {
- trigger_error("html_options: value is an object of class '" . get_class($value) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: value is an object of class '" . get_class($value) .
+ "' without __toString() method", E_USER_NOTICE);
return '';
}
@@ -177,7 +185,9 @@ function smarty_function_html_options_optoutput($key, $value, $selected, $id, $c
$idx ++;
} else {
$_idx = 0;
- $_html_result = smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null, $class, $_idx);
+ $_html_result =
+ smarty_function_html_options_optgroup($key, $value, $selected, !empty($id) ? ($id . '-' . $idx) : null,
+ $class, $_idx);
$idx ++;
}
diff --git a/include/smarty/libs/plugins/function.html_radios.php b/include/smarty/libs/plugins/function.html_radios.php
index f121d5eae..6ef84328a 100644
--- a/include/smarty/libs/plugins/function.html_radios.php
+++ b/include/smarty/libs/plugins/function.html_radios.php
@@ -45,7 +45,9 @@
*/
function smarty_function_html_radios($params, $template)
{
- require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
$name = 'radio';
$values = null;
@@ -73,7 +75,8 @@ function smarty_function_html_radios($params, $template)
if (method_exists($_val, "__toString")) {
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
} else {
- trigger_error("html_radios: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_radios: selected attribute is an object of class '" . get_class($_val) .
+ "' without __toString() method", E_USER_NOTICE);
}
} else {
$selected = (string) $_val;
@@ -96,7 +99,8 @@ function smarty_function_html_radios($params, $template)
break;
case 'radios':
- trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
+ trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead',
+ E_USER_WARNING);
$options = (array) $_val;
break;
@@ -108,9 +112,10 @@ function smarty_function_html_radios($params, $template)
case 'disabled':
case 'readonly':
- if (!empty($params['strict'])) {
+ if (!empty($params[ 'strict' ])) {
if (!is_scalar($_val)) {
- trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
+ trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute",
+ E_USER_NOTICE);
}
if ($_val === true || $_val === $_key) {
@@ -141,23 +146,28 @@ function smarty_function_html_radios($params, $template)
if (isset($options)) {
foreach ($options as $_key => $_val) {
- $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
+ $_html_result[] =
+ smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
+ $label_ids, $escape);
}
} else {
foreach ($values as $_i => $_key) {
- $_val = isset($output[$_i]) ? $output[$_i] : '';
- $_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
+ $_val = isset($output[ $_i ]) ? $output[ $_i ] : '';
+ $_html_result[] =
+ smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels,
+ $label_ids, $escape);
}
}
- if (!empty($params['assign'])) {
- $template->assign($params['assign'], $_html_result);
+ if (!empty($params[ 'assign' ])) {
+ $template->assign($params[ 'assign' ], $_html_result);
} else {
return implode("\n", $_html_result);
}
}
-function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape)
+function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids,
+ $escape)
{
$_output = '';
@@ -165,7 +175,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if (method_exists($value, "__toString")) {
$value = (string) $value->__toString();
} else {
- trigger_error("html_options: value is an object of class '" . get_class($value) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: value is an object of class '" . get_class($value) .
+ "' without __toString() method", E_USER_NOTICE);
return '';
}
@@ -177,7 +188,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if (method_exists($output, "__toString")) {
$output = (string) $output->__toString();
} else {
- trigger_error("html_options: output is an object of class '" . get_class($output) . "' without __toString() method", E_USER_NOTICE);
+ trigger_error("html_options: output is an object of class '" . get_class($output) .
+ "' without __toString() method", E_USER_NOTICE);
return '';
}
@@ -187,7 +199,8 @@ function smarty_function_html_radios_output($name, $value, $output, $selected, $
if ($labels) {
if ($label_ids) {
- $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value));
+ $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_',
+ $name . '_' . $value));
$_output .= '';
} else {
$_output .= '';
diff --git a/include/smarty/libs/plugins/function.html_select_date.php b/include/smarty/libs/plugins/function.html_select_date.php
index d66256651..3a48da0bb 100644
--- a/include/smarty/libs/plugins/function.html_select_date.php
+++ b/include/smarty/libs/plugins/function.html_select_date.php
@@ -6,15 +6,6 @@
* @subpackage PluginsFunction
*/
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
-
/**
* Smarty {html_select_date} plugin
* Type: function
@@ -52,6 +43,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
*/
function smarty_function_html_select_date($params)
{
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
+ if (!is_callable('smarty_make_timestamp')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
+ }
// generate timestamps used for month names only
static $_month_timestamps = null;
static $_current_year = null;
@@ -59,7 +56,7 @@ function smarty_function_html_select_date($params)
$_current_year = date('Y');
$_month_timestamps = array();
for ($i = 1; $i <= 12; $i ++) {
- $_month_timestamps[$i] = mktime(0, 0, 0, $i, 1, 2000);
+ $_month_timestamps[ $i ] = mktime(0, 0, 0, $i, 1, 2000);
}
}
@@ -177,22 +174,21 @@ function smarty_function_html_select_date($params)
// Note: date() is faster than strftime()
// Note: explode(date()) is faster than date() date() date()
- if (isset($params['time']) && is_array($params['time'])) {
- if (isset($params['time'][$prefix . 'Year'])) {
+ if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
+ if (isset($params[ 'time' ][ $prefix . 'Year' ])) {
// $_REQUEST[$field_array] given
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
- $$_variableName = isset($params['time'][$prefix . $_elementName])
- ? $params['time'][$prefix . $_elementName]
- : date($_elementKey);
+ $$_variableName =
+ isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
+ date($_elementKey);
}
- } elseif (isset($params['time'][$field_array][$prefix . 'Year'])) {
+ } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Year' ])) {
// $_REQUEST given
foreach (array('Y' => 'Year', 'm' => 'Month', 'd' => 'Day') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
- $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName])
- ? $params['time'][$field_array][$prefix . $_elementName]
- : date($_elementKey);
+ $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
+ $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
}
} else {
// no date found, use NOW
@@ -215,10 +211,10 @@ function smarty_function_html_select_date($params)
$t = $$key;
if ($t === null) {
$$key = (int) $_current_year;
- } elseif ($t[0] == '+') {
- $$key = (int) ($_current_year + (int)trim(substr($t, 1)));
- } elseif ($t[0] == '-') {
- $$key = (int) ($_current_year - (int)trim(substr($t, 1)));
+ } elseif ($t[ 0 ] == '+') {
+ $$key = (int) ($_current_year + (int) trim(substr($t, 1)));
+ } elseif ($t[ 0 ] == '-') {
+ $$key = (int) ($_current_year - (int) trim(substr($t, 1)));
} else {
$$key = (int) $$key;
}
@@ -243,13 +239,16 @@ function smarty_function_html_select_date($params)
}
if ($year_as_text) {
- $_html_years = ' ';
+ $_html_years =
+ ' ';
} else {
$_html_years = '' . $option_separator;
if (isset($year_empty) || isset($all_empty)) {
- $_html_years .= '' . (isset($year_empty) ? $year_empty : $all_empty) . ' ' . $option_separator;
+ $_html_years .= '' . (isset($year_empty) ? $year_empty : $all_empty) . ' ' .
+ $option_separator;
}
$op = $start_year > $end_year ? - 1 : 1;
for ($i = $start_year; $op > 0 ? $i <= $end_year : $i >= $end_year; $i += $op) {
- $_html_years .= '' . $i . ' ' . $option_separator;
+ $_html_years .= '' . $i .
+ ' ' . $option_separator;
}
$_html_years .= ' ';
@@ -284,9 +283,10 @@ function smarty_function_html_select_date($params)
$_html_months = '' . $option_separator;
if (isset($month_empty) || isset($all_empty)) {
- $_html_months .= '' . (isset($month_empty) ? $month_empty : $all_empty) . ' ' . $option_separator;
+ $_html_months .= '' . (isset($month_empty) ? $month_empty : $all_empty) . ' ' .
+ $option_separator;
}
for ($i = 1; $i <= 12; $i ++) {
$_val = sprintf('%02d', $i);
- $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[$i]) : ($month_format == "%m" ? $_val : strftime($month_format, $_month_timestamps[$i]));
- $_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[$i]);
- $_html_months .= '' . $_text . ' ' . $option_separator;
+ $_text = isset($month_names) ? smarty_function_escape_special_chars($month_names[ $i ]) :
+ ($month_format == "%m" ? $_val : strftime($month_format, $_month_timestamps[ $i ]));
+ $_value = $month_value_format == "%m" ? $_val : strftime($month_value_format, $_month_timestamps[ $i ]);
+ $_html_months .= '' . $_text . ' ' . $option_separator;
}
$_html_months .= ' ';
@@ -322,9 +323,9 @@ function smarty_function_html_select_date($params)
$_html_days = '' . $option_separator;
if (isset($day_empty) || isset($all_empty)) {
- $_html_days .= '' . (isset($day_empty) ? $day_empty : $all_empty) . ' ' . $option_separator;
+ $_html_days .= '' . (isset($day_empty) ? $day_empty : $all_empty) . ' ' .
+ $option_separator;
}
for ($i = 1; $i <= 31; $i ++) {
$_val = sprintf('%02d', $i);
$_text = $day_format == '%02d' ? $_val : sprintf($day_format, $i);
$_value = $day_value_format == '%02d' ? $_val : sprintf($day_value_format, $i);
- $_html_days .= '' . $_text . ' ' . $option_separator;
+ $_html_days .= '' .
+ $_text . ' ' . $option_separator;
}
$_html_days .= ' ';
@@ -350,7 +351,7 @@ function smarty_function_html_select_date($params)
// order the fields for output
$_html = '';
for ($i = 0; $i <= 2; $i ++) {
- switch ($field_order[$i]) {
+ switch ($field_order[ $i ]) {
case 'Y':
case 'y':
if (isset($_html_years)) {
diff --git a/include/smarty/libs/plugins/function.html_select_time.php b/include/smarty/libs/plugins/function.html_select_time.php
index 9af6aad5b..89f0406f6 100644
--- a/include/smarty/libs/plugins/function.html_select_time.php
+++ b/include/smarty/libs/plugins/function.html_select_time.php
@@ -6,15 +6,6 @@
* @subpackage PluginsFunction
*/
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
-
/**
* Smarty {html_select_time} function plugin
* Type: function
@@ -33,6 +24,12 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
*/
function smarty_function_html_select_time($params)
{
+ if (!is_callable('smarty_function_escape_special_chars')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
+ }
+ if (!is_callable('smarty_make_timestamp')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
+ }
$prefix = "Time_";
$field_array = null;
$field_separator = "\n";
@@ -148,31 +145,29 @@ function smarty_function_html_select_time($params)
}
}
- if (isset($params['time']) && is_array($params['time'])) {
- if (isset($params['time'][$prefix . 'Hour'])) {
+ if (isset($params[ 'time' ]) && is_array($params[ 'time' ])) {
+ if (isset($params[ 'time' ][ $prefix . 'Hour' ])) {
// $_REQUEST[$field_array] given
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
- $$_variableName = isset($params['time'][$prefix . $_elementName])
- ? $params['time'][$prefix . $_elementName]
- : date($_elementKey);
+ $$_variableName =
+ isset($params[ 'time' ][ $prefix . $_elementName ]) ? $params[ 'time' ][ $prefix . $_elementName ] :
+ date($_elementKey);
}
- $_meridian = isset($params['time'][$prefix . 'Meridian'])
- ? (' ' . $params['time'][$prefix . 'Meridian'])
- : '';
+ $_meridian =
+ isset($params[ 'time' ][ $prefix . 'Meridian' ]) ? (' ' . $params[ 'time' ][ $prefix . 'Meridian' ]) :
+ '';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
- } elseif (isset($params['time'][$field_array][$prefix . 'Hour'])) {
+ } elseif (isset($params[ 'time' ][ $field_array ][ $prefix . 'Hour' ])) {
// $_REQUEST given
foreach (array('H' => 'Hour', 'i' => 'Minute', 's' => 'Second') as $_elementKey => $_elementName) {
$_variableName = '_' . strtolower($_elementName);
- $$_variableName = isset($params['time'][$field_array][$prefix . $_elementName])
- ? $params['time'][$field_array][$prefix . $_elementName]
- : date($_elementKey);
+ $$_variableName = isset($params[ 'time' ][ $field_array ][ $prefix . $_elementName ]) ?
+ $params[ 'time' ][ $field_array ][ $prefix . $_elementName ] : date($_elementKey);
}
- $_meridian = isset($params['time'][$field_array][$prefix . 'Meridian'])
- ? (' ' . $params['time'][$field_array][$prefix . 'Meridian'])
- : '';
+ $_meridian = isset($params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) ?
+ (' ' . $params[ 'time' ][ $field_array ][ $prefix . 'Meridian' ]) : '';
$time = strtotime($_hour . ':' . $_minute . ':' . $_second . $_meridian);
list($_hour, $_minute, $_second) = $time = explode('-', date('H-i-s', $time));
} else {
@@ -203,9 +198,9 @@ function smarty_function_html_select_time($params)
$_html_hours = '' . $option_separator;
if (isset($hour_empty) || isset($all_empty)) {
- $_html_hours .= '' . (isset($hour_empty) ? $hour_empty : $all_empty) . ' ' . $option_separator;
+ $_html_hours .= '' . (isset($hour_empty) ? $hour_empty : $all_empty) . ' ' .
+ $option_separator;
}
$start = $use_24_hours ? 0 : 1;
@@ -224,15 +220,12 @@ function smarty_function_html_select_time($params)
$_value = $hour_value_format == '%02d' ? $_val : sprintf($hour_value_format, $i);
if (!$use_24_hours) {
- $_hour12 = $_hour == 0
- ? 12
- : ($_hour <= 12 ? $_hour : $_hour - 12);
+ $_hour12 = $_hour == 0 ? 12 : ($_hour <= 12 ? $_hour : $_hour - 12);
}
$selected = $_hour !== null ? ($use_24_hours ? $_hour == $_val : $_hour12 == $_val) : null;
- $_html_hours .= '' . $_text . ' ' . $option_separator;
+ $_html_hours .= '' .
+ $_text . ' ' . $option_separator;
}
$_html_hours .= ' ';
@@ -252,9 +245,10 @@ function smarty_function_html_select_time($params)
$_html_minutes = '' . $option_separator;
if (isset($minute_empty) || isset($all_empty)) {
- $_html_minutes .= '' . (isset($minute_empty) ? $minute_empty : $all_empty) . ' ' . $option_separator;
+ $_html_minutes .= '' . (isset($minute_empty) ? $minute_empty : $all_empty) . ' ' .
+ $option_separator;
}
$selected = $_minute !== null ? ($_minute - $_minute % $minute_interval) : null;
@@ -270,9 +265,8 @@ function smarty_function_html_select_time($params)
$_val = sprintf('%02d', $i);
$_text = $minute_format == '%02d' ? $_val : sprintf($minute_format, $i);
$_value = $minute_value_format == '%02d' ? $_val : sprintf($minute_value_format, $i);
- $_html_minutes .= '' . $_text . ' ' . $option_separator;
+ $_html_minutes .= '' . $_text . ' ' . $option_separator;
}
$_html_minutes .= ' ';
@@ -292,9 +286,10 @@ function smarty_function_html_select_time($params)
$_html_seconds = '' . $option_separator;
if (isset($second_empty) || isset($all_empty)) {
- $_html_seconds .= '' . (isset($second_empty) ? $second_empty : $all_empty) . ' ' . $option_separator;
+ $_html_seconds .= '' . (isset($second_empty) ? $second_empty : $all_empty) . ' ' .
+ $option_separator;
}
$selected = $_second !== null ? ($_second - $_second % $second_interval) : null;
@@ -310,9 +306,8 @@ function smarty_function_html_select_time($params)
$_val = sprintf('%02d', $i);
$_text = $second_format == '%02d' ? $_val : sprintf($second_format, $i);
$_value = $second_value_format == '%02d' ? $_val : sprintf($second_value_format, $i);
- $_html_seconds .= '' . $_text . ' ' . $option_separator;
+ $_html_seconds .= '' . $_text . ' ' . $option_separator;
}
$_html_seconds .= ' ';
@@ -332,9 +327,11 @@ function smarty_function_html_select_time($params)
$_html_meridian = '' . $option_separator;
if (isset($meridian_empty) || isset($all_empty)) {
- $_html_meridian .= '' . (isset($meridian_empty) ? $meridian_empty : $all_empty) . ' ' . $option_separator;
+ $_html_meridian .= '' . (isset($meridian_empty) ? $meridian_empty : $all_empty) .
+ ' ' . $option_separator;
}
- $_html_meridian .= ' 0 && $_hour < 12 ? ' selected="selected"' : '') . '>AM ' . $option_separator
- . 'PM ' . $option_separator
- . ' ';
+ $_html_meridian .= ' 0 && $_hour < 12 ? ' selected="selected"' : '') .
+ '>AM ' . $option_separator . 'PM ' . $option_separator .
+ '';
}
$_html = '';
diff --git a/include/smarty/libs/plugins/function.html_table.php b/include/smarty/libs/plugins/function.html_table.php
index ec7ba48a4..42e23e722 100644
--- a/include/smarty/libs/plugins/function.html_table.php
+++ b/include/smarty/libs/plugins/function.html_table.php
@@ -62,7 +62,7 @@ function smarty_function_html_table($params)
$caption = '';
$loop = null;
- if (!isset($params['loop'])) {
+ if (!isset($params[ 'loop' ])) {
trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
return;
@@ -110,11 +110,11 @@ function smarty_function_html_table($params)
}
$loop_count = count($loop);
- if (empty($params['rows'])) {
+ if (empty($params[ 'rows' ])) {
/* no rows specified */
$rows = ceil($loop_count / $cols_count);
- } elseif (empty($params['cols'])) {
- if (!empty($params['rows'])) {
+ } elseif (empty($params[ 'cols' ])) {
+ if (!empty($params[ 'rows' ])) {
/* no cols specified, but rows */
$cols_count = ceil($loop_count / $rows);
}
@@ -132,7 +132,7 @@ function smarty_function_html_table($params)
for ($r = 0; $r < $cols_count; $r ++) {
$output .= '';
- $output .= $cols[$r];
+ $output .= $cols[ $r ];
$output .= " \n";
}
$output .= "\n";
@@ -151,7 +151,7 @@ function smarty_function_html_table($params)
}
if ($x < $loop_count) {
- $output .= "" . $loop[$x] . " \n";
+ $output .= "" . $loop[ $x ] . " \n";
} else {
$output .= "$trailpad \n";
}
@@ -169,7 +169,7 @@ function smarty_function_html_table_cycle($name, $var, $no)
if (!is_array($var)) {
$ret = $var;
} else {
- $ret = $var[$no % count($var)];
+ $ret = $var[ $no % count($var) ];
}
return ($ret) ? ' ' . $ret : '';
diff --git a/include/smarty/libs/plugins/function.mailto.php b/include/smarty/libs/plugins/function.mailto.php
index 520fb7aa6..9d2a5d2d5 100644
--- a/include/smarty/libs/plugins/function.mailto.php
+++ b/include/smarty/libs/plugins/function.mailto.php
@@ -50,15 +50,16 @@
*/
function smarty_function_mailto($params)
{
- static $_allowed_encoding = array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
+ static $_allowed_encoding =
+ array('javascript' => true, 'javascript_charcode' => true, 'hex' => true, 'none' => true);
$extra = '';
- if (empty($params['address'])) {
+ if (empty($params[ 'address' ])) {
trigger_error("mailto: missing 'address' parameter", E_USER_WARNING);
return;
} else {
- $address = $params['address'];
+ $address = $params[ 'address' ];
}
$text = $address;
@@ -72,9 +73,9 @@ function smarty_function_mailto($params)
case 'cc':
case 'bcc':
case 'followupto':
- if (!empty($value)) {
- $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
- }
+ if (!empty($value)) {
+ $mail_parms[] = $var . '=' . str_replace($search, $replace, rawurlencode($value));
+ }
break;
case 'subject':
@@ -94,9 +95,10 @@ function smarty_function_mailto($params)
$address .= '?' . join('&', $mail_parms);
}
- $encode = (empty($params['encode'])) ? 'none' : $params['encode'];
- if (!isset($_allowed_encoding[$encode])) {
- trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex", E_USER_WARNING);
+ $encode = (empty($params[ 'encode' ])) ? 'none' : $params[ 'encode' ];
+ if (!isset($_allowed_encoding[ $encode ])) {
+ trigger_error("mailto: 'encode' parameter must be none, javascript, javascript_charcode or hex",
+ E_USER_WARNING);
return;
}
@@ -106,7 +108,7 @@ function smarty_function_mailto($params)
$js_encode = '';
for ($x = 0, $_length = strlen($string); $x < $_length; $x ++) {
- $js_encode .= '%' . bin2hex($string[$x]);
+ $js_encode .= '%' . bin2hex($string[ $x ]);
}
return '';
@@ -114,35 +116,31 @@ function smarty_function_mailto($params)
$string = '' . $text . ' ';
for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
- $ord[] = ord($string[$x]);
+ $ord[] = ord($string[ $x ]);
}
- $_ret = "\n";
+ $_ret = "\n";
return $_ret;
} elseif ($encode == 'hex') {
preg_match('!^(.*)(\?.*)$!', $address, $match);
- if (!empty($match[2])) {
+ if (!empty($match[ 2 ])) {
trigger_error("mailto: hex encoding does not work with extra attributes. Try javascript.", E_USER_WARNING);
return;
}
$address_encode = '';
for ($x = 0, $_length = strlen($address); $x < $_length; $x ++) {
- if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[$x])) {
- $address_encode .= '%' . bin2hex($address[$x]);
+ if (preg_match('!\w!' . Smarty::$_UTF8_MODIFIER, $address[ $x ])) {
+ $address_encode .= '%' . bin2hex($address[ $x ]);
} else {
- $address_encode .= $address[$x];
+ $address_encode .= $address[ $x ];
}
}
$text_encode = '';
for ($x = 0, $_length = strlen($text); $x < $_length; $x ++) {
- $text_encode .= '' . bin2hex($text[$x]) . ';';
+ $text_encode .= '' . bin2hex($text[ $x ]) . ';';
}
$mailto = "mailto:";
diff --git a/include/smarty/libs/plugins/function.math.php b/include/smarty/libs/plugins/function.math.php
index aba76e825..fc5db335c 100644
--- a/include/smarty/libs/plugins/function.math.php
+++ b/include/smarty/libs/plugins/function.math.php
@@ -24,19 +24,18 @@
*/
function smarty_function_math($params, $template)
{
- static $_allowed_funcs = array(
- 'int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
- 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true,
- 'rand' => true, 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true
- );
+ static $_allowed_funcs =
+ array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
+ 'log' => true, 'log10' => true, 'max' => true, 'min' => true, 'pi' => true, 'pow' => true, 'rand' => true,
+ 'round' => true, 'sin' => true, 'sqrt' => true, 'srand' => true, 'tan' => true);
// be sure equation parameter is present
- if (empty($params['equation'])) {
+ if (empty($params[ 'equation' ])) {
trigger_error("math: missing equation parameter", E_USER_WARNING);
return;
}
- $equation = $params['equation'];
+ $equation = $params[ 'equation' ];
// make sure parenthesis are balanced
if (substr_count($equation, "(") != substr_count($equation, ")")) {
@@ -45,12 +44,42 @@ function smarty_function_math($params, $template)
return;
}
- // match all vars in equation, make sure all are passed
- preg_match_all("!(?:0x[a-fA-F0-9]+)|([a-zA-Z][a-zA-Z0-9_]*)!", $equation, $match);
+ // disallow backticks
+ if (strpos($equation, '`') !== false) {
+ trigger_error("math: backtick character not allowed in equation", E_USER_WARNING);
- foreach ($match[1] as $curr_var) {
- if ($curr_var && !isset($params[$curr_var]) && !isset($_allowed_funcs[$curr_var])) {
- trigger_error("math: function call $curr_var not allowed", E_USER_WARNING);
+ return;
+ }
+
+ // also disallow dollar signs
+ if (strpos($equation, '$') !== false) {
+ trigger_error("math: dollar signs not allowed in equation", E_USER_WARNING);
+
+ return;
+ }
+
+ foreach ($params as $key => $val) {
+ if ($key != "equation" && $key != "format" && $key != "assign") {
+ // make sure value is not empty
+ if (strlen($val) == 0) {
+ trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
+
+ return;
+ }
+ if (!is_numeric($val)) {
+ trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
+
+ return;
+ }
+ }
+ }
+
+ // match all vars in equation, make sure all are passed
+ preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
+
+ foreach ($match[ 1 ] as $curr_var) {
+ if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
+ trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
return;
}
@@ -58,34 +87,23 @@ function smarty_function_math($params, $template)
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
- // make sure value is not empty
- if (strlen($val) == 0) {
- trigger_error("math: parameter $key is empty", E_USER_WARNING);
-
- return;
- }
- if (!is_numeric($val)) {
- trigger_error("math: parameter $key: is not numeric", E_USER_WARNING);
-
- return;
- }
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
}
}
$smarty_math_result = null;
eval("\$smarty_math_result = " . $equation . ";");
- if (empty($params['format'])) {
- if (empty($params['assign'])) {
+ if (empty($params[ 'format' ])) {
+ if (empty($params[ 'assign' ])) {
return $smarty_math_result;
} else {
- $template->assign($params['assign'], $smarty_math_result);
+ $template->assign($params[ 'assign' ], $smarty_math_result);
}
} else {
- if (empty($params['assign'])) {
- printf($params['format'], $smarty_math_result);
+ if (empty($params[ 'assign' ])) {
+ printf($params[ 'format' ], $smarty_math_result);
} else {
- $template->assign($params['assign'], sprintf($params['format'], $smarty_math_result));
+ $template->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result));
}
}
}
diff --git a/include/smarty/libs/plugins/modifier.capitalize.php b/include/smarty/libs/plugins/modifier.capitalize.php
index a8ad76370..6513a0495 100644
--- a/include/smarty/libs/plugins/modifier.capitalize.php
+++ b/include/smarty/libs/plugins/modifier.capitalize.php
@@ -29,17 +29,23 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
} else {
// uppercase word breaks
- $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert_cb', $string);
+ $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER,
+ 'smarty_mod_cap_mbconvert_cb', $string);
}
// check uc_digits case
if (!$uc_digits) {
- if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
- foreach ($matches[1] as $match) {
- $upper_string = substr_replace($upper_string, mb_strtolower($match[0], Smarty::$_CHARSET), $match[1], strlen($match[0]));
+ if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
+ PREG_OFFSET_CAPTURE)) {
+ foreach ($matches[ 1 ] as $match) {
+ $upper_string =
+ substr_replace($upper_string, mb_strtolower($match[ 0 ], Smarty::$_CHARSET), $match[ 1 ],
+ strlen($match[ 0 ]));
}
}
}
- $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb', $upper_string);
+ $upper_string =
+ preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb',
+ $upper_string);
return $upper_string;
}
@@ -48,16 +54,21 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
$string = strtolower($string);
}
// uppercase (including hyphenated words)
- $upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb', $string);
+ $upper_string =
+ preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb',
+ $string);
// check uc_digits case
if (!$uc_digits) {
- if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
- foreach ($matches[1] as $match) {
- $upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0]));
+ if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches,
+ PREG_OFFSET_CAPTURE)) {
+ foreach ($matches[ 1 ] as $match) {
+ $upper_string =
+ substr_replace($upper_string, strtolower($match[ 0 ]), $match[ 1 ], strlen($match[ 0 ]));
}
}
}
- $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb', $upper_string);
+ $upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb',
+ $upper_string);
return $upper_string;
}
@@ -71,20 +82,20 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
*/
function smarty_mod_cap_mbconvert_cb($matches)
{
- return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[2]), MB_CASE_UPPER, Smarty::$_CHARSET);
+ return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 2 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
function smarty_mod_cap_mbconvert2_cb($matches)
{
- return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[3]), MB_CASE_UPPER, Smarty::$_CHARSET);
+ return stripslashes($matches[ 1 ]) . mb_convert_case(stripslashes($matches[ 3 ]), MB_CASE_UPPER, Smarty::$_CHARSET);
}
function smarty_mod_cap_ucfirst_cb($matches)
{
- return stripslashes($matches[1]) . ucfirst(stripslashes($matches[2]));
+ return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
}
function smarty_mod_cap_ucfirst2_cb($matches)
{
- return stripslashes($matches[1]) . ucfirst(stripslashes($matches[3]));
+ return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 3 ]));
}
diff --git a/include/smarty/libs/plugins/modifier.date_format.php b/include/smarty/libs/plugins/modifier.date_format.php
index 28d6ff021..bfe363c08 100644
--- a/include/smarty/libs/plugins/modifier.date_format.php
+++ b/include/smarty/libs/plugins/modifier.date_format.php
@@ -35,7 +35,9 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
/**
* require_once the {@link shared.make_timestamp.php} plugin
*/
- require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
+ if (!is_callable('smarty_make_timestamp')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
+ }
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string);
} elseif ($default_date != '') {
@@ -44,7 +46,7 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
return;
}
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
- if (DS == '\\') {
+ if (Smarty::$_IS_WINDOWS) {
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
if (strpos($format, '%e') !== false) {
diff --git a/include/smarty/libs/plugins/modifier.debug_print_var.php b/include/smarty/libs/plugins/modifier.debug_print_var.php
index 4ff8213ce..34f85dcd5 100644
--- a/include/smarty/libs/plugins/modifier.debug_print_var.php
+++ b/include/smarty/libs/plugins/modifier.debug_print_var.php
@@ -24,10 +24,7 @@
*/
function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array())
{
- $_replace = array("\n" => '\n',
- "\r" => '\r',
- "\t" => '\t'
- );
+ $_replace = array("\n" => '\n', "\r" => '\r', "\t" => '\t');
switch (gettype($var)) {
case 'array' :
$results = 'Array (' . count($var) . ') ';
@@ -35,9 +32,9 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
break;
}
foreach ($var as $curr_key => $curr_val) {
- $results .= ' ' . str_repeat(' ', $depth * 2)
- . '' . strtr($curr_key, $_replace) . ' => '
- . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
+ $results .= ' ' . str_repeat(' ', $depth * 2) . '' . strtr($curr_key, $_replace) .
+ ' => ' .
+ smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --;
}
break;
@@ -54,9 +51,8 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
}
$objects[] = $var;
foreach ($object_vars as $curr_key => $curr_val) {
- $results .= ' ' . str_repeat(' ', $depth * 2)
- . ' ->' . strtr($curr_key, $_replace) . ' = '
- . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
+ $results .= ' ' . str_repeat(' ', $depth * 2) . ' ->' . strtr($curr_key, $_replace) .
+ ' = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++ $depth, $objects);
$depth --;
}
break;
@@ -88,12 +84,12 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
}
} else {
- if (isset($var[$length])) {
+ if (isset($var[ $length ])) {
$results = substr($var, 0, $length - 3) . '...';
}
}
- $results = htmlspecialchars('"' . $results . '"');
+ $results = htmlspecialchars('"' . $results . '"', ENT_QUOTES, Smarty::$_CHARSET);
break;
case 'unknown type' :
@@ -109,7 +105,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
}
}
- $results = htmlspecialchars($results);
+ $results = htmlspecialchars($results, ENT_QUOTES, Smarty::$_CHARSET);
}
return $results;
diff --git a/include/smarty/libs/plugins/modifier.escape.php b/include/smarty/libs/plugins/modifier.escape.php
index 9fdb0702f..9c247b933 100644
--- a/include/smarty/libs/plugins/modifier.escape.php
+++ b/include/smarty/libs/plugins/modifier.escape.php
@@ -66,7 +66,8 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// php <5.2.3 - prevent double encoding
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
- $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
+ $string =
+ str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
return $string;
}
@@ -107,7 +108,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return = '';
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
- $return .= '%' . bin2hex($string[$x]);
+ $return .= '%' . bin2hex($string[ $x ]);
}
return $return;
@@ -115,7 +116,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'hexentity':
$return = '';
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ if (!is_callable('smarty_mb_to_unicode')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ }
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '' . strtoupper(dechex($unicode)) . ';';
@@ -126,7 +129,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
- $return .= '' . bin2hex($string[$x]) . ';';
+ $return .= '' . bin2hex($string[ $x ]) . ';';
}
return $return;
@@ -134,7 +137,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'decentity':
$return = '';
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ if (!is_callable('smarty_mb_to_unicode')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ }
$return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
$return .= '' . $unicode . ';';
@@ -145,19 +150,21 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// no MBString fallback
$_length = strlen($string);
for ($x = 0; $x < $_length; $x ++) {
- $return .= '' . ord($string[$x]) . ';';
+ $return .= '' . ord($string[ $x ]) . ';';
}
return $return;
case 'javascript':
// escape quotes and backslashes, newlines, etc.
- return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '' => '<\/'));
+ return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n',
+ '' => '<\/'));
case 'mail':
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
-
+ if (!is_callable('smarty_mb_str_replace')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
+ }
return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
}
// no MBString fallback
@@ -167,7 +174,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ if (!is_callable('smarty_mb_to_unicode')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ }
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '' . $unicode . ';';
diff --git a/include/smarty/libs/plugins/modifier.regex_replace.php b/include/smarty/libs/plugins/modifier.regex_replace.php
index ffea16755..85f41fdda 100644
--- a/include/smarty/libs/plugins/modifier.regex_replace.php
+++ b/include/smarty/libs/plugins/modifier.regex_replace.php
@@ -23,11 +23,11 @@
*
* @return string
*/
-function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1)
+function smarty_modifier_regex_replace($string, $search, $replace, $limit = - 1)
{
if (is_array($search)) {
foreach ($search as $idx => $s) {
- $search[$idx] = _smarty_regex_replace_check($s);
+ $search[ $idx ] = _smarty_regex_replace_check($s);
}
} else {
$search = _smarty_regex_replace_check($search);
@@ -50,8 +50,8 @@ function _smarty_regex_replace_check($search)
$search = substr($search, 0, $pos);
}
// remove eval-modifier from $search
- if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
- $search = substr($search, 0, - strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
+ if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[ 1 ], 'e') !== false)) {
+ $search = substr($search, 0, - strlen($match[ 1 ])) . preg_replace('![e\s]+!', '', $match[ 1 ]);
}
return $search;
diff --git a/include/smarty/libs/plugins/modifier.replace.php b/include/smarty/libs/plugins/modifier.replace.php
index aa5e8570b..9dca259d5 100644
--- a/include/smarty/libs/plugins/modifier.replace.php
+++ b/include/smarty/libs/plugins/modifier.replace.php
@@ -25,8 +25,9 @@
function smarty_modifier_replace($string, $search, $replace)
{
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
-
+ if (!is_callable('smarty_mb_str_replace')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
+ }
return smarty_mb_str_replace($search, $replace, $string);
}
diff --git a/include/smarty/libs/plugins/modifier.truncate.php b/include/smarty/libs/plugins/modifier.truncate.php
index fbe62e823..6fe844259 100644
--- a/include/smarty/libs/plugins/modifier.truncate.php
+++ b/include/smarty/libs/plugins/modifier.truncate.php
@@ -35,20 +35,22 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
if (!$break_words && !$middle) {
- $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
+ $string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '',
+ mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
}
if (!$middle) {
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
}
- return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
+ return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc .
+ mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
}
return $string;
}
// no MBString fallback
- if (isset($string[$length])) {
+ if (isset($string[ $length ])) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
diff --git a/include/smarty/libs/plugins/modifiercompiler.count_characters.php b/include/smarty/libs/plugins/modifiercompiler.count_characters.php
index f8463d80a..0a3ce257b 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_characters.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_characters.php
@@ -21,12 +21,12 @@
*/
function smarty_modifiercompiler_count_characters($params)
{
- if (!isset($params[1]) || $params[1] != 'true') {
- return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[0] . ', $tmp)';
+ if (!isset($params[ 1 ]) || $params[ 1 ] != 'true') {
+ return 'preg_match_all(\'/[^\s]/' . Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
}
if (Smarty::$_MBSTRING) {
- return 'mb_strlen(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
+ return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
- return 'strlen(' . $params[0] . ')';
+ return 'strlen(' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php b/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php
index 34f0bbb8a..f7f447763 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php
@@ -23,5 +23,5 @@
function smarty_modifiercompiler_count_paragraphs($params)
{
// count \r or \n characters
- return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)';
+ return '(preg_match_all(\'#[\r\n]+#\', ' . $params[ 0 ] . ', $tmp)+1)';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.count_sentences.php b/include/smarty/libs/plugins/modifiercompiler.count_sentences.php
index f1ec56007..20032925e 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_sentences.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_sentences.php
@@ -23,5 +23,5 @@
function smarty_modifiercompiler_count_sentences($params)
{
// find periods, question marks, exclamation marks with a word before but not after.
- return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[0] . ', $tmp)';
+ return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . Smarty::$_UTF8_MODIFIER . '", ' . $params[ 0 ] . ', $tmp)';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.count_words.php b/include/smarty/libs/plugins/modifiercompiler.count_words.php
index 8b4330f1e..f20a197cd 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_words.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_words.php
@@ -24,8 +24,9 @@ function smarty_modifiercompiler_count_words($params)
if (Smarty::$_MBSTRING) {
// return 'preg_match_all(\'#[\w\pL]+#' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
- return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' . $params[0] . ', $tmp)';
+ return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . Smarty::$_UTF8_MODIFIER . '\', ' .
+ $params[ 0 ] . ', $tmp)';
}
// no MBString fallback
- return 'str_word_count(' . $params[0] . ')';
+ return 'str_word_count(' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.default.php b/include/smarty/libs/plugins/modifiercompiler.default.php
index fe777623e..2c4c00a37 100644
--- a/include/smarty/libs/plugins/modifiercompiler.default.php
+++ b/include/smarty/libs/plugins/modifiercompiler.default.php
@@ -21,9 +21,9 @@
*/
function smarty_modifiercompiler_default($params)
{
- $output = $params[0];
- if (!isset($params[1])) {
- $params[1] = "''";
+ $output = $params[ 0 ];
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = "''";
}
array_shift($params);
diff --git a/include/smarty/libs/plugins/modifiercompiler.escape.php b/include/smarty/libs/plugins/modifiercompiler.escape.php
index 0b29220ef..11565c2d9 100644
--- a/include/smarty/libs/plugins/modifiercompiler.escape.php
+++ b/include/smarty/libs/plugins/modifiercompiler.escape.php
@@ -6,11 +6,6 @@
* @subpackage PluginsModifierCompiler
*/
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
-
/**
* Smarty escape modifier plugin
* Type: modifier
@@ -28,6 +23,9 @@ require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
function smarty_modifiercompiler_escape($params, $compiler)
{
static $_double_encode = null;
+ if (!is_callable('smarty_literal_compiler_param')) {
+ require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
+ }
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
@@ -44,14 +42,10 @@ function smarty_modifiercompiler_escape($params, $compiler)
switch ($esc_type) {
case 'html':
if ($_double_encode) {
- return 'htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true) . ')';
+ return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
+ var_export($double_encode, true) . ')';
} elseif ($double_encode) {
- return 'htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ')';
+ return 'htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
@@ -60,19 +54,13 @@ function smarty_modifiercompiler_escape($params, $compiler)
if (Smarty::$_MBSTRING) {
if ($_double_encode) {
// php >=5.2.3 - go native
- return 'mb_convert_encoding(htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true)
- . '), "HTML-ENTITIES", '
- . var_export($char_set, true) . ')';
+ return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
+ var_export($char_set, true) . ', ' . var_export($double_encode, true) .
+ '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} elseif ($double_encode) {
// php <5.2.3 - only handle double encoding
- return 'mb_convert_encoding(htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true)
- . '), "HTML-ENTITIES", '
- . var_export($char_set, true) . ')';
+ return 'mb_convert_encoding(htmlspecialchars(' . $params[ 0 ] . ', ENT_QUOTES, ' .
+ var_export($char_set, true) . '), "HTML-ENTITIES", ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
@@ -81,32 +69,29 @@ function smarty_modifiercompiler_escape($params, $compiler)
// no MBString fallback
if ($_double_encode) {
// php >=5.2.3 - go native
- return 'htmlentities('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true) . ')';
+ return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
+ var_export($double_encode, true) . ')';
} elseif ($double_encode) {
// php <5.2.3 - only handle double encoding
- return 'htmlentities('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ')';
+ return 'htmlentities(' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ')';
} else {
// fall back to modifier.escape.php
}
case 'url':
- return 'rawurlencode(' . $params[0] . ')';
+ return 'rawurlencode(' . $params[ 0 ] . ')';
case 'urlpathinfo':
- return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))';
+ return 'str_replace("%2F", "/", rawurlencode(' . $params[ 0 ] . '))';
case 'quotes':
// escape unescaped single quotes
- return 'preg_replace("%(? "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "" => "<\/" ))';
+ return 'strtr(' . $params[ 0 ] .
+ ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "" => "<\/" ))';
}
}
catch (SmartyException $e) {
@@ -115,11 +100,15 @@ function smarty_modifiercompiler_escape($params, $compiler)
// could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
- $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
- $compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
+ SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] =
+ 'smarty_modifier_escape';
} else {
- $compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
- $compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
+ SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
+ 'smarty_modifier_escape';
}
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
diff --git a/include/smarty/libs/plugins/modifiercompiler.from_charset.php b/include/smarty/libs/plugins/modifiercompiler.from_charset.php
index dab43e9c3..e25a95749 100644
--- a/include/smarty/libs/plugins/modifiercompiler.from_charset.php
+++ b/include/smarty/libs/plugins/modifiercompiler.from_charset.php
@@ -22,12 +22,12 @@ function smarty_modifiercompiler_from_charset($params)
{
if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error?
- return $params[0];
+ return $params[ 0 ];
}
- if (!isset($params[1])) {
- $params[1] = '"ISO-8859-1"';
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = '"ISO-8859-1"';
}
- return 'mb_convert_encoding(' . $params[0] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[1] . ')';
+ return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.indent.php b/include/smarty/libs/plugins/modifiercompiler.indent.php
index e3ca20821..851f18448 100644
--- a/include/smarty/libs/plugins/modifiercompiler.indent.php
+++ b/include/smarty/libs/plugins/modifiercompiler.indent.php
@@ -22,12 +22,12 @@
function smarty_modifiercompiler_indent($params)
{
- if (!isset($params[1])) {
- $params[1] = 4;
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = 4;
}
- if (!isset($params[2])) {
- $params[2] = "' '";
+ if (!isset($params[ 2 ])) {
+ $params[ 2 ] = "' '";
}
- return 'preg_replace(\'!^!m\',str_repeat(' . $params[2] . ',' . $params[1] . '),' . $params[0] . ')';
+ return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.lower.php b/include/smarty/libs/plugins/modifiercompiler.lower.php
index 1d255f371..a335eff7f 100644
--- a/include/smarty/libs/plugins/modifiercompiler.lower.php
+++ b/include/smarty/libs/plugins/modifiercompiler.lower.php
@@ -24,8 +24,8 @@
function smarty_modifiercompiler_lower($params)
{
if (Smarty::$_MBSTRING) {
- return 'mb_strtolower(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
+ return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
- return 'strtolower(' . $params[0] . ')';
+ return 'strtolower(' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.string_format.php b/include/smarty/libs/plugins/modifiercompiler.string_format.php
index 71cdf2819..bcf9883db 100644
--- a/include/smarty/libs/plugins/modifiercompiler.string_format.php
+++ b/include/smarty/libs/plugins/modifiercompiler.string_format.php
@@ -21,5 +21,5 @@
*/
function smarty_modifiercompiler_string_format($params)
{
- return 'sprintf(' . $params[1] . ',' . $params[0] . ')';
+ return 'sprintf(' . $params[ 1 ] . ',' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.strip.php b/include/smarty/libs/plugins/modifiercompiler.strip.php
index fcd6cbaea..8173eed8f 100644
--- a/include/smarty/libs/plugins/modifiercompiler.strip.php
+++ b/include/smarty/libs/plugins/modifiercompiler.strip.php
@@ -25,8 +25,8 @@
function smarty_modifiercompiler_strip($params)
{
- if (!isset($params[1])) {
- $params[1] = "' '";
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = "' '";
}
return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
diff --git a/include/smarty/libs/plugins/modifiercompiler.strip_tags.php b/include/smarty/libs/plugins/modifiercompiler.strip_tags.php
index da5d364cb..e56bf9315 100644
--- a/include/smarty/libs/plugins/modifiercompiler.strip_tags.php
+++ b/include/smarty/libs/plugins/modifiercompiler.strip_tags.php
@@ -21,9 +21,9 @@
*/
function smarty_modifiercompiler_strip_tags($params)
{
- if (!isset($params[1]) || $params[1] === true || trim($params[1], '"') == 'true') {
+ if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') == 'true') {
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]})";
} else {
- return 'strip_tags(' . $params[0] . ')';
+ return 'strip_tags(' . $params[ 0 ] . ')';
}
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.to_charset.php b/include/smarty/libs/plugins/modifiercompiler.to_charset.php
index 9122d8bbb..fea8d8273 100644
--- a/include/smarty/libs/plugins/modifiercompiler.to_charset.php
+++ b/include/smarty/libs/plugins/modifiercompiler.to_charset.php
@@ -22,12 +22,12 @@ function smarty_modifiercompiler_to_charset($params)
{
if (!Smarty::$_MBSTRING) {
// FIXME: (rodneyrehm) shouldn't this throw an error?
- return $params[0];
+ return $params[ 0 ];
}
- if (!isset($params[1])) {
- $params[1] = '"ISO-8859-1"';
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = '"ISO-8859-1"';
}
- return 'mb_convert_encoding(' . $params[0] . ', ' . $params[1] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
+ return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(Smarty::$_CHARSET) . '")';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.unescape.php b/include/smarty/libs/plugins/modifiercompiler.unescape.php
index 3b17ea2e1..a3409bc73 100644
--- a/include/smarty/libs/plugins/modifiercompiler.unescape.php
+++ b/include/smarty/libs/plugins/modifiercompiler.unescape.php
@@ -20,31 +20,31 @@
*/
function smarty_modifiercompiler_unescape($params)
{
- if (!isset($params[1])) {
- $params[1] = 'html';
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = 'html';
}
- if (!isset($params[2])) {
- $params[2] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
+ if (!isset($params[ 2 ])) {
+ $params[ 2 ] = '\'' . addslashes(Smarty::$_CHARSET) . '\'';
} else {
- $params[2] = "'" . $params[2] . "'";
+ $params[ 2 ] = "'" . $params[ 2 ] . "'";
}
- switch (trim($params[1], '"\'')) {
+ switch (trim($params[ 1 ], '"\'')) {
case 'entity':
case 'htmlall':
if (Smarty::$_MBSTRING) {
- return 'mb_convert_encoding(' . $params[0] . ', ' . $params[2] . ', \'HTML-ENTITIES\')';
+ return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'HTML-ENTITIES\')';
}
- return 'html_entity_decode(' . $params[0] . ', ENT_NOQUOTES, ' . $params[2] . ')';
+ return 'html_entity_decode(' . $params[ 0 ] . ', ENT_NOQUOTES, ' . $params[ 2 ] . ')';
case 'html':
- return 'htmlspecialchars_decode(' . $params[0] . ', ENT_QUOTES)';
+ return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url':
- return 'rawurldecode(' . $params[0] . ')';
+ return 'rawurldecode(' . $params[ 0 ] . ')';
default:
- return $params[0];
+ return $params[ 0 ];
}
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.upper.php b/include/smarty/libs/plugins/modifiercompiler.upper.php
index 52ca4e8ff..a083c4f7e 100644
--- a/include/smarty/libs/plugins/modifiercompiler.upper.php
+++ b/include/smarty/libs/plugins/modifiercompiler.upper.php
@@ -22,8 +22,8 @@
function smarty_modifiercompiler_upper($params)
{
if (Smarty::$_MBSTRING) {
- return 'mb_strtoupper(' . $params[0] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
+ return 'mb_strtoupper(' . $params[ 0 ] . ', \'' . addslashes(Smarty::$_CHARSET) . '\')';
}
// no MBString fallback
- return 'strtoupper(' . $params[0] . ')';
+ return 'strtoupper(' . $params[ 0 ] . ')';
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.wordwrap.php b/include/smarty/libs/plugins/modifiercompiler.wordwrap.php
index 6bb63247d..91849738e 100644
--- a/include/smarty/libs/plugins/modifiercompiler.wordwrap.php
+++ b/include/smarty/libs/plugins/modifiercompiler.wordwrap.php
@@ -22,26 +22,30 @@
*/
function smarty_modifiercompiler_wordwrap($params, $compiler)
{
- if (!isset($params[1])) {
- $params[1] = 80;
+ if (!isset($params[ 1 ])) {
+ $params[ 1 ] = 80;
}
- if (!isset($params[2])) {
- $params[2] = '"\n"';
+ if (!isset($params[ 2 ])) {
+ $params[ 2 ] = '"\n"';
}
- if (!isset($params[3])) {
- $params[3] = 'false';
+ if (!isset($params[ 3 ])) {
+ $params[ 3 ] = 'false';
}
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
- $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->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';
} else {
- $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
- $compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'file' ] =
+ SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'wordwrap' ][ 'modifier' ][ 'function' ] =
+ 'smarty_mb_wordwrap';
}
$function = 'smarty_mb_wordwrap';
}
- return $function . '(' . $params[0] . ',' . $params[1] . ',' . $params[2] . ',' . $params[3] . ')';
+ return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}
diff --git a/include/smarty/libs/plugins/outputfilter.trimwhitespace.php b/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
index ad35d11a2..1a67123a4 100644
--- a/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
+++ b/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
@@ -26,13 +26,14 @@ function smarty_outputfilter_trimwhitespace($source)
// Unify Line-Breaks to \n
$source = preg_replace("/\015\012|\015|\012/", "\n", $source);
- // capture Internet Explorer Conditional Comments
- if (preg_match_all('##is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
+ // capture Internet Explorer and KnockoutJS Conditional Comments
+ if (preg_match_all('##is', $source, $matches,
+ PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
- $store[] = $match[0][0];
- $_length = strlen($match[0][0]);
+ $store[] = $match[ 0 ][ 0 ];
+ $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
- $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length);
+ $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
$_store ++;
@@ -45,29 +46,27 @@ function smarty_outputfilter_trimwhitespace($source)
// capture html elements not to be messed with
$_offset = 0;
- if (preg_match_all('#(]*>)|(]*>)|(]*>.*? ]*>)#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
+ if (preg_match_all('#(]*>)|(]*>)|(]*>.*? ]*>)#is',
+ $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
- $store[] = $match[0][0];
- $_length = strlen($match[0][0]);
+ $store[] = $match[ 0 ][ 0 ];
+ $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
- $source = substr_replace($source, $replace, $match[0][1] - $_offset, $_length);
+ $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
$_store ++;
}
}
- $expressions = array(
- // replace multiple spaces between tags by a single space
- // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
- '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
- // remove spaces between attributes (but not in attribute values!)
- '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
- // note: for some very weird reason trim() seems to remove spaces inside attributes.
- // maybe a \0 byte or something is interfering?
- '#^\s+<#Ss' => '<',
- '#>\s+$#Ss' => '>',
- );
+ $expressions = array(// replace multiple spaces between tags by a single space
+ // can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
+ '#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
+ // remove spaces between attributes (but not in attribute values!)
+ '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
+ // note: for some very weird reason trim() seems to remove spaces inside attributes.
+ // maybe a \0 byte or something is interfering?
+ '#^\s+<#Ss' => '<', '#>\s+$#Ss' => '>',);
$source = preg_replace(array_keys($expressions), array_values($expressions), $source);
// note: for some very weird reason trim() seems to remove spaces inside attributes.
@@ -77,9 +76,9 @@ function smarty_outputfilter_trimwhitespace($source)
$_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $source, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
- $_length = strlen($match[0][0]);
- $replace = $store[$match[1][0]];
- $source = substr_replace($source, $replace, $match[0][1] + $_offset, $_length);
+ $_length = strlen($match[ 0 ][ 0 ]);
+ $replace = $store[ $match[ 1 ][ 0 ] ];
+ $source = substr_replace($source, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length;
$_store ++;
diff --git a/include/smarty/libs/plugins/shared.escape_special_chars.php b/include/smarty/libs/plugins/shared.escape_special_chars.php
index d3bd756b1..b68fe4b9d 100644
--- a/include/smarty/libs/plugins/shared.escape_special_chars.php
+++ b/include/smarty/libs/plugins/shared.escape_special_chars.php
@@ -6,48 +6,29 @@
* @subpackage PluginsShared
*/
-if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
- /**
- * escape_special_chars common function
- * Function: smarty_function_escape_special_chars
- * Purpose: used by other smarty functions to escape
- * special chars except for already escaped ones
- *
- * @author Monte Ohrt
- *
- * @param string $string text that should by escaped
- *
- * @return string
- */
- function smarty_function_escape_special_chars($string)
- {
- if (!is_array($string)) {
+/**
+ * escape_special_chars common function
+ * Function: smarty_function_escape_special_chars
+ * Purpose: used by other smarty functions to escape
+ * special chars except for already escaped ones
+ *
+ * @author Monte Ohrt
+ *
+ * @param string $string text that should by escaped
+ *
+ * @return string
+ */
+function smarty_function_escape_special_chars($string)
+{
+ if (!is_array($string)) {
+ if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
$string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
- }
-
- return $string;
- }
-} else {
- /**
- * escape_special_chars common function
- * Function: smarty_function_escape_special_chars
- * Purpose: used by other smarty functions to escape
- * special chars except for already escaped ones
- *
- * @author Monte Ohrt
- *
- * @param string $string text that should by escaped
- *
- * @return string
- */
- function smarty_function_escape_special_chars($string)
- {
- if (!is_array($string)) {
+ } else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string);
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
}
-
- return $string;
}
+
+ return $string;
}
diff --git a/include/smarty/libs/plugins/shared.literal_compiler_param.php b/include/smarty/libs/plugins/shared.literal_compiler_param.php
index 47d728a76..8a3711d30 100644
--- a/include/smarty/libs/plugins/shared.literal_compiler_param.php
+++ b/include/smarty/libs/plugins/shared.literal_compiler_param.php
@@ -20,16 +20,17 @@
function smarty_literal_compiler_param($params, $index, $default = null)
{
// not set, go default
- if (!isset($params[$index])) {
+ if (!isset($params[ $index ])) {
return $default;
}
// test if param is a literal
- if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[$index])) {
- throw new SmartyException('$param[' . $index . '] is not a literal and is thus not evaluatable at compile time');
+ if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
+ throw new SmartyException('$param[' . $index .
+ '] is not a literal and is thus not evaluatable at compile time');
}
$t = null;
- eval("\$t = " . $params[$index] . ";");
+ eval("\$t = " . $params[ $index ] . ";");
return $t;
}
diff --git a/include/smarty/libs/plugins/shared.make_timestamp.php b/include/smarty/libs/plugins/shared.make_timestamp.php
index f87d40c7e..67f862441 100644
--- a/include/smarty/libs/plugins/shared.make_timestamp.php
+++ b/include/smarty/libs/plugins/shared.make_timestamp.php
@@ -21,12 +21,14 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
- } elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) {
+ } elseif ($string instanceof DateTime ||
+ (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)
+ ) {
return (int) $string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) == 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
- return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2),
- substr($string, 4, 2), substr($string, 6, 2), substr($string, 0, 4));
+ return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2), substr($string, 4, 2),
+ substr($string, 6, 2), substr($string, 0, 4));
} elseif (is_numeric($string)) {
// it is a numeric string, we handle it as timestamp
return (int) $string;
diff --git a/include/smarty/libs/plugins/shared.mb_str_replace.php b/include/smarty/libs/plugins/shared.mb_str_replace.php
index a5682ed30..0c3ffe258 100644
--- a/include/smarty/libs/plugins/shared.mb_str_replace.php
+++ b/include/smarty/libs/plugins/shared.mb_str_replace.php
@@ -26,7 +26,7 @@ if (!function_exists('smarty_mb_str_replace')) {
if (is_array($subject)) {
// call mb_replace for each single string in $subject
foreach ($subject as &$string) {
- $string = & smarty_mb_str_replace($search, $replace, $string, $c);
+ $string = smarty_mb_str_replace($search, $replace, $string, $c);
$count += $c;
}
} elseif (is_array($search)) {
diff --git a/include/smarty/libs/plugins/shared.mb_wordwrap.php b/include/smarty/libs/plugins/shared.mb_wordwrap.php
index 31f4acf01..21632a1c0 100644
--- a/include/smarty/libs/plugins/shared.mb_wordwrap.php
+++ b/include/smarty/libs/plugins/shared.mb_wordwrap.php
@@ -24,7 +24,8 @@ if (!function_exists('smarty_mb_wordwrap')) {
function smarty_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false)
{
// break words into tokens using white space as a delimiter
- $tokens = preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
+ $tokens =
+ preg_split('!(\s)!S' . Smarty::$_UTF8_MODIFIER, $str, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
$length = 0;
$t = '';
$_previous = false;
@@ -34,8 +35,9 @@ if (!function_exists('smarty_mb_wordwrap')) {
$token_length = mb_strlen($_token, Smarty::$_CHARSET);
$_tokens = array($_token);
if ($token_length > $width) {
- if ($cut) {
- $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
+ if ($cut) {
+ $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1,
+ PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_cacheresource.php b/include/smarty/libs/sysplugins/smarty_cacheresource.php
index 14ab62fd9..2a4552cb2 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource.php
@@ -46,11 +46,12 @@ abstract class Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
- * @param bool $update flag if called because cache update
+ * @param boolean $update flag if called because cache update
*
- * @return bool true or false if the cached content does not exist
+ * @return boolean true or false if the cached content does not exist
*/
- abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false);
+ abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null,
+ $update = false);
/**
* Write the rendered template output to cache
@@ -62,6 +63,15 @@ abstract class Smarty_CacheResource
*/
abstract public function writeCachedContent(Smarty_Internal_Template $_template, $content);
+ /**
+ * Read cached template from cache
+ *
+ * @param Smarty_Internal_Template $_template template object
+ *
+ * @return string content
+ */
+ abstract function readCachedContent(Smarty_Internal_Template $_template);
+
/**
* Return cached content
*
@@ -185,39 +195,26 @@ abstract class Smarty_CacheResource
}
// try smarty's cache
- if (isset($smarty->_cache['cacheresource_handlers'][$type])) {
- return $smarty->_cache['cacheresource_handlers'][$type];
+ if (isset($smarty->_cache[ 'cacheresource_handlers' ][ $type ])) {
+ return $smarty->_cache[ 'cacheresource_handlers' ][ $type ];
}
// 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
- return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type];
+ return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = $smarty->registered_cache_resources[ $type ];
}
// try sysplugins dir
- if (isset(self::$sysplugins[$type])) {
+ if (isset(self::$sysplugins[ $type ])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
- return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
+ return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
}
// try plugins dir
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
if ($smarty->loadPlugin($cache_resource_class)) {
- return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
+ return $smarty->_cache[ 'cacheresource_handlers' ][ $type ] = new $cache_resource_class();
}
// give up
throw new SmartyException("Unable to load cache resource '{$type}'");
}
-
- /**
- * Invalid Loaded Cache Files
- *
- * @param Smarty $smarty Smarty object
- */
- public function invalidLoadedCache(Smarty $smarty)
- {
- $smarty->_cache['isCached'] = array();
- if (isset($smarty->ext->_subtemplate)) {
- $smarty->ext->_subtemplate->tplObjects = array();
- }
- }
}
diff --git a/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php b/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php
index 4e9606ef1..8f1290e49 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php
@@ -43,7 +43,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
{
- return null;
+ return false;
}
/**
@@ -63,9 +63,9 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Delete content from cache
*
- * @param string $name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
+ * @param string|null $name template name
+ * @param string|null $cache_id cache id
+ * @param string|null $compile_id compile id
* @param integer|null $exp_time seconds till expiration time in seconds or null
*
* @return integer number of deleted caches
@@ -84,7 +84,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{
$_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;
- $path = $cached->source->filepath . $_cache_id . $_compile_id;
+ $path = $cached->source->uid . $_cache_id . $_compile_id;
$cached->filepath = sha1($path);
if ($_template->smarty->cache_locking) {
$cached->lock_id = sha1('lock.' . $path);
@@ -101,7 +101,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
- $mtime = $this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
+ $mtime =
+ $this->fetchTimestamp($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id);
if ($mtime !== null) {
$cached->timestamp = $mtime;
$cached->exists = !!$cached->timestamp;
@@ -109,7 +110,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
return;
}
$timestamp = null;
- $this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content, $timestamp);
+ $this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $cached->content,
+ $timestamp);
$cached->timestamp = isset($timestamp) ? $timestamp : false;
$cached->exists = !!$cached->timestamp;
}
@@ -117,27 +119,25 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Read the cached template and process the header
*
- * @param Smarty_Internal_Template $_template template object
- * @param Smarty_Template_Cached $cached cached object
- * @param bool $update flag if called because cache update
+ * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
+ * @param Smarty_Template_Cached $cached cached object
+ * @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
- public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
+ public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
+ $update = false)
{
if (!$cached) {
- $cached = $_template->cached;
+ $cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
- $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
+ $this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
+ $_smarty_tpl->compile_id, $content, $timestamp);
}
if (isset($content)) {
- /** @var Smarty_Internal_Template $_smarty_tpl
- * used in evaluated code
- */
- $_smarty_tpl = $_template;
eval("?>" . $content);
$cached->content = null;
return true;
@@ -156,7 +156,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
- return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, $content);
+ return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id,
+ $_template->compile_id, $_template->cache_lifetime, $content);
}
/**
@@ -164,7 +165,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
*
- * @return string content
+ * @return string|boolean content
*/
public function readCachedContent(Smarty_Internal_Template $_template)
{
@@ -172,7 +173,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null;
if ($content === null) {
$timestamp = null;
- $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
+ $this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
+ $_template->compile_id, $content, $timestamp);
}
if (isset($content)) {
return $content;
@@ -215,14 +217,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
} else {
return 0;
}
- // remove from template cache
- if (isset($smarty->_cache['template_objects'])) {
- foreach ($smarty->_cache['template_objects'] as $key => $_tpl) {
- if (isset($_tpl->cached) && $_tpl->source->uid == $source->uid) {
- unset($smarty->_cache['template_objects'][$key]);
- }
- }
- }
}
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);
diff --git a/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
index ee4021a19..bab1b5c09 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
@@ -55,7 +55,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
- $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
+ $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached);
}
@@ -69,40 +69,41 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
public function populateTimestamp(Smarty_Template_Cached $cached)
{
- if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content, $timestamp, $cached->source->uid)) {
+ if (!$this->fetch($cached->filepath, $cached->source->name, $cached->cache_id, $cached->compile_id, $content,
+ $timestamp, $cached->source->uid)
+ ) {
return;
}
$cached->content = $content;
$cached->timestamp = (int) $timestamp;
- $cached->exists = $cached->timestamp;
+ $cached->exists = !!$cached->timestamp;
}
/**
* Read the cached template and process the header
*
- * @param Smarty_Internal_Template $_template template object
- * @param Smarty_Template_Cached $cached cached object
- * @param bool $update flag if called because cache update
+ * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
+ * @param Smarty_Template_Cached $cached cached object
+ * @param boolean $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
- public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
+ public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
+ $update = false)
{
if (!$cached) {
- $cached = $_template->cached;
+ $cached = $_smarty_tpl->cached;
}
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
- if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
+ if (!$this->fetch($_smarty_tpl->cached->filepath, $_smarty_tpl->source->name, $_smarty_tpl->cache_id,
+ $_smarty_tpl->compile_id, $content, $timestamp, $_smarty_tpl->source->uid)
+ ) {
return false;
}
}
if (isset($content)) {
- /** @var Smarty_Internal_Template $_smarty_tpl
- * used in evaluated code
- */
- $_smarty_tpl = $_template;
eval("?>" . $content);
return true;
@@ -131,14 +132,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
*
- * @return string content
+ * @return string|false content
*/
public function readCachedContent(Smarty_Internal_Template $_template)
{
$content = $_template->cached->content ? $_template->cached->content : null;
$timestamp = null;
if ($content === null) {
- if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp, $_template->source->uid)) {
+ if (!$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id,
+ $_template->compile_id, $content, $timestamp, $_template->source->uid)
+ ) {
return false;
}
}
@@ -164,14 +167,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!$this->purge()) {
$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;
}
@@ -194,19 +189,9 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$uid = $this->getTemplateUid($smarty, $resource_name);
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' .
- $this->sanitize($compile_id);
+ $this->sanitize($compile_id);
$this->delete(array($cid));
$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;
}
@@ -242,7 +227,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$string = trim($string, '|');
if (!$string) {
- return null;
+ return '';
}
return preg_replace('#[^\w\|]+#S', '_', $string);
}
@@ -260,14 +245,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @return boolean success
*/
- protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null, &$timestamp = null, $resource_uid = null)
+ protected function fetch($cid, $resource_name = null, $cache_id = null, $compile_id = null, &$content = null,
+ &$timestamp = null, $resource_uid = null)
{
$t = $this->read(array($cid));
- $content = !empty($t[$cid]) ? $t[$cid] : null;
+ $content = !empty($t[ $cid ]) ? $t[ $cid ] : null;
$timestamp = null;
if ($content && ($timestamp = $this->getMetaTimestamp($content))) {
- $invalidated = $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
+ $invalidated =
+ $this->getLatestInvalidationTimestamp($cid, $resource_name, $cache_id, $compile_id, $resource_uid);
if ($invalidated > $timestamp) {
$timestamp = null;
$content = null;
@@ -286,7 +273,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
protected function addMetaTimestamp(&$content)
{
$mt = explode(" ", microtime());
- $ts = pack("NN", $mt[1], (int) ($mt[0] * 100000000));
+ $ts = pack("NN", $mt[ 1 ], (int) ($mt[ 0 ] * 100000000));
$content = $ts . $content;
}
@@ -300,6 +287,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
protected function getMetaTimestamp(&$content)
{
extract(unpack('N1s/N1m/a*content', $content));
+ /**
+ * @var int $s
+ * @var int $m
+ */
return $s + ($m / 100000000);
}
@@ -314,7 +305,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @return void
*/
- protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
+ protected function invalidate($cid = null, $resource_name = null, $cache_id = null, $compile_id = null,
+ $resource_uid = null)
{
$now = microtime(true);
$key = null;
@@ -354,7 +346,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @return float the microtime the CacheID was invalidated
*/
- protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
+ protected function getLatestInvalidationTimestamp($cid, $resource_name = null, $cache_id = null, $compile_id = null,
+ $resource_uid = null)
{
// abort if there is no CacheID
if (false && !$cid) {
@@ -388,7 +381,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* @return array list of InvalidationKeys
* @uses $invalidationKeyPrefix to prepend to each InvalidationKey
*/
- protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null, $resource_uid = null)
+ protected function listInvalidationKeys($cid, $resource_name = null, $cache_id = null, $compile_id = null,
+ $resource_uid = null)
{
$t = array('IVK#ALL');
$_name = $_compile = '#';
@@ -440,7 +434,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$key = 'LOCK#' . $cached->filepath;
$data = $this->read(array($key));
- return $data && time() - $data[$key] < $smarty->locking_timeout;
+ return $data && time() - $data[ $key ] < $smarty->locking_timeout;
}
/**
diff --git a/include/smarty/libs/sysplugins/smarty_data.php b/include/smarty/libs/sysplugins/smarty_data.php
index 7cf18a43e..b9f5de9a5 100644
--- a/include/smarty/libs/sysplugins/smarty_data.php
+++ b/include/smarty/libs/sysplugins/smarty_data.php
@@ -59,7 +59,7 @@ class Smarty_Data extends Smarty_Internal_Data
} elseif (is_array($_parent)) {
// set up variable values
foreach ($_parent as $_key => $_val) {
- $this->tpl_vars[$_key] = new Smarty_Variable($_val);
+ $this->tpl_vars[ $_key ] = new Smarty_Variable($_val);
}
} elseif ($_parent != null) {
throw new SmartyException("Wrong type for template variables");
diff --git a/include/smarty/libs/sysplugins/smarty_internal_block.php b/include/smarty/libs/sysplugins/smarty_internal_block.php
new file mode 100644
index 000000000..a33ad1b11
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_block.php
@@ -0,0 +1,90 @@
+name = $name;
+ $this->tplIndex = $tplIndex;
+ }
+
+ /**
+ * Compiled block code overloaded by {block} class
+ *
+ * @param \Smarty_Internal_Template $tpl
+ */
+ public function callBlock(Smarty_Internal_Template $tpl)
+ {
+ }
+}
\ No newline at end of file
diff --git a/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php b/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
index 64d02dfe5..7df4ddffb 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
@@ -27,39 +27,32 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
- $_source_file_path = str_replace(':', '.', $_template->source->filepath);
- $_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;
- $_filepath = $_template->source->uid;
+ $source = &$_template->source;
+ $smarty = &$_template->smarty;
+ $_compile_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
+ $_filepath = sha1($source->uid . $smarty->_joined_template_dir);
+ $cached->filepath = $smarty->getCacheDir();
+ if (isset($_template->cache_id)) {
+ $cached->filepath .= preg_replace(array('![^\w|]+!', '![|]+!'), array('_', $_compile_dir_sep),
+ $_template->cache_id) . $_compile_dir_sep;
+ }
+ if (isset($_template->compile_id)) {
+ $cached->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) . $_compile_dir_sep;
+ }
// if use_sub_dirs, break file into directories
- if ($_template->smarty->use_sub_dirs) {
- $_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
- $_filepath;
+ if ($smarty->use_sub_dirs) {
+ $cached->filepath .= $_filepath[ 0 ] . $_filepath[ 1 ] . $smarty->ds . $_filepath[ 2 ] . $_filepath[ 3 ] . $smarty->ds .
+ $_filepath[ 4 ] . $_filepath[ 5 ] . $smarty->ds;
}
- $_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
- if (isset($_cache_id)) {
- $_cache_id = str_replace('|', $_compile_dir_sep, $_cache_id) . $_compile_dir_sep;
- } else {
- $_cache_id = '';
+ $cached->filepath .= $_filepath;
+ $basename = $source->handler->getBasename($source);
+ if (!empty($basename)) {
+ $cached->filepath .= '.' . $basename;
}
- if (isset($_compile_id)) {
- $_compile_id = $_compile_id . $_compile_dir_sep;
- } else {
- $_compile_id = '';
+ if ($smarty->cache_locking) {
+ $cached->lock_id = $cached->filepath . '.lock';
}
- $_cache_dir = $_template->smarty->getCacheDir();
- if ($_template->smarty->cache_locking) {
- // create locking file name
- // relative file name?
- if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_cache_dir)) {
- $_lock_dir = rtrim(getcwd(), '/\\') . DS . $_cache_dir;
- } else {
- $_lock_dir = $_cache_dir;
- }
- $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 .= '.php';
$cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) {
$cached->timestamp = filemtime($cached->filepath);
@@ -84,23 +77,21 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
/**
* Read the cached template and process its header
*
- * @param Smarty_Internal_Template $_template template object
- * @param Smarty_Template_Cached $cached cached object
- * @param bool $update flag if called because cache update
+ * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
+ * @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
*/
- public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
+ public function process(Smarty_Internal_Template $_smarty_tpl, Smarty_Template_Cached $cached = null,
+ $update = false)
{
- /** @var Smarty_Internal_Template $_smarty_tpl
- * used in included file
- */
- $_smarty_tpl = $_template;
- $_template->cached->valid = false;
+ $_smarty_tpl->cached->valid = false;
if ($update && defined('HHVM_VERSION')) {
- return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath);
+ eval("?>" . file_get_contents($_smarty_tpl->cached->filepath));
+ return true;
} else {
- return @include $_template->cached->filepath;
+ return @include $_smarty_tpl->cached->filepath;
}
}
@@ -114,9 +105,13 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
- if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
- if (function_exists('opcache_invalidate')) {
- opcache_invalidate($_template->cached->filepath);
+ if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content,
+ $_template->smarty) === true
+ ) {
+ if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
+ opcache_invalidate($_template->cached->filepath, true);
+ } elseif (function_exists('apc_compile_file')) {
+ apc_compile_file($_template->cached->filepath);
}
$cached = $_template->cached;
$cached->timestamp = $cached->exists = is_file($cached->filepath);
@@ -153,7 +148,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
- return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time);
+ return $smarty->ext->_cacheResourceFile->clear($smarty, null, null, null, $exp_time);
}
/**
@@ -169,7 +164,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
- return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time);
+ return $smarty->ext->_cacheResourceFile->clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time);
}
/**
@@ -188,7 +183,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
clearstatcache();
}
if (is_file($cached->lock_id)) {
- $t = @filemtime($cached->lock_id);
+ $t = filemtime($cached->lock_id);
return $t && (time() - $t < $smarty->locking_timeout);
} else {
return false;
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_append.php b/include/smarty/libs/sysplugins/smarty_internal_compile_append.php
index bd2ffe474..8539d6b2a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_append.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_append.php
@@ -19,9 +19,9 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
/**
* Compiles code for the {append} tag
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @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
*/
@@ -31,14 +31,15 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
$this->optional_attributes = array('scope', 'index');
+ $this->mapCache = array();
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// map to compile assign attributes
- if (isset($_attr['index'])) {
- $_params['smarty_internal_index'] = '[' . $_attr['index'] . ']';
- unset($_attr['index']);
+ if (isset($_attr[ 'index' ])) {
+ $_params[ 'smarty_internal_index' ] = '[' . $_attr[ 'index' ] . ']';
+ unset($_attr[ 'index' ]);
} else {
- $_params['smarty_internal_index'] = '[]';
+ $_params[ 'smarty_internal_index' ] = '[]';
}
$_new_attr = array();
foreach ($_attr as $key => $value) {
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php b/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php
index 5e3fce3cc..3bd33847b 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php
@@ -17,12 +17,21 @@
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
{
/**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $option_flags = array('nocache', 'noscope');
+
+ /**
* Valid scope names
*
* @var array
*/
- public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
+ 'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
+ 'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY);
/**
* Compiles code for the {assign} tag
@@ -39,60 +48,47 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
- $this->optional_attributes = array('scope', 'bubble_up');
- $_nocache = 'null';
+ $this->optional_attributes = array('scope');
+ $this->mapCache = array();
+ $_nocache = false;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// nocache ?
+ if ($_var = $compiler->getId($_attr[ 'var' ])) {
+ $_var = "'{$_var}'";
+ } else {
+ $_var = $_attr[ 'var' ];
+ }
if ($compiler->tag_nocache || $compiler->nocache) {
- $_nocache = 'true';
+ $_nocache = true;
// create nocache var to make it know for further compiling
- if (isset($compiler->template->tpl_vars[trim($_attr['var'], "'")])) {
- $compiler->template->tpl_vars[trim($_attr['var'], "'")]->nocache = true;
- } else {
- $compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_Variable(null, true);
- }
+ $compiler->setNocacheInVariable($_attr[ 'var' ]);
}
// scope setup
- $_scope = Smarty::SCOPE_LOCAL;
- if (isset($_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') {
- $_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;
- }
- }
- // compiled output
- if (isset($parameter['smarty_internal_index'])) {
- $output =
- "smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
+ if ($_attr[ 'noscope' ]) {
+ $_scope = - 1;
} else {
- // implement Smarty2's behaviour of variables assigned by reference
- if ($compiler->template->smarty instanceof SmartyBC) {
- $output =
- "tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
- $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 {
- $output = "tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
- }
+ $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
+ }
+ // optional parameter
+ $_params = "";
+ if ($_nocache || $_scope) {
+ $_params .= ' ,' . var_export($_nocache, true);
+ }
+ if ($_scope) {
+ $_params .= ' ,' . $_scope;
+ }
+ if (isset($parameter[ 'smarty_internal_index' ])) {
+ $output =
+ "tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n";
+ $output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n";
+ $output .= "settype(\$_tmp_array, 'array');\n";
+ $output .= "}\n";
+ $output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
+ $output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});\n?>";
+ } else {
+ $output = "_assignInScope({$_var}, {$_attr['value']}{$_params});\n?>";
}
- $output .= "\n\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, $_attr[var], $_scope);";
- $output .= '?>';
-
return $output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_block.php b/include/smarty/libs/sysplugins/smarty_internal_compile_block.php
index ab1fc6e00..5098d62fe 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_block.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block.php
@@ -47,13 +47,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
*/
public $optional_attributes = array('assign');
- /**
- * nesting level of block tags
- *
- * @var int
- */
- public static $blockTagNestingLevel = 0;
-
/**
* Saved compiler object
*
@@ -72,10 +65,10 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
- if (!isset($compiler->_cache['blockNesting'])) {
- $compiler->_cache['blockNesting'] = 0;
+ if (!isset($compiler->_cache[ 'blockNesting' ])) {
+ $compiler->_cache[ 'blockNesting' ] = 0;
}
- if ($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');
@@ -84,10 +77,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- $compiler->_cache['blockNesting'] ++;
- $compiler->_cache['blockName'][$compiler->_cache['blockNesting']] = $_attr['name'];
- $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][0] = 'block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
- $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = false;
+ $compiler->_cache[ 'blockNesting' ] ++;
+ $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
+ $compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
+ $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
+ $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
+ $compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
@@ -97,54 +92,13 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// $compiler->suppressNocacheProcessing = true;
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
//$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->taglineno);
}
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->suppressNocacheProcessing = true;
}
-
- /**
- * Compile saved child block source
- *
- * @param \Smarty_Internal_TemplateCompilerBase compiler object
- * @param string $_name optional name of child block
- *
- * @return string compiled code of child block
- */
- static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
- {
- if (!isset($compiler->_cache['blockNesting'])) {
- $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
- $compiler->parser->lex->taglineno);
- }
- $compiler->has_code = true;
- $compiler->suppressNocacheProcessing = true;
- $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true;
- $output = "ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
- return $output;
- }
-
- /**
- * Compile $smarty.block.parent
- *
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
- * @param string $_name optional name of child block
- *
- * @return string compiled code of child block
- */
- static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
- {
- if (!isset($compiler->_cache['blockNesting'])) {
- $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
- $compiler->parser->lex->taglineno);
- }
- $compiler->suppressNocacheProcessing = true;
- $compiler->has_code = true;
- $output = "ext->_inheritance->processBlock(\$_smarty_tpl, 4, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
- return $output;
- }
}
/**
@@ -166,62 +120,34 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
{
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']);
+ $_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ];
+ unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]);
+ $_name = $_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;
+ $_block[ $name ] = 'true';
}
}
- $_funcName = $_block[0];
+ $_className = $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ];
// 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 = "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 = "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 = "template->source->type}:{$compiler->template->source->name} */\n";
- $output .= "function {$_funcName}(\$_smarty_tpl, \$_blockParentStack) {\n";
+ $output .= "/* {block {$_name}} */\n";
+ $output .= "class {$_className} extends Smarty_Internal_Block\n";
+ $output .= "{\n";
+ foreach ($_block as $property => $value) {
+ $output .= "public \${$property} = " . var_export($value,true) .";\n";
+ }
+ $output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
+ //$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
+ if ($compiler->template->compiled->has_nocache_code) {
+ $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
+ }
if (isset($_assign)) {
$output .= "ob_start();\n";
}
@@ -232,61 +158,45 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
+ $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
$output .= "}\n";
- $output .= "/* {/block '{$_name}'} */\n\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);
+ $compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
+ $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// nocache plugins must be copied
- if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
- foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
+ 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] =
+ $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 = "_cache['blockNesting'] == 1) {
- $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
- var_export($_block, true) . ");\n";
+ if ($compiler->_cache[ 'blockNesting' ] == 1) {
+ $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n";
} else {
- $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
- var_export($_block, true) . ", \$_blockParentStack);\n";
-
+ $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n";
}
$output .= "?>\n";
- $compiler->_cache['blockNesting'] --;
- if ($compiler->_cache['blockNesting'] == 0) {
- unset($compiler->_cache['blockNesting']);
+ $compiler->_cache[ 'blockNesting' ] --;
+ if ($compiler->_cache[ 'blockNesting' ] == 0) {
+ unset($compiler->_cache[ 'blockNesting' ]);
}
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true;
return $output;
}
-
- /**
- * @param $match
- *
- * @return mixed
- */
- function removeNocache($match)
- {
- $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);
- return $code;
- }
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_block_child.php b/include/smarty/libs/sysplugins/smarty_internal_compile_block_child.php
new file mode 100644
index 000000000..bb070ebe3
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block_child.php
@@ -0,0 +1,54 @@
+
+ */
+class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_CompileBase
+{
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $option_flags = array();
+
+ /**
+ * Saved compiler object
+ *
+ * @var Smarty_Internal_TemplateCompilerBase
+ */
+ public $compiler = null;
+
+ /**
+ * Compiles code for the {block_parent} tag
+ *
+ * @param array $args array with attributes from parser
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param array $parameter array with compilation parameter
+ *
+ * @return bool true
+ */
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ {
+ if (!isset($compiler->_cache[ 'blockNesting' ])) {
+ $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
+ $compiler->parser->lex->taglineno);
+ }
+ $compiler->has_code = true;
+ $compiler->suppressNocacheProcessing = true;
+ $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
+ $output = "inheritance->callChild(\$_smarty_tpl, \$this);\n?>\n";
+ return $output;
+ }
+}
\ No newline at end of file
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_block_parent.php b/include/smarty/libs/sysplugins/smarty_internal_compile_block_parent.php
new file mode 100644
index 000000000..0ec1e8485
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block_parent.php
@@ -0,0 +1,73 @@
+
+ */
+class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Shared_Inheritance
+{
+
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $optional_attributes = array('name');
+
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $shorttag_order = array('name');
+
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $option_flags = array();
+
+ /**
+ * Saved compiler object
+ *
+ * @var Smarty_Internal_TemplateCompilerBase
+ */
+ public $compiler = null;
+
+ /**
+ * Compiles code for the {block_parent} tag
+ *
+ * @param array $args array with attributes from parser
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param array $parameter array with compilation parameter
+ *
+ * @return bool true
+ */
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ {
+ // check and get attributes
+ $_attr = $this->getAttributes($compiler, $args);
+ if (!isset($compiler->_cache[ 'blockNesting' ])) {
+ $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
+ $compiler->parser->lex->taglineno);
+ }
+ $compiler->suppressNocacheProcessing = true;
+ $compiler->has_code = true;
+ $output = "inheritance->callParent(\$_smarty_tpl, \$this" .
+ (isset($_attr[ 'name' ]) ? ", {$_attr[ 'name' ]}" : '') . ");\n?>\n";
+ return $output;
+ }
+}
\ No newline at end of file
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
index cbc73d36a..50157382a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
@@ -35,43 +35,76 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
/**
* Compiles code for the {break} tag
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @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
- * @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ {
+ list($levels, $foreachLevels) = $this->checkLevels($args, $compiler);
+ $output = "getTagCompiler('foreach');
+ $output .= $foreachCompiler->compileRestore($foreachLevels);
+ }
+ $output .= "break {$levels};?>";
+ return $output;
+ }
+
+ /**
+ * check attributes and return array of break and foreach levels
+ *
+ * @param array $args array with attributes from parser
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param string $tag tag name
+ *
+ * @return array
+ * @throws \SmartyCompilerException
+ */
+ public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler, $tag = 'break')
{
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
- if (isset($_attr['levels'])) {
- if (!is_numeric($_attr['levels'])) {
+ if (isset($_attr[ 'levels' ])) {
+ if (!is_numeric($_attr[ 'levels' ])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
}
- $_levels = $_attr['levels'];
+ $levels = $_attr[ 'levels' ];
} else {
- $_levels = 1;
+ $levels = 1;
}
- $level_count = $_levels;
+ $level_count = $levels;
$stack_count = count($compiler->_tag_stack) - 1;
- while ($level_count > 0 && $stack_count >= 0) {
- if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
+ $foreachLevels = 0;
+ $lastTag = '';
+ while ($level_count >= 0 && $stack_count >= 0) {
+ if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) {
+ $lastTag = $compiler->_tag_stack[ $stack_count ][ 0 ];
+ if ($level_count === 0) {
+ break;
+ }
$level_count --;
+ if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') {
+ $foreachLevels ++;
+ }
}
$stack_count --;
}
if ($level_count != 0) {
- $compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true);
+ $compiler->trigger_template_error("cannot {$tag} {$levels} level(s)", null, true);
}
-
- return "";
+ if ($lastTag === 'foreach' && $tag === 'break') {
+ $foreachLevels --;
+ }
+ return array($levels, $foreachLevels);
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_call.php b/include/smarty/libs/sysplugins/smarty_internal_compile_call.php
index b7204bec0..739df5eca 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_call.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_call.php
@@ -53,13 +53,13 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
- if (isset($_attr['assign'])) {
+ if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
- $_assign = $_attr['assign'];
+ $_assign = $_attr[ 'assign' ];
}
//$_name = trim($_attr['name'], "'\"");
- $_name = $_attr['name'];
- unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
+ $_name = $_attr[ 'name' ];
+ unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'nocache' ]);
// set flag (compiled code of {function} must be included in cache file
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
$_nocache = 'true';
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php b/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
index be45f3e94..34fc55f9d 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
@@ -32,49 +32,50 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
*/
public $optional_attributes = array('name', 'assign', 'append');
- /**
- * Compiles code for the {capture} tag
- *
- * @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
- *
- * @return string compiled code
- */
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
- {
- // check and get attributes
- $_attr = $this->getAttributes($compiler, $args);
-
- $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'";
- $assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
- $append = isset($_attr['append']) ? $_attr['append'] : 'null';
-
- $compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
- // maybe nocache because of nocache variables
- $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
- $_output = "_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>";
-
- 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
+ * @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)
+ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{
- $tag = strtolower(trim($parameter[ 0 ], '"\''));
+ $tag = trim($parameter[ 0 ], '"\'');
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$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)";
+ return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')";
+ }
+
+ /**
+ * Compiles code for the {capture} tag
+ *
+ * @param array $args array with attributes from parser
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param null $parameter
+ *
+ * @return string compiled code
+ */
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
+ {
+ // check and get attributes
+ $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
+
+ $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
+ $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
+ $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
+
+ $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
+ // maybe nocache because of nocache variables
+ $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
+ $_output = "smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
+
+ return $_output;
}
}
@@ -89,29 +90,23 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/capture} tag
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param null $parameter
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
- $_attr = $this->getAttributes($compiler, $args);
+ $_attr = $this->getAttributes($compiler, $args, $parameter, '/capture');
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
- list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
+ list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
- $_output = "_cache['capture_stack']);\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_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
- $_output .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n";
- $_output .= "} else \$_smarty_tpl->capture_error();?>";
-
- return $_output;
+ return "smarty->ext->_capture->close(\$_smarty_tpl);?>";
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php b/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
index d2e50a08f..7c6e9b59e 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
@@ -38,15 +38,24 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
- public $optional_attributes = array('section', 'scope', 'bubble_up');
+ public $optional_attributes = array('section', 'scope');
+
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $option_flags = array('nocache', 'noscope');
/**
* Valid scope names
- *
+ *
* @var array
*/
- public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
+ 'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
+ 'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY);
/**
* Compiles code for the {config_load} tag
@@ -62,37 +71,22 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// save possible attributes
- $conf_file = $_attr['file'];
- if (isset($_attr['section'])) {
- $section = $_attr['section'];
+ $conf_file = $_attr[ 'file' ];
+ if (isset($_attr[ 'section' ])) {
+ $section = $_attr[ 'section' ];
} else {
$section = 'null';
}
- $_scope = Smarty::SCOPE_LOCAL;
- if (isset($_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') {
- $_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;
- }
+ // scope setup
+ if ($_attr[ 'noscope' ]) {
+ $_scope = - 1;
+ } else {
+ $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
}
// create config object
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
index 2ee04c94e..7492c7df2 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
@@ -14,23 +14,8 @@
* @package Smarty
* @subpackage Compiler
*/
-class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
+class Smarty_Internal_Compile_Continue extends Smarty_Internal_Compile_Break
{
- /**
- * Attribute definition: Overwrites base class.
- *
- * @var array
- * @see Smarty_Internal_CompileBase
- */
- public $optional_attributes = array('levels');
-
- /**
- * Attribute definition: Overwrites base class.
- *
- * @var array
- * @see Smarty_Internal_CompileBase
- */
- public $shorttag_order = array('levels');
/**
* Compiles code for the {continue} tag
@@ -44,34 +29,14 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
- static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
- // check and get attributes
- $_attr = $this->getAttributes($compiler, $args);
-
- if ($_attr['nocache'] === true) {
- $compiler->trigger_template_error('nocache option not allowed', null, true);
+ list($levels, $foreachLevels) = $this->checkLevels($args, $compiler, 'continue');
+ $output = " 1) {
+ /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
+ $foreachCompiler = $compiler->getTagCompiler('foreach');
+ $output .= $foreachCompiler->compileRestore($foreachLevels - 1);
}
-
- if (isset($_attr['levels'])) {
- if (!is_numeric($_attr['levels'])) {
- $compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
- }
- $_levels = $_attr['levels'];
- } else {
- $_levels = 1;
- }
- $level_count = $_levels;
- $stack_count = count($compiler->_tag_stack) - 1;
- while ($level_count > 0 && $stack_count >= 0) {
- if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
- $level_count --;
- }
- $stack_count --;
- }
- if ($level_count != 0) {
- $compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
- }
-
- return "";
+ $output .= "continue {$levels};?>";
+ return $output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php b/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
index d73c81a10..1668e72e8 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
@@ -34,7 +34,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true;
// display debug template
- $_output = "display_debug(\$_smarty_tpl);\n";
+ $_output =
+ "display_debug(\$_smarty_tpl);\n";
$_output .= "unset(\$_smarty_debug);\n?>";
return $_output;
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_eval.php b/include/smarty/libs/sysplugins/smarty_internal_compile_eval.php
index 407482f07..97a3c29c5 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_eval.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_eval.php
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('var');
+
/**
* Attribute definition: Overwrites base class.
*
@@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('assign');
+
/**
* Attribute definition: Overwrites base class.
*
@@ -48,17 +50,16 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
*/
public function compile($args, $compiler)
{
- $this->required_attributes = array('var');
- $this->optional_attributes = array('assign');
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if (isset($_attr['assign'])) {
+ if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
- $_assign = $_attr['assign'];
+ $_assign = $_attr[ 'assign' ];
}
// create template object
- $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr['var'] . ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
+ $_output = "\$_template = new {$compiler->smarty->template_class}('eval:'." . $_attr[ 'var' ] .
+ ", \$_smarty_tpl->smarty, \$_smarty_tpl);";
//was there an assign attribute?
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php b/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
index 7ce3dcf6f..83cb80500 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
@@ -55,37 +55,36 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
$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->parser->lex->line - 1);
}
// add code to initialize inheritance
$this->registerInit($compiler, true);
- $file = trim($_attr['file'], '\'"');
+ $file = trim($_attr[ 'file' ], '\'"');
if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') {
// generate code for each template
$files = array_reverse(explode('|', substr($file, 8)));
$i = 0;
foreach ($files as $file) {
- if ($file[0] == '"') {
+ if ($file[ 0 ] == '"') {
$file = trim($file, '".');
} else {
$file = "'{$file}'";
}
$i ++;
- if ($i == count($files) && isset($_attr['extends_resource'])) {
+ if ($i == count($files) && isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
$this->compileInclude($compiler, $file);
}
- if (!isset($_attr['extends_resource'])) {
+ if (!isset($_attr[ 'extends_resource' ])) {
$this->compileEndChild($compiler);
}
} else {
- $this->compileEndChild($compiler);
- $this->compileInclude($compiler, $_attr['file']);
+ $this->compileEndChild($compiler, $_attr[ 'file' ]);
}
$compiler->has_code = false;
return '';
@@ -95,24 +94,35 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
* Add code for inheritance endChild() method to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param null|string $template optional inheritance parent template
*/
- private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
+ private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler, $template = null)
{
+ $inlineUids = '';
+ if (isset($template) && $compiler->smarty->merge_compiled_includes) {
+ $code = $compiler->compileTag('include', array($template, array('scope' => 'parent')));
+ if (preg_match("/([,][\s]*['][a-z0-9]+['][,][\s]*[']content.*['])[)]/", $code, $match)) {
+ $inlineUids = $match[ 1 ];
+ }
+ }
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
- "ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n");
+ "inheritance->endChild(\$_smarty_tpl" .
+ (isset($template) ?
+ ', ' . $template . $inlineUids :
+ '') . ");\n?>\n");
}
/**
* Add code for including subtemplate to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
- * @param string $file subtemplate name
+ * @param string $template subtemplate name
*/
- private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $file)
+ private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->compileTag('include',
- array($file,
+ array($template,
array('scope' => 'parent'))));
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_for.php b/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
index 7b86d4859..e5e7c61c3 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
@@ -34,7 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
*/
public function compile($args, $compiler, $parameter)
{
- $compiler->loopNesting++;
+ $compiler->loopNesting ++;
if ($parameter == 0) {
$this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step');
@@ -42,46 +42,47 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$this->required_attributes = array('start', 'ifexp', 'var', 'step');
$this->optional_attributes = array();
}
+ $this->mapCache = array();
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = "tpl_vars[$var] = new Smarty_Variable;\n";
+ $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable(null, \$_smarty_tpl->isRenderingCache);\n";
$output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n";
}
- if (is_array($_attr['var'])) {
- $var = $_attr['var']['var'];
- $index = $_attr['var']['smarty_internal_index'];
+ if (is_array($_attr[ 'var' ])) {
+ $var = $_attr[ 'var' ][ 'var' ];
+ $index = $_attr[ 'var' ][ 'smarty_internal_index' ];
} else {
- $var = $_attr['var'];
+ $var = $_attr[ 'var' ];
$index = '';
}
$output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
} else {
- $_statement = $_attr['start'];
- if (is_array($_statement['var'])) {
- $var = $_statement['var']['var'];
- $index = $_statement['var']['smarty_internal_index'];
+ $_statement = $_attr[ 'start' ];
+ if (is_array($_statement[ 'var' ])) {
+ $var = $_statement[ 'var' ][ 'var' ];
+ $index = $_statement[ 'var' ][ 'smarty_internal_index' ];
} else {
- $var = $_statement['var'];
+ $var = $_statement[ 'var' ];
$index = '';
}
- $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;";
- if (isset($_attr['step'])) {
+ $output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable(null, \$_smarty_tpl->isRenderingCache);";
+ if (isset($_attr[ 'step' ])) {
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = $_attr[step];";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$var]->step = 1;";
}
- if (isset($_attr['max'])) {
+ if (isset($_attr[ 'max' ])) {
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) min(ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step)),$_attr[max]);\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$var]->total = (int) ceil((\$_smarty_tpl->tpl_vars[$var]->step > 0 ? $_attr[to]+1 - ($_statement[value]) : $_statement[value]-($_attr[to])+1)/abs(\$_smarty_tpl->tpl_vars[$var]->step));\n";
@@ -149,7 +150,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
*/
public function compile($args, $compiler, $parameter)
{
- $compiler->loopNesting--;
+ $compiler->loopNesting --;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// must endblock be nocache?
@@ -162,7 +163,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
$output = "\n";
return $output;
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_foreach.php b/include/smarty/libs/sysplugins/smarty_internal_compile_foreach.php
index 178a0a52c..5ddd42d8a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_foreach.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_foreach.php
@@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
* @var array
* @see Smarty_Internal_CompileBase
*/
- public $optional_attributes = array('name', 'key');
+ public $optional_attributes = array('name', 'key', 'properties');
/**
* Attribute definition: Overwrites base class.
@@ -92,32 +92,33 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$this->isNamed = false;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- $from = $_attr['from'];
- $item = $compiler->getId($_attr['item']);
+ $from = $_attr[ 'from' ];
+ $item = $compiler->getId($_attr[ 'item' ]);
if ($item === false) {
- $item = $compiler->getVariableName($_attr['item']);
+ $item = $compiler->getVariableName($_attr[ 'item' ]);
}
+ $key = $name = null;
$attributes = array('item' => $item);
- if (isset($_attr['key'])) {
- $key = $compiler->getId($_attr['key']);
+ if (isset($_attr[ 'key' ])) {
+ $key = $compiler->getId($_attr[ 'key' ]);
if ($key === false) {
- $key = $compiler->getVariableName($_attr['key']);
+ $key = $compiler->getVariableName($_attr[ 'key' ]);
}
- $attributes['key'] = $key;
+ $attributes[ 'key' ] = $key;
}
- if (isset($_attr['name'])) {
+ if (isset($_attr[ 'name' ])) {
$this->isNamed = true;
- $attributes['name'] = $compiler->getId($_attr['name']);
+ $name = $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']);
+ $fromName = $compiler->getVariableName($_attr[ 'from' ]);
if ($fromName) {
foreach (array('item', 'key') as $a) {
- if (isset($attributes[$a]) && $attributes[$a] == $fromName) {
+ if (isset($attributes[ $a ]) && $attributes[ $a ] == $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true);
}
@@ -125,151 +126,144 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
}
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
- $local = '$__foreach_' . (isset($attributes['name']) ? $attributes['name'] : $attributes['item']) . '_' .
- $this->counter ++ . '_';
- $needIteration = false;
+ $local = '$__foreach_' . $attributes[ 'item' ] . '_' . $this->counter ++ . '_';
// 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[ 'item' ])) {
+ $itemAttr = $this->matchResults[ 'item' ];
}
- if (!empty($this->matchResults['named'])) {
- $namedAttr = $this->matchResults['named'];
+ if (!empty($this->matchResults[ 'named' ])) {
+ $namedAttr = $this->matchResults[ 'named' ];
}
- if (isset($itemAttr['last'])) {
- $needIteration = true;
+ if (isset($_attr[ 'properties' ]) && preg_match_all("/['](.*?)[']/", $_attr[ 'properties' ], $match)) {
+ foreach ($match[ 1 ] as $prop) {
+ if (in_array($prop, $this->itemProperties)) {
+ $itemAttr[ $prop ] = true;
+ } else {
+ $compiler->trigger_template_error("Invalid property '{$prop}'", null, true);
+ }
+ }
+ if ($this->isNamed) {
+ foreach ($match[ 1 ] as $prop) {
+ if (in_array($prop, $this->nameProperties)) {
+ $nameAttr[ $prop ] = true;
+ } else {
+ $compiler->trigger_template_error("Invalid property '{$prop}'", null, true);
+ }
+ }
+ }
}
- if (isset($namedAttr['last'])) {
- $needIteration = true;
+ if (isset($itemAttr[ 'first' ])) {
+ $itemAttr[ 'index' ] = true;
+ }
+ if (isset($namedAttr[ 'first' ])) {
+ $namedAttr[ 'index' ] = true;
+ }
+ if (isset($namedAttr[ 'last' ])) {
+ $namedAttr[ 'iteration' ] = true;
+ $namedAttr[ 'total' ] = true;
+ }
+ if (isset($itemAttr[ 'last' ])) {
+ $itemAttr[ 'iteration' ] = true;
+ $itemAttr[ 'total' ] = true;
+ }
+ if (isset($namedAttr[ 'show' ])) {
+ $namedAttr[ 'total' ] = true;
+ }
+ if (isset($itemAttr[ 'show' ])) {
+ $itemAttr[ 'total' ] = true;
}
-
$keyTerm = '';
- if (isset($itemAttr['key'])) {
- $keyTerm = "{$itemVar}->key => ";
- } elseif (isset($attributes['key'])) {
+ if (isset($attributes[ 'key' ])) {
$keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => ";
}
-
- $saveVars = array();
- $restoreVars = array();
+ if (isset($itemAttr[ 'key' ])) {
+ $keyTerm = "{$itemVar}->key => ";
+ }
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";
- }
}
+ $needTotal = isset($itemAttr[ 'total' ]);
+ // Register tag
$this->openTag($compiler, 'foreach',
- array('foreach', $compiler->nocache, $local, $restoreVars, $itemVar, true));
+ array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2));
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
-
// generate output code
$output = " $code) {
- $output .= "{$local}{$k} = {$code}\n";
+ $output .= "\$_from = \$_smarty_tpl->smarty->ext->_foreach->init(\$_smarty_tpl, $from, " .
+ var_export($item, true);
+ if ($name || $needTotal || $key) {
+ $output .= ', ' . var_export($needTotal, true);
}
- if (isset($itemAttr['show']) || isset($itemAttr['total']) || isset($namedAttr['total']) || isset($namedAttr['show']) || isset($itemAttr['last']) || isset($namedAttr['last'])) {
- $output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
+ if ($name || $key) {
+ $output .= ', ' . var_export($key, true);
}
- $output .= "{$itemVar} = new Smarty_Variable();\n";
- if (isset($itemAttr['show'])) {
- $output .= "{$itemVar}->show = ({$local}total > 0);\n";
+ if ($name) {
+ $output .= ', ' . var_export($name, true) . ', ' . var_export($namedAttr, true);
}
- if (isset($itemAttr['total'])) {
- $output .= "{$itemVar}->total= {$local}total;\n";
+ $output .= ");\n";
+ if (isset($itemAttr[ 'show' ])) {
+ $output .= "{$itemVar}->show = ({$itemVar}->total > 0);\n";
}
- if ($this->isNamed) {
- $prop = array();
- if (isset($namedAttr['total'])) {
- $prop['total'] = "'total' => {$local}total";
- }
- if (isset($namedAttr['iteration'])) {
- $prop['iteration'] = "'iteration' => 0";
- }
- if (isset($namedAttr['index'])) {
- $prop['index'] = "'index' => -1";
- }
- if (isset($namedAttr['show'])) {
- $prop['show'] = "'show' => ({$local}total > 0)";
- }
- if (!empty($namedAttr)) {
- $_vars = 'array(' . join(', ', $prop) . ')';
- $output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
- }
+ if (isset($itemAttr[ 'iteration' ])) {
+ $output .= "{$itemVar}->iteration = 0;\n";
}
- if (isset($attributes['key'])) {
- $output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
+ if (isset($itemAttr[ 'index' ])) {
+ $output .= "{$itemVar}->index = -1;\n";
}
- if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
- $output .= "{$local}first = true;\n";
- }
- if (isset($itemAttr['iteration'])) {
- $output .= "{$itemVar}->iteration=0;\n";
- }
- if (isset($itemAttr['index'])) {
- $output .= "{$itemVar}->index=-1;\n";
- }
- if ($needIteration) {
- $output .= "{$local}iteration=0;\n";
- }
- $output .= "{$itemVar}->_loop = false;\n";
+ $output .= "if (\$_from !== null) {\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
- $output .= "{$itemVar}->_loop = true;\n";
- if (isset($attributes['key']) && isset($itemAttr['key'])) {
+ if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
- if (isset($itemAttr['iteration'])) {
+ if (isset($itemAttr[ 'iteration' ])) {
$output .= "{$itemVar}->iteration++;\n";
}
- if (isset($itemAttr['index'])) {
+ if (isset($itemAttr[ 'index' ])) {
$output .= "{$itemVar}->index++;\n";
}
- if ($needIteration) {
- $output .= "{$local}iteration++;\n";
+ if (isset($itemAttr[ 'first' ])) {
+ $output .= "{$itemVar}->first = !{$itemVar}->index;\n";
}
- if (isset($itemAttr['first'])) {
- $output .= "{$itemVar}->first = {$local}first;\n";
+ if (isset($itemAttr[ 'last' ])) {
+ $output .= "{$itemVar}->last = {$itemVar}->iteration == {$itemVar}->total;\n";
}
- if (isset($itemAttr['last'])) {
- $output .= "{$itemVar}->last = {$local}iteration == {$local}total;\n";
- }
- if ($this->isNamed) {
- if (isset($namedAttr['iteration'])) {
+ if (isset($foreachVar)) {
+ if (isset($namedAttr[ 'iteration' ])) {
$output .= "{$foreachVar}->value['iteration']++;\n";
}
- if (isset($namedAttr['index'])) {
+ if (isset($namedAttr[ 'index' ])) {
$output .= "{$foreachVar}->value['index']++;\n";
}
- if (isset($namedAttr['first'])) {
- $output .= "{$foreachVar}->value['first'] = {$local}first;\n";
+ if (isset($namedAttr[ 'first' ])) {
+ $output .= "{$foreachVar}->value['first'] = !{$foreachVar}->value['index'];\n";
}
- if (isset($namedAttr['last'])) {
- $output .= "{$foreachVar}->value['last'] = {$local}iteration == {$local}total;\n";
+ if (isset($namedAttr[ 'last' ])) {
+ $output .= "{$foreachVar}->value['last'] = {$foreachVar}->value['iteration'] == {$foreachVar}->value['total'];\n";
}
}
- if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
- $output .= "{$local}first = false;\n";
+ if (!empty($itemAttr)) {
+ $output .= "{$local}saved = {$itemVar};\n";
}
- $output .= "{$local}saved_local_item = {$itemVar};\n";
$output .= "?>";
return $output;
}
+
+ /**
+ * Compiles code for to restore saved template variables
+ *
+ * @param int $levels number of levels to restore
+ *
+ * @return string compiled code
+ */
+ public function compileRestore($levels)
+ {
+ return "\$_smarty_tpl->smarty->ext->_foreach->restore(\$_smarty_tpl, {$levels});\n";
+ }
}
/**
@@ -294,12 +288,13 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- list($openTag, $nocache, $local, $restoreVars, $itemVar, $foo) = $this->closeTag($compiler, array('foreach'));
- $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $restoreVars, $itemVar, false));
+ list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach'));
+ $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0));
$output = "_loop) {\n?>";
+ if ($restore == 2) {
+ $output .= "{$itemVar} = {$local}saved;\n";
+ }
+ $output .= "}\n} else {\n?>\n";
return $output;
}
}
@@ -329,19 +324,21 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true;
}
- list($openTag, $compiler->nocache, $local, $restoreVars, $itemVar, $restore) =
+ list($openTag, $compiler->nocache, $local, $itemVar, $restore) =
$this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = " 0) {
+ $output .= "}\n";
}
$output .= "}\n";
- foreach ($restoreVars as $restore) {
- $output .= $restore;
- }
- $output .= "?>";
-
+ /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
+ $foreachCompiler = $compiler->getTagCompiler('foreach');
+ $output .= $foreachCompiler->compileRestore(1);
+ $output .= "?>\n";
return $output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_function.php b/include/smarty/libs/sysplugins/smarty_internal_compile_function.php
index 28f335949..b7cd9e1c0 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_function.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_function.php
@@ -53,16 +53,15 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
- $compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
- unset($_attr['nocache']);
- $_name = trim($_attr['name'], "'\"");
- $compiler->parent_compiler->tpl_function[$_name] = $compiler->parent_compiler->template->tpl_function[$_name] = array();
+ unset($_attr[ 'nocache' ]);
+ $_name = trim($_attr[ 'name' ], "'\"");
+ $compiler->parent_compiler->tpl_function[ $_name ] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching);
$this->openTag($compiler, 'function', $save);
@@ -100,17 +99,15 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
- $compiler->loopNesting--;
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, array('function'));
- $_attr = $saved_data[0];
- $_name = trim($_attr['name'], "'\"");
- $compiler->parent_compiler->tpl_function[$_name]['called_functions'] = $compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions;
- $compiler->parent_compiler->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
- $compiler->parent_compiler->tpl_function[$_name]['uid'] = $compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
- $compiler->called_functions = array();
+ $_attr = $saved_data[ 0 ];
+ $_name = trim($_attr[ 'name' ], "'\"");
+ $compiler->parent_compiler->tpl_function[ $_name ][ 'compiled_filepath' ] =
+ $compiler->parent_compiler->template->compiled->filepath;
+ $compiler->parent_compiler->tpl_function[ $_name ][ 'uid' ] = $compiler->template->source->uid;
$_parameter = $_attr;
- unset($_parameter['name']);
+ unset($_parameter[ 'name' ]);
// default parameter
$_paramsArray = array();
foreach ($_parameter as $_key => $_value) {
@@ -133,7 +130,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . '_nocache';
if ($compiler->template->compiled->has_nocache_code) {
- $compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
+ $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name_caching' ] = $_funcNameCaching;
$output = "compiled->has_nocache_code = true;\n";
$output .= $_paramsCode;
- $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, \$_smarty_tpl->isRenderingCache);\n}";
$output .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
+ $output .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\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,
+ new Smarty_Internal_ParseTree_Tag($compiler->parser,
+ $output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "template->compiled->nocache_hash}%%*/ \\\$value){\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->smarty->ext->_tplFunction->restoreTemplateVariables(\\\$_smarty_tpl, '{$_name}');?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
- $output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n";
+ $output .= "}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n";
- $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->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this,
- 'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
+ $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->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
+ array($this, 'removeNocache'),
+ $_functionCode->to_smarty_php($compiler->parser)));
}
- $compiler->parent_compiler->tpl_function[$_name]['call_name'] = $compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName;
+ $compiler->parent_compiler->tpl_function[ $_name ][ 'call_name' ] = $_funcName;
$output = "tpl_vars;\n";
$output .= $_paramsCode;
- $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
- $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
+ $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\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 = " \$value){\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 = "\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,
+ new Smarty_Internal_ParseTree_Tag($compiler->parser,
+ $output));
$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) {
+ 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;
+ $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin ][ $type ] =
+ $data;
}
}
}
// restore old buffer
- $compiler->parser->current_buffer = $saved_data[1];
+ $compiler->parser->current_buffer = $saved_data[ 1 ];
// restore old status
- $compiler->template->compiled->has_nocache_code = $saved_data[2];
- $compiler->template->caching = $saved_data[3];
+ $compiler->template->compiled->has_nocache_code = $saved_data[ 2 ];
+ $compiler->template->caching = $saved_data[ 3 ];
return true;
}
/**
+ * Remove nocache code
+ *
* @param $match
*
- * @return mixed
+ * @return string
*/
function removeNocache($match)
{
- $code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->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);
return $code;
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_if.php b/include/smarty/libs/sysplugins/smarty_internal_compile_if.php
index 541e21816..14db55d4f 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_if.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_if.php
@@ -38,39 +38,30 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("missing if condition", null, true);
}
- if (is_array($parameter['if condition'])) {
+ if (is_array($parameter[ 'if condition' ])) {
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
+ } else {
+ $var = $parameter[ 'if condition' ][ 'var' ];
+ }
if ($compiler->nocache) {
- $_nocache = ',true';
// create nocache var to make it know for further compiling
- if (is_array($parameter['if condition']['var'])) {
- $var = trim($parameter['if condition']['var']['var'], "'");
- } else {
- $var = trim($parameter['if condition']['var'], "'");
- }
- if (isset($compiler->template->tpl_vars[$var])) {
- $compiler->template->tpl_vars[$var]->nocache = true;
- } else {
- $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
- }
- } else {
- $_nocache = '';
+ $compiler->setNocacheInVariable($var);
}
- if (is_array($parameter['if condition']['var'])) {
- $_output = "tpl_vars[" . $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'] . ") {?>";
+ $prefixVar = $compiler->getNewPrefixVariable();
+ $_output = "\n";
+ $assignAttr = array();
+ $assignAttr[][ 'value' ] = "{$prefixVar}";
+ $assignCompiler = new Smarty_Internal_Compile_Assign();
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
+ $_output .= $assignCompiler->compile($assignAttr, $compiler,
+ array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
} else {
- $_output = "tpl_vars[" . $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'] . ") {?>";
+ $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
+ $_output .= $assignCompiler->compile($assignAttr, $compiler, array());
}
-
+ $_output .= "";
return $_output;
} else {
return "";
@@ -133,86 +124,54 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$compiler->trigger_template_error("missing elseif condition", null, true);
}
- if (is_array($parameter['if condition'])) {
+ $assignCode = '';
+ $var = '';
+ if (is_array($parameter[ 'if condition' ])) {
$condition_by_assign = true;
- if ($compiler->nocache) {
- $_nocache = ',true';
- // create nocache var to make it know for further compiling
- if (is_array($parameter['if condition']['var'])) {
- $var = trim($parameter['if condition']['var']['var'], "'");
- } else {
- $var = trim($parameter['if condition']['var'], "'");
- }
- if (isset($compiler->template->tpl_vars[$var])) {
- $compiler->template->tpl_vars[$var]->nocache = true;
- } else {
- $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
- }
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
} else {
- $_nocache = '';
+ $var = $parameter[ 'if condition' ][ 'var' ];
+ }
+ if ($compiler->nocache) {
+ // create nocache var to make it know for further compiling
+ $compiler->setNocacheInVariable($var);
+ }
+ $prefixVar = $compiler->getNewPrefixVariable();
+ $assignCode = "\n";
+ $assignCompiler = new Smarty_Internal_Compile_Assign();
+ $assignAttr = array();
+ $assignAttr[][ 'value' ] = "{$prefixVar}";
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
+ $assignCode .= $assignCompiler->compile($assignAttr, $compiler,
+ array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
+ } else {
+ $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
+ $assignCode .= $assignCompiler->compile($assignAttr, $compiler, array());
}
} else {
$condition_by_assign = false;
}
- if (empty($compiler->prefix_code)) {
+ $prefixCode = $compiler->getPrefixCode();
+ if (empty($prefixCode)) {
if ($condition_by_assign) {
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
- if (is_array($parameter['if condition']['var'])) {
- $_output = "tpl_vars[" .
- $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 {
- $_output = "tpl_vars[" .
- $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;
+ $_output = $compiler->appendCode("", $assignCode);
+ return $compiler->appendCode($_output, "");
} else {
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
-
return "";
}
} else {
- $tmp = '';
- foreach ($compiler->prefix_code as $code) {
- $tmp = $compiler->appendCode($tmp, $code);
- }
- $compiler->prefix_code = array();
- $tmp = $compiler->appendCode("", $tmp);
+ $_output = $compiler->appendCode("", $prefixCode);
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) {
- if (is_array($parameter['if condition']['var'])) {
- $_output = $compiler->appendCode($tmp, "tpl_vars[" .
- $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 {
- $_output = $compiler->appendCode($tmp, "tpl_vars[" .
- $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;
+ $_output = $compiler->appendCode($_output, $assignCode);
+ return $compiler->appendCode($_output, "");
} else {
- return $compiler->appendCode($tmp, "");
+ return $compiler->appendCode($_output, "");
}
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_include.php b/include/smarty/libs/sysplugins/smarty_internal_compile_include.php
index 09fa11d6c..a81b0c740 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_include.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_include.php
@@ -43,7 +43,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
- public $option_flags = array('nocache', 'inline', 'caching', 'bubble_up');
+ public $option_flags = array('nocache', 'inline', 'caching');
/**
* Attribute definition: Overwrites base class.
@@ -58,8 +58,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*
* @var array
*/
- public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
- 'smarty' => true, 'tpl_root' => true);
+ public $valid_scopes = array('parent' => Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT,
+ 'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
+ 'smarty' => Smarty::SCOPE_SMARTY);
/**
* Compiles code for the {include} tag
@@ -73,16 +74,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
{
+ $uid = $t_hash = null;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- $hashResourceName = $fullResourceName = $source_resource = $_attr['file'];
+ $fullResourceName = $source_resource = $_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];
+ $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;
@@ -91,51 +93,32 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($type != 'string') {
$fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled;
- if (isset($compiled->includes[$fullResourceName])) {
- $compiled->includes[$fullResourceName] ++;
+ if (isset($compiled->includes[ $fullResourceName ])) {
+ $compiled->includes[ $fullResourceName ] ++;
$cache_tpl = true;
} else {
- $compiled->includes[$fullResourceName] = 1;
+ if ("{$compiler->template->source->type}:{$compiler->template->source->name}" ==
+ $fullResourceName
+ ) {
+ // recursive call of current template
+ $compiled->includes[ $fullResourceName ] = 2;
+ $cache_tpl = true;
+ } else {
+ $compiled->includes[ $fullResourceName ] = 1;
+ }
}
- $fullResourceName = '"' . $fullResourceName . '"';
+ $fullResourceName = $match[ 1 ] . $fullResourceName . $match[ 1 ];
}
}
- if (empty($match[5])) {
+ if (empty($match[ 5 ])) {
$variable_template = true;
}
} else {
$variable_template = true;
}
- if (isset($_attr['assign'])) {
- // output will be stored in a smarty variable instead of being displayed
- $_assign = $_attr['assign'];
- }
-
// scope setup
- $_scope = Smarty::SCOPE_LOCAL;
- if (isset($_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') {
- $_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;
- }
- if ($_attr['bubble_up'] === true) {
- $_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
- }
- }
- }
+ $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
// set flag to cache subtemplate object when called within loop or template name is variable.
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
@@ -146,10 +129,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// assume caching is off
$_caching = Smarty::CACHING_OFF;
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
-
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
// caching was on and {include} is not in nocache mode
@@ -158,30 +137,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
// flag if included template code should be merged into caller
- $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) &&
- !$compiler->template->source->handler->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) {
// variable template name ?
if ($variable_template) {
$merge_compiled_includes = false;
- if ($compiler->template->caching) {
- // must use individual cache file
- //$_attr['caching'] = 1;
- }
}
// variable 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
- ) {
- $merge_compiled_includes = false;
- if ($compiler->template->caching) {
- // must use individual cache file
- //$_attr['caching'] = 1;
- }
- }
+ if (isset($_attr[ 'compile_id' ]) && $compiler->isVariable($_attr[ 'compile_id' ])) {
+ $merge_compiled_includes = false;
}
}
@@ -191,28 +157,28 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* a call in nocache mode.
*
*/
- if ($_attr['nocache'] !== true && $_attr['caching']) {
- $_caching = $_new_caching = (int) $_attr['caching'];
+ if ($_attr[ 'nocache' ] !== true && $_attr[ 'caching' ]) {
+ $_caching = $_new_caching = (int) $_attr[ 'caching' ];
$call_nocache = true;
} else {
$_new_caching = Smarty::CACHING_LIFETIME_CURRENT;
}
- if (isset($_attr['cache_lifetime'])) {
- $_cache_lifetime = $_attr['cache_lifetime'];
+ if (isset($_attr[ 'cache_lifetime' ])) {
+ $_cache_lifetime = $_attr[ 'cache_lifetime' ];
$call_nocache = true;
$_caching = $_new_caching;
} else {
$_cache_lifetime = '$_smarty_tpl->cache_lifetime';
}
- if (isset($_attr['cache_id'])) {
- $_cache_id = $_attr['cache_id'];
+ if (isset($_attr[ 'cache_id' ])) {
+ $_cache_id = $_attr[ 'cache_id' ];
$call_nocache = true;
$_caching = $_new_caching;
} else {
$_cache_id = '$_smarty_tpl->cache_id';
}
- if (isset($_attr['compile_id'])) {
- $_compile_id = $_attr['compile_id'];
+ if (isset($_attr[ 'compile_id' ])) {
+ $_compile_id = $_attr[ 'compile_id' ];
} else {
$_compile_id = '$_smarty_tpl->compile_id';
}
@@ -221,55 +187,67 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if ($compiler->template->caching && $call_nocache) {
$merge_compiled_includes = false;
}
+ // assign attribute
+ if (isset($_attr[ 'assign' ])) {
+ // output will be stored in a smarty variable instead of being displayed
+ if ($_assign = $compiler->getId($_attr[ 'assign' ])) {
+ $_assign = "'{$_assign}'";
+ if ($compiler->tag_nocache || $compiler->nocache || $call_nocache) {
+ // create nocache var to make it know for further compiling
+ $compiler->setNocacheInVariable($_attr[ 'assign' ]);
+ }
+ } else {
+ $_assign = $_attr[ 'assign' ];
+ }
+ }
$has_compiled_template = false;
if ($merge_compiled_includes) {
- $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
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
- if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) {
- $has_compiled_template =
- $this->compileInlineTemplate($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);
+ $uid = $tpl->source->type . $tpl->source->uid;
+ if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) {
+ $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash);
} else {
$has_compiled_template = true;
}
+ unset($tpl);
}
// 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'], $_attr['bubble_up']);
+ unset($_attr[ 'file' ], $_attr[ 'assign' ], $_attr[ 'cache_id' ], $_attr[ 'compile_id' ], $_attr[ 'cache_lifetime' ], $_attr[ 'nocache' ], $_attr[ 'caching' ], $_attr[ 'scope' ], $_attr[ 'inline' ]);
// remaining attributes must be assigned as smarty variable
- $_vars_nc = '';
+ $_vars = 'array()';
if (!empty($_attr)) {
- if ($_scope == Smarty::SCOPE_LOCAL) {
- $_pairs = array();
- // create variables
- foreach ($_attr as $key => $value) {
- $_pairs[] = "'$key'=>$value";
- $_vars_nc .= "\$_smarty_tpl->tpl_vars['$key'] = new Smarty_Variable($value);\n";
- }
- $_vars = 'array(' . join(',', $_pairs) . ')';
- } else {
- $compiler->trigger_template_error('variable passing not allowed in parent/global scope', null, true);
+ $_pairs = array();
+ // create variables
+ foreach ($_attr as $key => $value) {
+ $_pairs[] = "'$key'=>$value";
}
- } else {
- $_vars = 'array()';
+ $_vars = 'array(' . join(',', $_pairs) . ')';
}
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
- $_compile_id != '$_smarty_tpl->compile_id';
+ $_compile_id != '$_smarty_tpl->compile_id';
if ($has_compiled_template && !$call_nocache) {
$_output = "makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
}
- if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) {
- //$compiler->suppressNocacheProcessing = false;
+ if (!empty($_attr) && $_caching == 9999 && $compiler->template->caching) {
+ $_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n";
+ $_vars_nc .= "\$_smarty_tpl->tpl_vars[\$ik] = new Smarty_Variable(\$iv);\n";
+ $_vars_nc .= "}\n";
$_output .= substr($compiler->processNocacheCode('\n", true), 6, - 3);
- //$compiler->suppressNocacheProcessing = true;
}
if (isset($_assign)) {
$_output .= "ob_start();\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";
+ $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func']}');\n";
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
@@ -292,7 +270,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
if (isset($_assign)) {
$_output .= "ob_start();\n";
}
- $_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n";
+ $_output .= "\$_smarty_tpl->_subTemplateRender({$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";
}
@@ -307,47 +285,47 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* Compile inline sub template
*
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
- * @param $fullResourceName
- * @param $_caching
- * @param $hashResourceName
- * @param $t_hash
- * @param $c_id
+ * @param \Smarty_Internal_Template $tpl
+ * @param string $t_hash
*
* @return bool
*/
- public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName,
- $_caching, $hashResourceName, $t_hash, $c_id)
+ public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
+ Smarty_Internal_Template $tpl, $t_hash)
{
- $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);
+ $uid = $tpl->source->type . $tpl->source->uid;
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;
+ $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $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'] =
+ $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $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'] =
+ $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] =
$tpl->compiled->nocache_hash;
+ if ($compiler->template->source->type == 'file') {
+ $sourceInfo = $compiler->template->source->filepath;
+ } else {
+ $basename = $compiler->template->source->handler->getBasename($compiler->template->source);
+ $sourceInfo = $compiler->template->source->type . ':' .
+ ($basename ? $basename : $compiler->template->source->name);
+ }
// get compiled code
$compiled_code = "source->type}:{$tpl->source->name}\" =============================*/\n";
+ $compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "\n";
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
$compiled_code .= "source->type}:{$tpl->source->name}\" =============================*/\n";
+ $compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
$compiled_code .= "?>";
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
@@ -357,7 +335,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$compiled_code);
$compiler->template->compiled->has_nocache_code = true;
}
- $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
+ $compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code;
return true;
} else {
return false;
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php b/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php
index e7e62997c..77586da8b 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php
@@ -64,7 +64,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$_smarty_tpl = $compiler->template;
$_filepath = false;
$_file = null;
- eval('$_file = @' . $_attr['file'] . ';');
+ eval('$_file = @' . $_attr[ 'file' ] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
$_filepath = $compiler->smarty->_realpath($_file, true);
} else {
@@ -75,7 +75,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
- $_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true);
+ $_path = $compiler->smarty->_realpath($_script_dir . $compiler->smarty->ds . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;
@@ -91,13 +91,13 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
}
- if (isset($_attr['assign'])) {
+ if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
- $_assign = $_attr['assign'];
+ $_assign = $_attr[ 'assign' ];
}
$_once = '_once';
- if (isset($_attr['once'])) {
- if ($_attr['once'] == 'false') {
+ if (isset($_attr[ 'once' ])) {
+ if ($_attr[ 'once' ] == 'false') {
$_once = '';
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
index 2ebde1661..02ef67c3a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
@@ -54,6 +54,9 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
+ //Does tag create output
+ $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
+
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
if (!$nocacheParam) {
// do not compile as nocache code
@@ -66,35 +69,35 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output = 'template->tpl_vars[$var])) {
- $compiler->template->tpl_vars[$var]->nocache = true;
+ $var = trim($_attr[ 'assign' ], "'");
+ if (isset($compiler->template->tpl_vars[ $var ])) {
+ $compiler->template->tpl_vars[ $var ]->nocache = true;
} else {
- $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
+ $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
}
}
- if (isset($_attr['script'])) {
+ if (isset($_attr[ 'script' ])) {
// script which must be included
$_function = "smarty_insert_{$_name}";
$_smarty_tpl = $compiler->template;
$_filepath = false;
- eval('$_script = @' . $_attr['script'] . ';');
+ eval('$_script = @' . $_attr[ 'script' ] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
$_filepath = $_script;
} else {
if (isset($compiler->smarty->security_policy)) {
$_dir = $compiler->smarty->security_policy->trusted_dir;
} else {
- $_dir = $compiler->smarty->trusted_dir;
+ $_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null;
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
- $_script_dir = rtrim($_script_dir, '/\\') . DS;
+ $_script_dir = rtrim($_script_dir, '/\\') . $compiler->smarty->ds;
if (file_exists($_script_dir . $_script)) {
$_filepath = $_script_dir . $_script;
break;
@@ -109,7 +112,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "require_once '{$_filepath}' ;";
require_once $_filepath;
if (!is_callable($_function)) {
- $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true);
+ $compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
+ null, true);
}
} else {
$_filepath = 'null';
@@ -118,12 +122,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) {
// try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
- $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true);
+ $compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null,
+ true);
}
}
}
// delete {insert} standard attributes
- unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']);
+ unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]);
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
@@ -138,7 +143,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>";
}
} else {
- $compiler->has_output = true;
if ($_smarty_tpl->caching && !$nocacheParam) {
$_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>";
} else {
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php b/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
index 8c6b701e1..7251dcd6c 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
+ if ($_attr[ 'nocache' ] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_make_nocache.php b/include/smarty/libs/sysplugins/smarty_internal_compile_make_nocache.php
new file mode 100644
index 000000000..720dd68b3
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_make_nocache.php
@@ -0,0 +1,64 @@
+getAttributes($compiler, $args);
+ if ($compiler->template->caching) {
+ $output = "smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n";
+ $compiler->has_code = true;
+ $compiler->suppressNocacheProcessing = true;
+ return $output;
+ } else {
+ return true;
+ }
+ }
+}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_block_plugin.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_block_plugin.php
index 9e2eea233..617564276 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_block_plugin.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_block_plugin.php
@@ -24,6 +24,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
*/
public $optional_attributes = array('_any');
+ /**
+ * nesting level
+ *
+ * @var int
+ */
+ public $nesting = 0;
+
/**
* Compiles code for the execution of block plugin
*
@@ -35,55 +42,81 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function = null)
{
- if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
+ if (!isset($tag[ 5 ]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
- unset($_attr['nocache']);
- // convert attributes into parameter array string
- $_paramsArray = array();
- foreach ($_attr as $_key => $_value) {
- if (is_int($_key)) {
- $_paramsArray[] = "$_key=>$_value";
- } else {
- $_paramsArray[] = "'$_key'=>$_value";
- }
- }
+ $this->nesting ++;
+ unset($_attr[ 'nocache' ]);
+ list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
$_params = 'array(' . implode(",", $_paramsArray) . ')';
- $this->openTag($compiler, $tag, array($_params, $compiler->nocache));
+ // compile code
+ $output = "nesting} = isset({$callback[0]}) ? {$callback[0]} : null;\n";
+ $callback = "\$_block_plugin{$this->nesting}{$callback[1]}";
+ }
+ if (isset($callable)) {
+ $output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n";
+ }
+ $output .= "\$_smarty_tpl->smarty->_cache['_tag_stack'][] = array('{$tag}', {$_params});\n";
+ $output .= "\$_block_repeat=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat);\nwhile (\$_block_repeat) {\nob_start();\n?>";
+ $this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
// maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
- // compile code
- $output = "smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else {
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
// closing tag of block plugin, restore nocache
- list($_params, $compiler->nocache) = $this->closeTag($compiler, substr($tag, 0, - 5));
- // This tag does create output
- $compiler->has_output = true;
+ list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, - 5));
+ //Does tag create output
+ $compiler->has_output = isset($_params[ 'assign' ]) ? false : true;
// compile code
- if (!isset($parameter['modifier_list'])) {
- $mod_pre = $mod_post = '';
+ if (!isset($parameter[ 'modifier_list' ])) {
+ $mod_pre = $mod_post = $mod_content = '';
+ $mod_content2 = 'ob_get_clean()';
} else {
- $mod_pre = ' ob_start(); ';
- $mod_post = 'echo ' .
- $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
- 'value' => 'ob_get_clean()')) . ';';
+ $mod_content2 = "\$_block_content{$this->nesting}";
+ $mod_content = "\$_block_content{$this->nesting} = ob_get_clean();\n";
+ $mod_pre = "ob_start();\n";
+ $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
+ array('modifierlist' => $parameter[ 'modifier_list' ],
+ 'value' => 'ob_get_clean()')) . ";\n";
}
- $output = "smarty->_cache['tag_stack']);?>";
+ $output = "smarty->_cache['_tag_stack']);";
+ $output .= "?>";
}
-
return $output . "\n";
}
+
+ /**
+ * Setup callback and parameter array
+ *
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param array $_attr attributes
+ * @param string $tag
+ * @param string $function
+ *
+ * @return array
+ */
+ public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function)
+ {
+ $_paramsArray = array();
+ foreach ($_attr as $_key => $_value) {
+ if (is_int($_key)) {
+ $_paramsArray[] = "$_key=>$_value";
+ } else {
+ $_paramsArray[] = "'$_key'=>$_value";
+ }
+ }
+ return array($function, $_paramsArray, null);
+ }
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php
index 16f233359..bf569be3a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php
@@ -110,11 +110,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes)
{
if ($named) {
- $this->resultOffsets['named'] = $this->startOffset + 3;
+ $this->resultOffsets[ 'named' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$properties = $this->nameProperties;
} else {
- $this->resultOffsets['item'] = $this->startOffset + 3;
+ $this->resultOffsets[ 'item' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties;
}
@@ -140,8 +140,8 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
foreach ($this->resultOffsets as $key => $offset) {
foreach ($match as $m) {
- if (isset($m[$offset]) && !empty($m[$offset])) {
- $this->matchResults[$key][strtolower($m[$offset])] = true;
+ if (isset($m[ $offset ]) && !empty($m[ $offset ])) {
+ $this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true;
}
}
}
@@ -173,9 +173,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$_content = $nextCompiler->template->source->getContent();
if ($_content != '') {
// run pre filter if required
- if ((isset($nextCompiler->smarty->autoload_filters['pre']) ||
- isset($nextCompiler->smarty->registered_filters['pre']))) {
- $_content = $nextCompiler->smarty->ext->_filter_Handler->runFilter('pre', $_content, $nextCompiler->template);
+ if ((isset($nextCompiler->smarty->autoload_filters[ 'pre' ]) ||
+ isset($nextCompiler->smarty->registered_filters[ 'pre' ]))
+ ) {
+ $_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content,
+ $nextCompiler->template);
}
$this->matchProperty($_content);
}
@@ -190,7 +192,6 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
-
}
/**
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_function_plugin.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_function_plugin.php
index 0d0ab8138..26529bb68 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_function_plugin.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_function_plugin.php
@@ -35,25 +35,20 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
- * @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
- * @param array $parameter array with compilation parameter
- * @param string $tag name of function plugin
- * @param string $function PHP function name
+ * @param array $args array with attributes from parser
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param array $parameter array with compilation parameter
+ * @param string $tag name of function plugin
+ * @param string $function PHP function name
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{
- // This tag does create output
- $compiler->has_output = true;
-
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
- unset($_attr['nocache']);
+
+ unset($_attr[ 'nocache' ]);
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
@@ -65,8 +60,15 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
// compile code
- $output = "\n";
-
+ $output = "{$function}({$_params},\$_smarty_tpl)";
+ if (!empty($parameter[ 'modifierlist' ])) {
+ $output = $compiler->compileTag('private_modifier', array(),
+ array('modifierlist' => $parameter[ 'modifierlist' ],
+ 'value' => $output));
+ }
+ //Does tag create output
+ $compiler->has_output = true;
+ $output = "\n";
return $output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
index 9594d2ae7..2ee88db48 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
@@ -31,15 +31,15 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- $output = $parameter['value'];
+ $output = $parameter[ 'value' ];
// loop over list of modifiers
- foreach ($parameter['modifierlist'] as $single_modifier) {
- $modifier = $single_modifier[0];
- $single_modifier[0] = $output;
+ foreach ($parameter[ 'modifierlist' ] as $single_modifier) {
+ $modifier = $single_modifier[ 0 ];
+ $single_modifier[ 0 ] = $output;
$params = implode(',', $single_modifier);
// check if we know already the type of modifier
- if (isset($compiler->known_modifier_type[$modifier])) {
- $modifier_types = array($compiler->known_modifier_type[$modifier]);
+ if (isset($compiler->known_modifier_type[ $modifier ])) {
+ $modifier_types = array($compiler->known_modifier_type[ $modifier ]);
} else {
$modifier_types = array(1, 2, 3, 4, 5, 6);
}
@@ -47,27 +47,30 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
switch ($type) {
case 1:
// registered modifier
- if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
- $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
+ if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
+ $function =
+ $compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
- if (is_object($function[0])) {
+ if (is_object($function[ 0 ])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
- $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
+ $modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
} else {
- $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
+ $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 2:
// registered modifier compiler
- if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
- $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
- $compiler->known_modifier_type[$modifier] = $type;
+ if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) {
+ $output =
+ call_user_func($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ],
+ $single_modifier, $compiler->smarty);
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
@@ -81,7 +84,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
@@ -94,7 +97,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
) {
$output = "{$function}({$params})";
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
@@ -107,17 +110,17 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
) {
$output = "{$modifier}({$params})";
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
case 6:
// default plugin handler
- if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$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))
+ $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
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
@@ -125,27 +128,26 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
- if (is_object($function[0])) {
- $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
- $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
+ if (is_object($function[ 0 ])) {
+ $output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')';
} else {
- $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
+ $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
}
}
- 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'])
+ 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
- $compiler->known_modifier_type[$modifier] = 4;
+ $compiler->known_modifier_type[ $modifier ] = 4;
} else {
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
}
break 2;
}
}
}
- if (!isset($compiler->known_modifier_type[$modifier])) {
+ if (!isset($compiler->known_modifier_type[ $modifier ])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_block_function.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_block_function.php
index d2bc5d60c..5c7fb6265 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_block_function.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_block_function.php
@@ -14,78 +14,29 @@
* @package Smarty
* @subpackage Compiler
*/
-class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase
+class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_Compile_Private_Block_Plugin
{
/**
- * Attribute definition: Overwrites base class.
+ * Setup callback and parameter array
*
- * @var array
- * @see Smarty_Internal_CompileBase
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param array $_attr attributes
+ * @param string $tag
+ * @param string $method
+ *
+ * @return array
*/
- public $optional_attributes = array('_any');
-
- /**
- * Compiles code for the execution of block plugin
- *
- * @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
- * @param array $parameter array with compilation parameter
- * @param string $tag name of block object
- * @param string $method name of method to call
- *
- * @return string compiled code
- */
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
+ public function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $method)
{
- if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
- // opening tag of block plugin
- // check and get attributes
- $_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
- unset($_attr['nocache']);
- // convert attributes into parameter array string
- $_paramsArray = array();
- foreach ($_attr as $_key => $_value) {
- if (is_int($_key)) {
- $_paramsArray[] = "$_key=>$_value";
- } else {
- $_paramsArray[] = "'$_key'=>$_value";
- }
- }
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
-
- $this->openTag($compiler, $tag . '->' . $method, array($_params, $compiler->nocache));
- // maybe nocache because of nocache variables or nocache plugin
- $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
- // compile code
- $output =
- "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 {
- $base_tag = substr($tag, 0, - 5);
- // must endblock be nocache?
- if ($compiler->nocache) {
- $compiler->tag_nocache = true;
- }
- // closing tag of block plugin, restore nocache
- list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag . '->' . $method);
- // This tag does create output
- $compiler->has_output = true;
- // compile code
- if (!isset($parameter['modifier_list'])) {
- $mod_pre = $mod_post = '';
+ $_paramsArray = array();
+ foreach ($_attr as $_key => $_value) {
+ if (is_int($_key)) {
+ $_paramsArray[] = "$_key=>$_value";
} else {
- $mod_pre = ' ob_start(); ';
- $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
- array('modifierlist' => $parameter['modifier_list'],
- 'value' => 'ob_get_clean()')) . ';';
+ $_paramsArray[] = "'$_key'=>$_value";
}
- $output = "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";
+ $callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}");
+ return array($callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$method}')");
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_function.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_function.php
index e306e0f6d..7f78a421e 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_function.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_object_function.php
@@ -27,11 +27,11 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/**
* 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 \Smarty_Internal_TemplateCompilerBase $compiler compiler object
- * @param array $parameter array with compilation parameter
- * @param string $tag name of function
- * @param string $method name of method to call
+ * @param array $parameter array with compilation parameter
+ * @param string $tag name of function
+ * @param string $method name of method to call
*
* @return string compiled code
*/
@@ -39,19 +39,19 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
- unset($_attr['nocache']);
+ //Does tag create output
+ $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
+
+ unset($_attr[ 'nocache' ]);
$_assign = null;
- if (isset($_attr['assign'])) {
- $_assign = $_attr['assign'];
- unset($_attr['assign']);
+ if (isset($_attr[ 'assign' ])) {
+ $_assign = $_attr[ 'assign' ];
+ unset($_attr[ 'assign' ]);
}
// method or property ?
- if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) {
+ if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $method))) {
// convert attributes into parameter array string
- if ($compiler->smarty->registered_objects[$tag][2]) {
+ if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) {
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
@@ -61,24 +61,26 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
- $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
+ $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
} else {
$_params = implode(",", $_attr);
- $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
+ $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
}
} else {
// object property
- $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
+ $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
}
+ if (!empty($parameter[ 'modifierlist' ])) {
+ $output = $compiler->compileTag('private_modifier', array(),
+ array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
+ }
+ //Does tag create output
+ $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
if (empty($_assign)) {
- // This tag does create output
- $compiler->has_output = true;
- $output = "\n";
+ return "\n";
} else {
- $output = "assign({$_assign},{$return});?>\n";
+ return "assign({$_assign},{$output});?>\n";
}
-
- return $output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php b/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php
index 3ca63a548..8bff8499f 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php
@@ -40,59 +40,65 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->has_code = false;
- if ($_attr['type'] == 'xml') {
+ if ($_attr[ 'type' ] == 'xml') {
$compiler->tag_nocache = true;
- $save = $compiler->template->compiled->has_nocache_code;
- $output = addcslashes($_attr['code'], "'\\");
- $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("", $compiler, true)));
- $compiler->template->compiled->has_nocache_code = $save;
+ $output = addcslashes($_attr[ 'code' ], "'\\");
+ $compiler->parser->current_buffer->append_subtree($compiler->parser,
+ new Smarty_Internal_ParseTree_Tag($compiler->parser,
+ $compiler->processNocacheCode("",
+ true)));
return '';
}
- if ($_attr['type'] != 'tag') {
+ if ($_attr[ 'type' ] != 'tag') {
if ($compiler->php_handling == Smarty::PHP_REMOVE) {
return '';
} elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
- $output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(