moved config_load from smarty core to plugin

This commit is contained in:
mohrt
2003-04-20 18:08:04 +00:00
parent efd4ed83b5
commit 386515966b
3 changed files with 3 additions and 117 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- moved config_load from smarty core to plugin (Monte)
- added &$repeat-paramter to block-functions (messju)
- enabled hex-constants in function.math.php (messju)
- enabled hex-constants (0x...) as function-attributes, inside if-statements

View File

@@ -1282,84 +1282,8 @@ class Smarty
*/
function config_load($file, $section = null, $scope = 'global')
{
if(@is_dir($this->config_dir)) {
$_config_dir = $this->config_dir;
} else {
// config_dir not found, try include_path
$this->_get_include_path($this->config_dir,$_config_dir);
}
$_file_path = str_replace('//', '/' ,$_config_dir . '/' . $file);
// get path to compiled object file
if(isset($section)) {
$_compile_file = $this->_get_auto_filename($this->compile_dir, $section . ' ' . $file);
} else {
$_compile_file = $this->_get_auto_filename($this->compile_dir, $file);
}
// need to compile config file?
if($this->force_compile || !file_exists($_compile_file) ||
($this->compile_check &&
file_exists($_file_path) &&
( filemtime($_compile_file) != filemtime($_file_path) ))) {
$_compile_config = true;
} else {
include($_compile_file);
$_compile_config = empty($_config_vars);
}
if($_compile_config) {
if(!is_object($this->_conf_obj)) {
require_once SMARTY_DIR . $this->config_class . '.class.php';
$this->_conf_obj = new $this->config_class($_config_dir);
$this->_conf_obj->overwrite = $this->config_overwrite;
$this->_conf_obj->booleanize = $this->config_booleanize;
$this->_conf_obj->read_hidden = $this->config_read_hidden;
$this->_conf_obj->fix_newlines = $this->config_fix_newlines;
$this->_conf_obj->set_path = $_config_dir;
}
if($_config_vars = array_merge($this->_conf_obj->get($file),
$this->_conf_obj->get($file, $section))) {
if(function_exists('var_export')) {
$_compile_data = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; return true; ?>';
} else {
$_compile_data = '<?php $_config_vars = unserialize(\'' . str_replace('\'','\\\'', serialize($_config_vars)) . '\'); return true; ?>';
}
$this->_write_file($_compile_file, $_compile_data, true);
touch($_compile_file,filemtime($_file_path));
}
}
if ($this->debugging) {
$debug_start_time = $this->_get_microtime();
}
if ($this->caching) {
$this->_cache_info['config'][] = $file;
}
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $_config_vars);
$this->_config[0]['files'][$file] = true;
if ($scope == 'parent') {
$this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $_config_vars);
$this->_config[1]['files'][$file] = true;
} else if ($scope == 'global') {
for ($i = 1, $for_max = count($this->_config); $i < $for_max; $i++) {
$this->_config[$i]['vars'] = @array_merge($this->_config[$i]['vars'], $_config_vars);
$this->_config[$i]['files'][$file] = true;
}
}
if ($this->debugging) {
$debug_start_time = $this->_get_microtime();
$this->_smarty_debug_info[] = array('type' => 'config',
'filename' => $file.' ['.$section.'] '.$scope,
'depth' => $this->_inclusion_depth,
'exec_time' => $this->_get_microtime() - $debug_start_time);
}
require_once($this->_get_plugin_filepath('function', 'config_load'));
smarty_function_config_load(array('file' => $file, 'section' => $section, 'scope' => $scope), $this);
}
/**

View File

@@ -474,9 +474,6 @@ class Smarty_Compiler extends Smarty {
else
return "<?php endforeach; endif; ?>";
case 'config_load':
return $this->_compile_config_load_tag($tag_args);
case 'strip':
case '/strip':
return $this->left_delimiter.$tag_command.$this->right_delimiter;
@@ -782,42 +779,6 @@ class Smarty_Compiler extends Smarty {
return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n";
}
/**
* Compile {config_load ...} tag
*
* @param string $tag_args
*/
function _compile_config_load_tag($tag_args)
{
$attrs = $this->_parse_attrs($tag_args);
if (empty($attrs['file'])) {
$this->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
}
if (empty($attrs['section'])) {
$attrs['section'] = 'null';
}
if (isset($attrs['scope'])) {
$scope = @$this->_dequote($attrs['scope']);
if ($scope != 'local' &&
$scope != 'parent' &&
$scope != 'global') {
$this->_syntax_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
}
} else {
if (isset($attrs['global']) && $attrs['global'])
$scope = 'parent';
else
$scope = 'local';
}
return '<?php $this->config_load(' . $attrs['file'] . ', ' . $attrs['section'] . ", '$scope'); ?>";
}
/**
* Compile {include ...} tag
*