This commit is contained in:
@@ -29,7 +29,37 @@ $allowNoKidsChecked = $editEvent ? ((int)$editEvent['allow_kids'] === 0) : false
|
||||
</div>
|
||||
|
||||
<div class="container dash-section">
|
||||
<div class="dash-grid-2">
|
||||
<div class="dash-grid">
|
||||
<div class="card dash-card">
|
||||
<div class="badge">Community</div>
|
||||
<h3>Dein Community-Status</h3>
|
||||
<ul class="dash-list">
|
||||
<li>Rang: <?= htmlspecialchars(trim(($communityLevel['icon'] ?? '') . ' ' . ($communityLevel['label'] ?? '')), ENT_QUOTES) ?></li>
|
||||
<li>Punkte: <?= number_format((float)$communityPoints, 1, ',', '.') ?></li>
|
||||
<li>Rollen: <?= htmlspecialchars($communityRoles ? implode(', ', $communityRoles) : 'Keine besonderen Rollen', ENT_QUOTES) ?></li>
|
||||
<li>Themen erstellen: <?= $communityRestrictions['thread_create_blocked'] ? 'Gesperrt' : 'Erlaubt' ?></li>
|
||||
<li>Antworten schreiben: <?= $communityRestrictions['reply_blocked'] ? 'Gesperrt' : 'Erlaubt' ?></li>
|
||||
</ul>
|
||||
<?php if (!empty($communityRestrictions['reason'])): ?>
|
||||
<p class="muted small" style="margin-top:10px;">Hinweis zur Community-Sperre: <?= htmlspecialchars((string)$communityRestrictions['reason'], ENT_QUOTES) ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($communityCanApply): ?>
|
||||
<form method="post" class="stack gap-6" style="margin-top:12px;">
|
||||
<input type="hidden" name="action" value="community_admin_apply">
|
||||
<label class="label" for="communityMotivation">Bewerbung als Forum-Admin</label>
|
||||
<textarea id="communityMotivation" name="motivation" class="textarea" rows="4" placeholder="Warum möchtest du die Community als Forum-Admin unterstützen?" required></textarea>
|
||||
<button class="btn" type="submit">Bewerbung absenden</button>
|
||||
</form>
|
||||
<?php elseif ($communityApplication): ?>
|
||||
<div style="margin-top:12px;">
|
||||
<p class="muted small" style="margin:0;">Letzte Bewerbung: <strong><?= htmlspecialchars((string)$communityApplication['status'], ENT_QUOTES) ?></strong></p>
|
||||
<?php if (!empty($communityApplication['decision_reason'])): ?>
|
||||
<p class="muted small" style="margin-top:6px;"><?= htmlspecialchars((string)$communityApplication['decision_reason'], ENT_QUOTES) ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="card dash-card">
|
||||
<div class="badge">Profil</div>
|
||||
<h3>Deine Angaben</h3>
|
||||
|
||||
257
partials/landing/community/index.php
Executable file → Normal file
257
partials/landing/community/index.php
Executable file → Normal file
@@ -5,28 +5,62 @@ $app = app();
|
||||
$pdo = $app->pdo();
|
||||
$userId = $_SESSION['user_id'] ?? null;
|
||||
$error = '';
|
||||
$info = '';
|
||||
$search = trim((string)($_GET['q'] ?? ''));
|
||||
$boardSlug = trim((string)($_GET['board'] ?? ''));
|
||||
|
||||
$communityCfg = require __DIR__ . '/../../../config/community.php';
|
||||
$community = $pdo ? new \App\Community($pdo, $communityCfg) : null;
|
||||
$stats = $community ? $community->getStats() : ['threads' => 0, 'posts' => 0, 'members' => 0];
|
||||
$access = $pdo ? new \App\CommunityAccess($pdo, $communityCfg) : null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'thread_create') {
|
||||
if (!$userId) {
|
||||
$error = 'Bitte einloggen, um Fragen zu stellen.';
|
||||
} elseif ($community) {
|
||||
$title = trim((string)($_POST['title'] ?? ''));
|
||||
$body = trim((string)($_POST['body'] ?? ''));
|
||||
if ($title === '' || $body === '') {
|
||||
$error = 'Titel und Text sind erforderlich.';
|
||||
} else {
|
||||
$community->createThread((int)$userId, $title, $body);
|
||||
redirect('/community');
|
||||
$stats = $community ? $community->getStats() : ['threads' => 0, 'posts' => 0, 'members' => 0];
|
||||
$forumCategories = $community ? $community->listForumCategories() : [];
|
||||
$selectedBoard = ($community && $boardSlug !== '') ? $community->getBoardBySlug($boardSlug) : null;
|
||||
$userRoles = $access && $userId ? $access->getUserRoles((int)$userId) : [];
|
||||
$isForumAdmin = $access && $userId ? $access->canModerateForum((int)$userId) : false;
|
||||
$canManageApplications = $access && $userId ? ($access->canManageApplications((int)$userId) && $access->supportsApplications()) : false;
|
||||
$canManageRoles = $access && $userId ? $access->canManageRoles((int)$userId) : false;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $community && $access) {
|
||||
$action = (string)($_POST['action'] ?? '');
|
||||
try {
|
||||
if ($action === 'thread_create') {
|
||||
if (!$userId) {
|
||||
throw new \RuntimeException('Bitte einloggen, um Themen zu erstellen.');
|
||||
}
|
||||
if (!$access->canCreateThread((int)$userId)) {
|
||||
$state = $access->getRestrictionState((int)$userId);
|
||||
throw new \RuntimeException($state['reason'] ?: 'Du darfst aktuell keine Themen erstellen.');
|
||||
}
|
||||
$community->createThreadInBoard((int)$userId, (string)($_POST['board_slug'] ?? ''), (string)($_POST['title'] ?? ''), (string)($_POST['body'] ?? ''));
|
||||
redirect('/community' . ($boardSlug !== '' ? '?board=' . rawurlencode($boardSlug) : ''));
|
||||
} elseif ($action === 'application_decide') {
|
||||
$access->decideApplication((int)$userId, (int)($_POST['application_id'] ?? 0), (string)($_POST['decision'] ?? ''), (string)($_POST['decision_reason'] ?? ''));
|
||||
$info = 'Bewerbung wurde bearbeitet.';
|
||||
} elseif ($action === 'report_resolve') {
|
||||
$access->resolveReport((int)$userId, (int)($_POST['report_id'] ?? 0), (string)($_POST['moderator_note'] ?? ''));
|
||||
$info = 'Meldung wurde abgeschlossen.';
|
||||
} elseif ($action === 'role_revoke') {
|
||||
$access->revokeRole((int)$userId, (int)($_POST['target_user_id'] ?? 0), (string)($_POST['role'] ?? ''));
|
||||
$info = 'Rolle wurde entzogen.';
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
$threads = $community ? ($search !== '' ? $community->searchThreads($search, 50) : $community->listThreads(50)) : [];
|
||||
$threads = $community
|
||||
? ($search !== '' ? $community->searchThreads($search, 50, $boardSlug !== '' ? $boardSlug : null) : $community->listThreads(50, $boardSlug !== '' ? $boardSlug : null))
|
||||
: [];
|
||||
$applications = $canManageApplications && $access ? $access->listApplications('open') : [];
|
||||
$reports = $isForumAdmin && $access ? $access->listOpenReports() : [];
|
||||
$roleAssignments = $canManageRoles && $access ? $access->listRoleAssignments() : [];
|
||||
?>
|
||||
<main class="section">
|
||||
<div class="container">
|
||||
@@ -36,6 +70,10 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<a href="/">Home</a>
|
||||
<span>/</span>
|
||||
<span>Community</span>
|
||||
<?php if ($selectedBoard): ?>
|
||||
<span>/</span>
|
||||
<span><?= htmlspecialchars((string)$selectedBoard['title'], ENT_QUOTES) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<h1>Community</h1>
|
||||
<p class="forum-hero__copy">Fragen stellen, Erfahrungen teilen, Antworten finden und gemeinsam weiterdenken.</p>
|
||||
@@ -50,10 +88,13 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="toast-bar" style="border-color:#f87171; color:#991b1b;"><?= htmlspecialchars($error, ENT_QUOTES) ?></div>
|
||||
<div class="toast-bar" style="margin-top:14px; border-color:#f87171; color:#991b1b;"><?= htmlspecialchars($error, ENT_QUOTES) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($info): ?>
|
||||
<div class="toast-bar" style="margin-top:14px;"><?= htmlspecialchars($info, ENT_QUOTES) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="forum-stats">
|
||||
<div class="forum-stats forum-stats--compact">
|
||||
<div class="forum-stat">
|
||||
<span class="forum-stat__label">Themen</span>
|
||||
<strong><?= number_format($stats['threads']) ?></strong>
|
||||
@@ -62,19 +103,59 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<span class="forum-stat__label">Beiträge</span>
|
||||
<strong><?= number_format($stats['posts']) ?></strong>
|
||||
</div>
|
||||
<div class="forum-stat">
|
||||
<span class="forum-stat__label">Mitglieder</span>
|
||||
<strong><?= number_format($stats['members']) ?></strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="forum-board">
|
||||
<div class="forum-category-list">
|
||||
<?php foreach ($forumCategories as $category): ?>
|
||||
<section class="forum-category-card">
|
||||
<div class="forum-category-card__title"><?= htmlspecialchars((string)$category['title'], ENT_QUOTES) ?></div>
|
||||
<div class="forum-board-grid">
|
||||
<?php foreach ($category['boards'] as $board): ?>
|
||||
<?php $latest = $board['latest_thread'] ?? null; ?>
|
||||
<article class="forum-board-row">
|
||||
<div class="forum-board-row__main">
|
||||
<div class="forum-row__icon" aria-hidden="true"><?= htmlspecialchars((string)($board['icon'] ?? '💬'), ENT_QUOTES) ?></div>
|
||||
<div>
|
||||
<h3>
|
||||
<a href="/community?board=<?= rawurlencode((string)$board['slug']) ?>">
|
||||
<?= htmlspecialchars((string)$board['title'], ENT_QUOTES) ?>
|
||||
</a>
|
||||
</h3>
|
||||
<p><?= htmlspecialchars((string)$board['description'], ENT_QUOTES) ?></p>
|
||||
<div class="forum-row__meta">
|
||||
<span>Themen: <?= (int)($board['thread_count'] ?? 0) ?></span>
|
||||
<span>Beiträge: <?= (int)($board['post_count'] ?? 0) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="forum-board-row__latest">
|
||||
<?php if ($latest): ?>
|
||||
<strong><a href="/community_thread?id=<?= (int)$latest['id'] ?>"><?= htmlspecialchars((string)$latest['title'], ENT_QUOTES) ?></a></strong>
|
||||
<span><?= htmlspecialchars((string)($latest['last_activity_by'] ?: 'Mitglied'), ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars((string)$latest['last_activity_at'], ENT_QUOTES) ?></span>
|
||||
<?php else: ?>
|
||||
<span class="muted">Noch keine Themen</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<div class="forum-board" style="margin-top:24px;">
|
||||
<div class="forum-board__head">
|
||||
<div>
|
||||
<h2>Forum</h2>
|
||||
<p class="muted">Hier findest du die neuesten Themen, Antworten und laufenden Gespräche.</p>
|
||||
<h2><?= htmlspecialchars($selectedBoard['title'] ?? 'Themenübersicht', ENT_QUOTES) ?></h2>
|
||||
<p class="muted">
|
||||
<?= htmlspecialchars($selectedBoard['description'] ?? 'Hier findest du die neuesten Themen, Antworten und laufenden Gespräche.', ENT_QUOTES) ?>
|
||||
</p>
|
||||
</div>
|
||||
<form method="get" class="forum-search">
|
||||
<?php if ($boardSlug !== ''): ?>
|
||||
<input type="hidden" name="board" value="<?= htmlspecialchars($boardSlug, ENT_QUOTES) ?>">
|
||||
<?php endif; ?>
|
||||
<label class="label" for="searchQ">Suche</label>
|
||||
<div class="forum-search__row">
|
||||
<input id="searchQ" name="q" class="input" value="<?= htmlspecialchars($search, ENT_QUOTES) ?>" placeholder="Schlagwort eingeben">
|
||||
@@ -100,11 +181,13 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<div class="forum-row__topic">
|
||||
<div class="forum-row__icon" aria-hidden="true">💬</div>
|
||||
<div>
|
||||
<h3><a href="/community_thread?id=<?= (int)$t['id'] ?>"><?= htmlspecialchars($t['title'], ENT_QUOTES) ?></a></h3>
|
||||
<h3><a href="/community_thread?id=<?= (int)$t['id'] ?>"><?= htmlspecialchars((string)$t['title'], ENT_QUOTES) ?></a></h3>
|
||||
<div class="forum-row__meta">
|
||||
<span><?= htmlspecialchars($t['display_name'] ?: 'Mitglied', ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars($lvl['icon'] ?? '', ENT_QUOTES) ?> <?= htmlspecialchars($lvl['label'] ?? '', ENT_QUOTES) ?></span>
|
||||
<span><?= number_format($pts, 1) ?> Punkte</span>
|
||||
<span><?= htmlspecialchars((string)($t['display_name'] ?: 'Mitglied'), ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars(trim((string)($lvl['icon'] ?? '') . ' ' . (string)($lvl['label'] ?? '')), ENT_QUOTES) ?></span>
|
||||
<?php if (!empty($t['board_title'])): ?>
|
||||
<span><?= htmlspecialchars((string)$t['board_title'], ENT_QUOTES) ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<p><?= nl2br(htmlspecialchars($preview, ENT_QUOTES)) ?><?= mb_strlen((string)$t['body']) > 220 ? '…' : '' ?></p>
|
||||
</div>
|
||||
@@ -114,8 +197,8 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<span>Antworten</span>
|
||||
</div>
|
||||
<div class="forum-row__activity">
|
||||
<strong><?= htmlspecialchars($t['last_activity_by'] ?: 'Mitglied', ENT_QUOTES) ?></strong>
|
||||
<span><?= htmlspecialchars($t['last_activity_at'], ENT_QUOTES) ?></span>
|
||||
<strong><?= htmlspecialchars((string)($t['last_activity_by'] ?: 'Mitglied'), ENT_QUOTES) ?></strong>
|
||||
<span><?= htmlspecialchars((string)$t['last_activity_at'], ENT_QUOTES) ?></span>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
@@ -125,6 +208,104 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($canManageApplications || $isForumAdmin || $canManageRoles): ?>
|
||||
<div class="forum-admin-grid">
|
||||
<?php if ($canManageApplications): ?>
|
||||
<section class="forum-board">
|
||||
<div class="forum-board__head">
|
||||
<div>
|
||||
<h2>Offene Bewerbungen</h2>
|
||||
<p class="muted">Bewerbungen ab Rang Community-Vater prüfen.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="forum-admin-list">
|
||||
<?php foreach ($applications as $application): ?>
|
||||
<article class="forum-admin-item">
|
||||
<div>
|
||||
<strong><?= htmlspecialchars((string)($application['display_name'] ?: $application['email']), ENT_QUOTES) ?></strong>
|
||||
<p><?= nl2br(htmlspecialchars((string)$application['motivation'], ENT_QUOTES)) ?></p>
|
||||
</div>
|
||||
<form method="post" class="forum-admin-item__actions">
|
||||
<input type="hidden" name="action" value="application_decide">
|
||||
<input type="hidden" name="application_id" value="<?= (int)$application['id'] ?>">
|
||||
<textarea name="decision_reason" class="textarea" rows="3" placeholder="Begründung (optional bei Annahme, sinnvoll bei Ablehnung)"></textarea>
|
||||
<div class="flex gap-12">
|
||||
<button class="btn" type="submit" name="decision" value="approved">Annehmen</button>
|
||||
<button class="btn ghost" type="submit" name="decision" value="rejected">Ablehnen</button>
|
||||
</div>
|
||||
</form>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
<?php if (!$applications): ?>
|
||||
<div class="forum-empty">Keine offenen Bewerbungen.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($isForumAdmin && $access && $access->supportsReports()): ?>
|
||||
<section class="forum-board">
|
||||
<div class="forum-board__head">
|
||||
<div>
|
||||
<h2>Offene Meldungen</h2>
|
||||
<p class="muted">Gemeldete Inhalte prüfen und moderieren.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="forum-admin-list">
|
||||
<?php foreach ($reports as $report): ?>
|
||||
<article class="forum-admin-item">
|
||||
<div>
|
||||
<strong><?= htmlspecialchars((string)$report['target_type'], ENT_QUOTES) ?> #<?= (int)$report['target_id'] ?></strong>
|
||||
<p><?= nl2br(htmlspecialchars((string)$report['reason'], ENT_QUOTES)) ?></p>
|
||||
<p class="muted small">Gemeldet von <?= htmlspecialchars((string)($report['reporter_name'] ?: 'Mitglied'), ENT_QUOTES) ?> am <?= htmlspecialchars((string)$report['created_at'], ENT_QUOTES) ?></p>
|
||||
</div>
|
||||
<form method="post" class="forum-admin-item__actions">
|
||||
<input type="hidden" name="action" value="report_resolve">
|
||||
<input type="hidden" name="report_id" value="<?= (int)$report['id'] ?>">
|
||||
<textarea name="moderator_note" class="textarea" rows="3" placeholder="Moderationsnotiz (optional)"></textarea>
|
||||
<button class="btn" type="submit">Als erledigt markieren</button>
|
||||
</form>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
<?php if (!$reports): ?>
|
||||
<div class="forum-empty">Keine offenen Meldungen.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($canManageRoles && $access && $access->hasModerationTables()): ?>
|
||||
<section class="forum-board">
|
||||
<div class="forum-board__head">
|
||||
<div>
|
||||
<h2>Rollenübersicht</h2>
|
||||
<p class="muted">Vergebene Community-Rollen im Blick behalten.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="forum-admin-list">
|
||||
<?php foreach ($roleAssignments as $assignment): ?>
|
||||
<article class="forum-admin-item">
|
||||
<div>
|
||||
<strong><?= htmlspecialchars((string)($assignment['display_name'] ?: $assignment['email']), ENT_QUOTES) ?></strong>
|
||||
<p class="muted small">Rolle: <?= htmlspecialchars((string)$assignment['role'], ENT_QUOTES) ?> · seit <?= htmlspecialchars((string)$assignment['assigned_at'], ENT_QUOTES) ?></p>
|
||||
</div>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="role_revoke">
|
||||
<input type="hidden" name="target_user_id" value="<?= (int)$assignment['user_id'] ?>">
|
||||
<input type="hidden" name="role" value="<?= htmlspecialchars((string)$assignment['role'], ENT_QUOTES) ?>">
|
||||
<button class="btn ghost" type="submit">Rolle entziehen</button>
|
||||
</form>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
<?php if (!$roleAssignments): ?>
|
||||
<div class="forum-empty">Keine Rollen vergeben.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
@@ -132,22 +313,36 @@ $threads = $community ? ($search !== '' ? $community->searchThreads($search, 50)
|
||||
<div class="modal" id="modalThread">
|
||||
<div class="panel">
|
||||
<div class="head flex between center-y">
|
||||
<h3 style="margin:0;">Neue Frage</h3>
|
||||
<h3 style="margin:0;">Neues Thema</h3>
|
||||
<button class="btn ghost" type="button" data-modal-close>✕</button>
|
||||
</div>
|
||||
<form method="post" class="stack gap-10" style="margin-top:12px;">
|
||||
<input type="hidden" name="action" value="thread_create">
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="fBoardModal">Unterforum</label>
|
||||
<select id="fBoardModal" name="board_slug" class="select">
|
||||
<?php foreach ($forumCategories as $category): ?>
|
||||
<optgroup label="<?= htmlspecialchars((string)$category['title'], ENT_QUOTES) ?>">
|
||||
<?php foreach ($category['boards'] as $board): ?>
|
||||
<option value="<?= htmlspecialchars((string)$board['slug'], ENT_QUOTES) ?>" <?= $boardSlug === $board['slug'] ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars((string)$board['title'], ENT_QUOTES) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="fTitleModal">Frage/Titel</label>
|
||||
<input id="fTitleModal" name="title" class="input" required>
|
||||
</div>
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="fBodyModal">Text</label>
|
||||
<textarea id="fBodyModal" name="body" class="textarea" rows="4" required></textarea>
|
||||
<textarea id="fBodyModal" name="body" class="textarea" rows="5" required></textarea>
|
||||
</div>
|
||||
<div class="flex gap-12" style="flex-wrap:wrap;">
|
||||
<button class="btn ghost" type="button" data-modal-close>Abbrechen</button>
|
||||
<button class="btn" type="submit">Frage erstellen</button>
|
||||
<button class="btn" type="submit">Thema erstellen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
283
partials/landing/community/thread.php
Executable file → Normal file
283
partials/landing/community/thread.php
Executable file → Normal file
@@ -5,22 +5,88 @@ $app = app();
|
||||
$pdo = $app->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;
|
||||
|
||||
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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +102,12 @@ if (!$thread) {
|
||||
$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) : [];
|
||||
?>
|
||||
<main class="section">
|
||||
<div class="container">
|
||||
@@ -43,14 +115,21 @@ $threadLevel = $community ? $community->membershipLevel($threadPoints) : ['label
|
||||
<a href="/">Home</a>
|
||||
<span>/</span>
|
||||
<a href="/community">Community</a>
|
||||
<?php if (!empty($thread['board_title'])): ?>
|
||||
<span>/</span>
|
||||
<a href="/community?board=<?= rawurlencode((string)$thread['board_slug']) ?>"><?= htmlspecialchars((string)$thread['board_title'], ENT_QUOTES) ?></a>
|
||||
<?php endif; ?>
|
||||
<span>/</span>
|
||||
<span><?= htmlspecialchars($thread['title'], ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars((string)$thread['title'], ENT_QUOTES) ?></span>
|
||||
</div>
|
||||
|
||||
<div class="forum-thread-head">
|
||||
<div>
|
||||
<h1><?= htmlspecialchars($thread['title'], ENT_QUOTES) ?></h1>
|
||||
<p class="forum-thread-head__meta">Erstellt von <?= htmlspecialchars($threadAuthor, ENT_QUOTES) ?> am <?= htmlspecialchars($thread['created_at'], ENT_QUOTES) ?></p>
|
||||
<h1><?= htmlspecialchars((string)$thread['title'], ENT_QUOTES) ?></h1>
|
||||
<p class="forum-thread-head__meta">Erstellt von <?= htmlspecialchars($threadAuthor, ENT_QUOTES) ?> am <?= htmlspecialchars((string)$thread['created_at'], ENT_QUOTES) ?></p>
|
||||
<?php if (!empty($thread['board_title'])): ?>
|
||||
<p class="muted small" style="margin:8px 0 0;">Bereich: <?= htmlspecialchars((string)$thread['board_title'], ENT_QUOTES) ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="forum-thread-head__meta-box">
|
||||
<strong><?= count($posts) ?></strong>
|
||||
@@ -58,21 +137,46 @@ $threadLevel = $community ? $community->membershipLevel($threadPoints) : ['label
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="toast-bar" style="margin-bottom:14px; border-color:#f87171; color:#991b1b;"><?= htmlspecialchars($error, ENT_QUOTES) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if ($info): ?>
|
||||
<div class="toast-bar" style="margin-bottom:14px;"><?= htmlspecialchars($info, ENT_QUOTES) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<article class="forum-post forum-post--lead">
|
||||
<aside class="forum-post__author">
|
||||
<div class="forum-post__avatar" aria-hidden="true"><?= strtoupper(mb_substr($threadAuthor, 0, 1)) ?></div>
|
||||
<strong><?= htmlspecialchars($threadAuthor, ENT_QUOTES) ?></strong>
|
||||
<span><?= htmlspecialchars($threadLevel['icon'] ?? '', ENT_QUOTES) ?> <?= htmlspecialchars($threadLevel['label'] ?? '', ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars(trim((string)($threadLevel['icon'] ?? '') . ' ' . (string)($threadLevel['label'] ?? '')), ENT_QUOTES) ?></span>
|
||||
<span><?= number_format($threadPoints, 1) ?> Punkte</span>
|
||||
<?php if ($isForumAdmin): ?>
|
||||
<div class="forum-post__admin">
|
||||
<button class="btn ghost" type="button" data-modal-open="modalThreadEdit">Thema bearbeiten</button>
|
||||
<form method="post" onsubmit="return confirm('Thema wirklich löschen?');">
|
||||
<input type="hidden" name="action" value="thread_delete">
|
||||
<button class="btn ghost" type="submit">Thema löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</aside>
|
||||
<div class="forum-post__body">
|
||||
<div class="forum-post__head">
|
||||
<span><?= htmlspecialchars($thread['created_at'], ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars((string)$thread['created_at'], ENT_QUOTES) ?></span>
|
||||
<span>#1</span>
|
||||
</div>
|
||||
<div class="forum-post__content">
|
||||
<?= nl2br(htmlspecialchars($thread['body'], ENT_QUOTES)) ?>
|
||||
<?= nl2br(htmlspecialchars((string)$thread['body'], ENT_QUOTES)) ?>
|
||||
</div>
|
||||
<?php if ($userId && $access && $access->supportsReports()): ?>
|
||||
<form method="post" class="forum-inline-report">
|
||||
<input type="hidden" name="action" value="report_content">
|
||||
<input type="hidden" name="target_type" value="thread">
|
||||
<input type="hidden" name="target_id" value="<?= (int)$thread['id'] ?>">
|
||||
<input type="hidden" name="reason" value="Thread benötigt Moderation oder Prüfung.">
|
||||
<button class="btn ghost" type="submit">Thema melden</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
@@ -82,21 +186,93 @@ $threadLevel = $community ? $community->membershipLevel($threadPoints) : ['label
|
||||
</div>
|
||||
|
||||
<div class="forum-replies">
|
||||
<?php foreach ($posts as $p): ?>
|
||||
<?php foreach ($posts as $index => $p): ?>
|
||||
<?php
|
||||
$postAuthor = (string)($p['display_name'] ?: 'Mitglied');
|
||||
$summary = $feedbackSummary[(int)$p['id']] ?? ['helpful' => 0, 'unhelpful' => 0];
|
||||
$userVote = $userVotes[(int)$p['id']] ?? 0;
|
||||
$isHighlighted = !empty($p['highlighted_at']);
|
||||
?>
|
||||
<article class="forum-post">
|
||||
<article class="forum-post<?= $isHighlighted ? ' forum-post--highlighted' : '' ?>">
|
||||
<aside class="forum-post__author">
|
||||
<div class="forum-post__avatar" aria-hidden="true"><?= strtoupper(mb_substr($postAuthor, 0, 1)) ?></div>
|
||||
<strong><?= htmlspecialchars($postAuthor, ENT_QUOTES) ?></strong>
|
||||
<?php if ($isHighlighted): ?>
|
||||
<span class="forum-highlight-badge">Hilfreich hervorgehoben</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($isForumAdmin && $access && $access->supportsRestrictions()): ?>
|
||||
<form method="post" class="forum-admin-mini-form">
|
||||
<input type="hidden" name="action" value="restriction_set">
|
||||
<input type="hidden" name="target_user_id" value="<?= (int)$p['user_id'] ?>">
|
||||
<input type="hidden" name="restriction_type" value="reply_blocked">
|
||||
<input type="hidden" name="reason" value="Antworten in der Community vorübergehend gesperrt.">
|
||||
<button class="btn ghost" type="submit">Antworten sperren</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</aside>
|
||||
<div class="forum-post__body">
|
||||
<div class="forum-post__head">
|
||||
<span><?= htmlspecialchars($p['created_at'], ENT_QUOTES) ?></span>
|
||||
<span><?= htmlspecialchars((string)$p['created_at'], ENT_QUOTES) ?></span>
|
||||
<span>#<?= $index + 2 ?></span>
|
||||
</div>
|
||||
<div class="forum-post__content">
|
||||
<?= nl2br(htmlspecialchars($p['body'], ENT_QUOTES)) ?>
|
||||
<?php if ($editPostId === (int)$p['id'] && $isForumAdmin): ?>
|
||||
<form method="post" class="stack gap-10">
|
||||
<input type="hidden" name="action" value="post_update">
|
||||
<input type="hidden" name="post_id" value="<?= (int)$p['id'] ?>">
|
||||
<textarea name="body" class="textarea" rows="6" required><?= htmlspecialchars((string)$p['body'], ENT_QUOTES) ?></textarea>
|
||||
<div class="flex gap-12">
|
||||
<button class="btn" type="submit">Änderung speichern</button>
|
||||
<a class="btn ghost" href="/community_thread?id=<?= $threadId ?>">Abbrechen</a>
|
||||
</div>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<?= nl2br(htmlspecialchars((string)$p['body'], ENT_QUOTES)) ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="forum-post__toolbar">
|
||||
<?php if ($userId && $access && $access->supportsFeedback()): ?>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="post_vote">
|
||||
<input type="hidden" name="post_id" value="<?= (int)$p['id'] ?>">
|
||||
<input type="hidden" name="value" value="1">
|
||||
<button class="btn ghost<?= $userVote === 1 ? ' is-active' : '' ?>" type="submit">Hilfreich (<?= (int)$summary['helpful'] ?>)</button>
|
||||
</form>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="post_vote">
|
||||
<input type="hidden" name="post_id" value="<?= (int)$p['id'] ?>">
|
||||
<input type="hidden" name="value" value="-1">
|
||||
<button class="btn ghost<?= $userVote === -1 ? ' is-active' : '' ?>" type="submit">Nicht hilfreich (<?= (int)$summary['unhelpful'] ?>)</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php if ($userId && $access && $access->supportsReports()): ?>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="report_content">
|
||||
<input type="hidden" name="target_type" value="post">
|
||||
<input type="hidden" name="target_id" value="<?= (int)$p['id'] ?>">
|
||||
<input type="hidden" name="reason" value="Beitrag benötigt Moderation oder Prüfung.">
|
||||
<button class="btn ghost" type="submit">Melden</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($userId && $access && $access->canHighlightHelpful($community->computePoints((int)$userId))): ?>
|
||||
<form method="post">
|
||||
<input type="hidden" name="action" value="highlight_post">
|
||||
<input type="hidden" name="post_id" value="<?= (int)$p['id'] ?>">
|
||||
<input type="hidden" name="highlight" value="<?= $isHighlighted ? '0' : '1' ?>">
|
||||
<button class="btn ghost" type="submit"><?= $isHighlighted ? 'Hervorhebung entfernen' : 'Als hilfreich hervorheben' ?></button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($isForumAdmin): ?>
|
||||
<a class="btn ghost" href="/community_thread?id=<?= $threadId ?>&edit_post=<?= (int)$p['id'] ?>">Bearbeiten</a>
|
||||
<form method="post" onsubmit="return confirm('Beitrag wirklich löschen?');">
|
||||
<input type="hidden" name="action" value="post_delete">
|
||||
<input type="hidden" name="post_id" value="<?= (int)$p['id'] ?>">
|
||||
<button class="btn ghost" type="submit">Löschen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
@@ -106,21 +282,68 @@ $threadLevel = $community ? $community->membershipLevel($threadPoints) : ['label
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="toast-bar" style="margin-top:12px; border-color:#f87171; color:#991b1b;"><?= htmlspecialchars($error, ENT_QUOTES) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($userId): ?>
|
||||
<form method="post" class="forum-reply-form">
|
||||
<input type="hidden" name="action" value="reply">
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="replyBody">Antwort</label>
|
||||
<textarea id="replyBody" name="body" class="textarea" rows="4" required></textarea>
|
||||
</div>
|
||||
<button class="btn" type="submit">Antwort senden</button>
|
||||
</form>
|
||||
<?php if ($userRestrictions['reply_blocked']): ?>
|
||||
<div class="forum-login-note">Du darfst aktuell keine Antworten schreiben. <?= !empty($userRestrictions['reason']) ? htmlspecialchars((string)$userRestrictions['reason'], ENT_QUOTES) : '' ?></div>
|
||||
<?php else: ?>
|
||||
<form method="post" class="forum-reply-form">
|
||||
<input type="hidden" name="action" value="reply">
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="replyBody">Antwort</label>
|
||||
<textarea id="replyBody" name="body" class="textarea" rows="4" required></textarea>
|
||||
</div>
|
||||
<button class="btn" type="submit">Antwort senden</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<div class="forum-login-note">Bitte <a href="/login">einloggen</a>, um zu antworten.</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<?php if ($isForumAdmin): ?>
|
||||
<div class="modal" id="modalThreadEdit">
|
||||
<div class="panel">
|
||||
<div class="head flex between center-y">
|
||||
<h3 style="margin:0;">Thema bearbeiten</h3>
|
||||
<button class="btn ghost" type="button" data-modal-close>✕</button>
|
||||
</div>
|
||||
<form method="post" class="stack gap-10" style="margin-top:12px;">
|
||||
<input type="hidden" name="action" value="thread_update">
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="threadTitleEdit">Titel</label>
|
||||
<input id="threadTitleEdit" name="title" class="input" value="<?= htmlspecialchars((string)$thread['title'], ENT_QUOTES) ?>" required>
|
||||
</div>
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="threadBodyEdit">Text</label>
|
||||
<textarea id="threadBodyEdit" name="body" class="textarea" rows="8" required><?= htmlspecialchars((string)$thread['body'], ENT_QUOTES) ?></textarea>
|
||||
</div>
|
||||
<div class="flex gap-12">
|
||||
<button class="btn ghost" type="button" data-modal-close>Abbrechen</button>
|
||||
<button class="btn" type="submit">Speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('[data-modal-open]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const id = btn.getAttribute('data-modal-open');
|
||||
const modal = document.getElementById(id);
|
||||
if (modal) modal.classList.add('open');
|
||||
});
|
||||
});
|
||||
document.querySelectorAll('[data-modal-close]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const modal = btn.closest('.modal');
|
||||
if (modal) modal.classList.remove('open');
|
||||
});
|
||||
});
|
||||
document.querySelectorAll('.modal').forEach(modal => {
|
||||
modal.addEventListener('click', (e) => {
|
||||
if (e.target === modal) modal.classList.remove('open');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user