From 2e28c7de45c3802e00eabad3d9a92342416c12dc Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 16 Mar 2001 23:02:43 +0000 Subject: [PATCH] Fixing the config_load scoping. --- Smarty_Compiler.class.php | 25 +++++++++++++++++-------- libs/Smarty_Compiler.class.php | 25 +++++++++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 13382efc..2dfc49c6 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -396,15 +396,24 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing 'file' attribute in config_load tag"); } + if (!empty($attrs['global']) && $attrs['global']) + $update_parent = 'true'; + else + $update_parent = 'false'; + $output = "config_dir."');\n" . - "}\n" . - "\$GLOBALS['_smarty_config'] = array_merge((array)\$GLOBALS['_smarty_config'], \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + "if (isset(\$parent_smarty_config) && $update_parent)\n" . + " \$parent_smarty_config = array_merge((array)\$parent_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n" . + "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; - if (!empty($attrs['section'])) - $output .= '$GLOBALS[\'_smarty_config\'] = array_merge((array)$GLOBALS[\'_smarty_config\'], $GLOBALS[\'_smarty_conf_obj\']->get('.$attrs['file'].', '.$attrs['section'].')); '; + if (!empty($attrs['section'])) { + $output .= "if (isset(\$parent_smarty_config) && $update_parent)\n" . + " \$parent_smarty_config = array_merge((array)\$parent_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n" . + "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + } $output .= '?>'; @@ -436,14 +445,14 @@ class Smarty_Compiler extends Smarty { return ""; + "$include_func_name(\"$include_file_name\", get_defined_vars(), array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n?>"; } /*======================================================================*\ @@ -841,7 +850,7 @@ class Smarty_Compiler extends Smarty { $var_name = substr($var_ref, 1, -1); - $output = "\$GLOBALS['_smarty_config']['$var_name']"; + $output = "\$_smarty_config['$var_name']"; $this->_parse_modifiers($output, $modifiers); diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 13382efc..2dfc49c6 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -396,15 +396,24 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing 'file' attribute in config_load tag"); } + if (!empty($attrs['global']) && $attrs['global']) + $update_parent = 'true'; + else + $update_parent = 'false'; + $output = "config_dir."');\n" . - "}\n" . - "\$GLOBALS['_smarty_config'] = array_merge((array)\$GLOBALS['_smarty_config'], \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + "if (isset(\$parent_smarty_config) && $update_parent)\n" . + " \$parent_smarty_config = array_merge((array)\$parent_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n" . + "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; - if (!empty($attrs['section'])) - $output .= '$GLOBALS[\'_smarty_config\'] = array_merge((array)$GLOBALS[\'_smarty_config\'], $GLOBALS[\'_smarty_conf_obj\']->get('.$attrs['file'].', '.$attrs['section'].')); '; + if (!empty($attrs['section'])) { + $output .= "if (isset(\$parent_smarty_config) && $update_parent)\n" . + " \$parent_smarty_config = array_merge((array)\$parent_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n" . + "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + } $output .= '?>'; @@ -436,14 +445,14 @@ class Smarty_Compiler extends Smarty { return ""; + "$include_func_name(\"$include_file_name\", get_defined_vars(), array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n?>"; } /*======================================================================*\ @@ -841,7 +850,7 @@ class Smarty_Compiler extends Smarty { $var_name = substr($var_ref, 1, -1); - $output = "\$GLOBALS['_smarty_config']['$var_name']"; + $output = "\$_smarty_config['$var_name']"; $this->_parse_modifiers($output, $modifiers);