diff --git a/library/smarty/libs/sysplugins/smarty_internal_compile_extends.php b/library/smarty/libs/sysplugins/smarty_internal_compile_extends.php new file mode 100644 --- /dev/null +++ b/library/smarty/libs/sysplugins/smarty_internal_compile_extends.php @@ -0,0 +1,83 @@ +getAttributes($compiler, $args); + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); + } + if (strpos($_attr['file'], '$_tmp') !== false) { + $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno); + } + + $name = $_attr['file']; + /** @var Smarty_Internal_Template $_smarty_tpl + * used in evaluated code + */ + $_smarty_tpl = $compiler->template; + eval("\$tpl_name = $name;"); + // create template object + $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template); + // check for recursion + $uid = $_template->source->uid; + if (isset($compiler->extends_uid[$uid])) { + $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1); + } + $compiler->extends_uid[$uid] = true; + if (empty($_template->source->components)) { + array_unshift($compiler->sources, $_template->source); + } else { + foreach ($_template->source->components as $source) { + array_unshift($compiler->sources, $source); + $uid = $source->uid; + if (isset($compiler->extends_uid[$uid])) { + $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1); + } + $compiler->extends_uid[$uid] = true; + } + } + unset ($_template); + $compiler->inheritance_child = true; + $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY); + return ''; + } +}