From: Alexander Ebert Date: Tue, 1 Jan 2013 16:49:03 +0000 (+0100) Subject: Fixed landing page and handled infinite loops X-Git-Tag: 2.0.0_Beta_1~621 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c8a4a1f5c09aa6f84fe689bc2a58d926ecd939b0;p=GitHub%2FWoltLab%2FWCF.git Fixed landing page and handled infinite loops Fixes #1063 --- diff --git a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php index 93a84cce09..5c472cf317 100644 --- a/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php +++ b/wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php @@ -116,6 +116,17 @@ class PageMenuItem extends ProcessibleDatabaseObject implements ITreeMenuItem { return ($this->isLandingPage ? false : true); } + /** + * Returns application abbreviation. + * + * @return string + */ + public function getApplication() { + $this->parseController(); + + return $this->application; + } + /** * Returns controller name. * diff --git a/wcfsetup/install/files/lib/system/SingletonFactory.class.php b/wcfsetup/install/files/lib/system/SingletonFactory.class.php index 7621eb7e63..9765eccaaf 100644 --- a/wcfsetup/install/files/lib/system/SingletonFactory.class.php +++ b/wcfsetup/install/files/lib/system/SingletonFactory.class.php @@ -51,9 +51,13 @@ abstract class SingletonFactory { */ public static final function getInstance() { $className = get_called_class(); - if (!isset(self::$__singletonObjects[$className])) { + if (!array_key_exists($className, self::$__singletonObjects)) { + self::$__singletonObjects[$className] = null; self::$__singletonObjects[$className] = new $className(); } + else if (array_key_exists($className, self::$__singletonObjects) && is_null(self::$__singletonObjects[$className])) { + throw new SystemException("Infinite loop detected while trying to retrieve object for '".$className."'"); + } return self::$__singletonObjects[$className]; } diff --git a/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php b/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php index a84d7ab558..c08ea140d9 100644 --- a/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php +++ b/wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php @@ -1,6 +1,8 @@ getLandingPage(); + if ($landingPage !== null) { + PageMenu::getInstance()->setActiveMenuItem($landingPage->menuItem); + + // add main breadcrumbs entry + $this->add(new Breadcrumb(WCF::getLanguage()->get(PAGE_TITLE), $landingPage->getLink())); + } + } + /** * Adds a breadcrumb (insertion order is crucial!). * 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 604a34fb10..e6b75edcf4 100644 --- a/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php +++ b/wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php @@ -5,7 +5,6 @@ use wcf\system\cache\CacheHandler; use wcf\system\event\EventHandler; use wcf\system\menu\ITreeMenuItem; use wcf\system\menu\TreeMenu; -use wcf\system\request\LinkHandler; use wcf\system\WCF; /** @@ -51,14 +50,6 @@ class PageMenu extends TreeMenu { } } } - - // set default menu item - if ($this->landingPage !== null) { - $this->setActiveMenuItem($this->landingPage->menuItem); - - // add main breadcrumbs entry - WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get(PAGE_TITLE), LinkHandler::getInstance()->getLink())); - } } /** diff --git a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php index fe2a6539ff..687fbb807b 100644 --- a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php @@ -1,22 +1,36 @@ * @package com.woltlab.wcf * @subpackage system.request * @category Community Framework */ class LinkHandler extends SingletonFactory { + /** + * regex object to filter title + * @var wcf\system\RegEx + */ + protected $titleRegex = null; + + /** + * @see wcf\system\SingletonFactory::init() + */ + protected function init() { + $this->titleRegex = new Regex('[\x0-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+'); + } + /** * Returns a relative link. * @@ -70,11 +84,11 @@ class LinkHandler extends SingletonFactory { // handle object if (isset($parameters['object'])) { - if (!($parameters['object'] instanceof \wcf\system\request\IRouteController) && $parameters['object'] instanceof \wcf\data\DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof \wcf\system\request\IRouteController) { + if (!($parameters['object'] instanceof IRouteController) && $parameters['object'] instanceof DatabaseObjectDecorator && $parameters['object']->getDecoratedObject() instanceof IRouteController) { $parameters['object'] = $parameters['object']->getDecoratedObject(); } - if ($parameters['object'] instanceof \wcf\system\request\IRouteController) { + if ($parameters['object'] instanceof IRouteController) { $parameters['id'] = $parameters['object']->getID(); $parameters['title'] = $parameters['object']->getTitle(); } @@ -84,7 +98,7 @@ class LinkHandler extends SingletonFactory { if (isset($parameters['title'])) { // remove illegal characters - $parameters['title'] = trim(preg_replace('/[\x0-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/', '-', $parameters['title']), '-'); + $parameters['title'] = trim($this->titleRegex->replace($parameters['title'], '-'), '-'); } $parameters['controller'] = $controller;