add types to url_dir() definition

This commit is contained in:
maxpozdeev 2025-01-21 16:16:27 +03:00
parent 3ddd6d6ee4
commit f952ddc130
2 changed files with 7 additions and 6 deletions

View file

@ -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, '/')) {

View file

@ -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':