-// XXX: put that function somewhere else. It's used in changes.php
-function relative_path ($url_str) {
- $url = parse_url ($url_str);
- if ($url ['host'] != $_SERVER ['HTTP_HOST']) {
- return null;
- }
-
- // first strip common directory names
- $url_path = split ('/', $url ['path']);
- $script_path = split ('/', $_SERVER ['SCRIPT_NAME']);
- $len = min (count ($url_path), count ($script_path));
- while ($url_path [0] == $script_path [0]) {
- array_shift ($url_path);
- array_shift ($script_path);
- }
-
- // $url_path contains $script_path; abort
- if (count ($script_path) == 0) {
- return null;
- }
-
- // now, create relative path
- $relpath = "";
- for ($i = 0; $i < (count ($script_path) - 1); $i++) {
- $relpath .= "../";
- }
- $relpath .= join ("/", $url_path);
- return $relpath;
-}
-