4 * Smarty Internal Plugin Compile extend
6 * Compiles the {extends} tag
14 * Smarty Internal Plugin Compile extend Class
16 class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
17 // attribute definitions
18 public $required_attributes = array('file');
19 public $shorttag_order = array('file');
22 * Compiles code for the {extends} tag
24 * @param array $args array with attributes from parser
25 * @param object $compiler compiler object
26 * @return string compiled code
28 public function compile($args, $compiler)
30 $this->compiler = $compiler;
31 $this->smarty = $compiler->smarty;
32 $this->_rdl = preg_quote($this->smarty->right_delimiter);
33 $this->_ldl = preg_quote($this->smarty->left_delimiter);
34 $filepath = $compiler->template->getTemplateFilepath();
35 // check and get attributes
36 $_attr = $this->_get_attributes($args);
37 if ($_attr['nocache'] === true) {
38 $this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
41 $_smarty_tpl = $compiler->template;
43 if (strpos($_attr['file'],'$_tmp') !== false) {
44 $this->compiler->trigger_template_error('illegal value for file attribute', $this->compiler->lex->taglineno);
46 eval('$include_file = ' . $_attr['file'] . ';');
47 // create template object
48 $_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template);
49 // save file dependency
50 if (in_array($_template->resource_type,array('eval','string'))) {
51 $template_sha1 = sha1($include_file);
53 $template_sha1 = sha1($_template->getTemplateFilepath());
55 if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
56 $this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"",$compiler->lex->line-1);
58 $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp(),$_template->resource_type);
59 $_content = substr($compiler->template->template_source,$compiler->lex->counter-1);
60 if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
61 preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
62 $this->compiler->trigger_template_error('unmatched {block} {/block} pairs');
64 preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
65 $_result_count = count($_result[0]);
67 while ($_start < $_result_count) {
70 while ($_level != 0) {
72 if (!strpos($_result[0][$_start + $_end][0], '/')) {
78 $_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
79 substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
80 Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
81 $_start = $_start + $_end + 1;
83 $compiler->template->template_source = $_template->getTemplateSource();
84 $compiler->template->template_filepath = $_template->getTemplateFilepath();
85 $compiler->abort_and_recompile = true;