diff --git a/Smarty.class.php b/Smarty.class.php index 6e19ecec..297deb5f 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -477,7 +477,7 @@ class Smarty function display($tpl_file, $cache_id = null) { $this->fetch($tpl_file, $cache_id, true); - } + } /*======================================================================*\ Function: fetch() @@ -526,7 +526,7 @@ class Smarty if ($this->show_info_header) { $info_header = ''."\n\n"; } else { - $info_header = ""; + $info_header = ''; } // if we just need to display the results, don't perform output @@ -548,7 +548,7 @@ class Smarty $this->_write_file($cache_file, $results, true); $results = $this->_process_cached_inserts($results); } - + if ($display) { if (isset($results)) { echo $results; } return; @@ -570,8 +570,8 @@ class Smarty if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) { if (!$this->compile_check) { // no need to check if the template needs recompiled - return true; - } else { + return true; + } else { // get template source and timestamp $this->_fetch_template_source($tpl_file, $template_source, $template_timestamp); if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) { @@ -591,7 +591,7 @@ class Smarty $this->_write_compiled_template($compile_path, $template_compiled); return true; } - } + } /*======================================================================*\ Function: _fetch_compile_path() @@ -756,6 +756,33 @@ class Smarty array_shift($this->_config); } + +/*======================================================================*\ + Function: _config_load + Purpose: load configuration values +\*======================================================================*/ + function _config_load($file, $section, $scope) + { + $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); + if ($scope == 'parent') { + if (count($this->_config) > 0) + $this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file)); + } else if ($scope == 'global') + for ($i = 1; $i < count($this->_config); $i++) + $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file)); + + if (!empty($section)) { + $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file, $section)); + if ($scope == 'parent') { + if (count($this->_config) > 0) + $this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file, $section)); + } else if ($scope == 'global') + for ($i = 1; $i < count($this->_config); $i++) + $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); + } + } + + /*======================================================================*\ Function: _process_cached_inserts Purpose: Replace cached inserts with the actual results diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 6922487d..e3060f63 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -54,7 +54,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_file($tpl_file, $template_source, &$template_compiled) { - if($this->security) { + if ($this->security) { // do not allow php syntax to be executed unless specified if ($this->php_handling == SMARTY_PHP_ALLOW && !$this->security_settings['PHP_HANDLING']) { @@ -249,7 +249,7 @@ class Smarty_Compiler extends Smarty { case 'php': if ($this->security && !$this->security_settings['PHP_TAGS']) { $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING); - return; + return; } list (,$php_block) = each($this->_php_blocks); $this->_current_line_no += substr_count($php_block, "\n"); @@ -347,12 +347,15 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing 'file' attribute in config_load tag"); } + if (empty($attrs['section'])) { + $attrs['section'] = 'null'; + } + $scope = $this->_dequote($attrs['scope']); if (!empty($scope)) { if ($scope != 'local' && $scope != 'parent' && $scope != 'global') { - var_dump($scope); $this->_syntax_error("invalid 'scope' attribute value"); } } else { @@ -362,27 +365,7 @@ class Smarty_Compiler extends Smarty { $scope = 'local'; } - $output = "_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file']."));\n"; - if ($scope == 'parent') - $output .= "if (count(\$this->_config) > 0)\n" . - " \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file']."));\n"; - else if ($scope == 'global') - $output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" . - " \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file']."));\n"; - - $dq_section = $this->_dequote($attrs['section']); - if (!empty($dq_section)) { - $output .= "\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - if ($scope == 'parent') - $output .= "if (count(\$this->_config) > 0)\n" . - " \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - else if ($scope == 'global') - $output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" . - " \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - } - - $output .= '?>'; + $output = '_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>"; return $output; } diff --git a/TODO b/TODO index 2b3278d0..9c89a9f9 100644 --- a/TODO +++ b/TODO @@ -7,3 +7,4 @@ * think about passing default structures to includes, i.e. {include default=$foo}, then using $bar in included template, instead of $foo.bar * support implementations of prefiltes, mods, and others as class methods. +* possibly implement default modifiers that apply to variables upon display diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 6e19ecec..297deb5f 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -477,7 +477,7 @@ class Smarty function display($tpl_file, $cache_id = null) { $this->fetch($tpl_file, $cache_id, true); - } + } /*======================================================================*\ Function: fetch() @@ -526,7 +526,7 @@ class Smarty if ($this->show_info_header) { $info_header = ''."\n\n"; } else { - $info_header = ""; + $info_header = ''; } // if we just need to display the results, don't perform output @@ -548,7 +548,7 @@ class Smarty $this->_write_file($cache_file, $results, true); $results = $this->_process_cached_inserts($results); } - + if ($display) { if (isset($results)) { echo $results; } return; @@ -570,8 +570,8 @@ class Smarty if (!$this->force_compile && $this->_compiled_template_exists($compile_path)) { if (!$this->compile_check) { // no need to check if the template needs recompiled - return true; - } else { + return true; + } else { // get template source and timestamp $this->_fetch_template_source($tpl_file, $template_source, $template_timestamp); if ($template_timestamp <= $this->_fetch_compiled_template_timestamp($compile_path)) { @@ -591,7 +591,7 @@ class Smarty $this->_write_compiled_template($compile_path, $template_compiled); return true; } - } + } /*======================================================================*\ Function: _fetch_compile_path() @@ -756,6 +756,33 @@ class Smarty array_shift($this->_config); } + +/*======================================================================*\ + Function: _config_load + Purpose: load configuration values +\*======================================================================*/ + function _config_load($file, $section, $scope) + { + $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file)); + if ($scope == 'parent') { + if (count($this->_config) > 0) + $this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file)); + } else if ($scope == 'global') + for ($i = 1; $i < count($this->_config); $i++) + $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file)); + + if (!empty($section)) { + $this->_config[0] = array_merge($this->_config[0], $this->_conf_obj->get($file, $section)); + if ($scope == 'parent') { + if (count($this->_config) > 0) + $this->_config[1] = array_merge($this->_config[1], $this->_conf_obj->get($file, $section)); + } else if ($scope == 'global') + for ($i = 1; $i < count($this->_config); $i++) + $this->_config[$i] = array_merge($this->_config[$i], $this->_conf_obj->get($file, $section)); + } + } + + /*======================================================================*\ Function: _process_cached_inserts Purpose: Replace cached inserts with the actual results diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 6922487d..e3060f63 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -54,7 +54,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_file($tpl_file, $template_source, &$template_compiled) { - if($this->security) { + if ($this->security) { // do not allow php syntax to be executed unless specified if ($this->php_handling == SMARTY_PHP_ALLOW && !$this->security_settings['PHP_HANDLING']) { @@ -249,7 +249,7 @@ class Smarty_Compiler extends Smarty { case 'php': if ($this->security && !$this->security_settings['PHP_TAGS']) { $this->_syntax_error("(secure mode) php tags not permitted", E_USER_WARNING); - return; + return; } list (,$php_block) = each($this->_php_blocks); $this->_current_line_no += substr_count($php_block, "\n"); @@ -347,12 +347,15 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing 'file' attribute in config_load tag"); } + if (empty($attrs['section'])) { + $attrs['section'] = 'null'; + } + $scope = $this->_dequote($attrs['scope']); if (!empty($scope)) { if ($scope != 'local' && $scope != 'parent' && $scope != 'global') { - var_dump($scope); $this->_syntax_error("invalid 'scope' attribute value"); } } else { @@ -362,27 +365,7 @@ class Smarty_Compiler extends Smarty { $scope = 'local'; } - $output = "_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file']."));\n"; - if ($scope == 'parent') - $output .= "if (count(\$this->_config) > 0)\n" . - " \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file']."));\n"; - else if ($scope == 'global') - $output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" . - " \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file']."));\n"; - - $dq_section = $this->_dequote($attrs['section']); - if (!empty($dq_section)) { - $output .= "\$this->_config[0] = array_merge(\$this->_config[0], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - if ($scope == 'parent') - $output .= "if (count(\$this->_config) > 0)\n" . - " \$this->_config[1] = array_merge(\$this->_config[1], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - else if ($scope == 'global') - $output .= "for (\$this->_i = 1; \$this->_i < count(\$this->_config); \$this->_i++)\n" . - " \$this->_config[\$this->_i] = array_merge(\$this->_config[\$this->_i], \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\n"; - } - - $output .= '?>'; + $output = '_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>"; return $output; }