From f952ddc130eabe1b461f62220167a6f71259260a Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Tue, 21 Jan 2025 16:16:27 +0300 Subject: [PATCH] add types to url_dir() definition --- src/includes/common.php | 11 ++++++----- src/init.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/includes/common.php b/src/includes/common.php index e981316..c5fb66b 100644 --- a/src/includes/common.php +++ b/src/includes/common.php @@ -108,18 +108,19 @@ function getRequestUri() } } -function url_dir($url, $onlyPath = 1) +function url_dir(string $url, bool $onlyPath = true) { if (false !== $p = strpos($url, '?')) { $url = substr($url, 0, $p); # to avoid parse errors on strange query strings } + $path = parse_url($url, PHP_URL_PATH) ?? ''; if ($onlyPath) { - $url = parse_url($url, PHP_URL_PATH); + $url = $path; } - if ($url == '') { - return '/'; + if ($path === '') { + return $url . '/'; } - if (substr($url, -1) == '/') { + if (substr($url, -1) === '/') { return $url; } if (false !== $p = strrpos($url, '/')) { diff --git a/src/init.php b/src/init.php index f7c9c9e..25e222a 100644 --- a/src/init.php +++ b/src/init.php @@ -367,7 +367,7 @@ function get_unsafe_mttinfo($v) /* Directory with settings.php. No need to set if you use default directory structure. */ $_mttinfo['mtt_url'] = Config::getUrl('mtt_url'); // need to have a trailing slash if ($_mttinfo['mtt_url'] == '') { - $_mttinfo['mtt_url'] = url_dir( get_unsafe_mttinfo('url'), 0 ); + $_mttinfo['mtt_url'] = url_dir( get_unsafe_mttinfo('url'), false ); } return $_mttinfo['mtt_url']; case 'mtt_uri':