[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/smarty/plugins/ -> function.config_load.php (source)

   1  <?php
   2  /**

   3   * Smarty plugin

   4   * @package Smarty

   5   * @subpackage plugins

   6   */
   7  
   8  /**

   9   * Smarty {config_load} function plugin

  10   *

  11   * Type:     function<br>

  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:

  17   * <pre>

  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)

  22   * </pre>

  23   * @param Smarty

  24   */
  25  function smarty_function_config_load($params, &$smarty)
  26  {
  27          if ($smarty->debugging) {
  28              $_params = array();
  29              require_once (SMARTY_CORE_DIR . 'core.get_microtime.php');
  30              $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
  31          }
  32  
  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;
  37  
  38          if (!isset($_file) || strlen($_file) == 0) {
  39              $smarty->trigger_error("missing 'file' attribute in config_load tag", E_USER_ERROR, __FILE__, __LINE__);
  40          }
  41  
  42          if (isset($_scope)) {
  43              if ($_scope != 'local' &&
  44                  $_scope != 'parent' &&
  45                  $_scope != 'global') {
  46                  $smarty->trigger_error("invalid 'scope' attribute value", E_USER_ERROR, __FILE__, __LINE__);
  47              }
  48          } else {
  49              if ($_global) {
  50                  $_scope = 'parent';
  51              } else {
  52                  $_scope = 'local';
  53              }
  54          }
  55  
  56          $_params = array('resource_name' => $_file,
  57                           'resource_base_path' => $smarty->config_dir,
  58                           'get_source' => false);
  59          $smarty->_parse_resource_name($_params);
  60          $_file_path = $_params['resource_type'] . ':' . $_params['resource_name'];
  61          if (isset($_section))
  62              $_compile_file = $smarty->_get_compile_path($_file_path.'|'.$_section);
  63          else
  64              $_compile_file = $smarty->_get_compile_path($_file_path);
  65  
  66          if($smarty->force_compile || !file_exists($_compile_file)) {
  67              $_compile = true;
  68          } elseif ($smarty->compile_check) {
  69              $_params = array('resource_name' => $_file,
  70                               'resource_base_path' => $smarty->config_dir,
  71                               'get_source' => false);
  72              $_compile = $smarty->_fetch_resource_info($_params) &&
  73                  $_params['resource_timestamp'] > filemtime($_compile_file);
  74          } else {
  75              $_compile = false;
  76          }
  77  
  78          if($_compile) {
  79              // compile config file

  80              if(!is_object($smarty->_conf_obj)) {
  81                  require_once SMARTY_DIR . $smarty->config_class . '.class.php';
  82                  $smarty->_conf_obj = new $smarty->config_class();
  83                  $smarty->_conf_obj->overwrite = $smarty->config_overwrite;
  84                  $smarty->_conf_obj->booleanize = $smarty->config_booleanize;
  85                  $smarty->_conf_obj->read_hidden = $smarty->config_read_hidden;
  86                  $smarty->_conf_obj->fix_newlines = $smarty->config_fix_newlines;
  87              }
  88  
  89              $_params = array('resource_name' => $_file,
  90                               'resource_base_path' => $smarty->config_dir,
  91                               $_params['get_source'] = true);
  92              if (!$smarty->_fetch_resource_info($_params)) {
  93                  return;
  94              }
  95              $smarty->_conf_obj->set_file_contents($_file, $_params['source_content']);
  96              $_config_vars = array_merge($smarty->_conf_obj->get($_file),
  97                      $smarty->_conf_obj->get($_file, $_section));
  98              if(function_exists('var_export')) {
  99                  $_output = '<?php $_config_vars = ' . var_export($_config_vars, true) . '; ?>';
 100              } else {
 101                  $_output = '<?php $_config_vars = unserialize(\'' . strtr(serialize($_config_vars),array('\''=>'\\\'', '\\'=>'\\\\')) . '\'); ?>';
 102              }
 103              $_params = (array('compile_path' => $_compile_file, 'compiled_content' => $_output, 'resource_timestamp' => $_params['resource_timestamp']));
 104              require_once(SMARTY_CORE_DIR . 'core.write_compiled_resource.php');
 105              smarty_core_write_compiled_resource($_params, $smarty);
 106          } else {
 107              include($_compile_file);
 108          }
 109  
 110          if ($smarty->caching) {
 111              $smarty->_cache_info['config'][$_file] = true;
 112          }
 113  
 114          $smarty->_config[0]['vars'] = @array_merge($smarty->_config[0]['vars'], $_config_vars);
 115          $smarty->_config[0]['files'][$_file] = true;
 116  
 117          if ($_scope == 'parent') {
 118                  $smarty->_config[1]['vars'] = @array_merge($smarty->_config[1]['vars'], $_config_vars);
 119                  $smarty->_config[1]['files'][$_file] = true;
 120          } else if ($_scope == 'global') {
 121              for ($i = 1, $for_max = count($smarty->_config); $i < $for_max; $i++) {
 122                  $smarty->_config[$i]['vars'] = @array_merge($smarty->_config[$i]['vars'], $_config_vars);
 123                  $smarty->_config[$i]['files'][$_file] = true;
 124              }
 125          }
 126  
 127          if ($smarty->debugging) {
 128              $_params = array();
 129              require_once (SMARTY_CORE_DIR . 'core.get_microtime.php');
 130              $smarty->_smarty_debug_info[] = array('type'      => 'config',
 131                                                  'filename'  => $_file.' ['.$_section.'] '.$_scope,
 132                                                  'depth'     => $smarty->_inclusion_depth,
 133                                                  'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
 134          }
 135  
 136  }
 137  
 138  /* vim: set expandtab: */

 139  
 140  ?>


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics