From c4f1a1de5b5f9dda969a3b3872eea5628d8ef9e2 Mon Sep 17 00:00:00 2001
From: Bart Visscher <bartv@thisnet.nl>
Date: Mon, 6 Aug 2012 22:15:55 +0200
Subject: [PATCH] Added function to make url absolute

---
 lib/helper.php | 15 +++++++++++++--
 lib/util.php   |  4 ++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/helper.php b/lib/helper.php
index 666bc6badfc..c404f6e5440 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -120,8 +120,19 @@ class OC_Helper {
 	 */
 	public static function linkToAbsolute( $app, $file ) {
 		$urlLinkTo = self::linkTo( $app, $file );
-		$urlLinkTo = self::serverProtocol(). '://'  . self::serverHost() . $urlLinkTo;
-		return $urlLinkTo;
+		return self::makeURLAbsolute($urlLinkTo);
+	}
+
+	/**
+	 * @brief Makes an $url absolute
+	 * @param $url the url
+	 * @returns the absolute url
+	 *
+	 * Returns a absolute url to the given app and file.
+	 */
+	public static function makeURLAbsolute( $url )
+	{
+		return self::serverProtocol(). '://'  . self::serverHost() . $url;
 	}
 
 	/**
diff --git a/lib/util.php b/lib/util.php
index f26fa63e446..4c5d416f9f2 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -348,7 +348,7 @@ class OC_Util {
 		else {
 			$defaultpage = OC_Appconfig::getValue('core', 'defaultpage');
 			if ($defaultpage) {
-				$location = OC_Helper::serverProtocol().'://'.OC_Helper::serverHost().OC::$WEBROOT.'/'.$defaultpage;
+				$location = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/'.$defaultpage);
 			}
 			else {
 				$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
@@ -476,7 +476,7 @@ class OC_Util {
 		@fclose($fp);
 
 		// accessing the file via http
-		$url = OC_Helper::serverProtocol(). '://'  . OC_Helper::serverHost() . OC::$WEBROOT.'/data'.$filename;
+		$url = OC_Helper::makeURLAbsolute(OC::$WEBROOT.'/data'.$filename);
 		$fp = @fopen($url, 'r');
 		$content=@fread($fp, 2048);
 		@fclose($fp);
-- 
GitLab