Factor out base url into a common function
Factor out base url into a common function

--- a/include/Router.class.php
+++ b/include/Router.class.php
@@ -638,10 +638,7 @@
 
 		$url = rtrim($url, "/");
 
-		$baseurl = $_SERVER['SCRIPT_NAME'];
-		if (substr_compare($baseurl, '.php', -4) === 0)
-			$baseurl = dirname($baseurl);
-		$baseurl = GitPHP_Util::AddSlash($baseurl);
+		$baseurl = GitPHP_Util::AddSlash(GitPHP_Util::BaseUrl());
 
 		if (strncmp($baseurl, $url, strlen($baseurl)) === 0)
 			$url = substr($url, strlen($baseurl));

--- a/include/Util.class.php
+++ b/include/Util.class.php
@@ -144,5 +144,18 @@
 		return $files;
 	}
 
+	/**
+	 * Get the base install url (without index)
+	 *
+	 * @return string base url
+	 */
+	public static function BaseUrl()
+	{
+		$baseurl = $_SERVER['SCRIPT_NAME'];
+		if (substr_compare($baseurl, '.php', -4) === 0)
+			$baseurl = dirname($baseurl);
+		return rtrim($baseurl, "/");
+	}
+
 }
 

--- a/include/controller/ControllerBase.class.php
+++ b/include/controller/ControllerBase.class.php
@@ -144,9 +144,7 @@
 	{
 		$locale = null;
 
-		$baseurl = $_SERVER['SCRIPT_NAME'];
-		if (substr_compare($baseurl, '.php', -4) === 0)
-			$baseurl = dirname($baseurl);
+		$baseurl = GitPHP_Util::BaseUrl();
 
 		if (!empty($this->params['lang'])) {
 			/*
@@ -531,12 +529,7 @@
 		$this->tpl->assign('scripturl', $scripturl);
 		$this->tpl->assign('fullscripturl', $fullscripturl);
 
-		$baseurl = $scripturl;
-		if (substr_compare($baseurl, '.php', -4) === 0) {
-			$baseurl = dirname($baseurl);
-		}
-		$baseurl = rtrim($baseurl, "/");
-		$this->tpl->assign('baseurl', $baseurl);
+		$this->tpl->assign('baseurl', GitPHP_Util::BaseUrl());
 
 		$requesturl = $_SERVER['REQUEST_URI'];
 		$querypos = strpos($requesturl, '?');

--- a/include/controller/Controller_DiffBase.class.php
+++ b/include/controller/Controller_DiffBase.class.php
@@ -62,9 +62,7 @@
 	{
 		$mode = GitPHP_Controller_DiffBase::UnifiedDiff;	// default
 
-		$baseurl = $_SERVER['SCRIPT_NAME'];
-		if (substr_compare($baseurl, '.php', -4) === 0)
-			$baseurl = dirname($baseurl);
+		$baseurl = GitPHP_Util::BaseUrl();
 
 		/*
 		 * Check cookie

comments