use dotclear URL handler behavior instead of registered handler

This commit is contained in:
Jean-Christian Denis 2023-04-30 23:13:14 +02:00
parent dba8a1f7d0
commit 7214890c44
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951

View file

@ -16,8 +16,9 @@ namespace Dotclear\Plugin\alias;
use dcCore; use dcCore;
use dcNsProcess; use dcNsProcess;
use dcUrlHandlers;
class Frontend extends dcNsProcess class Prepend extends dcNsProcess
{ {
public static function init(): bool public static function init(): bool
{ {
@ -32,21 +33,28 @@ class Frontend extends dcNsProcess
return false; return false;
} }
dcCore::app()->url->register('alias', '', '^(.*)$', function (string $args): void { dcCore::app()->addBehavior('urlHandlerGetArgsDocument', function (dcUrlHandlers $handler): void {
$part = $args; $found = false;
$type = 'alias';
$part = $args = $_SERVER['URL_REQUEST_PART'];
foreach ((new Alias())->getAliases() as $v) { foreach ((new Alias())->getAliases() as $v) {
if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) { 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; break;
} elseif ($v['alias_url'] == $args) { } elseif ($v['alias_url'] == $args) {
$part = $v['alias_destination']; $part = $v['alias_destination'];
$found = true;
break; break;
} }
} }
if (!$found) {
return;
}
dcCore::app()->url->unregister('alias'); dcCore::app()->url->unregister('alias');
dcCore::app()->url->getArgs($part, $type, $args); dcCore::app()->url->getArgs($part, $type, $args);