clean up code, respect force_compile and compile_check flags

This commit is contained in:
mohrt
2002-12-09 23:37:35 +00:00
parent c3cc85f094
commit 61987444e8
4 changed files with 82 additions and 94 deletions

View File

@@ -256,7 +256,7 @@ class Config_File {
$fp = @fopen($config_file, "r");
if (!is_resource($fp)) {
$this->_trigger_error_msg("Could not open config file '$config_file'");
return;
return false;
}
$contents = fread($fp, filesize($config_file));
@@ -286,6 +286,8 @@ class Config_File {
}
$this->_config_data[$config_file] = $config_data;
return true;
}

View File

@@ -1234,8 +1234,25 @@ function _generate_debug_output() {
$this->_get_include_path($this->config_dir,$_config_dir);
}
$_file_path = $_config_dir . '/' . $file;
$_file_path = str_replace('//', '/' ,$_config_dir . '/' . $file);
// get path to compiled object file
$_compile_file = $this->_get_auto_filename($this->compile_dir, $file . $section, 'SMARTY_CONFIG');
// need to generate cache?
if($this->force_compile ||
($this->compile_check && ( @filemtime($_compile_file) != @filemtime($_file_path) ))) {
$_generate_cache = true;
} else {
include($_compile_file);
if(empty($_config_vars)) {
$_generate_cache = true;
} else {
$_generate_cache = false;
}
}
if($_generate_cache) {
if(!is_object($this->_conf_obj)) {
require_once SMARTY_DIR . $this->config_class . '.class.php';
$this->_conf_obj = new Config_File($_config_dir);
@@ -1243,22 +1260,13 @@ function _generate_debug_output() {
$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(!isset($this->_config[0]['files'][$file])) {
// get path to compiled object file
$_cache_file = $this->_get_auto_filename($this->cache_dir, $file, 'SMARTY_CONFIG');
// see if cache file is up to date
if(@filemtime($_cache_file) == @filemtime($_file_path)) {
// load cache file
$this->_conf_obj = unserialize($this->_read_file($_cache_file));
} else {
// load file and save cache
$this->_conf_obj->load_file($file);
$_conf_obj_file_contents = serialize($this->_conf_obj);
$this->_write_file($_cache_file, $_conf_obj_file_contents, true);
touch($_cache_file,filemtime($_file_path));
if($_config_vars = $this->_conf_obj->get($file, $section)) {
$this->_write_file($_compile_file,
'<?php $_config_vars = unserialize(\'' . str_replace('\'','\\\'', serialize($_config_vars)) . '\'); ?>',
true);
touch($_compile_file,filemtime($_file_path));
}
}
@@ -1270,34 +1278,18 @@ function _generate_debug_output() {
$this->_cache_info['config'][] = $file;
}
if (!isset($this->_config[0]['files'][$file])) {
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file));
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $_config_vars);
$this->_config[0]['files'][$file] = true;
}
if ($scope == 'parent') {
if (count($this->_config) > 0 && !isset($this->_config[1]['files'][$file])) {
$this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file));
$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++) {
if (!isset($this->_config[$i]['files'][$file])) {
$this->_config[$i]['vars'] = @array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file));
$this->_config[$i]['vars'] = @array_merge($this->_config[$i]['vars'], $_config_vars);
$this->_config[$i]['files'][$file] = true;
}
}
}
if (!empty($section)) {
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file, $section));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file, $section));
} 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'], $this->_conf_obj->get($file, $section));
}
if ($this->debugging) {
$debug_start_time = $this->_get_microtime();

View File

@@ -256,7 +256,7 @@ class Config_File {
$fp = @fopen($config_file, "r");
if (!is_resource($fp)) {
$this->_trigger_error_msg("Could not open config file '$config_file'");
return;
return false;
}
$contents = fread($fp, filesize($config_file));
@@ -286,6 +286,8 @@ class Config_File {
}
$this->_config_data[$config_file] = $config_data;
return true;
}

View File

@@ -1234,8 +1234,25 @@ function _generate_debug_output() {
$this->_get_include_path($this->config_dir,$_config_dir);
}
$_file_path = $_config_dir . '/' . $file;
$_file_path = str_replace('//', '/' ,$_config_dir . '/' . $file);
// get path to compiled object file
$_compile_file = $this->_get_auto_filename($this->compile_dir, $file . $section, 'SMARTY_CONFIG');
// need to generate cache?
if($this->force_compile ||
($this->compile_check && ( @filemtime($_compile_file) != @filemtime($_file_path) ))) {
$_generate_cache = true;
} else {
include($_compile_file);
if(empty($_config_vars)) {
$_generate_cache = true;
} else {
$_generate_cache = false;
}
}
if($_generate_cache) {
if(!is_object($this->_conf_obj)) {
require_once SMARTY_DIR . $this->config_class . '.class.php';
$this->_conf_obj = new Config_File($_config_dir);
@@ -1243,22 +1260,13 @@ function _generate_debug_output() {
$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(!isset($this->_config[0]['files'][$file])) {
// get path to compiled object file
$_cache_file = $this->_get_auto_filename($this->cache_dir, $file, 'SMARTY_CONFIG');
// see if cache file is up to date
if(@filemtime($_cache_file) == @filemtime($_file_path)) {
// load cache file
$this->_conf_obj = unserialize($this->_read_file($_cache_file));
} else {
// load file and save cache
$this->_conf_obj->load_file($file);
$_conf_obj_file_contents = serialize($this->_conf_obj);
$this->_write_file($_cache_file, $_conf_obj_file_contents, true);
touch($_cache_file,filemtime($_file_path));
if($_config_vars = $this->_conf_obj->get($file, $section)) {
$this->_write_file($_compile_file,
'<?php $_config_vars = unserialize(\'' . str_replace('\'','\\\'', serialize($_config_vars)) . '\'); ?>',
true);
touch($_compile_file,filemtime($_file_path));
}
}
@@ -1270,34 +1278,18 @@ function _generate_debug_output() {
$this->_cache_info['config'][] = $file;
}
if (!isset($this->_config[0]['files'][$file])) {
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file));
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $_config_vars);
$this->_config[0]['files'][$file] = true;
}
if ($scope == 'parent') {
if (count($this->_config) > 0 && !isset($this->_config[1]['files'][$file])) {
$this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file));
$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++) {
if (!isset($this->_config[$i]['files'][$file])) {
$this->_config[$i]['vars'] = @array_merge($this->_config[$i]['vars'], $this->_conf_obj->get($file));
$this->_config[$i]['vars'] = @array_merge($this->_config[$i]['vars'], $_config_vars);
$this->_config[$i]['files'][$file] = true;
}
}
}
if (!empty($section)) {
$this->_config[0]['vars'] = @array_merge($this->_config[0]['vars'], $this->_conf_obj->get($file, $section));
if ($scope == 'parent') {
if (count($this->_config) > 0)
$this->_config[1]['vars'] = @array_merge($this->_config[1]['vars'], $this->_conf_obj->get($file, $section));
} 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'], $this->_conf_obj->get($file, $section));
}
if ($this->debugging) {
$debug_start_time = $this->_get_microtime();