Improved support for renamed static routes
authorAlexander Ebert <ebert@woltlab.com>
Thu, 28 Sep 2017 13:39:32 +0000 (15:39 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 28 Sep 2017 13:39:32 +0000 (15:39 +0200)
wcfsetup/install/files/lib/system/request/ControllerMap.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php
wcfsetup/install/files/lib/system/request/RouteHandler.class.php
wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php
wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php

index 9feeca63098353624cb405fbcc9ebee0bfc081c9..60da31ff5646742a4bffc59eb23ce26375a33439 100644 (file)
@@ -57,10 +57,11 @@ class ControllerMap extends SingletonFactory {
         * @param       string          $application    application identifier
         * @param       string          $controller     url controller
         * @param       boolean         $isAcpRequest   true if this is an ACP request
+        * @param       boolean         $skipCustomUrls true if custom url resolution should be suppressed, is always true for ACP requests
         * @return      mixed           array containing className, controller and pageType or a string containing the controller name for aliased controllers
         * @throws      SystemException
         */
-       public function resolve($application, $controller, $isAcpRequest) {
+       public function resolve($application, $controller, $isAcpRequest, $skipCustomUrls = false) {
                // validate controller
                if (!preg_match('~^[a-z][a-z0-9]+(?:\-[a-z][a-z0-9]+)*$~', $controller)) {
                        throw new SystemException("Malformed controller name '" . $controller . "'");
@@ -88,16 +89,21 @@ class ControllerMap extends SingletonFactory {
                if ($classData === null) {
                        throw new SystemException("Unknown controller '" . $controller . "'");
                }
-               else if (!$isAcpRequest) {
-                       // handle controllers with a custom url
-                       $controller = $classData['controller'];
+               else {
+                       // the ACP does not support custom urls at all
+                       if ($isAcpRequest) $skipCustomUrls = true;
                        
-                       if (isset($this->customUrls['reverse'][$application]) && isset($this->customUrls['reverse'][$application][$controller])) {
-                               return $this->customUrls['reverse'][$application][$controller];
-                       }
-                       else if ($application !== 'wcf') {
-                               if (isset($this->customUrls['reverse']['wcf']) && isset($this->customUrls['reverse']['wcf'][$controller])) {
-                                       return $this->customUrls['reverse']['wcf'][$controller];
+                       if (!$skipCustomUrls) {
+                               // handle controllers with a custom url
+                               $controller = $classData['controller'];
+                               
+                               if (isset($this->customUrls['reverse'][$application]) && isset($this->customUrls['reverse'][$application][$controller])) {
+                                       return $this->customUrls['reverse'][$application][$controller];
+                               }
+                               else if ($application !== 'wcf') {
+                                       if (isset($this->customUrls['reverse']['wcf']) && isset($this->customUrls['reverse']['wcf'][$controller])) {
+                                               return $this->customUrls['reverse']['wcf'][$controller];
+                                       }
                                }
                        }
                }
index 8525b4efdc69e65024ded7d3ccb73bc386cf63b6..1f11e1fd103ddd86912eed1971aa1e01529d8041 100644 (file)
@@ -159,7 +159,7 @@ class RequestHandler extends SingletonFactory {
                                        exit;
                                }
                                
-                               $classData = ControllerMap::getInstance()->resolve($application, $controller, $this->isACPRequest());
+                               $classData = ControllerMap::getInstance()->resolve($application, $controller, $this->isACPRequest(), RouteHandler::getInstance()->isRenamedController());
                                if (is_string($classData)) {
                                        $this->redirect($routeData, $application, $classData);
                                }
@@ -191,6 +191,10 @@ class RequestHandler extends SingletonFactory {
                        }
                }
                catch (SystemException $e) {
+                       if (defined('ENABLE_DEBUG_MODE') && ENABLE_DEBUG_MODE && defined('ENABLE_DEVELOPER_TOOLS') && ENABLE_DEVELOPER_TOOLS) {
+                               throw $e;
+                       }
+                       
                        throw new IllegalLinkException();
                }
        }
index 31870c2016b5417e5e24d637f341ab5702a7dfc6..36aaab1da53e7d48903f2913e1db5b4981184fcb 100644 (file)
@@ -38,7 +38,7 @@ class RouteHandler extends SingletonFactory {
         * current path info component
         * @var string
         */
-       protected static $pathInfo = null;
+       protected static $pathInfo;
        
        /**
         * HTTP protocol, either 'http://' or 'https://'
@@ -50,20 +50,26 @@ class RouteHandler extends SingletonFactory {
         * HTTP encryption
         * @var boolean
         */
-       protected static $secure = null;
+       protected static $secure;
        
        /**
         * list of application abbreviation and default controller name
         * @var string[]
         */
-       protected $defaultControllers = null;
+       protected $defaultControllers;
        
        /**
-        * true, if default controller is used (support for custom landing page)
+        * true if the default controller is used (support for custom landing page)
         * @var boolean
         */
        protected $isDefaultController = false;
        
+       /**
+        * true if the controller was renamed and has already been transformed
+        * @var boolean
+        */
+       protected $isRenamedController = false;
+       
        /**
         * list of available routes
         * @var IRequestRoute[]
@@ -74,7 +80,7 @@ class RouteHandler extends SingletonFactory {
         * parsed route data
         * @var array
         */
-       protected $routeData = null;
+       protected $routeData;
        
        /**
         * Sets default routes.
@@ -131,6 +137,11 @@ class RouteHandler extends SingletonFactory {
                                $this->isDefaultController = $this->routeData['isDefaultController'];
                                unset($this->routeData['isDefaultController']);
                                
+                               if (isset($this->routeData['isRenamedController'])) {
+                                       $this->isRenamedController = $this->routeData['isRenamedController'];
+                                       unset($this->routeData['isRenamedController']);
+                               }
+                               
                                $this->registerRouteData();
                                return true;
                        }
@@ -148,6 +159,16 @@ class RouteHandler extends SingletonFactory {
                return $this->isDefaultController;
        }
        
+       
+       /**
+        * Returns true if the controller was renamed and has already been transformed.
+        * 
+        * @return      boolean
+        */
+       public function isRenamedController() {
+               return $this->isRenamedController;
+       }
+       
        /**
         * Returns parsed route data
         * 
index 7592d6380c934cd719da6d71246b919c4ceda6ff..f4dc02e643f49d16435932fd4ae82c879c644a60 100644 (file)
@@ -40,7 +40,7 @@ class LookupRequestRoute implements IRequestRoute {
                                        -
                                        (?P<title>[^/]+)
                                )?
-                               /
+                               /?
                        )?
                $~x';
                
index 5548380516974e389fb09fb2d4c12d74ffdb9522..fddacb2397e966fea6f1291aeb9da5b795421005 100644 (file)
@@ -100,8 +100,9 @@ class StaticRequestRoute extends DynamicRequestRoute {
                        }
                        
                        $this->routeData['application'] = $this->staticApplication;
-                       $this->routeData['controller'] = $controller;
+                       $this->routeData['controller'] = ControllerMap::transformController($this->staticController);
                        $this->routeData['isDefaultController'] = false;
+                       $this->routeData['isRenamedController'] = (strcasecmp($controller, $this->staticController) !== 0);
                        
                        return true;
                }