LuminaWebsite/member_picture.php
Maaxxs 6d8747c9e4 Moderation: all comments with flags, swear word filter; reactions on pictures and comments; last active in member list; map starts with categories hidden
- Moderation page with tabs: approval, all comments (critical/suspicious flags, search, filters), swear word filter (mark / hold / block, maintained by mods, detects leetspeak)
- Discord-style emoji reactions on gallery pictures and comments (without reloading)
- Member list and profile: "last active" / online dot, sortable
- Map: all marker categories hidden at start

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 22:12:10 +02:00

187 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Ein Bild aus der Galerie eines Mitglieds in gross, mit Blaettern und Kommentaren darunter.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_once __DIR__ . '/includes/reactions.php';
require_permission('members.view');
$pictureId = (int) ($_GET['id'] ?? 0);
$stmt = db()->prepare(
"SELECT g.*, g.status AS picture_status, u.username, u.display_name, u.avatar_filename, u.status, u.gallery_comments_enabled
FROM member_gallery g JOIN users u ON u.id = g.user_id WHERE g.id = ?"
);
$stmt->execute([$pictureId]);
$picture = $stmt->fetch();
$me = current_user();
$isModerator = moderation_can();
$isOwner = $picture && (int) $me['id'] === (int) $picture['user_id'];
// Noch nicht freigegebene Bilder sehen nur der Besitzer und die Moderation.
if (!$picture || $picture['status'] !== 'active' || ($picture['picture_status'] === 'pending' && !$isOwner && !$isModerator)) {
show_not_found();
}
$ownerId = (int) $picture['user_id'];
$ownerName = $picture['display_name'] !== '' ? $picture['display_name'] : $picture['username'];
$commentsEnabled = !empty($picture['gallery_comments_enabled']);
// Vorheriges / naechstes Bild derselben Galerie (Reihenfolge wie auf der Profilseite)
$ids = db()->prepare('SELECT id FROM member_gallery WHERE user_id = ?' . ($isOwner || $isModerator ? '' : " AND status = 'visible'") . ' ORDER BY sort_order, id');
$ids->execute([$ownerId]);
$galleryIds = array_map('intval', $ids->fetchAll(PDO::FETCH_COLUMN));
$position = array_search($pictureId, $galleryIds, true);
$prevId = $position > 0 ? $galleryIds[$position - 1] : null;
$nextId = $position !== false && $position < count($galleryIds) - 1 ? $galleryIds[$position + 1] : null;
$comments = [];
if ($commentsEnabled) {
$commentStmt = db()->prepare(
"SELECT c.id, c.author_id, c.body, c.created_at, c.status AS comment_status, c.moderation_note,
u.username, u.display_name, u.avatar_filename, u.status
FROM gallery_comments c JOIN users u ON u.id = c.author_id
WHERE c.gallery_id = ? AND (c.status = 'visible' OR c.author_id = ? OR ?) ORDER BY c.created_at, c.id"
);
$commentStmt->execute([$pictureId, (int) $me['id'], $isModerator ? 1 : 0]);
$comments = $commentStmt->fetchAll();
}
// Reaktionen (Emojis) am Bild und an den Kommentaren - gehen mit den Kommentaren an und aus
$pictureReactions = reactions_for('picture', [$pictureId])[$pictureId] ?? [];
$commentReactions = reactions_for('comment', array_map('intval', array_column($comments, 'id')));
// Schon gemeldet? (Knopf dann ausgegraut)
$reportedPicture = !empty(moderation_my_reports('picture', [$pictureId]));
$reportedComments = moderation_my_reports('comment', array_map('intval', array_column($comments, 'id')));
/** Melden-Knopf (fragt nach einem Grund) bzw. Freigeben-Knopf fuer die Moderation. */
$reportButton = static function (string $type, int $id, bool $already): string {
if ($already) {
return '<span class="report-done" title="Du hast das gemeldet - danke!">' . icon('flag') . ' Gemeldet</span>';
}
return '<form class="inline-form" method="post" action="/moderation_action.php" '
. 'onsubmit="var r = prompt(&quot;Was ist daran nicht in Ordnung? (optional)&quot;); if (r === null) return false; this.reason.value = r; return true;">'
. csrf_field()
. '<input type="hidden" name="action" value="report"><input type="hidden" name="type" value="' . $type . '">'
. '<input type="hidden" name="id" value="' . $id . '"><input type="hidden" name="reason" value="">'
. '<button type="submit" class="icon-button report-button" title="Melden" aria-label="Melden">' . icon('flag') . '</button></form>';
};
$approveButton = static function (string $type, int $id): string {
return '<form class="inline-form" method="post" action="/moderation_action.php">' . csrf_field()
. '<input type="hidden" name="action" value="approve"><input type="hidden" name="type" value="' . $type . '">'
. '<input type="hidden" name="id" value="' . $id . '"><input type="hidden" name="back" value="picture">'
. '<button type="submit" class="button-success button-small">Freigeben</button></form>';
};
$url = profile_image_url($picture['filename']);
$pageTitle = ($picture['caption'] ?: 'Bild') . ' - ' . $ownerName;
include __DIR__ . '/includes/header.php';
?>
<div class="panel picture-view">
<div class="picture-view-head">
<a class="picture-owner" href="/member.php?id=<?= $ownerId ?>">
<?= avatar_html(['id' => $ownerId, 'username' => $picture['username'], 'display_name' => $picture['display_name'], 'avatar_filename' => $picture['avatar_filename']], 36) ?>
<span>Galerie von <strong><?= e($ownerName) ?></strong></span>
</a>
<div class="picture-view-tools">
<span class="text-muted"><?= $position !== false ? ($position + 1) . ' / ' . count($galleryIds) : '' ?></span>
<?php if (!$isOwner): ?><?= $reportButton('picture', $pictureId, $reportedPicture) ?><?php endif; ?>
</div>
</div>
<?php if ($picture['picture_status'] === 'pending'): ?>
<div class="pending-notice">
<span><strong>Wartet auf Freigabe</strong> - nur <?= $isOwner ? 'du und die Moderation sehen' : 'der Besitzer und die Moderation sehen' ?> dieses Bild.
<?php if (!empty($picture['moderation_note'])): ?><span class="text-muted">(<?= e((string) $picture['moderation_note']) ?>)</span><?php endif; ?></span>
<?php if ($isModerator): ?><?= $approveButton('picture', $pictureId) ?><?php endif; ?>
</div>
<?php endif; ?>
<figure class="picture-view-image">
<?php if ($prevId !== null): ?>
<a class="picture-nav picture-nav-prev" href="/member_picture.php?id=<?= $prevId ?>" title="Vorheriges Bild (←)" aria-label="Vorheriges Bild">‹</a>
<?php endif; ?>
<a href="<?= e($url) ?>" target="_blank" rel="noopener" title="Originalgröße öffnen">
<img src="<?= e($url) ?>" alt="<?= e($picture['caption'] ?: 'Bild von ' . $ownerName) ?>">
</a>
<?php if ($nextId !== null): ?>
<a class="picture-nav picture-nav-next" href="/member_picture.php?id=<?= $nextId ?>" title="Nächstes Bild (→)" aria-label="Nächstes Bild">›</a>
<?php endif; ?>
<?php if (!empty($picture['caption'])): ?><figcaption><?= e($picture['caption']) ?></figcaption><?php endif; ?>
</figure>
<?php if ($commentsEnabled): ?>
<div class="picture-reactions"><?= reactions_bar_html('picture', $pictureId, $pictureReactions, true) ?></div>
<?php endif; ?>
</div>
<div class="panel picture-comments" id="kommentare">
<h2><?= icon('message') ?> Kommentare<?= $commentsEnabled && $comments ? ' <span class="chip-count">' . count($comments) . '</span>' : '' ?></h2>
<?php if (!$commentsEnabled): ?>
<p class="text-muted"><?= $isOwner ? 'Du hast Kommentare unter deinen Bildern abgeschaltet. Einschalten kannst du sie beim Bearbeiten deiner Profilseite.' : e($ownerName) . ' hat Kommentare unter den eigenen Bildern abgeschaltet.' ?></p>
<?php else: ?>
<?php if (empty($comments)): ?>
<p class="text-muted">Noch keine Kommentare - schreib den ersten.</p>
<?php else: ?>
<ol class="comment-list">
<?php foreach ($comments as $comment): ?>
<?php $authorName = $comment['display_name'] !== '' ? $comment['display_name'] : $comment['username']; ?>
<li class="comment<?= $comment['comment_status'] === 'pending' ? ' is-pending' : '' ?>" id="kommentar-<?= (int) $comment['id'] ?>">
<?= avatar_html(['id' => $comment['author_id'], 'username' => $comment['username'], 'display_name' => $comment['display_name'], 'avatar_filename' => $comment['avatar_filename']], 36) ?>
<div class="comment-body">
<div class="comment-head">
<?php if ($comment['status'] === 'active'): ?>
<a href="/member.php?id=<?= (int) $comment['author_id'] ?>"><strong><?= e($authorName) ?></strong></a>
<?php else: ?>
<strong><?= e($authorName) ?></strong>
<?php endif; ?>
<?php if ((int) $comment['author_id'] === $ownerId): ?><span class="badge">Galerie-Besitzer</span><?php endif; ?>
<?php if ($comment['comment_status'] === 'pending'): ?>
<span class="pending-badge-inline" title="<?= e((string) $comment['moderation_note']) ?>">Wartet auf Freigabe</span>
<?php if ($isModerator): ?><?= $approveButton('comment', (int) $comment['id']) ?><?php endif; ?>
<?php endif; ?>
<time class="text-muted" datetime="<?= e(date('c', strtotime((string) $comment['created_at']))) ?>"><?= e(date('d.m.Y H:i', strtotime((string) $comment['created_at']))) ?></time>
<?php if ((int) $comment['author_id'] !== (int) $me['id']): ?>
<span class="comment-report"><?= $reportButton('comment', (int) $comment['id'], isset($reportedComments[(int) $comment['id']])) ?></span>
<?php endif; ?>
<?php if (gallery_comment_can_delete($comment, $ownerId)): ?>
<form class="inline-form comment-delete" method="post" action="/gallery_comment_action.php" onsubmit="return confirm('Diesen Kommentar löschen?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="comment_id" value="<?= (int) $comment['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="Kommentar löschen" aria-label="Kommentar löschen"><?= icon('trash') ?></button>
</form>
<?php endif; ?>
</div>
<p><?= gallery_comment_html((string) $comment['body']) ?></p>
<?= reactions_bar_html('comment', (int) $comment['id'], $commentReactions[(int) $comment['id']] ?? [], true, true) ?>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
<form class="comment-form" method="post" action="/gallery_comment_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="add">
<input type="hidden" name="picture_id" value="<?= $pictureId ?>">
<?= avatar_html($me, 36) ?>
<div class="comment-form-body">
<textarea name="body" rows="2" maxlength="<?= GALLERY_COMMENT_MAX ?>" required placeholder="Kommentar schreiben …" aria-label="Kommentar"></textarea>
<div class="comment-form-actions">
<span class="field-hint">Nur Text, Links werden klickbar. Bitte freundlich bleiben.</span>
<button type="submit" class="button-small">Senden</button>
</div>
</div>
</form>
<?php endif; ?>
</div>
<script src="<?= e(asset_url('/assets/js/reactions.js')) ?>"></script>
<script>
// Pfeiltasten blaettern (nicht beim Schreiben)
document.addEventListener('keydown', function (e) {
if (/^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement.tagName)) return;
var selector = { ArrowLeft: '.picture-nav-prev', ArrowRight: '.picture-nav-next' }[e.key];
var link = selector && document.querySelector(selector);
if (link) location.href = link.href;
});
</script>
<?php include __DIR__ . '/includes/footer.php'; ?>