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