32 public function fetch($template = null, $cache_id = null, $compile_id = null,
$parent = null, $display =
false, $merge_tpl_vars =
true, $no_output_filter =
false)
35 if ($template === null && $this instanceof $this->template_class) {
38 if (!empty($cache_id) && is_object($cache_id)) {
42 if (
$parent === null && ($this instanceof
Smarty || is_string($template))) {
48 : $this->smarty->createTemplate($template, $cache_id, $compile_id,
$parent,
false);
50 if ($this instanceof
Smarty) {
51 $_template->caching = $this->caching;
54 if ($merge_tpl_vars) {
56 $save_tpl_vars = $_template->tpl_vars;
57 $save_config_vars = $_template->config_vars;
58 $ptr_array = array($_template);
60 while (isset($ptr->parent)) {
61 $ptr_array[] = $ptr = $ptr->parent;
63 $ptr_array = array_reverse($ptr_array);
64 $parent_ptr = reset($ptr_array);
67 while ($parent_ptr = next($ptr_array)) {
68 if (!empty($parent_ptr->tpl_vars)) {
71 if (!empty($parent_ptr->config_vars)) {
82 if (!isset($_template->tpl_vars[
'smarty'])) {
85 if (isset($this->smarty->error_reporting)) {
86 $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);
89 if (!$this->smarty->debugging && $this->smarty->debugging_ctrl ==
'URL') {
90 if (isset($_SERVER[
'QUERY_STRING'])) {
91 $_query_string = $_SERVER[
'QUERY_STRING'];
95 if (
false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {
96 if (
false !== strpos($_query_string, $this->smarty->smarty_debug_id .
'=on')) {
98 setcookie(
'SMARTY_DEBUG',
true);
99 $this->smarty->debugging =
true;
100 }
elseif (
false !== strpos($_query_string, $this->smarty->smarty_debug_id .
'=off')) {
102 setcookie(
'SMARTY_DEBUG',
false);
103 $this->smarty->debugging =
false;
106 $this->smarty->debugging =
true;
109 if (isset($_COOKIE[
'SMARTY_DEBUG'])) {
110 $this->smarty->debugging =
true;
115 $_template->smarty->merged_templates_func = array();
118 if ($_template->source->recompiled) {
119 $_template->caching =
false;
122 if (!$_template->source->exists) {
124 $parent_resource =
" in '{$_template->parent->template_resource}'";
126 $parent_resource =
'';
128 throw new SmartyException(
"Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
133 if (!$_template->source->uncompiled) {
134 $_smarty_tpl = $_template;
135 if ($_template->source->recompiled) {
136 if ($this->smarty->debugging) {
139 $code = $_template->compiler->compileTemplate($_template);
140 if ($this->smarty->debugging) {
143 if ($this->smarty->debugging) {
150 }
catch (Exception $e) {
155 if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) {
156 $_template->compileTemplateSource();
158 if ($this->smarty->debugging) {
161 if (!$_template->compiled->loaded) {
162 include($_template->compiled->filepath);
163 if ($_template->mustCompile) {
165 $_template->compileTemplateSource();
166 include($_template->compiled->filepath);
168 $_template->compiled->loaded =
true;
170 $_template->decodeProperties($_template->compiled->_properties,
false);
174 if (empty($_template->properties[
'unifunc']) || !is_callable($_template->properties[
'unifunc'])) {
175 throw new SmartyException(
"Invalid compiled template for '{$_template->template_resource}'");
177 array_unshift($_template->_capture_stack,array());
181 $_template->properties[
'unifunc']($_template);
183 if (isset($_template->_capture_stack[0][0])) {
184 $_template->capture_error();
186 array_shift($_template->_capture_stack);
187 }
catch (Exception $e) {
193 if ($_template->source->uncompiled) {
194 if ($this->smarty->debugging) {
199 $_template->source->renderUncompiled($_template);
200 }
catch (Exception $e) {
205 throw new SmartyException(
"Resource '$_template->source->type' must have 'renderUncompiled' method");
208 $_output = ob_get_clean();
209 if (!$_template->source->recompiled && empty($_template->properties[
'file_dependency'][$_template->source->uid])) {
210 $_template->properties[
'file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
213 $_template->parent->properties[
'file_dependency'] = array_merge($_template->parent->properties[
'file_dependency'], $_template->properties[
'file_dependency']);
214 foreach ($_template->required_plugins as $code => $tmp1) {
215 foreach ($tmp1 as $name => $tmp) {
216 foreach ($tmp as $type =>
$data) {
217 $_template->parent->required_plugins[$code][$name][$type] =
$data;
222 if ($this->smarty->debugging) {
227 if ($this->smarty->debugging) {
230 $_template->properties[
'has_nocache_code'] =
false;
232 $cache_split = preg_split(
"!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output);
234 preg_match_all(
"!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts);
237 foreach ($cache_split as $curr_idx => $curr_split) {
239 $output .= preg_replace(
'/(<%|%>|<\?php|<\?|\?>)/',
'<?php echo \'$1\'; ?>', $curr_split);
240 if (isset($cache_parts[0][$curr_idx])) {
241 $_template->properties[
'has_nocache_code'] =
true;
243 $output .= preg_replace(
"!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!",
'', $cache_parts[0][$curr_idx]);
246 if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters[
'output']) || isset($this->smarty->registered_filters[
'output']))) {
250 $_smarty_tpl = $_template;
254 $_output = ob_get_clean();
255 }
catch (Exception $e) {
260 $_template->writeCachedContent(
$output);
261 if ($this->smarty->debugging) {
266 if (!empty($_template->properties[
'nocache_hash']) && !empty($_template->parent->properties[
'nocache_hash'])) {
268 $_output = str_replace(
"{$_template->properties['nocache_hash']}", $_template->parent->properties[
'nocache_hash'], $_output);
269 $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
273 if ($this->smarty->debugging) {
278 array_unshift($_template->_capture_stack,array());
282 $_template->properties[
'unifunc']($_template);
284 if (isset($_template->_capture_stack[0][0])) {
285 $_template->capture_error();
287 array_shift($_template->_capture_stack);
288 $_output = ob_get_clean();
289 }
catch (Exception $e) {
293 if ($this->smarty->debugging) {
297 if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters[
'output']) || isset($this->smarty->registered_filters[
'output']))) {
300 if (isset($this->error_reporting)) {
301 error_reporting($_smarty_old_error_level);
305 if ($this->caching && $this->cache_modified_check) {
306 $_isCached = $_template->isCached() && !$_template->has_nocache_code;
307 $_last_modified_date = @substr($_SERVER[
'HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER[
'HTTP_IF_MODIFIED_SINCE'],
'GMT') + 3);
308 if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
313 header(
'Status: 304 Not Modified');
317 if (!empty($_SERVER[
'SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
318 $_SERVER[
'SMARTY_PHPUNIT_HEADERS'][] =
'304 Not Modified';
323 header($_SERVER[
'SERVER_PROTOCOL'].
' 304 Not Modified');
329 if (!empty($_SERVER[
'SMARTY_PHPUNIT_DISABLE_HEADERS'])) {
330 $_SERVER[
'SMARTY_PHPUNIT_HEADERS'][] =
'Last-Modified: ' . gmdate(
'D, d M Y H:i:s', $_template->cached->timestamp) .
' GMT';
335 header(
'Last-Modified: ' . gmdate(
'D, d M Y H:i:s', $_template->cached->timestamp) .
' GMT');
344 if ($this->smarty->debugging) {
347 if ($merge_tpl_vars) {
349 $_template->tpl_vars = $save_tpl_vars;
350 $_template->config_vars = $save_config_vars;
352 $GLOBALS[
'peel_debug'][] = array(
'template' =>
'Display template Smarty <b>' . $_template->source->name .
'</b>' . ($_template->smarty->force_compile?
' - <span class="bold">recompile forced</span> (=> you are working local or with recompile forced in your configuration file)':
''),
'duration' =>
microtime_float() -
$GLOBALS[
'smarty_create_time'],
'start' =>
$GLOBALS[
'smarty_create_time'] -
$GLOBALS[
'script_start_time']);
355 if ($merge_tpl_vars) {
357 $_template->tpl_vars = $save_tpl_vars;
358 $_template->config_vars = $save_config_vars;
360 $GLOBALS[
'peel_debug'][] = array(
'template' =>
'Fetch template Smarty <b>' . $_template->source->name .
'</b>' . ($_template->smarty->force_compile?
' - <span class="bold">recompile forced</span> (=> you are working local or with recompile forced in your configuration file)':
''),
'duration' =>
microtime_float() -
$GLOBALS[
'smarty_create_time'],
'start' =>
$GLOBALS[
'smarty_create_time'] -
$GLOBALS[
'script_start_time']);
374 public function display($template = null, $cache_id = null, $compile_id = null,
$parent = null)
377 $this->
fetch($template, $cache_id, $compile_id,
$parent,
true);
389 public function isCached($template = null, $cache_id = null, $compile_id = null,
$parent = null)
391 if ($template === null && $this instanceof $this->template_class) {
392 return $this->cached->valid;
394 if (!($template instanceof $this->template_class)) {
398 $template = $this->smarty->createTemplate($template, $cache_id, $compile_id,
$parent,
false);
401 return $template->cached->valid;
426 public function registerPlugin($type, $tag, $callback, $cacheable =
true, $cache_attr = null)
428 if (isset($this->smarty->registered_plugins[$type][$tag])) {
430 }
elseif (!is_callable($callback)) {
433 $this->smarty->registered_plugins[$type][$tag] = array($callback, (
bool) $cacheable, (array) $cache_attr);
448 if (isset($this->smarty->registered_plugins[$type][$tag])) {
449 unset($this->smarty->registered_plugins[$type][$tag]);
464 $this->smarty->registered_resources[$type] = $callback instanceof
Smarty_Resource ? $callback : array($callback,
false);
476 if (isset($this->smarty->registered_resources[$type])) {
477 unset($this->smarty->registered_resources[$type]);
492 $this->smarty->registered_cache_resources[$type] = $callback;
504 if (isset($this->smarty->registered_cache_resources[$type])) {
505 unset($this->smarty->registered_cache_resources[$type]);
523 public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args =
true, $block_methods = array())
526 if (!empty($allowed)) {
527 foreach ((array) $allowed as $method) {
528 if (!is_callable(array($object_impl, $method))) {
529 throw new SmartyException(
"Undefined method '$method' in registered object");
534 if (!empty($block_methods)) {
535 foreach ((array) $block_methods as $method) {
536 if (!is_callable(array($object_impl, $method))) {
537 throw new SmartyException(
"Undefined method '$method' in registered object");
542 $this->smarty->registered_objects[$object_name] =
543 array($object_impl, (array) $allowed, (
boolean) $smarty_args, (array) $block_methods);
556 if (!isset($this->smarty->registered_objects[$name])) {
559 if (!is_object($this->smarty->registered_objects[$name][0])) {
562 return $this->smarty->registered_objects[$name][0];
573 if (isset($this->smarty->registered_objects[$name])) {
574 unset($this->smarty->registered_objects[$name]);
591 if (!class_exists($class_impl)) {
592 throw new SmartyException(
"Undefined class '$class_impl' in register template class");
595 $this->smarty->registered_classes[$class_name] = $class_impl;
608 if (is_callable($callback)) {
609 $this->smarty->default_plugin_handler_func = $callback;
611 throw new SmartyException(
"Default plugin handler '$callback' not callable");
626 if (is_callable($callback)) {
627 $this->smarty->default_template_handler_func = $callback;
629 throw new SmartyException(
"Default template handler '$callback' not callable");
644 if (is_callable($callback)) {
645 $this->smarty->default_config_handler_func = $callback;
647 throw new SmartyException(
"Default config handler '$callback' not callable");
662 $this->smarty->registered_filters[$type][$this->
_get_filter_name($callback)] = $callback;
676 if (isset($this->smarty->registered_filters[$type][$name])) {
677 unset($this->smarty->registered_filters[$type][$name]);
691 if (is_array($function_name)) {
692 $_class_name = (is_object($function_name[0]) ?
693 get_class($function_name[0]) : $function_name[0]);
694 return $_class_name .
'_' . $function_name[1];
696 return $function_name;
709 $_plugin =
"smarty_{$type}filter_{$name}";
710 $_filter_name = $_plugin;
711 if ($this->smarty->loadPlugin($_plugin)) {
712 if (class_exists($_plugin,
false)) {
713 $_plugin = array($_plugin,
'execute');
715 if (is_callable($_plugin)) {
716 $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
732 $_filter_name =
"smarty_{$type}filter_{$name}";
733 if (isset($this->smarty->registered_filters[$type][$_filter_name])) {
734 unset ($this->smarty->registered_filters[$type][$_filter_name]);
746 private function replaceCamelcase(
$match) {
747 return "_" . strtolower(
$match[1]);
758 static $_prefixes = array(
'set' =>
true,
'get' =>
true);
759 static $_resolved_property_name = array();
760 static $_resolved_property_source = array();
763 if (method_exists($this->smarty, $name)) {
764 return call_user_func_array(array($this->smarty, $name), $args);
767 $first3 = strtolower(substr($name, 0, 3));
768 if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !==
'_') {
769 if (isset($_resolved_property_name[$name])) {
770 $property_name = $_resolved_property_name[$name];
774 $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
776 $property_name = preg_replace_callback(
'/([A-Z])/', array($this,
'replaceCamelcase'), $property_name);
777 $_resolved_property_name[$name] = $property_name;
779 if (isset($_resolved_property_source[$property_name])) {
780 $_is_this = $_resolved_property_source[$property_name];
783 if (property_exists($this, $property_name)) {
785 }
else if (property_exists($this->smarty, $property_name)) {
788 $_resolved_property_source[$property_name] = $_is_this;
791 if ($first3 ==
'get')
792 return $this->$property_name;
794 return $this->$property_name = $args[0];
795 }
else if ($_is_this ===
false) {
796 if ($first3 ==
'get')
797 return $this->smarty->$property_name;
799 return $this->smarty->$property_name = $args[0];
801 throw new SmartyException(
"property '$property_name' does not exist.");
805 if ($name ==
'Smarty') {
806 throw new SmartyException(
"PHP5 requires you to call __construct() instead of Smarty()");
static runFilter($type, $content, Smarty_Internal_Template $template)
Run filters over content.
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
getRegisteredObject($name)
return a reference to a registered object
unregisterCacheResource($type)
Unregisters a cache resource.
display($template=null, $cache_id=null, $compile_id=null, $parent=null)
displays a Smarty template
fetch($template=null, $cache_id=null, $compile_id=null, $parent=null, $display=false, $merge_tpl_vars=true, $no_output_filter=false)
fetches a rendered Smarty template
unregisterObject($name)
unregister an object
static end_compile($template)
End logging of compile time.
registerDefaultTemplateHandler($callback)
Registers a default template handler.
static start_cache($template)
Start logging of cache time.
registerObject($object_name, $object_impl, $allowed=array(), $smarty_args=true, $block_methods=array())
Registers object to be used in templates.
registerDefaultPluginHandler($callback)
Registers a default plugin handler.
static $global_tpl_vars
#@-
registerFilter($type, $callback)
Registers a filter function.
static end_cache($template)
End logging of cache time.
unloadFilter($type, $name)
unload a filter of specified type and name
microtime_float()
microtime_float()
const CACHING_LIFETIME_CURRENT
Smarty plugin to format text blocks.
static start_compile($template)
Start logging of compile time.
loadFilter($type, $name)
load a filter of specified type and name
unregisterFilter($type, $callback)
Unregisters a filter function.
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))
unregisterPlugin($type, $tag)
Unregister Plugin.
registerCacheResource($type, Smarty_CacheResource $callback)
Registers a cache resource to cache a template's output.
_get_filter_name($function_name)
Return internal filter name.
static end_render($template)
End logging of compile time.
unregisterResource($type)
Unregisters a resource.
$GLOBALS['page_columns_count']
__call($name, $args)
Handle unknown class methods.
registerResource($type, $callback)
Registers a resource to fetch a template.
static display_debug($obj)
Opens a window for the Smarty Debugging Consol and display the data.
registerPlugin($type, $tag, $callback, $cacheable=true, $cache_attr=null)
Registers plugin to be used in templates.
isCached($template=null, $cache_id=null, $compile_id=null, $parent=null)
test if cache is valid
registerDefaultConfigHandler($callback)
Registers a default template handler.
createData($parent=null)
creates a data object
registerClass($class_name, $class_impl)
Registers static classes to be used in templates.
static start_render($template)
Start logging of render time.