From 9fa448598afe36bf747b31965ae497d1c1cd686a Mon Sep 17 00:00:00 2001 From: Louis-Alexander Kerst Date: Fri, 23 Jan 2026 20:08:28 +0000 Subject: [PATCH] seo json endDate und price tag angepasst --- functions.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index f49f355..820498e 100644 --- a/functions.php +++ b/functions.php @@ -105,13 +105,16 @@ function handle_image_upload(?array $file): ?string { function render_event_jsonld_graph(array $events): string { $graph = []; foreach ($events as $e) { - $start = $e['date'] . 'T' . ($e['time'] ?? '19:30') . ':00+02:00'; // Berlin Zeit im Sommer; vereinfacht + $startTime = $e['time'] ?? '19:30'; + $start = $e['date'] . 'T' . $startTime . ':00+02:00'; // Berlin Zeit im Sommer; vereinfacht $price = $e['price'] ?? ''; + $priceValue = normalize_price_value($price); $validFrom = $e['created_at'] ?? $e['updated_at'] ?? null; + $endDate = build_event_end_date($e, $startTime); $offers = $price !== '' ? array_filter([ "@type" => "Offer", "url" => event_url($e), - "price" => preg_replace('/[^\d,\.]/', '', $price), + "price" => $priceValue, "priceCurrency" => "EUR", "availability" => "https://schema.org/InStock", "validFrom" => $validFrom @@ -122,6 +125,7 @@ function render_event_jsonld_graph(array $events): string { "name" => $e['title'], "url" => event_url($e), "startDate" => $start, + "endDate" => $endDate, "eventStatus" => "https://schema.org/EventScheduled", "eventAttendanceMode" => "https://schema.org/OfflineEventAttendanceMode", "performer" => !empty($e['speaker']) ? [ @@ -159,6 +163,34 @@ function h(?string $s): string { return htmlspecialchars($s ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); } +function normalize_price_value(string $price): ?string { + $value = preg_replace('/[^\d,\.]/', '', $price); + if ($value === '') { + return null; + } + if (substr_count($value, ',') > 0 && substr_count($value, '.') > 0) { + $value = str_replace('.', '', $value); + $value = str_replace(',', '.', $value); + } else { + $value = str_replace(',', '.', $value); + } + return rtrim($value, '.'); +} + +function build_event_end_date(array $event, string $fallbackTime): ?string { + $endDate = trim((string)($event['end_date'] ?? '')); + $endTime = trim((string)($event['end_time'] ?? '')); + $time = $endTime !== '' ? $endTime : $fallbackTime; + if ($endDate !== '') { + return $endDate . 'T' . $time . ':00+02:00'; + } + // Falls keine Endzeit gepflegt ist, nehmen wir das Startdatum, damit Schema-Validatoren zufrieden sind. + if (!empty($event['date'])) { + return $event['date'] . 'T' . $time . ':00+02:00'; + } + return null; +} + /** * Erkennt, ob HTML-Tags enthalten sind. */