$src, 'defer' => $defer, 'async' => $async, 'type' => $type, 'version' => $version, // kann null, '' oder string sein ]; if ($pos === 'header') { $GLOBALS['page_header_scripts'][] = $data; } else { $GLOBALS['page_footer_scripts'][] = $data; } } /** * CSS registrieren * * @param string $href Pfad zur CSS * @param string $pos 'header' oder 'footer' * @param string|null $version gleiche Logik wie bei Scripts */ function tpl_add_style(string $href, string $pos = 'header', ?string $version = null): void { if ($version === null && defined('ASSET_VERSION')) { $version = ASSET_VERSION; } $GLOBALS['page_styles'][] = [ 'href' => $href, 'pos' => $pos, 'version' => $version, ]; } /** * Templating Loader * * Beispiel: * tpl('header'); // structure/header.php * tpl('hero', 'landing', 'main'); // landing/main/hero.php * tpl('faq', 'landing', 'fakecheck'); // landing/fakecheck/faq.php */ function tpl(string $file, string $type = 'structure', string $site = 'main'): void { $base = __DIR__ . '/../partials/'; // VALIDIERUNG: Nur einfache Check, kein Path-Traversal if (preg_match('/[^a-zA-Z0-9_\-]/', $file)) { echo ""; return; } if (preg_match('/[^a-zA-Z0-9_\-]/', $type)) { echo ""; return; } if (preg_match('/[^a-zA-Z0-9_\-]/', $site)) { echo ""; return; } if ($type === 'landing') { $path = $base . "landing/$site/$file.php"; } else { $path = $base . "structure/$file.php"; } extract($GLOBALS, EXTR_SKIP); if (file_exists($path)) { include $path; } else { echo ""; } } /** * Flash-Meldung setzen (wird genau einmal nach Redirect angezeigt). * * @param string $type z.B. 'success', 'error', 'info', 'warning' * @param string $message Die Meldung für den Nutzer */ function flash_set(string $type, string $message, ?string $context = null): void { if (session_status() !== PHP_SESSION_ACTIVE) { @session_start(); } $_SESSION['flash'] = [ 'type' => $type, 'message' => $message, 'context' => $context, ]; } /** * Flash-Meldung holen und direkt löschen (Einmal-Anzeige). * * @return array|null ['type' => 'success|error|info|warning', 'message' => '...'] */ function flash_get(): ?array { if (session_status() !== PHP_SESSION_ACTIVE) { @session_start(); } if (empty($_SESSION['flash']) || !is_array($_SESSION['flash'])) { return null; } $flash = $_SESSION['flash']; unset($_SESSION['flash']); $flash['type'] = $flash['type'] ?? 'info'; $flash['message'] = $flash['message'] ?? ''; $flash['context'] = $flash['context'] ?? null; return $flash; }