function Smarty_Compiler::_compile_block_tag in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/lib/smarty/Smarty_Compiler.class.php \Smarty_Compiler::_compile_block_tag()
compile block function tag
sets $output to compiled block function tag
Parameters
string $tag_command:
string $tag_args:
string $tag_modifier:
string $output:
Return value
boolean
1 call to Smarty_Compiler::_compile_block_tag()
- Smarty_Compiler::_compile_tag in includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php - Compile a template tag
File
- includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php, line 664
Class
- Smarty_Compiler
- Template compiling class @package Smarty
Code
function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) {
if ($tag_command[0] == '/') {
$start_tag = false;
$tag_command = substr($tag_command, 1);
}
else {
$start_tag = true;
}
$found = false;
$have_function = true;
/*
* First we check if the block function has already been registered
* or loaded from a plugin file.
*/
if (isset($this->_plugins['block'][$tag_command])) {
$found = true;
$plugin_func = $this->_plugins['block'][$tag_command][0];
if (!is_callable($plugin_func)) {
$message = "block function '{$tag_command}' is not implemented";
$have_function = false;
}
}
else {
if ($plugin_file = $this
->_get_plugin_filepath('block', $tag_command)) {
$found = true;
include_once $plugin_file;
$plugin_func = 'smarty_block_' . $tag_command;
if (!function_exists($plugin_func)) {
$message = "plugin function {$plugin_func}() not found in {$plugin_file}\n";
$have_function = false;
}
else {
$this->_plugins['block'][$tag_command] = array(
$plugin_func,
null,
null,
null,
true,
);
}
}
}
if (!$found) {
return false;
}
else {
if (!$have_function) {
$this
->_syntax_error($message, E_USER_WARNING, __FILE__, __LINE__);
return true;
}
}
/*
* Even though we've located the plugin function, compilation
* happens only once, so the plugin will still need to be loaded
* at runtime for future requests.
*/
$this
->_add_plugin('block', $tag_command);
if ($start_tag) {
$this
->_push_tag($tag_command);
}
else {
$this
->_pop_tag($tag_command);
}
if ($start_tag) {
$output = '<?php ' . $this
->_push_cacheable_state('block', $tag_command);
$attrs = $this
->_parse_attrs($tag_args);
$arg_list = $this
->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs = '');
$output .= "{$_cache_attrs}\$this->_tag_stack[] = array('{$tag_command}', array(" . implode(',', $arg_list) . ')); ';
$output .= $this
->_compile_plugin_call('block', $tag_command) . '($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat=true);';
$output .= 'while ($_block_repeat) { ob_start(); ?>';
}
else {
$output = '<?php $_block_content = ob_get_contents(); ob_end_clean(); ';
$_out_tag_text = $this
->_compile_plugin_call('block', $tag_command) . '($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat=false)';
if ($tag_modifier != '') {
$this
->_parse_modifiers($_out_tag_text, $tag_modifier);
}
$output .= 'echo ' . $_out_tag_text . '; } ';
$output .= " array_pop(\$this->_tag_stack); " . $this
->_pop_cacheable_state('block', $tag_command) . '?>';
}
return true;
}