block.json
1 month ago
index.asset.php
1 month ago
index.js
1 month ago
render.php
1 month ago
view.asset.php
1 month ago
view.js
1 month ago
render.php
171 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Server-side rendering for Child Author Header Block |
| 4 | */ |
| 5 | |
| 6 | $menu_slug = isset($attributes['menuSlug']) ? $attributes['menuSlug'] : ''; |
| 7 | $cta_text = isset($attributes['ctaText']) ? $attributes['ctaText'] : 'Latest Book!'; |
| 8 | $cta_url = isset($attributes['ctaUrl']) ? $attributes['ctaUrl'] : '#featured-book'; |
| 9 | |
| 10 | // Colors |
| 11 | $header_bg_color = isset($attributes['headerBgColor']) && !empty($attributes['headerBgColor']) ? $attributes['headerBgColor'] : (isset($attributes['navBgColor']) ? $attributes['navBgColor'] : ''); |
| 12 | $site_title_color = isset($attributes['siteTitleColor']) ? $attributes['siteTitleColor'] : ''; |
| 13 | $link_color = isset($attributes['linkColor']) ? $attributes['linkColor'] : ''; |
| 14 | $btn_bg_color = isset($attributes['btnBgColor']) ? $attributes['btnBgColor'] : ''; |
| 15 | $btn_text_color = isset($attributes['btnTextColor']) ? $attributes['btnTextColor'] : ''; |
| 16 | $btn_hover_bg_color = isset($attributes['btnHoverBgColor']) ? $attributes['btnHoverBgColor'] : ''; |
| 17 | $btn_hover_text_color = isset($attributes['btnHoverTextColor']) ? $attributes['btnHoverTextColor'] : ''; |
| 18 | |
| 19 | $block_id = isset($attributes['blockId']) ? $attributes['blockId'] : 'header-' . uniqid(); |
| 20 | $header_style = isset($attributes['headerStyle']) ? $attributes['headerStyle'] : 'fun'; |
| 21 | |
| 22 | // Logo |
| 23 | $logo_type = isset($attributes['logoType']) ? $attributes['logoType'] : 'custom'; |
| 24 | $logo_text = isset($attributes['logoText']) ? $attributes['logoText'] : 'Danielle Steel'; |
| 25 | $logo_image_url = isset($attributes['logoImageUrl']) ? $attributes['logoImageUrl'] : ''; |
| 26 | |
| 27 | |
| 28 | if (function_exists('rswpthemes_awt_get_menu_tree')) { |
| 29 | $menu_tree = rswpthemes_awt_get_menu_tree($menu_slug); |
| 30 | } else { |
| 31 | $menu_tree = []; |
| 32 | } |
| 33 | |
| 34 | $is_elegant = $header_style === 'elegant'; |
| 35 | |
| 36 | // --- LOGO LOGIC --- |
| 37 | $logo_content = ''; |
| 38 | if ($logo_type === 'image' && !empty($logo_image_url)) { |
| 39 | $logo_content = sprintf('<img src="%s" alt="%s" class="awt-logo-img w-32 md:w-40 h-auto" />', esc_url($logo_image_url), esc_attr(get_bloginfo('name'))); |
| 40 | } elseif ($logo_type === 'site_title') { |
| 41 | $logo_content = get_bloginfo('name'); |
| 42 | } else { |
| 43 | $logo_content = esc_html($logo_text); |
| 44 | } |
| 45 | |
| 46 | |
| 47 | // --- STYLING LOGIC --- |
| 48 | |
| 49 | // Container Classes |
| 50 | $container_classes = $is_elegant |
| 51 | ? 'bg-white/95 backdrop-blur-sm sticky top-0 z-50 border-b border-gray-200 transition-all duration-300' |
| 52 | : 'bg-white/80 backdrop-blur-sm sticky top-0 z-50 shadow-sm border-b border-yellow-sun/30 transition-all duration-300'; |
| 53 | |
| 54 | // Logo Classes |
| 55 | $logo_classes = $is_elegant |
| 56 | ? 'awt-site-title text-2xl font-serif font-bold text-slate-800 tracking-tight hover:text-slate-900 transition-colors' |
| 57 | : 'awt-site-title text-2xl md:text-3xl font-black text-navy tracking-tighter hover:text-blue-sky transition-colors'; |
| 58 | |
| 59 | // CTA Classes |
| 60 | $cta_classes = $is_elegant |
| 61 | ? 'hidden md:inline-block px-6 py-2 bg-slate-900 text-white font-medium rounded text-sm hover:bg-gray-800 transition-all awt-cta-btn' |
| 62 | : 'hidden md:inline-block btn-fun btn-yellow text-sm awt-cta-btn'; |
| 63 | |
| 64 | // Toggle Classes |
| 65 | $toggle_classes = $is_elegant |
| 66 | ? 'lg:hidden mobile-toggle-btn text-slate-800 focus:outline-none' |
| 67 | : 'lg:hidden mobile-toggle-btn text-navy hover:text-blue-sky focus:outline-none'; |
| 68 | |
| 69 | |
| 70 | // Dynamic Styles (Scoped) |
| 71 | $styles = []; |
| 72 | |
| 73 | if ($header_bg_color) { |
| 74 | $styles[] = ".block-{$block_id} { background-color: {$header_bg_color} !important; }"; |
| 75 | } |
| 76 | if ($site_title_color) { |
| 77 | $styles[] = ".block-{$block_id} .awt-site-title { color: {$site_title_color} !important; }"; |
| 78 | } |
| 79 | if ($link_color) { |
| 80 | $styles[] = ".block-{$block_id} ul li a { color: {$link_color} !important; }"; |
| 81 | // Also target mobile |
| 82 | $styles[] = ".block-{$block_id} .mobile-menu a { color: {$link_color} !important; }"; |
| 83 | } |
| 84 | if ($btn_bg_color || $btn_text_color) { |
| 85 | $bg = $btn_bg_color ? "background-color: {$btn_bg_color} !important; border-color: {$btn_bg_color} !important;" : ''; |
| 86 | $color = $btn_text_color ? "color: {$btn_text_color} !important;" : ''; |
| 87 | $styles[] = ".block-{$block_id} .awt-cta-btn { {$bg} {$color} }"; |
| 88 | } |
| 89 | if ($btn_hover_bg_color || $btn_hover_text_color) { |
| 90 | $bg = $btn_hover_bg_color ? "background-color: {$btn_hover_bg_color} !important; border-color: {$btn_hover_bg_color} !important;" : ''; |
| 91 | $color = $btn_hover_text_color ? "color: {$btn_hover_text_color} !important;" : ''; |
| 92 | $styles[] = ".block-{$block_id} .awt-cta-btn:hover { {$bg} {$color} }"; |
| 93 | } |
| 94 | |
| 95 | $scoped_style_block = !empty($styles) ? "<style>" . implode(' ', $styles) . "</style>" : ""; |
| 96 | |
| 97 | $show_cta = !empty($cta_text) && !empty($cta_url); |
| 98 | |
| 99 | // --- MENU RENDERING --- |
| 100 | |
| 101 | // Desktop Menu |
| 102 | $desktop_menu_html = ''; |
| 103 | if (function_exists('rswpthemes_awt_render_desktop_menu')) { |
| 104 | $desktop_menu_html = rswpthemes_awt_render_desktop_menu($menu_tree, 1, $link_color); |
| 105 | |
| 106 | if ($is_elegant) { |
| 107 | // Swap UL classes |
| 108 | $fun_ul = 'hidden md:flex space-x-6 lg:space-x-8 items-center font-bold text-navy/80'; |
| 109 | $ele_ul = 'hidden lg:flex space-x-8 items-center font-medium text-sm text-slate-800/80 uppercase tracking-wide'; |
| 110 | $desktop_menu_html = str_replace($fun_ul, $ele_ul, $desktop_menu_html); |
| 111 | |
| 112 | // Swap Link classes |
| 113 | $fun_link = 'hover:text-blue-sky'; |
| 114 | $ele_link = 'hover:text-slate-900 transition-colors'; |
| 115 | $desktop_menu_html = str_replace($fun_link, $ele_link, $desktop_menu_html); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Mobile Menu Default Color |
| 120 | $default_link_color = $is_elegant ? '#1e293b' : '#264653'; |
| 121 | $mobile_link_color = !empty($link_color) ? $link_color : $default_link_color; |
| 122 | ?> |
| 123 | |
| 124 | <?php echo $scoped_style_block; ?> |
| 125 | |
| 126 | <header |
| 127 | class="awt-header-block <?php echo esc_attr($container_classes); ?> block-<?php echo esc_attr($block_id); ?>"> |
| 128 | <!-- Note: nav tag gets background by default in classes, but scoped style targets it via ID if overridden --> |
| 129 | <nav class="awt-container mx-auto px-6 py-4 flex justify-between items-center relative"> |
| 130 | |
| 131 | <a href="<?php echo esc_url(home_url('/')); ?>" |
| 132 | class="<?php echo esc_attr($logo_classes); ?>"> |
| 133 | <?php echo $logo_content; ?> |
| 134 | </a> |
| 135 | |
| 136 | <?php echo $desktop_menu_html; ?> |
| 137 | |
| 138 | <div class="flex items-center gap-4"> |
| 139 | <?php if ($show_cta): ?> |
| 140 | <a href="<?php echo esc_url($cta_url); ?>" class="<?php echo esc_attr($cta_classes); ?>"> |
| 141 | <?php echo esc_html($cta_text); ?> |
| 142 | </a> |
| 143 | <?php endif; ?> |
| 144 | |
| 145 | <button id="mobile-menu-btn" |
| 146 | class="<?php echo esc_attr($toggle_classes); ?>"> |
| 147 | <svg class="w-8 h-8" fill="none" stroke="currentColor" stroke-width="2.5" viewBox="0 0 24 24"> |
| 148 | <path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16m-7 6h7"></path> |
| 149 | </svg> |
| 150 | </button> |
| 151 | </div> |
| 152 | </nav> |
| 153 | |
| 154 | <div |
| 155 | class="mobile-menu hidden lg:hidden bg-white border-t border-gray-100 absolute left-0 top-full w-full shadow-lg z-40"> |
| 156 | <?php |
| 157 | if (function_exists('rswpthemes_awt_render_mobile_menu')) { |
| 158 | echo rswpthemes_awt_render_mobile_menu($menu_tree, $mobile_link_color); |
| 159 | } |
| 160 | ?> |
| 161 | |
| 162 | <?php if ($show_cta): ?> |
| 163 | <div class="p-4 border-t border-gray-100"> |
| 164 | <a href="<?php echo esc_url($cta_url); ?>" |
| 165 | class="block text-center px-6 py-2.5 bg-yellow-sun text-navy font-black rounded-full shadow-md hover:bg-yellow-400 transition-all text-sm awt-cta-btn"> |
| 166 | <?php echo esc_html($cta_text); ?> |
| 167 | </a> |
| 168 | </div> |
| 169 | <?php endif; ?> |
| 170 | </div> |
| 171 | </header> |