1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Config Class
21 * This class contains functions that enable config files to be managed
23 * @package CodeIgniter
24 * @subpackage Libraries
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/libraries/config.html
31 var $config = array();
32 var $is_loaded = array();
37 * Sets the $config data from the primary config.php file as a class variable
40 * @param string the config file name
41 * @param boolean if configuration values should be loaded into their own section
42 * @param boolean true if errors should just return false, false if an error message should be displayed
43 * @return boolean if the file was successfully loaded or not
47 $this->config =& get_config();
48 log_message('debug', "Config Class Initialized");
51 // --------------------------------------------------------------------
57 * @param string the config file name
58 * @return boolean if the file was loaded correctly
60 function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
62 $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
64 if (in_array($file, $this->is_loaded, TRUE))
69 if ( ! file_exists(APPPATH.'config/'.$file.EXT))
71 if ($fail_gracefully === TRUE)
75 show_error('The configuration file '.$file.EXT.' does not exist.');
78 include(APPPATH.'config/'.$file.EXT);
80 if ( ! isset($config) OR ! is_array($config))
82 if ($fail_gracefully === TRUE)
86 show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.');
89 if ($use_sections === TRUE)
91 if (isset($this->config[$file]))
93 $this->config[$file] = array_merge($this->config[$file], $config);
97 $this->config[$file] = $config;
102 $this->config = array_merge($this->config, $config);
105 $this->is_loaded[] = $file;
108 log_message('debug', 'Config file loaded: config/'.$file.EXT);
112 // --------------------------------------------------------------------
115 * Fetch a config file item
119 * @param string the config item name
120 * @param string the index name
124 function item($item, $index = '')
128 if ( ! isset($this->config[$item]))
133 $pref = $this->config[$item];
137 if ( ! isset($this->config[$index]))
142 if ( ! isset($this->config[$index][$item]))
147 $pref = $this->config[$index][$item];
153 // --------------------------------------------------------------------
156 * Fetch a config file item - adds slash after item
158 * The second parameter allows a slash to be added to the end of
159 * the item, in the case of a path.
162 * @param string the config item name
166 function slash_item($item)
168 if ( ! isset($this->config[$item]))
173 $pref = $this->config[$item];
175 if ($pref != '' && substr($pref, -1) != '/')
183 // --------------------------------------------------------------------
189 * @param string the URI string
192 function site_url($uri = '')
196 $uri = implode('/', $uri);
201 return $this->slash_item('base_url').$this->item('index_page');
205 $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
206 return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
210 // --------------------------------------------------------------------
218 function system_url()
220 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
221 return $this->slash_item('base_url').end($x).'/';
224 // --------------------------------------------------------------------
227 * Set a config file item
230 * @param string the config item key
231 * @param string the config item value
234 function set_item($item, $value)
236 $this->config[$item] = $value;
241 // END CI_Config class
243 /* End of file Config.php */
244 /* Location: ./system/libraries/Config.php */