pdo(); $userId = $_SESSION['user_id'] ?? null; $error = ''; $threadId = (int)($_GET['id'] ?? 0); $communityCfg = require __DIR__ . '/../../../config/community.php'; $community = $pdo ? new \App\Community($pdo, $communityCfg) : null; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'reply') { if (!$userId) { $error = 'Bitte einloggen, um zu antworten.'; } elseif ($community) { $body = trim((string)($_POST['body'] ?? '')); if ($body === '') { $error = 'Antwort darf nicht leer sein.'; } else { $community->createPost((int)$userId, $threadId, $body); redirect('/community_thread?id=' . $threadId); } } } $thread = $community ? $community->getThread($threadId) : null; $posts = $community ? $community->listPosts($threadId) : []; if (!$thread) { http_response_code(404); echo "
Thread nicht gefunden.
"; return; } $threadAuthor = (string)($thread['display_name'] ?: 'Mitglied'); $threadPoints = ($community && $pdo) ? $community->computePoints((int)$thread['user_id']) : 0.0; $threadLevel = $community ? $community->membershipLevel($threadPoints) : ['label' => '', 'icon' => '']; ?>