seo json endDate und price tag angepasst

This commit is contained in:
2026-01-23 20:08:28 +00:00
parent 4befb5e619
commit 9fa448598a
+34 -2
View File
@@ -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.
*/