Files
usbcheck.it/partials/structure/layout_start.php

163 lines
5.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// public/partials/layout_start.php
// Erwartet (vor require):
// - $pageKey (string) Seiten-Key für i18n, z. B. 'landing', 'fakecheck', 'login', 'dashboard'
// - $lang (2-letter ISO, z. B. 'de', 'en', 'it', 'fr'), möglichst bereits aus fileload.php
// - optional: $pageTitle (string)
// - optional: $pageDescription (string)
// - optional: $canonical (string)
// - optional: $userInitials (string|null)
// -----------------------------------------------------------
// Fallbacks & i18n Title/Description
// -----------------------------------------------------------
// Sicherstellen, dass availableLangs existiert (kommt aus fileload.php)
$availableLangs = $availableLangs ?? [];
// Page-Key Fallback
if (!isset($pageKey) || !is_string($pageKey) || $pageKey === '') {
$pageKey = 'landing';
}
// Fallback für Sprache: lieber auf $availableLangs statt feste Liste
if (!isset($lang) || !isset($availableLangs[$lang])) {
$lang = array_key_first($availableLangs) ?: 'en';
}
// Title aus i18n, falls nichts explizit gesetzt wurde
if (!isset($pageTitle) || !is_string($pageTitle) || $pageTitle === '') {
// pages.{pageKey}.meta.title
$pageTitle = i18n_get("pages.$pageKey.meta.title", app_primary_domain());
}
// Description aus i18n, falls nichts explizit gesetzt wurde
if (!isset($pageDescription) || !is_string($pageDescription) || $pageDescription === '') {
// pages.{pageKey}.meta.description
$pageDescription = i18n_get("pages.$pageKey.meta.description", '');
}
// -----------------------------------------------------------
// Standard-Script für Header-Interaktionen
// -----------------------------------------------------------
if (function_exists('tpl_add_script')) {
// header.js kommt wie gehabt in den Footer
tpl_add_script('/assets/js/header.js', 'footer', true, false, '', null);
}
// -----------------------------------------------------------
// Canonical-URL bestimmen
// -----------------------------------------------------------
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? app_primary_domain();
$requestUri = $_SERVER['REQUEST_URI'] ?? '/';
// Wenn $canonical gesetzt → verwenden, sonst aktuelle URL ohne Query-String
$effectiveCanonical = isset($canonical) && is_string($canonical) && $canonical !== ''
? $canonical
: ($scheme . '://' . $host . strtok($requestUri, '?'));
?>
<!DOCTYPE html>
<html lang="<?= htmlspecialchars($lang) ?>">
<head>
<meta charset="UTF-8">
<title><?= htmlspecialchars($pageTitle) ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php if ($pageDescription !== ''): ?>
<meta name="description" content="<?= htmlspecialchars($pageDescription) ?>">
<?php endif; ?>
<!-- Canonical URL -->
<link rel="canonical" href="<?= htmlspecialchars($effectiveCanonical) ?>">
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Montserrat:wght@600;700;800&display=swap" rel="stylesheet">
<?php
// App-Config (usbConfig + i18n.available/current) ins Fenster schreiben
tpl('app_config', 'structure');
// CSS im Header aus der zentralen Registry
foreach ($GLOBALS['page_styles'] as $style) {
if (($style['pos'] ?? 'header') !== 'header') {
continue;
}
$href = $style['href'];
if (!empty($style['version'])) {
$href .= (str_contains($href, '?') ? '&' : '?') . 'v=' . urlencode($style['version']);
}
echo '<link rel="stylesheet" href="' . htmlspecialchars($href) . '">' . PHP_EOL;
}
// Scripts im Header aus der zentralen Registry
foreach ($GLOBALS['page_header_scripts'] as $script) {
$src = $script['src'];
if (!empty($script['version'])) {
$src .= (str_contains($src, '?') ? '&' : '?') . 'v=' . urlencode($script['version']);
}
$attr = '';
if (!empty($script['async'])) {
$attr .= ' async';
} elseif (!empty($script['defer'])) {
$attr .= ' defer';
}
if (!empty($script['type'])) {
$attr .= ' type="' . htmlspecialchars($script['type']) . '"';
}
echo '<script src="' . htmlspecialchars($src) . '"' . $attr . '></script>' . PHP_EOL;
}
?>
<script>
window.tailwind = window.tailwind || {};
window.tailwind.config = {
theme: {
extend: {
colors: {
'brand-primary': '#3a6ff8',
'brand-primarySoft': '#e8f1ff',
'brand-border': '#dfe6f4',
'brand-bg': '#f9fbff',
'brand-surface': '#ffffff',
'brand-text': '#0f1f3d',
'brand-muted': '#5f6b85'
},
fontFamily: {
heading: ['"Montserrat"', '"Plus Jakarta Sans"', '"Inter"', 'system-ui', 'sans-serif']
},
borderRadius: {
xl2: '1.75rem',
xl3: '2.25rem'
},
boxShadow: {
soft: '0 18px 45px rgba(58, 111, 248, 0.18)'
}
}
}
};
</script>
<!-- Tailwind (Dev) -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Eigenes CSS (falls du das irgendwann auch versionieren willst, gerne über tpl_add_style) -->
<link rel="stylesheet" href="/assets/css/main.css">
</head>
<body class="bg-brand-bg text-brand-text font-sans antialiased scroll-smooth">
<div class="min-h-screen flex flex-col">
<!-- HEADER -->
<?php tpl('header'); ?>
<!-- MAIN CONTENT -->
<main class="flex-1">