admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
| 10 | * @license http://www.codeignitor.com/user_guide/license.html |
| 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
| 15 | |
| 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter 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 |
| 26 | * @author Rick Ellis |
| 27 | * @link http://www.codeigniter.com/user_guide/libraries/config.html |
| 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 | */ |
| 41 | function CI_Config() |
| 42 | { |
| 43 | $this->config =& _get_config(); |
| 44 | log_message('debug', "Config Class Initialized"); |
| 45 | } |
| 46 | // END CI_Config() |
| 47 | |
| 48 | |
| 49 | // -------------------------------------------------------------------- |
| 50 | |
| 51 | /** |
| 52 | * Load Config File |
| 53 | * |
| 54 | * @access public |
| 55 | * @param string the config file name |
admin | 1082bdd | 2006-08-27 19:32:02 +0000 | [diff] [blame^] | 56 | * @return boolean if the file was loaded correctly |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 57 | */ |
| 58 | function load($file = '') |
| 59 | { |
| 60 | $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); |
| 61 | |
| 62 | if (in_array($file, $this->is_loaded)) |
| 63 | { |
admin | 1082bdd | 2006-08-27 19:32:02 +0000 | [diff] [blame^] | 64 | return TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | include_once(APPPATH.'config/'.$file.EXT); |
| 68 | |
| 69 | if ( ! isset($config) OR ! is_array($config)) |
| 70 | { |
| 71 | show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); |
| 72 | } |
| 73 | |
| 74 | $this->config = array_merge($this->config, $config); |
| 75 | |
| 76 | $this->is_loaded[] = $file; |
| 77 | unset($config); |
| 78 | |
| 79 | log_message('debug', 'Config file loaded: config/'.$file.EXT); |
admin | 1082bdd | 2006-08-27 19:32:02 +0000 | [diff] [blame^] | 80 | return TRUE; |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 81 | } |
| 82 | // END load() |
| 83 | |
| 84 | // -------------------------------------------------------------------- |
| 85 | |
| 86 | /** |
| 87 | * Fetch a config file item |
| 88 | * |
| 89 | * The second parameter allows a slash to be added to the end of |
| 90 | * the item, in the case of a path. |
| 91 | * |
| 92 | * @access public |
| 93 | * @param string the config item name |
| 94 | * @param bool |
| 95 | * @return string |
| 96 | */ |
| 97 | function item($item, $slash = FALSE) |
| 98 | { |
| 99 | if ( ! isset($this->config[$item])) |
| 100 | { |
| 101 | return FALSE; |
| 102 | } |
| 103 | |
| 104 | $pref = $this->config[$item]; |
| 105 | |
| 106 | if ($pref == '') |
| 107 | { |
| 108 | return $pref; |
| 109 | } |
| 110 | |
| 111 | if ($slash !== FALSE AND ereg("/$", $pref) === FALSE) |
| 112 | { |
| 113 | $pref .= '/'; |
| 114 | } |
| 115 | |
| 116 | return $pref; |
| 117 | } |
| 118 | // END item() |
| 119 | |
| 120 | // -------------------------------------------------------------------- |
| 121 | |
| 122 | /** |
| 123 | * Site URL |
| 124 | * |
| 125 | * @access public |
| 126 | * @param string the URI string |
| 127 | * @return string |
| 128 | */ |
| 129 | function site_url($uri = '') |
| 130 | { |
| 131 | if (is_array($uri)) |
| 132 | { |
| 133 | $uri = implode('/', $uri); |
| 134 | } |
| 135 | |
| 136 | if ($uri == '') |
| 137 | { |
| 138 | return $this->item('base_url', 1).$this->item('index_page'); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); |
| 143 | return $this->item('base_url', 1).$this->item('index_page', 1).preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix; |
| 144 | } |
| 145 | } |
| 146 | // END site_url() |
| 147 | |
| 148 | // -------------------------------------------------------------------- |
| 149 | |
| 150 | /** |
| 151 | * System URL |
| 152 | * |
| 153 | * @access public |
| 154 | * @return string |
| 155 | */ |
| 156 | function system_url() |
| 157 | { |
| 158 | $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH)); |
| 159 | return $this->item('base_url', 1).end($x).'/'; |
| 160 | } |
| 161 | // END system_url() |
| 162 | |
| 163 | // -------------------------------------------------------------------- |
| 164 | |
| 165 | /** |
| 166 | * Set a config file item |
| 167 | * |
| 168 | * @access public |
| 169 | * @param string the config item key |
| 170 | * @param string the config item value |
| 171 | * @return void |
| 172 | */ |
| 173 | function set_item($item, $value) |
| 174 | { |
| 175 | $this->config[$item] = $value; |
| 176 | } |
| 177 | // END set_item() |
| 178 | |
| 179 | } |
| 180 | |
| 181 | // END CI_Config class |
| 182 | ?> |