v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- require_once __DIR__ . '/icons.php';
- require_once __DIR__ . '/asset.php';
- require_once __DIR__ . '/csrf.php';
- require_once __DIR__ . '/cart.php';
-
- $cartItemCount = Cart::count();
- $cartIsGuest = !UserAuth::check();
-
- function renderShopIcon(array $settings, string $extraClass = 'icon'): string
- {
- $choice = (string) ($settings['shop_icon_choice'] ?? 'cart');
- if ($choice === 'custom') {
- $customSvg = (string) ($settings['shop_icon_custom_svg'] ?? '');
- if ($customSvg !== '') {
- return '<span class="' . htmlspecialchars($extraClass, ENT_QUOTES) . ' shop-icon-custom" aria-hidden="true">' . $customSvg . '</span>';
- }
- $choice = 'cart';
- }
-
- return Icons::icon($choice, $extraClass);
- }
- $cartExportItems = $cartIsGuest ? array_map(
- static fn(array $item): array => [
- 'product_id' => $item['product_id'],
- 'variant_id' => $item['variant_id'],
- 'quantity' => $item['quantity'],
- ],
- Cart::items()
- ) : [];
-
- if (Languages::current() !== '') {
- ob_start([Languages::class, 'absolutizeUrls']);
- }
-
- $navItems = SiteFront::navItems();
-
- $menuPositionClass = 'site-menu-' . ($settings['menu_position'] ?? 'top');
-
- $resolvedPageTitle = $pageTitle ?? $settings['site_name'];
- $resolvedPageDescription = $pageDescription ?? '';
- $isHomepage = ($_SERVER['REQUEST_URI'] ?? '') === '/' || basename((string) ($_SERVER['SCRIPT_NAME'] ?? '')) === 'index.php';
-
- ?>
- <!DOCTYPE html>
- <html lang="<?= htmlspecialchars(Languages::htmlLang(), ENT_QUOTES) ?>">
-
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title><?= htmlspecialchars($resolvedPageTitle) ?></title>
- <?php if (!empty($resolvedPageDescription)): ?>
- <meta name="description" content="<?= htmlspecialchars($resolvedPageDescription) ?>">
- <?php endif; ?>
- <?= SiteFront::renderSeoMeta() ?>
- <?= Languages::renderAlternates() ?>
- <?= SiteFront::renderOpenGraph($resolvedPageTitle, $resolvedPageDescription, $ogType ?? 'website', $ogImagePath ?? null) ?>
- <?php if ($isHomepage): ?>
- <?= SiteFront::renderOrganizationSchema() ?>
- <?php endif; ?>
- <?= Asset::favicon() ?>
- <?php if (($settings['pwa_enabled'] ?? '0') === '1'): ?>
- <?php $pwaIconUrl = !empty($settings['pwa_icon_url']) ? $settings['pwa_icon_url'] : ($settings['site_logo_url'] ?? ''); ?>
- <link rel="manifest" href="<?= htmlspecialchars(rtrim(Config::get('APP_BASE_PATH', ''), '/')) ?>/manifest.json">
- <meta name="theme-color" content="<?= htmlspecialchars($settings['pwa_theme_color'] ?: '#ffffff') ?>">
- <?php if (!empty($pwaIconUrl)): ?>
- <link rel="apple-touch-icon" href="<?= htmlspecialchars($pwaIconUrl) ?>">
- <?php endif; ?>
- <?php endif; ?>
- <?= Asset::css('assets/site.css') ?>
- <style>
- <?= SiteFront::renderFontFaces() ?><?= SiteFront::fontVariablesCss() ?>
- </style>
- <?php if (!empty($settings['custom_css'])): ?>
- <style>
- <?= $settings['custom_css'] ?>
- </style>
- <?php endif; ?>
- <?= SiteFront::renderCustomHeadHtml($pageType ?? null) ?>
- <?= SiteFront::renderAnalyticsScripts('head') ?>
- </head>
-
- <body class="<?= htmlspecialchars($menuPositionClass) ?>" data-theme="light">
- <?= SiteFront::renderAnalyticsScripts('body_start') ?>
- <script>
- (function() {
- try {
- var t = localStorage.getItem('stocketbase_theme');
- if (t === 'dark' || t === 'light') {
- document.body.setAttribute('data-theme', t);
- } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
- document.body.setAttribute('data-theme', 'dark');
- }
- } catch (e) {}
- })();
- </script>
- <?php if ($cartIsGuest): ?>
- <script>
- (function() {
- var STORAGE_KEY = 'stocketbase_cart_backup';
- var serverItems = <?= json_encode($cartExportItems, JSON_UNESCAPED_SLASHES) ?>;
-
- try {
- if (serverItems.length > 0) {
- localStorage.setItem(STORAGE_KEY, JSON.stringify(serverItems));
- return;
- }
-
- var raw = localStorage.getItem(STORAGE_KEY);
- if (!raw) {
- return;
- }
- var backup = JSON.parse(raw);
- if (!Array.isArray(backup) || backup.length === 0) {
- return;
- }
-
- var csrfToken = <?= json_encode(Csrf::token()) ?>;
- var body = new URLSearchParams();
- body.set('action', 'restore_from_client');
- body.set('csrf_token', csrfToken);
- body.set('items', JSON.stringify(backup));
-
- fetch('cart.php', {
- method: 'POST',
- credentials: 'same-origin',
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
- body: body.toString()
- }).then(function(response) {
- if (response.ok) {
- window.location.reload();
- }
- }).catch(function() {});
- } catch (e) {}
- })();
- </script>
- <?php endif; ?>
- <?= Icons::sprite() ?>
- <div class="site-shell">
-
- <?php $headerHasAuthButtons = UserAuth::check() || ($settings['login_enabled'] ?? '1') !== '0'; ?>
- <header class="site-header<?= $headerHasAuthButtons ? '' : ' site-header-no-auth' ?>">
- <div class="site-header-row">
- <?php
- $brandHasLogo = !empty($settings['site_logo_url']);
- $brandShowName = !$brandHasLogo || ($settings['site_show_name_with_logo'] ?? '0') === '1';
- $brandShortName = trim((string) ($settings['site_short_name'] ?? ''));
- $brandUseShort = $brandShowName && ($settings['site_short_name_enabled'] ?? '0') === '1' && $brandShortName !== '';
- ?>
- <a href="index.php" class="site-brand"<?= $brandUseShort ? ' data-short-name="1"' : '' ?>>
- <?php if ($brandHasLogo): ?>
- <img src="<?= htmlspecialchars($settings['site_logo_url']) ?>" alt="<?= htmlspecialchars($settings['site_name']) ?>" class="site-brand-logo">
- <?php endif; ?>
- <?php if ($brandShowName): ?>
- <span class="site-brand-full"><?= htmlspecialchars($settings['site_name']) ?></span>
- <?php if ($brandUseShort): ?>
- <span class="site-brand-short"><?= htmlspecialchars($brandShortName) ?></span>
- <?php endif; ?>
- <?php endif; ?>
- </a>
-
- <a href="cart.php" class="site-cart-link site-cart-link-header" id="site-cart-link-header">
- <?= renderShopIcon($settings) ?>
- <span class="site-cart-count"<?= $cartItemCount < 1 ? ' style="display:none;"' : '' ?>><?= (int) $cartItemCount ?></span>
- </a>
-
- <button type="button" class="site-menu-toggle" id="site-menu-toggle" aria-label="<?= htmlspecialchars(Language::get('nav_toggle_menu', 'Toggle menu')) ?>" aria-expanded="false">
- <?= Icons::icon('menu', 'icon icon-sm site-menu-toggle-icon-open') ?>
- <?= Icons::icon('x', 'icon icon-sm site-menu-toggle-icon-close') ?>
- </button>
-
- </div>
-
- <div class="site-nav-backdrop" id="site-nav-backdrop"></div>
-
- <nav class="site-nav" id="site-nav">
- <?php foreach ($navItems as $navItem): ?>
- <a href="<?= htmlspecialchars($navItem['url'], ENT_QUOTES) ?>" target="<?= htmlspecialchars($navItem['target'], ENT_QUOTES) ?>" <?= $navItem['target'] === '_blank' ? ' rel="noopener noreferrer"' : '' ?>><?= $navItem['icon_html'] ?? '' ?><?= htmlspecialchars($navItem['label']) ?></a>
- <?php endforeach; ?>
- <?= SiteFront::renderSearchControl('nav') ?>
-
- <div class="site-auth-links site-auth-links-mobile">
- <?php if (UserAuth::check()): ?>
- <a href="account.php"><?= htmlspecialchars(Language::get('nav_account', 'My account')) ?></a>
- <a href="user-login.php?logout=1"><?= htmlspecialchars(Language::get('nav_logout', 'Log out')) ?></a>
- <?php elseif (($settings['login_enabled'] ?? '1') !== '0'): ?>
- <a href="user-login.php?mode=login"><?= htmlspecialchars(Language::get('nav_login', 'Log in')) ?></a>
- <?php if (($settings['registration_enabled'] ?? '1') === '1'): ?>
- <a href="user-login.php?mode=register" class="site-auth-cta"><?= htmlspecialchars(Language::get('nav_signup', 'Sign up')) ?></a>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- </nav>
-
- <div class="site-auth-links site-auth-links-desktop">
- <a href="cart.php" class="site-cart-link site-cart-link-desktop" id="site-cart-link-desktop">
- <?= renderShopIcon($settings, 'icon') ?>
- <span class="site-cart-count"<?= $cartItemCount < 1 ? ' style="display:none;"' : '' ?>><?= (int) $cartItemCount ?></span>
- </a>
- <?php if (UserAuth::check()): ?>
- <a href="account.php"><?= htmlspecialchars(Language::get('nav_account', 'My account')) ?></a>
- <a href="user-login.php?logout=1"><?= htmlspecialchars(Language::get('nav_logout', 'Log out')) ?></a>
- <?php elseif (($settings['login_enabled'] ?? '1') !== '0'): ?>
- <a href="user-login.php?mode=login"><?= htmlspecialchars(Language::get('nav_login', 'Log in')) ?></a>
- <?php if (($settings['registration_enabled'] ?? '1') === '1'): ?>
- <a href="user-login.php?mode=register" class="site-auth-cta"><?= htmlspecialchars(Language::get('nav_signup', 'Sign up')) ?></a>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- </header>
-
- <main class="site-main">
- <?php foreach (SiteFront::activeAds('header') as $headerAd): ?>
- <?= SiteFront::renderAd($headerAd) ?>
- <?php endforeach; ?>