2009-03-22 16:09:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile extend
|
|
|
|
*
|
|
|
|
* Compiles the {extend} tag
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Smarty Internal Plugin Compile extend Class
|
|
|
|
*/
|
|
|
|
class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase {
|
|
|
|
/**
|
|
|
|
* Compiles code for the {extend} tag
|
|
|
|
*
|
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
* @return string compiled code
|
|
|
|
*/
|
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->compiler = $compiler;
|
|
|
|
$this->required_attributes = array('file');
|
|
|
|
// check and get attributes
|
|
|
|
$_attr = $this->_get_attributes($args);
|
2009-04-12 05:40:30 +00:00
|
|
|
$_smarty_tpl = $compiler->template;
|
2009-04-12 02:30:54 +00:00
|
|
|
// $include_file = '';
|
|
|
|
eval('$include_file = ' . $_attr['file'] . ';');
|
2009-03-22 16:09:05 +00:00
|
|
|
// create template object
|
|
|
|
$_template = new Smarty_Template ($include_file, $compiler->template);
|
|
|
|
// save file dependency
|
2009-04-24 19:59:51 +00:00
|
|
|
$compiler->template->properties['file_dependency'][] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
|
2009-03-22 16:09:05 +00:00
|
|
|
// $_old_source = preg_replace ('/' . $this->smarty->left_delimiter . 'extend\s+(?:file=)?\s*(\S+?|(["\']).+?\2)' . $this->smarty->right_delimiter . '/i', '' , $compiler->template->template_source, 1);
|
|
|
|
$_old_source = $compiler->template->template_source;
|
2009-06-14 11:07:26 +00:00
|
|
|
$_old_source = preg_replace_callback('/(' . $this->compiler->smarty->left_delimiter . 'block(.+?)' . $this->compiler->smarty->right_delimiter . ')((?:\r?\n?)(.*?)(?:\r?\n?))(' . $this->compiler->smarty->left_delimiter . '\/block(.*?)' . $this->compiler->smarty->right_delimiter . ')/is', array($this, 'saveBlockData'), $_old_source);
|
2009-03-22 16:09:05 +00:00
|
|
|
$compiler->template->template_source = $_template->getTemplateSource();
|
|
|
|
$compiler->abort_and_recompile = true;
|
|
|
|
return ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function saveBlockData(array $matches)
|
|
|
|
{
|
2009-04-12 02:30:54 +00:00
|
|
|
if (0 == preg_match('/(.?)(name=)([^ ]*)/', $matches[2], $_match)) {
|
2009-03-22 16:09:05 +00:00
|
|
|
$this->compiler->trigger_template_error("\"" . $matches[0] . "\" missing name attribute");
|
|
|
|
} else {
|
2009-04-12 02:30:54 +00:00
|
|
|
// compile block content
|
2009-06-14 11:07:26 +00:00
|
|
|
$_tpl = $this->compiler->smarty->createTemplate('string:' . $matches[3]);
|
2009-04-29 17:56:56 +00:00
|
|
|
$_tpl->suppressHeader = true;
|
|
|
|
$_compiled_content = $_tpl->getCompiledTemplate();
|
|
|
|
unset($_tpl);
|
2009-03-22 16:09:05 +00:00
|
|
|
$_name = trim($_match[3], "\"'");
|
2009-04-12 02:30:54 +00:00
|
|
|
|
2009-04-12 22:26:02 +00:00
|
|
|
if (isset($this->compiler->template->block_data[$_name])) {
|
|
|
|
if ($this->compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
2009-04-29 17:56:56 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['compiled'] .= $_compiled_content;
|
2009-04-12 22:26:02 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['source'] .= $matches[3];
|
|
|
|
} elseif ($this->compiler->template->block_data[$_name]['mode'] == 'append') {
|
2009-04-29 17:56:56 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['compiled'] = $_compiled_content . $this->compiler->template->block_data[$_name]['compiled'];
|
2009-04-12 22:26:02 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['source'] = $matches[3] . $this->compiler->template->block_data[$_name]['source'];
|
|
|
|
}
|
|
|
|
} else {
|
2009-04-29 17:56:56 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['compiled'] = $_compiled_content;
|
2009-03-22 16:09:05 +00:00
|
|
|
$this->compiler->template->block_data[$_name]['source'] = $matches[3];
|
|
|
|
}
|
2009-04-14 09:04:15 +00:00
|
|
|
// if (isset($this->compiler->template->block_data[$_name]['mode'])) {
|
|
|
|
// if ($this->compiler->template->block_data[$_name]['mode'] != 'replace') {
|
|
|
|
if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) {
|
|
|
|
$this->compiler->template->block_data[$_name]['mode'] = 'append';
|
|
|
|
} elseif (preg_match('/(.?)(prepend=true)(.*)/', $matches[2], $_match) != 0) {
|
|
|
|
$this->compiler->template->block_data[$_name]['mode'] = 'prepend';
|
|
|
|
// }
|
|
|
|
// }
|
2009-04-12 22:26:02 +00:00
|
|
|
} else {
|
|
|
|
$this->compiler->template->block_data[$_name]['mode'] = 'replace';
|
|
|
|
}
|
2009-03-22 16:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|