65 'function' => array());
120 $this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
121 $this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
122 $this->caching = $_caching === null ? $this->smarty->caching : $_caching;
123 if ($this->caching ===
true)
125 $this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
126 $this->parent = $_parent;
131 $this->block_data = $this->parent->block_data;
144 if (!$this->source->exists) {
146 $parent_resource =
" in '$this->parent->template_resource}'";
148 $parent_resource =
'';
150 throw new SmartyException(
"Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
153 $this->
mustCompile = (!$this->source->uncompiled && ($this->smarty->force_compile || $this->source->recompiled || $this->compiled->timestamp ===
false ||
154 ($this->smarty->compile_check && $this->compiled->timestamp < $this->source->timestamp)));
166 if (!$this->source->recompiled) {
167 $this->properties[
'file_dependency'] = array();
168 if ($this->source->components) {
170 $source = end($this->source->components);
171 $this->properties[
'file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
173 $this->properties[
'file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
176 if ($this->smarty->debugging) {
180 if ($this->smarty->compile_locking && !$this->source->recompiled) {
181 if ($saved_timestamp = $this->compiled->timestamp) {
182 touch($this->compiled->filepath);
187 $code = $this->compiler->compileTemplate($this);
188 }
catch (Exception $e) {
190 if ($this->smarty->compile_locking && !$this->source->recompiled && $saved_timestamp) {
191 touch($this->compiled->filepath, $saved_timestamp);
196 if (!$this->source->recompiled && $this->compiler->write_compiled_code) {
198 $_filepath = $this->compiled->filepath;
199 if ($_filepath ===
false)
200 throw new SmartyException(
'getCompiledFilepath() did not return a destination to save the compiled template to');
202 $this->compiled->exists =
true;
203 $this->compiled->isCompiled =
true;
205 if ($this->smarty->debugging) {
209 unset($this->compiler);
224 $this->properties[
'unifunc'] =
'content_' . str_replace(
'.',
'_', uniqid(
'',
true));
226 $_smarty_tpl = $this;
227 eval(
"?>" . $content);
228 $this->cached->valid =
true;
229 $this->cached->processed =
true;
230 return $this->cached->write($this, $content);
248 if ($this->smarty->allow_ambiguous_resources) {
254 if (isset($_templateId[150])) {
255 $_templateId = sha1($_templateId);
257 if (isset($this->smarty->template_objects[$_templateId])) {
259 $tpl = clone $this->smarty->template_objects[$_templateId];
260 $tpl->parent = $this;
269 $tpl->tpl_vars[
'smarty'] = clone $this->tpl_vars[
'smarty'];
277 $tpl->tpl_vars = &$scope_ptr->tpl_vars;
282 foreach (
$data as $_key => $_val) {
283 $tpl->tpl_vars[$_key] =
new Smarty_variable($_val);
286 return $tpl->fetch(null, null, null, null,
false,
false,
true);
305 $tpl->properties[
'nocache_hash'] = $hash;
309 $tpl->tpl_vars[
'smarty'] = clone $this->tpl_vars[
'smarty'];
317 $tpl->tpl_vars = &$scope_ptr->tpl_vars;
322 foreach (
$data as $_key => $_val) {
323 $tpl->tpl_vars[$_key] =
new Smarty_variable($_val);
339 $plugins_string =
'';
342 if (!empty($this->required_plugins[
'compiled'])) {
343 $plugins_string =
'<?php ';
344 foreach ($this->required_plugins[
'compiled'] as $tmp) {
345 foreach ($tmp as
$data) {
346 $file = addslashes($data[
'file']);
347 if (is_Array($data[
'function'])){
348 $plugins_string .=
"if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n";
350 $plugins_string .=
"if (!is_callable('{$data['function']}')) include '{$file}';\n";
354 $plugins_string .=
'?>';
356 if (!empty($this->required_plugins[
'nocache'])) {
357 $this->has_nocache_code =
true;
358 $plugins_string .=
"<?php echo '/*%%SmartyNocache:{$this->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
359 foreach ($this->required_plugins[
'nocache'] as $tmp) {
360 foreach ($tmp as
$data) {
361 $file = addslashes($data[
'file']);
362 if (is_Array($data[
'function'])){
363 $plugins_string .= addslashes(
"if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) include '{$file}';\n");
365 $plugins_string .= addslashes(
"if (!is_callable('{$data['function']}')) include '{$file}';\n");
369 $plugins_string .=
"?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n";
375 if (!$this->source->recompiled) {
376 $output =
"<?php /*%%SmartyHeaderCode:{$this->properties['nocache_hash']}%%*/";
377 if ($this->smarty->direct_access_security) {
378 $output .=
"if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
383 unset($this->properties[
'function']);
384 if (!empty($this->smarty->template_functions)) {
386 foreach ($this->smarty->template_functions as $name => $function_data) {
387 if (isset($function_data[
'called_nocache'])) {
388 foreach ($function_data[
'called_functions'] as $func_name) {
389 $this->smarty->template_functions[$func_name][
'called_nocache'] =
true;
393 foreach ($this->smarty->template_functions as $name => $function_data) {
394 if (isset($function_data[
'called_nocache'])) {
395 unset($function_data[
'called_nocache'], $function_data[
'called_functions'], $this->smarty->template_functions[$name][
'called_nocache']);
396 $this->properties[
'function'][$name] = $function_data;
402 if (!isset($this->properties[
'unifunc'])) {
403 $this->properties[
'unifunc'] =
'content_' . str_replace(
'.',
'_', uniqid(
'',
true));
405 if (!$this->source->recompiled) {
406 $output .=
"\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($this->properties,
true) .
',' . ($cache ?
'true' :
'false') .
"); /*/%%SmartyHeaderCode%%*/?>\n";
407 $output .=
'<?php if ($_valid && !is_callable(\'' . $this->properties[
'unifunc'] .
'\')) {
function ' . $this->properties['unifunc
'] . '($_smarty_tpl) {?>
';
409 $output .= $plugins_string;
411 if (!$this->source->recompiled) {
412 $output .= '<?php }} ?>
';
427 public function decodeProperties($properties, $cache = false)
429 $this->has_nocache_code = $properties['has_nocache_code
'];
430 $this->properties['nocache_hash
'] = $properties['nocache_hash
'];
431 if (isset($properties['cache_lifetime
'])) {
432 $this->properties['cache_lifetime
'] = $properties['cache_lifetime
'];
434 if (isset($properties['file_dependency
'])) {
435 $this->properties['file_dependency
'] = array_merge($this->properties['file_dependency
'], $properties['file_dependency
']);
437 if (!empty($properties['function'])) {
438 $this->properties['function'] = array_merge($this->properties['function'], $properties['function']);
439 $this->smarty->template_functions = array_merge($this->smarty->template_functions, $properties['function']);
441 $this->properties['version
'] = (isset($properties['version
'])) ? $properties['version
'] : '';
442 $this->properties['unifunc
'] = $properties['unifunc
'];
443 // check file dependencies at compiled code
445 if ($this->properties['version
'] != Smarty::SMARTY_VERSION) {
447 } 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
'])) {
448 foreach ($this->properties['file_dependency
'] as $_file_to_check) {
449 if ($_file_to_check[2] == 'file
' || $_file_to_check[2] == 'php
') {
450 if ($this->source->filepath == $_file_to_check[0] && isset($this->source->timestamp)) {
451 // do not recheck current template
452 $mtime = $this->source->timestamp;
454 // file and php types can be checked without loading the respective resource handlers
455 $mtime = @filemtime($_file_to_check[0]);
457 } elseif ($_file_to_check[2] == 'string') {
460 $source = Smarty_Resource::source(null, $this->smarty, $_file_to_check[0]);
461 $mtime = $source->timestamp;
463 if (!$mtime || $mtime > $_file_to_check[1]) {
470 // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc
472 $this->properties[
'cache_lifetime'] >= 0 &&
473 (time() > ($this->cached->timestamp + $this->properties[
'cache_lifetime']))) {
476 $this->cached->valid = $is_valid;
495 if (!isset($this->tpl_vars[$tpl_var])) {
496 $this->tpl_vars[$tpl_var] =
new Smarty_variable(array(), $nocache, $scope);
498 $this->tpl_vars[$tpl_var] = clone $this->tpl_vars[$tpl_var];
500 $this->tpl_vars[$tpl_var]->scope = $scope;
502 if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
503 settype($this->tpl_vars[$tpl_var]->value,
'array');
517 return $this->parent->tpl_vars;
520 while (!empty($ptr->parent)) {
523 return $ptr->tpl_vars;
543 while (!empty($ptr->parent)) {
559 if (is_array($value) ===
true || $value instanceof Countable) {
560 return count($value);
561 }
elseif ($value instanceof IteratorAggregate) {
564 return iterator_count($value->getIterator());
565 }
elseif ($value instanceof Iterator) {
566 return iterator_count($value);
567 }
elseif ($value instanceof PDOStatement) {
568 return $value->rowCount();
569 }
elseif ($value instanceof Traversable) {
570 return iterator_count($value);
571 }
elseif ($value instanceof ArrayAccess) {
572 if ($value->offsetExists(0)) {
575 }
elseif (is_object($value)) {
576 return count($value);
587 throw new SmartyException(
"Not matching {capture} open/close in \"{$this->template_resource}\"");
599 return $this->cached->handler->clear($this->smarty, $this->template_name, $this->cache_id, $this->compile_id, $exp_time);
608 public function __set($property_name, $value)
610 switch ($property_name) {
615 $this->$property_name = $value;
620 if (property_exists($this->smarty, $property_name)) {
621 $this->smarty->$property_name = $value;
626 throw new SmartyException(
"invalid template property '$property_name'.");
634 public function __get($property_name)
636 switch ($property_name) {
638 if (strlen($this->template_resource) == 0) {
644 if ($this->source->type !=
'eval') {
645 if ($this->smarty->allow_ambiguous_resources) {
646 $_templateId = $this->source->unique_resource . $this->cache_id .
$this->compile_id;
648 $_templateId = $this->smarty->joined_template_dir .
'#' . $this->template_resource . $this->cache_id .
$this->compile_id;
651 if (isset($_templateId[150])) {
652 $_templateId = sha1($_templateId);
654 $this->smarty->template_objects[$_templateId] = $this;
656 return $this->source;
659 $this->compiled = $this->source->getCompiled($this);
660 return $this->compiled;
663 if (!class_exists(
'Smarty_Template_Cached')) {
664 include SMARTY_SYSPLUGINS_DIR .
'smarty_cacheresource.php';
667 return $this->cached;
670 $this->smarty->loadPlugin($this->source->compiler_class);
671 $this->compiler =
new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
672 return $this->compiler;
676 if (property_exists($this->smarty, $property_name)) {
677 return $this->smarty->$property_name;
681 throw new SmartyException(
"template property '$property_name' does not exist.");
690 if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
691 $this->cached->handler->releaseLock($this->smarty, $this->cached);
__set($property_name, $value)
set Smarty property in template context
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
getSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
Template code runtime function to get subtemplate content.
__construct($template_resource, $smarty, $_parent=null, $_cache_id=null, $_compile_id=null, $_caching=null, $_cache_lifetime=null)
Create template data object.
getScopePointer($scope)
Get parent or root of template parent chain.
setupInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash)
Template code runtime function to set up an inline subtemplate.
static end_compile($template)
End logging of compile time.
static invalidLoadedCache(Smarty $smarty)
Invalid Loaded Cache Files.
static $global_tpl_vars
#@-
__get($property_name)
get Smarty property in template context
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
const CACHING_LIFETIME_CURRENT
static start_compile($template)
Start logging of compile time.
_count($value)
[util function] counts an array, arrayaccess/traversable or PDOStatement object
static source(Smarty_Internal_Template $_template=null, Smarty $smarty=null, $template_resource=null)
initialize Source Object for given resource
& getScope($scope)
Template code runtime function to get pointer to template variable array of requested scope...
createLocalArrayVariable($tpl_var, $nocache=false, $scope=Smarty::SCOPE_LOCAL)
Template code runtime function to create a local Smarty variable for array assignments.
createTemplateCodeFrame($content= '', $cache=false)
Create code frame for compiled and cached templates.
static getUniqueTemplateName($smarty, $template_resource)
modify resource_name according to resource handlers specifications
const CACHING_LIFETIME_SAVED
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
__destruct()
Template data object destrutor.
capture_error()
runtime error not matching capture tags
compileTemplateSource()
Compiles the template.
const SCOPE_LOCAL
define variable scopes
writeCachedContent($content)
Writes the cached template output.
mustCompile()
Returns if the current template must be compiled by the Smarty compiler.
const SMARTY_VERSION
#@+ constant definitions
static writeFile($_filepath, $_contents, Smarty $smarty)
Writes file in a safe way to disk.
clearCache($exp_time=null)
Empty cache for this template.