template.config_loader.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Template Lite config_load template internal module
  4. *
  5. * Type: template
  6. * Name: config_load
  7. */
  8. $this->_config_module_loaded = true;
  9. $this->template_dir = $this->_get_dir($this->template_dir);
  10. $this->config_dir = $this->_get_dir($this->config_dir);
  11. $this->compile_dir = $this->_get_dir($this->compile_dir);
  12. $name = ($this->encode_file_name) ? md5($this->template_dir . $file . $section_name . $var_name).'.php' : str_replace(".", "_", str_replace("/", "_", $file."_".$section_name."_".$var_name)).'.php';
  13. if ($this->debugging)
  14. {
  15. $debug_start_time = array_sum(explode(' ', microtime()));
  16. }
  17. if ($this->cache)
  18. {
  19. array_push($this->_cache_info['config'], $file);
  20. }
  21. if (!$this->force_compile && file_exists($this->compile_dir.'c_'.$name) && (filemtime($this->compile_dir.'c_'.$name) > filemtime($this->config_dir.$file)))
  22. {
  23. include($this->compile_dir.'c_'.$name);
  24. return true;
  25. }
  26. if (!is_object($this->_config_obj))
  27. {
  28. require_once(TEMPLATE_LITE_DIR . "class.config.php");
  29. $this->_config_obj = new $this->config_class;
  30. $this->_config_obj->overwrite = $this->config_overwrite;
  31. $this->_config_obj->booleanize = $this->config_booleanize;
  32. $this->_config_obj->fix_new_lines = $this->config_fix_new_lines;
  33. $this->_config_obj->read_hidden = $this->config_read_hidden;
  34. }
  35. if (!($_result = $this->_config_obj->config_load($this->config_dir.$file, $section_name, $var_name)))
  36. {
  37. return false;
  38. }
  39. if (!empty($var_name) || !empty($section_name))
  40. {
  41. $output = "\$this->_confs = " . var_export($_result, true) . ";";
  42. }
  43. else
  44. {
  45. // must shift of the bottom level of the array to get rid of the section labels
  46. $_temp = array();
  47. foreach($_result as $value)
  48. {
  49. $_temp = array_merge($_temp, $value);
  50. }
  51. $output = "\$this->_confs = " . var_export($_temp, true) . ";";
  52. }
  53. $f = fopen($this->compile_dir.'c_'.$name, "w");
  54. fwrite($f, '<?php ' . $output . ' ?>');
  55. fclose($f);
  56. eval($output);
  57. if ($this->debugging)
  58. {
  59. $this->_templatelite_debug_info[] = array('type' => 'config',
  60. 'filename' => $file.' ['.$section_name.'] '.$var_name,
  61. 'depth' => 0,
  62. 'exec_time' => array_sum(explode(' ', microtime())) - $debug_start_time );
  63. }
  64. return true;
  65. ?>