Public Member Functions | |
| CI_URI () | |
| Constructor. | |
| _fetch_uri_string () | |
| Get the URI String. | |
| _parse_request_uri () | |
| Parse the REQUEST_URI. | |
| _filter_uri ($str) | |
| Filter segments for malicious characters. | |
| _remove_url_suffix () | |
| Remove the suffix from the URL if needed. | |
| _explode_segments () | |
| Explode the URI Segments. | |
| _reindex_segments () | |
| Re-index Segments. | |
| segment ($n, $no_result=FALSE) | |
| Fetch a URI Segment. | |
| rsegment ($n, $no_result=FALSE) | |
| Fetch a URI "routed" Segment. | |
| uri_to_assoc ($n=3, $default=array()) | |
| Generate a key value pair from the URI string. | |
| ruri_to_assoc ($n=3, $default=array()) | |
| Identical to above only it uses the re-routed segment array. | |
| _uri_to_assoc ($n=3, $default=array(), $which= 'segment') | |
| Generate a key value pair from the URI string or Re-routed URI string. | |
| assoc_to_uri ($array) | |
| Generate a URI string from an associative array. | |
| slash_segment ($n, $where= 'trailing') | |
| Fetch a URI Segment and add a trailing slash. | |
| slash_rsegment ($n, $where= 'trailing') | |
| Fetch a URI Segment and add a trailing slash. | |
| _slash_segment ($n, $where= 'trailing', $which= 'segment') | |
| Fetch a URI Segment and add a trailing slash - helper function. | |
| segment_array () | |
| Segment Array. | |
| rsegment_array () | |
| Routed Segment Array. | |
| total_segments () | |
| Total number of segments. | |
| total_rsegments () | |
| Total number of routed segments. | |
| uri_string () | |
| Fetch the entire URI string. | |
| ruri_string () | |
| Fetch the entire Re-routed URI string. | |
Public Attributes | |
| $keyval = array() | |
| $uri_string | |
| $segments = array() | |
| $rsegments = array() | |
Definition at line 29 of file URI.php.
| CI_URI::_explode_segments | ( | ) |
Explode the URI Segments.
The individual segments will be stored in the $this->segments array.
private
Definition at line 227 of file URI.php.
References _filter_uri(), and uri_string().
00228 { 00229 foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) 00230 { 00231 // Filter segments for security 00232 $val = trim($this->_filter_uri($val)); 00233 00234 if ($val != '') 00235 { 00236 $this->segments[] = $val; 00237 } 00238 } 00239 }

| CI_URI::_fetch_uri_string | ( | ) |
Get the URI String.
private
Definition at line 60 of file URI.php.
References _parse_request_uri(), and uri_string().
00061 { 00062 if (strtoupper($this->config->item('uri_protocol')) == 'AUTO') 00063 { 00064 // If the URL has a question mark then it's simplest to just 00065 // build the URI string from the zero index of the $_GET array. 00066 // This avoids having to deal with $_SERVER variables, which 00067 // can be unreliable in some environments 00068 if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '') 00069 { 00070 $this->uri_string = key($_GET); 00071 return; 00072 } 00073 00074 // Is there a PATH_INFO variable? 00075 // Note: some servers seem to have trouble with getenv() so we'll test it two ways 00076 $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); 00077 if (trim($path, '/') != '' && $path != "/".SELF) 00078 { 00079 $this->uri_string = $path; 00080 return; 00081 } 00082 00083 // No PATH_INFO?... What about QUERY_STRING? 00084 $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); 00085 if (trim($path, '/') != '') 00086 { 00087 $this->uri_string = $path; 00088 return; 00089 } 00090 00091 // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists? 00092 $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); 00093 if (trim($path, '/') != '' && $path != "/".SELF) 00094 { 00095 // remove path and script information so we have good URI data 00096 $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path); 00097 return; 00098 } 00099 00100 // We've exhausted all our options... 00101 $this->uri_string = ''; 00102 } 00103 else 00104 { 00105 $uri = strtoupper($this->config->item('uri_protocol')); 00106 00107 if ($uri == 'REQUEST_URI') 00108 { 00109 $this->uri_string = $this->_parse_request_uri(); 00110 return; 00111 } 00112 00113 $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri); 00114 } 00115 00116 // If the URI contains only a slash we'll kill it 00117 if ($this->uri_string == '/') 00118 { 00119 $this->uri_string = ''; 00120 } 00121 }

| CI_URI::_filter_uri | ( | $ | str | ) |
Filter segments for malicious characters.
private
| string |
Definition at line 185 of file URI.php.
Referenced by _explode_segments().
00186 { 00187 if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE) 00188 { 00189 if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str)) 00190 { 00191 exit('The URI you submitted has disallowed characters.'); 00192 } 00193 } 00194 00195 // Convert programatic characters to entities 00196 $bad = array('$', '(', ')', '%28', '%29'); 00197 $good = array('$', '(', ')', '(', ')'); 00198 00199 return str_replace($bad, $good, $str); 00200 }

| CI_URI::_parse_request_uri | ( | ) |
Parse the REQUEST_URI.
Due to the way REQUEST_URI works it usually contains path info that makes it unusable as URI data. We'll trim off the unnecessary data, hopefully arriving at a valid URI that we can use.
private
Definition at line 135 of file URI.php.
Referenced by _fetch_uri_string().
00136 { 00137 if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '') 00138 { 00139 return ''; 00140 } 00141 00142 $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI'])); 00143 00144 if ($request_uri == '' OR $request_uri == SELF) 00145 { 00146 return ''; 00147 } 00148 00149 $fc_path = FCPATH; 00150 if (strpos($request_uri, '?') !== FALSE) 00151 { 00152 $fc_path .= '?'; 00153 } 00154 00155 $parsed_uri = explode("/", $request_uri); 00156 00157 $i = 0; 00158 foreach(explode("/", $fc_path) as $segment) 00159 { 00160 if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i]) 00161 { 00162 $i++; 00163 } 00164 } 00165 00166 $parsed_uri = implode("/", array_slice($parsed_uri, $i)); 00167 00168 if ($parsed_uri != '') 00169 { 00170 $parsed_uri = '/'.$parsed_uri; 00171 } 00172 00173 return $parsed_uri; 00174 }

| CI_URI::_reindex_segments | ( | ) |
Re-index Segments.
This function re-indexes the $this->segment array so that it starts at 1 rather than 0. Doing so makes it simpler to use functions like $this->uri->segment(n) since there is a 1:1 relationship between the segment array and the actual segments.
private
Definition at line 253 of file URI.php.
00254 { 00255 array_unshift($this->segments, NULL); 00256 array_unshift($this->rsegments, NULL); 00257 unset($this->segments[0]); 00258 unset($this->rsegments[0]); 00259 }
| CI_URI::_remove_url_suffix | ( | ) |
Remove the suffix from the URL if needed.
private
Definition at line 210 of file URI.php.
References uri_string().
00211 { 00212 if ($this->config->item('url_suffix') != "") 00213 { 00214 $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string); 00215 } 00216 }

| CI_URI::_slash_segment | ( | $ | n, | |
| $ | where = 'trailing', |
|||
| $ | which = 'segment' | |||
| ) |
Fetch a URI Segment and add a trailing slash - helper function.
private
| integer | ||
| string | ||
| string |
Definition at line 481 of file URI.php.
Referenced by slash_rsegment(), and slash_segment().
00482 { 00483 if ($where == 'trailing') 00484 { 00485 $trailing = '/'; 00486 $leading = ''; 00487 } 00488 elseif ($where == 'leading') 00489 { 00490 $leading = '/'; 00491 $trailing = ''; 00492 } 00493 else 00494 { 00495 $leading = '/'; 00496 $trailing = '/'; 00497 } 00498 return $leading.$this->$which($n).$trailing; 00499 }

| CI_URI::_uri_to_assoc | ( | $ | n = 3, |
|
| $ | default = array(), |
|||
| $ | which = 'segment' | |||
| ) |
Generate a key value pair from the URI string or Re-routed URI string.
private
| integer | the starting segment number | |
| array | an array of default values | |
| string | which array we should use |
Definition at line 344 of file URI.php.
References $segments.
Referenced by ruri_to_assoc(), and uri_to_assoc().
00345 { 00346 if ($which == 'segment') 00347 { 00348 $total_segments = 'total_segments'; 00349 $segment_array = 'segment_array'; 00350 } 00351 else 00352 { 00353 $total_segments = 'total_rsegments'; 00354 $segment_array = 'rsegment_array'; 00355 } 00356 00357 if ( ! is_numeric($n)) 00358 { 00359 return $default; 00360 } 00361 00362 if (isset($this->keyval[$n])) 00363 { 00364 return $this->keyval[$n]; 00365 } 00366 00367 if ($this->$total_segments() < $n) 00368 { 00369 if (count($default) == 0) 00370 { 00371 return array(); 00372 } 00373 00374 $retval = array(); 00375 foreach ($default as $val) 00376 { 00377 $retval[$val] = FALSE; 00378 } 00379 return $retval; 00380 } 00381 00382 $segments = array_slice($this->$segment_array(), ($n - 1)); 00383 00384 $i = 0; 00385 $lastval = ''; 00386 $retval = array(); 00387 foreach ($segments as $seg) 00388 { 00389 if ($i % 2) 00390 { 00391 $retval[$lastval] = $seg; 00392 } 00393 else 00394 { 00395 $retval[$seg] = FALSE; 00396 $lastval = $seg; 00397 } 00398 00399 $i++; 00400 } 00401 00402 if (count($default) > 0) 00403 { 00404 foreach ($default as $val) 00405 { 00406 if ( ! array_key_exists($val, $retval)) 00407 { 00408 $retval[$val] = FALSE; 00409 } 00410 } 00411 } 00412 00413 // Cache the array for reuse 00414 $this->keyval[$n] = $retval; 00415 return $retval; 00416 }

| CI_URI::assoc_to_uri | ( | $ | array | ) |
Generate a URI string from an associative array.
public
| array | an associative array of key/values |
Definition at line 428 of file URI.php.
00429 { 00430 $temp = array(); 00431 foreach ((array)$array as $key => $val) 00432 { 00433 $temp[] = $key; 00434 $temp[] = $val; 00435 } 00436 00437 return implode('/', $temp); 00438 }
| CI_URI::CI_URI | ( | ) |
Constructor.
Simply globalizes the $RTR object. The front loads the Router class early on so it's not available normally as other classes are.
public
Definition at line 45 of file URI.php.
References load_class(), and log_message().
00046 { 00047 $this->config =& load_class('Config'); 00048 log_message('debug', "URI Class Initialized"); 00049 }

| CI_URI::rsegment | ( | $ | n, | |
| $ | no_result = FALSE | |||
| ) |
Fetch a URI "routed" Segment.
This function returns the re-routed URI segment (assuming routing rules are used) based on the number provided. If there is no routing this function returns the same result as $this->segment()
public
| integer | ||
| bool |
Definition at line 292 of file URI.php.
| CI_URI::rsegment_array | ( | ) |
Routed Segment Array.
public
Definition at line 522 of file URI.php.
Referenced by ruri_string().

| CI_URI::ruri_string | ( | ) |
Fetch the entire Re-routed URI string.
public
Definition at line 575 of file URI.php.
References rsegment_array().
00576 { 00577 return '/'.implode('/', $this->rsegment_array()).'/'; 00578 }

| CI_URI::ruri_to_assoc | ( | $ | n = 3, |
|
| $ | default = array() | |||
| ) |
Identical to above only it uses the re-routed segment array.
Definition at line 328 of file URI.php.
References _uri_to_assoc().
00329 { 00330 return $this->_uri_to_assoc($n, $default, 'rsegment'); 00331 }

| CI_URI::segment | ( | $ | n, | |
| $ | no_result = FALSE | |||
| ) |
| CI_URI::segment_array | ( | ) |
| CI_URI::slash_rsegment | ( | $ | n, | |
| $ | where = 'trailing' | |||
| ) |
Fetch a URI Segment and add a trailing slash.
public
| integer | ||
| string |
Definition at line 465 of file URI.php.
References _slash_segment().
00466 { 00467 return $this->_slash_segment($n, $where, 'rsegment'); 00468 }

| CI_URI::slash_segment | ( | $ | n, | |
| $ | where = 'trailing' | |||
| ) |
Fetch a URI Segment and add a trailing slash.
public
| integer | ||
| string |
Definition at line 450 of file URI.php.
References _slash_segment().
00451 { 00452 return $this->_slash_segment($n, $where, 'segment'); 00453 }

| CI_URI::total_rsegments | ( | ) |
| CI_URI::total_segments | ( | ) |
| CI_URI::uri_string | ( | ) |
Fetch the entire URI string.
public
Definition at line 561 of file URI.php.
Referenced by _explode_segments(), _fetch_uri_string(), and _remove_url_suffix().
00562 { 00563 return $this->uri_string; 00564 }

| CI_URI::uri_to_assoc | ( | $ | n = 3, |
|
| $ | default = array() | |||
| ) |
Generate a key value pair from the URI string.
This function generates and associative array of URI data starting at the supplied segment. For example, if this is your URI:
example.com/user/search/name/joe/location/UK/gender/male
You can use this function to generate an array with this prototype:
array ( name => joe location => UK gender => male )
public
| integer | the starting segment number | |
| array | an array of default values |
Definition at line 320 of file URI.php.
References _uri_to_assoc().
00321 { 00322 return $this->_uri_to_assoc($n, $default, 'segment'); 00323 }

| CI_URI::$segments = array() |