aboutsummaryrefslogtreecommitdiffstats
path: root/library/Smarty/libs/sysplugins/smarty_internal_template.php
diff options
context:
space:
mode:
authorThomas Willingham <beardyunixer@beardyunixer.com>2014-12-11 20:15:27 +0000
committerThomas Willingham <beardyunixer@beardyunixer.com>2014-12-11 20:15:27 +0000
commit967ab871b836f618107fe144978bd1453c3c6634 (patch)
tree1bcb1b4bb1b25c904a2bc06f5c6d526d29909eaa /library/Smarty/libs/sysplugins/smarty_internal_template.php
parent960c35bad3a0dbaa7a1f2191aef60ad014d926ca (diff)
downloadvolse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.tar.gz
volse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.tar.bz2
volse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.zip
Update Smarty
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_internal_template.php')
-rw-r--r--library/Smarty/libs/sysplugins/smarty_internal_template.php200
1 files changed, 127 insertions, 73 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_internal_template.php b/library/Smarty/libs/sysplugins/smarty_internal_template.php
index de9d54cf6..f1a73a4ae 100644
--- a/library/Smarty/libs/sysplugins/smarty_internal_template.php
+++ b/library/Smarty/libs/sysplugins/smarty_internal_template.php
@@ -1,28 +1,27 @@
<?php
/**
* Smarty Internal Plugin Template
- *
* This file contains the Smarty template engine
*
- * @package Smarty
+ * @package Smarty
* @subpackage Template
- * @author Uwe Tews
+ * @author Uwe Tews
*/
/**
* Main class with template data structures and methods
*
- * @package Smarty
+ * @package Smarty
* @subpackage Template
- *
* @property Smarty_Template_Source $source
* @property Smarty_Template_Compiled $compiled
* @property Smarty_Template_Cached $cached
*/
-class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
-
+class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
+{
/**
* cache_id
+ *
* @var string
*/
public $cache_id = null;
@@ -33,95 +32,108 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public $compile_id = null;
/**
* caching enabled
+ *
* @var boolean
*/
public $caching = null;
/**
* cache lifetime in seconds
+ *
* @var integer
*/
public $cache_lifetime = null;
/**
* Template resource
+ *
* @var string
*/
public $template_resource = 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
+ *
* @var bool
*/
public $has_nocache_code = false;
/**
* special compiled and cached template properties
+ *
* @var array
*/
public $properties = array('file_dependency' => array(),
- 'nocache_hash' => '',
- 'function' => array());
+ 'nocache_hash' => '',
+ 'function' => array());
/**
* required plugins
+ *
* @var array
*/
public $required_plugins = array('compiled' => array(), 'nocache' => array());
/**
* Global smarty instance
+ *
* @var Smarty
*/
public $smarty = null;
/**
* 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());
/**
* Create template data object
- *
* Some of the global Smarty settings copied to template scope
* It load the required template resources and cacher 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 $_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
*/
public function __construct($template_resource, $smarty, $_parent = null, $_cache_id = null, $_compile_id = null, $_caching = null, $_cache_lifetime = null)
{
- $this->smarty = &$smarty;
+ $this->smarty = & $smarty;
// Smarty parameter
$this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
$this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
$this->caching = $_caching === null ? $this->smarty->caching : $_caching;
- if ($this->caching === true)
+ if ($this->caching === true) {
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
+ }
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
$this->parent = $_parent;
// Template resource
@@ -134,9 +146,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
/**
* 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()
@@ -153,12 +165,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$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
*/
public function compileTemplateSource()
@@ -166,16 +178,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if (!$this->source->recompiled) {
$this->properties['file_dependency'] = array();
if ($this->source->components) {
+ // for the extends resource the compiler will fill it
// uses real resource for file dependency
- $source = end($this->source->components);
- $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
+ // $source = end($this->source->components);
+ // $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
} else {
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
}
}
- if ($this->smarty->debugging) {
- Smarty_Internal_Debug::start_compile($this);
- }
// compile locking
if ($this->smarty->compile_locking && !$this->source->recompiled) {
if ($saved_timestamp = $this->compiled->timestamp) {
@@ -185,7 +195,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// call compiler
try {
$code = $this->compiler->compileTemplate($this);
- } catch (Exception $e) {
+ }
+ catch (Exception $e) {
// restore old timestamp in case of error
if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
touch($this->compiled->filepath, $saved_timestamp);
@@ -196,15 +207,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
// write compiled template
$_filepath = $this->compiled->filepath;
- if ($_filepath === false)
+ if ($_filepath === false) {
throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
+ }
Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
$this->compiled->exists = true;
$this->compiled->isCompiled = true;
}
- if ($this->smarty->debugging) {
- Smarty_Internal_Debug::end_compile($this);
- }
// release compiler object to free memory
unset($this->compiler);
}
@@ -212,6 +221,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
/**
* Writes the cached template output
*
+ * @param string $content
+ *
* @return bool
*/
public function writeCachedContent($content)
@@ -220,13 +231,18 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
// don't write cache file
return false;
}
+ $this->cached->timestamp = time();
$this->properties['cache_lifetime'] = $this->cache_lifetime;
- $this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true));
+ $this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
$content = $this->createTemplateCodeFrame($content, true);
+ /** @var Smarty_Internal_Template $_smarty_tpl
+ * used in evaluated code
+ */
$_smarty_tpl = $this;
eval("?>" . $content);
$this->cached->valid = true;
$this->cached->processed = true;
+
return $this->cached->write($this, $content);
}
@@ -238,15 +254,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @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 $vars optional variables to assign
+ * @param $data
* @param int $parent_scope scope in which {include} should execute
+ *
* @returns string template content
*/
public function getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
{
// already in template cache?
if ($this->smarty->allow_ambiguous_resources) {
- $_templateId = Smarty_Resource::getUniqueTemplateName($this->smarty, $template) . $cache_id . $compile_id;
+ $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id;
} else {
$_templateId = $this->smarty->joined_template_dir . '#' . $template . $cache_id . $compile_id;
}
@@ -268,13 +285,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$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;
+ $tpl->tpl_vars = & $this->tpl_vars;
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
- $tpl->tpl_vars = &Smarty::$global_tpl_vars;
+ $tpl->tpl_vars = & Smarty::$global_tpl_vars;
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
- $tpl->tpl_vars = &$this->tpl_vars;
+ $tpl->tpl_vars = & $this->tpl_vars;
} else {
- $tpl->tpl_vars = &$scope_ptr->tpl_vars;
+ $tpl->tpl_vars = & $scope_ptr->tpl_vars;
}
$tpl->config_vars = $this->config_vars;
if (!empty($data)) {
@@ -283,6 +300,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$tpl->tpl_vars[$_key] = new Smarty_variable($_val);
}
}
+
return $tpl->fetch(null, null, null, null, false, false, true);
}
@@ -294,27 +312,28 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* @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 $vars optional variables to assign
+ * @param $data
* @param int $parent_scope scope in which {include} should execute
* @param string $hash nocache hash code
+ *
* @returns string template content
*/
public function setupInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash)
{
$tpl = new $this->smarty->template_class($template, $this->smarty, $this, $cache_id, $compile_id, $caching, $cache_lifetime);
- $tpl->properties['nocache_hash'] = $hash;
+ $tpl->properties['nocache_hash'] = $hash;
// get variables from calling scope
- if ($parent_scope == Smarty::SCOPE_LOCAL ) {
+ 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;
+ $tpl->tpl_vars = & $this->tpl_vars;
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
- $tpl->tpl_vars = &Smarty::$global_tpl_vars;
+ $tpl->tpl_vars = & Smarty::$global_tpl_vars;
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
- $tpl->tpl_vars = &$this->tpl_vars;
+ $tpl->tpl_vars = & $this->tpl_vars;
} else {
- $tpl->tpl_vars = &$scope_ptr->tpl_vars;
+ $tpl->tpl_vars = & $scope_ptr->tpl_vars;
}
$tpl->config_vars = $this->config_vars;
if (!empty($data)) {
@@ -323,15 +342,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$tpl->tpl_vars[$_key] = new Smarty_variable($_val);
}
}
+
return $tpl;
}
-
/**
* Create code frame for compiled and cached templates
*
- * @param string $content optional template content
- * @param bool $cache flag for cache file
+ * @param string $content optional template content
+ * @param bool $cache flag for cache file
+ *
* @return string
*/
public function createTemplateCodeFrame($content = '', $cache = false)
@@ -344,7 +364,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
foreach ($this->required_plugins['compiled'] as $tmp) {
foreach ($tmp as $data) {
$file = addslashes($data['file']);
- $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$file}';\n";
+ if (is_Array($data['function'])) {
+ $plugins_string .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n";
+ } else {
+ $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$file}';\n";
+ }
}
}
$plugins_string .= '?>';
@@ -355,7 +379,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
foreach ($this->required_plugins['nocache'] as $tmp) {
foreach ($tmp as $data) {
$file = addslashes($data['file']);
- $plugins_string .= addslashes("if (!is_callable('{$data['function']}')) include '{$file}';\n");
+ if (is_Array($data['function'])) {
+ $plugins_string .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n");
+ } else {
+ $plugins_string .= addslashes("if (!is_callable('{$data['function']}')) include '{$file}';\n");
+ }
}
}
$plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n";
@@ -382,7 +410,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
}
}
- foreach ($this->smarty->template_functions as $name => $function_data) {
+ foreach ($this->smarty->template_functions as $name => $function_data) {
if (isset($function_data['called_nocache'])) {
unset($function_data['called_nocache'], $function_data['called_functions'], $this->smarty->template_functions[$name]['called_nocache']);
$this->properties['function'][$name] = $function_data;
@@ -392,7 +420,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
$this->properties['version'] = Smarty::SMARTY_VERSION;
if (!isset($this->properties['unifunc'])) {
- $this->properties['unifunc'] = 'content_' . str_replace('.', '_', uniqid('', true));
+ $this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
}
if (!$this->source->recompiled) {
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($this->properties, true) . ',' . ($cache ? 'true' : 'false') . "); /*/%%SmartyHeaderCode%%*/?>\n";
@@ -401,20 +429,21 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$output .= $plugins_string;
$output .= $content;
if (!$this->source->recompiled) {
- $output .= '<?php }} ?>';
+ $output .= "<?php }} ?>\n";
}
+
return $output;
}
/**
* 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
+ * @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)
{
@@ -436,7 +465,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$is_valid = true;
if ($this->properties['version'] != Smarty::SMARTY_VERSION) {
$is_valid = false;
- } else if (((!$cache && $this->smarty->compile_check && empty($this->compiled->_properties) && !$this->compiled->isCompiled) || $cache && ($this->smarty->compile_check === true || $this->smarty->compile_check === Smarty::COMPILECHECK_ON)) && !empty($this->properties['file_dependency'])) {
+ } elseif (((!$cache && $this->smarty->compile_check && empty($this->compiled->_properties) && !$this->compiled->isCompiled) || $cache && ($this->smarty->compile_check === true || $this->smarty->compile_check === Smarty::COMPILECHECK_ON)) && !empty($this->properties['file_dependency'])) {
foreach ($this->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)) {
@@ -459,6 +488,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
}
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 &&
+ $this->properties['cache_lifetime'] >= 0 &&
+ (time() > ($this->cached->timestamp + $this->properties['cache_lifetime']))
+ ) {
+ $is_valid = false;
+ }
$this->cached->valid = $is_valid;
} else {
$this->mustCompile = !$is_valid;
@@ -467,15 +503,16 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
if (!$cache) {
$this->compiled->_properties = $properties;
}
+
return $is_valid;
}
/**
* Template code runtime function to create a local Smarty variable for array assignments
*
- * @param string $tpl_var tempate variable name
- * @param bool $nocache cache mode of variable
- * @param int $scope scope of variable
+ * @param string $tpl_var tempate 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)
{
@@ -495,8 +532,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
/**
* 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
+ * @param int $scope requested variable scope
+ *
+ * @return array array of template variables
*/
public function &getScope($scope)
{
@@ -507,18 +545,21 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
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 pqrent or root scope
+ * @param int $scope pqrent or root scope
+ *
* @return mixed object
*/
public function getScopePointer($scope)
@@ -530,16 +571,19 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
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
+ * @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)
{
@@ -562,12 +606,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
} elseif (is_object($value)) {
return count($value);
}
+
return 0;
}
/**
* runtime error not matching capture tags
- *
+
*/
public function capture_error()
{
@@ -575,22 +620,26 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
/**
- * Empty cache for this template
- *
- * @param integer $exp_time expiration time
- * @return integer number of cache files deleted
- */
- public function clearCache($exp_time=null)
+ * 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_name, $this->cache_id, $this->compile_id, $exp_time);
}
- /**
+ /**
* set Smarty property in template context
*
* @param string $property_name property name
* @param mixed $value value
+ *
+ * @throws SmartyException
*/
public function __set($property_name, $value)
{
@@ -600,12 +649,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
case 'cached':
case 'compiler':
$this->$property_name = $value;
+
return;
// FIXME: routing of template -> smarty attributes
default:
if (property_exists($this->smarty, $property_name)) {
$this->smarty->$property_name = $value;
+
return;
}
}
@@ -617,6 +668,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
* get Smarty property in template context
*
* @param string $property_name property name
+ *
+ * @throws SmartyException
*/
public function __get($property_name)
{
@@ -640,10 +693,12 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
$this->smarty->template_objects[$_templateId] = $this;
}
+
return $this->source;
case 'compiled':
$this->compiled = $this->source->getCompiled($this);
+
return $this->compiled;
case 'cached':
@@ -651,11 +706,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
include SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
}
$this->cached = new Smarty_Template_Cached($this);
+
return $this->cached;
case 'compiler':
$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);
+
return $this->compiler;
// FIXME: routing of template -> smarty attributes
@@ -669,8 +726,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
/**
- * Template data object destrutor
- *
+ * Template data object destructor
+
*/
public function __destruct()
{
@@ -678,7 +735,4 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
$this->cached->handler->releaseLock($this->smarty, $this->cached);
}
}
-
}
-
-?> \ No newline at end of file