Fixed handling of default controllers, some optimizations
authorAlexander Ebert <ebert@woltlab.com>
Sat, 21 Feb 2015 11:08:47 +0000 (12:08 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 21 Feb 2015 11:08:47 +0000 (12:08 +0100)
wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php
wcfsetup/install/files/lib/system/request/RequestHandler.class.php

index 3a6209d3f0b6af5bd5848e1437cca13a002af079..2ee79a42e54dcd8605f64c053f21be189b686296 100644 (file)
@@ -279,13 +279,7 @@ class FlexibleRoute implements IRoute {
         */
        protected function getControllerName($application, $controller) {
                if (!isset(self::$controllerNames[$controller])) {
-                       $parts = preg_split('~([A-Z][a-z0-9]+)~', $controller, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
-                       $controllerName = '';
-                       for ($i = 0, $length = count($parts); $i < $length; $i++) {
-                               if (!empty($controllerName)) $controllerName .= '-';
-                               $controllerName .= strtolower($parts[$i]);
-                       }
-                       
+                       $controllerName = RequestHandler::getTokenizedController($controller);
                        $alias = (!$this->isACP) ? RequestHandler::getInstance()->getAliasByController($controllerName) : null;
                        
                        self::$controllerNames[$controller] = ($alias) ?: $controllerName;
index 81d3da3b928591907a5d1132e313a32081cc7dcc..433f9e26f573829de943bd3b2cd822f8e17ebbcc 100644 (file)
@@ -226,9 +226,7 @@ class RequestHandler extends SingletonFactory {
                        // check if controller was provided exactly as it should
                        if (!URL_LEGACY_MODE && !$this->isACPRequest()) {
                                if (preg_match('~([A-Za-z0-9]+)(?:Action|Form|Page)$~', $classData['className'], $matches)) {
-                                       $parts = preg_split('~([A-Z][a-z0-9]+)~', $matches[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
-                                       $parts = array_map('strtolower', $parts);
-                                       $realController = implode('-', $parts);
+                                       $realController = self::getTokenizedController($matches[1]);
                                        
                                        if ($controller != $realController) {
                                                $this->redirect($routeData, $application, $matches[1]);
@@ -239,6 +237,7 @@ class RequestHandler extends SingletonFactory {
                        $this->activeRequest = new Request($classData['className'], $classData['controller'], $classData['pageType']);
                }
                catch (SystemException $e) {
+                       die("<pre>".$e->getMessage());
                        throw new IllegalLinkException();
                }
        }
@@ -261,7 +260,7 @@ class RequestHandler extends SingletonFactory {
                        }
                }
                
-               $redirectURL = LinkHandler::getInstance()->getLink($routeData['controller'], $linkData);
+               $redirectURL = LinkHandler::getInstance()->getLink($routeData['controller'], $routeData);
                HeaderUtil::redirect($redirectURL, true);
                exit;
        }
@@ -292,6 +291,7 @@ class RequestHandler extends SingletonFactory {
                // check if currently invoked application matches the landing page
                if ($landingPageApplication == $application) {
                        $routeData['controller'] = $landingPage->getController();
+                       if (!URL_LEGACY_MODE) $routeData['controller'] = self::getTokenizedController($routeData['controller']);
                        return;
                }
                
@@ -305,7 +305,7 @@ class RequestHandler extends SingletonFactory {
                                exit;
                        }
                        else {
-                               $routeData['controller'] = preg_replace('~(Action|Form|Page)$~', '', array_pop($controller));
+                               $routeData['controller'] = self::getTokenizedController(preg_replace('~(Action|Form|Page)$~', '', array_pop($controller)));
                                return;
                        }
                }
@@ -433,4 +433,17 @@ class RequestHandler extends SingletonFactory {
                
                return null;
        }
+       
+       /**
+        * Returns the tokenized controller name, e.g. BoardList -> board-list.
+        * 
+        * @param       string          controller
+        * @return      string
+        */
+       public static function getTokenizedController($controller) {
+               $parts = preg_split('~([A-Z][a-z0-9]+)~', $controller, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+               $parts = array_map('strtolower', $parts);
+               
+               return implode('-', $parts);
+       }
 }