summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class27
1 files changed, 16 insertions, 11 deletions
diff --git a/it_url.class b/it_url.class
index 52a72d0..dffd805 100644
--- a/it_url.class
+++ b/it_url.class
@@ -708,27 +708,32 @@ function _atomicwrite($path, $data)
}
/**
- * Make an URL absolute by using host an protocol from current Apache request (but not port number)
+ * Make an URL absolute by using host and protocol from current Apache request (but not port number)
* @param $url Optional URL ( foo.html, /foo.html, //host/bar.html, http://host/bar.html ), default self
+ * @param $proto_force Optional protocol to enforce, default protocol of current request or http if in script context
* @return absolute version of URL ( http[s]://host/bar.html )
*/
-static function absolute($url=null)
+static function absolute($url = null, $proto_force = null)
{
if (!isset($url))
$url = $_SERVER['PHP_SELF'];
- if (!preg_match('/^\w+:/', $url))
+ if (list($proto_url, $urltmp) = it::match('^(\w+):(.*)$', $url))
{
- if (!preg_match('#^//#', $url))
- {
- $dir = preg_replace('#/[^/]*$#', '/', $_SERVER['PHP_SELF']);
- $url = preg_match('#^/#', $url) ? $url : "$dir$url";
- $url = "//" . $_SERVER['HTTP_HOST'] . $url;
- }
- $url = "http" . (isset($_SERVER['HTTPS']) ? 's':'') . ":$url";
+ $url = $urltmp;
+ $proto = $proto_force ?: $proto_url;
+ }
+ else
+ $proto = $proto_force ?: (isset($_SERVER['HTTPS']) ? 'https' : 'http');
+
+ if (!preg_match('#^//#', $url))
+ {
+ $dir = preg_replace('#/[^/]*$#', '/', $_SERVER['PHP_SELF']);
+ $url = preg_match('#^/#', $url) ? $url : "$dir$url";
+ $url = "//" . $_SERVER['HTTP_HOST'] . $url;
}
- return $url;
+ return "$proto:$url";
}
/**