WebOrbiton
v1.1.0.0

StocketBase

221 lines · 10.5 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/icons.php';
  6. require_once __DIR__ . '/asset.php';
  7. require_once __DIR__ . '/csrf.php';
  8. require_once __DIR__ . '/cart.php';
  9. ​
  10. $cartItemCount = Cart::count();
  11. $cartIsGuest = !UserAuth::check();
  12. ​
  13. function renderShopIcon(array $settings, string $extraClass = 'icon'): string
  14. {
  15. $choice = (string) ($settings['shop_icon_choice'] ?? 'cart');
  16. if ($choice === 'custom') {
  17. $customSvg = (string) ($settings['shop_icon_custom_svg'] ?? '');
  18. if ($customSvg !== '') {
  19. return '<span class="' . htmlspecialchars($extraClass, ENT_QUOTES) . ' shop-icon-custom" aria-hidden="true">' . $customSvg . '</span>';
  20. }
  21. $choice = 'cart';
  22. }
  23. ​
  24. return Icons::icon($choice, $extraClass);
  25. }
  26. $cartExportItems = $cartIsGuest ? array_map(
  27. static fn(array $item): array => [
  28. 'product_id' => $item['product_id'],
  29. 'variant_id' => $item['variant_id'],
  30. 'quantity' => $item['quantity'],
  31. ],
  32. Cart::items()
  33. ) : [];
  34. ​
  35. if (Languages::current() !== '') {
  36. ob_start([Languages::class, 'absolutizeUrls']);
  37. }
  38. ​
  39. $navItems = SiteFront::navItems();
  40. ​
  41. $menuPositionClass = 'site-menu-' . ($settings['menu_position'] ?? 'top');
  42. ​
  43. $resolvedPageTitle = $pageTitle ?? $settings['site_name'];
  44. $resolvedPageDescription = $pageDescription ?? '';
  45. $isHomepage = ($_SERVER['REQUEST_URI'] ?? '') === '/' || basename((string) ($_SERVER['SCRIPT_NAME'] ?? '')) === 'index.php';
  46. ​
  47. ?>
  48. <!DOCTYPE html>
  49. <html lang="<?= htmlspecialchars(Languages::htmlLang(), ENT_QUOTES) ?>">
  50. ​
  51. <head>
  52. <meta charset="utf-8">
  53. <meta name="viewport" content="width=device-width, initial-scale=1">
  54. <title><?= htmlspecialchars($resolvedPageTitle) ?></title>
  55. <?php if (!empty($resolvedPageDescription)): ?>
  56. <meta name="description" content="<?= htmlspecialchars($resolvedPageDescription) ?>">
  57. <?php endif; ?>
  58. <?php if (!empty($pageNoindex)): ?>
  59. <meta name="robots" content="noindex, nofollow">
  60. <?php endif; ?>
  61. <?= SiteFront::renderSeoMeta() ?>
  62. <?= Languages::renderAlternates() ?>
  63. <?= SiteFront::renderOpenGraph($resolvedPageTitle, $resolvedPageDescription, $ogType ?? 'website', $ogImagePath ?? null) ?>
  64. <?php if ($isHomepage): ?>
  65. <?= SiteFront::renderOrganizationSchema() ?>
  66. <?php endif; ?>
  67. <?= Asset::favicon() ?>
  68. <?php if (($settings['pwa_enabled'] ?? '0') === '1'): ?>
  69. <?php $pwaIconUrl = !empty($settings['pwa_icon_url']) ? $settings['pwa_icon_url'] : ($settings['site_logo_url'] ?? ''); ?>
  70. <link rel="manifest" href="<?= htmlspecialchars(rtrim(Config::get('APP_BASE_PATH', ''), '/')) ?>/manifest.json">
  71. <meta name="theme-color" content="<?= htmlspecialchars($settings['pwa_theme_color'] ?: '#ffffff') ?>">
  72. <?php if (!empty($pwaIconUrl)): ?>
  73. <link rel="apple-touch-icon" href="<?= htmlspecialchars($pwaIconUrl) ?>">
  74. <?php endif; ?>
  75. <?php endif; ?>
  76. <?= Asset::css('assets/site.css') ?>
  77. <style>
  78. <?= SiteFront::renderFontFaces() ?><?= SiteFront::fontVariablesCss() ?>
  79. </style>
  80. <?php if (!empty($settings['custom_css'])): ?>
  81. <style>
  82. <?= $settings['custom_css'] ?>
  83. </style>
  84. <?php endif; ?>
  85. <?= SiteFront::renderCustomHeadHtml($pageType ?? null) ?>
  86. <?= SiteFront::renderAnalyticsScripts('head') ?>
  87. </head>
  88. ​
  89. <body class="<?= htmlspecialchars($menuPositionClass) ?>" data-theme="light">
  90. <?= SiteFront::renderAnalyticsScripts('body_start') ?>
  91. <script>
  92. (function() {
  93. try {
  94. var t = localStorage.getItem('stocketbase_theme');
  95. if (t === 'dark' || t === 'light') {
  96. document.body.setAttribute('data-theme', t);
  97. } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  98. document.body.setAttribute('data-theme', 'dark');
  99. }
  100. } catch (e) {}
  101. })();
  102. </script>
  103. <?php if ($cartIsGuest): ?>
  104. <script>
  105. (function() {
  106. var STORAGE_KEY = 'stocketbase_cart_backup';
  107. var serverItems = <?= json_encode($cartExportItems, JSON_UNESCAPED_SLASHES) ?>;
  108. ​
  109. try {
  110. if (serverItems.length > 0) {
  111. localStorage.setItem(STORAGE_KEY, JSON.stringify(serverItems));
  112. return;
  113. }
  114. ​
  115. var raw = localStorage.getItem(STORAGE_KEY);
  116. if (!raw) {
  117. return;
  118. }
  119. var backup = JSON.parse(raw);
  120. if (!Array.isArray(backup) || backup.length === 0) {
  121. return;
  122. }
  123. ​
  124. var csrfToken = <?= json_encode(Csrf::token()) ?>;
  125. var body = new URLSearchParams();
  126. body.set('action', 'restore_from_client');
  127. body.set('csrf_token', csrfToken);
  128. body.set('items', JSON.stringify(backup));
  129. ​
  130. fetch('cart.php', {
  131. method: 'POST',
  132. credentials: 'same-origin',
  133. headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  134. body: body.toString()
  135. }).then(function(response) {
  136. if (response.ok) {
  137. window.location.reload();
  138. }
  139. }).catch(function() {});
  140. } catch (e) {}
  141. })();
  142. </script>
  143. <?php endif; ?>
  144. <?= Icons::sprite() ?>
  145. <div class="site-shell">
  146. ​
  147. <?php $headerHasAuthButtons = UserAuth::check() || ($settings['login_enabled'] ?? '1') !== '0'; ?>
  148. <header class="site-header<?= $headerHasAuthButtons ? '' : ' site-header-no-auth' ?>">
  149. <div class="site-header-row">
  150. <?php
  151. $brandHasLogo = !empty($settings['site_logo_url']);
  152. $brandShowName = !$brandHasLogo || ($settings['site_show_name_with_logo'] ?? '0') === '1';
  153. $brandShortName = trim((string) ($settings['site_short_name'] ?? ''));
  154. $brandUseShort = $brandShowName && ($settings['site_short_name_enabled'] ?? '0') === '1' && $brandShortName !== '';
  155. ?>
  156. <a href="index.php" class="site-brand"<?= $brandUseShort ? ' data-short-name="1"' : '' ?>>
  157. <?php if ($brandHasLogo): ?>
  158. <img src="<?= htmlspecialchars($settings['site_logo_url']) ?>" alt="<?= htmlspecialchars($settings['site_name']) ?>" class="site-brand-logo">
  159. <?php endif; ?>
  160. <?php if ($brandShowName): ?>
  161. <span class="site-brand-full"><?= htmlspecialchars($settings['site_name']) ?></span>
  162. <?php if ($brandUseShort): ?>
  163. <span class="site-brand-short"><?= htmlspecialchars($brandShortName) ?></span>
  164. <?php endif; ?>
  165. <?php endif; ?>
  166. </a>
  167. ​
  168. <a href="cart.php" class="site-cart-link site-cart-link-header" id="site-cart-link-header">
  169. <?= renderShopIcon($settings) ?>
  170. <span class="site-cart-count"<?= $cartItemCount < 1 ? ' style="display:none;"' : '' ?>><?= (int) $cartItemCount ?></span>
  171. </a>
  172. ​
  173. <button type="button" class="site-menu-toggle" id="site-menu-toggle" aria-label="<?= htmlspecialchars(Language::get('nav_toggle_menu', 'Toggle menu')) ?>" aria-expanded="false">
  174. <?= Icons::icon('menu', 'icon icon-sm site-menu-toggle-icon-open') ?>
  175. <?= Icons::icon('x', 'icon icon-sm site-menu-toggle-icon-close') ?>
  176. </button>
  177. ​
  178. </div>
  179. ​
  180. <div class="site-nav-backdrop" id="site-nav-backdrop"></div>
  181. ​
  182. <nav class="site-nav" id="site-nav">
  183. <?php foreach ($navItems as $navItem): ?>
  184. <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>
  185. <?php endforeach; ?>
  186. <?= SiteFront::renderSearchControl('nav') ?>
  187. ​
  188. <div class="site-auth-links site-auth-links-mobile">
  189. <?php if (UserAuth::check()): ?>
  190. <a href="account.php"><?= htmlspecialchars(Language::get('nav_account', 'My account')) ?></a>
  191. <a href="user-login.php?logout=1"><?= htmlspecialchars(Language::get('nav_logout', 'Log out')) ?></a>
  192. <?php elseif (($settings['login_enabled'] ?? '1') !== '0'): ?>
  193. <a href="user-login.php?mode=login"><?= htmlspecialchars(Language::get('nav_login', 'Log in')) ?></a>
  194. <?php if (($settings['registration_enabled'] ?? '1') === '1'): ?>
  195. <a href="user-login.php?mode=register" class="site-auth-cta"><?= htmlspecialchars(Language::get('nav_signup', 'Sign up')) ?></a>
  196. <?php endif; ?>
  197. <?php endif; ?>
  198. </div>
  199. </nav>
  200. ​
  201. <div class="site-auth-links site-auth-links-desktop">
  202. <a href="cart.php" class="site-cart-link site-cart-link-desktop" id="site-cart-link-desktop">
  203. <?= renderShopIcon($settings, 'icon') ?>
  204. <span class="site-cart-count"<?= $cartItemCount < 1 ? ' style="display:none;"' : '' ?>><?= (int) $cartItemCount ?></span>
  205. </a>
  206. <?php if (UserAuth::check()): ?>
  207. <a href="account.php"><?= htmlspecialchars(Language::get('nav_account', 'My account')) ?></a>
  208. <a href="user-login.php?logout=1"><?= htmlspecialchars(Language::get('nav_logout', 'Log out')) ?></a>
  209. <?php elseif (($settings['login_enabled'] ?? '1') !== '0'): ?>
  210. <a href="user-login.php?mode=login"><?= htmlspecialchars(Language::get('nav_login', 'Log in')) ?></a>
  211. <?php if (($settings['registration_enabled'] ?? '1') === '1'): ?>
  212. <a href="user-login.php?mode=register" class="site-auth-cta"><?= htmlspecialchars(Language::get('nav_signup', 'Sign up')) ?></a>
  213. <?php endif; ?>
  214. <?php endif; ?>
  215. </div>
  216. </header>
  217. ​
  218. <main class="site-main">
  219. <?php foreach (SiteFront::activeAds('header') as $headerAd): ?>
  220. <?= SiteFront::renderAd($headerAd) ?>
  221. <?php endforeach; ?>