summaryrefslogtreecommitdiffstats
path: root/system/core/URI.php
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-05-08 17:23:36 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-05-08 17:23:36 +0200
commit0854d91fd2848266ec37a37c8a1ccfd13a8a4eda (patch)
tree1433f1db86920fae6e6286c6cc517ba64cda2aba /system/core/URI.php
parent0cb8c59f91567af9aa6530f8764abafe1ae935c0 (diff)
parent3ef65bd7491f847fecdab1acc9687f0e90eee09b (diff)
Merged tip.
Diffstat (limited to 'system/core/URI.php')
-rw-r--r--system/core/URI.php77
1 files changed, 44 insertions, 33 deletions
diff --git a/system/core/URI.php b/system/core/URI.php
index c43cde005..94fac59ac 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
@@ -36,7 +36,7 @@ class CI_URI {
/**
* Constructor
*
- * Simply globalizes the $RTR object. The front
+ * Simply globalizes the $RTR object. The front
* loads the Router class early on so it's not available
* normally as other classes are.
*
@@ -64,14 +64,14 @@ class CI_URI {
// Is the request coming from the command line?
if (defined('STDIN'))
{
- $this->uri_string = $this->_parse_cli_args();
+ $this->_set_uri_string($this->_parse_cli_args());
return;
}
// Let's try the REQUEST_URI first, this will work in most situations
if ($uri = $this->_detect_uri())
{
- $this->uri_string = $uri;
+ $this->_set_uri_string($uri);
return;
}
@@ -80,51 +80,62 @@ class CI_URI {
$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
if (trim($path, '/') != '' && $path != "/".SELF)
{
- $this->uri_string = $path;
+ $this->_set_uri_string($path);
return;
}
// No PATH_INFO?... What about QUERY_STRING?
- $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+ $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') != '')
{
- $this->uri_string = $path;
+ $this->_set_uri_string($path);
return;
}
// As a last ditch effort lets try using the $_GET array
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
{
- $this->uri_string = key($_GET);
+ $this->_set_uri_string(key($_GET));
return;
}
// We've exhausted all our options...
$this->uri_string = '';
+ return;
}
- else
- {
- $uri = strtoupper($this->config->item('uri_protocol'));
- if ($uri == 'REQUEST_URI')
- {
- $this->uri_string = $this->_detect_uri();
- return;
- }
- elseif ($uri == 'CLI')
- {
- $this->uri_string = $this->_parse_cli_args();
- return;
- }
+ $uri = strtoupper($this->config->item('uri_protocol'));
- $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
+ if ($uri == 'REQUEST_URI')
+ {
+ $this->_set_uri_string($this->_detect_uri());
+ return;
}
-
- // If the URI contains only a slash we'll kill it
- if ($this->uri_string == '/')
+ elseif ($uri == 'CLI')
{
- $this->uri_string = '';
+ $this->_set_uri_string($this->_parse_cli_args());
+ return;
}
+
+ $path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
+ $this->_set_uri_string($path);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set the URI String
+ *
+ * @access public
+ * @return string
+ */
+ function _set_uri_string($str)
+ {
+ // Filter out control characters
+ $str = remove_invisible_characters($str, FALSE);
+
+ // If the URI contains only a slash we'll kill it
+ $this->uri_string = ($str == '/') ? '' : $str;
}
// --------------------------------------------------------------------
@@ -140,7 +151,7 @@ class CI_URI {
*/
private function _detect_uri()
{
- if ( ! isset($_SERVER['REQUEST_URI']))
+ if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
{
return '';
}
@@ -173,12 +184,12 @@ class CI_URI {
$_SERVER['QUERY_STRING'] = '';
$_GET = array();
}
-
+
if ($uri == '/' || empty($uri))
{
return '/';
}
-
+
$uri = parse_url($uri, PHP_URL_PATH);
// Do some final cleaning of the URI and return it
@@ -240,7 +251,7 @@ class CI_URI {
*/
function _remove_url_suffix()
{
- if ($this->config->item('url_suffix') != "")
+ if ($this->config->item('url_suffix') != "")
{
$this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
}
@@ -274,7 +285,7 @@ class CI_URI {
* 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
+ * 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.
*
@@ -312,7 +323,7 @@ class CI_URI {
* 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
+ * based on the number provided. If there is no routing this function returns the
* same result as $this->segment()
*
* @access public
@@ -414,7 +425,7 @@ class CI_URI {
$i = 0;
$lastval = '';
- $retval = array();
+ $retval = array();
foreach ($segments as $seg)
{
if ($i % 2)