From 42f5919915c7b2cef28f4f13f2f8b38acb79bad9 Mon Sep 17 00:00:00 2001 From: andre Date: Thu, 24 Sep 2026 21:58:16 +0100 Subject: [PATCH] fix: telefones em formato internacional (+351) nos links tel: e no JSON-LD Co-Authored-By: Claude Opus 5.5 --- config/functions_site.php | 11 +++++++++++ site/includes/seo.php | 2 +- site/index.php | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/config/functions_site.php b/config/functions_site.php index 4476ad3..5abc3cf 100644 --- a/config/functions_site.php +++ b/config/functions_site.php @@ -126,3 +126,14 @@ function site_sitemap_urls(PDO $pdo): array { } return $urls; } + +// E.164 form for tel: links and structured data. Numbers are stored however +// the admin typed them ("964 201 137", "+351 231 451 346"); a bare 9-digit +// Portuguese number gets +351 so the link also works from a foreign phone. +function site_tel(?string $phone): string { + $p = preg_replace('/[^\d+]/', '', (string) $phone); + if ($p === '') return ''; + if ($p[0] !== '+' && strlen($p) === 9) return '+351' . $p; + if ($p[0] !== '+' && str_starts_with($p, '00')) return '+' . substr($p, 2); + return $p; +} diff --git a/site/includes/seo.php b/site/includes/seo.php index 8d4fca2..a50be38 100644 --- a/site/includes/seo.php +++ b/site/includes/seo.php @@ -9,7 +9,7 @@ $ld = [ '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['phone'])) $ld['telephone'] = site_tel($info['phone']); if (!empty($info['email'])) $ld['email'] = $info['email']; if (!empty($info['adress'])) { $ld['address'] = [ diff --git a/site/index.php b/site/index.php index 4a2745d..bd75e07 100644 --- a/site/index.php +++ b/site/index.php @@ -18,7 +18,7 @@ $reviews = site_reviews(); // null when not configured / nothin ?> @@ -587,11 +587,11 @@ $session = session();