Files
papa-kind-treff.info/config/fileload.php
Lars Gebhardt-Kusche fa6e975df4
All checks were successful
Deploy / deploy (push) Successful in 1m3s
ycxyxc
2026-08-04 00:42:40 +02:00

84 lines
3.4 KiB
PHP
Executable File

<?php
declare(strict_types=1);
// 1) Load config (constants, env, domains)
require_once __DIR__ . '/config.php';
// 2) Composer Autoloader (falls vorhanden)
$composerAutoload = __DIR__ . '/../vendor/autoload.php';
if (file_exists($composerAutoload)) {
require_once $composerAutoload;
} else {
// 2b) Fallback: minimaler Autoloader
spl_autoload_register(function (string $class): void {
$prefix = 'App\\';
if (!str_starts_with($class, $prefix)) {
return;
}
$rel = substr($class, strlen($prefix));
$path = __DIR__ . '/../src/App/' . str_replace('\\', '/', $rel) . '.php';
if (file_exists($path)) {
require_once $path;
}
});
}
// 3) Global helper functions (tpl(), t(), asset_*())
require_once __DIR__ . '/../src/helpers.php';
// 4) Initialize App (services)
$config = \App\Config::fromPhpConstants(__DIR__ . '/../config');
\App\App::init($config);
// 5) Start session + create client-id cookie
$app = \App\App::get();
$app->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 '<!doctype html><html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Wartung</title><style>body{margin:0;font-family:sans-serif;background:#f6efe5;color:#243b53;display:grid;place-items:center;min-height:100vh;padding:24px}.card{max-width:680px;background:#fff;border:1px solid #e5d7c3;border-radius:20px;padding:28px;box-shadow:0 20px 60px rgba(36,59,83,.08)}h1{margin:0 0 12px;font-size:2rem}p{margin:0;line-height:1.6;color:#486581}</style></head><body><main class="card"><h1>Papa-Kind-Treff ist kurz in Wartung</h1><p>' . $message . '</p></main></body></html>';
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;