LuminaWebsite/reaction_action.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

72 lines
2.8 KiB
PHP

<?php
/**
* Reaktion (Emoji) auf ein Galeriebild oder einen Kommentar setzen bzw. entfernen.
* Antwortet mit der neuen Reaktionsleiste als JSON (assets/js/reactions.js) oder leitet
* ohne JavaScript zurueck zur Bildseite.
*/
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();
$isAjax = !empty($_SERVER['HTTP_X_REQUESTED_WITH']);
$type = (string) ($_POST['type'] ?? '');
$id = (int) ($_POST['id'] ?? 0);
$emoji = (string) ($_POST['emoji'] ?? '');
$fail = static function (string $message) use ($isAjax): void {
if ($isAjax) {
http_response_code(400);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode(['ok' => false, 'error' => $message], JSON_UNESCAPED_UNICODE);
exit;
}
set_flash('error', $message);
redirect('/members.php');
};
if (!isset(REACTION_TYPES[$type]) || $id <= 0 || !in_array($emoji, REACTION_EMOJIS, true)) {
$fail('Diese Reaktion gibt es nicht.');
}
// Inhalt, Bild und Besitzer laden - reagieren darf nur, wer den Inhalt auch sehen kann.
$me = current_user();
if ($type === 'picture') {
$stmt = db()->prepare(
'SELECT g.id AS picture_id, g.user_id AS owner_id, g.status, g.user_id AS author_id, u.gallery_comments_enabled, u.status AS owner_status
FROM member_gallery g JOIN users u ON u.id = g.user_id WHERE g.id = ?'
);
} else {
$stmt = db()->prepare(
'SELECT g.id AS picture_id, g.user_id AS owner_id, c.status, c.author_id, u.gallery_comments_enabled, u.status AS owner_status
FROM gallery_comments c JOIN member_gallery g ON g.id = c.gallery_id JOIN users u ON u.id = g.user_id WHERE c.id = ?'
);
}
$stmt->execute([$id]);
$content = $stmt->fetch();
$canSee = $content && $content['owner_status'] === 'active'
&& ($content['status'] === 'visible' || (int) $content['author_id'] === (int) $me['id'] || moderation_can());
if (!$canSee) {
$fail('Diesen Inhalt gibt es nicht (mehr).');
}
if (empty($content['gallery_comments_enabled'])) {
$fail('Unter diesen Bildern sind Kommentare und Reaktionen abgeschaltet.');
}
if (!security_throttle('reaction')) {
$fail('Du reagierst gerade sehr schnell - bitte kurz warten.');
}
reaction_toggle($type, $id, $emoji);
if ($isAjax) {
header('Content-Type: application/json; charset=UTF-8');
$reactions = reactions_for($type, [$id])[$id] ?? [];
echo json_encode(['ok' => true, 'html' => reactions_bar_html($type, $id, $reactions, true, $type === 'comment')], JSON_UNESCAPED_UNICODE);
exit;
}
redirect('/member_picture.php?id=' . (int) $content['picture_id'] . ($type === 'comment' ? '#kommentar-' . $id : ''));