/** * Compile saved child block source * * @param object $compiler compiler object * @param string $_name optional name of child block * @return string compiled code of child block */ static function compileChildBlock($compiler, $_name = null) { if ($compiler->inheritance_child) { $name1 = Smarty_Internal_Compile_Block::$nested_block_names[0]; if (isset($compiler->template->block_data[$name1])) { // replace inner block name with generic Smarty_Internal_Compile_Block::$block_data[$name1]['source'] .= $compiler->template->block_data[$name1]['source']; Smarty_Internal_Compile_Block::$block_data[$name1]['child'] = true; } $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK); $compiler->has_code = false; return; } // if called by {$smarty.block.child} 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.child} used outside {block} tags ', $compiler->lex->taglineno); } // undefined child? if (!isset($compiler->template->block_data[$_name]['source'])) { $compiler->popTrace(); return ''; } // flag that child is already compile by {$smarty.block.child} inclusion $compiler->template->block_data[$_name]['compiled'] = true; $_tpl = new Smarty_Internal_template('string:' . $compiler->template->block_data[$_name]['source'], $compiler->smarty, $compiler->template, $compiler->template->cache_id, $compiler->template->compile_id, $compiler->template->caching, $compiler->template->cache_lifetime); if ($compiler->smarty->debugging) { Smarty_Internal_Debug::ignore($_tpl); } $_tpl->tpl_vars = $compiler->template->tpl_vars; $_tpl->variable_filters = $compiler->template->variable_filters; $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; $_tpl->allow_relative_path = true; $_tpl->compiler->inheritance = true; $_tpl->compiler->suppressHeader = true; $_tpl->compiler->suppressFilter = true; $_tpl->compiler->suppressTemplatePropertyHeader = true; $_tpl->compiler->suppressMergedTemplates = true; $nocache = $compiler->nocache || $compiler->tag_nocache; if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) { $_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php(), $_tpl->compiler->compileTemplate($_tpl, $nocache)); } elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') { $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache) . $compiler->parser->current_buffer->to_smarty_php(); } elseif ($compiler->template->block_data[$_name]['mode'] == 'append') { $_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->compiler->compileTemplate($_tpl, $nocache); } elseif (!empty($compiler->template->block_data[$_name])) { $_output = $_tpl->compiler->compileTemplate($_tpl, $nocache); } $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']); $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']); $compiler->merged_templates = array_merge($compiler->merged_templates, $_tpl->compiler->merged_templates); $compiler->template->variable_filters = $_tpl->variable_filters; if ($_tpl->has_nocache_code) { $compiler->template->has_nocache_code = true; } foreach ($_tpl->required_plugins as $key => $tmp1) { if ($compiler->nocache && $compiler->template->caching) { $code = 'nocache'; } else { $code = $key; } foreach ($tmp1 as $name => $tmp) { foreach ($tmp as $type => $data) { $compiler->template->required_plugins[$code][$name][$type] = $data; } } } unset($_tpl); $compiler->has_code = true; return $_output; }