hhhh
This commit is contained in:
@@ -4,29 +4,73 @@ declare(strict_types=1);
|
||||
$app = app();
|
||||
$pdo = $app->pdo();
|
||||
$q = trim((string)($_GET['q'] ?? ''));
|
||||
$loc = trim((string)($_GET['loc'] ?? ''));
|
||||
$radius = isset($_GET['radius']) ? (float)$_GET['radius'] : 5.0;
|
||||
$radius = ($radius > 0) ? $radius : 5.0;
|
||||
$lat = isset($_GET['lat']) && $_GET['lat'] !== '' ? (float)$_GET['lat'] : null;
|
||||
$lng = isset($_GET['lng']) && $_GET['lng'] !== '' ? (float)$_GET['lng'] : null;
|
||||
$results = [];
|
||||
|
||||
if ($q !== '' && $pdo) {
|
||||
function geocode_loc(string $loc): array
|
||||
{
|
||||
$url = 'https://nominatim.openstreetmap.org/search?' . http_build_query([
|
||||
'format' => 'jsonv2',
|
||||
'limit' => 1,
|
||||
'q' => $loc,
|
||||
]);
|
||||
$ctx = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => "User-Agent: papa-kind-treff/1.0\r\nAccept-Language: de\r\n",
|
||||
'timeout' => 6,
|
||||
],
|
||||
]);
|
||||
$resp = @file_get_contents($url, false, $ctx);
|
||||
if ($resp === false) return [null, null];
|
||||
$json = json_decode($resp, true);
|
||||
if (!is_array($json) || empty($json[0]['lat']) || empty($json[0]['lon'])) return [null, null];
|
||||
return [round((float)$json[0]['lat'], 6), round((float)$json[0]['lon'], 6)];
|
||||
}
|
||||
|
||||
if ($pdo && ($q !== '' || $loc !== '' || ($lat !== null && $lng !== null))) {
|
||||
if ($lat === null && $lng === null && $loc !== '') {
|
||||
[$lat, $lng] = geocode_loc($loc);
|
||||
}
|
||||
$geo = ($lat !== null && $lng !== null) ? ['lat' => $lat, 'lng' => $lng, 'radius' => $radius] : null;
|
||||
$search = new \App\Search($pdo);
|
||||
$results = $search->searchEvents($q, 100);
|
||||
$results = $search->searchEvents($q, 100, $geo);
|
||||
}
|
||||
?>
|
||||
<main class="section">
|
||||
<div class="container">
|
||||
<p class="eyebrow">Suche</p>
|
||||
<h1>Events finden</h1>
|
||||
<form method="get" class="form-grid single" style="margin: 14px 0;">
|
||||
<form method="get" class="form-grid single" style="margin: 14px 0; gap:12px; align-items:end;">
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="q">Suchbegriff (Titel, Ort, Beschreibung)</label>
|
||||
<input id="q" name="q" class="input" value="<?= htmlspecialchars($q, ENT_QUOTES) ?>" placeholder="z. B. Berlin oder Spielplatz">
|
||||
</div>
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="loc">Ort oder PLZ (optional)</label>
|
||||
<input id="loc" name="loc" class="input" value="<?= htmlspecialchars($loc, ENT_QUOTES) ?>" placeholder="z. B. 10437 oder Berlin">
|
||||
<input type="hidden" name="lat" value="<?= $lat !== null ? htmlspecialchars((string)$lat, ENT_QUOTES) : '' ?>">
|
||||
<input type="hidden" name="lng" value="<?= $lng !== null ? htmlspecialchars((string)$lng, ENT_QUOTES) : '' ?>">
|
||||
</div>
|
||||
<div class="stack gap-6">
|
||||
<label class="label" for="radius">Umkreis (km)</label>
|
||||
<select id="radius" name="radius" class="select">
|
||||
<?php foreach ([1,2,5,10,15,25] as $r): ?>
|
||||
<option value="<?= $r ?>" <?= ((float)$radius === (float)$r) ? 'selected' : '' ?>><?= $r ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn" type="submit">Suchen</button>
|
||||
</form>
|
||||
|
||||
<?php if ($q === ''): ?>
|
||||
<p class="muted">Bitte gib einen Suchbegriff ein.</p>
|
||||
<?php if ($q === '' && $loc === '' && $lat === null && $lng === null): ?>
|
||||
<p class="muted">Bitte gib einen Suchbegriff oder einen Ort ein.</p>
|
||||
<?php else: ?>
|
||||
<h3 style="margin-top: 16px;"><?= count($results) ?> Ergebnis(se) für „<?= htmlspecialchars($q, ENT_QUOTES) ?>“</h3>
|
||||
<h3 style="margin-top: 16px;"><?= count($results) ?> Ergebnis(se)<?= $q !== '' ? ' für „' . htmlspecialchars($q, ENT_QUOTES) . '“' : '' ?></h3>
|
||||
<?php if (!$results): ?>
|
||||
<p class="muted">Keine passenden Events gefunden.</p>
|
||||
<?php else: ?>
|
||||
@@ -39,6 +83,9 @@ if ($q !== '' && $pdo) {
|
||||
<span>📍 <?= htmlspecialchars($ev['region'] ?: $ev['city'], ENT_QUOTES) ?></span>
|
||||
<span><?= $ev['visibility'] === 'public' ? 'Öffentlich' : 'Mitglieder' ?></span>
|
||||
<span class="badge"><?= ((int)$ev['allow_kids'] === 1) ? 'Mit Kindern' : 'Ohne Kinder' ?></span>
|
||||
<?php if (isset($ev['distance_km'])): ?>
|
||||
<span class="badge"><?= number_format((float)$ev['distance_km'], 1) ?> km</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<h3><?= htmlspecialchars($ev['title'], ENT_QUOTES) ?></h3>
|
||||
<p class="muted"><?= htmlspecialchars($ev['teaser_public'], ENT_QUOTES) ?></p>
|
||||
|
||||
Reference in New Issue
Block a user