From 833e0da4f0eec672757b5e0e323a0c9aa4c6bd87 Mon Sep 17 00:00:00 2001 From: Torsten Blindert Date: Fri, 4 May 2018 10:32:32 +0200 Subject: [PATCH 1/2] FEATURE: Implemented blacklist to exclude paths from seo routing --- Classes/BlacklistTrait.php | 41 ++++++++++++++++++++++++++++++++++++ Classes/Router.php | 5 +++-- Classes/RoutingComponent.php | 10 +++++---- Configuration/Settings.yaml | 2 ++ 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 Classes/BlacklistTrait.php diff --git a/Classes/BlacklistTrait.php b/Classes/BlacklistTrait.php new file mode 100644 index 0000000..6c947f1 --- /dev/null +++ b/Classes/BlacklistTrait.php @@ -0,0 +1,41 @@ +getPath(); + foreach ($this->blacklist as $rawPattern => $active) { + $pattern = '/' . str_replace('/', '\/', $rawPattern) . '/'; + if ($active === true && preg_match($pattern, $path) === 1) { + return true; + } + } + + return false; + } +} diff --git a/Classes/Router.php b/Classes/Router.php index 7a33778..a5f6b1b 100644 --- a/Classes/Router.php +++ b/Classes/Router.php @@ -17,6 +17,8 @@ class Router extends \Neos\Flow\Mvc\Routing\Router { + use BlacklistTrait; + /** * Resolves the current uri and ensures that a trailing slash is present * @@ -28,8 +30,7 @@ public function resolve(ResolveContext $resolveContext): UriInterface /** @var Uri $uri */ $uri = parent::resolve($resolveContext); - $info = pathinfo($uri); - if (!isset($info['extension'])) { + if ($this->matchesBlacklist($uri) === false && isset(pathinfo($uri)['extension']) === false) { // $uri needs to be reparsed, because the path often contains the query $parsedUri = new Uri((string)$uri); $parsedUri->setPath(rtrim($parsedUri->getPath(), '/') . '/'); diff --git a/Classes/RoutingComponent.php b/Classes/RoutingComponent.php index 377e916..c4b58fd 100644 --- a/Classes/RoutingComponent.php +++ b/Classes/RoutingComponent.php @@ -18,6 +18,8 @@ class RoutingComponent extends \Neos\Flow\Mvc\Routing\RoutingComponent { + use BlacklistTrait; + /** * The original routing component uses the concret router, not the interface * so it has to be overwritten here @@ -41,11 +43,11 @@ class RoutingComponent extends \Neos\Flow\Mvc\Routing\RoutingComponent public function handle(ComponentContext $componentContext) { $uri = $componentContext->getHttpRequest()->getUri(); + $path = $uri->getPath(); - if ($this->configuration['enable'] === true && $uri->getPath()[-1] !== '/') { - $info = pathinfo($uri); - if (!isset($info['extension'])) { - $uri->setPath($uri->getPath() . '/'); + if ($this->configuration['enable'] === true && $path[-1] !== '/') { + if ($this->matchesBlacklist($uri) === false && isset(pathinfo($uri)['extension']) === false) { + $uri->setPath($path . '/'); $response = $componentContext->getHttpResponse(); $response->setStatus($this->configuration['statusCode']); $response->setHeader('Location', (string) $uri); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 3a009fe..abcef52 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -4,6 +4,8 @@ Yeebase: redirect: enable: TRUE statusCode: 303 + blacklist: + '/neos/.*': TRUE Neos: Flow: From 70395735bb58d4c7622e04cc283e3f4c6b5397e4 Mon Sep 17 00:00:00 2001 From: Torsten Blindert Date: Fri, 4 May 2018 10:48:28 +0200 Subject: [PATCH 2/2] TASK: Fixed doc header --- Classes/BlacklistTrait.php | 2 +- Classes/Router.php | 2 +- Classes/RoutingComponent.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/BlacklistTrait.php b/Classes/BlacklistTrait.php index 6c947f1..209cf35 100644 --- a/Classes/BlacklistTrait.php +++ b/Classes/BlacklistTrait.php @@ -2,7 +2,7 @@ namespace Yeebase\SEO\Routing; /** - * This file is part of the Yeebase.Readiness package. + * This file is part of the Yeebase.SEO.Routing package. * * (c) 2018 yeebase media GmbH * diff --git a/Classes/Router.php b/Classes/Router.php index a5f6b1b..c7af187 100644 --- a/Classes/Router.php +++ b/Classes/Router.php @@ -2,7 +2,7 @@ namespace Yeebase\SEO\Routing; /** - * This file is part of the Yeebase.Readiness package. + * This file is part of the Yeebase.SEO.Routing package. * * (c) 2018 yeebase media GmbH * diff --git a/Classes/RoutingComponent.php b/Classes/RoutingComponent.php index c4b58fd..300a241 100644 --- a/Classes/RoutingComponent.php +++ b/Classes/RoutingComponent.php @@ -2,7 +2,7 @@ namespace Yeebase\SEO\Routing; /** - * This file is part of the Yeebase.Readiness package. + * This file is part of the Yeebase.SEO.Routing package. * * (c) 2018 yeebase media GmbH *