2009-11-06 14:35:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-03-01 16:46:30 +00:00
|
|
|
* Smarty Internal Plugin Compile Block
|
|
|
|
*
|
|
|
|
* Compiles the {block}{/block} tags
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2010-03-01 16:46:30 +00:00
|
|
|
* Smarty Internal Plugin Compile Block Class
|
|
|
|
*/
|
2009-11-06 14:35:00 +00:00
|
|
|
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
|
|
|
/**
|
2010-03-01 16:46:30 +00:00
|
|
|
* Compiles code for the {block} tag
|
|
|
|
*
|
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
2009-11-06 14:35:00 +00:00
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->compiler = $compiler;
|
|
|
|
$this->required_attributes = array('name');
|
2010-03-01 16:46:30 +00:00
|
|
|
$this->optional_attributes = array('assign', 'nocache');
|
2009-11-06 14:35:00 +00:00
|
|
|
// check and get attributes
|
|
|
|
$_attr = $this->_get_attributes($args);
|
2010-09-10 11:15:15 +00:00
|
|
|
$save = array($_attr, $compiler->parser->current_buffer, $this->compiler->nocache, $this->compiler->smarty->merge_compiled_includes);
|
2009-11-06 14:35:00 +00:00
|
|
|
$this->_open_tag('block', $save);
|
2010-01-11 20:44:01 +00:00
|
|
|
if (isset($_attr['nocache'])) {
|
|
|
|
if ($_attr['nocache'] == 'true') {
|
|
|
|
$compiler->nocache = true;
|
|
|
|
}
|
2010-09-10 11:15:15 +00:00
|
|
|
}
|
2010-09-17 18:10:10 +00:00
|
|
|
// set flag for {block} tag
|
|
|
|
$compiler->smarty->inheritance = true;
|
2010-09-10 11:15:15 +00:00
|
|
|
// must merge includes
|
|
|
|
$this->compiler->smarty->merge_compiled_includes = true;
|
2010-01-11 20:44:01 +00:00
|
|
|
|
2010-07-14 22:47:37 +00:00
|
|
|
$compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser);
|
2010-01-09 19:23:35 +00:00
|
|
|
$compiler->has_code = false;
|
2009-11-06 14:35:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-01 16:46:30 +00:00
|
|
|
* Smarty Internal Plugin Compile BlockClose Class
|
|
|
|
*/
|
2009-11-06 14:35:00 +00:00
|
|
|
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
|
|
|
/**
|
2010-03-01 16:46:30 +00:00
|
|
|
* Compiles code for the {/block} tag
|
|
|
|
*
|
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2009-11-06 14:35:00 +00:00
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->compiler = $compiler;
|
|
|
|
$this->smarty = $compiler->smarty;
|
|
|
|
$this->compiler->has_code = true;
|
|
|
|
// check and get attributes
|
|
|
|
$this->optional_attributes = array('name');
|
|
|
|
$_attr = $this->_get_attributes($args);
|
|
|
|
$saved_data = $this->_close_tag(array('block'));
|
|
|
|
// if name does match to opening tag
|
|
|
|
if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) {
|
|
|
|
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
|
|
|
|
}
|
|
|
|
$_name = trim($saved_data[0]['name'], "\"'");
|
2010-09-08 17:40:00 +00:00
|
|
|
if (isset($compiler->template->block_data[$_name])) {
|
2010-10-13 15:44:03 +00:00
|
|
|
// $_tpl = $this->smarty->createTemplate('eval:' . $compiler->template->block_data[$_name]['source'], null, null, $compiler->template);
|
|
|
|
$_tpl = new Smarty_Internal_template ('eval:' . $compiler->template->block_data[$_name]['source'], $this->smarty, $compiler->template, $compiler->template->cache_id,
|
|
|
|
$compiler->template->compile_id = null, $compiler->template->caching, $compiler->template->cache_lifetime);
|
2010-01-07 19:33:18 +00:00
|
|
|
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
2010-09-08 17:40:00 +00:00
|
|
|
$_tpl->template_filepath = $compiler->template->block_data[$_name]['file'];
|
2010-01-09 19:23:35 +00:00
|
|
|
if ($compiler->nocache) {
|
|
|
|
$_tpl->forceNocache = 2;
|
|
|
|
} else {
|
|
|
|
$_tpl->forceNocache = 1;
|
|
|
|
}
|
2009-12-10 17:23:32 +00:00
|
|
|
$_tpl->suppressHeader = true;
|
|
|
|
$_tpl->suppressFileDependency = true;
|
2010-09-08 17:40:00 +00:00
|
|
|
if (strpos($compiler->template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
2010-07-14 22:47:37 +00:00
|
|
|
$_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->parser->current_buffer->to_smarty_php(), $_tpl->getCompiledTemplate());
|
2010-09-08 17:40:00 +00:00
|
|
|
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
2010-07-14 22:47:37 +00:00
|
|
|
$_output = $_tpl->getCompiledTemplate() . $compiler->parser->current_buffer->to_smarty_php();
|
2010-09-08 17:40:00 +00:00
|
|
|
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
2010-07-14 22:47:37 +00:00
|
|
|
$_output = $compiler->parser->current_buffer->to_smarty_php() . $_tpl->getCompiledTemplate();
|
2010-09-08 17:40:00 +00:00
|
|
|
} elseif (!empty($compiler->template->block_data[$_name])) {
|
2009-12-03 19:49:17 +00:00
|
|
|
$_output = $_tpl->getCompiledTemplate();
|
2010-01-07 19:33:18 +00:00
|
|
|
}
|
2009-12-28 15:27:13 +00:00
|
|
|
$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']);
|
2010-03-01 16:46:30 +00:00
|
|
|
if ($_tpl->has_nocache_code) {
|
|
|
|
$compiler->template->has_nocache_code = true;
|
|
|
|
}
|
2010-02-05 17:03:22 +00:00
|
|
|
foreach($_tpl->required_plugins as $code => $tmp1) {
|
|
|
|
foreach($tmp1 as $name => $tmp) {
|
|
|
|
foreach($tmp as $type => $data) {
|
|
|
|
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-10 17:23:32 +00:00
|
|
|
unset($_tpl);
|
2009-11-06 14:35:00 +00:00
|
|
|
} else {
|
2010-07-14 22:47:37 +00:00
|
|
|
$_output = $compiler->parser->current_buffer->to_smarty_php();
|
2009-11-06 14:35:00 +00:00
|
|
|
}
|
2010-07-14 22:47:37 +00:00
|
|
|
$compiler->parser->current_buffer = $saved_data[1];
|
2010-09-10 11:15:15 +00:00
|
|
|
$compiler->nocache = $saved_data[2];
|
2010-09-24 12:13:19 +00:00
|
|
|
$compiler->smarty->merge_compiled_includes = $saved_data[3];
|
2010-01-09 19:23:35 +00:00
|
|
|
// $_output content has already nocache code processed
|
|
|
|
$compiler->suppressNocacheProcessing = true;
|
2010-09-17 18:10:10 +00:00
|
|
|
// reset flag
|
|
|
|
$compiler->smarty->inheritance = false;
|
2009-11-06 14:35:00 +00:00
|
|
|
return $_output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 16:46:30 +00:00
|
|
|
?>
|