update smarty to 3.1.28-dev which fixes a bug where changes in a template are only visible on the second pageload which is annoying for developing

This commit is contained in:
Mario Vavti 2015-12-06 21:09:58 +01:00
parent f2d7083183
commit 26c465ad0c
89 changed files with 5582 additions and 7114 deletions

View File

@ -460,12 +460,13 @@ included template.
PLUGINS
=======
Smarty3 are following the same coding rules as in Smarty2.
The only difference is that the template object is passed as additional third parameter.
Smarty 3 plugins follow the same coding rules as in Smarty 2.
The main difference is that the template object is now passed in place of the smarty object.
The smarty object can be still be accessed through $template->smarty.
smarty_plugintype_name (array $params, object $smarty, object $template)
smarty_plugintype_name (array $params, Smarty_Internal_Template $template)
The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty2 internals.
The Smarty 2 plugins are still compatible as long as they do not make use of specific Smarty 2 internals.
TEMPLATE INHERITANCE:

View File

@ -1,13 +1,178 @@
 ===== 3.1.27===== (18.06.2015)
18.06.2015
- bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
 ===== 3.1.28-dev===== (xx.xx.2015)
05.12.2015
-bugfix {strip} should insert a single space https://github.com/smarty-php/smarty/issues/111
25.11.2015
-bugfix a left delimter like '[%' did fail on [%$var_[%$variable%]%] (forum topic 25798)
02.11.2015
- bugfix {include} with variable file name like {include file="foo_`$bar`.tpl"} did fail in 3.1.28-dev https://github.com/smarty-php/smarty/issues/102
01.11.2015
- update config file processing
31.10.2015
- bugfix add missing $trusted_dir property to SmartyBC class (forum topic 25751)
29.10.2015
- improve template scope handling
24.10.2015
- more optimizations of template processing
- bugfix Error when using {include} within {capture} https://github.com/smarty-php/smarty/issues/100
21.10.2015
- move some code into runtime extensions
18.10.2015
- optimize filepath normalization
- rework of template inheritance
- speed and size optimizations
- bugfix under HHVM temporary cache file must only be created when caches template was updated
- fix compiled code for new {block} assign attribute
- update code generated by template function call handler
18.09.2015
- bugfix {if $foo instanceof $bar} failed to compile if 2nd value is a variable https://github.com/smarty-php/smarty/issues/92
17.09.2015
- bugfix {foreach} first attribute was not correctly reset since commit 05a8fa2 of 02.08.2015 https://github.com/smarty-php/smarty/issues/90
16.09.2015
- update compiler by moving no longer needed properties, code optimizations and other
14.09.2015
- optimize autoloader
- optimize subtemplate handling
- update template inheritance processing
- move code of {call} processing back into Smarty_Internal_Template class
- improvement invalidate OPCACHE for cleared compiled and cached template files (forum topic 25557)
- bugfix unintended multiple debug windows (forum topic 25699)
30.08.2015
- size optimization move some runtime functions into extension
- optimize inline template processing
- optimization merge inheritance child and parent templates into one compiled template file
29.08.2015
- improvement convert template inheritance into runtime processing
- bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68
23.08.2015
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop
- load seldom used Smarty API methods dynamically to reduce memory footprint
- cache template object of {include} if same template is included several times
- convert debug console processing to object
- use output buffers for better performance and less memory usage
- optimize nocache hash processing
- remove not really needed properties
- optimize rendering
- move caching to Smarty::_cache
- remove properties with redundant content
- optimize Smarty::templateExists()
- optimize use_include_path processing
- relocate properties for size optimization
- remove redundant code
- bugfix compiling super globals like {$smarty.get.foo} did fail in the master branch https://github.com/smarty-php/smarty/issues/77
06.08.2015
- avoid possible circular object references caused by parser/lexer objects
- rewrite compileAll... utility methods
- commit several internal improvements
- bugfix Smarty failed when compile_id did contain "|"
03.08.2015
- rework clear cache methods
- bugfix compileAllConfig() was broken since 3.1.22 because of the changes in config file processing
- improve getIncludePath() to return directory if no file was given
02.08.2015
- optimization and code cleanup of {foreach} and {section} compiler
- rework {capture} compiler
01.08.2015
- update DateTime object can be instance of DateTimeImmutable since PHP5.5 https://github.com/smarty-php/smarty/pull/75
- improvement show resource type and start of template source instead of uid on eval: and string: resource (forum topic 25630)
31.07.2015
- optimize {foreach} and {section} compiler
29.07.2015
- optimize {section} compiler for speed and size of compiled code
28.07.2015
- update for PHP 7 compatibility
26.07.2015
- improvement impement workaround for HHVM PHP incompatibillity https://github.com/facebook/hhvm/issues/4797
25.07.2015
- bugfix parser did hang on text starting <?something https://github.com/smarty-php/smarty/issues/74
20.07.2015
- bugfix config files got recompiled on each request
- improvement invalidate PHP 5.5 opcache for recompiled and cached templates https://github.com/smarty-php/smarty/issues/72
12.07.2015
- optimize {extends} compilation
10.07.2015
- bugfix force file: resource in demo resource.extendsall.php
08.07.2015
- bugfix convert each word of class names to ucfirst in in compiler. (forum topic 25588)
07.07.2015
- improvement allow fetch() or display() called on a template object to get output from other template
like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70
- improvement Added $limit parameter to regex_replace modifier #71
- new feature multiple indices on file: resource
06.07.2015
- optimize {block} compilation
- optimization get rid of __get and __set in source object
01.07.2015
- optimize compile check handling
- update {foreach} compiler
- bugfix debugging console did not display string values containing \n, \r or \t correctly https://github.com/smarty-php/smarty/issues/66
- optimize source resources
28.06.2015
- move $smarty->enableSecurity() into Smarty_Security class
- optimize security isTrustedResourceDir()
- move auto load filter methods into extension
- move $smarty->getTemplateVars() into extension
- move getStreamVariable() into extension
- move $smarty->append() and $smarty->appendByRef() into extension
- optimize autoloader
- optimize file path normalization
- bugfix PATH_SEPARATOR was replaced by mistake in autoloader
- remove redundant code
27.06.2015
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64
- update $smarty->_realpath for relative path not starting with './'
- update Smarty security with new realpath handling
- update {include_php} with new realpath handling
- move $smarty->loadPlugin() into extension
- minor compiler optimizations
- bugfix allow function plugins with name ending with 'close' https://github.com/smarty-php/smarty/issues/52
- rework of $smarty->clearCompiledTemplate() and move it to its own extension
19.06.2015
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
===== 3.1.27===== (18.06.2015)
18.06.2015
- bugfix another update on file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
===== 3.1.26===== (18.06.2015)
18.06.2015
- bugfix file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
18.06.2015
- bugfix file path normalization failed on path containing something like "/.foo/" https://github.com/smarty-php/smarty/issues/56
17.06.2015
- bugfix calling a plugin with nocache option but no other attributes like {foo nocache} caused call to undefined function https://github.com/smarty-php/smarty/issues/55
17.06.2015
- bugfix calling a plugin with nocache option but no other attributes like {foo nocache} caused call to undefined function https://github.com/smarty-php/smarty/issues/55
===== 3.1.25===== (15.06.2015)
15.06.2015
@ -209,8 +374,8 @@
- bugfix Debug Console did not include all data from merged compiled subtemplates
04.11.2014
- new feature $smarty->debug = true; => overwrite existing Debug Console window (old behaviour)
$smarty->debug = 2; => individual Debug Console window by template name
- new feature $smarty->debugging = true; => overwrite existing Debug Console window (old behaviour)
$smarty->debugging = 2; => individual Debug Console window by template name
03.11.2014
- bugfix Debug Console did not show included subtemplates since 3.1.17 (forum 25301)

View File

@ -25,62 +25,20 @@ class Smarty_Autoloader
* @var string
*/
public static $SMARTY_DIR = '';
/**
* Filepath to Smarty internal plugins
*
* @var string
*/
public static $SMARTY_SYSPLUGINS_DIR = '';
/**
* Array of not existing classes to avoid is_file calls for already tested classes
*
* @var array
*/
public static $unknown = array();
/**
* Array with Smarty core classes and their filename
*
* @var array
*/
public static $rootClasses = array('Smarty' => 'Smarty.class.php',
'SmartyBC' => 'SmartyBC.class.php',
);
private static $syspluginsClasses = array(
'smarty_config_source' => true,
'smarty_security' => true,
'smarty_cacheresource' => true,
'smarty_compiledresource' => true,
'smarty_cacheresource_custom' => true,
'smarty_cacheresource_keyvaluestore' => true,
'smarty_resource' => true,
'smarty_resource_custom' => true,
'smarty_resource_uncompiled' => true,
'smarty_resource_recompiled' => true,
'smarty_template_source' => true,
'smarty_template_compiled' => true,
'smarty_template_cached' => true,
'smarty_template_config' => true,
'smarty_data' => true,
'smarty_variable' => true,
'smarty_undefined_variable' => true,
'smartyexception' => true,
'smartycompilerexception' => true,
'smarty_internal_data' => true,
'smarty_internal_template' => true,
'smarty_internal_templatebase' => true,
'smarty_internal_resource_file' => true,
'smarty_internal_resource_extends' => true,
'smarty_internal_resource_eval' => true,
'smarty_internal_resource_string' => true,
'smarty_internal_resource_registered' => true,
'smarty_internal_extension_codeframe' => true,
'smarty_internal_extension_config' => true,
'smarty_internal_filter_handler' => true,
'smarty_internal_function_call_handler' => true,
'smarty_internal_cacheresource_file' => true,
'smarty_internal_write_file' => true,
);
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
/**
* Registers Smarty_Autoloader backward compatible to older installations.
@ -95,7 +53,9 @@ class Smarty_Autoloader
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
if (SMARTY_SPL_AUTOLOAD &&
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
spl_autoload_register();
@ -112,8 +72,9 @@ class Smarty_Autoloader
*/
public static function register($prepend = false)
{
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . '/';
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR : self::$SMARTY_DIR . 'sysplugins/';
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
@ -122,37 +83,42 @@ class Smarty_Autoloader
}
/**
* Handles autoloading of classes.
* Handles auto loading of classes.
*
* @param string $class A class name.
*/
public static function autoload($class)
{
// Request for Smarty or already unknown class
if (isset(self::$unknown[$class])) {
return;
}
$_class = strtolower($class);
if (isset(self::$syspluginsClasses[$_class])) {
$_class = (self::$syspluginsClasses[$_class] === true) ? $_class : self::$syspluginsClasses[$_class];
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
require_once $file;
return;
} elseif (0 !== strpos($_class, 'smarty_internal_')) {
if (isset(self::$rootClasses[$class])) {
$file = self::$SMARTY_DIR . self::$rootClasses[$class];
require_once $file;
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (strpos($_class, 'smarty_internal_') === 0) {
if (strpos($_class, 'smarty_internal_compile_') === 0) {
if (is_file($file)) {
require $file;
}
return;
}
self::$unknown[$class] = true;
@include $file;
return;
}
if (preg_match('/^(smarty_(((template_(source|config|cache|compiled|resource_base))|((cached|compiled)?resource)|(variable|security)))|(smarty(bc)?)$)/',
$_class, $match)) {
if (!empty($match[3])) {
@include $file;
return;
} elseif (!empty($match[9]) && isset(self::$rootClasses[$_class])) {
$file = self::$rootClasses[$_class];
require $file;
return;
}
}
if (0 !== strpos($_class, 'smarty')) {
return;
}
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) {
require_once $file;
require $file;
return;
}
self::$unknown[$class] = true;
return;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,13 @@ class SmartyBC extends Smarty
*/
public $_version = self::SMARTY_VERSION;
/**
* This is an array of directories where trusted php scripts reside.
*
* @var array
*/
public $trusted_dir = array();
/**
* Initialize new SmartyBC object
*

View File

@ -128,7 +128,7 @@
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<td><h3><font color=blue>${$vars@key}</font></h3>
{if isset($vars['nocache'])}<b>Nocache</b></br>{/if}
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var:10:80 nofilter}{/if}
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
</td>
<td><h3>Value</h3>{$vars['value']|debug_print_var:10:80 nofilter}</td>
<td>{if isset($vars['attributes'])}<h3>Attributes</h3>{$vars['attributes']|debug_print_var nofilter} {/if}</td>
@ -141,7 +141,7 @@
{foreach $config_vars as $vars}
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
<td><h3><font color=blue>#{$vars@key}#</font></h3>
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var:10:80 nofilter}{/if}
{if isset($vars['scope'])}<b>Origin:</b> {$vars['scope']|debug_print_var nofilter}{/if}
</td>
<td>{$vars['value']|debug_print_var:10:80 nofilter}</td>
</tr>
@ -152,9 +152,9 @@
</html>
{/capture}
<script type="text/javascript">
{$id = ''}
{$id = '__Smarty__'}
{if $display_mode}{$id = "$offset$template_name"|md5}{/if}
_smarty_console = window.open("", "console{$id}", "width=680,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
_smarty_console = window.open("", "console{$id}", "width=1024,height=600,left={$offset},top={$offset},resizable,scrollbars=yes");
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
_smarty_console.document.close();
</script>

View File

@ -24,9 +24,9 @@
*/
function smarty_modifier_debug_print_var($var, $max = 10, $length = 40, $depth = 0, $objects = array())
{
$_replace = array("\n" => '<i>\n</i>',
"\r" => '<i>\r</i>',
"\t" => '<i>\t</i>'
$_replace = array("\n" => '\n',
"\r" => '\r',
"\t" => '\t'
);
switch (gettype($var)) {
case 'array' :

View File

@ -19,10 +19,11 @@
* @param string $string input string
* @param string|array $search regular expression(s) to search for
* @param string|array $replace string(s) that should be replaced
* @param int $limit the maximum number of replacements
*
* @return string
*/
function smarty_modifier_regex_replace($string, $search, $replace)
function smarty_modifier_regex_replace($string, $search, $replace, $limit = -1)
{
if (is_array($search)) {
foreach ($search as $idx => $s) {
@ -32,7 +33,7 @@ function smarty_modifier_regex_replace($string, $search, $replace)
$search = _smarty_regex_replace_check($search);
}
return preg_replace($search, $replace, $string);
return preg_replace($search, $replace, $string, $limit);
}
/**

View File

@ -115,11 +115,11 @@ 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->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
} else {
$compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
}
return 'smarty_modifier_escape(' . join(', ', $params) . ')';

View File

@ -34,11 +34,11 @@ function smarty_modifiercompiler_wordwrap($params, $compiler)
$function = 'wordwrap';
if (Smarty::$_MBSTRING) {
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->parent_compiler->template->compiled->required_plugins['nocache']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->template->required_plugins['nocache']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
} else {
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->template->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php';
$compiler->parent_compiler->template->compiled->required_plugins['compiled']['wordwrap']['modifier']['function'] = 'smarty_mb_wordwrap';
}
$function = 'smarty_mb_wordwrap';
}

View File

@ -21,8 +21,8 @@ function smarty_make_timestamp($string)
if (empty($string)) {
// use "now":
return time();
} elseif ($string instanceof DateTime) {
return $string->getTimestamp();
} elseif ($string instanceof DateTime || (interface_exists('DateTimeInterface', false) && $string instanceof DateTimeInterface)) {
return (int) $string->format('U'); // PHP 5.2 BC
} elseif (strlen($string) == 14 && ctype_digit($string)) {
// it is mysql timestamp format of YYYYMMDDHHMMSS?
return mktime(substr($string, 8, 2), substr($string, 10, 2), substr($string, 12, 2),

View File

@ -20,9 +20,7 @@ abstract class Smarty_CacheResource
*
* @var array
*/
protected static $sysplugins = array(
'file' => 'smarty_internal_cacheresource_file.php',
);
protected static $sysplugins = array('file' => 'smarty_internal_cacheresource_file.php',);
/**
* populate Cached Object with meta data from Resource
@ -48,10 +46,11 @@ abstract class Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
* @return bool true or false if the cached content does not exist
*/
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null);
abstract public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false);
/**
* Write the rendered template output to cache
@ -74,8 +73,8 @@ abstract class Smarty_CacheResource
{
if ($_template->cached->handler->process($_template)) {
ob_start();
$_template->properties['unifunc']($_template);
$unifunc = $_template->cached->unifunc;
$unifunc($_template);
return ob_get_clean();
}
@ -186,27 +185,24 @@ abstract class Smarty_CacheResource
}
// try smarty's cache
if (isset($smarty->_cacheresource_handlers[$type])) {
return $smarty->_cacheresource_handlers[$type];
if (isset($smarty->_cache['cacheresource_handlers'][$type])) {
return $smarty->_cache['cacheresource_handlers'][$type];
}
// try registered resource
if (isset($smarty->registered_cache_resources[$type])) {
// do not cache these instances as they may vary from instance to instance
return $smarty->_cacheresource_handlers[$type] = $smarty->registered_cache_resources[$type];
return $smarty->_cache['cacheresource_handlers'][$type] = $smarty->registered_cache_resources[$type];
}
// try sysplugins dir
if (isset(self::$sysplugins[$type])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
if (!class_exists($cache_resource_class, false)) {
require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
}
return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class();
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
}
// try plugins dir
$cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
if ($smarty->loadPlugin($cache_resource_class)) {
return $smarty->_cacheresource_handlers[$type] = new $cache_resource_class();
return $smarty->_cache['cacheresource_handlers'][$type] = new $cache_resource_class();
}
// give up
throw new SmartyException("Unable to load cache resource '{$type}'");
@ -217,12 +213,13 @@ abstract class Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
*/
public static function invalidLoadedCache(Smarty $smarty)
public function invalidLoadedCache(Smarty $smarty)
{
foreach ($smarty->template_objects as $tpl) {
if (isset($tpl->cached)) {
$tpl->cached->valid = false;
$tpl->cached->processed = false;
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached)) {
unset ($smarty->_cache['template_objects'][$key]);
}
}
}
}

View File

@ -83,7 +83,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$_cache_id = isset($cached->cache_id) ? preg_replace('![^\w\|]+!', '_', $cached->cache_id) : null;
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w\|]+!', '_', $cached->compile_id) : null;
$_compile_id = isset($cached->compile_id) ? preg_replace('![^\w]+!', '_', $cached->compile_id) : null;
$path = $cached->source->filepath . $_cache_id . $_compile_id;
$cached->filepath = sha1($path);
if ($_template->smarty->cache_locking) {
@ -119,10 +119,11 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
if (!$cached) {
$cached = $_template->cached;
@ -130,14 +131,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$content = $cached->content ? $cached->content : null;
$timestamp = $cached->timestamp ? $cached->timestamp : null;
if ($content === null || !$timestamp) {
$this->fetch(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp
);
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
}
if (isset($content)) {
/** @var Smarty_Internal_Template $_smarty_tpl
@ -145,7 +139,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
$_smarty_tpl = $_template;
eval("?>" . $content);
$cached->content = null;
return true;
}
@ -162,14 +156,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
return $this->save(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$_template->properties['cache_lifetime'],
$content
);
return $this->save($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $_template->cache_lifetime, $content);
}
/**
@ -185,14 +172,7 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
$timestamp = null;
if ($content === null) {
$timestamp = null;
$this->fetch(
$_template->cached->filepath,
$_template->source->name,
$_template->cache_id,
$_template->compile_id,
$content,
$timestamp
);
$this->fetch($_template->cached->filepath, $_template->source->name, $_template->cache_id, $_template->compile_id, $content, $timestamp);
}
if (isset($content)) {
return $content;
@ -210,8 +190,6 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
$this->cache = array();
return $this->delete(null, null, null, $exp_time);
}
@ -228,32 +206,23 @@ abstract class Smarty_CacheResource_Custom extends Smarty_CacheResource
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$this->cache = array();
$cache_name = null;
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
if ($tpl->source->exists) {
$cache_name = $tpl->source->name;
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
if ($source->exists) {
$cache_name = $source->name;
} else {
return 0;
}
// remove from template cache
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $_tpl) {
if (isset($_tpl->cached) && $_tpl->source->uid == $source->uid) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
// template object no longer needed
unset($tpl);
}
return $this->delete($cache_name, $cache_id, $compile_id, $exp_time);

View File

@ -54,7 +54,8 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template)
{
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' . $this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$cached->filepath = $_template->source->uid . '#' . $this->sanitize($cached->source->resource) . '#' .
$this->sanitize($cached->cache_id) . '#' . $this->sanitize($cached->compile_id);
$this->populateTimestamp($cached);
}
@ -81,10 +82,11 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
if (!$cached) {
$cached = $_template->cached;
@ -121,7 +123,7 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
{
$this->addMetaTimestamp($content);
return $this->write(array($_template->cached->filepath => $content), $_template->properties['cache_lifetime']);
return $this->write(array($_template->cached->filepath => $content), $_template->cache_lifetime);
}
/**
@ -162,7 +164,14 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
if (!$this->purge()) {
$this->invalidate(null);
}
// remove from template cache
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if (isset($tpl->cached)) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
return - 1;
}
@ -183,11 +192,21 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$uid = $this->getTemplateUid($smarty, $resource_name, $cache_id, $compile_id);
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' . $this->sanitize($compile_id);
$uid = $this->getTemplateUid($smarty, $resource_name);
$cid = $uid . '#' . $this->sanitize($resource_name) . '#' . $this->sanitize($cache_id) . '#' .
$this->sanitize($compile_id);
$this->delete(array($cid));
$this->invalidate($cid, $resource_name, $cache_id, $compile_id, $uid);
// remove from template cache
if (isset($resource_name) && isset($smarty->_cache['template_objects'])) {
if (isset($smarty->_cache['template_objects'])) {
foreach ($smarty->_cache['template_objects'] as $key => $tpl) {
if ($tpl->source->uid == $uid && isset($tpl->cached)) {
unset($smarty->_cache['template_objects'][$key]);
}
}
}
}
return - 1;
}
@ -196,33 +215,20 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*
* @param Smarty $smarty Smarty object
* @param string $resource_name template name
* @param string $cache_id cache id
* @param string $compile_id compile id
*
* @return string filepath of cache file
* @throws \SmartyException
*
*/
protected function getTemplateUid(Smarty $smarty, $resource_name, $cache_id, $compile_id)
protected function getTemplateUid(Smarty $smarty, $resource_name)
{
$uid = '';
if (isset($resource_name)) {
$tpl = new $smarty->template_class($resource_name, $smarty);
if ($tpl->source->exists) {
$uid = $tpl->source->uid;
$source = Smarty_Template_Source::load(null, $smarty, $resource_name);
if ($source->exists) {
return $source->uid;
}
// remove from template cache
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
}
return $uid;
return '';
}
/**
@ -234,12 +240,10 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
*/
protected function sanitize($string)
{
// some poeple smoke bad weed
$string = trim($string, '|');
if (!$string) {
return null;
}
return preg_replace('#[^\w\|]+#S', '_', $string);
}
@ -397,7 +401,6 @@ abstract class Smarty_CacheResource_KeyValueStore extends Smarty_CacheResource
$t[] = 'IVK#COMPILE' . $_compile;
}
$_name .= '#';
// some poeple smoke bad weed
$cid = trim($cache_id, '|');
if (!$cid) {
return $t;

View File

@ -30,6 +30,7 @@ class Smarty_Data extends Smarty_Internal_Data
* @var string
*/
public $dataObjectName = '';
/**
* Smarty object
*
@ -48,6 +49,7 @@ class Smarty_Data extends Smarty_Internal_Data
*/
public function __construct($_parent = null, $smarty = null, $name = null)
{
parent::__construct();
self::$count ++;
$this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count);
$this->smarty = $smarty;

View File

@ -29,14 +29,12 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
{
$_source_file_path = str_replace(':', '.', $_template->source->filepath);
$_cache_id = isset($_template->cache_id) ? preg_replace('![^\w\|]+!', '_', $_template->cache_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
$_filepath = $_template->source->uid;
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
$_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
$_filepath;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_cache_id)) {
@ -60,7 +58,8 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
}
$cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock';
}
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php';
$cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) .
'.php';
$cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) {
$cached->timestamp = filemtime($cached->filepath);
@ -87,17 +86,22 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*
* @param Smarty_Internal_Template $_template template object
* @param Smarty_Template_Cached $cached cached object
* @param bool $update flag if called because cache update
*
* @return booleantrue or false if the cached content does not exist
* @return boolean true or false if the cached content does not exist
*/
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null)
public function process(Smarty_Internal_Template $_template, Smarty_Template_Cached $cached = null, $update = false)
{
/** @var Smarty_Internal_Template $_smarty_tpl
* used in included file
*/
$_smarty_tpl = $_template;
return @include $_template->cached->filepath;
$_template->cached->valid = false;
if ($update && defined('HHVM_VERSION')) {
return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath);
} else {
return @include $_template->cached->filepath;
}
}
/**
@ -110,8 +114,10 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
$obj = new Smarty_Internal_Write_File();
if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) {
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_template->cached->filepath);
}
$cached = $_template->cached;
$cached->timestamp = $cached->exists = is_file($cached->filepath);
if ($cached->exists) {
@ -147,7 +153,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function clearAll(Smarty $smarty, $exp_time = null)
{
return $this->clear($smarty, null, null, null, $exp_time);
return Smarty_Internal_Extension_Clear::clear($smarty, null, null, null, $exp_time);
}
/**
@ -163,108 +169,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource
*/
public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $exp_time)
{
$_cache_id = isset($cache_id) ? preg_replace('![^\w\|]+!', '_', $cache_id) : null;
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
$_compile_id_offset = $smarty->use_sub_dirs ? 3 : 0;
$_dir = realpath($smarty->getCacheDir()) . '/';
if ($_dir == '/') { //We should never want to delete this!
return 0;
}
$_dir_length = strlen($_dir);
if (isset($_cache_id)) {
$_cache_id_parts = explode('|', $_cache_id);
$_cache_id_parts_count = count($_cache_id_parts);
if ($smarty->use_sub_dirs) {
foreach ($_cache_id_parts as $id_part) {
$_dir .= $id_part . DS;
}
}
}
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = true;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resourcename_parts = basename(str_replace('^', '/', $tpl->cached->filepath));
} else {
return 0;
}
}
$_count = 0;
$_time = time();
if (file_exists($_dir)) {
$_cacheDirs = new RecursiveDirectoryIterator($_dir);
$_cache = new RecursiveIteratorIterator($_cacheDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_cache as $_file) {
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
// directory ?
if ($_file->isDir()) {
if (!$_cache->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
} else {
$_parts = explode($_dir_sep, str_replace('\\', '/', substr((string) $_file, $_dir_length)));
$_parts_count = count($_parts);
// check name
if (isset($resource_name)) {
if ($_parts[$_parts_count - 1] != $_resourcename_parts) {
continue;
}
}
// check compile id
if (isset($_compile_id) && (!isset($_parts[$_parts_count - 2 - $_compile_id_offset]) || $_parts[$_parts_count - 2 - $_compile_id_offset] != $_compile_id)) {
continue;
}
// check cache id
if (isset($_cache_id)) {
// count of cache id parts
$_parts_count = (isset($_compile_id)) ? $_parts_count - 2 - $_compile_id_offset : $_parts_count - 1 - $_compile_id_offset;
if ($_parts_count < $_cache_id_parts_count) {
continue;
}
for ($i = 0; $i < $_cache_id_parts_count; $i ++) {
if ($_parts[$i] != $_cache_id_parts[$i]) {
continue 2;
}
}
}
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[1])) {
continue;
}
} else {
if ($_time - @filemtime($_file) < $exp_time) {
continue;
}
}
}
$_count += @unlink((string) $_file) ? 1 : 0;
}
}
}
return $_count;
return Smarty_Internal_Extension_Clear::clear($smarty, $resource_name, $cache_id, $compile_id, $exp_time);
}
/**

View File

@ -19,13 +19,13 @@ class Smarty_Internal_Compile_Append extends Smarty_Internal_Compile_Assign
/**
* Compiles code for the {append} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// the following must be assigned at runtime because it will be overwritten in parent class
$this->required_attributes = array('var', 'value');

View File

@ -16,23 +16,31 @@
*/
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
{
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
'smarty' => true, 'tpl_root' => true);
/**
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
$this->optional_attributes = array('scope');
$this->optional_attributes = array('scope', 'bubble_up');
$_nocache = 'null';
$_scope = Smarty::SCOPE_LOCAL;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// nocache ?
@ -46,39 +54,43 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
}
}
// scope setup
$_scope = Smarty::SCOPE_LOCAL;
if (isset($_attr['scope'])) {
$_attr['scope'] = trim($_attr['scope'], "'\"");
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
if (!isset($this->valid_scopes[$_attr['scope']])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
}
if ($_attr['scope'] != 'local') {
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} elseif ($_attr['scope'] == 'smarty') {
$_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
}
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
}
}
// compiled output
if (isset($parameter['smarty_internal_index'])) {
$output = "<?php \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
$output =
"<?php \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];";
} else {
// implement Smarty2's behaviour of variables assigned by reference
if ($compiler->template->smarty instanceof SmartyBC) {
$output = "<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache; \$_smarty_tpl->tpl_vars[$_attr[var]]->scope = $_scope;";
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);";
$output =
"<?php if (isset(\$_smarty_tpl->tpl_vars[$_attr[var]])) {\$_smarty_tpl->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
$output .= "\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value = $_attr[value]; \$_smarty_tpl->tpl_vars[$_attr[var]]->nocache = $_nocache;";
$output .= "\n} else \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
} else {
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache, $_scope);";
$output = "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_Variable($_attr[value], $_nocache);";
}
}
if ($_scope == Smarty::SCOPE_PARENT) {
$output .= "\nif (\$_smarty_tpl->parent != null) \$_smarty_tpl->parent->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
} elseif ($_scope == Smarty::SCOPE_ROOT || $_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\n\$_ptr = \$_smarty_tpl->parent; while (\$_ptr != null) {\$_ptr->tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]]; \$_ptr = \$_ptr->parent; }";
}
if ($_scope == Smarty::SCOPE_GLOBAL) {
$output .= "\nSmarty::\$global_tpl_vars[$_attr[var]] = clone \$_smarty_tpl->tpl_vars[$_attr[var]];";
}
$output .= "\n\$_smarty_tpl->ext->_updateScope->updateScope(\$_smarty_tpl, $_attr[var], $_scope);";
$output .= '?>';
return $output;

View File

@ -1,24 +1,20 @@
<?php
/**
* Smarty Internal Plugin Compile Block
* Compiles the {block}{/block} tags
/*
* This file is part of Smarty.
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
* (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 Class
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews <uwe.tews@googlemail.com>
*/
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance
{
const parent = '____SMARTY_BLOCK_PARENT____';
/**
* Attribute definition: Overwrites base class.
*
@ -41,7 +37,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('hide', 'append', 'prepend', 'nocache');
public $option_flags = array('hide', 'nocache');
/**
* Attribute definition: Overwrites base class.
@ -49,395 +45,248 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('internal_file', 'internal_uid', 'internal_line');
/**
* nested child block names
*
* @var array
*/
public static $nested_block_names = array();
public $optional_attributes = array('assign');
/**
* child block source buffer
* nesting level of block tags
*
* @var array
* @var int
*/
public static $block_data = array();
public static $blockTagNestingLevel = 0;
/**
* 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 object $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 boolean true
* @return bool true
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
if (!isset($compiler->_cache['blockNesting'])) {
$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');
} else {
$this->option_flags = array('hide', 'nocache');
}
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$_name = trim($_attr['name'], "\"'");
// existing child must override parent settings
if (isset($compiler->template->block_data[$_name]) && $compiler->template->block_data[$_name]['mode'] == 'replace') {
$_attr['append'] = false;
$_attr['prepend'] = false;
$compiler->_cache['blockNesting'] ++;
$compiler->_cache['blockName'][$compiler->_cache['blockNesting']] = $_attr['name'];
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][0] = 'block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = false;
$this->openTag($compiler, 'block', array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
$compiler->template->compiled->has_nocache_code,
$compiler->template->caching));
// must whole block be nocache ?
if ($compiler->tag_nocache) {
$i = 0;
}
// check if we process an inheritance child template
if ($compiler->inheritance_child) {
array_unshift(self::$nested_block_names, $_name);
// build {block} for child block
self::$block_data[$_name]['source'] =
"{$compiler->smarty->left_delimiter}private_child_block name={$_attr['name']} file='{$compiler->template->source->filepath}' type='{$compiler->template->source->type}' resource='{$compiler->template->template_resource}'" .
" uid='{$compiler->template->source->uid}' line={$compiler->lex->line}";
if ($_attr['nocache']) {
self::$block_data[$_name]['source'] .= ' nocache';
}
self::$block_data[$_name]['source'] .= $compiler->smarty->right_delimiter;
$save = array($_attr, $compiler->inheritance);
$this->openTag($compiler, 'block', $save);
// set flag for {block} tag
$compiler->inheritance = true;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false;
return;
}
// must merge includes
if ($_attr['nocache'] == true) {
$compiler->tag_nocache = true;
}
$save = array($_attr, $compiler->inheritance, $compiler->parser->current_buffer, $compiler->nocache);
$this->openTag($compiler, 'block', $save);
$compiler->inheritance = true;
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
$compiler->has_code = false;
return true;
// $compiler->suppressNocacheProcessing = true;
if ($_attr['nocache'] === true) {
//$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->taglineno);
}
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
$compiler->suppressNocacheProcessing = true;
}
/**
* Compile saved child block source
*
* @param object $compiler compiler object
* @param string $_name optional name of child block
* @param \Smarty_Internal_TemplateCompilerBase compiler object
* @param string $_name optional name of child block
*
* @return string compiled code of child block
*/
static function compileChildBlock($compiler, $_name = null)
static function compileChildBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
{
if ($compiler->inheritance_child) {
$name1 = Smarty_Internal_Compile_Block::$nested_block_names[0];
if (isset($compiler->template->block_data[$name1])) {
// replace inner block name with generic
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source'];
Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true;
}
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false;
return;
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ',
$compiler->parser->lex->taglineno);
}
// if called by {$smarty.block.child} we must search the name of enclosing {block}
if ($_name == null) {
$stack_count = count($compiler->_tag_stack);
while (-- $stack_count >= 0) {
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
break;
}
}
}
if ($_name == null) {
$compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->lex->taglineno);
}
// undefined child?
if (!isset($compiler->template->block_data[$_name]['source'])) {
$compiler->popTrace();
return '';
}
// flag that child is already compile by {$smarty.block.child} inclusion
$compiler->template->block_data[$_name]['compiled'] = true;
$_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id,
$compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime);
if ($compiler->smarty->debugging) {
Smarty_Internal_Debug::ignore($_tpl);
}
$_tpl->tpl_vars = $compiler->template->tpl_vars;
$_tpl->variable_filters = $compiler->template->variable_filters;
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
$_tpl->allow_relative_path = true;
$_tpl->compiler->inheritance = true;
$_tpl->compiler->suppressHeader = true;
$_tpl->compiler->suppressFilter = true;
$_tpl->compiler->suppressTemplatePropertyHeader = true;
$nocache = $compiler->nocache || $compiler->tag_nocache;
if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) {
$_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler));
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler) . $compiler->parser->current_buffer->to_smarty_php();
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
} elseif (!empty($compiler->template->block_data[$_name])) {
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
}
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
$compiler->template->properties['tpl_function'] = array_merge($compiler->template->properties['tpl_function'], $_tpl->properties['tpl_function']);
$compiler->template->variable_filters = $_tpl->variable_filters;
if ($_tpl->has_nocache_code) {
$compiler->template->has_nocache_code = true;
}
foreach ($_tpl->required_plugins as $key => $tmp1) {
if ($compiler->nocache && $compiler->template->caching) {
$code = 'nocache';
} else {
$code = $key;
}
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$compiler->template->required_plugins[$code][$name][$type] = $data;
}
}
}
unset($_tpl);
$compiler->has_code = true;
return $_output;
$compiler->suppressNocacheProcessing = true;
$compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true;
$output = "<?php \n\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n";
return $output;
}
/**
* Compile $smarty.block.parent
*
* @param object $compiler compiler object
* @param string $_name optional name of child block
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param string $_name optional name of child block
*
* @return string compiled code of child block
*/
static function compileParentBlock($compiler, $_name = null)
static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null)
{
// if called by {$smarty.block.parent} we must search the name of enclosing {block}
if ($_name == null) {
$stack_count = count($compiler->_tag_stack);
while (-- $stack_count >= 0) {
if ($compiler->_tag_stack[$stack_count][0] == 'block') {
$_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'");
break;
}
}
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ',
$compiler->parser->lex->taglineno);
}
if ($_name == null) {
$compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno);
}
if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
$compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno);
}
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
$compiler->has_code = false;
return;
}
/**
* Process block source
*
* @param $compiler
* @param string $source source text
*/
static function blockSource($compiler, $source)
{
Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= $source;
$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";
return $output;
}
}
/**
* Smarty Internal Plugin Compile BlockClose Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
{
/**
* Compiles code for the {/block} tag
*
* @param array $args array with attributes from parser
* @param object $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
* @return bool true
*/
public function compile($args, $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']]);
$_block[2] = $_block[3] = 0;
$_name = trim($_attr['name'], "'\"");
$_assign = isset($_attr['assign']) ? $_attr['assign'] : null;
unset($_attr['assign'], $_attr['name']);
foreach ($_attr as $name => $stat) {
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat != 'false')) {
$_block[$name] = is_string($stat) ? trim($stat, "'\"") : $stat;
}
}
$_funcName = $_block[0];
// get compiled block code
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
if ($compiler->template->compiled->has_nocache_code) {
// $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
$_block[6] = $_funcNameCaching = $_funcName . '_nocache';
$output = "<?php\n";
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
$output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$_blockParentStack) {\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
if (isset($_assign)) {
$output .= "ob_start();\n";
}
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n";
if (isset($_assign)) {
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
}
$output .= "/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
$output .= "}\n";
$output .= "/* {/block '{$_name}'} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->blockOrFunctionCode .= $f = $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$this->compiler = $compiler;
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
array($this, 'removeNocache'),
$_functionCode->to_smarty_php($compiler->parser)));
$this->compiler = null;
}
$output = "<?php\n";
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
$output .= "function {$_funcName}(\$_smarty_tpl, \$_blockParentStack) {\n";
if (isset($_assign)) {
$output .= "ob_start();\n";
}
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php\n";
if (isset($_assign)) {
$output .= "\$_smarty_tpl->tpl_vars[{$_assign}] = new Smarty_Variable(ob_get_clean());\n";
}
$output .= "}\n";
$output .= "/* {/block '{$_name}'} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree($compiler->parser,
new Smarty_Internal_ParseTree_Tag($compiler->parser,
$output));
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// 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) {
$output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
var_export($_block, true) . ");\n";
} else {
$output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " .
var_export($_block, true) . ", \$_blockParentStack);\n";
}
$output .= "?>\n";
$compiler->_cache['blockNesting'] --;
if ($compiler->_cache['blockNesting'] == 0) {
unset($compiler->_cache['blockNesting']);
}
$compiler->has_code = true;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$saved_data = $this->closeTag($compiler, array('block'));
$_name = trim($saved_data[0]['name'], "\"'");
// reset flag for {block} tag
$compiler->inheritance = $saved_data[1];
// check if we process an inheritance child template
if ($compiler->inheritance_child) {
$name1 = Smarty_Internal_Compile_Block::$nested_block_names[0];
Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= "{$compiler->smarty->left_delimiter}/private_child_block{$compiler->smarty->right_delimiter}";
array_shift(Smarty_Internal_Compile_Block::$nested_block_names);
if (!empty(Smarty_Internal_Compile_Block::$nested_block_names)) {
$name2 = Smarty_Internal_Compile_Block::$nested_block_names[0];
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
if (isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child']) || !isset($compiler->template->block_data[$name1])) {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} else {
if ($compiler->template->block_data[$name1]['mode'] == 'append') {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source'];
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'] . Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} else {
Smarty_Internal_Compile_Block::$block_data[$name2]['source'] .= $compiler->template->block_data[$name1]['source'];
}
}
}
unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
} else {
if (isset($compiler->template->block_data[$name1]) || !$saved_data[0]['hide']) {
if (isset($compiler->template->block_data[$name1]) && !isset(Smarty_Internal_Compile_Block::$block_data[$name1]['child'])) {
if (strpos($compiler->template->block_data[$name1]['source'], Smarty_Internal_Compile_Block::parent) !== false) {
$compiler->template->block_data[$name1]['source'] =
str_replace(Smarty_Internal_Compile_Block::parent, Smarty_Internal_Compile_Block::$block_data[$name1]['source'], $compiler->template->block_data[$name1]['source']);
} elseif ($compiler->template->block_data[$name1]['mode'] == 'prepend') {
$compiler->template->block_data[$name1]['source'] .= Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
} elseif ($compiler->template->block_data[$name1]['mode'] == 'append') {
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'] . $compiler->template->block_data[$name1]['source'];
}
} else {
$compiler->template->block_data[$name1]['source'] = Smarty_Internal_Compile_Block::$block_data[$name1]['source'];
}
$compiler->template->block_data[$name1]['mode'] = 'replace';
if ($saved_data[0]['append']) {
$compiler->template->block_data[$name1]['mode'] = 'append';
}
if ($saved_data[0]['prepend']) {
$compiler->template->block_data[$name1]['mode'] = 'prepend';
}
}
unset(Smarty_Internal_Compile_Block::$block_data[$name1]);
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
}
$compiler->has_code = false;
return;
}
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
} else {
if ($saved_data[0]['hide'] && !isset($compiler->template->block_data[$_name]['source'])) {
$_output = '';
} else {
$_output = $compiler->parser->current_buffer->to_smarty_php();
}
}
if (isset($compiler->template->block_data[$_name]['compiled'])) {
unset($compiler->template->block_data[$_name]['compiled']);
}
// reset flags
$compiler->parser->current_buffer = $saved_data[2];
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
$compiler->nocache = $saved_data[3];
// $_output content has already nocache code processed
$compiler->suppressNocacheProcessing = true;
return $_output;
return $output;
}
}
/**
* Smarty Internal Plugin Compile Child Block Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Child_Block extends Smarty_Internal_CompileBase
{
/**
* Attribute definition: Overwrites base class.
* @param $match
*
* @var array
* @see Smarty_Internal_CompileBase
* @return mixed
*/
public $required_attributes = array('name', 'file', 'uid', 'line', 'type', 'resource');
/**
* Compiles code for the {private_child_block} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return boolean true
*/
public function compile($args, $compiler)
function removeNocache($match)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// update template with original template resource of {block}
if (trim($_attr['type'], "'") == 'file') {
$compiler->template->template_resource = 'file:' . realpath(trim($_attr['file'], "'"));
} else {
$compiler->template->template_resource = trim($_attr['resource'], "'");
}
// source object
unset ($compiler->template->source);
$exists = $compiler->template->source->exists;
// must merge includes
if ($_attr['nocache'] == true) {
$compiler->tag_nocache = true;
}
$save = array($_attr, $compiler->nocache);
// set trace back to child block
$compiler->pushTrace(trim($_attr['file'], "\"'"), trim($_attr['uid'], "\"'"), $_attr['line'] - $compiler->lex->line);
$this->openTag($compiler, 'private_child_block', $save);
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$compiler->has_code = false;
return true;
}
}
/**
* Smarty Internal Plugin Compile Child Block Close Class
*
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Private_Child_Blockclose extends Smarty_Internal_CompileBase
{
/**
* Compiles code for the {/private_child_block} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return boolean true
*/
public function compile($args, $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$saved_data = $this->closeTag($compiler, array('private_child_block'));
// end of child block
$compiler->popTrace();
$compiler->nocache = $saved_data[1];
$compiler->has_code = false;
return true;
$code =
preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/",
'', $match[0]);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code;
}
}

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('levels');
/**
* Attribute definition: Overwrites base class.
*
@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
/**
* Compiles code for the {break} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
}
$_levels = $_attr['levels'];
} else {
@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Break extends Smarty_Internal_CompileBase
$stack_count --;
}
if ($level_count != 0) {
$compiler->trigger_template_error("cannot break {$_levels} level(s)", $compiler->lex->taglineno);
$compiler->trigger_template_error("cannot break {$_levels} level(s)", null, true);
}
return "<?php break {$_levels};?>";

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -76,9 +78,11 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
//$compiler->suppressNocacheProcessing = true;
// was there an assign attribute
if (isset($_assign)) {
$_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
$_output =
"<?php ob_start();\n\$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
} else {
$_output = "<?php \$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n";
$_output =
"<?php \$_smarty_tpl->smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
}
return $_output;
}

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -34,12 +35,12 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
/**
* Compiles code for the {capture} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -51,10 +52,31 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>";
$_output = "<?php \$_smarty_tpl->_cache['capture_stack'][] = array($buffer, $assign, $append); ob_start(); ?>";
return $_output;
}
/**
* Compiles code for the {$smarty.capture.xxx}
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
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])) {
$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";
}
}
/**
@ -68,12 +90,12 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/capture} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -84,11 +106,11 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n";
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_cache['capture_stack']);\n";
$_output .= "if (!empty(\$_capture_buffer)) {\n";
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
$_output .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n";
$_output .= "} else \$_smarty_tpl->capture_error();?>";
return $_output;

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -30,30 +31,39 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file', 'section');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('section', 'scope');
public $optional_attributes = array('section', 'scope', 'bubble_up');
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
'smarty' => true, 'tpl_root' => true);
/**
* Compiles code for the {config_load} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// save possible attributes
@ -63,18 +73,31 @@ class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
} else {
$section = 'null';
}
$scope = 'local';
// scope setup
$_scope = Smarty::SCOPE_LOCAL;
if (isset($_attr['scope'])) {
$_attr['scope'] = trim($_attr['scope'], "'\"");
if (isset($_is_legal_scope[$_attr['scope']])) {
$scope = $_attr['scope'];
} else {
$compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
if (!isset($this->valid_scopes[$_attr['scope']])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
}
if ($_attr['scope'] != 'local') {
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} elseif ($_attr['scope'] == 'smarty') {
$_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
}
$_scope += (isset($_attr['bubble_up']) && $_attr['bubble_up'] == 'false') ? 0 : Smarty::SCOPE_BUBBLE_UP;
}
}
// create config object
$_output = "<?php Smarty_Internal_Extension_Config::configLoad(\$_smarty_tpl, $conf_file, $section, '$scope');?>";
$_output =
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
return $_output;
}

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('levels');
/**
* Attribute definition: Overwrites base class.
*
@ -34,25 +35,26 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
/**
* Compiles code for the {continue} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true);
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
if (isset($_attr['levels'])) {
if (!is_numeric($_attr['levels'])) {
$compiler->trigger_template_error('level attribute must be a numeric constant', $compiler->lex->taglineno);
$compiler->trigger_template_error('level attribute must be a numeric constant', null, true);
}
$_levels = $_attr['levels'];
} else {
@ -67,7 +69,7 @@ class Smarty_Internal_Compile_Continue extends Smarty_Internal_CompileBase
$stack_count --;
}
if ($level_count != 0) {
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", $compiler->lex->taglineno);
$compiler->trigger_template_error("cannot continue {$_levels} level(s)", null, true);
}
return "<?php continue {$_levels};?>";

View File

@ -34,8 +34,8 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true;
// display debug template
$_output = "<?php \$_smarty_tpl->smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>";
$_output = "<?php \$_smarty_debug = new Smarty_Internal_Debug;\n \$_smarty_debug->display_debug(\$_smarty_tpl);\n";
$_output .= "unset(\$_smarty_debug);\n?>";
return $_output;
}
}

View File

@ -15,7 +15,7 @@
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inheritance
{
/**
* Attribute definition: Overwrites base class.
@ -24,6 +24,15 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Array of names of optional attribute required by tag
* use array('_any') if there is no restriction of attributes names
*
* @var array
*/
public $optional_attributes = array('extends_resource');
/**
* Attribute definition: Overwrites base class.
*
@ -33,53 +42,93 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
public $shorttag_order = array('file');
/**
* Compiles code for the {extends} tag
* Compiles code for the {extends} tag extends: resource
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', $compiler->parser->lex->line - 1);
}
if (strpos($_attr['file'], '$_tmp') !== false) {
$compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
$compiler->trigger_template_error('illegal value for file attribute', $compiler->parser->lex->line - 1);
}
$name = $_attr['file'];
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
eval("\$tpl_name = $name;");
// create template object
$_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
// check for recursion
$uid = $_template->source->uid;
if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
}
$compiler->extends_uid[$uid] = true;
if (empty($_template->source->components)) {
array_unshift($compiler->sources, $_template->source);
} else {
foreach ($_template->source->components as $source) {
array_unshift($compiler->sources, $source);
$uid = $source->uid;
if (isset($compiler->extends_uid[$uid])) {
$compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
// add code to initialize inheritance
$this->registerInit($compiler, true);
$file = trim($_attr['file'], '\'"');
if (strlen($file) > 8 && substr($file, 0, 8) == 'extends:') {
// generate code for each template
$files = array_reverse(explode('|', substr($file, 8)));
$i = 0;
foreach ($files as $file) {
if ($file[0] == '"') {
$file = trim($file, '".');
} else {
$file = "'{$file}'";
}
$compiler->extends_uid[$uid] = true;
$i ++;
if ($i == count($files) && isset($_attr['extends_resource'])) {
$this->compileEndChild($compiler);
}
$this->compileInclude($compiler, $file);
}
if (!isset($_attr['extends_resource'])) {
$this->compileEndChild($compiler);
}
} else {
$this->compileEndChild($compiler);
$this->compileInclude($compiler, $_attr['file']);
}
unset ($_template);
$compiler->inheritance_child = true;
$compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
$compiler->has_code = false;
return '';
}
/**
* Add code for inheritance endChild() method to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*/
private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
"<?php \$_smarty_tpl->ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n");
}
/**
* Add code for including subtemplate to end of template
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
* @param string $file subtemplate name
*/
private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $file)
{
$compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser,
$compiler->compileTag('include',
array($file,
array('scope' => 'parent'))));
}
/**
* Create source code for {extends} from source components array
*
* @param []\Smarty_Internal_Template_Source $components
*
* @return string
*/
public static function extendsSourceArrayCode($components)
{
$resources = array();
foreach ($components as $source) {
$resources[] = $source->resource;
}
return '{extends file=\'extends:' . join('|', $resources) . '\' extends_resource=true}';
}
}

View File

@ -34,6 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
*/
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting++;
if ($parameter == 0) {
$this->required_attributes = array('start', 'to');
$this->optional_attributes = array('max', 'step');
@ -44,7 +45,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = "<?php ";
$output = "<?php\n";
if ($parameter == 1) {
foreach ($_attr['start'] as $_statement) {
if (is_array($_statement['var'])) {
@ -54,8 +55,8 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$var = $_statement['var'];
$index = '';
}
$output .= " \$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;";
$output .= " \$_smarty_tpl->tpl_vars[$var]->value{$index} = $_statement[value];\n";
$output .= "\$_smarty_tpl->tpl_vars[$var] = new Smarty_Variable;\n";
$output .= "\$_smarty_tpl->tpl_vars[$var]->value{$index} = {$_statement['value']};\n";
}
if (is_array($_attr['var'])) {
$var = $_attr['var']['var'];
@ -64,7 +65,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase
$var = $_attr['var'];
$index = '';
}
$output .= " if ($_attr[ifexp]) { for (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
$output .= "if ($_attr[ifexp]) {\nfor (\$_foo=true;$_attr[ifexp]; \$_smarty_tpl->tpl_vars[$var]->value{$index}$_attr[step]) {\n";
} else {
$_statement = $_attr['start'];
if (is_array($_statement['var'])) {
@ -148,6 +149,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
*/
public function compile($args, $compiler, $parameter)
{
$compiler->loopNesting--;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// must endblock be nocache?
@ -157,10 +159,11 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse'));
if ($openTag == 'forelse') {
return "<?php } ?>";
} else {
return "<?php }} ?>";
}
$output = "<?php }\n";
if ($openTag != 'forelse') {
$output .= "}\n";
}
$output .= "?>\n";
return $output;
}
}

View File

@ -14,7 +14,7 @@
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_ForeachSection
{
/**
* Attribute definition: Overwrites base class.
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('from', 'item');
/**
* Attribute definition: Overwrites base class.
*
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('name', 'key');
/**
* Attribute definition: Overwrites base class.
*
@ -38,178 +40,229 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_CompileBase
*/
public $shorttag_order = array('from', 'item', 'key', 'name');
/**
* counter
*
* @var int
*/
public $counter = 0;
/**
* Name of this tag
*
* @var string
*/
public $tagName = 'foreach';
/**
* Valid properties of $smarty.foreach.name.xxx variable
*
* @var array
*/
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total');
/**
* Valid properties of $item@xxx variable
*
* @var array
*/
public $itemProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'key');
/**
* Flag if tag had name attribute
*
* @var bool
*/
public $isNamed = false;
/**
* Compiles code for the {foreach} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->loopNesting ++;
// init
$this->isNamed = false;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$from = $_attr['from'];
$item = $_attr['item'];
if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
$compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
$item = $compiler->getId($_attr['item']);
if ($item === false) {
$item = $compiler->getVariableName($_attr['item']);
}
$attributes = array('item' => $item);
if (isset($_attr['key'])) {
$key = $_attr['key'];
} else {
$key = null;
$key = $compiler->getId($_attr['key']);
if ($key === false) {
$key = $compiler->getVariableName($_attr['key']);
}
$attributes['key'] = $key;
}
if (isset($_attr['name'])) {
$this->isNamed = true;
$attributes['name'] = $compiler->getId($_attr['name']);
}
foreach ($attributes as $a => $v) {
if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
}
}
$fromName = $compiler->getVariableName($_attr['from']);
if ($fromName) {
foreach (array('item', 'key') as $a) {
if (isset($attributes[$a]) && $attributes[$a] == $fromName) {
$compiler->trigger_template_error("'{$a}' and 'from' may not have same variable name '{$fromName}'",
null, true);
}
}
}
$this->openTag($compiler, 'foreach', array('foreach', $compiler->nocache, $item, $key, true));
$itemVar = "\$_smarty_tpl->tpl_vars['{$item}']";
$local = '$__foreach_' . (isset($attributes['name']) ? $attributes['name'] : $attributes['item']) . '_' .
$this->counter ++ . '_';
$needIteration = false;
// search for used tag attributes
$itemAttr = array();
$namedAttr = array();
$this->scanForProperties($attributes, $compiler);
if (!empty($this->matchResults['item'])) {
$itemAttr = $this->matchResults['item'];
}
if (!empty($this->matchResults['named'])) {
$namedAttr = $this->matchResults['named'];
}
if (isset($itemAttr['last'])) {
$needIteration = true;
}
if (isset($namedAttr['last'])) {
$needIteration = true;
}
$keyTerm = '';
if (isset($itemAttr['key'])) {
$keyTerm = "{$itemVar}->key => ";
} elseif (isset($attributes['key'])) {
$keyTerm = "\$_smarty_tpl->tpl_vars['{$key}']->value => ";
}
$saveVars = array();
$restoreVars = array();
if ($this->isNamed) {
$foreachVar = "\$_smarty_tpl->tpl_vars['__smarty_foreach_{$attributes['name']}']";
if (!empty($namedAttr)) {
$saveVars['saved'] = "isset({$foreachVar}) ? {$foreachVar} : false;";
$restoreVars[] = "if ({$local}saved) {\n{$foreachVar} = {$local}saved;\n}\n";
}
}
foreach (array('item', 'key') as $a) {
if (isset($attributes[$a])) {
$saveVars['saved_' . $a] =
"isset(\$_smarty_tpl->tpl_vars['{$attributes[$a]}']) ? \$_smarty_tpl->tpl_vars['{$attributes[$a]}'] : false;";
$restoreVars[] =
"if ({$local}saved_{$a}) {\n\$_smarty_tpl->tpl_vars['{$attributes[$a]}'] = {$local}saved_{$a};\n}\n";
}
}
$this->openTag($compiler, 'foreach',
array('foreach', $compiler->nocache, $local, $restoreVars, $itemVar, true));
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (isset($_attr['name'])) {
$name = trim($_attr['name'], '\'"');
$has_name = true;
$SmartyVarName = "\$smarty.foreach.{$name}.";
} else {
$has_name = false;
}
$ItemVarName = '$' . trim($item, '\'"') . '@';
// evaluates which Smarty variables and properties have to be computed
if ($has_name) {
$useSmartyForeach = $usesSmartyFirst = strpos($compiler->lex->data, $SmartyVarName . 'first') !== false;
$useSmartyForeach = ($usesSmartyLast = strpos($compiler->lex->data, $SmartyVarName . 'last') !== false) || $useSmartyForeach;
$useSmartyForeach = ($usesSmartyIndex = strpos($compiler->lex->data, $SmartyVarName . 'index') !== false) || $useSmartyForeach;
$useSmartyForeach = ($usesSmartyIteration = (!$usesSmartyIndex && ($usesSmartyFirst || $usesSmartyLast)) || strpos($compiler->lex->data, $SmartyVarName . 'iteration') !== false) || $useSmartyForeach;
$useSmartyForeach = ($usesSmartyShow = strpos($compiler->lex->data, $SmartyVarName . 'show') !== false) || $useSmartyForeach;
$useSmartyForeach = ($usesSmartyTotal = $usesSmartyLast ||strpos($compiler->lex->data, $SmartyVarName . 'total') !== false) || $useSmartyForeach;
} else {
$usesSmartyFirst = false;
$usesSmartyLast = false;
$usesSmartyTotal = false;
$usesSmartyShow = false;
$useSmartyForeach = false;
}
$usesPropKey = strpos($compiler->lex->data, $ItemVarName . 'key') !== false;
$usesPropFirst = strpos($compiler->lex->data, $ItemVarName . 'first') !== false;
$usesPropLast = strpos($compiler->lex->data, $ItemVarName . 'last') !== false;
$usesPropIndex = strpos($compiler->lex->data, $ItemVarName . 'index') !== false;
$usesPropIteration = (!$usesPropIndex && ($usesPropFirst || $usesPropLast)) || strpos($compiler->lex->data, $ItemVarName . 'iteration') !== false;
$usesPropShow = strpos($compiler->lex->data, $ItemVarName . 'show') !== false;
$usesPropTotal = $usesPropLast || strpos($compiler->lex->data, $ItemVarName . 'total') !== false;
$keyTerm = '';
if ($usesPropKey) {
$keyTerm = "\$_smarty_tpl->tpl_vars[$item]->key => ";
} elseif ($key != null) {
$keyTerm = "\$_smarty_tpl->tpl_vars[$key]->value => ";
}
// generate output code
$output = "<?php\n";
$output .= "\$_from = $from;\n";
$output .= "if (!is_array(\$_from) && !is_object(\$_from)) {\n";
$output .= "settype(\$_from, 'array');\n";
$output .= "}\n";
$output .= "\$_smarty_tpl->tpl_vars[$item] = new Smarty_Variable;\n";
$output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = false;\n";
if ($key != null) {
$output .= "\$_smarty_tpl->tpl_vars[$key] = new Smarty_Variable;\n";
foreach ($saveVars as $k => $code) {
$output .= "{$local}{$k} = {$code}\n";
}
if ($usesPropTotal) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->total= \$_smarty_tpl->_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";
}
if ($usesPropIteration) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->iteration=0;\n";
if (isset($itemAttr['total'])) {
$output .= "{$itemVar}->total= {$local}total;\n";
}
if ($usesPropIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->index=-1;\n";
}
if ($usesPropShow) {
if ($usesPropTotal) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->tpl_vars[$item]->total > 0);\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$item]->show = (\$_smarty_tpl->_count(\$_from) > 0);\n";
}
}
if ($has_name) {
if ($this->isNamed) {
$prop = array();
if ($usesSmartyTotal) {
$prop['total'] = "'total' => ";
$prop['total'] .= $usesSmartyShow ? '$total = ' : '';
$prop['total'] .= '$_smarty_tpl->_count($_from)';
if (isset($namedAttr['total'])) {
$prop['total'] = "'total' => {$local}total";
}
if ($usesSmartyIteration) {
if (isset($namedAttr['iteration'])) {
$prop['iteration'] = "'iteration' => 0";
}
if ($usesSmartyIndex) {
if (isset($namedAttr['index'])) {
$prop['index'] = "'index' => -1";
}
if ($usesSmartyShow) {
$prop['show'] = "'show' => ";
if ($usesSmartyTotal) {
$prop['show'] .= "(\$total > 0)";
} else {
$prop['show'] .= "(\$_smarty_tpl->_count(\$_from) > 0)";
}
if (isset($namedAttr['show'])) {
$prop['show'] = "'show' => ({$local}total > 0)";
}
if ($useSmartyForeach) {
if (!empty($namedAttr)) {
$_vars = 'array(' . join(', ', $prop) . ')';
$foreachVar = "'__foreach_{$name}'";
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar] = new Smarty_Variable({$_vars});\n";
$output .= "{$foreachVar} = new Smarty_Variable({$_vars});\n";
}
}
$output .= "foreach (\$_from as {$keyTerm}\$_smarty_tpl->tpl_vars[$item]->value) {\n";
$output .= "\$_smarty_tpl->tpl_vars[$item]->_loop = true;\n";
if ($key != null && $usesPropKey) {
$output .= "\$_smarty_tpl->tpl_vars[$key]->value = \$_smarty_tpl->tpl_vars[$item]->key;\n";
$output .= "if ({$local}total) {\n";
if (isset($attributes['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}'] = new Smarty_Variable();\n";
}
if ($usesPropIteration) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->iteration++;\n";
if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
$output .= "{$local}first = true;\n";
}
if ($usesPropIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->index++;\n";
if (isset($itemAttr['iteration'])) {
$output .= "{$itemVar}->iteration=0;\n";
}
if ($usesPropFirst) {
if ($usesPropIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->index == 0;\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$item]->first = \$_smarty_tpl->tpl_vars[$item]->iteration == 1;\n";
if (isset($itemAttr['index'])) {
$output .= "{$itemVar}->index=-1;\n";
}
if ($needIteration) {
$output .= "{$local}iteration=0;\n";
}
$output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n";
if (isset($attributes['key']) && isset($itemAttr['key'])) {
$output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n";
}
if (isset($itemAttr['iteration'])) {
$output .= "{$itemVar}->iteration++;\n";
}
if (isset($itemAttr['index'])) {
$output .= "{$itemVar}->index++;\n";
}
if ($needIteration) {
$output .= "{$local}iteration++;\n";
}
if (isset($itemAttr['first'])) {
$output .= "{$itemVar}->first = {$local}first;\n";
}
if (isset($itemAttr['last'])) {
$output .= "{$itemVar}->last = {$local}iteration == {$local}total;\n";
}
if ($this->isNamed) {
if (isset($namedAttr['iteration'])) {
$output .= "{$foreachVar}->value['iteration']++;\n";
}
if (isset($namedAttr['index'])) {
$output .= "{$foreachVar}->value['index']++;\n";
}
if (isset($namedAttr['first'])) {
$output .= "{$foreachVar}->value['first'] = {$local}first;\n";
}
if (isset($namedAttr['last'])) {
$output .= "{$foreachVar}->value['last'] = {$local}iteration == {$local}total;\n";
}
}
if ($usesPropLast) {
if ($usesPropIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->index + 1 == \$_smarty_tpl->tpl_vars[$item]->total;\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$item]->last = \$_smarty_tpl->tpl_vars[$item]->iteration == \$_smarty_tpl->tpl_vars[$item]->total;\n";
}
if (isset($namedAttr['first']) || isset($itemAttr['first'])) {
$output .= "{$local}first = false;\n";
}
if ($has_name) {
if ($usesSmartyIteration) {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration']++;\n";
}
if ($usesSmartyIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['index']++;\n";
}
if ($usesSmartyFirst) {
if ($usesSmartyIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] == 0;\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['first'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == 1;\n";
}
}
if ($usesSmartyLast) {
if ($usesSmartyIndex) {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['index'] + 1 == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n";
} else {
$output .= "\$_smarty_tpl->tpl_vars[$foreachVar]->value['last'] = \$_smarty_tpl->tpl_vars[$foreachVar]->value['iteration'] == \$_smarty_tpl->tpl_vars[$foreachVar]->value['total'];\n";
}
}
}
$itemName = trim($item,"'\"");
$output .= "\$foreach_{$itemName}_Sav = \$_smarty_tpl->tpl_vars[$item];\n";
$output .= "{$local}saved_local_item = {$itemVar};\n";
$output .= "?>";
return $output;
@ -227,24 +280,23 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {foreachelse} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache, $item, $key, $foo) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $item, $key, false));
$itemName = trim($item,"'\"");
list($openTag, $nocache, $local, $restoreVars, $itemVar, $foo) = $this->closeTag($compiler, array('foreach'));
$this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $restoreVars, $itemVar, false));
$output = "<?php\n";
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
$output .= "if (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
$output .= "} else {\n?>";
return $output;
}
}
@ -260,28 +312,33 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/foreach} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->loopNesting --;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
list($openTag, $compiler->nocache, $item, $key, $restore) = $this->closeTag($compiler, array('foreach', 'foreachelse'));
$itemName = trim($item,"'\"");
list($openTag, $compiler->nocache, $local, $restoreVars, $itemVar, $restore) =
$this->closeTag($compiler, array('foreach', 'foreachelse'));
$output = "<?php\n";
if ($restore) {
$output .= "\$_smarty_tpl->tpl_vars[$item] = \$foreach_{$itemName}_Sav;\n";
$output .= "{$itemVar} = {$local}saved_local_item;\n";
$output .= "}\n";
}
$output .= "}\n?>";
$output .= "}\n";
foreach ($restoreVars as $restore) {
$output .= $restore;
}
$output .= "?>";
return $output;
}

View File

@ -44,32 +44,31 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
/**
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return boolean true
* @return bool true
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
unset($_attr['nocache']);
$_name = trim($_attr['name'], "'\"");
$compiler->parent_compiler->templateProperties['tpl_function'][$_name] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching);
$compiler->parent_compiler->template->tpl_function[$_name] = array();
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
$compiler->template->caching);
$this->openTag($compiler, 'function', $save);
// set flag that we are compiling a template function
$compiler->compiles_template_function = true;
// Init temporary context
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
$compiler->template->has_nocache_code = false;
$compiler->template->caching = true;
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$compiler->template->compiled->has_nocache_code = false;
return true;
}
}
@ -101,15 +100,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*/
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->loopNesting--;
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, array('function'));
$_attr = $saved_data[0];
$_name = trim($_attr['name'], "'\"");
// reset flag that we are compiling a template function
$compiler->compiles_template_function = false;
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['called_functions'] = $compiler->called_functions;
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['uid'] = $compiler->template->source->uid;
$compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions;
$compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
$compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
$compiler->called_functions = array();
$_parameter = $_attr;
unset($_parameter['name']);
@ -130,89 +128,71 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
}
$_functionCode = $compiler->parser->current_buffer;
// setup buffer for template function code
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template($compiler->parser);
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . '_nocache';
if ($compiler->template->has_nocache_code) {
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name_caching'] = $_funcNameCaching;
if ($compiler->template->compiled->has_nocache_code) {
$compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
$output = "<?php\n";
$output .= "/* {$_funcNameCaching} */\n";
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
// build plugin include code
if (!empty($compiler->template->required_plugins['compiled'])) {
foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
foreach ($tmp as $data) {
$output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
}
}
}
if (!empty($compiler->template->required_plugins['nocache'])) {
$output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
foreach ($compiler->template->required_plugins['nocache'] as $tmp) {
foreach ($tmp as $data) {
$output .= "if (!is_callable(\'{$data['function']}\')) require_once \'{$data['file']}\';\n";
}
}
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
}
$output .= "ob_start();\n";
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
$output .= $_paramsCode;
$output .= "\$_smarty_tpl->properties['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n";
$output .= "\$_smarty_tpl->_cache['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n";
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}";
$output .= "\$params = var_export(\$params, true);\n";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
$output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
$output .= "if (!isset(\\\$_smarty_tpl->tpl_vars[\\\$key]) || \\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n";
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->properties['saved_tpl_vars']);\n}\n}\n";
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n";
$output .= "/*/ {$_funcName}_nocache */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()));
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this,
'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
}
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName;
$compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName;
$output = "<?php\n";
$output .= "/* {$_funcName} */\n";
$output .= "if (!function_exists('{$_funcName}')) {\n";
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
// build plugin include code
if (!empty($compiler->template->required_plugins['nocache'])) {
$compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $compiler->template->required_plugins['nocache']);
}
if (!empty($compiler->template->required_plugins['compiled'])) {
foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
foreach ($tmp as $data) {
$output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
}
}
}
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
$output .= $_paramsCode;
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($_functionCode);
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
$output = "<?php foreach (Smarty::\$global_tpl_vars as \$key => \$value){\n";
$output .= "if (\$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n";
$output .= "if (!isset(\$_smarty_tpl->tpl_vars[\$key]) || \$_smarty_tpl->tpl_vars[\$key] === \$value) \$saved_tpl_vars[\$key] = \$value;\n}\n";
$output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars;\n}\n}\n";
$output .= "/*/ {$_funcName} */\n\n";
$output .= "?>\n";
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php();
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
// nocache plugins must be copied
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
foreach ($tmp as $type => $data) {
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = $data;
}
}
}
// restore old buffer
$compiler->parser->current_buffer = $saved_data[1];
// restore old status
$compiler->template->has_nocache_code = $saved_data[2];
$compiler->template->required_plugins = $saved_data[3];
$compiler->template->caching = $saved_data[4];
$compiler->template->compiled->has_nocache_code = $saved_data[2];
$compiler->template->caching = $saved_data[3];
return true;
}
@ -223,7 +203,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
*/
function removeNocache($match)
{
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", '', $match[0]);
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", '', $match[0]);
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
return $code;
}

View File

@ -19,13 +19,14 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
/**
* Compiles code for the {if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -34,7 +35,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno);
$compiler->trigger_template_error("missing if condition", null, true);
}
if (is_array($parameter['if condition'])) {
@ -45,7 +46,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$var = trim($parameter['if condition']['var']['var'], "'");
} else {
$var = trim($parameter['if condition']['var'], "'");
}
}
if (isset($compiler->template->tpl_vars[$var])) {
$compiler->template->tpl_vars[$var]->nocache = true;
} else {
@ -55,11 +56,19 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$_nocache = '';
}
if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
"$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
}
return $_output;
@ -80,13 +89,13 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase
/**
* Compiles code for the {else} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
$this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache));
@ -106,13 +115,14 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
/**
* Compiles code for the {elseif} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -120,7 +130,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif'));
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno);
$compiler->trigger_template_error("missing elseif condition", null, true);
}
if (is_array($parameter['if condition'])) {
@ -149,11 +159,20 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
if ($condition_by_assign) {
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if (is_array($parameter['if condition']['var'])) {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " .
$parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else {
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
$_output = "<?php } else { if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
}
return $_output;
@ -166,17 +185,29 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$tmp = '';
foreach ($compiler->prefix_code as $code) {
$tmp = $compiler->appendCode($tmp, $code);
}
}
$compiler->prefix_code = array();
$tmp = $compiler->appendCode("<?php } else {?>", $tmp);
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) {
if (is_array($parameter['if condition']['var'])) {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " .
$parameter['if condition']['var']['var'] . "$_nocache);\n");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else {
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
$_output = $compiler->appendCode($tmp, "<?php if (!isset(\$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] .
"])) \$_smarty_tpl->tpl_vars[" .
$parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});");
$_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
}
return $_output;
@ -198,13 +229,13 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/if} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// must endblock be nocache?
if ($compiler->nocache) {

View File

@ -20,6 +20,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* caching mode to create nocache code but no cache file
*/
const CACHING_NOCACHE_CODE = 9999;
/**
* Attribute definition: Overwrites base class.
*
@ -27,6 +28,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -34,13 +36,15 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'inline', 'caching');
public $option_flags = array('nocache', 'inline', 'caching', 'bubble_up');
/**
* Attribute definition: Overwrites base class.
*
@ -49,6 +53,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
*/
public $optional_attributes = array('_any');
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'global' => true,
'smarty' => true, 'tpl_root' => true);
/**
* Compiles code for the {include} tag
*
@ -64,26 +76,73 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
$include_file = $_attr['file'];
$hashResourceName = $fullResourceName = $source_resource = $_attr['file'];
$variable_template = false;
$cache_tpl = false;
// parse resource_name
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type;
$name = !empty($match[5]) ? $match[5] : $match[6];
$handler = Smarty_Resource::load($compiler->smarty, $type);
if ($handler->recompiled || $handler->uncompiled) {
$variable_template = true;
}
if (!$variable_template) {
if ($type != 'string') {
$fullResourceName = "{$type}:{$name}";
$compiled = $compiler->parent_compiler->template->compiled;
if (isset($compiled->includes[$fullResourceName])) {
$compiled->includes[$fullResourceName] ++;
$cache_tpl = true;
} else {
$compiled->includes[$fullResourceName] = 1;
}
$fullResourceName = '"' . $fullResourceName . '"';
}
}
if (empty($match[5])) {
$variable_template = true;
}
} else {
$variable_template = true;
}
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
}
$_parent_scope = Smarty::SCOPE_LOCAL;
// scope setup
$_scope = Smarty::SCOPE_LOCAL;
if (isset($_attr['scope'])) {
$_attr['scope'] = trim($_attr['scope'], "'\"");
if ($_attr['scope'] == 'parent') {
$_parent_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_parent_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_parent_scope = Smarty::SCOPE_GLOBAL;
if (!isset($this->valid_scopes[$_attr['scope']])) {
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null, true);
}
if ($_attr['scope'] != 'local') {
if ($_attr['scope'] == 'parent') {
$_scope = Smarty::SCOPE_PARENT;
} elseif ($_attr['scope'] == 'root') {
$_scope = Smarty::SCOPE_ROOT;
} elseif ($_attr['scope'] == 'global') {
$_scope = Smarty::SCOPE_GLOBAL;
} elseif ($_attr['scope'] == 'smarty') {
$_scope = Smarty::SCOPE_SMARTY;
} elseif ($_attr['scope'] == 'tpl_root') {
$_scope = Smarty::SCOPE_TPL_ROOT;
}
if ($_attr['bubble_up'] === true) {
$_scope = $_scope + Smarty::SCOPE_BUBBLE_UP;
}
}
}
// set flag to cache subtemplate object when called within loop or template name is variable.
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
$_cache_tpl = 'true';
} else {
$_cache_tpl = 'false';
}
// assume caching is off
$_caching = Smarty::CACHING_OFF;
@ -99,31 +158,29 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
// flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled;
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) &&
!$compiler->template->source->handler->recompiled;
if ($merge_compiled_includes && $_attr['inline'] !== true) {
// variable template name ?
if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2)) || substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0) {
if ($variable_template) {
$merge_compiled_includes = false;
if ($compiler->template->caching) {
// must use individual cache file
//$_attr['caching'] = 1;
}
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) {
$compiler->trigger_template_error(' variable template file names not allow within {block} tags');
}
}
// variable compile_id?
if (isset($_attr['compile_id'])) {
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 || is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0) {
if (!((substr_count($_attr['compile_id'], '"') == 2 || substr_count($_attr['compile_id'], "'") == 2 ||
is_numeric($_attr['compile_id']))) || substr_count($_attr['compile_id'], '(') != 0 ||
substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0
) {
$merge_compiled_includes = false;
if ($compiler->template->caching) {
// must use individual cache file
//$_attr['caching'] = 1;
}
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) {
$compiler->trigger_template_error(' variable compile_id not allow within {block} tags');
}
}
}
}
@ -167,74 +224,23 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$has_compiled_template = false;
if ($merge_compiled_includes) {
if ($compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache) && $_caching != self::CACHING_NOCACHE_CODE) {
// $merge_compiled_includes = false;
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) {
$compiler->trigger_template_error(' invalid caching mode of subtemplate within {block} tags');
}
}
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
// we must observe different compile_id and caching
$uid = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
$tpl_name = null;
/** @var Smarty_Internal_Template $_smarty_tpl
* used in evaluated code
*/
$_smarty_tpl = $compiler->template;
eval("\$tpl_name = $include_file;");
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid])) {
$compiler->smarty->allow_ambiguous_resources = true;
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
// save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
if ($compiler->inheritance) {
$tpl->compiler->inheritance = true;
}
// make sure whole chain gets compiled
$tpl->mustCompile = true;
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
$tpl->compiler->suppressTemplatePropertyHeader = true;
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = str_replace(array('.', ','), '_', uniqid(rand(), true));
// get compiled code
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
unset($tpl->compiler);
// remove header code
$compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code);
if ($tpl->has_nocache_code) {
// replace nocache_hash
$compiled_code = str_replace("{$tpl->properties['nocache_hash']}", $compiler->template->properties['nocache_hash'], $compiled_code);
$compiler->template->has_nocache_code = true;
}
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->properties['unifunc']] = $compiled_code;
$has_compiled_template = true;
if (!empty($tpl->required_plugins['compiled'])) {
foreach ($tpl->required_plugins['compiled'] as $name => $callBack) {
if (!isset($compiler->template->required_plugins['compiled'][$name])) {
$compiler->template->required_plugins['compiled'][$name] = $callBack;
}
}
}
if (!empty($tpl->required_plugins['nocache'])) {
foreach ($tpl->required_plugins['nocache'] as $name => $callBack) {
if (!isset($compiler->template->required_plugins['nocache'][$name])) {
$compiler->template->required_plugins['nocache'][$name] = $callBack;
}
}
}
unset ($tpl);
}
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) {
$has_compiled_template =
$this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash,
$c_id);
} else {
$has_compiled_template = true;
}
}
// delete {include} standard attributes
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']);
unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline'], $_attr['bubble_up']);
// remaining attributes must be assigned as smarty variable
$_vars_nc = '';
if (!empty($_attr)) {
if ($_parent_scope == Smarty::SCOPE_LOCAL) {
if ($_scope == Smarty::SCOPE_LOCAL) {
$_pairs = array();
// create variables
foreach ($_attr as $key => $value) {
@ -243,35 +249,34 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
$_vars = 'array(' . join(',', $_pairs) . ')';
} else {
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', $compiler->lex->taglineno);
$compiler->trigger_template_error('variable passing not allowed in parent/global scope', null, true);
}
} else {
$_vars = 'array()';
}
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && $_compile_id != '$_smarty_tpl->compile_id';
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
$_compile_id != '$_smarty_tpl->compile_id';
if ($has_compiled_template && !$call_nocache) {
// if ($has_compiled_template && !$compiler->tag_nocache && !$compiler->nocache) {
// never call inline templates in nocache mode
//$compiler->suppressNocacheProcessing = true;
$_hash = $compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'];
$_output = "<?php /* Call merged included template \"" . $tpl_name . "\" */\n";
$_output = "<?php\n";
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
}
if (!empty($_vars_nc) && $_caching == 9999 && $_smarty_tpl->caching) {
if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) {
//$compiler->suppressNocacheProcessing = false;
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
//$compiler->suppressNocacheProcessing = true;
}
if (isset($_assign)) {
$_output .= " \$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}'));\n";
} else {
$_output .= "echo \$_smarty_tpl->getInlineSubTemplate({$include_file}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_parent_scope}, '{$_hash}', '{$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func']}');\n";
$_output .= "ob_start();\n";
}
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func']}');\n";
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
if ($update_compile_id) {
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
}
$_output .= "/* End of included template \"" . $tpl_name . "\" */?>\n";
$_output .= "?>\n";
return $_output;
}
@ -285,9 +290,11 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
}
// was there an assign attribute
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->tpl_vars[$_assign] = new Smarty_Variable(\$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope));\n";
} else {
$_output .= "echo \$_smarty_tpl->getSubTemplate ($include_file, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_parent_scope);\n";
$_output .= "ob_start();\n";
}
$_output .= "\$_smarty_tpl->smarty->ext->_subtemplate->render(\$_smarty_tpl, {$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n";
if (isset($_assign)) {
$_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
}
if ($update_compile_id) {
$_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n";
@ -295,4 +302,65 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_output .= "?>\n";
return $_output;
}
/**
* Compile inline sub template
*
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
* @param $fullResourceName
* @param $_caching
* @param $hashResourceName
* @param $t_hash
* @param $c_id
*
* @return bool
*/
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName,
$_caching, $hashResourceName, $t_hash, $c_id)
{
$compiler->smarty->allow_ambiguous_resources = true;
/* @var Smarty_Internal_Template $tpl */
$tpl =
new $compiler->smarty->template_class (trim($fullResourceName, '"\''), $compiler->smarty, $compiler->template,
$compiler->template->cache_id, $c_id, $_caching);
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid;
if (isset($compiler->template->_inheritance)) {
$tpl->_inheritance = clone $compiler->template->_inheritance;
}
$tpl->compiled = new Smarty_Template_Compiled();
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
$tpl->loadCompiler();
// save unique function name
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
// make sure whole chain gets compiled
$tpl->mustCompile = true;
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] =
$tpl->compiled->nocache_hash;
// get compiled code
$compiled_code = "<?php\n\n";
$compiled_code .= "/* Start inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
$compiled_code .= "<?php\n";
$compiled_code .= "}\n?>\n";
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
$compiled_code .= "<?php\n\n";
$compiled_code .= "/* End inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
$compiled_code .= "?>";
unset($tpl->compiler);
if ($tpl->compiled->has_nocache_code) {
// replace nocache_hash
$compiled_code =
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
$compiled_code);
$compiler->template->compiled->has_nocache_code = true;
}
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
return true;
} else {
return false;
}
}
}

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('file');
/**
* Attribute definition: Overwrites base class.
*
@ -41,13 +43,14 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
/**
* Compiles code for the {include_php} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @throws SmartyException
* @return string compiled code
* @return string
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
if (!($compiler->smarty instanceof SmartyBC)) {
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
@ -60,9 +63,10 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
*/
$_smarty_tpl = $compiler->template;
$_filepath = false;
eval('$_file = ' . $_attr['file'] . ';');
$_file = null;
eval('$_file = @' . $_attr['file'] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
$_filepath = $_file;
$_filepath = $compiler->smarty->_realpath($_file, true);
} else {
if (isset($compiler->smarty->security_policy)) {
$_dir = $compiler->smarty->security_policy->trusted_dir;
@ -71,16 +75,16 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
if (!empty($_dir)) {
foreach ((array) $_dir as $_script_dir) {
$_script_dir = rtrim($_script_dir, '/\\') . DS;
if (file_exists($_script_dir . $_file)) {
$_filepath = $_script_dir . $_file;
$_path = $compiler->smarty->_realpath($_script_dir . DS . $_file, true);
if (file_exists($_path)) {
$_filepath = $_path;
break;
}
}
}
}
if ($_filepath == false) {
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", $compiler->lex->taglineno);
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
}
if (isset($compiler->smarty->security_policy)) {
@ -99,7 +103,7 @@ class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
}
if (isset($_assign)) {
return "<?php ob_start(); include{$_once} ('{$_filepath}'); \$_smarty_tpl->assign({$_assign},ob_get_contents()); ob_end_clean();?>";
return "<?php ob_start();\ninclude{$_once} ('{$_filepath}');\n\$_smarty_tpl->assign({$_assign},ob_get_clean());\n?>";
} else {
return "<?php include{$_once} ('{$_filepath}');?>\n";
}

View File

@ -24,6 +24,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -31,6 +32,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
@ -42,12 +44,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
/**
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -63,7 +66,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_output = '<?php ';
// save possible attributes
eval('$_name = ' . $_attr['name'] . ';');
eval('$_name = @' . $_attr['name'] . ';');
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
@ -80,7 +83,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
$_function = "smarty_insert_{$_name}";
$_smarty_tpl = $compiler->template;
$_filepath = false;
eval('$_script = ' . $_attr['script'] . ';');
eval('$_script = @' . $_attr['script'] . ';');
if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
$_filepath = $_script;
} else {
@ -100,13 +103,13 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
}
}
if ($_filepath == false) {
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", $compiler->lex->taglineno);
$compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
}
// code for script file loading
$_output .= "require_once '{$_filepath}' ;";
require_once $_filepath;
if (!is_callable($_function)) {
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", $compiler->lex->taglineno);
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'", null, true);
}
} else {
$_filepath = 'null';
@ -115,7 +118,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
if (!is_callable($_function)) {
// try plugin
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", $compiler->lex->taglineno);
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null, true);
}
}
}
@ -124,7 +127,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
// convert attributes into parameter array string
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
$_paramsArray[] = "'$_key' => $_value";
$_paramsArray[] = "'$_key' => $_value";
}
$_params = 'array(' . implode(", ", $_paramsArray) . ')';
// call insert

View File

@ -20,16 +20,17 @@ class Smarty_Internal_Compile_Ldelim extends Smarty_Internal_CompileBase
* Compiles code for the {ldelim} tag
* This tag does output the left delimiter
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;

View File

@ -27,12 +27,12 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase
* Compiles code for the {nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'nocache', array($compiler->nocache));
@ -57,12 +57,12 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase
* Compiles code for the {/nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return bool
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
// leave nocache mode

View File

@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
/**
* Compiles code for the execution of block plugin
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $function)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
@ -60,7 +60,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
// maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// compile code
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else {
// must endblock be nocache?
if ($compiler->nocache) {
@ -75,9 +75,13 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$mod_pre = $mod_post = '';
} else {
$mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
$mod_post = 'echo ' .
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
}
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
}
return $output . "\n";

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array();
/**
* Attribute definition: Overwrites base class.
*
@ -34,15 +35,15 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param object $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
* @param string $tag name of function plugin
* @param string $function PHP function name
* @param string $function PHP function name
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $function)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
{
// This tag does create output
$compiler->has_output = true;

View File

@ -20,13 +20,14 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
/**
* Compiles code for modifier execution
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -52,7 +53,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
$output = "{$function}({$params})";
} else {
if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
}
@ -73,7 +75,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifiercompiler plugin
if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$plugin = 'smarty_modifiercompiler_' . $modifier;
$output = $plugin($single_modifier, $compiler);
}
@ -85,7 +89,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// modifier plugin
if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
$output = "{$function}({$params})";
}
$compiler->known_modifier_type[$modifier] = $type;
@ -96,7 +102,9 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
// PHP function
if (is_callable($modifier)) {
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
) {
$output = "{$modifier}({$params})";
}
$compiler->known_modifier_type[$modifier] = $type;
@ -105,21 +113,29 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
break;
case 6:
// default plugin handler
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) ||
(is_callable($compiler->smarty->default_plugin_handler_func) &&
$compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
) {
$function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
// check if modifier allowed
if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
if (!is_object($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
) {
if (!is_array($function)) {
$output = "{$function}({$params})";
} else {
if (is_object($function[0])) {
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
} else {
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
}
}
}
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
) {
// was a plugin
$compiler->known_modifier_type[$modifier] = 4;
} else {
@ -130,7 +146,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
}
}
if (!isset($compiler->known_modifier_type[$modifier])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
}
}

View File

@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
/**
* Compiles code for the execution of block plugin
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block object
* @param string $method name of method to call
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block object
* @param string $method name of method to call
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $method)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
@ -60,7 +60,8 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
// maybe nocache because of nocache variables or nocache plugin
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
// compile code
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
$output =
"<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else {
$base_tag = substr($tag, 0, - 5);
// must endblock be nocache?
@ -76,9 +77,13 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
$mod_pre = $mod_post = '';
} else {
$mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
}
$output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
}
return $output . "\n";

View File

@ -27,15 +27,15 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co
/**
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $method name of method to call
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag, $method)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);

View File

@ -42,10 +42,12 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
$compiler->has_code = false;
if ($_attr['type'] == 'xml') {
$compiler->tag_nocache = true;
$save = $compiler->template->has_nocache_code;
$save = $compiler->template->compiled->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\");
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true)));
$compiler->template->has_nocache_code = $save;
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>", $compiler, true)));
$compiler->template->compiled->has_nocache_code = $save;
return '';
}
if ($_attr['type'] != 'tag') {
@ -53,29 +55,31 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
return '';
} elseif ($compiler->php_handling == Smarty::PHP_QUOTE) {
$output = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this,
'quote'), $_attr['code']);
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Text($compiler->parser, $output));
'quote'), $_attr['code']);
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Text($output));
return '';
} elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr['type'] == 'unmatched') {
$compiler->tag_nocache = true;
$save = $compiler->template->has_nocache_code;
$save = $compiler->template->compiled->has_nocache_code;
$output = addcslashes($_attr['code'], "'\\");
$compiler->parser->current_buffer->append_subtree(new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" . $output . "';?>", $compiler, true)));
$compiler->template->has_nocache_code = $save;
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->processNocacheCode("<?php echo '" .
$output .
"';?>", $compiler, true)));
$compiler->template->compiled->has_nocache_code = $save;
return '';
} elseif ($compiler->php_handling == Smarty::PHP_ALLOW) {
if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', $compiler->lex->taglineno);
$compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', null, true);
}
$compiler->has_code = true;
return $_attr['code'];
} else {
$compiler->trigger_template_error('Illegal $smarty->php_handling value', $compiler->lex->taglineno);
$compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
}
} else {
$compiler->has_code = true;
if (!($compiler->smarty instanceof SmartyBC)) {
$compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', $compiler->lex->taglineno);
$compiler->trigger_template_error('{php}[/php} tags not allowed. Use SmartyBC to enable them', null, true);
}
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
@ -84,11 +88,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ('nocache' == trim($match[2])) {
$compiler->tag_nocache = true;
} else {
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", $compiler->lex->taglineno);
$compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true);
}
}
return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#",
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
"#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), array('<?php ', '?>'), $_attr['code']);
}
}
@ -140,7 +144,9 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
if ($lex->phpType == 'unmatched') {
return;
}
if (($lex->phpType == 'php' || $lex->phpType == 'asp') && ($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)) {
if (($lex->phpType == 'php' || $lex->phpType == 'asp') &&
($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE)
) {
return;
}
$start = $lex->counter + strlen($lex->value);
@ -167,7 +173,8 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
}
}
while ($close > $pos && $close < $start) {
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) {
if (preg_match('~' . preg_quote($closeTag, '~') .
'~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $from)) {
$close = $match[0][1];
$from = $close + strlen($match[0][0]);
} else {
@ -190,6 +197,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
* Call back function for $php_handling = PHP_QUOTE
*
*/
/**
* @param $match
*
* @return string
*/
private function quote($match)
{
return htmlspecialchars($match[0], ENT_QUOTES);

View File

@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
* @see Smarty_Internal_CompileBase
*/
public $optional_attributes = array('assign');
/**
* Attribute definition: Overwrites base class.
*
@ -34,14 +35,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
/**
* Compiles code for generating output from any expression
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @throws SmartyException
* @return string compiled code
* @return string
* @throws \SmartyException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@ -57,7 +58,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
$output = $parameter['value'];
// tag modifier
if (!empty($parameter['modifierlist'])) {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'],
'value' => $output));
}
if (!$_attr['nofilter']) {
// default modifier
@ -74,7 +76,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
$compiler->default_modifier_list = $modifierlist;
}
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output));
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list,
'value' => $output));
}
// autoescape html
if ($compiler->template->smarty->escape_html) {
@ -82,7 +85,8 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
// loop over registered filters
if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) {
foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key =>
$function) {
if (!is_array($function)) {
$output = "{$function}({$output},\$_smarty_tpl)";
} elseif (is_object($function[0])) {
@ -104,13 +108,14 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
}
}
if (isset($compiler->template->variable_filters)) {
foreach ($compiler->template->variable_filters as $filter) {
if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) {
$output = $result;
} else {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output));
}
foreach ($compiler->variable_filters as $filter) {
if (count($filter) == 1 &&
($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false
) {
$output = $result;
} else {
$output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter),
'value' => $output));
}
}
}
@ -123,23 +128,23 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
}
/**
* @param object $compiler compiler object
* @param string $name name of variable filter
* @param string $output embedded output
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param string $name name of variable filter
* @param string $output embedded output
*
* @return string
*/
private function compile_output_filter($compiler, $name, $output)
private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{
$plugin_name = "smarty_variablefilter_{$name}";
$path = $compiler->smarty->loadPlugin($plugin_name, false);
if ($path) {
if ($compiler->template->caching) {
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
} else {
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
}
} else {
// not found

View File

@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
/**
* Compiles code for the execution of a block function
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block function
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block function
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
{
if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
// opening tag of block plugin
@ -69,11 +69,11 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
$function = $tag_info[0];
// compile code
if (!is_array($function)) {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} elseif (is_object($function[0])) {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
} else {
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
$output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
}
} else {
// must endblock be nocache?
@ -95,14 +95,22 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
$mod_pre = $mod_post = '';
} else {
$mod_pre = ' ob_start(); ';
$mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
$mod_post = 'echo ' .
$compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
'value' => 'ob_get_clean()')) . ';';
}
if (!is_array($function)) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post .
" } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
} elseif (is_object($function[0])) {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
} else {
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre . " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . "} array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
" echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
$mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
}
}

View File

@ -27,14 +27,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
/**
* Compiles code for the execution of a registered function
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter, $tag)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
{
// This tag does create output
$compiler->has_output = true;

View File

@ -19,44 +19,51 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
/**
* Compiles code for the special $smarty variables
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param $parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param $parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$compiled_ref = ' ';
$variable = trim($_index[0], "'");
if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) {
$variable = strtolower($compiler->getId($_index[0]));
if ($variable === false) {
$compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
}
if (!isset($compiler->smarty->security_policy) ||
$compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
) {
switch ($variable) {
case 'foreach':
$name = trim($_index[1], "'");
$foreachVar = "'__foreach_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}]) ? \$_smarty_tpl->tpl_vars[$foreachVar]->value[{$_index[2]}] : null)";
case 'section':
return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index);
case 'capture':
return "Smarty::\$_smarty_vars$parameter";
if (class_exists('Smarty_Internal_Compile_Capture')) {
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
}
return '';
case 'now':
return 'time()';
case 'cookies':
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
if (isset($compiler->smarty->security_policy) &&
!$compiler->smarty->security_policy->allow_super_globals
) {
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
$compiled_ref = '$_COOKIE';
break;
return '$_COOKIE';
case 'get':
case 'post':
case 'env':
case 'server':
case 'session':
case 'request':
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
if (isset($compiler->smarty->security_policy) &&
!$compiler->smarty->security_policy->allow_super_globals
) {
$compiler->trigger_template_error("(secure mode) super globals not permitted");
break;
}
@ -78,11 +85,13 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
return "'$_version'";
case 'const':
if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
if (isset($compiler->smarty->security_policy) &&
!$compiler->smarty->security_policy->allow_constants
) {
$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]})";
@ -90,9 +99,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
case 'config':
if (isset($_index[2])) {
return "(is_array(\$tmp = \$_smarty_tpl->getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)";
return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
} else {
return "\$_smarty_tpl->getConfigVariable($_index[1])";
return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])";
}
case 'ldelim':
$_ldelim = $compiler->smarty->left_delimiter;
@ -114,7 +123,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
$compiled_ref = $compiled_ref . "[$_ind]";
}
}
return $compiled_ref;
}
return $compiled_ref;
}
}

View File

@ -25,11 +25,11 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_CompileBase
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
$compiler->trigger_template_error('nocache option not allowed', null, true);
}
// this tag does not return compiled code
$compiler->has_code = true;

View File

@ -14,7 +14,7 @@
* @package Smarty
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection
{
/**
* Attribute definition: Overwrites base class.
@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $required_attributes = array('name', 'loop');
/**
* Attribute definition: Overwrites base class.
*
@ -30,6 +31,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
* @see Smarty_Internal_CompileBase
*/
public $shorttag_order = array('name', 'loop');
/**
* Attribute definition: Overwrites base class.
*
@ -38,103 +40,343 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_CompileBase
*/
public $optional_attributes = array('start', 'step', 'max', 'show');
/**
* counter
*
* @var int
*/
public $counter = 0;
/**
* Name of this tag
*
* @var string
*/
public $tagName = 'section';
/**
* Valid properties of $smarty.section.name.xxx variable
*
* @var array
*/
public static $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
'index_prev', 'index_next');
/**
* {section} tag has no item properties
*
* @var array
*/
public $itemProperties = null;
/**
* {section} tag has always name attribute
*
* @var bool
*/
public $isNamed = true;
/**
* Compiles code for the {section} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'section', array('section', $compiler->nocache));
$attributes = array('name' => $compiler->getId($_attr['name']));
unset($_attr['name']);
foreach ($attributes as $a => $v) {
if ($v === false) {
$compiler->trigger_template_error("'{$a}' attribute/variable has illegal value", null, true);
}
}
$local = "\$__section_{$attributes['name']}_" . $this->counter ++ . '_';
$sectionVar = "\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']";
$this->openTag($compiler, 'section', array('section', $compiler->nocache, $local, $sectionVar));
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$output = "<?php ";
$section_name = $_attr['name'];
$output .= "if (isset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name])) unset(\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]);\n";
$section_props = "\$_smarty_tpl->tpl_vars['smarty']->value['section'][$section_name]";
$initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__section_{$attributes['name']}'] : false",);
$initNamedProperty = array();
$initFor = array();
$incFor = array();
$cmpFor = array();
$propValue = array('index' => "{$sectionVar}->value['index']", 'show' => 'true', 'step' => 1,
'iteration' => "{$local}iteration",
);
$propType = array('index' => 2, 'iteration' => 2, 'show' => 0, 'step' => 0,);
// search for used tag attributes
$this->scanForProperties($attributes, $compiler);
if (!empty($this->matchResults['named'])) {
$namedAttr = $this->matchResults['named'];
}
$namedAttr['index'] = true;
$output = "<?php\n";
foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) {
case 'loop':
$output .= "{$section_props}['loop'] = is_array(\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop); unset(\$_loop);\n";
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$t = 0;
} else {
$v = "(is_array(@\$_loop=$attr_value) ? count(\$_loop) : max(0, (int) \$_loop))";
$t = 1;
}
if (isset($namedAttr['loop'])) {
$initNamedProperty['loop'] = "'loop' => {$v}";
if ($t == 1) {
$v = "{$sectionVar}->value['loop']";
}
} elseif ($t == 1) {
$initLocal['loop'] = $v;
$v = "{$local}loop";
}
break;
case 'show':
if (is_bool($attr_value)) {
$show_attr_value = $attr_value ? 'true' : 'false';
$v = $attr_value ? 'true' : 'false';
$t = 0;
} else {
$show_attr_value = "(bool) $attr_value";
$v = "(bool) $attr_value";
$t = 3;
}
$output .= "{$section_props}['show'] = $show_attr_value;\n";
break;
case 'name':
$output .= "{$section_props}['$attr_name'] = $attr_value;\n";
case 'step':
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$v = ($v == 0) ? 1 : $v;
$t = 0;
break;
}
$initLocal['step'] = "((int)@$attr_value) == 0 ? 1 : (int)@$attr_value";
$v = "{$local}step";
$t = 2;
break;
case 'max':
case 'start':
$output .= "{$section_props}['$attr_name'] = (int) $attr_value;\n";
if (is_numeric($attr_value)) {
$v = (int) $attr_value;
$t = 0;
break;
}
$v = "(int)@$attr_value";
$t = 3;
break;
}
if ($t == 3 && $compiler->getId($attr_value)) {
$t = 1;
}
$propValue[$attr_name] = $v;
$propType[$attr_name] = $t;
}
case 'step':
$output .= "{$section_props}['$attr_name'] = ((int) $attr_value) == 0 ? 1 : (int) $attr_value;\n";
break;
if (isset($namedAttr['step'])) {
$initNamedProperty['step'] = $propValue['step'];
}
if (isset($namedAttr['iteration'])) {
$propValue['iteration'] = "{$sectionVar}->value['iteration']";
}
$incFor['iteration'] = "{$propValue['iteration']}++";
$initFor['iteration'] = "{$propValue['iteration']} = 1";
if ($propType['step'] == 0) {
if ($propValue['step'] == 1) {
$incFor['index'] = "{$sectionVar}->value['index']++";
} elseif ($propValue['step'] > 1) {
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
} else {
$incFor['index'] = "{$sectionVar}->value['index'] -= " . - $propValue['step'];
}
} else {
$incFor['index'] = "{$sectionVar}->value['index'] += {$propValue['step']}";
}
if (!isset($propValue['max'])) {
$propValue['max'] = $propValue['loop'];
$propType['max'] = $propType['loop'];
} elseif ($propType['max'] != 0) {
$propValue['max'] = "{$propValue['max']} < 0 ? {$propValue['loop']} : {$propValue['max']}";
$propType['max'] = 1;
} else {
if ($propValue['max'] < 0) {
$propValue['max'] = $propValue['loop'];
$propType['max'] = $propType['loop'];
}
}
if (!isset($_attr['show'])) {
$output .= "{$section_props}['show'] = true;\n";
}
if (!isset($_attr['loop'])) {
$output .= "{$section_props}['loop'] = 1;\n";
}
if (!isset($_attr['max'])) {
$output .= "{$section_props}['max'] = {$section_props}['loop'];\n";
if (!isset($propValue['start'])) {
$start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'],
5 => ' - 1');
if ($propType['loop'] == 0) {
$start_code[5] = '';
$start_code[4] = $propValue['loop'] - 1;
}
if ($propType['step'] == 0) {
if ($propValue['step'] > 0) {
$start_code = array(1 => '0');
$propType['start'] = 0;
} else {
$start_code[1] = $start_code[2] = $start_code[3] = '';
$propType['start'] = $propType['loop'];
}
} else {
$propType['start'] = 1;
}
$propValue['start'] = join('', $start_code);
} else {
$output .= "if ({$section_props}['max'] < 0)\n" . " {$section_props}['max'] = {$section_props}['loop'];\n";
$start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ",
4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ',
8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ',
12 => 'min(', 13 => $propValue['start'], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ',
18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1",
19 => ')');
if ($propType['step'] == 0) {
$start_code[3] = $start_code[5] = $start_code[15] = $start_code[17] = '';
if ($propValue['step'] > 0) {
$start_code[6] = $start_code[18] = '';
} else {
$start_code[4] = $start_code[16] = '';
}
}
if ($propType['start'] == 0) {
if ($propType['loop'] == 0) {
$start_code[8] = $propValue['start'] + $propValue['loop'];
}
$propType['start'] = $propType['step'] + $propType['loop'];
$start_code[1] = '';
if ($propValue['start'] < 0) {
for ($i = 11; $i <= 19; $i ++) {
$start_code[$i] = '';
}
if ($propType['start'] == 0) {
$start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] +
$propValue['loop']));
}
} else {
for ($i = 1; $i <= 11; $i ++) {
$start_code[$i] = '';
}
if ($propType['start'] == 0) {
$start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] -
1, $propValue['start']));
}
}
}
$propValue['start'] = join('', $start_code);
}
if ($propType['start'] != 0) {
$initLocal['start'] = $propValue['start'];
$propValue['start'] = "{$local}start";
}
if (!isset($_attr['step'])) {
$output .= "{$section_props}['step'] = 1;\n";
}
$initFor['index'] = "{$sectionVar}->value['index'] = {$propValue['start']}";
if (!isset($_attr['start'])) {
$output .= "{$section_props}['start'] = {$section_props}['step'] > 0 ? 0 : {$section_props}['loop']-1;\n";
} else {
$output .= "if ({$section_props}['start'] < 0)\n" . " {$section_props}['start'] = max({$section_props}['step'] > 0 ? 0 : -1, {$section_props}['loop'] + {$section_props}['start']);\n" . "else\n" . " {$section_props}['start'] = min({$section_props}['start'], {$section_props}['step'] > 0 ? {$section_props}['loop'] : {$section_props}['loop']-1);\n";
}
$output .= "if ({$section_props}['show']) {\n";
if (!isset($_attr['start']) && !isset($_attr['step']) && !isset($_attr['max'])) {
$output .= " {$section_props}['total'] = {$section_props}['loop'];\n";
$propValue['total'] = $propValue['loop'];
$propType['total'] = $propType['loop'];
} else {
$output .= " {$section_props}['total'] = min(ceil(({$section_props}['step'] > 0 ? {$section_props}['loop'] - {$section_props}['start'] : {$section_props}['start']+1)/abs({$section_props}['step'])), {$section_props}['max']);\n";
$propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max'];
if ($propType['total'] == 0) {
$propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] -
$propValue['start'] : (int) $propValue['start'] + 1) /
abs($propValue['step'])), $propValue['max']);
} else {
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ',
9 => $propValue['start'], 10 => '+ 1', 11 => ')', 12 => '/ ', 13 => 'abs(',
14 => $propValue['step'], 15 => ')', 16 => ')', 17 => ", {$propValue['max']})",);
if (!isset($propValue['max'])) {
$total_code[1] = $total_code[17] = '';
}
if ($propType['loop'] + $propType['start'] == 0) {
$total_code[5] = $propValue['loop'] - $propValue['start'];
$total_code[6] = $total_code[7] = '';
}
if ($propType['start'] == 0) {
$total_code[9] = (int) $propValue['start'] + 1;
$total_code[10] = '';
}
if ($propType['step'] == 0) {
$total_code[13] = $total_code[15] = '';
if ($propValue['step'] == 1 || $propValue['step'] == - 1) {
$total_code[2] = $total_code[12] = $total_code[14] = $total_code[16] = '';
} elseif ($propValue['step'] < 0) {
$total_code[14] = - $propValue['step'];
}
$total_code[4] = '';
if ($propValue['step'] > 0) {
$total_code[8] = $total_code[9] = $total_code[10] = '';
} else {
$total_code[5] = $total_code[6] = $total_code[7] = $total_code[8] = '';
}
}
$propValue['total'] = join('', $total_code);
}
}
$output .= " if ({$section_props}['total'] == 0)\n" . " {$section_props}['show'] = false;\n" . "} else\n" . " {$section_props}['total'] = 0;\n";
$output .= "if ({$section_props}['show']):\n";
$output .= "
for ({$section_props}['index'] = {$section_props}['start'], {$section_props}['iteration'] = 1;
{$section_props}['iteration'] <= {$section_props}['total'];
{$section_props}['index'] += {$section_props}['step'], {$section_props}['iteration']++):\n";
$output .= "{$section_props}['rownum'] = {$section_props}['iteration'];\n";
$output .= "{$section_props}['index_prev'] = {$section_props}['index'] - {$section_props}['step'];\n";
$output .= "{$section_props}['index_next'] = {$section_props}['index'] + {$section_props}['step'];\n";
$output .= "{$section_props}['first'] = ({$section_props}['iteration'] == 1);\n";
$output .= "{$section_props}['last'] = ({$section_props}['iteration'] == {$section_props}['total']);\n";
if (isset($namedAttr['total'])) {
$initNamedProperty['total'] = "'total' => {$propValue['total']}";
if ($propType['total'] > 0) {
$propValue['total'] = "{$sectionVar}->value['total']";
}
} elseif ($propType['total'] > 0) {
$initLocal['total'] = $propValue['total'];
$propValue['total'] = "{$local}total";
}
$cmpFor['iteration'] = "{$propValue['iteration']} <= {$propValue['total']}";
foreach ($initLocal as $key => $code) {
$output .= "{$local}{$key} = {$code};\n";
}
$_vars = 'array(' . join(', ', $initNamedProperty) . ')';
$output .= "{$sectionVar} = new Smarty_Variable({$_vars});\n";
$cond_code = "{$propValue['total']} != 0";
if ($propType['total'] == 0) {
if ($propValue['total'] == 0) {
$cond_code = 'false';
} else {
$cond_code = 'true';
}
}
if ($propType['show'] > 0) {
$output .= "{$local}show = {$propValue['show']} ? {$cond_code} : false;\n";
$output .= "if ({$local}show) {\n";
} elseif ($propValue['show'] == 'true') {
$output .= "if ({$cond_code}) {\n";
} else {
$output .= "if (false) {\n";
}
$jinit = join(', ', $initFor);
$jcmp = join(', ', $cmpFor);
$jinc = join(', ', $incFor);
$output .= "for ({$jinit}; {$jcmp}; {$jinc}){\n";
if (isset($namedAttr['rownum'])) {
$output .= "{$sectionVar}->value['rownum'] = {$propValue['iteration']};\n";
}
if (isset($namedAttr['index_prev'])) {
$output .= "{$sectionVar}->value['index_prev'] = {$propValue['index']} - {$propValue['step']};\n";
}
if (isset($namedAttr['index_next'])) {
$output .= "{$sectionVar}->value['index_next'] = {$propValue['index']} + {$propValue['step']};\n";
}
if (isset($namedAttr['first'])) {
$output .= "{$sectionVar}->value['first'] = ({$propValue['iteration']} == 1);\n";
}
if (isset($namedAttr['last'])) {
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
}
$output .= "?>";
return $output;
@ -152,20 +394,20 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
/**
* Compiles code for the {sectionelse} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
list($openTag, $nocache) = $this->closeTag($compiler, array('section'));
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache));
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
return "<?php endfor; else: ?>";
return "<?php }} else {\n ?>";
}
}
@ -180,27 +422,33 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/section} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('section', 'sectionelse'));
list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section',
'sectionelse'));
$output = "<?php\n";
if ($openTag == 'sectionelse') {
return "<?php endif; ?>";
$output .= "}\n";
} else {
return "<?php endfor; endif; ?>";
$output .= "}\n}\n";
}
$output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n";
$output .= "?>";
return $output;
}
}

View File

@ -25,10 +25,10 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase
*
* @return string compiled code
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->variable_filter_stack[] = $compiler->template->variable_filters;
$compiler->template->variable_filters = $parameter['modifier_list'];
$compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code
$compiler->has_code = false;
@ -53,14 +53,14 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$_attr = $this->getAttributes($compiler, $args);
// reset variable filter to previous state
if (count($compiler->variable_filter_stack)) {
$compiler->template->variable_filters = array_pop($compiler->variable_filter_stack);
$compiler->variable_filters = array_pop($compiler->variable_filter_stack);
} else {
$compiler->template->variable_filters = array();
$compiler->variable_filters = array();
}
// this tag does not return compiled code
$compiler->has_code = false;

View File

@ -19,24 +19,27 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
/**
* Compiles code for the {while} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $parameter array with compilation parameter
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compile($args, $compiler, $parameter)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'while', $compiler->nocache);
if (!array_key_exists("if condition", $parameter)) {
$compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno);
$compiler->trigger_template_error("missing while condition", null, true);
}
// maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$_output = "<?php\n";
if (is_array($parameter['if condition'])) {
if ($compiler->nocache) {
$_nocache = ',true';
@ -55,17 +58,24 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$_nocache = '';
}
if (is_array($parameter['if condition']['var'])) {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
"]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
"$_nocache);\n";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
$parameter['if condition']['value'] . ") {?>";
} else {
$_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
"] = new Smarty_Variable(null{$_nocache});";
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
$parameter['if condition']['value'] . ") {?>";
}
return $_output;
} else {
return "<?php while ({$parameter['if condition']}) {?>";
}
$_output .= "while ({$parameter['if condition']}) {?>";
}
return $_output;
}
}
@ -80,19 +90,19 @@ class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
/**
* Compiles code for the {/while} tag
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, $compiler)
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
}
$compiler->nocache = $this->closeTag($compiler, array('while'));
return "<?php }?>";
return "<?php }?>\n";
}
}

View File

@ -21,6 +21,7 @@ abstract class Smarty_Internal_CompileBase
* @var array
*/
public $required_attributes = array();
/**
* Array of names of optional attribute required by tag
* use array('_any') if there is no restriction of attributes names
@ -28,12 +29,14 @@ abstract class Smarty_Internal_CompileBase
* @var array
*/
public $optional_attributes = array();
/**
* Shorttag attribute order defined by its names
*
* @var array
*/
public $shorttag_order = array();
/**
* Array of names of valid option flags
*
@ -68,7 +71,7 @@ abstract class Smarty_Internal_CompileBase
$_indexed_attr[$this->shorttag_order[$key]] = $mixed;
} else {
// too many shorthands
$compiler->trigger_template_error('too many shorthand attributes', $compiler->lex->taglineno);
$compiler->trigger_template_error('too many shorthand attributes', null, true);
}
// named attribute
} else {
@ -90,7 +93,7 @@ abstract class Smarty_Internal_CompileBase
$_indexed_attr[$kv['key']] = false;
}
} else {
$compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $compiler->lex->taglineno);
$compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", null, true);
}
// must be named attribute
} else {
@ -102,7 +105,7 @@ abstract class Smarty_Internal_CompileBase
// check if all required attributes present
foreach ($this->required_attributes as $attr) {
if (!array_key_exists($attr, $_indexed_attr)) {
$compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno);
$compiler->trigger_template_error("missing \"" . $attr . "\" attribute", null, true);
}
}
// check for not allowed attributes
@ -110,7 +113,7 @@ abstract class Smarty_Internal_CompileBase
$tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
foreach ($_indexed_attr as $key => $dummy) {
if (!in_array($key, $tmp_array) && $key !== 0) {
$compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $compiler->lex->taglineno);
$compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", null, true);
}
}
}
@ -162,12 +165,13 @@ abstract class Smarty_Internal_CompileBase
}
}
// wrong nesting of tags
$compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag");
$compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag .
"{$compiler->smarty->right_delimiter} tag");
return;
}
// wrong nesting of tags
$compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno);
$compiler->trigger_template_error("unexpected closing tag", null, true);
return;
}

View File

@ -30,6 +30,7 @@ class Smarty_Internal_Config_File_Compiler
* @var string
*/
public $parser_class;
/**
* Lexer object
*
@ -100,16 +101,17 @@ class Smarty_Internal_Config_File_Compiler
public function compileTemplate(Smarty_Internal_Template $template)
{
$this->template = $template;
$this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->name, $this->template->source->timestamp, $this->template->source->type);
// on empty config just return
if ($template->source->content == '') {
return true;
}
$this->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath,
$this->template->source->getTimeStamp(),
$this->template->source->type);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
$this->smarty->_debug->start_compile($this->template);
}
// init the lexer/parser to compile the config file
$lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->content) . "\n", $this);
/* @var Smarty_Internal_ConfigFileLexer $lex */
$lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $template->source->getContent()) .
"\n", $this);
/* @var Smarty_Internal_ConfigFileParser $parser */
$parser = new $this->parser_class($lex, $this);
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
@ -136,14 +138,16 @@ class Smarty_Internal_Config_File_Compiler
mb_internal_encoding($mbEncoding);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this->template);
$this->smarty->_debug->end_compile($this->template);
}
// template header code
$template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header = "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " .
strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
$code = '<?php Smarty_Internal_Extension_Config::loadConfigVars($_smarty_tpl, ' . var_export($this->config_data, true) . '); ?>';
return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code);
$code = '<?php $_smarty_tpl->smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
var_export($this->config_data, true) . '); ?>';
return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code);
}
/**

View File

@ -13,34 +13,70 @@
*
* @package Smarty
* @subpackage Template
*
* @method mixed getConfigVars(string $varName = null, bool $searchParents = true)
* @method mixed getStreamVariable(string $variable)
* @method Smarty_Internal_Data clearAssign(mixed $tpl_var)
* @method Smarty_Internal_Data clearAllAssign()
* @method Smarty_Internal_Data clearConfig(string $varName = null)
* @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local')
* @property int $scope
*/
class Smarty_Internal_Data
{
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 4;
/**
* name of class used for templates
*
* @var string
*/
public $template_class = 'Smarty_Internal_Template';
/**
* template variables
*
* @var array
* @var Smarty_Variable[]
*/
public $tpl_vars = array();
/**
* parent template (if any)
*
* @var Smarty_Internal_Template
* @var Smarty|Smarty_Internal_Template|Smarty_Internal_Data
*/
public $parent = null;
/**
* configuration settings
*
* @var array
* @var string[]
*/
public $config_vars = array();
/**
* extension handler
*
* @var Smarty_Internal_Extension_Handler
*/
public $ext = null;
/**
* Smarty_Internal_Data constructor.
*
* Install extension handler
*/
public function __construct()
{
$this->ext = new Smarty_Internal_Extension_Handler();
$this->ext->objType = $this->_objType;
}
/**
* assigns a Smarty variable
*
@ -48,7 +84,8 @@ class Smarty_Internal_Data
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for
* chaining
*/
public function assign($tpl_var, $value = null, $nocache = false)
{
@ -56,119 +93,53 @@ class Smarty_Internal_Data
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
$this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache);
if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $_key);
}
}
}
} else {
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache);
if ($this->_objType == 2 && $this->scope) {
$this->ext->_updateScope->updateScope($this, $tpl_var);
}
}
}
return $this;
}
/**
* assigns a global Smarty variable
*
* @param string $varname the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function assignGlobal($varname, $value = null, $nocache = false)
{
if ($varname != '') {
Smarty::$global_tpl_vars[$varname] = new Smarty_Variable($value, $nocache);
$ptr = $this;
while ($ptr instanceof Smarty_Internal_Template) {
$ptr->tpl_vars[$varname] = clone Smarty::$global_tpl_vars[$varname];
$ptr = $ptr->parent;
}
}
return $this;
}
/**
* assigns values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param $value
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function assignByRef($tpl_var, &$value, $nocache = false)
{
if ($tpl_var != '') {
$this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
$this->tpl_vars[$tpl_var]->value = &$value;
}
return $this;
}
/**
* appends values to template variables
*
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param boolean $merge flag if array elements shall be merged
* @param boolean $nocache if true any output of this variable will be not cached
* @api Smarty::append()
* @link http://www.smarty.net/docs/en/api.append.tpl
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
* @param array|string $tpl_var the template variable name(s)
* @param mixed $value the value to append
* @param bool $merge flag if array elements shall be merged
* @param bool $nocache if true any output of this variable will
* be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function append($tpl_var, $value = null, $merge = false, $nocache = false)
{
if (is_array($tpl_var)) {
// $tpl_var is an array, ignore $value
foreach ($tpl_var as $_key => $_val) {
if ($_key != '') {
if (!isset($this->tpl_vars[$_key])) {
$tpl_var_inst = $this->getVariable($_key, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
$this->tpl_vars[$_key] = new Smarty_Variable(null, $nocache);
} else {
$this->tpl_vars[$_key] = clone $tpl_var_inst;
}
}
if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$_key]->value, 'array');
}
if ($merge && is_array($_val)) {
foreach ($_val as $_mkey => $_mval) {
$this->tpl_vars[$_key]->value[$_mkey] = $_mval;
}
} else {
$this->tpl_vars[$_key]->value[] = $_val;
}
}
}
} else {
if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) {
$tpl_var_inst = $this->getVariable($tpl_var, null, true, false);
if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
$this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
} else {
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
}
}
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
if ($merge && is_array($value)) {
foreach ($value as $_mkey => $_mval) {
$this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
}
} else {
$this->tpl_vars[$tpl_var]->value[] = $value;
}
}
}
return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache);
}
return $this;
/**
* assigns a global Smarty variable
*
* @param string $varName the global variable name
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function assignGlobal($varName, $value = null, $nocache = false)
{
return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache);
}
/**
@ -178,227 +149,77 @@ class Smarty_Internal_Data
* @param mixed &$value the referenced value to append
* @param boolean $merge flag if array elements shall be merged
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function appendByRef($tpl_var, &$value, $merge = false)
{
if ($tpl_var != '' && isset($value)) {
if (!isset($this->tpl_vars[$tpl_var])) {
$this->tpl_vars[$tpl_var] = new Smarty_Variable();
}
if (!is_array($this->tpl_vars[$tpl_var]->value)) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
if ($merge && is_array($value)) {
foreach ($value as $_key => $_val) {
$this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
}
} else {
$this->tpl_vars[$tpl_var]->value[] = &$value;
}
}
return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge);
}
return $this;
/**
* assigns values to template variables by reference
*
* @param string $tpl_var the template variable name
* @param $value
* @param boolean $nocache if true any output of this variable will be not cached
*
* @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
*/
public function assignByRef($tpl_var, &$value, $nocache = false)
{
return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache);
}
/**
* Returns a single or all template variables
*
* @param string $varname variable name or null
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents include parent templates?
* @api Smarty::getTemplateVars()
* @link http://www.smarty.net/docs/en/api.get.template.vars.tpl
*
* @return string variable value or or array of variables
* @param string $varName variable name or null
* @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object
* @param bool $searchParents include parent templates?
*
* @return mixed variable value or or array of variables
*/
public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true)
{
if (isset($varname)) {
$_var = $this->getVariable($varname, $_ptr, $search_parents, false);
if (is_object($_var)) {
return $_var->value;
} else {
return null;
return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents);
}
/**
* Follow the parent chain an merge template and config variables
*
* @param \Smarty_Internal_Data|null $data
*/
public function _mergeVars(Smarty_Internal_Data $data = null)
{
if (isset($data)) {
if (!empty($this->tpl_vars)) {
$data->tpl_vars = array_merge($this->tpl_vars, $data->tpl_vars);
}
if (!empty($this->config_vars)) {
$data->config_vars = array_merge($this->config_vars, $data->config_vars);
}
} else {
$_result = array();
if ($_ptr === null) {
$_ptr = $this;
}
while ($_ptr !== null) {
foreach ($_ptr->tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if ($search_parents && isset(Smarty::$global_tpl_vars)) {
foreach (Smarty::$global_tpl_vars AS $key => $var) {
if (!array_key_exists($key, $_result)) {
$_result[$key] = $var->value;
}
}
}
return $_result;
$data = $this;
}
if (isset($this->parent)) {
$this->parent->_mergeVars($data);
}
}
/**
* clear the given assigned template variable.
* Handle unknown class methods
*
* @param string|array $tpl_var the template variable(s) to clear
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearAssign($tpl_var)
{
if (is_array($tpl_var)) {
foreach ($tpl_var as $curr_var) {
unset($this->tpl_vars[$curr_var]);
}
} else {
unset($this->tpl_vars[$tpl_var]);
}
return $this;
}
/**
* clear all the assigned template variables.
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearAllAssign()
{
$this->tpl_vars = array();
return $this;
}
/**
* load a config file, optionally load just selected sections
*
* @param string $config_file filename
* @param mixed $sections array of section names, single section or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function configLoad($config_file, $sections = null)
{
// load Config class
Smarty_Internal_Extension_Config::configLoad($this, $config_file, $sections);
return $this;
}
/**
* gets the object of a Smarty variable
*
* @param string $variable the name of the Smarty variable
* @param object $_ptr optional pointer to data object
* @param boolean $search_parents search also in parent data
* @param bool $error_enable
*
* @return object the object of the variable
*/
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
{
if ($_ptr === null) {
$_ptr = $this;
}
while ($_ptr !== null) {
if (isset($_ptr->tpl_vars[$variable])) {
// found it, return it
return $_ptr->tpl_vars[$variable];
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset(Smarty::$global_tpl_vars[$variable])) {
// found it, return it
return Smarty::$global_tpl_vars[$variable];
}
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return new Smarty_Undefined_Variable;
}
/**
* gets a config variable
*
* @param string $variable the name of the config variable
* @param bool $error_enable
*
* @return mixed the value of the config variable
*/
public function getConfigVariable($variable, $error_enable = true)
{
return Smarty_Internal_Extension_Config::getConfigVariable($this, $variable, $error_enable = true);
}
/**
* Returns a single or all config variables
*
* @param string $varname variable name or null
* @param bool $search_parents
*
* @return string variable value or or array of variables
*/
public function getConfigVars($varname = null, $search_parents = true)
{
return Smarty_Internal_Extension_Config::getConfigVars($this, $varname, $search_parents);
}
/**
* Deassigns a single or all config variables
*
* @param string $varname variable name or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
public function clearConfig($varname = null)
{
return Smarty_Internal_Extension_Config::clearConfig($this, $varname);
}
/**
* gets a stream variable
*
* @param string $variable the stream of the variable
* @param string $name unknown method-name
* @param array $args argument array
*
* @return mixed
* @throws SmartyException
* @return mixed the value of the stream variable
*/
public function getStreamVariable($variable)
public function __call($name, $args)
{
$_result = '';
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
return $this->ext->_callExternalMethod($this, $name, $args);
}
}

View File

@ -21,44 +21,44 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @var array
*/
public static $template_data = array();
public $template_data = array();
/**
* List of uid's which shall be ignored
*
* @var array
*/
public static $ignore_uid = array();
public $ignore_uid = array();
/**
* Index of display() and fetch() calls
*
* @var int
*/
public static $index = 0;
public $index = 0;
/**
* Counter for window offset
*
* @var int
*/
public static $offset = 0;
public $offset = 0;
/**
* Start logging template
*
* @param \Smarty_Internal_Template $template template
* @param null $mode true: display false: fetch null: subtemolate
* @param null $mode true: display false: fetch null: subtemplate
*/
public static function start_template(Smarty_Internal_Template $template, $mode = null)
public function start_template(Smarty_Internal_Template $template, $mode = null)
{
if (isset($mode)) {
self::$index ++;
self::$offset ++;
self::$template_data[self::$index] = null;
$this->index ++;
$this->offset ++;
$this->template_data[$this->index] = null;
}
$key = self::get_key($template);
self::$template_data[self::$index][$key]['start_template_time'] = microtime(true);
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_template_time'] = microtime(true);
}
/**
@ -66,11 +66,12 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template cached template
*/
public static function end_template(Smarty_Internal_Template $template)
public function end_template(Smarty_Internal_Template $template)
{
$key = self::get_key($template);
self::$template_data[self::$index][$key]['total_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_template_time'];
self::$template_data[self::$index][$key]['properties'] = $template->properties;
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['total_time'] +=
microtime(true) - $this->template_data[$this->index][$key]['start_template_time'];
//$this->template_data[$this->index][$key]['properties'] = $template->properties;
}
/**
@ -78,28 +79,29 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template
*/
public static function start_compile(Smarty_Internal_Template $template)
public function start_compile(Smarty_Internal_Template $template)
{
static $_is_stringy = array('string' => true, 'eval' => true);
if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid;
if (!isset(self::$template_data[self::$index][$key])) {
if (!isset($this->template_data[$this->index][$key])) {
if (isset($_is_stringy[$template->source->type])) {
self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
$this->template_data[$this->index][$key]['name'] =
'\'' . substr($template->source->name, 0, 25) . '...\'';
} else {
self::$template_data[self::$index][$key]['name'] = $template->source->filepath;
$this->template_data[$this->index][$key]['name'] = $template->source->filepath;
}
self::$template_data[self::$index][$key]['compile_time'] = 0;
self::$template_data[self::$index][$key]['render_time'] = 0;
self::$template_data[self::$index][$key]['cache_time'] = 0;
$this->template_data[$this->index][$key]['compile_time'] = 0;
$this->template_data[$this->index][$key]['render_time'] = 0;
$this->template_data[$this->index][$key]['cache_time'] = 0;
}
} else {
if (isset(self::$ignore_uid[$template->source->uid])) {
if (isset($this->ignore_uid[$template->source->uid])) {
return;
}
$key = self::get_key($template);
$key = $this->get_key($template);
}
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
}
/**
@ -107,18 +109,19 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template
*/
public static function end_compile(Smarty_Internal_Template $template)
public function end_compile(Smarty_Internal_Template $template)
{
if (!empty($template->compiler->trace_uid)) {
$key = $template->compiler->trace_uid;
} else {
if (isset(self::$ignore_uid[$template->source->uid])) {
if (isset($this->ignore_uid[$template->source->uid])) {
return;
}
$key = self::get_key($template);
$key = $this->get_key($template);
}
self::$template_data[self::$index][$key]['compile_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
$this->template_data[$this->index][$key]['compile_time'] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time'];
}
/**
@ -126,10 +129,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template
*/
public static function start_render(Smarty_Internal_Template $template)
public function start_render(Smarty_Internal_Template $template)
{
$key = self::get_key($template);
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
}
/**
@ -137,10 +140,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template
*/
public static function end_render(Smarty_Internal_Template $template)
public function end_render(Smarty_Internal_Template $template)
{
$key = self::get_key($template);
self::$template_data[self::$index][$key]['render_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['render_time'] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time'];
}
/**
@ -148,10 +152,10 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template cached template
*/
public static function start_cache(Smarty_Internal_Template $template)
public function start_cache(Smarty_Internal_Template $template)
{
$key = self::get_key($template);
self::$template_data[self::$index][$key]['start_time'] = microtime(true);
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['start_time'] = microtime(true);
}
/**
@ -159,10 +163,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template cached template
*/
public static function end_cache(Smarty_Internal_Template $template)
public function end_cache(Smarty_Internal_Template $template)
{
$key = self::get_key($template);
self::$template_data[self::$index][$key]['cache_time'] += microtime(true) - self::$template_data[self::$index][$key]['start_time'];
$key = $this->get_key($template);
$this->template_data[$this->index][$key]['cache_time'] +=
microtime(true) - $this->template_data[$this->index][$key]['start_time'];
}
/**
@ -170,7 +175,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template cached template
*/
public static function register_template(Smarty_Internal_Template $template)
public function register_template(Smarty_Internal_Template $template)
{
}
@ -189,14 +194,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
* @param Smarty_Internal_Template|Smarty $obj object to debug
* @param bool $full
*/
public static function display_debug($obj, $full = false)
public function display_debug($obj, $full = false)
{
if (!$full) {
self::$offset ++;
$savedIndex = self::$index;
self::$index = 9999;
$this->offset ++;
$savedIndex = $this->index;
$this->index = 9999;
}
if ($obj instanceof Smarty) {
if ($obj->_objType == 1) {
$smarty = $obj;
} else {
$smarty = $obj->smarty;
@ -227,7 +232,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debObj->compile_id = null;
$debObj->cache_id = null;
// prepare information of assigned variables
$ptr = self::get_debug_vars($obj);
$ptr = $this->get_debug_vars($obj);
$_assigned_vars = $ptr->tpl_vars;
ksort($_assigned_vars);
$_config_vars = $ptr->config_vars;
@ -235,11 +240,11 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$debugging = $smarty->debugging;
$_template = new Smarty_Internal_Template($debObj->debug_tpl, $debObj);
if ($obj instanceof Smarty_Internal_Template) {
if ($obj->_objType == 2) {
$_template->assign('template_name', $obj->source->type . ':' . $obj->source->name);
}
if ($obj instanceof Smarty || $full) {
$_template->assign('template_data', self::$template_data[self::$index]);
if ($obj->_objType == 1 || $full) {
$_template->assign('template_data', $this->template_data[$this->index]);
} else {
$_template->assign('template_data', null);
}
@ -247,13 +252,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$_template->assign('config_vars', $_config_vars);
$_template->assign('execution_time', microtime(true) - $smarty->start_time);
$_template->assign('display_mode', $debugging == 2 || !$full);
$_template->assign('offset', self::$offset * 50);
$_template->assign('offset', $this->offset * 50);
echo $_template->fetch();
if (isset($full)) {
self::$index --;
$this->index --;
}
if (!$full) {
self::$index = $savedIndex;
$this->index = $savedIndex;
}
}
@ -264,14 +269,14 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @return StdClass
*/
public static function get_debug_vars($obj)
public function get_debug_vars($obj)
{
$config_vars = array();
foreach ($obj->config_vars as $key => $var) {
$config_vars[$key]['value'] = $var;
if ($obj instanceof Smarty_Internal_Template) {
if ($obj->_objType == 2) {
$config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj instanceof Smarty_Data) {
} elseif ($obj->_objType == 4) {
$tpl_vars[$key]['scope'] = $obj->dataObjectName;
} else {
$config_vars[$key]['scope'] = 'Smarty object';
@ -294,9 +299,9 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
}
}
}
if ($obj instanceof Smarty_Internal_Template) {
if ($obj->_objType == 2) {
$tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
} elseif ($obj instanceof Smarty_Data) {
} elseif ($obj->_objType == 4) {
$tpl_vars[$key]['scope'] = $obj->dataObjectName;
} else {
$tpl_vars[$key]['scope'] = 'Smarty object';
@ -304,7 +309,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
}
if (isset($obj->parent)) {
$parent = self::get_debug_vars($obj->parent);
$parent = $this->get_debug_vars($obj->parent);
foreach ($parent->tpl_vars as $name => $pvar) {
if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) {
$tpl_vars[$name]['scope'] = $pvar['scope'];
@ -351,7 +356,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @return string key into $template_data
*/
private static function get_key(Smarty_Internal_Template $template)
private function get_key(Smarty_Internal_Template $template)
{
static $_is_stringy = array('string' => true, 'eval' => true);
// calculate Uid if not already done
@ -359,18 +364,19 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
$template->source->filepath;
}
$key = $template->source->uid;
if (isset(self::$template_data[self::$index][$key])) {
if (isset($this->template_data[$this->index][$key])) {
return $key;
} else {
if (isset($_is_stringy[$template->source->type])) {
self::$template_data[self::$index][$key]['name'] = '\'' . substr($template->source->name, 0, 25) . '...\'';
$this->template_data[$this->index][$key]['name'] =
'\'' . substr($template->source->name, 0, 25) . '...\'';
} else {
self::$template_data[self::$index][$key]['name'] = $template->source->filepath;
$this->template_data[$this->index][$key]['name'] = $template->source->filepath;
}
self::$template_data[self::$index][$key]['compile_time'] = 0;
self::$template_data[self::$index][$key]['render_time'] = 0;
self::$template_data[self::$index][$key]['cache_time'] = 0;
self::$template_data[self::$index][$key]['total_time'] = 0;
$this->template_data[$this->index][$key]['compile_time'] = 0;
$this->template_data[$this->index][$key]['render_time'] = 0;
$this->template_data[$this->index][$key]['cache_time'] = 0;
$this->template_data[$this->index][$key]['total_time'] = 0;
return $key;
}
@ -381,13 +387,13 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param \Smarty_Internal_Template $template
*/
public static function ignore(Smarty_Internal_Template $template)
public function ignore(Smarty_Internal_Template $template)
{
// calculate Uid if not already done
if ($template->source->uid == '') {
$template->source->filepath;
}
self::$ignore_uid[$template->source->uid] = true;
$this->ignore_uid[$template->source->uid] = true;
}
/**
@ -395,7 +401,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_Data
*
* @param Smarty_Internal_Template $_template
*/
public static function debugUrl(Smarty_Internal_Template $_template)
public function debugUrl(Smarty_Internal_Template $_template)
{
if (isset($_SERVER['QUERY_STRING'])) {
$_query_string = $_SERVER['QUERY_STRING'];

View File

@ -1,127 +0,0 @@
<?php
/**
* Smarty Internal Extension
* This file contains the Smarty template extension to create a code frame
*
* @package Smarty
* @subpackage Template
* @author Uwe Tews
*/
/**
* Class Smarty_Internal_Extension_CodeFrame
* Create code frame for compiled and cached templates
*/
class Smarty_Internal_Extension_CodeFrame
{
/**
* Create code frame for compiled and cached templates
*
* @param Smarty_Internal_Template $_template
* @param string $content optional template content
* @param bool $cache flag for cache file
*
* @return string
*/
public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false)
{
// build property code
$_template->properties['has_nocache_code'] = $_template->has_nocache_code || !empty($_template->required_plugins['nocache']);
$_template->properties['version'] = Smarty::SMARTY_VERSION;
if (!isset($_template->properties['unifunc'])) {
$_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
}
$properties = $_template->properties;
if (!$cache) {
unset($properties['tpl_function']);
if (!empty($_template->compiler->templateProperties)) {
$properties['tpl_function'] = $_template->compiler->templateProperties['tpl_function'];
}
}
$output = "<?php\n";
$output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
if ($_template->smarty->direct_access_security) {
$output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
}
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ");\n";
$output .= "/*/%%SmartyHeaderCode%%*/\n";
$output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
$output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
// include code for plugins
if (!$cache) {
if (!empty($_template->required_plugins['compiled'])) {
foreach ($_template->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 (!empty($_template->required_plugins['nocache'])) {
$_template->has_nocache_code = true;
$output .= "echo '/*%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
foreach ($_template->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->properties['nocache_hash']}%%*/';\n";
}
}
$output .= "?>\n";
$output = self::appendCode($output, $content);
return self::appendCode($output, "<?php }\n}\n?>");
}
/**
* Create code frame of compiled template function
*
* @param \Smarty_Internal_Template $_template
* @param string $content
*
* @return string
*/
public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '')
{
if (!isset($_template->properties['unifunc'])) {
$_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
}
$output = "<?php\n";
$output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
$output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
$output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
$output .= "?>\n" . $content;
$output .= "<?php\n";
$output .= "/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/\n";
$output .= "}\n}\n?>";
return $output;
}
/**
* Append code segments and remove unneeded ?> <?php transitions
*
* @param string $left
* @param string $right
*
* @return string
*/
public static function appendCode($left, $right)
{
if (preg_match('/\s*\?>$/', $left) && preg_match('/^<\?php\s+/', $right)) {
$left = preg_replace('/\s*\?>$/', "\n", $left);
$left .= preg_replace('/^<\?php\s+/', '', $right);
} else {
$left .= $right;
}
return $left;
}
}

View File

@ -1,160 +0,0 @@
<?php
/**
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Extension_Config
{
/**
* @param $obj
* @param $config_file
* @param null $sections
* @param string $scope
*/
static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
$confObj = new $smarty->template_class($config_file, $smarty, $obj);
$confObj->caching = Smarty::CACHING_OFF;
$confObj->source = Smarty_Template_Config::load($confObj);
$confObj->source->config_sections = $sections;
$confObj->source->scope = $scope;
$confObj->compiled = Smarty_Template_Compiled::load($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::start_render($confObj);
}
$confObj->compiled->render($confObj);
if ($confObj->smarty->debugging) {
Smarty_Internal_Debug::end_render($confObj);
}
if ($obj instanceof Smarty_Internal_Template) {
$obj->properties['file_dependency'][$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->timestamp, $confObj->source->type);
}
}
/**
* load config variables
*
* @param mixed $sections array of section names, single section or null
* @param string $scope global,parent or local
*
* @throws Exception
*/
static function loadConfigVars($_template, $_config_vars)
{
$scope = $_template->source->scope;
// pointer to scope (local scope is parent of template object
$scope_ptr = $_template->parent;
if ($scope == 'parent') {
if (isset($_template->parent->parent)) {
$scope_ptr = $_template->parent->parent;
}
} elseif ($scope == 'root' || $scope == 'global') {
while (isset($scope_ptr->parent)) {
$scope_ptr = $scope_ptr->parent;
}
}
// copy global config vars
foreach ($_config_vars['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
// scan sections
$sections = $_template->source->config_sections;
if (!empty($sections)) {
foreach ((array) $sections as $_template_section) {
if (isset($_config_vars['sections'][$_template_section])) {
foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) {
if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
$scope_ptr->config_vars[$variable] = $value;
} else {
$scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
}
}
}
}
}
}
/**
* Returns a single or all config variables
*
* @param string $varname variable name or null
* @param bool $search_parents
*
* @return string variable value or or array of variables
*/
static function getConfigVars($obj, $varname = null, $search_parents = true)
{
$_ptr = $obj;
$var_array = array();
while ($_ptr !== null) {
if (isset($varname)) {
if (isset($_ptr->config_vars[$varname])) {
return $_ptr->config_vars[$varname];
}
} else {
$var_array = array_merge($_ptr->config_vars, $var_array);
}
// not found, try at parent
if ($search_parents) {
$_ptr = $_ptr->parent;
} else {
$_ptr = null;
}
}
if (isset($varname)) {
return '';
} else {
return $var_array;
}
}
/**
* gets a config variable
*
* @param string $variable the name of the config variable
* @param bool $error_enable
*
* @return mixed the value of the config variable
*/
static function getConfigVariable($obj, $variable, $error_enable = true)
{
$_ptr = $obj;
while ($_ptr !== null) {
if (isset($_ptr->config_vars[$variable])) {
// found it, return it
return $_ptr->config_vars[$variable];
}
// not found, try at parent
$_ptr = $_ptr->parent;
}
if ($obj->error_unassigned && $error_enable) {
// force a notice
$x = $$variable;
}
return null;
}
/**
* remove a single or all config variables
*
* @param string $name variable name or null
*
* @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for chaining
*/
static function clearConfig($obj, $name = null)
{
if (isset($name)) {
unset($obj->config_vars[$name]);
} else {
$obj->config_vars = array();
}
return $obj;
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* Smarty Resource Extension
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
*/
/**
* Smarty Resource Extension
* Default template and config file handling
*
* @package Smarty
* @subpackage TemplateResources
*/
class Smarty_Internal_Extension_DefaultTemplateHandler
{
/**
* get default content from template of config resource handler
*
* @param Smarty_Internal_Template $_template
* @param Smarty_Internal_Template_Source $source
* @param Smarty_Resource $resObj
*/
static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj)
{
if ($source->isConfig) {
$default_handler = $_template->smarty->default_config_handler_func;
} else {
$default_handler = $_template->smarty->default_template_handler_func;
}
$_content = $_timestamp = null;
$_return = call_user_func_array($default_handler,
array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty));
if (is_string($_return)) {
$source->exists = is_file($_return);
if ($source->exists) {
$source->timestamp = filemtime($_return);
}
$source->filepath = $_return;
} elseif ($_return === true) {
$source->content = $_content;
$source->timestamp = $_timestamp;
$source->exists = true;
$source->recompiled = true;
$source->filepath = false;
}
}
/**
* register template default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultTemplateHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_template_handler_func = $callback;
} else {
throw new SmartyException("Default template handler not callable");
}
}
/**
* register config default handler
*
* @param Smarty $smarty
* @param mixed $callback
*
* @throws SmartyException
*/
static function registerDefaultConfigHandler(Smarty $smarty, $callback)
{
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
}
}

View File

@ -1,67 +0,0 @@
<?php
/**
* Smarty Internal Plugin Filter Handler
* Smarty filter handler class
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
/**
* Class for filter processing
*
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Filter_Handler
{
/**
* Run filters over content
* The filters will be lazy loaded if required
* class name format: Smarty_FilterType_FilterName
* plugin filename format: filtertype.filtername.php
* Smarty2 filter plugins could be used
*
* @param string $type the type of filter ('pre','post','output') which shall run
* @param string $content the content which shall be processed by the filters
* @param Smarty_Internal_Template $template template object
*
* @throws SmartyException
* @return string the filtered content
*/
public static function runFilter($type, $content, Smarty_Internal_Template $template)
{
$output = $content;
// loop over autoload filters of specified type
if (!empty($template->smarty->autoload_filters[$type])) {
foreach ((array) $template->smarty->autoload_filters[$type] as $name) {
$plugin_name = "Smarty_{$type}filter_{$name}";
if ($template->smarty->loadPlugin($plugin_name)) {
if (function_exists($plugin_name)) {
// use loaded Smarty2 style plugin
$output = $plugin_name($output, $template);
} elseif (class_exists($plugin_name, false)) {
// loaded class of filter plugin
$output = call_user_func(array($plugin_name, 'execute'), $output, $template);
}
} else {
// nothing found, throw exception
throw new SmartyException("Unable to load filter {$plugin_name}");
}
}
}
// loop over registerd filters of specified type
if (!empty($template->smarty->registered_filters[$type])) {
foreach ($template->smarty->registered_filters[$type] as $key => $name) {
if (is_array($template->smarty->registered_filters[$type][$key])) {
$output = call_user_func($template->smarty->registered_filters[$type][$key], $output, $template);
} else {
$output = $template->smarty->registered_filters[$type][$key]($output, $template);
}
}
}
// return filtered output
return $output;
}
}

View File

@ -1,71 +0,0 @@
<?php
/**
* Smarty Internal Plugin Function Call Handler
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
/**
* This class does handles template functions defined with the {function} tag missing in cache file.
* It can happen when the template function was called with the nocache option or within a nocache section.
* The template function will be loaded from it's compiled template file, executed and added to the cache file
* for later use.
*
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Function_Call_Handler
{
/**
* This function handles calls to template functions defined by {function}
* It does create a PHP function at the first call
*
* @param string $_name template function name
* @param Smarty_Internal_Template $_smarty_tpl
* @param string $_function PHP function name
* @param array $_params Smarty variables passed as call parameter
* @param bool $_nocache nocache flag
*
* @return bool
*/
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache)
{
$funcParam = $_smarty_tpl->properties['tpl_function'][$_name];
if (is_file($funcParam['compiled_filepath'])) {
// read compiled file
$code = file_get_contents($funcParam['compiled_filepath']);
// grab template function
if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) {
// grab source info from file dependency
preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
unset($code);
$output = '';
// make PHP function known
eval($match[0]);
if (function_exists($_function)) {
// search cache file template
$tplPtr = $_smarty_tpl;
while (!isset($tplPtr->cached) && isset($tplPtr->parent)) {
$tplPtr = $tplPtr->parent;
}
// add template function code to cache file
if (isset($tplPtr->cached)) {
$cache = $tplPtr->cached;
$content = $cache->read($tplPtr);
if ($content) {
// check if we must update file dependency
if (!preg_match("/'{$funcParam['uid']}'([\S\s]*?)'nocache_hash'/", $content, $match2)) {
$content = preg_replace("/('file_dependency'([\S\s]*?)\()/", "\\1{$match1[0]}", $content);
}
$cache->write($tplPtr, $content . "<?php " . $match[0] . "?>\n");
}
}
return true;
}
}
}
return false;
}
}

View File

@ -1,46 +0,0 @@
<?php
/**
* Smarty read include path plugin
*
* @package Smarty
* @subpackage PluginsInternal
* @author Monte Ohrt
*/
/**
* Smarty Internal Read Include Path Class
*
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Get_Include_Path
{
/**
* Return full file path from PHP include_path
*
* @param string $filepath filepath
*
* @return string|boolean full filepath or false
*/
public static function getIncludePath($filepath)
{
static $_include_path = null;
if (function_exists('stream_resolve_include_path')) {
// available since PHP 5.3.2
return stream_resolve_include_path($filepath);
}
if ($_include_path === null) {
$_include_path = explode(PATH_SEPARATOR, get_include_path());
}
foreach ($_include_path as $_path) {
if (file_exists($_path . DS . $filepath)) {
return $_path . DS . $filepath;
}
}
return false;
}
}

View File

@ -42,10 +42,10 @@ class Smarty_Internal_Nocache_Insert
$_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>";
}
$_tpl = $_template;
while ($_tpl->parent instanceof Smarty_Internal_Template) {
while (isset($_tpl->parent) && $_tpl->parent->_objType == 2) {
$_tpl = $_tpl->parent;
}
return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/";
return "/*%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/";
}
}

View File

@ -17,13 +17,6 @@
abstract class Smarty_Internal_ParseTree
{
/**
* Parser object
*
* @var object
*/
public $parser;
/**
* Buffer content
*
@ -41,9 +34,21 @@ abstract class Smarty_Internal_ParseTree
/**
* Return buffer
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string buffer content
*/
abstract public function to_smarty_php();
abstract public function to_smarty_php(Smarty_Internal_Templateparser $parser);
/**
* Template data object destructor
*/
public function __destruct()
{
$this->data = null;
$this->subtrees = null;
}
}

View File

@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_Code extends Smarty_Internal_ParseTree
/**
* Create parse tree buffer for code fragment
*
* @param object $parser parser object
* @param string $data content
* @param string $data content
*/
public function __construct($parser, $data)
public function __construct($data)
{
$this->parser = $parser;
$this->data = $data;
}
/**
* Return buffer content in parentheses
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string content
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
return sprintf("(%s)", $this->data);
}

View File

@ -25,43 +25,45 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
*/
public function __construct($parser, Smarty_Internal_ParseTree $subtree)
{
$this->parser = $parser;
$this->subtrees[] = $subtree;
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
$parser->block_nesting_level = count($parser->compiler->_tag_stack);
}
}
/**
* Append buffer to subtree
*
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
* @param \Smarty_Internal_Templateparser $parser
* @param Smarty_Internal_ParseTree $subtree parse tree buffer
*/
public function append_subtree(Smarty_Internal_ParseTree $subtree)
public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
{
$last_subtree = count($this->subtrees) - 1;
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $this->parser->block_nesting_level) {
if ($last_subtree >= 0 && $this->subtrees[$last_subtree] instanceof Smarty_Internal_ParseTree_Tag && $this->subtrees[$last_subtree]->saved_block_nesting < $parser->block_nesting_level) {
if ($subtree instanceof Smarty_Internal_ParseTree_Code) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>');
$this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo ' . $subtree->data . ';?>');
} elseif ($subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>');
$this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, '<?php echo "' . $subtree->data . '";?>');
} else {
$this->subtrees[$last_subtree]->data = $this->parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data);
$this->subtrees[$last_subtree]->data = $parser->compiler->appendCode($this->subtrees[$last_subtree]->data, $subtree->data);
}
} else {
$this->subtrees[] = $subtree;
}
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$this->parser->block_nesting_level = count($this->parser->compiler->_tag_stack);
$parser->block_nesting_level = count($parser->compiler->_tag_stack);
}
}
/**
* Merge subtree buffer content together
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string compiled template code
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
$code = '';
foreach ($this->subtrees as $subtree) {
@ -69,15 +71,15 @@ class Smarty_Internal_ParseTree_Dq extends Smarty_Internal_ParseTree
$code .= ".";
}
if ($subtree instanceof Smarty_Internal_ParseTree_Tag) {
$more_php = $subtree->assign_to_var();
$more_php = $subtree->assign_to_var($parser);
} else {
$more_php = $subtree->to_smarty_php();
$more_php = $subtree->to_smarty_php($parser);
}
$code .= $more_php;
if (!$subtree instanceof Smarty_Internal_ParseTree_DqContent) {
$this->parser->compiler->has_variable_string = true;
$parser->compiler->has_variable_string = true;
}
}

View File

@ -21,21 +21,21 @@ class Smarty_Internal_ParseTree_DqContent extends Smarty_Internal_ParseTree
/**
* Create parse tree buffer with string content
*
* @param object $parser parser object
* @param string $data string section
* @param string $data string section
*/
public function __construct($parser, $data)
public function __construct($data)
{
$this->parser = $parser;
$this->data = $data;
}
/**
* Return content as double quoted string
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string doubled quoted string
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
return '"' . $this->data . '"';
}

View File

@ -29,12 +29,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/**
* Create parse tree buffer for Smarty tag
*
* @param object $parser parser object
* @param string $data content
* @param \Smarty_Internal_Templateparser $parser parser object
* @param string $data content
*/
public function __construct($parser, $data)
public function __construct(Smarty_Internal_Templateparser $parser, $data)
{
$this->parser = $parser;
$this->data = $data;
$this->saved_block_nesting = $parser->block_nesting_level;
}
@ -42,9 +41,11 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/**
* Return buffer content
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string content
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
return $this->data;
}
@ -52,14 +53,16 @@ class Smarty_Internal_ParseTree_Tag extends Smarty_Internal_ParseTree
/**
* Return complied code that loads the evaluated output of buffer content into a temporary variable
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string template code
*/
public function assign_to_var()
public function assign_to_var(Smarty_Internal_Templateparser $parser)
{
$var = sprintf('$_tmp%d', ++ Smarty_Internal_Templateparser::$prefix_number);
$tmp = $this->parser->compiler->appendCode('<?php ob_start();?>', $this->data);
$tmp = $this->parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
$this->parser->compiler->prefix_code[] = sprintf("%s", $tmp);
$tmp = $parser->compiler->appendCode('<?php ob_start();?>', $this->data);
$tmp = $parser->compiler->appendCode($tmp, "<?php {$var}=ob_get_clean();?>");
$parser->compiler->prefix_code[] = sprintf("%s", $tmp);
return $var;
}

View File

@ -29,19 +29,18 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
/**
* Create root of parse tree for template elements
*
* @param object $parser parse object
*/
public function __construct($parser)
public function __construct()
{
$this->parser = $parser;
}
/**
* Append buffer to subtree
*
* @param Smarty_Internal_ParseTree $subtree
* @param \Smarty_Internal_Templateparser $parser
* @param Smarty_Internal_ParseTree $subtree
*/
public function append_subtree(Smarty_Internal_ParseTree $subtree)
public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
{
if (!empty($subtree->subtrees)) {
$this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
@ -52,38 +51,69 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
}
}
/**
* Append array to subtree
*
* @param \Smarty_Internal_Templateparser $parser
* @param \Smarty_Internal_ParseTree[] $array
*/
public function append_array(Smarty_Internal_Templateparser $parser, $array = array())
{
if (!empty($array)) {
$this->subtrees = array_merge($this->subtrees, (array) $array);
}
}
/**
* Prepend array to subtree
*
* @param \Smarty_Internal_Templateparser $parser
* @param \Smarty_Internal_ParseTree[] $array
*/
public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array())
{
if (!empty($array)) {
$this->subtrees = array_merge((array) $array, $this->subtrees);
}
}
/**
* Sanitize and merge subtree buffers together
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string template code content
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
$code = '';
for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) {
$subtree = $this->subtrees[$key]->to_smarty_php();
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text || $this->subtrees[$key + 1]->data == '')) {
$subtree = $this->subtrees[$key]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text ||
$this->subtrees[$key + 1]->data == '')) {
$key ++;
if ($this->subtrees[$key]->data == '') {
continue;
}
$subtree .= $this->subtrees[$key]->to_smarty_php();
$subtree .= $this->subtrees[$key]->to_smarty_php($parser);
}
if ($subtree == '') {
continue;
}
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n", $subtree);
$code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n",
$subtree);
continue;
}
if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
$subtree = $this->subtrees[$key]->to_smarty_php();
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag || $this->subtrees[$key + 1]->data == '')) {
$subtree = $this->subtrees[$key]->to_smarty_php($parser);
while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag ||
$this->subtrees[$key + 1]->data == '')) {
$key ++;
if ($this->subtrees[$key]->data == '') {
continue;
}
$subtree = $this->parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php());
$subtree = $parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php($parser));
}
if ($subtree == '') {
continue;
@ -91,7 +121,7 @@ class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
$code .= $subtree;
continue;
}
$code .= $this->subtrees[$key]->to_smarty_php();
$code .= $this->subtrees[$key]->to_smarty_php($parser);
}
return $code;
}

View File

@ -19,21 +19,21 @@ class Smarty_Internal_ParseTree_Text extends Smarty_Internal_ParseTree
/**
* Create template text buffer
*
* @param object $parser parser object
* @param string $data text
* @param string $data text
*/
public function __construct($parser, $data)
public function __construct($data)
{
$this->parser = $parser;
$this->data = $data;
}
/**
* Return buffer content
*
* @param \Smarty_Internal_Templateparser $parser
*
* @return string text
*/
public function to_smarty_php()
public function to_smarty_php(Smarty_Internal_Templateparser $parser)
{
return $this->data;
}

View File

@ -34,30 +34,29 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
*/
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$uid = sha1(getcwd());
$uid = '';
$sources = array();
$components = explode('|', $source->name);
$exists = true;
foreach ($components as $component) {
$s = Smarty_Resource::source(null, $source->smarty, $component);
if ($s->type == 'php') {
throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
/* @var \Smarty_Template_Source $_s */
$_s = Smarty_Template_Source::load(null, $source->smarty, $component);
if ($_s->type == 'php') {
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
}
$sources[$s->uid] = $s;
$uid .= realpath($s->filepath);
if ($_template && $_template->smarty->compile_check) {
$exists = $exists && $s->exists;
$sources[$_s->uid] = $_s;
$uid .= $_s->filepath;
if ($_template) {
$exists = $exists && $_s->exists;
}
}
$source->components = $sources;
$source->filepath = $s->filepath;
$source->filepath = $_s->filepath;
$source->uid = sha1($uid);
if ($_template && $_template->smarty->compile_check) {
$source->timestamp = $s->timestamp;
$source->exists = $exists;
$source->exists = $exists;
if ($_template) {
$source->timestamp = $_s->timestamp;
}
// need the template at getContent()
$source->template = $_template;
}
/**
@ -68,10 +67,11 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
public function populateTimestamp(Smarty_Template_Source $source)
{
$source->exists = true;
foreach ($source->components as $s) {
$source->exists = $source->exists && $s->exists;
/* @var \Smarty_Template_Source $_s */
foreach ($source->components as $_s) {
$source->exists = $source->exists && $_s->exists;
}
$source->timestamp = $s->timestamp;
$source->timestamp = $source->exists ? $_s->getTimeStamp() : false;
}
/**
@ -91,9 +91,10 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource
$_components = array_reverse($source->components);
$_content = '';
foreach ($_components as $_component) {
/* @var \Smarty_Template_Source $_s */
foreach ($_components as $_s) {
// read content
$_content .= $_component->content;
$_content .= $_s->getContent();
}
return $_content;
}

View File

@ -29,120 +29,83 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
{
$file = $source->name;
preg_match('#^(?P<absolute>[\\\/]|[a-zA-Z]:[\\\/])|(\[(?P<index>[^\]]+)\])|(?P<rel>\.[\\\/])#', $file, $fileMatch);
// save basename
if (!empty($fileMatch['absolute'])) {
$file = $this->normalizePath($file);
// absolute file ?
if ($file[0] == '/' || $file[1] == ':') {
$file = $source->smarty->_realpath($file, true);
return is_file($file) ? $file : false;
}
// go relative to a given template?
if (!empty($fileMatch['rel']) && $_template && $_template->parent instanceof Smarty_Internal_Template) {
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' && !$_template->parent->allow_relative_path) {
if ($file[0] == '.' && $_template && isset($_template->parent) && $_template->parent->_objType == 2 &&
preg_match('#^[.]{1,2}[\\\/]#', $file)
) {
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' &&
!isset($_template->parent->_cache['allow_relative_path'])
) {
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
}
$path = dirname($_template->parent->source->filepath) . DS . $file;
// normalize path
$path = $this->normalizePath($path);
$path = $source->smarty->_realpath($path);
// files relative to a template only get one shot
return is_file($path) ? $path : false;
}
if ($source->isConfig) {
$_directories = $source->smarty->getConfigDir();
} else {
$_directories = $source->smarty->getTemplateDir();
// normalize DS
if (strpos($file, DS == '/' ? '\\' : '/') !== false) {
$file = str_replace(DS == '/' ? '\\' : '/', DS, $file);
}
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
// template_dir index?
if (!empty($fileMatch['index'])) {
$index = $fileMatch['index'];
$_directory = null;
// try string indexes
if (isset($_directories[$index])) {
$_directory = $_directories[$index];
} elseif (is_numeric($index)) {
// try numeric index
$index = (int) $index;
if ($file[0] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
$file = $fileMatch[2];
$_indices = explode(',', $fileMatch[1]);
$_index_dirs = array();
foreach ($_indices as $index) {
$index = trim($index);
// try string indexes
if (isset($_directories[$index])) {
$_directory = $_directories[$index];
} else {
// try at location index
$keys = array_keys($_directories);
$_directory = $_directories[$keys[$index]];
$_index_dirs[] = $_directories[$index];
} elseif (is_numeric($index)) {
// try numeric index
$index = (int) $index;
if (isset($_directories[$index])) {
$_index_dirs[] = $_directories[$index];
} else {
// try at location index
$keys = array_keys($_directories);
if (isset($_directories[$keys[$index]])) {
$_index_dirs[] = $_directories[$keys[$index]];
}
}
}
}
if ($_directory) {
preg_match('#\](.+)$#', $file, $fileMatch);
$path = $_directory . $fileMatch[1];
$path = $this->normalizePath($path);
if (is_file($path)) {
return $path;
}
} else {
if (empty($_index_dirs)) {
// index not found
return false;
} else {
$_directories = $_index_dirs;
}
}
// relative file name?
foreach ($_directories as $_directory) {
$_filepath = $_directory . $file;
$path = $this->normalizePath($_filepath);
$path = $_directory . $file;
if (is_file($path)) {
return (strpos($path, '.' . DS) !== false) ? $source->smarty->_realpath($path) : $path;
}
}
if (!isset($_index_dirs)) {
// Could be relative to cwd
$path = $source->smarty->_realpath($file, true);
if (is_file($path)) {
return $path;
}
if ($source->smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) {
// try PHP include_path
if (function_exists('stream_resolve_include_path')) {
$_filepath = stream_resolve_include_path($_filepath);
} else {
$_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath);
}
if ($_filepath !== false) {
$path = $this->normalizePath($_filepath);
if (is_file($path)) {
return $path;
}
}
}
}
// Could be relative to cwd
$path = $this->normalizePath(getcwd() . DS . $file);
return is_file($path) ? $path : false;
}
/**
* Normalize path
* - remove /./ and /../
* - make it absolute
*
* @param string $path file path
*
* @return string
*/
public function normalizePath($path)
{
if ($path[0] == '.') {
$path = getcwd() . DS . $path;
// Use include path ?
if ($source->smarty->use_include_path) {
return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty);
}
$path = preg_replace('#[\\\/]+([.][\\\/]+)*#', DS, $path);
while (strrpos($path, '.' . DS) !== false) {
$path = preg_replace('#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', DS, $path);
}
return $path;
}
/**
* test is file exists and save timestamp
*
* @param Smarty_Template_Source $source source object
* @param string $file file name
*
* @return bool true if file exists
*/
protected function fileExists(Smarty_Template_Source $source, $file)
{
$source->timestamp = is_file($file) ? @filemtime($file) : false;
return $source->exists = !!$source->timestamp;
return false;
}
/**
@ -156,13 +119,13 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
$source->filepath = $this->buildFilepath($source, $_template);
if ($source->filepath !== false) {
if (is_object($source->smarty->security_policy)) {
$source->smarty->security_policy->isTrustedResourceDir($source->filepath);
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
}
$source->exists = true;
$source->uid = sha1($source->filepath);
if ($source->smarty->compile_check && !isset($source->timestamp)) {
$source->timestamp = @filemtime($source->filepath);
if ($source->smarty->compile_check == 1) {
$source->timestamp = filemtime($source->filepath);
}
} else {
$source->timestamp = false;
@ -177,9 +140,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
*/
public function populateTimestamp(Smarty_Template_Source $source)
{
$source->timestamp = $source->exists = is_file($source->filepath);
if (!$source->exists) {
$source->timestamp = $source->exists = is_file($source->filepath);
}
if ($source->exists) {
$source->timestamp = @filemtime($source->filepath);
$source->timestamp = filemtime($source->filepath);
}
}
@ -193,13 +158,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
*/
public function getContent(Smarty_Template_Source $source)
{
if ($source->timestamp) {
if ($source->exists) {
return file_get_contents($source->filepath);
}
if ($source instanceof Smarty_Config_Source) {
throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
}
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
throw new SmartyException('Unable to read ' . ($source->isConfig ? 'config' : 'template') .
" {$source->type} '{$source->name}'");
}
/**

View File

@ -24,6 +24,14 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
*/
protected $short_open_tag;
/**
* Resource does implement populateCompiledFilepath() method
*
* @var bool
*/
public $hasCompiledHandler = true;
/**
* Create a new PHP Resource
@ -43,7 +51,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
*/
public function getContent(Smarty_Template_Source $source)
{
if ($source->timestamp) {
if ($source->exists) {
return '';
}
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
@ -64,7 +72,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
throw new SmartyException("PHP templates are disabled");
}
if (!$source->exists) {
if ($_template->parent instanceof Smarty_Internal_Template) {
if (isset($_template->parent) && $_template->parent->_objType == 2) {
$parent_resource = " in '{$_template->parent->template_resource}'";
} else {
$parent_resource = '';

View File

@ -76,12 +76,13 @@ class Smarty_Internal_Resource_Registered extends Smarty_Resource
public function getContent(Smarty_Template_Source $source)
{
// return template string
$t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty));
$content = null;
$t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$content, $source->smarty));
if (is_bool($t) && !$t) {
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
}
return $source->content;
return $content;
}
/**

View File

@ -8,11 +8,6 @@
* @author Uwe Tews
*/
/**
* @ignore
*/
//include 'smarty_internal_parsetree.php';
/**
* Class SmartyTemplateCompiler
*
@ -35,20 +30,6 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
*/
public $parser_class;
/**
* Lexer object
*
* @var object
*/
public $lex;
/**
* Parser object
*
* @var object
*/
public $parser;
/**
* array of vars which can be compiled in local scope
*
@ -56,6 +37,27 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
*/
public $local_var = array();
/**
* array of callbacks called when the normal compile process of template is finished
*
* @var array
*/
public $postCompileCallbacks = array();
/**
* prefix code
*
* @var string
*/
public $prefixCompiledCode = '';
/**
* postfix code
*
* @var string
*/
public $postfixCompiledCode = '';
/**
* Initialize compiler
*
@ -63,10 +65,9 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
* @param string $parser_class class name
* @param Smarty $smarty global instance
*/
public function __construct($lexer_class, $parser_class, $smarty)
public function __construct($lexer_class, $parser_class, Smarty $smarty)
{
$this->smarty = $smarty;
parent::__construct();
parent::__construct($smarty);
// get required plugins
$this->lexer_class = $lexer_class;
$this->parser_class = $parser_class;
@ -76,8 +77,10 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
* method to compile a Smarty template
*
* @param mixed $_content template source
* @param bool $isTemplateSource
*
* @return bool true if compiling succeeded, false if it failed
* @return bool true if compiling succeeded, false if it failed
* @throws \SmartyCompilerException
*/
protected function doCompile($_content, $isTemplateSource = false)
{
@ -85,14 +88,11 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
tags in the templates are replaces with PHP code,
then written to compiled files. */
// init the lexer/parser to compile the template
$this->lex = new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this);
$this->parser = new $this->parser_class($this->lex, $this);
if ($isTemplateSource) {
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->properties['nocache_hash'] = '{$this->nocache_hash}';\n?>\n");
}
if ($this->inheritance_child) {
// start state on child templates
$this->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
$this->parser =
new $this->parser_class(new $this->lexer_class(str_replace(array("\r\n", "\r"), "\n", $_content), $this),
$this);
if ($isTemplateSource && $this->template->caching) {
$this->parser->insertPhpCode("<?php\n\$_smarty_tpl->compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n");
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
@ -103,21 +103,17 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
if ($this->smarty->_parserdebug) {
$this->parser->PrintTrace();
$this->lex->PrintTrace();
$this->parser->lex->PrintTrace();
}
// get tokens from lexer and parse them
while ($this->lex->yylex() && !$this->abort_and_recompile) {
while ($this->parser->lex->yylex()) {
if ($this->smarty->_parserdebug) {
echo "<pre>Line {$this->lex->line} Parsing {$this->parser->yyTokenName[$this->lex->token]} Token " .
htmlentities($this->lex->value) . "</pre>";
echo "<pre>Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " .
htmlentities($this->parser->lex->value) . "</pre>";
}
$this->parser->doParse($this->lex->token, $this->lex->value);
$this->parser->doParse($this->parser->lex->token, $this->parser->lex->value);
}
if ($this->abort_and_recompile) {
// exit here on abort
return false;
}
// finish parsing process
$this->parser->doParse(0, 0);
if ($mbEncoding) {
@ -127,10 +123,47 @@ class Smarty_Internal_SmartyTemplateCompiler extends Smarty_Internal_TemplateCom
if (count($this->_tag_stack) > 0) {
// get stacked info
list($openTag, $_data) = array_pop($this->_tag_stack);
$this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag . "{$this->smarty->right_delimiter} tag");
$this->trigger_template_error("unclosed {$this->smarty->left_delimiter}" . $openTag .
"{$this->smarty->right_delimiter} tag");
}
// call post compile callbacks
foreach ($this->postCompileCallbacks as $cb) {
$parameter = $cb;
$parameter[0] = $this;
call_user_func_array($cb[0], $parameter);
}
// return compiled code
// return str_replace(array("? >\n<?php","? ><?php"), array('',''), $this->parser->retvalue);
return $this->parser->retvalue;
return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode;
}
/**
* Register a post compile callback
* - when the callback is called after template compiling the compiler object will be inserted as first parameter
*
* @param callback $callback
* @param array $parameter optional parameter array
* @param string $key optional key for callback
* @param bool $replace if true replace existing keyed callback
*/
public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
{
array_unshift($parameter, $callback);
if (isset($key)) {
if ($replace || !isset($this->postCompileCallbacks[$key])) {
$this->postCompileCallbacks[$key] = $parameter;
}
} else {
$this->postCompileCallbacks[] = $parameter;
}
}
/**
* Remove a post compile callback
*
* @param string $key callback key
*/
public function unregisterPostCompileCallback($key)
{
unset($this->postCompileCallbacks[$key]);
}
}

View File

@ -14,12 +14,20 @@
* @package Smarty
* @subpackage Template
*
* @property Smarty_Template_Source $source
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
* @property Smarty_Template_Source|Smarty_Template_Config $source
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
* @method bool mustCompile()
*/
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{
/**
* This object type (Smarty = 1, template = 2, data = 4)
*
* @var int
*/
public $_objType = 2;
/**
* Global smarty instance
*
@ -27,90 +35,66 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public $smarty = null;
/**
* Source instance
*
* @var Smarty_Template_Source|Smarty_Template_Config
*/
public $source = null;
/**
* Template resource
*
* @var string
*/
public $template_resource = null;
/**
* Saved template Id
*
* @var null|string
*/
public $templateId = null;
/**
* flag if compiled template is invalid and must be (re)compiled
*
* @var bool
*/
public $mustCompile = null;
/**
* flag if template does contain nocache code sections
* Template Id
*
* @var bool
* @var null|string
*/
public $has_nocache_code = false;
public $templateId = null;
/**
* special compiled and cached template properties
* Known template functions
*
* @var array
*/
public $properties = array('file_dependency' => array(),
'nocache_hash' => '',
'tpl_function' => array(),
);
public $tpl_function = array();
/**
* required plugins
* Scope in which template is rendered
*
* @var array
* @var int
*/
public $required_plugins = array('compiled' => array(), 'nocache' => array());
/**
* blocks for template inheritance
*
* @var array
*/
public $block_data = array();
/**
* variable filters
*
* @var array
*/
public $variable_filters = array();
/**
* optional log of tag/attributes
*
* @var array
*/
public $used_tags = array();
/**
* internal flag to allow relative path in child template blocks
*
* @var bool
*/
public $allow_relative_path = false;
/**
* internal capture runtime stack
*
* @var array
*/
public $_capture_stack = array(0 => array());
public $scope = 0;
/**
* Create template data object
* Some of the global Smarty settings copied to template scope
* It load the required template resources and caching plugins
*
* @param string $template_resource template resource string
* @param Smarty $smarty Smarty instance
* @param Smarty_Internal_Template $_parent back pointer to parent object with variables or null
* @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null
* @param bool $_caching use caching?
* @param int $_cache_lifetime cache life-time in seconds
* @param string $template_resource template resource string
* @param Smarty $smarty Smarty instance
* @param \Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $_parent back pointer to parent object
* with variables or null
* @param mixed $_cache_id cache id or null
* @param mixed $_compile_id compile id or null
* @param bool $_caching use caching?
* @param int $_cache_lifetime cache life-time in seconds
*
* @throws \SmartyException
*/
public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
public function __construct($template_resource, Smarty $smarty, Smarty_Internal_Data $_parent = null,
$_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
{
$this->smarty = &$smarty;
// Smarty parameter
@ -124,30 +108,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->parent = $_parent;
// Template resource
$this->template_resource = $template_resource;
// copy block data of template inheritance
if ($this->parent instanceof Smarty_Internal_Template) {
$this->block_data = $this->parent->block_data;
}
}
/**
* fetches rendered template
*
* @throws Exception
* @throws SmartyException
* @return string rendered template output
*/
public function fetch()
{
return $this->render(true, false, false);
}
/**
* displays a Smarty template
*/
public function display()
{
$this->render(true, false, true);
$this->source = Smarty_Template_Source::load($this);
parent::__construct();
}
/**
@ -161,53 +123,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* @throws SmartyException
* @return string rendered template output
*/
public function render($merge_tpl_vars = false, $no_output_filter = true, $display = null)
public function render($no_output_filter = true, $display = null)
{
$parentIsTpl = $this->parent instanceof Smarty_Internal_Template;
$parentIsTpl = isset($this->parent) && $this->parent->_objType == 2;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_template($this, $display);
}
$save_tpl_vars = null;
$save_config_vars = null;
// merge all variable scopes into template
if ($merge_tpl_vars) {
// save local variables
$save_tpl_vars = $this->tpl_vars;
$save_config_vars = $this->config_vars;
$ptr_array = array($this);
$ptr = $this;
while (isset($ptr->parent)) {
$ptr_array[] = $ptr = $ptr->parent;
}
$ptr_array = array_reverse($ptr_array);
$parent_ptr = reset($ptr_array);
$tpl_vars = $parent_ptr->tpl_vars;
$config_vars = $parent_ptr->config_vars;
while ($parent_ptr = next($ptr_array)) {
if (!empty($parent_ptr->tpl_vars)) {
$tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
}
if (!empty($parent_ptr->config_vars)) {
$config_vars = array_merge($config_vars, $parent_ptr->config_vars);
}
}
if (!empty(Smarty::$global_tpl_vars)) {
$tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
}
$this->tpl_vars = $tpl_vars;
$this->config_vars = $config_vars;
}
// dummy local smarty variable
if (!isset($this->tpl_vars['smarty'])) {
$this->tpl_vars['smarty'] = new Smarty_Variable;
}
$_smarty_old_error_level = isset($this->smarty->error_reporting) ? error_reporting($this->smarty->error_reporting) : null;
// check URL debugging control
if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
Smarty_Internal_Debug::debugUrl($this);
}
if (!isset($this->source)) {
$this->loadSource();
$this->smarty->_debug->start_template($this, $display);
}
// checks if template exists
if (!$this->source->exists) {
@ -218,201 +138,83 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
// check URL debugging control
if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
$this->smarty->_debug->debugUrl($this);
}
// disable caching for evaluated code
if ($this->source->recompiled) {
if ($this->source->handler->recompiled) {
$this->caching = false;
}
// read from cache or render
$isCacheTpl = $this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
$isCacheTpl =
$this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED;
if ($isCacheTpl) {
if (!isset($this->cached)) {
$this->loadCached();
}
$this->cached->isCached($this);
}
if (!($isCacheTpl) || !$this->cached->valid) {
if ($isCacheTpl) {
$this->properties['tpl_function'] = array();
}
// render template (not loaded and not in cache)
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_render($this);
}
if (!$this->source->uncompiled) {
// render compiled code
if (!isset($this->compiled)) {
$this->loadCompiled();
}
$content = $this->compiled->render($this);
} else {
$content = $this->source->renderUncompiled($this);
}
if (!$this->source->recompiled && empty($this->properties['file_dependency'][$this->source->uid])) {
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
}
if ($parentIsTpl) {
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
//$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_render($this);
}
// write to cache when necessary
if (!$this->source->recompiled && $isCacheTpl) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$this->cached->updateCache($this, $content, $no_output_filter);
$compile_check = $this->smarty->compile_check;
$this->smarty->compile_check = false;
if ($parentIsTpl) {
$this->properties['tpl_function'] = $this->parent->properties['tpl_function'];
}
if (!$this->cached->processed) {
$this->cached->process($this);
}
$this->smarty->compile_check = $compile_check;
$content = $this->getRenderedTemplateCode();
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
}
} else {
if (!empty($this->properties['nocache_hash']) && !empty($this->parent->properties['nocache_hash'])) {
// replace nocache_hash
$content = str_replace("{$this->properties['nocache_hash']}", $this->parent->properties['nocache_hash'], $content);
$this->parent->has_nocache_code = $this->parent->has_nocache_code || $this->has_nocache_code;
}
}
$this->cached->render($this, $no_output_filter);
} elseif ($this->source->handler->uncompiled) {
$this->source->render($this);
} else {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_cache($this);
}
$content = $this->cached->render($this);
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_cache($this);
if (!isset($this->compiled)) {
$this->loadCompiled();
}
$this->compiled->render($this);
}
if ((!$this->caching || $this->has_nocache_code || $this->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
$content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $this);
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
// display or fetch
if ($display) {
if ($this->caching && $this->smarty->cache_modified_check) {
$this->cached->cacheModifiedCheck($this, $content);
$this->smarty->ext->_cachemodify->cacheModifiedCheck($this->cached, $this,
isset($content) ? $content : ob_get_clean());
} else {
echo $content;
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) &&
!$no_output_filter && (isset($this->smarty->autoload_filters['output']) ||
isset($this->smarty->registered_filters['output']))
) {
echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
} else {
ob_end_flush();
flush();
}
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_template($this);
}
// debug output
if ($this->smarty->debugging) {
Smarty_Internal_Debug::display_debug($this, true);
}
if ($merge_tpl_vars) {
// restore local variables
$this->tpl_vars = $save_tpl_vars;
$this->config_vars = $save_config_vars;
$this->smarty->_debug->end_template($this);
// debug output
$this->smarty->_debug->display_debug($this, true);
}
return '';
} else {
if ($merge_tpl_vars) {
// restore local variables
$this->tpl_vars = $save_tpl_vars;
$this->config_vars = $save_config_vars;
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_template($this);
}
if ($this->smarty->debugging == 2 and $display === false) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::display_debug($this, true);
$this->smarty->_debug->end_template($this);
if ($this->smarty->debugging == 2 and !$display) {
$this->smarty->_debug->display_debug($this, true);
}
}
if ($parentIsTpl) {
$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);
foreach ($this->required_plugins as $code => $tmp1) {
if (!empty($this->tpl_function)) {
$this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function);
}
foreach ($this->compiled->required_plugins as $code => $tmp1) {
foreach ($tmp1 as $name => $tmp) {
foreach ($tmp as $type => $data) {
$this->parent->required_plugins[$code][$name][$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']) || isset($this->smarty->registered_filters['output']))
) {
return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this);
}
// return cache content
return $content;
return null;
}
}
/**
* get rendered template content by calling compiled or cached template code
*
* @return string
* @throws Exception
*/
public function getRenderedTemplateCode()
{
$level = ob_get_level();
try {
ob_start();
if (empty($this->properties['unifunc']) || !is_callable($this->properties['unifunc'])) {
throw new SmartyException("Invalid compiled template for '{$this->template_resource}'");
}
if (isset($this->smarty->security_policy)) {
$this->smarty->security_policy->startTemplate($this);
}
array_unshift($this->_capture_stack, array());
//
// render compiled or saved template code
//
$this->properties['unifunc']($this);
// any unclosed {capture} tags ?
if (isset($this->_capture_stack[0][0])) {
$this->capture_error();
}
array_shift($this->_capture_stack);
if (isset($this->smarty->security_policy)) {
$this->smarty->security_policy->exitTemplate($this);
}
return ob_get_clean();
}
catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
}
/**
* Returns if the current template must be compiled by the Smarty compiler
* It does compare the timestamps of template source and the compiled templates and checks the force compile
* configuration
*
* @throws SmartyException
* @return boolean true if the template must be compiled
*/
public function mustCompile()
{
if (!$this->source->exists) {
if ($this->parent instanceof Smarty_Internal_Template) {
$parent_resource = " in '$this->parent->template_resource}'";
} else {
$parent_resource = '';
}
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
}
if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->uncompiled && ($this->smarty->force_compile || $this->source->recompiled || $this->compiled->timestamp === false ||
($this->smarty->compile_check && $this->compiled->timestamp < $this->source->timestamp)));
}
return $this->mustCompile;
}
/**
* Compiles the template
* If the template is not evaluated the compiled template is saved on disk
@ -431,328 +233,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public function writeCachedContent($content)
{
return $this->cached->writeCachedContent($this, $content);
return $this->smarty->ext->_updateCache->writeCachedContent($this->cached, $this, $content);
}
/**
* Template code runtime function to get subtemplate content
* Get unique template id
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param $data
* @param int $parent_scope scope in which {include} should execute
*
* @returns string template content
* @return string
*/
public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
public function _getTemplateId()
{
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope);
return $tpl->render();
}
/**
* Template code runtime function to set up an inline subtemplate
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $parent_scope scope in which {include} should execute
*
* @returns object template object
*/
public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
{
$_templateId = $this->getTemplateId($template, $cache_id, $compile_id);
// already in template cache?
if (isset($this->smarty->template_objects[$_templateId])) {
// clone cached template object because of possible recursive call
$tpl = clone $this->smarty->template_objects[$_templateId];
$tpl->parent = $this;
if ((bool) $tpl->caching !== (bool) $caching) {
unset($tpl->compiled);
}
$tpl->caching = $caching;
$tpl->cache_lifetime = $cache_lifetime;
} else {
$tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime);
$tpl->templateId = $_templateId;
}
// get variables from calling scope
if ($parent_scope == Smarty::SCOPE_LOCAL) {
$tpl->tpl_vars = $this->tpl_vars;
$tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty'];
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
$tpl->tpl_vars = &$this->tpl_vars;
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
$tpl->tpl_vars = &$this->tpl_vars;
} else {
$tpl->tpl_vars = &$scope_ptr->tpl_vars;
}
$tpl->config_vars = $this->config_vars;
if (!empty($data)) {
// set up variable values
foreach ($data as $_key => $_val) {
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
}
}
$tpl->properties['tpl_function'] = $this->properties['tpl_function'];
return $tpl;
}
/**
* Template code runtime function to set up an inline subtemplate
*
* @param string $template the resource handle of the template file
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param integer $caching cache mode
* @param integer $cache_lifetime life time of cache data
* @param array $data passed parameter template variables
* @param int $parent_scope scope in which {include} should execute
* @param string $hash nocache hash code
* @param string $content_func name of content function
*
* @returns object template content
*/
public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash, $content_func)
{
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope);
$tpl->properties['nocache_hash'] = $hash;
if (!isset($this->smarty->template_objects[$tpl->templateId])) {
$this->smarty->template_objects[$tpl->templateId] = $tpl;
}
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_template($tpl);
Smarty_Internal_Debug::start_render($tpl);
}
$tpl->properties['unifunc'] = $content_func;
$output = $tpl->getRenderedTemplateCode();
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_template($tpl);
Smarty_Internal_Debug::end_render($tpl);
}
if (!empty($tpl->properties['file_dependency'])) {
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $tpl->properties['file_dependency']);
}
$this->properties['tpl_function'] = $tpl->properties['tpl_function'];
return str_replace($tpl->properties['nocache_hash'], $this->properties['nocache_hash'], $output);
}
/**
* Call template function
*
* @param string $name template function name
* @param object|\Smarty_Internal_Template $_smarty_tpl template object
* @param array $params parameter array
* @param bool $nocache true if called nocache
*
* @throws \SmartyException
*/
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
{
if (isset($_smarty_tpl->properties['tpl_function'][$name])) {
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
} else {
if (isset($_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'])) {
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'];
} else {
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
}
}
if (function_exists($function)) {
$function ($_smarty_tpl, $params);
return;
}
// try to load template function dynamically
if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) {
$function ($_smarty_tpl, $params);
return;
}
}
throw new SmartyException("Unable to find template function '{$name}'");
}
/**
* This function is executed automatically when a compiled or cached template file is included
* - Decode saved properties from compiled template and cache files
* - Check if compiled or cache file is valid
*
* @param array $properties special template properties
* @param bool $cache flag if called from cache file
*
* @return bool flag if compiled or cache file is valid
*/
public function decodeProperties($properties, $cache = false)
{
$properties['version'] = (isset($properties['version'])) ? $properties['version'] : '';
$is_valid = true;
if (Smarty::SMARTY_VERSION != $properties['version']) {
// new version must rebuild
$is_valid = false;
} elseif ((!$cache && $this->smarty->compile_check || $cache && ($this->smarty->compile_check === true || $this->smarty->compile_check === Smarty::COMPILECHECK_ON)) && !empty($properties['file_dependency'])) {
// check file dependencies at compiled code
foreach ($properties['file_dependency'] as $_file_to_check) {
if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') {
if ($this->source->filepath == $_file_to_check[0] && isset($this->source->timestamp)) {
// do not recheck current template
$mtime = $this->source->timestamp;
} else {
// file and php types can be checked without loading the respective resource handlers
$mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false;
}
} elseif ($_file_to_check[2] == 'string') {
continue;
} else {
$source = Smarty_Resource::source(null, $this->smarty, $_file_to_check[0]);
$mtime = $source->timestamp;
}
if (!$mtime || $mtime > $_file_to_check[1]) {
$is_valid = false;
break;
}
}
}
if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED &&
$properties['cache_lifetime'] >= 0 &&
(time() > ($this->cached->timestamp + $properties['cache_lifetime']))
) {
$is_valid = false;
}
$this->cached->valid = $is_valid;
} else {
$this->mustCompile = !$is_valid;
}
if ($is_valid) {
$this->has_nocache_code = $properties['has_nocache_code'];
// $this->properties['nocache_hash'] = $properties['nocache_hash'];
if (isset($properties['cache_lifetime'])) {
$this->properties['cache_lifetime'] = $properties['cache_lifetime'];
}
if (isset($properties['file_dependency'])) {
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $properties['file_dependency']);
}
if (isset($properties['tpl_function'])) {
$this->properties['tpl_function'] = array_merge($this->properties['tpl_function'], $properties['tpl_function']);
}
$this->properties['version'] = $properties['version'];
$this->properties['unifunc'] = $properties['unifunc'];
}
return $is_valid;
}
/**
* Template code runtime function to create a local Smarty variable for array assignments
*
* @param string $tpl_var template variable name
* @param bool $nocache cache mode of variable
* @param int $scope scope of variable
*/
public function createLocalArrayVariable($tpl_var, $nocache = false, $scope = Smarty::SCOPE_LOCAL)
{
if (!isset($this->tpl_vars[$tpl_var])) {
$this->tpl_vars[$tpl_var] = new Smarty_Variable(array(), $nocache, $scope);
} else {
$this->tpl_vars[$tpl_var] = clone $this->tpl_vars[$tpl_var];
if ($scope != Smarty::SCOPE_LOCAL) {
$this->tpl_vars[$tpl_var]->scope = $scope;
}
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
settype($this->tpl_vars[$tpl_var]->value, 'array');
}
}
}
/**
* Template code runtime function to get pointer to template variable array of requested scope
*
* @param int $scope requested variable scope
*
* @return array array of template variables
*/
public function &getScope($scope)
{
if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
return $this->parent->tpl_vars;
} elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
$ptr = $this->parent;
while (!empty($ptr->parent)) {
$ptr = $ptr->parent;
}
return $ptr->tpl_vars;
} elseif ($scope == Smarty::SCOPE_GLOBAL) {
return Smarty::$global_tpl_vars;
}
$null = null;
return $null;
}
/**
* Get parent or root of template parent chain
*
* @param int $scope parent or root scope
*
* @return mixed object
*/
public function getScopePointer($scope)
{
if ($scope == Smarty::SCOPE_PARENT && !empty($this->parent)) {
return $this->parent;
} elseif ($scope == Smarty::SCOPE_ROOT && !empty($this->parent)) {
$ptr = $this->parent;
while (!empty($ptr->parent)) {
$ptr = $ptr->parent;
}
return $ptr;
}
return null;
}
/**
* [util function] counts an array, arrayAccess/traversable or PDOStatement object
*
* @param mixed $value
*
* @return int the count for arrays and objects that implement countable, 1 for other objects that don't, and 0
* for empty elements
*/
public function _count($value)
{
if (is_array($value) === true || $value instanceof Countable) {
return count($value);
} elseif ($value instanceof IteratorAggregate) {
// Note: getIterator() returns a Traversable, not an Iterator
// thus rewind() and valid() methods may not be present
return iterator_count($value->getIterator());
} elseif ($value instanceof Iterator) {
return iterator_count($value);
} elseif ($value instanceof PDOStatement) {
return $value->rowCount();
} elseif ($value instanceof Traversable) {
return iterator_count($value);
} elseif ($value instanceof ArrayAccess) {
if ($value->offsetExists(0)) {
return 1;
}
} elseif (is_object($value)) {
return count($value);
}
return 0;
return isset($this->templateId) ? $this->templateId : $this->templateId =
$this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id);
}
/**
@ -763,33 +255,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\"");
}
/**
* Empty cache for this template
*
* @param integer $exp_time expiration time
*
* @return integer number of cache files deleted
*/
public function clearCache($exp_time = null)
{
Smarty_CacheResource::invalidLoadedCache($this->smarty);
return $this->cached->handler->clear($this->smarty, $this->template_resource, $this->cache_id, $this->compile_id, $exp_time);
}
/**
* Load source resource
*
* @throws SmartyException
*/
public function loadSource()
{
$this->source = Smarty_Template_Source::load($this);
if ($this->smarty->template_resource_caching && !$this->source->recompiled && isset($this->templateId)) {
$this->smarty->template_objects[$this->templateId] = $this;
}
}
/**
* Load compiled object
*
@ -797,9 +262,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function loadCompiled()
{
if (!isset($this->compiled)) {
if (!class_exists('Smarty_Template_Compiled', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_template_compiled.php';
}
$this->compiled = Smarty_Template_Compiled::load($this);
}
}
@ -811,9 +273,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function loadCached()
{
if (!isset($this->cached)) {
if (!class_exists('Smarty_Template_Cached', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_template_cached.php';
}
$this->cached = Smarty_Template_Cached::load($this);
}
}
@ -825,8 +284,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
*/
public function loadCompiler()
{
$this->smarty->loadPlugin($this->source->compiler_class);
$this->compiler = new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
if (!class_exists($this->source->handler->compiler_class)) {
$this->smarty->loadPlugin($this->source->handler->compiler_class);
}
$this->compiler = new $this->source->handler->compiler_class($this->source->handler->template_lexer_class,
$this->source->handler->template_parser_class,
$this->smarty);
}
/**
@ -859,7 +322,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function __set($property_name, $value)
{
switch ($property_name) {
case 'source':
case 'compiled':
case 'cached':
case 'compiler':
@ -886,10 +348,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
public function __get($property_name)
{
switch ($property_name) {
case 'source':
$this->loadSource();
return $this->source;
case 'compiled':
$this->loadCompiled();
return $this->compiled;

View File

@ -11,8 +11,32 @@
/**
* Class with shared template methods
*
* @package Smarty
* @subpackage Template
* @package Smarty
* @subpackage Template
*
* @property Smarty $smarty
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
* @method array getAutoloadFilters(string $type = null)
* @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null)
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
* @method string getDebugTemplate()
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
* @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers)
* @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
* @method array getDefaultModifier()
* @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback)
* @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterResource(string $name)
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
* @method object getRegisteredObject(string $object_name)
* @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getTags(mixed $template = null)
*/
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
{
@ -23,6 +47,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @var string
*/
public $cache_id = null;
/**
* Set this if you want different sets of compiled files for the same
* templates.
@ -30,12 +55,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
* @var string
*/
public $compile_id = null;
/**
* caching enabled
*
* @var boolean
*/
public $caching = false;
/**
* cache lifetime in seconds
*
@ -43,515 +70,247 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
*/
public $cache_lifetime = 3600;
/**
* universal cache
*
* @var array()
*/
public $_cache = array();
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @throws Exception
* @throws SmartyException
* @return string rendered template output
*/
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
return $result === null ? ob_get_clean() : $result;
}
/**
* displays a Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*/
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
// display template
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
}
/**
* test if cache is valid
*
* @param string|object $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @api Smarty::isCached()
* @link http://www.smarty.net/docs/en/api.is.cached.tpl
*
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
*
* @return boolean cache status
*/
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
{
if ($template === null && $this instanceof $this->template_class) {
$template = $this;
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
}
/**
* fetches a rendered Smarty template
*
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
*
* @return mixed
* @throws \Exception
* @throws \SmartyException
*/
private function _execute($template, $cache_id, $compile_id, $parent, $function)
{
$smarty = $this->_objType == 1 ? $this : $this->smarty;
if ($template === null) {
if ($this->_objType != 2) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = clone $this;
}
} elseif (is_object($template)) {
if (!isset($template->_objType) || $template->_objType != 2) {
throw new SmartyException($function . '():Template object expected');
} else {
/* @var Smarty_Internal_Template $template */
$template = clone $template;
}
} else {
if (!($template instanceof $this->template_class)) {
if ($parent === null) {
$parent = $this;
}
$smarty = isset($this->smarty) ? $this->smarty : $this;
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
// get template object
/* @var Smarty_Internal_Template $template */
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
if ($this->_objType == 1) {
// set caching in template object
$template->caching = $this->caching;
}
}
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
// fetch template content
$level = ob_get_level();
try {
$_smarty_old_error_level =
($this->_objType == 1 && isset($smarty->error_reporting)) ? error_reporting($smarty->error_reporting) :
null;
if ($function == 2) {
if ($template->caching) {
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
$result = $template->cached->isCached($template);
$template->smarty->_cache['isCached'][$template->_getTemplateId()] = $template;
} else {
return false;
}
} else {
ob_start();
$template->_mergeVars();
if (!empty(Smarty::$global_tpl_vars)) {
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
}
$result = $template->render(false, $function);
}
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
return $result;
}
return $template->cached->isCached($template);
}
/**
* creates a data object
*
* @param object $parent next higher level of Smarty variables
* @param string $name optional data block name
*
* @returns Smarty_Data data object
*/
public function createData($parent = null, $name = null)
{
$dataObj = new Smarty_Data($parent, $this, $name);
if ($this->debugging) {
Smarty_Internal_Debug::register_data($dataObj);
catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
}
return $dataObj;
}
/**
* Get unique template id
*
* @param string $template_name
* @param null|mixed $cache_id
* @param null|mixed $compile_id
*
* @return string
*/
public function getTemplateId($template_name, $cache_id = null, $compile_id = null)
{
$cache_id = isset($cache_id) ? $cache_id : $this->cache_id;
$compile_id = isset($compile_id) ? $compile_id : $this->compile_id;
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->allow_ambiguous_resources) {
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}";
} else {
$_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}";
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
return $_templateId;
}
/**
* Registers plugin to be used in templates
*
* @param string $type plugin type
* @param string $tag name of template tag
* @param callback $callback PHP callback to register
* @param boolean $cacheable if true (default) this fuction is cachable
* @param array $cache_attr caching attributes if any
* @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @param string $type plugin type
* @param string $name name of template tag
* @param callback $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
*
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException when the plugin tag is invalid
*/
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_plugins[$type][$tag])) {
throw new SmartyException("Plugin tag \"{$tag}\" already registered");
} elseif (!is_callable($callback)) {
throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
$smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
}
return $this;
}
/**
* Unregister Plugin
*
* @param string $type of plugin
* @param string $tag name of plugin
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterPlugin($type, $tag)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_plugins[$type][$tag])) {
unset($smarty->registered_plugins[$type][$tag]);
}
return $this;
}
/**
* Registers a resource to fetch a template
*
* @param string $type name of resource type
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource
* (deprecated)
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerResource($type, $callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
return $this;
}
/**
* Unregisters a resource
*
* @param string $type name of resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterResource($type)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_resources[$type])) {
unset($smarty->registered_resources[$type]);
}
return $this;
}
/**
* Registers a cache resource to cache a template's output
*
* @param string $type name of cache resource type
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerCacheResource($type, Smarty_CacheResource $callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_cache_resources[$type] = $callback;
return $this;
}
/**
* Unregisters a cache resource
*
* @param string $type name of cache resource type
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterCacheResource($type)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_cache_resources[$type])) {
unset($smarty->registered_cache_resources[$type]);
}
return $this;
}
/**
* Registers object to be used in templates
*
* @param $object_name
* @param object $object_impl the referenced PHP object to register
* @param array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
{
// test if allowed methods callable
if (!empty($allowed)) {
foreach ((array) $allowed as $method) {
if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
throw new SmartyException("Undefined method or property '$method' in registered object");
}
}
}
// test if block methods callable
if (!empty($block_methods)) {
foreach ((array) $block_methods as $method) {
if (!is_callable(array($object_impl, $method))) {
throw new SmartyException("Undefined method '$method' in registered object");
}
}
}
// register the object
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_objects[$object_name] =
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
return $this;
}
/**
* return a reference to a registered object
*
* @param string $name object name
*
* @return object
* @throws SmartyException if no such object is found
*/
public function getRegisteredObject($name)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (!isset($smarty->registered_objects[$name])) {
throw new SmartyException("'$name' is not a registered object");
}
if (!is_object($smarty->registered_objects[$name][0])) {
throw new SmartyException("registered '$name' is not an object");
}
return $smarty->registered_objects[$name][0];
}
/**
* unregister an object
*
* @param string $name object name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterObject($name)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_objects[$name])) {
unset($smarty->registered_objects[$name]);
}
return $this;
}
/**
* Registers static classes to be used in templates
*
* @param $class_name
* @param string $class_impl the referenced PHP class to register
*
* @throws SmartyException
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerClass($class_name, $class_impl)
{
// test if exists
if (!class_exists($class_impl)) {
throw new SmartyException("Undefined class '$class_impl' in register template class");
}
// register the class
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_classes[$class_name] = $class_impl;
return $this;
}
/**
* Registers a default plugin handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultPluginHandler($callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (is_callable($callback)) {
$smarty->default_plugin_handler_func = $callback;
} else {
throw new SmartyException("Default plugin handler '$callback' not callable");
}
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultTemplateHandler($callback)
{
Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultTemplateHandler($this, $callback);
return $this;
}
/**
* Registers a default template handler
*
* @param callable $callback class/method name
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @throws SmartyException if $callback is not callable
*/
public function registerDefaultConfigHandler($callback)
{
Smarty_Internal_Extension_DefaultTemplateHandler::registerDefaultConfigHandler($this, $callback);
return $this;
}
/**
* Registers a filter function
*
* @param string $type filter type
* @param callback $callback
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function registerFilter($type, $callback)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
return $this;
}
/**
* Unregisters a filter function
*
* @param string $type filter type
* @param callback $callback
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
*/
public function unregisterFilter($type, $callback)
{
$name = $this->_get_filter_name($callback);
$smarty = isset($this->smarty) ? $this->smarty : $this;
if (isset($smarty->registered_filters[$type][$name])) {
unset($smarty->registered_filters[$type][$name]);
}
return $this;
}
/**
* Return internal filter name
*
* @param callback $function_name
*
* @return string internal filter name
*/
public function _get_filter_name($function_name)
{
if (is_array($function_name)) {
$_class_name = (is_object($function_name[0]) ?
get_class($function_name[0]) : $function_name[0]);
return $_class_name . '_' . $function_name[1];
} else {
return $function_name;
}
return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr);
}
/**
* load a filter of specified type and name
*
* @api Smarty::loadFilter()
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
*
* @param string $type filter type
* @param string $name filter name
*
* @return bool
* @throws SmartyException if filter could not be loaded
*/
public function loadFilter($type, $name)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$_plugin = "smarty_{$type}filter_{$name}";
$_filter_name = $_plugin;
if ($smarty->loadPlugin($_plugin)) {
if (class_exists($_plugin, false)) {
$_plugin = array($_plugin, 'execute');
}
if (is_callable($_plugin)) {
$smarty->registered_filters[$type][$_filter_name] = $_plugin;
return true;
}
}
throw new SmartyException("{$type}filter \"{$name}\" not callable");
return $this->ext->loadFilter->loadFilter($this, $type, $name);
}
/**
* unload a filter of specified type and name
* Registers a filter function
*
* @param string $type filter type
* @param string $name filter name
* @api Smarty::registerFilter()
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
*
* @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or
* Smarty_Internal_Template) instance for chaining
* @param string $type filter type
* @param callback $callback
* @param string|null $name optional filter name
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
public function unloadFilter($type, $name)
public function registerFilter($type, $callback, $name = null)
{
$smarty = isset($this->smarty) ? $this->smarty : $this;
$_filter_name = "smarty_{$type}filter_{$name}";
if (isset($smarty->registered_filters[$type][$_filter_name])) {
unset ($smarty->registered_filters[$type][$_filter_name]);
}
return $this;
return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name);
}
/**
* preg_replace callback to convert camelcase getter/setter to underscore property names
* Registers object to be used in templates
*
* @param string $match match string
* @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl
*
* @return string replacemant
* @param string $object_name
* @param object $object the referenced PHP object to register
* @param array $allowed_methods_properties list of allowed methods (empty = all)
* @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
*/
private function replaceCamelcase($match)
public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true,
$block_methods = array())
{
return "_" . strtolower($match[1]);
return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties,
$format, $block_methods);
}
/**
* Handle unknown class methods
*
* @param string $name unknown method-name
* @param array $args argument array
*
* @throws SmartyException
* @param boolean $caching
*/
public function __call($name, $args)
public function setCaching($caching)
{
static $_prefixes = array('set' => true, 'get' => true);
static $_resolved_property_name = array();
static $_resolved_property_source = array();
// see if this is a set/get for a property
$first3 = strtolower(substr($name, 0, 3));
if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') {
if (isset($_resolved_property_name[$name])) {
$property_name = $_resolved_property_name[$name];
} else {
// try to keep case correct for future PHP 6.0 case-sensitive class methods
// lcfirst() not available < PHP 5.3.0, so improvise
$property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
// convert camel case to underscored name
$property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name);
$_resolved_property_name[$name] = $property_name;
}
if (isset($_resolved_property_source[$property_name])) {
$status = $_resolved_property_source[$property_name];
} else {
$status = null;
if (property_exists($this, $property_name)) {
$status = true;
} elseif (property_exists($this->smarty, $property_name)) {
$status = false;
}
$_resolved_property_source[$property_name] = $status;
}
$smarty = null;
if ($status === true) {
$smarty = $this;
} elseif ($status === false) {
$smarty = $this->smarty;
}
if ($smarty) {
if ($first3 == 'get') {
return $smarty->$property_name;
} else {
return $smarty->$property_name = $args[0];
}
}
throw new SmartyException("property '$property_name' does not exist.");
}
throw new SmartyException("Call of unknown method '$name'.");
$this->caching = $caching;
}
/**
* @param int $cache_lifetime
*/
public function setCacheLifetime($cache_lifetime)
{
$this->cache_lifetime = $cache_lifetime;
}
/**
* @param string $compile_id
*/
public function setCompileId($compile_id)
{
$this->compile_id = $compile_id;
}
/**
* @param string $cache_id
*/
public function setCacheId($cache_id)
{
$this->cache_id = $cache_id;
}
}

View File

@ -14,6 +14,11 @@
*
* @package Smarty
* @subpackage Compiler
*
* @property Smarty_Internal_SmartyTemplateCompiler $prefixCompiledCode = ''
* @property Smarty_Internal_SmartyTemplateCompiler $postfixCompiledCode = ''
* @method Smarty_Internal_SmartyTemplateCompiler registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
* @method Smarty_Internal_SmartyTemplateCompiler unregisterPostCompileCallback($key)
*/
abstract class Smarty_Internal_TemplateCompilerBase
{
@ -25,6 +30,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $smarty = null;
/**
* Parser object
*
* @var Smarty_Internal_Templateparser
*/
public $parser = null;
/**
* hash for nocache sections
*
@ -40,11 +52,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
public $suppressNocacheProcessing = false;
/**
* compile tag objects
* compile tag objects cache
*
* @var array
*/
public static $_tag_objects = array();
public $_tag_objects = array();
/**
* tag stack
@ -81,34 +93,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $templateProperties = array();
/**
* sources which must be compiled
*
* @var array
*/
public $sources = array();
/**
* flag that we are inside {block}
*
* @var bool
*/
public $inheritance = false;
/**
* flag when compiling inheritance child template
*
* @var bool
*/
public $inheritance_child = false;
/**
* uid of templates called by {extends} for recursion check
*
* @var array
*/
public $extends_uid = array();
/**
* source line offset for error messages
*
@ -158,27 +142,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $forceNocache = false;
/**
* suppress Smarty header code in compiled template
*
* @var bool
*/
public $suppressHeader = false;
/**
* suppress template property header code in compiled template
*
* @var bool
*/
public $suppressTemplatePropertyHeader = false;
/**
* suppress pre and post filter
*
* @var bool
*/
public $suppressFilter = false;
/**
* flag if compiled template file shall we written
*
@ -186,13 +149,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $write_compiled_code = true;
/**
* flag if currently a template function is compiled
*
* @var bool
*/
public $compiles_template_function = false;
/**
* called sub functions from template function
*
@ -201,11 +157,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
public $called_functions = array();
/**
* compiled template function code
* compiled template or block function code
*
* @var string
*/
public $templateFunctionCode = '';
public $blockOrFunctionCode = '';
/**
* php_handling setting either from Smarty or security
@ -249,13 +205,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $tag_nocache = false;
/**
* Flag to restart parsing
*
* @var bool
*/
public $abort_and_recompile = false;
/**
* Compiled tag prefix code
*
@ -291,6 +240,27 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $has_output = false;
/**
* Stack for {setfilter} {/setfilter}
*
* @var array
*/
public $variable_filter_stack = array();
/**
* variable filters for {setfilter} {/setfilter}
*
* @var array
*/
public $variable_filters = array();
/**
* Nesting count of looping tags like {foreach}, {for}, {section}, {while}
*
* @var int
*/
public $loopNesting = 0;
/**
* Strip preg pattern
*
@ -298,20 +268,38 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!';
/**
* plugin search order
*
* @var array
*/
public $plugin_search_order = array('function', 'block', 'compiler', 'class');
/**
* General storage area for tag compiler plugins
*
* @var array
*/
public $_cache = array();
/**
* method to compile a Smarty template
*
* @param mixed $_content template source
* @param mixed $_content template source
* @param bool $isTemplateSource
*
* @return bool true if compiling succeeded, false if it failed
* @return bool true if compiling succeeded, false if it failed
*/
abstract protected function doCompile($_content);
abstract protected function doCompile($_content, $isTemplateSource = false);
/**
* Initialize compiler
*
* @param Smarty $smarty global instance
*/
public function __construct()
public function __construct(Smarty $smarty)
{
$this->smarty = $smarty;
$this->nocache_hash = str_replace(array('.', ','), '_', uniqid(rand(), true));
}
@ -323,116 +311,139 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return bool true if compiling succeeded, false if it failed
* @throws \Exception
*/
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null)
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null,
Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
{
// save template object in compiler class
$this->template = $template;
if (isset($this->template->smarty->security_policy)) {
$this->php_handling = $this->template->smarty->security_policy->php_handling;
} else {
$this->php_handling = $this->template->smarty->php_handling;
}
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false;
if (empty($template->properties['nocache_hash'])) {
$template->properties['nocache_hash'] = $this->nocache_hash;
} else {
$this->nocache_hash = $template->properties['nocache_hash'];
}
$save_source = $this->template->source;
// template header code
$template_header = '';
if (!$this->suppressHeader) {
$template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n";
$template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n";
}
// get code frame of compiled template
$_compiled_code = $template->smarty->ext->_codeFrame->create($template,
$this->compileTemplateSource($template, $nocache,
$parent_compiler),
$this->postFilter($this->blockOrFunctionCode) .
join('', $this->mergedSubTemplatesCode));
return $_compiled_code;
}
if (empty($this->template->source->components)) {
$this->sources = array($template->source);
} else {
// we have array of inheritance templates by extends: resource
$this->sources = array_reverse($template->source->components);
}
$loop = 0;
// the $this->sources array can get additional elements while compiling by the {extends} tag
while ($this->template->source = array_shift($this->sources)) {
/**
* Compile template source and run optional post filter
*
* @param \Smarty_Internal_Template $template
* @param null|bool $nocache flag if template must be compiled in nocache mode
* @param \Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return string
* @throws \Exception
*/
public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null,
Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
{
try {
// save template object in compiler class
$this->template = $template;
if (property_exists($this->template->smarty, 'plugin_search_order')) {
$this->plugin_search_order = $this->template->smarty->plugin_search_order;
}
if ($this->smarty->debugging) {
$this->smarty->_debug->start_compile($this->template);
}
if (isset($this->template->smarty->security_policy)) {
$this->php_handling = $this->template->smarty->security_policy->php_handling;
} else {
$this->php_handling = $this->template->smarty->php_handling;
}
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
$nocache = isset($nocache) ? $nocache : false;
if (empty($template->compiled->nocache_hash)) {
$template->compiled->nocache_hash = $this->nocache_hash;
} else {
$this->nocache_hash = $template->compiled->nocache_hash;
}
// flag for nocache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
// reset has nocache code flag
$this->template->compiled->has_nocache_code = false;
$this->has_variable_string = false;
$this->prefix_code = array();
// add file dependency
$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;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
$no_sources = count($this->sources);
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type);
$loop ++;
if ($no_sources) {
$this->inheritance_child = true;
// get template source
if (!empty($this->template->source->components)) {
// we have array of inheritance templates by extends: resource
// generate corresponding source code sequence
$_content =
Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components);
} else {
$this->inheritance_child = false;
}
do {
// flag for nochache sections
$this->nocache = $nocache;
$this->tag_nocache = false;
// reset has nocache code flag
$this->template->has_nocache_code = false;
$this->has_variable_string = false;
$this->prefix_code = array();
$_compiled_code = '';
// flag for aborting current and start recompile
$this->abort_and_recompile = false;
// get template source
$_content = $this->template->source->content;
if ($_content != '') {
// run prefilter if required
if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) {
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template);
}
// call compiler
$_compiled_code = $this->doCompile($_content, true);
}
} while ($this->abort_and_recompile);
$_content = $this->template->source->getContent();
}
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
}
catch (Exception $e) {
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this->template);
$this->smarty->_debug->end_compile($this->template);
}
$this->_tag_stack = array();
$this->_tag_objects = array();
// free memory
$this->parent_compiler = null;
$this->template = null;
$this->parser = null;
throw $e;
}
// restore source
$this->template->source = $save_source;
unset($save_source);
$this->smarty->_current_file = $this->template->source->filepath;
// free memory
unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex);
self::$_tag_objects = array();
// return compiled code to template object
$merged_code = '';
if (!empty($this->mergedSubTemplatesCode)) {
foreach ($this->mergedSubTemplatesCode as $code) {
$merged_code .= $code;
}
if ($this->smarty->debugging) {
$this->smarty->_debug->end_compile($this->template);
}
// run postfilter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') {
$_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template);
}
if ($this->suppressTemplatePropertyHeader) {
$_compiled_code .= $merged_code;
} else {
$_compiled_code = $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code;
}
if (!empty($this->templateFunctionCode)) {
// run postfilter if required on compiled template code
if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter) {
$_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template);
} else {
$_compiled_code .= $this->templateFunctionCode;
}
}
// unset content because template inheritance could have replace source with parent code
unset ($template->source->content);
$this->parent_compiler = null;
$this->template = null;
$this->parser = null;
return $_compiled_code;
}
/**
* Optionally process compiled code by post filter
*
* @param string $code compiled code
*
* @return string
* @throws \SmartyException
*/
public function postFilter($code)
{
// run post filter if on code
if (!empty($code) &&
(isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post']))
) {
return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
} else {
return $code;
}
}
/**
* Run optional prefilter
*
* @param string $_content template source
*
* @return string
* @throws \SmartyException
*/
public function preFilter($_content)
{
// run pre filter if required
if ($_content != '' &&
((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])))
) {
return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
} else {
return $_content;
}
}
/**
* Compile Tag
* This is a call back from the lexer/parser
@ -478,17 +489,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->has_code = true;
$this->has_output = false;
// log tag/attributes
if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
$this->template->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) || in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)
if (in_array("'nocache'", $args) || in_array(array('nocache' => 'true'), $args) ||
in_array(array('nocache' => '"true"'), $args) || in_array(array('nocache' => "'true'"), $args)
) {
$this->tag_nocache = true;
}
// compile the smarty tag (required compile classes to compile the tag are autoloaded)
// 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->templateProperties['tpl_function'][$tag])) {
if (isset($this->parent_compiler->template->tpl_function[$tag])) {
// template defined by {template} tag
$args['_attr']['name'] = "'" . $tag . "'";
$_output = $this->callTagCompiler('call', $args, $parameter);
@ -522,18 +534,23 @@ abstract class Smarty_Internal_TemplateCompilerBase
// 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 (!in_array($method, $this->smarty->registered_objects[$tag][3]) &&
(empty($this->smarty->registered_objects[$tag][1]) ||
in_array($method, $this->smarty->registered_objects[$tag][1]))
) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
} elseif (in_array($method, $this->smarty->registered_objects[$tag][3])) {
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag, $method);
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
$method);
} else {
// throw exception
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' . $tag . '"', $this->lex->taglineno);
$this->trigger_template_error('not allowed method "' . $method . '" in registered object "' .
$tag . '"', null, true);
}
}
// check if tag is registered
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type) {
foreach (array(Smarty::PLUGIN_COMPILER, Smarty::PLUGIN_FUNCTION, Smarty::PLUGIN_BLOCK) as $plugin_type)
{
if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
// if compiler function plugin call it now
if ($plugin_type == Smarty::PLUGIN_COMPILER) {
@ -552,20 +569,26 @@ abstract class Smarty_Internal_TemplateCompilerBase
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);
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));
}
}
// compile registered function or block function
if ($plugin_type == Smarty::PLUGIN_FUNCTION || $plugin_type == Smarty::PLUGIN_BLOCK) {
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter,
$tag);
}
}
}
// check plugins from plugins folder
foreach ($this->smarty->plugin_search_order as $plugin_type) {
if ($plugin_type == Smarty::PLUGIN_COMPILER && $this->smarty->loadPlugin('smarty_compiler_' . $tag) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))) {
foreach ($this->plugin_search_order as $plugin_type) {
if ($plugin_type == Smarty::PLUGIN_COMPILER &&
$this->smarty->loadPlugin('smarty_compiler_' . $tag) &&
(!isset($this->smarty->security_policy) ||
$this->smarty->security_policy->isTrustedTag($tag, $this))
) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
// convert arguments format for old compiler plugins
@ -589,8 +612,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
throw new SmartyException("Plugin \"{$tag}\" not callable");
} else {
if ($function = $this->getPlugin($tag, $plugin_type)) {
if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter, $tag, $function);
if (!isset($this->smarty->security_policy) ||
$this->smarty->security_policy->isTrustedTag($tag, $this)
) {
return $this->callTagCompiler('private_' . $plugin_type . '_plugin', $args, $parameter,
$tag, $function);
}
}
}
@ -598,7 +624,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (is_callable($this->smarty->default_plugin_handler_func)) {
$found = false;
// look for already resolved tags
foreach ($this->smarty->plugin_search_order as $plugin_type) {
foreach ($this->plugin_search_order as $plugin_type) {
if (isset($this->default_handler_plugins[$plugin_type][$tag])) {
$found = true;
break;
@ -606,7 +632,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
if (!$found) {
// call default handler
foreach ($this->smarty->plugin_search_order as $plugin_type) {
foreach ($this->plugin_search_order as $plugin_type) {
if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) {
$found = true;
break;
@ -624,12 +650,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
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);
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));
}
} else {
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter, $tag);
return $this->callTagCompiler('private_registered_' . $plugin_type, $args, $parameter,
$tag);
}
}
}
@ -640,20 +668,36 @@ abstract class Smarty_Internal_TemplateCompilerBase
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);
return $this->callTagCompiler('private_object_block_function', $args, $parameter, $tag,
$method);
} else {
// throw exception
$this->trigger_template_error('not allowed closing tag method "' . $method . '" in registered object "' . $base_tag . '"', $this->lex->taglineno);
$this->trigger_template_error('not allowed closing tag method "' . $method .
'" in registered object "' . $base_tag . '"', null, true);
}
}
// registered block tag ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) || isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag]) ||
isset($this->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag])
) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
}
// registered function tag ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag);
}
// block plugin?
if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) {
return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function);
}
// function plugin?
if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) {
if (!isset($this->smarty->security_policy) ||
$this->smarty->security_policy->isTrustedTag($tag, $this)
) {
return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function);
}
}
// registered compiler plugin ?
if (isset($this->smarty->registered_plugins[Smarty::PLUGIN_COMPILER][$tag])) {
// if compiler function plugin call it now
@ -665,7 +709,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
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);
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));
}
@ -684,7 +729,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
throw new SmartyException("Plugin \"{$tag}\" not callable");
}
}
$this->trigger_template_error("unknown tag \"" . $tag . "\"", $this->lex->taglineno);
$this->trigger_template_error("unknown tag \"" . $tag . "\"", null, true);
}
}
@ -700,12 +745,26 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (strpos($variable, '(') == 0) {
// not a variable variable
$var = trim($variable, '\'');
$this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache;
$this->template->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
$this->tag_nocache = $this->tag_nocache |
$this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache;
// todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
}
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
}
/**
* compile config variable
*
* @param string $variable
*
* @return string
*/
public function compileConfigVariable($variable)
{
// return '$_smarty_tpl->config_vars[' . $variable . ']';
return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')';
}
/**
* This method is called from parser to process a text content section
* - remove text from inheritance child templates as they may generate output
@ -718,9 +777,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function processText($text)
{
if ($this->parser->strip) {
return new Smarty_Internal_ParseTree_Text($this->parser, preg_replace($this->stripRegEx, '', $text));
return new Smarty_Internal_ParseTree_Text(preg_replace($this->stripRegEx, ' ', $text));
} else {
return new Smarty_Internal_ParseTree_Text($this->parser, $text);
return new Smarty_Internal_ParseTree_Text($text);
}
}
@ -728,7 +787,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
* lazy loads internal compile plugin for tag and calls the compile method
* compile objects cached for reuse.
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_Tagname.php
* plugin filename format: Smarty_Internal_TagName.php
*
* @param string $tag tag name
* @param array $args list of tag attributes
@ -740,23 +799,24 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null)
{
// check if tag allowed by security
if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
// re-use object if already exists
if (!isset(self::$_tag_objects[$tag])) {
// lazy load internal compiler plugin
$class_name = 'Smarty_Internal_Compile_' . $tag;
if ($this->smarty->loadPlugin($class_name)) {
self::$_tag_objects[$tag] = new $class_name;
} else {
return false;
}
// re-use object if already exists
if (!isset($this->_tag_objects[$tag])) {
// lazy load internal compiler plugin
$_tag = explode('_', $tag);
$_tag = array_map('ucfirst', $_tag);
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
if (class_exists($class_name) &&
(!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
) {
$this->_tag_objects[$tag] = new $class_name;
} else {
$this->_tag_objects[$tag] = false;
return false;
}
// compile this tag
return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
}
// no internal compile plugin for this tag
return false;
// compile this tag
return $this->_tag_objects[$tag] === false ? false :
$this->_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
}
/**
@ -771,18 +831,24 @@ abstract class Smarty_Internal_TemplateCompilerBase
{
$function = null;
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
$function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
} elseif (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type];
$function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
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];
$function =
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
}
} else {
if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
$function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
} elseif (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type];
$function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
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];
$function =
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
}
}
if (isset($function)) {
@ -798,11 +864,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (is_string($file)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
$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'] =
$function;
} else {
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file;
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
$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'] =
$function;
}
if ($plugin_type == 'modifier') {
$this->modifier_plugins[$plugin_name] = true;
@ -831,17 +901,22 @@ abstract class Smarty_Internal_TemplateCompilerBase
$callback = null;
$script = null;
$cacheable = true;
$result = call_user_func_array($this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
$result = call_user_func_array($this->smarty->default_plugin_handler_func,
array($tag, $plugin_type, $this->template, &$callback, &$script, &$cacheable));
if ($result) {
$this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) {
if (is_file($script)) {
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
$this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script;
$this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback;
$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'] =
$callback;
} else {
$this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script;
$this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
$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'] =
$callback;
}
require_once $script;
} else {
@ -898,16 +973,19 @@ abstract class Smarty_Internal_TemplateCompilerBase
// If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) {
// generate replacement code
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->template->caching &&
!$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
) {
$this->template->has_nocache_code = true;
$this->template->compiled->has_nocache_code = true;
$_output = addcslashes($content, '\'\\');
$_output = str_replace("^#^", "'", $_output);
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output .
"/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
// make sure we include modifier plugins for nocache code
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
$this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->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 {
@ -923,6 +1001,36 @@ abstract class Smarty_Internal_TemplateCompilerBase
return $_output;
}
/**
* Get Id
*
* @param string $input
*
* @return bool|string
*/
public function getId($input)
{
if (preg_match('~^[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*$~', $input, $match)) {
return $match[1];
}
return false;
}
/**
* Get variable name from string
*
* @param string $input
*
* @return bool|string
*/
public function getVariableName($input)
{
if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) {
return $match[1];
}
return false;
}
/**
* Generate nocache code string
*
@ -932,47 +1040,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function makeNocacheCode($code)
{
return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " . str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
}
/**
* push current file and line offset on stack for tracing {block} source lines
*
* @param string $file new filename
* @param string $uid uid of file
* @param int $line line offset to source
* @param bool $debug false debug end_compile shall not be called
*/
public function pushTrace($file, $uid, $line, $debug = true)
{
if ($this->smarty->debugging && $debug) {
Smarty_Internal_Debug::end_compile($this->template);
}
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid, $this->trace_line_offset));
$this->trace_filepath = $this->smarty->_current_file = $file;
$this->trace_uid = $uid;
$this->trace_line_offset = $line;
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
}
/**
* restore file and line offset
*/
public function popTrace()
{
if ($this->smarty->debugging) {
Smarty_Internal_Debug::end_compile($this->template);
}
$r = array_pop($this->trace_stack);
$this->smarty->_current_file = $r[0];
$this->trace_filepath = $r[1];
$this->trace_uid = $r[2];
$this->trace_line_offset = $r[3];
if ($this->smarty->debugging) {
Smarty_Internal_Debug::start_compile($this->template);
}
return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/<?php " .
str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
}
/**
@ -981,33 +1050,53 @@ abstract class Smarty_Internal_TemplateCompilerBase
* In this case the parser is called to obtain information about expected tokens.
* If parameter $args contains a string this is used as error message
*
* @param string $args individual error message or null
* @param string $line line-number
* @param string $args individual error message or null
* @param string $line line-number
* @param null|bool $tagline if true the line number of last tag
*
* @throws SmartyCompilerException when an unexpected token is found
* @throws \SmartyCompilerException when an unexpected token is found
*/
public function trigger_template_error($args = null, $line = null)
public function trigger_template_error($args = null, $line = null, $tagline = null)
{
// get template source line which has error
if (!isset($line)) {
$line = $this->lex->line;
$lex = $this->parser->lex;
if ($tagline === true) {
// get line number of Tag
$line = $lex->taglineno;
} elseif (!isset($line)) {
// get template source line which has error
$line = $lex->line;
} else {
$line = (int) $line;
}
if (in_array($this->template->source->type, array('eval', 'string'))) {
$templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!', ' ',
strlen($lex->data) > 40 ?
substr($lex->data, 0, 40) .
'...' : $lex->data));
} else {
$templateName = $this->template->source->type . ':' . $this->template->source->filepath;
}
// $line += $this->trace_line_offset;
$match = preg_split("/\n/", $this->lex->data);
$error_text = 'Syntax error in template "' . (empty($this->trace_filepath) ? $this->template->source->filepath : $this->trace_filepath) . '" on line ' . ($line + $this->trace_line_offset) . ' "' . trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" ';
$match = preg_split("/\n/", $lex->data);
$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])) . '" ';
if (isset($args)) {
// individual error message
$error_text .= $args;
} else {
$expect = array();
// expected token from parser
$error_text .= ' - Unexpected "' . $this->lex->value . '"';
$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($this->lex->smarty_token_names[$exp_token])) {
if (isset($lex->smarty_token_names[$exp_token])) {
// token type from lexer
$expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
$expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"';
} else {
// otherwise internal token name
$expect[] = $this->parser->yyTokenName[$token];

View File

@ -7,6 +7,7 @@
* @subpackage Utilities
* @author Uwe Tews
*/
/**
* TestInstall class
*
@ -19,8 +20,7 @@ class Smarty_Internal_TestInstall
* diagnose Smarty setup
* If $errors is secified, the diagnostic report will be appended to the array, rather than being output.
*
* @param Smarty $smarty Smarty instance to test
* @param array $errors array to push results into rather than outputting them
* @param array $errors array to push results into rather than outputting them
*
* @return bool status, true if everything is fine, false else
*/
@ -47,7 +47,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) {
$template_dir = stream_resolve_include_path($_template_dir);
} else {
$template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir);
$template_dir = $smarty->ext->_getIncludePath->getIncludePath($_template_dir, null, $smarty);
}
if ($template_dir !== false) {
@ -58,7 +58,8 @@ class Smarty_Internal_TestInstall
continue;
} else {
$status = false;
$message = "FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
$message =
"FAILED: $_template_dir does not exist (and couldn't be found in include_path either)";
if ($errors === null) {
echo $message . ".\n";
} else {
@ -166,7 +167,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) {
$plugin_dir = stream_resolve_include_path($_plugin_dir);
} else {
$plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir);
$plugin_dir = $smarty->ext->_getIncludePath->getIncludePath($_plugin_dir, null, $smarty);
}
if ($plugin_dir !== false) {
@ -288,7 +289,6 @@ class Smarty_Internal_TestInstall
// test if all registered config_dir are accessible
foreach ($smarty->getConfigDir() as $config_dir) {
$_config_dir = $config_dir;
$config_dir = realpath($config_dir);
// resolve include_path or fail existence
if (!$config_dir) {
if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) {
@ -296,7 +296,7 @@ class Smarty_Internal_TestInstall
if ($_stream_resolve_include_path) {
$config_dir = stream_resolve_include_path($_config_dir);
} else {
$config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir);
$config_dir = $smarty->ext->_getIncludePath->getIncludePath($_config_dir, null, $smarty);
}
if ($config_dir !== false) {
@ -358,106 +358,164 @@ class Smarty_Internal_TestInstall
// test if sysplugins are available
$source = SMARTY_SYSPLUGINS_DIR;
if (is_dir($source)) {
$expected = array(
"smarty_cacheresource.php" => true,
"smarty_cacheresource_custom.php" => true,
"smarty_cacheresource_keyvaluestore.php" => true,
"smarty_data.php" => true,
"smarty_internal_cacheresource_file.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_nocache.php" => true,
"smarty_internal_compile_private_block_plugin.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_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_while.php" => true,
"smarty_internal_compilebase.php" => true,
"smarty_internal_config_file_compiler.php" => true,
"smarty_internal_configfilelexer.php" => true,
"smarty_internal_configfileparser.php" => true,
"smarty_internal_data.php" => true,
"smarty_internal_debug.php" => true,
"smarty_internal_extension_codeframe.php" => true,
"smarty_internal_extension_config.php" => true,
"smarty_internal_extension_defaulttemplatehandler.php" => true,
"smarty_internal_filter_handler.php" => true,
"smarty_internal_function_call_handler.php" => true,
"smarty_internal_get_include_path.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_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_utility.php" => true,
"smarty_internal_write_file.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_source.php" => true,
"smarty_undefined_variable.php" => true,
"smarty_variable.php" => true,
"smartycompilerexception.php" => true,
"smartyexception.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_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_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_extension_clear.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_getconfigvars.php' => true,
'smarty_internal_method_getdebugtemplate.php' => true,
'smarty_internal_method_getdefaultmodifiers.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_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_codeframe.php' => true,
'smarty_internal_runtime_filterhandler.php' => true,
'smarty_internal_runtime_foreach.php' => true,
'smarty_internal_runtime_getincludepath.php' => true,
'smarty_internal_runtime_hhvm.php' => true,
'smarty_internal_runtime_inheritance.php' => true,
'smarty_internal_runtime_iscached.php' => true,
'smarty_internal_runtime_subtemplate.php' => true,
'smarty_internal_runtime_tplfunction.php' => true,
'smarty_internal_runtime_updatecache.php' => true,
'smarty_internal_runtime_updatescope.php' => true,
'smarty_internal_runtime_validatecompiled.php' => true,
'smarty_internal_runtime_var.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()) {
$filename = $file->getFilename();
if (isset($expected[$filename])) {
unset($expected[$filename]);
if (isset($expectedSysplugins[$filename])) {
unset($expectedSysplugins[$filename]);
}
}
}
if ($expected) {
if ($expectedSysplugins) {
$status = false;
$message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expected));
$message = "FAILED: files missing from libs/sysplugins: " . join(', ', array_keys($expectedSysplugins));
if ($errors === null) {
echo $message . ".\n";
} else {
@ -482,67 +540,43 @@ class Smarty_Internal_TestInstall
// test if core plugins are available
$source = SMARTY_PLUGINS_DIR;
if (is_dir($source)) {
$expected = array(
"block.textformat.php" => true,
"function.counter.php" => true,
"function.cycle.php" => true,
"function.fetch.php" => true,
"function.html_checkboxes.php" => true,
"function.html_image.php" => true,
"function.html_options.php" => true,
"function.html_radios.php" => true,
"function.html_select_date.php" => true,
"function.html_select_time.php" => true,
"function.html_table.php" => true,
"function.mailto.php" => true,
"function.math.php" => true,
"modifier.capitalize.php" => true,
"modifier.date_format.php" => true,
"modifier.debug_print_var.php" => true,
"modifier.escape.php" => true,
"modifier.regex_replace.php" => true,
"modifier.replace.php" => true,
"modifier.spacify.php" => true,
"modifier.truncate.php" => true,
"modifiercompiler.cat.php" => true,
"modifiercompiler.count_characters.php" => true,
"modifiercompiler.count_paragraphs.php" => true,
"modifiercompiler.count_sentences.php" => true,
"modifiercompiler.count_words.php" => true,
"modifiercompiler.default.php" => true,
"modifiercompiler.escape.php" => true,
"modifiercompiler.from_charset.php" => true,
"modifiercompiler.indent.php" => true,
"modifiercompiler.lower.php" => true,
"modifiercompiler.noprint.php" => true,
"modifiercompiler.string_format.php" => true,
"modifiercompiler.strip.php" => true,
"modifiercompiler.strip_tags.php" => true,
"modifiercompiler.to_charset.php" => true,
"modifiercompiler.unescape.php" => true,
"modifiercompiler.upper.php" => true,
"modifiercompiler.wordwrap.php" => true,
"outputfilter.trimwhitespace.php" => true,
"shared.escape_special_chars.php" => true,
"shared.literal_compiler_param.php" => true,
"shared.make_timestamp.php" => true,
"shared.mb_str_replace.php" => true,
"shared.mb_unicode.php" => true,
"shared.mb_wordwrap.php" => true,
"variablefilter.htmlspecialchars.php" => true,
);
$expectedPlugins =
array('block.textformat.php' => true, 'function.counter.php' => true,
'function.cycle.php' => true, 'function.fetch.php' => true,
'function.html_checkboxes.php' => true, 'function.html_image.php' => true,
'function.html_options.php' => true, 'function.html_radios.php' => true,
'function.html_select_date.php' => true, 'function.html_select_time.php' => true,
'function.html_table.php' => true, 'function.mailto.php' => true,
'function.math.php' => true, 'modifier.capitalize.php' => true,
'modifier.date_format.php' => true, 'modifier.debug_print_var.php' => true,
'modifier.escape.php' => true, 'modifier.regex_replace.php' => true,
'modifier.replace.php' => true, 'modifier.spacify.php' => true,
'modifier.truncate.php' => true, 'modifiercompiler.cat.php' => true,
'modifiercompiler.count_characters.php' => true, 'modifiercompiler.count_paragraphs.php' => true,
'modifiercompiler.count_sentences.php' => true, 'modifiercompiler.count_words.php' => true,
'modifiercompiler.default.php' => true, 'modifiercompiler.escape.php' => true,
'modifiercompiler.from_charset.php' => true, 'modifiercompiler.indent.php' => true,
'modifiercompiler.lower.php' => true, 'modifiercompiler.noprint.php' => true,
'modifiercompiler.string_format.php' => true, 'modifiercompiler.strip.php' => true,
'modifiercompiler.strip_tags.php' => true, 'modifiercompiler.to_charset.php' => true,
'modifiercompiler.unescape.php' => true, 'modifiercompiler.upper.php' => true,
'modifiercompiler.wordwrap.php' => true, 'outputfilter.trimwhitespace.php' => true,
'shared.escape_special_chars.php' => true, 'shared.literal_compiler_param.php' => true,
'shared.make_timestamp.php' => true, 'shared.mb_str_replace.php' => true,
'shared.mb_unicode.php' => true, 'shared.mb_wordwrap.php' => true,
'variablefilter.htmlspecialchars.php' => true,);
$iterator = new DirectoryIterator($source);
foreach ($iterator as $file) {
if (!$file->isDot()) {
$filename = $file->getFilename();
if (isset($expected[$filename])) {
unset($expected[$filename]);
if (isset($expectedPlugins[$filename])) {
unset($expectedPlugins[$filename]);
}
}
}
if ($expected) {
if ($expectedPlugins) {
$status = false;
$message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expected));
$message = "FAILED: files missing from libs/plugins: " . join(', ', array_keys($expectedPlugins));
if ($errors === null) {
echo $message . ".\n";
} else {

View File

@ -1,303 +0,0 @@
<?php
/**
* Project: Smarty: the PHP compiling template engine
* File: smarty_internal_utility.php
* SVN: $Id: $
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* For questions, help, comments, discussion, etc., please join the
* Smarty mailing list. Send a blank e-mail to
* smarty-discussion-subscribe@googlegroups.com
*
* @link http://www.smarty.net/
* @copyright 2008 New Digital Group, Inc.
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
* @package Smarty
* @subpackage PluginsInternal
* @version 3-SVN$Rev: 3286 $
*/
/**
* Utility class
*
* @package Smarty
* @subpackage Security
*/
class Smarty_Internal_Utility
{
/**
* private constructor to prevent calls creation of new instances
*/
final private function __construct()
{
// intentionally left blank
}
/**
* Compile all template files
*
* @param string $extension template file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
*
* @return integer number of template files compiled
*/
public static function compileAllTemplates($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
{
// switch off time limit
if (function_exists('set_time_limit')) {
@set_time_limit($time_limit);
}
$smarty->force_compile = $force_compile;
$_count = 0;
$_error_count = 0;
// loop over array of template directories
foreach ($smarty->getTemplateDir() as $_dir) {
$_compileDirs = new RecursiveDirectoryIterator($_dir);
$_compile = new RecursiveIteratorIterator($_compileDirs);
foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
continue;
}
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
$_template_file = $_file;
} else {
$_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
}
echo '<br>', $_dir, '---', $_template_file;
flush();
$_start_time = microtime(true);
try {
$_tpl = $smarty->createTemplate($_template_file, null, null, null, false);
if ($_tpl->mustCompile()) {
$_tpl->compileTemplateSource();
$_count ++;
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
}
catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count ++;
}
// free memory
$smarty->template_objects = array();
$_tpl->smarty->template_objects = array();
$_tpl = null;
if ($max_errors !== null && $_error_count == $max_errors) {
echo '<br><br>too many errors';
exit();
}
}
}
return $_count;
}
/**
* Compile all config files
*
* @param string $extension config file name extension
* @param bool $force_compile force all to recompile
* @param int $time_limit set maximum execution time
* @param int $max_errors set maximum allowed errors
* @param Smarty $smarty Smarty instance
*
* @return integer number of config files compiled
*/
public static function compileAllConfig($extension, $force_compile, $time_limit, $max_errors, Smarty $smarty)
{
// switch off time limit
if (function_exists('set_time_limit')) {
@set_time_limit($time_limit);
}
$smarty->force_compile = $force_compile;
$_count = 0;
$_error_count = 0;
// loop over array of template directories
foreach ($smarty->getConfigDir() as $_dir) {
$_compileDirs = new RecursiveDirectoryIterator($_dir);
$_compile = new RecursiveIteratorIterator($_compileDirs);
foreach ($_compile as $_fileinfo) {
$_file = $_fileinfo->getFilename();
if (substr(basename($_fileinfo->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
if (!substr_compare($_file, $extension, - strlen($extension)) == 0) {
continue;
}
if ($_fileinfo->getPath() == substr($_dir, 0, - 1)) {
$_config_file = $_file;
} else {
$_config_file = substr($_fileinfo->getPath(), strlen($_dir)) . DS . $_file;
}
echo '<br>', $_dir, '---', $_config_file;
flush();
$_start_time = microtime(true);
try {
$_config = new Smarty_Internal_Config($_config_file, $smarty);
if ($_config->mustCompile()) {
$_config->compileConfigSource();
$_count ++;
echo ' compiled in ', microtime(true) - $_start_time, ' seconds';
flush();
} else {
echo ' is up to date';
flush();
}
}
catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "<br><br>";
$_error_count ++;
}
if ($max_errors !== null && $_error_count == $max_errors) {
echo '<br><br>too many errors';
exit();
}
}
}
return $_count;
}
/**
* Delete compiled template file
*
* @param string $resource_name template name
* @param string $compile_id compile id
* @param integer $exp_time expiration time
* @param Smarty $smarty Smarty instance
*
* @return integer number of template files deleted
*/
public static function clearCompiledTemplate($resource_name, $compile_id, $exp_time, Smarty $smarty)
{
$_compile_dir = realpath($smarty->getCompileDir()) . '/';
if ($_compile_dir == '/') { //We should never want to delete this!
return 0;
}
$_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!', '_', $compile_id) : null;
$_dir_sep = $smarty->use_sub_dirs ? '/' : '^';
if (isset($resource_name)) {
$_save_stat = $smarty->caching;
$smarty->caching = false;
$tpl = new $smarty->template_class($resource_name, $smarty);
$smarty->caching = $_save_stat;
// remove from template cache
$tpl->source; // have the template registered before unset()
if ($smarty->allow_ambiguous_resources) {
$_templateId = $tpl->source->unique_resource . $tpl->cache_id . $tpl->compile_id;
} else {
$_templateId = $smarty->joined_template_dir . '#' . $resource_name . $tpl->cache_id . $tpl->compile_id;
}
if (isset($_templateId[150])) {
$_templateId = sha1($_templateId);
}
unset($smarty->template_objects[$_templateId]);
if ($tpl->source->exists) {
$_resource_part_1 = basename(str_replace('^', '/', $tpl->compiled->filepath));
$_resource_part_1_length = strlen($_resource_part_1);
} else {
return 0;
}
$_resource_part_2 = str_replace('.php', '.cache.php', $_resource_part_1);
$_resource_part_2_length = strlen($_resource_part_2);
}
$_dir = $_compile_dir;
if ($smarty->use_sub_dirs && isset($_compile_id)) {
$_dir .= $_compile_id . $_dir_sep;
}
if (isset($_compile_id)) {
$_compile_id_part = str_replace('\\', '/', $_compile_dir . $_compile_id . $_dir_sep);
$_compile_id_part_length = strlen($_compile_id_part);
}
$_count = 0;
try {
$_compileDirs = new RecursiveDirectoryIterator($_dir);
// NOTE: UnexpectedValueException thrown for PHP >= 5.3
}
catch (Exception $e) {
return 0;
}
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
foreach ($_compile as $_file) {
if (substr(basename($_file->getPathname()), 0, 1) == '.' || strpos($_file, '.svn') !== false) {
continue;
}
$_filepath = str_replace('\\', '/', (string) $_file);
if ($_file->isDir()) {
if (!$_compile->isDot()) {
// delete folder if empty
@rmdir($_file->getPathname());
}
} else {
$unlink = false;
if ((!isset($_compile_id) || (isset($_filepath[$_compile_id_part_length]) && $a = !strncmp($_filepath, $_compile_id_part, $_compile_id_part_length)))
&& (!isset($resource_name)
|| (isset($_filepath[$_resource_part_1_length])
&& substr_compare($_filepath, $_resource_part_1, - $_resource_part_1_length, $_resource_part_1_length) == 0)
|| (isset($_filepath[$_resource_part_2_length])
&& substr_compare($_filepath, $_resource_part_2, - $_resource_part_2_length, $_resource_part_2_length) == 0))
) {
if (isset($exp_time)) {
if (time() - @filemtime($_filepath) >= $exp_time) {
$unlink = true;
}
} else {
$unlink = true;
}
}
if ($unlink && @unlink($_filepath)) {
$_count ++;
}
}
}
// clear compiled cache
Smarty_Resource::$sources = array();
Smarty_Resource::$compileds = array();
return $_count;
}
/**
* Return array of tag/attributes of all tags used by an template
*
* @param Smarty_Internal_Template $template
*
* @throws Exception
* @throws SmartyException
* @return array of tag/attributes
*/
public static function getTags(Smarty_Internal_Template $template)
{
$template->smarty->get_used_tags = true;
$template->compileTemplateSource();
return $template->used_tags;
}
}

View File

@ -1,88 +0,0 @@
<?php
/**
* Smarty write file plugin
*
* @package Smarty
* @subpackage PluginsInternal
* @author Monte Ohrt
*/
/**
* Smarty Internal Write File Class
*
* @package Smarty
* @subpackage PluginsInternal
*/
class Smarty_Internal_Write_File
{
/**
* Writes file in a safe way to disk
*
* @param string $_filepath complete filepath
* @param string $_contents file content
* @param Smarty $smarty smarty instance
*
* @throws SmartyException
* @return boolean true
*/
public function writeFile($_filepath, $_contents, Smarty $smarty)
{
$_error_reporting = error_reporting();
error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
if ($smarty->_file_perms !== null) {
$old_umask = umask(0);
}
$_dirpath = dirname($_filepath);
// if subdirs, create dir structure
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true);
}
// write to tmp file, then move to overt file lock race condition
$_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true));
if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_tmp_file}");
}
/*
* Windows' rename() fails if the destination exists,
* Linux' rename() properly handles the overwrite.
* Simply unlink()ing a file might cause other processes
* currently reading that file to fail, but linux' rename()
* seems to be smart enough to handle that for us.
*/
if (Smarty::$_IS_WINDOWS) {
// remove original file
if (is_file($_filepath)) {
@unlink($_filepath);
}
// rename tmp file
$success = @rename($_tmp_file, $_filepath);
} else {
// rename tmp file
$success = @rename($_tmp_file, $_filepath);
if (!$success) {
// remove original file
if (is_file($_filepath)) {
@unlink($_filepath);
}
// rename tmp file
$success = @rename($_tmp_file, $_filepath);
}
}
if (!$success) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_filepath}");
}
if ($smarty->_file_perms !== null) {
// set file permissions
chmod($_filepath, $smarty->_file_perms);
umask($old_umask);
}
error_reporting($_error_reporting);
return true;
}
}

View File

@ -29,37 +29,25 @@ abstract class Smarty_Resource
* @var boolean
*/
public $recompiled = false;
/**
* resource handler object
*
* @var Smarty_Resource
*/
public $handler = null;
/**
* cache for Smarty_Template_Source instances
*
* @var array
*/
public static $sources = array();
/**
* cache for Smarty_Template_Compiled instances
*
* @var array
*/
public static $compileds = array();
/**
* resource types provided by the core
*
* @var array
*/
protected static $sysplugins = array(
'file' => 'smarty_internal_resource_file.php',
'string' => 'smarty_internal_resource_string.php',
'extends' => 'smarty_internal_resource_extends.php',
'stream' => 'smarty_internal_resource_stream.php',
'eval' => 'smarty_internal_resource_eval.php',
'php' => 'smarty_internal_resource_php.php'
);
public static $sysplugins = array('file' => 'smarty_internal_resource_file.php',
'string' => 'smarty_internal_resource_string.php',
'extends' => 'smarty_internal_resource_extends.php',
'stream' => 'smarty_internal_resource_stream.php',
'eval' => 'smarty_internal_resource_eval.php',
'php' => 'smarty_internal_resource_php.php');
/**
* Flag if resource does implement populateCompiledFilepath() method
*
* @var bool
*/
public $hasCompiledHandler = false;
/**
* Name of the Class to compile this resource's contents with
@ -84,7 +72,6 @@ abstract class Smarty_Resource
/**
* Load template's source into current template object
* {@internal The loaded source is assigned to $_template->source->content directly.}}
*
* @param Smarty_Template_Source $source source object
*
@ -123,9 +110,15 @@ abstract class Smarty_Resource
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
{
if ($isConfig) {
return get_class($this) . '#' . $smarty->joined_config_dir . '#' . $resource_name;
if (!isset($smarty->_joined_config_dir)) {
$smarty->getTemplateDir(null, true);
}
return get_class($this) . '#' . $smarty->_joined_config_dir . '#' . $resource_name;
} else {
return get_class($this) . '#' . $smarty->joined_template_dir . '#' . $resource_name;
if (!isset($smarty->_joined_template_dir)) {
$smarty->getTemplateDir();
}
return get_class($this) . '#' . $smarty->_joined_template_dir . '#' . $resource_name;
}
}
@ -153,42 +146,32 @@ abstract class Smarty_Resource
public static function load(Smarty $smarty, $type)
{
// try smarty's cache
if (isset($smarty->_resource_handlers[$type])) {
return $smarty->_resource_handlers[$type];
if (isset($smarty->_cache['resource_handlers'][$type])) {
return $smarty->_cache['resource_handlers'][$type];
}
// try registered resource
if (isset($smarty->registered_resources[$type])) {
if ($smarty->registered_resources[$type] instanceof Smarty_Resource) {
$smarty->_resource_handlers[$type] = $smarty->registered_resources[$type];
} else {
$smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Registered();
}
return $smarty->_resource_handlers[$type];
return $smarty->_cache['resource_handlers'][$type] =
$smarty->registered_resources[$type] instanceof Smarty_Resource ? $smarty->registered_resources[$type] :
new Smarty_Internal_Resource_Registered();
}
// try sysplugins dir
if (isset(self::$sysplugins[$type])) {
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
if (!class_exists($_resource_class, false)) {
require SMARTY_SYSPLUGINS_DIR . self::$sysplugins[$type];
}
return $smarty->_resource_handlers[$type] = new $_resource_class();
return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
}
// try plugins dir
$_resource_class = 'Smarty_Resource_' . ucfirst($type);
if ($smarty->loadPlugin($_resource_class)) {
if (class_exists($_resource_class, false)) {
return $smarty->_resource_handlers[$type] = new $_resource_class();
return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
} else {
$smarty->registerResource($type, array(
"smarty_resource_{$type}_source",
"smarty_resource_{$type}_timestamp",
"smarty_resource_{$type}_secure",
"smarty_resource_{$type}_trusted"
));
$smarty->registerResource($type,
array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
"smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
// give it another try, now that the resource is registered properly
return self::load($smarty, $type);
}
@ -201,7 +184,7 @@ abstract class Smarty_Resource
if (is_object($smarty->security_policy)) {
$smarty->security_policy->isTrustedStream($type);
}
return $smarty->_resource_handlers[$type] = new Smarty_Internal_Resource_Stream();;
return $smarty->_cache['resource_handlers'][$type] = new Smarty_Internal_Resource_Stream();
}
// TODO: try default_(template|config)_handler
@ -221,7 +204,7 @@ abstract class Smarty_Resource
*/
public static function parseResourceName($resource_name, $default_resource)
{
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
$type = $match[1];
$name = substr($resource_name, strlen($match[0]));
} else {
@ -229,38 +212,30 @@ abstract class Smarty_Resource
// or single character before the colon is not a resource type, but part of the filepath
$type = $default_resource;
$name = $resource_name;
}
return array($name, $type);
}
/**
* modify resource_name according to resource handlers specifications
*
* @param Smarty $smarty Smarty instance
* @param string $resource_name resource_name to make unique
*
* @return string unique resource name
*/
/**
* modify template_resource according to resource handlers specifications
*
* @param Smarty_Internal_template $template Smarty instance
* @param string $template_resource template_resource to extract resource handler and name of
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
* @param string $template_resource template_resource to extract resource handler and name of
*
* @return string unique resource name
*/
public static function getUniqueTemplateName($template, $template_resource)
public static function getUniqueTemplateName($obj, $template_resource)
{
$smarty = isset($template->smarty) ? $template->smarty : $template;
$smarty = $obj->_objType == 2 ? $obj->smarty : $obj;
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
// TODO: optimize for Smarty's internal resource types
$resource = Smarty_Resource::load($smarty, $type);
// go relative to a given template?
$_file_is_dotted = $name[0] == '.' && ($name[1] == '.' || $name[1] == '/');
if ($template instanceof Smarty_Internal_Template && $_file_is_dotted && ($template->source->type == 'file' || $template->parent->source->type == 'extends')) {
$name = dirname($template->source->filepath) . DS . $name;
if ($obj->_objType == 2 && $_file_is_dotted &&
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
) {
$name = dirname($obj->source->filepath) . DS . $name;
}
return $resource->buildUniqueResourceName($smarty, $name);
}
@ -276,7 +251,8 @@ abstract class Smarty_Resource
*
* @return Smarty_Template_Source Source Object
*/
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
$template_resource = null)
{
return Smarty_Template_Source::load($_template, $smarty, $template_resource);
}

View File

@ -23,6 +23,13 @@ abstract class Smarty_Resource_Recompiled extends Smarty_Resource
*/
public $recompiled = true;
/**
* Resource does implement populateCompiledFilepath() method
*
* @var bool
*/
public $hasCompiledHandler = true;
/**
* populate Compiled Object with compiled filepath
*

View File

@ -23,6 +23,13 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
*/
public $uncompiled = true;
/**
* Resource does implement populateCompiledFilepath() method
*
* @var bool
*/
public $hasCompiledHandler = true;
/**
* Render and output the template (without using the compiler)
*

View File

@ -34,6 +34,7 @@ class Smarty_Security
* @var integer
*/
public $php_handling = Smarty::PHP_PASSTHRU;
/**
* This is the list of template directories that are considered secure.
* $template_dir is in this list implicitly.
@ -41,6 +42,7 @@ class Smarty_Security
* @var array
*/
public $secure_dir = array();
/**
* This is an array of directories where trusted php scripts reside.
* {@link $security} is disabled during their inclusion/execution.
@ -48,18 +50,21 @@ class Smarty_Security
* @var array
*/
public $trusted_dir = array();
/**
* List of regular expressions (PCRE) that include trusted URIs
*
* @var array
*/
public $trusted_uri = array();
/**
* List of trusted constants names
*
* @var array
*/
public $trusted_constants = array();
/**
* This is an array of trusted static classes.
* If empty access to all static classes is allowed.
@ -96,6 +101,7 @@ class Smarty_Security
* @var array
*/
public $trusted_static_properties = array();
/**
* This is an array of trusted PHP functions.
* If empty all functions are allowed.
@ -103,12 +109,8 @@ class Smarty_Security
*
* @var array
*/
public $php_functions = array(
'isset', 'empty',
'count', 'sizeof',
'in_array', 'is_array',
'time',
);
public $php_functions = array('isset', 'empty', 'count', 'sizeof', 'in_array', 'is_array', 'time',);
/**
* This is an array of trusted PHP modifiers.
* If empty all modifiers are allowed.
@ -116,11 +118,8 @@ class Smarty_Security
*
* @var array
*/
public $php_modifiers = array(
'escape',
'count',
'nl2br',
);
public $php_modifiers = array('escape', 'count', 'nl2br',);
/**
* This is an array of allowed tags.
* If empty no restriction by allowed_tags.
@ -128,6 +127,7 @@ class Smarty_Security
* @var array
*/
public $allowed_tags = array();
/**
* This is an array of disabled tags.
* If empty no restriction by disabled_tags.
@ -135,6 +135,7 @@ class Smarty_Security
* @var array
*/
public $disabled_tags = array();
/**
* This is an array of allowed modifier plugins.
* If empty no restriction by allowed_modifiers.
@ -142,6 +143,7 @@ class Smarty_Security
* @var array
*/
public $allowed_modifiers = array();
/**
* This is an array of disabled modifier plugins.
* If empty no restriction by disabled_modifiers.
@ -149,12 +151,14 @@ class Smarty_Security
* @var array
*/
public $disabled_modifiers = array();
/**
* This is an array of disabled special $smarty variables.
*
* @var array
*/
public $disabled_special_smarty_vars = array();
/**
* This is an array of trusted streams.
* If empty all streams are allowed.
@ -163,60 +167,70 @@ class Smarty_Security
* @var array
*/
public $streams = array('file');
/**
* + flag if constants can be accessed from template
*
* @var boolean
*/
public $allow_constants = true;
/**
* + flag if super globals can be accessed from template
*
* @var boolean
*/
public $allow_super_globals = true;
/**
* max template nesting level
*
* @var int
*/
public $max_template_nesting = 0;
/**
* current template nesting level
*
* @var int
*/
private $_current_template_nesting = 0;
/**
* Cache for $resource_dir lookup
*
* @var array
*/
protected $_resource_dir = null;
protected $_resource_dir = array();
/**
* Cache for $template_dir lookup
*
* @var array
*/
protected $_template_dir = null;
protected $_template_dir = array();
/**
* Cache for $config_dir lookup
*
* @var array
*/
protected $_config_dir = null;
protected $_config_dir = array();
/**
* Cache for $secure_dir lookup
*
* @var array
*/
protected $_secure_dir = null;
protected $_secure_dir = array();
/**
* Cache for $php_resource_dir lookup
*
* @var array
*/
protected $_php_resource_dir = null;
/**
* Cache for $trusted_dir lookup
*
@ -224,6 +238,20 @@ class Smarty_Security
*/
protected $_trusted_dir = null;
/**
* Cache for include path status
*
* @var bool
*/
protected $_include_path_status = false;
/**
* Cache for $_include_array lookup
*
* @var array
*/
protected $_include_dir = array();
/**
* @param Smarty $smarty
*/
@ -243,7 +271,9 @@ class Smarty_Security
*/
public function isTrustedPhpFunction($function_name, $compiler)
{
if (isset($this->php_functions) && (empty($this->php_functions) || in_array($function_name, $this->php_functions))) {
if (isset($this->php_functions) &&
(empty($this->php_functions) || in_array($function_name, $this->php_functions))
) {
return true;
}
@ -263,7 +293,9 @@ class Smarty_Security
*/
public function isTrustedStaticClass($class_name, $compiler)
{
if (isset($this->static_classes) && (empty($this->static_classes) || in_array($class_name, $this->static_classes))) {
if (isset($this->static_classes) &&
(empty($this->static_classes) || in_array($class_name, $this->static_classes))
) {
return true;
}
@ -301,9 +333,8 @@ class Smarty_Security
// fall back
return $this->isTrustedStaticClass($class_name, $compiler);
}
if (isset($allowed[$class_name])
&& (empty($allowed[$class_name])
|| in_array($name, $allowed[$class_name]))
if (isset($allowed[$class_name]) &&
(empty($allowed[$class_name]) || in_array($name, $allowed[$class_name]))
) {
return true;
}
@ -323,7 +354,9 @@ class Smarty_Security
*/
public function isTrustedPhpModifier($modifier_name, $compiler)
{
if (isset($this->php_modifiers) && (empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))) {
if (isset($this->php_modifiers) &&
(empty($this->php_modifiers) || in_array($modifier_name, $this->php_modifiers))
) {
return true;
}
@ -344,9 +377,11 @@ class Smarty_Security
public function isTrustedTag($tag_name, $compiler)
{
// check for internal always required tags
if (in_array($tag_name, array('assign', 'call', 'private_filter', 'private_block_plugin', 'private_function_plugin', 'private_object_block_function',
'private_object_function', 'private_registered_function', 'private_registered_block', 'private_special_variable', 'private_print_expression', 'private_modifier'))
) {
if (in_array($tag_name, array('assign', 'call', 'private_filter', 'private_block_plugin',
'private_function_plugin', 'private_object_block_function',
'private_object_function', 'private_registered_function',
'private_registered_block', 'private_special_variable',
'private_print_expression', 'private_modifier'))) {
return true;
}
// check security settings
@ -354,12 +389,12 @@ class Smarty_Security
if (empty($this->disabled_tags) || !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", $compiler->lex->taglineno);
$compiler->trigger_template_error("tag '{$tag_name}' disabled by security setting", null, true);
}
} elseif (in_array($tag_name, $this->allowed_tags) && !in_array($tag_name, $this->disabled_tags)) {
return true;
} else {
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", $compiler->lex->taglineno);
$compiler->trigger_template_error("tag '{$tag_name}' not allowed by security setting", null, true);
}
return false; // should not, but who knows what happens to the compiler in the future?
@ -379,7 +414,7 @@ class Smarty_Security
if (!in_array($var_name, $this->disabled_special_smarty_vars)) {
return true;
} else {
$compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", $compiler->lex->taglineno);
$compiler->trigger_template_error("special variable '\$smarty.{$var_name}' not allowed by security setting", null, true);
}
return false; // should not, but who knows what happens to the compiler in the future?
@ -405,12 +440,14 @@ class Smarty_Security
if (empty($this->disabled_modifiers) || !in_array($modifier_name, $this->disabled_modifiers)) {
return true;
} else {
$compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", $compiler->lex->taglineno);
$compiler->trigger_template_error("modifier '{$modifier_name}' disabled by security setting", null, true);
}
} elseif (in_array($modifier_name, $this->allowed_modifiers) && !in_array($modifier_name, $this->disabled_modifiers)) {
} elseif (in_array($modifier_name, $this->allowed_modifiers) &&
!in_array($modifier_name, $this->disabled_modifiers)
) {
return true;
} else {
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", $compiler->lex->taglineno);
$compiler->trigger_template_error("modifier '{$modifier_name}' not allowed by security setting", null, true);
}
return false; // should not, but who knows what happens to the compiler in the future?
@ -419,7 +456,7 @@ class Smarty_Security
/**
* Check if constants are enabled or trusted
*
* @param string $const contant name
* @param string $const constant name
* @param object $compiler compiler object
*
* @return bool
@ -463,81 +500,70 @@ class Smarty_Security
/**
* Check if directory of file resource is trusted.
*
* @param string $filepath
* @param string $filepath
* @param null|bool $isConfig
*
* @return boolean true if directory is trusted
* @throws SmartyException if directory is not trusted
* @return bool true if directory is trusted
* @throws \SmartyException if directory is not trusted
*/
public function isTrustedResourceDir($filepath)
public function isTrustedResourceDir($filepath, $isConfig = null)
{
$_template = false;
$_config = false;
$_secure = false;
$_template_dir = $this->smarty->getTemplateDir();
$_config_dir = $this->smarty->getConfigDir();
// check if index is outdated
if ((!$this->_template_dir || $this->_template_dir !== $_template_dir)
|| (!$this->_config_dir || $this->_config_dir !== $_config_dir)
|| (!empty($this->secure_dir) && (!$this->_secure_dir || $this->_secure_dir !== $this->secure_dir))
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;
}
}
$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'])
) {
$this->_resource_dir = array();
$_template = true;
$_config = true;
$_secure = !empty($this->secure_dir);
}
// rebuild template dir index
if ($_template) {
$this->_template_dir = $_template_dir;
foreach ($_template_dir as $directory) {
$directory = realpath($directory);
$this->_resource_dir[$directory] = true;
$_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->_template_dir = $_dir;
}
$this->smarty->_cache['template_dir_new'] = false;
}
// rebuild config dir index
if ($_config) {
$this->_config_dir = $_config_dir;
foreach ($_config_dir as $directory) {
$directory = realpath($directory);
$this->_resource_dir[$directory] = true;
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->_config_dir = $_dir;
}
$this->smarty->_cache['config_dir_new'] = false;
}
// rebuild secure dir index
if ($_secure) {
$this->_secure_dir = $this->secure_dir;
if ($this->_secure_dir !== (array) $this->secure_dir) {
foreach ($this->_secure_dir as $directory) {
unset($this->_resource_dir[$directory]);
}
foreach ((array) $this->secure_dir as $directory) {
$directory = realpath($directory);
$directory = $this->smarty->_realpath($directory . DS, true);
$this->_resource_dir[$directory] = true;
}
$this->_secure_dir = (array) $this->secure_dir;
}
$_filepath = realpath($filepath);
$directory = dirname($_filepath);
$_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 (isset($this->_resource_dir[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$this->_resource_dir = array_merge($this->_resource_dir, $_directory);
return true;
}
// abort if we've reached root
if (($pos = strrpos($directory, DS)) === false || !isset($directory[1])) {
break;
}
// bubble up one level
$directory = substr($directory, 0, $pos);
}
// give up
throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
$this->_resource_dir = $this->_checkDir($filepath, $this->_resource_dir);
return true;
}
/**
@ -587,33 +613,13 @@ class Smarty_Security
$this->_trusted_dir = $this->trusted_dir;
foreach ((array) $this->trusted_dir as $directory) {
$directory = realpath($directory);
$directory = $this->smarty->_realpath($directory . DS, true);
$this->_php_resource_dir[$directory] = true;
}
}
$_filepath = realpath($filepath);
$directory = dirname($_filepath);
$_directory = array();
while (true) {
// remember the directory to add it to _resource_dir in case we're successful
$_directory[] = $directory;
// test if the directory is trusted
if (isset($this->_php_resource_dir[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory);
return true;
}
// abort if we've reached root
if (($pos = strrpos($directory, DS)) === false || !isset($directory[2])) {
break;
}
// bubble up one level
$directory = substr($directory, 0, $pos);
}
throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
$this->_php_resource_dir = $this->_checkDir($this->smarty->_realpath($filepath, true), $this->_php_resource_dir);
return true;
}
/**
@ -633,12 +639,77 @@ class Smarty_Security
/**
* Exit template processing
*
* @param $template
* @internal param $template
*/
public function exitTemplate($template)
public function exitTemplate()
{
if ($this->max_template_nesting > 0) {
$this->_current_template_nesting --;
}
}
/**
* Check if file is inside a valid directory
*
* @param string $filepath
* @param array $dirs valid directories
*
* @return array
* @throws \SmartyException
*/
private function _checkDir($filepath, $dirs)
{
$directory = dirname($filepath) . DS;
$_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 (isset($dirs[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$dirs = array_merge($dirs, $_directory);
return $dirs;
}
// abort if we've reached root
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
break;
}
// bubble up one level
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory);
}
// give up
throw new SmartyException("directory '{$filepath}' not allowed by security setting");
}
/**
* Loads security class and enables security
*
* @param \Smarty $smarty
* @param string|Smarty_Security $security_class if a string is used, it must be class-name
*
* @return \Smarty current Smarty instance for chaining
* @throws \SmartyException when an invalid class name is provided
*/
public static function enableSecurity(Smarty $smarty, $security_class)
{
if ($security_class instanceof Smarty_Security) {
$smarty->security_policy = $security_class;
return;
} elseif (is_object($security_class)) {
throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
}
if ($security_class == null) {
$security_class = $smarty->security_class;
}
if (!class_exists($security_class)) {
throw new SmartyException("Security class '$security_class' is not defined");
} elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
} else {
$smarty->security_policy = new $security_class($smarty);
}
return;
}
}

View File

@ -14,36 +14,8 @@
* @subpackage TemplateResources
* @author Rodney Rehm
*/
class Smarty_Template_Cached
class Smarty_Template_Cached extends Smarty_Template_Resource_Base
{
/**
* Source Filepath
*
* @var string
*/
public $filepath = false;
/**
* Source Content
*
* @var string
*/
public $content = null;
/**
* Source Timestamp
*
* @var integer
*/
public $timestamp = false;
/**
* Source Existence
*
* @var boolean
*/
public $exists = false;
/**
* Cache Is Valid
*
@ -51,13 +23,6 @@ class Smarty_Template_Cached
*/
public $valid = null;
/**
* Cache was processed
*
* @var boolean
*/
public $processed = false;
/**
* CacheResource Handler
*
@ -65,13 +30,6 @@ class Smarty_Template_Cached
*/
public $handler = null;
/**
* Template Compile Id (Smarty_Internal_Template::$compile_id)
*
* @var string
*/
public $compile_id = null;
/**
* Template Cache Id (Smarty_Internal_Template::$cache_id)
*
@ -79,6 +37,13 @@ class Smarty_Template_Cached
*/
public $cache_id = null;
/**
* saved cache lifetime in seconds
*
* @var integer
*/
public $cache_lifetime = 0;
/**
* Id for cache locking
*
@ -100,6 +65,13 @@ class Smarty_Template_Cached
*/
public $source = null;
/**
* Nocache hash codes of processed compiled templates
*
* @var array
*/
public $hashes = array();
/**
* create Cached Object container
*
@ -109,9 +81,6 @@ class Smarty_Template_Cached
{
$this->compile_id = $_template->compile_id;
$this->cache_id = $_template->cache_id;
if (!isset($_template->source)) {
$_template->loadSource();
}
$this->source = $_template->source;
if (!class_exists('Smarty_CacheResource', false)) {
require SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
@ -126,13 +95,42 @@ class Smarty_Template_Cached
*/
static function load(Smarty_Internal_Template $_template)
{
$_template->cached = $cached = new Smarty_Template_Cached($_template);
$cached->handler->populate($cached, $_template);
$_template->cached = new Smarty_Template_Cached($_template);
$_template->cached->handler->populate($_template->cached, $_template);
// caching enabled ?
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->recompiled) {
$cached->valid = false;
if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT ||
$_template->caching == Smarty::CACHING_LIFETIME_SAVED) || $_template->source->handler->recompiled
) {
$_template->cached->valid = false;
}
return $_template->cached;
}
/**
* Render cache template
*
* @param \Smarty_Internal_Template $_template
* @param bool $no_output_filter
*
* @throws \Exception
*/
public function render(Smarty_Internal_Template $_template, $no_output_filter = true)
{
if ($this->isCached($_template)) {
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_cache($_template);
}
if (!$this->processed) {
$this->process($_template);
}
$this->getRenderedTemplateCode($_template);
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_cache($_template);
}
return;
} else {
$_template->smarty->ext->_updateCache->updateCache($this, $_template, $no_output_filter);
}
return $cached;
}
/**
@ -149,16 +147,20 @@ class Smarty_Template_Cached
}
while (true) {
while (true) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
if ($this->exists === false || $_template->smarty->force_compile || $_template->smarty->force_cache) {
$this->valid = false;
} else {
$this->valid = true;
}
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT && $_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)) {
if ($this->valid && $_template->caching == Smarty::CACHING_LIFETIME_CURRENT &&
$_template->cache_lifetime >= 0 && time() > ($this->timestamp + $_template->cache_lifetime)
) {
// lifetime expired
$this->valid = false;
}
if ($this->valid && $_template->source->timestamp > $this->timestamp) {
if ($this->valid && $_template->smarty->compile_check == 1 &&
$_template->source->getTimeStamp() > $this->timestamp
) {
$this->valid = false;
}
if ($this->valid || !$_template->smarty->cache_locking) {
@ -174,7 +176,7 @@ class Smarty_Template_Cached
if (!$_template->smarty->cache_locking || $this->handler->locked($_template->smarty, $this) === null) {
// load cache file for the following checks
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::start_cache($_template);
$_template->smarty->_debug->start_cache($_template);
}
if ($this->handler->process($_template, $this) === false) {
$this->valid = false;
@ -182,7 +184,7 @@ class Smarty_Template_Cached
$this->processed = true;
}
if ($_template->smarty->debugging) {
Smarty_Internal_Debug::end_cache($_template);
$_template->smarty->_debug->end_cache($_template);
}
} else {
$this->is_locked = true;
@ -191,7 +193,10 @@ class Smarty_Template_Cached
} else {
return $this->valid;
}
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED && $_template->properties['cache_lifetime'] >= 0 && (time() > ($_template->cached->timestamp + $_template->properties['cache_lifetime']))) {
if ($this->valid && $_template->caching === Smarty::CACHING_LIFETIME_SAVED &&
$_template->cached->cache_lifetime >= 0 &&
(time() > ($_template->cached->timestamp + $_template->cached->cache_lifetime))
) {
$this->valid = false;
}
if ($_template->smarty->cache_locking) {
@ -210,10 +215,11 @@ class Smarty_Template_Cached
* Process cached template
*
* @param Smarty_Internal_Template $_template template object
* @param bool $update flag if called because cache update
*/
public function process(Smarty_Internal_Template $_template)
public function process(Smarty_Internal_Template $_template, $update = false)
{
if ($this->handler->process($_template, $this) === false) {
if ($this->handler->process($_template, $this, $update) === false) {
$this->valid = false;
}
if ($this->valid) {
@ -223,55 +229,6 @@ class Smarty_Template_Cached
}
}
/**
* Render cached template
*
* @param Smarty_Internal_Template $_template
*
* @return string
* @throws Exception
*/
public function render(Smarty_Internal_Template $_template)
{
if (!$this->processed) {
$this->process($_template);
}
return $_template->getRenderedTemplateCode();
}
/**
* Write this cache object to handler
*
* @param Smarty_Internal_Template $_template template object
* @param string $content content to cache
*
* @return boolean success
*/
public function write(Smarty_Internal_Template $_template, $content)
{
if (!$_template->source->recompiled) {
if ($this->handler->writeCachedContent($_template, $content)) {
$this->content = null;
$this->timestamp = time();
$this->exists = true;
$this->valid = true;
$this->processed = false;
if ($_template->smarty->cache_locking) {
$this->handler->releaseLock($_template->smarty, $this);
}
return true;
}
$this->content = null;
$this->timestamp = false;
$this->exists = false;
$this->valid = false;
$this->processed = false;
}
return false;
}
/**
* Read cache content from handler
*
@ -281,123 +238,9 @@ class Smarty_Template_Cached
*/
public function read(Smarty_Internal_Template $_template)
{
if (!$_template->source->recompiled) {
if (!$_template->source->handler->recompiled) {
return $this->handler->readCachedContent($_template);
}
return false;
}
/**
* Sanitize content and write it to cache resource
*
* @param Smarty_Internal_Template $_template
* @param string $content
* @param bool $no_output_filter
*
* @throws SmartyException
*/
public function updateCache(Smarty_Internal_Template $_template, $content, $no_output_filter)
{
$_template->properties['has_nocache_code'] = false;
// get text between non-cached items
$cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $content);
// get non-cached items
preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $content, $cache_parts);
$output = '';
// loop over items, stitch back together
foreach ($cache_split as $curr_idx => $curr_split) {
// escape PHP tags in template content
$output .= 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->properties['has_nocache_code'] = true;
$output .= $cache_parts[1][$curr_idx];
}
}
if (!$no_output_filter && !$_template->has_nocache_code && (isset($_template->smarty->autoload_filters['output']) || isset($_template->smarty->registered_filters['output']))) {
$output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
}
// write cache file content
$this->writeCachedContent($_template, $output);
}
/**
* Writes the content to cache resource
*
* @param Smarty_Internal_Template $_template
* @param string $content
*
* @return bool
*/
public function writeCachedContent(Smarty_Internal_Template $_template, $content)
{
if ($_template->source->recompiled || !($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED)) {
// don't write cache file
return false;
}
$_template->properties['cache_lifetime'] = $_template->cache_lifetime;
$_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
$content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, true);
if (!empty($_template->properties['tpl_function'])) {
foreach ($_template->properties['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($_template, $content);
}
/**
* check client side cache
*
* @param Smarty_Internal_Template $_template
* @param string $content
*/
public function cacheModifiedCheck(Smarty_Internal_Template $_template, $content)
{
$_isCached = $_template->isCached() && !$_template->has_nocache_code;
$_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
if ($_isCached && $this->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified');
break;
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
}
break;
default:
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
break;
}
} else {
switch (PHP_SAPI) {
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->timestamp) . ' GMT';
}
break;
default:
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->timestamp) . ' GMT');
break;
}
echo $content;
}
}
}

View File

@ -9,48 +9,15 @@
* @author Rodney Rehm
* @property string $content compiled content
*/
class Smarty_Template_Compiled
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
{
/**
* Compiled Filepath
*
* @var string
*/
public $filepath = null;
/**
* Compiled Timestamp
*
* @var integer
*/
public $timestamp = null;
/**
* Compiled Existence
*
* @var boolean
*/
public $exists = false;
/**
* Compiled Content Loaded
*
* @var boolean
*/
public $processed = false;
/**
* Code of recompiled template resource
* nocache hash
*
* @var string|null
*/
public $code = null;
/**
* create Compiled Object container
*/
public function __construct()
{
}
public $nocache_hash = null;
/**
* get a Compiled Object of this source
@ -61,11 +28,10 @@ class Smarty_Template_Compiled
*/
static function load($_template)
{
if (!isset($_template->source)) {
$_template->loadSource();
}
// check runtime cache
if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
if (!$_template->source->handler->recompiled &&
($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
) {
$_cache_key = $_template->source->unique_resource . '#';
if ($_template->caching) {
$_cache_key .= 'caching#';
@ -76,13 +42,15 @@ class Smarty_Template_Compiled
}
}
$compiled = new Smarty_Template_Compiled();
if (method_exists($_template->source->handler, 'populateCompiledFilepath')) {
if ($_template->source->handler->hasCompiledHandler) {
$_template->source->handler->populateCompiledFilepath($compiled, $_template);
} else {
$compiled->populateCompiledFilepath($_template);
}
// runtime cache
if (!$_template->source->recompiled && $_template->smarty->resource_caching) {
if (!$_template->source->handler->recompiled &&
($_template->smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)
) {
$_template->source->compileds[$_cache_key] = $compiled;
}
return $compiled;
@ -95,20 +63,20 @@ class Smarty_Template_Compiled
**/
public function populateCompiledFilepath(Smarty_Internal_Template $_template)
{
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w]+!', '_', $_template->compile_id) : null;
if ($_template->source->isConfig) {
$_flag = '_' . ((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2
+ (int) $_template->smarty->config_overwrite * 4);
$_flag = '_' .
((int) $_template->smarty->config_read_hidden + (int) $_template->smarty->config_booleanize * 2 +
(int) $_template->smarty->config_overwrite * 4);
} else {
$_flag = '_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
$_flag =
'_' . ((int) $_template->smarty->merge_compiled_includes + (int) $_template->smarty->escape_html * 2);
}
$_filepath = $_template->source->uid . $_flag;
// if use_sub_dirs, break file into directories
if ($_template->smarty->use_sub_dirs) {
$_filepath = substr($_filepath, 0, 2) . DS
. substr($_filepath, 2, 2) . DS
. substr($_filepath, 4, 2) . DS
. $_filepath;
$_filepath = substr($_filepath, 0, 2) . DS . substr($_filepath, 2, 2) . DS . substr($_filepath, 4, 2) . DS .
$_filepath;
}
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
if (isset($_compile_id)) {
@ -124,7 +92,7 @@ class Smarty_Template_Compiled
// set basename if not specified
$_basename = $_template->source->handler->getBasename($_template->source);
if ($_basename === null) {
$_basename = basename(preg_replace('![^\w\/]+!', '_', $_template->source->name));
$_basename = basename(preg_replace('![^\w]+!', '_', $_template->source->name));
}
// separate (optional) basename by dot
if ($_basename) {
@ -132,9 +100,9 @@ class Smarty_Template_Compiled
}
$this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php';
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = @filemtime($this->filepath);
$this->exists = is_file($this->filepath);
if (!$this->exists) {
$this->timestamp = false;
}
}
@ -148,15 +116,18 @@ class Smarty_Template_Compiled
public function process(Smarty_Internal_Template $_template)
{
$_smarty_tpl = $_template;
if ($_template->source->recompiled || !$_template->compiled->exists || $_template->smarty->force_compile) {
if ($_template->source->handler->recompiled || !$_template->compiled->exists ||
$_template->smarty->force_compile || ($_template->smarty->compile_check &&
$_template->source->getTimeStamp() > $_template->compiled->getTimeStamp())
) {
$this->compileTemplateSource($_template);
$compileCheck = $_template->smarty->compile_check;
$_template->smarty->compile_check = false;
if ($_template->source->recompiled) {
if ($_template->source->handler->recompiled) {
$level = ob_get_level();
ob_start();
try {
eval("?>" . $this->code);
eval("?>" . $this->content);
}
catch (Exception $e) {
while (ob_get_level() > $level) {
@ -165,25 +136,46 @@ class Smarty_Template_Compiled
throw $e;
}
ob_get_clean();
$this->code = null;
$this->content = null;
} else {
include($_template->compiled->filepath);
$this->loadCompiledTemplate($_template);
}
$_template->smarty->compile_check = $compileCheck;
} else {
include($_template->compiled->filepath);
$_template->mustCompile = true;
@include($_template->compiled->filepath);
if ($_template->mustCompile) {
$this->compileTemplateSource($_template);
$compileCheck = $_template->smarty->compile_check;
$_template->smarty->compile_check = false;
include($_template->compiled->filepath);
$this->loadCompiledTemplate($_template);
$_template->smarty->compile_check = $compileCheck;
}
}
$this->unifunc = $_template->properties['unifunc'];
$_template->smarty->ext->_subTemplate->registerSubTemplates($_template);
$this->processed = true;
}
/**
* Load fresh compiled template by including the PHP file
* HHVM requires a work around because of a PHP incompatibility
*
* @param \Smarty_Internal_Template $_template
*/
private function loadCompiledTemplate(Smarty_Internal_Template $_template)
{
if (function_exists('opcache_invalidate')) {
opcache_invalidate($_template->compiled->filepath);
}
$_smarty_tpl = $_template;
if (defined('HHVM_VERSION')) {
$_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->compiled->filepath);
} else {
include($_template->compiled->filepath);
}
}
/**
* render compiled template code
*
@ -194,12 +186,26 @@ class Smarty_Template_Compiled
*/
public function render(Smarty_Internal_Template $_template)
{
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_render($_template);
}
if (!$this->processed) {
$this->process($_template);
}
$_template->properties['unifunc'] = $this->unifunc;
return $_template->getRenderedTemplateCode();
if (isset($_template->cached)) {
$_template->cached->file_dependency =
array_merge($_template->cached->file_dependency, $this->file_dependency);
}
$this->getRenderedTemplateCode($_template);
if ($_template->caching && $this->has_nocache_code) {
$_template->cached->hashes[$this->nocache_hash] = true;
}
if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) {
$_template->parent->tpl_function = array_merge($_template->parent->tpl_function, $_template->tpl_function);
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_render($_template);
}
}
/**
@ -212,22 +218,26 @@ class Smarty_Template_Compiled
*/
public function compileTemplateSource(Smarty_Internal_Template $_template)
{
if (!$_template->source->recompiled) {
$_template->properties['file_dependency'] = array();
}
$_template->source->compileds = array();
$this->file_dependency = array();
$this->tpl_function = array();
$this->includes = array();
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
if (!$_template->source->recompiled) {
if ($saved_timestamp = $_template->compiled->timestamp) {
if (!$_template->source->handler->recompiled) {
if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
touch($_template->compiled->filepath);
}
}
// call compiler
try {
$_template->loadCompiler();
$code = $_template->compiler->compileTemplate($_template);
}
catch (Exception $e) {
// restore old timestamp in case of error
if (!$_template->source->recompiled && $saved_timestamp) {
if (!$_template->source->handler->recompiled && $saved_timestamp) {
touch($_template->compiled->filepath, $saved_timestamp);
}
throw $e;
@ -253,18 +263,17 @@ class Smarty_Template_Compiled
*/
public function write(Smarty_Internal_Template $_template, $code)
{
if (!$_template->source->recompiled) {
$obj = new Smarty_Internal_Write_File();
if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) {
if (!$_template->source->handler->recompiled) {
if ($_template->smarty->ext->_writeFile->writeFile($this->filepath, $code, $_template->smarty) === true) {
$this->timestamp = $this->exists = is_file($this->filepath);
if ($this->exists) {
$this->timestamp = @filemtime($this->filepath);
$this->timestamp = filemtime($this->filepath);
return true;
}
}
return false;
} else {
$this->code = $code;
$this->content = $code;
}
$this->timestamp = time();
$this->exists = true;
@ -280,7 +289,7 @@ class Smarty_Template_Compiled
*/
public function read(Smarty_Internal_Template $_template)
{
if (!$_template->source->recompiled) {
if (!$_template->source->handler->recompiled) {
return file_get_contents($this->filepath);
}
return isset($this->content) ? $this->content : false;

View File

@ -14,34 +14,10 @@
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
* @property integer $timestamp Source Timestamp
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
* @property string $content Source Content
*
*/
class Smarty_Template_Config extends Smarty_Template_Source
{
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = 'Smarty_Internal_Configfileparser';
/**
* array of section names, single section or null
*
@ -74,7 +50,11 @@ class Smarty_Template_Config extends Smarty_Template_Source
*/
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
{
// must clone handler as we change class names
$this->handler = clone $handler; // Note: prone to circular references
$this->handler->compiler_class = 'Smarty_Internal_Config_File_Compiler';
$this->handler->template_lexer_class = 'Smarty_Internal_Configfilelexer';
$this->handler->template_parser_class = 'Smarty_Internal_Configfileparser';
$this->resource = $resource;
$this->type = $type;
$this->name = $name;
@ -89,30 +69,29 @@ class Smarty_Template_Config extends Smarty_Template_Source
* @param Smarty $smarty smarty object
* @param string $template_resource resource identifier
*
* @return Smarty_Template_Source Source Object
* @return Smarty_Template_Config Source Object
* @throws SmartyException
*/
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
{
static $_incompatible_resources = array('extends' => true, 'php' => true);
$smarty = $_template->smarty;
$template_resource = $_template->template_resource;
if (empty($template_resource)) {
throw new SmartyException('Missing config name');
}
// parse resource_name, load resource handler
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $_template->smarty->default_config_type);
// make sure configs are not loaded via anything smarty can't handle
if (isset($_incompatible_resources[$type])) {
throw new SmartyException ("Unable to use resource '{$type}' for config");
}
$resource = Smarty_Resource::load($smarty, $type);
$source = new Smarty_Template_Config($resource, $smarty, $template_resource, $type, $name);
$resource = Smarty_Resource::load($_template->smarty, $type);
$source = new Smarty_Template_Config($resource, $_template->smarty, $template_resource, $type, $name);
$resource->populate($source, $_template);
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_config_handler_func)) {
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resource);
if (!$source->exists && isset($_template->smarty->default_config_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
}
$source->unique_resource = $resource->buildUniqueResourceName($smarty, $name, true);
$source->unique_resource = $resource->buildUniqueResourceName($_template->smarty, $name, true);
return $source;
}
}

View File

@ -7,34 +7,10 @@
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
* @property integer $timestamp Source Timestamp
* @property boolean $exists Source Existence
* @property boolean $template Extended Template reference
* @property string $content Source Content
*
*/
class Smarty_Template_Source
{
/**
* Name of the Class to compile this resource's contents with
*
* @var string
*/
public $compiler_class = null;
/**
* Name of the Class to tokenize this resource's contents with
*
* @var string
*/
public $template_lexer_class = null;
/**
* Name of the Class to parse this resource's contents with
*
* @var string
*/
public $template_parser_class = null;
/**
* Unique Template ID
*
@ -76,6 +52,21 @@ class Smarty_Template_Source
* @var string
*/
public $filepath = null;
/**
* Source Timestamp
*
* @var integer
*/
public $timestamp = null;
/**
* Source Existence
*
* @var boolean
*/
public $exists = false;
/**
* Source File Base name
*
@ -86,14 +77,14 @@ class Smarty_Template_Source
/**
* The Components an extended template is made of
*
* @var array
* @var \Smarty_Template_Source[]
*/
public $components = null;
/**
* Resource Handler
*
* @var Smarty_Resource
* @var \Smarty_Resource
*/
public $handler = null;
@ -103,32 +94,28 @@ class Smarty_Template_Source
* @var Smarty
*/
public $smarty = null;
/**
* Resource is source
*
* @var bool
*/
public $isConfig = false;
/**
* Source is bypassing compiler
*
* @var boolean
*/
public $uncompiled = false;
/**
* Source must be recompiled on every occasion
*
* @var boolean
*/
public $recompiled = false;
/**
* cache for Smarty_Template_Compiled instances
*
* @var array
* @var Smarty_Template_Compiled[]
*/
public $compileds = array();
/**
* Template source content eventually set by default handler
*
* @var string
*/
public $content = null;
/**
* create Source Object container
*
@ -138,18 +125,10 @@ class Smarty_Template_Source
* @param string $type type of resource
* @param string $name resource name
*
* @internal param string $unique_resource unique resource name
*/
public function __construct(Smarty_Resource $handler, Smarty $smarty, $resource, $type, $name)
{
$this->handler = $handler; // Note: prone to circular references
$this->recompiled = $handler->recompiled;
$this->uncompiled = $handler->uncompiled;
$this->compiler_class = $handler->compiler_class;
$this->template_lexer_class = $handler->template_lexer_class;
$this->template_parser_class = $handler->template_parser_class;
$this->smarty = $smarty;
$this->resource = $resource;
$this->type = $type;
@ -167,7 +146,8 @@ class Smarty_Template_Source
* @return Smarty_Template_Source Source Object
* @throws SmartyException
*/
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null, $template_resource = null)
public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
$template_resource = null)
{
if ($_template) {
$smarty = $_template->smarty;
@ -177,36 +157,51 @@ class Smarty_Template_Source
throw new SmartyException('Missing template name');
}
// parse resource_name, load resource handler, identify unique resource name
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_resource_type);
$resource = Smarty_Resource::load($smarty, $type);
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]([\s\S]*)$/', $template_resource, $match)) {
$type = $match[1];
$name = $match[2];
} else {
// no resource given, use default
// or single character before the colon is not a resource type, but part of the filepath
$type = $smarty->default_resource_type;
$name = $template_resource;
}
$handler = isset($smarty->_cache['resource_handlers'][$type]) ?
$smarty->_cache['resource_handlers'][$type] :
Smarty_Resource::load($smarty, $type);
// if resource is not recompiling and resource name is not dotted we can check the source cache
if ($smarty->resource_caching && !$resource->recompiled && !(isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'))) {
$unique_resource = $resource->buildUniqueResourceName($smarty, $name);
if (isset($smarty->source_objects[$unique_resource])) {
return $smarty->source_objects[$unique_resource];
if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$handler->recompiled &&
!(isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/'))
) {
$unique_resource = $handler->buildUniqueResourceName($smarty, $name);
if (isset($smarty->_cache['source_objects'][$unique_resource])) {
return $smarty->_cache['source_objects'][$unique_resource];
}
} else {
$unique_resource = null;
}
// create new source object
$source = new Smarty_Template_Source($resource, $smarty, $template_resource, $type, $name);
$resource->populate($source, $_template);
if ((!isset($source->exists) || !$source->exists) && isset($_template->smarty->default_template_handler_func)) {
Smarty_Internal_Extension_DefaultTemplateHandler::_getDefault($_template, $source, $resObj);
$source = new Smarty_Template_Source($handler, $smarty, $template_resource, $type, $name);
$handler->populate($source, $_template);
if (!$source->exists && isset($_template->smarty->default_template_handler_func)) {
Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
}
// on recompiling resources we are done
if ($smarty->resource_caching && !$resource->recompiled) {
if (($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON) && !$handler->recompiled) {
// may by we have already $unique_resource
$is_relative = false;
if (!isset($unique_resource)) {
$is_relative = isset($name[1]) && $name[0] == '.' && ($name[1] == '.' || $name[1] == '/') &&
($type == 'file' || (isset($_template->parent->source) && $_template->parent->source->type == 'extends'));
$unique_resource = $resource->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name);
($type == 'file' ||
(isset($_template->parent->source) && $_template->parent->source->type == 'extends'));
$unique_resource =
$handler->buildUniqueResourceName($smarty, $is_relative ? $source->filepath . $name : $name);
}
$source->unique_resource = $unique_resource;
// save in runtime cache if not relative
if (!$is_relative) {
$smarty->source_objects[$unique_resource] = $source;
$smarty->_cache['source_objects'][$unique_resource] = $source;
}
}
return $source;
@ -216,70 +211,57 @@ class Smarty_Template_Source
* render the uncompiled source
*
* @param Smarty_Internal_Template $_template template object
*
* @return string
* @throws \Exception
*/
public function renderUncompiled(Smarty_Internal_Template $_template)
{
$level = ob_get_level();
ob_start();
try {
$this->handler->renderUncompiled($_template->source, $_template);
return ob_get_clean();
}
catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
$this->handler->renderUncompiled($_template->source, $_template);
}
/**
* Render uncompiled source
*
* @param \Smarty_Internal_Template $_template
*/
public function render(Smarty_Internal_Template $_template)
{
if ($_template->source->handler->uncompiled) {
if ($_template->smarty->debugging) {
$_template->smarty->_debug->start_render($_template);
}
$this->handler->renderUncompiled($_template->source, $_template);
if (isset($_template->parent) && $_template->parent->_objType == 2 && !empty($_template->tpl_function)) {
$_template->parent->tpl_function =
array_merge($_template->parent->tpl_function, $_template->tpl_function);
}
if ($_template->smarty->debugging) {
$_template->smarty->_debug->end_render($_template);
}
throw $e;
}
}
/**
* <<magic>> Generic Setter.
* Get source time stamp
*
* @param string $property_name valid: timestamp, exists, content, template
* @param mixed $value new value (is not checked)
*
* @throws SmartyException if $property_name is not valid
* @return int
*/
public function __set($property_name, $value)
public function getTimeStamp()
{
switch ($property_name) {
// regular attributes
case 'timestamp':
case 'exists':
case 'content':
// required for extends: only
case 'template':
$this->$property_name = $value;
break;
default:
throw new SmartyException("source property '$property_name' does not exist.");
if (!isset($this->timestamp)) {
$this->handler->populateTimestamp($this);
}
return $this->timestamp;
}
/**
* <<magic>> Generic getter.
* Get source content
*
* @param string $property_name valid: timestamp, exists, content
*
* @return mixed
* @throws SmartyException if $property_name is not valid
* @return string
*/
public function __get($property_name)
public function getContent()
{
switch ($property_name) {
case 'timestamp':
case 'exists':
$this->handler->populateTimestamp($this);
return $this->$property_name;
case 'content':
return $this->content = $this->handler->getContent($this);
default:
throw new SmartyException("source property '$property_name' does not exist.");
}
return isset($this->content) ? $this->content : $this->handler->getContent($this);
}
}

View File

@ -21,25 +21,17 @@ class Smarty_Variable
* @var boolean
*/
public $nocache = false;
/**
* the scope the variable will have (local,parent or root)
*
* @var int
*/
public $scope = Smarty::SCOPE_LOCAL;
/**
* create Smarty variable object
*
* @param mixed $value the value to assign
* @param boolean $nocache if true any output of this variable will be not cached
* @param int $scope the scope the variable will have (local,parent or root)
*/
public function __construct($value = null, $nocache = false, $scope = Smarty::SCOPE_LOCAL)
public function __construct($value = null, $nocache = false)
{
$this->value = $value;
$this->nocache = $nocache;
$this->scope = $scope;
}
/**