Fixed application path on install
authorAlexander Ebert <ebert@woltlab.com>
Thu, 3 Nov 2011 13:41:40 +0000 (14:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 3 Nov 2011 13:41:40 +0000 (14:41 +0100)
wcfsetup/install/files/lib/system/WCFACP.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php
wcfsetup/install/files/lib/system/request/RouteHandler.class.php

index 0d75545cb6f858db39cf33768277f01fd5a52f2c..7b2c5a971a2c370418dfb2d15f12251bd2ad3c4f 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system;
 use wcf\system\cache\CacheHandler;
+use wcf\system\request\RouteHandler;
 use wcf\system\session\ACPSessionFactory;
 use wcf\system\session\SessionHandler;
 use wcf\system\template\ACPTemplateEngine;
@@ -86,25 +87,11 @@ class WCFACP extends WCF {
                parent::assignDefaultTemplateVariables();
                
                // base tag is determined on runtime
-               $phpSelf = $_SERVER['PHP_SELF'];
-               if (isset($_SERVER['PATH_INFO'])) {
-                       // strip path info
-                       $phpSelf = str_replace($_SERVER['PATH_INFO'], '', $phpSelf);
-               }
-               if (($pos = strpos($phpSelf, 'index.php')) !== false) {
-                       // strip index.php
-                       $phpSelf = substr($phpSelf, 0, $pos);
-               }
-               
-               // get protocol and domain name
-               $protocol = 'http://';
-               if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || $_SERVER['SERVER_PORT'] == 443) {
-                       $protocol = 'https://';
-               }
-               $phpSelf = $protocol . $_SERVER['HTTP_HOST'] .  $phpSelf;
+               $host = RouteHandler::getHost();
+               $path = RouteHandler::getPath();
                
                self::getTPL()->assign(array(
-                       'baseHref' => $phpSelf,
+                       'baseHref' => $host . $path,
                        'quickAccessPackages' => $this->getQuickAccessPackages(),
                        //'timezone' => util\DateUtil::getTimezone()
                ));
index 014c7e1d3ca64ef8d21d94cc9c09e637d61a9547..1f685fdc236ad77d77c9cab4353d1c3165b00e15 100644 (file)
@@ -15,6 +15,7 @@ use wcf\system\form;
 use wcf\system\form\container;
 use wcf\system\form\element;
 use wcf\system\request\LinkHandler;
+use wcf\system\request\RouteHandler;
 use wcf\system\WCF;
 use wcf\util\FileUtil;
 use wcf\util\HeaderUtil;
@@ -218,18 +219,13 @@ class PackageInstallationDispatcher {
                        $this->package = null;
                        
                        if ($package->standalone) {
-                               $domainPath = '';
-                               if (isset($_SERVER['PHP_SELF'])) {
-                                       $domainPath = $_SERVER['PHP_SELF'];
-                                       if (strpos($domainPath, '.php') !== false) {
-                                               $domainPath = preg_replace('~index\.php$~', '', $domainPath);
-                                       }
-                               }
+                               $host = RouteHandler::getHost();
+                               $path = RouteHandler::getPath(array('acp'));
                                
                                // insert as application
                                ApplicationEditor::create(array(
-                                       'domainName' => (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : '',
-                                       'domainPath' => $domainPath,
+                                       'domainName' => $host,
+                                       'domainPath' => $path,
                                        'packageID' => $package->packageID
                                ));
                        }
index f1ffa1e62bc757ee76ca9d061933ddf91e026379..c814fa8ed8b66d570eb09d0d52fc7e342d58fa54 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\system\request;
 use wcf\system\event\EventHandler;
 use wcf\system\SingletonFactory;
+use wcf\util\FileUtil;
 
 /**
  * Handles routes for HTTP requests.
@@ -17,6 +18,18 @@ use wcf\system\SingletonFactory;
  * @category   Community Framework
  */
 class RouteHandler extends SingletonFactory {
+       /**
+        * current host and protocol
+        * @var string
+        */
+       protected static $host = '';
+       
+       /**
+        * current absolute path
+        * @var string
+        */
+       protected static $path = '';
+       
        /**
         * router filter for ACP
         * @var boolean
@@ -138,4 +151,52 @@ class RouteHandler extends SingletonFactory {
                
                throw new SystemException("Unable to build route, no available route is satisfied.");
        }
+       
+       /**
+        * Returns protocol and domain name.
+        * 
+        * @return      string
+        */
+       public static function getHost() {
+               if (empty(self::$host)) {
+                       // get protocol and domain name
+                       $protocol = 'http://';
+                       if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || $_SERVER['SERVER_PORT'] == 443) {
+                               $protocol = 'https://';
+                       }
+                       
+                       self::$host = $protocol . $_SERVER['HTTP_HOST'];
+               }
+               
+               return self::$host;
+       }
+       
+       /**
+        * Returns absolute domain path.
+        * 
+        * @param       array           $removeComponents
+        * @return      string
+        */
+       public static function getPath(array $removeComponents = array()) {
+               if (empty(self::$path)) {
+                       self::$path = FileUtil::addTrailingSlash(dirname($_SERVER['SCRIPT_NAME']));
+               }
+               
+               if (!empty($removeComponents)) {
+                       $path = explode('/', self::$path);
+                       foreach ($path as $index => $component) {
+                               if (empty($path[$index])) {
+                                       unset($path[$index]);
+                               }
+                               
+                               if (in_array($component, $removeComponents)) {
+                                       unset($path[$index]);
+                               }
+                       }
+                       
+                       return implode('/', $path) . '/';
+               }
+               
+               return self::$path;
+       }
 }