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
sudo: true
sudo: false
dist: trusty
@@ -15,6 +15,7 @@ matrix:
- php: 7.0
- php: 7.1
- php: 7.2
fast_finish: true
services:
- 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.3" ]; then phpenv config-add error_reporting.ini; 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
before_install:
- phpenv config-rm xdebug.ini || return 0
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:
- 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
{block_parent} == {$smarty.block.parent}
{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
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()
===================================================================================
@@ -44,7 +49,7 @@ Smarty 3.1.32
....
{/foreach}
Smarty 3.1.31
Smarty 3.1.31
New tags for inheritance parent and child
=========================================
{block_parent} == {$smarty.block.parent}

View File

@@ -1,10 +1,11 @@
# Smarty 3 template engine
www.smarty.net
[smarty.net](https://www.smarty.net/)
## Documentation
For documentation see
www.smarty.net/docs/en/
[www.smarty.net/docs/en/](https://www.smarty.net/docs/en/)
## Distribution repository
> 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.
To get the latest stable version of Smarty 3.1 use
To get the latest stable version of Smarty 3.1 use:
```json
"require": {
@@ -26,7 +27,7 @@ To get the latest stable version of Smarty 3.1 use
in your composer.json file.
To get the trunk version use
To get the trunk version use:
```json
"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
"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
"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
"require": {
@@ -58,7 +59,7 @@ Similar applies for the lexer/parser generator
}
```
Or you could use
Or you could use:
```json
"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
- 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

View File

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

View File

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

View File

@@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsBlock
*/
/**
* Smarty {textformat}{/textformat} block plugin
* Type: block function
@@ -20,7 +19,7 @@
* - wrap_char - string ("\n")
* - indent_char - string (" ")
* - wrap_boundary - boolean (true)
*
*
*
* @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat}
* (Smarty online manual)
@@ -32,18 +31,16 @@
*
* @return string content re-formatted
* @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)) {
return;
}
if (Smarty::$_MBSTRING && !$mb_wordwrap_loaded) {
if (!is_callable('smarty_modifier_mb_wordwrap')) {
require_once(SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php');
}
$mb_wordwrap_loaded = true;
if (Smarty::$_MBSTRING) {
$template->_checkPlugins(array(array('function' => 'smarty_modifier_mb_wordwrap',
'file' => SMARTY_PLUGINS_DIR . 'modifier.mb_wordwrap.php')));
}
$style = null;

View File

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

View File

@@ -36,12 +36,10 @@
* @return string
* @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' ])) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$alt = '';
$file = '';

View File

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

View File

@@ -5,7 +5,6 @@
* @package Smarty
* @subpackage PluginsFunction
*/
/**
* Smarty {html_radios} function plugin
* File: function.html_radios.php
@@ -42,13 +41,12 @@
*
* @return string
* @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' ])) {
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
$template->smarty->_cache[ '_required_sesc' ] = true;
}
$template->_checkPlugins(array(array('function' => 'smarty_function_escape_special_chars',
'file' => SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php')));
$name = 'radio';
$values = null;

View File

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

View File

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

View File

@@ -25,7 +25,8 @@
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
{
static $_double_encode = null;
static $is_loaded1 = false;
static $is_loaded_1 = false;
static $is_loaded_2 = false;
if ($_double_encode === null) {
$_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':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded1) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
$is_loaded1 = true;
}
$is_loaded_1 = true;
}
$return = '';
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':
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded1) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
}
$is_loaded1 = true;
$is_loaded_1 = true;
}
$return = '';
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':
if (Smarty::$_MBSTRING) {
if (!is_callable('smarty_mb_str_replace')) {
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
if (!$is_loaded_2) {
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('@',
'.'), 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
$return = '';
if (Smarty::$_MBSTRING) {
if (!$is_loaded1) {
if (!$is_loaded_1) {
if (!is_callable('smarty_mb_to_unicode')) {
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) {
if ($unicode >= 126) {

View File

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

View File

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

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
*
* @param []\Smarty_Internal_Template_Source $components
* @param \Smarty_Internal_Template $template
*
* @return string
*/
public static function extendsSourceArrayCode($components)
public static function extendsSourceArrayCode(Smarty_Internal_Template $template)
{
$resources = array();
foreach ($components as $source) {
foreach ($template->source->components as $source) {
$resources[] = $source->resource;
}
return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}';
return $template->smarty->left_delimiter . 'extends file=\'extends:' . join('|', $resources) .
'\' extends_resource=true' . $template->smarty->right_delimiter;
}
}

View File

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

View File

@@ -295,12 +295,12 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] =
$tpl->compiled->nocache_hash;
if ($compiler->template->source->type === 'file') {
$sourceInfo = $compiler->template->source->filepath;
if ($tpl->source->type === 'file') {
$sourceInfo = $tpl->source->filepath;
} else {
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
$sourceInfo = $compiler->template->source->type . ':' .
($basename ? $basename : $compiler->template->source->name);
$basename = $tpl->source->handler->getBasename($tpl->source);
$sourceInfo = $tpl->source->type . ':' .
($basename ? $basename : $tpl->source->name);
}
// get compiled code
$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)
{
if ($named) {
$this->resultOffsets[ 'named' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$this->resultOffsets[ 'named' ] = $this->startOffset + 4;
$this->propertyPreg .= "(([\$]smarty[.]{$this->tagName}[.]" . ($this->tagName === 'section' ? "|[\[]\s*" : '')
. "){$attributes['name']}[.](";
$properties = $this->nameProperties;
} else {
$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' ]) ||
isset($compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
if (isset($compiler->required_plugins[ 'nocache' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ]) ||
isset($compiler->required_plugins[ 'compiled' ][ $modifier ][ Smarty::PLUGIN_MODIFIER ][ 'file' ])
) {
// was a plugin
$compiler->known_modifier_type[ $modifier ] = 4;

View File

@@ -51,9 +51,6 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return '';
case 'now':
return 'time()';
case 'block':
$tag = $compiler->getTagCompiler('block');
return $tag->compileSpecialVariable(array(), $compiler, $_index);
case 'cookies':
if (isset($compiler->smarty->security_policy) &&
!$compiler->smarty->security_policy->allow_super_globals
@@ -114,7 +111,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'rdelim':
return "\$_smarty_tpl->smarty->right_delimiter";
default:
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], '\'') . ' is not defined');
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break;
}
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
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal =
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initLocal = array();
$initNamedProperty = array();
$initFor = array();
$incFor = array();
@@ -455,9 +454,6 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
} else {
$output .= "}\n}\n";
}
$output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n";
$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) {
continue;
}
if (!substr_compare($_file, $extension, -strlen($extension)) === 0) {
if (substr_compare($_file, $extension, -strlen($extension)) !== 0) {
continue;
}
if ($_fileinfo->getPath() !== substr($_dir, 0, -1)) {
@@ -115,7 +115,7 @@ class Smarty_Internal_Method_CompileAllTemplates
$_smarty->_clearTemplateCache();
if ($max_errors !== null && $_error_count === $max_errors) {
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
if ($searchParents) {
if ($searchParents && isset($_ptr->parent)) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
@@ -93,7 +93,7 @@ class Smarty_Internal_Method_GetTemplateVars
return $_ptr->tpl_vars[ $varName ];
}
// not found, try at parent
if ($searchParents) {
if ($searchParents && isset($_ptr->parent)) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
@@ -103,14 +103,11 @@ class Smarty_Internal_Method_GetTemplateVars
// found it, return it
return Smarty::$global_tpl_vars[ $varName ];
}
/* @var \Smarty $smarty */
$smarty = isset($data->smarty) ? $data->smarty : $data;
if ($smarty->error_unassigned && $errorEnable) {
if ($errorEnable && $data->_getSmartyObj()->error_unassigned) {
// force a notice
$x = $$varName;
}
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";
}
// 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 .= $content;
$output .= "<?php }\n?>";
$output .= $functions;
$output .= "<?php }\n";
// 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,
$properties = array())
{
$needTotal = $needTotal || isset($properties[ 'total' ]);
$saveVars = array();
$total = null;
if (!is_array($from)) {
if (is_object($from)) {
$total = $this->count($from);
if ($needTotal) {
$total = $this->count($from);
}
} else {
settype($from, 'array');
}
}
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 ])) {
$saveVars[ 'item' ] = array($item,

View File

@@ -42,11 +42,10 @@ class Smarty_Internal_Runtime_Inheritance
*
* @var int
*/
public $tplIndex = -1;
public $tplIndex = - 1;
/**
* Array of template source objects
* - key template index
*
* @var Smarty_Template_Source[]
*/
@@ -75,7 +74,7 @@ class Smarty_Internal_Runtime_Inheritance
$tpl->inheritance->init($tpl, $initChild, $blockNames);
return;
}
$this->tplIndex++;
++$this->tplIndex;
$this->sources[ $this->tplIndex ] = $tpl->source;
// start of child sub template(s)
@@ -85,7 +84,7 @@ class Smarty_Internal_Runtime_Inheritance
//grab any output of child templates
ob_start();
}
$this->inheritanceLevel++;
++$this->inheritanceLevel;
// $tpl->startRenderCallbacks[ 'inheritance' ] = array($this, 'subTemplateStart');
// $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)
{
$this->inheritanceLevel--;
--$this->inheritanceLevel;
if (!$this->inheritanceLevel) {
ob_end_clean();
$this->state = 2;
@@ -167,8 +166,7 @@ class Smarty_Internal_Runtime_Inheritance
*
* @throws \SmartyException
*/
public function process(Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
public function process(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block,
Smarty_Internal_Block $parent = null)
{
if ($block->hide && !isset($block->child)) {
@@ -179,7 +177,7 @@ class Smarty_Internal_Runtime_Inheritance
}
$block->parent = $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))) {
$this->callBlock($block, $tpl);
@@ -187,7 +185,7 @@ class Smarty_Internal_Runtime_Inheritance
$this->process($tpl, $block->child, $block);
}
if ($block->prepend && isset($parent)) {
$this->callParent($tpl, $block);
$this->callParent($tpl, $block, '{block prepend}');
if ($block->append) {
if ($block->callsChild || !isset($block->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_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
*/
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)) {
$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_Block $block
* @param null|string $name
* @param boolean $returnContent flag if content shall be returned
* @param string $tag
*
* @return null|string null or block content dependent on $returnContent
* @return null|string block content
* @throws \SmartyException
*/
public function callParent(Smarty_Internal_Template $tpl,
Smarty_Internal_Block $block,
$name = null,
$returnContent = false)
public function callParent(Smarty_Internal_Template $tpl, Smarty_Internal_Block $block, $tag)
{
if ($returnContent) {
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)) {
if (isset($block->parent)) {
$this->callBlock($block->parent, $tpl);
} 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_Template $tpl

View File

@@ -120,15 +120,13 @@ class Smarty_Internal_Runtime_TplFunction
}
// add template function code to cache file
if (isset($tplPtr->cached)) {
/* @var Smarty_Template_Cached $cache */
$cache = $tplPtr->cached;
$content = $cache->read($tplPtr);
$content = $tplPtr->cached->read($tplPtr);
if ($content) {
// check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) {
$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) .
"\n" . preg_replace(array('/^\s*<\?php\s+/',
'/\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
*
@@ -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_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
*
* @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
) {
// don't write cache file
return false;
}
if (!isset($_template->cached)) {
$_template->loadCached();
}
$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
*
* @param \Smarty_Template_Cached $cached
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @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) {
$cached = $_template->cached;
if ($cached->handler->writeCachedContent($_template, $content)) {
$cached->content = null;
$cached->timestamp = time();
@@ -160,5 +174,4 @@ class Smarty_Internal_Runtime_UpdateCache
return false;
}
}

View File

@@ -234,15 +234,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$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 &&
(!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
(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
* - 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)
{
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
*
* @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 createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getAutoloadFilters(string $type = null)

View File

@@ -57,6 +57,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var bool
*/
public $suppressNocacheProcessing = false;
/**
* caching enabled (copied from template object)
*
* @var int
*/
public $caching = 0;
/**
* tag stack
*
@@ -69,6 +77,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var 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
*
@@ -374,6 +394,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
} else {
$this->nocache_hash = $template->compiled->nocache_hash;
}
$this->caching = $template->caching;
// flag for nocache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
@@ -394,12 +415,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
// we have array of inheritance templates by extends: resource
// generate corresponding source code sequence
$_content =
Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components);
Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template);
} else {
// get template source
$_content = $this->template->source->getContent();
}
$_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) {
if ($this->smarty->debugging) {
@@ -594,7 +618,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function processText($text)
{
if ((string)$text !== '') {
if ((string) $text != '') {
$store = array();
$_store = 0;
if ($this->parser->strip) {
@@ -602,39 +626,37 @@ abstract class Smarty_Internal_TemplateCompilerBase
// capture html elements not to be messed with
$_offset = 0;
if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
$text,
$matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
$text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
++$_store;
$_store ++;
}
}
$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
'#(: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!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#>[\040\011]+$#Ss' => '> ',
'#>[\040\011]*[\n]\s*$#Ss' => '>',
$this->stripRegEx => '',);
'#>[\040\011]+$#Ss' => '> ', '#>[\040\011]*[\n]\s*$#Ss' => '>',
$this->stripRegEx => '',);
$text = preg_replace(array_keys($expressions), array_values($expressions), $text);
$_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is',
$text,
$matches,
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ];
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length;
++$_store;
$_store ++;
}
}
} else {
@@ -711,25 +733,25 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function getPlugin($plugin_name, $plugin_type)
{
$function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
if ($this->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
}
} else {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} else if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
}
}
if (isset($function)) {
@@ -742,15 +764,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
$function = 'smarty_' . $plugin_type . '_' . $plugin_name;
$file = $this->smarty->loadPlugin($function, false);
if (is_string($file)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
if ($this->caching && ($this->nocache || $this->tag_nocache)) {
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
} else {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
}
if ($plugin_type === 'modifier') {
@@ -790,15 +812,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) {
if (is_file($script)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
if ($this->caching && ($this->nocache || $this->tag_nocache)) {
$this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
$this->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
} else {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
$this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
}
require_once $script;
@@ -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 ($is_code && !empty($content)) {
// 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->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";
// make sure we include modifier plugins for nocache code
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
$this->required_plugins[ 'nocache' ][ $plugin_name ][ 'modifier' ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ];
}
}
} else {
@@ -1266,6 +1288,65 @@ abstract class Smarty_Internal_TemplateCompilerBase
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
*

View File

@@ -18,10 +18,10 @@
*/
class Smarty_Internal_Templatelexer
{
const TEXT = 1;
const TAG = 2;
const TAGBODY = 3;
const LITERAL = 4;
const TEXT = 1;
const TAG = 2;
const TAGBODY = 3;
const LITERAL = 4;
const DOUBLEQUOTEDSTRING = 5;
/**
* Source
@@ -192,8 +192,8 @@ class Smarty_Internal_Templatelexer
* @var null
*/
private $yy_global_pattern5 = null;
private $_yy_state = 1;
private $_yy_stack = array();
private $_yy_state = 1;
private $_yy_stack = array();
/**
* constructor
@@ -239,7 +239,7 @@ class Smarty_Internal_Templatelexer
return $this->compiler->replaceDelimiter($preg);
}
/**
/**
* check if current value is an autoliteral left delimiter
*
* @return bool
@@ -306,7 +306,7 @@ class Smarty_Internal_Templatelexer
}
}
public function yylex1()
public function yylex1()
{
if (!isset($this->yy_global_pattern1)) {
$this->yy_global_pattern1 =
@@ -398,7 +398,7 @@ class Smarty_Internal_Templatelexer
$this->yypushstate(self::LITERAL);
}
function yy_r1_12()
function yy_r1_12()
{
$this->token = Smarty_Internal_Templateparser::TP_LITERALEND;
$this->yypushstate(self::LITERAL);
@@ -420,11 +420,11 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
public function yylex2()
public function yylex2()
{
if (!isset($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)) {
$this->dataLength = strlen($this->data);
@@ -518,13 +518,20 @@ class Smarty_Internal_Templatelexer
}
function yy_r2_15()
{
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_SMARTYBLOCKCHILDPARENT;
$this->taglineno = $this->line;
}
function yy_r2_18()
{
$this->yypopstate();
$this->token = Smarty_Internal_Templateparser::TP_CLOSETAG;
$this->taglineno = $this->line;
}
function yy_r2_17()
function yy_r2_20()
{
if ($this->_yy_stack[ count($this->_yy_stack) - 1 ] === self::TEXT) {
$this->yypopstate();
@@ -538,21 +545,21 @@ class Smarty_Internal_Templatelexer
}
} // end function
function yy_r2_20()
function yy_r2_23()
{
$this->token = Smarty_Internal_Templateparser::TP_LDELSLASH;
$this->yybegin(self::TAGBODY);
$this->taglineno = $this->line;
}
function yy_r2_22()
function yy_r2_25()
{
$this->token = Smarty_Internal_Templateparser::TP_LDEL;
$this->yybegin(self::TAGBODY);
$this->taglineno = $this->line;
}
public function yylex3()
public function yylex3()
{
if (!isset($this->yy_global_pattern3)) {
$this->yy_global_pattern3 =
@@ -830,7 +837,7 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_HEX;
}
function yy_r3_58()
function yy_r3_58()
{
$this->token = Smarty_Internal_Templateparser::TP_SPACE;
} // end function
@@ -840,7 +847,7 @@ class Smarty_Internal_Templatelexer
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
}
public function yylex4()
public function yylex4()
{
if (!isset($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;
} // end function
public function yylex5()
public function yylex5()
{
if (!isset($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 {
$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;
if ($errors === null) {
echo "$plugin_dir is OK.\n";
@@ -332,157 +332,159 @@ class Smarty_Internal_TestInstall
// test if sysplugins are available
$source = SMARTY_SYSPLUGINS_DIR;
if (is_dir($source)) {
$expectedSysplugins = array(
'smartycompilerexception.php' => true,
'smartyexception.php' => true,
'smarty_cacheresource.php' => true,
'smarty_cacheresource_custom.php' => true,
'smarty_cacheresource_keyvaluestore.php' => true,
'smarty_data.php' => true,
'smarty_internal_block.php' => true,
'smarty_internal_cacheresource_file.php' => true,
'smarty_internal_compilebase.php' => true,
'smarty_internal_compile_append.php' => true,
'smarty_internal_compile_assign.php' => true,
'smarty_internal_compile_block.php' => true,
'smarty_internal_compile_break.php' => true,
'smarty_internal_compile_call.php' => true,
'smarty_internal_compile_capture.php' => true,
'smarty_internal_compile_config_load.php' => true,
'smarty_internal_compile_continue.php' => true,
'smarty_internal_compile_debug.php' => true,
'smarty_internal_compile_eval.php' => true,
'smarty_internal_compile_extends.php' => true,
'smarty_internal_compile_for.php' => true,
'smarty_internal_compile_foreach.php' => true,
'smarty_internal_compile_function.php' => true,
'smarty_internal_compile_if.php' => true,
'smarty_internal_compile_include.php' => true,
'smarty_internal_compile_include_php.php' => true,
'smarty_internal_compile_insert.php' => true,
'smarty_internal_compile_ldelim.php' => true,
'smarty_internal_compile_make_nocache.php' => true,
'smarty_internal_compile_nocache.php' => true,
'smarty_internal_compile_private_block_plugin.php' => true,
'smarty_internal_compile_private_foreachsection.php' => true,
'smarty_internal_compile_private_function_plugin.php' => true,
'smarty_internal_compile_private_modifier.php' => true,
'smarty_internal_compile_private_object_block_function.php' => true,
'smarty_internal_compile_private_object_function.php' => true,
'smarty_internal_compile_private_php.php' => true,
'smarty_internal_compile_private_print_expression.php' => true,
'smarty_internal_compile_private_registered_block.php' => true,
'smarty_internal_compile_private_registered_function.php' => true,
'smarty_internal_compile_private_special_variable.php' => true,
'smarty_internal_compile_rdelim.php' => true,
'smarty_internal_compile_section.php' => true,
'smarty_internal_compile_setfilter.php' => true,
'smarty_internal_compile_shared_inheritance.php' => true,
'smarty_internal_compile_while.php' => true,
'smarty_internal_configfilelexer.php' => true,
'smarty_internal_configfileparser.php' => true,
'smarty_internal_config_file_compiler.php' => true,
'smarty_internal_data.php' => true,
'smarty_internal_debug.php' => true,
'smarty_internal_errorhandler.php' => true,
'smarty_internal_extension_handler.php' => true,
'smarty_internal_method_addautoloadfilters.php' => true,
'smarty_internal_method_adddefaultmodifiers.php' => true,
'smarty_internal_method_append.php' => true,
'smarty_internal_method_appendbyref.php' => true,
'smarty_internal_method_assignbyref.php' => true,
'smarty_internal_method_assignglobal.php' => true,
'smarty_internal_method_clearallassign.php' => true,
'smarty_internal_method_clearallcache.php' => true,
'smarty_internal_method_clearassign.php' => true,
'smarty_internal_method_clearcache.php' => true,
'smarty_internal_method_clearcompiledtemplate.php' => true,
'smarty_internal_method_clearconfig.php' => true,
'smarty_internal_method_compileallconfig.php' => true,
'smarty_internal_method_compilealltemplates.php' => true,
'smarty_internal_method_configload.php' => true,
'smarty_internal_method_createdata.php' => true,
'smarty_internal_method_getautoloadfilters.php' => true,
'smarty_internal_method_getconfigvariable.php' => true,
'smarty_internal_method_getconfigvars.php' => true,
'smarty_internal_method_getdebugtemplate.php' => true,
'smarty_internal_method_getdefaultmodifiers.php' => true,
'smarty_internal_method_getglobal.php' => true,
'smarty_internal_method_getregisteredobject.php' => true,
'smarty_internal_method_getstreamvariable.php' => true,
'smarty_internal_method_gettags.php' => true,
'smarty_internal_method_gettemplatevars.php' => true,
'smarty_internal_method_literals.php' => true,
'smarty_internal_method_loadfilter.php' => true,
'smarty_internal_method_loadplugin.php' => true,
'smarty_internal_method_mustcompile.php' => true,
'smarty_internal_method_registercacheresource.php' => true,
'smarty_internal_method_registerclass.php' => true,
'smarty_internal_method_registerdefaultconfighandler.php' => true,
'smarty_internal_method_registerdefaultpluginhandler.php' => true,
'smarty_internal_method_registerdefaulttemplatehandler.php' => true,
'smarty_internal_method_registerfilter.php' => true,
'smarty_internal_method_registerobject.php' => true,
'smarty_internal_method_registerplugin.php' => true,
'smarty_internal_method_registerresource.php' => true,
'smarty_internal_method_setautoloadfilters.php' => true,
'smarty_internal_method_setdebugtemplate.php' => true,
'smarty_internal_method_setdefaultmodifiers.php' => true,
'smarty_internal_method_unloadfilter.php' => true,
'smarty_internal_method_unregistercacheresource.php' => true,
'smarty_internal_method_unregisterfilter.php' => true,
'smarty_internal_method_unregisterobject.php' => true,
'smarty_internal_method_unregisterplugin.php' => true,
'smarty_internal_method_unregisterresource.php' => true,
'smarty_internal_nocache_insert.php' => true,
'smarty_internal_parsetree.php' => true,
'smarty_internal_parsetree_code.php' => true,
'smarty_internal_parsetree_dq.php' => true,
'smarty_internal_parsetree_dqcontent.php' => true,
'smarty_internal_parsetree_tag.php' => true,
'smarty_internal_parsetree_template.php' => true,
'smarty_internal_parsetree_text.php' => true,
'smarty_internal_resource_eval.php' => true,
'smarty_internal_resource_extends.php' => true,
'smarty_internal_resource_file.php' => true,
'smarty_internal_resource_php.php' => true,
'smarty_internal_resource_registered.php' => true,
'smarty_internal_resource_stream.php' => true,
'smarty_internal_resource_string.php' => true,
'smarty_internal_runtime_cachemodify.php' => true,
'smarty_internal_runtime_cacheresourcefile.php' => true,
'smarty_internal_runtime_capture.php' => true,
'smarty_internal_runtime_codeframe.php' => true,
'smarty_internal_runtime_filterhandler.php' => true,
'smarty_internal_runtime_foreach.php' => true,
'smarty_internal_runtime_getincludepath.php' => true,
'smarty_internal_runtime_inheritance.php' => true,
'smarty_internal_runtime_make_nocache.php' => true,
'smarty_internal_runtime_tplfunction.php' => true,
'smarty_internal_runtime_updatecache.php' => true,
'smarty_internal_runtime_updatescope.php' => true,
'smarty_internal_runtime_writefile.php' => true,
'smarty_internal_smartytemplatecompiler.php' => true,
'smarty_internal_template.php' => true,
'smarty_internal_templatebase.php' => true,
'smarty_internal_templatecompilerbase.php' => true,
'smarty_internal_templatelexer.php' => true,
'smarty_internal_templateparser.php' => true,
'smarty_internal_testinstall.php' => true,
'smarty_internal_undefined.php' => true,
'smarty_resource.php' => true,
'smarty_resource_custom.php' => true,
'smarty_resource_recompiled.php' => true,
'smarty_resource_uncompiled.php' => true,
'smarty_security.php' => true,
'smarty_template_cached.php' => true,
'smarty_template_compiled.php' => true,
'smarty_template_config.php' => true,
'smarty_template_resource_base.php' => true,
'smarty_template_source.php' => true,
'smarty_undefined_variable.php' => true,
'smarty_variable.php' => true,
);
$expectedSysplugins = array('smartycompilerexception.php' => true,
'smartyexception.php' => true,
'smarty_cacheresource.php' => true,
'smarty_cacheresource_custom.php' => true,
'smarty_cacheresource_keyvaluestore.php' => true,
'smarty_data.php' => true,
'smarty_internal_block.php' => true,
'smarty_internal_cacheresource_file.php' => true,
'smarty_internal_compilebase.php' => true,
'smarty_internal_compile_append.php' => true,
'smarty_internal_compile_assign.php' => true,
'smarty_internal_compile_block.php' => true,
'smarty_internal_compile_block_child.php' => true,
'smarty_internal_compile_block_parent.php' => true,
'smarty_internal_compile_child.php' => true,
'smarty_internal_compile_parent.php' => true,
'smarty_internal_compile_break.php' => true,
'smarty_internal_compile_call.php' => true,
'smarty_internal_compile_capture.php' => true,
'smarty_internal_compile_config_load.php' => true,
'smarty_internal_compile_continue.php' => true,
'smarty_internal_compile_debug.php' => true,
'smarty_internal_compile_eval.php' => true,
'smarty_internal_compile_extends.php' => true,
'smarty_internal_compile_for.php' => true,
'smarty_internal_compile_foreach.php' => true,
'smarty_internal_compile_function.php' => true,
'smarty_internal_compile_if.php' => true,
'smarty_internal_compile_include.php' => true,
'smarty_internal_compile_include_php.php' => true,
'smarty_internal_compile_insert.php' => true,
'smarty_internal_compile_ldelim.php' => true,
'smarty_internal_compile_make_nocache.php' => true,
'smarty_internal_compile_nocache.php' => true,
'smarty_internal_compile_private_block_plugin.php' => true,
'smarty_internal_compile_private_foreachsection.php' => true,
'smarty_internal_compile_private_function_plugin.php' => true,
'smarty_internal_compile_private_modifier.php' => true,
'smarty_internal_compile_private_object_block_function.php' => true,
'smarty_internal_compile_private_object_function.php' => true,
'smarty_internal_compile_private_php.php' => true,
'smarty_internal_compile_private_print_expression.php' => true,
'smarty_internal_compile_private_registered_block.php' => true,
'smarty_internal_compile_private_registered_function.php' => true,
'smarty_internal_compile_private_special_variable.php' => true,
'smarty_internal_compile_rdelim.php' => true,
'smarty_internal_compile_section.php' => true,
'smarty_internal_compile_setfilter.php' => true,
'smarty_internal_compile_shared_inheritance.php' => true,
'smarty_internal_compile_while.php' => true,
'smarty_internal_configfilelexer.php' => true,
'smarty_internal_configfileparser.php' => true,
'smarty_internal_config_file_compiler.php' => true,
'smarty_internal_data.php' => true,
'smarty_internal_debug.php' => true,
'smarty_internal_errorhandler.php' => true,
'smarty_internal_extension_handler.php' => true,
'smarty_internal_method_addautoloadfilters.php' => true,
'smarty_internal_method_adddefaultmodifiers.php' => true,
'smarty_internal_method_append.php' => true,
'smarty_internal_method_appendbyref.php' => true,
'smarty_internal_method_assignbyref.php' => true,
'smarty_internal_method_assignglobal.php' => true,
'smarty_internal_method_clearallassign.php' => true,
'smarty_internal_method_clearallcache.php' => true,
'smarty_internal_method_clearassign.php' => true,
'smarty_internal_method_clearcache.php' => true,
'smarty_internal_method_clearcompiledtemplate.php' => true,
'smarty_internal_method_clearconfig.php' => true,
'smarty_internal_method_compileallconfig.php' => true,
'smarty_internal_method_compilealltemplates.php' => true,
'smarty_internal_method_configload.php' => true,
'smarty_internal_method_createdata.php' => true,
'smarty_internal_method_getautoloadfilters.php' => true,
'smarty_internal_method_getconfigvariable.php' => true,
'smarty_internal_method_getconfigvars.php' => true,
'smarty_internal_method_getdebugtemplate.php' => true,
'smarty_internal_method_getdefaultmodifiers.php' => true,
'smarty_internal_method_getglobal.php' => true,
'smarty_internal_method_getregisteredobject.php' => true,
'smarty_internal_method_getstreamvariable.php' => true,
'smarty_internal_method_gettags.php' => true,
'smarty_internal_method_gettemplatevars.php' => true,
'smarty_internal_method_literals.php' => true,
'smarty_internal_method_loadfilter.php' => true,
'smarty_internal_method_loadplugin.php' => true,
'smarty_internal_method_mustcompile.php' => true,
'smarty_internal_method_registercacheresource.php' => true,
'smarty_internal_method_registerclass.php' => true,
'smarty_internal_method_registerdefaultconfighandler.php' => true,
'smarty_internal_method_registerdefaultpluginhandler.php' => true,
'smarty_internal_method_registerdefaulttemplatehandler.php' => true,
'smarty_internal_method_registerfilter.php' => true,
'smarty_internal_method_registerobject.php' => true,
'smarty_internal_method_registerplugin.php' => true,
'smarty_internal_method_registerresource.php' => true,
'smarty_internal_method_setautoloadfilters.php' => true,
'smarty_internal_method_setdebugtemplate.php' => true,
'smarty_internal_method_setdefaultmodifiers.php' => true,
'smarty_internal_method_unloadfilter.php' => true,
'smarty_internal_method_unregistercacheresource.php' => true,
'smarty_internal_method_unregisterfilter.php' => true,
'smarty_internal_method_unregisterobject.php' => true,
'smarty_internal_method_unregisterplugin.php' => true,
'smarty_internal_method_unregisterresource.php' => true,
'smarty_internal_nocache_insert.php' => true,
'smarty_internal_parsetree.php' => true,
'smarty_internal_parsetree_code.php' => true,
'smarty_internal_parsetree_dq.php' => true,
'smarty_internal_parsetree_dqcontent.php' => true,
'smarty_internal_parsetree_tag.php' => true,
'smarty_internal_parsetree_template.php' => true,
'smarty_internal_parsetree_text.php' => true,
'smarty_internal_resource_eval.php' => true,
'smarty_internal_resource_extends.php' => true,
'smarty_internal_resource_file.php' => true,
'smarty_internal_resource_php.php' => true,
'smarty_internal_resource_registered.php' => true,
'smarty_internal_resource_stream.php' => true,
'smarty_internal_resource_string.php' => true,
'smarty_internal_runtime_cachemodify.php' => true,
'smarty_internal_runtime_cacheresourcefile.php' => true,
'smarty_internal_runtime_capture.php' => true,
'smarty_internal_runtime_codeframe.php' => true,
'smarty_internal_runtime_filterhandler.php' => true,
'smarty_internal_runtime_foreach.php' => true,
'smarty_internal_runtime_getincludepath.php' => true,
'smarty_internal_runtime_inheritance.php' => true,
'smarty_internal_runtime_make_nocache.php' => true,
'smarty_internal_runtime_tplfunction.php' => true,
'smarty_internal_runtime_updatecache.php' => true,
'smarty_internal_runtime_updatescope.php' => true,
'smarty_internal_runtime_writefile.php' => true,
'smarty_internal_smartytemplatecompiler.php' => true,
'smarty_internal_template.php' => true,
'smarty_internal_templatebase.php' => true,
'smarty_internal_templatecompilerbase.php' => true,
'smarty_internal_templatelexer.php' => true,
'smarty_internal_templateparser.php' => true,
'smarty_internal_testinstall.php' => true,
'smarty_internal_undefined.php' => true,
'smarty_resource.php' => true,
'smarty_resource_custom.php' => true,
'smarty_resource_recompiled.php' => true,
'smarty_resource_uncompiled.php' => true,
'smarty_security.php' => true,
'smarty_template_cached.php' => true,
'smarty_template_compiled.php' => true,
'smarty_template_config.php' => true,
'smarty_template_resource_base.php' => true,
'smarty_template_source.php' => true,
'smarty_undefined_variable.php' => true,
'smarty_variable.php' => true,);
$iterator = new DirectoryIterator($source);
foreach ($iterator as $file) {
if (!$file->isDot()) {

View File

@@ -258,8 +258,6 @@ class Smarty_Security
public function __construct($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)
{
if ($this->_include_path_status !== $this->smarty->use_include_path) {
foreach ($this->_include_dir as $directory) {
unset($this->_resource_dir[ $directory ]);
}
if ($this->smarty->use_include_path) {
$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;
}
$_dir = $this->smarty->use_include_path ? $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty) : array();
if ($this->_include_dir !== $_dir) {
$this->_updateResourceDir($this->_include_dir, $_dir);
$this->_include_dir = $_dir;
}
$this->_include_path_status = $this->smarty->use_include_path;
}
if ($isConfig !== true &&
(!isset($this->smarty->_cache[ 'template_dir_new' ]) || $this->smarty->_cache[ 'template_dir_new' ])
) {
$_dir = $this->smarty->getTemplateDir();
if ($this->_template_dir !== $_dir) {
foreach ($this->_template_dir as $directory) {
unset($this->_resource_dir[ $directory ]);
}
foreach ($_dir as $directory) {
$this->_resource_dir[ $directory ] = true;
}
$this->_updateResourceDir($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();
if ($this->_config_dir !== $_dir) {
foreach ($this->_config_dir as $directory) {
unset($this->_resource_dir[ $directory ]);
}
foreach ($_dir as $directory) {
$this->_resource_dir[ $directory ] = true;
}
$this->_updateResourceDir($this->_config_dir, $_dir);
$this->_config_dir = $_dir;
}
$this->smarty->_cache[ 'config_dir_new' ] = false;
}
if ($this->_secure_dir !== (array) $this->secure_dir) {
foreach ($this->_secure_dir as $directory) {
unset($this->_resource_dir[ $directory ]);
if ($this->_secure_dir !== $this->secure_dir) {
$this->secure_dir = (array)$this->secure_dir;
foreach($this->secure_dir as $k => $d) {
$this->secure_dir[$k] = $this->smarty->_realpath($d. DIRECTORY_SEPARATOR,true);
}
foreach ((array) $this->secure_dir as $directory) {
$directory = $this->smarty->_realpath($directory . DIRECTORY_SEPARATOR, true);
$this->_resource_dir[ $directory ] = true;
}
$this->_secure_dir = (array) $this->secure_dir;
$this->_updateResourceDir($this->_secure_dir, $this->secure_dir);
$this->_secure_dir = $this->secure_dir;
}
$addPath = $this->_checkDir($filepath, $this->_resource_dir);
if ($addPath !== false) {
$this->_resource_dir = array_merge($this->_resource_dir, $addPath);
}
$this->_resource_dir = $this->_checkDir($filepath, $this->_resource_dir);
return true;
}
@@ -618,49 +594,70 @@ class Smarty_Security
$this->_trusted_dir = $this->trusted_dir;
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 =
$this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir);
return true;
$addPath = $this->_checkDir($filepath, $this->_php_resource_dir);
if ($addPath !== false) {
$this->_php_resource_dir = array_merge($this->_php_resource_dir, $addPath);
}
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
*
* @param string $filepath
* @param array $dirs valid directories
*
* @return array
* @return array|bool
* @throws \SmartyException
*/
private function _checkDir($filepath, $dirs)
{
$directory = dirname($filepath) . DIRECTORY_SEPARATOR;
$directory = dirname($this->smarty->_realpath($filepath, true)) . DIRECTORY_SEPARATOR;
$_directory = array();
while (true) {
// remember the directory to add it to _resource_dir in case we're successful
$_directory[ $directory ] = true;
// test if the directory is trusted
if (!preg_match('#[\\\\/][.][.][\\\\/]#',$directory)) {
while (true) {
// test if the directory is trusted
if (isset($dirs[ $directory ])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$dirs = array_merge($dirs, $_directory);
return $dirs;
return $_directory;
}
// abort if we've reached root
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
if (!preg_match('#[\\\\/][^\\\\/]+[\\\\/]$#', $directory)) {
// give up
break;
}
// bubble up one level
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DIRECTORY_SEPARATOR, $directory);
// remember the directory to add it to _resource_dir in case we're successful
$_directory[ $directory ] = true;
// bubble up one level
$directory = preg_replace('#[\\\\/][^\\\\/]+[\\\\/]$#', DIRECTORY_SEPARATOR, $directory);
}
}
// 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;
/**
* required plugins
*
* @var array
*/
public $required_plugins = array();
/**
* Included sub templates
* - 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);