| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2003-04-20 21:18:26 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2003-04-20 21:18:26 +00:00
										 |  |  |  * @package Smarty | 
					
						
							|  |  |  |  * @subpackage plugins | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty {config_load} function plugin | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Type:     function<br> | 
					
						
							|  |  |  |  * Name:     config_load<br> | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |  * Purpose:  load config file vars | 
					
						
							| 
									
										
										
										
											2003-04-20 21:18:26 +00:00
										 |  |  |  * @link http://smarty.php.net/manual/en/language.function.config.load.php {config_load} | 
					
						
							|  |  |  |  *       (Smarty online manual) | 
					
						
							| 
									
										
										
										
											2005-10-11 16:22:56 +00:00
										 |  |  |  * @author Monte Ohrt <monte at ohrt dot com> | 
					
						
							| 
									
										
										
										
											2005-11-26 08:34:08 +00:00
										 |  |  |  * @author messju mohr <messju at lammfellpuschen dot de> (added use of resources) | 
					
						
							| 
									
										
										
										
											2003-04-20 21:18:26 +00:00
										 |  |  |  * @param array Format: | 
					
						
							|  |  |  |  * <pre> | 
					
						
							|  |  |  |  * array('file' => required config file name, | 
					
						
							|  |  |  |  *       'section' => optional config file section to load | 
					
						
							|  |  |  |  *       'scope' => local/parent/global | 
					
						
							|  |  |  |  *       'global' => overrides scope, setting to parent if true) | 
					
						
							|  |  |  |  * </pre> | 
					
						
							|  |  |  |  * @param Smarty | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | function smarty_function_config_load($params, &$smarty) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-04-21 14:22:46 +00:00
										 |  |  |         if ($smarty->debugging) { | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             $_params = array(); | 
					
						
							| 
									
										
										
										
											2004-09-16 23:07:32 +00:00
										 |  |  |             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | 
					
						
							| 
									
										
										
										
											2003-06-16 19:45:11 +00:00
										 |  |  |             $_debug_start_time = smarty_core_get_microtime($_params, $smarty); | 
					
						
							| 
									
										
										
										
											2003-04-21 14:22:46 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |         $_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; | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!isset($_file) || strlen($_file) == 0) { | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  |             $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (isset($_scope)) { | 
					
						
							|  |  |  |             if ($_scope != 'local' && | 
					
						
							|  |  |  |                 $_scope != 'parent' && | 
					
						
							|  |  |  |                 $_scope != 'global') { | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  |                 $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             if ($_global) { | 
					
						
							|  |  |  |                 $_scope = 'parent'; | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |                 $_scope = 'local'; | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-23 09:49:23 +00:00
										 |  |  |         $_params = array('resource_name' => $_file, | 
					
						
							|  |  |  |                          'resource_base_path' => $smarty->config_dir, | 
					
						
							|  |  |  |                          'get_source' => false); | 
					
						
							| 
									
										
										
										
											2004-01-21 17:21:26 +00:00
										 |  |  |         $smarty->_parse_resource_name($_params); | 
					
						
							|  |  |  |         $_file_path = $_params['resource_type'] . ':' . $_params['resource_name']; | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  |         if (isset($_section)) | 
					
						
							| 
									
										
										
										
											2003-08-14 10:59:30 +00:00
										 |  |  |             $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             $_compile_file = $smarty->_get_compile_path($_file_path); | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-23 09:49:23 +00:00
										 |  |  |         if($smarty->force_compile || !file_exists($_compile_file)) { | 
					
						
							|  |  |  |             $_compile = true; | 
					
						
							|  |  |  |         } elseif ($smarty->compile_check) { | 
					
						
							|  |  |  |             $_params = array('resource_name' => $_file, | 
					
						
							|  |  |  |                              'resource_base_path' => $smarty->config_dir, | 
					
						
							|  |  |  |                              'get_source' => false); | 
					
						
							|  |  |  |             $_compile = $smarty->_fetch_resource_info($_params) && | 
					
						
							|  |  |  |                 $_params['resource_timestamp'] > filemtime($_compile_file); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $_compile = false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if($_compile) { | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             // compile config file
 | 
					
						
							|  |  |  |             if(!is_object($smarty->_conf_obj)) { | 
					
						
							|  |  |  |                 require_once SMARTY_DIR . $smarty->config_class . '.class.php'; | 
					
						
							| 
									
										
										
										
											2004-01-21 17:21:26 +00:00
										 |  |  |                 $smarty->_conf_obj = new $smarty->config_class(); | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |                 $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; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2004-03-23 09:49:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $_params = array('resource_name' => $_file, | 
					
						
							|  |  |  |                              'resource_base_path' => $smarty->config_dir, | 
					
						
							|  |  |  |                              $_params['get_source'] = true); | 
					
						
							| 
									
										
										
										
											2004-01-22 23:54:51 +00:00
										 |  |  |             if (!$smarty->_fetch_resource_info($_params)) { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2004-01-21 17:21:26 +00:00
										 |  |  |             $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']); | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             $_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(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>'; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2004-01-21 17:21:26 +00:00
										 |  |  |             $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp'])); | 
					
						
							| 
									
										
										
										
											2004-09-16 23:07:32 +00:00
										 |  |  |             require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php'); | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             smarty_core_write_compiled_resource($_params, $smarty); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2003-08-14 10:59:30 +00:00
										 |  |  |             include($_compile_file); | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2003-06-11 21:52:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |         if ($smarty->caching) { | 
					
						
							| 
									
										
										
										
											2003-05-12 07:53:57 +00:00
										 |  |  |             $smarty->_cache_info['config'][$_file] = true; | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars); | 
					
						
							|  |  |  |         $smarty->_config[0]['files'][$_file] = true; | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |         if ($_scope == 'parent') { | 
					
						
							|  |  |  |                 $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars); | 
					
						
							|  |  |  |                 $smarty->_config[1]['files'][$_file] = true; | 
					
						
							|  |  |  |         } else if ($_scope == 'global') { | 
					
						
							|  |  |  |             for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) { | 
					
						
							| 
									
										
										
										
											2003-11-29 01:44:41 +00:00
										 |  |  |                 $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars); | 
					
						
							|  |  |  |                 $smarty->_config[$i]['files'][$_file] = true; | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |         if ($smarty->debugging) { | 
					
						
							| 
									
										
										
										
											2003-11-29 02:15:41 +00:00
										 |  |  |             $_params = array(); | 
					
						
							| 
									
										
										
										
											2004-09-16 23:07:32 +00:00
										 |  |  |             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |             $smarty->_smarty_debug_info[] = array('type'      => 'config', | 
					
						
							| 
									
										
										
										
											2003-04-20 21:07:54 +00:00
										 |  |  |                                                 'filename'  => $_file.' ['.$_section.'] '.$_scope, | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  |                                                 'depth'     => $smarty->_inclusion_depth, | 
					
						
							| 
									
										
										
										
											2003-06-16 19:45:11 +00:00
										 |  |  |                                                 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2003-11-29 00:49:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-20 18:08:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* vim: set expandtab: */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ?>
 |