Files
fitme3070.pt/site/includes/seo.php
T
2026-06-12 21:20:23 +01:00

55 lines
2.2 KiB
PHP

<?php
// JSON-LD structured data for the gym (rendered inside <head> by include.php).
// Built from fitme3070_info + work_hours so admin edits stay in sync.
$ld = [
'@context' => 'https://schema.org',
'@type' => 'ExerciseGym',
'name' => ($info['name'] ?? '') !== '' ? $info['name'] : 'FitMe 3070',
'url' => base_url(),
'image' => base_url('site/assets/img/home.jpg'),
'logo' => base_url('site/assets/img/logos/logo_black.svg'),
];
if (!empty($info['phone'])) $ld['telephone'] = $info['phone'];
if (!empty($info['email'])) $ld['email'] = $info['email'];
if (!empty($info['adress'])) {
$ld['address'] = [
'@type' => 'PostalAddress',
'streetAddress' => $info['adress'],
'addressLocality' => 'Mira',
'addressCountry' => 'PT',
];
}
if (!empty($info['google_maps_link'])) $ld['hasMap'] = $info['google_maps_link'];
$ld_same_as = array_values(array_filter([$info['facebook'] ?? '', $info['instagram'] ?? '']));
if ($ld_same_as) $ld['sameAs'] = $ld_same_as;
// Opening hours: the 'segunda' row in work_hours covers Mon-Fri (see index.php).
$ld_days = [
'segunda' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
'sabado' => ['Saturday'],
'domingo' => ['Sunday'],
];
$ld_hours = [];
foreach ((isset($GLOBALS['pdo']) ? site_work_hours($GLOBALS['pdo']) : []) as $h) {
if (!isset($ld_days[$h['week_day']])) continue;
$ld_hours[] = [
'@type' => 'OpeningHoursSpecification',
'dayOfWeek' => $ld_days[$h['week_day']],
'opens' => substr((string) $h['open'], 0, 5),
'closes' => substr((string) $h['close'], 0, 5),
];
}
if ($ld_hours) $ld['openingHoursSpecification'] = $ld_hours;
?>
<script type="application/ld+json">
<?= json_encode($ld, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ?>
</script>
<?php /* A dynamic page (e.g. an event landing page) can attach its own JSON-LD
— such as an Event schema — via this global, set before _open.php runs. */ ?>
<?php if (!empty($GLOBALS['_jsonld_extra'])): ?>
<script type="application/ld+json">
<?= json_encode($GLOBALS['_jsonld_extra'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) ?>
</script>
<?php endif; ?>