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