Moved config loading code inside main class, the compiled template now

simply calls that method.
This commit is contained in:
andrey
2001-06-19 15:30:29 +00:00
parent 911da5cf03
commit 73b049acb7
5 changed files with 81 additions and 60 deletions

View File

@@ -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 = '<!-- 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
@@ -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

View File

@@ -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 = "<?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
View File

@@ -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

View File

@@ -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 = '<!-- 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
@@ -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

View File

@@ -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 = "<?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;
}