• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/function.config_load.php

00001 <?php
00025 function smarty_function_config_load($params, &$smarty)
00026 {
00027         if ($smarty->debugging) {
00028             $_params = array();
00029             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
00030             $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
00031         }
00032 
00033         $_file = isset($params['file']) ? $smarty->_dequote($params['file']) : null;
00034         $_section = isset($params['section']) ? $smarty->_dequote($params['section']) : null;
00035         $_scope = isset($params['scope']) ? $smarty->_dequote($params['scope']) : 'global';
00036         $_global = isset($params['global']) ? $smarty->_dequote($params['global']) : false;
00037 
00038         if (!isset($_file) || strlen($_file) == 0) {
00039             $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
00040         }
00041 
00042         if (isset($_scope)) {
00043             if ($_scope != 'local' &&
00044                 $_scope != 'parent' &&
00045                 $_scope != 'global') {
00046                 $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
00047             }
00048         } else {
00049             if ($_global) {
00050                 $_scope = 'parent';
00051             } else {
00052                 $_scope = 'local';
00053             }
00054         }
00055 
00056         $_params = array('resource_name' => $_file,
00057                          'resource_base_path' => $smarty->config_dir,
00058                          'get_source' => false);
00059         $smarty->_parse_resource_name($_params);
00060         $_file_path = $_params['resource_type'] . ':' . $_params['resource_name'];
00061         if (isset($_section))
00062             $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
00063         else
00064             $_compile_file = $smarty->_get_compile_path($_file_path);
00065 
00066         if($smarty->force_compile || !file_exists($_compile_file)) {
00067             $_compile = true;
00068         } elseif ($smarty->compile_check) {
00069             $_params = array('resource_name' => $_file,
00070                              'resource_base_path' => $smarty->config_dir,
00071                              'get_source' => false);
00072             $_compile = $smarty->_fetch_resource_info($_params) &&
00073                 $_params['resource_timestamp'] > filemtime($_compile_file);
00074         } else {
00075             $_compile = false;
00076         }
00077 
00078         if($_compile) {
00079             // compile config file
00080             if(!is_object($smarty->_conf_obj)) {
00081                 require_once SMARTY_DIR . $smarty->config_class . '.class.php';
00082                 $smarty->_conf_obj = new $smarty->config_class();
00083                 $smarty->_conf_obj->overwrite = $smarty->config_overwrite;
00084                 $smarty->_conf_obj->booleanize = $smarty->config_booleanize;
00085                 $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
00086                 $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
00087             }
00088 
00089             $_params = array('resource_name' => $_file,
00090                              'resource_base_path' => $smarty->config_dir,
00091                              $_params['get_source'] = true);
00092             if (!$smarty->_fetch_resource_info($_params)) {
00093                 return;
00094             }
00095             $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
00096             $_config_vars = array_merge($smarty->_conf_obj->get($_file),
00097                     $smarty->_conf_obj->get($_file, $_section));
00098             if(function_exists('var_export')) {
00099                 $_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
00100             } else {
00101                 $_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
00102             }
00103             $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp']));
00104             require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
00105             smarty_core_write_compiled_resource($_params, $smarty);
00106         } else {
00107             include($_compile_file);
00108         }
00109 
00110         if ($smarty->caching) {
00111             $smarty->_cache_info['config'][$_file] = true;
00112         }
00113 
00114         $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);
00115         $smarty->_config[0]['files'][$_file] = true;
00116 
00117         if ($_scope == 'parent') {
00118                 $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);
00119                 $smarty->_config[1]['files'][$_file] = true;
00120         } else if ($_scope == 'global') {
00121             for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {
00122                 $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);
00123                 $smarty->_config[$i]['files'][$_file] = true;
00124             }
00125         }
00126 
00127         if ($smarty->debugging) {
00128             $_params = array();
00129             require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
00130             $smarty->_smarty_debug_info[] = array('type'      => 'config',
00131                                                 'filename'  => $_file.' ['.$_section.'] '.$_scope,
00132                                                 'depth'     => $smarty->_inclusion_depth,
00133                                                 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
00134         }
00135 
00136 }
00137 
00138 /* vim: set expandtab: */
00139 
00140 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2