From 7d2e27ae2fa0e1db6cab12446148de070a8ab538 Mon Sep 17 00:00:00 2001 From: uwetews Date: Sun, 9 Aug 2015 20:53:32 +0200 Subject: [PATCH] use parent_compiler object for storing required plugins --- .../smarty_internal_compile_block.php | 5 ++- .../smarty_internal_compile_function.php | 36 ++++------------- .../smarty_internal_compile_include.php | 14 ------- ...arty_internal_compile_private_modifier.php | 4 +- ...ernal_compile_private_print_expression.php | 8 ++-- .../smarty_internal_extension_codeframe.php | 10 ++--- libs/sysplugins/smarty_internal_template.php | 14 ++----- .../smarty_internal_templatecompilerbase.php | 40 +++++++++---------- 8 files changed, 45 insertions(+), 86 deletions(-) diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 4fe6d439..51e3e256 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -167,6 +167,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase $_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash; $_tpl->allow_relative_path = true; $_tpl->loadCompiler(); + $_tpl->compiler->parent_compiler = $compiler; $_tpl->compiler->_tag_objects = $compiler->_tag_objects; $_tpl->compiler->inheritance = true; $_tpl->compiler->suppressHeader = true; @@ -192,7 +193,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase if ($_tpl->compiled->has_nocache_code) { $compiler->template->compiled->has_nocache_code = true; } - foreach ($_tpl->required_plugins as $key => $tmp1) { + foreach ($_tpl->compiled->required_plugins as $key => $tmp1) { if ($compiler->nocache && $compiler->template->caching) { $code = 'nocache'; } else { @@ -200,7 +201,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase } foreach ($tmp1 as $name => $tmp) { foreach ($tmp as $type => $data) { - $compiler->template->required_plugins[$code][$name][$type] = $data; + $compiler->parent_compiler->template->compiled->required_plugins[$code][$name][$type] = $data; } } } diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index af33c82f..eddef0f8 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -140,23 +140,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $output .= "/* {$_funcNameCaching} */\n"; $output .= "if (!function_exists('{$_funcNameCaching}')) {\n"; $output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n"; - // build plugin include code - if (!empty($compiler->template->required_plugins['compiled'])) { - foreach ($compiler->template->required_plugins['compiled'] as $tmp) { - foreach ($tmp as $data) { - $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n"; - } - } - } - if (!empty($compiler->template->required_plugins['nocache'])) { - $output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/template->required_plugins['nocache'] as $tmp) { - foreach ($tmp as $data) { - $output .= "if (!is_callable(\'{$data['function']}\')) require_once \'{$data['file']}\';\n"; - } - } - $output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n"; - } $output .= "ob_start();\n"; $output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n"; $output .= $_paramsCode; @@ -186,17 +169,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $output .= "/* {$_funcName} */\n"; $output .= "if (!function_exists('{$_funcName}')) {\n"; $output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n"; - // build plugin include code - if (!empty($compiler->template->required_plugins['nocache'])) { - $compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $compiler->template->required_plugins['nocache']); - } - if (!empty($compiler->template->required_plugins['compiled'])) { - foreach ($compiler->template->required_plugins['compiled'] as $tmp) { - foreach ($tmp as $data) { - $output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n"; - } - } - } $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; $output .= $_paramsCode; $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>"; @@ -209,6 +181,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $output .= "?>\n"; $compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output)); $compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); + // nocache plugins must be copied + if (!empty($compiler->template->compiled->required_plugins['nocache'])) { + foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) { + foreach ($tmp as $type => $data) { + $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = $data; + } + } + } // restore old buffer $compiler->parser->current_buffer = $saved_data[1]; diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 048e7ce1..84ae64c2 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -229,20 +229,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase } $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; $has_compiled_template = true; - if (!empty($tpl->required_plugins['compiled'])) { - foreach ($tpl->required_plugins['compiled'] as $name => $callBack) { - if (!isset($compiler->template->required_plugins['compiled'][$name])) { - $compiler->template->required_plugins['compiled'][$name] = $callBack; - } - } - } - if (!empty($tpl->required_plugins['nocache'])) { - foreach ($tpl->required_plugins['nocache'] as $name => $callBack) { - if (!isset($compiler->template->required_plugins['nocache'][$name])) { - $compiler->template->required_plugins['nocache'][$name] = $callBack; - } - } - } unset ($tpl); } } else { diff --git a/libs/sysplugins/smarty_internal_compile_private_modifier.php b/libs/sysplugins/smarty_internal_compile_private_modifier.php index 48fe707e..9594d2ae 100644 --- a/libs/sysplugins/smarty_internal_compile_private_modifier.php +++ b/libs/sysplugins/smarty_internal_compile_private_modifier.php @@ -133,8 +133,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa } } } - if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || - isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) + if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || + isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ) { // was a plugin $compiler->known_modifier_type[$modifier] = 4; diff --git a/libs/sysplugins/smarty_internal_compile_private_print_expression.php b/libs/sysplugins/smarty_internal_compile_private_print_expression.php index 90089515..af714a53 100644 --- a/libs/sysplugins/smarty_internal_compile_private_print_expression.php +++ b/libs/sysplugins/smarty_internal_compile_private_print_expression.php @@ -142,11 +142,11 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C $path = $compiler->smarty->loadPlugin($plugin_name, false); if ($path) { if ($compiler->template->caching) { - $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; - $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; + $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; + $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; } else { - $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; - $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; + $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path; + $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name; } } else { // not found diff --git a/libs/sysplugins/smarty_internal_extension_codeframe.php b/libs/sysplugins/smarty_internal_extension_codeframe.php index 15ff7ca8..155bcc27 100644 --- a/libs/sysplugins/smarty_internal_extension_codeframe.php +++ b/libs/sysplugins/smarty_internal_extension_codeframe.php @@ -47,8 +47,8 @@ class Smarty_Internal_Extension_CodeFrame $output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n"; // include code for plugins if (!$cache) { - if (!empty($_template->required_plugins['compiled'])) { - foreach ($_template->required_plugins['compiled'] as $tmp) { + if (!empty($_template->compiled->required_plugins['compiled'])) { + foreach ($_template->compiled->required_plugins['compiled'] as $tmp) { foreach ($tmp as $data) { $file = addslashes($data['file']); if (is_array($data['function'])) { @@ -59,10 +59,10 @@ class Smarty_Internal_Extension_CodeFrame } } } - if (!empty($_template->required_plugins['nocache'])) { - $_template->has_nocache_code = true; + if ($_template->caching && !empty($_template->compiled->required_plugins['nocache'])) { + $_template->compiled->has_nocache_code = true; $output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/smarty; "; - foreach ($_template->required_plugins['nocache'] as $tmp) { + foreach ($_template->compiled->required_plugins['nocache'] as $tmp) { foreach ($tmp as $data) { $file = addslashes($data['file']); if (is_Array($data['function'])) { diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 3a4e19ba..953bf96a 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -48,14 +48,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public $mustCompile = null; - - /** - * required plugins - * - * @var array - */ - public $required_plugins = array('compiled' => array(), 'nocache' => array()); - /** * blocks for template inheritance * @@ -340,10 +332,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase } if ($parentIsTpl) { $this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function); - foreach ($this->required_plugins as $code => $tmp1) { - foreach ($tmp1 as $name => $tmp) { + foreach ($this->compiled->required_plugins as $code => $tmp1) { + foreach ($tmp1 as $name => $tmp) { foreach ($tmp as $type => $data) { - $this->parent->required_plugins[$code][$name][$type] = $data; + $this->parent->compiled->required_plugins[$code][$name][$type] = $data; } } } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 8caf3feb..b8a5791a 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -850,18 +850,18 @@ abstract class Smarty_Internal_TemplateCompilerBase { $function = null; if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { - $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; - } elseif (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]; - $function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; + if (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { + $function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; + } elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]; + $function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function']; } } else { - if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) { - $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; - } elseif (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) { - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]; - $function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; + if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) { + $function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; + } elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) { + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]; + $function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function']; } } if (isset($function)) { @@ -877,11 +877,11 @@ abstract class Smarty_Internal_TemplateCompilerBase if (is_string($file)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file; - $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function; + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file; + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function; } else { - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file; - $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function; + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file; + $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function; } if ($plugin_type == 'modifier') { $this->modifier_plugins[$plugin_name] = true; @@ -918,11 +918,11 @@ abstract class Smarty_Internal_TemplateCompilerBase if ($script !== null) { if (is_file($script)) { if ($this->template->caching && ($this->nocache || $this->tag_nocache)) { - $this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script; - $this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback; + $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script; + $this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback; } else { - $this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; - $this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; + $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script; + $this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback; } require_once $script; } else { @@ -989,8 +989,8 @@ abstract class Smarty_Internal_TemplateCompilerBase "/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; // make sure we include modifier plugins for nocache code foreach ($this->modifier_plugins as $plugin_name => $dummy) { - if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) { - $this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier']; + if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier'])) { + $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name]['modifier'] = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier']; } } } else {