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