diff --git a/README.md b/README.md index 546ba34..5302674 100644 --- a/README.md +++ b/README.md @@ -340,6 +340,15 @@ Reshanta. Oben wird die Region gewählt, unten links lassen sich die Marker-Kate „Alle anzeigen“/„Alle verstecken“ auf einmal ein- und ausblenden (beim Öffnen sind alle versteckt), beim Überfahren eines Markers erscheint sein Name. Zoomen per Mausrad, `+`/`-` oder die Knöpfe oben rechts, verschieben per Ziehen, `0` setzt die Ansicht zurück. +**Orte teilen:** Der 📍-Knopf in der Leiste oben rechts markiert per Klick einen Ort (Name +optional, der nächste Marker wird vorgeschlagen) und erzeugt einen Link wie +`/map.php?karte=verteron&x=2149&y=1962&zoom=4&ort=Treffpunkt`. Wer ihn öffnet, landet direkt dort, +mit pulsierendem Pin. In Kommentaren, Bildunterschriften und Termin-Beschreibungen werden solche +Links automatisch zu „📍 Verteron – Treffpunkt“ und zählen für die Moderation nicht als (fremder) +Link. Beim Kalender-Termin gibt es „🗺️ Ort auf der Karte wählen“: Die Karte öffnet sich im +Fenster (`index.html?pick=1`), Klick auf den Ort, „Diesen Ort übernehmen“ +(`LocationController.js`, `includes/map_links.php`, `assets/js/calendar.js`). + Der Viewer ist ein eigenständiges Paket (HTML/CSS/JS ohne Bibliotheken) unter `assets/map/` und wird von `map.php` per iframe eingebettet - so greift sein Stylesheet nicht auf das Seitenlayout über. Die Seite braucht die Berechtigung `map.view`. Die Karte selbst braucht diff --git a/assets/css/style.css b/assets/css/style.css index 156dcdc..e11d88a 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -5436,3 +5436,44 @@ a.calendar-agenda-entry:hover { text-decoration: none; filter: brightness(1.2); .calendar-edit[open] .calendar-form { position: absolute; right: 0; z-index: 15; width: min(560px, 90vw); background: #232323; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6); } .moderation-calendar-icon { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 8px; background: rgba(59, 165, 93, 0.15); color: #57d68d; flex-shrink: 0; } .moderation-calendar-icon .icon { width: 28px; height: 28px; } + +/* ---- Orte auf der Karte (Links, Kalender-Treffpunkt) ---- */ +.map-link { + display: inline-flex; + align-items: center; + gap: 0.25rem; + padding: 0.05rem 0.55rem; + border-radius: 999px; + background: rgba(229, 57, 53, 0.14); + border: 1px solid rgba(229, 57, 53, 0.45); + color: #ff9a97; + font-weight: 600; + font-size: 0.88em; + white-space: nowrap; +} +.map-link:hover { text-decoration: none; background: rgba(229, 57, 53, 0.24); color: #ffc2c0; } +.calendar-location { font-size: 0.88rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; } + +.calendar-location-field { display: flex; flex-direction: column; gap: 0.35rem; } +.calendar-location-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; } +.calendar-location-chosen { font-size: 0.88rem; color: var(--text-muted); } +.calendar-location-chosen.is-set { color: #ff9a97; font-weight: 600; } +.calendar-location-clear { background: transparent; border: 1px solid var(--border); color: var(--text-muted); } +.calendar-location-clear[hidden] { display: none; } + +#map-pick-modal { padding: 1rem; align-items: center; justify-content: center; } +.map-pick-dialog { + display: flex; + flex-direction: column; + width: min(1200px, 100%); + height: min(820px, calc(100vh - 2rem)); + border-radius: 12px; + overflow: hidden; + border: 1px solid var(--border); + background: var(--bg-panel); + box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7); +} +.map-pick-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 1rem; padding: 0.6rem 3rem 0.6rem 1rem; position: relative; border-bottom: 1px solid var(--border); } +.map-pick-head .text-muted { font-size: 0.85rem; } +.map-pick-head .modal-close { position: absolute; top: 0.45rem; right: 0.6rem; } +.map-pick-dialog iframe { flex: 1; width: 100%; border: 0; background: #0a0a1e; } diff --git a/assets/js/calendar.js b/assets/js/calendar.js new file mode 100644 index 0000000..2f2aaee --- /dev/null +++ b/assets/js/calendar.js @@ -0,0 +1,64 @@ +/** + * Kalender: Treffpunkt eines Termins auf der Karte auswaehlen. Die Karte laeuft im Fenster + * (assets/map/index.html?pick=1) und schickt den gewaehlten Ort per postMessage zurueck. + */ +(function () { + 'use strict'; + + var modal = document.getElementById('map-pick-modal'); + if (!modal) return; + var frame = modal.querySelector('[data-map-frame]'); + var field = null; // Feld des Formulars, fuer das gerade ausgewaehlt wird + + function open(target) { + field = target; + var current = field.querySelector('input[name="location"]').value; + // Schon ein Ort gewaehlt? Dann die Karte dort oeffnen. + var query = current.indexOf('?') !== -1 ? current.slice(current.indexOf('?') + 1) + '&' : ''; + frame.src = '/assets/map/index.html?' + query + 'pick=1'; + modal.hidden = false; + document.body.style.overflow = 'hidden'; + } + + function close() { + modal.hidden = true; + document.body.style.overflow = ''; + frame.src = 'about:blank'; + } + + function setLocation(target, url, label) { + target.querySelector('input[name="location"]').value = url; + var text = target.querySelector('[data-location-label]'); + text.textContent = url ? '📍 ' + label : 'Kein Ort gewählt'; + text.classList.toggle('is-set', !!url); + target.querySelector('[data-clear-location]').hidden = !url; + } + + document.addEventListener('click', function (event) { + var pick = event.target.closest('[data-pick-location]'); + if (pick) { + open(pick.closest('[data-location-field]')); + return; + } + var clear = event.target.closest('[data-clear-location]'); + if (clear) { + setLocation(clear.closest('[data-location-field]'), '', ''); + return; + } + if (event.target.closest('[data-close-map-pick]') || event.target === modal) { + close(); + } + }); + + document.addEventListener('keydown', function (event) { + if (event.key === 'Escape' && !modal.hidden) close(); + }); + + // Antwort der Karte: nur von unserer eigenen Seite annehmen + window.addEventListener('message', function (event) { + if (event.origin !== window.location.origin || !event.data || event.data.type !== 'lumina-map-pick' || !field) return; + if (typeof event.data.url !== 'string' || event.data.url.indexOf('/map.php?') !== 0) return; + setLocation(field, event.data.url, String(event.data.label || '')); + close(); + }); +})(); diff --git a/assets/map/app.js b/assets/map/app.js index 874c68f..5a356ff 100644 --- a/assets/map/app.js +++ b/assets/map/app.js @@ -6,5 +6,7 @@ document.addEventListener('DOMContentLoaded', () => { const controller = new MapController(); // Vor init(), damit schon die erste Karte ihre Taktiken laedt. new TacticController(controller); + // Orte teilen/auswaehlen - nach den Taktiken, damit beide auf Kartenwechsel reagieren + controller.locations = new LocationController(controller); controller.init(); }); \ No newline at end of file diff --git a/assets/map/index.html b/assets/map/index.html index 0b873a9..9f96366 100644 --- a/assets/map/index.html +++ b/assets/map/index.html @@ -165,6 +165,7 @@ + \ No newline at end of file diff --git a/assets/map/js/controllers/LocationController.js b/assets/map/js/controllers/LocationController.js new file mode 100644 index 0000000..2ef0e08 --- /dev/null +++ b/assets/map/js/controllers/LocationController.js @@ -0,0 +1,263 @@ +/** + * Orte auf der Karte verlinken: + * - Link oeffnen: /map.php?karte=verteron&x=1234&y=2345&zoom=5&ort=Treffpunkt oeffnet die Karte an + * der Stelle und setzt dort einen Pin (map.php reicht die Parameter an diesen Viewer weiter). + * - Ort teilen (📍-Knopf): auf die Karte klicken, Namen eingeben, Link kopieren. + * - Ort auswaehlen (?pick=1): die Karte laeuft in einem Fenster der Website (z.B. Kalender); + * "Diesen Ort uebernehmen" schickt den Ort per postMessage an die Seite zurueck. + */ + +class LocationController { + constructor(mapController) { + this.map = mapController; + this.view = mapController.view; + this.params = new URLSearchParams(window.location.search); + this.pickMode = this.params.get('pick') === '1'; + this.active = false; // Klick auf die Karte setzt gerade einen Ort + this.pin = null; // {x, y} in Weltkoordinaten + this.label = ''; + + this.buildUi(); + this.view.onPinUpdate = () => this.updatePin(); + this.map.onTap = (clientX, clientY) => this.handleTap(clientX, clientY); + this.map.onMapChanged = this.chain(this.map.onMapChanged, () => this.clearPin()); + + // Mausklick (ohne Ziehen) auf die Karte + let down = null; + this.view.canvas.addEventListener('mousedown', e => { down = { x: e.clientX, y: e.clientY }; }); + this.view.canvas.addEventListener('mouseup', e => { + if (down && Math.hypot(e.clientX - down.x, e.clientY - down.y) < 5) this.handleTap(e.clientX, e.clientY); + down = null; + }); + + if (this.pickMode) { + document.body.classList.add('pick-mode'); + this.start(); + } + } + + /** Zwei Callbacks hintereinander (TacticController haengt sich auch an onMapChanged). */ + chain(first, second) { + return (...args) => { + if (first) first(...args); + second(...args); + }; + } + + /** Karte aus dem Link (?karte=...), sonst null. */ + requestedMap() { + const slug = this.params.get('karte'); + return slug && this.map.mapData.maps.some(m => m.slug === slug) ? slug : null; + } + + /** Nach dem Laden der Karte aus dem Link: an die Stelle springen und den Pin setzen. */ + applyLink() { + const x = parseFloat(this.params.get('x')); + const y = parseFloat(this.params.get('y')); + if (!this.requestedMap() || !isFinite(x) || !isFinite(y)) return; + const zoom = parseInt(this.params.get('zoom'), 10); + this.view.zoom = Math.min(CONFIG.MAX_ZOOM, Math.max(CONFIG.MIN_ZOOM, isFinite(zoom) ? zoom : CONFIG.MIN_ZOOM + 3)); + this.view.centerWorldX = x; + this.view.centerWorldY = y; + this.setPin(x, y, (this.params.get('ort') || '').slice(0, 60)); + this.map.render(); + if (this.pickMode) this.showPanel(); + } + + buildUi() { + const overlay = document.getElementById('ui-overlay'); + + // 📍-Knopf in der Zoom-Leiste + const button = document.createElement('button'); + button.id = 'btn-share-location'; + button.title = 'Ort teilen - auf die Karte klicken und den Link kopieren'; + button.textContent = '📍'; + button.addEventListener('click', () => (this.active ? this.stop() : this.start())); + document.getElementById('zoom-controls').appendChild(button); + this.button = button; + + // Hinweis oben: "Klicke auf die Karte" + this.banner = document.createElement('div'); + this.banner.id = 'loc-banner'; + this.banner.className = 'panel hidden'; + this.banner.innerHTML = '📍 Klicke auf die Karte, um einen Ort zu markieren'; + if (!this.pickMode) { + const cancel = document.createElement('button'); + cancel.type = 'button'; + cancel.textContent = 'Abbrechen'; + cancel.addEventListener('click', () => this.stop()); + this.banner.appendChild(cancel); + } + overlay.appendChild(this.banner); + + // Pin mit Beschriftung + this.pinEl = document.createElement('div'); + this.pinEl.id = 'map-pin'; + this.pinEl.className = 'hidden'; + this.pinEl.innerHTML = ''; + document.getElementById('map-container').appendChild(this.pinEl); + + // Fenster mit Name und Link bzw. "Uebernehmen" + this.panel = document.createElement('div'); + this.panel.id = 'loc-panel'; + this.panel.className = 'panel hidden'; + this.panel.innerHTML = + '' + + '

' + (this.pickMode ? 'Ort auswählen' : 'Ort teilen') + '

' + + '' + + '
' + + (this.pickMode + ? '' + : '') + + '

' + (this.pickMode ? 'Woanders klicken, um den Ort zu ändern.' : 'Den Link kannst du in Terminen, Kommentaren oder im Discord einfügen.') + '

'; + overlay.appendChild(this.panel); + + this.nameInput = this.panel.querySelector('#loc-name'); + this.nameInput.addEventListener('input', () => { + this.label = this.nameInput.value.trim(); + this.updatePin(); + this.updateLink(); + }); + // Tasten wie H oder +/- sollen beim Tippen nicht die Karte steuern + this.nameInput.addEventListener('keydown', e => e.stopPropagation()); + this.panel.querySelector('.loc-close').addEventListener('click', () => { + this.panel.classList.add('hidden'); + if (!this.pickMode) this.clearPin(); + }); + if (this.pickMode) { + this.panel.querySelector('#loc-use').addEventListener('click', () => this.sendPick()); + } else { + this.panel.querySelector('#loc-copy').addEventListener('click', () => this.copyLink()); + } + } + + start() { + this.active = true; + this.button.classList.add('active'); + this.banner.classList.remove('hidden'); + this.view.canvas.classList.add('picking'); + } + + stop() { + this.active = false; + this.button.classList.remove('active'); + this.banner.classList.add('hidden'); + this.view.canvas.classList.remove('picking'); + } + + /** Klick/Tipp auf die Karte - true, wenn er hier verarbeitet wurde. */ + handleTap(clientX, clientY) { + if (!this.active || !this.map.mapData.currentMap) return false; + const rect = this.view.canvas.getBoundingClientRect(); + const world = this.view.screenToWorld(clientX - rect.left, clientY - rect.top); + const x = Math.round(world.x); + const y = Math.round(world.y); + if (x < CONFIG.WORLD_MIN_X || x > CONFIG.WORLD_MAX_X || y < CONFIG.WORLD_MIN_Y || y > CONFIG.WORLD_MAX_Y) return true; + + // Name vorschlagen: der naechste Marker in der Naehe (auch ausgeblendete Kategorien) + const nearby = this.nearestMarkerName(clientX - rect.left, clientY - rect.top); + this.setPin(x, y, this.nameInput.value.trim() || nearby); + this.showPanel(); + if (!this.pickMode) this.stop(); + return true; + } + + nearestMarkerName(screenX, screenY) { + let best = ''; + let bestDist = 40; + for (const marker of this.map.mapData.markers) { + const p = this.view.worldToScreen(marker.worldX, marker.worldY); + const dist = Math.hypot(p.x - screenX, p.y - screenY); + if (dist < bestDist) { + bestDist = dist; + best = marker.iconText || marker.nt || marker.name || ''; + } + } + return String(best).slice(0, 60); + } + + setPin(x, y, label) { + this.pin = { x, y }; + this.label = label || ''; + this.nameInput.value = this.label; + this.updatePin(); + this.updateLink(); + } + + clearPin() { + this.pin = null; + this.pinEl.classList.add('hidden'); + } + + updatePin() { + if (!this.pin) return; + const p = this.view.worldToScreen(this.pin.x, this.pin.y); + this.pinEl.style.left = p.x + 'px'; + this.pinEl.style.top = p.y + 'px'; + this.pinEl.querySelector('.pin-label').textContent = this.label; + this.pinEl.querySelector('.pin-label').hidden = this.label === ''; + this.pinEl.classList.remove('hidden'); + } + + showPanel() { + this.panel.classList.remove('hidden'); + this.updateLink(); + if (!this.pickMode) this.nameInput.focus(); + } + + mapName() { + return this.map.mapData.currentMap ? this.map.mapData.currentMap.name : ''; + } + + /** Pfad des Links, z.B. /map.php?karte=verteron&x=1&y=2&zoom=5&ort=Portal */ + linkPath() { + if (!this.pin || !this.map.mapData.currentMap) return ''; + const params = new URLSearchParams({ + karte: this.map.mapData.currentMap.slug, + x: String(this.pin.x), + y: String(this.pin.y), + zoom: String(Math.max(this.view.zoom, CONFIG.MIN_ZOOM + 2)), + }); + if (this.label) params.set('ort', this.label); + return '/map.php?' + params.toString(); + } + + updateLink() { + const where = this.panel.querySelector('#loc-where'); + where.textContent = this.pin ? '🗺️ ' + this.mapName() + (this.label ? ' – ' + this.label : '') : ''; + const link = this.panel.querySelector('#loc-link'); + if (link) link.value = this.pin ? window.location.origin + this.linkPath() : ''; + } + + copyLink() { + const link = this.panel.querySelector('#loc-link'); + const done = () => this.toast('Link kopiert - einfach in Termin, Kommentar oder Discord einfügen.'); + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard.writeText(link.value).then(done, () => { link.select(); document.execCommand('copy'); done(); }); + } else { + link.select(); + document.execCommand('copy'); + done(); + } + } + + sendPick() { + if (!this.pin) return; + window.parent.postMessage({ + type: 'lumina-map-pick', + url: this.linkPath(), + label: this.mapName() + (this.label ? ' – ' + this.label : ''), + }, window.location.origin); + } + + toast(text) { + const toast = document.getElementById('toast'); + if (!toast) return; + toast.textContent = text; + toast.classList.remove('hidden'); + clearTimeout(this.toastTimer); + this.toastTimer = setTimeout(() => toast.classList.add('hidden'), 2500); + } +} diff --git a/assets/map/js/controllers/MapController.js b/assets/map/js/controllers/MapController.js index eb3c88d..7581e80 100644 --- a/assets/map/js/controllers/MapController.js +++ b/assets/map/js/controllers/MapController.js @@ -48,8 +48,11 @@ class MapController { saved = null; } const has = slug => this.mapData.maps.some(m => m.slug === slug); - const slug = has(saved) ? saved : (has(CONFIG.DEFAULT_MAP) ? CONFIG.DEFAULT_MAP : this.mapData.maps[0].slug); + // Ein geteilter Ort (?karte=...) hat Vorrang vor der zuletzt gewaehlten Karte + const linked = this.locations ? this.locations.requestedMap() : null; + const slug = linked || (has(saved) ? saved : (has(CONFIG.DEFAULT_MAP) ? CONFIG.DEFAULT_MAP : this.mapData.maps[0].slug)); await this.loadMap(slug); + if (this.locations) this.locations.applyLink(); } } catch (e) { console.error('Failed to initialize:', e); @@ -570,6 +573,8 @@ class MapController { lastTap = 0; } else { lastTap = now; + // Ort teilen/auswaehlen: Antippen setzt den Pin + if (this.onTap && this.onTap(touch.clientX, touch.clientY)) return; // Antippen zeigt den Namen eines Markers (statt Mauszeiger-Hover). this.checkHover(touch); } diff --git a/assets/map/js/views/MapView.js b/assets/map/js/views/MapView.js index db5ca1b..3ba0fac 100644 --- a/assets/map/js/views/MapView.js +++ b/assets/map/js/views/MapView.js @@ -96,6 +96,8 @@ class MapView { // Zeichenebene der Taktiken sofort mitziehen, nicht erst nach dem Laden der Kacheln. if (this.onViewChange) this.onViewChange(); + // Pin eines geteilten Ortes mitziehen (LocationController) + if (this.onPinUpdate) this.onPinUpdate(); if (!mapData.currentMap) return; diff --git a/assets/map/styles.css b/assets/map/styles.css index f459409..92de178 100644 --- a/assets/map/styles.css +++ b/assets/map/styles.css @@ -982,3 +982,118 @@ button.tp-item.active { bottom: 120px; } } + +/* ---- Orte teilen / auswaehlen (LocationController) ---- */ +#btn-share-location.active { background: var(--accent-gold); color: #1a1a2e; } +#map-canvas.picking { cursor: crosshair; } + +#loc-banner { + position: absolute; + top: 72px; + left: 50%; + transform: translateX(-50%); + display: flex; + align-items: center; + gap: 12px; + padding: 8px 14px; + border-color: rgba(255, 215, 0, 0.55); + font-size: 14px; + white-space: nowrap; + z-index: 5; +} +#loc-banner button { padding: 4px 10px; font-size: 12px; } + +#map-pin { + position: absolute; + z-index: 4; + pointer-events: none; + transform: translate(-50%, -100%); + display: flex; + flex-direction: column; + align-items: center; +} +#map-pin .pin-dot { + position: relative; + width: 22px; + height: 22px; + border-radius: 50% 50% 50% 0; + transform: rotate(-45deg); + background: #e53935; + border: 3px solid #fff; + box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6); + margin-bottom: 6px; +} +#map-pin .pin-dot::after { + content: ''; + position: absolute; + left: 50%; + top: 50%; + width: 44px; + height: 44px; + margin: -22px 0 0 -22px; + border-radius: 50%; + border: 3px solid rgba(229, 57, 53, 0.7); + animation: pin-pulse 1.6s ease-out infinite; +} +@keyframes pin-pulse { + from { transform: scale(0.4); opacity: 1; } + to { transform: scale(1.6); opacity: 0; } +} +#map-pin .pin-label { + margin-bottom: 6px; + padding: 3px 9px; + border-radius: 6px; + background: rgba(10, 10, 30, 0.92); + border: 1px solid rgba(255, 215, 0, 0.6); + color: var(--accent-gold); + font-size: 13px; + font-weight: 600; + white-space: nowrap; +} + +#loc-panel { + position: absolute; + bottom: 24px; + left: 50%; + transform: translateX(-50%); + width: min(440px, calc(100vw - 32px)); + padding: 14px 16px; + display: flex; + flex-direction: column; + gap: 10px; + z-index: 6; + border-color: rgba(255, 215, 0, 0.45); + box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6); +} +#loc-panel h3 { font-size: 15px; color: var(--accent-gold); } +#loc-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); } +#loc-panel .loc-optional { opacity: 0.7; } +#loc-panel input { + width: 100%; + padding: 8px 10px; + border-radius: 6px; + border: 1px solid var(--border-color); + background: rgba(0, 0, 0, 0.35); + color: var(--text-primary); + font-size: 14px; +} +#loc-panel input:focus { outline: none; border-color: var(--accent-gold); } +.loc-where { font-size: 13px; color: var(--text-primary); } +.loc-link-row { display: flex; gap: 8px; } +.loc-link-row input { flex: 1; min-width: 0; font-size: 12px !important; } +.loc-primary { + padding: 8px 14px; + border-radius: 6px; + border: none; + background: var(--accent-gold); + color: #1a1a2e; + font-weight: 700; + cursor: pointer; + white-space: nowrap; +} +.loc-primary:hover { filter: brightness(1.1); } +.loc-hint { font-size: 11px; color: var(--text-secondary); } +.loc-close { position: absolute; top: 8px; right: 10px; background: none; border: none; color: var(--text-secondary); font-size: 16px; cursor: pointer; } + +/* Auswahl-Fenster (Kalender): keine Taktiken, mehr Platz */ +.pick-mode #tactic-panel { display: none !important; } diff --git a/calendar.php b/calendar.php index a5803e9..6a3cdc2 100644 --- a/calendar.php +++ b/calendar.php @@ -171,8 +171,21 @@ $weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']; $today = date('Y-m-d'); $dayNames = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag']; +/** Treffpunkt auf der Karte: verstecktes Feld + Knopf, der die Karte zum Auswaehlen oeffnet (assets/js/calendar.js). */ +$locationField = static function (?array $row): string { + $link = !empty($row['location_path']) ? map_link_parse((string) $row['location_path']) : null; + return '
' + . 'Treffpunkt auf der Karte (optional)' + . '' + . '
' + . '' . ($link ? '📍 ' . e(map_link_label($link)) : 'Kein Ort gewählt') . '' + . '' + . '' + . '
'; +}; + /** Formularfelder fuer "Termin eintragen" und "Bearbeiten". */ -$entryFields = static function (?array $row): string { +$entryFields = static function (?array $row) use ($locationField): string { $start = $row ? date('Y-m-d\TH:i', strtotime((string) $row['starts_at'])) : date('Y-m-d\T20:00', strtotime('+1 day')); $end = $row && $row['ends_at'] ? date('Y-m-d\TH:i', strtotime((string) $row['ends_at'])) : ''; return '' @@ -181,7 +194,8 @@ $entryFields = static function (?array $row): string { . '' . '' . ''; + . e((string) ($row['description'] ?? '')) . '' + . $locationField($row); }; $pageTitle = 'Kalender'; @@ -309,4 +323,18 @@ include __DIR__ . '/includes/header.php'; + + + + + diff --git a/calendar_action.php b/calendar_action.php index a659296..72224da 100644 --- a/calendar_action.php +++ b/calendar_action.php @@ -31,12 +31,14 @@ $parseTime = static function (string $value): ?string { return $time ? $time->format('Y-m-d H:i:s') : null; }; -/** Eingaben pruefen - bei Fehlern mit Meldung zurueck. @return array{0:string,1:?string,2:string,3:?string} */ +/** Eingaben pruefen - bei Fehlern mit Meldung zurueck. @return array{0:string,1:?string,2:string,3:?string,4:?string} */ $readInput = static function () use ($parseTime, $backTo): array { $title = trim((string) preg_replace('/\s+/u', ' ', (string) ($_POST['title'] ?? ''))); $description = trim(str_replace("\r\n", "\n", (string) ($_POST['description'] ?? ''))); $startsAt = $parseTime((string) ($_POST['starts_at'] ?? '')); $endsAt = trim((string) ($_POST['ends_at'] ?? '')) !== '' ? $parseTime((string) $_POST['ends_at']) : null; + $locationInput = trim((string) ($_POST['location'] ?? '')); + $location = $locationInput !== '' ? map_link_parse($locationInput) : null; $error = null; if ($title === '') { @@ -53,12 +55,14 @@ $readInput = static function () use ($parseTime, $backTo): array { $error = 'Das Ende muss nach dem Beginn liegen.'; } elseif ($endsAt !== null && strtotime($endsAt) - strtotime($startsAt) > 7 * 86400) { $error = 'Ein Termin darf höchstens eine Woche dauern.'; + } elseif ($locationInput !== '' && $location === null) { + $error = 'Der Ort ist kein gültiger Link auf unsere Karte - bitte über „Ort auf der Karte wählen“ aussuchen.'; } if ($error !== null) { set_flash('error', $error); redirect($backTo($startsAt)); } - return [$title, $description !== '' ? $description : null, (string) $startsAt, $endsAt]; + return [$title, $description !== '' ? $description : null, (string) $startsAt, $endsAt, $location['path'] ?? null]; }; /** Termin laden (oder zurueck zum Kalender). */ @@ -75,7 +79,7 @@ $loadEntry = static function (int $id) use ($pdo, $backTo): array { switch ($action) { case 'create': - [$title, $description, $startsAt, $endsAt] = $readInput(); + [$title, $description, $startsAt, $endsAt, $locationPath] = $readInput(); $text = $title . "\n" . (string) $description; if (moderation_blocks($text, 'Kalender-Termin')) { set_flash('error', 'Der Termin enthält ein Wort, das hier nicht erlaubt ist.'); @@ -87,8 +91,8 @@ switch ($action) { } [$status, $note] = moderation_initial_status('calendar', $text); $pdo->prepare( - 'INSERT INTO calendar_entries (user_id, title, description, starts_at, ends_at, status, moderation_note) VALUES (?, ?, ?, ?, ?, ?, ?)' - )->execute([$myId, $title, $description, $startsAt, $endsAt, $status, $note]); + 'INSERT INTO calendar_entries (user_id, title, description, starts_at, ends_at, location_path, status, moderation_note) VALUES (?, ?, ?, ?, ?, ?, ?, ?)' + )->execute([$myId, $title, $description, $startsAt, $endsAt, $locationPath, $status, $note]); $entryId = (int) $pdo->lastInsertId(); // Wer einlaedt, ist natuerlich dabei $pdo->prepare('INSERT INTO calendar_participants (entry_id, user_id) VALUES (?, ?)')->execute([$entryId, $myId]); @@ -103,7 +107,7 @@ switch ($action) { set_flash('error', 'Nur wer den Termin eingetragen hat, kann ihn bearbeiten.'); redirect($backTo($entry['starts_at'], (int) $entry['id'])); } - [$title, $description, $startsAt, $endsAt] = $readInput(); + [$title, $description, $startsAt, $endsAt, $locationPath] = $readInput(); $text = $title . "\n" . (string) $description; if (moderation_blocks($text, 'Kalender-Termin')) { set_flash('error', 'Der Termin enthält ein Wort, das hier nicht erlaubt ist.'); @@ -115,8 +119,8 @@ switch ($action) { [$status, $note] = ['pending', $entry['moderation_note']]; } $pdo->prepare( - 'UPDATE calendar_entries SET title = ?, description = ?, starts_at = ?, ends_at = ?, status = ?, moderation_note = ?, updated_at = ? WHERE id = ?' - )->execute([$title, $description, $startsAt, $endsAt, $status, $note, date('Y-m-d H:i:s'), (int) $entry['id']]); + 'UPDATE calendar_entries SET title = ?, description = ?, starts_at = ?, ends_at = ?, location_path = ?, status = ?, moderation_note = ?, updated_at = ? WHERE id = ?' + )->execute([$title, $description, $startsAt, $endsAt, $locationPath, $status, $note, date('Y-m-d H:i:s'), (int) $entry['id']]); set_flash('success', $status === 'pending' ? 'Termin gespeichert - für alle sichtbar nach der Freigabe.' : 'Termin gespeichert.'); redirect($backTo($startsAt, (int) $entry['id'])); diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 55efb9c..62eb913 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -27,6 +27,7 @@ if (session_status() !== PHP_SESSION_ACTIVE) { require_once __DIR__ . '/db.php'; require_once __DIR__ . '/functions.php'; +require_once __DIR__ . '/map_links.php'; require_once __DIR__ . '/auth.php'; require_once __DIR__ . '/permissions.php'; require_once __DIR__ . '/schema.php'; diff --git a/includes/calendar_entry.php b/includes/calendar_entry.php index ec28c0c..a3e3118 100644 --- a/includes/calendar_entry.php +++ b/includes/calendar_entry.php @@ -29,6 +29,10 @@ $actionForm = static function (string $action, string $label, string $class, str + + +
Treffpunkt:
+

diff --git a/includes/map_links.php b/includes/map_links.php new file mode 100644 index 0000000..67c27c7 --- /dev/null +++ b/includes/map_links.php @@ -0,0 +1,78 @@ + 'Verteron', + 'elthen' => 'Eltnen', + 'poeta' => 'Poeta', + 'altgard' => 'Altgard', + 'morheim' => 'Morheim', + 'ishalgen' => 'Ishalgen', + 'abyss-reshanta-a' => 'Abyss Reshanta A', + 'abyss-reshanta-b' => 'Abyss Reshanta B', + 'chaotic-middle-reshanta' => 'Chaotic Middle Reshanta', + 'chaotic-upper-reshanta' => 'Chaotic Upper Reshanta', +]; + +/** Regex fuer Karten-Links dieser Website (absolut mit unserer Domain oder relativ). */ +function map_link_pattern(): string +{ + $host = preg_quote((string) ($_SERVER['HTTP_HOST'] ?? 'lumina-ascendes.de'), '~'); + return '~(?:https?://(?:www\.)?' . $host . ')?/map\.php\?[^\s<>"\']+~i'; +} + +/** + * Karten-Link zerlegen und pruefen. + * + * @return array{slug: string, x: int, y: int, zoom: int, ort: string, path: string}|null + */ +function map_link_parse(string $url): ?array +{ + $url = html_entity_decode(trim($url), ENT_QUOTES | ENT_HTML5, 'UTF-8'); + if (!preg_match(map_link_pattern(), $url, $match) || $match[0] !== $url) { + return null; + } + parse_str((string) parse_url($url, PHP_URL_QUERY), $query); + $slug = (string) ($query['karte'] ?? ''); + if (!isset(MAP_LINK_NAMES[$slug]) || !is_numeric($query['x'] ?? null) || !is_numeric($query['y'] ?? null)) { + return null; + } + $link = [ + 'slug' => $slug, + 'x' => max(0, min(4096, (int) $query['x'])), + 'y' => max(0, min(4096, (int) $query['y'])), + 'zoom' => max(2, min(6, (int) ($query['zoom'] ?? 5))), + 'ort' => mb_substr(trim((string) ($query['ort'] ?? '')), 0, 60), + ]; + $params = ['karte' => $link['slug'], 'x' => $link['x'], 'y' => $link['y'], 'zoom' => $link['zoom']]; + if ($link['ort'] !== '') { + $params['ort'] = $link['ort']; + } + $link['path'] = '/map.php?' . http_build_query($params); + return $link; +} + +/** "Verteron – Treffpunkt Brücke" */ +function map_link_label(array $link): string +{ + return MAP_LINK_NAMES[$link['slug']] . ($link['ort'] !== '' ? ' – ' . $link['ort'] : ''); +} + +/** Huebscher Link mit Pin fuer Texte (Kommentare, Termine). */ +function map_link_html(array $link): string +{ + return '📍 ' . e(map_link_label($link)) . ''; +} + +/** Text ohne eigene Karten-Links - die zaehlen fuer die Moderation nicht als "Link". */ +function map_links_strip(string $text): string +{ + return (string) preg_replace(map_link_pattern(), ' ', $text); +} diff --git a/includes/member_profile.php b/includes/member_profile.php index 898a9b5..1a873f6 100644 --- a/includes/member_profile.php +++ b/includes/member_profile.php @@ -132,7 +132,14 @@ function gallery_comment_html(string $body): string $html = e($body); $html = (string) preg_replace_callback( '~https?://[^\s<>"\']+~i', - static fn (array $m): string => '' . $m[0] . '', + static function (array $m): string { + // Orte auf unserer Karte als "📍 Verteron – Treffpunkt" + $mapLink = map_link_parse($m[0]); + if ($mapLink !== null) { + return map_link_html($mapLink); + } + return '' . $m[0] . ''; + }, $html ); return nl2br($html, false); diff --git a/includes/moderation.php b/includes/moderation.php index e1bea19..21a1818 100644 --- a/includes/moderation.php +++ b/includes/moderation.php @@ -51,6 +51,8 @@ function moderation_user_trusted(): bool /** Enthaelt der Text einen Link (auch ohne http, z.B. www.… oder discord.gg/…)? */ function moderation_has_link(string $text): bool { + // Links auf Orte unserer Karte sind harmlos + $text = map_links_strip($text); 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); } diff --git a/includes/schema.php b/includes/schema.php index 28521ae..653ea91 100644 --- a/includes/schema.php +++ b/includes/schema.php @@ -11,7 +11,7 @@ declare(strict_types=1); */ // Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu. -const SCHEMA_VERSION = 21; +const SCHEMA_VERSION = 22; /** * Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql). @@ -380,6 +380,8 @@ CREATE TABLE IF NOT EXISTS calendar_entries ( description TEXT NULL, starts_at DATETIME NOT NULL, ends_at DATETIME NULL, + -- Treffpunkt auf der Karte (Link /map.php?karte=...&x=...&y=...) + location_path VARCHAR(300) NULL, -- visible / pending (Moderation wie bei Kommentaren) status VARCHAR(10) NOT NULL DEFAULT 'visible', moderation_note VARCHAR(255) NULL, @@ -465,6 +467,10 @@ function schema_column_upgrades(): array 'status' => "ALTER TABLE member_gallery ADD COLUMN status VARCHAR(10) NOT NULL DEFAULT 'visible' AFTER caption", 'moderation_note' => "ALTER TABLE member_gallery ADD COLUMN moderation_note VARCHAR(255) NULL AFTER status", ], + // Treffpunkt auf der Karte (Link /map.php?karte=...&x=...&y=...) + 'calendar_entries' => [ + 'location_path' => "ALTER TABLE calendar_entries ADD COLUMN location_path VARCHAR(300) NULL AFTER ends_at", + ], 'shop_orders' => [ 'requested_quantity' => "ALTER TABLE shop_orders ADD COLUMN requested_quantity INT UNSIGNED NOT NULL DEFAULT 0 AFTER quantity", ], diff --git a/map.php b/map.php index bb66105..0b4e5c3 100644 --- a/map.php +++ b/map.php @@ -14,6 +14,16 @@ try { // Die Karte ist ein eigenstaendiger Viewer (assets/map/) mit eigenem Stylesheet, das // global auf body/button/* greift. Im iframe bleibt er vom Seitenlayout getrennt. // Die Taktiken laedt und speichert er selbst ueber tactics_api.php. +// Geteilter Ort (/map.php?karte=verteron&x=1234&y=2345&zoom=5&ort=Treffpunkt): an den Viewer weiterreichen. +$linkParams = array_filter([ + 'karte' => preg_match('/^[a-z0-9-]{1,40}$/', (string) ($_GET['karte'] ?? '')) ? (string) $_GET['karte'] : '', + 'x' => is_numeric($_GET['x'] ?? null) ? (string) (int) $_GET['x'] : '', + 'y' => is_numeric($_GET['y'] ?? null) ? (string) (int) $_GET['y'] : '', + 'zoom' => is_numeric($_GET['zoom'] ?? null) ? (string) (int) $_GET['zoom'] : '', + 'ort' => mb_substr(trim((string) ($_GET['ort'] ?? '')), 0, 60), +], static fn (string $v): bool => $v !== ''); +$frameSrc = '/assets/map/index.html' . ($linkParams ? '?' . http_build_query($linkParams) : ''); + $pageTitle = 'Karte'; $containerWide = true; include __DIR__ . '/includes/header.php'; @@ -35,5 +45,5 @@ include __DIR__ . '/includes/header.php'; - + diff --git a/sql/schema.sql b/sql/schema.sql index 871f65c..f7faf47 100644 --- a/sql/schema.sql +++ b/sql/schema.sql @@ -507,6 +507,8 @@ CREATE TABLE IF NOT EXISTS calendar_entries ( description TEXT NULL, starts_at DATETIME NOT NULL, ends_at DATETIME NULL, + -- Treffpunkt auf der Karte (Link /map.php?karte=...&x=...&y=...) + location_path VARCHAR(300) NULL, -- visible / pending (Moderation wie bei Kommentaren) status VARCHAR(10) NOT NULL DEFAULT 'visible', moderation_note VARCHAR(255) NULL,