Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * CodeIgniter Config Class
|
| 20 | *
|
| 21 | * This class contains functions that enable config files to be managed
|
| 22 | *
|
| 23 | * @package CodeIgniter
|
| 24 | * @subpackage Libraries
|
| 25 | * @category Libraries
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 26 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 27 | * @link http://codeigniter.com/user_guide/libraries/config.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 28 | */
|
| 29 | class CI_Config {
|
| 30 |
|
| 31 | var $config = array();
|
| 32 | var $is_loaded = array();
|
| 33 |
|
| 34 | /**
|
| 35 | * Constructor
|
| 36 | *
|
| 37 | * Sets the $config data from the primary config.php file as a class variable
|
| 38 | *
|
| 39 | * @access public
|
| 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
|
| 44 | */
|
| 45 | function CI_Config()
|
| 46 | {
|
| 47 | $this->config =& get_config();
|
| 48 | log_message('debug', "Config Class Initialized");
|
| 49 | }
|
| 50 |
|
| 51 | // --------------------------------------------------------------------
|
| 52 |
|
| 53 | /**
|
| 54 | * Load Config File
|
| 55 | *
|
| 56 | * @access public
|
| 57 | * @param string the config file name
|
| 58 | * @return boolean if the file was loaded correctly
|
| 59 | */
|
| 60 | function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
|
| 61 | {
|
| 62 | $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
|
| 63 |
|
| 64 | if (in_array($file, $this->is_loaded, TRUE))
|
| 65 | {
|
| 66 | return TRUE;
|
| 67 | }
|
| 68 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 69 | if ( ! file_exists(APPPATH.'config/'.$file.EXT))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 70 | {
|
| 71 | if ($fail_gracefully === TRUE)
|
| 72 | {
|
| 73 | return FALSE;
|
| 74 | }
|
| 75 | show_error('The configuration file '.$file.EXT.' does not exist.');
|
| 76 | }
|
| 77 |
|
| 78 | include(APPPATH.'config/'.$file.EXT);
|
| 79 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 80 | if ( ! isset($config) OR ! is_array($config))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 81 | {
|
| 82 | if ($fail_gracefully === TRUE)
|
| 83 | {
|
| 84 | return FALSE;
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 85 | }
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 86 | show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.');
|
| 87 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 88 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 89 | if ($use_sections === TRUE)
|
| 90 | {
|
| 91 | if (isset($this->config[$file]))
|
| 92 | {
|
| 93 | $this->config[$file] = array_merge($this->config[$file], $config);
|
| 94 | }
|
| 95 | else
|
| 96 | {
|
| 97 | $this->config[$file] = $config;
|
| 98 | }
|
| 99 | }
|
| 100 | else
|
| 101 | {
|
| 102 | $this->config = array_merge($this->config, $config);
|
| 103 | }
|
| 104 |
|
| 105 | $this->is_loaded[] = $file;
|
| 106 | unset($config);
|
| 107 |
|
| 108 | log_message('debug', 'Config file loaded: config/'.$file.EXT);
|
| 109 | return TRUE;
|
| 110 | }
|
| 111 |
|
| 112 | // --------------------------------------------------------------------
|
| 113 |
|
| 114 | /**
|
| 115 | * Fetch a config file item
|
| 116 | *
|
| 117 | *
|
| 118 | * @access public
|
| 119 | * @param string the config item name
|
| 120 | * @param string the index name
|
| 121 | * @param bool
|
| 122 | * @return string
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 123 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 124 | function item($item, $index = '')
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 125 | {
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 126 | if ($index == '')
|
| 127 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 128 | if ( ! isset($this->config[$item]))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 129 | {
|
| 130 | return FALSE;
|
| 131 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 132 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 133 | $pref = $this->config[$item];
|
| 134 | }
|
| 135 | else
|
| 136 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 137 | if ( ! isset($this->config[$index]))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 138 | {
|
| 139 | return FALSE;
|
| 140 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 141 |
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 142 | if ( ! isset($this->config[$index][$item]))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 143 | {
|
| 144 | return FALSE;
|
| 145 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 146 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 147 | $pref = $this->config[$index][$item];
|
| 148 | }
|
| 149 |
|
| 150 | return $pref;
|
| 151 | }
|
| 152 |
|
| 153 | // --------------------------------------------------------------------
|
| 154 |
|
| 155 | /**
|
| 156 | * Fetch a config file item - adds slash after item
|
| 157 | *
|
| 158 | * The second parameter allows a slash to be added to the end of
|
| 159 | * the item, in the case of a path.
|
| 160 | *
|
| 161 | * @access public
|
| 162 | * @param string the config item name
|
| 163 | * @param bool
|
| 164 | * @return string
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 165 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 166 | function slash_item($item)
|
| 167 | {
|
Derek Jones | 0b59f27 | 2008-05-13 04:22:33 +0000 | [diff] [blame^] | 168 | if ( ! isset($this->config[$item]))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 169 | {
|
| 170 | return FALSE;
|
| 171 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 172 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 173 | $pref = $this->config[$item];
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 174 |
|
Derek Allard | 15dcf49 | 2008-05-12 21:37:04 +0000 | [diff] [blame] | 175 | if ($pref != '' && substr($pref, -1) != '/')
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 176 | {
|
Derek Allard | 15dcf49 | 2008-05-12 21:37:04 +0000 | [diff] [blame] | 177 | $pref .= '/';
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 178 | }
|
| 179 |
|
| 180 | return $pref;
|
| 181 | }
|
| 182 |
|
| 183 | // --------------------------------------------------------------------
|
| 184 |
|
| 185 | /**
|
| 186 | * Site URL
|
| 187 | *
|
| 188 | * @access public
|
| 189 | * @param string the URI string
|
| 190 | * @return string
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 191 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 192 | function site_url($uri = '')
|
| 193 | {
|
| 194 | if (is_array($uri))
|
| 195 | {
|
| 196 | $uri = implode('/', $uri);
|
| 197 | }
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 198 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 199 | if ($uri == '')
|
| 200 | {
|
| 201 | return $this->slash_item('base_url').$this->item('index_page');
|
| 202 | }
|
| 203 | else
|
| 204 | {
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 205 | $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 206 | return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
|
| 207 | }
|
| 208 | }
|
| 209 |
|
| 210 | // --------------------------------------------------------------------
|
| 211 |
|
| 212 | /**
|
| 213 | * System URL
|
| 214 | *
|
| 215 | * @access public
|
| 216 | * @return string
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 217 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 218 | function system_url()
|
| 219 | {
|
| 220 | $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
|
| 221 | return $this->slash_item('base_url').end($x).'/';
|
| 222 | }
|
| 223 |
|
| 224 | // --------------------------------------------------------------------
|
| 225 |
|
| 226 | /**
|
| 227 | * Set a config file item
|
| 228 | *
|
| 229 | * @access public
|
| 230 | * @param string the config item key
|
| 231 | * @param string the config item value
|
| 232 | * @return void
|
Derek Allard | 0fd8f02 | 2008-05-13 02:01:47 +0000 | [diff] [blame] | 233 | */
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 234 | function set_item($item, $value)
|
| 235 | {
|
| 236 | $this->config[$item] = $value;
|
| 237 | }
|
| 238 |
|
| 239 | }
|
| 240 |
|
| 241 | // END CI_Config class
|
Derek Allard | 15dcf49 | 2008-05-12 21:37:04 +0000 | [diff] [blame] | 242 |
|
| 243 | /* End of file Config.php */
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 244 | /* Location: ./system/libraries/Config.php */ |