512) $size = 512; $site_id = (int)($_GET['site_id'] ?? 0); $repo = dirname(__DIR__); $name = 'Site'; $theme = '#4C1D95'; $logo = ''; if (!function_exists('imagecreatetruecolor')) { header('HTTP/1.1 501 Not Implemented'); header('Content-Type: text/plain; charset=utf-8'); echo 'GD not available'; exit; } try { require_once $repo . '/functions/sqlfunctions.php'; if (is_file($repo . '/functions/system.php')) { require_once $repo . '/functions/system.php'; } $host = strtolower(preg_replace('/:\d+$/', '', (string)($_SERVER['HTTP_HOST'] ?? ''))); if ($site_id > 0) { $row = mysql_prepare_get( "SELECT site_id, site_name, site_color, colors, logo_url, 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.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; $theme_raw = trim((string)($row[0][2] ?? $theme)); $colors_json = (string)($row[0][3] ?? ''); $logo = trim((string)($row[0][4] ?? '')); $wiz = @json_decode((string)($row[0][5] ?? ''), true); if ($logo === '' && is_array($wiz) && !empty($wiz['logo_url'])) { $logo = 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)); } elseif (strpos($theme_raw, '#') === 0) { $theme = $theme_raw; } } } catch (Throwable $e) { // generated fallback below } function a2h_icon_hex_rgb(string $hex): array { $hex = ltrim(trim($hex), '#'); if (strlen($hex) === 3) { $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; } if (!preg_match('/^[0-9a-fA-F]{6}$/', $hex)) { return [76, 29, 149]; } return [hexdec(substr($hex, 0, 2)), hexdec(substr($hex, 2, 2)), hexdec(substr($hex, 4, 2))]; } function a2h_icon_local_logo(string $logo, string $repo): string { $logo = trim($logo); if ($logo === '') return ''; $path = ''; if (preg_match('#^https?://[^/]+(/file_repository/.+)$#i', $logo, $m)) { $path = $m[1]; } elseif (strpos($logo, '/file_repository/') === 0) { $path = $logo; } elseif (preg_match('#^file_repository/#', $logo)) { $path = '/' . $logo; } if ($path === '' || strpos($path, '..') !== false) { return ''; } $full = $repo . $path; return is_file($full) ? $full : ''; } function a2h_icon_load(string $file) { $raw = @file_get_contents($file); if ($raw === false || $raw === '') return null; $im = @imagecreatefromstring($raw); return $im ?: null; } function a2h_icon_letter_png(int $size, string $name, string $theme): void { [$r, $g, $b] = a2h_icon_hex_rgb($theme); $im = imagecreatetruecolor($size, $size); imagealphablending($im, true); $bg = imagecolorallocate($im, $r, $g, $b); imagefilledrectangle($im, 0, 0, $size - 1, $size - 1, $bg); $letter = strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', $name) ?: 'S', 0, 1)); $white = imagecolorallocate($im, 255, 255, 255); $font = 5; $fw = imagefontwidth($font) * strlen($letter); $fh = imagefontheight($font); $scale = max(8, (int)round($size / 28)); $tmp = imagecreatetruecolor($fw, $fh); $tbg = imagecolorallocate($tmp, $r, $g, $b); imagefilledrectangle($tmp, 0, 0, $fw, $fh, $tbg); imagestring($tmp, $font, 0, 0, $letter, $white); $dw = $fw * $scale; $dh = $fh * $scale; imagecopyresampled( $im, $tmp, (int)(($size - $dw) / 2), (int)(($size - $dh) / 2), 0, 0, $dw, $dh, $fw, $fh ); imagedestroy($tmp); header('Content-Type: image/png'); imagepng($im); imagedestroy($im); } function a2h_icon_from_file(string $file, int $size, string $theme): bool { $src = a2h_icon_load($file); if (!$src) return false; [$r, $g, $b] = a2h_icon_hex_rgb($theme); $out = imagecreatetruecolor($size, $size); imagealphablending($out, false); imagesavealpha($out, false); $bg = imagecolorallocate($out, $r, $g, $b); imagefilledrectangle($out, 0, 0, $size - 1, $size - 1, $bg); imagealphablending($out, true); $sw = imagesx($src); $sh = imagesy($src); if ($sw < 1 || $sh < 1) { imagedestroy($src); imagedestroy($out); return false; } $pad = (int)round($size * 0.08); $box = $size - ($pad * 2); $scale = min($box / $sw, $box / $sh); $dw = max(1, (int)round($sw * $scale)); $dh = max(1, (int)round($sh * $scale)); $dx = (int)(($size - $dw) / 2); $dy = (int)(($size - $dh) / 2); imagecopyresampled($out, $src, $dx, $dy, 0, 0, $dw, $dh, $sw, $sh); imagedestroy($src); header('Content-Type: image/png'); imagepng($out); imagedestroy($out); return true; } $local = a2h_icon_local_logo($logo, $repo); if ($local !== '' && a2h_icon_from_file($local, $size, $theme)) { exit; } a2h_icon_letter_png($size, $name, $theme); exit;