diff options
author | Thomas Willingham <beardyunixer@beardyunixer.com> | 2014-12-11 20:15:27 +0000 |
---|---|---|
committer | Thomas Willingham <beardyunixer@beardyunixer.com> | 2014-12-11 20:15:27 +0000 |
commit | 967ab871b836f618107fe144978bd1453c3c6634 (patch) | |
tree | 1bcb1b4bb1b25c904a2bc06f5c6d526d29909eaa /library/Smarty/libs/sysplugins/smarty_internal_compile_function.php | |
parent | 960c35bad3a0dbaa7a1f2191aef60ad014d926ca (diff) | |
download | volse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.tar.gz volse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.tar.bz2 volse-hubzilla-967ab871b836f618107fe144978bd1453c3c6634.zip |
Update Smarty
Diffstat (limited to 'library/Smarty/libs/sysplugins/smarty_internal_compile_function.php')
-rw-r--r-- | library/Smarty/libs/sysplugins/smarty_internal_compile_function.php | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/library/Smarty/libs/sysplugins/smarty_internal_compile_function.php b/library/Smarty/libs/sysplugins/smarty_internal_compile_function.php index 876b13dee..298eb16f2 100644 --- a/library/Smarty/libs/sysplugins/smarty_internal_compile_function.php +++ b/library/Smarty/libs/sysplugins/smarty_internal_compile_function.php @@ -1,22 +1,21 @@ <?php /** * Smarty Internal Plugin Compile Function - * * Compiles the {function} {/function} tags * - * @package Smarty + * @package Smarty * @subpackage Compiler - * @author Uwe Tews + * @author Uwe Tews */ /** * Smarty Internal Plugin Compile Function Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { - +class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase +{ /** * Attribute definition: Overwrites base class. * @@ -42,9 +41,10 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { /** * Compiles code for the {function} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * * @return boolean true */ public function compile($args, $compiler, $parameter) @@ -57,16 +57,19 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { } unset($_attr['nocache']); $save = array($_attr, $compiler->parser->current_buffer, - $compiler->template->has_nocache_code, $compiler->template->required_plugins); + $compiler->template->has_nocache_code, $compiler->template->required_plugins); $this->openTag($compiler, 'function', $save); $_name = trim($_attr['name'], "'\""); unset($_attr['name']); // set flag that we are compiling a template function $compiler->compiles_template_function = true; $compiler->template->properties['function'][$_name]['parameter'] = array(); + /** @var Smarty_Internal_Template $_smarty_tpl + * used in evaluated code + */ $_smarty_tpl = $compiler->template; foreach ($_attr as $_key => $_data) { - eval ('$tmp='.$_data.';'); + eval ('$tmp=' . $_data . ';'); $compiler->template->properties['function'][$_name]['parameter'][$_key] = $tmp; } $compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter']; @@ -79,7 +82,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}; foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>"; } - // Init temporay context + // Init temporary context $compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array()); $compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser); $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); @@ -88,23 +91,23 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase { $compiler->template->properties['function'][$_name]['compiled'] = ''; return true; } - } /** * Smarty Internal Plugin Compile Functionclose Class * - * @package Smarty + * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase { - +class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase +{ /** * Compiles code for the {/function} tag * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * * @return boolean true */ public function compile($args, $compiler, $parameter) @@ -116,8 +119,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $plugins_string = ''; if (!empty($compiler->template->required_plugins['compiled'])) { $plugins_string = '<?php '; - foreach($compiler->template->required_plugins['compiled'] as $tmp) { - foreach($tmp as $data) { + foreach ($compiler->template->required_plugins['compiled'] as $tmp) { + foreach ($tmp as $data) { $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; } } @@ -125,22 +128,17 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase } if (!empty($compiler->template->required_plugins['nocache'])) { $plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; - foreach($compiler->template->required_plugins['nocache'] as $tmp) { - foreach($tmp as $data) { + foreach ($compiler->template->required_plugins['nocache'] as $tmp) { + foreach ($tmp as $data) { $plugins_string .= "if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n"; } } $plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n"; } - // remove last line break from function definition - $last = count($compiler->parser->current_buffer->subtrees) - 1; - if ($compiler->parser->current_buffer->subtrees[$last] instanceof _smarty_linebreak) { - unset($compiler->parser->current_buffer->subtrees[$last]); - } - // if caching save template function for possible nocache call + // if caching save template function for possible nocache call if ($compiler->template->caching) { $compiler->template->properties['function'][$_name]['compiled'] .= $plugins_string - . $compiler->parser->current_buffer->to_smarty_php(); + . $compiler->parser->current_buffer->to_smarty_php(); $compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash']; $compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code; $compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions; @@ -149,7 +147,8 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $compiler->has_code = false; $output = true; } else { - $output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;}}?>\n"; + $output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars; +foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;}}?>\n"; } // reset flag that we are compiling a template function $compiler->compiles_template_function = false; @@ -157,9 +156,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $compiler->parser->current_buffer = $saved_data[1]; $compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2]; $compiler->template->required_plugins = $saved_data[3]; + return $output; } - } - -?>
\ No newline at end of file |