From: Alexander Ebert Date: Thu, 26 Nov 2015 10:00:40 +0000 (+0100) Subject: Fixed wcfsetup and acp/frontend access X-Git-Tag: 3.0.0_Beta_1~2030^2~234^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2d38f34636761f9a5f90847e7df74369f3921cbe;p=GitHub%2FWoltLab%2FWCF.git Fixed wcfsetup and acp/frontend access --- diff --git a/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php b/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php index 0e52537f23..e35977943a 100644 --- a/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/TreeMenu.class.php @@ -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(); } diff --git a/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php b/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php index a828e0af8b..db2334786e 100644 --- a/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/acp/ACPMenu.class.php @@ -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(); } } diff --git a/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php b/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php index ba95c43adc..5f20d75d36 100644 --- a/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php index e2a3305794..c92c4db6de 100644 --- a/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/UserMenu.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php index c6f56507e4..f3bbfdd01e 100644 --- a/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/profile/UserProfileMenu.class.php @@ -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(); } /** diff --git a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php index 03d7176a93..b09b857ee9 100644 --- a/wcfsetup/install/files/lib/system/request/RequestHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RequestHandler.class.php @@ -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."); } diff --git a/wcfsetup/install/files/lib/system/request/RouteHandler.class.php b/wcfsetup/install/files/lib/system/request/RouteHandler.class.php index c6bec80ec9..9238d0ba53 100644 --- a/wcfsetup/install/files/lib/system/request/RouteHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/RouteHandler.class.php @@ -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()) { diff --git a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php index 0258c90775..96192b1eab 100644 --- a/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/DynamicRequestRoute.class.php @@ -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)) { diff --git a/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php index e4360e48b7..d1a37eb487 100644 --- a/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/IRequestRoute.class.php @@ -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. * diff --git a/wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php index ac69ec6d15..25d6fc95fa 100644 --- a/wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/LookupRequestRoute.class.php @@ -1,17 +1,32 @@ + * @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']); diff --git a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php index 087c2eac2d..1fc6958f88 100644 --- a/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php +++ b/wcfsetup/install/files/lib/system/request/route/StaticRequestRoute.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/system/session/SessionFactory.class.php b/wcfsetup/install/files/lib/system/session/SessionFactory.class.php index 943695bbb7..969b6d6163 100644 --- a/wcfsetup/install/files/lib/system/session/SessionFactory.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionFactory.class.php @@ -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(); }