PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/PhpDocumentor/phpDocumentor/Smarty-2.6.0/libs/plugins/function.config_load.php

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