LuminaWebsite/includes/map_links.php
Maaxxs c869f93152 Map: share locations and pick them for calendar entries
- Map links (/map.php?karte=…&x=…&y=…&zoom=…&ort=…) open the region at that spot with a pin
- "Share location" button on the map: click a spot, optional name, copy the link
- Calendar entries: "Pick location on the map" opens the map in a window, "Use this location" stores the meeting point
- Map links in comments, captions and descriptions render as "📍 Region – Location" and do not count as external links for moderation

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

78 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* Links auf Orte der Karte (/map.php?karte=verteron&x=1234&y=2345&zoom=5&ort=Treffpunkt),
* erzeugt ueber "Ort teilen" bzw. "Ort auswaehlen" (assets/map/js/controllers/LocationController.js).
* Hier: erkennen, pruefen und als "📍 Verteron – Treffpunkt" anzeigen.
*/
// Anzeigenamen der Karten (wie data/maps.json + CONFIG.MAP_NAMES im Viewer)
const MAP_LINK_NAMES = [
'verteron' => '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 '<a class="map-link" href="' . e($link['path']) . '" title="Auf der Karte zeigen">📍 ' . e(map_link_label($link)) . '</a>';
}
/** 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);
}