use dotclear URL handler behavior instead of registered handler
This commit is contained in:
parent
dba8a1f7d0
commit
7214890c44
1 changed files with 14 additions and 6 deletions
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue