26 private $nocache_hash = null;
151 abstract protected function doCompile($_content);
157 $this->nocache_hash = str_replace(
'.',
'-', uniqid(rand(),
true));
167 if (empty($template->properties[
'nocache_hash'])) {
168 $template->properties[
'nocache_hash'] = $this->nocache_hash;
170 $this->nocache_hash = $template->properties[
'nocache_hash'];
173 $this->nocache =
false;
174 $this->tag_nocache =
false;
178 $this->
template->has_nocache_code =
false;
179 $this->smarty->_current_file = $saved_filepath = $this->
template->source->filepath;
181 $template_header =
'';
182 if (!$this->suppressHeader) {
183 $template_header .=
"<?php /* Smarty version " .
Smarty::SMARTY_VERSION .
", created on " . strftime(
"%Y-%m-%d %H:%M:%S") .
"\n";
184 $template_header .=
" compiled from \"" . $this->
template->source->filepath .
"\" */ ?>\n";
189 $this->abort_and_recompile =
false;
191 $_content = $template->source->content;
193 if ((isset($this->smarty->autoload_filters[
'pre']) || isset($this->smarty->registered_filters[
'pre'])) && !$this->suppressFilter) {
197 if ($_content ==
'') {
198 if ($this->suppressTemplatePropertyHeader) {
206 $_compiled_code = $this->
doCompile($_content);
207 }
while ($this->abort_and_recompile);
208 $this->
template->source->filepath = $saved_filepath;
210 unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template);
211 self::$_tag_objects = array();
214 if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) {
215 foreach ($this->merged_templates as $code) {
216 $merged_code .= $code;
220 if ((isset($this->smarty->autoload_filters[
'post']) || isset($this->smarty->registered_filters[
'post'])) && !$this->suppressFilter) {
223 if ($this->suppressTemplatePropertyHeader) {
224 $code = $_compiled_code . $merged_code;
229 unset ($template->source->content);
244 public function compileTag($tag, $args, $parameter = array()) {
247 $this->has_code =
true;
248 $this->has_output =
false;
250 if (isset($this->smarty->get_used_tags) && $this->smarty->get_used_tags) {
251 $this->
template->used_tags[] = array($tag, $args);
254 if (in_array(
"'nocache'", $args) || in_array(array(
'nocache' =>
'true'), $args)
255 || in_array(array(
'nocache' =>
'"true"'), $args) || in_array(array(
'nocache' =>
"'true'"), $args)) {
256 $this->tag_nocache =
true;
259 if (($_output = $this->
callTagCompiler($tag, $args, $parameter)) ===
false) {
260 if (isset($this->smarty->template_functions[$tag])) {
262 $args[
'_attr'][
'name'] =
"'" . $tag .
"'";
266 if ($_output !==
false) {
267 if ($_output !==
true) {
269 if ($this->has_code) {
271 if ($this->has_output) {
282 if (isset($args[
'_attr'])) {
283 foreach ($args[
'_attr'] as $key => $attribute) {
284 if (is_array($attribute)) {
285 $args = array_merge($args, $attribute);
290 if (strlen($tag) < 6 || substr($tag, -5) !=
'close') {
292 if (isset($this->smarty->registered_objects[$tag]) && isset($parameter[
'object_methode'])) {
293 $methode = $parameter[
'object_methode'];
294 if (!in_array($methode, $this->smarty->registered_objects[$tag][3]) &&
295 (empty($this->smarty->registered_objects[$tag][1]) || in_array($methode, $this->smarty->registered_objects[$tag][1]))) {
296 return $this->
callTagCompiler(
'private_object_function', $args, $parameter, $tag, $methode);
297 }
elseif (in_array($methode, $this->smarty->registered_objects[$tag][3])) {
298 return $this->
callTagCompiler(
'private_object_block_function', $args, $parameter, $tag, $methode);
300 return $this->
trigger_template_error(
'unallowed methode "' . $methode .
'" in registered object "' . $tag .
'"', $this->lex->taglineno);
305 if (isset($this->smarty->registered_plugins[$plugin_type][$tag])) {
309 foreach ($args as $key => $mixed) {
310 if (is_array($mixed)) {
311 $new_args = array_merge($new_args, $mixed);
313 $new_args[$key] = $mixed;
316 if (!$this->smarty->registered_plugins[$plugin_type][$tag][1]) {
317 $this->tag_nocache =
true;
319 $function = $this->smarty->registered_plugins[$plugin_type][$tag][0];
320 if (!is_array($function)) {
321 return $function($new_args, $this);
322 }
else if (is_object($function[0])) {
323 return $this->smarty->registered_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this);
325 return call_user_func_array($function, array($new_args, $this));
330 return $this->
callTagCompiler(
'private_registered_' . $plugin_type, $args, $parameter, $tag);
335 foreach ($this->smarty->plugin_search_order as $plugin_type) {
336 if ($plugin_type ==
Smarty::PLUGIN_COMPILER && $this->smarty->loadPlugin(
'smarty_compiler_' . $tag) && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))) {
337 $plugin =
'smarty_compiler_' . $tag;
338 if (is_callable($plugin)) {
341 foreach ($args as $key => $mixed) {
342 if (is_array($mixed)) {
343 $new_args = array_merge($new_args, $mixed);
345 $new_args[$key] = $mixed;
348 return $plugin($new_args, $this->smarty);
350 if (class_exists($plugin,
false)) {
351 $plugin_object =
new $plugin;
352 if (method_exists($plugin_object,
'compile')) {
353 return $plugin_object->compile($args, $this);
358 if ($function = $this->
getPlugin($tag, $plugin_type)) {
359 if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
360 return $this->
callTagCompiler(
'private_' . $plugin_type .
'_plugin', $args, $parameter, $tag, $function);
365 if (is_callable($this->smarty->default_plugin_handler_func)) {
368 foreach ($this->smarty->plugin_search_order as $plugin_type) {
369 if (isset($this->default_handler_plugins[$plugin_type][$tag])) {
376 foreach ($this->smarty->plugin_search_order as $plugin_type) {
387 foreach ($args as $mixed) {
388 $new_args = array_merge($new_args, $mixed);
390 $function = $this->default_handler_plugins[$plugin_type][$tag][0];
391 if (!is_array($function)) {
392 return $function($new_args, $this);
393 }
else if (is_object($function[0])) {
394 return $this->default_handler_plugins[$plugin_type][$tag][0][0]->$function[1]($new_args, $this);
396 return call_user_func_array($function, array($new_args, $this));
399 return $this->
callTagCompiler(
'private_registered_' . $plugin_type, $args, $parameter, $tag);
405 $base_tag = substr($tag, 0, -5);
407 if (isset($this->smarty->registered_objects[$base_tag]) && isset($parameter[
'object_methode'])) {
408 $methode = $parameter[
'object_methode'];
409 if (in_array($methode, $this->smarty->registered_objects[$base_tag][3])) {
410 return $this->
callTagCompiler(
'private_object_block_function', $args, $parameter, $tag, $methode);
412 return $this->
trigger_template_error(
'unallowed closing tag methode "' . $methode .
'" in registered object "' . $base_tag .
'"', $this->lex->taglineno);
417 return $this->
callTagCompiler(
'private_registered_block', $args, $parameter, $tag);
421 return $this->
callTagCompiler(
'private_block_plugin', $args, $parameter, $tag, $function);
428 $this->tag_nocache =
true;
431 if (!is_array($function)) {
432 return $function($args, $this);
433 }
else if (is_object($function[0])) {
436 return call_user_func_array($function, array($args, $this));
439 if ($this->smarty->loadPlugin(
'smarty_compiler_' . $tag)) {
440 $plugin =
'smarty_compiler_' . $tag;
441 if (is_callable($plugin)) {
442 return $plugin($args, $this->smarty);
444 if (class_exists($plugin,
false)) {
445 $plugin_object =
new $plugin;
446 if (method_exists($plugin_object,
'compile')) {
447 return $plugin_object->compile($args, $this);
471 public function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) {
473 if (isset(self::$_tag_objects[$tag])) {
475 return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
478 $class_name =
'Smarty_Internal_Compile_' . $tag;
479 if ($this->smarty->loadPlugin($class_name)) {
481 if (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this)) {
483 self::$_tag_objects[$tag] =
new $class_name;
485 return self::$_tag_objects[$tag]->compile($args, $this, $param1, $param2, $param3);
501 if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
502 if (isset($this->template->required_plugins[
'nocache'][$plugin_name][$plugin_type])) {
503 $function = $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type][
'function'];
504 }
else if (isset($this->template->required_plugins[
'compiled'][$plugin_name][$plugin_type])) {
505 $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type] = $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type];
506 $function = $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type][
'function'];
509 if (isset($this->template->required_plugins[
'compiled'][$plugin_name][$plugin_type])) {
510 $function = $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type][
'function'];
511 }
else if (isset($this->template->required_plugins[
'nocache'][$plugin_name][$plugin_type])) {
512 $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type] = $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type];
513 $function = $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type][
'function'];
516 if (isset($function)) {
517 if ($plugin_type ==
'modifier') {
518 $this->modifier_plugins[$plugin_name] =
true;
523 $function =
'smarty_' . $plugin_type .
'_' . $plugin_name;
524 $file = $this->smarty->loadPlugin($function,
false);
526 if (is_string($file)) {
527 if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
528 $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type][
'file'] = $file;
529 $this->
template->required_plugins[
'nocache'][$plugin_name][$plugin_type][
'function'] = $function;
531 $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type][
'file'] = $file;
532 $this->
template->required_plugins[
'compiled'][$plugin_name][$plugin_type][
'function'] = $function;
534 if ($plugin_type ==
'modifier') {
535 $this->modifier_plugins[$plugin_name] =
true;
539 if (is_callable($function)) {
557 $result = call_user_func_array(
558 $this->smarty->default_plugin_handler_func, array($tag, $plugin_type, $this->
template, &$callback, &$script, &$cacheable)
561 $this->tag_nocache = $this->tag_nocache || !$cacheable;
562 if ($script !== null) {
563 if (is_file($script)) {
564 if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
565 $this->
template->required_plugins[
'nocache'][$tag][$plugin_type][
'file'] = $script;
566 $this->
template->required_plugins[
'nocache'][$tag][$plugin_type][
'function'] = $callback;
568 $this->
template->required_plugins[
'compiled'][$tag][$plugin_type][
'file'] = $script;
569 $this->
template->required_plugins[
'compiled'][$tag][$plugin_type][
'function'] = $callback;
571 include_once $script;
573 $this->
trigger_template_error(
"Default plugin handler: Returned script file \"{$script}\" for \"{$tag}\" not found");
576 if (!is_string($callback) && !(is_array($callback) && is_string($callback[0]) && is_string($callback[1]))) {
577 $this->
trigger_template_error(
"Default plugin handler: Returned callback for \"{$tag}\" must be a static function name or array of class and function name");
579 if (is_callable($callback)) {
580 $this->default_handler_plugins[$plugin_type][$tag] = array($callback,
true, array());
602 if ($is_code && !empty($content)) {
604 if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching && !$this->suppressNocacheProcessing &&
605 ($this->nocache || $this->tag_nocache || $this->forceNocache == 2)) {
606 $this->
template->has_nocache_code =
true;
607 $_output = addcslashes($content,
'\'\\
');
608 $_output = str_replace("^#^", "'", $_output);
609 $_output = "<?php echo
'/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output . "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n
";
610 // make sure we include modifier plugins for nocache code
611 foreach ($this->modifier_plugins as $plugin_name => $dummy) {
612 if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
613 $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier'];
622 $this->modifier_plugins = array();
623 $this->suppressNocacheProcessing = false;
624 $this->tag_nocache = false;
640 public function trigger_template_error($args = null, $line = null) {
641 // get template source line which has error
643 $line = $this->lex->line;
645 $match = preg_split("/\n/
", $this->lex->data);
646 $error_text = 'Syntax Error in template "' . $this->template->source->filepath . '" on line ' . $line . ' "' . trim(preg_replace('![\t\r\n]+!
', ' ', $match[$line - 1])) . '" ';
648 // individual error message
649 $error_text .= $args;
651 // expected token from parser
652 $error_text .= ' - Unexpected "' . $this->lex->value . '"';
653 if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) {
654 foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
655 $exp_token = $this->parser->yyTokenName[$token];
656 if (isset($this->lex->smarty_token_names[$exp_token])) {
657 // token type from lexer
658 $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
660 // otherwise internal token name
661 $expect[] = $this->parser->yyTokenName[$token];
664 $error_text .= ', expected one of: ' . implode(' , ', $expect);
667 throw new SmartyCompilerException($error_text);
static runFilter($type, $content, Smarty_Internal_Template $template)
Run filters over content.
$suppressNocacheProcessing
$compiles_template_function
getPlugin($plugin_name, $plugin_type)
Check for plugins and return function name.
const PLUGIN_FUNCTION
plugin types
processNocacheCode($content, $is_code)
Inject inline code for nocache template sections.
compileTemplate(Smarty_Internal_Template $template)
Method to compile a Smarty template.
compileTag($tag, $args, $parameter=array())
Compile Tag.
createTemplateCodeFrame($content= '', $cache=false)
Create code frame for compiled and cached templates.
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))
getPluginFromDefaultHandler($tag, $plugin_type)
Check for plugins by default plugin handler.
trigger_template_error($args=null, $line=null)
display compiler error messages without dying
doCompile($_content)
Methode to compile a Smarty template.
callTagCompiler($tag, $args, $param1=null, $param2=null, $param3=null)
lazy loads internal compile plugin for tag and calls the compile methode
$suppressTemplatePropertyHeader
const SMARTY_VERSION
#@+ constant definitions
__construct()
Initialize compiler.