From 7214890c445a055cb9095ea7cde8883668586121 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Apr 2023 23:13:14 +0200 Subject: [PATCH] use dotclear URL handler behavior instead of registered handler --- src/{Frontend.php => Prepend.php} | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) rename src/{Frontend.php => Prepend.php} (68%) diff --git a/src/Frontend.php b/src/Prepend.php similarity index 68% rename from src/Frontend.php rename to src/Prepend.php index 87970bd..6d1381a 100644 --- a/src/Frontend.php +++ b/src/Prepend.php @@ -16,8 +16,9 @@ namespace Dotclear\Plugin\alias; use dcCore; use dcNsProcess; +use dcUrlHandlers; -class Frontend extends dcNsProcess +class Prepend extends dcNsProcess { public static function init(): bool { @@ -32,21 +33,28 @@ class Frontend extends dcNsProcess return false; } - dcCore::app()->url->register('alias', '', '^(.*)$', function (string $args): void { - $part = $args; - + dcCore::app()->addBehavior('urlHandlerGetArgsDocument', function (dcUrlHandlers $handler): void { + $found = false; + $type = 'alias'; + $part = $args = $_SERVER['URL_REQUEST_PART']; foreach ((new Alias())->getAliases() as $v) { if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) { - $part = preg_replace($v['alias_url'], $v['alias_destination'], $args); + $part = preg_replace($v['alias_url'], $v['alias_destination'], $args); + $found = true; break; } elseif ($v['alias_url'] == $args) { - $part = $v['alias_destination']; + $part = $v['alias_destination']; + $found = true; break; } } + if (!$found) { + return; + } + dcCore::app()->url->unregister('alias'); dcCore::app()->url->getArgs($part, $type, $args);