-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package CodeIgniter\r
- * @author ExpressionEngine Dev Team\r
- * @copyright Copyright (c) 2008, EllisLab, Inc.\r
- * @license http://codeigniter.com/user_guide/license.html\r
- * @link http://codeigniter.com\r
- * @since Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * URI Class\r
- *\r
- * Parses URIs and determines routing\r
- *\r
- * @package CodeIgniter\r
- * @subpackage Libraries\r
- * @category URI\r
- * @author ExpressionEngine Dev Team\r
- * @link http://codeigniter.com/user_guide/libraries/uri.html\r
- */\r
-class CI_URI {\r
-\r
- var $keyval = array();\r
- var $uri_string;\r
- var $segments = array();\r
- var $rsegments = array();\r
-\r
- /**\r
- * Constructor\r
- *\r
- * Simply globalizes the $RTR object. The front\r
- * loads the Router class early on so it's not available\r
- * normally as other classes are.\r
- *\r
- * @access public\r
- */ \r
- function CI_URI()\r
- {\r
- $this->config =& load_class('Config');\r
- log_message('debug', "URI Class Initialized");\r
- }\r
- \r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Get the URI String\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _fetch_uri_string()\r
- {\r
- if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')\r
- {\r
- // If the URL has a question mark then it's simplest to just\r
- // build the URI string from the zero index of the $_GET array.\r
- // This avoids having to deal with $_SERVER variables, which\r
- // can be unreliable in some environments\r
- if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')\r
- {\r
- $this->uri_string = key($_GET);\r
- return;\r
- }\r
- \r
- // Is there a PATH_INFO variable?\r
- // Note: some servers seem to have trouble with getenv() so we'll test it two ways \r
- $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO'); \r
- if (trim($path, '/') != '' && $path != "/".SELF)\r
- {\r
- $this->uri_string = $path;\r
- return;\r
- }\r
- \r
- // No PATH_INFO?... What about QUERY_STRING?\r
- $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING'); \r
- if (trim($path, '/') != '')\r
- {\r
- $this->uri_string = $path;\r
- return;\r
- }\r
- \r
- // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?\r
- $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO'); \r
- if (trim($path, '/') != '' && $path != "/".SELF)\r
- {\r
- // remove path and script information so we have good URI data\r
- $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);\r
- return;\r
- }\r
-\r
- // We've exhausted all our options...\r
- $this->uri_string = '';\r
- }\r
- else\r
- {\r
- $uri = strtoupper($this->config->item('uri_protocol'));\r
- \r
- if ($uri == 'REQUEST_URI')\r
- {\r
- $this->uri_string = $this->_parse_request_uri();\r
- return;\r
- }\r
- \r
- $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);\r
- }\r
- \r
- // If the URI contains only a slash we'll kill it\r
- if ($this->uri_string == '/')\r
- {\r
- $this->uri_string = '';\r
- } \r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Parse the REQUEST_URI\r
- *\r
- * Due to the way REQUEST_URI works it usually contains path info\r
- * that makes it unusable as URI data. We'll trim off the unnecessary\r
- * data, hopefully arriving at a valid URI that we can use.\r
- *\r
- * @access private\r
- * @return string\r
- */ \r
- function _parse_request_uri()\r
- {\r
- if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '')\r
- {\r
- return '';\r
- }\r
- \r
- $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI']));\r
-\r
- if ($request_uri == '' OR $request_uri == SELF)\r
- {\r
- return '';\r
- }\r
- \r
- $fc_path = FCPATH; \r
- if (strpos($request_uri, '?') !== FALSE)\r
- {\r
- $fc_path .= '?';\r
- }\r
- \r
- $parsed_uri = explode("/", $request_uri);\r
- \r
- $i = 0;\r
- foreach(explode("/", $fc_path) as $segment)\r
- {\r
- if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i])\r
- {\r
- $i++;\r
- }\r
- }\r
- \r
- $parsed_uri = implode("/", array_slice($parsed_uri, $i));\r
- \r
- if ($parsed_uri != '')\r
- {\r
- $parsed_uri = '/'.$parsed_uri;\r
- }\r
-\r
- return $parsed_uri;\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Filter segments for malicious characters\r
- *\r
- * @access private\r
- * @param string\r
- * @return string\r
- */ \r
- function _filter_uri($str)\r
- {\r
- if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)\r
- {\r
- if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))\r
- {\r
- exit('The URI you submitted has disallowed characters.');\r
- }\r
- } \r
- \r
- // Convert programatic characters to entities\r
- $bad = array('$', '(', ')', '%28', '%29');\r
- $good = array('$', '(', ')', '(', ')');\r
- \r
- return str_replace($bad, $good, $str);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Remove the suffix from the URL if needed\r
- *\r
- * @access private\r
- * @return void\r
- */ \r
- function _remove_url_suffix()\r
- {\r
- if ($this->config->item('url_suffix') != "")\r
- {\r
- $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);\r
- }\r
- }\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Explode the URI Segments. The individual segments will\r
- * be stored in the $this->segments array. \r
- *\r
- * @access private\r
- * @return void\r
- */ \r
- function _explode_segments()\r
- {\r
- foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)\r
- {\r
- // Filter segments for security\r
- $val = trim($this->_filter_uri($val));\r
- \r
- if ($val != '')\r
- {\r
- $this->segments[] = $val;\r
- }\r
- }\r
- }\r
- \r
- // -------------------------------------------------------------------- \r
- /**\r
- * Re-index Segments\r
- *\r
- * This function re-indexes the $this->segment array so that it\r
- * starts at 1 rather than 0. Doing so makes it simpler to\r
- * use functions like $this->uri->segment(n) since there is\r
- * a 1:1 relationship between the segment array and the actual segments.\r
- *\r
- * @access private\r
- * @return void\r
- */ \r
- function _reindex_segments()\r
- {\r
- array_unshift($this->segments, NULL);\r
- array_unshift($this->rsegments, NULL);\r
- unset($this->segments[0]);\r
- unset($this->rsegments[0]);\r
- } \r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch a URI Segment\r
- *\r
- * This function returns the URI segment based on the number provided.\r
- *\r
- * @access public\r
- * @param integer\r
- * @param bool\r
- * @return string\r
- */\r
- function segment($n, $no_result = FALSE)\r
- {\r
- return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch a URI "routed" Segment\r
- *\r
- * This function returns the re-routed URI segment (assuming routing rules are used)\r
- * based on the number provided. If there is no routing this function returns the\r
- * same result as $this->segment()\r
- *\r
- * @access public\r
- * @param integer\r
- * @param bool\r
- * @return string\r
- */\r
- function rsegment($n, $no_result = FALSE)\r
- {\r
- return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Generate a key value pair from the URI string\r
- *\r
- * This function generates and associative array of URI data starting\r
- * at the supplied segment. For example, if this is your URI:\r
- *\r
- * example.com/user/search/name/joe/location/UK/gender/male\r
- *\r
- * You can use this function to generate an array with this prototype:\r
- *\r
- * array (\r
- * name => joe\r
- * location => UK\r
- * gender => male\r
- * )\r
- *\r
- * @access public\r
- * @param integer the starting segment number\r
- * @param array an array of default values\r
- * @return array\r
- */\r
- function uri_to_assoc($n = 3, $default = array())\r
- {\r
- return $this->_uri_to_assoc($n, $default, 'segment');\r
- }\r
- /**\r
- * Identical to above only it uses the re-routed segment array\r
- *\r
- */\r
- function ruri_to_assoc($n = 3, $default = array())\r
- {\r
- return $this->_uri_to_assoc($n, $default, 'rsegment');\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Generate a key value pair from the URI string or Re-routed URI string\r
- *\r
- * @access private\r
- * @param integer the starting segment number\r
- * @param array an array of default values\r
- * @param string which array we should use\r
- * @return array\r
- */\r
- function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')\r
- {\r
- if ($which == 'segment')\r
- {\r
- $total_segments = 'total_segments';\r
- $segment_array = 'segment_array';\r
- }\r
- else\r
- {\r
- $total_segments = 'total_rsegments';\r
- $segment_array = 'rsegment_array';\r
- }\r
- \r
- if ( ! is_numeric($n))\r
- {\r
- return $default;\r
- }\r
- \r
- if (isset($this->keyval[$n]))\r
- {\r
- return $this->keyval[$n];\r
- }\r
- \r
- if ($this->$total_segments() < $n)\r
- {\r
- if (count($default) == 0)\r
- {\r
- return array();\r
- }\r
- \r
- $retval = array();\r
- foreach ($default as $val)\r
- {\r
- $retval[$val] = FALSE;\r
- } \r
- return $retval;\r
- }\r
-\r
- $segments = array_slice($this->$segment_array(), ($n - 1));\r
-\r
- $i = 0;\r
- $lastval = '';\r
- $retval = array();\r
- foreach ($segments as $seg)\r
- {\r
- if ($i % 2)\r
- {\r
- $retval[$lastval] = $seg;\r
- }\r
- else\r
- {\r
- $retval[$seg] = FALSE;\r
- $lastval = $seg;\r
- }\r
- \r
- $i++;\r
- }\r
-\r
- if (count($default) > 0)\r
- {\r
- foreach ($default as $val)\r
- {\r
- if ( ! array_key_exists($val, $retval))\r
- {\r
- $retval[$val] = FALSE;\r
- }\r
- }\r
- }\r
-\r
- // Cache the array for reuse\r
- $this->keyval[$n] = $retval;\r
- return $retval;\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Generate a URI string from an associative array\r
- *\r
- *\r
- * @access public\r
- * @param array an associative array of key/values\r
- * @return array\r
- */ \r
- function assoc_to_uri($array)\r
- { \r
- $temp = array();\r
- foreach ((array)$array as $key => $val)\r
- {\r
- $temp[] = $key;\r
- $temp[] = $val;\r
- }\r
- \r
- return implode('/', $temp);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch a URI Segment and add a trailing slash\r
- *\r
- * @access public\r
- * @param integer\r
- * @param string\r
- * @return string\r
- */\r
- function slash_segment($n, $where = 'trailing')\r
- {\r
- return $this->_slash_segment($n, $where, 'segment');\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch a URI Segment and add a trailing slash\r
- *\r
- * @access public\r
- * @param integer\r
- * @param string\r
- * @return string\r
- */\r
- function slash_rsegment($n, $where = 'trailing')\r
- {\r
- return $this->_slash_segment($n, $where, 'rsegment');\r
- }\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch a URI Segment and add a trailing slash - helper function\r
- *\r
- * @access private\r
- * @param integer\r
- * @param string\r
- * @param string\r
- * @return string\r
- */\r
- function _slash_segment($n, $where = 'trailing', $which = 'segment')\r
- { \r
- if ($where == 'trailing')\r
- {\r
- $trailing = '/';\r
- $leading = '';\r
- }\r
- elseif ($where == 'leading')\r
- {\r
- $leading = '/';\r
- $trailing = '';\r
- }\r
- else\r
- {\r
- $leading = '/';\r
- $trailing = '/';\r
- }\r
- return $leading.$this->$which($n).$trailing;\r
- }\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Segment Array\r
- *\r
- * @access public\r
- * @return array\r
- */\r
- function segment_array()\r
- {\r
- return $this->segments;\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Routed Segment Array\r
- *\r
- * @access public\r
- * @return array\r
- */\r
- function rsegment_array()\r
- {\r
- return $this->rsegments;\r
- }\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Total number of segments\r
- *\r
- * @access public\r
- * @return integer\r
- */\r
- function total_segments()\r
- {\r
- return count($this->segments);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Total number of routed segments\r
- *\r
- * @access public\r
- * @return integer\r
- */\r
- function total_rsegments()\r
- {\r
- return count($this->rsegments);\r
- }\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch the entire URI string\r
- *\r
- * @access public\r
- * @return string\r
- */\r
- function uri_string()\r
- {\r
- return $this->uri_string;\r
- }\r
-\r
- \r
- // --------------------------------------------------------------------\r
- \r
- /**\r
- * Fetch the entire Re-routed URI string\r
- *\r
- * @access public\r
- * @return string\r
- */\r
- function ruri_string()\r
- {\r
- return '/'.implode('/', $this->rsegment_array()).'/';\r
- }\r
-\r
-}\r
-// END URI Class\r
-\r
-/* End of file URI.php */\r
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2008, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * URI Class
+ *
+ * Parses URIs and determines routing
+ *
+ * @package CodeIgniter
+ * @subpackage Libraries
+ * @category URI
+ * @author ExpressionEngine Dev Team
+ * @link http://codeigniter.com/user_guide/libraries/uri.html
+ */
+class CI_URI {
+
+ var $keyval = array();
+ var $uri_string;
+ var $segments = array();
+ var $rsegments = array();
+
+ /**
+ * Constructor
+ *
+ * Simply globalizes the $RTR object. The front
+ * loads the Router class early on so it's not available
+ * normally as other classes are.
+ *
+ * @access public
+ */
+ function CI_URI()
+ {
+ $this->config =& load_class('Config');
+ log_message('debug', "URI Class Initialized");
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Get the URI String
+ *
+ * @access private
+ * @return string
+ */
+ function _fetch_uri_string()
+ {
+ if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
+ {
+ // If the URL has a question mark then it's simplest to just
+ // build the URI string from the zero index of the $_GET array.
+ // This avoids having to deal with $_SERVER variables, which
+ // can be unreliable in some environments
+ if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
+ {
+ $this->uri_string = key($_GET);
+ return;
+ }
+
+ // Is there a PATH_INFO variable?
+ // Note: some servers seem to have trouble with getenv() so we'll test it two ways
+ $path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
+ if (trim($path, '/') != '' && $path != "/".SELF)
+ {
+ $this->uri_string = $path;
+ return;
+ }
+
+ // No PATH_INFO?... What about QUERY_STRING?
+ $path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
+ if (trim($path, '/') != '')
+ {
+ $this->uri_string = $path;
+ return;
+ }
+
+ // No QUERY_STRING?... Maybe the ORIG_PATH_INFO variable exists?
+ $path = (isset($_SERVER['ORIG_PATH_INFO'])) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
+ if (trim($path, '/') != '' && $path != "/".SELF)
+ {
+ // remove path and script information so we have good URI data
+ $this->uri_string = str_replace($_SERVER['SCRIPT_NAME'], '', $path);
+ return;
+ }
+
+ // We've exhausted all our options...
+ $this->uri_string = '';
+ }
+ else
+ {
+ $uri = strtoupper($this->config->item('uri_protocol'));
+
+ if ($uri == 'REQUEST_URI')
+ {
+ $this->uri_string = $this->_parse_request_uri();
+ return;
+ }
+
+ $this->uri_string = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
+ }
+
+ // If the URI contains only a slash we'll kill it
+ if ($this->uri_string == '/')
+ {
+ $this->uri_string = '';
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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.
+ *
+ * @access private
+ * @return string
+ */
+ function _parse_request_uri()
+ {
+ if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '')
+ {
+ return '';
+ }
+
+ $request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $_SERVER['REQUEST_URI']));
+
+ if ($request_uri == '' OR $request_uri == SELF)
+ {
+ return '';
+ }
+
+ $fc_path = FCPATH;
+ if (strpos($request_uri, '?') !== FALSE)
+ {
+ $fc_path .= '?';
+ }
+
+ $parsed_uri = explode("/", $request_uri);
+
+ $i = 0;
+ foreach(explode("/", $fc_path) as $segment)
+ {
+ if (isset($parsed_uri[$i]) && $segment == $parsed_uri[$i])
+ {
+ $i++;
+ }
+ }
+
+ $parsed_uri = implode("/", array_slice($parsed_uri, $i));
+
+ if ($parsed_uri != '')
+ {
+ $parsed_uri = '/'.$parsed_uri;
+ }
+
+ return $parsed_uri;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Filter segments for malicious characters
+ *
+ * @access private
+ * @param string
+ * @return string
+ */
+ function _filter_uri($str)
+ {
+ if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
+ {
+ if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
+ {
+ exit('The URI you submitted has disallowed characters.');
+ }
+ }
+
+ // Convert programatic characters to entities
+ $bad = array('$', '(', ')', '%28', '%29');
+ $good = array('$', '(', ')', '(', ')');
+
+ return str_replace($bad, $good, $str);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Remove the suffix from the URL if needed
+ *
+ * @access private
+ * @return void
+ */
+ function _remove_url_suffix()
+ {
+ if ($this->config->item('url_suffix') != "")
+ {
+ $this->uri_string = preg_replace("|".preg_quote($this->config->item('url_suffix'))."$|", "", $this->uri_string);
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Explode the URI Segments. The individual segments will
+ * be stored in the $this->segments array.
+ *
+ * @access private
+ * @return void
+ */
+ function _explode_segments()
+ {
+ foreach(explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val)
+ {
+ // Filter segments for security
+ $val = trim($this->_filter_uri($val));
+
+ if ($val != '')
+ {
+ $this->segments[] = $val;
+ }
+ }
+ }
+
+ // --------------------------------------------------------------------
+ /**
+ * 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.
+ *
+ * @access private
+ * @return void
+ */
+ function _reindex_segments()
+ {
+ array_unshift($this->segments, NULL);
+ array_unshift($this->rsegments, NULL);
+ unset($this->segments[0]);
+ unset($this->rsegments[0]);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch a URI Segment
+ *
+ * This function returns the URI segment based on the number provided.
+ *
+ * @access public
+ * @param integer
+ * @param bool
+ * @return string
+ */
+ function segment($n, $no_result = FALSE)
+ {
+ return ( ! isset($this->segments[$n])) ? $no_result : $this->segments[$n];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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()
+ *
+ * @access public
+ * @param integer
+ * @param bool
+ * @return string
+ */
+ function rsegment($n, $no_result = FALSE)
+ {
+ return ( ! isset($this->rsegments[$n])) ? $no_result : $this->rsegments[$n];
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * 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
+ * )
+ *
+ * @access public
+ * @param integer the starting segment number
+ * @param array an array of default values
+ * @return array
+ */
+ function uri_to_assoc($n = 3, $default = array())
+ {
+ return $this->_uri_to_assoc($n, $default, 'segment');
+ }
+ /**
+ * Identical to above only it uses the re-routed segment array
+ *
+ */
+ function ruri_to_assoc($n = 3, $default = array())
+ {
+ return $this->_uri_to_assoc($n, $default, 'rsegment');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Generate a key value pair from the URI string or Re-routed URI string
+ *
+ * @access private
+ * @param integer the starting segment number
+ * @param array an array of default values
+ * @param string which array we should use
+ * @return array
+ */
+ function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
+ {
+ if ($which == 'segment')
+ {
+ $total_segments = 'total_segments';
+ $segment_array = 'segment_array';
+ }
+ else
+ {
+ $total_segments = 'total_rsegments';
+ $segment_array = 'rsegment_array';
+ }
+
+ if ( ! is_numeric($n))
+ {
+ return $default;
+ }
+
+ if (isset($this->keyval[$n]))
+ {
+ return $this->keyval[$n];
+ }
+
+ if ($this->$total_segments() < $n)
+ {
+ if (count($default) == 0)
+ {
+ return array();
+ }
+
+ $retval = array();
+ foreach ($default as $val)
+ {
+ $retval[$val] = FALSE;
+ }
+ return $retval;
+ }
+
+ $segments = array_slice($this->$segment_array(), ($n - 1));
+
+ $i = 0;
+ $lastval = '';
+ $retval = array();
+ foreach ($segments as $seg)
+ {
+ if ($i % 2)
+ {
+ $retval[$lastval] = $seg;
+ }
+ else
+ {
+ $retval[$seg] = FALSE;
+ $lastval = $seg;
+ }
+
+ $i++;
+ }
+
+ if (count($default) > 0)
+ {
+ foreach ($default as $val)
+ {
+ if ( ! array_key_exists($val, $retval))
+ {
+ $retval[$val] = FALSE;
+ }
+ }
+ }
+
+ // Cache the array for reuse
+ $this->keyval[$n] = $retval;
+ return $retval;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Generate a URI string from an associative array
+ *
+ *
+ * @access public
+ * @param array an associative array of key/values
+ * @return array
+ */
+ function assoc_to_uri($array)
+ {
+ $temp = array();
+ foreach ((array)$array as $key => $val)
+ {
+ $temp[] = $key;
+ $temp[] = $val;
+ }
+
+ return implode('/', $temp);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch a URI Segment and add a trailing slash
+ *
+ * @access public
+ * @param integer
+ * @param string
+ * @return string
+ */
+ function slash_segment($n, $where = 'trailing')
+ {
+ return $this->_slash_segment($n, $where, 'segment');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch a URI Segment and add a trailing slash
+ *
+ * @access public
+ * @param integer
+ * @param string
+ * @return string
+ */
+ function slash_rsegment($n, $where = 'trailing')
+ {
+ return $this->_slash_segment($n, $where, 'rsegment');
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch a URI Segment and add a trailing slash - helper function
+ *
+ * @access private
+ * @param integer
+ * @param string
+ * @param string
+ * @return string
+ */
+ function _slash_segment($n, $where = 'trailing', $which = 'segment')
+ {
+ if ($where == 'trailing')
+ {
+ $trailing = '/';
+ $leading = '';
+ }
+ elseif ($where == 'leading')
+ {
+ $leading = '/';
+ $trailing = '';
+ }
+ else
+ {
+ $leading = '/';
+ $trailing = '/';
+ }
+ return $leading.$this->$which($n).$trailing;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Segment Array
+ *
+ * @access public
+ * @return array
+ */
+ function segment_array()
+ {
+ return $this->segments;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Routed Segment Array
+ *
+ * @access public
+ * @return array
+ */
+ function rsegment_array()
+ {
+ return $this->rsegments;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Total number of segments
+ *
+ * @access public
+ * @return integer
+ */
+ function total_segments()
+ {
+ return count($this->segments);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Total number of routed segments
+ *
+ * @access public
+ * @return integer
+ */
+ function total_rsegments()
+ {
+ return count($this->rsegments);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch the entire URI string
+ *
+ * @access public
+ * @return string
+ */
+ function uri_string()
+ {
+ return $this->uri_string;
+ }
+
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Fetch the entire Re-routed URI string
+ *
+ * @access public
+ * @return string
+ */
+ function ruri_string()
+ {
+ return '/'.implode('/', $this->rsegment_array()).'/';
+ }
+
+}
+// END URI Class
+
+/* End of file URI.php */
/* Location: ./system/libraries/URI.php */
\ No newline at end of file