From cf68494f552e0eb3d98ba29f12a0dd51f43e06cd Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Fri, 28 Nov 2025 03:31:46 +0100 Subject: [PATCH] lniks --- config/i18n.php | 92 ++++++++++++++++++++++++++ partials/structure/header.php | 29 +++++--- public/assets/i18n/de.json | 18 ++++- public/index.php | 1 + public/landingpage/dashboard/index.php | 1 + public/landingpage/fakecheck/index.php | 2 +- public/landingpage/login/index.php | 1 + 7 files changed, 132 insertions(+), 12 deletions(-) diff --git a/config/i18n.php b/config/i18n.php index 4b53e3b..0befd15 100644 --- a/config/i18n.php +++ b/config/i18n.php @@ -232,3 +232,95 @@ function app_i18n_get_frontend_config(): array 'available' => $GLOBALS['availableLangs'] ?? [], ]; } + +/** + * Komplette JSON-Struktur für eine Sprache laden. + * Nutzt einfachen Request-Cache, damit pro Sprache nur einmal von Platte gelesen wird. + */ +function app_i18n_load_lang_json(string $lang): array +{ + static $cache = []; + + $lang = strtolower(substr($lang, 0, 5)); + + if (isset($cache[$lang])) { + return $cache[$lang]; + } + + $baseDir = realpath(__DIR__ . '/../public/assets/i18n'); + if ($baseDir === false) { + $cache[$lang] = []; + return $cache[$lang]; + } + + $path = $baseDir . '/' . $lang . '.json'; + if (!is_file($path)) { + // Fallback: en.json, falls vorhanden + $fallback = $baseDir . '/en.json'; + if (is_file($fallback)) { + $json = @file_get_contents($fallback); + $data = json_decode($json, true); + $cache[$lang] = is_array($data) ? $data : []; + return $cache[$lang]; + } + + $cache[$lang] = []; + return $cache[$lang]; + } + + $json = @file_get_contents($path); + $data = json_decode($json, true); + $cache[$lang] = is_array($data) ? $data : []; + + return $cache[$lang]; +} + +/** + * Nav-Anker für eine Seite aus der Sprachdatei holen. + * + * Erwartete Struktur im JSON: + * "pages": { + * "landing": { + * "meta": { ... }, + * "anchors": { + * "how": "So funktioniert USBCheck", + * "problem": "Warum gefälschte USB-Sticks gefährlich sind", + * ... + * } + * } + * } + * + * Rückgabe-Format: + * [ + * [ 'href' => '#how', 'label' => 'So funktioniert USBCheck' ], + * [ 'href' => '#problem', 'label' => 'Warum gefälschte USB-Sticks gefährlich sind' ], + * ... + * ] + */ +function app_get_nav_anchors(string $pageKey): array +{ + $lang = $GLOBALS['lang'] ?? 'en'; + $data = app_i18n_load_lang_json($lang); + + $nav = $data['pages'][$pageKey]['anchors'] ?? null; + if (!is_array($nav)) { + return []; + } + + $anchors = []; + foreach ($nav as $id => $label) { + $id = trim((string)$id); + $label = trim((string)$label); + + if ($id === '' || $label === '') { + continue; + } + + $anchors[] = [ + 'href' => '#' . $id, + 'label' => $label, + ]; + } + + return $anchors; +} diff --git a/partials/structure/header.php b/partials/structure/header.php index 3ef10be..d093bde 100644 --- a/partials/structure/header.php +++ b/partials/structure/header.php @@ -6,9 +6,16 @@ $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' $host = $_SERVER['HTTP_HOST'] ?? app_primary_domain(); $baseUrl = $scheme . '://' . $host; -// Wenn $navAnchors NICHT gesetzt ist → leeres Array +// Aktueller Page-Key (z.B. 'landing', 'fakecheck', 'dashboard') +$pageKey = $GLOBALS['pageKey'] ?? null; + +// Nav-Anker: wenn nicht explizit gesetzt, aus der i18n-JSON holen if (!isset($navAnchors) || !is_array($navAnchors)) { - $navAnchors = []; + if ($pageKey && function_exists('app_get_nav_anchors')) { + $navAnchors = app_get_nav_anchors($pageKey); // ['href' => '#how', 'label' => '...'] + } else { + $navAnchors = []; + } } // Session sollte in config/fileload.php bereits gestartet sein. @@ -112,14 +119,16 @@ function build_lang_url(string $code, string $path, array $query): string
- + + +
diff --git a/public/assets/i18n/de.json b/public/assets/i18n/de.json index 2ba2c40..e663aa6 100755 --- a/public/assets/i18n/de.json +++ b/public/assets/i18n/de.json @@ -9,9 +9,25 @@ "landing": { "meta": { "title": "KEIN TITEL" - } + }, +, + "anchors": { + "how": "So funktioniert USBCheck", + "problem": "Warum gefälschte USB-Sticks gefährlich sind", + "features": "Funktionen", + "security": "Sicherheit", + "faq": "FAQ" + } }, "main": { +, + "anchors": { + "how": "So funktioniert USBCheck", + "problem": "Warum gefälschte USB-Sticks gefährlich sind", + "features": "Funktionen", + "security": "Sicherheit", + "faq": "FAQ" + }, "sections": { "security": { "security_kicker": "Sicherheit & Datenschutz", diff --git a/public/index.php b/public/index.php index e552b39..408cc70 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,6 @@