0) { $row = mysql_prepare_get( "SELECT site_id, site_name, site_color, colors, logo_url, a2h, wizard_data FROM site_data WHERE site_id=? LIMIT 1", 'md_hub', [$site_id] ); } else { $row = mysql_prepare_get( "SELECT S.site_id, S.site_name, S.site_color, S.colors, S.logo_url, S.a2h, S.wizard_data FROM domains D INNER JOIN site_data S ON S.site_id=D.site_id WHERE D.host=? ORDER BY D.domain_id ASC LIMIT 1", 'md_hub', [$host] ); } if (isset($row[0][0])) { $site_id = (int)$row[0][0]; $name = trim((string)($row[0][1] ?? '')) ?: $name; $short = mb_strlen($name) > 12 ? (mb_substr($name, 0, 12)) : $name; $theme_raw = trim((string)($row[0][2] ?? '#4C1D95')); $colors_json = (string)($row[0][3] ?? ''); $icon = trim((string)($row[0][4] ?? '')); $a2h_on = !empty($row[0][5]); $wiz = @json_decode((string)($row[0][6] ?? ''), true); if ($icon === '' && is_array($wiz) && !empty($wiz['logo_url'])) { $icon = trim((string)$wiz['logo_url']); } if ($colors_json !== '') { $dec = @json_decode($colors_json, true); if (is_array($dec) && !empty($dec[0])) { $theme_raw = (string)$dec[0]; } } if (function_exists('sites_color_to_hex') && function_exists('sites_normalize_color')) { $theme = sites_color_to_hex(sites_normalize_color($theme_raw)); } else { $theme = (strpos($theme_raw, '#') === 0) ? $theme_raw : '#4C1D95'; } } } catch (Throwable $e) { // defaults } // iOS Add to Home Screen needs a real PNG (not JPEG labeled .png, not SVG). $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; $png = $scheme . '://' . $host . '/public/a2h-icon.php?site_id=' . (int)$site_id; $icons = [ ['src' => $png . '&size=180', 'sizes' => '180x180', 'type' => 'image/png', 'purpose' => 'any'], ['src' => $png . '&size=192', 'sizes' => '192x192', 'type' => 'image/png', 'purpose' => 'any'], ['src' => $png . '&size=512', 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'any'], ['src' => $png . '&size=192', 'sizes' => '192x192', 'type' => 'image/png', 'purpose' => 'maskable'], ['src' => $png . '&size=512', 'sizes' => '512x512', 'type' => 'image/png', 'purpose' => 'maskable'], ]; $manifest = [ 'id' => $site_id > 0 ? ('/?site=' . $site_id) : '/', 'name' => $name, 'short_name' => $short, 'description' => $name . ' — install for quick access', 'start_url' => '/', 'scope' => '/', 'display' => 'standalone', 'orientation' => 'any', 'background_color' => $bg, 'theme_color' => $theme, 'icons' => $icons, 'categories' => ['business', 'productivity'], 'prefer_related_applications' => false, ]; // Even if A2H flag is off, still return a valid manifest (install prompt only when flag on) echo json_encode($manifest, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);