Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс

This commit is contained in:
jimagie committed 2026-10-22 19:28:52 +05:00
commit bb7d8af290
469 files changed
+26426

No files matched your search

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace Jinove\Vinoteca;
class Routing
{
private const MOVED = ["news" => "articles"];
public static function onPageStart(): void
{
if (defined("ADMIN_SECTION") || PHP_SAPI === "cli" || !in_array($_SERVER["REQUEST_METHOD"] ?? "", ["GET", "HEAD"], true)) {
return;
}
$uri = (string)($_SERVER["REQUEST_URI"] ?? "");
$path = (string)parse_url($uri, PHP_URL_PATH);
$query = (string)parse_url($uri, PHP_URL_QUERY);
if ($path === "" || preg_match('#^/(bitrix|upload|local|include)/#', $path)) {
return;
}
if (str_contains(basename($path), ".")) {
return;
}
$target = str_contains($path, "%") ? $path : mb_strtolower($path);
if (preg_match('#^(/(?:ru|pl))?/(' . implode("|", array_keys(self::MOVED)) . ')(/.*)?$#', $target, $match)) {
$target = $match[1] . "/" . self::MOVED[$match[2]] . ($match[3] ?? "/");
}
if (!str_ends_with($target, "/")) {
$target .= "/";
}
if ($target !== $path) {
LocalRedirect(Config::host() . $target . ($query !== "" ? "?" . $query : ""), true, "301 Moved permanently");
}
}
}