LuminaWebsite/moderation_action.php
Maaxxs e4f23fcde4 Audit log, abuse protection, gallery comments with moderation, safe image uploads, 404 page
- Audit log: every admin_log entry is also stored permanently in the database (admin/audit.php, audit.view)
- Rate limits per account, login throttling per IP (not per account), emergency lock after mass deletions, force logout / lock in user management
- Comments under gallery pictures (picture page, report button, owner can disable them)
- Moderation: new members, links, reported content and a "moderate everything" switch go to the approval list (moderation.php)
- Every uploaded image is re-encoded (strips appended code and EXIF data)
- Custom 404 page, also shown for pages without permission

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

104 lines
3.9 KiB
PHP

<?php
/**
* Moderation von Galeriebildern und Kommentaren:
* - report: jedes Mitglied meldet einen Inhalt (ab 2 Meldungen automatisch ausgeblendet)
* - approve: freigeben (sichtbar fuer alle, Meldungen verworfen)
* - hide: ausblenden (zurueck in die Freigabe-Liste)
* - dismiss: Meldungen verwerfen, Inhalt bleibt sichtbar
* - delete: endgueltig loeschen
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_permission('members.view');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/members.php');
}
verify_csrf();
$action = (string) ($_POST['action'] ?? '');
$type = (string) ($_POST['type'] ?? '');
$id = (int) ($_POST['id'] ?? 0);
if (!isset(MODERATION_TYPES[$type]) || $id <= 0) {
set_flash('error', 'Unbekannter Inhalt.');
redirect('/members.php');
}
[$table, $label] = MODERATION_TYPES[$type];
$pdo = db();
// Wohin danach: zur Bildseite (von dort aus gemeldet/freigegeben) oder zur Freigabe-Liste
$pictureId = $id;
if ($type === 'comment') {
$stmt = $pdo->prepare('SELECT gallery_id FROM gallery_comments WHERE id = ?');
$stmt->execute([$id]);
$pictureId = (int) $stmt->fetchColumn();
}
$back = ($action === 'report' || ($_POST['back'] ?? '') === 'picture')
? '/member_picture.php?id=' . $pictureId . ($type === 'comment' ? '#kommentare' : '')
: '/moderation.php';
if ($action === 'report') {
if (!security_throttle('report')) {
set_flash('error', 'Du hast in den letzten Minuten schon viel gemeldet. Bitte warte kurz.');
redirect($back);
}
$reason = mb_substr(trim((string) ($_POST['reason'] ?? '')), 0, 255);
set_flash('success', moderation_report($type, $id, $reason));
redirect($back);
}
// Ab hier nur die Moderation
if (!moderation_can()) {
show_not_found();
}
$owner = $type === 'picture' ? 'user_id' : 'author_id';
$stmt = $pdo->prepare("SELECT * , $owner AS owner_id FROM $table WHERE id = ?");
$stmt->execute([$id]);
$content = $stmt->fetch();
if (!$content) {
set_flash('error', 'Diesen Inhalt gibt es nicht (mehr).');
redirect('/moderation.php');
}
$logFields = [
'Von' => admin_log_user((int) $content['owner_id']),
$type === 'picture' ? 'Bildunterschrift' : 'Text' => mb_strimwidth((string) ($type === 'picture' ? ($content['caption'] ?? '') : $content['body']), 0, 300, '…'),
'Grund der Prüfung' => (string) ($content['moderation_note'] ?? ''),
];
switch ($action) {
case 'approve':
$pdo->prepare("UPDATE $table SET status = 'visible', moderation_note = NULL WHERE id = ?")->execute([$id]);
moderation_clear_reports($type, $id);
admin_log('✅ ' . $label . ' freigegeben', $logFields, 'success', 'members');
set_flash('success', $label . ' freigegeben - jetzt für alle sichtbar.');
break;
case 'hide':
$pdo->prepare("UPDATE $table SET status = 'pending', moderation_note = ? WHERE id = ?")
->execute(['Von der Moderation ausgeblendet', $id]);
admin_log('🙈 ' . $label . ' ausgeblendet', $logFields, 'warning', 'members');
set_flash('success', $label . ' ausgeblendet.');
break;
case 'dismiss':
moderation_clear_reports($type, $id);
admin_log('👌 Meldungen verworfen (' . $label . ' bleibt)', $logFields, 'info', 'members');
set_flash('success', 'Meldungen verworfen.');
break;
case 'delete':
$pdo->prepare("DELETE FROM $table WHERE id = ?")->execute([$id]);
moderation_clear_reports($type, $id);
if ($type === 'picture') {
profile_delete_file((string) $content['filename']); // Kommentare fallen per ON DELETE CASCADE weg
}
admin_log('🗑️ ' . $label . ' gelöscht (Moderation)', $logFields, 'warning', 'members');
set_flash('success', $label . ' gelöscht.');
$back = '/moderation.php';
break;
default:
set_flash('error', 'Unbekannte Aktion.');
}
redirect($back);