Compare commits

...

38 Commits

Author SHA1 Message Date
uwetews 35480f10e7 Release 3.1.29 2015-12-21 02:57:06 +01:00
uwetews 6867515183 v3.1.28-p1 patch 2015-12-21 02:49:46 +01:00
uwetews efaa61cfb6 - optimization improve speed of filetime checks on extends and extendsall resource 2015-12-21 02:18:27 +01:00
uwetews 3548de5fa1 - bugfix the source uid of the extendsall resource must contain $template_dir settings https://github.com/smarty-php/smarty/issues/123 2015-12-20 17:51:16 +01:00
uwetews 78243be722 - bugfix add addition check for OS type on normalization of file path https://github.com/smarty-php/smarty/issues/134 2015-12-20 16:21:32 +01:00
uwetews 6483164d18 - update compilation of Smarty special variables 2015-12-20 15:13:34 +01:00
uwetews e655856871 - bugfix failure when the default resource type was set to 'extendsall' https://github.com/smarty-php/smarty/issues/123 2015-12-20 05:27:43 +01:00
uwetews dc9872e0e2 - bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139 2015-12-19 21:55:32 +01:00
uwetews 9cdf68807f - improvement make sure that compiled and cache templates never can contain a trailing '?>? 2015-12-19 21:37:46 +01:00
uwetews d11956fc78 - remove no longer used code 2015-12-19 21:35:24 +01:00
uwetews 116c0caa5b update travis 2015-12-19 20:19:32 +01:00
uwetews b75f638d20 update travis 2015-12-19 20:16:18 +01:00
uwetews 5558f4face update travis 2015-12-19 20:13:46 +01:00
uwetews 224a1c4874 - bugfix broken PHP 5.2 compatibility 2015-12-19 20:10:45 +01:00
uwetews e32720ef4e - bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138 2015-12-19 19:18:31 +01:00
uwetews 818715351a typo 2015-12-18 05:52:04 +01:00
uwetews 44eea98260 - bugfix regression when mdifier parameter was follow by math https://github.com/smarty-php/smarty/issues/132 2015-12-18 04:43:55 +01:00
uwetews 05c069d889 - bugfix using {block append/prepend} on same block in multiple levels of inheritance templates could fail (forum topic 25827) 2015-12-18 00:34:58 +01:00
uwetews 9a8bcb93b1 - bugfix text content consisting of just a single '0' like in {if true}0{/if} was suppressed (forum topic 25834) 2015-12-17 21:51:19 +01:00
uwetews 919861014a - bugfix using {block append/prepend} on same block in multiple levels of inheritance templates could fail (forum topic 25827) 2015-12-17 21:32:36 +01:00
uwetews fb80bd53a5 - bugfix {$smarty.capture.nameFail} did lowercase capture name https://github.com/smarty-php/smarty/issues/135 2015-12-17 20:31:30 +01:00
uwetews b7118b6beb - optimize direct access $smarty->template_dir = 'foo'; should call Smarty::setTemplateDir() https://github.com/smarty-php/smarty/issues/121 2015-12-16 22:32:07 +01:00
uwetews c4a5aca865 - bugfix direct access $smarty->template_dir = 'foo'; should call Smarty::setTemplateDir() https://github.com/smarty-php/smarty/issues/121 2015-12-16 04:54:34 +01:00
uwetews fa3aed33ee - bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128 2015-12-16 03:25:33 +01:00
uwetews e1eefdca75 Merge pull request #127 from logbon72/master
Restored Smarty_Internal_Data::getVariable()
2015-12-16 00:58:13 +01:00
uwetews b842934abd Merge pull request #129 from eaglewu/patch-1
Compatible with PHP7
2015-12-16 00:57:54 +01:00
Di Wu 1f7a82e2be Compatible with PHP7
Explicitly defining the evaluation order with the curly braces.

In PHP5
``
$person->$property['first'] is evaluated as $person->{$property['first']}
``

But in PHP7
``
$person->$property['first'] is evaluated as {$person->$property}['first']
``
2015-12-15 17:37:53 +08:00
Joseph Orilogbon 048b648bff - Restored Smarty_Internal_Data::getVariable(), but added deprecation message. 2015-12-15 08:54:21 +01:00
uwetews 017120c1ef - bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828) 2015-12-15 03:37:13 +01:00
uwetews 80f872ac06 Merge pull request #126 from glensc/patch-1
Update NEW_FEATURES.txt
2015-12-15 01:52:53 +01:00
uwetews 862ce9db08 - bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122 2015-12-15 01:34:18 +01:00
Elan Ruusamäe ca12046179 typos here too 2015-12-14 23:33:42 +02:00
Elan Ruusamäe 362af770fe one more typo fix
altho not sure where the quote should be here
2015-12-14 23:31:40 +02:00
Elan Ruusamäe b40684c5d5 more typos 2015-12-14 23:30:45 +02:00
Elan Ruusamäe 5c71e35d4f Update NEW_FEATURES.txt
typos
2015-12-14 23:29:07 +02:00
uwetews c4e6ad6c35 - bugfix multiple calls of {section} with same name droped E_NOTICE error https://github.com/smarty-php/smarty/issues/118 2015-12-14 00:18:27 +01:00
uwetews f8ec3ecaef - bugfix {$smarty.config.foo} broken in 3.1.28 https://github.com/smarty-php/smarty/issues/120 2015-12-14 00:04:31 +01:00
uwetews bc3ea2c878 Prepare .1.29-dev 2015-12-13 15:41:00 +01:00
32 changed files with 1440 additions and 1406 deletions
-1
View File
@@ -13,7 +13,6 @@ matrix:
- php: hhvm
before_script:
- travis_retry composer self-update
- travis_retry composer --prefer-source --dev install
install:
+4 -4
View File
@@ -21,17 +21,17 @@ Smarty 3.1.28
fetch() and display()
=====================
The fetch() and display() methods of the template object accept now optionally the same parameter
as the corresponding Smarty methods to get tne content of another template.
as the corresponding Smarty methods to get the content of another template.
Example:
$template->display(); Does display template of template object
$template->dispaly('foo.tpl'); Does display template 'foo.bar'
$template->display('foo.tpl'); Does display template 'foo.bar'
File: resource
==============
Multiple template_dir entries can now be selected by a comma separated list of indices.
The template_dir array is searched in the order of the indices. (Could be used to change the default search order)
Example:
$smarty->display([1],[0]foo.bar');
$smarty->display('[1],[0]foo.bar');
Filter support
==============
@@ -130,4 +130,4 @@ Smarty 3.1.22
Smarty::DEBUG_INDIVIDUAL will create for each display() and fetch() call an individual debug window.
.
+39 -3
View File
@@ -1,14 +1,50 @@
===== 3.1.28 ===== (13.12.2015)
===== 3.1.29 ===== (21.12.2015)
21.12.2015
- optimization improve speed of filetime checks on extends and extendsall resource
20.12.2015
- bugfix failure when the default resource type was set to 'extendsall' https://github.com/smarty-php/smarty/issues/123
- update compilation of Smarty special variables
- bugfix add addition check for OS type on normalizaition of file path https://github.com/smarty-php/smarty/issues/134
- bugfix the source uid of the extendsall resource must contain $template_dir settings https://github.com/smarty-php/smarty/issues/123
19.12.2015
- bugfix using $smarty.capture.foo in expressions could fail https://github.com/smarty-php/smarty/pull/138
- bugfix broken PHP 5.2 compatibility https://github.com/smarty-php/smarty/issues/139
- remove no longer used code
- improvement make sure that compiled and cache templates never can contain a trailing '?>?
18.12.2015
- bugfix regression when modifier parameter was follow by math https://github.com/smarty-php/smarty/issues/132
17.12.2015
- bugfix {$smarty.capture.nameFail} did lowercase capture name https://github.com/smarty-php/smarty/issues/135
- bugfix using {block append/prepend} on same block in multiple levels of inheritance templates could fail (forum topic 25827)
- bugfix text content consisting of just a single '0' like in {if true}0{/if} was suppressed (forum topic 25834)
16.12.2015
- bugfix {foreach} did fail if from atrribute is a Generator class https://github.com/smarty-php/smarty/issues/128
- bugfix direct access $smarty->template_dir = 'foo'; should call Smarty::setTemplateDir() https://github.com/smarty-php/smarty/issues/121
15.12.2015
- bugfix {$smarty.cookies.foo} did return the $_COOKIE array not the 'foo' value https://github.com/smarty-php/smarty/issues/122
- bugfix a call to clearAllCache() and other should clear all internal template object caches (forum topic 25828)
14.12.2015
- bugfix {$smarty.config.foo} broken in 3.1.28 https://github.com/smarty-php/smarty/issues/120
- bugfix multiple calls of {section} with same name droped E_NOTICE error https://github.com/smarty-php/smarty/issues/118
===== 3.1.28 ===== (13.12.2015)
13.12.2015
- bugfix {foreach} and {section} with uppercase characters in name attribute did not work (forum topic 25819)
- bugfix $smarty->debugging_ctrl = 'URL' did not work (forum topic 25811)
- bugfix Debug Console could display incorrect data when using subtemplates
09.12.2015
- bugix Smarty did fail under PHP 7.0.0 with use_include_path = true;
- bugfix Smarty did fail under PHP 7.0.0 with use_include_path = true;
09.12.2015
-bugfix {strip} should exclude some html tags from stripping, related to fix for https://github.com/smarty-php/smarty/issues/111
- bugfix {strip} should exclude some html tags from stripping, related to fix for https://github.com/smarty-php/smarty/issues/111
08.12.2015
- bugfix internal template function data got stored in wrong compiled file https://github.com/smarty-php/smarty/issues/114
+21 -12
View File
@@ -22,35 +22,44 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
{
$uid = '';
$sources = array();
$exists = true;
foreach ($source->smarty->getTemplateDir() as $key => $directory) {
$timestamp = 0;
foreach ($_template->smarty->getTemplateDir() as $key => $directory) {
try {
$s = Smarty_Template_Source::load(null, $source->smarty, 'file:[' . $key . ']' . $source->name);
$s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
if (!$s->exists) {
continue;
}
$sources[$s->uid] = $s;
$sources[ $s->uid ] = $s;
$uid .= $s->filepath;
$timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp;
}
catch (SmartyException $e) {
}
}
if (!$sources) {
$source->exists = false;
return;
return;
}
$sources = array_reverse($sources, true);
reset($sources);
$s = current($sources);
$source->components = $sources;
$source->filepath = $s->filepath;
$source->uid = sha1($uid);
$source->exists = $exists;
if ($_template && $_template->smarty->compile_check) {
$source->timestamp = $s->getTimeStamp();
}
$source->uid = sha1($uid . $_template->smarty->_joined_template_dir);
$source->exists = true;
$source->timestamp = $timestamp;
}
/*
* Disable timestamp checks for extendsall resource.
* The individual source components will be checked.
*
* @return bool
*/
public function checkTimestamps()
{
return false;
}
}
+2 -10
View File
@@ -352,26 +352,18 @@ tag(res) ::= LDEL variable(e). {
res = $this->compiler->compileTag('private_print_expression',array(),array('value'=>e));
}
tag(res) ::= LDEL variable(e) modifierlist(l) attributes(a). {
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>e, 'modifierlist'=>l));
}
tag(res) ::= LDEL variable(e) attributes(a). {
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>e));
}
tag(res) ::= LDEL value(e). {
res = $this->compiler->compileTag('private_print_expression',array(),array('value'=>e));
}
tag(res) ::= LDEL value(e) modifierlist(l) attributes(a). {
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>e, 'modifierlist'=>l));
}
tag(res) ::= LDEL value(e) attributes(a). {
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>e));
}
tag(res) ::= LDEL expr(e) modifierlist(l) attributes(a). {
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>e,'modifierlist'=>l));
tag(res) ::= LDEL expr(e). {
res = $this->compiler->compileTag('private_print_expression',array(),array('value'=>e));
}
tag(res) ::= LDEL expr(e) attributes(a). {
+16 -9
View File
@@ -27,7 +27,7 @@
* @author Uwe Tews
* @author Rodney Rehm
* @package Smarty
* @version 3.1.28
* @version 3.1.29
*/
/**
@@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.28';
const SMARTY_VERSION = '3.1.29';
/**
* define variable scopes
@@ -677,15 +677,20 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* removed properties
*
* @var array
* @var string[]
*/
private static $obsoleteProperties = array('resource_caching', 'template_resource_caching',
'direct_access_security', '_dir_perms', '_file_perms',
'plugin_search_order', 'inheritance_merge_compiled_includes');
private static $accessMap = array('template_dir' => 'getTemplateDir', 'config_dir' => 'getConfigDir',
'plugins_dir' => 'getPluginsDir', 'compile_dir' => 'getCompileDir',
'cache_dir' => 'getCacheDir',);
/**
* List of private properties which will call getter/setter ona direct access
*
* @var array
*/
private static $accessMap = array('template_dir' => 'TemplateDir', 'config_dir' => 'ConfigDir',
'plugins_dir' => 'PluginsDir', 'compile_dir' => 'CompileDir',
'cache_dir' => 'CacheDir',);
/**#@-*/
@@ -1173,7 +1178,7 @@ class Smarty extends Smarty_Internal_TemplateBase
$path = str_replace($nds, DS, $path);
}
if ($realpath === true && $path[0] !== '/' && $path[1] !== ':') {
if ($realpath === true && (($path[0] !== '/' && DS == '/') || ($path[1] !== ':' && DS != '/'))) {
$path = getcwd() . DS . $path;
}
while ((strpos($path, '.' . DS) !== false) || (strpos($path, DS . DS) !== false)) {
@@ -1344,7 +1349,8 @@ class Smarty extends Smarty_Internal_TemplateBase
{
if (isset(self::$accessMap[$name])) {
return $this->{self::$accessMap[$name]}();
$method = 'get' . self::$accessMap[$name];
return $this->{$method}();
} elseif (in_array($name, self::$obsoleteProperties)) {
return null;
} else {
@@ -1363,7 +1369,8 @@ class Smarty extends Smarty_Internal_TemplateBase
public function __set($name, $value)
{
if (isset(self::$accessMap[$name])) {
$this->{self::$accessMap[$name]}($value);
$method = 'set' . self::$accessMap[$name];
$this->{$method}($value);
} elseif (in_array($name, self::$obsoleteProperties)) {
return;
} else {
+3 -6
View File
@@ -215,12 +215,9 @@ abstract class Smarty_CacheResource
*/
public function invalidLoadedCache(Smarty $smarty)
{
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached)) {
unset ($smarty->_cache['template_objects'][$key]);
}
}
$smarty->_cache['isCached'] = array();
if (isset($smarty->ext->_subtemplate)) {
$smarty->ext->_subtemplate->tplObjects = array();
}
}
}
@@ -142,7 +142,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher
}
$compiler->suppressNocacheProcessing = true;
$compiler->has_code = true;
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 4, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
return $output;
}
}
@@ -69,13 +69,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
*/
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// make all lower case
$parameter = array_map('strtolower', $parameter);
$tag = trim($parameter[0], '"\'');
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
$tag = strtolower(trim($parameter[ 0 ], '"\''));
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null";
return "(isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null)";
}
}
@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
*
* @var array
*/
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total');
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total');
/**
* Valid properties of $item@xxx variable
@@ -183,8 +183,10 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
foreach ($saveVars as $k => $code) {
$output .= "{$local}{$k} = {$code}\n";
}
if (isset($itemAttr['show']) || isset($itemAttr['total']) || isset($namedAttr['total']) || isset($namedAttr['show']) || isset($itemAttr['last']) || isset($namedAttr['last'])) {
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
}
$output .= "{$itemVar} = new Smarty_Variable();\n";
$output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n";
if (isset($itemAttr['show'])) {
$output .= "{$itemVar}->show = ({$local}total > 0);\n";
}
@@ -210,7 +212,6 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
$output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
}
}
$output .= "if ({$local}total) {\n";
if (isset($attributes['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
}
@@ -226,7 +227,9 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo
if ($needIteration) {
$output .= "{$local}iteration=0;\n";
}
$output .= "{$itemVar}->_loop = false;\n";
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
$output .= "{$itemVar}->_loop = true;\n";
if (isset($attributes['key']) && isset($itemAttr['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
@@ -296,7 +299,7 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
$output = "<?php\n";
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
$output .= "} else {\n?>";
$output .= "if (!{$itemVar}->_loop) {\n?>";
return $output;
}
}
@@ -332,7 +335,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
if ($restore) {
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
}
$output .= "}\n";
foreach ($restoreVars as $restore) {
@@ -50,7 +50,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
*
* @var array
*/
public static $nameProperties = array();
public $nameProperties = array();
/**
* {section} tag has no item properties
@@ -112,8 +112,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
if ($named) {
$this->resultOffsets['named'] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$className = get_class($this);
$properties = $className::$nameProperties;
$properties = $this->nameProperties;
} else {
$this->resultOffsets['item'] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]{$attributes['item']}[@](";
@@ -204,17 +203,15 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
* @return string compiled code
* @throws \SmartyCompilerException
*/
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$tag = strtolower(trim($parameter[ 0 ], '"\''));
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
/* @var Smarty_Internal_Compile_Foreach|Smarty_Internal_Compile_Section $className */
$className = 'Smarty_Internal_Compile_' . ucfirst($tag);
$property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false;
if (!$property || !in_array($property, $className::$nameProperties)) {
if (!$property || !in_array($property, $this->nameProperties)) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
}
$tagVar = "'__smarty_{$tag}_{$name}'";
@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = strtolower($compiler->getId($_index[0]));
$variable = strtolower($compiler->getId($_index[ 0 ]));
if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
}
@@ -39,7 +39,11 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
switch ($variable) {
case 'foreach':
case 'section':
return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index);
if (!isset($compiler->_tag_objects[ $variable ])) {
$class = 'Smarty_Internal_Compile_' . ucfirst($variable);
$compiler->_tag_objects[ $variable ] = new $class;
}
return $compiler->_tag_objects[ $variable ]->compileSpecialVariable(array(), $compiler, $_index);
case 'capture':
if (class_exists('Smarty_Internal_Compile_Capture')) {
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
@@ -54,7 +58,8 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
return '$_COOKIE';
$compiled_ref = '$_COOKIE';
break;
case 'get':
case 'post':
case 'env':
@@ -80,9 +85,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return 'dirname($_smarty_tpl->source->filepath)';
case 'version':
$_version = Smarty::SMARTY_VERSION;
return "'$_version'";
return "Smarty::SMARTY_VERSION";
case 'const':
if (isset($compiler->smarty->security_policy) &&
@@ -91,33 +94,27 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiler->trigger_template_error("(secure mode) constants not permitted");
break;
}
if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) {
if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
return "@constant('{$_index[1]}')";
} else {
return "@constant({$_index[1]})";
}
case 'config':
if (isset($_index[2])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
if (isset($_index[ 2 ])) {
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else {
return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])";
return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
}
case 'ldelim':
$_ldelim = $compiler->smarty->left_delimiter;
return "'$_ldelim'";
return "\$_smarty_tpl->smarty->left_delimiter";
case 'rdelim':
$_rdelim = $compiler->smarty->right_delimiter;
return "'$_rdelim'";
return "\$_smarty_tpl->smarty->right_delimiter";
default:
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
$compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
break;
}
if (isset($_index[1])) {
if (isset($_index[ 1 ])) {
array_shift($_index);
foreach ($_index as $_ind) {
$compiled_ref = $compiled_ref . "[$_ind]";
@@ -59,7 +59,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*
* @var array
*/
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
'index_prev', 'index_next');
/**
@@ -103,7 +103,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['__section_{$attributes['name']}'] : false",);
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array();
$initFor = array();
$incFor = array();
+15
View File
@@ -187,6 +187,21 @@ class Smarty_Internal_Data
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
}
/**
* gets the object of a Smarty variable
*
* @param string $variable the name of the Smarty variable
* @param Smarty_Internal_Data $_ptr optional pointer to data object
* @param boolean $searchParents search also in parent data
* @param bool $error_enable
*
* @return Smarty_Variable|Smarty_Undefined_Variable the object of the variable
* @deprecated since 3.1.28 please use Smarty_Internal_Data::getTemplateVars() instead.
*/
public function getVariable($variable = null, Smarty_Internal_Data $_ptr = null, $searchParents = true, $error_enable = true){
return $this->ext->getTemplateVars->_getVariable($this, $variable, $_ptr, $searchParents, $error_enable);
}
/**
* Follow the parent chain an merge template and config variables
*
@@ -114,14 +114,6 @@ class Smarty_Internal_Extension_Clear
}
}
}
// remove from template cache
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached) && $tpl->cached->filepath == (string) $_file) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
if (function_exists('opcache_invalidate')) {
opcache_invalidate((string) $_file);
@@ -34,10 +34,7 @@ class Smarty_Internal_Method_ClearAllCache
{
// load cache resource and call clearAll
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
if ($smarty->caching_type != 'file') {
$_cache_resource->invalidLoadedCache($smarty);
}
$_cache_resource->invalidLoadedCache($smarty);
return $_cache_resource->clearAll($smarty, $exp_time);
}
}
@@ -37,10 +37,7 @@ class Smarty_Internal_Method_ClearCache
{
// load cache resource and call clear
$_cache_resource = Smarty_CacheResource::load($smarty, $type);
if ($smarty->caching_type != 'file' && !isset($template_name)) {
$_cache_resource->invalidLoadedCache($smarty);
}
$_cache_resource->invalidLoadedCache($smarty);
return $_cache_resource->clear($smarty, $template_name, $cache_id, $compile_id, $exp_time);
}
}
@@ -107,13 +107,6 @@ class Smarty_Internal_Method_ClearCompiledTemplate
}
if ($unlink && @unlink($_filepath)) {
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->compiled) && $tpl->compiled->filepath == $_filepath) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
$_count ++;
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_filepath);
@@ -121,11 +114,10 @@ class Smarty_Internal_Method_ClearCompiledTemplate
}
}
}
// clear compiled cache
if (!isset($resource_name) && isset($smarty->_cache['source_objects'])) {
foreach ($smarty->_cache['source_objects'] as $source) {
$source->compileds = array();
}
// clear template objects cache
$smarty->_cache['isCached'] = array();
if (isset($smarty->ext->_subtemplate)) {
$smarty->ext->_subtemplate->tplObjects = array();
}
return $_count;
}
@@ -162,7 +162,7 @@ class Smarty_Internal_Method_ConfigLoad
*
* @return mixed the value of the config variable
*/
public function _getConfigVariable(\Smarty_Internal_Template $tpl, $varName, $errorEnable = true)
public function _getConfigVariable(Smarty_Internal_Template $tpl, $varName, $errorEnable = true)
{
$_ptr = $tpl;
while ($_ptr !== null) {
@@ -44,7 +44,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
if ($_s->type == 'php') {
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
}
$sources[$_s->uid] = $_s;
$sources[ $_s->uid ] = $_s;
$uid .= $_s->filepath;
if ($_template) {
$exists = $exists && $_s->exists;
@@ -110,4 +110,15 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
{
return str_replace(':', '.', basename($source->filepath));
}
/*
* Disable timestamp checks for extends resource.
* The individual source components will be checked.
*
* @return bool
*/
public function checkTimestamps()
{
return false;
}
}
@@ -89,6 +89,6 @@ class Smarty_Internal_Runtime_CodeFrame
$output .= $functions;
$output .= "<?php }\n";
// remove unneeded PHP tags
return preg_replace('/\s*\?>[\n]?<\?php\s*/', "\n", $output);
return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output);
}
}
@@ -27,6 +27,9 @@ class Smarty_Internal_Runtime_Foreach
// thus rewind() and valid() methods may not be present
return iterator_count($value->getIterator());
} elseif ($value instanceof Iterator) {
if ($value instanceof Generator) {
return 1;
}
return iterator_count($value);
} elseif ($value instanceof PDOStatement) {
return $value->rowCount();
@@ -127,8 +127,11 @@ class Smarty_Internal_Runtime_Inheritance
* - search in inheritance template hierarchy for child blocks
* if found call it, otherwise ignore
*
* $type 3 = {$smarty.block.parent}:
* - get block id from parent stack and call parent block
* $type 3 = {block append} {block prepend}:
* - call parent block
*
* $type 4 = {$smarty.block.parent}:
* - call parent block
*
* @param \Smarty_Internal_Template $tpl template object of caller
* @param int $type call type see above
@@ -140,16 +143,22 @@ class Smarty_Internal_Runtime_Inheritance
*/
public function processBlock(Smarty_Internal_Template $tpl, $type = 0, $name, $block, $callStack = array())
{
if (!isset($this->blockParameter[$name])) {
$this->blockParameter[$name] = array();
if (!isset($this->blockParameter[ $name ])) {
$this->blockParameter[ $name ] = array();
}
if ($this->state == 1) {
$block[2] = count($this->blockParameter[$name]);
$block[3] = $this->tplIndex;
$this->blockParameter[$name][] = $block;
$block[ 2 ] = count($this->blockParameter[ $name ]);
$block[ 3 ] = $this->tplIndex;
$this->blockParameter[ $name ][] = $block;
return;
}
if ($type == 3) {
if (!empty($callStack)) {
$block = array_shift($callStack);
} else {
return;
}
} elseif ($type == 4) {
if (!empty($callStack)) {
array_shift($callStack);
if (empty($callStack)) {
@@ -160,23 +169,23 @@ class Smarty_Internal_Runtime_Inheritance
return;
}
} else {
$blockParameter = &$this->blockParameter[$name];
$index = 0;
$blockParameter = &$this->blockParameter[ $name ];
if ($type == 0) {
$index = $block[2] = count($blockParameter);
$block[3] = $this->tplIndex;
$index = $block[ 2 ] = count($blockParameter);
$block[ 3 ] = $this->tplIndex;
$callStack = array(&$block);
} elseif ($type == 1) {
$block[3] = $callStack[0][3];
$index = 0;
$block[ 3 ] = $callStack[ 0 ][ 3 ];
for ($i = 0; $i < count($blockParameter); $i ++) {
if ($blockParameter[$i][3] <= $block[3]) {
$index = $blockParameter[$i][2];
if ($blockParameter[ $i ][ 3 ] <= $block[ 3 ]) {
$index = $blockParameter[ $i ][ 2 ];
}
}
$block[2] = $index;
$block[ 2 ] = $index;
$callStack = array(&$block);
} else {
$index = $callStack[0][2];
} elseif ($type == 2) {
$index = $callStack[ 0 ][ 2 ];
if ($index == 0) {
return;
}
@@ -184,29 +193,40 @@ class Smarty_Internal_Runtime_Inheritance
}
$index --;
// find lowest level child block
while ($index >= 0 && ($type || !$block[1])) {
$block = &$blockParameter[$index];
while ($index >= 0 && ($type || !$block[ 1 ])) {
$block = &$blockParameter[ $index ];
array_unshift($callStack, $block);
if ($block[1]) {
if ($block[ 1 ]) {
break;
}
$index --;
}
if (isset($block['hide']) && $index <= 0) {
if (isset($block[ 'hide' ]) && $index <= 0) {
return;
}
}
$this->blockNesting ++;
if (isset($block['append'])) {
$this->processBlock($tpl, 3, $name, null, $callStack);
// {block append} ?
if (isset($block[ 'append' ])) {
$appendStack = $callStack;
if ($type == 0) {
array_shift($appendStack);
}
$this->processBlock($tpl, 3, $name, null, $appendStack);
}
// call block of current stack level
if (isset($block[6])) {
$block[6]($tpl, $callStack);
} else {
$block[0]($tpl, $callStack);
}
if (isset($block['prepend'])) {
$this->processBlock($tpl, 3, $name, null, $callStack);
// {block prepend} ?
if (isset($block[ 'prepend' ])) {
$prependStack = $callStack;
if ($type == 0) {
array_shift($prependStack);
}
$this->processBlock($tpl, 3, $name, null, $prependStack);
}
$this->blockNesting --;
}
@@ -20,7 +20,7 @@ class Smarty_Internal_Runtime_TplFunction
*
* @throws \SmartyException
*/
public function callTemplateFunction(\Smarty_Internal_Template $tpl, $name, $params, $nocache)
public function callTemplateFunction(Smarty_Internal_Template $tpl, $name, $params, $nocache)
{
if (isset($tpl->tpl_function[$name])) {
if (!$tpl->caching || ($tpl->caching && $nocache)) {
@@ -73,7 +73,7 @@ class Smarty_Internal_Runtime_UpdateCache
/**
* Cache was invalid , so render from compiled and write to cache
*
*
* @param \Smarty_Template_Cached $cached
* @param \Smarty_Internal_Template $_template
* @param $no_output_filter
@@ -129,20 +129,6 @@ class Smarty_Internal_Runtime_UpdateCache
return false;
}
$content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true);
if (!empty($_template->cached->tpl_function)) {
foreach ($_template->cached->tpl_function as $funcParam) {
if (is_file($funcParam['compiled_filepath'])) {
// read compiled file
$code = file_get_contents($funcParam['compiled_filepath']);
// grab template function
if (preg_match("/\/\* {$funcParam['call_name']} \*\/([\S\s]*?)\/\*\/ {$funcParam['call_name']} \*\//",
$code, $match)) {
unset($code);
$content .= "<?php " . $match[0] . "?>\n";
}
}
}
}
return $this->write($cached, $_template, $content);
}
@@ -17,7 +17,7 @@ class Smarty_Internal_Runtime_UpdateScope
* @param string $varName variable name
* @param int $scope scope to which bubble up variable value
*/
public function updateScope(\Smarty_Internal_Template $tpl, $varName, $scope = Smarty::SCOPE_LOCAL)
public function updateScope(Smarty_Internal_Template $tpl, $varName, $scope = Smarty::SCOPE_LOCAL)
{
if (!$scope && !$tpl->scope) {
return;
@@ -43,8 +43,13 @@ class Smarty_Internal_Runtime_ValidateCompiled
} elseif ($_file_to_check[2] == 'string') {
continue;
} else {
$source = Smarty_Template_Source::load(null, $tpl->smarty, $_file_to_check[0]);
$mtime = $source->getTimeStamp();
$handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]);
if ($handler->checkTimestamps()) {
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
$mtime = $source->getTimeStamp();
} else {
continue;
}
}
if (!$mtime || $mtime > $_file_to_check[1]) {
$is_valid = false;
@@ -17,7 +17,7 @@ class Smarty_Internal_Runtime_Var
* @param string $varName template variable name
* @param bool $nocache cache mode of variable
*/
public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $varName, $nocache = false)
public function createLocalArrayVariable(Smarty_Internal_Template $tpl, $varName, $nocache = false)
{
if (!isset($tpl->tpl_vars[$varName])) {
$tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache);
@@ -328,7 +328,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->compileTemplateSource($template, $nocache,
$parent_compiler),
$this->postFilter($this->blockOrFunctionCode) .
join('', $this->mergedSubTemplatesCode), false, $this);
join('', $this->mergedSubTemplatesCode), false,
$this);
return $_compiled_code;
}
@@ -374,7 +375,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->has_variable_string = false;
$this->prefix_code = array();
// add file dependency
$this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] =
$this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] =
array($this->template->source->filepath, $this->template->source->getTimeStamp(),
$this->template->source->type);
$this->smarty->_current_file = $this->template->source->filepath;
@@ -423,7 +424,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
{
// run post filter if on code
if (!empty($code) &&
(isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post']))
(isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ]))
) {
return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
} else {
@@ -443,7 +444,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
{
// run pre filter if required
if ($_content != '' &&
((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])))
((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ])))
) {
return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
} else {
@@ -496,8 +497,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->has_code = true;
$this->has_output = false;
// log tag/attributes
if (isset($this->smarty->_cache['get_used_tags'])) {
$this->template->_cache['used_tags'][] = array($tag, $args);
if (isset($this->smarty->_cache[ 'get_used_tags' ])) {
$this->template->_cache[ 'used_tags' ][] = array($tag, $args);
}
// check nocache option flag
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) ||
@@ -507,9 +508,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
if (isset($this->parent_compiler->template->tpl_function[$tag])) {
if (isset($this->parent_compiler->template->tpl_function[ $tag ])) {
// template defined by {template} tag
$args['_attr']['name'] = "'" . $tag . "'";
$args[ '_attr' ][ 'name' ] = "'" . $tag . "'";
$_output = $this->callTagCompiler('call', $args, $parameter);
}
}
@@ -529,8 +530,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
return null;
} else {
// map_named attributes
if (isset($args['_attr'])) {
foreach ($args['_attr'] as $key => $attribute) {
if (isset($args[ '_attr' ])) {
foreach ($args[ '_attr' ] as $key => $attribute) {
if (is_array($attribute)) {
$args = array_merge($args, $attribute);
}
@@ -539,14 +540,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
// not an internal compiler tag
if (strlen($tag) < 6 || substr($tag, - 5) != 'close') {
// check if tag is a registered object
if (isset($this->smarty->registered_objects[$tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (!in_array($method, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) ||
in_array($method, $this->smarty->registered_objects[$tag][1]))
if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) {
$method = $parameter[ 'object_method' ];
if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) &&
(empty($this->smarty->registered_objects[ $tag ][ 1 ]) ||
in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
} elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
$method);
} else {
@@ -558,7 +559,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
// check if tag is registered
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type)
{
if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) {
// if compiler function plugin call it now
if ($plugin_type == Smarty::PLUGIN_COMPILER) {
$new_args = array();
@@ -566,18 +567,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
} else {
$new_args[$key] = $mixed;
$new_args[ $key ] = $mixed;
}
}
if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) {
if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) {
$this->tag_nocache = true;
}
$function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
$function = $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ];
if (!is_array($function)) {
return $function($new_args, $this);
} elseif (is_object($function[0])) {
return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->{$function[1]}($new_args,
$this);
} elseif (is_object($function[ 0 ])) {
return $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ][ 0 ]->{$function[ 1 ]}($new_args,
$this);
} else {
return call_user_func_array($function, array($new_args, $this));
}
@@ -604,7 +605,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (is_array($mixed)) {
$new_args = array_merge($new_args, $mixed);
} else {
$new_args[$key] = $mixed;
$new_args[ $key ] = $mixed;
}
}
@@ -632,7 +633,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$found = false;
// look for already resolved tags
foreach ($this->plugin_search_order as $plugin_type) {
if (isset($this->default_handler_plugins[$plugin_type][$tag])) {
if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) {
$found = true;
break;
}
@@ -653,12 +654,12 @@ abstract class Smarty_Internal_TemplateCompilerBase
foreach ($args as $mixed) {
$new_args = array_merge($new_args, $mixed);
}
$function = $this->default_handler_plugins[$plugin_type][$tag][0];
$function = $this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ];
if (!is_array($function)) {
return $function($new_args, $this);
} elseif (is_object($function[0])) {
return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args,
$this);
} elseif (is_object($function[ 0 ])) {
return $this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ][ 0 ]->$function[ 1 ]($new_args,
$this);
} else {
return call_user_func_array($function, array($new_args, $this));
}
@@ -672,9 +673,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
// compile closing tag of block function
$base_tag = substr($tag, 0, - 5);
// check if closing tag is a registered object
if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter['object_method'])) {
$method = $parameter['object_method'];
if (in_array($method, $this->smarty->registered_objects[$base_tag][3])) {
if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) {
$method = $parameter[ 'object_method' ];
if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
$method);
} else {
@@ -684,13 +685,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
}
// registered block tag ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) ||
isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])
if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) ||
isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
}
// registered function tag ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag);
}
// block plugin?
@@ -706,18 +707,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
}
// registered compiler plugin ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) {
if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ])) {
// if compiler function plugin call it now
$args = array();
if (!$this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][1]) {
if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) {
$this->tag_nocache = true;
}
$function = $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0];
$function = $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ];
if (!is_array($function)) {
return $function($args, $this);
} elseif (is_object($function[0])) {
return $this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag][0][0]->$function[1]($args,
$this);
} elseif (is_object($function[ 0 ])) {
return $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ][ 0 ]->$function[ 1 ]($args,
$this);
} else {
return call_user_func_array($function, array($args, $this));
}
@@ -783,58 +784,57 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function processText($text)
{
$store = array();
$_store = 0;
$_offset = 0;
if ($this->parser->strip) {
if (strpos($text, '<') !== false) {
// 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)) {
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);
if ((string) $text != '') {
$store = array();
$_store = 0;
$_offset = 0;
if ($this->parser->strip) {
if (strpos($text, '<') !== false) {
// 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)) {
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 ++;
$_offset += $_length - strlen($replace);
$_store ++;
}
}
}
$expressions = array(// replace multiple spaces between tags by a single space
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#^\s+<#Ss' => '<',
'#>\s+$#Ss' => '>',
$this->stripRegEx => ''
);
$expressions = array(// replace multiple spaces between tags by a single space
// can't remove them entirely, becaue that might break poorly implemented CSS display:inline-block elements
'#(:SMARTY@!@|>)\s+(?=@!@SMARTY:|<)#s' => '\1 \2',
// remove spaces between attributes (but not in attribute values!)
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#^\s+<#Ss' => '<',
'#>\s+$#Ss' => '>',
$this->stripRegEx => '');
$text = preg_replace(array_keys($expressions), array_values($expressions), $text);
$_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ];
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$text = preg_replace(array_keys($expressions), array_values($expressions), $text);
$_offset = 0;
if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is', $text, $matches,
PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ];
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length;
$_store ++;
$_offset += strlen($replace) - $_length;
$_store ++;
}
}
} else {
$text = preg_replace($this->stripRegEx, '', $text);
}
} else {
$text = preg_replace($this->stripRegEx, '', $text);
}
}
if ($text) {
return new Smarty_Internal_ParseTree_Text($text);
}
return null;
}
}
/**
* lazy loads internal compile plugin for tag and calls the compile method
@@ -853,7 +853,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
{
// re-use object if already exists
if (!isset($this->_tag_objects[$tag])) {
if (!isset($this->_tag_objects[ $tag ])) {
// lazy load internal compiler plugin
$_tag = explode('_', $tag);
$_tag = array_map('ucfirst', $_tag);
@@ -861,15 +861,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (class_exists($class_name) &&
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
) {
$this->_tag_objects[$tag] = new $class_name;
$this->_tag_objects[ $tag ] = new $class_name;
} else {
$this->_tag_objects[$tag] = false;
$this->_tag_objects[ $tag ] = false;
return false;
}
}
// compile this tag
return $this->_tag_objects[$tag] === false ? false :
$this->_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
return $this->_tag_objects[ $tag ] === false ? false :
$this->_tag_objects[ $tag ]->compile($args, $this, $param1, $param2, $param3);
}
/**
@@ -884,29 +884,29 @@ abstract class Smarty_Internal_TemplateCompilerBase
{
$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 (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
} elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) {
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] =
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type];
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function =
$this->parent_compiler->template->compiled->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])) {
if (isset($this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
} elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) {
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] =
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type];
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
} elseif (isset($this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function =
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
}
}
if (isset($function)) {
if ($plugin_type == 'modifier') {
$this->modifier_plugins[$plugin_name] = true;
$this->modifier_plugins[ $plugin_name ] = true;
}
return $function;
@@ -917,18 +917,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
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'] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
} else {
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'file' ] =
$file;
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ] =
$function;
}
if ($plugin_type == 'modifier') {
$this->modifier_plugins[$plugin_name] = true;
$this->modifier_plugins[ $plugin_name ] = true;
}
return $function;
@@ -961,14 +961,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
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'] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
$this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['function'] =
$this->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
} else {
$this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['file'] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'file' ] =
$script;
$this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['function'] =
$this->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
}
require_once $script;
@@ -976,11 +976,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->trigger_template_error("Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
}
}
if (!is_string($callback) && !(is_array($callback) && is_string($callback[0]) && is_string($callback[1]))) {
if (!is_string($callback) &&
!(is_array($callback) && is_string($callback[ 0 ]) && is_string($callback[ 1 ]))
) {
$this->trigger_template_error("Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name");
}
if (is_callable($callback)) {
$this->default_handler_plugins[$plugin_type][$tag] = array($callback, true, array());
$this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback, true, array());
return true;
} else {
@@ -1036,9 +1038,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
"/*/%%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->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' ];
}
}
} else {
@@ -1064,7 +1066,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function getId($input)
{
if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) {
return $match[1];
return $match[ 1 ];
}
return false;
}
@@ -1079,7 +1081,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function getVariableName($input)
{
if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) {
return $match[1];
return $match[ 1 ];
}
return false;
}
@@ -1136,7 +1138,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$error_text =
'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) .
'" on line ' . ($line + $this->trace_line_offset) . ' "' .
trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" ';
if (isset($args)) {
// individual error message
$error_text .= $args;
@@ -1146,13 +1148,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
$error_text .= ' - Unexpected "' . $lex->value . '"';
if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
$exp_token = $this->parser->yyTokenName[$token];
if (isset($lex->smarty_token_names[$exp_token])) {
$exp_token = $this->parser->yyTokenName[ $token ];
if (isset($lex->smarty_token_names[ $exp_token ])) {
// token type from lexer
$expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"';
$expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"';
} else {
// otherwise internal token name
$expect[] = $this->parser->yyTokenName[$token];
$expect[] = $this->parser->yyTokenName[ $token ];
}
}
$error_text .= ', expected one of: ' . implode(' , ', $expect);
@@ -1160,7 +1162,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
$e = new SmartyCompilerException($error_text);
$e->line = $line;
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1]));
$e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ]));
$e->desc = $args;
$e->template = $this->template->source->filepath;
throw $e;
File diff suppressed because it is too large Load Diff
+10
View File
@@ -240,6 +240,16 @@ abstract class Smarty_Resource
return $resource->buildUniqueResourceName($smarty, $name);
}
/*
* Check if resource must check time stamps when when loading complied or cached templates.
* Resources like 'extends' which use source components my disable timestamp checks on own resource.
*
* @return bool
*/
public function checkTimestamps() {
return true;
}
/**
* initialize Source Object for given resource
* wrapper for backward compatibility to versions < 3.1.22
@@ -79,13 +79,6 @@ abstract class Smarty_Template_Resource_Base
*/
public $required_plugins = array();
/**
* Known template functions
*
* @var array
*/
public $tpl_function = array();
/**
* Included subtemplates
*