Bladeren bron

#379 GetAbsoluteUrlRoot becomes GetAbsoluteUrlAppRoot which will simplify the development of plugins, fixed a cosmetic issue in export.php (format: html + iTop not installed in the url root path)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1259 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 jaren geleden
bovenliggende
commit
85e67ba54b
2 gewijzigde bestanden met toevoegingen van 12 en 17 verwijderingen
  1. 8 5
      application/utils.inc.php
  2. 4 12
      webservices/export.php

+ 8 - 5
application/utils.inc.php

@@ -345,14 +345,17 @@ class utils
      * @param $bForceHTTPS bool True to force HTTPS, false otherwise
      * @return string The absolute URL to the server's root, without the first slash
      */                   
-	static public function GetAbsoluteUrlRoot($bForceHTTPS = false)
+	static public function GetAbsoluteUrlAppRoot($sCurrentRelativePath = '', $bForceHTTPS = false)
 	{
 		$sAbsoluteUrl = self::GetAbsoluteUrl(false, $bForceHTTPS); // False => Don't get the query string
-		$sServerPos = 3 + strpos($sAbsoluteUrl, '://');
-		$iFirstSlashPos = strpos($sAbsoluteUrl, '/', $sServerPos);
-		if ($iFirstSlashPos !== false)
+		$sAppRootPos = strpos($sAbsoluteUrl, $sCurrentRelativePath);
+		if ($sAppRootPos !== false)
 		{
-			$sAbsoluteUrl = substr($sAbsoluteUrl, 0, $iFirstSlashPos); // remove the current page, keep just the path, without the first /
+			$sAbsoluteUrl = substr($sAbsoluteUrl, 0, $sAppRootPos); // remove the current page and path
+		}
+		else
+		{
+			throw new Exception("Failed to determine application root path $sAbsoluteUrl ($sCurrentRelativePath)");
 		}
 		return $sAbsoluteUrl;
 	}

+ 4 - 12
webservices/export.php

@@ -59,21 +59,13 @@ if (!empty($sExpression))
 			{
 				case 'html':
 				$oP = new NiceWebPage("iTop - Export");
+
 				// The HTML output is made for pages located in the /pages/ folder
 				// since this page is in a different folder, let's adjust the HTML 'base' attribute
 				// to make the relative hyperlinks in the page work
-				$sServerName = $_SERVER['SERVER_NAME'];
-				$sProtocol = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 'https' : 'http';
-				if ($sProtocol == 'http')
-				{
-					$sPort = ($_SERVER['SERVER_PORT'] == 80) ? '' : ':'.$_SERVER['SERVER_PORT'];
-				}
-				else
-				{
-					$sPort = ($_SERVER['SERVER_PORT'] == 443) ? '' : ':'.$_SERVER['SERVER_PORT'];
-				}
-				$sUrl = "$sProtocol://{$sServerName}{$sPort}/pages/";
-				$oP->set_base($sUrl);
+				$sUrl = utils::GetAbsoluteUrlAppRoot('/webservices/');
+				$oP->set_base($sUrl.'/pages/');
+
 				$oResultBlock = new DisplayBlock($oFilter, 'list', false, array('menu' => false, 'display_limit' => false, 'zlist' => 'details'));
 				$oResultBlock->Display($oP, 'expresult');
 				break;