9 * Smarty {config_load} function plugin
12 * Name: config_load<br>
13 * Purpose: load config file vars
14 * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}
15 * (Smarty online manual)
16 * @param array Format:
18 * array('file' => required config file name,
19 * 'section' => optional config file section to load
20 * 'scope' => local/parent/global
21 * 'global' => overrides scope, setting to parent if true)
25 function smarty_function_config_load($params, &$smarty)
27 if ($smarty->debugging
) {
29 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
30 $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
33 $_file = isset($params['file']) ?
$smarty->_dequote($params['file']) : null;
34 $_section = isset($params['section']) ?
$smarty->_dequote($params['section']) : null;
35 $_scope = isset($params['scope']) ?
$smarty->_dequote($params['scope']) : 'global';
36 $_global = isset($params['global']) ?
$smarty->_dequote($params['global']) : false;
38 if (!isset($_file) ||
strlen($_file) == 0) {
39 $smarty->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR
, __FILE__
, __LINE__
);
43 if ($_scope != 'local' &&
44 $_scope != 'parent' &&
45 $_scope != 'global') {
46 $smarty->_syntax_error("invalid 'scope' attribute value", E_USER_ERROR
, __FILE__
, __LINE__
);
56 if(@is_dir
($smarty->config_dir
)) {
57 $_config_dir = $smarty->config_dir
;
59 // config_dir not found, try include_path
60 $_params = array('file_path' => $smarty->config_dir
);
61 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_include_path.php');
62 smarty_core_get_include_path($_params, $smarty);
63 $_config_dir = $_params['new_file_path'];
66 $_file_path = $_config_dir . DIRECTORY_SEPARATOR
. $_file;
68 $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
70 $_compile_file = $smarty->_get_compile_path($_file_path);
72 if($smarty->force_compile
73 ||
!file_exists($_compile_file)
74 ||
($smarty->compile_check
75 && !$smarty->_is_compiled($_file_path, $_compile_file))) {
76 // compile config file
77 if(!is_object($smarty->_conf_obj
)) {
78 require_once SMARTY_DIR
. $smarty->config_class
. '.class.php';
79 $smarty->_conf_obj
= new $smarty->config_class($_config_dir);
80 $smarty->_conf_obj
->overwrite
= $smarty->config_overwrite
;
81 $smarty->_conf_obj
->booleanize
= $smarty->config_booleanize
;
82 $smarty->_conf_obj
->read_hidden
= $smarty->config_read_hidden
;
83 $smarty->_conf_obj
->fix_newlines
= $smarty->config_fix_newlines
;
84 $smarty->_conf_obj
->set_path
= $_config_dir;
86 $_config_vars = array_merge($smarty->_conf_obj
->get($_file),
87 $smarty->_conf_obj
->get($_file, $_section));
88 if(function_exists('var_export')) {
89 $_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
91 $_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
93 $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => filemtime($_file_path)));
94 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.write_compiled_resource.php');
95 smarty_core_write_compiled_resource($_params, $smarty);
97 include($_compile_file);
100 if ($smarty->caching
) {
101 $smarty->_cache_info
['config'][$_file] = true;
104 $smarty->_config
[0]['vars'] = @array_merge
($smarty->_config
[0]['vars'], $_config_vars);
105 $smarty->_config
[0]['files'][$_file] = true;
107 if ($_scope == 'parent') {
108 $smarty->_config
[1]['vars'] = @array_merge
($smarty->_config
[1]['vars'], $_config_vars);
109 $smarty->_config
[1]['files'][$_file] = true;
110 } else if ($_scope == 'global') {
111 for ($i = 1, $for_max = count($smarty->_config
); $i < $for_max; $i++
) {
112 $smarty->_config
[$i]['vars'] = @array_merge
($smarty->_config
[$i]['vars'], $_config_vars);
113 $smarty->_config
[$i]['files'][$_file] = true;
117 if ($smarty->debugging
) {
119 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.get_microtime.php');
120 $smarty->_smarty_debug_info
[] = array('type' => 'config',
121 'filename' => $_file.' ['.$_section.'] '.$_scope,
122 'depth' => $smarty->_inclusion_depth
,
123 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
128 /* vim: set expandtab: */
This page took 0.540534 seconds and 4 git commands to generate.