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 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 36 | * @filesource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * URI Class |
| 42 | * |
| 43 | * Parses URIs and determines routing |
| 44 | * |
| 45 | * @package CodeIgniter |
| 46 | * @subpackage Libraries |
| 47 | * @category URI |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 48 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 49 | * @link https://codeigniter.com/user_guide/libraries/uri.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 50 | */ |
| 51 | class CI_URI { |
| 52 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 53 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 54 | * List of cached URI segments |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 55 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 56 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 57 | */ |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 58 | public $keyval = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 59 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 60 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 61 | * Current URI string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 62 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 63 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 64 | */ |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 65 | public $uri_string = ''; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 66 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 67 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 68 | * List of URI segments |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 69 | * |
vlakoff | e196050 | 2014-05-01 08:53:34 +0200 | [diff] [blame] | 70 | * Starts at 1 instead of 0. |
| 71 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 72 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 73 | */ |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 74 | public $segments = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 75 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 76 | /** |
vlakoff | e196050 | 2014-05-01 08:53:34 +0200 | [diff] [blame] | 77 | * List of routed URI segments |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 78 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 79 | * Starts at 1 instead of 0. |
| 80 | * |
| 81 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 82 | */ |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 83 | public $rsegments = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | |
| 85 | /** |
Andrey Andreev | de14aa5 | 2014-01-15 15:51:08 +0200 | [diff] [blame] | 86 | * Permitted URI chars |
| 87 | * |
| 88 | * PCRE character group allowed in URI segments |
| 89 | * |
| 90 | * @var string |
| 91 | */ |
| 92 | protected $_permitted_uri_chars; |
| 93 | |
| 94 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 95 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 97 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 99 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | { |
Derek Jones | 7576a3b | 2010-03-02 14:00:36 -0600 | [diff] [blame] | 101 | $this->config =& load_class('Config', 'core'); |
Andrey Andreev | de14aa5 | 2014-01-15 15:51:08 +0200 | [diff] [blame] | 102 | |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 103 | // If query strings are enabled, we don't need to parse any segments. |
| 104 | // However, they don't make sense under CLI. |
| 105 | if (is_cli() OR $this->config->item('enable_query_strings') !== TRUE) |
Andrey Andreev | de14aa5 | 2014-01-15 15:51:08 +0200 | [diff] [blame] | 106 | { |
| 107 | $this->_permitted_uri_chars = $this->config->item('permitted_uri_chars'); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 108 | |
| 109 | // If it's a CLI request, ignore the configuration |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 110 | if (is_cli()) |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 111 | { |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 112 | $uri = $this->_parse_argv(); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 113 | } |
| 114 | else |
| 115 | { |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 116 | $protocol = $this->config->item('uri_protocol'); |
| 117 | empty($protocol) && $protocol = 'REQUEST_URI'; |
| 118 | |
| 119 | switch ($protocol) |
| 120 | { |
| 121 | case 'AUTO': // For BC purposes only |
| 122 | case 'REQUEST_URI': |
| 123 | $uri = $this->_parse_request_uri(); |
| 124 | break; |
| 125 | case 'QUERY_STRING': |
| 126 | $uri = $this->_parse_query_string(); |
| 127 | break; |
| 128 | case 'PATH_INFO': |
| 129 | default: |
| 130 | $uri = isset($_SERVER[$protocol]) |
| 131 | ? $_SERVER[$protocol] |
| 132 | : $this->_parse_request_uri(); |
| 133 | break; |
| 134 | } |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 135 | } |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 136 | |
| 137 | $this->_set_uri_string($uri); |
Andrey Andreev | de14aa5 | 2014-01-15 15:51:08 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 140 | log_message('info', 'URI Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | // -------------------------------------------------------------------- |
| 144 | |
| 145 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 146 | * Set URI String |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 147 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 148 | * @param string $str |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 149 | * @return void |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 150 | */ |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 151 | protected function _set_uri_string($str) |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 152 | { |
Andrey Andreev | f5f898f | 2012-10-23 02:13:29 +0300 | [diff] [blame] | 153 | // Filter out control characters and trim slashes |
| 154 | $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 155 | |
| 156 | if ($this->uri_string !== '') |
| 157 | { |
| 158 | // Remove the URL suffix, if present |
| 159 | if (($suffix = (string) $this->config->item('url_suffix')) !== '') |
| 160 | { |
| 161 | $slen = strlen($suffix); |
| 162 | |
| 163 | if (substr($this->uri_string, -$slen) === $suffix) |
| 164 | { |
| 165 | $this->uri_string = substr($this->uri_string, 0, -$slen); |
| 166 | } |
| 167 | } |
| 168 | |
Andrey Andreev | a439905 | 2014-01-18 18:58:06 +0200 | [diff] [blame] | 169 | $this->segments[0] = NULL; |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 170 | // Populate the segments array |
Andrey Andreev | 4e4f2f5 | 2014-05-01 12:47:42 +0300 | [diff] [blame] | 171 | foreach (explode('/', trim($this->uri_string, '/')) as $val) |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 172 | { |
Andrey Andreev | bfa233f | 2014-12-05 12:00:11 +0200 | [diff] [blame] | 173 | $val = trim($val); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 174 | // Filter segments for security |
Andrey Andreev | bfa233f | 2014-12-05 12:00:11 +0200 | [diff] [blame] | 175 | $this->filter_uri($val); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 176 | |
| 177 | if ($val !== '') |
| 178 | { |
| 179 | $this->segments[] = $val; |
| 180 | } |
| 181 | } |
Andrey Andreev | a439905 | 2014-01-18 18:58:06 +0200 | [diff] [blame] | 182 | |
| 183 | unset($this->segments[0]); |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 184 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | // -------------------------------------------------------------------- |
| 188 | |
| 189 | /** |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 190 | * Parse REQUEST_URI |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | * |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 192 | * Will parse REQUEST_URI and automatically detect the URI from it, |
| 193 | * while fixing the query string if necessary. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | * @return string |
| 196 | */ |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 197 | protected function _parse_request_uri() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 199 | if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | { |
| 201 | return ''; |
| 202 | } |
| 203 | |
Andrey Andreev | fddbde6 | 2015-07-28 00:07:21 +0300 | [diff] [blame] | 204 | // parse_url() returns false if no host is present, but the path or query string |
| 205 | // contains a colon followed by a number |
Andrey Andreev | 5ffbdce | 2015-07-28 12:19:10 +0300 | [diff] [blame] | 206 | $uri = parse_url('http://dummy'.$_SERVER['REQUEST_URI']); |
Andrey Andreev | d4516e3 | 2012-10-31 14:44:38 +0200 | [diff] [blame] | 207 | $query = isset($uri['query']) ? $uri['query'] : ''; |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 208 | $uri = isset($uri['path']) ? $uri['path'] : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | |
Cyrille TOULET | cbf3a55 | 2015-03-30 09:14:46 +0200 | [diff] [blame] | 210 | if (isset($_SERVER['SCRIPT_NAME'][0])) |
| 211 | { |
| 212 | if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) |
| 213 | { |
| 214 | $uri = (string) substr($uri, strlen($_SERVER['SCRIPT_NAME'])); |
| 215 | } |
| 216 | elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) |
| 217 | { |
| 218 | $uri = (string) substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); |
| 219 | } |
| 220 | } |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 221 | |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 222 | // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct |
| 223 | // URI is found, and also fixes the QUERY_STRING server var and $_GET array. |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 224 | if (trim($uri, '/') === '' && strncmp($query, '/', 1) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | { |
Andrey Andreev | d4516e3 | 2012-10-31 14:44:38 +0200 | [diff] [blame] | 226 | $query = explode('?', $query, 2); |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 227 | $uri = $query[0]; |
Andrey Andreev | d4516e3 | 2012-10-31 14:44:38 +0200 | [diff] [blame] | 228 | $_SERVER['QUERY_STRING'] = isset($query[1]) ? $query[1] : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | } |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 230 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | { |
Andrey Andreev | d4516e3 | 2012-10-31 14:44:38 +0200 | [diff] [blame] | 232 | $_SERVER['QUERY_STRING'] = $query; |
| 233 | } |
| 234 | |
Andrey Andreev | ea6688b | 2012-10-31 21:52:11 +0200 | [diff] [blame] | 235 | parse_str($_SERVER['QUERY_STRING'], $_GET); |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 236 | |
Andrey Andreev | 4b322b1 | 2012-10-26 15:37:28 +0300 | [diff] [blame] | 237 | if ($uri === '/' OR $uri === '') |
ericbarnes@ericbarnes.local | e58199b | 2011-02-02 22:40:36 -0500 | [diff] [blame] | 238 | { |
| 239 | return '/'; |
| 240 | } |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 241 | |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 242 | // Do some final cleaning of the URI and return it |
CJ | 0bf9cfa | 2012-12-06 17:15:49 +0800 | [diff] [blame] | 243 | return $this->_remove_relative_directory($uri); |
chernjie | af3bd3e | 2012-12-06 12:06:50 +0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // -------------------------------------------------------------------- |
| 247 | |
| 248 | /** |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 249 | * Parse QUERY_STRING |
| 250 | * |
| 251 | * Will parse QUERY_STRING and automatically detect the URI from it. |
| 252 | * |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 253 | * @return string |
| 254 | */ |
| 255 | protected function _parse_query_string() |
| 256 | { |
| 257 | $uri = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); |
| 258 | |
| 259 | if (trim($uri, '/') === '') |
| 260 | { |
| 261 | return ''; |
| 262 | } |
| 263 | elseif (strncmp($uri, '/', 1) === 0) |
| 264 | { |
| 265 | $uri = explode('?', $uri, 2); |
| 266 | $_SERVER['QUERY_STRING'] = isset($uri[1]) ? $uri[1] : ''; |
Andrey Andreev | 0ae4e6c | 2015-02-18 21:14:55 +0200 | [diff] [blame] | 267 | $uri = $uri[0]; |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 268 | } |
Andrey Andreev | 9dd2dbb | 2012-10-31 17:54:56 +0200 | [diff] [blame] | 269 | |
Andrey Andreev | ea6688b | 2012-10-31 21:52:11 +0200 | [diff] [blame] | 270 | parse_str($_SERVER['QUERY_STRING'], $_GET); |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 271 | |
Andrey Andreev | b2280ce | 2012-12-06 16:19:22 +0200 | [diff] [blame] | 272 | return $this->_remove_relative_directory($uri); |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | // -------------------------------------------------------------------- |
| 276 | |
| 277 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 278 | * Parse CLI arguments |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 279 | * |
| 280 | * Take each command line argument and assume it is a URI segment. |
| 281 | * |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 282 | * @return string |
| 283 | */ |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 284 | protected function _parse_argv() |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 285 | { |
| 286 | $args = array_slice($_SERVER['argv'], 1); |
Andrey Andreev | f2b19fe | 2012-10-31 16:16:24 +0200 | [diff] [blame] | 287 | return $args ? implode('/', $args) : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | // -------------------------------------------------------------------- |
| 291 | |
| 292 | /** |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 293 | * Remove relative directory (../) and multi slashes (///) |
| 294 | * |
| 295 | * Do some final cleaning of the URI and return it, currently only used in self::_parse_request_uri() |
| 296 | * |
Andrey Andreev | f0f93f5 | 2015-12-07 12:12:44 +0200 | [diff] [blame] | 297 | * @param string $uri |
Andrey Andreev | 30d5324 | 2014-01-16 14:41:46 +0200 | [diff] [blame] | 298 | * @return string |
| 299 | */ |
| 300 | protected function _remove_relative_directory($uri) |
| 301 | { |
| 302 | $uris = array(); |
| 303 | $tok = strtok($uri, '/'); |
| 304 | while ($tok !== FALSE) |
| 305 | { |
| 306 | if (( ! empty($tok) OR $tok === '0') && $tok !== '..') |
| 307 | { |
| 308 | $uris[] = $tok; |
| 309 | } |
| 310 | $tok = strtok('/'); |
| 311 | } |
| 312 | |
| 313 | return implode('/', $uris); |
| 314 | } |
| 315 | |
| 316 | // -------------------------------------------------------------------- |
| 317 | |
| 318 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 319 | * Filter URI |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 321 | * Filters segments for malicious characters. |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 322 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 323 | * @param string $str |
Andrey Andreev | bfa233f | 2014-12-05 12:00:11 +0200 | [diff] [blame] | 324 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | */ |
Andrey Andreev | bfa233f | 2014-12-05 12:00:11 +0200 | [diff] [blame] | 326 | public function filter_uri(&$str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | { |
Andrey Andreev | 08fef7d | 2014-01-15 18:37:01 +0200 | [diff] [blame] | 328 | if ( ! empty($str) && ! empty($this->_permitted_uri_chars) && ! preg_match('/^['.$this->_permitted_uri_chars.']+$/i'.(UTF8_ENABLED ? 'u' : ''), $str)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | { |
Andrey Andreev | de14aa5 | 2014-01-15 15:51:08 +0200 | [diff] [blame] | 330 | show_error('The URI you submitted has disallowed characters.', 400); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // -------------------------------------------------------------------- |
| 335 | |
| 336 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 337 | * Fetch URI Segment |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 339 | * @see CI_URI::$segments |
| 340 | * @param int $n Index |
| 341 | * @param mixed $no_result What to return if the segment index is not found |
| 342 | * @return mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 344 | public function segment($n, $no_result = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 346 | return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | // -------------------------------------------------------------------- |
| 350 | |
| 351 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 352 | * Fetch URI "routed" Segment |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 353 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 354 | * Returns the re-routed URI segment (assuming routing rules are used) |
| 355 | * based on the index provided. If there is no routing, will return |
| 356 | * the same result as CI_URI::segment(). |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 358 | * @see CI_URI::$rsegments |
| 359 | * @see CI_URI::segment() |
| 360 | * @param int $n Index |
| 361 | * @param mixed $no_result What to return if the segment index is not found |
| 362 | * @return mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 363 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 364 | public function rsegment($n, $no_result = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 366 | return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // -------------------------------------------------------------------- |
| 370 | |
| 371 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 372 | * URI to assoc |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 373 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 374 | * Generates an associative array of URI data starting at the supplied |
| 375 | * segment index. For example, if this is your URI: |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 376 | * |
| 377 | * example.com/user/search/name/joe/location/UK/gender/male |
| 378 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 379 | * You can use this method to generate an array with this prototype: |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 381 | * array ( |
| 382 | * name => joe |
| 383 | * location => UK |
| 384 | * gender => male |
| 385 | * ) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 387 | * @param int $n Index (default: 3) |
| 388 | * @param array $default Default values |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | * @return array |
| 390 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 391 | public function uri_to_assoc($n = 3, $default = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 393 | return $this->_uri_to_assoc($n, $default, 'segment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 394 | } |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 395 | |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 396 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 397 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 399 | * Routed URI to assoc |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 400 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 401 | * Identical to CI_URI::uri_to_assoc(), only it uses the re-routed |
| 402 | * segment array. |
| 403 | * |
| 404 | * @see CI_URI::uri_to_assoc() |
| 405 | * @param int $n Index (default: 3) |
| 406 | * @param array $default Default values |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 407 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 409 | public function ruri_to_assoc($n = 3, $default = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 411 | return $this->_uri_to_assoc($n, $default, 'rsegment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | // -------------------------------------------------------------------- |
| 415 | |
| 416 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 417 | * Internal URI-to-assoc |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 418 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 419 | * Generates a key/value pair from the URI string or re-routed URI string. |
| 420 | * |
| 421 | * @used-by CI_URI::uri_to_assoc() |
| 422 | * @used-by CI_URI::ruri_to_assoc() |
| 423 | * @param int $n Index (default: 3) |
| 424 | * @param array $default Default values |
| 425 | * @param string $which Array name ('segment' or 'rsegment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | * @return array |
| 427 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 428 | protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | if ( ! is_numeric($n)) |
| 431 | { |
| 432 | return $default; |
| 433 | } |
| 434 | |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 435 | if (isset($this->keyval[$which], $this->keyval[$which][$n])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 436 | { |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 437 | return $this->keyval[$which][$n]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Daniel Hunsaker | 4279223 | 2012-12-31 08:57:12 -0700 | [diff] [blame] | 440 | $total_segments = "total_{$which}s"; |
| 441 | $segment_array = "{$which}_array"; |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 442 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | if ($this->$total_segments() < $n) |
| 444 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 445 | return (count($default) === 0) |
| 446 | ? array() |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 447 | : array_fill_keys($default, NULL); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | $segments = array_slice($this->$segment_array(), ($n - 1)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | $i = 0; |
| 452 | $lastval = ''; |
vkeranov | 2b6b430 | 2012-10-27 18:12:24 +0300 | [diff] [blame] | 453 | $retval = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 454 | foreach ($segments as $seg) |
| 455 | { |
| 456 | if ($i % 2) |
| 457 | { |
| 458 | $retval[$lastval] = $seg; |
| 459 | } |
| 460 | else |
| 461 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 462 | $retval[$seg] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | $lastval = $seg; |
| 464 | } |
| 465 | |
| 466 | $i++; |
| 467 | } |
| 468 | |
| 469 | if (count($default) > 0) |
| 470 | { |
| 471 | foreach ($default as $val) |
| 472 | { |
| 473 | if ( ! array_key_exists($val, $retval)) |
| 474 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 475 | $retval[$val] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | // Cache the array for reuse |
Andrey Andreev | 9093042 | 2012-10-24 23:53:12 +0300 | [diff] [blame] | 481 | isset($this->keyval[$which]) OR $this->keyval[$which] = array(); |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 482 | $this->keyval[$which][$n] = $retval; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 483 | return $retval; |
| 484 | } |
| 485 | |
| 486 | // -------------------------------------------------------------------- |
| 487 | |
| 488 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 489 | * Assoc to URI |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 491 | * Generates a URI string from an associative array. |
| 492 | * |
| 493 | * @param array $array Input array of key/value pairs |
| 494 | * @return string URI string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 495 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 496 | public function assoc_to_uri($array) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | { |
| 498 | $temp = array(); |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 499 | foreach ((array) $array as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | { |
Andrey Andreev | a798fdb | 2012-01-08 00:20:49 +0200 | [diff] [blame] | 501 | $temp[] = $key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 502 | $temp[] = $val; |
| 503 | } |
| 504 | |
| 505 | return implode('/', $temp); |
| 506 | } |
| 507 | |
| 508 | // -------------------------------------------------------------------- |
| 509 | |
| 510 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 511 | * Slash segment |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 513 | * Fetches an URI segment with a slash. |
| 514 | * |
| 515 | * @param int $n Index |
| 516 | * @param string $where Where to add the slash ('trailing' or 'leading') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | * @return string |
| 518 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 519 | public function slash_segment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | { |
| 521 | return $this->_slash_segment($n, $where, 'segment'); |
| 522 | } |
| 523 | |
| 524 | // -------------------------------------------------------------------- |
| 525 | |
| 526 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 527 | * Slash routed segment |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 529 | * Fetches an URI routed segment with a slash. |
| 530 | * |
| 531 | * @param int $n Index |
| 532 | * @param string $where Where to add the slash ('trailing' or 'leading') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 533 | * @return string |
| 534 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 535 | public function slash_rsegment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 536 | { |
| 537 | return $this->_slash_segment($n, $where, 'rsegment'); |
| 538 | } |
| 539 | |
| 540 | // -------------------------------------------------------------------- |
| 541 | |
| 542 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 543 | * Internal Slash segment |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 544 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 545 | * Fetches an URI Segment and adds a slash to it. |
| 546 | * |
| 547 | * @used-by CI_URI::slash_segment() |
| 548 | * @used-by CI_URI::slash_rsegment() |
| 549 | * |
| 550 | * @param int $n Index |
| 551 | * @param string $where Where to add the slash ('trailing' or 'leading') |
| 552 | * @param string $which Array name ('segment' or 'rsegment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 553 | * @return string |
| 554 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 555 | protected function _slash_segment($n, $where = 'trailing', $which = 'segment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 556 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 557 | $leading = $trailing = '/'; |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 558 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 559 | if ($where === 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 560 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | $leading = ''; |
| 562 | } |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 563 | elseif ($where === 'leading') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 565 | $trailing = ''; |
| 566 | } |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 567 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 568 | return $leading.$this->$which($n).$trailing; |
| 569 | } |
| 570 | |
| 571 | // -------------------------------------------------------------------- |
| 572 | |
| 573 | /** |
| 574 | * Segment Array |
| 575 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 576 | * @return array CI_URI::$segments |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 578 | public function segment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 579 | { |
| 580 | return $this->segments; |
| 581 | } |
| 582 | |
| 583 | // -------------------------------------------------------------------- |
| 584 | |
| 585 | /** |
| 586 | * Routed Segment Array |
| 587 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 588 | * @return array CI_URI::$rsegments |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 589 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 590 | public function rsegment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | { |
| 592 | return $this->rsegments; |
| 593 | } |
| 594 | |
| 595 | // -------------------------------------------------------------------- |
| 596 | |
| 597 | /** |
| 598 | * Total number of segments |
| 599 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 600 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 601 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 602 | public function total_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | { |
| 604 | return count($this->segments); |
| 605 | } |
| 606 | |
| 607 | // -------------------------------------------------------------------- |
| 608 | |
| 609 | /** |
| 610 | * Total number of routed segments |
| 611 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 612 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 613 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 614 | public function total_rsegments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 615 | { |
| 616 | return count($this->rsegments); |
| 617 | } |
| 618 | |
| 619 | // -------------------------------------------------------------------- |
| 620 | |
| 621 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 622 | * Fetch URI string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 623 | * |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 624 | * @return string CI_URI::$uri_string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 625 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 626 | public function uri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 627 | { |
| 628 | return $this->uri_string; |
| 629 | } |
| 630 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 631 | // -------------------------------------------------------------------- |
| 632 | |
| 633 | /** |
Andrey Andreev | cca7427 | 2012-10-28 14:43:36 +0200 | [diff] [blame] | 634 | * Fetch Re-routed URI string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | * @return string |
| 637 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 638 | public function ruri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 639 | { |
Andrey Andreev | c26b9eb | 2014-02-24 11:31:36 +0200 | [diff] [blame] | 640 | return ltrim(load_class('Router', 'core')->directory, '/').implode('/', $this->rsegments); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | } |