mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
Moved config loading code inside main class, the compiled template now
simply calls that method.
This commit is contained in:
@@ -526,7 +526,7 @@ class Smarty
|
||||
if ($this->show_info_header) {
|
||||
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
|
||||
} else {
|
||||
$info_header = "";
|
||||
$info_header = '';
|
||||
}
|
||||
|
||||
// if we just need to display the results, don't perform output
|
||||
@@ -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
|
||||
|
@@ -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']) {
|
||||
@@ -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 = "<?php\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";
|
||||
|
||||
$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 = '<?php $this->_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
1
TODO
1
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
|
||||
|
@@ -526,7 +526,7 @@ class Smarty
|
||||
if ($this->show_info_header) {
|
||||
$info_header = '<!-- Smarty '.$this->_version.' '.strftime("%Y-%m-%d %H:%M:%S %Z").' -->'."\n\n";
|
||||
} else {
|
||||
$info_header = "";
|
||||
$info_header = '';
|
||||
}
|
||||
|
||||
// if we just need to display the results, don't perform output
|
||||
@@ -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
|
||||
|
@@ -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']) {
|
||||
@@ -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 = "<?php\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";
|
||||
|
||||
$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 = '<?php $this->_config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
Reference in New Issue
Block a user