diff --git a/config/functions_site.php b/config/functions_site.php index 5abc3cf..73b9fe6 100644 --- a/config/functions_site.php +++ b/config/functions_site.php @@ -137,3 +137,42 @@ function site_tel(?string $phone): string { if ($p[0] !== '+' && str_starts_with($p, '00')) return '+' . substr($p, 2); return $p; } + +// ─── Modalidade icon markup ─────────────────────────────────────────────────── +// The FitMe icon set (uploads/modalidades/icons/fitme-*.svg, shipped in the repo +// — backoffice uploads are always named upl_*) is inlined so CSS can animate +// the strokes: every drawable element gets pathLength="1" for the draw-in, and +// the carries data-anim, a per-family movement (see style.css). Anything +// else (legacy PNGs, uploaded SVGs) stays a plain . +function modalidade_icon_anim(string $slug): string { + $map = [ + 'lift' => ['yourfit-pump', 'crossfit', 'crossfit-teen-s', 'fbb', 'yourfit-core', 'total-workout'], + 'punch' => ['yourfit-fight', 'bootcamp'], + 'breathe' => ['yourfit-mind', 'yoga', 'pilates'], + 'bounce' => ['zumba', 'jump', 'yourfit-pulse', 'hybrid'], + 'flicker' => ['fitburn'], + 'ride' => ['cycling'], + 'run' => ['run3070', 'on-ramp', 'localizada'], + ]; + foreach ($map as $anim => $slugs) if (in_array($slug, $slugs, true)) return $anim; + return 'lift'; +} + +function modalidade_icon_html(?string $icon): string { + $icon = trim((string) $icon); + if ($icon === '') return ''; + if (preg_match('/^fitme-([a-z0-9-]+)\.svg$/', $icon, $m)) { + $file = dirname(__DIR__) . '/uploads/modalidades/icons/' . $icon; + $svg = is_file($file) ? (string) file_get_contents($file) : ''; + if (str_starts_with(ltrim($svg), '~is', '', $svg); + $svg = preg_replace('~\son\w+\s*=\s*("[^"]*"|\'[^\']*\')~i', '', $svg); + $svg = preg_replace('~\scolor="[^"]*"~', '', $svg, 1); // colour comes from CSS + $svg = preg_replace('~<(path|circle|rect|line|polyline|polygon|ellipse)\b~', '<$1 pathLength="1"', $svg); + $svg = preg_replace('~^\s*