This commit is contained in:
Uwe Tews
2015-07-07 17:51:40 +02:00
parent f66cd7e062
commit 733755f94a

View File

@@ -33,63 +33,70 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
* @var string * @var string
*/ */
public $template_resource = null; public $template_resource = null;
/** /**
* Saved template Id * Saved template Id
* *
* @var null|string * @var null|string
*/ */
public $templateId = null; public $templateId = null;
/** /**
* flag if compiled template is invalid and must be (re)compiled * flag if compiled template is invalid and must be (re)compiled
* *
* @var bool * @var bool
*/ */
public $mustCompile = null; public $mustCompile = null;
/** /**
* flag if template does contain nocache code sections * flag if template does contain nocache code sections
* *
* @var bool * @var bool
*/ */
public $has_nocache_code = false; public $has_nocache_code = false;
/** /**
* special compiled and cached template properties * special compiled and cached template properties
* *
* @var array * @var array
*/ */
public $properties = array('file_dependency' => array(), public $properties = array('file_dependency' => array(), 'nocache_hash' => '', 'tpl_function' => array(),);
'nocache_hash' => '',
'tpl_function' => array(),
);
/** /**
* required plugins * required plugins
* *
* @var array * @var array
*/ */
public $required_plugins = array('compiled' => array(), 'nocache' => array()); public $required_plugins = array('compiled' => array(), 'nocache' => array());
/** /**
* blocks for template inheritance * blocks for template inheritance
* *
* @var array * @var array
*/ */
public $block_data = array(); public $block_data = array();
/** /**
* variable filters * variable filters
* *
* @var array * @var array
*/ */
public $variable_filters = array(); public $variable_filters = array();
/** /**
* optional log of tag/attributes * optional log of tag/attributes
* *
* @var array * @var array
*/ */
public $used_tags = array(); public $used_tags = array();
/** /**
* internal flag to allow relative path in child template blocks * internal flag to allow relative path in child template blocks
* *
* @var bool * @var bool
*/ */
public $allow_relative_path = false; public $allow_relative_path = false;
/** /**
* internal capture runtime stack * internal capture runtime stack
* *
@@ -133,10 +140,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
/** /**
* fetches rendered template * fetches rendered template
* *
* @param string $template the resource handle of the template file or template object * @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 $cache_id cache id to be used with this template
* @param mixed $compile_id compile 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 object $parent next higher level of Smarty variables
* *
* @throws Exception * @throws Exception
* @throws SmartyException * @throws SmartyException
@@ -235,7 +242,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$this->caching = false; $this->caching = false;
} }
// read from cache or render // 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 ($isCacheTpl) {
if (!isset($this->cached)) { if (!isset($this->cached)) {
$this->loadCached(); $this->loadCached();
@@ -260,7 +268,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$content = $this->source->renderUncompiled($this); $content = $this->source->renderUncompiled($this);
} }
if (!$this->source->recompiled && empty($this->properties['file_dependency'][$this->source->uid])) { 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->getTimeStamp(), $this->source->type); $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath,
$this->source->getTimeStamp(),
$this->source->type);
} }
if ($parentIsTpl) { if ($parentIsTpl) {
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']); $this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
@@ -304,7 +314,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
Smarty_Internal_Debug::end_cache($this); Smarty_Internal_Debug::end_cache($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']))) { 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); $content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $this);
} }
if (isset($_smarty_old_error_level)) { if (isset($_smarty_old_error_level)) {
@@ -418,7 +430,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}"); throw new SmartyException("Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
} }
if ($this->mustCompile === null) { if ($this->mustCompile === null) {
$this->mustCompile = (!$this->source->uncompiled && ($this->smarty->force_compile || $this->source->recompiled || !$this->compiled->exists || $this->mustCompile = (!$this->source->uncompiled &&
($this->smarty->force_compile || $this->source->recompiled || !$this->compiled->exists ||
($this->smarty->compile_check && $this->compiled->getTimeStamp() < $this->source->getTimeStamp()))); ($this->smarty->compile_check && $this->compiled->getTimeStamp() < $this->source->getTimeStamp())));
} }
@@ -610,7 +623,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if (Smarty::SMARTY_VERSION != $properties['version']) { if (Smarty::SMARTY_VERSION != $properties['version']) {
// new version must rebuild // new version must rebuild
$is_valid = false; $is_valid = false;
} elseif (!empty($properties['file_dependency']) && ((!$cache && $this->smarty->compile_check) || $this->smarty->compile_check == 1)) { } elseif (!empty($properties['file_dependency']) &&
((!$cache && $this->smarty->compile_check) || $this->smarty->compile_check == 1)
) {
// check file dependencies at compiled code // check file dependencies at compiled code
foreach ($properties['file_dependency'] as $_file_to_check) { foreach ($properties['file_dependency'] as $_file_to_check) {
if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') { if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'php') {
@@ -636,8 +651,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
if ($cache) { if ($cache) {
// CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 &&
$properties['cache_lifetime'] >= 0 &&
(time() > ($this->cached->timestamp + $properties['cache_lifetime'])) (time() > ($this->cached->timestamp + $properties['cache_lifetime']))
) { ) {
$is_valid = false; $is_valid = false;
@@ -680,7 +694,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
if ($scope != Smarty::SCOPE_LOCAL) { if ($scope != Smarty::SCOPE_LOCAL) {
$this->tpl_vars[$tpl_var]->scope = $scope; $this->tpl_vars[$tpl_var]->scope = $scope;
} }
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) { 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'); settype($this->tpl_vars[$tpl_var]->value, 'array');
} }
} }