Some small optimizations
authorMarcel Werk <burntime@woltlab.com>
Tue, 22 Nov 2011 21:24:08 +0000 (22:24 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 22 Nov 2011 21:24:08 +0000 (22:24 +0100)
wcfsetup/install/files/lib/data/user/User.class.php
wcfsetup/install/files/lib/system/request/LinkHandler.class.php

index 8af6960931c5ece0c75b9ab102669cc1cdfe5876..9e5ea6066b6c94c4d7a7fe41a774faee5822940f 100644 (file)
@@ -4,6 +4,7 @@ use wcf\data\DatabaseObject;
 use wcf\data\user\group\UserGroup;
 use wcf\data\user\UserList;
 use wcf\system\cache\CacheHandler;
+use wcf\system\request\IRouteController;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
 use wcf\util\StringUtil;
@@ -18,7 +19,7 @@ use wcf\util\StringUtil;
  * @subpackage data.user
  * @category   Community Framework
  */
-final class User extends DatabaseObject {
+final class User extends DatabaseObject implements IRouteController {
        /**
         * @see wcf\data\DatabaseObject::$databaseTableName
         */
@@ -336,4 +337,18 @@ final class User extends DatabaseObject {
        public static function getDatabaseTableAlias() {
                return 'user_table';
        }
+       
+       /**
+        * @see wcf\system\request\IRouteController::getID()
+        */
+       public function getID() {
+               return $this->userID;
+       }
+       
+       /**
+        * @see wcf\system\request\IRouteController::getTitle()
+        */
+       public function getTitle() {
+               return $this->username;
+       }
 }
index 6841c8c7ab744b030e40b2bd6881d943f424ef05..459becdc463387f869c48b1c6d0fdbc5e694aca4 100644 (file)
@@ -38,15 +38,24 @@ class LinkHandler extends SingletonFactory {
                // build route
                if ($controller !== null) {
                        // handle object
-                       if (isset($parameters['object']) && $parameters['object'] instanceof \wcf\system\request\IRouteController) {
-                               $parameters['id'] = $parameters['object']->getID();
+                       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)  {
+                                       $parameters['object'] = $parameters['object']->getDecoratedObject();
+                               }
                                
-                               // remove illegal characters
-                               $parameters['title'] = preg_replace('/[\x0-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/', '-', $parameters['object']->getTitle());
+                               if ($parameters['object'] instanceof \wcf\system\request\IRouteController) {
+                                       $parameters['id'] = $parameters['object']->getID();
+                                       $parameters['title'] = $parameters['object']->getTitle();
+                               }
                                
                                unset($parameters['object']);
                        }
                        
+                       if (isset($parameters['title'])) {
+                               // remove illegal characters
+                               $parameters['title'] = trim(preg_replace('/[\x0-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/', '-', $parameters['title']), '-');
+                       }
+                       
                        $parameters['controller'] = $controller;
                        $routeURL = RouteHandler::getInstance()->buildRoute($parameters);
                        if (!$isRaw && !empty($url)) {