diff --git a/README.md b/README.md index c69740c..74a0467 100644 --- a/README.md +++ b/README.md @@ -682,11 +682,14 @@ Unter **Wiki** im Menü liegt der Einsteiger-Guide der Legion: Kapitel mit Unter automatisch nummeriert (3. / 3.1.), mit Suche, „WIP“-Markierung, Verlauf aller Änderungen und Wiederherstellen alter Versionen. Geschrieben wird in einem einfachen Textformat mit Knöpfen (fett, Überschrift, Liste, Tabelle, Link, `[[Wiki-Link]]`, Bild-Upload) und -Live-Vorschau (`includes/wiki.php`, `wiki_render()`); eingegebenes HTML ist nie aktiv. +Live-Vorschau (`includes/wiki.php`, `wiki_render()`); eingegebenes HTML ist nie aktiv. **Videos:** +Ein Link zu YouTube (auch Shorts und Startzeit), Twitch (Clip oder Video), Vimeo oder einer +Videodatei (.mp4/.webm) allein in einer Zeile wird zum eingebetteten Player - im Editor über +den Knopf „▶ Video“ (`wiki_video_embed()`; YouTube über youtube-nocookie.com). - **Lesen:** `wiki.view` - bekommen beim Update alle Gruppen, die ins Dashboard dürfen. - **Schreiben:** `wiki.edit` für ganze Gruppen, oder einzelne Mitglieder, die die Leitung im - Wiki unter „Mitwirkende“ hinzufügt (Tabelle `wiki_contributors`). + Wiki unter „Mitwirkende“ hinzufügt (Tabelle `wiki_contributors`, Suchliste mit Avatar und Gruppe). - **Verwalten:** `wiki.manage` - Seiten löschen und verschieben, Mitwirkende verwalten, alte Versionen wiederherstellen. @@ -770,6 +773,22 @@ die Moderation. Es gelten dieselben Regeln wie bei Kommentaren: Schimpfwortfilte Links bzw. von neuen Mitgliedern erst nach Freigabe (Moderation → Freigabe), Melden-Knopf, höchstens 8 neue Termine pro Stunde (`calendar_action.php`). +## Aktivitätscheck + +**Aktivitätscheck** im Menü (`activity.php`, Berechtigung `activity.manage`) bzw. `/aktivitaetscheck` +im Discord: Der Bot postet im gewählten Kanal eine Nachricht mit den Knöpfen „Ich bin da“ und +„Ich bin nicht da“ (Knopftexte, Titel, Text, Farbe und Bild frei wählbar, mit Live-Vorschau). +Antworten kann, wer die Zielrolle hat; die Antwort lässt sich bis zum Ende ändern. Nach der +eingestellten Zeit - oder vorher über „Jetzt abschließen“ (Website) bzw. +`/aktivitaetscheck_beenden` - bekommen alle ohne Rückmeldung die gewählten Folgen: PN (Text mit +{name}/{titel}/{server}), Rolle entfernen, Rolle geben; auf Wunsch auch alle mit „nicht da“. +Die Liste landet immer im Log-Kanal. „Abbrechen“ beendet ohne Folgen. Die Website zeigt je +Check, wer da / nicht da / noch offen ist. + +Im Bot: `cogs/activity.py` (Tabellen `activity_checks`, `activity_responses`, Knöpfe über +DynamicItem auch nach Neustarts), API `/api/activity-checks` in `api.py`. Der Bot kann Rollen nur +unterhalb seiner eigenen Rolle ändern. + ## Moderation (Galeriebilder und Kommentare) `includes/moderation.php`, Seite **Admin → Moderation** (`moderation.php`, Berechtigung diff --git a/activity.php b/activity.php new file mode 100644 index 0000000..0062639 --- /dev/null +++ b/activity.php @@ -0,0 +1,319 @@ + 0) { + $detail = activity_api_request('GET', '/' . $detailId)['check'] ?? null; + } else { + $checks = activity_api_request('GET', '', ['guild_id' => events_guild_id()])['checks'] ?? []; + } +} catch (Throwable $e) { + $apiError = $e->getMessage(); +} +if ($detailId > 0 && !$detail && !$apiError) { + show_not_found(); +} + +// Kanaele und Rollen fuer das Formular +$channels = []; +$roles = []; +$pickerError = null; +if ($detailId === 0) { + try { + $channels = guilds_api_request('/channels')['channels'] ?? []; + $roles = guilds_api_request('/roles')['roles'] ?? []; + } catch (Throwable $e) { + $pickerError = $e->getMessage(); + } +} + +/** Discord-IDs -> Website-Konten (Name + Profilbild), fuer die Listen in der Detailansicht. */ +$usersByDiscord = []; +if ($detail) { + $ids = array_merge(array_column($detail['responses'] ?? [], 'user_id'), array_column($detail['pending'] ?? [], 'user_id'), + array_column($detail['result']['missing'] ?? [], 'user_id')); + $ids = array_values(array_unique(array_map('strval', $ids))); + if ($ids) { + $stmt = db()->prepare('SELECT id, username, display_name, avatar_filename, discord_id FROM users WHERE discord_id IN (' + . implode(',', array_fill(0, count($ids), '?')) . ')'); + $stmt->execute($ids); + foreach ($stmt->fetchAll() as $row) { + $usersByDiscord[(string) $row['discord_id']] = $row; + } + } +} +$person = static function (string $discordId, string $fallbackName) use ($usersByDiscord): string { + $user = $usersByDiscord[$discordId] ?? null; + $name = $user ? ($user['display_name'] !== '' ? $user['display_name'] : $user['username']) : $fallbackName; + $avatar = avatar_html($user ?: ['id' => $discordId, 'display_name' => $fallbackName], 28); + return '
  • ' . $avatar . ($user ? '' . e($name) . '' : '' . e($name) . '') . '
  • '; +}; + +/** "noch 2 Tage 4 Std." bzw. "vor 3 Std." */ +$relative = static function (int $timestamp): string { + $diff = $timestamp - time(); + $abs = abs($diff); + $text = $abs >= 86400 ? floor($abs / 86400) . ' Tg. ' . floor(($abs % 86400) / 3600) . ' Std.' + : ($abs >= 3600 ? floor($abs / 3600) . ' Std. ' . floor(($abs % 3600) / 60) . ' Min.' : max(1, (int) floor($abs / 60)) . ' Min.'); + return $diff >= 0 ? 'noch ' . $text : 'vor ' . $text; +}; + +$roleOptions = static function (string $selected = '', bool $withNone = false) use ($roles): string { + $html = $withNone ? '' : ''; + foreach ($roles as $role) { + $rid = (string) ($role['role_id'] ?? ''); + $html .= ''; + } + return $html; +}; + +$openChecks = array_values(array_filter($checks, static fn ($c) => ($c['status'] ?? '') === 'open')); +$pastChecks = array_values(array_filter($checks, static fn ($c) => ($c['status'] ?? '') !== 'open')); + +$pageTitle = $detail ? 'Aktivitätscheck: ' . $detail['title'] : 'Aktivitätschecks'; +$containerWide = true; +include __DIR__ . '/includes/header.php'; +?> + +
    Der Discord-Bot ist gerade nicht erreichbar:
    + + + + $r['status'] === 'present')); + $absent = array_values(array_filter($detail['responses'] ?? [], static fn ($r) => $r['status'] === 'absent')); + $missing = $isOpen ? ($detail['pending'] ?? []) : ($detail['result']['missing'] ?? []); + ?> +
    + ‹ Alle Aktivitätschecks +
    +

    📋

    + +
    +

    + # · für @ · + + · Im Discord ansehen +

    + +
    +
    + + +
    +
    + + +
    +
    + +
    + Folgen ohne Rückmeldung: + + keine - nur Liste im Log-Kanal' ?> + +
    Ergebnis: PN verschickt, + Rollen geändert + +
    +
    + +
    +
    +

    ✅ Da

    + +

    Noch niemand.

    +
    +
    +

    ❌ Nicht da

    + +

    Niemand.

    +
    +
    +

    ⏳

    + +

    +
    +
    + + +
    +
    + + +
    +
    + + + +
    +
    +

    📋 Aktivitätschecks

    + + + +
    +

    + Der Bot postet eine Nachricht mit den Knöpfen „Ich bin da“ und „Ich bin nicht da“. Wer die Zielrolle hat, meldet sich + dort zurück. Zur Frist - oder vorher über „Jetzt abschließen“ - bekommen alle ohne Rückmeldung die eingestellten Folgen. + Im Discord geht das auch mit /aktivitaetscheck. +

    + +
    Kanäle/Rollen konnten nicht geladen werden:
    + +
    + + + + + +
    +

    Laufende Checks

    +

    Gerade läuft kein Aktivitätscheck.

    +
    + + + + 📋 + # · @ · +
    + + +
    + ✅ · ❌ · ⏳ offen +
    + +
    +
    + + +
    +

    Beendet

    + +
    + + + + diff --git a/activity_action.php b/activity_action.php new file mode 100644 index 0000000..46a1d28 --- /dev/null +++ b/activity_action.php @@ -0,0 +1,111 @@ + events_guild_id(), + 'channel_id' => $channelId, + 'target_role_id' => $roleId, + 'title' => mb_substr($title, 0, 100), + 'message' => mb_substr($message, 0, 3500), + 'color' => preg_match('/^#[0-9a-f]{6}$/i', $color) ? hexdec(substr($color, 1)) : 0xC9A227, + 'image_url' => $image !== '' ? $image : null, + 'ping_role' => !empty($_POST['ping_role']), + 'yes_label' => mb_substr(trim((string) ($_POST['yes_label'] ?? '')), 0, 60) ?: null, + 'no_label' => mb_substr(trim((string) ($_POST['no_label'] ?? '')), 0, 60) ?: null, + 'duration_minutes' => $minutes, + 'dm_enabled' => $dmEnabled, + 'dm_message' => $dmEnabled ? mb_substr(trim((string) ($_POST['dm_message'] ?? '')), 0, 1800) : null, + 'remove_role_id' => $idField('remove_role_id'), + 'add_role_id' => $idField('add_role_id'), + 'apply_to_absent' => !empty($_POST['apply_to_absent']), + 'created_by' => (int) ($me['discord_id'] ?? 0), + ]; + $result = activity_api_request('POST', '', [], $body); + $consequences = array_filter([ + $dmEnabled ? 'PN' : null, + $body['remove_role_id'] ? 'Rolle entfernen' : null, + $body['add_role_id'] ? 'Rolle geben' : null, + ]); + admin_log('📋 Aktivitätscheck gestartet', [ + 'Titel' => $body['title'], + 'Dauer' => $minutes >= 1440 ? ($minutes / 1440) . ' Tage' : ($minutes / 60) . ' Stunden', + 'Folgen' => $consequences ? implode(', ', $consequences) : 'keine', + ], 'info', 'events'); + set_flash('success', 'Aktivitätscheck gepostet - die Leute können sich jetzt im Discord zurückmelden.'); + redirect('/activity.php?id=' . (int) ($result['check_id'] ?? 0)); + + case 'close': + case 'cancel': + $result = activity_api_request('POST', '/' . $id . '/close', [], [ + 'cancel' => $action === 'cancel', + 'closed_by' => $myName . ' (Website)', + ])['result'] ?? []; + admin_log($action === 'cancel' ? '🚫 Aktivitätscheck abgebrochen' : '📋 Aktivitätscheck abgeschlossen', [ + 'Check' => '#' . $id, + 'Ohne Rückmeldung' => $action === 'cancel' ? '' : (string) count($result['missing'] ?? []), + ], $action === 'cancel' ? 'warning' : 'success', 'events'); + set_flash('success', $action === 'cancel' + ? 'Aktivitätscheck abgebrochen - ohne Folgen.' + : 'Aktivitätscheck abgeschlossen. Ohne Rückmeldung: ' . count($result['missing'] ?? []) . '.'); + redirect('/activity.php?id=' . $id); + + case 'delete': + activity_api_request('DELETE', '/' . $id); + admin_log('🗑️ Aktivitätscheck gelöscht', ['Check' => '#' . $id], 'warning', 'events'); + set_flash('success', 'Aktivitätscheck gelöscht.'); + redirect('/activity.php'); + } +} catch (InvalidArgumentException $e) { + set_flash('error', $e->getMessage()); + redirect('/activity.php'); +} catch (Throwable $e) { + set_flash('error', 'Der Discord-Bot hat nicht mitgespielt: ' . $e->getMessage()); + redirect($id > 0 ? '/activity.php?id=' . $id : '/activity.php'); +} + +redirect('/activity.php'); diff --git a/assets/css/style.css b/assets/css/style.css index c514e45..eae74df 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -530,6 +530,7 @@ input[type="email"], input[type="password"], input[type="number"], input[type="search"], +input[type="url"], input[type="datetime-local"], textarea, select { @@ -5519,3 +5520,93 @@ a.calendar-agenda-entry:hover { text-decoration: none; filter: brightness(1.2); /* Kommentarfeld: Avatar neben dem Feld (Formulare sind sonst global untereinander) */ .comment-form { flex-direction: row; } .comment-form textarea { font-family: inherit; font-size: 0.95rem; } + +/* ---- Wiki: eingebettete Videos ---- */ +.wiki-video { + position: relative; + width: 100%; + max-width: 860px; + aspect-ratio: 16 / 9; + margin: 1rem 0; + border-radius: 12px; + overflow: hidden; + background: #000; + border: 1px solid var(--border); + box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); +} +.wiki-video iframe, .wiki-video video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; } +.wiki-video-portrait { max-width: 340px; aspect-ratio: 9 / 16; } +.wiki-video-file video { object-fit: contain; background: #000; } + +/* Wiki: Mitwirkende hinzufuegen mit Suchliste (Avatare rund) */ +.wiki-contributor-add { align-items: center; } +.wiki-contributor-add .item-picker { flex: 1 1 240px; min-width: 0; } +.item-picker-round .item-picker-thumb { border-radius: 50%; object-fit: cover; } +.item-picker[data-picker-round] .item-picker-preview { border-radius: 50% !important; object-fit: cover; } + +/* ---- Aktivitaetschecks ---- */ +.activity-form-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 1.5rem; align-items: start; } +@media (max-width: 1000px) { .activity-form-grid { grid-template-columns: 1fr; } } +.activity-form-fields { display: flex; flex-direction: column; gap: 1rem; } +.activity-form fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: 0.7rem; } +.activity-form legend { padding: 0 0.4rem; color: var(--gold); font-weight: 700; } +.activity-form label { display: flex; flex-direction: column; gap: 0.3rem; } +.activity-form label.checkbox-label { flex-direction: row; align-items: center; gap: 0.5rem; } +.activity-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; } +.activity-color-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; } +.activity-color-row > span { margin-right: 0.3rem; } +.activity-swatch { position: relative; flex-direction: row !important; width: 28px; height: 28px; border-radius: 50%; background: var(--swatch); cursor: pointer; border: 2px solid transparent; } +.activity-swatch input { position: absolute; opacity: 0; } +.activity-swatch:has(input:checked) { border-color: #fff; box-shadow: 0 0 0 2px var(--swatch); } +.activity-color-row input[type="color"] { width: 36px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; } + +.activity-preview-wrap { position: sticky; top: 1rem; } +.discord-preview { margin-top: 0.4rem; padding: 1rem; border-radius: 10px; background: #313338; color: #dbdee1; font-size: 0.92rem; } +.discord-ping { display: inline-block; margin-bottom: 0.4rem; padding: 0 0.2rem; border-radius: 3px; background: rgba(88, 101, 242, 0.3); color: #c9cdfb; font-weight: 600; } +.discord-ping[hidden] { display: none; } +.discord-embed { border-left: 4px solid #c9a227; border-radius: 4px; background: #2b2d31; padding: 0.7rem 0.9rem; display: flex; flex-direction: column; gap: 0.5rem; max-width: 520px; } +.discord-embed-title { color: #fff; font-size: 1rem; } +.discord-embed-text { line-height: 1.45; overflow-wrap: anywhere; } +.discord-embed-field { display: flex; flex-direction: column; font-size: 0.85rem; } +.discord-embed-field b { color: #fff; } +.discord-embed-image { max-width: 100%; border-radius: 4px; } +.discord-embed-image[hidden] { display: none; } +.discord-embed-footer { font-size: 0.75rem; color: #949ba4; } +.discord-buttons { display: flex; gap: 0.5rem; margin-top: 0.6rem; } +.discord-button { padding: 0.35rem 0.9rem; border-radius: 4px; background: #4e5058; color: #fff; font-weight: 600; font-size: 0.85rem; } +.discord-button-green { background: #248046; } + +.activity-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0.8rem; } +.activity-card { + display: flex; + flex-direction: column; + gap: 0.4rem; + padding: 0.9rem 1rem; + border-radius: 12px; + border: 1px solid var(--border); + border-left: 4px solid var(--accent, var(--gold)); + background: rgba(255, 255, 255, 0.03); + color: var(--text); +} +.activity-card:hover { text-decoration: none; background: rgba(255, 255, 255, 0.06); } +.activity-card .text-muted { font-size: 0.82rem; } +.activity-bar { display: flex; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; } +.activity-bar i { display: block; height: 100%; } +.bar-present { background: #3ba55d; } +.bar-absent { background: #ed4245; } +.activity-counts { font-size: 0.82rem; color: var(--text-muted); } +.activity-past { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; } +.activity-past li { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; align-items: baseline; } + +.activity-detail-head .raid-header { margin-top: 0.4rem; } +.activity-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0; } +.activity-consequences { margin-top: 0.4rem; font-size: 0.9rem; } +.activity-columns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; } +@media (max-width: 900px) { .activity-columns { grid-template-columns: 1fr; } } +.activity-column h2 { display: flex; align-items: center; gap: 0.5rem; font-size: 1.1rem; } +.activity-column ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; } +.activity-person { display: flex; align-items: center; gap: 0.5rem; } +.activity-present { border-top: 3px solid #3ba55d; } +.activity-absent { border-top: 3px solid #ed4245; } +.activity-missing { border-top: 3px solid #f0b232; } +.activity-form textarea { font-family: inherit; resize: vertical; } diff --git a/assets/js/activity.js b/assets/js/activity.js new file mode 100644 index 0000000..aa1c1c6 --- /dev/null +++ b/assets/js/activity.js @@ -0,0 +1,93 @@ +/** + * Aktivitaetscheck anlegen: Formular ein-/ausblenden und Live-Vorschau, wie die Nachricht im + * Discord aussehen wird (Farbe, Titel, Text, Bild, Knoepfe, Frist). + */ +(function () { + 'use strict'; + + var panel = document.getElementById('activity-create'); + var form = document.getElementById('activity-form'); + if (!panel || !form) return; + + document.querySelectorAll('[data-toggle-activity-form]').forEach(function (button) { + button.addEventListener('click', function () { + panel.hidden = !panel.hidden; + if (!panel.hidden) { + panel.scrollIntoView({ behavior: 'smooth', block: 'start' }); + f.title.focus(); + } + }); + }); + + var f = form.elements; // form.title waere das title-Attribut des Formulars, nicht das Feld + var dmToggle = form.querySelector('[data-toggle-dm]'); + var dmField = form.querySelector('.activity-dm'); + dmToggle.addEventListener('change', function () { dmField.hidden = !dmToggle.checked; }); + + function out(name) { return form.querySelector('[data-out="' + name + '"]'); } + + // Discord-Formatierung grob nachbilden: **fett**, *kursiv*, Zeilenumbrueche (Text sicher als Text) + function discordText(text) { + var div = document.createElement('div'); + div.textContent = text; + return div.innerHTML + .replace(/\*\*(.+?)\*\*/g, '$1') + .replace(/(^|[^*])\*([^*\n]+)\*/g, '$1$2') + .replace(/\n/g, '
    '); + } + + function color() { + var custom = f.color_custom.value; + var picked = form.querySelector('input[name="color"]:checked'); + return custom && custom.toLowerCase() !== '#c9a227' ? custom : (picked ? picked.value : '#c9a227'); + } + + function update() { + out('title').textContent = f.title.value || 'Aktivitätscheck'; + out('message').innerHTML = discordText(f.message.value); + out('embed').style.borderLeftColor = color(); + + var role = f.target_role_id.options[f.target_role_id.selectedIndex]; + out('role').textContent = role && role.value ? role.textContent.replace(/^@/, '') : 'Rolle'; + out('ping').hidden = !f.ping_role.checked; + + out('yes').textContent = f.yes_label.value.trim() || 'Ich bin da'; + out('no').textContent = f.no_label.value.trim() || 'Ich bin nicht da'; + + var value = Math.max(1, parseInt(f.duration_value.value, 10) || 1); + var ms = value * (f.duration_unit.value === 'hours' ? 3600e3 : 86400e3); + var end = new Date(Date.now() + ms); + out('deadline').textContent = end.toLocaleString('de-DE', { weekday: 'long', day: '2-digit', month: 'long', hour: '2-digit', minute: '2-digit' }) + + ' (in ' + value + (f.duration_unit.value === 'hours' ? (value === 1 ? ' Stunde' : ' Stunden') : (value === 1 ? ' Tag' : ' Tagen')) + ')'; + + var image = f.image_url.value.trim(); + var img = out('image'); + if (/^https:\/\/\S+$/.test(image)) { + img.src = image; + img.hidden = false; + } else { + img.hidden = true; + } + } + + form.addEventListener('input', update); + form.addEventListener('change', update); + // Eigene Farbe gewaehlt -> Auswahlkreise abwaehlen, Kreis gewaehlt -> eigene Farbe zuruecksetzen + f.color_custom.addEventListener('input', function () { + form.querySelectorAll('input[name="color"]').forEach(function (r) { r.checked = false; }); + }); + form.querySelectorAll('input[name="color"]').forEach(function (radio) { + radio.addEventListener('change', function () { f.color_custom.value = '#c9a227'; }); + }); + + form.addEventListener('submit', function (event) { + var consequences = []; + if (dmToggle.checked) consequences.push('PN'); + if (f.remove_role_id.value) consequences.push('Rolle entfernen'); + if (f.add_role_id.value) consequences.push('Rolle geben'); + var text = 'Check jetzt im Discord posten?\n\nFolgen ohne Rückmeldung: ' + (consequences.length ? consequences.join(', ') : 'keine (nur Liste im Log-Kanal)'); + if (!window.confirm(text)) event.preventDefault(); + }); + + update(); +})(); diff --git a/assets/js/item-picker.js b/assets/js/item-picker.js index e3ac0a2..be37afa 100644 --- a/assets/js/item-picker.js +++ b/assets/js/item-picker.js @@ -6,7 +6,8 @@ * name - der Text selbst wird gesendet (freie Eingabe erlaubt, z.B. neue Gegenstaende) * id - ein verstecktes Feld bekommt die ID; nur Eintraege aus der Liste sind gueltig * submit - wie name, schickt nach der Auswahl das Formular ab (Suche im Verlauf) - * Optional data-picker-empty: Text, wenn nichts passt. + * Optional data-picker-empty: Text, wenn nichts passt; data-picker-invalid: Meldung ohne Auswahl; + * data-picker-round: runde Bilder (Avatare). * Von aussen: element.itemPicker.set(idOderName) und element.itemPicker.refresh(). */ (function () { @@ -67,11 +68,14 @@ var iconSlot = root.querySelector('.item-picker-icon'); var searchIcon = iconSlot ? iconSlot.innerHTML : ''; var emptyText = root.dataset.pickerEmpty || 'Kein Gegenstand gefunden.'; + var invalidText = root.dataset.pickerInvalid || 'Bitte einen Gegenstand aus der Liste wählen.'; var list = document.createElement('ul'); list.className = 'item-picker-list'; list.id = (input.id || 'item-picker-' + Math.random().toString(36).slice(2)) + '-list'; list.setAttribute('role', 'listbox'); + // Personen (Avatare) rund statt eckiger Gegenstandsbilder + if (root.hasAttribute('data-picker-round')) list.classList.add('item-picker-round'); list.hidden = true; document.body.appendChild(list); @@ -113,7 +117,7 @@ hidden.dataset.max = item && item.qty != null ? item.qty : ''; hidden.dispatchEvent(new Event('change')); } - input.setCustomValidity(id || !input.required ? '' : 'Bitte einen Gegenstand aus der Liste wählen.'); + input.setCustomValidity(id || !input.required ? '' : invalidText); } } diff --git a/assets/js/wiki-editor.js b/assets/js/wiki-editor.js index a53deaa..a3dc074 100644 --- a/assets/js/wiki-editor.js +++ b/assets/js/wiki-editor.js @@ -68,6 +68,14 @@ if (title) replaceSelection('', '', '[[' + title.trim() + ']]'); } else if (btn.dataset.insert === 'image') { imageInput.click(); + } else if (btn.dataset.insert === 'video') { + var video = window.prompt('Link zum Video - YouTube, Twitch (Clip oder Video), Vimeo oder eine Videodatei (.mp4/.webm):', 'https://'); + if (video && /^https?:\/\/\S+$/.test(video.trim())) { + // Allein in einer Zeile wird der Link zum eingebetteten Player + insertBlock(video.trim()); + } else if (video && video.trim() !== 'https://') { + window.alert('Das sieht nicht nach einem Link aus. Bitte die komplette Adresse einfügen (https://…).'); + } } }); diff --git a/includes/activity_api.php b/includes/activity_api.php new file mode 100644 index 0000000..9eaedc2 --- /dev/null +++ b/includes/activity_api.php @@ -0,0 +1,36 @@ + $queryParams + * @param array|null $jsonBody + * @return array + * @throws RuntimeException + */ +function activity_api_request(string $method, string $path = '', array $queryParams = [], ?array $jsonBody = null): array +{ + $base = preg_replace('#/raids$#', '', raids_api_config()['url']); + + return bot_api_request($method, $base . '/activity-checks' . $path, $queryParams, $jsonBody, 'Aktivitätscheck-API'); +} + +/** Farben zur schnellen Auswahl (Discord-Embed-Farbe links am Rand). */ +const ACTIVITY_COLORS = [ + '#c9a227' => 'Gold', + '#5865f2' => 'Blurple', + '#3ba55d' => 'Grün', + '#ed4245' => 'Rot', + '#f0b232' => 'Orange', + '#9b59b6' => 'Lila', + '#1abc9c' => 'Türkis', +]; + +const ACTIVITY_DEFAULT_DM = 'Hallo {name}! Du hast dich beim Aktivitätscheck **{titel}** auf **{server}** nicht zurückgemeldet. ' + . 'Melde dich bitte bei der Gildenleitung, wenn du weiterhin dabei sein möchtest.'; diff --git a/includes/header.php b/includes/header.php index b3ad488..a2762e5 100644 --- a/includes/header.php +++ b/includes/header.php @@ -14,6 +14,7 @@ $canManageRoles = $currentUser && user_has_permission('roles.manage'); $canViewRaids = $currentUser && user_has_permission('raids.view'); $canViewPremades = $currentUser && user_has_permission('premades.view'); $canViewEvents = $currentUser && user_has_permission('events.view'); +$canManageActivity = $currentUser && user_has_permission('activity.manage'); $canViewMap = $currentUser && user_has_permission('map.view'); $canViewWarehouse = $currentUser && user_has_permission('warehouse.view'); $canViewContributions = $currentUser && user_has_permission('contributions.view'); @@ -64,6 +65,7 @@ $isRaidsActive = $currentScript === 'raids.php'; $isPremadesActive = $currentScript === 'premades.php'; $isEventsActive = $currentScript === 'events.php'; $isCalendarActive = $currentScript === 'calendar.php'; +$isActivityActive = $currentScript === 'activity.php'; $isMapActive = $currentScript === 'map.php'; $isWarehouseActive = $currentScript === 'warehouse.php'; $isContributionsActive = in_array($currentScript, ['contributions.php', 'contributions_award.php'], true); @@ -85,6 +87,7 @@ $pageBackgrounds = [ 'premades.php' => 'bg-premades', 'events.php' => 'bg-events', 'calendar.php' => 'bg-events', + 'activity.php' => 'bg-events', 'map.php' => 'bg-map', 'warehouse.php' => 'bg-warehouse', 'contributions.php' => 'bg-contributions', @@ -224,6 +227,11 @@ $otherFlashes = array_values(array_filter($allFlashes, fn (array $f): bool => ($ Events + + + Aktivitätscheck + + Karte diff --git a/includes/permissions.php b/includes/permissions.php index 8a48c38..3b38b9a 100644 --- a/includes/permissions.php +++ b/includes/permissions.php @@ -20,6 +20,7 @@ const CORE_PERMISSIONS = [ ['key' => 'premades.manage', 'description' => 'Alle Premade-Gruppen verwalten (nicht nur die eigene)'], ['key' => 'events.view', 'description' => 'Geplante Event-Erinnerungen einsehen'], ['key' => 'events.manage', 'description' => 'Event-Erinnerungen planen, bearbeiten und löschen'], + ['key' => 'activity.manage', 'description' => 'Aktivitätschecks im Discord starten, ansehen und beenden (inkl. Folgen wie PN und Rollenänderung)'], ['key' => 'map.view', 'description' => 'Interaktive Karte und Taktiken ansehen'], ['key' => 'map.tactics', 'description' => 'Taktiken auf der Karte anlegen, zeichnen und bearbeiten'], ['key' => 'warehouse.view', 'description' => 'Lagerhaus: Bestand und Verlauf einsehen'], diff --git a/includes/wiki.php b/includes/wiki.php index 660b3da..f9927a6 100644 --- a/includes/wiki.php +++ b/includes/wiki.php @@ -190,6 +190,76 @@ function wiki_safe_url(string $url, bool $image = false): ?string return null; } +/** + * Video zum Einbetten, wenn die Zeile nur aus einem Video-Link besteht: YouTube (auch Shorts, + * youtu.be, Startzeit ?t=), Twitch (Clips und Videos), Vimeo oder eine Videodatei (.mp4/.webm). + * Eingebettet wird nur ueber feste Player-Adressen - die ID wird streng geprueft, der Rest der + * Adresse nie uebernommen. + */ +function wiki_video_embed(string $line): ?string +{ + $url = trim($line); + if (!preg_match('#^https?://\S+$#i', $url)) { + return null; + } + $parts = parse_url($url); + $host = strtolower(preg_replace('/^(www\.|m\.)/', '', (string) ($parts['host'] ?? '')) ?? ''); + $path = (string) ($parts['path'] ?? ''); + parse_str((string) ($parts['query'] ?? ''), $query); + $title = 'Video'; + $frame = static fn (string $src, string $class = '') => '
    '; + + // YouTube: watch?v=ID, youtu.be/ID, shorts/ID, embed/ID, live/ID + $youtubeId = null; + $isShort = false; + if ($host === 'youtube.com' || $host === 'youtube-nocookie.com') { + if ($path === '/watch' && isset($query['v'])) { + $youtubeId = (string) $query['v']; + } elseif (preg_match('#^/(shorts|embed|live)/([\w-]{11})#', $path, $m)) { + $youtubeId = $m[2]; + $isShort = $m[1] === 'shorts'; + } + } elseif ($host === 'youtu.be' && preg_match('#^/([\w-]{11})#', $path, $m)) { + $youtubeId = $m[1]; + } + if ($youtubeId !== null && preg_match('/^[\w-]{11}$/', $youtubeId)) { + // Startzeit: ?t=90, ?t=1m30s oder ?start=90 + $start = 0; + $t = (string) ($query['t'] ?? $query['start'] ?? ''); + if (preg_match('/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/', $t, $tm) && $t !== '') { + $start = (int) ($tm[1] ?? 0) * 3600 + (int) ($tm[2] ?? 0) * 60 + (int) ($tm[3] ?? 0); + } + return $frame('https://www.youtube-nocookie.com/embed/' . $youtubeId . '?rel=0' . ($start > 0 ? '&start=' . $start : ''), $isShort ? ' wiki-video-portrait' : ''); + } + + // Twitch braucht die eigene Domain als "parent" + $parent = preg_replace('/:\d+$/', '', (string) ($_SERVER['HTTP_HOST'] ?? 'lumina-ascendes.de')); + if ($host === 'clips.twitch.tv' && preg_match('#^/([\w-]+)$#', $path, $m)) { + return $frame('https://clips.twitch.tv/embed?clip=' . $m[1] . '&parent=' . $parent . '&autoplay=false'); + } + if ($host === 'twitch.tv') { + if (preg_match('#^/[\w]+/clip/([\w-]+)$#', $path, $m)) { + return $frame('https://clips.twitch.tv/embed?clip=' . $m[1] . '&parent=' . $parent . '&autoplay=false'); + } + if (preg_match('#^/videos/(\d+)$#', $path, $m)) { + return $frame('https://player.twitch.tv/?video=v' . $m[1] . '&parent=' . $parent . '&autoplay=false'); + } + } + + // Vimeo: vimeo.com/123456789 + if ($host === 'vimeo.com' && preg_match('#^/(\d+)$#', $path, $m)) { + return $frame('https://player.vimeo.com/video/' . $m[1]); + } + + // Videodatei (z.B. auf Discord oder einem eigenen Server) + if (preg_match('#\.(mp4|webm|mov)$#i', $path)) { + return '
    '; + } + return null; +} + /** Inline-Formatierung einer (bereits maskierten) Zeile. */ function wiki_inline(string $html): string { @@ -258,6 +328,7 @@ function wiki_anchor(string $text): string * ## Ueberschrift, ### Unterueberschrift - Liste / 1. nummerierte Liste * **fett**, *kursiv*, ~~durchgestrichen~~, `Code` > Hinweis-Kasten * [Text](https://...), [[Seitentitel]], ![Bild](https://...) + * Video-Link allein in einer Zeile (YouTube, Twitch, Vimeo, .mp4) -> eingebetteter Player * | Tabelle | mit | Spalten | (zweite Zeile | --- | macht die erste zur Kopfzeile) * --- Trennlinie */ @@ -292,6 +363,14 @@ function wiki_render(string $text): string continue; } + // Video-Link allein in einer Zeile + $video = wiki_video_embed($trim); + if ($video !== null) { + $out[] = $video; + $i++; + continue; + } + // Tabelle: aufeinanderfolgende Zeilen, die mit | beginnen if ($trim[0] === '|') { $rows = []; @@ -351,7 +430,7 @@ function wiki_render(string $text): string $para = []; while ($i < $n) { $t = trim($lines[$i]); - if ($t === '' || $t[0] === '|' || $t[0] === '>' || preg_match('/^(#{1,4}\s|[-*]\s|\d+\.\s|-{3,}$)/', $t)) { + if ($t === '' || $t[0] === '|' || $t[0] === '>' || preg_match('/^(#{1,4}\s|[-*]\s|\d+\.\s|-{3,}$)/', $t) || wiki_video_embed($t) !== null) { break; } $para[] = wiki_inline(e($t)); diff --git a/wiki.php b/wiki.php index 518c760..00c1c89 100644 --- a/wiki.php +++ b/wiki.php @@ -57,11 +57,25 @@ $contributors = db()->query( $addableMembers = []; if ($canManage && !$page && $query === '') { $addableMembers = db()->query( - "SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users - WHERE status = 'active' AND id NOT IN (SELECT user_id FROM wiki_contributors) + "SELECT u.id, COALESCE(NULLIF(u.display_name, ''), u.username) AS name, u.avatar_filename, u.class_name, + (SELECT COALESCE(NULLIF(r.display_name, ''), r.name) FROM user_roles ur JOIN roles r ON r.id = ur.role_id + WHERE ur.user_id = u.id ORDER BY COALESCE(r.roster_order, 999), r.name LIMIT 1) AS top_role + FROM users u + WHERE u.status = 'active' AND u.id NOT IN (SELECT user_id FROM wiki_contributors) ORDER BY name" )->fetchAll(); } +// Fuer die Suchliste (assets/js/item-picker.js): Avatar, Name, Gruppe und Klasse +$contributorPickerItems = []; +foreach ($addableMembers as $member) { + $contributorPickerItems[] = [ + 'id' => (int) $member['id'], + 'name' => (string) $member['name'], + 'category' => trim(($member['top_role'] ?? 'Mitglied') . (!empty($member['class_name']) ? ' · ' . $member['class_name'] : '')), + 'icon' => !empty($member['avatar_filename']) ? '/assets/uploads/avatars/' . rawurlencode((string) $member['avatar_filename']) : null, + 'qty' => null, + ]; +} $pageCount = count($flat); $pageTitle = $page ? $page['title'] . ' - Wiki' : 'Wiki'; @@ -278,14 +292,17 @@ $nameOf = static fn (array $u): string => $u['display_name'] !== '' ? $u['displa
    - - +
    + + +
    +
    + + diff --git a/wiki_edit.php b/wiki_edit.php index 42943b9..7144f2b 100644 --- a/wiki_edit.php +++ b/wiki_edit.php @@ -66,6 +66,7 @@ include __DIR__ . '/includes/header.php'; + @@ -88,6 +89,7 @@ include __DIR__ . '/includes/header.php'; [Text](https://…)Link [[Sealed Dungeons]]Link auf eine andere Wiki-Seite ![Beschreibung](Adresse)Bild (einfacher über den Knopf „Bild“) + https://youtu.be/…Video: Link zu YouTube, Twitch, Vimeo oder einer .mp4-Datei allein in eine Zeile (oder Knopf „Video“)