use dotclear URL handler behavior instead of registered handler

This commit is contained in:
Jean-Christian Paul 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 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);