Integrate ongoing master.

This commit is contained in:
AnrDaemon
2018-06-19 07:51:02 +03:00
45 changed files with 2533 additions and 2094 deletions

View File

@@ -1,7 +1,7 @@
language: php language: php
sudo: true sudo: false
dist: trusty dist: trusty
@@ -15,6 +15,7 @@ matrix:
- php: 7.0 - php: 7.0
- php: 7.1 - php: 7.1
- php: 7.2 - php: 7.2
fast_finish: true
services: services:
- memcached - memcached
@@ -25,14 +26,14 @@ before_script:
- if [ ${TRAVIS_PHP_VERSION:0:3} <= "5.6" ]; then phpenv config-add travis.ini; fi - if [ ${TRAVIS_PHP_VERSION:0:3} <= "5.6" ]; then phpenv config-add travis.ini; fi
- if [ ${TRAVIS_PHP_VERSION:0:3} >= "5.3" ]; then phpenv config-add error_reporting.ini; fi - if [ ${TRAVIS_PHP_VERSION:0:3} >= "5.3" ]; then phpenv config-add error_reporting.ini; fi
- if [[ $TRAVIS_PHP_VERSION = 7.* ]]; then composer require phpunit/phpunit 6.4.1; fi - if [[ $TRAVIS_PHP_VERSION = 7.* ]]; then composer require phpunit/phpunit 6.4.1; fi
- composer install
- mysql -e "create database IF NOT EXISTS test;" -uroot - mysql -e "create database IF NOT EXISTS test;" -uroot
before_install: before_install:
- phpenv config-rm xdebug.ini || return 0 - phpenv config-rm xdebug.ini || return 0
install: install:
- git clone --depth=50 --branch=master git://github.com/smarty-php/smarty-phpunit.git - travis_retry composer install
- git clone --depth=50 --branch=master git://github.com/smarty-php/smarty-phpunit.git
script: script:
- cd smarty-phpunit - cd smarty-phpunit

View File

@@ -1,4 +1,11 @@
3.1.31-dev 3.1.3"
New tags for inheritance parent and chilD
{parent} == {$smarty.block.parent}
{child} == {$smarty.block.child}
Both tags support the assign attribute like
{child assign=foo}
3.1.31
New tags for inheritance parent and child New tags for inheritance parent and child
{block_parent} == {$smarty.block.parent} {block_parent} == {$smarty.block.parent}
{block_child} == {$smarty.block.child} {block_child} == {$smarty.block.child}

View File

@@ -2,7 +2,12 @@
This file contains a brief description of new features which have been added to Smarty 3.1 This file contains a brief description of new features which have been added to Smarty 3.1
Smarty 3.1.32 Smarty 3.1.32 New tags for inheritance parent and child
=========================================
{parent} == {$smarty.block.parent}
{child} == {$smarty.block.child}
Both tags support the assign attribute like
{child assign=foo}
Deprecate functions Smarty::muteExpectedErrors() and Smarty::unmuteExpectedErrors() Deprecate functions Smarty::muteExpectedErrors() and Smarty::unmuteExpectedErrors()
=================================================================================== ===================================================================================
@@ -44,7 +49,7 @@ Smarty 3.1.32
.... ....
{/foreach} {/foreach}
Smarty 3.1.31 Smarty 3.1.31
New tags for inheritance parent and child New tags for inheritance parent and child
========================================= =========================================
{block_parent} == {$smarty.block.parent} {block_parent} == {$smarty.block.parent}

View File

@@ -1,10 +1,11 @@
# Smarty 3 template engine # Smarty 3 template engine
www.smarty.net [smarty.net](https://www.smarty.net/)
## Documentation ## Documentation
For documentation see For documentation see
www.smarty.net/docs/en/ [www.smarty.net/docs/en/](https://www.smarty.net/docs/en/)
## Distribution repository ## Distribution repository
> Smarty 3.1.28 introduces run time template inheritance > Smarty 3.1.28 introduces run time template inheritance
@@ -16,7 +17,7 @@ Smarty versions 3.1.11 or later are now on github and can be installed with Comp
The "smarty/smarty" package will start at libs/.... subfolder. The "smarty/smarty" package will start at libs/.... subfolder.
To get the latest stable version of Smarty 3.1 use To get the latest stable version of Smarty 3.1 use:
```json ```json
"require": { "require": {
@@ -26,7 +27,7 @@ To get the latest stable version of Smarty 3.1 use
in your composer.json file. in your composer.json file.
To get the trunk version use To get the trunk version use:
```json ```json
"require": { "require": {
@@ -34,7 +35,7 @@ To get the trunk version use
} }
``` ```
For a specific version use something like For a specific version use something like:
```json ```json
"require": { "require": {
@@ -42,7 +43,7 @@ For a specific version use something like
} }
``` ```
PHPUnit test can be installed by corresponding composer entries like PHPUnit test can be installed by corresponding composer entries like:
```json ```json
"require": { "require": {
@@ -50,7 +51,7 @@ PHPUnit test can be installed by corresponding composer entries like
} }
``` ```
Similar applies for the lexer/parser generator Similar applies for the lexer/parser generator.
```json ```json
"require": { "require": {
@@ -58,7 +59,7 @@ Similar applies for the lexer/parser generator
} }
``` ```
Or you could use Or you could use:
```json ```json
"require": { "require": {
@@ -66,6 +67,6 @@ Or you could use
} }
``` ```
Which is a wrapper to install all 3 packages Which is a wrapper to install all 3 packages.
Composer can also be used for Smarty2 versions 2.6.24 to 2.6.30 Composer can also be used for Smarty2 versions 2.6.24 to 2.6.30.

View File

@@ -1,4 +1,39 @@
===== 3.1.32 - dev === ===== 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.
===== 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 22.11.2017
- bugfix {break} and {continue} could fail if {foreach}{/foreach} did contain other - 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 looping tags like {for}, {section} and {while} https://github.com/smarty-php/smarty/issues/323

View File

@@ -281,7 +281,7 @@ class Smarty_Internal_Templatelexer
ldel = ~(SMARTYldel)SMARTYal~ ldel = ~(SMARTYldel)SMARTYal~
rdel = ~\s*SMARTYrdel~ rdel = ~\s*SMARTYrdel~
nocacherdel = ~(\s+nocache)?\s*SMARTYrdel~ nocacherdel = ~(\s+nocache)?\s*SMARTYrdel~
notblockid = ~(?:(?!block)[0-9]*[a-zA-Z_]\w*)~ smartyblockchildparent = ~[\$]smarty\.block\.(child|parent)~
integer = ~\d+~ integer = ~\d+~
hex = ~0[xX][0-9a-fA-F]+~ hex = ~0[xX][0-9a-fA-F]+~
math = ~\s*([*]{1,2}|[%/^&]|[<>]{2})\s*~ math = ~\s*([*]{1,2}|[%/^&]|[<>]{2})\s*~
@@ -321,7 +321,6 @@ class Smarty_Internal_Templatelexer
as = ~\s+as\s+~ as = ~\s+as\s+~
to = ~\s+to\s+~ to = ~\s+to\s+~
step = ~\s+step\s+~ step = ~\s+step\s+~
block = ~block~
if = ~(if|elseif|else if|while)\s+~ if = ~(if|elseif|else if|while)\s+~
for = ~for\s+~ for = ~for\s+~
makenocache = ~make_nocache\s+~ makenocache = ~make_nocache\s+~
@@ -406,7 +405,12 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG; $this->token = Smarty_Internal_Templateparser::TP_SIMPLETAG;
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
ldel slash notblockid rdel { ldel smartyblockchildparent rdel {
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT;
$this->taglineno = $this->line;
}
ldel slash id rdel {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_CLOSETAG; $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG;
$this->taglineno = $this->line; $this->taglineno = $this->line;

View File

@@ -324,6 +324,18 @@ smartytag(A)::= SIMPLETAG(B). {
} }
} }
} }
// {$smarty.block.child} or {$smarty.block.parent}
smartytag(A) ::= SMARTYBLOCKCHILDPARENT(i). {
$j = strrpos(i,'.');
if (i[$j+1] == 'c') {
// {$smarty.block.child}
A = $this->compiler->compileTag('child',array(),array(i));;
} else {
// {$smarty.block.parent}
A = $this->compiler->compileTag('parent',array(),array(i));;
}
}
smartytag(A) ::= LDEL tagbody(B) RDEL. { smartytag(A) ::= LDEL tagbody(B) RDEL. {
A = B; A = B;
} }

View File

@@ -21,13 +21,13 @@
* smarty-discussion-subscribe@googlegroups.com * smarty-discussion-subscribe@googlegroups.com
* *
* @link http://www.smarty.net/ * @link http://www.smarty.net/
* @copyright 2017 New Digital Group, Inc. * @copyright 2018 New Digital Group, Inc.
* @copyright 2017 Uwe Tews * @copyright 2018 Uwe Tews
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews * @author Uwe Tews <uwe dot tews at gmail dot com>
* @author Rodney Rehm * @author Rodney Rehm
* @package Smarty * @package Smarty
* @version 3.1.32-dev * @version 3.1.33-dev
*/ */
/** /**
* set SMARTY_DIR to absolute path to Smarty library files. * set SMARTY_DIR to absolute path to Smarty library files.
@@ -112,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.32-dev-38'; const SMARTY_VERSION = '3.1.33-dev-5';
/** /**
* define variable scopes * define variable scopes
*/ */
@@ -835,7 +835,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$this->plugins_dir = (array)$this->plugins_dir; $this->plugins_dir = (array)$this->plugins_dir;
} }
foreach ($this->plugins_dir as $k => $v) { foreach ($this->plugins_dir as $k => $v) {
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true); $this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, '/\\') . DIRECTORY_SEPARATOR, true);
} }
$this->_cache[ 'plugin_files' ] = array(); $this->_cache[ 'plugin_files' ] = array();
$this->_pluginsDirNormalized = true; $this->_pluginsDirNormalized = true;
@@ -1011,7 +1011,7 @@ class Smarty extends Smarty_Internal_TemplateBase
Smarty_Internal_Template $template = null) Smarty_Internal_Template $template = null)
{ {
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : $template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" :
$template_name; $template_name;
$cache_id = $cache_id === null ? $this->cache_id : $cache_id; $cache_id = $cache_id === null ? $this->cache_id : $cache_id;
$compile_id = $compile_id === null ? $this->compile_id : $compile_id; $compile_id = $compile_id === null ? $this->compile_id : $compile_id;
$caching = (int)($caching === null ? $this->caching : $caching); $caching = (int)($caching === null ? $this->caching : $caching);
@@ -1042,9 +1042,9 @@ class Smarty extends Smarty_Internal_TemplateBase
*/ */
public function _realpath($path, $realpath = null) public function _realpath($path, $realpath = null)
{ {
$nds = DIRECTORY_SEPARATOR === '/' ? '\\' : '/'; $nds = array('/' => '\\', '\\' => '/');
// normalize DIRECTORY_SEPARATOR // normalize DIRECTORY_SEPARATOR
$path = str_replace($nds, DIRECTORY_SEPARATOR, $path); //$path = str_replace(array($nds[DIRECTORY_SEPARATOR], DIRECTORY_SEPARATOR . '.' . DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, $path);
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u', preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
$path, $path,
$parts); $parts);
@@ -1056,25 +1056,12 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = getcwd() . DIRECTORY_SEPARATOR . $path; $path = getcwd() . DIRECTORY_SEPARATOR . $path;
} }
} }
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns do {
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#u', DIRECTORY_SEPARATOR, $path); $path = preg_replace(
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first array('#[\\\\/]{2}#', '#[\\\\/][.][\\\\/]#', '#[\\\\/]([^\\\\/.]+)[\\\\/][.][.][\\\\/]#'),
if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false && DIRECTORY_SEPARATOR, $path, -1, $count);
preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#u', $path, $match) } while($count > 0);
) { return $realpath !== false ? $parts[ 'root' ] . $path : str_ireplace(getcwd(), '.', $parts[ 'root' ] . $path);
$counts = array();
foreach ($match[ 0 ] as $m) {
$counts[] = (int)((strlen($m) - 1) / 3);
}
sort($counts);
foreach ($counts as $count) {
$path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#u',
DIRECTORY_SEPARATOR,
$path);
}
}
return $parts[ 'root' ] . $path;
} }
/** /**
@@ -1270,19 +1257,20 @@ class Smarty extends Smarty_Internal_TemplateBase
* @param string $name property name * @param string $name property name
* *
* @return mixed * @return mixed
* @throws \SmartyException
*/ */
public function __get($name) public function __get($name)
{ {
if (isset($this->accessMap[ $name ])) { if (isset($this->accessMap[ $name ])) {
$method = 'get' . $this->accessMap[ $name ]; $method = 'get' . $this->accessMap[ $name ];
return $this->{$method}(); return $this->{$method}();
} else if (isset($this->_cache[ $name ])) { } else {if (isset($this->_cache[ $name ])) {
return $this->_cache[ $name ]; return $this->_cache[ $name ];
} else if (in_array($name, $this->obsoleteProperties)) { } else {if (in_array($name, $this->obsoleteProperties)) {
return null; return null;
} else { } else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
} }}}
return null; return null;
} }
@@ -1293,13 +1281,15 @@ class Smarty extends Smarty_Internal_TemplateBase
* *
* @param string $name property name * @param string $name property name
* @param mixed $value parameter passed to setter * @param mixed $value parameter passed to setter
*
* @throws \SmartyException
*/ */
public function __set($name, $value) public function __set($name, $value)
{ {
if (isset($this->accessMap[ $name ])) { if (isset($this->accessMap[ $name ])) {
$method = 'set' . $this->accessMap[ $name ]; $method = 'set' . $this->accessMap[ $name ];
$this->{$method}($value); $this->{$method}($value);
} else if (in_array($name, $this->obsoleteProperties)) { } else {if (in_array($name, $this->obsoleteProperties)) {
return; return;
} else { } else {
if (is_object($value) && method_exists($value, $name)) { if (is_object($value) && method_exists($value, $name)) {
@@ -1307,7 +1297,7 @@ class Smarty extends Smarty_Internal_TemplateBase
} else { } else {
trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE);
} }
} }}
} }
/** /**

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsBlock * @subpackage PluginsBlock
*/ */
/** /**
* Smarty {textformat}{/textformat} block plugin * Smarty {textformat}{/textformat} block plugin
* Type: block function * Type: block function
@@ -20,7 +19,7 @@
* - wrap_char - string ("\n") * - wrap_char - string ("\n")
* - indent_char - string (" ") * - indent_char - string (" ")
* - wrap_boundary - boolean (true) * - wrap_boundary - boolean (true)
* *
* *
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual) * (Smarty online manual)
@@ -32,18 +31,16 @@
* *
* @return string content re-formatted * @return string content re-formatted
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @throws \SmartyException
*/ */
function smarty_block_textformat($params, $content, $template, &$repeat) function smarty_block_textformat($params, $content, Smarty_Internal_Template $template, &$repeat)
{ {
static $mb_wordwrap_loaded = false;
if (is_null($content)) { if (is_null($content)) {
return; return;
} }
if (Smarty::$_MBSTRING && !$mb_wordwrap_loaded) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_modifier_mb_wordwrap')) { $template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
require_once(SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php'); 'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
}
$mb_wordwrap_loaded = true;
} }
$style = null; $style = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_checkboxes} function plugin * Smarty {html_checkboxes} function plugin
* File: function.html_checkboxes.php * File: function.html_checkboxes.php
@@ -37,18 +36,17 @@
* @author credits to Monte Ohrt <monte at ohrt dot com> * @author credits to Monte Ohrt <monte at ohrt dot com>
* @version 1.0 * @version 1.0
* *
* @param array $params parameters * @param array $params parameters
* @param object $template template object * @param Smarty_Internal_Template $template template object
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/ */
function smarty_function_html_checkboxes($params, $template) function smarty_function_html_checkboxes($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = 'checkbox'; $name = 'checkbox';
$values = null; $values = null;

View File

@@ -36,12 +36,10 @@
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
*/ */
function smarty_function_html_image($params, $template) function smarty_function_html_image($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$alt = ''; $alt = '';
$file = ''; $file = '';

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_options} function plugin * Smarty {html_options} function plugin
* Type: function * Type: function
@@ -34,13 +33,12 @@
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/ */
function smarty_function_html_options($params, Smarty_Internal_Template $template) function smarty_function_html_options($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = null; $name = null;
$values = null; $values = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_radios} function plugin * Smarty {html_radios} function plugin
* File: function.html_radios.php * File: function.html_radios.php
@@ -42,13 +41,12 @@
* *
* @return string * @return string
* @uses smarty_function_escape_special_chars() * @uses smarty_function_escape_special_chars()
* @throws \SmartyException
*/ */
function smarty_function_html_radios($params, $template) function smarty_function_html_radios($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$name = 'radio'; $name = 'radio';
$values = null; $values = null;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_select_date} plugin * Smarty {html_select_date} plugin
* Type: function * Type: function
@@ -42,17 +41,12 @@
* @param \Smarty_Internal_Template $template * @param \Smarty_Internal_Template $template
* *
* @return string * @return string
* @throws \SmartyException
*/ */
function smarty_function_html_select_date($params, Smarty_Internal_Template $template) function smarty_function_html_select_date($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
if (!isset($template->smarty->_cache[ '_required_smt' ])) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
$template->smarty->_cache[ '_required_smt' ] = true;
}
// generate timestamps used for month names only // generate timestamps used for month names only
static $_month_timestamps = null; static $_month_timestamps = null;
static $_current_year = null; static $_current_year = null;
@@ -117,6 +111,8 @@ function smarty_function_html_select_date($params, Smarty_Internal_Template $tem
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsFunction * @subpackage PluginsFunction
*/ */
/** /**
* Smarty {html_select_time} function plugin * Smarty {html_select_time} function plugin
* Type: function * Type: function
@@ -23,17 +22,12 @@
* *
* @return string * @return string
* @uses smarty_make_timestamp() * @uses smarty_make_timestamp()
* @throws \SmartyException
*/ */
function smarty_function_html_select_time($params, Smarty_Internal_Template $template) function smarty_function_html_select_time($params, Smarty_Internal_Template $template)
{ {
if (!isset($template->smarty->_cache[ '_required_sesc' ])) { $template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); 'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$template->smarty->_cache[ '_required_sesc' ] = true;
}
if (!isset($template->smarty->_cache[ '_required_smt' ])) {
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
$template->smarty->_cache[ '_required_smt' ] = true;
}
$prefix = 'Time_'; $prefix = 'Time_';
$field_array = null; $field_array = null;
$field_separator = "\n"; $field_separator = "\n";
@@ -84,6 +78,8 @@ function smarty_function_html_select_time($params, Smarty_Internal_Template $tem
switch ($_key) { switch ($_key) {
case 'time': case 'time':
if (!is_array($_value) && $_value !== null) { if (!is_array($_value) && $_value !== null) {
$template->_checkPlugins(array(array('function' => 'smarty_make_timestamp',
'file' => SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php')));
$time = smarty_make_timestamp($_value); $time = smarty_make_timestamp($_value);
} }
break; break;

View File

@@ -25,7 +25,8 @@
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true) function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{ {
static $_double_encode = null; static $_double_encode = null;
static $is_loaded1 = false; static $is_loaded_1 = false;
static $is_loaded_2 = false;
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }
@@ -123,11 +124,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'hexentity': case 'hexentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
$is_loaded1 = true;
} }
$is_loaded_1 = true;
} }
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
@@ -147,11 +148,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'decentity': case 'decentity':
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
} }
$is_loaded1 = true; $is_loaded_1 = true;
} }
$return = ''; $return = '';
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
@@ -179,8 +180,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
case 'mail': case 'mail':
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) { if (!$is_loaded_2) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php'); if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
}
$is_loaded_2 = true;
} }
return smarty_mb_str_replace(array('@', return smarty_mb_str_replace(array('@',
'.'), array(' [AT] ', '.'), array(' [AT] ',
@@ -195,11 +199,11 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
// escape non-standard chars, such as ms document quotes // escape non-standard chars, such as ms document quotes
$return = ''; $return = '';
if (Smarty::$_MBSTRING) { if (Smarty::$_MBSTRING) {
if (!$is_loaded1) { if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) { if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
} }
$is_loaded1 = true; $is_loaded_1 = true;
} }
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) { foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
if ($unicode >= 126) { if ($unicode >= 126) {

View File

@@ -5,7 +5,6 @@
* @package Smarty * @package Smarty
* @subpackage PluginsModifierCompiler * @subpackage PluginsModifierCompiler
*/ */
/** /**
* Smarty escape modifier plugin * Smarty escape modifier plugin
* Type: modifier * Type: modifier
@@ -15,21 +14,18 @@
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual) * @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm * @author Rodney Rehm
* *
* @param array $params parameters * @param array $params parameters
* @param $compiler * @param Smarty_Internal_TemplateCompilerBase $compiler
* *
* @return string with compiled code * @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 $_double_encode = null;
static $is_loaded = false; static $is_loaded = false;
if (!$is_loaded) { $compiler->template->_checkPlugins(array(array('function' => 'smarty_literal_compiler_param',
if (!is_callable('smarty_literal_compiler_param')) { 'file' => SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php')));
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
}
$is_loaded = true;
}
if ($_double_encode === null) { if ($_double_encode === null) {
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>='); $_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
} }
@@ -104,14 +100,14 @@ function smarty_modifiercompiler_escape($params, $compiler)
// could not optimize |escape call, so fallback to regular plugin // could not optimize |escape call, so fallback to regular plugin
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) { if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] = $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'modifier.escape.php'; SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] = $compiler->required_plugins[ 'nocache' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape'; 'smarty_modifier_escape';
} else { } else {
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] = $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'file' ] =
SMARTY_PLUGINS_DIR . 'modifier.escape.php'; SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] = $compiler->required_plugins[ 'compiled' ][ 'escape' ][ 'modifier' ][ 'function' ] =
'smarty_modifier_escape'; 'smarty_modifier_escape';
} }

View File

@@ -22,7 +22,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $required_attributes = array('name'); public $required_attributes = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -30,7 +29,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $shorttag_order = array('name'); public $shorttag_order = array('name');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -38,7 +36,6 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
* @see Smarty_Internal_CompileBase * @see Smarty_Internal_CompileBase
*/ */
public $option_flags = array('hide', 'nocache'); public $option_flags = array('hide', 'nocache');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -47,27 +44,20 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
*/ */
public $optional_attributes = array('assign'); public $optional_attributes = array('assign');
/**
* Saved compiler object
*
* @var Smarty_Internal_TemplateCompilerBase
*/
public $compiler = null;
/** /**
* Compiles code for the {block} tag * Compiles code for the {block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @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) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
if (!isset($compiler->_cache['blockNesting'])) { if (!isset($compiler->_cache[ 'blockNesting' ])) {
$compiler->_cache['blockNesting'] = 0; $compiler->_cache[ 'blockNesting' ] = 0;
} }
if ($compiler->_cache['blockNesting'] === 0) { if ($compiler->_cache[ 'blockNesting' ] === 0) {
// make sure that inheritance gets initialized in template code // make sure that inheritance gets initialized in template code
$this->registerInit($compiler); $this->registerInit($compiler);
$this->option_flags = array('hide', 'nocache', 'append', 'prepend'); $this->option_flags = array('hide', 'nocache', 'append', 'prepend');
@@ -76,70 +66,24 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
} }
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
$compiler->_cache['blockNesting']++; ++$compiler->_cache[ 'blockNesting' ];
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true)); $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
$compiler->_cache['blockName'][ $compiler->_cache['blockNesting'] ] = $_attr['name']; $compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
$compiler->_cache['blockClass'][ $compiler->_cache['blockNesting'] ] = $_className; $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
$compiler->_cache['blockParams'][ $compiler->_cache['blockNesting'] ] = array(); $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
$compiler->_cache['blockParams'][1]['subBlocks'][ trim($_attr['name'], '"\'') ][] = $_className; $compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
$this->openTag($compiler, $this->openTag($compiler,
'block', 'block',
array($_attr, $compiler->nocache, $compiler->parser->current_buffer, array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching)); $compiler->template->caching));
// must whole block be nocache ? $compiler->saveRequiredPlugins(true);
if ($compiler->tag_nocache) {
$i = 0;
}
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $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->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false; $compiler->template->compiled->has_nocache_code = false;
$compiler->suppressNocacheProcessing = true; $compiler->suppressNocacheProcessing = true;
} }
/**
* Compiles code for the {$smarty.block.parent} or {$smarty.block.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 compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false;
if (!$name) {
$compiler->trigger_template_error("invalid '\$smarty.block' expected '\$smarty.block.child' or '\$smarty.block.parent'",
null,
true);
}
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->trigger_template_error(" '\$smarty.block.{$name}' used outside {block} tags ",
$compiler->parser->lex->taglineno);
}
$compiler->suppressNocacheProcessing = true;
switch ($name) {
case 'child':
$compiler->_cache['blockParams'][ $compiler->_cache['blockNesting'] ]['callsChild'] = 'true';
return '$_smarty_tpl->inheritance->callChild($_smarty_tpl, $this, true)';
break;
case 'parent':
return '$_smarty_tpl->inheritance->callParent($_smarty_tpl, $this, null, true)';
break;
default:
$compiler->trigger_template_error("invalid '\$smarty.block.{$name}' expected '\$smarty.block.child' or '\$smarty.block.parent'",
null,
true);
}
}
} }
/** /**
* Smarty Internal Plugin Compile BlockClose Class * Smarty Internal Plugin Compile BlockClose Class
* *
@@ -149,27 +93,27 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
/** /**
* Compiles code for the {/block} tag * Compiles code for the {/block} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* *
* @return string compiled code * @return bool true
* @internal param array $parameter array with compilation parameter
*/ */
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{ {
list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block')); list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block'));
// init block parameter // init block parameter
$_block = $compiler->_cache['blockParams'][ $compiler->_cache['blockNesting'] ]; $_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ];
unset($compiler->_cache['blockParams'][ $compiler->_cache['blockNesting'] ]); unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]);
$_name = $_attr['name']; $_name = $_attr[ 'name' ];
$_assign = isset($_attr['assign']) ? $_attr['assign'] : null; $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
unset($_attr['assign'], $_attr['name']); unset($_attr[ 'assign' ], $_attr[ 'name' ]);
foreach ($_attr as $name => $stat) { foreach ($_attr as $name => $stat) {
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) { if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) {
$_block[ $name ] = 'true'; $_block[ $name ] = 'true';
} }
} }
$_className = $compiler->_cache['blockClass'][ $compiler->_cache['blockNesting'] ]; $_className = $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ];
// get compiled block code // get compiled block code
$_functionCode = $compiler->parser->current_buffer; $_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code // setup buffer for template function code
@@ -180,10 +124,11 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$output .= "class {$_className} extends Smarty_Internal_Block\n"; $output .= "class {$_className} extends Smarty_Internal_Block\n";
$output .= "{\n"; $output .= "{\n";
foreach ($_block as $property => $value) { foreach ($_block as $property => $value) {
$output .= "public \${$property} = " . var_export($value, true) . ";\n"; $output .= "public \${$property} = " . var_export($value,true) .";\n";
} }
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n"; $output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
//$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n"; $output .= $compiler->compileRequiredPlugins();
$compiler->restoreRequiredPlugins();
if ($compiler->template->compiled->has_nocache_code) { if ($compiler->template->compiled->has_nocache_code) {
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
} }
@@ -206,34 +151,25 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output)); $output));
$compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
// nocache plugins must be copied
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
foreach ($tmp as $type => $data) {
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][ $plugin ][ $type ] =
$data;
}
}
}
// restore old status // restore old status
$compiler->template->compiled->has_nocache_code = $_has_nocache_code; $compiler->template->compiled->has_nocache_code = $_has_nocache_code;
$compiler->tag_nocache = $compiler->nocache; $compiler->tag_nocache = $compiler->nocache;
$compiler->nocache = $_nocache; $compiler->nocache = $_nocache;
$compiler->parser->current_buffer = $_buffer; $compiler->parser->current_buffer = $_buffer;
$output = "<?php \n"; $output = "<?php \n";
if ($compiler->_cache['blockNesting'] === 1) { if ($compiler->_cache[ 'blockNesting' ] === 1) {
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n";
} else { } else {
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n";
} }
$output .= "?>\n"; $output .= "?>\n";
$compiler->_cache['blockNesting']--; --$compiler->_cache[ 'blockNesting' ];
if ($compiler->_cache['blockNesting'] === 0) { if ($compiler->_cache[ 'blockNesting' ] === 0) {
unset($compiler->_cache['blockNesting']); unset($compiler->_cache[ 'blockNesting' ]);
} }
$compiler->has_code = true;
$compiler->suppressNocacheProcessing = true; $compiler->suppressNocacheProcessing = true;
return $output; return $output;
} }

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Block Child Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child
{
/**
* Tag name
*
* @var string
*/
public $tag = 'block_child';
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Block Parent Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
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';
}

View File

@@ -0,0 +1,77 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Child Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
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 = "<?php \n";
if (isset($_assign)) {
$output .= "ob_start();\n";
}
$output .= '$_smarty_tpl->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;
}
}

View File

@@ -135,16 +135,17 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh
/** /**
* Create source code for {extends} from source components array * Create source code for {extends} from source components array
* *
* @param []\Smarty_Internal_Template_Source $components * @param \Smarty_Internal_Template $template
* *
* @return string * @return string
*/ */
public static function extendsSourceArrayCode($components) public static function extendsSourceArrayCode(Smarty_Internal_Template $template)
{ {
$resources = array(); $resources = array();
foreach ($components as $source) { foreach ($template->source->components as $source) {
$resources[] = $source->resource; $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;
} }
} }

View File

@@ -67,6 +67,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
// Init temporary context // Init temporary context
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template(); $compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false; $compiler->template->compiled->has_nocache_code = false;
$compiler->saveRequiredPlugins(true);
return true; return true;
} }
} }
@@ -134,13 +135,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n"; $output .= "function {$_funcNameCaching} (Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= "ob_start();\n"; $output .= "ob_start();\n";
$output .= $compiler->compileRequiredPlugins();
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n"; $output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\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 .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php "; $output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$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 .= "\\\$_smarty_tpl->smarty->ext->_tplFunction->saveTemplateVariables(\\\$_smarty_tpl, '{$_name}');\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value, \\\$_smarty_tpl->isRenderingCache);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>"; $output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser, $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output)); $output));
@@ -166,7 +168,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
$output .= "if (!function_exists('{$_funcName}')) {\n"; $output .= "if (!function_exists('{$_funcName}')) {\n";
$output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n"; $output .= "function {$_funcName}(Smarty_Internal_Template \$_smarty_tpl,\$params) {\n";
$output .= $_paramsCode; $output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value, \$_smarty_tpl->isRenderingCache);\n}?>"; $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, $compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output)); $output));
@@ -178,19 +182,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
new Smarty_Internal_ParseTree_Tag($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output)); $output));
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); $compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// nocache plugins must be copied // restore old buffer
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 // restore old status
$compiler->restoreRequiredPlugins();
$compiler->template->compiled->has_nocache_code = $saved_data[ 2 ]; $compiler->template->compiled->has_nocache_code = $saved_data[ 2 ];
$compiler->template->caching = $saved_data[ 3 ]; $compiler->template->caching = $saved_data[ 3 ];
return true; return true;

View File

@@ -295,12 +295,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->mustCompile = true; $tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] = $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] =
$tpl->compiled->nocache_hash; $tpl->compiled->nocache_hash;
if ($compiler->template->source->type === 'file') { if ($tpl->source->type === 'file') {
$sourceInfo = $compiler->template->source->filepath; $sourceInfo = $tpl->source->filepath;
} else { } else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source); $basename = $tpl->source->handler->getBasename($tpl->source);
$sourceInfo = $compiler->template->source->type . ':' . $sourceInfo = $tpl->source->type . ':' .
($basename ? $basename : $compiler->template->source->name); ($basename ? $basename : $tpl->source->name);
} }
// get compiled code // get compiled code
$compiled_code = "<?php\n\n"; $compiled_code = "<?php\n\n";

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of Smarty.
*
* (c) 2015 Uwe Tews
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Smarty Internal Plugin Compile Parent Class
*
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child
{
/**
* Tag name
*
* @var string
*/
public $tag = 'parent';
/**
* Block type
*
* @var string
*/
public $blockType = 'Parent';
}

View File

@@ -112,8 +112,9 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes) public function buildPropertyPreg($named, $attributes)
{ {
if ($named) { if ($named) {
$this->resultOffsets[ 'named' ] = $this->startOffset + 3; $this->resultOffsets[ 'named' ] = $this->startOffset + 4;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; $this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '')
. "){$attributes['name']}[.](";
$properties = $this->nameProperties; $properties = $this->nameProperties;
} else { } else {
$this->resultOffsets[ 'item' ] = $this->startOffset + 3; $this->resultOffsets[ 'item' ] = $this->startOffset + 3;

View File

@@ -130,8 +130,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
} }
} }
} }
if (isset($compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) || if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) ||
isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) { ) {
// was a plugin // was a plugin
$compiler->known_modifier_type[ $modifier ] = 4; $compiler->known_modifier_type[ $modifier ] = 4;

View File

@@ -51,9 +51,6 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return ''; return '';
case 'now': case 'now':
return 'time()'; return 'time()';
case 'block':
$tag = $compiler->getTagCompiler('block');
return $tag->compileSpecialVariable(array(), $compiler, $_index);
case 'cookies': case 'cookies':
if (isset($compiler->smarty->security_policy) && if (isset($compiler->smarty->security_policy) &&
!$compiler->smarty->security_policy->allow_super_globals !$compiler->smarty->security_policy->allow_super_globals
@@ -114,7 +111,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'rdelim': case 'rdelim':
return "\$_smarty_tpl->smarty->right_delimiter"; return "\$_smarty_tpl->smarty->right_delimiter";
default: default:
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], '\'') . ' is not defined'); $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break; break;
} }
if (isset($_index[ 1 ])) { if (isset($_index[ 1 ])) {

View File

@@ -104,8 +104,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal = $initLocal = array();
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array(); $initNamedProperty = array();
$initFor = array(); $initFor = array();
$incFor = array(); $incFor = array();
@@ -455,9 +454,6 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
} else { } else {
$output .= "}\n}\n"; $output .= "}\n}\n";
} }
$output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n";
$output .= '?>'; $output .= '?>';
return $output; return $output;

View File

@@ -75,7 +75,7 @@ class Smarty_Internal_Method_CompileAllTemplates
if (substr(basename($_fileinfo->getPathname()), 0, 1) === '.' || strpos($_file, '.svn') !== false) { if (substr(basename($_fileinfo->getPathname()), 0, 1) === '.' || strpos($_file, '.svn') !== false) {
continue; continue;
} }
if (!substr_compare($_file, $extension, -strlen($extension)) === 0) { if (substr_compare($_file, $extension, -strlen($extension)) !== 0) {
continue; continue;
} }
if ($_fileinfo->getPath() !== substr($_dir, 0, -1)) { if ($_fileinfo->getPath() !== substr($_dir, 0, -1)) {
@@ -115,7 +115,7 @@ class Smarty_Internal_Method_CompileAllTemplates
$_smarty->_clearTemplateCache(); $_smarty->_clearTemplateCache();
if ($max_errors !== null && $_error_count === $max_errors) { if ($max_errors !== null && $_error_count === $max_errors) {
echo "\n<br><br>too many errors\n"; echo "\n<br><br>too many errors\n";
exit(); exit(1);
} }
} }
} }

View File

@@ -53,7 +53,7 @@ class Smarty_Internal_Method_GetTemplateVars
} }
} }
// not found, try at parent // not found, try at parent
if ($searchParents) { if ($searchParents && isset($_ptr->parent)) {
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} else { } else {
$_ptr = null; $_ptr = null;
@@ -93,7 +93,7 @@ class Smarty_Internal_Method_GetTemplateVars
return $_ptr->tpl_vars[ $varName ]; return $_ptr->tpl_vars[ $varName ];
} }
// not found, try at parent // not found, try at parent
if ($searchParents) { if ($searchParents && isset($_ptr->parent)) {
$_ptr = $_ptr->parent; $_ptr = $_ptr->parent;
} else { } else {
$_ptr = null; $_ptr = null;
@@ -103,14 +103,11 @@ class Smarty_Internal_Method_GetTemplateVars
// found it, return it // found it, return it
return Smarty::$global_tpl_vars[ $varName ]; return Smarty::$global_tpl_vars[ $varName ];
} }
/* @var \Smarty $smarty */ if ($errorEnable && $data->_getSmartyObj()->error_unassigned) {
$smarty = isset($data->smarty) ? $data->smarty : $data;
if ($smarty->error_unassigned && $errorEnable) {
// force a notice // force a notice
$x = $$varName; $x = $$varName;
} }
return new Smarty_Undefined_Variable; return new Smarty_Undefined_Variable;
} }
} }

View File

@@ -58,42 +58,34 @@ class Smarty_Internal_Runtime_CodeFrame
var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n"; var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
} }
// include code for plugins
if (!$cache) {
if (!empty($_template->compiled->required_plugins[ 'compiled' ])) {
foreach ($_template->compiled->required_plugins[ 'compiled' ] as $tmp) {
foreach ($tmp as $data) {
$file = addslashes($data[ 'file' ]);
if (is_array($data[ 'function' ])) {
$output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
} else {
$output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
}
}
}
}
if ($_template->caching && !empty($_template->compiled->required_plugins[ 'nocache' ])) {
$_template->compiled->has_nocache_code = true;
$output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
foreach ($_template->compiled->required_plugins[ 'nocache' ] as $tmp) {
foreach ($tmp as $data) {
$file = addslashes($data[ 'file' ]);
if (is_array($data[ 'function' ])) {
$output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
} else {
$output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
}
}
}
$output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
}
}
$output .= "?>"; $output .= "?>";
$output .= $content; $output .= $content;
$output .= "<?php }\n?>"; $output .= "<?php }\n?>";
$output .= $functions; $output .= $functions;
$output .= "<?php }\n"; $output .= "<?php }\n";
// remove unneeded PHP tags // remove unneeded PHP tags
return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output); if (preg_match('/\s*\?>[\n]?<\?php\s*/', $output)) {
$curr_split = preg_split('/\s*\?>[\n]?<\?php\s*/',
$output);
preg_match_all('/\s*\?>[\n]?<\?php\s*/',
$output,
$curr_parts);
$output = '';
foreach ($curr_split as $idx => $curr_output) {
$output .= $curr_output;
if (isset($curr_parts[ 0 ][ $idx ])) {
$output .= "\n";
}
}
}
if (preg_match('/\?>\s*$/', $output)) {
$curr_split = preg_split('/\?>\s*$/',
$output);
$output = '';
foreach ($curr_split as $idx => $curr_output) {
$output .= $curr_output;
}
}
return $output;
} }
} }

View File

@@ -37,17 +37,20 @@ class Smarty_Internal_Runtime_Foreach
public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null, public function init(Smarty_Internal_Template $tpl, $from, $item, $needTotal = false, $key = null, $name = null,
$properties = array()) $properties = array())
{ {
$needTotal = $needTotal || isset($properties[ 'total' ]);
$saveVars = array(); $saveVars = array();
$total = null; $total = null;
if (!is_array($from)) { if (!is_array($from)) {
if (is_object($from)) { if (is_object($from)) {
$total = $this->count($from); if ($needTotal) {
$total = $this->count($from);
}
} else { } else {
settype($from, 'array'); settype($from, 'array');
} }
} }
if (!isset($total)) { if (!isset($total)) {
$total = empty($from) ? 0 : (($needTotal || isset($properties[ 'total' ])) ? count($from) : 1); $total = empty($from) ? 0 : ($needTotal ? count($from) : 1);
} }
if (isset($tpl->tpl_vars[ $item ])) { if (isset($tpl->tpl_vars[ $item ])) {
$saveVars[ 'item' ] = array($item, $saveVars[ 'item' ] = array($item,

View File

@@ -42,11 +42,10 @@ class Smarty_Internal_Runtime_Inheritance
* *
* @var int * @var int
*/ */
public $tplIndex = -1; public $tplIndex = - 1;
/** /**
* Array of template source objects * Array of template source objects
* - key template index
* *
* @var Smarty_Template_Source[] * @var Smarty_Template_Source[]
*/ */
@@ -75,7 +74,7 @@ class Smarty_Internal_Runtime_Inheritance
$tpl->inheritance->init($tpl, $initChild, $blockNames); $tpl->inheritance->init($tpl, $initChild, $blockNames);
return; return;
} }
$this->tplIndex++; ++$this->tplIndex;
$this->sources[ $this->tplIndex ] = $tpl->source; $this->sources[ $this->tplIndex ] = $tpl->source;
// start of child sub template(s) // start of child sub template(s)
@@ -85,7 +84,7 @@ class Smarty_Internal_Runtime_Inheritance
//grab any output of child templates //grab any output of child templates
ob_start(); ob_start();
} }
$this->inheritanceLevel++; ++$this->inheritanceLevel;
// $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart'); // $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
// $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd'); // $tpl->endRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateEnd');
} }
@@ -109,7 +108,7 @@ class Smarty_Internal_Runtime_Inheritance
*/ */
public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null) public function endChild(Smarty_Internal_Template $tpl, $template = null, $uid = null, $func = null)
{ {
$this->inheritanceLevel--; --$this->inheritanceLevel;
if (!$this->inheritanceLevel) { if (!$this->inheritanceLevel) {
ob_end_clean(); ob_end_clean();
$this->state = 2; $this->state = 2;
@@ -167,8 +166,7 @@ class Smarty_Internal_Runtime_Inheritance
* *
* @throws \SmartyException * @throws \SmartyException
*/ */
public function process(Smarty_Internal_Template $tpl, public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block,
Smarty_Internal_Block $block,
Smarty_Internal_Block $parent = null) Smarty_Internal_Block $parent = null)
{ {
if ($block->hide && !isset($block->child)) { if ($block->hide && !isset($block->child)) {
@@ -179,7 +177,7 @@ class Smarty_Internal_Runtime_Inheritance
} }
$block->parent = $parent; $block->parent = $parent;
if ($block->append && !$block->prepend && isset($parent)) { if ($block->append && !$block->prepend && isset($parent)) {
$this->callParent($tpl, $block); $this->callParent($tpl, $block, '\'{block append}\'');
} }
if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) { if ($block->callsChild || !isset($block->child) || ($block->child->hide && !isset($block->child->child))) {
$this->callBlock($block, $tpl); $this->callBlock($block, $tpl);
@@ -187,7 +185,7 @@ class Smarty_Internal_Runtime_Inheritance
$this->process($tpl, $block->child, $block); $this->process($tpl, $block->child, $block);
} }
if ($block->prepend && isset($parent)) { if ($block->prepend && isset($parent)) {
$this->callParent($tpl, $block); $this->callParent($tpl, $block, '{block prepend}');
if ($block->append) { if ($block->append) {
if ($block->callsChild || !isset($block->child) || if ($block->callsChild || !isset($block->child) ||
($block->child->hide && !isset($block->child->child)) ($block->child->hide && !isset($block->child->child))
@@ -202,70 +200,42 @@ class Smarty_Internal_Runtime_Inheritance
} }
/** /**
* Render child on $smarty.block.child * Render child on \$smarty.block.child
* *
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl
* @param \Smarty_Internal_Block $block * @param \Smarty_Internal_Block $block
* @param boolean $returnContent flag if content shall be returned
* *
* @return null|string null or block content dependent on $returnContent * @return null|string block content
* @throws \SmartyException * @throws \SmartyException
*/ */
public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $returnContent = false) public function callChild(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block)
{ {
if ($returnContent) {
ob_start();
}
if (isset($block->child)) { if (isset($block->child)) {
$this->process($tpl, $block->child, $block); $this->process($tpl, $block->child, $block);
} }
if ($returnContent) {
return ob_get_clean();
}
return;
} }
/** /**
* Render parent block on $smarty.block.parent or {block append/prepend} * Render parent block on \$smarty.block.parent or {block append/prepend}
* *
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl
* @param \Smarty_Internal_Block $block * @param \Smarty_Internal_Block $block
* @param null|string $name * @param string $tag
* @param boolean $returnContent flag if content shall be returned
* *
* @return null|string null or block content dependent on $returnContent * @return null|string block content
* @throws \SmartyException * @throws \SmartyException
*/ */
public function callParent(Smarty_Internal_Template $tpl, public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $tag)
Smarty_Internal_Block $block,
$name = null,
$returnContent = false)
{ {
if ($returnContent) { if (isset($block->parent)) {
ob_start();
}
if (isset($name)) {
$block = $block->parent;
while (isset($block)) {
if (isset($block->subBlocks[ $name ])) {
} else {
$block = $block->parent;
}
}
return;
} else if (isset($block->parent)) {
$this->callBlock($block->parent, $tpl); $this->callBlock($block->parent, $tpl);
} else { } else {
throw new SmartyException("inheritance: illegal '\$smarty.block.parent' or {block append/prepend} used in parent template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'"); throw new SmartyException("inheritance: illegal '{$tag}' used in child template '{$tpl->inheritance->sources[$block->tplIndex]->filepath}' block '{$block->name}'");
} }
if ($returnContent) {
return ob_get_clean();
}
return;
} }
/** /**
* redender block * render block
* *
* @param \Smarty_Internal_Block $block * @param \Smarty_Internal_Block $block
* @param \Smarty_Internal_Template $tpl * @param \Smarty_Internal_Template $tpl

View File

@@ -120,15 +120,13 @@ class Smarty_Internal_Runtime_TplFunction
} }
// add template function code to cache file // add template function code to cache file
if (isset($tplPtr->cached)) { if (isset($tplPtr->cached)) {
/* @var Smarty_Template_Cached $cache */ $content = $tplPtr->cached->read($tplPtr);
$cache = $tplPtr->cached;
$content = $cache->read($tplPtr);
if ($content) { if ($content) {
// check if we must update file dependency // check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) { if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
$content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content); $content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content);
} }
$tplPtr->smarty->ext->_updateCache->write($cache, $tplPtr, $tplPtr->smarty->ext->_updateCache->write($tplPtr,
preg_replace('/\s*\?>\s*$/', "\n", $content) . preg_replace('/\s*\?>\s*$/', "\n", $content) .
"\n" . preg_replace(array('/^\s*<\?php\s+/', "\n" . preg_replace(array('/^\s*<\?php\s+/',
'/\s*\?>\s*$/',), "\n", '/\s*\?>\s*$/',), "\n",

View File

@@ -21,56 +21,6 @@ class Smarty_Internal_Runtime_UpdateCache
{ {
} }
/**
* Sanitize content and write it to cache resource
*
* @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template
* @param bool $no_output_filter
*
* @throws \SmartyException
*/
public function removeNoCacheHash(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template,
$no_output_filter)
{
$content = ob_get_clean();
unset($cached->hashes[ $_template->compiled->nocache_hash ]);
if (!empty($cached->hashes)) {
$hash_array = array();
foreach ($cached->hashes as $hash => $foo) {
$hash_array[] = "/{$hash}/";
}
$content = preg_replace($hash_array, $_template->compiled->nocache_hash, $content);
}
$_template->cached->has_nocache_code = false;
// get text between non-cached items
$cache_split =
preg_split("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
$content);
// get non-cached items
preg_match_all("!/\*%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%\*/!s",
$content, $cache_parts);
$content = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
// escape PHP tags in template content
$content .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/',
"<?php echo '\$1'; ?>\n", $curr_split);
if (isset($cache_parts[ 0 ][ $curr_idx ])) {
$_template->cached->has_nocache_code = true;
$content .= $cache_parts[ 1 ][ $curr_idx ];
}
}
if (!$no_output_filter && !$_template->cached->has_nocache_code &&
(isset($_template->smarty->autoload_filters[ 'output' ]) ||
isset($_template->smarty->registered_filters[ 'output' ]))
) {
$content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template);
}
// write cache file content
$this->writeCachedContent($cached, $_template, $content);
}
/** /**
* Cache was invalid , so render from compiled and write to cache * Cache was invalid , so render from compiled and write to cache
* *
@@ -107,37 +57,101 @@ class Smarty_Internal_Runtime_UpdateCache
} }
/** /**
* Writes the content to cache resource * Sanitize content and write it to cache resource
* *
* @param \Smarty_Template_Cached $cached * @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template * @param Smarty_Internal_Template $_template
* @param bool $no_output_filter
*
* @throws \SmartyException
*/
public function removeNoCacheHash(Smarty_Template_Cached $cached,
Smarty_Internal_Template $_template,
$no_output_filter)
{
$php_pattern = '/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/';
$content = ob_get_clean();
$hash_array = $cached->hashes;
$hash_array[$_template->compiled->nocache_hash] = true;
$hash_array = array_keys($hash_array);
$nocache_hash = '(' . implode('|', $hash_array) . ')';
$_template->cached->has_nocache_code = false;
// get text between non-cached items
$cache_split =
preg_split("!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content);
// get non-cached items
preg_match_all("!/\*%%SmartyNocache:{$nocache_hash}%%\*\/(.+?)/\*/%%SmartyNocache:{$nocache_hash}%%\*/!s",
$content,
$cache_parts);
$content = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
if (preg_match($php_pattern, $curr_split)) {
// escape PHP tags in template content
$php_split = preg_split($php_pattern,
$curr_split);
preg_match_all($php_pattern,
$curr_split,
$php_parts);
foreach ($php_split as $idx_php => $curr_php) {
$content .= $curr_php;
if (isset($php_parts[ 0 ][ $idx_php ])) {
$content .= "<?php echo '{$php_parts[ 1 ][ $idx_php ]}'; ?>\n";
}
}
} else {
$content .= $curr_split;
}
if (isset($cache_parts[ 0 ][ $curr_idx ])) {
$_template->cached->has_nocache_code = true;
$content .= $cache_parts[ 2 ][ $curr_idx ];
}
}
if (!$no_output_filter && !$_template->cached->has_nocache_code &&
(isset($_template->smarty->autoload_filters[ 'output' ]) ||
isset($_template->smarty->registered_filters[ 'output' ]))
) {
$content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template);
}
// write cache file content
$this->writeCachedContent($_template, $content);
}
/**
* Writes the content to cache resource
*
* @param Smarty_Internal_Template $_template
* @param string $content * @param string $content
* *
* @return bool * @return bool
*/ */
public function writeCachedContent(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{ {
if ($_template->source->handler->recompiled || !$_template->caching if ($_template->source->handler->recompiled || !$_template->caching
) { ) {
// don't write cache file // don't write cache file
return false; return false;
} }
if (!isset($_template->cached)) {
$_template->loadCached();
}
$content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true); $content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true);
return $this->write($cached, $_template, $content); return $this->write($_template, $content);
} }
/** /**
* Write this cache object to handler * Write this cache object to handler
* *
* @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template template object * @param Smarty_Internal_Template $_template template object
* @param string $content content to cache * @param string $content content to cache
* *
* @return bool success * @return bool success
*/ */
public function write(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content) public function write(Smarty_Internal_Template $_template, $content)
{ {
if (!$_template->source->handler->recompiled) { if (!$_template->source->handler->recompiled) {
$cached = $_template->cached;
if ($cached->handler->writeCachedContent($_template, $content)) { if ($cached->handler->writeCachedContent($_template, $content)) {
$cached->content = null; $cached->content = null;
$cached->timestamp = time(); $cached->timestamp = time();
@@ -160,5 +174,4 @@ class Smarty_Internal_Runtime_UpdateCache
return false; return false;
} }
} }

View File

@@ -234,15 +234,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->smarty->_debug->display_debug($this, true); $this->smarty->_debug->display_debug($this, true);
} }
} }
if ($this->_isSubTpl()) {
foreach ($this->compiled->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$this->parent->compiled->required_plugins[ $code ][ $name ][ $type ] = $data;
}
}
}
}
if (!$no_output_filter && if (!$no_output_filter &&
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
(isset($this->smarty->autoload_filters[ 'output' ]) || (isset($this->smarty->autoload_filters[ 'output' ]) ||
@@ -428,6 +419,39 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
} }
/**
* Check if plugins are callable require file otherwise
*
* @param array $plugins required plugins
*
* @throws \SmartyException
*/
public function _checkPlugins($plugins) {
static $checked = array();
foreach($plugins as $plugin) {
$name = join('::', (array)$plugin[ 'function' ]);
if (!isset($checked[$name])) {
if (!is_callable($plugin['function'])) {
if (is_file($plugin['file'])) {
require_once $plugin['file'];
if (is_callable($plugin['function'])) {
$checked[ $name ] = true;
}
}
} else {
$checked[ $name ] = true;
}
}
if (!isset($checked[ $name ])) {
if (false !== $this->smarty->loadPlugin($name)) {
$checked[ $name ] = true;
} else {
throw new SmartyException("Plugin '{$name}' not callable");
}
}
}
}
/** /**
* This function is executed automatically when a compiled or cached template file is included * This function is executed automatically when a compiled or cached template file is included
* - Decode saved properties from compiled template and cache files * - Decode saved properties from compiled template and cache files
@@ -523,7 +547,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/ */
public function writeCachedContent($content) public function writeCachedContent($content)
{ {
return $this->smarty->ext->_updateCache->writeCachedContent($this->cached, $this, $content); return $this->smarty->ext->_updateCache->writeCachedContent($this, $content);
} }
/** /**

View File

@@ -20,7 +20,7 @@
* They are located in a corresponding Smarty_Internal_Method_xxxx class * They are located in a corresponding Smarty_Internal_Method_xxxx class
* *
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null) * @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers) * @method Smarty_Internal_TemplateBase addDefaultModifiers(mixed $modifiers)
* @method Smarty_Internal_TemplateBase addLiterals(mixed $literals) * @method Smarty_Internal_TemplateBase addLiterals(mixed $literals)
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null) * @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getAutoloadFilters(string $type = null) * @method array getAutoloadFilters(string $type = null)

View File

@@ -57,6 +57,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var bool * @var bool
*/ */
public $suppressNocacheProcessing = false; public $suppressNocacheProcessing = false;
/**
* caching enabled (copied from template object)
*
* @var int
*/
public $caching = 0;
/** /**
* tag stack * tag stack
* *
@@ -69,6 +77,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var array * @var array
*/ */
public $_tag_stack_count = array(); public $_tag_stack_count = array();
/**
* Plugins used by template
*
* @var array
*/
public $required_plugins = array('compiled' => array(), 'nocache' => array());
/**
* Required plugins stack
*
* @var array
*/
public $required_plugins_stack = array();
/** /**
* current template * current template
* *
@@ -374,6 +394,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else { } else {
$this->nocache_hash = $template->compiled->nocache_hash; $this->nocache_hash = $template->compiled->nocache_hash;
} }
$this->caching = $template->caching;
// flag for nocache sections // flag for nocache sections
$this->nocache = $nocache; $this->nocache = $nocache;
$this->tag_nocache = false; $this->tag_nocache = false;
@@ -394,12 +415,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
// we have array of inheritance templates by extends: resource // we have array of inheritance templates by extends: resource
// generate corresponding source code sequence // generate corresponding source code sequence
$_content = $_content =
Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template);
} else { } else {
// get template source // get template source
$_content = $this->template->source->getContent(); $_content = $this->template->source->getContent();
} }
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
if (!empty($this->required_plugins[ 'compiled' ]) || !empty($this->required_plugins[ 'nocache' ])) {
$_compiled_code = '<?php ' . $this->compileRequiredPlugins() . "?>\n" . $_compiled_code;
}
} }
catch (Exception $e) { catch (Exception $e) {
if ($this->smarty->debugging) { if ($this->smarty->debugging) {
@@ -594,7 +618,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/ */
public function processText($text) public function processText($text)
{ {
if ((string)$text !== '') { if ((string) $text != '') {
$store = array(); $store = array();
$_store = 0; $_store = 0;
if ($this->parser->strip) { if ($this->parser->strip) {
@@ -602,39 +626,37 @@ abstract class Smarty_Internal_TemplateCompilerBase
// capture html elements not to be messed with // capture html elements not to be messed with
$_offset = 0; $_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is', if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$text, $text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ]; $store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@'; $replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length); $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace); $_offset += $_length - strlen($replace);
++$_store; $_store ++;
} }
} }
$expressions = array(// replace multiple spaces between tags by a single space $expressions = array(// replace multiple spaces between tags by a single space
'#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove newline between tags // remove newline between tags
'#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2',
// remove multiple spaces between attributes (but not in attribute values!) // remove multiple spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#>[\040\011]+$#Ss' => '> ', '#>[\040\011]+$#Ss' => '> ', '#>[\040\011]*[\n]\s*$#Ss' => '>',
'#>[\040\011]*[\n]\s*$#Ss' => '>', $this->stripRegEx => '',);
$this->stripRegEx => '',);
$text = preg_replace(array_keys($expressions), array_values($expressions), $text); $text = preg_replace(array_keys($expressions), array_values($expressions), $text);
$_offset = 0; $_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches,
$text,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) { PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) { foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]); $_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ]; $replace = $store[ $match[ 1 ][ 0 ] ];
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length); $text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length; $_offset += strlen($replace) - $_length;
++$_store; $_store ++;
} }
} }
} else { } else {
@@ -711,25 +733,25 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function getPlugin($plugin_name, $plugin_type) public function getPlugin($plugin_name, $plugin_type)
{ {
$function = null; $function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function = $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 ])) { } else if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] = $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ]; $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function = $function =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ]; $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} }
} else { } 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 = $function =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ]; $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) { } else if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] = $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ]; $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function = $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 (isset($function)) {
@@ -742,15 +764,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
$function = 'smarty_' . $plugin_type . '_' . $plugin_name; $function = 'smarty_' . $plugin_type . '_' . $plugin_name;
$file = $this->smarty->loadPlugin($function, false); $file = $this->smarty->loadPlugin($function, false);
if (is_string($file)) { if (is_string($file)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->caching && ($this->nocache || $this->tag_nocache)) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] = $this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$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; $function;
} else { } else {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] = $this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$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; $function;
} }
if ($plugin_type === 'modifier') { if ($plugin_type === 'modifier') {
@@ -790,15 +812,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->tag_nocache = $this->tag_nocache || !$cacheable; $this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) { if ($script !== null) {
if (is_file($script)) { if (is_file($script)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { if ($this->caching && ($this->nocache || $this->tag_nocache)) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] = $this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
$script; $script;
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] = $this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback; $callback;
} else { } else {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] = $this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
$script; $script;
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] = $this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback; $callback;
} }
require_once $script; require_once $script;
@@ -853,7 +875,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
// If the template is not evaluated and we have a nocache section and or a nocache tag // If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) { if ($is_code && !empty($content)) {
// generate replacement code // generate replacement code
if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching && if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->caching &&
!$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache) !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
) { ) {
$this->template->compiled->has_nocache_code = true; $this->template->compiled->has_nocache_code = true;
@@ -862,9 +884,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
// make sure we include modifier plugins for nocache code // make sure we include modifier plugins for nocache code
foreach ($this->modifier_plugins as $plugin_name => $dummy) { foreach ($this->modifier_plugins as $plugin_name => $dummy) {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) { if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] = $this->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ]; $this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
} }
} }
} else { } else {
@@ -1266,6 +1288,65 @@ abstract class Smarty_Internal_TemplateCompilerBase
return $code; 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 * method to compile a Smarty template
* *

View File

@@ -18,10 +18,10 @@
*/ */
class Smarty_Internal_Templatelexer class Smarty_Internal_Templatelexer
{ {
const TEXT = 1; const TEXT = 1;
const TAG = 2; const TAG = 2;
const TAGBODY = 3; const TAGBODY = 3;
const LITERAL = 4; const LITERAL = 4;
const DOUBLEQUOTEDSTRING = 5; const DOUBLEQUOTEDSTRING = 5;
/** /**
* Source * Source
@@ -192,8 +192,8 @@ class Smarty_Internal_Templatelexer
* @var null * @var null
*/ */
private $yy_global_pattern5 = null; private $yy_global_pattern5 = null;
private $_yy_state = 1; private $_yy_state = 1;
private $_yy_stack = array(); private $_yy_stack = array();
/** /**
* constructor * constructor
@@ -239,7 +239,7 @@ class Smarty_Internal_Templatelexer
return $this->compiler->replaceDelimiter($preg); return $this->compiler->replaceDelimiter($preg);
} }
/** /**
* check if current value is an autoliteral left delimiter * check if current value is an autoliteral left delimiter
* *
* @return bool * @return bool
@@ -306,7 +306,7 @@ class Smarty_Internal_Templatelexer
} }
} }
public function yylex1() public function yylex1()
{ {
if (!isset($this->yy_global_pattern1)) { if (!isset($this->yy_global_pattern1)) {
$this->yy_global_pattern1 = $this->yy_global_pattern1 =
@@ -398,7 +398,7 @@ class Smarty_Internal_Templatelexer
$this->yypushstate(self::LITERAL); $this->yypushstate(self::LITERAL);
} }
function yy_r1_12() function yy_r1_12()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LITERALEND; $this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
$this->yypushstate(self::LITERAL); $this->yypushstate(self::LITERAL);
@@ -420,11 +420,11 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yylex2() public function yylex2()
{ {
if (!isset($this->yy_global_pattern2)) { if (!isset($this->yy_global_pattern2)) {
$this->yy_global_pattern2 = $this->yy_global_pattern2 =
$this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYalmake_nocache\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/](?:(?!block)[0-9]*[a-zA-Z_]\\w*)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS"); $this->replace("/\G((SMARTYldel)SMARTYal(if|elseif|else if|while)\\s+)|\G((SMARTYldel)SMARTYalfor\\s+)|\G((SMARTYldel)SMARTYalforeach(?![^\s]))|\G((SMARTYldel)SMARTYalsetfilter\\s+)|\G((SMARTYldel)SMARTYalmake_nocache\\s+)|\G((SMARTYldel)SMARTYal[0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$]smarty\\.block\\.(child|parent)\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/][0-9]*[a-zA-Z_]\\w*\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[$][0-9]*[a-zA-Z_]\\w*(\\s+nocache)?\\s*SMARTYrdel)|\G((SMARTYldel)SMARTYal[\/])|\G((SMARTYldel)SMARTYal)/isS");
} }
if (!isset($this->dataLength)) { if (!isset($this->dataLength)) {
$this->dataLength = strlen($this->data); $this->dataLength = strlen($this->data);
@@ -518,13 +518,20 @@ class Smarty_Internal_Templatelexer
} }
function yy_r2_15() function yy_r2_15()
{
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT;
$this->taglineno = $this->line;
}
function yy_r2_18()
{ {
$this->yypopstate(); $this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_CLOSETAG; $this->token = Smarty_Internal_Templateparser::TP_CLOSETAG;
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
function yy_r2_17() function yy_r2_20()
{ {
if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] === self::TEXT) { if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] === self::TEXT) {
$this->yypopstate(); $this->yypopstate();
@@ -538,21 +545,21 @@ class Smarty_Internal_Templatelexer
} }
} // end function } // end function
function yy_r2_20() function yy_r2_23()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH; $this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
function yy_r2_22() function yy_r2_25()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LDEL; $this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->yybegin(self::TAGBODY); $this->yybegin(self::TAGBODY);
$this->taglineno = $this->line; $this->taglineno = $this->line;
} }
public function yylex3() public function yylex3()
{ {
if (!isset($this->yy_global_pattern3)) { if (!isset($this->yy_global_pattern3)) {
$this->yy_global_pattern3 = $this->yy_global_pattern3 =
@@ -830,7 +837,7 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_HEX; $this->token = Smarty_Internal_Templateparser::TP_HEX;
} }
function yy_r3_58() function yy_r3_58()
{ {
$this->token = Smarty_Internal_Templateparser::TP_SPACE; $this->token = Smarty_Internal_Templateparser::TP_SPACE;
} // end function } // end function
@@ -840,7 +847,7 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT; $this->token = Smarty_Internal_Templateparser::TP_TEXT;
} }
public function yylex4() public function yylex4()
{ {
if (!isset($this->yy_global_pattern4)) { if (!isset($this->yy_global_pattern4)) {
$this->yy_global_pattern4 = $this->yy_global_pattern4 =
@@ -912,12 +919,12 @@ class Smarty_Internal_Templatelexer
} }
} }
function yy_r4_5() function yy_r4_5()
{ {
$this->token = Smarty_Internal_Templateparser::TP_LITERAL; $this->token = Smarty_Internal_Templateparser::TP_LITERAL;
} // end function } // end function
public function yylex5() public function yylex5()
{ {
if (!isset($this->yy_global_pattern5)) { if (!isset($this->yy_global_pattern5)) {
$this->yy_global_pattern5 = $this->yy_global_pattern5 =

File diff suppressed because it is too large Load Diff

View File

@@ -200,7 +200,7 @@ class Smarty_Internal_TestInstall
} else { } else {
$errors[ 'plugins_dir' ] = $message; $errors[ 'plugins_dir' ] = $message;
} }
} else if ($_core_plugins_dir && $_core_plugins_dir === realpath($plugin_dir)) { } else if ($_core_plugins_dir && $_core_plugins_dir == realpath($plugin_dir)) {
$_core_plugins_available = true; $_core_plugins_available = true;
if ($errors === null) { if ($errors === null) {
echo "$plugin_dir is OK.\n"; echo "$plugin_dir is OK.\n";
@@ -332,157 +332,159 @@ class Smarty_Internal_TestInstall
// test if sysplugins are available // test if sysplugins are available
$source = SMARTY_SYSPLUGINS_DIR; $source = SMARTY_SYSPLUGINS_DIR;
if (is_dir($source)) { if (is_dir($source)) {
$expectedSysplugins = array( $expectedSysplugins = array('smartycompilerexception.php' => true,
'smartycompilerexception.php' => true, 'smartyexception.php' => true,
'smartyexception.php' => true, 'smarty_cacheresource.php' => true,
'smarty_cacheresource.php' => true, 'smarty_cacheresource_custom.php' => true,
'smarty_cacheresource_custom.php' => true, 'smarty_cacheresource_keyvaluestore.php' => true,
'smarty_cacheresource_keyvaluestore.php' => true, 'smarty_data.php' => true,
'smarty_data.php' => true, 'smarty_internal_block.php' => true,
'smarty_internal_block.php' => true, 'smarty_internal_cacheresource_file.php' => true,
'smarty_internal_cacheresource_file.php' => true, 'smarty_internal_compilebase.php' => true,
'smarty_internal_compilebase.php' => true, 'smarty_internal_compile_append.php' => true,
'smarty_internal_compile_append.php' => true, 'smarty_internal_compile_assign.php' => true,
'smarty_internal_compile_assign.php' => true, 'smarty_internal_compile_block.php' => true,
'smarty_internal_compile_block.php' => true, 'smarty_internal_compile_block_child.php' => true,
'smarty_internal_compile_break.php' => true, 'smarty_internal_compile_block_parent.php' => true,
'smarty_internal_compile_call.php' => true, 'smarty_internal_compile_child.php' => true,
'smarty_internal_compile_capture.php' => true, 'smarty_internal_compile_parent.php' => true,
'smarty_internal_compile_config_load.php' => true, 'smarty_internal_compile_break.php' => true,
'smarty_internal_compile_continue.php' => true, 'smarty_internal_compile_call.php' => true,
'smarty_internal_compile_debug.php' => true, 'smarty_internal_compile_capture.php' => true,
'smarty_internal_compile_eval.php' => true, 'smarty_internal_compile_config_load.php' => true,
'smarty_internal_compile_extends.php' => true, 'smarty_internal_compile_continue.php' => true,
'smarty_internal_compile_for.php' => true, 'smarty_internal_compile_debug.php' => true,
'smarty_internal_compile_foreach.php' => true, 'smarty_internal_compile_eval.php' => true,
'smarty_internal_compile_function.php' => true, 'smarty_internal_compile_extends.php' => true,
'smarty_internal_compile_if.php' => true, 'smarty_internal_compile_for.php' => true,
'smarty_internal_compile_include.php' => true, 'smarty_internal_compile_foreach.php' => true,
'smarty_internal_compile_include_php.php' => true, 'smarty_internal_compile_function.php' => true,
'smarty_internal_compile_insert.php' => true, 'smarty_internal_compile_if.php' => true,
'smarty_internal_compile_ldelim.php' => true, 'smarty_internal_compile_include.php' => true,
'smarty_internal_compile_make_nocache.php' => true, 'smarty_internal_compile_include_php.php' => true,
'smarty_internal_compile_nocache.php' => true, 'smarty_internal_compile_insert.php' => true,
'smarty_internal_compile_private_block_plugin.php' => true, 'smarty_internal_compile_ldelim.php' => true,
'smarty_internal_compile_private_foreachsection.php' => true, 'smarty_internal_compile_make_nocache.php' => true,
'smarty_internal_compile_private_function_plugin.php' => true, 'smarty_internal_compile_nocache.php' => true,
'smarty_internal_compile_private_modifier.php' => true, 'smarty_internal_compile_private_block_plugin.php' => true,
'smarty_internal_compile_private_object_block_function.php' => true, 'smarty_internal_compile_private_foreachsection.php' => true,
'smarty_internal_compile_private_object_function.php' => true, 'smarty_internal_compile_private_function_plugin.php' => true,
'smarty_internal_compile_private_php.php' => true, 'smarty_internal_compile_private_modifier.php' => true,
'smarty_internal_compile_private_print_expression.php' => true, 'smarty_internal_compile_private_object_block_function.php' => true,
'smarty_internal_compile_private_registered_block.php' => true, 'smarty_internal_compile_private_object_function.php' => true,
'smarty_internal_compile_private_registered_function.php' => true, 'smarty_internal_compile_private_php.php' => true,
'smarty_internal_compile_private_special_variable.php' => true, 'smarty_internal_compile_private_print_expression.php' => true,
'smarty_internal_compile_rdelim.php' => true, 'smarty_internal_compile_private_registered_block.php' => true,
'smarty_internal_compile_section.php' => true, 'smarty_internal_compile_private_registered_function.php' => true,
'smarty_internal_compile_setfilter.php' => true, 'smarty_internal_compile_private_special_variable.php' => true,
'smarty_internal_compile_shared_inheritance.php' => true, 'smarty_internal_compile_rdelim.php' => true,
'smarty_internal_compile_while.php' => true, 'smarty_internal_compile_section.php' => true,
'smarty_internal_configfilelexer.php' => true, 'smarty_internal_compile_setfilter.php' => true,
'smarty_internal_configfileparser.php' => true, 'smarty_internal_compile_shared_inheritance.php' => true,
'smarty_internal_config_file_compiler.php' => true, 'smarty_internal_compile_while.php' => true,
'smarty_internal_data.php' => true, 'smarty_internal_configfilelexer.php' => true,
'smarty_internal_debug.php' => true, 'smarty_internal_configfileparser.php' => true,
'smarty_internal_errorhandler.php' => true, 'smarty_internal_config_file_compiler.php' => true,
'smarty_internal_extension_handler.php' => true, 'smarty_internal_data.php' => true,
'smarty_internal_method_addautoloadfilters.php' => true, 'smarty_internal_debug.php' => true,
'smarty_internal_method_adddefaultmodifiers.php' => true, 'smarty_internal_errorhandler.php' => true,
'smarty_internal_method_append.php' => true, 'smarty_internal_extension_handler.php' => true,
'smarty_internal_method_appendbyref.php' => true, 'smarty_internal_method_addautoloadfilters.php' => true,
'smarty_internal_method_assignbyref.php' => true, 'smarty_internal_method_adddefaultmodifiers.php' => true,
'smarty_internal_method_assignglobal.php' => true, 'smarty_internal_method_append.php' => true,
'smarty_internal_method_clearallassign.php' => true, 'smarty_internal_method_appendbyref.php' => true,
'smarty_internal_method_clearallcache.php' => true, 'smarty_internal_method_assignbyref.php' => true,
'smarty_internal_method_clearassign.php' => true, 'smarty_internal_method_assignglobal.php' => true,
'smarty_internal_method_clearcache.php' => true, 'smarty_internal_method_clearallassign.php' => true,
'smarty_internal_method_clearcompiledtemplate.php' => true, 'smarty_internal_method_clearallcache.php' => true,
'smarty_internal_method_clearconfig.php' => true, 'smarty_internal_method_clearassign.php' => true,
'smarty_internal_method_compileallconfig.php' => true, 'smarty_internal_method_clearcache.php' => true,
'smarty_internal_method_compilealltemplates.php' => true, 'smarty_internal_method_clearcompiledtemplate.php' => true,
'smarty_internal_method_configload.php' => true, 'smarty_internal_method_clearconfig.php' => true,
'smarty_internal_method_createdata.php' => true, 'smarty_internal_method_compileallconfig.php' => true,
'smarty_internal_method_getautoloadfilters.php' => true, 'smarty_internal_method_compilealltemplates.php' => true,
'smarty_internal_method_getconfigvariable.php' => true, 'smarty_internal_method_configload.php' => true,
'smarty_internal_method_getconfigvars.php' => true, 'smarty_internal_method_createdata.php' => true,
'smarty_internal_method_getdebugtemplate.php' => true, 'smarty_internal_method_getautoloadfilters.php' => true,
'smarty_internal_method_getdefaultmodifiers.php' => true, 'smarty_internal_method_getconfigvariable.php' => true,
'smarty_internal_method_getglobal.php' => true, 'smarty_internal_method_getconfigvars.php' => true,
'smarty_internal_method_getregisteredobject.php' => true, 'smarty_internal_method_getdebugtemplate.php' => true,
'smarty_internal_method_getstreamvariable.php' => true, 'smarty_internal_method_getdefaultmodifiers.php' => true,
'smarty_internal_method_gettags.php' => true, 'smarty_internal_method_getglobal.php' => true,
'smarty_internal_method_gettemplatevars.php' => true, 'smarty_internal_method_getregisteredobject.php' => true,
'smarty_internal_method_literals.php' => true, 'smarty_internal_method_getstreamvariable.php' => true,
'smarty_internal_method_loadfilter.php' => true, 'smarty_internal_method_gettags.php' => true,
'smarty_internal_method_loadplugin.php' => true, 'smarty_internal_method_gettemplatevars.php' => true,
'smarty_internal_method_mustcompile.php' => true, 'smarty_internal_method_literals.php' => true,
'smarty_internal_method_registercacheresource.php' => true, 'smarty_internal_method_loadfilter.php' => true,
'smarty_internal_method_registerclass.php' => true, 'smarty_internal_method_loadplugin.php' => true,
'smarty_internal_method_registerdefaultconfighandler.php' => true, 'smarty_internal_method_mustcompile.php' => true,
'smarty_internal_method_registerdefaultpluginhandler.php' => true, 'smarty_internal_method_registercacheresource.php' => true,
'smarty_internal_method_registerdefaulttemplatehandler.php' => true, 'smarty_internal_method_registerclass.php' => true,
'smarty_internal_method_registerfilter.php' => true, 'smarty_internal_method_registerdefaultconfighandler.php' => true,
'smarty_internal_method_registerobject.php' => true, 'smarty_internal_method_registerdefaultpluginhandler.php' => true,
'smarty_internal_method_registerplugin.php' => true, 'smarty_internal_method_registerdefaulttemplatehandler.php' => true,
'smarty_internal_method_registerresource.php' => true, 'smarty_internal_method_registerfilter.php' => true,
'smarty_internal_method_setautoloadfilters.php' => true, 'smarty_internal_method_registerobject.php' => true,
'smarty_internal_method_setdebugtemplate.php' => true, 'smarty_internal_method_registerplugin.php' => true,
'smarty_internal_method_setdefaultmodifiers.php' => true, 'smarty_internal_method_registerresource.php' => true,
'smarty_internal_method_unloadfilter.php' => true, 'smarty_internal_method_setautoloadfilters.php' => true,
'smarty_internal_method_unregistercacheresource.php' => true, 'smarty_internal_method_setdebugtemplate.php' => true,
'smarty_internal_method_unregisterfilter.php' => true, 'smarty_internal_method_setdefaultmodifiers.php' => true,
'smarty_internal_method_unregisterobject.php' => true, 'smarty_internal_method_unloadfilter.php' => true,
'smarty_internal_method_unregisterplugin.php' => true, 'smarty_internal_method_unregistercacheresource.php' => true,
'smarty_internal_method_unregisterresource.php' => true, 'smarty_internal_method_unregisterfilter.php' => true,
'smarty_internal_nocache_insert.php' => true, 'smarty_internal_method_unregisterobject.php' => true,
'smarty_internal_parsetree.php' => true, 'smarty_internal_method_unregisterplugin.php' => true,
'smarty_internal_parsetree_code.php' => true, 'smarty_internal_method_unregisterresource.php' => true,
'smarty_internal_parsetree_dq.php' => true, 'smarty_internal_nocache_insert.php' => true,
'smarty_internal_parsetree_dqcontent.php' => true, 'smarty_internal_parsetree.php' => true,
'smarty_internal_parsetree_tag.php' => true, 'smarty_internal_parsetree_code.php' => true,
'smarty_internal_parsetree_template.php' => true, 'smarty_internal_parsetree_dq.php' => true,
'smarty_internal_parsetree_text.php' => true, 'smarty_internal_parsetree_dqcontent.php' => true,
'smarty_internal_resource_eval.php' => true, 'smarty_internal_parsetree_tag.php' => true,
'smarty_internal_resource_extends.php' => true, 'smarty_internal_parsetree_template.php' => true,
'smarty_internal_resource_file.php' => true, 'smarty_internal_parsetree_text.php' => true,
'smarty_internal_resource_php.php' => true, 'smarty_internal_resource_eval.php' => true,
'smarty_internal_resource_registered.php' => true, 'smarty_internal_resource_extends.php' => true,
'smarty_internal_resource_stream.php' => true, 'smarty_internal_resource_file.php' => true,
'smarty_internal_resource_string.php' => true, 'smarty_internal_resource_php.php' => true,
'smarty_internal_runtime_cachemodify.php' => true, 'smarty_internal_resource_registered.php' => true,
'smarty_internal_runtime_cacheresourcefile.php' => true, 'smarty_internal_resource_stream.php' => true,
'smarty_internal_runtime_capture.php' => true, 'smarty_internal_resource_string.php' => true,
'smarty_internal_runtime_codeframe.php' => true, 'smarty_internal_runtime_cachemodify.php' => true,
'smarty_internal_runtime_filterhandler.php' => true, 'smarty_internal_runtime_cacheresourcefile.php' => true,
'smarty_internal_runtime_foreach.php' => true, 'smarty_internal_runtime_capture.php' => true,
'smarty_internal_runtime_getincludepath.php' => true, 'smarty_internal_runtime_codeframe.php' => true,
'smarty_internal_runtime_inheritance.php' => true, 'smarty_internal_runtime_filterhandler.php' => true,
'smarty_internal_runtime_make_nocache.php' => true, 'smarty_internal_runtime_foreach.php' => true,
'smarty_internal_runtime_tplfunction.php' => true, 'smarty_internal_runtime_getincludepath.php' => true,
'smarty_internal_runtime_updatecache.php' => true, 'smarty_internal_runtime_inheritance.php' => true,
'smarty_internal_runtime_updatescope.php' => true, 'smarty_internal_runtime_make_nocache.php' => true,
'smarty_internal_runtime_writefile.php' => true, 'smarty_internal_runtime_tplfunction.php' => true,
'smarty_internal_smartytemplatecompiler.php' => true, 'smarty_internal_runtime_updatecache.php' => true,
'smarty_internal_template.php' => true, 'smarty_internal_runtime_updatescope.php' => true,
'smarty_internal_templatebase.php' => true, 'smarty_internal_runtime_writefile.php' => true,
'smarty_internal_templatecompilerbase.php' => true, 'smarty_internal_smartytemplatecompiler.php' => true,
'smarty_internal_templatelexer.php' => true, 'smarty_internal_template.php' => true,
'smarty_internal_templateparser.php' => true, 'smarty_internal_templatebase.php' => true,
'smarty_internal_testinstall.php' => true, 'smarty_internal_templatecompilerbase.php' => true,
'smarty_internal_undefined.php' => true, 'smarty_internal_templatelexer.php' => true,
'smarty_resource.php' => true, 'smarty_internal_templateparser.php' => true,
'smarty_resource_custom.php' => true, 'smarty_internal_testinstall.php' => true,
'smarty_resource_recompiled.php' => true, 'smarty_internal_undefined.php' => true,
'smarty_resource_uncompiled.php' => true, 'smarty_resource.php' => true,
'smarty_security.php' => true, 'smarty_resource_custom.php' => true,
'smarty_template_cached.php' => true, 'smarty_resource_recompiled.php' => true,
'smarty_template_compiled.php' => true, 'smarty_resource_uncompiled.php' => true,
'smarty_template_config.php' => true, 'smarty_security.php' => true,
'smarty_template_resource_base.php' => true, 'smarty_template_cached.php' => true,
'smarty_template_source.php' => true, 'smarty_template_compiled.php' => true,
'smarty_undefined_variable.php' => true, 'smarty_template_config.php' => true,
'smarty_variable.php' => true, 'smarty_template_resource_base.php' => true,
); 'smarty_template_source.php' => true,
'smarty_undefined_variable.php' => true,
'smarty_variable.php' => true,);
$iterator = new DirectoryIterator($source); $iterator = new DirectoryIterator($source);
foreach ($iterator as $file) { foreach ($iterator as $file) {
if (!$file->isDot()) { if (!$file->isDot()) {

View File

@@ -258,8 +258,6 @@ class Smarty_Security
public function __construct($smarty) public function __construct($smarty)
{ {
$this->smarty = $smarty; $this->smarty = $smarty;
$this->smarty->_cache[ 'template_dir_new' ] = true;
$this->smarty->_cache[ 'config_dir_new' ] = true;
} }
/** /**
@@ -514,60 +512,38 @@ class Smarty_Security
public function isTrustedResourceDir($filepath, $isConfig = null) public function isTrustedResourceDir($filepath, $isConfig = null)
{ {
if ($this->_include_path_status !== $this->smarty->use_include_path) { if ($this->_include_path_status !== $this->smarty->use_include_path) {
foreach ($this->_include_dir as $directory) { $_dir = $this->smarty->use_include_path ? $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty) : array();
unset($this->_resource_dir[ $directory ]); if ($this->_include_dir !== $_dir) {
} $this->_updateResourceDir($this->_include_dir, $_dir);
if ($this->smarty->use_include_path) { $this->_include_dir = $_dir;
$this->_include_dir = array();
$_dirs = $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty);
foreach ($_dirs as $directory) {
$this->_include_dir[] = $directory;
$this->_resource_dir[ $directory ] = true;
}
} }
$this->_include_path_status = $this->smarty->use_include_path; $this->_include_path_status = $this->smarty->use_include_path;
} }
if ($isConfig !== true &&
(!isset($this->smarty->_cache[ 'template_dir_new' ]) || $this->smarty->_cache[ 'template_dir_new' ])
) {
$_dir = $this->smarty->getTemplateDir(); $_dir = $this->smarty->getTemplateDir();
if ($this->_template_dir !== $_dir) { if ($this->_template_dir !== $_dir) {
foreach ($this->_template_dir as $directory) { $this->_updateResourceDir($this->_template_dir, $_dir);
unset($this->_resource_dir[ $directory ]);
}
foreach ($_dir as $directory) {
$this->_resource_dir[ $directory ] = true;
}
$this->_template_dir = $_dir; $this->_template_dir = $_dir;
} }
$this->smarty->_cache[ 'template_dir_new' ] = false;
}
if ($isConfig !== false &&
(!isset($this->smarty->_cache[ 'config_dir_new' ]) || $this->smarty->_cache[ 'config_dir_new' ])
) {
$_dir = $this->smarty->getConfigDir(); $_dir = $this->smarty->getConfigDir();
if ($this->_config_dir !== $_dir) { if ($this->_config_dir !== $_dir) {
foreach ($this->_config_dir as $directory) { $this->_updateResourceDir($this->_config_dir, $_dir);
unset($this->_resource_dir[ $directory ]);
}
foreach ($_dir as $directory) {
$this->_resource_dir[ $directory ] = true;
}
$this->_config_dir = $_dir; $this->_config_dir = $_dir;
} }
$this->smarty->_cache[ 'config_dir_new' ] = false;
} if ($this->_secure_dir !== $this->secure_dir) {
if ($this->_secure_dir !== (array) $this->secure_dir) { $this->secure_dir = (array)$this->secure_dir;
foreach ($this->_secure_dir as $directory) { foreach($this->secure_dir as $k => $d) {
unset($this->_resource_dir[ $directory ]); $this->secure_dir[$k] = $this->smarty->_realpath($d. DIRECTORY_SEPARATOR,true);
} }
foreach ((array) $this->secure_dir as $directory) { $this->_updateResourceDir($this->_secure_dir, $this->secure_dir);
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true); $this->_secure_dir = $this->secure_dir;
$this->_resource_dir[ $directory ] = true; }
} $addPath = $this->_checkDir($filepath, $this->_resource_dir);
$this->_secure_dir = (array) $this->secure_dir; if ($addPath !== false) {
$this->_resource_dir = array_merge($this->_resource_dir, $addPath);
} }
$this->_resource_dir = $this->_checkDir($filepath, $this->_resource_dir);
return true; return true;
} }
@@ -618,49 +594,70 @@ class Smarty_Security
$this->_trusted_dir = $this->trusted_dir; $this->_trusted_dir = $this->trusted_dir;
foreach ((array) $this->trusted_dir as $directory) { foreach ((array) $this->trusted_dir as $directory) {
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true); $directory = $this->smarty->_realpath($directory . '/', true);
$this->_php_resource_dir[ $directory ] = true; $this->_php_resource_dir[ $directory ] = true;
} }
} }
$addPath = $this->_checkDir($filepath, $this->_php_resource_dir);
$this->_php_resource_dir = if ($addPath !== false) {
$this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir); $this->_php_resource_dir = array_merge($this->_php_resource_dir, $addPath);
return true; }
return true;
} }
/**
* Remove old directories and its sub folders, add new directories
*
* @param array $oldDir
* @param array $newDir
*/
private function _updateResourceDir($oldDir, $newDir) {
foreach ($oldDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$length = strlen($directory);
foreach ($this->_resource_dir as $dir) {
if (substr($dir, 0,$length) === $directory) {
unset($this->_resource_dir[ $dir ]);
}
}
}
foreach ($newDir as $directory) {
// $directory = $this->smarty->_realpath($directory, true);
$this->_resource_dir[ $directory ] = true;
}
}
/** /**
* Check if file is inside a valid directory * Check if file is inside a valid directory
* *
* @param string $filepath * @param string $filepath
* @param array $dirs valid directories * @param array $dirs valid directories
* *
* @return array * @return array|bool
* @throws \SmartyException * @throws \SmartyException
*/ */
private function _checkDir($filepath, $dirs) private function _checkDir($filepath, $dirs)
{ {
$directory = dirname($filepath) . DIRECTORY_SEPARATOR; $directory = dirname($this->smarty->_realpath($filepath, true)) . DIRECTORY_SEPARATOR;
$_directory = array(); $_directory = array();
while (true) { if (!preg_match('#[\\\\/][.][.][\\\\/]#',$directory)) {
// remember the directory to add it to _resource_dir in case we're successful while (true) {
$_directory[ $directory ] = true; // test if the directory is trusted
// test if the directory is trusted
if (isset($dirs[ $directory ])) { if (isset($dirs[ $directory ])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup return $_directory;
$dirs = array_merge($dirs, $_directory);
return $dirs;
} }
// abort if we've reached root // abort if we've reached root
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) { if (!preg_match('#[\\\\/][^\\\\/]+[\\\\/]$#', $directory)) {
// give up
break; break;
} }
// bubble up one level // remember the directory to add it to _resource_dir in case we're successful
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory); $_directory[ $directory ] = true;
// bubble up one level
$directory = preg_replace('#[\\\\/][^\\\\/]+[\\\\/]$#', DIRECTORY_SEPARATOR, $directory);
}
} }
// give up // give up
throw new SmartyException("directory '{$filepath}' not allowed by security setting"); throw new SmartyException(sprintf('Smarty Security: not trusted file path \'%s\' ',$filepath));
} }
/** /**

View File

@@ -72,13 +72,6 @@ abstract class Smarty_Template_Resource_Base
*/ */
public $content = null; public $content = null;
/**
* required plugins
*
* @var array
*/
public $required_plugins = array();
/** /**
* Included sub templates * Included sub templates
* - index name * - index name

View File

@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Uwe Tews
* Date: 25.10.2015
* Time: 23:58
*/
$sysplugins = array();
$iterator = new DirectoryIterator(__DIR__ . '/../libs/sysplugins');
foreach ($iterator as $file) {
if (!$file->isDot() && 'php' == $file->getExtension()) {
$filename = $file->getBasename();
$sysplugins[ $filename ] = true;
}
}
$plugins = array();
$iterator = new DirectoryIterator(__DIR__ . '/../libs/plugins');
foreach ($iterator as $file) {
if (!$file->isDot() && 'php' == $file->getExtension()) {
$filename = $file->getBasename();
$plugins[ $filename ] = true;
}
}
$code = file_get_contents(__DIR__ . '/../libs/sysplugins/smarty_internal_testinstall.php');
$expectedPlugins = '$expectedPlugins = ' . var_export($plugins, true);
$code = preg_replace('#\$expectedPlugins =[^;]+#', $expectedPlugins, $code);
$expectedSysplugins = '$expectedSysplugins = ' . var_export($sysplugins, true);
$code = preg_replace('#\$expectedSysplugins =[^;]+#', $expectedSysplugins, $code);
file_put_contents(__DIR__ . '/../libs/sysplugins/smarty_internal_testinstall.php', $code);