mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
* moved config array into class itself
* added 'scope' attribute for config_load
This commit is contained in:
6
NEWS
6
NEWS
@@ -1,8 +1,12 @@
|
||||
- added 'scope' attribute for {config_load}, 'global' is now deprecated but
|
||||
is still supported. (Andrei)
|
||||
- reduced template symbol table pollution by moving config array into the
|
||||
class itself. (Andrei)
|
||||
- fixed a bug with passing quoted arguments to modifiers inside {if}
|
||||
statements. (Andrei, Sam Beckwith)
|
||||
- added security features for third party template editing. (Monte)
|
||||
- added assign custom function, documented. (Monte)
|
||||
- fixed bug with template header using version instead of _version (Monte)
|
||||
- fixed bug with template header using version instead of _version. (Monte)
|
||||
- fixed a problem with putting $ followed by numbers inside {strip} and
|
||||
{/strip} tags. (Andrei)
|
||||
- fixed Config_File class to allow empty config paths (defaults to current
|
||||
|
@@ -162,6 +162,7 @@ class Smarty
|
||||
var $_tpl_vars = array(); // where assigned template vars are kept
|
||||
var $_sections = array(); // keeps track of sections
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_config = array(); // loaded configuration settings
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '1.4.2'; // Smarty version number
|
||||
var $_extract = false; // flag for custom functions
|
||||
@@ -519,6 +520,9 @@ class Smarty
|
||||
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
/* Initialize config array. */
|
||||
$this->_config = array(array());
|
||||
|
||||
if ($this->show_info_header) {
|
||||
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
|
||||
} else {
|
||||
@@ -739,15 +743,17 @@ class Smarty
|
||||
Function: _smarty_include()
|
||||
Purpose: called for included templates
|
||||
\*======================================================================*/
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars,
|
||||
&$_smarty_config_parent)
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
|
||||
{
|
||||
$_smarty_config = $_smarty_config_parent;
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
array_unshift($this->_config, $this->_config[0]);
|
||||
|
||||
$this->_process_template($_smarty_include_tpl_file, $compile_path);
|
||||
include($compile_path);
|
||||
|
||||
array_shift($this->_config);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
|
@@ -347,20 +347,39 @@ 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;
|
||||
$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 {
|
||||
if (!empty($attrs['global']) && $attrs['global'])
|
||||
$scope = 'parent';
|
||||
else
|
||||
$scope = 'local';
|
||||
}
|
||||
|
||||
$output = "<?php\n" .
|
||||
"\$_smarty_config = array_merge((array)\$_smarty_config, \$this->_conf_obj->get(".$attrs['file']."));\n";
|
||||
if ($update_parent)
|
||||
$output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file']."));\n";
|
||||
"\$this->_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";
|
||||
|
||||
if (!empty($attrs['section'])) {
|
||||
$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, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\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 .= '?>';
|
||||
@@ -393,7 +412,7 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
return "<?php " .
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" .
|
||||
"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
|
||||
"unset(\$_smarty_tpl_vars); ?>";
|
||||
}
|
||||
@@ -793,7 +812,7 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
$var_name = substr($var_ref, 1, -1);
|
||||
|
||||
$output = "\$_smarty_config['$var_name']";
|
||||
$output = "\$this->_config[0]['$var_name']";
|
||||
|
||||
$this->_parse_modifiers($output, $modifiers);
|
||||
|
||||
@@ -891,4 +910,6 @@ class Smarty_Compiler extends Smarty {
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set et: */
|
||||
|
||||
?>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{config_load file=test.conf section="setup"}
|
||||
{config_load file=test.conf section=""}
|
||||
{include file=header.tpl title=foo}
|
||||
|
||||
<PRE>
|
||||
|
@@ -162,6 +162,7 @@ class Smarty
|
||||
var $_tpl_vars = array(); // where assigned template vars are kept
|
||||
var $_sections = array(); // keeps track of sections
|
||||
var $_conf_obj = null; // configuration object
|
||||
var $_config = array(); // loaded configuration settings
|
||||
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
|
||||
var $_version = '1.4.2'; // Smarty version number
|
||||
var $_extract = false; // flag for custom functions
|
||||
@@ -519,6 +520,9 @@ class Smarty
|
||||
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
/* Initialize config array. */
|
||||
$this->_config = array(array());
|
||||
|
||||
if ($this->show_info_header) {
|
||||
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
|
||||
} else {
|
||||
@@ -739,15 +743,17 @@ class Smarty
|
||||
Function: _smarty_include()
|
||||
Purpose: called for included templates
|
||||
\*======================================================================*/
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars,
|
||||
&$_smarty_config_parent)
|
||||
function _smarty_include($_smarty_include_tpl_file, $_smarty_include_vars)
|
||||
{
|
||||
$_smarty_config = $_smarty_config_parent;
|
||||
$this->_tpl_vars = array_merge($this->_tpl_vars, $_smarty_include_vars);
|
||||
extract($this->_tpl_vars);
|
||||
|
||||
array_unshift($this->_config, $this->_config[0]);
|
||||
|
||||
$this->_process_template($_smarty_include_tpl_file, $compile_path);
|
||||
include($compile_path);
|
||||
|
||||
array_shift($this->_config);
|
||||
}
|
||||
|
||||
/*======================================================================*\
|
||||
|
@@ -347,20 +347,39 @@ 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;
|
||||
$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 {
|
||||
if (!empty($attrs['global']) && $attrs['global'])
|
||||
$scope = 'parent';
|
||||
else
|
||||
$scope = 'local';
|
||||
}
|
||||
|
||||
$output = "<?php\n" .
|
||||
"\$_smarty_config = array_merge((array)\$_smarty_config, \$this->_conf_obj->get(".$attrs['file']."));\n";
|
||||
if ($update_parent)
|
||||
$output .= "\$_smarty_config_parent = array_merge((array)\$_smarty_config_parent, \$this->_conf_obj->get(".$attrs['file']."));\n";
|
||||
"\$this->_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";
|
||||
|
||||
if (!empty($attrs['section'])) {
|
||||
$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, \$this->_conf_obj->get(".$attrs['file'].", ".$attrs['section']."));\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 .= '?>';
|
||||
@@ -393,7 +412,7 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
return "<?php " .
|
||||
"\$_smarty_tpl_vars = \$this->_tpl_vars;\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."), \$_smarty_config);\n" .
|
||||
"\$this->_smarty_include(".$include_file.", array(".implode(',', (array)$arg_list)."));\n" .
|
||||
"\$this->_tpl_vars = \$_smarty_tpl_vars;\n" .
|
||||
"unset(\$_smarty_tpl_vars); ?>";
|
||||
}
|
||||
@@ -793,7 +812,7 @@ class Smarty_Compiler extends Smarty {
|
||||
|
||||
$var_name = substr($var_ref, 1, -1);
|
||||
|
||||
$output = "\$_smarty_config['$var_name']";
|
||||
$output = "\$this->_config[0]['$var_name']";
|
||||
|
||||
$this->_parse_modifiers($output, $modifiers);
|
||||
|
||||
@@ -891,4 +910,6 @@ class Smarty_Compiler extends Smarty {
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set et: */
|
||||
|
||||
?>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{config_load file=test.conf section="setup"}
|
||||
{config_load file=test.conf section=""}
|
||||
{include file=header.tpl title=foo}
|
||||
|
||||
<PRE>
|
||||
|
Reference in New Issue
Block a user