session()->start(); $clientId = $app->session()->ensureClientId(); try { $pdo = $app->pdo(); if ($pdo) { $settings = new \App\SystemSettings($pdo); $settings->ensureSchema(); if ($settings->getBool('site_maintenance_mode')) { $isAdminUser = false; if (isset($_SESSION['user_id'])) { $communityCfg = __DIR__ . '/community.php'; $communityConfig = file_exists($communityCfg) ? require $communityCfg : []; $communityAccess = new \App\CommunityAccess($pdo, $communityConfig); $isAdminUser = $communityAccess->canManageApplications((int)$_SESSION['user_id']); } $uriPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/'; $uriPath = preg_replace('~/{2,}~', '/', $uriPath); $uriPath = trim($uriPath, '/'); $maintenanceWhitelist = [ 'login', 'logout', 'verify', 'reset', 'impressum', 'datenschutz', ]; if (!$isAdminUser && !in_array($uriPath, $maintenanceWhitelist, true)) { http_response_code(503); header('Retry-After: 600'); $message = htmlspecialchars( $settings->get('site_maintenance_message', 'Papa-Kind-Treff ist gerade kurz in Wartung. Bitte versuche es in Kürze erneut.') ?? '', ENT_QUOTES ); echo 'Wartung

Papa-Kind-Treff ist kurz in Wartung

' . $message . '

'; exit; } } } } catch (\Throwable) { // Fail open to avoid locking the whole site on transient settings/schema issues. } // Optionally expose a single global for templates if desired $GLOBALS['client_id'] = $clientId;