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