d9d65b954e4604c0e936a9579398b654ac1c9ad0
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / plugins / function.config_load.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * Smarty {config_load} function plugin\r
10  *\r
11  * Type:     function<br>\r
12  * Name:     config_load<br>\r
13  * Purpose:  load config file vars\r
14  * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load}\r
15  *       (Smarty online manual)\r
16  * @param array Format:\r
17  * <pre>\r
18  * array('file' => required config file name,\r
19  *       'section' => optional config file section to load\r
20  *       'scope' => local/parent/global\r
21  *       'global' => overrides scope, setting to parent if true)\r
22  * </pre>\r
23  * @param Smarty\r
24  */\r
25 function smarty_function_config_load($params, &$smarty)\r
26 {\r
27         if ($smarty->debugging) {\r
28                         $_params = array();\r
29             require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
30             $_debug_start_time = smarty_core_get_microtime($_params, $smarty);\r
31         }\r
32 \r
33                 $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;\r
34                 $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;\r
35                 $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';\r
36                 $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;\r
37 \r
38         if (!isset($_file) || strlen($_file) == 0) {\r
39             $smarty->_syntax_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);\r
40         }\r
41 \r
42         if (isset($_scope)) {\r
43             if ($_scope != 'local' &&\r
44                 $_scope != 'parent' &&\r
45                 $_scope != 'global') {\r
46                 $smarty->_syntax_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);\r
47             }\r
48         } else {\r
49             if ($_global) {\r
50                 $_scope = 'parent';\r
51                         } else {\r
52                 $_scope = 'local';\r
53                         }\r
54         }               \r
55                         \r
56         if(@is_dir($smarty->config_dir)) {\r
57             $_config_dir = $smarty->config_dir;            \r
58         } else {\r
59             // config_dir not found, try include_path\r
60                         $_params = array('file_path' => $smarty->config_dir);\r
61                         require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_include_path.php');\r
62             smarty_core_get_include_path($_params, $smarty);\r
63                         $_config_dir = $_params['new_file_path'];\r
64         }\r
65 \r
66                 $_file_path = $_config_dir . DIRECTORY_SEPARATOR . $_file;\r
67         if (isset($_section)) \r
68             $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);\r
69         else\r
70             $_compile_file = $smarty->_get_compile_path($_file_path);\r
71                 \r
72                 if($smarty->force_compile\r
73                                 || !file_exists($_compile_file)\r
74                                 || ($smarty->compile_check\r
75                                         && !$smarty->_is_compiled($_file_path, $_compile_file))) {\r
76                         // compile config file\r
77                 if(!is_object($smarty->_conf_obj)) {\r
78                 require_once SMARTY_DIR . $smarty->config_class . '.class.php';\r
79                 $smarty->_conf_obj = new $smarty->config_class($_config_dir);\r
80                 $smarty->_conf_obj->overwrite = $smarty->config_overwrite;\r
81                 $smarty->_conf_obj->booleanize = $smarty->config_booleanize;\r
82                 $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;\r
83                 $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;\r
84                 $smarty->_conf_obj->set_path = $_config_dir;\r
85                 }\r
86                 $_config_vars = array_merge($smarty->_conf_obj->get($_file),\r
87                         $smarty->_conf_obj->get($_file, $_section));\r
88                         if(function_exists('var_export')) {\r
89                                 $_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';\r
90                         } else {\r
91                                 $_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';\r
92                         }\r
93                         $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => filemtime($_file_path)));\r
94                         require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_compiled_resource.php');\r
95                         smarty_core_write_compiled_resource($_params, $smarty);\r
96                 } else {\r
97             include($_compile_file);\r
98                 }\r
99 \r
100         if ($smarty->caching) {\r
101             $smarty->_cache_info['config'][$_file] = true;\r
102         }\r
103 \r
104         $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);\r
105         $smarty->_config[0]['files'][$_file] = true;\r
106         \r
107         if ($_scope == 'parent') {\r
108                 $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);\r
109                 $smarty->_config[1]['files'][$_file] = true;\r
110         } else if ($_scope == 'global') {\r
111             for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {\r
112                     $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);\r
113                     $smarty->_config[$i]['files'][$_file] = true;\r
114             }\r
115         }\r
116                 \r
117         if ($smarty->debugging) {\r
118                         $_params = array();\r
119                         require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php');\r
120             $smarty->_smarty_debug_info[] = array('type'      => 'config',\r
121                                                 'filename'  => $_file.' ['.$_section.'] '.$_scope,\r
122                                                 'depth'     => $smarty->_inclusion_depth,\r
123                                                 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);\r
124         }\r
125         \r
126 }\r
127 \r
128 /* vim: set expandtab: */\r
129 \r
130 ?>\r