-<?php
-// +-----------------------------------------------------------------------+
-// | Copyright (c) 2002-2004, Richard Heyes |
-// | All rights reserved. |
-// | |
-// | Redistribution and use in source and binary forms, with or without |
-// | modification, are permitted provided that the following conditions |
-// | are met: |
-// | |
-// | o Redistributions of source code must retain the above copyright |
-// | notice, this list of conditions and the following disclaimer. |
-// | o Redistributions in binary form must reproduce the above copyright |
-// | notice, this list of conditions and the following disclaimer in the |
-// | documentation and/or other materials provided with the distribution.|
-// | o The names of the authors may not be used to endorse or promote |
-// | products derived from this software without specific prior written |
-// | permission. |
-// | |
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
-// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// | |
-// +-----------------------------------------------------------------------+
-// | Author: Richard Heyes <richard at php net> |
-// +-----------------------------------------------------------------------+
-//
-// $Id: URL.php,v 1.1 2008-05-04 07:04:50 hsur Exp $
-//
-// Net_URL Class
-
-class Net_URL
-{
- /**
- * Full url
- * @var string
- */
- var $url;
-
- /**
- * Protocol
- * @var string
- */
- var $protocol;
-
- /**
- * Username
- * @var string
- */
- var $username;
-
- /**
- * Password
- * @var string
- */
- var $password;
-
- /**
- * Host
- * @var string
- */
- var $host;
-
- /**
- * Port
- * @var integer
- */
- var $port;
-
- /**
- * Path
- * @var string
- */
- var $path;
-
- /**
- * Query string
- * @var array
- */
- var $querystring;
-
- /**
- * Anchor
- * @var string
- */
- var $anchor;
-
- /**
- * Whether to use []
- * @var bool
- */
- var $useBrackets;
-
- /**
- * PHP4 Constructor
- *
- * @see __construct()
- */
- function Net_URL($url = null, $useBrackets = true)
- {
- $this->__construct($url, $useBrackets);
- }
-
- /**
- * PHP5 Constructor
- *
- * Parses the given url and stores the various parts
- * Defaults are used in certain cases
- *
- * @param string $url Optional URL
- * @param bool $useBrackets Whether to use square brackets when
- * multiple querystrings with the same name
- * exist
- */
- function __construct($url = null, $useBrackets = true)
- {
- $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
-
- $this->useBrackets = $useBrackets;
- $this->url = $url;
- $this->user = '';
- $this->pass = '';
- $this->host = '';
- $this->port = 80;
- $this->path = '';
- $this->querystring = array();
- $this->anchor = '';
-
- // Only use defaults if not an absolute URL given
- if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
-
- $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
-
- /**
- * Figure out host/port
- */
- if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
- $host = $matches[1];
- if (!empty($matches[3])) {
- $port = $matches[3];
- } else {
- $port = $this->getStandardPort($this->protocol);
- }
- }
-
- $this->user = '';
- $this->pass = '';
- $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
- $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
- $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
- $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
- $this->anchor = '';
- }
-
- // Parse the url and store the various parts
- if (!empty($url)) {
- $urlinfo = parse_url($url);
-
- // Default querystring
- $this->querystring = array();
-
- foreach ($urlinfo as $key => $value) {
- switch ($key) {
- case 'scheme':
- $this->protocol = $value;
- $this->port = $this->getStandardPort($value);
- break;
-
- case 'user':
- case 'pass':
- case 'host':
- case 'port':
- $this->$key = $value;
- break;
-
- case 'path':
- if ($value{0} == '/') {
- $this->path = $value;
- } else {
- $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
- $this->path = sprintf('%s/%s', $path, $value);
- }
- break;
-
- case 'query':
- $this->querystring = $this->_parseRawQueryString($value);
- break;
-
- case 'fragment':
- $this->anchor = $value;
- break;
- }
- }
- }
- }
-
- /**
- * Returns full url
- *
- * @return string Full url
- * @access public
- */
- function getURL()
- {
- $querystring = $this->getQueryString();
-
- $this->url = $this->protocol . '://'
- . $this->user . (!empty($this->pass) ? ':' : '')
- . $this->pass . (!empty($this->user) ? '@' : '')
- . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
- . $this->path
- . (!empty($querystring) ? '?' . $querystring : '')
- . (!empty($this->anchor) ? '#' . $this->anchor : '');
-
- return $this->url;
- }
-
- /**
- * Adds a querystring item
- *
- * @param string $name Name of item
- * @param string $value Value of item
- * @param bool $preencoded Whether value is urlencoded or not, default = not
- * @access public
- */
- function addQueryString($name, $value, $preencoded = false)
- {
- if ($preencoded) {
- $this->querystring[$name] = $value;
- } else {
- $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
- }
- }
-
- /**
- * Removes a querystring item
- *
- * @param string $name Name of item
- * @access public
- */
- function removeQueryString($name)
- {
- if (isset($this->querystring[$name])) {
- unset($this->querystring[$name]);
- }
- }
-
- /**
- * Sets the querystring to literally what you supply
- *
- * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc
- * @access public
- */
- function addRawQueryString($querystring)
- {
- $this->querystring = $this->_parseRawQueryString($querystring);
- }
-
- /**
- * Returns flat querystring
- *
- * @return string Querystring
- * @access public
- */
- function getQueryString()
- {
- if (!empty($this->querystring)) {
- foreach ($this->querystring as $name => $value) {
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
- }
- } elseif (!is_null($value)) {
- $querystring[] = $name . '=' . $value;
- } else {
- $querystring[] = $name;
- }
- }
- $querystring = implode(ini_get('arg_separator.output'), $querystring);
- } else {
- $querystring = '';
- }
-
- return $querystring;
- }
-
- /**
- * Parses raw querystring and returns an array of it
- *
- * @param string $querystring The querystring to parse
- * @return array An array of the querystring data
- * @access private
- */
- function _parseRawQuerystring($querystring)
- {
- $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
- $return = array();
-
- foreach ($parts as $part) {
- if (strpos($part, '=') !== false) {
- $value = substr($part, strpos($part, '=') + 1);
- $key = substr($part, 0, strpos($part, '='));
- } else {
- $value = null;
- $key = $part;
- }
- if (substr($key, -2) == '[]') {
- $key = substr($key, 0, -2);
- if (@!is_array($return[$key])) {
- $return[$key] = array();
- $return[$key][] = $value;
- } else {
- $return[$key][] = $value;
- }
- } elseif (!$this->useBrackets AND !empty($return[$key])) {
- $return[$key] = (array)$return[$key];
- $return[$key][] = $value;
- } else {
- $return[$key] = $value;
- }
- }
-
- return $return;
- }
-
- /**
- * Resolves //, ../ and ./ from a path and returns
- * the result. Eg:
- *
- * /foo/bar/../boo.php => /foo/boo.php
- * /foo/bar/../../boo.php => /boo.php
- * /foo/bar/.././/boo.php => /foo/boo.php
- *
- * This method can also be called statically.
- *
- * @param string $url URL path to resolve
- * @return string The result
- */
- function resolvePath($path)
- {
- $path = explode('/', str_replace('//', '/', $path));
-
- for ($i=0; $i<count($path); $i++) {
- if ($path[$i] == '.') {
- unset($path[$i]);
- $path = array_values($path);
- $i--;
-
- } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
- unset($path[$i]);
- unset($path[$i-1]);
- $path = array_values($path);
- $i -= 2;
-
- } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
- unset($path[$i]);
- $path = array_values($path);
- $i--;
-
- } else {
- continue;
- }
- }
-
- return implode('/', $path);
- }
-
- /**
- * Returns the standard port number for a protocol
- *
- * @param string $scheme The protocol to lookup
- * @return integer Port number or NULL if no scheme matches
- *
- * @author Philippe Jausions <Philippe.Jausions@11abacus.com>
- */
- function getStandardPort($scheme)
- {
- switch (strtolower($scheme)) {
- case 'http': return 80;
- case 'https': return 443;
- case 'ftp': return 21;
- case 'imap': return 143;
- case 'imaps': return 993;
- case 'pop3': return 110;
- case 'pop3s': return 995;
- default: return null;
- }
- }
-
- /**
- * Forces the URL to a particular protocol
- *
- * @param string $protocol Protocol to force the URL to
- * @param integer $port Optional port (standard port is used by default)
- */
- function setProtocol($protocol, $port = null)
- {
- $this->protocol = $protocol;
- $this->port = is_null($port) ? $this->getStandardPort() : $port;
- }
-
-}
-?>
+<?php\r
+// +-----------------------------------------------------------------------+\r
+// | Copyright (c) 2002-2004, Richard Heyes |\r
+// | All rights reserved. |\r
+// | |\r
+// | Redistribution and use in source and binary forms, with or without |\r
+// | modification, are permitted provided that the following conditions |\r
+// | are met: |\r
+// | |\r
+// | o Redistributions of source code must retain the above copyright |\r
+// | notice, this list of conditions and the following disclaimer. |\r
+// | o Redistributions in binary form must reproduce the above copyright |\r
+// | notice, this list of conditions and the following disclaimer in the |\r
+// | documentation and/or other materials provided with the distribution.|\r
+// | o The names of the authors may not be used to endorse or promote |\r
+// | products derived from this software without specific prior written |\r
+// | permission. |\r
+// | |\r
+// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |\r
+// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |\r
+// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |\r
+// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |\r
+// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |\r
+// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |\r
+// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |\r
+// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |\r
+// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |\r
+// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |\r
+// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |\r
+// | |\r
+// +-----------------------------------------------------------------------+\r
+// | Author: Richard Heyes <richard at php net> |\r
+// +-----------------------------------------------------------------------+\r
+//\r
+// $Id: URL.php,v 1.1 2006/11/27 17:14:39 hsur Exp $\r
+//\r
+// Net_URL Class\r
+\r
+class Net_URL\r
+{\r
+ /**\r
+ * Full url\r
+ * @var string\r
+ */\r
+ var $url;\r
+\r
+ /**\r
+ * Protocol\r
+ * @var string\r
+ */\r
+ var $protocol;\r
+\r
+ /**\r
+ * Username\r
+ * @var string\r
+ */\r
+ var $username;\r
+\r
+ /**\r
+ * Password\r
+ * @var string\r
+ */\r
+ var $password;\r
+\r
+ /**\r
+ * Host\r
+ * @var string\r
+ */\r
+ var $host;\r
+\r
+ /**\r
+ * Port\r
+ * @var integer\r
+ */\r
+ var $port;\r
+\r
+ /**\r
+ * Path\r
+ * @var string\r
+ */\r
+ var $path;\r
+\r
+ /**\r
+ * Query string\r
+ * @var array\r
+ */\r
+ var $querystring;\r
+\r
+ /**\r
+ * Anchor\r
+ * @var string\r
+ */\r
+ var $anchor;\r
+\r
+ /**\r
+ * Whether to use []\r
+ * @var bool\r
+ */\r
+ var $useBrackets;\r
+\r
+ /**\r
+ * PHP4 Constructor\r
+ *\r
+ * @see __construct()\r
+ */\r
+ function Net_URL($url = null, $useBrackets = true)\r
+ {\r
+ $this->__construct($url, $useBrackets);\r
+ }\r
+\r
+ /**\r
+ * PHP5 Constructor\r
+ *\r
+ * Parses the given url and stores the various parts\r
+ * Defaults are used in certain cases\r
+ *\r
+ * @param string $url Optional URL\r
+ * @param bool $useBrackets Whether to use square brackets when\r
+ * multiple querystrings with the same name\r
+ * exist\r
+ */\r
+ function __construct($url = null, $useBrackets = true)\r
+ {\r
+ $HTTP_SERVER_VARS = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];\r
+\r
+ $this->useBrackets = $useBrackets;\r
+ $this->url = $url;\r
+ $this->user = '';\r
+ $this->pass = '';\r
+ $this->host = '';\r
+ $this->port = 80;\r
+ $this->path = '';\r
+ $this->querystring = array();\r
+ $this->anchor = '';\r
+\r
+ // Only use defaults if not an absolute URL given\r
+ if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {\r
+\r
+ $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');\r
+\r
+ /**\r
+ * Figure out host/port\r
+ */\r
+ if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {\r
+ $host = $matches[1];\r
+ if (!empty($matches[3])) {\r
+ $port = $matches[3];\r
+ } else {\r
+ $port = $this->getStandardPort($this->protocol);\r
+ }\r
+ }\r
+\r
+ $this->user = '';\r
+ $this->pass = '';\r
+ $this->host = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');\r
+ $this->port = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));\r
+ $this->path = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';\r
+ $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;\r
+ $this->anchor = '';\r
+ }\r
+\r
+ // Parse the url and store the various parts\r
+ if (!empty($url)) {\r
+ $urlinfo = parse_url($url);\r
+\r
+ // Default querystring\r
+ $this->querystring = array();\r
+\r
+ foreach ($urlinfo as $key => $value) {\r
+ switch ($key) {\r
+ case 'scheme':\r
+ $this->protocol = $value;\r
+ $this->port = $this->getStandardPort($value);\r
+ break;\r
+\r
+ case 'user':\r
+ case 'pass':\r
+ case 'host':\r
+ case 'port':\r
+ $this->$key = $value;\r
+ break;\r
+\r
+ case 'path':\r
+ if ($value{0} == '/') {\r
+ $this->path = $value;\r
+ } else {\r
+ $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);\r
+ $this->path = sprintf('%s/%s', $path, $value);\r
+ }\r
+ break;\r
+\r
+ case 'query':\r
+ $this->querystring = $this->_parseRawQueryString($value);\r
+ break;\r
+\r
+ case 'fragment':\r
+ $this->anchor = $value;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Returns full url\r
+ *\r
+ * @return string Full url\r
+ * @access public\r
+ */\r
+ function getURL()\r
+ {\r
+ $querystring = $this->getQueryString();\r
+\r
+ $this->url = $this->protocol . '://'\r
+ . $this->user . (!empty($this->pass) ? ':' : '')\r
+ . $this->pass . (!empty($this->user) ? '@' : '')\r
+ . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)\r
+ . $this->path\r
+ . (!empty($querystring) ? '?' . $querystring : '')\r
+ . (!empty($this->anchor) ? '#' . $this->anchor : '');\r
+\r
+ return $this->url;\r
+ }\r
+\r
+ /**\r
+ * Adds a querystring item\r
+ *\r
+ * @param string $name Name of item\r
+ * @param string $value Value of item\r
+ * @param bool $preencoded Whether value is urlencoded or not, default = not\r
+ * @access public\r
+ */\r
+ function addQueryString($name, $value, $preencoded = false)\r
+ {\r
+ if ($preencoded) {\r
+ $this->querystring[$name] = $value;\r
+ } else {\r
+ $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Removes a querystring item\r
+ *\r
+ * @param string $name Name of item\r
+ * @access public\r
+ */\r
+ function removeQueryString($name)\r
+ {\r
+ if (isset($this->querystring[$name])) {\r
+ unset($this->querystring[$name]);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Sets the querystring to literally what you supply\r
+ *\r
+ * @param string $querystring The querystring data. Should be of the format foo=bar&x=y etc\r
+ * @access public\r
+ */\r
+ function addRawQueryString($querystring)\r
+ {\r
+ $this->querystring = $this->_parseRawQueryString($querystring);\r
+ }\r
+\r
+ /**\r
+ * Returns flat querystring\r
+ *\r
+ * @return string Querystring\r
+ * @access public\r
+ */\r
+ function getQueryString()\r
+ {\r
+ if (!empty($this->querystring)) {\r
+ foreach ($this->querystring as $name => $value) {\r
+ if (is_array($value)) {\r
+ foreach ($value as $k => $v) {\r
+ $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);\r
+ }\r
+ } elseif (!is_null($value)) {\r
+ $querystring[] = $name . '=' . $value;\r
+ } else {\r
+ $querystring[] = $name;\r
+ }\r
+ }\r
+ $querystring = implode(ini_get('arg_separator.output'), $querystring);\r
+ } else {\r
+ $querystring = '';\r
+ }\r
+\r
+ return $querystring;\r
+ }\r
+\r
+ /**\r
+ * Parses raw querystring and returns an array of it\r
+ *\r
+ * @param string $querystring The querystring to parse\r
+ * @return array An array of the querystring data\r
+ * @access private\r
+ */\r
+ function _parseRawQuerystring($querystring)\r
+ {\r
+ $parts = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);\r
+ $return = array();\r
+\r
+ foreach ($parts as $part) {\r
+ if (strpos($part, '=') !== false) {\r
+ $value = substr($part, strpos($part, '=') + 1);\r
+ $key = substr($part, 0, strpos($part, '='));\r
+ } else {\r
+ $value = null;\r
+ $key = $part;\r
+ }\r
+ if (substr($key, -2) == '[]') {\r
+ $key = substr($key, 0, -2);\r
+ if (@!is_array($return[$key])) {\r
+ $return[$key] = array();\r
+ $return[$key][] = $value;\r
+ } else {\r
+ $return[$key][] = $value;\r
+ }\r
+ } elseif (!$this->useBrackets AND !empty($return[$key])) {\r
+ $return[$key] = (array)$return[$key];\r
+ $return[$key][] = $value;\r
+ } else {\r
+ $return[$key] = $value;\r
+ }\r
+ }\r
+\r
+ return $return;\r
+ }\r
+\r
+ /**\r
+ * Resolves //, ../ and ./ from a path and returns\r
+ * the result. Eg:\r
+ *\r
+ * /foo/bar/../boo.php => /foo/boo.php\r
+ * /foo/bar/../../boo.php => /boo.php\r
+ * /foo/bar/.././/boo.php => /foo/boo.php\r
+ *\r
+ * This method can also be called statically.\r
+ *\r
+ * @param string $url URL path to resolve\r
+ * @return string The result\r
+ */\r
+ function resolvePath($path)\r
+ {\r
+ $path = explode('/', str_replace('//', '/', $path));\r
+\r
+ for ($i=0; $i<count($path); $i++) {\r
+ if ($path[$i] == '.') {\r
+ unset($path[$i]);\r
+ $path = array_values($path);\r
+ $i--;\r
+\r
+ } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {\r
+ unset($path[$i]);\r
+ unset($path[$i-1]);\r
+ $path = array_values($path);\r
+ $i -= 2;\r
+\r
+ } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {\r
+ unset($path[$i]);\r
+ $path = array_values($path);\r
+ $i--;\r
+\r
+ } else {\r
+ continue;\r
+ }\r
+ }\r
+\r
+ return implode('/', $path);\r
+ }\r
+\r
+ /**\r
+ * Returns the standard port number for a protocol\r
+ *\r
+ * @param string $scheme The protocol to lookup\r
+ * @return integer Port number or NULL if no scheme matches\r
+ *\r
+ * @author Philippe Jausions <Philippe.Jausions@11abacus.com>\r
+ */\r
+ function getStandardPort($scheme)\r
+ {\r
+ switch (strtolower($scheme)) {\r
+ case 'http': return 80;\r
+ case 'https': return 443;\r
+ case 'ftp': return 21;\r
+ case 'imap': return 143;\r
+ case 'imaps': return 993;\r
+ case 'pop3': return 110;\r
+ case 'pop3s': return 995;\r
+ default: return null;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Forces the URL to a particular protocol\r
+ *\r
+ * @param string $protocol Protocol to force the URL to\r
+ * @param integer $port Optional port (standard port is used by default)\r
+ */\r
+ function setProtocol($protocol, $port = null)\r
+ {\r
+ $this->protocol = $protocol;\r
+ $this->port = is_null($port) ? $this->getStandardPort() : $port;\r
+ }\r
+\r
+}\r
+?>\r