/** * Register post compile callback to compile inheritance initialization code * * @param \Smarty_Internal_TemplateCompilerBase $compiler * @param bool|false $initChildSequence if true force child template */ public function registerInit(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) { if ($initChildSequence || !isset($compiler->_cache['inheritanceInit'])) { $compiler->registerPostCompileCallback(array('Smarty_Internal_Compile_Shared_Inheritance', 'postCompile'), array($initChildSequence), 'inheritanceInit', $initChildSequence); $compiler->_cache['inheritanceInit'] = true; } }
/** * Compiles code for the {$MVC.capture.xxx} * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $tag = strtolower(trim($parameter[0], '"\'')); $name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false; if (!$name) { $compiler->trigger_template_error("missing or illegal \$MVC.{$tag} name attribute", null, true); } return "(isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null)"; }
/** * Compiles code for the {$smarty.capture.xxx} * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase$compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) { $tag = trim($parameter[0], '"\''); $name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false; if (!$name) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); } return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')"; }
/** * Compiles code for the {$smarty.capture.xxx} * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { // make all lower case $parameter = array_map('strtolower', $parameter); $tag = trim($parameter[0], '"\''); if (!isset($parameter[1]) || false === ($name = $compiler->getId($parameter[1]))) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno); } return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null"; }
/** * Compiles code for the {block_parent} tag * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return bool true */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { if (!isset($compiler->_cache['blockNesting'])) { $compiler->trigger_template_error(' tag {$smarty.block.child} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->has_code = true; $compiler->suppressNocacheProcessing = true; $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]['callsChild'] = 'true'; $output = "<?php \n\$_smarty_tpl->inheritance->callChild(\$_smarty_tpl, \$this);\n?>\n"; return $output; }
/** * Initialize compiler * * @param string $lexer_class class name * @param string $parser_class class name * @param Smarty $smarty global instance */ public function __construct($lexer_class, $parser_class, Smarty $smarty) { parent::__construct($smarty); // get required plugins $this->lexer_class = $lexer_class; $this->parser_class = $parser_class; }
public function __construct($lexer_class, $parser_class, $smarty) { $this->smarty = $smarty; parent::__construct(); $this->lexer_class = $lexer_class; $this->parser_class = $parser_class; }
public function compileTemplate(Smarty_Internal_Template $template) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } $this->nocache = false; $this->tag_nocache = false; $this->template = $template; $this->template->has_nocache_code = false; $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } do { $this->abort_and_recompile = false; $_content = $template->source->content; if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } if ($_content == '') { if ($this->suppressTemplatePropertyHeader) { $code = ''; } else { $code = $template_header . $template->createTemplateCodeFrame(); } return $code; } $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); $this->template->source->filepath = $saved_filepath; unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); } } if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } unset($template->source->content); return $code; }
public function yy_syntax_error($yymajor, $TOKEN) { #line 200 "../smarty/lexer/smarty_internal_templateparser.y" $this->internalError = true; $this->yymajor = $yymajor; $this->compiler->trigger_template_error(); }
/** * Method to compile a Smarty template * * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * * @param Smarty_Internal_TemplateCompilerBase $parent_compiler * * @return bool true if compiling succeeded, false if it failed * @throws \SmartyException */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : false; // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */\n"; } if ($isExtendsResource = !empty($this->template->source->components)) { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } // the $this->sources array can get additional elements while compiling by the {extends} tag if (!$isExtendsResource) { $this->inheritance_child = $this->template->source->isChild; $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } if (!($this->template->source->recompiled || $this->template->source->type == 'string' || $this->template->source->type == 'extends')) { $this->parent_compiler->resourceInfo[$this->template->source->uid] = $this->template->source->getResourceInfo($this->template); } } do { // flag for aborting current and start recompile $this->abort_and_recompile = false; if ($isExtendsResource) { $_content = ''; } else { // get template source $_content = $this->template->source->content; } if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } } // call compiler $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex); self::$_tag_objects = array(); // return compiled code to template object // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } // unset content because template inheritance could have replace source with parent code unset($template->source->content); $this->parent_compiler = null; $this->template = null; if ($this->suppressTemplatePropertyHeader) { return $_compiled_code; } else { $properties = array('resourceInfo' => $this->resourceInfo, 'isInheritanceChild' => $this->inheritance_child); if (isset($this->templateProperties['tpl_function'])) { $properties['templateFunctions'] = $this->templateProperties['tpl_function']; } if (isset($this->templateProperties['block_function'])) { $properties['blockFunctions'] = $this->templateProperties['block_function']; } foreach ($this->plugins as $tmp) { foreach ($tmp as $plugin) { $properties['plugins'][$plugin['file']] = $plugin['function']; } } foreach ($this->nocachePlugins as $tmp) { foreach ($tmp as $plugin) { $properties['nocachePlugins'][$plugin['file']] = $plugin['function']; } } return Smarty_Internal_Extension_CodeFrame::create($template, $properties, $_compiled_code, $template_header); } }
/** * Compile template source and run optional post filter * * @param \Smarty_Internal_Template $template * @param null|bool $nocache flag if template must be compiled in nocache mode * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler * * @return string * @throws \Exception */ public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { try { // save template object in compiler class $this->template = $template; if (property_exists($this->template->smarty, 'plugin_search_order')) { $this->plugin_search_order = $this->template->smarty->plugin_search_order; } if ($this->smarty->debugging) { $this->smarty->_debug->start_compile($this->template); } if (isset($this->template->smarty->security_policy)) { $this->php_handling = $this->template->smarty->security_policy->php_handling; } else { $this->php_handling = $this->template->smarty->php_handling; } $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : false; if (empty($template->compiled->nocache_hash)) { $template->compiled->nocache_hash = $this->nocache_hash; } else { $this->nocache_hash = $template->compiled->nocache_hash; } // flag for nocache sections $this->nocache = $nocache; $this->tag_nocache = false; // reset has nocache code flag $this->template->compiled->has_nocache_code = false; $this->has_variable_string = false; $this->prefix_code = array(); // add file dependency $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->getTimeStamp(), $this->template->source->type); $this->smarty->_current_file = $this->template->source->filepath; // get template source if (!empty($this->template->source->components)) { // we have array of inheritance templates by extends: resource // generate corresponding source code sequence $_content = Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); } else { // get template source $_content = $this->template->source->getContent(); } $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); } catch (Exception $e) { if ($this->smarty->debugging) { $this->smarty->_debug->end_compile($this->template); } $this->_tag_stack = array(); self::$_tag_objects = array(); // free memory $this->parent_compiler = null; $this->template = null; $this->parser = null; throw $e; } if ($this->smarty->debugging) { $this->smarty->_debug->end_compile($this->template); } $this->parent_compiler = null; $this->parser = null; return $_compiled_code; }
function yy_r3_3($yy_subpatterns) { $to = strlen($this->data); preg_match("/{$this->ldel}\\/?literal{$this->rdel}/", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[0][1])) { $to = $match[0][1]; } else { $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); } $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_LITERAL; }
/** * Compiles code for the {$smarty.foreach} tag * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { if (!isset($parameter[1]) || false === ($name = $compiler->getId($parameter[1]))) { $compiler->trigger_template_error("missing or illegal \$Smarty.foreach name attribute", $compiler->lex->taglineno); } if (!isset($parameter[2]) || false === ($property = $compiler->getId($parameter[2])) || !in_array(strtolower($property), array('first', 'last', 'index', 'iteration', 'show', 'total'))) { $compiler->trigger_template_error("missing or illegal \$Smarty.foreach property attribute", $compiler->lex->taglineno); } $property = strtolower($property); $foreachVar = "'__foreach_{$name}'"; return "(isset(\$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$foreachVar}]->value['{$property}'] : null)"; }
/** * Method to compile a Smarty template * * @param Smarty_Internal_Template $template template object to compile * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = false; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // reset has noche code flag $this->template->has_nocache_code = false; $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } do { // flag for aborting current and start recompile $this->abort_and_recompile = false; // get template source $_content = $template->source->content; // run prefilter if required if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // on empty template just return header if ($_content == '') { if ($this->suppressTemplatePropertyHeader) { $code = ''; } else { $code = $template_header . $template->createTemplateCodeFrame(); } return $code; } // call compiler $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); $this->template->source->filepath = $saved_filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); // return compiled code to template object $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } // run postfilter if required on merged code if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); } } // run postfilter if required on compiled template code if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } return $code; }
/** * Compiles the template * * If the template is not evaluated the compiled template is saved on disk */ public function compileTemplateSource() { if (!$this->resource_object->isEvaluated) { $this->properties['file_dependency'] = array(); $this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp(), $this->resource_type); } if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this); } // compile template if (!is_object($this->compiler_object)) { // load compiler $this->smarty->loadPlugin($this->resource_object->compiler_class); $this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty); } // compile locking if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated) { if ($saved_timestamp = $this->getCompiledTimestamp()) { touch($this->getCompiledFilepath()); } } // call compiler try { $this->compiler_object->compileTemplate($this); } catch (Exception $e) { // restore old timestamp in case of error if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated && $saved_timestamp) { touch($this->getCompiledFilepath(), $saved_timestamp); } throw $e; } // compiling succeded if (!$this->resource_object->isEvaluated && $this->write_compiled_code) { // write compiled template Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty); } if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this); } // release objects to free memory Smarty_Internal_TemplateCompilerBase::$_tag_objects = array(); unset($this->compiler_object->parser->root_buffer, $this->compiler_object->parser->current_buffer, $this->compiler_object->parser, $this->compiler_object->lex, $this->compiler_object->template, $this->compiler_object); }
/** * Compiles code for the special $smarty variables * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param $parameter * * @return string compiled code * @throws \SmartyCompilerException */ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $_index = preg_split("/\\]\\[/", substr($parameter, 1, strlen($parameter) - 2)); $variable = strtolower($compiler->getId($_index[0])); if ($variable === false) { $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true); } if (!isset($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)) { switch ($variable) { case 'foreach': case 'section': return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index); case 'capture': if (class_exists('Smarty_Internal_Compile_Capture')) { return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); } return ''; case 'now': return 'time()'; case 'cookies': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; } return '$_COOKIE'; case 'get': case 'post': case 'env': case 'server': case 'session': case 'request': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) { $compiler->trigger_template_error("(secure mode) super globals not permitted"); break; } $compiled_ref = '$_' . strtoupper($variable); break; case 'template': return 'basename($_smarty_tpl->source->filepath)'; case 'template_object': return '$_smarty_tpl'; case 'current_dir': return 'dirname($_smarty_tpl->source->filepath)'; case 'version': $_version = Smarty::SMARTY_VERSION; return "'{$_version}'"; case 'const': if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) { $compiler->trigger_template_error("(secure mode) constants not permitted"); break; } if (strpos($_index[1], '$') === false && strpos($_index[1], '\'') === false) { return "@constant('{$_index[1]}')"; } else { return "@constant({$_index[1]})"; } case 'config': if (isset($_index[2])) { return "(is_array(\$tmp = \$_smarty_tpl->_getConfigVariable({$_index['1']})) ? \$tmp[{$_index['2']}] : null)"; } else { return "\$_smarty_tpl->_getConfigVariable({$_index['1']})"; } case 'ldelim': $_ldelim = $compiler->smarty->left_delimiter; return "'{$_ldelim}'"; case 'rdelim': $_rdelim = $compiler->smarty->right_delimiter; return "'{$_rdelim}'"; default: $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid'); break; } if (isset($_index[1])) { array_shift($_index); foreach ($_index as $_ind) { $compiled_ref = $compiled_ref . "[{$_ind}]"; } } return $compiled_ref; } }
/** * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $tag = strtolower(trim($parameter[0], '"\'')); $name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false; if (!$name) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); } $property = isset($parameter[2]) ? strtolower($compiler->getId($parameter[2])) : false; if (!$property || !in_array($property, $this->nameProperties)) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); } $tagVar = "'__smarty_{$tag}_{$name}'"; return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block * @throws \SmartyCompilerException */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { // if called by {$smarty.block.parent} we must search the name of enclosing {block} if ($_name == null) { $stack_count = count($compiler->_tag_stack); while (--$stack_count >= 0) { if ($compiler->_tag_stack[$stack_count][0] == 'block') { $_name = trim($compiler->_tag_stack[$stack_count][1][0]['name'], "\"'"); break; } } } if ($_name == null) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->lex->taglineno); } if (empty(Smarty_Internal_Compile_Block::$nested_block_names)) { $compiler->trigger_template_error(' illegal {$smarty.block.parent} in parent template ', $compiler->lex->taglineno); } Smarty_Internal_Compile_Block::$block_data[Smarty_Internal_Compile_Block::$nested_block_names[0]]['source'] .= Smarty_Internal_Compile_Block::parent; $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->has_code = false; return; }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { if (!$compiler->inheritanceChild) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used in parent template ', $compiler->parser->lex->taglineno); } if (!$compiler->blockTagNestingLevel) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->suppressNocacheProcessing = true; $compiler->has_code = true; $_output = "<?php \n\$_smarty_tpl->_Block->callParentBlock(\$_smarty_tpl, \$block);?>"; return $_output; }
/** * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag * * @param array $args array with attributes from parser * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code * @throws \SmartyCompilerException */ public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { // make all lower case $parameter = array_map('strtolower', $parameter); $tag = trim($parameter[0], '"\''); if (!isset($parameter[1]) || false === ($name = $compiler->getId($parameter[1]))) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true); } $className = 'Smarty_Internal_Compile_' . ucfirst($tag); if (!isset($parameter[2]) || false === ($property = $compiler->getId($parameter[2])) || !in_array($property, $className::$nameProperties)) { $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true); } $tagVar = "'__smarty_{$tag}_{$name}'"; return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)"; }
/** * Method to compile a Smarty template * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = NULL, $parent_compiler = NULL) { // save template object in compiler class $this->template = $template; if (isset($this->template->smarty->security_policy)) { $this->php_handling = $this->template->smarty->security_policy->php_handling; } else { $this->php_handling = $this->template->smarty->php_handling; } $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : FALSE; if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = FALSE; // reset has nocache code flag $this->template->has_nocache_code = FALSE; $save_source = $this->template->source; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } if (empty($this->template->source->components)) { $this->sources = [$template->source]; } else { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } $loop = 0; // the $this->sources array can get additional elements while compiling by the {extends} tag while ($this->template->source = array_shift($this->sources)) { $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } $no_sources = count($this->sources); $this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = [$this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type]; $loop++; if ($no_sources) { $this->inheritance_child = TRUE; } else { $this->inheritance_child = FALSE; } do { // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = FALSE; // reset has nocache code flag $this->template->has_nocache_code = FALSE; $this->has_variable_string = FALSE; $this->prefix_code = []; $_compiled_code = ''; // flag for aborting current and start recompile $this->abort_and_recompile = FALSE; // get template source $_content = $this->template->source->content; if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // call compiler $_compiled_code = $this->doCompile($_content, TRUE); } } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } } // restore source $this->template->source = $save_source; unset($save_source); $this->smarty->_current_file = $this->template->source->filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex); self::$_tag_objects = []; // return compiled code to template object $merged_code = ''; if (!empty($this->mergedSubTemplatesCode)) { foreach ($this->mergedSubTemplatesCode as $code) { $merged_code .= $code; } } // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $_compiled_code .= $merged_code; } else { $_compiled_code = $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code; } if (!empty($this->templateFunctionCode)) { // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter) { $_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template); } else { $_compiled_code .= $this->templateFunctionCode; } } // unset content because template inheritance could have replace source with parent code unset($template->source->content); $this->parent_compiler = NULL; $this->template = NULL; return $_compiled_code; }
function yy_r8_3() { $to = strlen($this->data); preg_match("~{$this->ldel}[/]?literal\\s*{$this->rdel}~i", $this->data, $match, PREG_OFFSET_CAPTURE, $this->counter); if (isset($match[0][1])) { $to = $match[0][1]; } else { $this->compiler->trigger_template_error("missing or misspelled literal closing tag"); } $this->value = substr($this->data, $this->counter, $to - $this->counter); $this->token = Smarty_Internal_Templateparser::TP_BLOCKSOURCE; }
/** * Add code for including subtemplate to end of template * * @param \Smarty_Internal_TemplateCompilerBase $compiler * @param string $file subtemplate name */ private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $file) { $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, $compiler->compileTag('include', array($file, array('scope' => 'parent')))); }
/** * Compile $smarty.block.parent * * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param string $_name optional name of child block * * @return string compiled code of child block */ static function compileParentBlock(Smarty_Internal_TemplateCompilerBase $compiler, $_name = null) { if (!isset($compiler->_cache['blockNesting'])) { $compiler->trigger_template_error(' tag {$smarty.block.parent} used outside {block} tags ', $compiler->parser->lex->taglineno); } $compiler->suppressNocacheProcessing = true; $compiler->has_code = true; $output = "<?php \n\$_smarty_tpl->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; return $output; }
/** * Method to compile a Smarty template. * * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = false) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // reset has nocache code flag $this->template->has_nocache_code = false; $save_source = $this->template->source; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= '<?php /* Smarty version ' . Smarty::SMARTY_VERSION . ', created on ' . strftime('%Y-%m-%d %H:%M:%S') . "\n"; $template_header .= ' compiled from "' . $this->template->source->filepath . "\" */ ?>\n"; } if (empty($this->template->source->components)) { $this->sources = array($template->source); } else { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } $loop = 0; // the $this->sources array can get additional elements while compiling by the {extends} tag while ($this->template->source = array_shift($this->sources)) { $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } $no_sources = count($this->sources); if ($loop || $no_sources) { $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); } ++$loop; if ($no_sources) { $this->inheritance_child = true; } else { $this->inheritance_child = false; } do { $_compiled_code = ''; // flag for aborting current and start recompile $this->abort_and_recompile = false; // get template source $_content = $this->template->source->content; if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // call compiler $_compiled_code = $this->doCompile($_content); } } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } } // restore source $this->template->source = $save_source; unset($save_source); $this->smarty->_current_file = $this->template->source->filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); // return compiled code to template object $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } } // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } // unset content because template inheritance could have replace source with parent code unset($template->source->content); return $code; }