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 |
Andrey Andreev | 9ba661b | 2012-06-04 14:44:34 +0300 | [diff] [blame] | 114 | $path = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [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 | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 122 | $path = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 123 | if (trim($path, '/') !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [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 | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 166 | protected function _set_uri_string($str) |
Pascal Kriete | 73598e3 | 2011-04-05 15:01:05 -0400 | [diff] [blame] | 167 | { |
Andrey Andreev | f5f898f | 2012-10-23 02:13:29 +0300 | [diff] [blame] | 168 | // Filter out control characters and trim slashes |
| 169 | $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | // -------------------------------------------------------------------- |
| 173 | |
| 174 | /** |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 175 | * Detects the URI |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | * |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 177 | * This function will detect the URI automatically |
| 178 | * and fix the query string if necessary. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 180 | * @return string |
| 181 | */ |
Paul | f7345e4 | 2011-08-27 06:51:16 +1200 | [diff] [blame] | 182 | protected function _detect_uri() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 184 | if ( ! isset($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | { |
| 186 | return ''; |
| 187 | } |
| 188 | |
Andrey Andreev | a8262ba | 2012-06-14 03:16:44 +0300 | [diff] [blame] | 189 | if (strpos($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME']) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 190 | { |
Andrey Andreev | a8262ba | 2012-06-14 03:16:44 +0300 | [diff] [blame] | 191 | $uri = substr($_SERVER['REQUEST_URI'], strlen($_SERVER['SCRIPT_NAME'])); |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 192 | } |
Andrey Andreev | a8262ba | 2012-06-14 03:16:44 +0300 | [diff] [blame] | 193 | elseif (strpos($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])) === 0) |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 194 | { |
Andrey Andreev | fb85979 | 2012-06-14 03:32:19 +0300 | [diff] [blame] | 195 | $uri = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME']))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | } |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 197 | else |
| 198 | { |
| 199 | $uri = $_SERVER['REQUEST_URI']; |
| 200 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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. |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 204 | if (strpos($uri, '?/') === 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 | } |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 208 | |
| 209 | $parts = explode('?', $uri, 2); |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 210 | $uri = $parts[0]; |
| 211 | if (isset($parts[1])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 213 | $_SERVER['QUERY_STRING'] = $parts[1]; |
Dan Horrigan | 65d603e | 2010-12-15 08:38:30 -0500 | [diff] [blame] | 214 | parse_str($_SERVER['QUERY_STRING'], $_GET); |
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 | { |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 218 | $_SERVER['QUERY_STRING'] = ''; |
| 219 | $_GET = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | } |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 221 | |
Andrey Andreev | 4b322b1 | 2012-10-26 15:37:28 +0300 | [diff] [blame] | 222 | if ($uri === '/' OR $uri === '') |
ericbarnes@ericbarnes.local | e58199b | 2011-02-02 22:40:36 -0500 | [diff] [blame] | 223 | { |
| 224 | return '/'; |
| 225 | } |
Eric Barnes | 26eebdd | 2011-04-17 23:45:41 -0400 | [diff] [blame] | 226 | |
Andrey Andreev | d461934 | 2012-06-14 02:27:25 +0300 | [diff] [blame] | 227 | $uri = parse_url('pseudo://hostname/'.$uri, PHP_URL_PATH); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | |
Dan Horrigan | fea45ad | 2011-01-19 00:54:12 -0500 | [diff] [blame] | 229 | // Do some final cleaning of the URI and return it |
| 230 | return str_replace(array('//', '../'), '/', trim($uri, '/')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 234 | |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 235 | /** |
| 236 | * Is cli Request? |
| 237 | * |
| 238 | * Duplicate of function from the Input class to test to see if a request was made from the command line |
| 239 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 240 | * @return bool |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 241 | */ |
| 242 | protected function _is_cli_request() |
| 243 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 244 | return (php_sapi_name() === 'cli') OR defined('STDIN'); |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Stephen | 2e00c24 | 2011-08-28 10:25:40 +0200 | [diff] [blame] | 247 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | |
| 249 | /** |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 250 | * Parse cli arguments |
| 251 | * |
| 252 | * Take each command line argument and assume it is a URI segment. |
| 253 | * |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 254 | * @return string |
| 255 | */ |
Paul | f7345e4 | 2011-08-27 06:51:16 +1200 | [diff] [blame] | 256 | protected function _parse_cli_args() |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 257 | { |
| 258 | $args = array_slice($_SERVER['argv'], 1); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 259 | return $args ? '/'.implode('/', $args) : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // -------------------------------------------------------------------- |
| 263 | |
| 264 | /** |
| 265 | * Filter segments for malicious characters |
| 266 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 267 | * Called by CI_Router |
| 268 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 269 | * @param string |
| 270 | * @return string |
| 271 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 272 | public function _filter_uri($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 273 | { |
Alex Bilbie | 04d43fe | 2012-06-02 17:59:11 +0100 | [diff] [blame] | 274 | if ($str !== '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') === FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | { |
Derek Jones | f0a9b33 | 2009-07-29 14:19:18 +0000 | [diff] [blame] | 276 | // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards |
| 277 | // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern |
Andrey Andreev | 58ae971 | 2012-06-15 23:44:48 +0300 | [diff] [blame] | 278 | if ( ! preg_match('|^['.str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-')).']+$|i', urldecode($str))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
Derek Jones | 817163a | 2009-07-11 17:05:58 +0000 | [diff] [blame] | 280 | show_error('The URI you submitted has disallowed characters.', 400); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 284 | // Convert programatic characters to entities and return |
| 285 | return str_replace( |
| 286 | array('$', '(', ')', '%28', '%29'), // Bad |
| 287 | array('$', '(', ')', '(', ')'), // Good |
| 288 | $str); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | // -------------------------------------------------------------------- |
| 292 | |
| 293 | /** |
| 294 | * Remove the suffix from the URL if needed |
| 295 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 296 | * Called by CI_Router |
| 297 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | * @return void |
| 299 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 300 | public function _remove_url_suffix() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | { |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 302 | $suffix = (string) $this->config->item('url_suffix'); |
| 303 | |
| 304 | if ($suffix !== '' && ($offset = strrpos($this->uri_string, $suffix)) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | { |
Andrey Andreev | 95d78cf | 2012-06-16 19:54:33 +0300 | [diff] [blame] | 306 | $this->uri_string = substr_replace($this->uri_string, '', $offset, strlen($suffix)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | // -------------------------------------------------------------------- |
| 311 | |
| 312 | /** |
| 313 | * Explode the URI Segments. The individual segments will |
| 314 | * be stored in the $this->segments array. |
| 315 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 316 | * Called by CI_Router |
| 317 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | * @return void |
| 319 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 320 | public function _explode_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | { |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 322 | foreach (explode('/', preg_replace('|/*(.+?)/*$|', '\\1', $this->uri_string)) as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 323 | { |
| 324 | // Filter segments for security |
| 325 | $val = trim($this->_filter_uri($val)); |
| 326 | |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 327 | if ($val !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | { |
| 329 | $this->segments[] = $val; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 335 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | /** |
| 337 | * Re-index Segments |
| 338 | * |
| 339 | * This function re-indexes the $this->segment array so that it |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 340 | * starts at 1 rather than 0. Doing so makes it simpler to |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | * use functions like $this->uri->segment(n) since there is |
| 342 | * a 1:1 relationship between the segment array and the actual segments. |
| 343 | * |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 344 | * Called by CI_Router |
| 345 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 346 | * @return void |
| 347 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 348 | public function _reindex_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | { |
| 350 | array_unshift($this->segments, NULL); |
| 351 | array_unshift($this->rsegments, NULL); |
| 352 | unset($this->segments[0]); |
| 353 | unset($this->rsegments[0]); |
| 354 | } |
| 355 | |
| 356 | // -------------------------------------------------------------------- |
| 357 | |
| 358 | /** |
| 359 | * Fetch a URI Segment |
| 360 | * |
| 361 | * This function returns the URI segment based on the number provided. |
| 362 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 363 | * @param int |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 364 | * @param mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | * @return string |
| 366 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 367 | public function segment($n, $no_result = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 369 | return isset($this->segments[$n]) ? $this->segments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | // -------------------------------------------------------------------- |
| 373 | |
| 374 | /** |
| 375 | * Fetch a URI "routed" Segment |
| 376 | * |
| 377 | * 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] | 378 | * 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] | 379 | * same result as $this->segment() |
| 380 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 381 | * @param int |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 382 | * @param mixed |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | * @return string |
| 384 | */ |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 385 | public function rsegment($n, $no_result = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 387 | return isset($this->rsegments[$n]) ? $this->rsegments[$n] : $no_result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | // -------------------------------------------------------------------- |
| 391 | |
| 392 | /** |
| 393 | * Generate a key value pair from the URI string |
| 394 | * |
| 395 | * This function generates and associative array of URI data starting |
| 396 | * at the supplied segment. For example, if this is your URI: |
| 397 | * |
| 398 | * example.com/user/search/name/joe/location/UK/gender/male |
| 399 | * |
| 400 | * You can use this function to generate an array with this prototype: |
| 401 | * |
| 402 | * array ( |
| 403 | * name => joe |
| 404 | * location => UK |
| 405 | * gender => male |
| 406 | * ) |
| 407 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 408 | * @param int the starting segment number |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 409 | * @param array an array of default values |
| 410 | * @return array |
| 411 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 412 | public function uri_to_assoc($n = 3, $default = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 413 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 414 | return $this->_uri_to_assoc($n, $default, 'segment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | } |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 416 | |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 417 | // -------------------------------------------------------------------- |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 418 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | /** |
| 420 | * Identical to above only it uses the re-routed segment array |
| 421 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 422 | * @param int the starting segment number |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 423 | * @param array an array of default values |
| 424 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 425 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 426 | public function ruri_to_assoc($n = 3, $default = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 427 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 428 | return $this->_uri_to_assoc($n, $default, 'rsegment'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | // -------------------------------------------------------------------- |
| 432 | |
| 433 | /** |
| 434 | * Generate a key value pair from the URI string or Re-routed URI string |
| 435 | * |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 436 | * @param int $n = 3 the starting segment number |
| 437 | * @param array $default = array() an array of default values |
| 438 | * @param string $which = 'segment' which array we should use |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | * @return array |
| 440 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 441 | protected function _uri_to_assoc($n = 3, $default = array(), $which = 'segment') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | if ( ! is_numeric($n)) |
| 444 | { |
| 445 | return $default; |
| 446 | } |
| 447 | |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 448 | in_array($which, array('segment', 'rsegment'), TRUE) OR $which = 'segment'; |
| 449 | |
| 450 | if (isset($this->keyval[$which], $this->keyval[$which][$n])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | { |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 452 | return $this->keyval[$which][$n]; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 455 | if ($which === 'segment') |
| 456 | { |
| 457 | $total_segments = 'total_segments'; |
| 458 | $segment_array = 'segment_array'; |
| 459 | } |
| 460 | else |
| 461 | { |
| 462 | $total_segments = 'total_rsegments'; |
| 463 | $segment_array = 'rsegment_array'; |
| 464 | } |
| 465 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | if ($this->$total_segments() < $n) |
| 467 | { |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 468 | return (count($default) === 0) |
| 469 | ? array() |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 470 | : array_fill_keys($default, NULL); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | $segments = array_slice($this->$segment_array(), ($n - 1)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | $i = 0; |
| 475 | $lastval = ''; |
vkeranov | 2b6b430 | 2012-10-27 18:12:24 +0300 | [diff] [blame^] | 476 | $retval = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | foreach ($segments as $seg) |
| 478 | { |
| 479 | if ($i % 2) |
| 480 | { |
| 481 | $retval[$lastval] = $seg; |
| 482 | } |
| 483 | else |
| 484 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 485 | $retval[$seg] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | $lastval = $seg; |
| 487 | } |
| 488 | |
| 489 | $i++; |
| 490 | } |
| 491 | |
| 492 | if (count($default) > 0) |
| 493 | { |
| 494 | foreach ($default as $val) |
| 495 | { |
| 496 | if ( ! array_key_exists($val, $retval)) |
| 497 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 498 | $retval[$val] = NULL; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | // Cache the array for reuse |
Andrey Andreev | 9093042 | 2012-10-24 23:53:12 +0300 | [diff] [blame] | 504 | isset($this->keyval[$which]) OR $this->keyval[$which] = array(); |
Andrey Andreev | 4a7cc76 | 2012-10-24 23:52:05 +0300 | [diff] [blame] | 505 | $this->keyval[$which][$n] = $retval; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | return $retval; |
| 507 | } |
| 508 | |
| 509 | // -------------------------------------------------------------------- |
| 510 | |
| 511 | /** |
| 512 | * Generate a URI string from an associative array |
| 513 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 514 | * @param array an associative array of key/values |
| 515 | * @return array |
| 516 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 517 | public function assoc_to_uri($array) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 518 | { |
| 519 | $temp = array(); |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 520 | foreach ((array) $array as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | { |
Andrey Andreev | a798fdb | 2012-01-08 00:20:49 +0200 | [diff] [blame] | 522 | $temp[] = $key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 523 | $temp[] = $val; |
| 524 | } |
| 525 | |
| 526 | return implode('/', $temp); |
| 527 | } |
| 528 | |
| 529 | // -------------------------------------------------------------------- |
| 530 | |
| 531 | /** |
| 532 | * Fetch a URI Segment and add a trailing slash |
| 533 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 534 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 535 | * @param string |
| 536 | * @return string |
| 537 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 538 | public function slash_segment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | { |
| 540 | return $this->_slash_segment($n, $where, 'segment'); |
| 541 | } |
| 542 | |
| 543 | // -------------------------------------------------------------------- |
| 544 | |
| 545 | /** |
| 546 | * Fetch a URI Segment and add a trailing slash |
| 547 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 548 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 549 | * @param string |
| 550 | * @return string |
| 551 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 552 | public function slash_rsegment($n, $where = 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 553 | { |
| 554 | return $this->_slash_segment($n, $where, 'rsegment'); |
| 555 | } |
| 556 | |
| 557 | // -------------------------------------------------------------------- |
| 558 | |
| 559 | /** |
| 560 | * Fetch a URI Segment and add a trailing slash - helper function |
| 561 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 562 | * @param int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | * @param string |
| 564 | * @param string |
| 565 | * @return string |
| 566 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 567 | protected function _slash_segment($n, $where = 'trailing', $which = 'segment') |
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 | $leading = $trailing = '/'; |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 570 | |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 571 | if ($where === 'trailing') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 573 | $leading = ''; |
| 574 | } |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 575 | elseif ($where === 'leading') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 576 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | $trailing = ''; |
| 578 | } |
Phil Sturgeon | 48c718c | 2010-12-30 23:40:02 +0000 | [diff] [blame] | 579 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 580 | return $leading.$this->$which($n).$trailing; |
| 581 | } |
| 582 | |
| 583 | // -------------------------------------------------------------------- |
| 584 | |
| 585 | /** |
| 586 | * Segment Array |
| 587 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 588 | * @return array |
| 589 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 590 | public function segment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | { |
| 592 | return $this->segments; |
| 593 | } |
| 594 | |
| 595 | // -------------------------------------------------------------------- |
| 596 | |
| 597 | /** |
| 598 | * Routed Segment Array |
| 599 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 600 | * @return array |
| 601 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 602 | public function rsegment_array() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | { |
| 604 | return $this->rsegments; |
| 605 | } |
| 606 | |
| 607 | // -------------------------------------------------------------------- |
| 608 | |
| 609 | /** |
| 610 | * Total number of segments |
| 611 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 612 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 613 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 614 | public function total_segments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 615 | { |
| 616 | return count($this->segments); |
| 617 | } |
| 618 | |
| 619 | // -------------------------------------------------------------------- |
| 620 | |
| 621 | /** |
| 622 | * Total number of routed segments |
| 623 | * |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 624 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 625 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 626 | public function total_rsegments() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 627 | { |
| 628 | return count($this->rsegments); |
| 629 | } |
| 630 | |
| 631 | // -------------------------------------------------------------------- |
| 632 | |
| 633 | /** |
| 634 | * Fetch the entire URI string |
| 635 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | * @return string |
| 637 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 638 | public function uri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 639 | { |
| 640 | return $this->uri_string; |
| 641 | } |
| 642 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 643 | // -------------------------------------------------------------------- |
| 644 | |
| 645 | /** |
| 646 | * Fetch the entire Re-routed URI string |
| 647 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | * @return string |
| 649 | */ |
Andrey Andreev | c123e11 | 2012-01-08 00:17:34 +0200 | [diff] [blame] | 650 | public function ruri_string() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | { |
Phil Sturgeon | 55a6ddb | 2012-05-23 18:37:24 +0100 | [diff] [blame] | 652 | return implode('/', $this->rsegment_array()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 656 | |
| 657 | /* End of file URI.php */ |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 658 | /* Location: ./system/core/URI.php */ |