]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/Smarty/plugins/function.config_load.php
Release 6.5.0
[Github/sugarcrm.git] / include / Smarty / plugins / function.config_load.php
1 <?php
2
3 /*
4
5 Modification information for LGPL compliance
6
7 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
8
9 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
10
11 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
12
13 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
14
15 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
16
17 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
18
19 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
20
21 r10971 - 2006-01-12 14:58:30 -0800 (Thu, 12 Jan 2006) - chris - Bug 4128: updating Smarty templates to 2.6.11, a version supposedly that plays better with PHP 5.1
22
23 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
24
25
26 */
27
28
29 /**
30  * Smarty plugin
31  * @package Smarty
32  * @subpackage plugins
33  */
34
35 /**
36  * Smarty {config_load} function plugin
37  *
38  * Type:     function<br>
39  * Name:     config_load<br>
40  * Purpose:  load config file vars
41  * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}
42  *       (Smarty online manual)
43  * @author Monte Ohrt <monte at ohrt dot com>
44  * @author messju mohr <messju at lammfellpuschen dot de> (added use of resources)
45  * @param array Format:
46  * <pre>
47  * array('file' => required config file name,
48  *       'section' => optional config file section to load
49  *       'scope' => local/parent/global
50  *       'global' => overrides scope, setting to parent if true)
51  * </pre>
52  * @param Smarty
53  */
54 function smarty_function_config_load($params, &$smarty)
55 {
56         if ($smarty->debugging) {
57             $_params = array();
58             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
59             $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
60         }
61
62         $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
63         $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
64         $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
65         $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
66
67         if (!isset($_file) || strlen($_file) == 0) {
68             $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
69         }
70
71         if (isset($_scope)) {
72             if ($_scope != 'local' &&
73                 $_scope != 'parent' &&
74                 $_scope != 'global') {
75                 $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
76             }
77         } else {
78             if ($_global) {
79                 $_scope = 'parent';
80             } else {
81                 $_scope = 'local';
82             }
83         }
84
85         $_params = array('resource_name' => $_file,
86                          'resource_base_path' => $smarty->config_dir,
87                          'get_source' => false);
88         $smarty->_parse_resource_name($_params);
89         $_file_path = $_params['resource_type'] . ':' . $_params['resource_name'];
90         if (isset($_section))
91             $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
92         else
93             $_compile_file = $smarty->_get_compile_path($_file_path);
94
95         if($smarty->force_compile || !file_exists($_compile_file)) {
96             $_compile = true;
97         } elseif ($smarty->compile_check) {
98             $_params = array('resource_name' => $_file,
99                              'resource_base_path' => $smarty->config_dir,
100                              'get_source' => false);
101             $_compile = $smarty->_fetch_resource_info($_params) &&
102                 $_params['resource_timestamp'] > filemtime($_compile_file);
103         } else {
104             $_compile = false;
105         }
106
107         if($_compile) {
108             // compile config file
109             if(!is_object($smarty->_conf_obj)) {
110                 require_once SMARTY_DIR . $smarty->config_class . '.class.php';
111                 $smarty->_conf_obj = new $smarty->config_class();
112                 $smarty->_conf_obj->overwrite = $smarty->config_overwrite;
113                 $smarty->_conf_obj->booleanize = $smarty->config_booleanize;
114                 $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
115                 $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
116             }
117
118             $_params = array('resource_name' => $_file,
119                              'resource_base_path' => $smarty->config_dir,
120                              $_params['get_source'] = true);
121             if (!$smarty->_fetch_resource_info($_params)) {
122                 return;
123             }
124             $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
125             $_config_vars = array_merge($smarty->_conf_obj->get($_file),
126                     $smarty->_conf_obj->get($_file, $_section));
127             if(function_exists('var_export')) {
128                 $_output = '<?php
129
130 /*
131
132 Modification information for LGPL compliance
133
134 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
135
136 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
137
138 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
139
140 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
141
142 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
143
144 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
145
146 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
147
148 r10971 - 2006-01-12 14:58:30 -0800 (Thu, 12 Jan 2006) - chris - Bug 4128: updating Smarty templates to 2.6.11, a version supposedly that plays better with PHP 5.1
149
150 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
151
152
153 */
154
155  $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
156             } else {
157                 $_output = '<?php
158
159 /*
160
161 Modification information for LGPL compliance
162
163 r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync
164
165 r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover
166
167 r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex
168
169 r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3  tags and updated the build system 
170
171 r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development
172
173 r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372
174
175 r42807 - 2008-12-29 11:16:59 -0800 (Mon, 29 Dec 2008) - dwong - Branch from trunk/sugarcrm r42806 to branches/tokyo/sugarcrm
176
177 r10971 - 2006-01-12 14:58:30 -0800 (Thu, 12 Jan 2006) - chris - Bug 4128: updating Smarty templates to 2.6.11, a version supposedly that plays better with PHP 5.1
178
179 r8230 - 2005-10-03 17:47:19 -0700 (Mon, 03 Oct 2005) - majed - Added Sugar_Smarty to the code tree.
180
181
182 */
183
184  $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
185             }
186             $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp']));
187             require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
188             smarty_core_write_compiled_resource($_params, $smarty);
189         } else {
190             include($_compile_file);
191         }
192
193         if ($smarty->caching) {
194             $smarty->_cache_info['config'][$_file] = true;
195         }
196
197         $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);
198         $smarty->_config[0]['files'][$_file] = true;
199
200         if ($_scope == 'parent') {
201                 $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);
202                 $smarty->_config[1]['files'][$_file] = true;
203         } else if ($_scope == 'global') {
204             for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {
205                 $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);
206                 $smarty->_config[$i]['files'][$_file] = true;
207             }
208         }
209
210         if ($smarty->debugging) {
211             $_params = array();
212             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
213             $smarty->_smarty_debug_info[] = array('type'      => 'config',
214                                                 'filename'  => $_file.' ['.$_section.'] '.$_scope,
215                                                 'depth'     => $smarty->_inclusion_depth,
216                                                 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
217         }
218
219 }
220
221 /* vim: set expandtab: */
222
223 ?>