From: Sverre B. <sv...@us...> - 2005-11-03 13:26:18
|
Update of /cvsroot/archive-access/archive-access/projects/wera/src/webapps/wera/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25617/lib Modified Files: url.inc Log Message: tidy Index: url.inc =================================================================== RCS file: /cvsroot/archive-access/archive-access/projects/wera/src/webapps/wera/lib/url.inc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** url.inc 4 Oct 2005 22:59:27 -0000 1.1 --- url.inc 3 Nov 2005 13:25:46 -0000 1.2 *************** *** 1,3 **** --- 1,4 ---- <?php + /* * This file is part of WERA. *************** *** 38,96 **** // string combineUrl(string $orig_url, string $url) - combines an absolute url with a relative link - - // Strips portnumber if 80 ! function stripPort($url) ! { ! $url = str_replace(":80/","/",$url); return $url; ! } // Strips http:// ! function stripProtocol($url) ! { ! $url = eregi_replace ("^http://","",$url); return $url; ! } ! // Example url: http://www.domain.com/path/index.html // returns true if it is :] ! function isAbsolute($url) ! { ! if (eregi ("^http://", $url) ) ! { return true; ! } ! else ! { return false; - } } // Returns document name: index.html ! function getDocname($url) ! { ! eregi ("[^/]*$", $url, $matches); ! if ($matches != "") ! { #print "Matches: " . $matches[0] . "<br>\n"; ! return $matches[0]; ! } ! else ! return false; ! } // Returns domain-name: www.domain.com // !! Only if the URL starts with http:// ! function getDomain($url) ! { ! if (isAbsolute($url)) ! { ! $url = eregi_replace ("^http://", "", $url); ! eregi ("^[^/]*", $url, $matches); return $matches[0]; ! } ! else { return false;} } // Returns path: /path/ usage: getDomain("someurl"[,true|false][,true|false]) --- 39,84 ---- // string combineUrl(string $orig_url, string $url) - combines an absolute url with a relative link // Strips portnumber if 80 ! function stripPort($url) { ! $url = str_replace(":80/", "/", $url); return $url; ! } // Strips http:// ! function stripProtocol($url) { ! $url = eregi_replace("^http://", "", $url); return $url; ! } // Example url: http://www.domain.com/path/index.html // returns true if it is :] ! function isAbsolute($url) { ! if (eregi("^http://", $url)) { return true; ! } else { return false; } + } // Returns document name: index.html ! function getDocname($url) { ! eregi("[^/]*$", $url, $matches); ! if ($matches != "") { #print "Matches: " . $matches[0] . "<br>\n"; ! return $matches[0]; ! } else ! return false; ! } // Returns domain-name: www.domain.com // !! Only if the URL starts with http:// ! function getDomain($url) { ! if (isAbsolute($url)) { ! $url = eregi_replace("^http://", "", $url); ! eregi("^[^/]*", $url, $matches); return $matches[0]; ! } else { ! return false; } + } // Returns path: /path/ usage: getDomain("someurl"[,true|false][,true|false]) *************** *** 98,106 **** // Set noendslash to true if you don't want the end slash returned // Otherwise, don't pass the the two last parameters ! function getPath($url,$nostartslash=FALSE, $noendslash=FALSE) ! { ! //If url field is empty - return a null field. ! if ($url==""){return $url;} $domain = getDomain($url); --- 86,95 ---- // Set noendslash to true if you don't want the end slash returned // Otherwise, don't pass the the two last parameters ! function getPath($url, $nostartslash = FALSE, $noendslash = FALSE) { ! //If url field is empty - return a null field. ! if ($url == "") { ! return $url; ! } $domain = getDomain($url); *************** *** 108,120 **** #print "Domain: $domain<br>\n"; #print "Docname: $docname<br>\n"; ! $url = eregi_replace ( "^http://", "", $url); ! $url = eregi_replace ( "$domain", "", $url); if ($docname) ! $url = eregi_replace ( "$docname", "", $url); ! if ($nostartslash) { $url = eregi_replace ( "^/*", "", $url ); } ! if ($noendslash) { $url = eregi_replace ( "/*$", "", $url ); } #print "Returned path: $url<br>\n"; return $url; ! } // Returns: --- 97,113 ---- #print "Domain: $domain<br>\n"; #print "Docname: $docname<br>\n"; ! $url = eregi_replace("^http://", "", $url); ! $url = eregi_replace("$domain", "", $url); if ($docname) ! $url = eregi_replace("$docname", "", $url); ! if ($nostartslash) { ! $url = eregi_replace("^/*", "", $url); ! } ! if ($noendslash) { ! $url = eregi_replace("/*$", "", $url); ! } #print "Returned path: $url<br>\n"; return $url; ! } // Returns: *************** *** 122,169 **** // 0 If url is relative to domain (starts with /) // 1 If url is relative to domain/path (doesn't start with /) ! function isRelative($url) ! { ! if (isAbsolute($url)) { return -1; } ! elseif ( eregi ( "^/", $url)) { return false; } ! else { return true;} } // Takes original url and a relative url and combines them to an absolute url ! function combineUrl($l_url,$o_url) ! { $query = $l_url; if (!isAbsolute($l_url)) // If relative ! { ! // Her m� det gj�res litt av hvert for � f� rett streng til s�ket. ! if (isRelative($l_url)) // Relative to domain/path/ ! { ! $domain = getDomain($o_url); #print "Parameter for getPath: $o_url<br>\n"; ! $orig_path = getPath($o_url); #print "Orig_path: $orig_path<br>\n"; ! while ( eregi ("^\.\.\/", $l_url)) ! { #print $orig_path; ! $orig_path = eregi_replace ("[^/]*\/$","",$orig_path); ! $orig_path = $orig_path . "/"; ! $orig_path = eregi_replace ("\/{2}","/",$orig_path); ! $l_url = eregi_replace ("^\.\.\/", "", $l_url); #print " -> " . $orig_path; ! } ! $l_url = eregi_replace ("^(\.\/)(\.\/)*", "", $l_url); ! $query = "http://" . $domain . $orig_path . $l_url; #print $query; ! } ! else // It is relative to domain only ! { ! $domain = getDomain($o_url); ! $orig_path = getPath($o_url); ! $query = "http://" . $domain . $l_url; ! } ! } return $query; ! } ! ?> --- 115,163 ---- // 0 If url is relative to domain (starts with /) // 1 If url is relative to domain/path (doesn't start with /) ! function isRelative($url) { ! if (isAbsolute($url)) { ! return -1; } + elseif (eregi("^/", $url)) { + return false; + } else { + return true; + } + } // Takes original url and a relative url and combines them to an absolute url ! function combineUrl($l_url, $o_url) { $query = $l_url; if (!isAbsolute($l_url)) // If relative ! { ! // Her m� det gj�res litt av hvert for � f� rett streng til s�ket. ! if (isRelative($l_url)) // Relative to domain/path/ ! { ! $domain = getDomain($o_url); #print "Parameter for getPath: $o_url<br>\n"; ! $orig_path = getPath($o_url); #print "Orig_path: $orig_path<br>\n"; ! while (eregi("^\.\.\/", $l_url)) { #print $orig_path; ! $orig_path = eregi_replace("[^/]*\/$", "", $orig_path); ! $orig_path = $orig_path."/"; ! $orig_path = eregi_replace("\/{2}", "/", $orig_path); ! $l_url = eregi_replace("^\.\.\/", "", $l_url); #print " -> " . $orig_path; ! } ! $l_url = eregi_replace("^(\.\/)(\.\/)*", "", $l_url); ! $query = "http://".$domain.$orig_path.$l_url; #print $query; ! } else // It is relative to domain only ! { ! $domain = getDomain($o_url); ! $orig_path = getPath($o_url); ! $query = "http://".$domain.$l_url; ! } ! } return $query; ! } ?> + |