Skip to content

Commit

Permalink
Update event-date-single.json-ld.php
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr-w authored Dec 15, 2023
1 parent 04c443a commit 665ec0d
Showing 1 changed file with 56 additions and 48 deletions.
104 changes: 56 additions & 48 deletions fragments/event-date-single.json-ld.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
<?php
$date = $this->event_date;
/**
* @var rex_fragment $this
* @var event_date $date
*/
$date = $this->getVar('event_date');
$offers = $date->getOfferAll();
$location = $date->getLocation();
$schemaUrl = "https://schema.org";
$currency = rex_config::get("events", "currency");

$jsonOptions = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK;
?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Event",
"name": "<?= $date->getValue('name') ?>",
"startDate": "<?= $date->getStartDate()->format(DateTimeInterface::ATOM) ?> ",
"endDate": "<?= $date->getEndDate()->format(DateTimeInterface::ATOM) ?>",
"eventAttendanceMode": "https://schema.org/OfflineEventAttendanceMode",
"eventStatus": "https://schema.org/EventScheduled",
<?php if ($location) { ?>
"location": {
"@type": "Place",
"name": "<?= $location->getValue('name') ?>",
"address": {
"@type": "PostalAddress",
"streetAddress": "<?= $location->getValue('street') ?>",
"addressLocality": "<?= $location->getValue('locality') ?>",
"postalCode": "<?= $location->getValue('zip') ?>",
"addressCountry": "<?= $location->getValue('countrycode') ?>"
}
},
<?php } ?>
"image": "/media/<?= $date->getImage() ?>",
"description": "<?= $date->getDescriptionAsPlainText() ?>",
<?php if ($offers) { ?>
"offers":
<?php foreach ($offers as $offer) { ?>
{
"@type": "Offer",
"url": "<?= $offer->getValue('url') ?>",
"price": "<?= $offer->getValue('price') ?>",
"priceCurrency": "<?= rex_config::get("events", "currency") ?>",
"availability": "<?= $offer->getValue('availability') ?>",
"validFrom": "<?= $date->getValue('createdate') ?>"
},
<?php } ?>
<?php } ?>
"performer": {
"@type": "PerformingGroup",
"name": "<?= $date->getValue('name') ?>"
},
"organizer": {
"@type": "Organization",
"name": "<?= rex_config::get("events", "default_organizer_name") ?>",
"url": "<?= rex_yrewrite::getCurrentDomain()->getName() ?>"
}
}
</script>
{
"@context": "<?= $schemaUrl ?>",
"@type": "Event",
"name": <?= json_encode($date->getValue('name'), $jsonOptions) ?> ,
"startDate": <?= json_encode($date->getValue('start_date')->format(DateTimeInterface::ATOM), $jsonOptions) ?> ,
"endDate": <?= json_encode($date->getValue('end_date')->format(DateTimeInterface::ATOM), $jsonOptions) ?> ,
"eventAttendanceMode": "<?= $schemaUrl ?>/OfflineEventAttendanceMode",
"eventStatus": "<?= $schemaUrl ?>/EventScheduled",
<?php if ($location) { ?>
"location": {
"@type": "Place",
"name": <?= json_encode($location->getValue('name'), $jsonOptions) ?> ,
"address": {
"@type": "PostalAddress",
"streetAddress": <?= json_encode($location->getValue('street'), $jsonOptions) ?> ,
"addressLocality": <?= json_encode($location->getValue('locality'), $jsonOptions) ?> ,
"postalCode": <?= json_encode($location->getValue('zip'), $jsonOptions) ?> ,
"addressCountry": <?= json_encode($location->getValue('countrycode'), $jsonOptions) ?>
}
},
<?php } ?>
"image": "/media/<?= $date->getImage() ?>",
"description": <?= json_encode($date->getDescriptionAsPlainText(), $jsonOptions) ?> ,
<?php if ($offers) { ?>
"offers":
<?php foreach ($offers as $offer) { ?>
{
"@type": "Offer",
"url": <?= json_encode($offer->getValue('url'), $jsonOptions) ?> ,
"price": <?= json_encode($offer->getValue('price'), $jsonOptions) ?> ,
"priceCurrency": <?= json_encode($currency, $jsonOptions) ?> ,
"availability": <?= json_encode($offer->getValue('availability'), $jsonOptions) ?> ,
"validFrom": <?= json_encode($date->getValue('createdate'), $jsonOptions) ?>
},
<?php } ?>
<?php } ?>
"performer": {
"@type": "PerformingGroup",
"name": <?= json_encode($date->getValue('name'), $jsonOptions) ?>
},
"organizer": {
"@type": "Organization",
"name": <?= json_encode(rex_config::get("events", "default_organizer_name"), $jsonOptions) ?> ,
"url": <?= json_encode(rex_yrewrite::getCurrentDomain()->getName(), $jsonOptions) ?>
}
}
</script>

0 comments on commit 665ec0d

Please sign in to comment.