?php
require_once __DIR__ . '/config/db.php';
require_once __DIR__ . '/includes/auth.php';
start_session();
$db = get_db();
$logged_in_user = is_logged_in() ? get_logged_in_user() : null;
$username = trim($_GET['u'] ?? '');
if (!$username) { header('Location: /'); exit; }
$stmt = $db->prepare("SELECT u.*, cp.* FROM users u JOIN creator_profiles cp ON u.id = cp.user_id WHERE u.username = ? AND u.is_active = 1");
$stmt->execute([$username]);
$creator = $stmt->fetch();
if (!$creator) { http_response_code(404); echo '
Creator not found
'; exit; }
$sections_q = $db->prepare("SELECT * FROM profile_sections WHERE user_id=? AND is_visible=1 ORDER BY sort_order");
$sections_q->execute([$creator['user_id']]);
$visible_sections = array_column($sections_q->fetchAll(), 'section_type');
if (empty($visible_sections)) $visible_sections = ['hero','about','galleries'];
$galleries = $db->prepare("SELECT g.*, COUNT(gi.id) as item_count FROM galleries g LEFT JOIN gallery_items gi ON g.id = gi.gallery_id WHERE g.user_id=? GROUP BY g.id ORDER BY g.created_at DESC LIMIT 12");
$galleries->execute([$creator['user_id']]);
$galleries = $galleries->fetchAll();
$links = $db->prepare("SELECT * FROM custom_links WHERE user_id=? AND is_active=1 ORDER BY sort_order, id");
$links->execute([$creator['user_id']]);
$links = $links->fetchAll();
$prices = $db->prepare("SELECT * FROM pricing_items WHERE user_id=? AND is_active=1 ORDER BY sort_order, id");
$prices->execute([$creator['user_id']]);
$prices = $prices->fetchAll();
$texts = $db->prepare("SELECT * FROM text_blocks WHERE user_id=? AND is_active=1 ORDER BY sort_order, id");
$texts->execute([$creator['user_id']]);
$texts = $texts->fetchAll();
$pinned = $db->prepare("SELECT * FROM cloud_files WHERE user_id=? AND pinned_to_profile=1 AND is_public=1 ORDER BY created_at DESC LIMIT 6");
$pinned->execute([$creator['user_id']]);
$pinned = $pinned->fetchAll();
// Customization values
$accent = $creator['accent_color'] ?? '#c9a96e';
$bg_color = $creator['background_color'] ?? '#0a0a0a';
$txt_color= $creator['text_color'] ?? '#f0ebe3';
$bg_image = $creator['background_image'] ?? null;
$bg_music = $creator['background_music'] ?? null;
$hfont = $creator['heading_font'] ?? 'cormorant';
$bfont = $creator['font_choice'] ?? 'jost';
$tagline = $creator['tagline'] ?? '';
$btn_style= $creator['button_style'] ?? 'pill';
$avatar_shape = $creator['avatar_shape'] ?? 'circle';
$card_style = $creator['card_style'] ?? 'solid';
$layout_width = $creator['layout_width'] ?? 'standard';
$animated_bg = $creator['animated_bg'] ?? 0;
$font_imports = [
'inter' => 'Inter:wght@300;400;500;600', 'jost' => 'Jost:wght@300;400;500',
'playfair' => 'Playfair+Display:wght@400;700;900', 'poppins' => 'Poppins:wght@300;400;500;600',
'montserrat' => 'Montserrat:wght@300;400;500;600', 'lora' => 'Lora:wght@400;500;600',
'dancing' => 'Dancing+Script:wght@400;700', 'greatvibes' => 'Great+Vibes',
'bebas' => 'Bebas+Neue', 'oswald' => 'Oswald:wght@300;400;500',
'cormorant'=> 'Cormorant+Garamond:wght@300;400;500;600',
];
$font_css = [
'inter' => "'Inter',sans-serif", 'jost' => "'Jost',sans-serif",
'playfair' => "'Playfair Display',serif", 'poppins' => "'Poppins',sans-serif",
'montserrat' => "'Montserrat',sans-serif", 'lora' => "'Lora',serif",
'dancing' => "'Dancing Script',cursive", 'greatvibes' => "'Great Vibes',cursive",
'bebas' => "'Bebas Neue',sans-serif", 'oswald' => "'Oswald',sans-serif",
'cormorant'=> "'Cormorant Garamond',serif",
];
$hfi = $font_imports[$hfont] ?? $font_imports['cormorant'];
$bfi = $font_imports[$bfont] ?? $font_imports['jost'];
$hfc = $font_css[$hfont] ?? $font_css['cormorant'];
$bfc = $font_css[$bfont] ?? $font_css['jost'];
// Button radius based on style
$btn_radius = $btn_style === 'pill' ? '50px' : ($btn_style === 'rounded' ? '6px' : '0px');
// Avatar shape CSS
$avatar_css = '';
if ($avatar_shape === 'circle') $avatar_css = 'border-radius:50%;';
elseif ($avatar_shape === 'rounded') $avatar_css = 'border-radius:18px;';
elseif ($avatar_shape === 'hexagon') $avatar_css = 'border-radius:0;clip-path:polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%);';
// Card style
$card_bg = 'rgba(17,17,17,0.95)';
$card_border = '1px solid rgba(255,255,255,0.08)';
$card_blur = '';
if ($card_style === 'glass') { $card_bg = 'rgba(255,255,255,0.04)'; $card_blur = 'backdrop-filter:blur(16px);-webkit-backdrop-filter:blur(16px);'; $card_border = '1px solid rgba(255,255,255,0.12)'; }
elseif ($card_style === 'bordered') { $card_bg = 'transparent'; $card_border = '1px solid var(--accent)'; }
// Layout width
$max_w = $layout_width === 'narrow' ? '520px' : ($layout_width === 'wide' ? '860px' : '680px');
?>
— HerHost