доставка в плавающем
This commit is contained in:
@@ -16,6 +16,86 @@ require_once dirname(__DIR__) . '/app/bootstrap.php';
|
||||
|
||||
$router = new Router();
|
||||
|
||||
$absoluteSiteUrl = static function (): string {
|
||||
$siteUrl = rtrim((string) app_env('SITE_URL', ''), '/');
|
||||
if ($siteUrl !== '') {
|
||||
return $siteUrl;
|
||||
}
|
||||
|
||||
$host = preg_replace('/[^a-z0-9.\-:]/i', '', (string) ($_SERVER['HTTP_HOST'] ?? 'new.rybstock.ru'));
|
||||
|
||||
return 'https://' . $host;
|
||||
};
|
||||
|
||||
$xmlEscape = static fn (string $value): string => htmlspecialchars($value, ENT_XML1 | ENT_COMPAT, 'UTF-8');
|
||||
|
||||
$sitemapHandler = static function () use ($absoluteSiteUrl, $xmlEscape): void {
|
||||
$baseUrl = $absoluteSiteUrl();
|
||||
$today = date('Y-m-d');
|
||||
$urls = [];
|
||||
|
||||
$addUrl = static function (
|
||||
string $path,
|
||||
string $priority,
|
||||
string $changefreq = 'weekly',
|
||||
?string $lastmod = null
|
||||
) use (&$urls, $baseUrl, $today): void {
|
||||
$urls[] = [
|
||||
'loc' => $baseUrl . ($path === '/' ? '/' : '/' . ltrim($path, '/')),
|
||||
'lastmod' => $lastmod ?: $today,
|
||||
'changefreq' => $changefreq,
|
||||
'priority' => $priority,
|
||||
];
|
||||
};
|
||||
|
||||
$addUrl('/', '1.0', 'daily');
|
||||
$addUrl('/catalog', '0.9', 'daily');
|
||||
$addUrl('/promo', '0.8', 'daily');
|
||||
$addUrl('/new', '0.8', 'daily');
|
||||
$addUrl('/delivery', '0.6', 'monthly');
|
||||
$addUrl('/payment', '0.5', 'monthly');
|
||||
$addUrl('/contacts', '0.5', 'monthly');
|
||||
$addUrl('/returns', '0.4', 'monthly');
|
||||
|
||||
try {
|
||||
foreach ((new CategoryRepository())->active() as $category) {
|
||||
$addUrl('/catalog/' . (string) $category['slug'], '0.7', 'weekly');
|
||||
}
|
||||
|
||||
foreach ((new ProductRepository())->sitemapProducts() as $product) {
|
||||
$dateSource = $product['updated_at'] ?: ($product['published_at'] ?: $product['created_at']);
|
||||
$lastmod = $dateSource ? date('Y-m-d', strtotime((string) $dateSource)) : $today;
|
||||
$addUrl('/product/' . (string) $product['slug'], '0.6', 'weekly', $lastmod);
|
||||
}
|
||||
} catch (Throwable) {
|
||||
// Keep a valid sitemap available even during database maintenance.
|
||||
}
|
||||
|
||||
header('Content-Type: application/xml; charset=UTF-8');
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
echo "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
|
||||
foreach ($urls as $url) {
|
||||
echo " <url>\n";
|
||||
echo ' <loc>' . $xmlEscape($url['loc']) . "</loc>\n";
|
||||
echo ' <lastmod>' . $xmlEscape($url['lastmod']) . "</lastmod>\n";
|
||||
echo ' <changefreq>' . $xmlEscape($url['changefreq']) . "</changefreq>\n";
|
||||
echo ' <priority>' . $xmlEscape($url['priority']) . "</priority>\n";
|
||||
echo " </url>\n";
|
||||
}
|
||||
echo "</urlset>\n";
|
||||
};
|
||||
|
||||
$robotsHandler = static function () use ($absoluteSiteUrl): void {
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
echo "User-agent: *\n";
|
||||
echo "Allow: /\n";
|
||||
echo "Disallow: /admin/\n";
|
||||
echo "Disallow: /public/admin/\n";
|
||||
echo "Disallow: /cart\n";
|
||||
echo "\n";
|
||||
echo 'Sitemap: ' . $absoluteSiteUrl() . "/sitemap.xml\n";
|
||||
};
|
||||
|
||||
$catalogSearchHandler = static function (?string $rawQuery = null): void {
|
||||
$queryParameters = [];
|
||||
parse_str((string) (parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_QUERY) ?? ''), $queryParameters);
|
||||
@@ -111,11 +191,15 @@ $catalogSearchHandler = static function (?string $rawQuery = null): void {
|
||||
};
|
||||
|
||||
$router->get('/', static fn () => (new HomeController())->index());
|
||||
$router->get('/robots.txt', $robotsHandler);
|
||||
$router->get('/sitemap.xml', $sitemapHandler);
|
||||
$router->post('/price-request', static fn () => (new PriceRequestController())->store());
|
||||
$router->post('/wishlist-request', static fn () => (new WishlistRequestController())->store());
|
||||
$router->post('/api/cart/sync', static fn () => (new CartController())->sync());
|
||||
$router->get('/search', static fn () => $catalogSearchHandler());
|
||||
$router->get('/search/{query}', static fn (string $query) => $catalogSearchHandler($query));
|
||||
$router->get('/promo', static fn () => (new CatalogController())->promo());
|
||||
$router->get('/new', static fn () => (new CatalogController())->newest());
|
||||
$router->get('/catalog', static fn () => trim((string) ($_GET['q'] ?? '')) !== '' ? $catalogSearchHandler() : (new CatalogController())->index());
|
||||
$router->get('/delivery', static fn () => (new PageController())->delivery());
|
||||
$router->get('/payment', static fn () => (new PageController())->payment());
|
||||
|
||||
Reference in New Issue
Block a user