summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2014-08-24 11:43:12 +0200
committerAleksander Machniak <alec@alec.pl>2014-08-24 11:43:12 +0200
commit5f58127eae9ed8c54c190506e11af13e8ba57170 (patch)
tree1cffa050bf982c6e346acd96194e47f4374544a8 /program/lib
parent75bbada03b0e616248ec3458d1a6ee98bfc03659 (diff)
Added rcube_utils::resolve_url()
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/Roundcube/rcube_utils.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index 86d9eb2cc..ef303f8c1 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -1071,4 +1071,34 @@ class rcube_utils
return $path[0] == DIRECTORY_SEPARATOR;
}
}
+
+ /**
+ * Resolve relative URL
+ *
+ * @param string $url Relative URL
+ *
+ * @return string Absolute URL
+ */
+ public static function resolve_url($url)
+ {
+ // prepend protocol://hostname:port
+ if (!preg_match('|^https?://|', $url)) {
+ $schema = 'http';
+ $default_port = 80;
+
+ if (self::https_check()) {
+ $schema = 'https';
+ $default_port = 443;
+ }
+
+ $prefix = $schema . '://' . preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
+ if ($_SERVER['SERVER_PORT'] != $default_port) {
+ $prefix .= ':' . $_SERVER['SERVER_PORT'];
+ }
+
+ $url = $prefix . ($url[0] == '/' ? '' : '/') . $url;
+ }
+
+ return $url;
+ }
}