- 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>
72 lines
2.8 KiB
PHP
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 = ? AND g.is_background = 0'
|
|
);
|
|
} 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 : ''));
|