37 $abs_uri = preg_replace(
"{^[^:]+://[^/]+}",
'', $abs_uri);
38 $base = preg_replace(
"{^[^:]+://[^/]+}",
'', $base);
40 $abs_array = explode(
'/', $abs_uri);
41 $base_array = explode(
'/', $base);
45 if (strrpos($abs_uri,
'/') !== strlen($abs_uri))
46 $fileName = array_pop($abs_array);
47 if (strrpos($base,
'/') !== strlen($base))
48 array_pop($base_array);
51 while ($abs_array[0] == $base_array[0] &&
sizeof($abs_array) > 0)
53 array_shift($abs_array);
54 array_shift($base_array);
58 $rel_uri = str_repeat(
'../',
sizeof($base_array)).join(
'/', $abs_array).
'/'.$fileName;
68 function makeAbsolute($rel_uri, $base, $REMOVE_LEADING_DOTS =
true)
70 preg_match(
"'^([^:]+://[^/]+)/'", $base, $m);
72 if (preg_match(
"'^/'", $rel_uri))
73 return $base_start.$rel_uri;
75 $base = preg_replace(
"{[^/]+$}",
'', $base);
77 $base = preg_replace(
"{^[^:]+://[^/]+}",
'', $base);
78 $base_array = explode(
'/', $base);
79 if (count($base_array) and !strlen($base_array[0]))
80 array_shift($base_array);
83 while ($i < count($base_array))
85 if ($base_array[$i - 1] ==
".")
87 array_splice($base_array, $i - 1, 1);
90 elseif ($base_array[$i] ==
".." and $base_array[$i - 1]!=
"..")
92 array_splice($base_array, $i - 1, 2);
96 if ($i == count($base_array))
97 array_push($base_array,
"");
106 if (count($base_array) and $base_array[-1] ==
".")
107 $base_array[-1] =
"";
124 if ($REMOVE_LEADING_DOTS)
126 while (count($base_array) and preg_match(
"/^\.\.?$/", $base_array[0]))
127 array_shift($base_array);
129 return($base_start .
'/' . implode(
"/", $base_array));
143 $self = UriUtil::getProtocolStr().$_SERVER[
'SERVER_NAME'].$_SERVER[
'PHP_SELF'];
144 $path = dirname($self).
'/';
148 return array(
'absolute' => $absUrl,
'relative' => $relUrl);
159 $url_parts = @parse_url($url);
160 if (empty($url_parts[
"host"]))
163 $fh = @fopen($url,
"r");
170 if (!empty($url_parts[
"path"]))
171 $documentpath = $url_parts[
"path"];
175 if (!empty($url_parts[
"query"]))
176 $documentpath .=
"?" . $url_parts[
"query"];
178 $host = $url_parts[
"host"];
179 $port = $url_parts[
"port"];
185 $socket = @fsockopen($host, $port, $errno, $errstr, $timeout);
190 fwrite ($socket,
"HEAD ".$documentpath.
" HTTP/1.0\r\nHost: $host\r\n\r\n");
191 $http_response = fgets($socket, 22);
192 preg_match(
'/.+ ([0-9]{3}) .+/', $http_response, $matches);
193 if (intval($matches[1]) < 400)
201 Log::debug(
"$url: HTTP-Response: $http_response", __CLASS__);
212 if (strlen($_SERVER[
'HTTPS']) > 0 && $_SERVER[
'HTTPS'] !=
'off')
224 if ($_SERVER[
"SERVER_PORT"] !=
"80") {
225 $pageURL .= $_SERVER[
"SERVER_NAME"].
":".$_SERVER[
"SERVER_PORT"].$_SERVER[
"REQUEST_URI"];
228 $pageURL .= $_SERVER[
"SERVER_NAME"].$_SERVER[
"REQUEST_URI"];
debug($message, $category)
makeRelative($abs_uri, $base)
makeAbsolute($rel_uri, $base, $REMOVE_LEADING_DOTS=true)
isDebugEnabled($category)
URIUtil provides support for uri manipulation.
validateUrl($url, $timeout=10)
translate($rel_uri, $base)