summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-09-16 21:41:05 +0300
committerAndrew Dolgov <[email protected]>2020-09-16 21:41:05 +0300
commit88c4dc405e04b219ed4ab76603f4cf82c073c140 (patch)
tree77ab1d3f53caac7ae44cd9ecbedde1b00faebafd /include
parent9d3c79498368fa99cfde684c759a1c40825aaaa9 (diff)
build_url: also put query parameters and fragment in resulting URL
rewrite_relative_url: simplify handling of relative URLs
Diffstat (limited to 'include')
-rw-r--r--include/functions.php28
1 files changed, 13 insertions, 15 deletions
diff --git a/include/functions.php b/include/functions.php
index bc66317bb..508801fb7 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1511,7 +1511,12 @@
}
function build_url($parts) {
- return $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
+ $tmp = $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
+
+ if (isset($parts['query'])) $tmp .= '?' . $parts['query'];
+ if (isset($parts['fragment'])) $tmp .= '#' . $parts['fragment'];
+
+ return $tmp;
}
/**
@@ -1537,23 +1542,16 @@
} else {
$parts = parse_url($url);
- if (!isset($parts['path'])) {
- $parts['path'] = '/';
- }
-
- $dir = $parts['path'];
-
- if (substr($dir, -1) !== '/') {
- $dir = dirname($parts['path']);
- $dir !== '/' && $dir .= '/';
- }
+ $rel_parts['host'] = $parts['host'];
+ $rel_parts['scheme'] = $parts['scheme'];
- $parts['path'] = $dir . $rel_url;
+ if (strpos($rel_parts['path'], '/') !== 0)
+ $rel_parts['path'] = '/' . $rel_parts['path'];
- $parts['path'] = str_replace("/./", "/", $parts['path']);
- $parts['path'] = str_replace("//", "/", $parts['path']);
+ $rel_parts['path'] = str_replace("/./", "/", $rel_parts['path']);
+ $rel_parts['path'] = str_replace("//", "/", $rel_parts['path']);
- return validate_url(build_url($parts));
+ return validate_url(build_url($rel_parts));
}
}