Fixed wcfsetup and acp/frontend access
authorAlexander Ebert <ebert@woltlab.com>
Thu, 26 Nov 2015 10:00:40 +0000 (11:00 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 26 Nov 2015 10:00:40 +0000 (11:00 +0100)
12 files changed:
wcfsetup/install/files/lib/system/menu/TreeMenu.class.php
wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php
wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php
wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php
wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.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/DynamicRequestRoute.class.php
wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php
wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php
wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php
wcfsetup/install/files/lib/system/session/SessionFactory.class.php

index 0e52537f23b9dd1de3f5e60c1d07b6d467bd064a..e35977943a031bcf0eac65379652b45ad0415e35 100644 (file)
@@ -15,11 +15,6 @@ use wcf\system\WCF;
  * @category   Community Framework
  */
 abstract class TreeMenu extends SingletonFactory {
-       /**
-        * @var EventHandler
-        */
-       protected $eventHandler;
-       
        /**
         * list of visible menu items
         * @var array<\wcf\system\menu\ITreeMenuItem>
@@ -38,17 +33,6 @@ abstract class TreeMenu extends SingletonFactory {
         */
        public $menuItems = null;
        
-       /**
-        * TreeMenu constructor.
-        * 
-        * @param       EventHandler    $eventHandler
-        */
-       public function __construct(EventHandler $eventHandler) {
-               $this->eventHandler = $eventHandler;
-               
-               parent::__construct();
-       }
-       
        /**
         * @see \wcf\system\SingletonFactory::init()
         */
@@ -66,7 +50,7 @@ abstract class TreeMenu extends SingletonFactory {
                $this->buildMenuItemList();
                
                // call init event
-               $this->eventHandler->fireAction($this, 'init');
+               EventHandler::getInstance()->fireAction($this, 'init');
        }
        
        /**
@@ -74,7 +58,7 @@ abstract class TreeMenu extends SingletonFactory {
         */
        protected function loadCache() {
                // call loadCache event
-               $this->eventHandler->fireAction($this, 'loadCache');
+               EventHandler::getInstance()->fireAction($this, 'loadCache');
                
                $this->menuItems = array();
        }
index a828e0af8bfe26eaa3508449db41b798c4d06c36..db2334786e5731bffd6acd3bf77e9052a1883f72 100644 (file)
@@ -15,23 +15,6 @@ use wcf\system\menu\TreeMenu;
  * @category   Community Framework
  */
 class ACPMenu extends TreeMenu {
-       /**
-        * @var ACPMenuCacheBuilder
-        */
-       protected $acpMenuCacheBuilder;
-       
-       /**
-        * ACPMenu constructor.
-        * 
-        * @param       ACPMenuCacheBuilder     $acpMenuCacheBuilder
-        * @param       EventHandler            $eventHandler
-        */
-       public function __construct(ACPMenuCacheBuilder $acpMenuCacheBuilder, EventHandler $eventHandler) {
-               $this->acpMenuCacheBuilder = $acpMenuCacheBuilder;
-               
-               parent::__construct($eventHandler);
-       }
-       
        /**
         * @see TreeMenu::loadCache()
         */
@@ -42,6 +25,6 @@ class ACPMenu extends TreeMenu {
                        return;
                }
                
-               $this->menuItems = $this->acpMenuCacheBuilder->getData();
+               $this->menuItems = ACPMenuCacheBuilder::getInstance()->getData();
        }
 }
index ba95c43adc73835032bb86f4885d54348e209273..5f20d75d367c83ee6dcabf8a383335e0fce5bc0e 100644 (file)
@@ -24,23 +24,6 @@ class PageMenu extends TreeMenu {
         */
        protected $landingPage = null;
        
-       /**
-        * @var PageMenuCacheBuilder
-        */
-       protected $pageMenuCacheBuilder;
-       
-       /**
-        * PageMenu constructor.
-        * 
-        * @param       EventHandler            $eventHandler
-        * @param       PageMenuCacheBuilder    $pageMenuCacheBuilder
-        */
-       public function __construct(EventHandler $eventHandler, PageMenuCacheBuilder $pageMenuCacheBuilder) {
-               $this->pageMenuCacheBuilder = $pageMenuCacheBuilder;
-               
-               parent::__construct($eventHandler);
-       }
-       
        /**
         * @see \wcf\system\SingletonFactory::init()
         * @throws      SystemException
@@ -58,7 +41,7 @@ class PageMenu extends TreeMenu {
                $this->buildMenuItemList('footer');
                
                // call init event
-               $this->eventHandler->fireAction($this, 'init');
+               EventHandler::getInstance()->fireAction($this, 'init');
                
                foreach ($this->menuItems as $menuItems) {
                        foreach ($menuItems as $menuItem) {
@@ -92,7 +75,7 @@ class PageMenu extends TreeMenu {
                parent::loadCache();
                
                // get cache
-               $this->menuItems = $this->pageMenuCacheBuilder->getData();
+               $this->menuItems = PageMenuCacheBuilder::getInstance()->getData();
        }
        
        /**
index e2a33057940aad62d83d30e5b79a6cc77b58adb2..c92c4db6de8e78d024ab8f97d134551570e6549b 100644 (file)
@@ -18,30 +18,13 @@ use wcf\system\menu\TreeMenu;
  * @category   Community Framework
  */
 class UserMenu extends TreeMenu {
-       /**
-        * @var UserMenuCacheBuilder
-        */
-       protected $userMenuCacheBuilder;
-       
-       /**
-        * UserMenu constructor.
-        * 
-        * @param       EventHandler            $eventHandler
-        * @param       UserMenuCacheBuilder    $userMenuCacheBuilder
-        */
-       public function __construct(EventHandler $eventHandler, UserMenuCacheBuilder $userMenuCacheBuilder) {
-               $this->userMenuCacheBuilder = $userMenuCacheBuilder;
-               
-               parent::__construct($eventHandler);
-       }
-       
        /**
         * @see TreeMenu::loadCache()
         */
        protected function loadCache() {
                parent::loadCache();
                
-               $this->menuItems = $this->userMenuCacheBuilder->getData();
+               $this->menuItems = UserMenuCacheBuilder::getInstance()->getData();
        }
        
        /**
index c6f56507e43ff90876cd5a3ccb5acfc627b2b001..f3bbfdd01efda8581240feec3f9cd416690ea28a 100644 (file)
@@ -23,35 +23,12 @@ class UserProfileMenu extends SingletonFactory {
         */
        public $activeMenuItem = null;
        
-       /**
-        * @var EventHandler
-        */
-       protected $eventHandler;
-       
        /**
         * list of all menu items
         * @var UserProfileMenuItem[]
         */
        public $menuItems = null;
        
-       /**
-        * @var UserProfileMenuCacheBuilder
-        */
-       protected $userProfileMenuCacheBuilder;
-       
-       /**
-        * UserProfileMenu constructor.
-        * 
-        * @param       EventHandler                    $eventHandler
-        * @param       UserProfileMenuCacheBuilder     $userProfileMenuCacheBuilder
-        */
-       public function __construct(EventHandler $eventHandler, UserProfileMenuCacheBuilder $userProfileMenuCacheBuilder) {
-               $this->eventHandler = $eventHandler;
-               $this->userProfileMenuCacheBuilder = $userProfileMenuCacheBuilder;
-               
-               parent::__construct();
-       }
-       
        /**
         * @see \wcf\system\SingletonFactory::init()
         */
@@ -63,7 +40,7 @@ class UserProfileMenu extends SingletonFactory {
                $this->checkMenuItems();
                
                // call init event
-               $this->eventHandler->fireAction($this, 'init');
+               EventHandler::getInstance()->fireAction($this, 'init');
        }
        
        /**
@@ -71,9 +48,9 @@ class UserProfileMenu extends SingletonFactory {
         */
        protected function loadCache() {
                // call loadCache event
-               $this->eventHandler->fireAction($this, 'loadCache');
+               EventHandler::getInstance()->fireAction($this, 'loadCache');
                
-               $this->menuItems = $this->userProfileMenuCacheBuilder->getData();
+               $this->menuItems = UserProfileMenuCacheBuilder::getInstance()->getData();
        }
        
        /**
index 03d7176a939dd7bf14df82af39d785325e7ca9a1..b09b857ee9f8caf30cf0723f91dd28a3a119b92e 100644 (file)
@@ -80,7 +80,7 @@ class RequestHandler extends SingletonFactory {
        public function handle($application = 'wcf', $isACPRequest = false) {
                $this->isACPRequest = $isACPRequest;
                
-               if (!RouteHandler::getInstance()->matches($application)) {
+               if (!RouteHandler::getInstance()->matches()) {
                        if (ENABLE_DEBUG_MODE) {
                                throw new SystemException("Cannot handle request, no valid route provided.");
                        }
index c6bec80ec96fc46b05c5de50b482cf7d637eff6d..9238d0ba5368bd9001a4f10efd474345e564f96c 100644 (file)
@@ -4,7 +4,7 @@ use wcf\system\application\ApplicationHandler;
 use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\request\route\DynamicRequestRoute;
-use wcf\system\request\route\IRequestRoute;
+use wcf\system\request\route\LookupRequestRoute;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 use wcf\util\FileUtil;
@@ -86,7 +86,9 @@ class RouteHandler extends SingletonFactory {
                $this->addRoute($route);
                
                $route = new DynamicRequestRoute();
-               $route->setIsACP(false);
+               $this->addRoute($route);
+               
+               $route = new LookupRequestRoute();
                $this->addRoute($route);
                
                // fire event
@@ -116,25 +118,15 @@ class RouteHandler extends SingletonFactory {
         * first route that is able to consume all path components is used,
         * even if other routes may fit better. Route order is crucial!
         * 
-        * @param       string  $application    application identifier
         * @return      boolean
         */
-       public function matches($application) {
+       public function matches() {
                foreach ($this->routes as $route) {
-                       if ($this->requestHandler->isACPRequest() != $route->isACP()) {
+                       if (RequestHandler::getInstance()->isACPRequest() != $route->isACP()) {
                                continue;
                        }
                        
-                       $match = false;
-                       if ($route instanceof IRequestRoute) {
-                               $match = $route->matches($application, self::getPathInfo());
-                       }
-                       else if ($route instanceof IRoute) {
-                               // legacy route
-                               $match =  $route->matches(self::getPathInfo());
-                       }
-                       
-                       if ($match) {
+                       if ($route->matches(self::getPathInfo())) {
                                $this->routeData = $route->getRouteData();
                                
                                $this->isDefaultController = $this->routeData['isDefaultController'];
@@ -186,7 +178,7 @@ class RouteHandler extends SingletonFactory {
         * @throws      SystemException
         */
        public function buildRoute(array $components, $isACP = null) {
-               if ($isACP === null) $isACP = $this->requestHandler->isACPRequest();
+               if ($isACP === null) $isACP = RequestHandler::getInstance()->isACPRequest();
                
                foreach ($this->routes as $route) {
                        if ($isACP != $route->isACP()) {
index 0258c90775282d5dc2cf7d5ef7cd40d8814018ee..96192b1eabbf391d736b04d4fb2b0acb34baf935 100644 (file)
@@ -53,6 +53,13 @@ class DynamicRequestRoute implements IRequestRoute {
         */
        protected $routeData = [];
        
+       /**
+        * DynamicRequestRoute constructor.
+        */
+       public function __construct() {
+               $this->init();
+       }
+       
        /**
         * Sets default routing information.
         */
@@ -288,7 +295,7 @@ class DynamicRequestRoute implements IRequestRoute {
        /**
         * @see IRoute::matches()
         */
-       public function matches($application, $requestURL) {
+       public function matches($requestURL) {
                if (preg_match($this->pattern, $requestURL, $matches)) {
                        foreach ($matches as $key => $value) {
                                if (!is_numeric($key)) {
index e4360e48b7ac739d616c20391907d2265f479bfa..d1a37eb4877bf438280265238487939e0e44cc5d 100644 (file)
@@ -12,46 +12,7 @@ use wcf\system\request\IRoute;
  * @subpackage  system.request
  * @category    Community Framework
  */
-interface IRequestRoute {
-       /**
-        * Builds a link upon route components.
-        *
-        * @param       array           $components     list of url components
-        * @return      string
-        */
-       public function buildLink(array $components);
-       
-       /**
-        * Returns true if current route can handle the build request.
-        *
-        * @param       array           $components     list of url components
-        * @return      boolean
-        */
-       public function canHandle(array $components);
-       
-       /**
-        * Returns parsed route data.
-        *
-        * @return      array
-        */
-       public function getRouteData();
-       
-       /**
-        * Returns true if route applies for ACP.
-        *
-        * @return      boolean
-        */
-       public function isACP();
-       
-       /**
-        * Returns true if given request url matches this route.
-        *
-        * @param       string          $application    application identifier
-        * @param       string          $requestURL     request url
-        * @return      boolean
-        */
-       public function matches($application, $requestURL);
-       
+interface IRequestRoute extends IRoute {
        /**
         * Configures this route to handle either ACP or frontend requests.
         * 
index ac69ec6d151343b45fe1fb409c3c25d0bf18f8b1..25d6fc95faa22fc5ed83810ac07156f6c06b8425 100644 (file)
@@ -1,17 +1,32 @@
 <?php
 namespace wcf\system\request\route;
-
+use wcf\system\application\ApplicationHandler;
 use wcf\system\exception\SystemException;
 use wcf\system\request\ControllerMap;
 use wcf\util\FileUtil;
 
+/**
+ * Attempts to resolve arbitrary request URLs against the list of known custom
+ * controller URLs, optionally recognizing id and title parameter.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.request
+ * @category   Community Framework
+ */
 class LookupRequestRoute implements IRequestRoute {
+       /**
+        * list of parsed route information
+        * @var array
+        */
        protected $routeData = [];
        
        /**
         * @inheritDoc
         */
-       public function matches($application, $requestURL) {
+       public function matches($requestURL) {
                $requestURL = FileUtil::addLeadingSlash($requestURL);
                
                if ($requestURL === '/') {
@@ -33,6 +48,7 @@ class LookupRequestRoute implements IRequestRoute {
                $~x';
                
                if (preg_match($regex, $requestURL, $matches)) {
+                       $application = ApplicationHandler::getInstance()->getActiveApplication()->getAbbreviation();
                        if (!empty($matches['id'])) {
                                // check for static controller URLs
                                $this->routeData = ControllerMap::getInstance()->resolveCustomController($application, $matches['controller']);
index 087c2eac2ddac3285355ab198ea1e86bfc7c59e3..1fc6958f881643cf5eedadeb5f9d31c31a7c8acb 100644 (file)
@@ -73,8 +73,8 @@ class StaticRequestRoute extends DynamicRequestRoute {
        /**
         * @see \wcf\system\request\IRoute::matches()
         */
-       public function matches($application, $requestURL) {
-               if (parent::matches($application, $requestURL)) {
+       public function matches($requestURL) {
+               if (parent::matches($requestURL)) {
                        $this->routeData['application'] = $this->staticApplication;
                        $this->routeData['controller'] = ControllerMap::getInstance()->lookup($this->staticController);
                        $this->routeData['isDefaultController'] = false;
index 943695bbb7ad881bcea73a84a47cc9151ebd9be7..969b6d616322804d21298879ec1530ebba64e2aa 100644 (file)
@@ -23,7 +23,7 @@ class SessionFactory extends ACPSessionFactory {
         */
        public function hasValidCookie() {
                if (isset($_COOKIE[COOKIE_PREFIX.'cookieHash'])) {
-                       if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == $this->sessionHandler->sessionID) {
+                       if ($_COOKIE[COOKIE_PREFIX.'cookieHash'] == SessionHandler::getInstance()->sessionID) {
                                return true;
                        }
                }
@@ -49,11 +49,12 @@ class SessionFactory extends ACPSessionFactory {
        protected function init() {
                if (!$this->hasValidCookie()) {
                        // cookie support will be enabled upon next request
-                       HeaderUtil::setCookie('cookieHash', $this->sessionHandler->sessionID);
+                       HeaderUtil::setCookie('cookieHash', SessionHandler::getInstance()->sessionID);
                }
                
                // enable cookie support
-               $this->sessionHandler->enableCookies();
+               
+               SessionHandler::getInstance()->enableCookies();
                
                parent::init();
        }