Fecha os itens 3.2.2, 3.3.1, 4.6, 5.2, 5.6, 5.7 e 7.4 do relatório de auditoria de 2026-09-24: escapa saídas de site_img_url()/canonical, valida identificadores de coluna em db_info_save(), troca 100vh por 100dvh, remove a última cor solta, encurta a transição para ~150ms, acrescenta decoding=async/fetchpriority=high nas imagens da home, e documenta as versões vendorizadas em ASSETS.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
69 lines
3.7 KiB
PHP
69 lines
3.7 KiB
PHP
<?php
|
|
// ─── Contactos (fitme3070_info, linha id=1) ───────────────────────────────────
|
|
// Single-row table read by site_info() (functions_site.php) — contact section,
|
|
// footer, mobile "Ligar" bar, WhatsApp button and the SEO JSON-LD all take their
|
|
// values from here, so one save updates every place.
|
|
// Used by views/admin/info/edit.php.
|
|
|
|
// field => [label, max length, input type]. Order is the form order.
|
|
function info_fields(): array {
|
|
return [
|
|
'name' => ['Nome do ginásio', 200, 'text'],
|
|
'adress' => ['Morada', 200, 'text'],
|
|
'phone' => ['Telefone principal', 25, 'tel'],
|
|
'telephone' => ['Telefone secundário', 25, 'tel'],
|
|
'whatsapp' => ['WhatsApp (só dígitos, ex.: 351964201137)', 13, 'text'],
|
|
'email' => ['E-mail', 100, 'email'],
|
|
'website' => ['Website', 100, 'text'],
|
|
'instagram' => ['Instagram (URL)', 200, 'url'],
|
|
'facebook' => ['Facebook (URL)', 200, 'url'],
|
|
'messenger' => ['Messenger (URL)', 200, 'url'],
|
|
'google_maps_link' => ['Google Maps — link', 255, 'url'],
|
|
'google_maps' => ['Google Maps — código embed (iframe)', 0, 'textarea'],
|
|
];
|
|
}
|
|
|
|
function info_from_post(array $post, array &$errors): array {
|
|
$data = [];
|
|
foreach (info_fields() as $key => [$label, $max, $type]) {
|
|
$v = trim((string) ($post[$key] ?? ''));
|
|
if ($key === 'whatsapp') $v = preg_replace('/\D+/', '', $v);
|
|
if ($max > 0 && mb_strlen($v) > $max) $errors[] = "«{$label}» tem mais de {$max} caracteres.";
|
|
if ($v !== '' && $type === 'email' && !filter_var($v, FILTER_VALIDATE_EMAIL)) $errors[] = 'O e-mail não é válido.';
|
|
if ($v !== '' && $type === 'url' && !preg_match('~^https?://~i', $v)) $errors[] = "«{$label}» tem de começar por https://";
|
|
$data[$key] = $v;
|
|
}
|
|
// Only a Google Maps iframe survives; anything else is dropped here rather
|
|
// than stored and filtered on every page view.
|
|
$data['google_maps'] = clean_map_embed($data['google_maps']);
|
|
if ($data['name'] === '') $errors[] = 'O nome é obrigatório.';
|
|
if ($data['phone'] === '') $errors[] = 'O telefone principal é obrigatório.';
|
|
return $data;
|
|
}
|
|
|
|
function db_info_save(PDO $pdo, array $data): bool {
|
|
$cols = array_keys(info_fields());
|
|
foreach ($cols as $c) {
|
|
if (!preg_match('/^[A-Za-z0-9_]+$/', $c)) {
|
|
throw new InvalidArgumentException("Nome de coluna inválido: $c");
|
|
}
|
|
}
|
|
// One row per gym (id = gyms.id): the gym being edited in the backoffice.
|
|
$gid = admin_gym_id();
|
|
$__before = audit_row($pdo, 'fitme3070_info', 'id', (int) $gid);
|
|
$exists = (bool) $pdo->query("SELECT COUNT(*) FROM fitme3070_info WHERE id = " . $gid)->fetchColumn();
|
|
$vals = array_map(fn($c) => $data[$c] ?? '', $cols);
|
|
if ($exists) {
|
|
$sets = implode(', ', array_map(fn($c) => "`$c` = ?", $cols));
|
|
$stmt = $pdo->prepare("UPDATE fitme3070_info SET $sets, updated_at = NOW() WHERE id = " . $gid);
|
|
} else {
|
|
$names = implode(', ', array_map(fn($c) => "`$c`", $cols));
|
|
$marks = implode(', ', array_fill(0, count($cols), '?'));
|
|
$stmt = $pdo->prepare("INSERT INTO fitme3070_info (id, $names, updated_at) VALUES (" . $gid . ", $marks, NOW())");
|
|
}
|
|
$stmt->execute($vals);
|
|
$__r = $stmt->rowCount() > 0;
|
|
audit_change($pdo, 'info', 'fitme3070_info', 'id', (int) $gid, $__before ? 'update' : 'create', $__before, 'name');
|
|
return $__r;
|
|
}
|