You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
7.7 KiB
PHTML
177 lines
7.7 KiB
PHTML
14 years ago
|
<?php
|
||
9 years ago
|
/*
|
||
|
* This file is part of Smarty.
|
||
13 years ago
|
*
|
||
9 years ago
|
* (c) 2015 Uwe Tews
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
14 years ago
|
*/
|
||
|
|
||
|
/**
|
||
|
* Smarty Internal Plugin Compile Block Class
|
||
13 years ago
|
*
|
||
9 years ago
|
* @author Uwe Tews <uwe.tews@googlemail.com>
|
||
14 years ago
|
*/
|
||
9 years ago
|
class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance
|
||
11 years ago
|
{
|
||
13 years ago
|
/**
|
||
|
* Attribute definition: Overwrites base class.
|
||
|
*
|
||
|
* @var array
|
||
|
* @see Smarty_Internal_CompileBase
|
||
|
*/
|
||
14 years ago
|
public $required_attributes = array('name');
|
||
11 years ago
|
/**
|
||
|
* Attribute definition: Overwrites base class.
|
||
|
*
|
||
|
* @var array
|
||
|
* @see Smarty_Internal_CompileBase
|
||
|
*/
|
||
|
public $shorttag_order = array('name');
|
||
13 years ago
|
/**
|
||
|
* Attribute definition: Overwrites base class.
|
||
|
*
|
||
|
* @var array
|
||
|
* @see Smarty_Internal_CompileBase
|
||
|
*/
|
||
9 years ago
|
public $option_flags = array('hide', 'nocache');
|
||
13 years ago
|
/**
|
||
|
* Attribute definition: Overwrites base class.
|
||
|
*
|
||
|
* @var array
|
||
|
* @see Smarty_Internal_CompileBase
|
||
|
*/
|
||
9 years ago
|
public $optional_attributes = array('assign');
|
||
|
|
||
14 years ago
|
/**
|
||
|
* Compiles code for the {block} tag
|
||
13 years ago
|
*
|
||
9 years ago
|
* @param array $args array with attributes from parser
|
||
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||
|
* @param array $parameter array with compilation parameter
|
||
10 years ago
|
*
|
||
14 years ago
|
*/
|
||
9 years ago
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||
14 years ago
|
{
|
||
7 years ago
|
if (!isset($compiler->_cache[ 'blockNesting' ])) {
|
||
|
$compiler->_cache[ 'blockNesting' ] = 0;
|
||
10 years ago
|
}
|
||
7 years ago
|
if ($compiler->_cache[ 'blockNesting' ] === 0) {
|
||
9 years ago
|
// make sure that inheritance gets initialized in template code
|
||
|
$this->registerInit($compiler);
|
||
|
$this->option_flags = array('hide', 'nocache', 'append', 'prepend');
|
||
|
} else {
|
||
|
$this->option_flags = array('hide', 'nocache');
|
||
11 years ago
|
}
|
||
9 years ago
|
// check and get attributes
|
||
|
$_attr = $this->getAttributes($compiler, $args);
|
||
7 years ago
|
++$compiler->_cache[ 'blockNesting' ];
|
||
7 years ago
|
$_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(rand(), true));
|
||
|
$compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ];
|
||
|
$compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className;
|
||
|
$compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array();
|
||
|
$compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className;
|
||
7 years ago
|
$this->openTag($compiler,
|
||
|
'block',
|
||
|
array($_attr, $compiler->nocache, $compiler->parser->current_buffer,
|
||
|
$compiler->template->compiled->has_nocache_code,
|
||
|
$compiler->template->caching));
|
||
|
$compiler->saveRequiredPlugins(true);
|
||
11 years ago
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||
9 years ago
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||
|
$compiler->template->compiled->has_nocache_code = false;
|
||
|
$compiler->suppressNocacheProcessing = true;
|
||
13 years ago
|
}
|
||
14 years ago
|
}
|
||
|
/**
|
||
|
* Smarty Internal Plugin Compile BlockClose Class
|
||
13 years ago
|
*
|
||
11 years ago
|
*/
|
||
9 years ago
|
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_Inheritance
|
||
11 years ago
|
{
|
||
14 years ago
|
/**
|
||
|
* Compiles code for the {/block} tag
|
||
13 years ago
|
*
|
||
9 years ago
|
* @param array $args array with attributes from parser
|
||
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||
|
* @param array $parameter array with compilation parameter
|
||
10 years ago
|
*
|
||
9 years ago
|
* @return bool true
|
||
14 years ago
|
*/
|
||
9 years ago
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||
14 years ago
|
{
|
||
9 years ago
|
list($_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching) = $this->closeTag($compiler, array('block'));
|
||
|
// init block parameter
|
||
7 years ago
|
$_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ];
|
||
|
unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]);
|
||
|
$_name = $_attr[ 'name' ];
|
||
|
$_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
|
||
|
unset($_attr[ 'assign' ], $_attr[ 'name' ]);
|
||
9 years ago
|
foreach ($_attr as $name => $stat) {
|
||
7 years ago
|
if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) {
|
||
7 years ago
|
$_block[ $name ] = 'true';
|
||
11 years ago
|
}
|
||
|
}
|
||
7 years ago
|
$_className = $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ];
|
||
9 years ago
|
// get compiled block code
|
||
|
$_functionCode = $compiler->parser->current_buffer;
|
||
|
// setup buffer for template function code
|
||
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||
|
|
||
7 years ago
|
$output = "<?php\n";
|
||
|
$output .= "/* {block {$_name}} */\n";
|
||
|
$output .= "class {$_className} extends Smarty_Internal_Block\n";
|
||
|
$output .= "{\n";
|
||
|
foreach ($_block as $property => $value) {
|
||
|
$output .= "public \${$property} = " . var_export($value,true) .";\n";
|
||
|
}
|
||
|
$output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n";
|
||
7 years ago
|
$output .= $compiler->compileRequiredPlugins();
|
||
|
$compiler->restoreRequiredPlugins();
|
||
9 years ago
|
if ($compiler->template->compiled->has_nocache_code) {
|
||
|
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n";
|
||
14 years ago
|
}
|
||
9 years ago
|
if (isset($_assign)) {
|
||
|
$output .= "ob_start();\n";
|
||
11 years ago
|
}
|
||
9 years ago
|
$output .= "?>\n";
|
||
|
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||
|
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||
|
$output));
|
||
|
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||
|
$output = "<?php\n";
|
||
|
if (isset($_assign)) {
|
||
7 years ago
|
$output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
|
||
10 years ago
|
}
|
||
9 years ago
|
$output .= "}\n";
|
||
7 years ago
|
$output .= "}\n";
|
||
|
$output .= "/* {/block {$_name}} */\n\n";
|
||
9 years ago
|
$output .= "?>\n";
|
||
|
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||
|
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||
|
$output));
|
||
7 years ago
|
$compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||
7 years ago
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||
9 years ago
|
// restore old status
|
||
|
$compiler->template->compiled->has_nocache_code = $_has_nocache_code;
|
||
|
$compiler->tag_nocache = $compiler->nocache;
|
||
|
$compiler->nocache = $_nocache;
|
||
|
$compiler->parser->current_buffer = $_buffer;
|
||
|
$output = "<?php \n";
|
||
7 years ago
|
if ($compiler->_cache[ 'blockNesting' ] === 1) {
|
||
7 years ago
|
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n";
|
||
9 years ago
|
} else {
|
||
7 years ago
|
$output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n";
|
||
9 years ago
|
}
|
||
|
$output .= "?>\n";
|
||
7 years ago
|
--$compiler->_cache[ 'blockNesting' ];
|
||
|
if ($compiler->_cache[ 'blockNesting' ] === 0) {
|
||
7 years ago
|
unset($compiler->_cache[ 'blockNesting' ]);
|
||
9 years ago
|
}
|
||
|
$compiler->has_code = true;
|
||
|
$compiler->suppressNocacheProcessing = true;
|
||
|
return $output;
|
||
11 years ago
|
}
|
||
|
}
|