= htmlspecialchars((string)$thread['title'], ENT_QUOTES) ?>
Bereich: = htmlspecialchars((string)$thread['board_title'], ENT_QUOTES) ?>
pdo(); $userId = $_SESSION['user_id'] ?? null; $error = ''; $info = ''; $threadId = (int)($_GET['id'] ?? 0); $editPostId = (int)($_GET['edit_post'] ?? 0); $communityCfg = require __DIR__ . '/../../../config/community.php'; $community = $pdo ? new \App\Community($pdo, $communityCfg) : null; $access = $pdo ? new \App\CommunityAccess($pdo, $communityCfg) : null; $forumCategories = $community ? $community->listForumCategories() : []; if ($_SERVER['REQUEST_METHOD'] === 'POST' && $community && $access) { $action = (string)($_POST['action'] ?? ''); try { if ($action === 'reply') { if (!$userId) { throw new \RuntimeException('Bitte einloggen, um zu antworten.'); } if (!$access->canReply((int)$userId)) { $state = $access->getRestrictionState((int)$userId); throw new \RuntimeException($state['reason'] ?: 'Du darfst aktuell nicht antworten.'); } $body = trim((string)($_POST['body'] ?? '')); if ($body === '') { throw new \RuntimeException('Antwort darf nicht leer sein.'); } $community->createPost((int)$userId, $threadId, $body); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'post_vote') { if (!$userId) { throw new \RuntimeException('Bitte einloggen, um Beiträge zu bewerten.'); } $access->votePost((int)$userId, (int)($_POST['post_id'] ?? 0), (int)($_POST['value'] ?? 0)); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'report_content') { if (!$userId) { throw new \RuntimeException('Bitte einloggen, um Beiträge zu melden.'); } $access->submitReport((int)$userId, (string)($_POST['target_type'] ?? ''), (int)($_POST['target_id'] ?? 0), (string)($_POST['reason'] ?? '')); $info = 'Deine Meldung wurde eingereicht.'; } elseif ($action === 'post_update') { if (!$userId || !$access->canModerateForum((int)$userId)) { throw new \RuntimeException('Keine Berechtigung.'); } $community->updatePost((int)($_POST['post_id'] ?? 0), (string)($_POST['body'] ?? '')); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'post_delete') { if (!$userId || !$access->canModerateForum((int)$userId)) { throw new \RuntimeException('Keine Berechtigung.'); } $community->deletePost((int)($_POST['post_id'] ?? 0)); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'thread_update') { if (!$userId || !$access->canModerateForum((int)$userId)) { throw new \RuntimeException('Keine Berechtigung.'); } $community->updateThread($threadId, (string)($_POST['title'] ?? ''), (string)($_POST['body'] ?? '')); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'thread_delete') { if (!$userId || !$access->canModerateForum((int)$userId)) { throw new \RuntimeException('Keine Berechtigung.'); } $community->deleteThread($threadId); redirect('/community'); } elseif ($action === 'highlight_post') { if (!$userId) { throw new \RuntimeException('Bitte einloggen.'); } $points = $community->computePoints((int)$userId); if (!$access->canHighlightHelpful($points) && !$access->canModerateForum((int)$userId)) { throw new \RuntimeException('Dafür ist mindestens der Rang Mentor-Vater erforderlich.'); } $postId = (int)($_POST['post_id'] ?? 0); $highlight = ((string)($_POST['highlight'] ?? '1')) === '1'; $community->toggleHelpfulHighlight($postId, $highlight ? (int)$userId : null); redirect('/community_thread?id=' . $threadId); } elseif ($action === 'restriction_set') { $access->setRestriction((int)$userId, (int)($_POST['target_user_id'] ?? 0), (string)($_POST['restriction_type'] ?? ''), (string)($_POST['reason'] ?? '')); $info = 'Community-Sperre wurde gesetzt.'; } elseif ($action === 'restriction_clear') { $access->clearRestriction((int)$userId, (int)($_POST['target_user_id'] ?? 0), (string)($_POST['restriction_type'] ?? '')); $info = 'Community-Sperre wurde aufgehoben.'; } } catch (\Throwable $e) { $error = $e->getMessage(); } } $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' => '']; $userRoles = $access && $userId ? $access->getUserRoles((int)$userId) : []; $isForumAdmin = $access && $userId ? $access->canModerateForum((int)$userId) : false; $userRestrictions = $access && $userId ? $access->getRestrictionState((int)$userId) : ['reply_blocked' => false, 'reason' => null]; $postIds = array_map(static fn(array $post): int => (int)$post['id'], $posts); $feedbackSummary = $access ? $access->getPostFeedbackSummary($postIds) : []; $userVotes = ($access && $userId) ? $access->getUserPostVotes((int)$userId, $postIds) : []; ?>Bereich: = htmlspecialchars((string)$thread['board_title'], ENT_QUOTES) ?>