[Tabelle, Beschriftung, Spalte mit dem Verfasser, Spalte mit dem Text] const MODERATION_TYPES = [ 'picture' => ['member_gallery', 'Bild', 'user_id', 'caption'], 'comment' => ['gallery_comments', 'Kommentar', 'author_id', 'body'], 'calendar' => ['calendar_entries', 'Termin', 'user_id', 'title'], ]; /** Darf das angemeldete Konto moderieren? */ function moderation_can(): bool { return user_has_permission('comments.moderate'); } function moderation_all_manual(): bool { return setting_get('moderation_all') === '1'; } /** Ist das angemeldete Konto schon lange genug dabei, um ohne Freigabe zu posten? */ function moderation_user_trusted(): bool { $user = current_user(); if (!$user) { return false; } $stmt = db()->prepare('SELECT COALESCE(discord_joined_at, created_at) FROM users WHERE id = ?'); $stmt->execute([(int) $user['id']]); $since = strtotime((string) $stmt->fetchColumn()); return $since !== false && $since < time() - MODERATION_TRUST_DAYS * 86400; } /** Enthaelt der Text einen Link (auch ohne http, z.B. www.… oder discord.gg/…)? */ function moderation_has_link(string $text): bool { return (bool) preg_match('~https?://|www\.|discord\.gg/|\b[a-z0-9-]+\.(com|de|net|org|io|gg|ru|xyz|ly|me|tk|top|shop)\b~i', $text); } /** * Status fuer neuen Inhalt des angemeldeten Kontos. * * @return array{0: string, 1: ?string} [status, Grund] */ function moderation_initial_status(string $type, string $text = ''): array { if (moderation_can()) { return ['visible', null]; } $hits = moderation_word_hits($text); if (moderation_word_action($hits) === 'hold') { return ['pending', 'Schimpfwortfilter: ' . implode(', ', array_keys(array_filter($hits, static fn ($a) => $a === 'hold')))]; } if (moderation_all_manual()) { return ['pending', 'Alles wird gerade manuell freigegeben']; } if (!moderation_user_trusted()) { return ['pending', 'Neues Mitglied (erste ' . MODERATION_TRUST_DAYS . ' Tage)']; } // Links (auch in Bildunterschriften) - beliebter Weg fuer Spam und Phishing if ($text !== '' && moderation_has_link($text)) { return ['pending', 'Enthält einen Link']; } return ['visible', null]; } /** Wartende Inhalte (fuer die Zahl in der Seitenleiste). */ function moderation_pending_count(): int { $count = 0; foreach (MODERATION_TYPES as [$table]) { try { $count += (int) db()->query("SELECT COUNT(*) FROM $table WHERE status = 'pending'")->fetchColumn(); } catch (PDOException $e) { // Spalten/Tabellen noch nicht angelegt } } return $count; } /** * Inhalt melden. Ab MODERATION_REPORT_THRESHOLD Meldungen wird er ausgeblendet. * * @return string Meldung fuer den Nutzer */ function moderation_report(string $type, int $contentId, string $reason): string { $me = current_user(); [$table, $label, $owner] = MODERATION_TYPES[$type]; $stmt = db()->prepare("SELECT id, $owner AS owner_id, status FROM $table WHERE id = ?"); $stmt->execute([$contentId]); $content = $stmt->fetch(); if (!$content) { return 'Diesen Inhalt gibt es nicht (mehr).'; } if ((int) $content['owner_id'] === (int) $me['id']) { return 'Eigene Inhalte kannst du nicht melden - aber löschen.'; } try { db()->prepare('INSERT INTO content_reports (content_type, content_id, reporter_id, reason) VALUES (?, ?, ?, ?)') ->execute([$type, $contentId, (int) $me['id'], $reason !== '' ? $reason : null]); } catch (PDOException $e) { return 'Du hast diesen Inhalt schon gemeldet - danke, die Moderation schaut es sich an.'; } $count = db()->prepare('SELECT COUNT(*) FROM content_reports WHERE content_type = ? AND content_id = ?'); $count->execute([$type, $contentId]); $reports = (int) $count->fetchColumn(); $hidden = false; if ($content['status'] === 'visible' && $reports >= MODERATION_REPORT_THRESHOLD) { db()->prepare("UPDATE $table SET status = 'pending', moderation_note = ? WHERE id = ?") ->execute([$reports . ' Meldungen', $contentId]); $hidden = true; } admin_log($hidden ? '🚩 ' . $label . ' nach Meldungen ausgeblendet' : '🚩 ' . $label . ' gemeldet', [ 'Von' => admin_log_user((int) $content['owner_id']), 'Grund' => $reason, 'Meldungen' => (string) $reports, 'Prüfen' => 'Moderation → Freigabe-Liste', ], 'warning', 'members'); return $hidden ? 'Danke für die Meldung. Der Inhalt ist ausgeblendet, bis die Moderation entschieden hat.' : 'Danke für die Meldung - die Moderation schaut es sich an.'; } /** Meldungen zu einem Inhalt verwerfen (nach Freigabe oder Loeschen). */ function moderation_clear_reports(string $type, int $contentId): void { db()->prepare('DELETE FROM content_reports WHERE content_type = ? AND content_id = ?')->execute([$type, $contentId]); } /** * Welche der Inhalte hat das angemeldete Konto schon gemeldet? * * @param array $ids * @return array */ function moderation_my_reports(string $type, array $ids): array { $me = current_user(); if (!$me || empty($ids)) { return []; } $placeholders = implode(',', array_fill(0, count($ids), '?')); try { $stmt = db()->prepare("SELECT content_id FROM content_reports WHERE content_type = ? AND reporter_id = ? AND content_id IN ($placeholders)"); $stmt->execute(array_merge([$type, (int) $me['id']], array_map('intval', $ids))); return array_fill_keys(array_map('intval', $stmt->fetchAll(PDO::FETCH_COLUMN)), true); } catch (PDOException $e) { return []; } } // ---- Schimpfwortfilter ---- // Was ein Filterwort bewirkt: Schluessel => Beschriftung const MODERATION_WORD_ACTIONS = [ 'flag' => 'Nur markieren', 'hold' => 'Zur Freigabe zurückhalten', 'block' => 'Blockieren', ]; // Startliste beim ersten Aufruf - danach pflegt die Moderation die Liste selbst (moderation.php). const MODERATION_DEFAULT_WORDS = [ 'hurensohn' => 'hold', 'hure' => 'hold', 'wichser' => 'hold', 'fotze' => 'hold', 'missgeburt' => 'hold', 'spast*' => 'hold', 'schwuchtel' => 'hold', 'heil hitler' => 'hold', 'fick*' => 'hold', 'arschloch' => 'hold', 'bastard' => 'hold', 'kys' => 'hold', 'kill yourself' => 'hold', 'bring dich um' => 'hold', 'behindert' => 'flag', 'nazi*' => 'flag', 'nitro' => 'flag', 'free' => 'flag', 'gratis' => 'flag', 'gewinnspiel' => 'flag', 'giveaway' => 'flag', 'kaufen' => 'flag', 'verkaufe*' => 'flag', 'cheap' => 'flag', 'boost*' => 'flag', 'steam gift' => 'flag', 'airdrop' => 'flag', 'crypto' => 'flag', 'krypto*' => 'flag', 'passwort' => 'flag', 'password' => 'flag', 'verify' => 'flag', 'verifizier*' => 'flag', ]; /** * Die Filterwoerter (beim allerersten Aufruf mit der Startliste befuellt). * * @return array Wort => Aktion */ function moderation_words(bool $reload = false): array { static $words = null; if ($words !== null && !$reload) { return $words; } try { $words = db()->query('SELECT word, action FROM moderation_words ORDER BY word')->fetchAll(PDO::FETCH_KEY_PAIR); if (!$words && setting_get('moderation_words_seeded') !== '1') { $insert = db()->prepare('INSERT INTO moderation_words (word, action) VALUES (?, ?)'); foreach (MODERATION_DEFAULT_WORDS as $word => $action) { $insert->execute([$word, $action]); } setting_set('moderation_words_seeded', '1'); $words = MODERATION_DEFAULT_WORDS; ksort($words); } } catch (PDOException $e) { $words = []; } return $words; } /** Text fuer den Vergleich: klein, Leetspeak aufgeloest (f1ck, @rsch), Buchstaben-Wiederholungen gekuerzt. */ function moderation_normalize(string $text): string { $text = mb_strtolower($text); $text = strtr($text, ['0' => 'o', '1' => 'i', '3' => 'e', '4' => 'a', '5' => 's', '7' => 't', '@' => 'a', '$' => 's', '€' => 'e']); return (string) preg_replace('/(\p{L})\1{2,}/u', '$1', $text); // fiiiick -> fick } /** * Welche Filterwoerter kommen im Text vor? Ganze Woerter, mit * auch als Wortteil. * * @return array Wort => Aktion */ function moderation_word_hits(string $text): array { if (trim($text) === '') { return []; } $variants = array_unique([mb_strtolower($text), moderation_normalize($text)]); $hits = []; foreach (moderation_words() as $word => $action) { $core = preg_quote(trim((string) $word, '*'), '/'); $core = str_replace(' ', '\s+', $core); // Leerzeichen im Filterwort: beliebig viel Abstand $before = str_starts_with((string) $word, '*') ? '' : '(? hold > flag), null ohne Treffer. */ function moderation_word_action(array $hits): ?string { foreach (['block', 'hold', 'flag'] as $action) { if (in_array($action, $hits, true)) { return $action; } } return null; } /** Blockiert der Filter diesen Text? (Moderation ausgenommen) - dann gleich ins Log. */ function moderation_blocks(string $text, string $where): bool { $hits = moderation_word_hits($text); if (moderation_can() || moderation_word_action($hits) !== 'block') { return false; } admin_log('🚫 Beitrag vom Schimpfwortfilter blockiert', [ 'Wo' => $where, 'Wörter' => implode(', ', array_keys(array_filter($hits, static fn ($a) => $a === 'block'))), 'Text' => mb_strimwidth($text, 0, 300, '…'), ], 'warning', 'members'); return true; } /** * Markierungen fuer einen Kommentar: [Text, Stufe] mit Stufe "critical" oder "warning". * Erwartet: status, body, report_count, author_since (Discord-Beitritt bzw. Kontoerstellung). * * @return array */ function moderation_comment_flags(array $comment): array { $flags = []; $body = (string) $comment['body']; if (($comment['status'] ?? '') === 'pending') { $flags[] = ['Wartet auf Freigabe', 'critical']; } $reports = (int) ($comment['report_count'] ?? 0); if ($reports > 0) { $flags[] = [$reports === 1 ? '1 Meldung' : $reports . ' Meldungen', 'critical']; } $hits = moderation_word_hits($body); if ($hits) { $flags[] = ['Filterwort: ' . implode(', ', array_slice(array_keys($hits), 0, 3)), 'critical']; } if (moderation_has_link($body)) { $flags[] = ['Enthält Link', 'warning']; } $since = strtotime((string) ($comment['author_since'] ?? '')); if ($since !== false && $since > time() - MODERATION_TRUST_DAYS * 86400) { $flags[] = ['Neues Mitglied', 'warning']; } $letters = preg_replace('/[^\p{L}]/u', '', $body) ?? ''; if (mb_strlen($letters) >= 12 && mb_strtoupper($letters) === $letters) { $flags[] = ['Nur Großbuchstaben', 'warning']; } if (preg_match('/(.)\1{7,}/u', $body)) { $flags[] = ['Zeichen-Spam', 'warning']; } return $flags; }