2012-07-04 05:23:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Template
|
|
|
|
* This file contains the Smarty template engine
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @package Smarty
|
2012-07-04 05:23:08 +00:00
|
|
|
* @subpackage Template
|
2014-09-07 11:38:28 +00:00
|
|
|
* @author Uwe Tews
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main class with template data structures and methods
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @package Smarty
|
2012-07-04 05:23:08 +00:00
|
|
|
* @subpackage Template
|
|
|
|
* @property Smarty_Template_Source $source
|
|
|
|
* @property Smarty_Template_Compiled $compiled
|
|
|
|
* @property Smarty_Template_Cached $cached
|
|
|
|
*/
|
2014-09-07 11:38:28 +00:00
|
|
|
class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|
|
|
{
|
2012-07-04 05:23:08 +00:00
|
|
|
/**
|
|
|
|
* cache_id
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $cache_id = null;
|
|
|
|
/**
|
|
|
|
* $compile_id
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $compile_id = null;
|
|
|
|
/**
|
|
|
|
* caching enabled
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
public $caching = null;
|
|
|
|
/**
|
|
|
|
* cache lifetime in seconds
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
public $cache_lifetime = null;
|
|
|
|
/**
|
|
|
|
* Template resource
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $template_resource = null;
|
|
|
|
/**
|
|
|
|
* flag if compiled template is invalid and must be (re)compiled
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $mustCompile = null;
|
|
|
|
/**
|
|
|
|
* flag if template does contain nocache code sections
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $has_nocache_code = false;
|
|
|
|
/**
|
|
|
|
* special compiled and cached template properties
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $properties = array('file_dependency' => array(),
|
2014-09-07 11:38:28 +00:00
|
|
|
'nocache_hash' => '',
|
|
|
|
'function' => array());
|
2012-07-04 05:23:08 +00:00
|
|
|
/**
|
|
|
|
* required plugins
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $required_plugins = array('compiled' => array(), 'nocache' => array());
|
|
|
|
/**
|
|
|
|
* Global smarty instance
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var Smarty
|
|
|
|
*/
|
|
|
|
public $smarty = null;
|
|
|
|
/**
|
|
|
|
* blocks for template inheritance
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $block_data = array();
|
|
|
|
/**
|
|
|
|
* variable filters
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $variable_filters = array();
|
|
|
|
/**
|
|
|
|
* optional log of tag/attributes
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $used_tags = array();
|
|
|
|
/**
|
|
|
|
* internal flag to allow relative path in child template blocks
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $allow_relative_path = false;
|
|
|
|
/**
|
|
|
|
* internal capture runtime stack
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param mixed $_cache_id cache id or null
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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)
|
|
|
|
{
|
2014-09-07 11:38:28 +00:00
|
|
|
$this->smarty = & $smarty;
|
2012-07-04 05:23:08 +00:00
|
|
|
// 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;
|
2014-09-07 11:38:28 +00:00
|
|
|
if ($this->caching === true) {
|
2012-07-04 05:23:08 +00:00
|
|
|
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
|
2014-09-07 11:38:28 +00:00
|
|
|
}
|
2012-07-04 05:23:08 +00:00
|
|
|
$this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @throws SmartyException
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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)));
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->mustCompile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles the template
|
|
|
|
* If the template is not evaluated the compiled template is saved on disk
|
|
|
|
*/
|
|
|
|
public function compileTemplateSource()
|
|
|
|
{
|
|
|
|
if (!$this->source->recompiled) {
|
|
|
|
$this->properties['file_dependency'] = array();
|
|
|
|
if ($this->source->components) {
|
2014-09-07 11:38:28 +00:00
|
|
|
// for the extends resource the compiler will fill it
|
2012-07-04 05:23:08 +00:00
|
|
|
// uses real resource for file dependency
|
2014-09-07 11:38:28 +00:00
|
|
|
// $source = end($this->source->components);
|
|
|
|
// $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
|
2012-07-04 05:23:08 +00:00
|
|
|
} else {
|
|
|
|
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// compile locking
|
|
|
|
if ($this->smarty->compile_locking && !$this->source->recompiled) {
|
|
|
|
if ($saved_timestamp = $this->compiled->timestamp) {
|
|
|
|
touch($this->compiled->filepath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// call compiler
|
|
|
|
try {
|
|
|
|
$code = $this->compiler->compileTemplate($this);
|
2014-09-07 11:38:28 +00:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
2012-07-04 05:23:08 +00:00
|
|
|
// restore old timestamp in case of error
|
|
|
|
if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
|
|
|
|
touch($this->compiled->filepath, $saved_timestamp);
|
|
|
|
}
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
// compiling succeded
|
|
|
|
if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
|
|
|
|
// write compiled template
|
|
|
|
$_filepath = $this->compiled->filepath;
|
2014-09-07 11:38:28 +00:00
|
|
|
if ($_filepath === false) {
|
2012-07-04 05:23:08 +00:00
|
|
|
throw new SmartyException('getCompiledFilepath() did not return a destination to save the compiled template to');
|
2014-09-07 11:38:28 +00:00
|
|
|
}
|
2012-07-04 05:23:08 +00:00
|
|
|
Smarty_Internal_Write_File::writeFile($_filepath, $code, $this->smarty);
|
|
|
|
$this->compiled->exists = true;
|
|
|
|
$this->compiled->isCompiled = true;
|
|
|
|
}
|
|
|
|
// release compiler object to free memory
|
|
|
|
unset($this->compiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the cached template output
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param string $content
|
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function writeCachedContent($content)
|
|
|
|
{
|
|
|
|
if ($this->source->recompiled || !($this->caching == Smarty::CACHING_LIFETIME_CURRENT || $this->caching == Smarty::CACHING_LIFETIME_SAVED)) {
|
|
|
|
// don't write cache file
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->properties['cache_lifetime'] = $this->cache_lifetime;
|
2014-09-07 11:38:28 +00:00
|
|
|
$this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
2012-07-04 05:23:08 +00:00
|
|
|
$content = $this->createTemplateCodeFrame($content, true);
|
2014-09-07 11:38:28 +00:00
|
|
|
/** @var Smarty_Internal_Template $_smarty_tpl
|
|
|
|
* used in evaluated code
|
|
|
|
*/
|
2012-07-04 05:23:08 +00:00
|
|
|
$_smarty_tpl = $this;
|
|
|
|
eval("?>" . $content);
|
|
|
|
$this->cached->valid = true;
|
|
|
|
$this->cached->processed = true;
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->cached->write($this, $content);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Template code runtime function to get subtemplate content
|
|
|
|
*
|
|
|
|
* @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
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param $data
|
2012-07-04 05:23:08 +00:00
|
|
|
* @param int $parent_scope scope in which {include} should execute
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id;
|
2012-07-04 05:23:08 +00:00
|
|
|
} else {
|
|
|
|
$_templateId = $this->smarty->joined_template_dir . '#' . $template . $cache_id . $compile_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_templateId[150])) {
|
|
|
|
$_templateId = sha1($_templateId);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
// 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) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $this->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & Smarty::$global_tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $this->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} else {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $scope_ptr->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $tpl->fetch(null, null, null, null, false, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param $data
|
2012-07-04 05:23:08 +00:00
|
|
|
* @param int $parent_scope scope in which {include} should execute
|
|
|
|
* @param string $hash nocache hash code
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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);
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->properties['nocache_hash'] = $hash;
|
2012-07-04 05:23:08 +00:00
|
|
|
// get variables from calling scope
|
2014-09-07 11:38:28 +00:00
|
|
|
if ($parent_scope == Smarty::SCOPE_LOCAL) {
|
2012-07-04 05:23:08 +00:00
|
|
|
$tpl->tpl_vars = $this->tpl_vars;
|
|
|
|
$tpl->tpl_vars['smarty'] = clone $this->tpl_vars['smarty'];
|
|
|
|
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $this->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & Smarty::$global_tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} elseif (($scope_ptr = $this->getScopePointer($parent_scope)) == null) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $this->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
} else {
|
2014-09-07 11:38:28 +00:00
|
|
|
$tpl->tpl_vars = & $scope_ptr->tpl_vars;
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $tpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create code frame for compiled and cached templates
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param string $content optional template content
|
|
|
|
* @param bool $cache flag for cache file
|
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function createTemplateCodeFrame($content = '', $cache = false)
|
|
|
|
{
|
|
|
|
$plugins_string = '';
|
|
|
|
// include code for plugins
|
|
|
|
if (!$cache) {
|
|
|
|
if (!empty($this->required_plugins['compiled'])) {
|
|
|
|
$plugins_string = '<?php ';
|
|
|
|
foreach ($this->required_plugins['compiled'] as $tmp) {
|
|
|
|
foreach ($tmp as $data) {
|
|
|
|
$file = addslashes($data['file']);
|
2014-09-07 11:38:28 +00:00
|
|
|
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";
|
|
|
|
}
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$plugins_string .= '?>';
|
|
|
|
}
|
|
|
|
if (!empty($this->required_plugins['nocache'])) {
|
|
|
|
$this->has_nocache_code = true;
|
|
|
|
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$this->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
|
|
|
foreach ($this->required_plugins['nocache'] as $tmp) {
|
|
|
|
foreach ($tmp as $data) {
|
|
|
|
$file = addslashes($data['file']);
|
2014-09-07 11:38:28 +00:00
|
|
|
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");
|
|
|
|
}
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// build property code
|
|
|
|
$this->properties['has_nocache_code'] = $this->has_nocache_code;
|
|
|
|
$output = '';
|
|
|
|
if (!$this->source->recompiled) {
|
|
|
|
$output = "<?php /*%%SmartyHeaderCode:{$this->properties['nocache_hash']}%%*/";
|
|
|
|
if ($this->smarty->direct_access_security) {
|
|
|
|
$output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($cache) {
|
|
|
|
// remove compiled code of{function} definition
|
|
|
|
unset($this->properties['function']);
|
|
|
|
if (!empty($this->smarty->template_functions)) {
|
|
|
|
// copy code of {function} tags called in nocache mode
|
|
|
|
foreach ($this->smarty->template_functions as $name => $function_data) {
|
|
|
|
if (isset($function_data['called_nocache'])) {
|
|
|
|
foreach ($function_data['called_functions'] as $func_name) {
|
|
|
|
$this->smarty->template_functions[$func_name]['called_nocache'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
foreach ($this->smarty->template_functions as $name => $function_data) {
|
2012-07-04 05:23:08 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->properties['version'] = Smarty::SMARTY_VERSION;
|
|
|
|
if (!isset($this->properties['unifunc'])) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$this->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
|
|
|
if (!$this->source->recompiled) {
|
|
|
|
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($this->properties, true) . ',' . ($cache ? 'true' : 'false') . "); /*/%%SmartyHeaderCode%%*/?>\n";
|
|
|
|
$output .= '<?php if ($_valid && !is_callable(\'' . $this->properties['unifunc'] . '\')) {function ' . $this->properties['unifunc'] . '($_smarty_tpl) {?>';
|
|
|
|
}
|
|
|
|
$output .= $plugins_string;
|
|
|
|
$output .= $content;
|
|
|
|
if (!$this->source->recompiled) {
|
2014-09-07 11:38:28 +00:00
|
|
|
$output .= "<?php }} ?>\n";
|
2012-07-04 05:23:08 +00:00
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
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
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @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
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
public function decodeProperties($properties, $cache = false)
|
|
|
|
{
|
|
|
|
$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 (!empty($properties['function'])) {
|
|
|
|
$this->properties['function'] = array_merge($this->properties['function'], $properties['function']);
|
|
|
|
$this->smarty->template_functions = array_merge($this->smarty->template_functions, $properties['function']);
|
|
|
|
}
|
|
|
|
$this->properties['version'] = (isset($properties['version'])) ? $properties['version'] : '';
|
|
|
|
$this->properties['unifunc'] = $properties['unifunc'];
|
|
|
|
// check file dependencies at compiled code
|
|
|
|
$is_valid = true;
|
|
|
|
if ($this->properties['version'] != Smarty::SMARTY_VERSION) {
|
|
|
|
$is_valid = false;
|
2014-09-07 11:38:28 +00:00
|
|
|
} 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'])) {
|
2012-07-04 05:23:08 +00:00
|
|
|
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)) {
|
|
|
|
// do not recheck current template
|
|
|
|
$mtime = $this->source->timestamp;
|
|
|
|
} else {
|
|
|
|
// file and php types can be checked without loading the respective resource handlers
|
|
|
|
$mtime = @filemtime($_file_to_check[0]);
|
|
|
|
}
|
|
|
|
} 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) {
|
2014-09-07 11:38:28 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2012-07-04 05:23:08 +00:00
|
|
|
$this->cached->valid = $is_valid;
|
|
|
|
} else {
|
|
|
|
$this->mustCompile = !$is_valid;
|
|
|
|
}
|
|
|
|
// store data in reusable Smarty_Template_Compiled
|
|
|
|
if (!$cache) {
|
|
|
|
$this->compiled->_properties = $properties;
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Template code runtime function to create a local Smarty variable for array assignments
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param string $tpl_var tempate variable name
|
|
|
|
* @param bool $nocache cache mode of variable
|
|
|
|
* @param int $scope scope of variable
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param int $scope requested variable scope
|
|
|
|
*
|
|
|
|
* @return array array of template variables
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $ptr->tpl_vars;
|
|
|
|
} elseif ($scope == Smarty::SCOPE_GLOBAL) {
|
|
|
|
return Smarty::$global_tpl_vars;
|
|
|
|
}
|
|
|
|
$null = null;
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get parent or root of template parent chain
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @param int $scope pqrent or root scope
|
|
|
|
*
|
2012-07-04 05:23:08 +00:00
|
|
|
* @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;
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $ptr;
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [util function] counts an array, arrayaccess/traversable or PDOStatement object
|
|
|
|
*
|
2014-09-07 11:38:28 +00:00
|
|
|
* @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
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* runtime error not matching capture tags
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
public function capture_error()
|
|
|
|
{
|
|
|
|
throw new SmartyException("Not matching {capture} open/close in \"{$this->template_resource}\"");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-07 11:38:28 +00:00
|
|
|
* Empty cache for this template
|
|
|
|
*
|
|
|
|
* @param integer $exp_time expiration time
|
|
|
|
*
|
|
|
|
* @return integer number of cache files deleted
|
|
|
|
*/
|
|
|
|
public function clearCache($exp_time = null)
|
2012-07-04 05:23:08 +00:00
|
|
|
{
|
|
|
|
Smarty_CacheResource::invalidLoadedCache($this->smarty);
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->cached->handler->clear($this->smarty, $this->template_name, $this->cache_id, $this->compile_id, $exp_time);
|
|
|
|
}
|
|
|
|
|
2014-09-07 11:38:28 +00:00
|
|
|
/**
|
2012-07-04 05:23:08 +00:00
|
|
|
* set Smarty property in template context
|
|
|
|
*
|
|
|
|
* @param string $property_name property name
|
|
|
|
* @param mixed $value value
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
|
|
|
* @throws SmartyException
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
public function __set($property_name, $value)
|
|
|
|
{
|
|
|
|
switch ($property_name) {
|
|
|
|
case 'source':
|
|
|
|
case 'compiled':
|
|
|
|
case 'cached':
|
|
|
|
case 'compiler':
|
|
|
|
$this->$property_name = $value;
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME: routing of template -> smarty attributes
|
|
|
|
default:
|
|
|
|
if (property_exists($this->smarty, $property_name)) {
|
|
|
|
$this->smarty->$property_name = $value;
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new SmartyException("invalid template property '$property_name'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get Smarty property in template context
|
|
|
|
*
|
|
|
|
* @param string $property_name property name
|
2014-09-07 11:38:28 +00:00
|
|
|
*
|
|
|
|
* @throws SmartyException
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
public function __get($property_name)
|
|
|
|
{
|
|
|
|
switch ($property_name) {
|
|
|
|
case 'source':
|
|
|
|
if (strlen($this->template_resource) == 0) {
|
|
|
|
throw new SmartyException('Missing template name');
|
|
|
|
}
|
|
|
|
$this->source = Smarty_Resource::source($this);
|
|
|
|
// cache template object under a unique ID
|
|
|
|
// do not cache eval resources
|
|
|
|
if ($this->source->type != 'eval') {
|
|
|
|
if ($this->smarty->allow_ambiguous_resources) {
|
|
|
|
$_templateId = $this->source->unique_resource . $this->cache_id . $this->compile_id;
|
|
|
|
} else {
|
|
|
|
$_templateId = $this->smarty->joined_template_dir . '#' . $this->template_resource . $this->cache_id . $this->compile_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($_templateId[150])) {
|
|
|
|
$_templateId = sha1($_templateId);
|
|
|
|
}
|
|
|
|
$this->smarty->template_objects[$_templateId] = $this;
|
|
|
|
}
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->source;
|
|
|
|
|
|
|
|
case 'compiled':
|
|
|
|
$this->compiled = $this->source->getCompiled($this);
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->compiled;
|
|
|
|
|
|
|
|
case 'cached':
|
|
|
|
if (!class_exists('Smarty_Template_Cached')) {
|
|
|
|
include SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php';
|
|
|
|
}
|
|
|
|
$this->cached = new Smarty_Template_Cached($this);
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
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);
|
2014-09-07 11:38:28 +00:00
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
return $this->compiler;
|
|
|
|
|
|
|
|
// FIXME: routing of template -> smarty attributes
|
|
|
|
default:
|
|
|
|
if (property_exists($this->smarty, $property_name)) {
|
|
|
|
return $this->smarty->$property_name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new SmartyException("template property '$property_name' does not exist.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-07 11:38:28 +00:00
|
|
|
* Template data object destructor
|
|
|
|
|
2012-07-04 05:23:08 +00:00
|
|
|
*/
|
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
|
|
|
|
$this->cached->handler->releaseLock($this->smarty, $this->cached);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|