61 'tpl_function' => array(),
117 $this->cache_id = $_cache_id === null ? $this->smarty->cache_id : $_cache_id;
118 $this->compile_id = $_compile_id === null ? $this->smarty->compile_id : $_compile_id;
119 $this->caching = $_caching === null ? $this->smarty->caching : $_caching;
120 if ($this->caching ===
true) {
123 $this->cache_lifetime = $_cache_lifetime === null ? $this->smarty->cache_lifetime : $_cache_lifetime;
124 $this->parent = $_parent;
129 $this->block_data = $this->parent->block_data;
142 return $this->
render(
true,
false,
false);
150 $this->
render(
true,
false,
true);
164 public function render($merge_tpl_vars =
false, $no_output_filter =
true, $display = null)
167 if ($this->smarty->debugging) {
170 $save_tpl_vars = null;
171 $save_config_vars = null;
173 if ($merge_tpl_vars) {
177 $ptr_array = array($this);
179 while (isset($ptr->parent)) {
180 $ptr_array[] = $ptr = $ptr->parent;
182 $ptr_array = array_reverse($ptr_array);
183 $parent_ptr = reset($ptr_array);
186 while ($parent_ptr = next($ptr_array)) {
187 if (!empty($parent_ptr->tpl_vars)) {
190 if (!empty($parent_ptr->config_vars)) {
201 if (!isset($this->tpl_vars[
'smarty'])) {
204 $_smarty_old_error_level = isset($this->smarty->error_reporting) ? error_reporting($this->smarty->error_reporting) : null;
206 if (!$this->smarty->debugging && $this->smarty->debugging_ctrl ==
'URL') {
209 if (!isset($this->source)) {
213 if (!$this->source->exists) {
215 $parent_resource =
" in '{$this->parent->template_resource}'";
217 $parent_resource =
'';
219 throw new SmartyException(
"Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
222 if ($this->source->recompiled) {
223 $this->caching =
false;
228 if (!isset($this->cached)) {
231 $this->cached->isCached($this);
233 if (!($isCacheTpl) || !$this->cached->valid) {
235 $this->properties[
'tpl_function'] = array();
238 if ($this->smarty->debugging) {
241 if (!$this->source->uncompiled) {
243 if (!isset($this->compiled)) {
246 $content = $this->compiled->render($this);
248 $content = $this->source->renderUncompiled($this);
250 if (!$this->source->recompiled && empty($this->properties[
'file_dependency'][$this->source->uid])) {
251 $this->properties[
'file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
254 $this->parent->properties[
'file_dependency'] = array_merge($this->parent->properties[
'file_dependency'], $this->properties[
'file_dependency']);
257 if ($this->smarty->debugging) {
261 if (!$this->source->recompiled && $isCacheTpl) {
262 if ($this->smarty->debugging) {
265 $this->cached->updateCache($this, $content, $no_output_filter);
266 $compile_check = $this->smarty->compile_check;
267 $this->smarty->compile_check =
false;
269 $this->properties[
'tpl_function'] = $this->parent->properties[
'tpl_function'];
271 if (!$this->cached->processed) {
272 $this->cached->process($this);
274 $this->smarty->compile_check = $compile_check;
276 if ($this->smarty->debugging) {
280 if (!empty($this->properties[
'nocache_hash']) && !empty($this->parent->properties[
'nocache_hash'])) {
282 $content = str_replace(
"{$this->properties['nocache_hash']}", $this->parent->properties[
'nocache_hash'], $content);
287 if ($this->smarty->debugging) {
290 $content = $this->cached->render($this);
291 if ($this->smarty->debugging) {
295 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']))) {
298 if (isset($_smarty_old_error_level)) {
299 error_reporting($_smarty_old_error_level);
303 if ($this->caching && $this->smarty->cache_modified_check) {
304 $this->cached->cacheModifiedCheck($this, $content);
308 if ($this->smarty->debugging) {
312 if ($this->smarty->debugging) {
315 if ($merge_tpl_vars) {
317 $this->tpl_vars = $save_tpl_vars;
318 $this->config_vars = $save_config_vars;
322 if ($merge_tpl_vars) {
324 $this->tpl_vars = $save_tpl_vars;
325 $this->config_vars = $save_config_vars;
327 if ($this->smarty->debugging) {
330 if ($this->smarty->debugging == 2 and $display ===
false) {
331 if ($this->smarty->debugging) {
336 $this->parent->properties[
'tpl_function'] = array_merge($this->parent->properties[
'tpl_function'], $this->properties[
'tpl_function']);
337 foreach ($this->required_plugins as $code => $tmp1) {
338 foreach ($tmp1 as $name => $tmp) {
339 foreach ($tmp as $type => $data) {
340 $this->parent->required_plugins[$code][$name][$type] = $data;
358 $level = ob_get_level();
361 if (empty($this->properties[
'unifunc']) || !is_callable($this->properties[
'unifunc'])) {
362 throw new SmartyException(
"Invalid compiled template for '{$this->template_resource}'");
364 if (isset($this->smarty->security_policy)) {
365 $this->smarty->security_policy->startTemplate($this);
367 array_unshift($this->_capture_stack, array());
371 $this->properties[
'unifunc']($this);
373 if (isset($this->_capture_stack[0][0])) {
376 array_shift($this->_capture_stack);
377 if (isset($this->smarty->security_policy)) {
378 $this->smarty->security_policy->exitTemplate($this);
380 return ob_get_clean();
382 catch (Exception $e) {
383 while (ob_get_level() > $level) {
400 if (!$this->source->exists) {
402 $parent_resource =
" in '$this->parent->template_resource}'";
404 $parent_resource =
'';
406 throw new SmartyException(
"Unable to load template {$this->source->type} '{$this->source->name}'{$parent_resource}");
409 $this->
mustCompile = (!$this->source->uncompiled && ($this->smarty->force_compile || $this->source->recompiled || $this->compiled->timestamp ===
false ||
410 ($this->smarty->compile_check && $this->compiled->timestamp < $this->source->timestamp)));
422 return $this->compiled->compileTemplateSource($this);
434 return $this->cached->writeCachedContent($this, $content);
453 return $tpl->render();
473 if (isset($this->smarty->template_objects[$_templateId])) {
475 $tpl = clone $this->smarty->template_objects[$_templateId];
476 $tpl->parent = $this;
477 if ((
bool) $tpl->caching !== (
bool)
$caching) {
478 unset($tpl->compiled);
484 $tpl->templateId = $_templateId;
489 $tpl->tpl_vars[
'smarty'] = clone $this->tpl_vars[
'smarty'];
494 } elseif (($scope_ptr = $this->
getScopePointer($parent_scope)) == null) {
497 $tpl->tpl_vars = &$scope_ptr->tpl_vars;
502 foreach ($data as $_key => $_val) {
506 $tpl->properties[
'tpl_function'] = $this->properties[
'tpl_function'];
528 $tpl->properties[
'nocache_hash'] = $hash;
529 if (!isset($this->smarty->template_objects[$tpl->templateId])) {
530 $this->smarty->template_objects[$tpl->templateId] = $tpl;
532 if ($this->smarty->debugging) {
536 $tpl->properties[
'unifunc'] = $content_func;
537 $output = $tpl->getRenderedTemplateCode();
538 if ($this->smarty->debugging) {
542 if (!empty($tpl->properties[
'file_dependency'])) {
543 $this->properties[
'file_dependency'] = array_merge($this->properties[
'file_dependency'], $tpl->properties[
'file_dependency']);
545 $this->properties[
'tpl_function'] = $tpl->properties[
'tpl_function'];
546 return str_replace($tpl->properties[
'nocache_hash'], $this->properties[
'nocache_hash'], $output);
561 if (isset($_smarty_tpl->properties[
'tpl_function'][$name])) {
562 if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
563 $function = $_smarty_tpl->properties[
'tpl_function'][$name][
'call_name'];
565 if (isset($_smarty_tpl->properties[
'tpl_function'][$name][
'call_name_caching'])) {
566 $function = $_smarty_tpl->properties[
'tpl_function'][$name][
'call_name_caching'];
568 $function = $_smarty_tpl->properties[
'tpl_function'][$name][
'call_name'];
571 if (function_exists($function)) {
572 $function ($_smarty_tpl, $params);
577 $function ($_smarty_tpl, $params);
581 throw new SmartyException(
"Unable to find template function '{$name}'");
601 } elseif ((!$cache && $this->smarty->compile_check || $cache && ($this->smarty->compile_check ===
true || $this->smarty->compile_check ===
Smarty::COMPILECHECK_ON)) && !empty(
$properties[
'file_dependency'])) {
603 foreach (
$properties[
'file_dependency'] as $_file_to_check) {
604 if ($_file_to_check[2] ==
'file' || $_file_to_check[2] ==
'php') {
605 if ($this->source->filepath == $_file_to_check[0] && isset($this->source->timestamp)) {
607 $mtime = $this->source->timestamp;
610 $mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) :
false;
612 } elseif ($_file_to_check[2] ==
'string') {
616 $mtime = $source->timestamp;
618 if (!$mtime || $mtime > $_file_to_check[1]) {
628 (time() > ($this->cached->timestamp +
$properties[
'cache_lifetime']))
632 $this->cached->valid = $is_valid;
637 $this->has_nocache_code =
$properties[
'has_nocache_code'];
640 $this->properties[
'cache_lifetime'] =
$properties[
'cache_lifetime'];
643 $this->properties[
'file_dependency'] = array_merge($this->properties[
'file_dependency'],
$properties[
'file_dependency']);
646 $this->properties[
'tpl_function'] = array_merge($this->properties[
'tpl_function'],
$properties[
'tpl_function']);
648 $this->properties[
'version'] =
$properties[
'version'];
649 $this->properties[
'unifunc'] =
$properties[
'unifunc'];
663 if (!isset($this->tpl_vars[$tpl_var])) {
664 $this->tpl_vars[$tpl_var] =
new Smarty_Variable(array(), $nocache, $scope);
666 $this->tpl_vars[$tpl_var] = clone $this->tpl_vars[$tpl_var];
668 $this->tpl_vars[$tpl_var]->scope = $scope;
670 if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
671 settype($this->tpl_vars[$tpl_var]->value,
'array');
686 return $this->parent->tpl_vars;
689 while (!empty($ptr->parent)) {
693 return $ptr->tpl_vars;
715 while (!empty($ptr->parent)) {
735 if (is_array($value) ===
true || $value instanceof Countable) {
736 return count($value);
737 } elseif ($value instanceof IteratorAggregate) {
740 return iterator_count($value->getIterator());
741 } elseif ($value instanceof Iterator) {
742 return iterator_count($value);
743 } elseif ($value instanceof PDOStatement) {
744 return $value->rowCount();
745 } elseif ($value instanceof Traversable) {
746 return iterator_count($value);
747 } elseif ($value instanceof ArrayAccess) {
748 if ($value->offsetExists(0)) {
751 } elseif (is_object($value)) {
752 return count($value);
763 throw new SmartyException(
"Not matching {capture} open/close in \"{$this->template_resource}\"");
777 return $this->cached->handler->clear($this->smarty, $this->template_resource, $this->cache_id, $this->compile_id, $exp_time);
788 if ($this->smarty->template_resource_caching && !$this->source->recompiled && isset($this->templateId)) {
799 if (!isset($this->compiled)) {
800 if (!class_exists(
'Smarty_Template_Compiled',
false)) {
801 require SMARTY_SYSPLUGINS_DIR .
'smarty_template_compiled.php';
813 if (!isset($this->cached)) {
814 if (!class_exists(
'Smarty_Template_Cached',
false)) {
815 require SMARTY_SYSPLUGINS_DIR .
'smarty_template_cached.php';
828 $this->smarty->loadPlugin($this->source->compiler_class);
829 $this->compiler =
new $this->source->compiler_class($this->source->template_lexer_class, $this->source->template_parser_class, $this->smarty);
844 if (method_exists($this->smarty, $name)) {
845 return call_user_func_array(array($this->smarty, $name), $args);
848 return parent::__call($name, $args);
859 public function __set($property_name, $value)
861 switch ($property_name) {
866 $this->$property_name = $value;
870 if (property_exists($this->smarty, $property_name)) {
871 $this->smarty->$property_name = $value;
875 throw new SmartyException(
"invalid template property '$property_name'.");
886 public function __get($property_name)
888 switch ($property_name) {
891 return $this->source;
895 return $this->compiled;
899 return $this->cached;
903 return $this->compiler;
906 if (property_exists($this->smarty, $property_name)) {
907 return $this->smarty->$property_name;
910 throw new SmartyException(
"template property '$property_name' does not exist.");
918 if ($this->smarty->cache_locking && isset($this->cached) && $this->cached->is_locked) {
919 $this->cached->handler->releaseLock($this->smarty, $this->cached);