From 28bd5f4e954ea8b9917f689a1103c0619e127276 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Mon, 2 Mar 2026 02:02:41 +0100 Subject: [PATCH] update --- config/config.php | 12 +- config/fileload.php | 9 +- .../landing}/kea_dashboard.php | 0 public/page/layout_end.php | 11 -- public/page/layout_start.php | 38 ------ src/App/functions.php | 120 ++++++++++++++++-- src/helpers.php | 103 --------------- 7 files changed, 119 insertions(+), 174 deletions(-) rename {public/page => partials/landing}/kea_dashboard.php (100%) delete mode 100644 public/page/layout_end.php delete mode 100644 public/page/layout_start.php delete mode 100755 src/helpers.php diff --git a/config/config.php b/config/config.php index 0a395dc..68072b9 100755 --- a/config/config.php +++ b/config/config.php @@ -6,20 +6,14 @@ ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); -// Pick config set: first try root files, otherwise fall back to env dir (prod/staging/...) -$appEnvFromEnv = getenv('APP_ENV') ?: 'prod'; -$envDir = rtrim(__DIR__, '/\\') . '/' . $appEnvFromEnv; - -foreach (['domaindata.php','settings.php'] as $cfgFile) { +// Required config files live in /config (sync copies staging/prod here) +foreach (['domaindata.php', 'settings.php'] as $cfgFile) { $rootPath = __DIR__ . '/' . $cfgFile; - $envPath = $envDir . '/' . $cfgFile; if (file_exists($rootPath)) { require_once $rootPath; - } elseif (file_exists($envPath)) { - require_once $envPath; } else { - throw new \RuntimeException("Missing required config file: $cfgFile (looked for $rootPath or $envPath)"); + throw new \RuntimeException("Missing required config file: $cfgFile (expected $rootPath)"); } } diff --git a/config/fileload.php b/config/fileload.php index 56cc528..59a7867 100755 --- a/config/fileload.php +++ b/config/fileload.php @@ -28,10 +28,9 @@ spl_autoload_register(function ($class) { // 2. Funktionen laden require_once __DIR__ . '/../src/App/functions.php'; -// 3. Konfiguration laden -// Wir simulieren hier den Sync-Prozess: Wenn config/db.php nicht da ist, nimm staging. -$configFile = file_exists(__DIR__ . '/db.php') ? __DIR__ . '/db.php' : __DIR__ . '/staging/db.php'; -$settingsFile = file_exists(__DIR__ . '/settings.php') ? __DIR__ . '/settings.php' : __DIR__ . '/staging/settings.php'; +// 3. Konfiguration laden (nur Root-Dateien; Sync kopiert staging/prod hierher) +$settingsFile = __DIR__ . '/settings.php'; +$configFile = __DIR__ . '/db.php'; if (file_exists($settingsFile)) { require_once $settingsFile; @@ -45,4 +44,4 @@ if (file_exists($configFile)) { // Globales Config Objekt erstellen global $appConfig; $dbEnabled = defined('APP_DB_ENABLED') ? APP_DB_ENABLED : true; -$appConfig = new \App\Config($dbConfig, $dbEnabled); \ No newline at end of file +$appConfig = new \App\Config($dbConfig, $dbEnabled); diff --git a/public/page/kea_dashboard.php b/partials/landing/kea_dashboard.php similarity index 100% rename from public/page/kea_dashboard.php rename to partials/landing/kea_dashboard.php diff --git a/public/page/layout_end.php b/public/page/layout_end.php deleted file mode 100644 index 91179a6..0000000 --- a/public/page/layout_end.php +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/public/page/layout_start.php b/public/page/layout_start.php deleted file mode 100644 index 5be8f93..0000000 --- a/public/page/layout_start.php +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - Nexus Control Panel - - - - - - - -
-
\ No newline at end of file diff --git a/src/App/functions.php b/src/App/functions.php index d9a63b2..8dc6d39 100644 --- a/src/App/functions.php +++ b/src/App/functions.php @@ -1,22 +1,59 @@ i18n()->get($key, $default, $vars); +} + /** * Lädt ein Template-Partial. * * @param string $name Dateiname ohne .php - * @param string $folder Unterordner in /public/partials/ + * @param string $folder Unterordner in /partials/ * @param array $data Daten, die im Template verfügbar sein sollen */ function tpl(string $name, string $folder = 'landing', array $data = []): void { - $path = __DIR__ . '/../../public/partials/' . $folder . '/' . $name . '.php'; - if (file_exists($path)) { - extract($data); - require $path; - } else { - echo ""; + $base = __DIR__ . '/../../partials/'; + + foreach ([$name, $folder] as $value) { + if (preg_match('/[^a-zA-Z0-9_\-]/', $value)) { + echo ""; + return; + } } + + $paths = []; + if ($folder === 'landing') { + $paths[] = $base . 'landing/' . $name . '.php'; + $paths[] = $base . 'landing/main/' . $name . '.php'; + } else { + $paths[] = $base . 'structure/' . $name . '.php'; + } + + $path = null; + foreach ($paths as $candidate) { + if (file_exists($candidate)) { + $path = $candidate; + break; + } + } + + if ($path === null) { + echo ""; + return; + } + + extract($data); + require $path; } /** @@ -25,4 +62,71 @@ function tpl(string $name, string $folder = 'landing', array $data = []): void function e(?string $string): string { return htmlspecialchars($string ?? '', ENT_QUOTES, 'UTF-8'); -} \ No newline at end of file +} + +function app_primary_domain(): string +{ + if (defined('APP_DOMAIN_PRIMARY')) { + return APP_DOMAIN_PRIMARY; + } + if (defined('APP_DOMAIN_NAME')) { + return APP_DOMAIN_NAME; + } + return $_SERVER['HTTP_HOST'] ?? ''; +} + +function app_fakecheck_domain(): string +{ + if (defined('APP_DOMAIN_FAKECHECK')) { + return APP_DOMAIN_FAKECHECK; + } + return app_primary_domain(); +} + +function asset_styles(): void +{ + $styles = app()->assets()->styles(); + + $order = ['early' => 0, 'normal' => 1, 'late' => 2]; + usort($styles, fn($a, $b) => ($order[$a['priority']] ?? 1) <=> ($order[$b['priority']] ?? 1)); + + foreach ($styles as $s) { + $href = $s['href']; + $v = $s['version']; + if ($v !== null && $v !== '') { + $sep = (str_contains($href, '?') ? '&' : '?'); + $href = $href . $sep . 'v=' . rawurlencode((string)$v); + } + echo '' . "\n"; + } +} + +function asset_scripts(string $pos = 'footer'): void +{ + $scripts = ($pos === 'header') ? app()->assets()->headerScripts() : app()->assets()->footerScripts(); + + foreach ($scripts as $s) { + $src = $s['src']; + $v = $s['version']; + if ($v !== null && $v !== '') { + $sep = (str_contains($src, '?') ? '&' : '?'); + $src = $src . $sep . 'v=' . rawurlencode((string)$v); + } + + $attrs = ''; + if (!empty($s['defer'])) { + $attrs .= ' defer'; + } + if (!empty($s['async'])) { + $attrs .= ' async'; + } + + echo '' . "\n"; + } +} + +function redirect(string $path): void +{ + header('Location: ' . $path, true, 303); + exit; +} diff --git a/src/helpers.php b/src/helpers.php deleted file mode 100755 index acae534..0000000 --- a/src/helpers.php +++ /dev/null @@ -1,103 +0,0 @@ -i18n()->get($key, $default, $vars); -} - -function tpl(string $file, string $type = 'structure', string $site = 'main'): void -{ - $base = __DIR__ . '/../partials/'; - - // very small validation - foreach ([$file, $type, $site] as $v) { - if (preg_match('/[^a-zA-Z0-9_\-]/', $v)) { - echo ""; - return; - } - } - - if ($type === 'landing') { - $path = $base . "landing/$site/$file.php"; - } else { - $path = $base . "structure/$file.php"; - } - - if (file_exists($path)) { - include $path; - } else { - echo ""; - } -} - -function app_primary_domain(): string -{ - if (defined('APP_DOMAIN_PRIMARY')) { - return APP_DOMAIN_PRIMARY; - } - if (defined('APP_DOMAIN_NAME')) { - return APP_DOMAIN_NAME; - } - return $_SERVER['HTTP_HOST'] ?? ''; -} - -function app_fakecheck_domain(): string -{ - if (defined('APP_DOMAIN_FAKECHECK')) { - return APP_DOMAIN_FAKECHECK; - } - return app_primary_domain(); -} - -function asset_styles(): void -{ - $styles = app()->assets()->styles(); - - // simple priority order - $order = ['early' => 0, 'normal' => 1, 'late' => 2]; - usort($styles, fn($a,$b) => ($order[$a['priority']] ?? 1) <=> ($order[$b['priority']] ?? 1)); - - foreach ($styles as $s) { - $href = $s['href']; - $v = $s['version']; - if ($v !== null && $v !== '') { - $sep = (str_contains($href, '?') ? '&' : '?'); - $href = $href . $sep . 'v=' . rawurlencode((string)$v); - } - echo '' . "\n"; - } -} - -function asset_scripts(string $pos = 'footer'): void -{ - $scripts = ($pos === 'header') ? app()->assets()->headerScripts() : app()->assets()->footerScripts(); - - foreach ($scripts as $s) { - $src = $s['src']; - $v = $s['version']; - if ($v !== null && $v !== '') { - $sep = (str_contains($src, '?') ? '&' : '?'); - $src = $src . $sep . 'v=' . rawurlencode((string)$v); - } - - $attrs = ''; - if (!empty($s['defer'])) $attrs .= ' defer'; - if (!empty($s['async'])) $attrs .= ' async'; - - echo '' . "\n"; - } -} - -function redirect(string $path): void -{ - header('Location: ' . $path, true, 303); - exit; -}