Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 29 | * Config Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 30 | * |
| 31 | * This class contains functions that enable config files to be managed |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/libraries/config.html |
| 38 | */ |
| 39 | class CI_Config { |
| 40 | |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 41 | /** |
| 42 | * List of all loaded config values |
| 43 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 44 | * @var array |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 45 | */ |
Eric Roberts | aa141a5 | 2012-07-04 02:13:56 -0500 | [diff] [blame] | 46 | public $config = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 47 | |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 48 | /** |
| 49 | * List of all loaded config files |
| 50 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 51 | * @var array |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 52 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 53 | public $is_loaded = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 54 | |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 55 | /** |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 56 | * List of paths to search when trying to load a config file. |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 57 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 58 | * @used-by CI_Loader Must be public |
| 59 | * @var array |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 60 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 61 | public $_config_paths = array(APPPATH); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 64 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 66 | * Sets the $config data from the primary config.php file as a class variable. |
| 67 | * |
| 68 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 70 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 72 | $this->config =& get_config(); |
Andrey Andreev | d52b242 | 2012-01-07 21:28:32 +0200 | [diff] [blame] | 73 | log_message('debug', 'Config Class Initialized'); |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 74 | |
| 75 | // Set the base_url automatically if none was provided |
Taufan Aditya | 8749bc7 | 2012-03-11 05:43:45 +0700 | [diff] [blame] | 76 | if (empty($this->config['base_url'])) |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 77 | { |
Pascal Kriete | 5d5895f | 2011-02-14 13:27:07 -0500 | [diff] [blame] | 78 | if (isset($_SERVER['HTTP_HOST'])) |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 79 | { |
Andrey Andreev | 3fb0267 | 2012-10-22 16:48:01 +0300 | [diff] [blame] | 80 | $base_url = is_https() ? 'https' : 'http'; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 81 | $base_url .= '://'.$_SERVER['HTTP_HOST'] |
| 82 | .str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 83 | } |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 84 | else |
| 85 | { |
| 86 | $base_url = 'http://localhost/'; |
| 87 | } |
| 88 | |
| 89 | $this->set_item('base_url', $base_url); |
| 90 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 92 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | // -------------------------------------------------------------------- |
| 94 | |
| 95 | /** |
| 96 | * Load Config File |
| 97 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 98 | * @param string $file Configuration file name |
| 99 | * @param bool $use_sections Whether configuration values should be loaded into their own section |
| 100 | * @param bool $fail_gracefully Whether to just return FALSE or display an error message |
| 101 | * @return bool TRUE if the file was loaded correctly or FALSE on failure |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 102 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 103 | public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | { |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 105 | $file = ($file === '') ? 'config' : str_replace('.php', '', $file); |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 106 | $found = $loaded = FALSE; |
Andrey Andreev | 9438e26 | 2012-10-05 13:16:27 +0300 | [diff] [blame] | 107 | |
Eric Roberts | d6ab7a2 | 2012-07-04 01:56:04 -0500 | [diff] [blame] | 108 | $check_locations = defined('ENVIRONMENT') |
| 109 | ? array(ENVIRONMENT.'/'.$file, $file) |
| 110 | : array($file); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Pascal Kriete | 5d5895f | 2011-02-14 13:27:07 -0500 | [diff] [blame] | 112 | foreach ($this->_config_paths as $path) |
Phil Sturgeon | 05fa611 | 2011-04-06 22:57:43 +0100 | [diff] [blame] | 113 | { |
Phil Sturgeon | 05fa611 | 2011-04-06 22:57:43 +0100 | [diff] [blame] | 114 | foreach ($check_locations as $location) |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 115 | { |
Andrey Andreev | d52b242 | 2012-01-07 21:28:32 +0200 | [diff] [blame] | 116 | $file_path = $path.'config/'.$location.'.php'; |
Phil Sturgeon | 05fa611 | 2011-04-06 22:57:43 +0100 | [diff] [blame] | 117 | |
| 118 | if (in_array($file_path, $this->is_loaded, TRUE)) |
| 119 | { |
| 120 | $loaded = TRUE; |
| 121 | continue 2; |
| 122 | } |
| 123 | |
| 124 | if (file_exists($file_path)) |
| 125 | { |
| 126 | $found = TRUE; |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | if ($found === FALSE) |
| 132 | { |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 133 | continue; |
| 134 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 136 | include($file_path); |
| 137 | |
| 138 | if ( ! isset($config) OR ! is_array($config)) |
| 139 | { |
| 140 | if ($fail_gracefully === TRUE) |
| 141 | { |
| 142 | return FALSE; |
| 143 | } |
| 144 | show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); |
| 145 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 146 | |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 147 | if ($use_sections === TRUE) |
| 148 | { |
| 149 | if (isset($this->config[$file])) |
| 150 | { |
| 151 | $this->config[$file] = array_merge($this->config[$file], $config); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | $this->config[$file] = $config; |
| 156 | } |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | $this->config = array_merge($this->config, $config); |
| 161 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 162 | |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 163 | $this->is_loaded[] = $file_path; |
| 164 | unset($config); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 165 | |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 166 | $loaded = TRUE; |
| 167 | log_message('debug', 'Config file loaded: '.$file_path); |
katzgrau | d127e61 | 2011-04-22 10:59:25 -0400 | [diff] [blame] | 168 | break; |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 169 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 170 | |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 171 | if ($loaded === FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 172 | { |
| 173 | if ($fail_gracefully === TRUE) |
| 174 | { |
| 175 | return FALSE; |
| 176 | } |
Eric Roberts | aa141a5 | 2012-07-04 02:13:56 -0500 | [diff] [blame] | 177 | show_error('The configuration file '.$file.'.php does not exist.'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | } |
Phil Sturgeon | 05fa611 | 2011-04-06 22:57:43 +0100 | [diff] [blame] | 179 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 180 | return TRUE; |
| 181 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | // -------------------------------------------------------------------- |
| 184 | |
| 185 | /** |
| 186 | * Fetch a config file item |
| 187 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 188 | * @param string $item Config item name |
| 189 | * @param string $index Index name |
| 190 | * @return string|bool The configuration item or FALSE on failure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 192 | public function item($item, $index = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | { |
Andrey Andreev | 9ba661b | 2012-06-04 14:44:34 +0300 | [diff] [blame] | 194 | if ($index == '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 195 | { |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 196 | return isset($this->config[$item]) ? $this->config[$item] : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 199 | return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 201 | |
| 202 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | |
| 204 | /** |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 205 | * Fetch a config file item with slash appended (if not empty) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 207 | * @param string $item Config item name |
| 208 | * @return string|bool The configuration item or FALSE on failure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 210 | public function slash_item($item) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | { |
| 212 | if ( ! isset($this->config[$item])) |
| 213 | { |
| 214 | return FALSE; |
| 215 | } |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 216 | elseif (trim($this->config[$item]) === '') |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 217 | { |
| 218 | return ''; |
| 219 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 221 | return rtrim($this->config[$item], '/').'/'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 222 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 223 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | // -------------------------------------------------------------------- |
| 225 | |
| 226 | /** |
| 227 | * Site URL |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 228 | * |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 229 | * Returns base_url . index_page [. uri_string] |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 230 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 231 | * @uses CI_Config::_uri_string() |
| 232 | * |
| 233 | * @param string|string[] $uri URI string or an array of segments |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | * @return string |
| 235 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 236 | public function site_url($uri = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 237 | { |
Andrey Andreev | 1764dd7 | 2012-06-16 18:48:19 +0300 | [diff] [blame] | 238 | if (empty($uri)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | { |
Phil Sturgeon | 4df8b22 | 2010-12-15 14:23:14 +0000 | [diff] [blame] | 240 | return $this->slash_item('base_url').$this->item('index_page'); |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 241 | } |
| 242 | |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 243 | $uri = $this->_uri_string($uri); |
| 244 | |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 245 | if ($this->item('enable_query_strings') === FALSE) |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 246 | { |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 247 | $suffix = ($this->item('url_suffix') === FALSE) ? '' : $this->item('url_suffix'); |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 248 | |
| 249 | if ($suffix !== '' && ($offset = strpos($uri, '?')) !== FALSE) |
| 250 | { |
| 251 | $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset); |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | $uri .= $suffix; |
| 256 | } |
| 257 | |
| 258 | return $this->slash_item('base_url').$this->slash_item('index_page').$uri; |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 259 | } |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 260 | elseif (strpos($uri, '?') === FALSE) |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 261 | { |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 262 | $uri = '?'.$uri; |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 263 | } |
Andrey Andreev | 1764dd7 | 2012-06-16 18:48:19 +0300 | [diff] [blame] | 264 | |
| 265 | return $this->slash_item('base_url').$this->item('index_page').$uri; |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 266 | } |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 267 | |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 268 | // ------------------------------------------------------------- |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 269 | |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 270 | /** |
| 271 | * Base URL |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 272 | * |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 273 | * Returns base_url [. uri_string] |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 274 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 275 | * @uses CI_Config::_uri_string() |
| 276 | * |
| 277 | * @param string|string[] $uri URI string or an array of segments |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 278 | * @return string |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 279 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 280 | public function base_url($uri = '') |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 281 | { |
Eric Roberts | aa141a5 | 2012-07-04 02:13:56 -0500 | [diff] [blame] | 282 | return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/'); |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 283 | } |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 284 | |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 285 | // ------------------------------------------------------------- |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 286 | |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 287 | /** |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 288 | * Build URI string |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 289 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 290 | * @used-by CI_Config::site_url() |
| 291 | * @used-by CI_Config::base_url() |
| 292 | * |
| 293 | * @param string|string[] $uri URI string or an array of segments |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 294 | * @return string |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 295 | */ |
| 296 | protected function _uri_string($uri) |
| 297 | { |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 298 | if ($this->item('enable_query_strings') === FALSE) |
anaxamaxan@blackdog.local | d09c51a | 2011-02-02 23:00:16 -0800 | [diff] [blame] | 299 | { |
Derek Jones | 6d743e2 | 2010-03-02 13:22:03 -0600 | [diff] [blame] | 300 | if (is_array($uri)) |
| 301 | { |
| 302 | $uri = implode('/', $uri); |
| 303 | } |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 304 | return trim($uri, '/'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | } |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 306 | elseif (is_array($uri)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | { |
Andrey Andreev | 1764dd7 | 2012-06-16 18:48:19 +0300 | [diff] [blame] | 308 | return http_build_query($uri); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | } |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 310 | |
Greg Aker | 03abee3 | 2011-12-25 00:31:29 -0600 | [diff] [blame] | 311 | return $uri; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 312 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 313 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 314 | // -------------------------------------------------------------------- |
David Behler | 2d2c9c6 | 2011-08-14 20:03:08 +0200 | [diff] [blame] | 315 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | /** |
| 317 | * System URL |
| 318 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | * @return string |
| 320 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 321 | public function system_url() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | { |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 323 | $x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 324 | return $this->slash_item('base_url').end($x).'/'; |
| 325 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 326 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | // -------------------------------------------------------------------- |
| 328 | |
| 329 | /** |
| 330 | * Set a config file item |
| 331 | * |
Andrey Andreev | 5232ba0 | 2012-10-27 15:25:05 +0300 | [diff] [blame^] | 332 | * @param string $item Config item key |
| 333 | * @param string $value Config item value |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 334 | * @return void |
| 335 | */ |
Andrey Andreev | ccabcfd | 2012-01-07 19:30:47 +0200 | [diff] [blame] | 336 | public function set_item($item, $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | { |
| 338 | $this->config[$item] = $value; |
| 339 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 340 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | } |
| 342 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | /* End of file Config.php */ |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 344 | /* Location: ./system/core/Config.php */ |