This commit is contained in:
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>
|
||||
|
||||
Reference in New Issue
Block a user