From 97b6b000ac329ec5a70a5b95e38e2541d3275107 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 11 Nov 2011 22:20:14 +0100 Subject: [PATCH] Enabled basic SEO-like support --- .../system/request/IRouteController.class.php | 28 +++++++++++++++++++ .../lib/system/request/LinkHandler.class.php | 10 +++++++ .../files/lib/system/request/Route.class.php | 9 +++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 wcfsetup/install/files/lib/system/request/IRouteController.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 index 0000000000..9014e19213 --- /dev/null +++ b/wcfsetup/install/files/lib/system/request/IRouteController.class.php @@ -0,0 +1,28 @@ + + * @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(); +} diff --git a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php index 9ab4ae5299..6841c8c7ab 100644 --- a/wcfsetup/install/files/lib/system/request/LinkHandler.class.php +++ b/wcfsetup/install/files/lib/system/request/LinkHandler.class.php @@ -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)) { diff --git a/wcfsetup/install/files/lib/system/request/Route.class.php b/wcfsetup/install/files/lib/system/request/Route.class.php index 039f378c74..6159aeda79 100644 --- a/wcfsetup/install/files/lib/system/request/Route.class.php +++ b/wcfsetup/install/files/lib/system/request/Route.class.php @@ -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]); } } -- 2.20.1