alias/_public.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2022-11-27 12:57:51 +00:00
<?php
2022-11-27 13:51:46 +00:00
/**
* @brief alias, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Olivier Meunier and contributors
*
2022-11-28 21:52:27 +00:00
* @copyright Jean-Christian Denis
2022-11-27 13:51:46 +00:00
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
dcCore::app()->url->register('alias', '', '^(.*)$', ['urlAlias','alias']);
2022-11-27 12:57:51 +00:00
class urlAlias extends dcUrlHandlers
{
2022-11-27 13:51:46 +00:00
public static function alias($args)
{
$o = new dcAliases();
$aliases = $o->getAliases();
foreach ($aliases as $v) {
if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) {
self::callAliasHandler(preg_replace($v['alias_url'], $v['alias_destination'], $args));
return;
} elseif ($v['alias_url'] == $args) {
self::callAliasHandler($v['alias_destination']);
return;
}
}
self::callAliasHandler($args);
}
public static function callAliasHandler($part)
{
dcCore::app()->url->unregister('alias');
dcCore::app()->url->getArgs($part, $type, $args);
if (!$type) {
dcCore::app()->url->callDefaultHandler($args);
} else {
dcCore::app()->url->callHandler($type, $args);
}
}
2022-11-27 12:57:51 +00:00
}