diff --git a/NEWS b/NEWS index 4acd56a1..da7fb852 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ - - configs directory missing from 1.4.1 release, added back in (Monte) - - added windows include_path setup instructions to FAQ & QUICKSTART + - cleaned up compiled templates global scope by moving some variables into + the class itself. (Andrei) + - fixed a bug that would not allow referring to a section in the including + file from the included file. (Andrei) + - configs directory missing from 1.4.1 release, added back in. (Monte) + - added windows include_path setup instructions to FAQ & QUICKSTART. (Monte) Version 1.4.1 diff --git a/Smarty.class.php b/Smarty.class.php index 13b01aba..ac38551e 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -147,6 +147,8 @@ class Smarty // internal vars var $_error_msg = false; // error messages. true/false var $_tpl_vars = array(); // where assigned template vars are kept + var $_sections = array(); // keeps track of sections + var $_conf_obj = null; // configuration object var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' @@ -173,6 +175,11 @@ class Smarty } } } + + /* Prepare the configuration object. */ + if (!class_exists('Config_File')) + include_once 'Config_File.class.php'; + $this->_conf_obj = new Config_File($this->config_dir); } diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index c2768387..2b0853a2 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -258,6 +258,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _compile_compiler_tag Purpose: compile the custom compiler tag @@ -274,6 +275,7 @@ class Smarty_Compiler extends Smarty { return ''; } + /*======================================================================*\ Function: _compile_custom_tag Purpose: compile custom function tag @@ -297,6 +299,7 @@ class Smarty_Compiler extends Smarty { return ""; } + /*======================================================================*\ Function: _compile_insert_tag Purpose: Compile {insert ...} tag @@ -337,18 +340,15 @@ class Smarty_Compiler extends Smarty { else $update_parent = false; - $output = "config_dir."');\n" . - "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + $output = "_conf_obj->get(".$attrs['file']."));\n"; if ($update_parent) - $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file']."));\n"; if (!empty($attrs['section'])) { - $output .= "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + $output .= "\$_smarty_config = array_merge((array)\$_smarty_config, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; if ($update_parent) - $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; } $output .= '?>'; @@ -356,6 +356,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _compile_include_tag Purpose: Compile {include ...} tag @@ -370,7 +371,7 @@ class Smarty_Compiler extends Smarty { foreach ($attrs as $arg_name => $arg_value) { if ($arg_name == 'file') { - $_smarty_include_tpl_file = $arg_value; + $include_file = $arg_value; continue; } if (is_bool($arg_value)) @@ -380,11 +381,12 @@ class Smarty_Compiler extends Smarty { return "_tpl_vars;\n" . - "\$this->_smarty_include(".$_smarty_include_tpl_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" . + "\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" . "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . "unset(\$_smarty_tpl_vars); ?>"; } + /*======================================================================*\ Function: _compile_section_start Purpose: Compile {section ...} tag @@ -399,8 +401,8 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing section name"); } - $output .= "if (isset(\$_smarty_sections[$section_name])) unset(\$_smarty_sections[$section_name]);\n"; - $section_props = "\$_smarty_sections[$section_name]['properties']"; + $output .= "if (isset(\$this->_sections[$section_name])) unset(\$this->_sections[$section_name]);\n"; + $section_props = "\$this->_sections[$section_name]['properties']"; foreach ($attrs as $attr_name => $attr_value) { switch ($attr_name) { @@ -449,6 +451,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _compile_if_tag Purpose: Compile {if ...} tag @@ -553,6 +556,7 @@ class Smarty_Compiler extends Smarty { return ''; } + /*======================================================================*\ Function: _parse_is_expr Purpose: Parse is expression @@ -612,6 +616,7 @@ class Smarty_Compiler extends Smarty { return $tokens; } + /*======================================================================*\ Function: _parse_attrs Purpose: Parse attribute string @@ -685,6 +690,7 @@ class Smarty_Compiler extends Smarty { return $attrs; } + /*======================================================================*\ Function: _parse_vars_props Purpose: compile variables and section properties tokens into @@ -717,6 +723,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _parse_var Purpose: parse variable expression into PHP code @@ -738,7 +745,7 @@ class Smarty_Compiler extends Smarty { $parts = explode('.', substr($index, 1, -1)); $section = $parts[0]; $section_prop = isset($parts[1]) ? $parts[1] : 'index'; - $output .= "[\$_smarty_sections['$section']['properties']['$section_prop']]"; + $output .= "[\$this->_sections['$section']['properties']['$section_prop']]"; } else if ($index{0} == '.') { $output .= "['" . substr($index, 1) . "']"; } else { @@ -751,6 +758,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _parse_conf_var Purpose: parse configuration variable expression into PHP code @@ -770,6 +778,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _parse_section_prop Purpose: parse section property expression into PHP code @@ -784,13 +793,14 @@ class Smarty_Compiler extends Smarty { $section_name = $match[1]; $prop_name = $match[2]; - $output = "\$_smarty_sections['$section_name']['properties']['$prop_name']"; + $output = "\$this->_sections['$section_name']['properties']['$prop_name']"; $this->_parse_modifiers($output, $modifiers); return $output; } + /*======================================================================*\ Function: _parse_modifiers Purpose: parse modifier chain into PHP code @@ -841,6 +851,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _syntax_error Purpose: display Smarty syntax error diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 13b01aba..ac38551e 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -147,6 +147,8 @@ class Smarty // internal vars var $_error_msg = false; // error messages. true/false var $_tpl_vars = array(); // where assigned template vars are kept + var $_sections = array(); // keeps track of sections + var $_conf_obj = null; // configuration object var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' @@ -173,6 +175,11 @@ class Smarty } } } + + /* Prepare the configuration object. */ + if (!class_exists('Config_File')) + include_once 'Config_File.class.php'; + $this->_conf_obj = new Config_File($this->config_dir); } diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index c2768387..2b0853a2 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -258,6 +258,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _compile_compiler_tag Purpose: compile the custom compiler tag @@ -274,6 +275,7 @@ class Smarty_Compiler extends Smarty { return ''; } + /*======================================================================*\ Function: _compile_custom_tag Purpose: compile custom function tag @@ -297,6 +299,7 @@ class Smarty_Compiler extends Smarty { return ""; } + /*======================================================================*\ Function: _compile_insert_tag Purpose: Compile {insert ...} tag @@ -337,18 +340,15 @@ class Smarty_Compiler extends Smarty { else $update_parent = false; - $output = "config_dir."');\n" . - "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + $output = "_conf_obj->get(".$attrs['file']."));\n"; if ($update_parent) - $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file']."));\n"; + $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file']."));\n"; if (!empty($attrs['section'])) { - $output .= "\$_smarty_config = array_merge((array)\$_smarty_config, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + $output .= "\$_smarty_config = array_merge((array)\$_smarty_config, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; if ($update_parent) - $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$GLOBALS['_smarty_conf_obj']->get(".$attrs['file'].", ".$attrs['section']."));\n"; + $output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; } $output .= '?>'; @@ -356,6 +356,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _compile_include_tag Purpose: Compile {include ...} tag @@ -370,7 +371,7 @@ class Smarty_Compiler extends Smarty { foreach ($attrs as $arg_name => $arg_value) { if ($arg_name == 'file') { - $_smarty_include_tpl_file = $arg_value; + $include_file = $arg_value; continue; } if (is_bool($arg_value)) @@ -380,11 +381,12 @@ class Smarty_Compiler extends Smarty { return "_tpl_vars;\n" . - "\$this->_smarty_include(".$_smarty_include_tpl_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" . + "\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" . "\$this->_tpl_vars = \$_smarty_tpl_vars;\n" . "unset(\$_smarty_tpl_vars); ?>"; } + /*======================================================================*\ Function: _compile_section_start Purpose: Compile {section ...} tag @@ -399,8 +401,8 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing section name"); } - $output .= "if (isset(\$_smarty_sections[$section_name])) unset(\$_smarty_sections[$section_name]);\n"; - $section_props = "\$_smarty_sections[$section_name]['properties']"; + $output .= "if (isset(\$this->_sections[$section_name])) unset(\$this->_sections[$section_name]);\n"; + $section_props = "\$this->_sections[$section_name]['properties']"; foreach ($attrs as $attr_name => $attr_value) { switch ($attr_name) { @@ -449,6 +451,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _compile_if_tag Purpose: Compile {if ...} tag @@ -553,6 +556,7 @@ class Smarty_Compiler extends Smarty { return ''; } + /*======================================================================*\ Function: _parse_is_expr Purpose: Parse is expression @@ -612,6 +616,7 @@ class Smarty_Compiler extends Smarty { return $tokens; } + /*======================================================================*\ Function: _parse_attrs Purpose: Parse attribute string @@ -685,6 +690,7 @@ class Smarty_Compiler extends Smarty { return $attrs; } + /*======================================================================*\ Function: _parse_vars_props Purpose: compile variables and section properties tokens into @@ -717,6 +723,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _parse_var Purpose: parse variable expression into PHP code @@ -738,7 +745,7 @@ class Smarty_Compiler extends Smarty { $parts = explode('.', substr($index, 1, -1)); $section = $parts[0]; $section_prop = isset($parts[1]) ? $parts[1] : 'index'; - $output .= "[\$_smarty_sections['$section']['properties']['$section_prop']]"; + $output .= "[\$this->_sections['$section']['properties']['$section_prop']]"; } else if ($index{0} == '.') { $output .= "['" . substr($index, 1) . "']"; } else { @@ -751,6 +758,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _parse_conf_var Purpose: parse configuration variable expression into PHP code @@ -770,6 +778,7 @@ class Smarty_Compiler extends Smarty { return $output; } + /*======================================================================*\ Function: _parse_section_prop Purpose: parse section property expression into PHP code @@ -784,13 +793,14 @@ class Smarty_Compiler extends Smarty { $section_name = $match[1]; $prop_name = $match[2]; - $output = "\$_smarty_sections['$section_name']['properties']['$prop_name']"; + $output = "\$this->_sections['$section_name']['properties']['$prop_name']"; $this->_parse_modifiers($output, $modifiers); return $output; } + /*======================================================================*\ Function: _parse_modifiers Purpose: parse modifier chain into PHP code @@ -841,6 +851,7 @@ class Smarty_Compiler extends Smarty { } } + /*======================================================================*\ Function: _syntax_error Purpose: display Smarty syntax error