35 lines
887 B
PHP
35 lines
887 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca;
|
|
|
|
use Bitrix\Main\Application;
|
|
|
|
final class Navigation
|
|
{
|
|
public static function isActive(string $path, bool $exact = false): bool
|
|
{
|
|
if (defined("ERROR_404")) {
|
|
return false;
|
|
}
|
|
$current = self::current();
|
|
|
|
return $exact ? $current === $path : str_starts_with($current, $path);
|
|
}
|
|
|
|
private static function current(): string
|
|
{
|
|
$uri = (string)Application::getInstance()->getContext()->getRequest()->getRequestUri();
|
|
$path = (string)parse_url($uri, PHP_URL_PATH);
|
|
if (SITE_DIR !== "/" && str_starts_with($path, SITE_DIR)) {
|
|
$path = "/" . substr($path, strlen(SITE_DIR));
|
|
}
|
|
if (str_ends_with($path, "index.php")) {
|
|
$path = substr($path, 0, -9);
|
|
}
|
|
|
|
return $path === "" ? "/" : $path;
|
|
}
|
|
}
|