From b91cb0e88ea11ff2ad982cc5fe7b9b1c64391cc0 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 21 Feb 2015 12:08:47 +0100 Subject: [PATCH] Fixed handling of default controllers, some optimizations --- .../system/request/FlexibleRoute.class.php | 8 +------ .../system/request/RequestHandler.class.php | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php b/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php index 3a6209d3f0..2ee79a42e5 100644 --- a/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/FlexibleRoute.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 81d3da3b92..433f9e26f5 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -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("
".$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);
+	}
 }
-- 
2.20.1