diff --git a/include/smarty/.gitattributes b/include/smarty/.gitattributes
deleted file mode 100644
index 412eeda78..000000000
--- a/include/smarty/.gitattributes
+++ /dev/null
@@ -1,22 +0,0 @@
-# Auto detect text files and perform LF normalization
-* text=auto
-
-# Custom for Visual Studio
-*.cs diff=csharp
-*.sln merge=union
-*.csproj merge=union
-*.vbproj merge=union
-*.fsproj merge=union
-*.dbproj merge=union
-
-# Standard to msysgit
-*.doc diff=astextplain
-*.DOC diff=astextplain
-*.docx diff=astextplain
-*.DOCX diff=astextplain
-*.dot diff=astextplain
-*.DOT diff=astextplain
-*.pdf diff=astextplain
-*.PDF diff=astextplain
-*.rtf diff=astextplain
-*.RTF diff=astextplain
diff --git a/include/smarty/.gitignore b/include/smarty/.gitignore
deleted file mode 100644
index 0ff15aa49..000000000
--- a/include/smarty/.gitignore
+++ /dev/null
@@ -1,221 +0,0 @@
-#################
-## Eclipse
-#################
-
-*.pydevproject
-.project
-.metadata
-bin/
-tmp/
-*.tmp
-*.bak
-*.swp
-*~.nib
-local.properties
-.classpath
-.settings/
-.loadpath
-
-# External tool builders
-.externalToolBuilders/
-
-# Locally stored "Eclipse launch configurations"
-*.launch
-
-# CDT-specific
-.cproject
-
-# PDT-specific
-.buildpath
-
-
-#################
-## Visual Studio
-#################
-
-## Ignore Visual Studio temporary files, build results, and
-## files generated by popular Visual Studio add-ons.
-
-# User-specific files
-*.suo
-*.user
-*.sln.docstates
-
-# Build results
-
-[Dd]ebug/
-[Rr]elease/
-x64/
-build/
-[Bb]in/
-[Oo]bj/
-
-# MSTest test Results
-[Tt]est[Rr]esult*/
-[Bb]uild[Ll]og.*
-
-*_i.c
-*_p.c
-*.ilk
-*.meta
-*.obj
-*.pch
-*.pdb
-*.pgc
-*.pgd
-*.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.tmp_proj
-*.log
-*.vspscc
-*.vssscc
-.builds
-*.pidb
-*.log
-*.scc
-
-# Visual C++ cache files
-ipch/
-*.aps
-*.ncb
-*.opensdf
-*.sdf
-*.cachefile
-
-# Visual Studio profiler
-*.psess
-*.vsp
-*.vspx
-
-# Guidance Automation Toolkit
-*.gpState
-
-# ReSharper is a .NET coding add-in
-_ReSharper*/
-*.[Rr]e[Ss]harper
-
-# TeamCity is a build add-in
-_TeamCity*
-
-# DotCover is a Code Coverage Tool
-*.dotCover
-
-# NCrunch
-*.ncrunch*
-.*crunch*.local.xml
-
-# Installshield output folder
-[Ee]xpress/
-
-# DocProject is a documentation generator add-in
-DocProject/buildhelp/
-DocProject/Help/*.HxT
-DocProject/Help/*.HxC
-DocProject/Help/*.hhc
-DocProject/Help/*.hhk
-DocProject/Help/*.hhp
-DocProject/Help/Html2
-DocProject/Help/html
-
-# Click-Once directory
-publish/
-
-# Publish Web Output
-*.Publish.xml
-*.pubxml
-
-# NuGet Packages Directory
-## TODO: If you have NuGet Package Restore enabled, uncomment the next line
-#packages/
-
-# Windows Azure Build Output
-csx
-*.build.csdef
-
-# Windows Store app package directory
-AppPackages/
-
-# Others
-sql/
-*.Cache
-ClientBin/
-[Ss]tyle[Cc]op.*
-~$*
-*~
-*.dbmdl
-*.[Pp]ublish.xml
-*.pfx
-*.publishsettings
-
-# RIA/Silverlight projects
-Generated_Code/
-
-# Backup & report files from converting an old project file to a newer
-# Visual Studio version. Backup files are not needed, because we have git ;-)
-_UpgradeReport_Files/
-Backup*/
-UpgradeLog*.XML
-UpgradeLog*.htm
-
-# SQL Server files
-App_Data/*.mdf
-App_Data/*.ldf
-
-#############
-## Windows detritus
-#############
-
-# Windows image file caches
-Thumbs.db
-ehthumbs.db
-
-# Folder config file
-Desktop.ini
-
-# Recycle Bin used on file shares
-$RECYCLE.BIN/
-
-# Mac crap
-.DS_Store
-
-
-#############
-## Python
-#############
-
-*.py[co]
-
-# Packages
-*.egg
-*.egg-info
-dist/
-build/
-eggs/
-parts/
-var/
-sdist/
-develop-eggs/
-.installed.cfg
-
-# Installer logs
-pip-log.txt
-
-# Unit test / coverage reports
-.coverage
-.tox
-
-#Translations
-*.mo
-
-#Mr Developer
-.mr.developer.cfg
-
-.idea/
-
-# Smarty
-lexer/*.php
-lexer/*.out
diff --git a/include/smarty/.travis.yml b/include/smarty/.travis.yml
deleted file mode 100644
index fbf081bac..000000000
--- a/include/smarty/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-language: php
-
-php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
- - 7.0
- - hhvm
-
-matrix:
- allow_failures:
- - php: hhvm
-
-before_script:
- - travis_retry composer self-update
- - travis_retry composer --prefer-source --dev install
-
-install:
- - git clone --depth=50 --branch=master git://github.com/smarty-php/smarty-phpunit.git
-
-script:
- - cd smarty-phpunit
- - phpunit ./
-
diff --git a/include/smarty/change_log.txt b/include/smarty/CHANGELOG.md
similarity index 75%
rename from include/smarty/change_log.txt
rename to include/smarty/CHANGELOG.md
index dadc5d17d..e3bb93a4f 100644
--- a/include/smarty/change_log.txt
+++ b/include/smarty/CHANGELOG.md
@@ -1,31 +1,633 @@
- ===== 3.1.29 ===== (21.12.2015)
+# Changelog
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+## [Unreleased]
+
+## [3.1.39] - 2021-02-17
+
+### Security
+- Prevent access to `$smarty.template_object` in sandbox mode
+- Fixed code injection vulnerability by using illegal function names in `{function name='blah'}{/function}`
+
+## [3.1.38] - 2021-01-08
+
+### Fixed
+- Smarty::SMARTY_VERSION wasn't updated https://github.com/smarty-php/smarty/issues/628
+
+## [3.1.37] - 2021-01-07
+
+### Changed
+- Changed error handlers and handling of undefined constants for php8-compatibility (set $errcontext argument optional) https://github.com/smarty-php/smarty/issues/605
+- Changed expected error levels in unit tests for php8-compatibility
+- Travis unit tests now run for all php versions >= 5.3, including php8
+- Travis runs on Xenial where possible
+
+### Fixed
+- PHP5.3 compatibility fixes
+- Brought lexer source functionally up-to-date with compiled version
+
+## [3.1.36] - 2020-04-14
+
+### Fixed
+ - Smarty::SMARTY_VERSION wasn't updated in v3.1.35 https://github.com/smarty-php/smarty/issues/584
+
+## [3.1.35] - 2020-04-14
+ - remove whitespaces after comments https://github.com/smarty-php/smarty/issues/447
+ - fix foreachelse on arrayiterators https://github.com/smarty-php/smarty/issues/506
+ - fix files contained in git export archive for package maintainers https://github.com/smarty-php/smarty/issues/325
+ - throw SmartyException when setting caching attributes for cacheable plugin https://github.com/smarty-php/smarty/issues/457
+ - fix errors that occured where isset was replaced with null check such as https://github.com/smarty-php/smarty/issues/453
+ - unit tests are now in the repository
+
+## 3.1.34 release - 05.11.2019
+13.01.2020
+ - fix typo in exception message (JercSi)
+ - fix typehint warning with callable (bets4breakfast)
+ - add travis badge and compatability info to readme (matks)
+ - fix stdClass cast when compiling foreach (carpii)
+ - fix wrong set/get methods for memcached (IT-Experte)
+ - fix pborm assigning value to object variables in smarty_internal_compile_assign (Hunman)
+ - exclude error_reporting.ini from git export (glensc)
+
+## 3.1.34-dev-6 -
+30.10.2018
+ - bugfix a nested subblock in an inheritance child template was not replace by
+ outer level block with same name in same child template https://github.com/smarty-php/smarty/issues/500
+
+29.10.2018
+ - bugfix Smarty::$php_handling == PHP_PASSTHRU (default) did eat the "\n" (newline) character if it did directly followed
+ a PHP tag like "?>" or other https://github.com/smarty-php/smarty/issues/501
+
+14.10.2018
+ - bugfix autoloader exit shortcut https://github.com/smarty-php/smarty/issues/467
+
+11.10.2018
+ - bugfix {insert} not works when caching is enabled and included template is present
+ https://github.com/smarty-php/smarty/issues/496
+ - bugfix in date-format modifier; NULL at date string or default_date did not produce correct output
+ https://github.com/smarty-php/smarty/pull/458
+
+09.10.2018
+ - bugfix fix of 26.8.2017 https://github.com/smarty-php/smarty/issues/327
+ modifier is applied to sum expression https://github.com/smarty-php/smarty/issues/491
+ - bugfix indexed arrays could not be defined "array(...)""
+
+18.09.2018
+ - bugfix large plain text template sections without a Smarty tag > 700kB could
+ could fail in version 3.1.32 and 3.1.33 because PHP preg_match() restrictions
+ https://github.com/smarty-php/smarty/issues/488
+
+## 3.1.33 release - 12.09.2018
+## 3.1.33-dev-12 -
+03.09.2018
+ - bugfix {foreach} using new style property access like {$item@property} on
+ Smarty 2 style named foreach loop could produce errors https://github.com/smarty-php/smarty/issues/484
+
+31.08.2018
+ - bugfix some custom left and right delimiters like '{^' '^}' did not work
+ https://github.com/smarty-php/smarty/issues/450 https://github.com/smarty-php/smarty/pull/482
+
+ - reformating for PSR-2 coding standards https://github.com/smarty-php/smarty/pull/483
+
+ - bugfix on Windows absolute filepathes did fail if the drive letter was followed by a linux DIRECTORY_SEPARATOR
+ like C:/ at Smarty > 3.1.33-dev-5 https://github.com/smarty-php/smarty/issues/451
+
+ - PSR-2 code style fixes for config and template file Lexer/Parser generated with
+ the Smarty Lexer/Parser generator from https://github.com/smarty-php/smarty-lexer
+ https://github.com/smarty-php/smarty/pull/483
+
+26.08.2018
+ - bugfix/enhancement {capture} allow variable as capture block name in Smarty special variable
+ like $smarty.capture.$foo https://github.com/smarty-php/smarty/issues/478 https://github.com/smarty-php/smarty/pull/481
+
+## 3.1.33-dev-6 -
+19.08.2018
+ - fix PSR-2 coding standards and PHPDoc blocks https://github.com/smarty-php/smarty/pull/452
+ https://github.com/smarty-php/smarty/pull/475
+ https://github.com/smarty-php/smarty/pull/473
+ - bugfix PHP5.2 compatibility https://github.com/smarty-php/smarty/pull/472
+
+## 3.1.33-dev-4 -
+17.05.2018
+ - bugfix strip-block produces different output in Smarty v3.1.32 https://github.com/smarty-php/smarty/issues/436
+ - bugfix Smarty::compileAllTemplates ignores `$extension` parameter https://github.com/smarty-php/smarty/issues/437
+ https://github.com/smarty-php/smarty/pull/438
+ - improvement do not compute total property in {foreach} if not needed https://github.com/smarty-php/smarty/issues/443
+ - bugfix plugins may not be loaded when setMergeCompiledIncludes is true https://github.com/smarty-php/smarty/issues/435
+
+26.04.2018
+ - bugfix regarding Security Vulnerability did not solve the problem under Linux.
+ Security issue CVE-2018-16831
+
+## 3.1.32 - (24.04.2018)
+24.04.2018
+ - bugfix possible Security Vulnerability in Smarty_Security class.
+
+26.03.2018
+ - bugfix plugins may not be loaded if {function} or {block} tags are executed in nocache mode
+ https://github.com/smarty-php/smarty/issues/371
+
+26.03.2018
+ - new feature {parent} = {$smarty.block.parent} {child} = {$smarty.block.child}
+
+23.03.2018
+ - bugfix preg_replace could fail on large content resulting in a blank page https://github.com/smarty-php/smarty/issues/417
+
+21.03.2018
+ - bugfix {$smarty.section...} used outside {section}{/section} showed incorrect values if {section}{/section} was called inside
+ another loop https://github.com/smarty-php/smarty/issues/422
+ - bugfix short form of {section} attributes did not work https://github.com/smarty-php/smarty/issues/428
+
+17.03.2018
+ - improvement Smarty::compileAllTemplates() exit with a non-zero status code if max errors is reached https://github.com/smarty-php/smarty/pull/402
+
+16.03.2018
+ - bugfix extends resource did not work with user defined left/right delimiter https://github.com/smarty-php/smarty/issues/419
+
+22.11.2017
+ - bugfix {break} and {continue} could fail if {foreach}{/foreach} did contain other
+ looping tags like {for}, {section} and {while} https://github.com/smarty-php/smarty/issues/323
+
+20.11.2017
+ - bugfix rework of newline spacing between tag code and template text.
+ now again identical with Smarty2 (forum topic 26878)
+ - replacement of " by '
+
+05.11.2017
+ - lexer/parser optimization
+ - code cleanup and optimizations
+ - bugfix {$smarty.section.name.loop} used together with {$smarty.section.name.total} could produce
+ wrong results (forum topic 27041)
+
+26.10.2017
+ - bugfix Smarty version was not filled in header comment of compiled and cached files
+ - optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR
+ - deprecate functions Smarty::muteExpectedErrors() and Smarty::unmuteExpectedErrors()
+ as Smarty does no longer use error suppression like @filemtime().
+ for backward compatibility code is moved from Smarty class to an external class and still can be
+ called.
+ - correction of PHPDoc blocks
+ - minor code cleanup
+
+21.10.2017
+ - bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
+ https://github.com/smarty-php/smarty/issues/394
+
+18.10.2017
+ - bugfix fix implementation of unclosed block tag in double quoted string of 12.10.2017
+ https://github.com/smarty-php/smarty/issues/396 https://github.com/smarty-php/smarty/issues/397
+ https://github.com/smarty-php/smarty/issues/391 https://github.com/smarty-php/smarty/issues/392
+
+12.10.2017
+ - bugfix $smarty.block.child and $smarty.block.parent could not be used like any
+ $smarty special variable https://github.com/smarty-php/smarty/issues/393
+ - unclosed block tag in double quoted string must throw compiler exception.
+ https://github.com/smarty-php/smarty/issues/391 https://github.com/smarty-php/smarty/issues/392
+
+07.10.2017
+ - bugfix modification of 9.8.2017 did fail on some recursive
+ tag nesting. https://github.com/smarty-php/smarty/issues/389
+
+26.8.2017
+ - bugfix chained modifier failed when last modifier parameter is a signed value
+ https://github.com/smarty-php/smarty/issues/327
+ - bugfix templates filepath with multibyte characters did not work
+ https://github.com/smarty-php/smarty/issues/385
+ - bugfix {make_nocache} did display code if the template did not contain other nocache code
+ https://github.com/smarty-php/smarty/issues/369
+
+09.8.2017
+ - improvement repeated delimiter like {{ and }} will be treated as literal
+ https://groups.google.com/forum/#!topic/smarty-developers/h9r82Bx4KZw
+
+05.8.2017
+ - bugfix wordwrap modifier could fail if used in nocache code.
+ converted plugin file shared.mb_wordwrap.php into modifier.mb_wordwrap.php
+ - cleanup of _getSmartyObj()
+
+31.7.2017
+ - Call clearstatcache() after mkdir() failure https://github.com/smarty-php/smarty/pull/379
+
+30.7.2017
+ - rewrite mkdir() bugfix to retry automatically see https://github.com/smarty-php/smarty/pull/377
+ https://github.com/smarty-php/smarty/pull/379
+
+21.7.2017
+ - security possible PHP code injection on custom resources at display() or fetch()
+ calls if the resource does not sanitize the template name
+ - bugfix fix 'mkdir(): File exists' error on create directory from parallel
+ processes https://github.com/smarty-php/smarty/pull/377
+ - bugfix solve preg_match() hhvm parameter problem https://github.com/smarty-php/smarty/pull/372
+
+27.5.2017
+ - bugfix change compiled code for registered function and modifiers to called as callable to allow closures
+ https://github.com/smarty-php/smarty/pull/368, https://github.com/smarty-php/smarty/issues/273
+ - bugfix https://github.com/smarty-php/smarty/pull/368 did break the default plugin handler
+ - improvement replace phpversion() by PHP_VERSION constant.
+ https://github.com/smarty-php/smarty/pull/363
+
+21.5.2017
+ - performance store flag for already required shared plugin functions in static variable or
+ Smarty's $_cache to improve performance when plugins are often called
+ https://github.com/smarty-php/smarty/commit/51e0d5cd405d764a4ea257d1bac1fb1205f74528#commitcomment-22280086
+ - bugfix remove special treatment of classes implementing ArrayAccess in {foreach}
+ https://github.com/smarty-php/smarty/issues/332
+ - bugfix remove deleted files by clear_cache() and clear_compiled_template() from
+ ACP cache if present, add some is_file() checks to avoid possible warnings on filemtime()
+ caused by above functions.
+ https://github.com/smarty-php/smarty/issues/341
+ - bugfix version 3.1.31 did fail under PHP 5.2
+ https://github.com/smarty-php/smarty/issues/365
+
+19.5.2017
+ - change properties $accessMap and $obsoleteProperties from private to protected
+ https://github.com/smarty-php/smarty/issues/351
+ - new feature The named capture buffers can now be accessed also as array
+ See NEWS_FEATURES.txt https://github.com/smarty-php/smarty/issues/366
+ - improvement check if ini_get() and ini_set() not disabled
+ https://github.com/smarty-php/smarty/pull/362
+
+24.4.2017
+ - fix spelling https://github.com/smarty-php/smarty/commit/e3eda8a5f5653d8abb960eb1bc47e3eca679b1b4#commitcomment-21803095
+
+17.4.2017
+ - correct generated code on empty() and isset() call, observe change PHP behaviour since PHP 5.5
+ https://github.com/smarty-php/smarty/issues/347
+
+14.4.2017
+ - merge pull requests https://github.com/smarty-php/smarty/pull/349, https://github.com/smarty-php/smarty/pull/322 and https://github.com/smarty-php/smarty/pull/337 to fix spelling and annotation
+
+13.4.2017
+ - bugfix array_merge() parameter should be checked https://github.com/smarty-php/smarty/issues/350
+
+## 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
- bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138
- bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139
- remove no longer used code
- 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
- bugfix using {block append/prepend} on same block in multiple levels of inheritance templates could fail (forum topic 25827)
- bugfix text content consisting of just a single '0' like in {if true}0{/if} was suppressed (forum topic 25834)
-
+
16.12.2015
- bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128
- bugfix direct access $smarty->template_dir = 'foo'; should call Smarty::setTemplateDir() https://github.com/smarty-php/smarty/issues/121
-
+
15.12.2015
- bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122
- bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828)
@@ -33,25 +635,25 @@
14.12.2015
- bugfix {$smarty.config.foo} broken in 3.1.28 https://github.com/smarty-php/smarty/issues/120
- bugfix multiple calls of {section} with same name droped E_NOTICE error https://github.com/smarty-php/smarty/issues/118
-
- ===== 3.1.28 ===== (13.12.2015)
+
+ - 3.1.28 - (13.12.2015)
13.12.2015
- bugfix {foreach} and {section} with uppercase characters in name attribute did not work (forum topic 25819)
- bugfix $smarty->debugging_ctrl = 'URL' did not work (forum topic 25811)
- bugfix Debug Console could display incorrect data when using subtemplates
-
+
09.12.2015
- bugfix Smarty did fail under PHP 7.0.0 with use_include_path = true;
-
+
09.12.2015
- bugfix {strip} should exclude some html tags from stripping, related to fix for https://github.com/smarty-php/smarty/issues/111
-
+
08.12.2015
- bugfix internal template function data got stored in wrong compiled file https://github.com/smarty-php/smarty/issues/114
-
+
05.12.2015
-bugfix {strip} should insert a single space https://github.com/smarty-php/smarty/issues/111
-
+
25.11.2015
-bugfix a left delimter like '[%' did fail on [%$var_[%$variable%]%] (forum topic 25798)
@@ -60,7 +662,7 @@
01.11.2015
- update config file processing
-
+
31.10.2015
- bugfix add missing $trusted_dir property to SmartyBC class (forum topic 25751)
@@ -84,7 +686,7 @@
18.09.2015
- bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92
-
+
17.09.2015
- bugfix {foreach} first attribute was not correctly reset since commit 05a8fa2 of 02.08.2015 https://github.com/smarty-php/smarty/issues/90
@@ -98,7 +700,7 @@
- move code of {call} processing back into Smarty_Internal_Template class
- improvement invalidate OPCACHE for cleared compiled and cached template files (forum topic 25557)
- bugfix unintended multiple debug windows (forum topic 25699)
-
+
30.08.2015
- size optimization move some runtime functions into extension
- optimize inline template processing
@@ -213,18 +815,18 @@
19.06.2015
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
- ===== 3.1.27===== (18.06.2015)
+ - 3.1.27- (18.06.2015)
18.06.2015
- bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
- ===== 3.1.26===== (18.06.2015)
+ - 3.1.26- (18.06.2015)
18.06.2015
- bugfix file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
17.06.2015
- bugfix calling a plugin with nocache option but no other attributes like {foo nocache} caused call to undefined function https://github.com/smarty-php/smarty/issues/55
- ===== 3.1.25===== (15.06.2015)
+ - 3.1.25- (15.06.2015)
15.06.2015
- optimization of smarty_cachereource_keyvaluestore.php code
@@ -247,22 +849,22 @@
01.06.2015
- bugfix including template variables broken since 3.1.22 https://github.com/smarty-php/smarty/issues/47
-
+
27.05.2015
- bugfix {include} with variable file name must not create by default individual cache file (since 3.1.22) https://github.com/smarty-php/smarty/issues/43
-
+
24.05.2015
- bugfix if condition string 'neq' broken due to a typo https://github.com/smarty-php/smarty/issues/42
- ===== 3.1.24===== (23.05.2015)
+ - 3.1.24- (23.05.2015)
23.05.2015
- improvement on php_handling to allow very large PHP sections, better error handling
- improvement allow extreme large comment sections (forum 25538)
-
+
21.05.2015
- bugfix broken PHP 5.2 compatibility when compiling 1 did compile into wrong code https://github.com/smarty-php/smarty/issues/41
-
+
19.05.2015
- bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39
- bugfix output filter trimwhitespace could run into the pcre.backtrack_limit on large output (code.google issue 220)
@@ -270,14 +872,14 @@
18.05.2015
- improvement introduce shortcuts in lexer/parser rules for most frequent terms for higher
- compilation speed
+ compilation speed
16.05.2015
- bugfix {php}{/php} did work just for single lines https://github.com/smarty-php/smarty/issues/33
- improvement remove not needed ?> handling from parser to new compiler module
05.05.2015
- bugfix code could be messed up when {tags} are used in multiple attributes https://github.com/smarty-php/smarty/issues/23
-
+
04.05.2015
- bugfix Smarty_Resource::parseResourceName incompatible with Google AppEngine (https://github.com/smarty-php/smarty/issues/22)
- improvement use is_file() checks to avoid errors suppressed by @ which could still cause problems (https://github.com/smarty-php/smarty/issues/24)
@@ -327,13 +929,13 @@
28.04.2015
- bugfix plugins of merged subtemplates not loaded in 3.1.22-dev (forum topic 25508)
-
- 23.04.2015
+
+ 23.04.2015
- bugfix a nocache template variable used as parameter at {insert} was by mistake cached
-
+
20.04.2015
- bugfix at a template function containing nocache code a parmeter could overwrite a template variable of same name
-
+
27.03.2015
- bugfix Smarty_Security->allow_constants=false; did also disable true, false and null (change of 16.03.2015)
- improvement added a whitelist for trusted constants to security Smarty_Security::$trusted_constants (forum topic 25471)
@@ -341,39 +943,39 @@
20.03.2015
- bugfix make sure that function properties get saved only in compiled files containing the fuction definition {forum topic 25452}
- bugfix correct update of global variable values on exit of template functions. (reported under Smarty Developers)
-
+
16.03.2015
- bugfix problems with {function}{/function} and {call} tags in different subtemplate cache files {forum topic 25452}
- bugfix Smarty_Security->allow_constants=false; did not disallow direct usage of defined constants like {SMARTY_DIR} {forum topic 25457}
- bugfix {block}{/block} tags did not work inside double quoted strings https://github.com/smarty-php/smarty/issues/18
-
-
+
+
15.03.2015
- bugfix $smarty->compile_check must be restored before rendering of a just updated cache file {forum 25452}
-
+
14.03.2015
- bugfix {nocache} {/nocache} tags corrupted code when used within a nocache section caused by a nocache template variable.
-
+
- bugfix template functions defined with {function} in an included subtemplate could not be called in nocache
mode with {call... nocache} if the subtemplate had it's own cache file {forum 25452}
-
+
10.03.2015
- bugfix {include ... nocache} whith variable file or compile_id attribute was not executed in nocache mode.
-
+
12.02.2015
- bugfix multiple Smarty::fetch() of same template when $smarty->merge_compiled_includes = true; could cause function already defined error
-
+
11.02.2015
- bugfix recursive {includes} did create E_NOTICE message when $smarty->merge_compiled_includes = true; (github issue #16)
-
+
22.01.2015
- new feature security can now control access to static methods and properties
see also NEW_FEATURES.txt
21.01.2015
- bugfix clearCompiledTemplates(), clearAll() and clear() could try to delete whole drive at wrong path permissions because realpath() fail (forum 25397)
- - bugfix 'self::' and 'parent::' was interpreted in template syntax as static class
-
+ - bugfix 'self::' and 'parent::' was interpreted in template syntax as static class
+
04.01.2015
- push last weeks changes to github
@@ -384,10 +986,10 @@
- optimization restructure config file processing
31.12.2014
- - bugfix use function_exists('mb_get_info') for setting Smarty::$_MBSTRING.
+ - bugfix use function_exists('mb_get_info') for setting Smarty::$_MBSTRING.
Function mb_split could be overloaded depending on php.ini mbstring.func_overload
-
-
+
+
29.12.2014
- new feature security can now limit the template nesting level by property $max_template_nesting
see also NEW_FEATURES.txt (forum 25370)
@@ -401,14 +1003,14 @@
13.12.2014
- improvement optimization of lexer and parser resulting in a up to 30% higher compiling speed
-
+
11.12.2014
- bugfix resolve parser ambiguity between constant print tag {CONST} and other smarty tags after change of 09.12.2014
-
+
09.12.2014
- bugfix variables $null, $true and $false did not work after the change of 12.11.2014 (forum 25342)
- bugfix call of template function by a variable name did not work after latest changes (forum 25342)
-
+
23.11.2014
- bugfix a plugin with attached modifier could fail if the tag was immediately followed by another Smarty tag (since 3.1.21) (forum 25326)
@@ -426,12 +1028,12 @@
04.11.2014
- new feature $smarty->debugging = true; => overwrite existing Debug Console window (old behaviour)
$smarty->debugging = 2; => individual Debug Console window by template name
-
+
03.11.2014
- bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301)
- bugfix Modifier debug_print_var did not limit recursion or prevent recursive object display at Debug Console
(ATTENTION: parameter order has changed to be able to specify maximum recursion)
- - bugfix Debug consol did not include subtemplate information with $smarty->merge_compiled_includes = true
+ - bugfix Debug consol did not include subtemplate information with $smarty->merge_compiled_includes = true
- improvement The template variables are no longer displayed as objects on the Debug Console
- improvement $smarty->createData($parent = null, $name = null) new optional name parameter for display at Debug Console
- addition of some hooks for future extension of Debug Console
@@ -448,8 +1050,8 @@
26.10.2014
- bugfix E_NOTICE message was created during compilation when ASP tags '<%' or '%>' are in template source text
- bugfix merge_compiled_includes option failed when caching enables and same subtemplate was included cached and not cached
-
- ===== 3.1.21 ===== (18.10.2014)
+
+ - 3.1.21 - (18.10.2014)
18.10.2014
- composer moved to github
@@ -472,157 +1074,157 @@
- bugfix change of 08.10.2014 could create E_NOTICE meassage when using "" with $php_handling PHP_PASSTHRU was executed in {nocache} sections
- ===== 3.1.20 ===== (09.10.2014)
+ - 3.1.20 - (09.10.2014)
08.10.2014
- bugfix security mode of "';
- } elseif ($encode == 'javascript_charcode') {
+ } elseif ($encode === 'javascript_charcode') {
$string = '' . $text . '';
-
- for ($x = 0, $y = strlen($string); $x < $y; $x ++) {
- $ord[] = ord($string[$x]);
+ for ($x = 0, $y = strlen($string); $x < $y; $x++) {
+ $ord[] = ord($string[ $x ]);
}
-
- $_ret = "\n";
-
+ $_ret = "\n";
return $_ret;
- } elseif ($encode == 'hex') {
+ } 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]);
+ for ($x = 0, $_length = strlen($address); $x < $_length; $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]) . ';';
+ for ($x = 0, $_length = strlen($text); $x < $_length; $x++) {
+ $text_encode .= '' . bin2hex($text[ $x ]) . ';';
}
-
$mailto = "mailto:";
-
return '' . $text_encode . '';
} else {
// no encoding
diff --git a/include/smarty/libs/plugins/function.math.php b/include/smarty/libs/plugins/function.math.php
index aba76e825..7348d9649 100644
--- a/include/smarty/libs/plugins/function.math.php
+++ b/include/smarty/libs/plugins/function.math.php
@@ -6,16 +6,15 @@
* @package Smarty
* @subpackage PluginsFunction
*/
-
/**
* Smarty {math} function plugin
- * Type: function
- * Name: math
+ * Type: function
+ * Name: math
* Purpose: handle math computations in template
*
- * @link http://www.smarty.net/manual/en/language.function.math.php {math}
+ * @link http://www.smarty.net/manual/en/language.function.math.php {math}
* (Smarty online manual)
- * @author Monte Ohrt
+ * @author Monte Ohrt
*
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
@@ -24,68 +23,90 @@
*/
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, ")")) {
+ if (substr_count($equation, '(') !== substr_count($equation, ')')) {
trigger_error("math: unbalanced parenthesis", 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][a-zA-Z0-9_]*)!", $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", E_USER_WARNING);
-
- return;
- }
+ // disallow backticks
+ if (strpos($equation, '`') !== false) {
+ trigger_error("math: backtick character not allowed in equation", 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") {
+ 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);
-
+ 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);
-
+ 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;
+ }
+ }
+ foreach ($params as $key => $val) {
+ if ($key !== 'equation' && $key !== 'format' && $key !== 'assign') {
$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..c5fc400a6 100644
--- a/include/smarty/libs/plugins/modifier.capitalize.php
+++ b/include/smarty/libs/plugins/modifier.capitalize.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty capitalize modifier plugin
- * Type: modifier
- * Name: capitalize
+ * Type: modifier
+ * Name: capitalize
* Purpose: capitalize words in the string
* {@internal {$string|capitalize:true:true} is the fastest option for MBString enabled systems }}
*
@@ -29,39 +28,75 @@ 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;
}
-
// lowercase first
if ($lc_rest) {
$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;
}
-/*
+/**
*
* Bug: create_function() use exhausts memory when used in long loops
* Fix: use declared functions for callbacks instead of using create_function()
@@ -69,22 +104,42 @@ function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = fals
*
* @author Kyle Renfrow
*/
+/**
+ * @param $matches
+ *
+ * @return string
+ */
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);
}
+/**
+ * @param $matches
+ *
+ * @return string
+ */
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);
}
+/**
+ * @param $matches
+ *
+ * @return string
+ */
function smarty_mod_cap_ucfirst_cb($matches)
{
- return stripslashes($matches[1]) . ucfirst(stripslashes($matches[2]));
+ return stripslashes($matches[ 1 ]) . ucfirst(stripslashes($matches[ 2 ]));
}
+/**
+ * @param $matches
+ *
+ * @return string
+ */
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..c8e88c5c9 100644
--- a/include/smarty/libs/plugins/modifier.date_format.php
+++ b/include/smarty/libs/plugins/modifier.date_format.php
@@ -5,13 +5,12 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty date_format modifier plugin
- * Type: modifier
- * Name: date_format
- * Purpose: format datestamps via strftime
- * Input:
+ * Type: modifier
+ * Name: date_format
+ * Purpose: format datestamps via strftime
+ * Input:
* - string: input date string
* - format: strftime format for output
* - default_date: default date if $string is empty
@@ -35,18 +34,40 @@ 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 ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
+ static $is_loaded = false;
+ if (!$is_loaded) {
+ if (!is_callable('smarty_make_timestamp')) {
+ include_once SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php';
+ }
+ $is_loaded = true;
+ }
+ if (!empty($string) && $string !== '0000-00-00' && $string !== '0000-00-00 00:00:00') {
$timestamp = smarty_make_timestamp($string);
- } elseif ($default_date != '') {
+ } elseif (!empty($default_date)) {
$timestamp = smarty_make_timestamp($default_date);
} else {
return;
}
- if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
- if (DS == '\\') {
- $_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 ($formatter === 'strftime' || ($formatter === 'auto' && strpos($format, '%') !== false)) {
+ 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) {
$_win_from[] = '%e';
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
@@ -57,7 +78,6 @@ function smarty_modifier_date_format($string, $format = null, $default_date = ''
}
$format = str_replace($_win_from, $_win_to, $format);
}
-
return strftime($format, $timestamp);
} else {
return date($format, $timestamp);
diff --git a/include/smarty/libs/plugins/modifier.debug_print_var.php b/include/smarty/libs/plugins/modifier.debug_print_var.php
index 4ff8213ce..78397d017 100644
--- a/include/smarty/libs/plugins/modifier.debug_print_var.php
+++ b/include/smarty/libs/plugins/modifier.debug_print_var.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage Debug
*/
-
/**
* Smarty debug_print_var modifier plugin
- * Type: modifier
- * Name: debug_print_var
+ * Type: modifier
+ * Name: debug_print_var
* Purpose: formats variable contents for display in the console
*
* @author Monte Ohrt
@@ -24,46 +23,40 @@
*/
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' :
+ case 'array':
$results = 'Array (' . count($var) . ')';
- if ($depth == $max) {
+ if ($depth === $max) {
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);
- $depth --;
+ $results .= '
' . str_repeat(' ', $depth * 2) . '' . strtr($curr_key, $_replace) .
+ ' => ' .
+ smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
+ $depth--;
}
break;
-
- case 'object' :
+ case 'object':
$object_vars = get_object_vars($var);
$results = '' . get_class($var) . ' Object (' . count($object_vars) . ')';
if (in_array($var, $objects)) {
$results .= ' called recursive';
break;
}
- if ($depth == $max) {
+ if ($depth === $max) {
break;
}
$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);
- $depth --;
+ $results .= '
' . str_repeat(' ', $depth * 2) . ' ->' . strtr($curr_key, $_replace) .
+ ' = ' . smarty_modifier_debug_print_var($curr_val, $max, $length, ++$depth, $objects);
+ $depth--;
}
break;
-
- case 'boolean' :
- case 'NULL' :
- case 'resource' :
+ case 'boolean':
+ case 'NULL':
+ case 'resource':
if (true === $var) {
$results = 'true';
} elseif (false === $var) {
@@ -71,34 +64,30 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
} elseif (null === $var) {
$results = 'null';
} else {
- $results = htmlspecialchars((string) $var);
+ $results = htmlspecialchars((string)$var);
}
$results = '' . $results . '';
break;
-
- case 'integer' :
- case 'float' :
- $results = htmlspecialchars((string) $var);
+ case 'integer':
+ case 'float':
+ $results = htmlspecialchars((string)$var);
break;
-
- case 'string' :
+ case 'string':
$results = strtr($var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
$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' :
- default :
- $results = strtr((string) $var, $_replace);
+ case 'unknown type':
+ default:
+ $results = strtr((string)$var, $_replace);
if (Smarty::$_MBSTRING) {
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
@@ -108,9 +97,7 @@ function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth =
$results = substr($results, 0, $length - 3) . '...';
}
}
-
- $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..150901c7c 100644
--- a/include/smarty/libs/plugins/modifier.escape.php
+++ b/include/smarty/libs/plugins/modifier.escape.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty escape modifier plugin
- * Type: modifier
- * Name: escape
+ * Type: modifier
+ * Name: escape
* Purpose: escape string for output
*
* @link http://www.smarty.net/docs/en/language.modifier.escape
@@ -25,14 +24,14 @@
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{
static $_double_encode = null;
+ static $is_loaded_1 = false;
+ static $is_loaded_2 = false;
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
-
if (!$char_set) {
$char_set = Smarty::$_CHARSET;
}
-
switch ($esc_type) {
case 'html':
if ($_double_encode) {
@@ -46,12 +45,21 @@ 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;
}
}
-
+ // no break
case 'htmlall':
if (Smarty::$_MBSTRING) {
// mb_convert_encoding ignores htmlspecialchars()
@@ -66,16 +74,24 @@ 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;
}
}
-
// htmlentities() won't convert everything, so use mb_convert_encoding
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
}
-
// no MBString fallback
if ($_double_encode) {
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
@@ -85,89 +101,134 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
} else {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlentities($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;
}
}
-
+ // no break
case 'url':
return rawurlencode($string);
-
case 'urlpathinfo':
return str_replace('%2F', '/', rawurlencode($string));
-
case 'quotes':
// escape unescaped single quotes
return preg_replace("%(? '\\\\', "'" => "\\'", '"' => '\\"', "\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');
-
- return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
+ if (!$is_loaded_2) {
+ if (!is_callable('smarty_mb_str_replace')) {
+ include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
+ }
+ $is_loaded_2 = true;
+ }
+ return smarty_mb_str_replace(
+ array(
+ '@',
+ '.'
+ ),
+ array(
+ ' [AT] ',
+ ' [DOT] '
+ ),
+ $string
+ );
}
// no MBString fallback
- return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
-
+ return str_replace(
+ array(
+ '@',
+ '.'
+ ),
+ array(
+ ' [AT] ',
+ ' [DOT] '
+ ),
+ $string
+ );
case 'nonstd':
// escape non-standard chars, such as ms document quotes
$return = '';
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
+ if (!$is_loaded_1) {
+ if (!is_callable('smarty_mb_to_unicode')) {
+ include_once SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php';
+ }
+ $is_loaded_1 = true;
+ }
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) {
$return .= '' . $unicode . ';';
@@ -175,12 +236,10 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= chr($unicode);
}
}
-
return $return;
}
-
$_length = strlen($string);
- for ($_i = 0; $_i < $_length; $_i ++) {
+ for ($_i = 0; $_i < $_length; $_i++) {
$_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it
if ($_ord >= 126) {
@@ -189,9 +248,7 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
$return .= substr($string, $_i, 1);
}
}
-
return $return;
-
default:
return $string;
}
diff --git a/include/smarty/libs/plugins/modifier.mb_wordwrap.php b/include/smarty/libs/plugins/modifier.mb_wordwrap.php
new file mode 100644
index 000000000..1cd625b64
--- /dev/null
+++ b/include/smarty/libs/plugins/modifier.mb_wordwrap.php
@@ -0,0 +1,71 @@
+ $width) {
+ if ($cut) {
+ $_tokens = preg_split(
+ '!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER,
+ $_token,
+ -1,
+ PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE
+ );
+ }
+ }
+ foreach ($_tokens as $token) {
+ $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
+ $token_length = mb_strlen($token, Smarty::$_CHARSET);
+ $length += $token_length;
+ if ($length > $width) {
+ // remove space before inserted break
+ if ($_previous) {
+ $t = mb_substr($t, 0, -1, Smarty::$_CHARSET);
+ }
+ if (!$_space) {
+ // add the break before the token
+ if (!empty($t)) {
+ $t .= $break;
+ }
+ $length = $token_length;
+ }
+ } elseif ($token === "\n") {
+ // hard break must reset counters
+ $length = 0;
+ }
+ $_previous = $_space;
+ // add the token
+ $t .= $token;
+ }
+ }
+ return $t;
+}
diff --git a/include/smarty/libs/plugins/modifier.regex_replace.php b/include/smarty/libs/plugins/modifier.regex_replace.php
index ffea16755..7eb550695 100644
--- a/include/smarty/libs/plugins/modifier.regex_replace.php
+++ b/include/smarty/libs/plugins/modifier.regex_replace.php
@@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty regex_replace modifier plugin
- * Type: modifier
- * Name: regex_replace
+ * Type: modifier
+ * Name: regex_replace
* Purpose: regular expression search/replace
*
- * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
+ * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
* regex_replace (Smarty online manual)
- * @author Monte Ohrt
+ * @author Monte Ohrt
*
* @param string $string input string
* @param string|array $search regular expression(s) to search for
@@ -27,12 +26,11 @@ 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);
}
-
return preg_replace($search, $replace, $string, $limit);
}
@@ -50,9 +48,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..a98f5a4a6 100644
--- a/include/smarty/libs/plugins/modifier.replace.php
+++ b/include/smarty/libs/plugins/modifier.replace.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty replace modifier plugin
- * Type: modifier
- * Name: replace
+ * Type: modifier
+ * Name: replace
* Purpose: simple search/replace
*
* @link http://smarty.php.net/manual/en/language.modifier.replace.php replace (Smarty online manual)
@@ -24,11 +23,15 @@
*/
function smarty_modifier_replace($string, $search, $replace)
{
+ static $is_loaded = false;
if (Smarty::$_MBSTRING) {
- require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
-
+ if (!$is_loaded) {
+ if (!is_callable('smarty_mb_str_replace')) {
+ include_once SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php';
+ }
+ $is_loaded = true;
+ }
return smarty_mb_str_replace($search, $replace, $string);
}
-
return str_replace($search, $replace, $string);
}
diff --git a/include/smarty/libs/plugins/modifier.spacify.php b/include/smarty/libs/plugins/modifier.spacify.php
index e5c41ad8b..98efd4b30 100644
--- a/include/smarty/libs/plugins/modifier.spacify.php
+++ b/include/smarty/libs/plugins/modifier.spacify.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty spacify modifier plugin
- * Type: modifier
- * Name: spacify
+ * Type: modifier
+ * Name: spacify
* Purpose: add spaces between characters in a string
*
* @link http://smarty.php.net/manual/en/language.modifier.spacify.php spacify (Smarty online manual)
@@ -23,5 +22,5 @@
function smarty_modifier_spacify($string, $spacify_char = ' ')
{
// well… what about charsets besides latin and UTF-8?
- return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, - 1, PREG_SPLIT_NO_EMPTY));
+ return implode($spacify_char, preg_split('//' . Smarty::$_UTF8_MODIFIER, $string, -1, PREG_SPLIT_NO_EMPTY));
}
diff --git a/include/smarty/libs/plugins/modifier.truncate.php b/include/smarty/libs/plugins/modifier.truncate.php
index fbe62e823..bb881bf6e 100644
--- a/include/smarty/libs/plugins/modifier.truncate.php
+++ b/include/smarty/libs/plugins/modifier.truncate.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifier
*/
-
/**
* Smarty truncate modifier plugin
- * Type: modifier
- * Name: truncate
+ * Type: modifier
+ * Name: truncate
* Purpose: Truncate a string to a certain length if necessary,
* optionally splitting in the middle of a word, and
* appending the $etc string or inserting $etc into the middle.
@@ -27,28 +26,29 @@
*/
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
{
- if ($length == 0) {
+ if ($length === 0) {
return '';
}
-
if (Smarty::$_MBSTRING) {
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));
@@ -56,9 +56,7 @@ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_wo
if (!$middle) {
return substr($string, 0, $length) . $etc;
}
-
- return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
+ return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2);
}
-
return $string;
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.cat.php b/include/smarty/libs/plugins/modifiercompiler.cat.php
index db9d81fbf..21d0e6624 100644
--- a/include/smarty/libs/plugins/modifiercompiler.cat.php
+++ b/include/smarty/libs/plugins/modifiercompiler.cat.php
@@ -5,19 +5,18 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty cat modifier plugin
- * Type: modifier
- * Name: cat
- * Date: Feb 24, 2003
- * Purpose: catenate a value to a variable
- * Input: string to catenate
+ * Type: modifier
+ * Name: cat
+ * Date: Feb 24, 2003
+ * Purpose: catenate a value to a variable
+ * Input: string to catenate
* Example: {$var|cat:"foo"}
*
- * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
+ * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
- * @author Uwe Tews
+ * @author Uwe Tews
*
* @param array $params parameters
*
diff --git a/include/smarty/libs/plugins/modifiercompiler.count_characters.php b/include/smarty/libs/plugins/modifiercompiler.count_characters.php
index f8463d80a..6c44278af 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_characters.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_characters.php
@@ -5,14 +5,14 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty count_characters modifier plugin
- * Type: modifier
- * Name: count_characteres
+ * Type: modifier
+ * Name: count_characters
* Purpose: count the number of characters in a text
*
- * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
+ * @link http://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
+ * manual)
* @author Uwe Tews
*
* @param array $params parameters
@@ -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..e214a56f0 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_paragraphs.php
@@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty count_paragraphs modifier plugin
- * Type: modifier
- * Name: count_paragraphs
+ * Type: modifier
+ * Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
- * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
+ * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
- * @author Uwe Tews
+ * @author Uwe Tews
*
* @param array $params parameters
*
@@ -23,5 +22,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..027745635 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_sentences.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_sentences.php
@@ -5,16 +5,15 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty count_sentences modifier plugin
- * Type: modifier
+ * Type: modifier
* Name: count_sentences
* Purpose: count the number of sentences in a text
*
- * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
+ * @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
- * @author Uwe Tews
+ * @author Uwe Tews
*
* @param array $params parameters
*
@@ -23,5 +22,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..6d889da5c 100644
--- a/include/smarty/libs/plugins/modifiercompiler.count_words.php
+++ b/include/smarty/libs/plugins/modifiercompiler.count_words.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty count_words modifier plugin
- * Type: modifier
- * Name: count_words
+ * Type: modifier
+ * Name: count_words
* Purpose: count the number of words in a text
*
* @link http://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
@@ -24,8 +23,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..ae886c4b2 100644
--- a/include/smarty/libs/plugins/modifiercompiler.default.php
+++ b/include/smarty/libs/plugins/modifiercompiler.default.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty default modifier plugin
- * Type: modifier
- * Name: default
+ * Type: modifier
+ * Name: default
* Purpose: designate default value for empty variables
*
* @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
@@ -21,15 +20,13 @@
*/
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);
foreach ($params as $param) {
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
}
-
return $output;
}
diff --git a/include/smarty/libs/plugins/modifiercompiler.escape.php b/include/smarty/libs/plugins/modifiercompiler.escape.php
index 0b29220ef..e0763adce 100644
--- a/include/smarty/libs/plugins/modifiercompiler.escape.php
+++ b/include/smarty/libs/plugins/modifiercompiler.escape.php
@@ -5,122 +5,108 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
-/**
- * @ignore
- */
-require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
-
/**
* Smarty escape modifier plugin
- * Type: modifier
- * Name: escape
+ * Type: modifier
+ * Name: escape
* Purpose: escape string for output
*
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*
- * @param array $params parameters
- * @param $compiler
+ * @param array $params parameters
+ * @param Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
+ * @throws \SmartyException
*/
-function smarty_modifiercompiler_escape($params, $compiler)
+function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler)
{
static $_double_encode = null;
+ static $is_loaded = false;
+ $compiler->template->_checkPlugins(
+ array(
+ array(
+ 'function' => 'smarty_literal_compiler_param',
+ 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php'
+ )
+ )
+ );
if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
}
-
try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
$double_encode = smarty_literal_compiler_param($params, 3, true);
-
if (!$char_set) {
$char_set = Smarty::$_CHARSET;
}
-
switch ($esc_type) {
case 'html':
if ($_double_encode) {
- return 'htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true) . ')';
+ 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
}
-
+ // no break
case 'htmlall':
if (Smarty::$_MBSTRING) {
if ($_double_encode) {
// php >=5.2.3 - go native
- return 'mb_convert_encoding(htmlspecialchars('
- . $params[0] . ', ENT_QUOTES, '
- . var_export($char_set, true) . ', '
- . var_export($double_encode, true)
- . '), "HTML-ENTITIES", '
- . var_export($char_set, true) . ')';
+ 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
}
}
-
// 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
}
-
+ // no break
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) {
+ } catch (SmartyException $e) {
// pass through to regular plugin fallback
}
-
// 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->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
+ SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->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->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
+ SMARTY_PLUGINS_DIR . 'modifier.escape.php';
+ $compiler->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..acce7784b 100644
--- a/include/smarty/libs/plugins/modifiercompiler.from_charset.php
+++ b/include/smarty/libs/plugins/modifiercompiler.from_charset.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty from_charset modifier plugin
- * Type: modifier
- * Name: from_charset
+ * Type: modifier
+ * Name: from_charset
* Purpose: convert character encoding from $charset to internal encoding
*
* @author Rodney Rehm
@@ -22,12 +21,10 @@ 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..2088ad6a8 100644
--- a/include/smarty/libs/plugins/modifiercompiler.indent.php
+++ b/include/smarty/libs/plugins/modifiercompiler.indent.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty indent modifier plugin
- * Type: modifier
- * Name: indent
+ * Type: modifier
+ * Name: indent
* Purpose: indent lines of text
*
* @link http://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
@@ -19,15 +18,13 @@
*
* @return string with compiled code
*/
-
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..0d899a002 100644
--- a/include/smarty/libs/plugins/modifiercompiler.lower.php
+++ b/include/smarty/libs/plugins/modifiercompiler.lower.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty lower modifier plugin
- * Type: modifier
- * Name: lower
+ * Type: modifier
+ * Name: lower
* Purpose: convert string to lowercase
*
* @link http://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
@@ -20,12 +19,11 @@
*
* @return string with compiled code
*/
-
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.noprint.php b/include/smarty/libs/plugins/modifiercompiler.noprint.php
index 4906908b4..1275190e0 100644
--- a/include/smarty/libs/plugins/modifiercompiler.noprint.php
+++ b/include/smarty/libs/plugins/modifiercompiler.noprint.php
@@ -5,14 +5,13 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty noprint modifier plugin
- * Type: modifier
- * Name: noprint
+ * Type: modifier
+ * Name: noprint
* Purpose: return an empty string
*
- * @author Uwe Tews
+ * @author Uwe Tews
* @return string with compiled code
*/
function smarty_modifiercompiler_noprint()
diff --git a/include/smarty/libs/plugins/modifiercompiler.string_format.php b/include/smarty/libs/plugins/modifiercompiler.string_format.php
index 71cdf2819..663094311 100644
--- a/include/smarty/libs/plugins/modifiercompiler.string_format.php
+++ b/include/smarty/libs/plugins/modifiercompiler.string_format.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty string_format modifier plugin
- * Type: modifier
- * Name: string_format
+ * Type: modifier
+ * Name: string_format
* Purpose: format strings via sprintf
*
* @link http://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
@@ -21,5 +20,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..04ea332c5 100644
--- a/include/smarty/libs/plugins/modifiercompiler.strip.php
+++ b/include/smarty/libs/plugins/modifiercompiler.strip.php
@@ -5,14 +5,13 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty strip modifier plugin
- * Type: modifier
- * Name: strip
+ * Type: modifier
+ * Name: strip
* Purpose: Replace all repeated spaces, newlines, tabs
- * with a single space or supplied replacement string.
- * Example: {$var|strip} {$var|strip:" "}
+ * with a single space or supplied replacement string.
+ * Example: {$var|strip} {$var|strip:" "}
* Date: September 25th, 2002
*
* @link http://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
@@ -22,12 +21,10 @@
*
* @return string with compiled code
*/
-
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..1bca1a28e 100644
--- a/include/smarty/libs/plugins/modifiercompiler.strip_tags.php
+++ b/include/smarty/libs/plugins/modifiercompiler.strip_tags.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty strip_tags modifier plugin
- * Type: modifier
- * Name: strip_tags
+ * Type: modifier
+ * Name: strip_tags
* Purpose: strip html tags from text
*
* @link http://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
@@ -21,9 +20,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..d652eab1b 100644
--- a/include/smarty/libs/plugins/modifiercompiler.to_charset.php
+++ b/include/smarty/libs/plugins/modifiercompiler.to_charset.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty to_charset modifier plugin
- * Type: modifier
- * Name: to_charset
+ * Type: modifier
+ * Name: to_charset
* Purpose: convert character encoding from internal encoding to $charset
*
* @author Rodney Rehm
@@ -22,12 +21,10 @@ 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..05beb81f5 100644
--- a/include/smarty/libs/plugins/modifiercompiler.unescape.php
+++ b/include/smarty/libs/plugins/modifiercompiler.unescape.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty unescape modifier plugin
- * Type: modifier
- * Name: unescape
+ * Type: modifier
+ * Name: unescape
* Purpose: unescape html entities
*
* @author Rodney Rehm
@@ -20,31 +19,26 @@
*/
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..ea4e95b7a 100644
--- a/include/smarty/libs/plugins/modifiercompiler.upper.php
+++ b/include/smarty/libs/plugins/modifiercompiler.upper.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty upper modifier plugin
- * Type: modifier
- * Name: lower
+ * Type: modifier
+ * Name: lower
* Purpose: convert string to uppercase
*
* @link http://smarty.php.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
@@ -22,8 +21,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..8565f140e 100644
--- a/include/smarty/libs/plugins/modifiercompiler.wordwrap.php
+++ b/include/smarty/libs/plugins/modifiercompiler.wordwrap.php
@@ -5,43 +5,35 @@
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
-
/**
* Smarty wordwrap modifier plugin
- * Type: modifier
- * Name: wordwrap
+ * Type: modifier
+ * Name: wordwrap
* Purpose: wrap a string of text at a given length
*
* @link http://smarty.php.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews
*
- * @param array $params parameters
- * @param $compiler
+ * @param array $params parameters
+ * @param \Smarty_Internal_TemplateCompilerBase $compiler
*
* @return string with compiled code
+ * @throws \SmartyException
*/
-function smarty_modifiercompiler_wordwrap($params, $compiler)
+function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompilerBase $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';
- } 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';
- }
- $function = 'smarty_mb_wordwrap';
+ $function = $compiler->getPlugin('mb_wordwrap', 'modifier');
}
-
- 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..7e4503a1c 100644
--- a/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
+++ b/include/smarty/libs/plugins/outputfilter.trimwhitespace.php
@@ -5,86 +5,85 @@
* @package Smarty
* @subpackage PluginsFilter
*/
-
/**
* Smarty trimwhitespace outputfilter plugin
* Trim unnecessary whitespace from HTML markup.
*
- * @author Rodney Rehm
+ * @author Rodney Rehm
*
* @param string $source input string
*
* @return string filtered output
- * @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
+ * @todo substr_replace() is not overloaded by mbstring.func_overload - so this function might fail!
*/
function smarty_outputfilter_trimwhitespace($source)
{
$store = array();
$_store = 0;
$_offset = 0;
-
// 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)) {
+ $source = preg_replace('/\015\012|\015|\012/', "\n", $source);
+ // 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 ++;
+ $_store++;
}
}
-
// Strip all HTML-Comments
// yes, even the ones in ]*>)|(]*>)|(]*>.*?
]*>)#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 ++;
+ $_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.
// maybe a \0 byte or something is interfering?
// $source = trim( $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 ++;
+ $_store++;
}
}
-
return $source;
}
diff --git a/include/smarty/libs/plugins/shared.escape_special_chars.php b/include/smarty/libs/plugins/shared.escape_special_chars.php
index d3bd756b1..6b18d3eec 100644
--- a/include/smarty/libs/plugins/shared.escape_special_chars.php
+++ b/include/smarty/libs/plugins/shared.escape_special_chars.php
@@ -5,49 +5,28 @@
* @package Smarty
* @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..65caf03c8 100644
--- a/include/smarty/libs/plugins/shared.literal_compiler_param.php
+++ b/include/smarty/libs/plugins/shared.literal_compiler_param.php
@@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsShared
*/
-
/**
* evaluate compiler parameter
*
@@ -20,16 +19,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..9626dc68e 100644
--- a/include/smarty/libs/plugins/shared.make_timestamp.php
+++ b/include/smarty/libs/plugins/shared.make_timestamp.php
@@ -5,12 +5,11 @@
* @package Smarty
* @subpackage PluginsShared
*/
-
/**
- * Function: smarty_make_timestamp
+ * Function: smarty_make_timestamp
* Purpose: used by other smarty functions to make a timestamp from a string.
*
- * @author Monte Ohrt
+ * @author Monte Ohrt
*
* @param DateTime|int|string $string date object, timestamp or string that can be converted using strtotime()
*
@@ -21,23 +20,30 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
- } 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)) {
+ } 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;
+ return (int)$string;
} else {
// strtotime should handle it
$time = strtotime($string);
- if ($time == - 1 || $time === false) {
+ if ($time === -1 || $time === false) {
// strtotime() was not able to parse $string, use "now":
return time();
}
-
return $time;
}
}
diff --git a/include/smarty/libs/plugins/shared.mb_str_replace.php b/include/smarty/libs/plugins/shared.mb_str_replace.php
index a5682ed30..206cf9ea6 100644
--- a/include/smarty/libs/plugins/shared.mb_str_replace.php
+++ b/include/smarty/libs/plugins/shared.mb_str_replace.php
@@ -6,14 +6,13 @@
* @subpackage PluginsShared
*/
if (!function_exists('smarty_mb_str_replace')) {
-
/**
* Multibyte string replace
*
- * @param string $search the string to be searched
- * @param string $replace the replacement string
- * @param string $subject the source string
- * @param int &$count number of matches found
+ * @param string|string[] $search the string to be searched
+ * @param string|string[] $replace the replacement string
+ * @param string $subject the source string
+ * @param int &$count number of matches found
*
* @return string replaced string
* @author Rodney Rehm
@@ -26,7 +25,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)) {
@@ -37,7 +36,7 @@ if (!function_exists('smarty_mb_str_replace')) {
}
} else {
$n = max(count($search), count($replace));
- while ($n --) {
+ while ($n--) {
$subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
$count += $c;
next($search);
@@ -49,7 +48,6 @@ if (!function_exists('smarty_mb_str_replace')) {
$count = count($parts) - 1;
$subject = implode($replace, $parts);
}
-
return $subject;
}
}
diff --git a/include/smarty/libs/plugins/shared.mb_unicode.php b/include/smarty/libs/plugins/shared.mb_unicode.php
index 0f790b56a..7d1206506 100644
--- a/include/smarty/libs/plugins/shared.mb_unicode.php
+++ b/include/smarty/libs/plugins/shared.mb_unicode.php
@@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsShared
*/
-
/**
* convert characters to their decimal unicode equivalents
*
@@ -20,12 +19,11 @@
function smarty_mb_to_unicode($string, $encoding = null)
{
if ($encoding) {
- $expanded = mb_convert_encoding($string, "UTF-32BE", $encoding);
+ $expanded = mb_convert_encoding($string, 'UTF-32BE', $encoding);
} else {
- $expanded = mb_convert_encoding($string, "UTF-32BE");
+ $expanded = mb_convert_encoding($string, 'UTF-32BE');
}
-
- return unpack("N*", $expanded);
+ return unpack('N*', $expanded);
}
/**
@@ -45,10 +43,9 @@ function smarty_mb_from_unicode($unicode, $encoding = null)
if (!$encoding) {
$encoding = mb_internal_encoding();
}
- foreach ((array) $unicode as $utf32be) {
- $character = pack("N*", $utf32be);
- $t .= mb_convert_encoding($character, $encoding, "UTF-32BE");
+ foreach ((array)$unicode as $utf32be) {
+ $character = pack('N*', $utf32be);
+ $t .= mb_convert_encoding($character, $encoding, 'UTF-32BE');
}
-
return $t;
}
diff --git a/include/smarty/libs/plugins/shared.mb_wordwrap.php b/include/smarty/libs/plugins/shared.mb_wordwrap.php
deleted file mode 100644
index 31f4acf01..000000000
--- a/include/smarty/libs/plugins/shared.mb_wordwrap.php
+++ /dev/null
@@ -1,73 +0,0 @@
- $width) {
- if ($cut) {
- $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, - 1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
- }
- }
-
- foreach ($_tokens as $token) {
- $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token);
- $token_length = mb_strlen($token, Smarty::$_CHARSET);
- $length += $token_length;
-
- if ($length > $width) {
- // remove space before inserted break
- if ($_previous) {
- $t = mb_substr($t, 0, - 1, Smarty::$_CHARSET);
- }
-
- if (!$_space) {
- // add the break before the token
- if (!empty($t)) {
- $t .= $break;
- }
- $length = $token_length;
- }
- } elseif ($token == "\n") {
- // hard break must reset counters
- $_previous = 0;
- $length = 0;
- }
- $_previous = $_space;
- // add the token
- $t .= $token;
- }
- }
-
- return $t;
- }
-}
diff --git a/include/smarty/libs/plugins/variablefilter.htmlspecialchars.php b/include/smarty/libs/plugins/variablefilter.htmlspecialchars.php
index aecd1e7e7..3c85295db 100644
--- a/include/smarty/libs/plugins/variablefilter.htmlspecialchars.php
+++ b/include/smarty/libs/plugins/variablefilter.htmlspecialchars.php
@@ -5,15 +5,15 @@
* @package Smarty
* @subpackage PluginsFilter
*/
-
/**
* Smarty htmlspecialchars variablefilter plugin
*
- * @param string $source input string
+ * @param string $source input string
+ * @param \Smarty_Internal_Template $template
*
* @return string filtered output
*/
-function smarty_variablefilter_htmlspecialchars($source)
+function smarty_variablefilter_htmlspecialchars($source, Smarty_Internal_Template $template)
{
return htmlspecialchars($source, ENT_QUOTES, Smarty::$_CHARSET);
}
diff --git a/include/smarty/libs/sysplugins/smarty_cacheresource.php b/include/smarty/libs/sysplugins/smarty_cacheresource.php
index 14ab62fd9..91e9f3924 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource.php
@@ -25,12 +25,12 @@ abstract class Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
- * @param Smarty_Template_Cached $cached cached object
+ * @param \Smarty_Template_Cached $cached cached object
* @param Smarty_Internal_Template $_template template object
*
* @return void
*/
- abstract public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
+ abstract public function populate(\Smarty_Template_Cached $cached, Smarty_Internal_Template $_template);
/**
* populate Cached Object with timestamp and exists from Resource
@@ -46,11 +46,15 @@ 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 +66,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 public function readCachedContent(Smarty_Internal_Template $_template);
+
/**
* Return cached content
*
@@ -77,7 +90,6 @@ abstract class Smarty_CacheResource
$unifunc($_template);
return ob_get_clean();
}
-
return null;
}
@@ -123,7 +135,6 @@ abstract class Smarty_CacheResource
}
sleep(1);
}
-
return $hadLock;
}
@@ -183,41 +194,26 @@ abstract class Smarty_CacheResource
if (!isset($type)) {
$type = $smarty->caching_type;
}
-
// 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..68ad11289 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource_custom.php
@@ -18,12 +18,12 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* fetch cached content and its modification time from data source
*
- * @param string $id unique cache content identifier
- * @param string $name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param string $content cached content
- * @param integer $mtime cache modification timestamp (epoch)
+ * @param string $id unique cache content identifier
+ * @param string $name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param string $content cached content
+ * @param integer $mtime cache modification timestamp (epoch)
*
* @return void
*/
@@ -34,27 +34,27 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
* {@internal implementing this method is optional.
* Only implement it if modification times can be accessed faster than loading the complete cached content.}}
*
- * @param string $id unique cache content identifier
- * @param string $name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
+ * @param string $id unique cache content identifier
+ * @param string $name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
*
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
*/
protected function fetchTimestamp($id, $name, $cache_id, $compile_id)
{
- return null;
+ return false;
}
/**
* Save content to cache
*
- * @param string $id unique cache content identifier
- * @param string $name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param integer|null $exp_time seconds till expiration or null
- * @param string $content content to cache
+ * @param string $id unique cache content identifier
+ * @param string $name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param integer|null $exp_time seconds till expiration or null
+ * @param string $content content to cache
*
* @return boolean success
*/
@@ -63,10 +63,10 @@ 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 integer|null $exp_time seconds till expiration time in seconds or null
+ * @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
*/
@@ -75,8 +75,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
- * @param Smarty_Template_Cached $cached cached object
- * @param Smarty_Internal_Template $_template template object
+ * @param Smarty_Template_Cached $cached cached object
+ * @param Smarty_Internal_Template $_template template object
*
* @return void
*/
@@ -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,15 +101,22 @@ 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;
-
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,54 +124,66 @@ 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);
+ eval('?>' . $content);
$cached->content = null;
return true;
}
-
return false;
}
/**
* Write the rendered template output to cache
*
- * @param Smarty_Internal_Template $_template template object
- * @param string $content content to cache
+ * @param Smarty_Internal_Template $_template template object
+ * @param string $content content to cache
*
* @return boolean success
*/
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
+ );
}
/**
* Read cached template from cache
*
- * @param Smarty_Internal_Template $_template template object
+ * @param Smarty_Internal_Template $_template template object
*
- * @return string content
+ * @return string|boolean content
*/
public function readCachedContent(Smarty_Internal_Template $_template)
{
@@ -172,7 +191,14 @@ 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;
@@ -183,8 +209,8 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache
*
- * @param Smarty $smarty Smarty object
- * @param integer $exp_time expiration time (number of seconds, not timestamp)
+ * @param Smarty $smarty Smarty object
+ * @param integer $exp_time expiration time (number of seconds, not timestamp)
*
* @return integer number of cache files deleted
*/
@@ -196,18 +222,18 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
/**
* Empty cache for a specific template
*
- * @param Smarty $smarty Smarty object
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param integer $exp_time expiration time (number of seconds, not timestamp)
+ * @param Smarty $smarty Smarty object
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param integer $exp_time expiration time (number of seconds, not timestamp)
*
- * @return integer number of cache files deleted
+ * @return int number of cache files deleted
+ * @throws \SmartyException
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$cache_name = null;
-
if (isset($resource_name)) {
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
if ($source->exists) {
@@ -215,24 +241,15 @@ 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);
}
/**
* Check is cache is locked for this template
*
- * @param Smarty $smarty Smarty object
- * @param Smarty_Template_Cached $cached cached object
+ * @param Smarty $smarty Smarty object
+ * @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
@@ -240,7 +257,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
{
$id = $cached->lock_id;
$name = $cached->source->name . '.lock';
-
$mtime = $this->fetchTimestamp($id, $name, $cached->cache_id, $cached->compile_id);
if ($mtime === null) {
$this->fetch($id, $name, $cached->cache_id, $cached->compile_id, $content, $mtime);
diff --git a/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php b/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
index ee4021a19..59bf1d4a8 100644
--- a/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
+++ b/include/smarty/libs/sysplugins/smarty_cacheresource_keyvaluestore.php
@@ -47,98 +47,120 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* populate Cached Object with meta data from Resource
*
- * @param Smarty_Template_Cached $cached cached object
- * @param Smarty_Internal_Template $_template template object
+ * @param Smarty_Template_Cached $cached cached object
+ * @param Smarty_Internal_Template $_template template object
*
* @return void
*/
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);
}
/**
* populate Cached Object with timestamp and exists from Resource
*
- * @param Smarty_Template_Cached $cached cached object
+ * @param Smarty_Template_Cached $cached cached object
*
* @return void
*/
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->timestamp = (int)$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);
-
+ eval('?>' . $content);
return true;
}
-
return false;
}
/**
* Write the rendered template output to cache
*
- * @param Smarty_Internal_Template $_template template object
- * @param string $content content to cache
+ * @param Smarty_Internal_Template $_template template object
+ * @param string $content content to cache
*
* @return boolean success
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
$this->addMetaTimestamp($content);
-
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
}
/**
* Read cached template from cache
*
- * @param Smarty_Internal_Template $_template template object
+ * @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;
}
}
@@ -152,73 +174,55 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
* Empty cache
* {@internal the $exp_time argument is ignored altogether }}
*
- * @param Smarty $smarty Smarty object
- * @param integer $exp_time expiration time [being ignored]
+ * @param Smarty $smarty Smarty object
+ * @param integer $exp_time expiration time [being ignored]
*
* @return integer number of cache files deleted [always -1]
- * @uses purge() to clear the whole store
- * @uses invalidate() to mark everything outdated if purge() is inapplicable
+ * @uses purge() to clear the whole store
+ * @uses invalidate() to mark everything outdated if purge() is inapplicable
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
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;
+ return -1;
}
/**
* Empty cache for a specific template
* {@internal the $exp_time argument is ignored altogether}}
*
- * @param Smarty $smarty Smarty object
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param integer $exp_time expiration time [being ignored]
+ * @param Smarty $smarty Smarty object
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param integer $exp_time expiration time [being ignored]
*
- * @return integer number of cache files deleted [always -1]
- * @uses buildCachedFilepath() to generate the CacheID
- * @uses invalidate() to mark CacheIDs parent chain as outdated
- * @uses delete() to remove CacheID from cache
+ * @return int number of cache files deleted [always -1]
+ * @throws \SmartyException
+ * @uses buildCachedFilepath() to generate the CacheID
+ * @uses invalidate() to mark CacheIDs parent chain as outdated
+ * @uses delete() to remove CacheID from cache
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$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;
+ return -1;
}
/**
* Get template's unique ID
*
- * @param Smarty $smarty Smarty object
- * @param string $resource_name template name
+ * @param Smarty $smarty Smarty object
+ * @param string $resource_name template name
*
* @return string filepath of cache file
* @throws \SmartyException
- *
*/
protected function getTemplateUid(Smarty $smarty, $resource_name)
{
@@ -234,7 +238,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Sanitize CacheID components
*
- * @param string $string CacheID component to sanitize
+ * @param string $string CacheID component to sanitize
*
* @return string sanitized CacheID component
*/
@@ -242,7 +246,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$string = trim($string, '|');
if (!$string) {
- return null;
+ return '';
}
return preg_replace('#[^\w\|]+#S', '_', $string);
}
@@ -250,30 +254,36 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Fetch and prepare a cache object.
*
- * @param string $cid CacheID to fetch
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param string $content cached content
- * @param integer &$timestamp cached timestamp (epoch)
- * @param string $resource_uid resource's uid
+ * @param string $cid CacheID to fetch
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param string $content cached content
+ * @param integer &$timestamp cached timestamp (epoch)
+ * @param string $resource_uid resource's uid
*
* @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;
}
}
-
return !!$content;
}
@@ -285,37 +295,46 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
protected function addMetaTimestamp(&$content)
{
- $mt = explode(" ", microtime());
- $ts = pack("NN", $mt[1], (int) ($mt[0] * 100000000));
+ $mt = explode(' ', microtime());
+ $ts = pack('NN', $mt[ 1 ], (int)($mt[ 0 ] * 100000000));
$content = $ts . $content;
}
/**
* Extract the timestamp the $content was cached
*
- * @param string &$content the cached content
+ * @param string &$content the cached content
*
* @return float the microtime the content was cached
*/
protected function getMetaTimestamp(&$content)
{
extract(unpack('N1s/N1m/a*content', $content));
+ /**
+ * @var int $s
+ * @var int $m
+ */
return $s + ($m / 100000000);
}
/**
* Invalidate CacheID
*
- * @param string $cid CacheID
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param string $resource_uid source's uid
+ * @param string $cid CacheID
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param string $resource_uid source's uid
*
* @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;
// invalidate everything
@@ -346,16 +365,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Determine the latest timestamp known to the invalidation chain
*
- * @param string $cid CacheID to determine latest invalidation timestamp of
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param string $resource_uid source's filepath
+ * @param string $cid CacheID to determine latest invalidation timestamp of
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param string $resource_uid source's filepath
*
* @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) {
return 0;
@@ -364,32 +388,35 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!($_cid = $this->listInvalidationKeys($cid, $resource_name, $cache_id, $compile_id, $resource_uid))) {
return 0;
}
-
// there are no InValidationKeys
if (!($values = $this->read($_cid))) {
return 0;
}
// make sure we're dealing with floats
$values = array_map('floatval', $values);
-
return max($values);
}
/**
* Translate a CacheID into the list of applicable InvalidationKeys.
- * Splits "some|chain|into|an|array" into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
+ * Splits 'some|chain|into|an|array' into array( '#clearAll#', 'some', 'some|chain', 'some|chain|into', ... )
*
- * @param string $cid CacheID to translate
- * @param string $resource_name template name
- * @param string $cache_id cache id
- * @param string $compile_id compile id
- * @param string $resource_uid source's filepath
+ * @param string $cid CacheID to translate
+ * @param string $resource_name template name
+ * @param string $cache_id cache id
+ * @param string $compile_id compile id
+ * @param string $resource_uid source's filepath
*
* @return array list of InvalidationKeys
- * @uses $invalidationKeyPrefix to prepend to each InvalidationKey
+ * @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 = '#';
if ($resource_name) {
@@ -421,17 +448,16 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$t[] = 'IVK#CACHE#' . $part;
$t[] = 'IVK#CID' . $_name . $part . $_compile;
// skip past delimiter position
- $i ++;
+ $i++;
}
-
return $t;
}
/**
* Check is cache is locked for this template
*
- * @param Smarty $smarty Smarty object
- * @param Smarty_Template_Cached $cached cached object
+ * @param Smarty $smarty Smarty object
+ * @param Smarty_Template_Cached $cached cached object
*
* @return boolean true or false if cache is locked
*/
@@ -439,8 +465,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;
}
/**
@@ -476,7 +501,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Read values for a set of keys from cache
*
- * @param array $keys list of keys to fetch
+ * @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
*/
@@ -485,8 +510,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Save values for a set of keys to cache
*
- * @param array $keys list of values to save
- * @param int $expire expiration time
+ * @param array $keys list of values to save
+ * @param int $expire expiration time
*
* @return boolean true on success, false on failure
*/
@@ -495,7 +520,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
/**
* Remove values from cache
*
- * @param array $keys list of keys to delete
+ * @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
*/
diff --git a/include/smarty/libs/sysplugins/smarty_data.php b/include/smarty/libs/sysplugins/smarty_data.php
index 7cf18a43e..2545ed3a8 100644
--- a/include/smarty/libs/sysplugins/smarty_data.php
+++ b/include/smarty/libs/sysplugins/smarty_data.php
@@ -22,7 +22,7 @@ class Smarty_Data extends Smarty_Internal_Data
*
* @var int
*/
- static $count = 0;
+ public static $count = 0;
/**
* Data block name
@@ -50,7 +50,7 @@ class Smarty_Data extends Smarty_Internal_Data
public function __construct($_parent = null, $smarty = null, $name = null)
{
parent::__construct();
- self::$count ++;
+ self::$count++;
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
$this->smarty = $smarty;
if (is_object($_parent)) {
@@ -59,10 +59,10 @@ 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");
+ } 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..9956d642b
--- /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)
+ {
+ }
+}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php b/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
index 64d02dfe5..61618449d 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_cacheresource_file.php
@@ -27,39 +27,43 @@ 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 ? DIRECTORY_SEPARATOR : '^';
+ $_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 ] . DIRECTORY_SEPARATOR . $_filepath[ 2 ] .
+ $_filepath[ 3 ] .
+ DIRECTORY_SEPARATOR .
+ $_filepath[ 4 ] . $_filepath[ 5 ] . DIRECTORY_SEPARATOR;
}
- $_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 +88,23 @@ 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)
- {
- /** @var Smarty_Internal_Template $_smarty_tpl
- * used in included file
- */
- $_smarty_tpl = $_template;
- $_template->cached->valid = false;
+ public function process(
+ Smarty_Internal_Template $_smarty_tpl,
+ Smarty_Template_Cached $cached = null,
+ $update = 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;
}
}
@@ -110,13 +114,23 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
- * @return boolean success
+ * @return bool success
+ * @throws \SmartyException
*/
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')
+ && (!function_exists('ini_get') || 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);
@@ -131,7 +145,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
/**
* Read cached template from cache
*
- * @param Smarty_Internal_Template $_template template object
+ * @param Smarty_Internal_Template $_template template object
*
* @return string content
*/
@@ -153,7 +167,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 +183,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 +202,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..1a9befbf6 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_append.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_append.php
@@ -19,11 +19,12 @@ 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
+ * @throws \SmartyCompilerException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
@@ -31,14 +32,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..1f0ab9b7d 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_assign.php
@@ -16,20 +16,31 @@
*/
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
*
- * @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
@@ -39,60 +50,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});?>";
+ } else {
+ $output = "_assignInScope({$_var}, {$_attr['value']}{$_params});?>";
}
- $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..8ff15d8e5 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_block.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block.php
@@ -1,5 +1,5 @@
_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,81 +68,40 @@ 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;
- $this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
- $compiler->template->compiled->has_nocache_code,
- $compiler->template->caching));
- // must whole block be nocache ?
- if ($compiler->tag_nocache) {
- $i = 0;
- }
+ ++$compiler->_cache[ 'blockNesting' ];
+ $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(mt_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
+ )
+ );
+ $compiler->saveRequiredPlugins(true);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
- // $compiler->suppressNocacheProcessing = 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;
- }
}
/**
* Smarty Internal Plugin Compile BlockClose Class
- *
*/
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
{
/**
* Compiles code for the {/block} 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 bool true
*/
@@ -166,127 +109,81 @@ 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;
+ if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) {
+ $_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 .= $compiler->compileRequiredPlugins();
+ $compiler->restoreRequiredPlugins();
+ 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";
}
$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->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->parser->current_buffer->append_subtree(
+ $compiler->parser,
+ new Smarty_Internal_ParseTree_Tag(
+ $compiler->parser,
+ $output
+ )
+ );
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
- // nocache plugins must be copied
- if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
- foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
- foreach ($tmp as $type => $data) {
- $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] =
- $data;
- }
- }
- }
-
-
+ $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// 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..588d18628
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block_child.php
@@ -0,0 +1,24 @@
+
+ */
+class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child
+{
+ /**
+ * Tag name
+ *
+ * @var string
+ */
+ public $tag = 'block_child';
+}
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..97f11ca43
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_block_parent.php
@@ -0,0 +1,31 @@
+
+ */
+class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Child
+{
+ /**
+ * Tag name
+ *
+ * @var string
+ */
+ public $tag = 'block_parent';
+
+ /**
+ * Block type
+ *
+ * @var string
+ */
+ public $blockType = 'Parent';
+}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
index cbc73d36a..1ee8d75d7 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_break.php
@@ -32,46 +32,86 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
*/
public $shorttag_order = array('levels');
+ /**
+ * Tag name may be overloaded by Smarty_Internal_Compile_Continue
+ *
+ * @var string
+ */
+ public $tag = 'break';
+
/**
* Compiles code for the {break} tag
*
- * @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
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
+ {
+ list($levels, $foreachLevels) = $this->checkLevels($args, $compiler);
+ $output = " 0 && $this->tag === 'continue') {
+ $foreachLevels--;
+ }
+ if ($foreachLevels > 0) {
+ /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */
+ $foreachCompiler = $compiler->getTagCompiler('foreach');
+ $output .= $foreachCompiler->compileRestore($foreachLevels);
+ }
+ $output .= "{$this->tag} {$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
+ *
+ * @return array
+ * @throws \SmartyCompilerException
+ */
+ public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
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;
+ $foreachLevels = 0;
+ $lastTag = '';
while ($level_count > 0 && $stack_count >= 0) {
- if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) {
- $level_count --;
+ 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 --;
+ $stack_count--;
}
- if ($level_count != 0) {
- $compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true);
+ if ($level_count !== 0) {
+ $compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true);
}
-
- return "";
+ if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) {
+ $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..445cabc60 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_call.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_call.php
@@ -43,8 +43,8 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
/**
* Compiles the calls of user defined tags defined by {function}
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
*
* @return string compiled code
*/
@@ -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 = trim($_attr['name'], "''");
+ $_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';
@@ -74,7 +74,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
$_paramsArray[] = "'$_key'=>$_value";
}
}
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
+ $_params = 'array(' . implode(',', $_paramsArray) . ')';
//$compiler->suppressNocacheProcessing = true;
// was there an assign attribute
if (isset($_assign)) {
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php b/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
index be45f3e94..a4ffbc9ea 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_capture.php
@@ -33,48 +33,44 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
public $optional_attributes = array('name', 'assign', 'append');
/**
- * Compiles code for the {capture} tag
+ * Compiles code for the {$smarty.capture.xxx}
*
- * @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @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
*/
- 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;
+ public static function compileSpecialVariable(
+ $args,
+ Smarty_Internal_TemplateCompilerBase $compiler,
+ $parameter = null
+ ) {
+ return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl' .
+ (isset($parameter[ 1 ]) ? ", {$parameter[ 1 ]})" : ')');
}
/**
- * Compiles code for the {$smarty.capture.xxx}
+ * Compiles code for the {capture} tag
*
- * @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 null $parameter
*
* @return string compiled code
- * @throws \SmartyCompilerException
*/
- public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
{
- $tag = strtolower(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)";
+ // 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 +85,21 @@ 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]);
-
- $_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;
+ list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
+ return "smarty->ext->_capture->close(\$_smarty_tpl);?>";
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_child.php b/include/smarty/libs/sysplugins/smarty_internal_compile_child.php
new file mode 100644
index 000000000..f728c18bf
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_child.php
@@ -0,0 +1,79 @@
+
+ */
+class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
+{
+ /**
+ * Attribute definition: Overwrites base class.
+ *
+ * @var array
+ * @see Smarty_Internal_CompileBase
+ */
+ public $optional_attributes = array('assign');
+
+ /**
+ * Tag name
+ *
+ * @var string
+ */
+ public $tag = 'child';
+
+ /**
+ * Block type
+ *
+ * @var string
+ */
+ public $blockType = 'Child';
+
+ /**
+ * Compiles code for the {child} tag
+ *
+ * @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 function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ {
+ // check and get attributes
+ $_attr = $this->getAttributes($compiler, $args);
+ $tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
+ if (!isset($compiler->_cache[ 'blockNesting' ])) {
+ $compiler->trigger_template_error(
+ "{$tag} used outside {block} tags ",
+ $compiler->parser->lex->taglineno
+ );
+ }
+ $compiler->has_code = true;
+ $compiler->suppressNocacheProcessing = true;
+ if ($this->blockType === 'Child') {
+ $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
+ }
+ $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
+ $output = "inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
+ ($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n";
+ if (isset($_assign)) {
+ $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
+ }
+ $output .= "?>\n";
+ return $output;
+ }
+}
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..8fe64ee10 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
@@ -38,20 +38,31 @@ 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
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -61,44 +72,25 @@ 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
$_output =
"smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
-
return $_output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
index 2ee04c94e..e545728ee 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_continue.php
@@ -14,64 +14,12 @@
* @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.
+ * Tag name
*
- * @var array
- * @see Smarty_Internal_CompileBase
+ * @var string
*/
- 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
- *
- * @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 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);
- }
-
- 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 "";
- }
+ public $tag = 'continue';
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php b/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
index d73c81a10..799416689 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_debug.php
@@ -20,8 +20,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
/**
* Compiles code for the {debug} tag
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
*
* @return string compiled code
*/
@@ -29,12 +29,11 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
-
// compile always as nocache
$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..8e0174e3e 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.
*
@@ -41,31 +43,28 @@ class Smarty_Internal_Compile_Eval extends Smarty_Internal_CompileBase
/**
* Compiles code for the {eval} tag
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
*
* @return string compiled code
*/
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());";
} else {
- $_output .= "echo \$_template->fetch();";
+ $_output .= 'echo $_template->fetch();';
}
-
return "";
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php b/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
index 7ce3dcf6f..d72d2b76f 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_extends.php
@@ -1,5 +1,4 @@
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'], '\'"');
- if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') {
+ $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'])) {
+ $i++;
+ 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,40 +93,66 @@ 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
+ *
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
+ private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler, $template = null)
{
- $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
- "ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n");
+ $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,
+ 'inheritance->endChild($_smarty_tpl' .
+ (isset($template) ?
+ ", {$template}{$inlineUids}" :
+ '') . ");\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
+ *
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- 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('scope' => 'parent'))));
+ $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag(
+ $compiler->parser,
+ $compiler->compileTag(
+ 'include',
+ array(
+ $template,
+ array('scope' => 'parent')
+ )
+ )
+ );
}
/**
* Create source code for {extends} from source components array
*
- * @param []\Smarty_Internal_Template_Source $components
+ * @param \Smarty_Internal_Template $template
*
* @return string
*/
- public static function extendsSourceArrayCode($components)
+ public static function extendsSourceArrayCode(Smarty_Internal_Template $template)
{
$resources = array();
- foreach ($components as $source) {
+ foreach ($template->source->components as $source) {
$resources[] = $source->resource;
}
- return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}';
+ return $template->smarty->left_delimiter . 'extends file=\'extends:' . join('|', $resources) .
+ '\' extends_resource=true' . $template->smarty->right_delimiter;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_for.php b/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
index 7b86d4859..3f113e56d 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_for.php
@@ -26,73 +26,72 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
* The parser is generating different sets of attribute by which this compiler can
* determine which syntax is used.
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
- * @param array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
+ * @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting++;
- if ($parameter == 0) {
+ if ($parameter === 0) {
$this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step');
} else {
$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";
}
$output .= "if (\$_smarty_tpl->tpl_vars[$var]->total > 0) {\n";
$output .= "for (\$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value], \$_smarty_tpl->tpl_vars[$var]->iteration = 1;\$_smarty_tpl->tpl_vars[$var]->iteration <= \$_smarty_tpl->tpl_vars[$var]->total;\$_smarty_tpl->tpl_vars[$var]->value{$index} += \$_smarty_tpl->tpl_vars[$var]->step, \$_smarty_tpl->tpl_vars[$var]->iteration++) {\n";
- $output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration == 1;";
- $output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration == \$_smarty_tpl->tpl_vars[$var]->total;";
+ $output .= "\$_smarty_tpl->tpl_vars[$var]->first = \$_smarty_tpl->tpl_vars[$var]->iteration === 1;";
+ $output .= "\$_smarty_tpl->tpl_vars[$var]->last = \$_smarty_tpl->tpl_vars[$var]->iteration === \$_smarty_tpl->tpl_vars[$var]->total;";
}
- $output .= "?>";
-
+ $output .= '?>';
$this->openTag($compiler, 'for', array('for', $compiler->nocache));
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
@@ -112,9 +111,9 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {forelse} tag
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
- * @param array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
+ * @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@@ -122,10 +121,8 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
-
list($openTag, $nocache) = $this->closeTag($compiler, array('for'));
$this->openTag($compiler, 'forelse', array('forelse', $nocache));
-
return "";
}
}
@@ -141,9 +138,9 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/for} tag
*
- * @param array $args array with attributes from parser
- * @param object $compiler compiler object
- * @param array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @param object $compiler compiler object
+ * @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
@@ -156,14 +153,12 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
-
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
-
$output = "\n";
+ }
+ $output .= "?>";
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..a68da5409 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.
@@ -78,198 +78,197 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
/**
* Compiles code for the {foreach} tag
*
- * @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
*
* @return string compiled code
* @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
- $compiler->loopNesting ++;
+ $compiler->loopNesting++;
// init
$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) {
- $compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
- null, true);
+ if (isset($attributes[ $a ]) && $attributes[ $a ] === $fromName) {
+ $compiler->trigger_template_error(
+ "'{$a}' and 'from' may not have same variable name '{$fromName}'",
+ null,
+ true
+ );
}
}
}
-
$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";
- }
- }
- $this->openTag($compiler, 'foreach',
- array('foreach', $compiler->nocache, $local, $restoreVars, $itemVar, true));
+ $needTotal = isset($itemAttr[ 'total' ]);
+ // Register tag
+ $this->openTag(
+ $compiler,
+ 'foreach',
+ 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 .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
- $output .= "{$itemVar}->_loop = true;\n";
- if (isset($attributes['key']) && isset($itemAttr['key'])) {
+ $output .= "{$itemVar}->do_else = true;\n";
+ $output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
+ $output .= "{$itemVar}->do_else = false;\n";
+ 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 .= "?>";
-
+ $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});";
+ }
}
/**
@@ -283,23 +282,22 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {foreachelse} tag
*
- * @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
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// 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 .= "}\nif ({$itemVar}->do_else) {\n?>";
return $output;
}
}
@@ -315,33 +313,31 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/foreach} tag
*
- * @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
*
* @return string compiled code
+ * @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
- $compiler->loopNesting --;
+ $compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
-
- list($openTag, $compiler->nocache, $local, $restoreVars, $itemVar, $restore) =
- $this->closeTag($compiler, array('foreach', 'foreachelse'));
+ list(
+ $openTag, $compiler->nocache, $local, $itemVar, $restore
+ ) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = "getTagCompiler('foreach');
+ $output .= $foreachCompiler->compileRestore(1);
$output .= "?>";
-
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..d0f2b0f4a 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_function.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_function.php
@@ -16,7 +16,6 @@
*/
class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
{
-
/**
* Attribute definition: Overwrites base class.
*
@@ -44,31 +43,36 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
- * @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
*
* @return bool true
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
- $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();
- $save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
- $compiler->template->caching);
+ unset($_attr[ 'nocache' ]);
+ $_name = trim($_attr[ 'name' ], '\'"');
+
+ if (!preg_match('/^[a-zA-Z0-9_\x80-\xff]+$/', $_name)) {
+ $compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
+ }
+
+ $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);
// Init temporary context
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
+ $compiler->saveRequiredPlugins(true);
return true;
}
}
@@ -81,7 +85,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
*/
class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
{
-
/**
* Compiler object
*
@@ -92,25 +95,22 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/function} tag
*
- * @param array $args array with attributes from parser
- * @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
- * @param array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool true
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
- $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) {
@@ -121,7 +121,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
}
}
if (!empty($_paramsArray)) {
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
+ $_params = 'array(' . implode(',', $_paramsArray) . ')';
$_paramsCode = "\$params = array_merge($_params, \$params);\n";
} else {
$_paramsCode = '';
@@ -129,81 +129,107 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
-
$_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 = "compileRequiredPlugins();
$output .= "\$_smarty_tpl->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}\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 .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
- $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
+ $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}%%*/\";?>";
+ $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 .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\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}\n";
+ $output .= $compiler->compileCheckPlugins(array_merge($compiler->required_plugins[ 'compiled' ],
+ $compiler->required_plugins[ 'nocache' ]));
+ $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 = " \$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) {
- foreach ($tmp as $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->restoreRequiredPlugins();
+ $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)
+ public 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..df3dc3fad 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_if.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_if.php
@@ -33,44 +33,36 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'if', array(1, $compiler->nocache));
// must whole block be nocache ?
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
-
- if (!array_key_exists("if condition", $parameter)) {
- $compiler->trigger_template_error("missing if condition", null, true);
+ if (!isset($parameter[ 'if condition' ])) {
+ $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 "";
@@ -89,18 +81,16 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
/**
* Compiles code for the {else} tag
*
- * @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
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
-
- return "";
+ return '';
}
}
@@ -126,93 +116,60 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
-
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
-
- if (!array_key_exists("if condition", $parameter)) {
- $compiler->trigger_template_error("missing elseif condition", null, true);
+ if (!isset($parameter[ 'if condition' ])) {
+ $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, "");
}
}
}
@@ -229,13 +186,12 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/if} tag
*
- * @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
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
+ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// must endblock be nocache?
if ($compiler->nocache) {
@@ -243,10 +199,9 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
}
list($nesting, $compiler->nocache) = $this->closeTag($compiler, array('if', 'else', 'elseif'));
$tmp = '';
- for ($i = 0; $i < $nesting; $i ++) {
+ for ($i = 0; $i < $nesting; $i++) {
$tmp .= '}';
}
-
return "";
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_include.php b/include/smarty/libs/sysplugins/smarty_internal_compile_include.php
index 09fa11d6c..716c91d49 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,85 +58,68 @@ 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
*
- * @param array $args array with attributes from parser
- * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
- * @param array $parameter array with compilation parameter
+ * @param array $args array with attributes from parser
+ * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
*
- * @throws SmartyCompilerException
- * @return string compiled code
+ * @return string
+ * @throws \Exception
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
+ public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler)
{
+ $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;
}
if (!$variable_template) {
- if ($type != 'string') {
+ 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) {
$_cache_tpl = 'true';
@@ -145,142 +128,133 @@ 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
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
$_caching = self::CACHING_NOCACHE_CODE;
}
-
// 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;
-
- if ($merge_compiled_includes && $_attr['inline'] !== true) {
+ $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr[ 'inline' ] === true) &&
+ !$compiler->template->source->handler->recompiled;
+ 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;
}
}
-
/*
* if the {include} tag provides individual parameter for caching or compile_id
* the subtemplate must not be included into the common cache file and is treated like
* 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';
}
-
// if subtemplate will be called in nocache mode do not merge
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;
- $_output .= substr($compiler->processNocacheCode('\n", true), 6, - 3);
- //$compiler->suppressNocacheProcessing = true;
+ 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);
}
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";
}
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
}
- $_output .= "?>\n";
-
+ $_output .= "?>";
return $_output;
}
-
if ($call_nocache) {
$compiler->tag_nocache = true;
}
@@ -292,14 +266,14 @@ 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";
}
if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
}
- $_output .= "?>\n";
+ $_output .= "?>";
return $_output;
}
@@ -307,57 +281,64 @@ 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
+ * @throws \Exception
+ * @throws \SmartyException
*/
- public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName,
- $_caching, $hashResourceName, $t_hash, $c_id)
- {
- $compiler->smarty->allow_ambiguous_resources = true;
- /* @var Smarty_Internal_Template $tpl */
- $tpl =
- new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template,
- $compiler->template->cache_id, $c_id, $_caching);
+ public function compileInlineTemplate(
+ Smarty_Internal_SmartyTemplateCompiler $compiler,
+ Smarty_Internal_Template $tpl,
+ $t_hash
+ ) {
+ $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 ($tpl->source->type === 'file') {
+ $sourceInfo = $tpl->source->filepath;
+ } else {
+ $basename = $tpl->source->handler->getBasename($tpl->source);
+ $sourceInfo = $tpl->source->type . ':' .
+ ($basename ? $basename : $tpl->source->name);
+ }
// get compiled code
$compiled_code = "source->type}:{$tpl->source->name}\" =============================*/\n";
- $compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
+ $compiled_code .= "/* Start inline template \"{$sourceInfo}\" =============================*/\n";
+ $compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_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 .= "?>";
+ $compiled_code .= "/* End inline template \"{$sourceInfo}\" =============================*/\n";
+ $compiled_code .= '?>';
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code =
- str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
- $compiled_code);
+ str_replace(
+ "{$tpl->compiled->nocache_hash}",
+ $compiler->template->compiled->nocache_hash,
+ $compiled_code
+ );
$compiler->template->compiled->has_nocache_code = true;
}
- $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
+ $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..1b0fdaad3 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_include_php.php
@@ -43,7 +43,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include_php} tag
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string
@@ -57,14 +57,16 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
-
- /** @var Smarty_Internal_Template $_smarty_tpl
+ /**
+ *
+ *
+ * @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_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 {
@@ -74,8 +76,8 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
$_dir = $compiler->smarty->trusted_dir;
}
if (!empty($_dir)) {
- foreach ((array) $_dir as $_script_dir) {
- $_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true);
+ foreach ((array)$_dir as $_script_dir) {
+ $_path = $compiler->smarty->_realpath($_script_dir . DIRECTORY_SEPARATOR . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;
@@ -83,25 +85,22 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
}
}
- if ($_filepath == false) {
+ if ($_filepath === false) {
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
}
-
if (isset($compiler->smarty->security_policy)) {
$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 = '';
}
}
-
if (isset($_assign)) {
return "assign({$_assign},ob_get_clean());\n?>";
} else {
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
index 2ebde1661..4bdc3952e 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_insert.php
@@ -1,5 +1,4 @@
template;
$_name = null;
$_script = null;
-
$_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;
+ foreach ((array)$_dir as $_script_dir) {
+ $_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;
if (file_exists($_script_dir . $_script)) {
$_filepath = $_script_dir . $_script;
break;
@@ -102,14 +101,18 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
}
}
- if ($_filepath == false) {
+ if ($_filepath === false) {
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
}
// code for script file loading
$_output .= "require_once '{$_filepath}' ;";
- require_once $_filepath;
+ include_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 +121,16 @@ 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,14 +145,13 @@ 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 {
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
}
}
-
+ $compiler->template->compiled->has_nocache_code = true;
return $_output;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php b/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
index 8c6b701e1..5493d4ecc 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_ldelim.php
@@ -20,7 +20,7 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
@@ -29,12 +29,9 @@ 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
- $compiler->has_code = true;
-
return $compiler->smarty->left_delimiter;
}
}
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..8a34ccd0a
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_make_nocache.php
@@ -0,0 +1,62 @@
+getAttributes($compiler, $args);
+ if ($compiler->template->caching) {
+ $output = "smarty->ext->_make_nocache->save(\$_smarty_tpl, {$_attr[ 'var' ]});\n?>\n";
+ $compiler->template->compiled->has_nocache_code = true;
+ $compiler->suppressNocacheProcessing = true;
+ return $output;
+ } else {
+ return true;
+ }
+ }
+}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_nocache.php b/include/smarty/libs/sysplugins/smarty_internal_compile_nocache.php
index b29a993aa..12f64ed2e 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_nocache.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_nocache.php
@@ -27,7 +27,7 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
* Compiles code for the {nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
@@ -40,7 +40,6 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
$compiler->nocache = true;
// this tag does not return compiled code
$compiler->has_code = false;
-
return true;
}
}
@@ -57,7 +56,7 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
* Compiles code for the {/nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
- * @param array $args array with attributes from parser
+ * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
@@ -69,7 +68,6 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
list($compiler->nocache) = $this->closeTag($compiler, array('nocache'));
// this tag does not return compiled code
$compiler->has_code = false;
-
return true;
}
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_compile_parent.php b/include/smarty/libs/sysplugins/smarty_internal_compile_parent.php
new file mode 100644
index 000000000..ff23edf73
--- /dev/null
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_parent.php
@@ -0,0 +1,31 @@
+
+ */
+class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
+{
+ /**
+ * Tag name
+ *
+ * @var string
+ */
+ public $tag = 'parent';
+
+ /**
+ * Block type
+ *
+ * @var string
+ */
+ public $blockType = 'Parent';
+}
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..199a296c8 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,66 +24,101 @@ 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
*
- * @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 block plugin
- * @param string $function PHP function name
+ * @param array $parameter array with compilation parameter
+ * @param string $tag name of block plugin
+ * @param string $function PHP function name
*
* @return string compiled code
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- 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;
+ $this->nesting++;
+ unset($_attr[ 'nocache' ]);
+ list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
+ $_params = 'array(' . implode(',', $_paramsArray) . ')';
+ // compile code
+ $output = "nesting} = isset({$callback[0]}) ? {$callback[0]} : null;\n";
+ $callback = "\$_block_plugin{$this->nesting}{$callback[1]}";
}
- 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";
- }
+ if (isset($callable)) {
+ $output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n";
}
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
-
- $this->openTag($compiler, $tag, array($_params, $compiler->nocache));
+ $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();?>";
+ $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));
// 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\']);?>';
}
+ return $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..d3aab24bb 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_foreachsection.php
@@ -16,28 +16,6 @@
*/
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
{
-
- /**
- * Preg search pattern
- *
- * @var string
- */
- private $propertyPreg = '';
-
- /**
- * Offsets in preg match result
- *
- * @var array
- */
- private $resultOffsets = array();
-
- /**
- * Start offset
- *
- * @var int
- */
- private $startOffset = 0;
-
/**
* Name of this tag
*
@@ -71,19 +49,42 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public $matchResults = array();
+ /**
+ * Preg search pattern
+ *
+ * @var string
+ */
+ private $propertyPreg = '';
+
+ /**
+ * Offsets in preg match result
+ *
+ * @var array
+ */
+ private $resultOffsets = array();
+
+ /**
+ * Start offset
+ *
+ * @var int
+ */
+ private $startOffset = 0;
+
/**
* Scan sources for used tag attributes
*
- * @param array $attributes
+ * @param array $attributes
* @param \Smarty_Internal_TemplateCompilerBase $compiler
+ *
+ * @throws \SmartyException
*/
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler)
{
$this->propertyPreg = '~(';
- $this->startOffset = 0;
+ $this->startOffset = 1;
$this->resultOffsets = array();
$this->matchResults = array('named' => array(), 'item' => array());
- if ($this->isNamed) {
+ if (isset($attributes[ 'name' ])) {
$this->buildPropertyPreg(true, $attributes);
}
if (isset($this->itemProperties)) {
@@ -110,18 +111,19 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes)
{
if ($named) {
- $this->resultOffsets['named'] = $this->startOffset + 3;
- $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
+ $this->resultOffsets[ 'named' ] = $this->startOffset = $this->startOffset + 3;
+ $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" .
+ ($this->tagName === 'section' ? "|[\[]\s*" : '') .
+ "){$attributes['name']}[.](";
$properties = $this->nameProperties;
} else {
- $this->resultOffsets['item'] = $this->startOffset + 3;
+ $this->resultOffsets[ 'item' ] = $this->startOffset = $this->startOffset + 2;
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties;
}
- $this->startOffset += count($properties) + 2;
$propName = reset($properties);
while ($propName) {
- $this->propertyPreg .= "({$propName})";
+ $this->propertyPreg .= "{$propName}";
$propName = next($properties);
if ($propName) {
$this->propertyPreg .= '|';
@@ -137,11 +139,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public function matchProperty($source)
{
- preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
+ preg_match_all($this->propertyPreg, $source, $match);
foreach ($this->resultOffsets as $key => $offset) {
- foreach ($match as $m) {
- if (isset($m[$offset]) && !empty($m[$offset])) {
- $this->matchResults[$key][strtolower($m[$offset])] = true;
+ foreach ($match[ $offset ] as $m) {
+ if (!empty($m)) {
+ $this->matchResults[ $key ][ strtolower($m) ] = true;
}
}
}
@@ -161,6 +163,8 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
* Find matches in all parent template source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
+ *
+ * @throws \SmartyException
*/
public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
@@ -171,11 +175,16 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ($compiler !== $nextCompiler) {
// get template source
$_content = $nextCompiler->template->source->getContent();
- if ($_content != '') {
+ 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,15 +199,14 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*/
public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
-
}
/**
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}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
@@ -217,4 +225,4 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$tagVar = "'__smarty_{$tag}_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
}
-}
\ No newline at end of file
+}
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..055823423 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,21 @@ 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
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
- 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) {
@@ -63,10 +59,20 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
$_paramsArray[] = "'$_key'=>$_value";
}
}
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
+ $_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
+ )
+ );
+ }
+ $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..72773fff8 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php
@@ -1,5 +1,4 @@
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) {
+ /* @var string $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 +48,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 (!is_array($function)) {
- $output = "{$function}({$params})";
- } else {
- if (is_object($function[0])) {
- $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
- $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
- } else {
- $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
- }
+ if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
+ if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) {
+ $output =
+ sprintf(
+ 'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
+ Smarty::PLUGIN_MODIFIER,
+ var_export($modifier, true),
+ $params
+ );
+ $compiler->known_modifier_type[ $modifier ] = $type;
+ break 2;
}
- $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;
@@ -75,13 +79,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) ||
- $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
+ if (!is_object($compiler->smarty->security_policy)
+ || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
@@ -89,12 +93,12 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) ||
- $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
+ if (!is_object($compiler->smarty->security_policy)
+ || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$output = "{$function}({$params})";
}
- $compiler->known_modifier_type[$modifier] = $type;
+ $compiler->known_modifier_type[ $modifier ] = $type;
break 2;
}
break;
@@ -102,54 +106,53 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// PHP function
if (is_callable($modifier)) {
// check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) ||
- $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
+ if (!is_object($compiler->smarty->security_policy)
+ || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})";
}
- $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]) ||
- (is_callable($compiler->smarty->default_plugin_handler_func) &&
- $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
+ if (isset($compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])
+ || (is_callable($compiler->smarty->default_plugin_handler_func)
+ && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
- $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
+ $function = $compiler->default_handler_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ];
// check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) ||
- $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
+ if (!is_object($compiler->smarty->security_policy)
+ || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) {
$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->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
+ ||
+ isset($compiler->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])) {
- $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
+ if (!isset($compiler->known_modifier_type[ $modifier ])) {
+ $compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true);
}
}
-
return $output;
}
}
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..baac51b28 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..2a763c6e3 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,31 +27,30 @@ 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
+ * @throws \SmartyCompilerException
+ * @throws \SmartyException
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
- if ($_attr['nocache'] === true) {
- $compiler->tag_nocache = true;
- }
- unset($_attr['nocache']);
+ 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)) {
@@ -60,25 +59,27 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
$_paramsArray[] = "'$_key'=>$_value";
}
}
- $_params = 'array(' . implode(",", $_paramsArray) . ')';
- $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
+ $_params = 'array(' . implode(',', $_paramsArray) . ')';
+ $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})";
+ $_params = implode(',', $_attr);
+ $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)
+ );
}
-
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..ff48c6fbc 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_compile_private_php.php
@@ -16,7 +16,6 @@
*/
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
{
-
/**
* Attribute definition: Overwrites base class.
*
@@ -40,59 +39,87 @@ 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(
+ "\n",
+ true
+ )
+ )
+ );
return '';
}
- if ($_attr['type'] != 'tag') {
- if ($compiler->php_handling == Smarty::PHP_REMOVE) {
+ if ($_attr[ 'type' ] !== 'tag') {
+ if ($compiler->php_handling === Smarty::PHP_REMOVE) {
return '';
- } elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
- $output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(]*>)|(]*>)|(]*>.*?
]*>)#is',
- $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
- foreach ($matches as $match) {
- $store[] = $match[ 0 ][ 0 ];
- $_length = strlen($match[ 0 ][ 0 ]);
- $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
- $text = substr_replace($text, $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',
- '#^\s+<#Ss' => '<',
- '#>\s+$#Ss' => '>',
- $this->stripRegEx => '');
-
- $text = preg_replace(array_keys($expressions), array_values($expressions), $text);
- $_offset = 0;
- if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches,
- PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
- foreach ($matches as $match) {
- $_length = strlen($match[ 0 ][ 0 ]);
- $replace = $store[ $match[ 1 ][ 0 ] ];
- $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
-
- $_offset += strlen($replace) - $_length;
- $_store ++;
- }
- }
- } else {
- $text = preg_replace($this->stripRegEx, '', $text);
- }
- }
- return new Smarty_Internal_ParseTree_Text($text);
+ if (strpos($text, '<') === false) {
+ return preg_replace($this->stripRegEx, '', $text);
}
- return null;
+
+ $store = array();
+ $_store = 0;
+
+ // capture html elements not to be messed with
+ $_offset = 0;
+ if (preg_match_all(
+ '#(]*>)|(]*>)|(]*>.*?
]*>)#is',
+ $text,
+ $matches,
+ PREG_OFFSET_CAPTURE | PREG_SET_ORDER
+ )
+ ) {
+ foreach ($matches as $match) {
+ $store[] = $match[ 0 ][ 0 ];
+ $_length = strlen($match[ 0 ][ 0 ]);
+ $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
+ $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
+ $_offset += $_length - strlen($replace);
+ $_store++;
+ }
+ }
+ $expressions = array(// replace multiple spaces between tags by a single space
+ '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2',
+ // remove newline between tags
+ '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2',
+ // remove multiple spaces between attributes (but not in attribute values!)
+ '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
+ '#>[\040\011]+$#Ss' => '> ',
+ '#>[\040\011]*[\n]\s*$#Ss' => '>',
+ $this->stripRegEx => '',
+ );
+ $text = preg_replace(array_keys($expressions), array_values($expressions), $text);
+ $_offset = 0;
+ if (preg_match_all(
+ '#@!@SMARTY:([0-9]+):SMARTY@!@#is',
+ $text,
+ $matches,
+ PREG_OFFSET_CAPTURE | PREG_SET_ORDER
+ )
+ ) {
+ foreach ($matches as $match) {
+ $_length = strlen($match[ 0 ][ 0 ]);
+ $replace = $store[ $match[ 1 ][ 0 ] ];
+ $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
+ $_offset += strlen($replace) - $_length;
+ $_store++;
+ }
+ }
+ return $text;
}
/**
@@ -842,154 +751,174 @@ abstract class Smarty_Internal_TemplateCompilerBase
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_TagName.php
*
- * @param string $tag tag name
- * @param array $args list of tag attributes
- * @param mixed $param1 optional parameter
- * @param mixed $param2 optional parameter
- * @param mixed $param3 optional parameter
+ * @param string $tag tag name
+ * @param array $args list of tag attributes
+ * @param mixed $param1 optional parameter
+ * @param mixed $param2 optional parameter
+ * @param mixed $param3 optional parameter
*
- * @return string compiled code
+ * @return bool|string compiled code or false
+ * @throws \SmartyCompilerException
*/
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
+ {
+ /* @var Smarty_Internal_CompileBase $tagCompiler */
+ $tagCompiler = $this->getTagCompiler($tag);
+ // compile this tag
+ return $tagCompiler === false ? false : $tagCompiler->compile($args, $this, $param1, $param2, $param3);
+ }
+
+ /**
+ * lazy loads internal compile plugin for tag compile objects cached for reuse.
+ *
+ * class name format: Smarty_Internal_Compile_TagName
+ * plugin filename format: Smarty_Internal_TagName.php
+ *
+ * @param string $tag tag name
+ *
+ * @return bool|\Smarty_Internal_CompileBase tag compiler object or false if not found
+ */
+ public function getTagCompiler($tag)
{
// re-use object if already exists
- if (!isset($this->_tag_objects[ $tag ])) {
+ if (!isset(self::$_tag_objects[ $tag ])) {
// lazy load internal compiler plugin
$_tag = explode('_', $tag);
$_tag = array_map('ucfirst', $_tag);
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
- if (class_exists($class_name) &&
- (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
+ if (class_exists($class_name)
+ && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
) {
- $this->_tag_objects[ $tag ] = new $class_name;
+ self::$_tag_objects[ $tag ] = new $class_name;
} else {
- $this->_tag_objects[ $tag ] = false;
- return false;
+ self::$_tag_objects[ $tag ] = false;
}
}
- // compile this tag
- return $this->_tag_objects[ $tag ] === false ? false :
- $this->_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3);
+ return self::$_tag_objects[ $tag ];
}
/**
* Check for plugins and return function name
*
- * @param $plugin_name
- * @param string $plugin_type type of plugin
+ * @param $plugin_name
+ * @param string $plugin_type type of plugin
*
* @return string call name of function
+ * @throws \SmartyException
*/
public function getPlugin($plugin_name, $plugin_type)
{
$function = null;
- if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
+ if ($this->caching && ($this->nocache || $this->tag_nocache)) {
+ if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
+ } elseif (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
}
} else {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
+ if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$function =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
+ } elseif (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
}
}
if (isset($function)) {
- if ($plugin_type == 'modifier') {
+ if ($plugin_type === 'modifier') {
$this->modifier_plugins[ $plugin_name ] = true;
}
-
return $function;
}
// loop through plugin dirs and find the plugin
$function = 'smarty_' . $plugin_type . '_' . $plugin_name;
$file = $this->smarty->loadPlugin($function, false);
-
if (is_string($file)) {
- if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
+ if ($this->caching && ($this->nocache || $this->tag_nocache)) {
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
} else {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
}
- if ($plugin_type == 'modifier') {
+ if ($plugin_type === 'modifier') {
$this->modifier_plugins[ $plugin_name ] = true;
}
-
return $function;
}
if (is_callable($function)) {
// plugin function is defined in the script
return $function;
}
-
return false;
}
/**
* Check for plugins by default plugin handler
*
- * @param string $tag name of tag
- * @param string $plugin_type type of plugin
+ * @param string $tag name of tag
+ * @param string $plugin_type type of plugin
*
- * @return boolean true if found
+ * @return bool true if found
+ * @throws \SmartyCompilerException
*/
public function getPluginFromDefaultHandler($tag, $plugin_type)
{
$callback = null;
$script = null;
$cacheable = true;
- $result = call_user_func_array($this->smarty->default_plugin_handler_func,
- array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
+ $result = call_user_func_array(
+ $this->smarty->default_plugin_handler_func,
+ array(
+ $tag,
+ $plugin_type,
+ $this->template,
+ &$callback,
+ &$script,
+ &$cacheable,
+ )
+ );
if ($result) {
$this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) {
if (is_file($script)) {
- if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
+ if ($this->caching && ($this->nocache || $this->tag_nocache)) {
+ $this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
+ $this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
} else {
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
+ $this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
+ $this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
}
- require_once $script;
+ include_once $script;
} else {
- $this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
+ $this->trigger_template_error("Default plugin handler: Returned script file '{$script}' for '{$tag}' not found");
}
}
- if (!is_string($callback) &&
- !(is_array($callback) && is_string($callback[ 0 ]) && is_string($callback[ 1 ]))
- ) {
- $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name");
- }
if (is_callable($callback)) {
- $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array());
-
+ $this->default_handler_plugins[ $plugin_type ][ $tag ] = array(
+ $callback,
+ true,
+ array()
+ );
return true;
} else {
- $this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" not callable");
+ $this->trigger_template_error("Default plugin handler: Returned callback for '{$tag}' not callable");
}
}
-
return false;
}
@@ -1003,9 +932,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function appendCode($left, $right)
{
- if (preg_match('/\s*\?>\s*$/', $left) && preg_match('/^\s*<\?php\s+/', $right)) {
- $left = preg_replace('/\s*\?>\s*$/', "\n", $left);
- $left .= preg_replace('/^\s*<\?php\s+/', '', $right);
+ if (preg_match('/\s*\?>\s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) {
+ $left = preg_replace('/\s*\?>\s?$/D', "\n", $left);
+ $left .= preg_replace('/^<\?php\s+/', '', $right);
} else {
$left .= $right;
}
@@ -1018,8 +947,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
* If the content is compiled code and it should be not cached the code is injected
* into the rendered output.
*
- * @param string $content content of template element
- * @param boolean $is_code true if content is compiled code
+ * @param string $content content of template element
+ * @param boolean $is_code true if content is compiled code
*
* @return string content
*/
@@ -1028,19 +957,19 @@ abstract class Smarty_Internal_TemplateCompilerBase
// If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) {
// generate replacement code
- if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching &&
- !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
+ if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->caching
+ && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
) {
$this->template->compiled->has_nocache_code = true;
$_output = addcslashes($content, '\'\\');
- $_output = str_replace("^#^", "'", $_output);
- $_output = "nocache_hash}%%*/" . $_output .
- "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
+ $_output = str_replace('^#^', '\'', $_output);
+ $_output =
+ "nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
// make sure we include modifier plugins for nocache code
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
- if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
- $this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
- $this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
+ if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
+ $this->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
+ $this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
}
}
} else {
@@ -1052,7 +981,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->modifier_plugins = array();
$this->suppressNocacheProcessing = false;
$this->tag_nocache = false;
-
return $_output;
}
@@ -1065,8 +993,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function getId($input)
{
- if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) {
- return $match[ 1 ];
+ if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) {
+ return $match[ 2 ];
}
return false;
}
@@ -1086,6 +1014,52 @@ abstract class Smarty_Internal_TemplateCompilerBase
return false;
}
+ /**
+ * Set nocache flag in variable or create new variable
+ *
+ * @param string $varName
+ */
+ public function setNocacheInVariable($varName)
+ {
+ // create nocache var to make it know for further compiling
+ if ($_var = $this->getId($varName)) {
+ if (isset($this->template->tpl_vars[ $_var ])) {
+ $this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ];
+ $this->template->tpl_vars[ $_var ]->nocache = true;
+ } else {
+ $this->template->tpl_vars[ $_var ] = new Smarty_Variable(null, true);
+ }
+ }
+ }
+
+ /**
+ * @param array $_attr tag attributes
+ * @param array $validScopes
+ *
+ * @return int|string
+ * @throws \SmartyCompilerException
+ */
+ public function convertScope($_attr, $validScopes)
+ {
+ $_scope = 0;
+ if (isset($_attr[ 'scope' ])) {
+ $_scopeName = trim($_attr[ 'scope' ], '\'"');
+ if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) {
+ $_scope = $_scopeName;
+ } elseif (is_string($_scopeName)) {
+ $_scopeName = trim($_scopeName, '\'"');
+ $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false;
+ } else {
+ $_scope = false;
+ }
+ if ($_scope === false) {
+ $err = var_export($_scopeName, true);
+ $this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true);
+ }
+ }
+ return $_scope;
+ }
+
/**
* Generate nocache code string
*
@@ -1096,7 +1070,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function makeNocacheCode($code)
{
return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*//*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
+ str_replace('^#^', '\'', addcslashes($code, '\'\\')) .
+ "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
}
/**
@@ -1105,8 +1080,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
* In this case the parser is called to obtain information about expected tokens.
* If parameter $args contains a string this is used as error message
*
- * @param string $args individual error message or null
- * @param string $line line-number
+ * @param string $args individual error message or null
+ * @param string $line line-number
* @param null|bool $tagline if true the line number of last tag
*
* @throws \SmartyCompilerException when an unexpected token is found
@@ -1121,18 +1096,28 @@ abstract class Smarty_Internal_TemplateCompilerBase
// get template source line which has error
$line = $lex->line;
} else {
- $line = (int) $line;
+ $line = (int)$line;
}
-
- if (in_array($this->template->source->type, array('eval', 'string'))) {
- $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ',
- strlen($lex->data) > 40 ?
- substr($lex->data, 0, 40) .
- '...' : $lex->data));
+ if (in_array(
+ $this->template->source->type,
+ array(
+ 'eval',
+ 'string'
+ )
+ )
+ ) {
+ $templateName = $this->template->source->type . ':' . trim(
+ preg_replace(
+ '![\t\r\n]+!',
+ ' ',
+ strlen($lex->data) > 40 ?
+ substr($lex->data, 0, 40) .
+ '...' : $lex->data
+ )
+ );
} else {
$templateName = $this->template->source->type . ':' . $this->template->source->filepath;
}
-
// $line += $this->trace_line_offset;
$match = preg_split("/\n/", $lex->data);
$error_text =
@@ -1160,6 +1145,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
$error_text .= ', expected one of: ' . implode(' , ', $expect);
}
}
+ if ($this->smarty->_parserdebug) {
+ $this->parser->errorRunDown();
+ echo ob_get_clean();
+ flush();
+ }
$e = new SmartyCompilerException($error_text);
$e->line = $line;
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
@@ -1167,4 +1157,604 @@ abstract class Smarty_Internal_TemplateCompilerBase
$e->template = $this->template->source->filepath;
throw $e;
}
+
+ /**
+ * Return var_export() value with all white spaces removed
+ *
+ * @param mixed $value
+ *
+ * @return string
+ */
+ public function getVarExport($value)
+ {
+ return preg_replace('/\s/', '', var_export($value, true));
+ }
+
+ /**
+ * enter double quoted string
+ * - save tag stack count
+ */
+ public function enterDoubleQuote()
+ {
+ array_push($this->_tag_stack_count, $this->getTagStackCount());
+ }
+
+ /**
+ * Return tag stack count
+ *
+ * @return int
+ */
+ public function getTagStackCount()
+ {
+ return count($this->_tag_stack);
+ }
+
+ /**
+ * @param $lexerPreg
+ *
+ * @return mixed
+ */
+ public function replaceDelimiter($lexerPreg)
+ {
+ return str_replace(
+ array('SMARTYldel', 'SMARTYliteral', 'SMARTYrdel', 'SMARTYautoliteral', 'SMARTYal'),
+ array(
+ $this->ldelPreg, $this->literalPreg, $this->rdelPreg,
+ $this->smarty->getAutoLiteral() ? '{1,}' : '{9}',
+ $this->smarty->getAutoLiteral() ? '' : '\\s*'
+ ),
+ $lexerPreg
+ );
+ }
+
+ /**
+ * Build lexer regular expressions for left and right delimiter and user defined literals
+ */
+ public function initDelimiterPreg()
+ {
+ $ldel = $this->smarty->getLeftDelimiter();
+ $this->ldelLength = strlen($ldel);
+ $this->ldelPreg = '';
+ foreach (str_split($ldel, 1) as $chr) {
+ $this->ldelPreg .= '[' . preg_quote($chr,'/') . ']';
+ }
+ $rdel = $this->smarty->getRightDelimiter();
+ $this->rdelLength = strlen($rdel);
+ $this->rdelPreg = '';
+ foreach (str_split($rdel, 1) as $chr) {
+ $this->rdelPreg .= '[' . preg_quote($chr,'/') . ']';
+ }
+ $literals = $this->smarty->getLiterals();
+ if (!empty($literals)) {
+ foreach ($literals as $key => $literal) {
+ $literalPreg = '';
+ foreach (str_split($literal, 1) as $chr) {
+ $literalPreg .= '[' . preg_quote($chr,'/') . ']';
+ }
+ $literals[ $key ] = $literalPreg;
+ }
+ $this->literalPreg = '|' . implode('|', $literals);
+ } else {
+ $this->literalPreg = '';
+ }
+ }
+
+ /**
+ * leave double quoted string
+ * - throw exception if block in string was not closed
+ *
+ * @throws \SmartyCompilerException
+ */
+ public function leaveDoubleQuote()
+ {
+ if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) {
+ $tag = $this->getOpenBlockTag();
+ $this->trigger_template_error(
+ "unclosed '{{$tag}}' in doubled quoted string",
+ null,
+ true
+ );
+ }
+ }
+
+ /**
+ * Get left delimiter preg
+ *
+ * @return string
+ */
+ public function getLdelPreg()
+ {
+ return $this->ldelPreg;
+ }
+
+ /**
+ * Get right delimiter preg
+ *
+ * @return string
+ */
+ public function getRdelPreg()
+ {
+ return $this->rdelPreg;
+ }
+
+ /**
+ * Get length of left delimiter
+ *
+ * @return int
+ */
+ public function getLdelLength()
+ {
+ return $this->ldelLength;
+ }
+
+ /**
+ * Get length of right delimiter
+ *
+ * @return int
+ */
+ public function getRdelLength()
+ {
+ return $this->rdelLength;
+ }
+
+ /**
+ * Get name of current open block tag
+ *
+ * @return string|boolean
+ */
+ public function getOpenBlockTag()
+ {
+ $tagCount = $this->getTagStackCount();
+ if ($tagCount) {
+ return $this->_tag_stack[ $tagCount - 1 ][ 0 ];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Check if $value contains variable elements
+ *
+ * @param mixed $value
+ *
+ * @return bool|int
+ */
+ public function isVariable($value)
+ {
+ if (is_string($value)) {
+ return preg_match('/[$(]/', $value);
+ }
+ if (is_bool($value) || is_numeric($value)) {
+ return false;
+ }
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ if ($this->isVariable($k) || $this->isVariable($v)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return false;
+ }
+
+ /**
+ * Get new prefix variable name
+ *
+ * @return string
+ */
+ public function getNewPrefixVariable()
+ {
+ ++self::$prefixVariableNumber;
+ return $this->getPrefixVariable();
+ }
+
+ /**
+ * Get current prefix variable name
+ *
+ * @return string
+ */
+ public function getPrefixVariable()
+ {
+ return '$_prefixVariable' . self::$prefixVariableNumber;
+ }
+
+ /**
+ * append code to prefix buffer
+ *
+ * @param string $code
+ */
+ public function appendPrefixCode($code)
+ {
+ $this->prefix_code[] = $code;
+ }
+
+ /**
+ * get prefix code string
+ *
+ * @return string
+ */
+ public function getPrefixCode()
+ {
+ $code = '';
+ $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
+ $this->prefixCodeStack[] = array();
+ foreach ($prefixArray as $c) {
+ $code = $this->appendCode($code, $c);
+ }
+ $this->prefix_code = array();
+ return $code;
+ }
+
+ /**
+ * Save current required plugins
+ *
+ * @param bool $init if true init required plugins
+ */
+ public function saveRequiredPlugins($init = false)
+ {
+ $this->required_plugins_stack[] = $this->required_plugins;
+ if ($init) {
+ $this->required_plugins = array('compiled' => array(), 'nocache' => array());
+ }
+ }
+
+ /**
+ * Restore required plugins
+ */
+ public function restoreRequiredPlugins()
+ {
+ $this->required_plugins = array_pop($this->required_plugins_stack);
+ }
+
+ /**
+ * Compile code to call Smarty_Internal_Template::_checkPlugins()
+ * for required plugins
+ *
+ * @return string
+ */
+ public function compileRequiredPlugins()
+ {
+ $code = $this->compileCheckPlugins($this->required_plugins[ 'compiled' ]);
+ if ($this->caching && !empty($this->required_plugins[ 'nocache' ])) {
+ $code .= $this->makeNocacheCode($this->compileCheckPlugins($this->required_plugins[ 'nocache' ]));
+ }
+ return $code;
+ }
+
+ /**
+ * Compile code to call Smarty_Internal_Template::_checkPlugins
+ * - checks if plugin is callable require otherwise
+ *
+ * @param $requiredPlugins
+ *
+ * @return string
+ */
+ public function compileCheckPlugins($requiredPlugins)
+ {
+ if (!empty($requiredPlugins)) {
+ $plugins = array();
+ foreach ($requiredPlugins as $plugin) {
+ foreach ($plugin as $data) {
+ $plugins[] = $data;
+ }
+ }
+ return '$_smarty_tpl->_checkPlugins(' . $this->getVarExport($plugins) . ');' . "\n";
+ } else {
+ return '';
+ }
+ }
+
+ /**
+ * method to compile a Smarty template
+ *
+ * @param mixed $_content template source
+ * @param bool $isTemplateSource
+ *
+ * @return bool true if compiling succeeded, false if it failed
+ */
+ abstract protected function doCompile($_content, $isTemplateSource = false);
+
+ /**
+ * Compile Tag
+ *
+ * @param string $tag tag name
+ * @param array $args array with tag attributes
+ * @param array $parameter array with compilation parameter
+ *
+ * @throws SmartyCompilerException
+ * @throws SmartyException
+ * @return string compiled code
+ */
+ private function compileTag2($tag, $args, $parameter)
+ {
+ $plugin_type = '';
+ // $args contains the attributes parsed and compiled by the lexer/parser
+ // assume that tag does compile into code, but creates no HTML output
+ $this->has_code = true;
+ // log tag/attributes
+ if (isset($this->smarty->_cache[ 'get_used_tags' ])) {
+ $this->template->_cache[ 'used_tags' ][] = array(
+ $tag,
+ $args
+ );
+ }
+ // check nocache option flag
+ foreach ($args as $arg) {
+ if (!is_array($arg)) {
+ if ($arg === "'nocache'" || $arg === 'nocache') {
+ $this->tag_nocache = true;
+ }
+ } else {
+ foreach ($arg as $k => $v) {
+ if (($k === "'nocache'" || $k === 'nocache') && (trim($v, "'\" ") === 'true')) {
+ $this->tag_nocache = true;
+ }
+ }
+ }
+ }
+ // compile the smarty tag (required compile classes to compile the tag are auto loaded)
+ if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
+ if (isset($this->parent_compiler->tpl_function[ $tag ])
+ || (isset($this->template->smarty->ext->_tplFunction)
+ && $this->template->smarty->ext->_tplFunction->getTplFunction($this->template, $tag) !== false)
+ ) {
+ // template defined by {template} tag
+ $args[ '_attr' ][ 'name' ] = "'{$tag}'";
+ $_output = $this->callTagCompiler('call', $args, $parameter);
+ }
+ }
+ if ($_output !== false) {
+ if ($_output !== true) {
+ // did we get compiled code
+ if ($this->has_code) {
+ // return compiled code
+ return $_output;
+ }
+ }
+ // tag did not produce compiled code
+ return null;
+ } else {
+ // map_named attributes
+ if (isset($args[ '_attr' ])) {
+ foreach ($args[ '_attr' ] as $key => $attribute) {
+ if (is_array($attribute)) {
+ $args = array_merge($args, $attribute);
+ }
+ }
+ }
+ // not an internal compiler tag
+ if (strlen($tag) < 6 || substr($tag, -5) !== 'close') {
+ // check if tag is a registered object
+ if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) {
+ $method = $parameter[ 'object_method' ];
+ if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])
+ && (empty($this->smarty->registered_objects[ $tag ][ 1 ])
+ || in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
+ ) {
+ return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
+ } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
+ return $this->callTagCompiler(
+ 'private_object_block_function',
+ $args,
+ $parameter,
+ $tag,
+ $method
+ );
+ } else {
+ // throw exception
+ $this->trigger_template_error(
+ 'not allowed method "' . $method . '" in registered object "' .
+ $tag . '"',
+ null,
+ true
+ );
+ }
+ }
+ // check if tag is registered
+ foreach (array(
+ Smarty::PLUGIN_COMPILER,
+ Smarty::PLUGIN_FUNCTION,
+ Smarty::PLUGIN_BLOCK,
+ ) as $plugin_type) {
+ if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) {
+ // if compiler function plugin call it now
+ if ($plugin_type === Smarty::PLUGIN_COMPILER) {
+ $new_args = array();
+ foreach ($args as $key => $mixed) {
+ if (is_array($mixed)) {
+ $new_args = array_merge($new_args, $mixed);
+ } else {
+ $new_args[ $key ] = $mixed;
+ }
+ }
+ if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) {
+ $this->tag_nocache = true;
+ }
+ return call_user_func_array(
+ $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ],
+ array(
+ $new_args,
+ $this
+ )
+ );
+ }
+ // compile registered function or block function
+ if ($plugin_type === Smarty::PLUGIN_FUNCTION || $plugin_type === Smarty::PLUGIN_BLOCK) {
+ return $this->callTagCompiler(
+ 'private_registered_' . $plugin_type,
+ $args,
+ $parameter,
+ $tag
+ );
+ }
+ }
+ }
+ // check plugins from plugins folder
+ foreach ($this->plugin_search_order as $plugin_type) {
+ if ($plugin_type === Smarty::PLUGIN_COMPILER
+ && $this->smarty->loadPlugin('smarty_compiler_' . $tag)
+ && (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this))
+ ) {
+ $plugin = 'smarty_compiler_' . $tag;
+ if (is_callable($plugin)) {
+ // convert arguments format for old compiler plugins
+ $new_args = array();
+ foreach ($args as $key => $mixed) {
+ if (is_array($mixed)) {
+ $new_args = array_merge($new_args, $mixed);
+ } else {
+ $new_args[ $key ] = $mixed;
+ }
+ }
+ return $plugin($new_args, $this->smarty);
+ }
+ if (class_exists($plugin, false)) {
+ $plugin_object = new $plugin;
+ if (method_exists($plugin_object, 'compile')) {
+ return $plugin_object->compile($args, $this);
+ }
+ }
+ throw new SmartyException("Plugin '{$tag}' not callable");
+ } else {
+ if ($function = $this->getPlugin($tag, $plugin_type)) {
+ if (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this)
+ ) {
+ return $this->callTagCompiler(
+ 'private_' . $plugin_type . '_plugin',
+ $args,
+ $parameter,
+ $tag,
+ $function
+ );
+ }
+ }
+ }
+ }
+ if (is_callable($this->smarty->default_plugin_handler_func)) {
+ $found = false;
+ // look for already resolved tags
+ foreach ($this->plugin_search_order as $plugin_type) {
+ if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) {
+ $found = true;
+ break;
+ }
+ }
+ if (!$found) {
+ // call default handler
+ foreach ($this->plugin_search_order as $plugin_type) {
+ if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) {
+ $found = true;
+ break;
+ }
+ }
+ }
+ if ($found) {
+ // if compiler function plugin call it now
+ if ($plugin_type === Smarty::PLUGIN_COMPILER) {
+ $new_args = array();
+ foreach ($args as $key => $mixed) {
+ if (is_array($mixed)) {
+ $new_args = array_merge($new_args, $mixed);
+ } else {
+ $new_args[ $key ] = $mixed;
+ }
+ }
+ return call_user_func_array(
+ $this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ],
+ array(
+ $new_args,
+ $this
+ )
+ );
+ } else {
+ return $this->callTagCompiler(
+ 'private_registered_' . $plugin_type,
+ $args,
+ $parameter,
+ $tag
+ );
+ }
+ }
+ }
+ } else {
+ // compile closing tag of block function
+ $base_tag = substr($tag, 0, -5);
+ // check if closing tag is a registered object
+ if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) {
+ $method = $parameter[ 'object_method' ];
+ if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) {
+ return $this->callTagCompiler(
+ 'private_object_block_function',
+ $args,
+ $parameter,
+ $tag,
+ $method
+ );
+ } else {
+ // throw exception
+ $this->trigger_template_error(
+ 'not allowed closing tag method "' . $method .
+ '" in registered object "' . $base_tag . '"',
+ null,
+ true
+ );
+ }
+ }
+ // registered block tag ?
+ if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
+ || isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
+ ) {
+ return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
+ }
+ // registered function tag ?
+ if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
+ return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag);
+ }
+ // block plugin?
+ if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
+ return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
+ }
+ // function plugin?
+ if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) {
+ if (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this)
+ ) {
+ return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function);
+ }
+ }
+ // registered compiler plugin ?
+ if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) {
+ // if compiler function plugin call it now
+ $args = array();
+ if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) {
+ $this->tag_nocache = true;
+ }
+ return call_user_func_array(
+ $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ],
+ array(
+ $args,
+ $this
+ )
+ );
+ }
+ if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
+ $plugin = 'smarty_compiler_' . $tag;
+ if (is_callable($plugin)) {
+ return $plugin($args, $this->smarty);
+ }
+ if (class_exists($plugin, false)) {
+ $plugin_object = new $plugin;
+ if (method_exists($plugin_object, 'compile')) {
+ return $plugin_object->compile($args, $this);
+ }
+ }
+ throw new SmartyException("Plugin '{$tag}' not callable");
+ }
+ }
+ $this->trigger_template_error("unknown tag '{$tag}'", null, true);
+ }
+ }
}
diff --git a/include/smarty/libs/sysplugins/smarty_internal_templatelexer.php b/include/smarty/libs/sysplugins/smarty_internal_templatelexer.php
index 993b7be62..867a31d26 100644
--- a/include/smarty/libs/sysplugins/smarty_internal_templatelexer.php
+++ b/include/smarty/libs/sysplugins/smarty_internal_templatelexer.php
@@ -18,6 +18,12 @@
*/
class Smarty_Internal_Templatelexer
{
+ const TEXT = 1;
+ const TAG = 2;
+ const TAGBODY = 3;
+ const LITERAL = 4;
+ const DOUBLEQUOTEDSTRING = 5;
+
/**
* Source
*
@@ -25,6 +31,13 @@ class Smarty_Internal_Templatelexer
*/
public $data;
+ /**
+ * Source length
+ *
+ * @var int
+ */
+ public $dataLength = null;
+
/**
* byte counter
*
@@ -67,34 +80,6 @@ class Smarty_Internal_Templatelexer
*/
public $phpType = '';
- /**
- * escaped left delimiter
- *
- * @var string
- */
- public $ldel = '';
-
- /**
- * escaped left delimiter length
- *
- * @var int
- */
- public $ldel_length = 0;
-
- /**
- * escaped right delimiter
- *
- * @var string
- */
- public $rdel = '';
-
- /**
- * escaped right delimiter length
- *
- * @var int
- */
- public $rdel_length = 0;
-
/**
* state number
*
@@ -116,19 +101,6 @@ class Smarty_Internal_Templatelexer
*/
public $compiler = null;
- /**
- * literal tag nesting level
- *
- * @var int
- */
- private $literal_cnt = 0;
-
- /**
- * PHP start tag string
- *
- * @var string
- */
-
/**
* trace file
*
@@ -157,85 +129,164 @@ class Smarty_Internal_Templatelexer
*/
public $state_name = array(1 => 'TEXT', 2 => 'TAG', 3 => 'TAGBODY', 4 => 'LITERAL', 5 => 'DOUBLEQUOTEDSTRING',);
- /**
- * storage for assembled token patterns
- *
- * @var string
- */
- private $yy_global_pattern1 = null;
-
- private $yy_global_pattern2 = null;
-
- private $yy_global_pattern3 = null;
-
- private $yy_global_pattern4 = null;
-
- private $yy_global_pattern5 = null;
-
/**
* token names
*
* @var array
*/
public $smarty_token_names = array( // Text for parser error messages
- 'NOT' => '(!,not)', 'OPENP' => '(', 'CLOSEP' => ')',
- 'OPENB' => '[', 'CLOSEB' => ']', 'PTR' => '->', 'APTR' => '=>',
- 'EQUAL' => '=', 'NUMBER' => 'number', 'UNIMATH' => '+" , "-',
- 'MATH' => '*" , "/" , "%', 'INCDEC' => '++" , "--',
- 'SPACE' => ' ', 'DOLLAR' => '$', 'SEMICOLON' => ';',
- 'COLON' => ':', 'DOUBLECOLON' => '::', 'AT' => '@', 'HATCH' => '#',
- 'QUOTE' => '"', 'BACKTICK' => '`', 'VERT' => '"|" modifier',
- 'DOT' => '.', 'COMMA' => '","', 'QMARK' => '"?"',
- 'ID' => 'id, name', 'TEXT' => 'text',
- 'LDELSLASH' => '{/..} closing tag', 'LDEL' => '{...} Smarty tag',
- 'COMMENT' => 'comment', 'AS' => 'as', 'TO' => 'to',
+ 'NOT' => '(!,not)',
+ 'OPENP' => '(',
+ 'CLOSEP' => ')',
+ 'OPENB' => '[',
+ 'CLOSEB' => ']',
+ 'PTR' => '->',
+ 'APTR' => '=>',
+ 'EQUAL' => '=',
+ 'NUMBER' => 'number',
+ 'UNIMATH' => '+" , "-',
+ 'MATH' => '*" , "/" , "%',
+ 'INCDEC' => '++" , "--',
+ 'SPACE' => ' ',
+ 'DOLLAR' => '$',
+ 'SEMICOLON' => ';',
+ 'COLON' => ':',
+ 'DOUBLECOLON' => '::',
+ 'AT' => '@',
+ 'HATCH' => '#',
+ 'QUOTE' => '"',
+ 'BACKTICK' => '`',
+ 'VERT' => '"|" modifier',
+ 'DOT' => '.',
+ 'COMMA' => '","',
+ 'QMARK' => '"?"',
+ 'ID' => 'id, name',
+ 'TEXT' => 'text',
+ 'LDELSLASH' => '{/..} closing tag',
+ 'LDEL' => '{...} Smarty tag',
+ 'COMMENT' => 'comment',
+ 'AS' => 'as',
+ 'TO' => 'to',
'PHP' => '" '"<", "==" ... logical operator',
'TLOGOP' => '"lt", "eq" ... logical operator; "is div by" ... if condition',
- 'SCOND' => '"is even" ... if condition',);
+ 'SCOND' => '"is even" ... if condition',
+ );
+
+ /**
+ * literal tag nesting level
+ *
+ * @var int
+ */
+ private $literal_cnt = 0;
+
+ /**
+ * preg token pattern for state TEXT
+ *
+ * @var string
+ */
+ private $yy_global_pattern1 = null;
+
+ /**
+ * preg token pattern for state TAG
+ *
+ * @var string
+ */
+ private $yy_global_pattern2 = null;
+
+ /**
+ * preg token pattern for state TAGBODY
+ *
+ * @var string
+ */
+ private $yy_global_pattern3 = null;
+
+ /**
+ * preg token pattern for state LITERAL
+ *
+ * @var string
+ */
+ private $yy_global_pattern4 = null;
+
+ /**
+ * preg token pattern for state DOUBLEQUOTEDSTRING
+ *
+ * @var null
+ */
+ private $yy_global_pattern5 = null;
+
+ /**
+ * preg token pattern for text
+ *
+ * @var null
+ */
+ private $yy_global_text = null;
+
+ /**
+ * preg token pattern for literal
+ *
+ * @var null
+ */
+ private $yy_global_literal = null;
+
+ private $_yy_state = 1;
+
+ private $_yy_stack = array();
/**
* constructor
*
- * @param string $data template source
+ * @param string $source template source
* @param Smarty_Internal_TemplateCompilerBase $compiler
*/
- function __construct($data, Smarty_Internal_TemplateCompilerBase $compiler)
+ public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler)
{
- $this->data = $data;
+ $this->data = $source;
+ $this->dataLength = strlen($this->data);
$this->counter = 0;
- if (preg_match('~^\xEF\xBB\xBF~i', $this->data, $match)) {
+ if (preg_match('/^\xEF\xBB\xBF/i', $this->data, $match)) {
$this->counter += strlen($match[ 0 ]);
}
$this->line = 1;
- $this->smarty = $compiler->smarty;
+ $this->smarty = $compiler->template->smarty;
$this->compiler = $compiler;
- $this->ldel = preg_quote($this->smarty->left_delimiter, '~');
- $this->ldel_length = strlen($this->smarty->left_delimiter);
- $this->rdel = preg_quote($this->smarty->right_delimiter, '~');
- $this->rdel_length = strlen($this->smarty->right_delimiter);
- $this->smarty_token_names[ 'LDEL' ] = $this->smarty->left_delimiter;
- $this->smarty_token_names[ 'RDEL' ] = $this->smarty->right_delimiter;
+ $this->compiler->initDelimiterPreg();
+ $this->smarty_token_names[ 'LDEL' ] = $this->smarty->getLeftDelimiter();
+ $this->smarty_token_names[ 'RDEL' ] = $this->smarty->getRightDelimiter();
}
+ /**
+ * open lexer/parser trace file
+ *
+ */
public function PrintTrace()
{
$this->yyTraceFILE = fopen('php://output', 'w');
$this->yyTracePrompt = '
';
}
- /*
- * Check if this tag is autoliteral
+ /**
+ * replace placeholders with runtime preg code
+ *
+ * @param string $preg
+ *
+ * @return string
+ */
+ public function replace($preg)
+ {
+ return $this->compiler->replaceDelimiter($preg);
+ }
+
+ /**
+ * check if current value is an autoliteral left delimiter
+ *
+ * @return bool
*/
public function isAutoLiteral()
{
- return $this->smarty->auto_literal && isset($this->value[ $this->ldel_length ]) ?
- strpos(" \n\t\r", $this->value[ $this->ldel_length ]) !== false : false;
- }
-
- private $_yy_state = 1;
-
- private $_yy_stack = array();
+ return $this->smarty->getAutoLiteral() && isset($this->value[ $this->compiler->getLdelLength() ]) ?
+ strpos(" \n\t\r", $this->value[ $this->compiler->getLdelLength() ]) !== false : false;
+ } // end function
public function yylex()
{
@@ -246,15 +297,13 @@ class Smarty_Internal_Templatelexer
{
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState push %s\n", $this->yyTracePrompt,
- isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
- $this->_yy_state);
+ isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
}
array_push($this->_yy_stack, $this->_yy_state);
$this->_yy_state = $state;
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
- isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
- $this->_yy_state);
+ isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
}
}
@@ -262,14 +311,12 @@ class Smarty_Internal_Templatelexer
{
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState pop %s\n", $this->yyTracePrompt,
- isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
- $this->_yy_state);
+ isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
}
$this->_yy_state = array_pop($this->_yy_stack);
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%snew State %s\n", $this->yyTracePrompt,
- isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
- $this->_yy_state);
+ isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
}
}
@@ -278,8 +325,7 @@ class Smarty_Internal_Templatelexer
$this->_yy_state = $state;
if ($this->yyTraceFILE) {
fprintf($this->yyTraceFILE, "%sState set %s\n", $this->yyTracePrompt,
- isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] :
- $this->_yy_state);
+ isset($this->state_name[ $this->_yy_state ]) ? $this->state_name[ $this->_yy_state ] : $this->_yy_state);
}
}
@@ -287,26 +333,25 @@ class Smarty_Internal_Templatelexer
{
if (!isset($this->yy_global_pattern1)) {
$this->yy_global_pattern1 =
- "/\G([{][}])|\G(" . $this->ldel . "[*])|\G((" . $this->ldel . "\\s*php(.*?)" . $this->rdel . ")|(" .
- $this->ldel . "\\s*[\/]php" . $this->rdel . "))|\G(" . $this->ldel . "\\s*literal\\s*" . $this->rdel .
- ")|\G(" . $this->ldel . "\\s*)|\G(\\s*" . $this->rdel .
- ")|\G((<[?]((php\\s+|=)|\\s+))|(<[%])|(<[?]xml\\s+)|(