LuminaWebsite/gallery_comment_action.php
Maaxxs 2a0e5c6fbc Own profile background image, hover borders on buttons, members below profile in the menu
- Profile background: upload an image only for the background (not part of the gallery),
  same moderation as gallery pictures, one per member, replace or delete it
- Hover border on buttons: black on gold buttons, gold on dark ones (dashboard points
  buttons keep their own effect)
- Sidebar: "Mitglieder" directly below "Mein Profil", tour follows the new order

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

112 lines
4.9 KiB
PHP

<?php
/**
* Kommentare unter Galeriebildern: schreiben und loeschen.
* Loeschen duerfen Verfasser, Bild-Besitzer und die Moderation (comments.moderate).
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_once __DIR__ . '/includes/reactions.php';
require_permission('members.view');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/members.php');
}
verify_csrf();
$action = (string) ($_POST['action'] ?? '');
$me = current_user();
$pdo = db();
if ($action === 'add') {
$pictureId = (int) ($_POST['picture_id'] ?? 0);
$back = '/member_picture.php?id=' . $pictureId . '#kommentare';
$stmt = $pdo->prepare(
'SELECT g.id, g.user_id, g.status AS picture_status, u.status, u.gallery_comments_enabled FROM member_gallery g JOIN users u ON u.id = g.user_id WHERE g.id = ? AND g.is_background = 0'
);
$stmt->execute([$pictureId]);
$picture = $stmt->fetch();
$canSeePicture = $picture && ($picture['picture_status'] === 'visible'
|| (int) $picture['user_id'] === (int) $me['id'] || moderation_can());
if (!$picture || $picture['status'] !== 'active' || !$canSeePicture) {
set_flash('error', 'Dieses Bild gibt es nicht (mehr).');
redirect('/members.php');
}
if (empty($picture['gallery_comments_enabled'])) {
set_flash('error', 'Unter diesen Bildern sind Kommentare abgeschaltet.');
redirect($back);
}
$body = trim(str_replace("\r\n", "\n", (string) ($_POST['body'] ?? '')));
// Mehr als zwei Leerzeilen am Stueck sind nur Platzverschwendung
$body = (string) preg_replace("/\n{3,}/", "\n\n", $body);
if ($body === '') {
set_flash('error', 'Der Kommentar ist leer.');
redirect($back);
}
if (mb_strlen($body) > GALLERY_COMMENT_MAX) {
set_flash('error', 'Der Kommentar ist zu lang (höchstens ' . GALLERY_COMMENT_MAX . ' Zeichen).');
redirect($back);
}
// Derselbe Text kurz hintereinander = doppelt abgeschickt oder Spam
$dupe = $pdo->prepare('SELECT COUNT(*) FROM gallery_comments WHERE author_id = ? AND body = ? AND created_at > ?');
$dupe->execute([(int) $me['id'], $body, date('Y-m-d H:i:s', time() - 600)]);
if ((int) $dupe->fetchColumn() > 0) {
set_flash('error', 'Diesen Kommentar hast du gerade schon geschrieben.');
redirect($back);
}
if (moderation_blocks($body, 'Kommentar unter einem Galeriebild')) {
set_flash('error', 'Dein Kommentar enthält ein Wort, das hier nicht erlaubt ist.');
redirect($back);
}
if (!security_throttle('comment')) {
set_flash('error', 'Du hast in den letzten Minuten schon viele Kommentare geschrieben. Bitte warte kurz.');
redirect($back);
}
[$status, $moderationNote] = moderation_initial_status('comment', $body);
$pdo->prepare('INSERT INTO gallery_comments (gallery_id, author_id, body, status, moderation_note) VALUES (?, ?, ?, ?, ?)')
->execute([$pictureId, (int) $me['id'], $body, $status, $moderationNote]);
if ($status === 'pending') {
set_flash('success', 'Kommentar gespeichert. Für alle sichtbar nach einer kurzen Freigabe durch die Moderation ('
. mb_strtolower((string) $moderationNote) . ').');
}
redirect('/member_picture.php?id=' . $pictureId . '#kommentar-' . (int) $pdo->lastInsertId());
}
if ($action === 'delete') {
$commentId = (int) ($_POST['comment_id'] ?? 0);
$stmt = $pdo->prepare(
'SELECT c.id, c.author_id, c.body, c.gallery_id, g.user_id AS owner_id
FROM gallery_comments c JOIN member_gallery g ON g.id = c.gallery_id WHERE c.id = ?'
);
$stmt->execute([$commentId]);
$comment = $stmt->fetch();
if (!$comment) {
set_flash('error', 'Diesen Kommentar gibt es nicht (mehr).');
redirect('/members.php');
}
$back = '/member_picture.php?id=' . (int) $comment['gallery_id'] . '#kommentare';
if (!gallery_comment_can_delete($comment, (int) $comment['owner_id'])) {
set_flash('error', 'Diesen Kommentar darfst du nicht löschen.');
redirect($back);
}
$pdo->prepare('DELETE FROM gallery_comments WHERE id = ?')->execute([$commentId]);
moderation_clear_reports('comment', $commentId);
reactions_delete('comment', [$commentId]);
// Loescht die Moderation einen fremden Kommentar auf einem fremden Bild -> ins Log
$isAuthor = (int) $comment['author_id'] === (int) $me['id'];
$isOwner = (int) $comment['owner_id'] === (int) $me['id'];
if (!$isAuthor && !$isOwner) {
admin_log('💬 Kommentar gelöscht (Moderation)', [
'Verfasser' => admin_log_user((int) $comment['author_id']),
'Unter Bild von' => admin_log_user((int) $comment['owner_id']),
'Text' => mb_strimwidth((string) $comment['body'], 0, 300, '…'),
], 'warning', 'members');
}
set_flash('success', 'Kommentar gelöscht.');
redirect($back);
}
set_flash('error', 'Unbekannte Aktion.');
redirect('/members.php');