Fixed landing page and handled infinite loops
authorAlexander Ebert <ebert@woltlab.com>
Tue, 1 Jan 2013 16:49:03 +0000 (17:49 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 1 Jan 2013 16:49:03 +0000 (17:49 +0100)
Fixes #1063

wcfsetup/install/files/lib/data/page/menu/item/PageMenuItem.class.php
wcfsetup/install/files/lib/system/SingletonFactory.class.php
wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php
wcfsetup/install/files/lib/system/menu/page/PageMenu.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php

index 93a84cce09e1ffe9cf656cd8401ddeff5f253553..5c472cf317f7c7b2f417e33df0b0846947417c71 100644 (file)
@@ -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.
         * 
index 7621eb7e6392f7269611e03f548c4164ae3f9278..9765eccaaf75cc1fd91500dd00b306b01fb5c278 100644 (file)
@@ -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];
        }
index a84d7ab5588341aafc96ec6bc16d5fe5413539d2..c08ea140d92e1d164c3857dc80de18070dee4e0b 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 namespace wcf\system\breadcrumb;
+use wcf\system\menu\page\PageMenu;
 use wcf\system\SingletonFactory;
+use wcf\system\WCF;
 
 /**
  * Manages breadcrumbs.
@@ -24,6 +26,20 @@ class Breadcrumbs extends SingletonFactory implements \Countable, \Iterator {
         */
        protected $index = 0;
        
+       /**
+        * @see wcf\system\SingletonFactory::init()
+        */
+       protected function init() {
+               // set default menu item
+               $landingPage = PageMenu::getInstance()->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!).
         * 
index 604a34fb10071dd578dd0e464bd537a0b2559c64..e6b75edcf4704824bb04aab7bd99e9e40a6f497e 100644 (file)
@@ -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()));
-               }
        }
        
        /**
index fe2a6539ff589121e1f2dc43af463eb55067248a..687fbb807bd71702f6b563e6aae658a3ea409e4b 100644 (file)
@@ -1,22 +1,36 @@
 <?php
 namespace wcf\system\request;
-use wcf\system\menu\page\PageMenu;
-
+use wcf\data\DatabaseObjectDecorator;
 use wcf\system\application\ApplicationHandler;
+use wcf\system\menu\page\PageMenu;
 use wcf\system\request\RouteHandler;
+use wcf\system\Regex;
 use wcf\system\SingletonFactory;
 
 /**
  * Handles relative links within the wcf.
  * 
  * @author     Marcel Werk
- * @copyright  2001-2012 WoltLab GmbH
+ * @copyright  2001-2013 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 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;