Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | 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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
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 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * URI Class |
| 30 | * |
| 31 | * Parses URIs and determines routing |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Libraries |
| 35 | * @category URI |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/libraries/uri.html |
| 38 | */ |
| 39 | class CI_URI { |
| 40 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 41 | /** |
| 42 | * List of cached uri segments |
| 43 | * |
| 44 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 45 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 46 | public $keyval = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 47 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 48 | /** |
| 49 | * Current uri string |
| 50 | * |
| 51 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 52 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 53 | public $uri_string; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 54 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 55 | /** |
| 56 | * List of uri segments |
| 57 | * |
| 58 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 59 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 60 | public $segments = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 61 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 62 | /** |
| 63 | * Re-indexed list of uri segments |
| 64 | * Starts at 1 instead of 0 |
| 65 | * |
| 66 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 67 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 68 | public $rsegments = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Constructor |
| 72 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 73 | * Simply globalizes the $RTR object. The front |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | * loads the Router class early on so it's not available |
| 75 | * normally as other classes are. |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 76 | * |
| 77 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 79 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | { |
Derek Jones | 7576a3b | 2010-03-02 14:00:36 -0600 | [diff] [blame] | 81 | $this->config =& load_class('Config', 'core'); |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 82 | log_message('debug', 'URI Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | // -------------------------------------------------------------------- |
| 86 | |
| 87 | /** |
| 88 | * Get the URI String |
| 89 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 90 | * Called by CI_Router |
| 91 | * |
| 92 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 94 | public function _fetch_uri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 95 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 96 | if (strtoupper($this->config->item('uri_protocol')) === 'AUTO') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | { |
Phil Sturgeon | dda07e9 | 2011-01-31 23:26:25 +0000 | [diff] [blame] | 98 | // Is the request coming from the command line? |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 99 | if ($this->_is_cli_request()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 101 | $this->_set_uri_string($this->_parse_cli_args()); |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 102 | return; |
| 103 | } |
| 104 | |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 105 | // Let's try the REQUEST_URI first, this will work in most situations |
| 106 | if ($uri = $this->_detect_uri()) |
| 107 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 108 | $this->_set_uri_string($uri); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
| 112 | // Is there a PATH_INFO variable? |
| 113 | // Note: some servers seem to have trouble with getenv() so we'll test it two ways |
| 114 | $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 115 | if (trim($path, '/') != '' && $path !== '/'.SELF) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 117 | $this->_set_uri_string($path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
| 121 | // No PATH_INFO?... What about QUERY_STRING? |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 122 | $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 123 | if (trim($path, '/') != '') |
| 124 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 125 | $this->_set_uri_string($path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
Dan Horrigan | 65d603e | 2010-12-15 08:38:30 -0500 | [diff] [blame] | 129 | // As a last ditch effort lets try using the $_GET array |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 130 | if (is_array($_GET) && count($_GET) === 1 && trim(key($_GET), '/') != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 132 | $this->_set_uri_string(key($_GET)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | return; |
| 134 | } |
| 135 | |
| 136 | // We've exhausted all our options... |
| 137 | $this->uri_string = ''; |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 138 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 139 | } |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 140 | |
| 141 | $uri = strtoupper($this->config->item('uri_protocol')); |
| 142 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 143 | if ($uri === 'REQUEST_URI') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | { |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 145 | $this->_set_uri_string($this->_detect_uri()); |
| 146 | return; |
| 147 | } |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 148 | elseif ($uri === 'CLI') |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 149 | { |
| 150 | $this->_set_uri_string($this->_parse_cli_args()); |
| 151 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 154 | $path = isset($_SERVER[$uri]) ? $_SERVER[$uri] : @getenv($uri); |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 155 | $this->_set_uri_string($path); |
| 156 | } |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 157 | |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 158 | // -------------------------------------------------------------------- |
| 159 | |
| 160 | /** |
| 161 | * Set the URI String |
| 162 | * |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 163 | * @param string |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 164 | * @return void |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 165 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 166 | public function _set_uri_string($str) |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 167 | { |
| 168 | // Filter out control characters |
| 169 | $str = remove_invisible_characters($str, FALSE); |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 170 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | // If the URI contains only a slash we'll kill it |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 172 | $this->uri_string = ($str === '/') ? '' : $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // -------------------------------------------------------------------- |
| 176 | |
| 177 | /** |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 178 | * Detects the URI |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | * |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 180 | * This function will detect the URI automatically and fix the query string |
| 181 | * if necessary. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 182 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | * @return string |
| 184 | */ |
Paul | f7345e4 | 2011-08-27 06:51:16 +1200 | [diff] [blame] | 185 | protected function _detect_uri() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 186 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 187 | if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 188 | { |
| 189 | return ''; |
| 190 | } |
| 191 | |
Michiel Vugteveen | 0609d58 | 2012-01-08 13:26:17 +0100 | [diff] [blame] | 192 | $uri = $_SERVER['REQUEST_URI']; |
| 193 | if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 194 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 195 | $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); |
| 196 | } |
Michiel Vugteveen | 0609d58 | 2012-01-08 13:26:17 +0100 | [diff] [blame] | 197 | elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0) |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 198 | { |
| 199 | $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME']))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 202 | // This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct |
| 203 | // URI is found, and also fixes the QUERY_STRING server var and $_GET array. |
| 204 | if (strncmp($uri, '?/', 2) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 206 | $uri = substr($uri, 2); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | } |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 208 | $parts = preg_split('#\?#i', $uri, 2); |
| 209 | $uri = $parts[0]; |
| 210 | if (isset($parts[1])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 211 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 212 | $_SERVER['QUERY_STRING'] = $parts[1]; |
Dan Horrigan | 65d603e | 2010-12-15 08:38:30 -0500 | [diff] [blame] | 213 | parse_str($_SERVER['QUERY_STRING'], $_GET); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | } |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 215 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 217 | $_SERVER['QUERY_STRING'] = ''; |
| 218 | $_GET = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | } |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 220 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 221 | if ($uri == '/' OR empty($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 | $uri = parse_url($uri, PHP_URL_PATH); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [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 |
| 229 | return str_replace(array('//', '../'), '/', trim($uri, '/')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 233 | |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 234 | /** |
| 235 | * Is cli Request? |
| 236 | * |
| 237 | * Duplicate of function from the Input class to test to see if a request was made from the command line |
| 238 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 239 | * @return bool |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 240 | */ |
| 241 | protected function _is_cli_request() |
| 242 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 243 | return (php_sapi_name() === 'cli') OR defined('STDIN'); |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 246 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 247 | |
| 248 | /** |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 249 | * Parse cli arguments |
| 250 | * |
| 251 | * Take each command line argument and assume it is a URI segment. |
| 252 | * |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 253 | * @return string |
| 254 | */ |
Paul | f7345e4 | 2011-08-27 06:51:16 +1200 | [diff] [blame] | 255 | protected function _parse_cli_args() |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 256 | { |
| 257 | $args = array_slice($_SERVER['argv'], 1); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 258 | return $args ? '/'.implode('/', $args) : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // -------------------------------------------------------------------- |
| 262 | |
| 263 | /** |
| 264 | * Filter segments for malicious characters |
| 265 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 266 | * Called by CI_Router |
| 267 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | * @param string |
| 269 | * @return string |
| 270 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 271 | public function _filter_uri($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | { |
| 273 | if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) |
| 274 | { |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 275 | // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards |
| 276 | // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 277 | if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', $str)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | { |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 279 | show_error('The URI you submitted has disallowed characters.', 400); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 283 | // Convert programatic characters to entities and return |
| 284 | return str_replace( |
| 285 | array('$', '(', ')', '%28', '%29'), // Bad |
| 286 | array('$', '(', ')', '(', ')'), // Good |
| 287 | $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | // -------------------------------------------------------------------- |
| 291 | |
| 292 | /** |
| 293 | * Remove the suffix from the URL if needed |
| 294 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 295 | * Called by CI_Router |
| 296 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 297 | * @return void |
| 298 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 299 | public function _remove_url_suffix() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 301 | if ($this->config->item('url_suffix') != '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 302 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 303 | $this->uri_string = preg_replace('|'.preg_quote($this->config->item('url_suffix')).'$|', '', $this->uri_string); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | // -------------------------------------------------------------------- |
| 308 | |
| 309 | /** |
| 310 | * Explode the URI Segments. The individual segments will |
| 311 | * be stored in the $this->segments array. |
| 312 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 313 | * Called by CI_Router |
| 314 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 315 | * @return void |
| 316 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 317 | public function _explode_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 319 | foreach (explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $this->uri_string)) as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | { |
| 321 | // Filter segments for security |
| 322 | $val = trim($this->_filter_uri($val)); |
| 323 | |
| 324 | if ($val != '') |
| 325 | { |
| 326 | $this->segments[] = $val; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 332 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | /** |
| 334 | * Re-index Segments |
| 335 | * |
| 336 | * This function re-indexes the $this->segment array so that it |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 337 | * starts at 1 rather than 0. Doing so makes it simpler to |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 338 | * use functions like $this->uri->segment(n) since there is |
| 339 | * a 1:1 relationship between the segment array and the actual segments. |
| 340 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 341 | * Called by CI_Router |
| 342 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | * @return void |
| 344 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 345 | public function _reindex_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | { |
| 347 | array_unshift($this->segments, NULL); |
| 348 | array_unshift($this->rsegments, NULL); |
| 349 | unset($this->segments[0]); |
| 350 | unset($this->rsegments[0]); |
| 351 | } |
| 352 | |
| 353 | // -------------------------------------------------------------------- |
| 354 | |
| 355 | /** |
| 356 | * Fetch a URI Segment |
| 357 | * |
| 358 | * This function returns the URI segment based on the number provided. |
| 359 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 360 | * @param int |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 361 | * @param mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | * @return string |
| 363 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 364 | public function segment($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->segments[$n]) ? $this->segments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // -------------------------------------------------------------------- |
| 370 | |
| 371 | /** |
| 372 | * Fetch a URI "routed" Segment |
| 373 | * |
| 374 | * This function returns the re-routed URI segment (assuming routing rules are used) |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 375 | * based on the number provided. If there is no routing this function returns the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 376 | * same result as $this->segment() |
| 377 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 378 | * @param int |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 379 | * @param mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | * @return string |
| 381 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 382 | public function rsegment($n, $no_result = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 384 | return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | // -------------------------------------------------------------------- |
| 388 | |
| 389 | /** |
| 390 | * Generate a key value pair from the URI string |
| 391 | * |
| 392 | * This function generates and associative array of URI data starting |
| 393 | * at the supplied segment. For example, if this is your URI: |
| 394 | * |
| 395 | * example.com/user/search/name/joe/location/UK/gender/male |
| 396 | * |
| 397 | * You can use this function to generate an array with this prototype: |
| 398 | * |
| 399 | * array ( |
| 400 | * name => joe |
| 401 | * location => UK |
| 402 | * gender => male |
| 403 | * ) |
| 404 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 405 | * @param int the starting segment number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | * @param array an array of default values |
| 407 | * @return array |
| 408 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 409 | public function uri_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, 'segment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | } |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 413 | |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 414 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 415 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | /** |
| 417 | * Identical to above only it uses the re-routed segment array |
| 418 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 419 | * @param int the starting segment number |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 420 | * @param array an array of default values |
| 421 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 423 | public function ruri_to_assoc($n = 3, $default = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 425 | return $this->_uri_to_assoc($n, $default, 'rsegment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | // -------------------------------------------------------------------- |
| 429 | |
| 430 | /** |
| 431 | * Generate a key value pair from the URI string or Re-routed URI string |
| 432 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 433 | * @param int the starting segment number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 434 | * @param array an array of default values |
| 435 | * @param string which array we should use |
| 436 | * @return array |
| 437 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 438 | protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | if ( ! is_numeric($n)) |
| 441 | { |
| 442 | return $default; |
| 443 | } |
| 444 | |
| 445 | if (isset($this->keyval[$n])) |
| 446 | { |
| 447 | return $this->keyval[$n]; |
| 448 | } |
| 449 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 450 | if ($which === 'segment') |
| 451 | { |
| 452 | $total_segments = 'total_segments'; |
| 453 | $segment_array = 'segment_array'; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | $total_segments = 'total_rsegments'; |
| 458 | $segment_array = 'rsegment_array'; |
| 459 | } |
| 460 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 461 | if ($this->$total_segments() < $n) |
| 462 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 463 | return (count($default) === 0) |
| 464 | ? array() |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 465 | : array_fill_keys($default, NULL); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | $segments = array_slice($this->$segment_array(), ($n - 1)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 469 | $i = 0; |
| 470 | $lastval = ''; |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 471 | $retval = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 472 | foreach ($segments as $seg) |
| 473 | { |
| 474 | if ($i % 2) |
| 475 | { |
| 476 | $retval[$lastval] = $seg; |
| 477 | } |
| 478 | else |
| 479 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 480 | $retval[$seg] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | $lastval = $seg; |
| 482 | } |
| 483 | |
| 484 | $i++; |
| 485 | } |
| 486 | |
| 487 | if (count($default) > 0) |
| 488 | { |
| 489 | foreach ($default as $val) |
| 490 | { |
| 491 | if ( ! array_key_exists($val, $retval)) |
| 492 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 493 | $retval[$val] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | // Cache the array for reuse |
| 499 | $this->keyval[$n] = $retval; |
| 500 | return $retval; |
| 501 | } |
| 502 | |
| 503 | // -------------------------------------------------------------------- |
| 504 | |
| 505 | /** |
| 506 | * Generate a URI string from an associative array |
| 507 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | * @param array an associative array of key/values |
| 509 | * @return array |
| 510 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 511 | public function assoc_to_uri($array) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | { |
| 513 | $temp = array(); |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 514 | foreach ((array) $array as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | { |
Andrey Andreev | a798fdb | 2012-01-08 00:20:49 +0200 | [diff] [blame] | 516 | $temp[] = $key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | $temp[] = $val; |
| 518 | } |
| 519 | |
| 520 | return implode('/', $temp); |
| 521 | } |
| 522 | |
| 523 | // -------------------------------------------------------------------- |
| 524 | |
| 525 | /** |
| 526 | * Fetch a URI Segment and add a trailing slash |
| 527 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 528 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 529 | * @param string |
| 530 | * @return string |
| 531 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 532 | public function slash_segment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 533 | { |
| 534 | return $this->_slash_segment($n, $where, 'segment'); |
| 535 | } |
| 536 | |
| 537 | // -------------------------------------------------------------------- |
| 538 | |
| 539 | /** |
| 540 | * Fetch a URI Segment and add a trailing slash |
| 541 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 542 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 543 | * @param string |
| 544 | * @return string |
| 545 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 546 | public function slash_rsegment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 547 | { |
| 548 | return $this->_slash_segment($n, $where, 'rsegment'); |
| 549 | } |
| 550 | |
| 551 | // -------------------------------------------------------------------- |
| 552 | |
| 553 | /** |
| 554 | * Fetch a URI Segment and add a trailing slash - helper function |
| 555 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 556 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 557 | * @param string |
| 558 | * @param string |
| 559 | * @return string |
| 560 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 561 | protected function _slash_segment($n, $where = 'trailing', $which = 'segment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 562 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 563 | $leading = $trailing = '/'; |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 564 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 565 | if ($where === 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 566 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 567 | $leading = ''; |
| 568 | } |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 569 | elseif ($where === 'leading') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 570 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 571 | $trailing = ''; |
| 572 | } |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 573 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | return $leading.$this->$which($n).$trailing; |
| 575 | } |
| 576 | |
| 577 | // -------------------------------------------------------------------- |
| 578 | |
| 579 | /** |
| 580 | * Segment Array |
| 581 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | * @return array |
| 583 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 584 | public function segment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | { |
| 586 | return $this->segments; |
| 587 | } |
| 588 | |
| 589 | // -------------------------------------------------------------------- |
| 590 | |
| 591 | /** |
| 592 | * Routed Segment Array |
| 593 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 594 | * @return array |
| 595 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 596 | public function rsegment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 597 | { |
| 598 | return $this->rsegments; |
| 599 | } |
| 600 | |
| 601 | // -------------------------------------------------------------------- |
| 602 | |
| 603 | /** |
| 604 | * Total number of segments |
| 605 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 606 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 607 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 608 | public function total_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 609 | { |
| 610 | return count($this->segments); |
| 611 | } |
| 612 | |
| 613 | // -------------------------------------------------------------------- |
| 614 | |
| 615 | /** |
| 616 | * Total number of routed segments |
| 617 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 618 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 619 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 620 | public function total_rsegments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 621 | { |
| 622 | return count($this->rsegments); |
| 623 | } |
| 624 | |
| 625 | // -------------------------------------------------------------------- |
| 626 | |
| 627 | /** |
| 628 | * Fetch the entire URI string |
| 629 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 630 | * @return string |
| 631 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 632 | public function uri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 633 | { |
| 634 | return $this->uri_string; |
| 635 | } |
| 636 | |
| 637 | |
| 638 | // -------------------------------------------------------------------- |
| 639 | |
| 640 | /** |
| 641 | * Fetch the entire Re-routed URI string |
| 642 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 643 | * @return string |
| 644 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 645 | public function ruri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 646 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame^] | 647 | return implode('/', $this->rsegment_array()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | |
| 652 | /* End of file URI.php */ |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 653 | /* Location: ./system/core/URI.php */ |