cosmetic
This commit is contained in:
parent
39a933e5a1
commit
552de6fea8
@ -40,7 +40,7 @@ class Alias
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
// nullsafe PHP < 8.0
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return [];
|
||||
}
|
||||
@ -51,7 +51,7 @@ class Alias
|
||||
'alias_url',
|
||||
'alias_destination',
|
||||
'alias_position',
|
||||
'alias_redirect'
|
||||
'alias_redirect',
|
||||
])
|
||||
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog->id))
|
||||
->order('alias_position ASC')
|
||||
@ -100,11 +100,11 @@ class Alias
|
||||
* @param string $url The URL
|
||||
* @param string $destination The destination
|
||||
* @param int $position The position
|
||||
* @param bool $position Do redirection
|
||||
* @param bool $redirect Do redirection
|
||||
*/
|
||||
public function createAlias(string $url, string $destination, int $position, bool $redirect): void
|
||||
{
|
||||
// nullsafe PHP < 8.0
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
@ -135,7 +135,7 @@ class Alias
|
||||
*/
|
||||
public function deleteAlias(string $url): void
|
||||
{
|
||||
// nullsafe PHP < 8.0
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
@ -152,7 +152,7 @@ class Alias
|
||||
*/
|
||||
public function deleteAliases(): void
|
||||
{
|
||||
// nullsafe PHP < 8.0
|
||||
// nullsafe
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return;
|
||||
}
|
||||
@ -172,6 +172,6 @@ class Alias
|
||||
*/
|
||||
public static function removeBlogUrl(string $url): string
|
||||
{
|
||||
return str_replace(dcCore::app()->blog->url, '', trim($url));
|
||||
return is_null(dcCore::app()->blog) ? trim($url) : str_replace(dcCore::app()->blog->url, '', trim($url));
|
||||
}
|
||||
}
|
||||
|
@ -36,16 +36,19 @@ class Prepend extends dcNsProcess
|
||||
|
||||
dcCore::app()->addBehavior('urlHandlerGetArgsDocument', function (dcUrlHandlers $handler): void {
|
||||
$found = $redir = false;
|
||||
$type = 'alias';
|
||||
$type = '';
|
||||
$part = $args = $_SERVER['URL_REQUEST_PART'];
|
||||
|
||||
// load all Aliases
|
||||
foreach ((new Alias())->getAliases() as $v) {
|
||||
// multi alias using "/url/" to "destination"
|
||||
if (@preg_match('#^/.*/$#', $v['alias_url']) && @preg_match($v['alias_url'], $args)) {
|
||||
$part = preg_replace($v['alias_url'], $v['alias_destination'], $args);
|
||||
$found = true;
|
||||
$redir = !empty($v['alias_redirect']);
|
||||
|
||||
break;
|
||||
// single alias using "url" to "destination"
|
||||
} elseif ($v['alias_url'] == $args) {
|
||||
$part = $v['alias_destination'];
|
||||
$found = true;
|
||||
@ -55,17 +58,21 @@ class Prepend extends dcNsProcess
|
||||
}
|
||||
}
|
||||
|
||||
// no URLs found
|
||||
if (!$found) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use visible redirection
|
||||
if ($redir) {
|
||||
Http::redirect(dcCore::app()->blog->url . $part);
|
||||
}
|
||||
|
||||
// regain URL type
|
||||
$_SERVER['URL_REQUEST_PART'] = $part;
|
||||
dcCore::app()->url->getArgs($part, $type, $args);
|
||||
|
||||
// call real handler
|
||||
if (!$type) {
|
||||
dcCore::app()->url->callDefaultHandler($args);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user