mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	fix config_load, compile fetched arrays to compile_dir, switch display
back to runtime. clean up var names and function names, split up compile testing and compiling to separate funcs, rename some template_* functions to file_* functions and update logic so they can be used for file resources other than templates.
This commit is contained in:
		@@ -26,13 +26,14 @@ function smarty_function_config_load($params, &$smarty)
 | 
			
		||||
{
 | 
			
		||||
        if ($smarty->debugging) {
 | 
			
		||||
			$_params = array();
 | 
			
		||||
            $_debug_start_time = $smarty->_execute_core_function('get_microtime', $_params);
 | 
			
		||||
            require_once(SMARTY_DIR . 'core/core.get_microtime.php');
 | 
			
		||||
            $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		$_file = isset($params['file']) ? $params['file'] : null;
 | 
			
		||||
		$_section = isset($params['section']) ? $params['section'] : null;
 | 
			
		||||
		$_scope = isset($params['scope']) ? $params['scope'] : 'global';
 | 
			
		||||
		$_global = isset($params['global']) ? $params['global'] : false;
 | 
			
		||||
		$_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
 | 
			
		||||
		$_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
 | 
			
		||||
		$_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
 | 
			
		||||
		$_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
 | 
			
		||||
 | 
			
		||||
        if (!isset($_file) || strlen($_file) == 0) {
 | 
			
		||||
            $smarty->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
 | 
			
		||||
@@ -51,28 +52,46 @@ function smarty_function_config_load($params, &$smarty)
 | 
			
		||||
                $_scope = 'local';
 | 
			
		||||
			}
 | 
			
		||||
        }		
 | 
			
		||||
 | 
			
		||||
			
 | 
			
		||||
        if(@is_dir($smarty->config_dir)) {
 | 
			
		||||
            $_config_dir = $smarty->config_dir;            
 | 
			
		||||
        } else {
 | 
			
		||||
            // config_dir not found, try include_path
 | 
			
		||||
			$_params = array('file_path' => $smarty->config_dir);
 | 
			
		||||
            $smarty->_execute_core_function('get_include_path', $_params);
 | 
			
		||||
			require_once(SMARTY_DIR . 'core/core.get_include_path.php');
 | 
			
		||||
            smarty_core_get_include_path($_params, $smarty);
 | 
			
		||||
			$_config_dir = $_params['new_file_path'];
 | 
			
		||||
        }		
 | 
			
		||||
		
 | 
			
		||||
        if(!is_object($smarty->_conf_obj)) {
 | 
			
		||||
            require_once SMARTY_DIR . $smarty->config_class . '.class.php';
 | 
			
		||||
            $smarty->_conf_obj = new $smarty->config_class($_config_dir);
 | 
			
		||||
            $smarty->_conf_obj->overwrite = $smarty->config_overwrite;
 | 
			
		||||
            $smarty->_conf_obj->booleanize = $smarty->config_booleanize;
 | 
			
		||||
            $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
 | 
			
		||||
            $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
 | 
			
		||||
            $smarty->_conf_obj->set_path = $_config_dir;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $_config_vars = array_merge($smarty->_conf_obj->get($_file),
 | 
			
		||||
                $smarty->_conf_obj->get($_file, $_section));
 | 
			
		||||
		$_compile_file = $smarty->_get_compile_path($_config_dir . '/' . $_file);
 | 
			
		||||
		
 | 
			
		||||
		if($smarty->force_compile
 | 
			
		||||
				|| !file_exists($_compile_file)
 | 
			
		||||
				|| ($smarty->compile_check
 | 
			
		||||
					&& $smarty->_file_needs_compiling($_config_dir . '/' . $_file, $_compile_file))) {
 | 
			
		||||
			// compile config file
 | 
			
		||||
        	if(!is_object($smarty->_conf_obj)) {
 | 
			
		||||
            	require_once SMARTY_DIR . $smarty->config_class . '.class.php';
 | 
			
		||||
            	$smarty->_conf_obj = new $smarty->config_class($_config_dir);
 | 
			
		||||
            	$smarty->_conf_obj->overwrite = $smarty->config_overwrite;
 | 
			
		||||
            	$smarty->_conf_obj->booleanize = $smarty->config_booleanize;
 | 
			
		||||
            	$smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
 | 
			
		||||
            	$smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
 | 
			
		||||
            	$smarty->_conf_obj->set_path = $_config_dir;
 | 
			
		||||
        	}
 | 
			
		||||
        	$_config_vars = array_merge($smarty->_conf_obj->get($_file),
 | 
			
		||||
                	$smarty->_conf_obj->get($_file, $_section));
 | 
			
		||||
			if(function_exists('var_export')) {
 | 
			
		||||
				$_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
 | 
			
		||||
			} else {
 | 
			
		||||
				$_output = '<?php $_config_vars = unserialize(' . serialize($_config_vars) . '); ?>';
 | 
			
		||||
			}
 | 
			
		||||
			$_params = (array('compile_path' => $_compile_file, 'template_compiled' => $_output));
 | 
			
		||||
			require_once(SMARTY_DIR . 'core/core.write_compiled_template.php');
 | 
			
		||||
			smarty_core_write_compiled_template($_params, $smarty);
 | 
			
		||||
		} else {
 | 
			
		||||
			include_once($_compile_file);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        if ($smarty->caching) {
 | 
			
		||||
            $smarty->_cache_info['config'][$_file] = true;
 | 
			
		||||
@@ -90,14 +109,16 @@ function smarty_function_config_load($params, &$smarty)
 | 
			
		||||
                    $smarty->_config[$i]['files'][$_file] = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
        if ($smarty->debugging) {
 | 
			
		||||
			$_params = array();
 | 
			
		||||
			require_once(SMARTY_DIR . 'core/core.get_microtime.php');
 | 
			
		||||
            $smarty->_smarty_debug_info[] = array('type'      => 'config',
 | 
			
		||||
                                                'filename'  => $_file.' ['.$_section.'] '.$_scope,
 | 
			
		||||
                                                'depth'     => $smarty->_inclusion_depth,
 | 
			
		||||
                                                'exec_time' => $smarty->_execute_core_function('get_microtime', $_params) - $_debug_start_time);
 | 
			
		||||
        }	
 | 
			
		||||
                                                'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
 | 
			
		||||
        }
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* vim: set expandtab: */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user