Enabled basic SEO-like support
authorAlexander Ebert <ebert@woltlab.com>
Fri, 11 Nov 2011 21:20:14 +0000 (22:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 11 Nov 2011 21:20:14 +0000 (22:20 +0100)
wcfsetup/install/files/lib/system/request/IRouteController.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/request/LinkHandler.class.php
wcfsetup/install/files/lib/system/request/Route.class.php

diff --git a/wcfsetup/install/files/lib/system/request/IRouteController.class.php b/wcfsetup/install/files/lib/system/request/IRouteController.class.php
new file mode 100644 (file)
index 0000000..9014e19
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace wcf\system\request;
+
+/**
+ * Default interface for route controllers.
+ *
+ * @author     Alexander Ebert
+ * @copyright  2001-2011 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
+ */
+interface IRouteController {
+       /**
+        * Returns the object id.
+        * 
+        * @return      integer
+        */
+       public function getID();
+       
+       /**
+        * Returns the object title.
+        * 
+        * @return      string
+        */
+       public function getTitle();
+}
index 9ab4ae52995a7818548558205e13bc130feeb41d..6841c8c7ab744b030e40b2bd6881d943f424ef05 100644 (file)
@@ -37,6 +37,16 @@ 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();
+                               
+                               // remove illegal characters
+                               $parameters['title'] = preg_replace('/[\x0-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/', '-', $parameters['object']->getTitle());
+                               
+                               unset($parameters['object']);
+                       }
+                       
                        $parameters['controller'] = $controller;
                        $routeURL = RouteHandler::getInstance()->buildRoute($parameters);
                        if (!$isRaw && !empty($url)) {
index 039f378c74ca7b911741ab53b50aa6fbffed1a69..6159aeda79a4258144d883bde42647ea12a74194 100644 (file)
@@ -242,7 +242,14 @@ class Route {
                                        continue;
                                }
                                
-                               $link .= $components[$component] . '/';
+                               // handle built-in SEO
+                               if ($component === 'id' && isset($components['title'])) {
+                                       $link .= $components[$component] . '-' . $components['title'] . '/';
+                                       unset($components['title']);
+                               }
+                               else {
+                                       $link .= $components[$component] . '/';
+                               }
                                unset($components[$component]);
                        }
                }