Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
| 3 | * CodeIgniter
|
| 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 8 | * @author ExpressionEngine Dev Team
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 10 | * @license http://codeigniter.com/user_guide/license.html
|
| 11 | * @link http://codeigniter.com
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 12 | * @since Version 1.0
|
| 13 | * @filesource
|
| 14 | */
|
| 15 |
|
| 16 | // ------------------------------------------------------------------------
|
| 17 |
|
| 18 | /**
|
| 19 | * URI Class
|
| 20 | *
|
| 21 | * Parses URIs and determines routing
|
| 22 | *
|
| 23 | * @package CodeIgniter
|
| 24 | * @subpackage Libraries
|
| 25 | * @category URI
|
Derek Allard | 3d879d5 | 2008-01-18 19:41:32 +0000 | [diff] [blame] | 26 | * @author ExpressionEngine Dev Team
|
Derek Jones | 7a9193a | 2008-01-21 18:39:20 +0000 | [diff] [blame] | 27 | * @link http://codeigniter.com/user_guide/libraries/uri.html
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 28 | */
|
| 29 | class CI_URI {
|
| 30 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 31 | var $keyval = array();
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 32 | var $uri_string;
|
| 33 | var $segments = array();
|
| 34 | var $rsegments = array();
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 35 |
|
| 36 | /**
|
| 37 | * Constructor
|
| 38 | *
|
| 39 | * Simply globalizes the $RTR object. The front
|
| 40 | * loads the Router class early on so it's not available
|
| 41 | * normally as other classes are.
|
| 42 | *
|
| 43 | * @access public
|
| 44 | */
|
| 45 | function CI_URI()
|
| 46 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 47 | $this->config =& load_class('Config');
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 48 | log_message('debug', "URI Class Initialized");
|
| 49 | }
|
| 50 |
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 51 |
|
| 52 | // --------------------------------------------------------------------
|
| 53 |
|
| 54 | /**
|
| 55 | * Get the URI String
|
| 56 | *
|
| 57 | * @access private
|
| 58 | * @return string
|
| 59 | */
|
| 60 | function _fetch_uri_string()
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 61 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 62 | if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
|
| 63 | {
|
| 64 | // If the URL has a question mark then it's simplest to just
|
| 65 | // build the URI string from the zero index of the $_GET array.
|
| 66 | // This avoids having to deal with $_SERVER variables, which
|
| 67 | // can be unreliable in some environments
|
Derek Jones | 27b5005 | 2008-04-14 14:03:04 +0000 | [diff] [blame] | 68 | if (is_array($_GET) AND count($_GET) == 1 AND trim(key($_GET), '/') != '')
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 69 | {
|
Derek Jones | 2712610 | 2008-01-29 23:43:09 +0000 | [diff] [blame] | 70 | $this->uri_string = key($_GET);
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 71 | return;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 72 | }
|
| 73 |
|
| 74 | // Is there a PATH_INFO variable?
|
| 75 | // Note: some servers seem to have trouble with getenv() so we'll test it two ways
|
| 76 | $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
|
Derek Jones | 27b5005 | 2008-04-14 14:03:04 +0000 | [diff] [blame] | 77 | if (trim($path, '/') != '' AND $path != "/".SELF)
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 78 | {
|
| 79 | $this->uri_string = $path;
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 80 | return;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 81 | }
|
| 82 |
|
| 83 | // No PATH_INFO?... What about QUERY_STRING?
|
| 84 | $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
|
Derek Jones | 27b5005 | 2008-04-14 14:03:04 +0000 | [diff] [blame] | 85 | if (trim($path, '/') != '')
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 86 | {
|
| 87 | $this->uri_string = $path;
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 88 | return;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 89 | }
|
| 90 |
|
| 91 | // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
|
| 92 | $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
|
Derek Jones | 27b5005 | 2008-04-14 14:03:04 +0000 | [diff] [blame] | 93 | if (trim($path, '/') != '' AND $path != "/".SELF)
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 94 | {
|
Derek Jones | 62a9020 | 2008-05-07 16:40:28 +0000 | [diff] [blame] | 95 | // remove path and script information so we have good URI data
|
| 96 | $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 97 | return;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 98 | }
|
| 99 |
|
| 100 | // We've exhausted all our options...
|
| 101 | $this->uri_string = '';
|
| 102 | }
|
| 103 | else
|
| 104 | {
|
| 105 | $uri = strtoupper($this->config->item('uri_protocol'));
|
| 106 |
|
| 107 | if ($uri == 'REQUEST_URI')
|
| 108 | {
|
| 109 | $this->uri_string = $this->_parse_request_uri();
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 110 | return;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 111 | }
|
| 112 |
|
| 113 | $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
|
| 114 | }
|
| 115 |
|
| 116 | // If the URI contains only a slash we'll kill it
|
| 117 | if ($this->uri_string == '/')
|
| 118 | {
|
| 119 | $this->uri_string = '';
|
| 120 | }
|
| 121 | }
|
Rick Ellis | de2623c | 2007-07-21 18:28:24 +0000 | [diff] [blame] | 122 |
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 123 | // --------------------------------------------------------------------
|
| 124 |
|
| 125 | /**
|
| 126 | * Parse the REQUEST_URI
|
| 127 | *
|
| 128 | * Due to the way REQUEST_URI works it usually contains path info
|
| 129 | * that makes it unusable as URI data. We'll trim off the unnecessary
|
| 130 | * data, hopefully arriving at a valid URI that we can use.
|
| 131 | *
|
| 132 | * @access private
|
| 133 | * @return string
|
| 134 | */
|
| 135 | function _parse_request_uri()
|
| 136 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 137 | if (! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '')
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 138 | {
|
| 139 | return '';
|
| 140 | }
|
| 141 |
|
| 142 | $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI']));
|
| 143 |
|
| 144 | if ($request_uri == '' OR $request_uri == SELF)
|
| 145 | {
|
| 146 | return '';
|
| 147 | }
|
| 148 |
|
| 149 | $fc_path = FCPATH;
|
| 150 | if (strpos($request_uri, '?') !== FALSE)
|
| 151 | {
|
| 152 | $fc_path .= '?';
|
| 153 | }
|
| 154 |
|
| 155 | $parsed_uri = explode("/", $request_uri);
|
| 156 |
|
| 157 | $i = 0;
|
| 158 | foreach(explode("/", $fc_path) as $segment)
|
| 159 | {
|
| 160 | if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i])
|
| 161 | {
|
| 162 | $i++;
|
| 163 | }
|
| 164 | }
|
| 165 |
|
| 166 | $parsed_uri = implode("/", array_slice($parsed_uri, $i));
|
| 167 |
|
| 168 | if ($parsed_uri != '')
|
| 169 | {
|
| 170 | $parsed_uri = '/'.$parsed_uri;
|
| 171 | }
|
| 172 |
|
| 173 | return $parsed_uri;
|
| 174 | }
|
| 175 |
|
| 176 | // --------------------------------------------------------------------
|
| 177 |
|
| 178 | /**
|
| 179 | * Filter segments for malicious characters
|
| 180 | *
|
| 181 | * @access private
|
| 182 | * @param string
|
| 183 | * @return string
|
| 184 | */
|
| 185 | function _filter_uri($str)
|
| 186 | {
|
Derek Jones | 500b9d3 | 2008-01-19 17:12:31 +0000 | [diff] [blame] | 187 | if ($str != '' AND $this->config->item('permitted_uri_chars') != '')
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 188 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 189 | if (! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 190 | {
|
| 191 | exit('The URI you submitted has disallowed characters.');
|
| 192 | }
|
Derek Jones | 500b9d3 | 2008-01-19 17:12:31 +0000 | [diff] [blame] | 193 | }
|
| 194 |
|
| 195 | return $str;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 196 | }
|
| 197 |
|
| 198 | // --------------------------------------------------------------------
|
| 199 |
|
| 200 | /**
|
| 201 | * Remove the suffix from the URL if needed
|
| 202 | *
|
| 203 | * @access private
|
| 204 | * @return void
|
| 205 | */
|
| 206 | function _remove_url_suffix()
|
| 207 | {
|
| 208 | if ($this->config->item('url_suffix') != "")
|
| 209 | {
|
| 210 | $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
|
| 211 | }
|
| 212 | }
|
| 213 |
|
| 214 | // --------------------------------------------------------------------
|
| 215 |
|
| 216 | /**
|
| 217 | * Explode the URI Segments. The individual segments will
|
| 218 | * be stored in the $this->segments array.
|
| 219 | *
|
| 220 | * @access private
|
| 221 | * @return void
|
| 222 | */
|
| 223 | function _explode_segments()
|
| 224 | {
|
| 225 | foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
|
| 226 | {
|
| 227 | // Filter segments for security
|
| 228 | $val = trim($this->_filter_uri($val));
|
| 229 |
|
| 230 | if ($val != '')
|
| 231 | $this->segments[] = $val;
|
| 232 | }
|
| 233 | }
|
| 234 |
|
| 235 | // --------------------------------------------------------------------
|
| 236 | /**
|
| 237 | * Re-index Segments
|
| 238 | *
|
| 239 | * This function re-indexes the $this->segment array so that it
|
| 240 | * starts at 1 rather then 0. Doing so makes it simpler to
|
| 241 | * use functions like $this->uri->segment(n) since there is
|
| 242 | * a 1:1 relationship between the segment array and the actual segments.
|
| 243 | *
|
| 244 | * @access private
|
| 245 | * @return void
|
| 246 | */
|
| 247 | function _reindex_segments()
|
| 248 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 249 | $i = 1;
|
Derek Jones | b069789 | 2008-02-13 03:38:39 +0000 | [diff] [blame] | 250 |
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 251 | foreach ($this->segments as $val)
|
| 252 | {
|
| 253 | $this->segments[$i++] = $val;
|
| 254 | }
|
Derek Jones | b069789 | 2008-02-13 03:38:39 +0000 | [diff] [blame] | 255 |
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 256 | unset($this->segments[0]);
|
| 257 |
|
Derek Jones | b069789 | 2008-02-13 03:38:39 +0000 | [diff] [blame] | 258 | $i = 1;
|
| 259 |
|
| 260 | foreach ($this->rsegments as $val)
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 261 | {
|
Derek Jones | b069789 | 2008-02-13 03:38:39 +0000 | [diff] [blame] | 262 | $this->rsegments[$i++] = $val;
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 263 | }
|
Derek Jones | b069789 | 2008-02-13 03:38:39 +0000 | [diff] [blame] | 264 |
|
| 265 | unset($this->rsegments[0]);
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 266 | }
|
| 267 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 268 | // --------------------------------------------------------------------
|
| 269 |
|
| 270 | /**
|
| 271 | * Fetch a URI Segment
|
| 272 | *
|
| 273 | * This function returns the URI segment based on the number provided.
|
| 274 | *
|
| 275 | * @access public
|
| 276 | * @param integer
|
| 277 | * @param bool
|
| 278 | * @return string
|
| 279 | */
|
| 280 | function segment($n, $no_result = FALSE)
|
| 281 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 282 | return (! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 283 | }
|
| 284 |
|
| 285 | // --------------------------------------------------------------------
|
| 286 |
|
| 287 | /**
|
| 288 | * Fetch a URI "routed" Segment
|
| 289 | *
|
| 290 | * This function returns the re-routed URI segment (assuming routing rules are used)
|
| 291 | * based on the number provided. If there is no routing this function returns the
|
| 292 | * same result as $this->segment()
|
| 293 | *
|
| 294 | * @access public
|
| 295 | * @param integer
|
| 296 | * @param bool
|
| 297 | * @return string
|
| 298 | */
|
| 299 | function rsegment($n, $no_result = FALSE)
|
| 300 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 301 | return (! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 302 | }
|
| 303 |
|
| 304 | // --------------------------------------------------------------------
|
| 305 |
|
| 306 | /**
|
| 307 | * Generate a key value pair from the URI string
|
| 308 | *
|
| 309 | * This function generates and associative array of URI data starting
|
| 310 | * at the supplied segment. For example, if this is your URI:
|
| 311 | *
|
| 312 | * www.your-site.com/user/search/name/joe/location/UK/gender/male
|
| 313 | *
|
| 314 | * You can use this function to generate an array with this prototype:
|
| 315 | *
|
| 316 | * array (
|
| 317 | * name => joe
|
| 318 | * location => UK
|
| 319 | * gender => male
|
| 320 | * )
|
| 321 | *
|
| 322 | * @access public
|
| 323 | * @param integer the starting segment number
|
| 324 | * @param array an array of default values
|
| 325 | * @return array
|
| 326 | */
|
| 327 | function uri_to_assoc($n = 3, $default = array())
|
| 328 | {
|
| 329 | return $this->_uri_to_assoc($n, $default, 'segment');
|
| 330 | }
|
| 331 | /**
|
| 332 | * Identical to above only it uses the re-routed segment array
|
| 333 | *
|
| 334 | */
|
| 335 | function ruri_to_assoc($n = 3, $default = array())
|
| 336 | {
|
| 337 | return $this->_uri_to_assoc($n, $default, 'rsegment');
|
| 338 | }
|
| 339 |
|
| 340 | // --------------------------------------------------------------------
|
| 341 |
|
| 342 | /**
|
| 343 | * Generate a key value pair from the URI string or Re-routed URI string
|
| 344 | *
|
| 345 | * @access private
|
| 346 | * @param integer the starting segment number
|
| 347 | * @param array an array of default values
|
| 348 | * @param string which array we should use
|
| 349 | * @return array
|
| 350 | */
|
| 351 | function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
|
| 352 | {
|
| 353 | if ($which == 'segment')
|
| 354 | {
|
| 355 | $total_segments = 'total_segments';
|
| 356 | $segment_array = 'segment_array';
|
| 357 | }
|
| 358 | else
|
| 359 | {
|
| 360 | $total_segments = 'total_rsegments';
|
| 361 | $segment_array = 'rsegment_array';
|
| 362 | }
|
| 363 |
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 364 | if (! is_numeric($n))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 365 | {
|
| 366 | return $default;
|
| 367 | }
|
| 368 |
|
| 369 | if (isset($this->keyval[$n]))
|
| 370 | {
|
| 371 | return $this->keyval[$n];
|
| 372 | }
|
| 373 |
|
| 374 | if ($this->$total_segments() < $n)
|
| 375 | {
|
| 376 | if (count($default) == 0)
|
| 377 | {
|
| 378 | return array();
|
| 379 | }
|
| 380 |
|
| 381 | $retval = array();
|
| 382 | foreach ($default as $val)
|
| 383 | {
|
| 384 | $retval[$val] = FALSE;
|
| 385 | }
|
| 386 | return $retval;
|
| 387 | }
|
| 388 |
|
| 389 | $segments = array_slice($this->$segment_array(), ($n - 1));
|
| 390 |
|
| 391 | $i = 0;
|
| 392 | $lastval = '';
|
| 393 | $retval = array();
|
| 394 | foreach ($segments as $seg)
|
| 395 | {
|
| 396 | if ($i % 2)
|
| 397 | {
|
| 398 | $retval[$lastval] = $seg;
|
| 399 | }
|
| 400 | else
|
| 401 | {
|
| 402 | $retval[$seg] = FALSE;
|
| 403 | $lastval = $seg;
|
| 404 | }
|
| 405 |
|
| 406 | $i++;
|
| 407 | }
|
| 408 |
|
| 409 | if (count($default) > 0)
|
| 410 | {
|
| 411 | foreach ($default as $val)
|
| 412 | {
|
Derek Allard | 7327499 | 2008-05-05 16:39:18 +0000 | [diff] [blame] | 413 | if (! array_key_exists($val, $retval))
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 414 | {
|
| 415 | $retval[$val] = FALSE;
|
| 416 | }
|
| 417 | }
|
| 418 | }
|
| 419 |
|
| 420 | // Cache the array for reuse
|
| 421 | $this->keyval[$n] = $retval;
|
| 422 | return $retval;
|
| 423 | }
|
| 424 |
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 425 | // --------------------------------------------------------------------
|
| 426 |
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 427 | /**
|
| 428 | * Generate a URI string from an associative array
|
| 429 | *
|
| 430 | *
|
| 431 | * @access public
|
| 432 | * @param array an associative array of key/values
|
| 433 | * @return array
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 434 | */
|
| 435 | function assoc_to_uri($array)
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 436 | {
|
| 437 | $temp = array();
|
| 438 | foreach ((array)$array as $key => $val)
|
| 439 | {
|
| 440 | $temp[] = $key;
|
| 441 | $temp[] = $val;
|
| 442 | }
|
| 443 |
|
| 444 | return implode('/', $temp);
|
| 445 | }
|
| 446 |
|
| 447 | // --------------------------------------------------------------------
|
| 448 |
|
| 449 | /**
|
| 450 | * Fetch a URI Segment and add a trailing slash
|
| 451 | *
|
| 452 | * @access public
|
| 453 | * @param integer
|
| 454 | * @param string
|
| 455 | * @return string
|
| 456 | */
|
| 457 | function slash_segment($n, $where = 'trailing')
|
| 458 | {
|
| 459 | return $this->_slash_segment($n, $where, 'segment');
|
| 460 | }
|
| 461 |
|
| 462 | // --------------------------------------------------------------------
|
| 463 |
|
| 464 | /**
|
| 465 | * Fetch a URI Segment and add a trailing slash
|
| 466 | *
|
| 467 | * @access public
|
| 468 | * @param integer
|
| 469 | * @param string
|
| 470 | * @return string
|
| 471 | */
|
| 472 | function slash_rsegment($n, $where = 'trailing')
|
| 473 | {
|
| 474 | return $this->_slash_segment($n, $where, 'rsegment');
|
| 475 | }
|
| 476 |
|
| 477 | // --------------------------------------------------------------------
|
| 478 |
|
| 479 | /**
|
| 480 | * Fetch a URI Segment and add a trailing slash - helper function
|
| 481 | *
|
| 482 | * @access private
|
| 483 | * @param integer
|
| 484 | * @param string
|
| 485 | * @param string
|
| 486 | * @return string
|
| 487 | */
|
| 488 | function _slash_segment($n, $where = 'trailing', $which = 'segment')
|
| 489 | {
|
| 490 | if ($where == 'trailing')
|
| 491 | {
|
| 492 | $trailing = '/';
|
| 493 | $leading = '';
|
| 494 | }
|
| 495 | elseif ($where == 'leading')
|
| 496 | {
|
| 497 | $leading = '/';
|
| 498 | $trailing = '';
|
| 499 | }
|
| 500 | else
|
| 501 | {
|
| 502 | $leading = '/';
|
| 503 | $trailing = '/';
|
| 504 | }
|
| 505 | return $leading.$this->$which($n).$trailing;
|
| 506 | }
|
| 507 |
|
| 508 | // --------------------------------------------------------------------
|
| 509 |
|
| 510 | /**
|
| 511 | * Segment Array
|
| 512 | *
|
| 513 | * @access public
|
| 514 | * @return array
|
| 515 | */
|
| 516 | function segment_array()
|
| 517 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 518 | return $this->segments;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 519 | }
|
| 520 |
|
| 521 | // --------------------------------------------------------------------
|
| 522 |
|
| 523 | /**
|
| 524 | * Routed Segment Array
|
| 525 | *
|
| 526 | * @access public
|
| 527 | * @return array
|
| 528 | */
|
| 529 | function rsegment_array()
|
| 530 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 531 | return $this->rsegments;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 532 | }
|
| 533 |
|
| 534 | // --------------------------------------------------------------------
|
| 535 |
|
| 536 | /**
|
| 537 | * Total number of segments
|
| 538 | *
|
| 539 | * @access public
|
| 540 | * @return integer
|
| 541 | */
|
| 542 | function total_segments()
|
| 543 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 544 | return count($this->segments);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 545 | }
|
| 546 |
|
| 547 | // --------------------------------------------------------------------
|
| 548 |
|
| 549 | /**
|
| 550 | * Total number of routed segments
|
| 551 | *
|
| 552 | * @access public
|
| 553 | * @return integer
|
| 554 | */
|
| 555 | function total_rsegments()
|
| 556 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 557 | return count($this->rsegments);
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 558 | }
|
| 559 |
|
| 560 | // --------------------------------------------------------------------
|
| 561 |
|
| 562 | /**
|
| 563 | * Fetch the entire URI string
|
| 564 | *
|
| 565 | * @access public
|
| 566 | * @return string
|
| 567 | */
|
| 568 | function uri_string()
|
| 569 | {
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 570 | return $this->uri_string;
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 571 | }
|
| 572 |
|
| 573 |
|
| 574 | // --------------------------------------------------------------------
|
| 575 |
|
| 576 | /**
|
| 577 | * Fetch the entire Re-routed URI string
|
| 578 | *
|
| 579 | * @access public
|
| 580 | * @return string
|
| 581 | */
|
| 582 | function ruri_string()
|
| 583 | {
|
| 584 | return '/'.implode('/', $this->rsegment_array()).'/';
|
| 585 | }
|
| 586 |
|
| 587 | }
|
| 588 | // END URI Class
|
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 589 | |
| 590 | /* End of file URI.php */ |
| 591 | /* Location: ./system/libraries/URI.php */ |