render.php
739 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Book Details Block - Server-Side Render |
| 4 | * * Displays comprehensive book information with a 2-column layout. |
| 5 | * Replicates the exact logic from single-book.php for consistency. |
| 6 | * * @package Author_Website_Templates |
| 7 | * @since 1.0.9 |
| 8 | */ |
| 9 | |
| 10 | // Prevent direct access |
| 11 | if (!defined('ABSPATH')) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | // Extract block attributes |
| 16 | $show_gallery = isset($attributes['showGallery']) ? (bool) $attributes['showGallery'] : true; |
| 17 | $show_meta = isset($attributes['showMeta']) ? (bool) $attributes['showMeta'] : true; |
| 18 | $show_buy_buttons = isset($attributes['showBuyButtons']) ? (bool) $attributes['showBuyButtons'] : true; |
| 19 | $show_description = isset($attributes['showDescription']) ? (bool) $attributes['showDescription'] : true; |
| 20 | $show_price = isset($attributes['showPrice']) ? (bool) $attributes['showPrice'] : true; |
| 21 | $show_formats = isset($attributes['showFormats']) ? (bool) $attributes['showFormats'] : true; |
| 22 | |
| 23 | // Design attributes |
| 24 | $section_bg_color = isset($attributes['sectionBgColor']) ? esc_attr($attributes['sectionBgColor']) : '#FFFDF5'; |
| 25 | $title_color = isset($attributes['titleColor']) ? esc_attr($attributes['titleColor']) : '#264653'; |
| 26 | $accent_color = isset($attributes['accentColor']) ? esc_attr($attributes['accentColor']) : '#EF476F'; |
| 27 | $btn_bg_color = isset($attributes['btnBgColor']) ? esc_attr($attributes['btnBgColor']) : '#FFD166'; |
| 28 | |
| 29 | // Label attributes |
| 30 | $label_back = isset($attributes['labelBack']) ? $attributes['labelBack'] : __('Back to All Books', 'author-website-templates'); |
| 31 | $label_latest = isset($attributes['labelLatest']) ? $attributes['labelLatest'] : __('Latest Release!', 'author-website-templates'); |
| 32 | $label_illustrated = isset($attributes['labelIllustrated']) ? $attributes['labelIllustrated'] : __('Illustrated by', 'author-website-templates'); |
| 33 | $label_order = isset($attributes['labelOrder']) ? $attributes['labelOrder'] : __('Order Your Copy!', 'author-website-templates'); |
| 34 | $label_peek = isset($attributes['labelPeek']) ? $attributes['labelPeek'] : __('A Peek Inside!', 'author-website-templates'); |
| 35 | $label_about = isset($attributes['labelAbout']) ? $attributes['labelAbout'] : __('About the Book', 'author-website-templates'); |
| 36 | $label_details = isset($attributes['labelDetails']) ? $attributes['labelDetails'] : __('Book Details', 'author-website-templates'); |
| 37 | |
| 38 | // Get current post ID and check context |
| 39 | $book_id = null; |
| 40 | |
| 41 | if ( ! empty( $attributes['bookId'] ) ) { |
| 42 | $book_id = intval( $attributes['bookId'] ); |
| 43 | } elseif ( is_singular( 'book' ) ) { |
| 44 | $book_id = get_the_ID(); |
| 45 | } |
| 46 | |
| 47 | // Variables init |
| 48 | $book_data = []; |
| 49 | |
| 50 | // Show placeholder if no Book ID is found |
| 51 | if ( ! $book_id && ! ( defined('REST_REQUEST') && REST_REQUEST ) && ! is_admin() ) { |
| 52 | if ( current_user_can( 'edit_posts' ) ) { |
| 53 | echo '<div class="awt-placeholder p-4 bg-yellow-50 border border-yellow-200 text-yellow-800 rounded text-center">'; |
| 54 | echo '<strong>' . esc_html__( 'Note:', 'author-website-templates' ) . '</strong> ' . esc_html__( 'Please provide a Book ID in the block settings or utilize this block on a Book single page.', 'author-website-templates' ); |
| 55 | echo '</div>'; |
| 56 | } |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | $is_book = get_post_type($book_id) === 'book'; |
| 61 | $use_placeholder = !$is_book || is_admin() || (defined('REST_REQUEST') && REST_REQUEST); |
| 62 | |
| 63 | if (!$use_placeholder) { |
| 64 | // --- REAL DATA FETCHING (Copied from single-book.php) --- |
| 65 | |
| 66 | // Title & Cover |
| 67 | $book_data['title'] = get_the_title($book_id); |
| 68 | $book_data['cover_url'] = get_the_post_thumbnail_url($book_id, 'large'); |
| 69 | |
| 70 | // Author/Illustrator Logic |
| 71 | $author_terms = get_the_terms($book_id, 'book-author'); |
| 72 | $author_name = ''; |
| 73 | if ($author_terms && !is_wp_error($author_terms)) { |
| 74 | $author_name = $author_terms[0]->name; |
| 75 | } else { |
| 76 | $author_name = get_post_meta($book_id, '_rsbs_book_translator', true); |
| 77 | } |
| 78 | $book_data['author_name'] = empty($author_name) ? __('Unknown Author', 'author-website-templates') : $author_name; |
| 79 | |
| 80 | // Description |
| 81 | $description = get_post_meta($book_id, '_rsbs_short_description', true); |
| 82 | if (empty($description)) { |
| 83 | $description = get_the_content(null, false, $book_id); |
| 84 | } |
| 85 | if (empty($description)) { |
| 86 | $description = get_the_excerpt($book_id); |
| 87 | } |
| 88 | $book_data['description'] = $description; |
| 89 | |
| 90 | // Buy Buttons |
| 91 | $book_data['primary_btn_text'] = get_post_meta($book_id, '_rsbs_buy_btn_text', true); |
| 92 | $book_data['primary_btn_link'] = get_post_meta($book_id, '_rsbs_buy_btn_link', true); |
| 93 | $book_data['additional_stores'] = get_post_meta($book_id, 'rswpbs_also_available_website_list', true); |
| 94 | |
| 95 | // Price |
| 96 | $book_data['regular_price'] = get_post_meta($book_id, '_rsbs_book_price', true); |
| 97 | $book_data['sale_price'] = get_post_meta($book_id, '_rsbs_book_sale_price', true); |
| 98 | |
| 99 | $currenySign = '$'; |
| 100 | $currenySign = get_option('rswpbs_price_currency', '$'); |
| 101 | if (null === $currenySign) { |
| 102 | $currenySign = '$'; |
| 103 | } |
| 104 | // Formats |
| 105 | $book_data['formats'] = get_post_meta($book_id, 'rswpbs_book_formats', true); |
| 106 | |
| 107 | // Gallery |
| 108 | $book_data['gallery_images'] = get_post_meta($book_id, 'rswpbs_book_sample_content', true); |
| 109 | |
| 110 | // Book Details List (Exact Logic from single-book.php) |
| 111 | // Assuming helper functions like rswpbs_get_book_reading_age might not be available in block context context, |
| 112 | // we use direct get_post_meta calls with the keys from register-cmb.php. |
| 113 | |
| 114 | $book_info_fields = [ |
| 115 | 'availability' => [ |
| 116 | 'value' => rswpbs_get_book_availability_status($book_id), |
| 117 | 'label' => rswpbs_static_text_availability(), |
| 118 | 'condition' => function ($value) { |
| 119 | return !empty($value) && $value !== 'blank'; |
| 120 | } |
| 121 | ], |
| 122 | 'original_title' => [ |
| 123 | 'value' => rswpbs_get_book_original_name($book_id), |
| 124 | 'label' => rswpbs_static_text_original_title(), |
| 125 | 'wrapper' => function ($value) { |
| 126 | $url = rswpbs_get_book_original_url(); |
| 127 | return $url ? "<a href='" . esc_url($url) . "'>" . esc_html($value) . "</a>" : esc_html($value); |
| 128 | } |
| 129 | ], |
| 130 | 'categories' => [ |
| 131 | 'value' => rswpbs_get_book_categories($book_id), |
| 132 | 'label' => rswpbs_static_text_categories(), |
| 133 | 'escape' => 'wp_kses_post' |
| 134 | ], |
| 135 | 'series' => [ |
| 136 | 'value' => rswpbs_get_book_series($book_id), |
| 137 | 'label' => rswpbs_static_text_series(), |
| 138 | 'escape' => 'wp_kses_post' |
| 139 | ], |
| 140 | 'publish_date' => [ |
| 141 | 'value' => rswpbs_get_book_publish_date($book_id), |
| 142 | 'label' => rswpbs_static_text_publish_date() |
| 143 | ], |
| 144 | 'publish_year' => [ |
| 145 | 'value' => rswpbs_get_book_publish_year($book_id), |
| 146 | 'label' => rswpbs_static_text_published_year(), |
| 147 | 'condition' => function () { |
| 148 | return !empty(rswpbs_get_book_publish_date()); |
| 149 | } |
| 150 | ], |
| 151 | 'publisher' => [ |
| 152 | 'value' => esc_html(rswpbs_get_book_publisher_name($book_id)), |
| 153 | 'label' => rswpbs_static_text_publisher_name(), |
| 154 | 'escape' => false |
| 155 | ], |
| 156 | 'pages' => [ |
| 157 | 'value' => rswpbs_get_book_pages($book_id), |
| 158 | 'label' => rswpbs_static_text_total_pages() |
| 159 | ], |
| 160 | 'isbn' => [ |
| 161 | 'value' => rswpbs_get_book_isbn($book_id), |
| 162 | 'label' => rswpbs_static_text_isbn() |
| 163 | ], |
| 164 | 'isbn_10' => [ |
| 165 | 'value' => rswpbs_get_book_isbn_10($book_id), |
| 166 | 'label' => rswpbs_static_text_isbn_10() |
| 167 | ], |
| 168 | 'isbn_13' => [ |
| 169 | 'value' => rswpbs_get_book_isbn_13($book_id), |
| 170 | 'label' => rswpbs_static_text_isbn_13() |
| 171 | ], |
| 172 | 'asin' => [ |
| 173 | 'value' => rswpbs_get_book_asin($book_id), |
| 174 | 'label' => rswpbs_static_text_asin() |
| 175 | ], |
| 176 | 'format' => [ |
| 177 | 'value' => rswpbs_get_book_format($book_id), |
| 178 | 'label' => rswpbs_static_text_format() |
| 179 | ], |
| 180 | 'country' => [ |
| 181 | 'value' => rswpbs_get_book_country($book_id), |
| 182 | 'label' => rswpbs_static_text_country() |
| 183 | ], |
| 184 | 'language' => [ |
| 185 | 'value' => rswpbs_get_book_language($book_id), |
| 186 | 'label' => rswpbs_static_text_language() |
| 187 | ], |
| 188 | 'translator' => [ |
| 189 | 'value' => rswpbs_get_book_translator($book_id), |
| 190 | 'label' => rswpbs_static_text_translator() |
| 191 | ], |
| 192 | 'file_size' => [ |
| 193 | 'value' => rswpbs_get_book_file_size($book_id), |
| 194 | 'label' => rswpbs_static_text_file_size() |
| 195 | ], |
| 196 | 'dimension' => [ |
| 197 | 'value' => rswpbs_get_book_dimension($book_id), |
| 198 | 'label' => rswpbs_static_text_dimension() |
| 199 | ], |
| 200 | 'weight' => [ |
| 201 | 'value' => rswpbs_get_book_weight($book_id), |
| 202 | 'label' => rswpbs_static_text_weight() |
| 203 | ], |
| 204 | 'file_format' => [ |
| 205 | 'value' => rswpbs_get_book_file_format($book_id), |
| 206 | 'label' => rswpbs_static_text_file_format() |
| 207 | ], |
| 208 | 'simultaneous_device_usage' => [ |
| 209 | 'value' => rswpbs_get_simultaneous_device_usage($book_id), |
| 210 | 'label' => rswpbs_static_text_simultaneous_device_usage() |
| 211 | ], |
| 212 | 'text_to_speech' => [ |
| 213 | 'value' => rswpbs_get_book_text_to_speech($book_id), |
| 214 | 'label' => rswpbs_static_text_text_to_speech() |
| 215 | ], |
| 216 | 'screen_reader' => [ |
| 217 | 'value' => rswpbs_get_screen_reader($book_id), |
| 218 | 'label' => rswpbs_static_text_screen_reader() |
| 219 | ], |
| 220 | 'enhanced_typesetting' => [ |
| 221 | 'value' => rswpbs_get_enhanced_typesetting($book_id), |
| 222 | 'label' => rswpbs_static_text_enhanced_typesetting() |
| 223 | ], |
| 224 | 'x_ray' => [ |
| 225 | 'value' => rswpbs_get_x_ray($book_id), |
| 226 | 'label' => rswpbs_static_text_x_ray() |
| 227 | ], |
| 228 | 'word_wise' => [ |
| 229 | 'value' => rswpbs_get_word_wise($book_id), |
| 230 | 'label' => rswpbs_static_text_word_wise() |
| 231 | ], |
| 232 | 'sticky_notes' => [ |
| 233 | 'value' => rswpbs_get_sticky_notes($book_id), |
| 234 | 'label' => rswpbs_static_text_sticky_notes() |
| 235 | ], |
| 236 | 'print_length' => [ |
| 237 | 'value' => rswpbs_get_print_length($book_id), |
| 238 | 'label' => rswpbs_static_text_print_length() |
| 239 | ], |
| 240 | 'avg_rate' => [ |
| 241 | 'value' => rswpbs_get_avg_rate($book_id), |
| 242 | 'label' => rswpbs_static_text_avarage_ratings(), |
| 243 | 'escape' => 'wp_kses_post' |
| 244 | ], |
| 245 | 'reading_date' => [ |
| 246 | 'value' => rswpbs_get_book_reading_date($book_id), |
| 247 | 'label' => rswpbs_static_text_reading_date(), |
| 248 | 'escape' => 'wp_kses_post' |
| 249 | ] |
| 250 | ]; |
| 251 | $book_data['details'] = $book_info_fields; |
| 252 | |
| 253 | } else { |
| 254 | // --- PLACEHOLDER DATA (For Editor Preview) --- |
| 255 | $book_data = [ |
| 256 | 'title' => __('The Magical Adventure', 'author-website-templates'), |
| 257 | 'cover_url' => RSWPTHEMES_AWT_PLUGIN_URL . 'includes/assets/images/book-placeholder.png', |
| 258 | 'author_name' => 'Jane Doe', |
| 259 | 'description' => __('Join our hero on an incredible journey through magical lands. Perfect for young readers!', 'author-website-templates'), |
| 260 | 'primary_btn_text' => 'Buy Now', |
| 261 | 'primary_btn_link' => '#', |
| 262 | 'additional_stores' => [ |
| 263 | ['website_name' => 'Amazon', 'book_url' => '#'], |
| 264 | ['website_name' => 'Barnes & Noble', 'book_url' => '#'] |
| 265 | ], |
| 266 | 'regular_price' => '$19.99', |
| 267 | 'sale_price' => '$14.99', |
| 268 | 'formats' => [ |
| 269 | ['format_name' => 'Hardcover', 'format_price' => '$19.99'], |
| 270 | ['format_name' => 'Kindle', 'format_price' => '$9.99'] |
| 271 | ], |
| 272 | 'gallery_images' => [ |
| 273 | ['upload_image' => RSWPTHEMES_AWT_PLUGIN_URL . 'includes/assets/images/book-placeholder.png'], |
| 274 | ['upload_image' => RSWPTHEMES_AWT_PLUGIN_URL . 'includes/assets/images/book-placeholder.png'] |
| 275 | ], |
| 276 | 'details' => [ |
| 277 | 'availability' => [ |
| 278 | 'value' => 'In Stock', |
| 279 | 'label' => 'Availability:', |
| 280 | ], |
| 281 | 'categories' => [ |
| 282 | 'value' => 'Fantasy, Adventure', |
| 283 | 'label' => 'Categories:', |
| 284 | 'escape' => 'wp_kses_post' |
| 285 | ], |
| 286 | 'series' => [ |
| 287 | 'value' => 'Magic World Series', |
| 288 | 'label' => 'Series:', |
| 289 | 'escape' => 'wp_kses_post' |
| 290 | ], |
| 291 | 'publish_date' => [ |
| 292 | 'value' => '2024-01-12', |
| 293 | 'label' => 'Publish Date:' |
| 294 | ], |
| 295 | 'publish_year' => [ |
| 296 | 'value' => '2024', |
| 297 | 'label' => 'Published Year:' |
| 298 | ], |
| 299 | 'publisher' => [ |
| 300 | 'value' => "<a href='#'>Example Press</a>", |
| 301 | 'label' => 'Publisher:', |
| 302 | 'escape' => false |
| 303 | ], |
| 304 | 'pages' => [ |
| 305 | 'value' => '32', |
| 306 | 'label' => 'Total Pages:' |
| 307 | ], |
| 308 | 'isbn' => [ |
| 309 | 'value' => '978-1234567890', |
| 310 | 'label' => 'ISBN:' |
| 311 | ], |
| 312 | 'asin' => [ |
| 313 | 'value' => 'B0TESTASIN', |
| 314 | 'label' => 'ASIN:' |
| 315 | ], |
| 316 | 'format' => [ |
| 317 | 'value' => 'Hardcover', |
| 318 | 'label' => 'Format:' |
| 319 | ], |
| 320 | 'country' => [ |
| 321 | 'value' => 'USA', |
| 322 | 'label' => 'Country:' |
| 323 | ], |
| 324 | 'language' => [ |
| 325 | 'value' => 'English', |
| 326 | 'label' => 'Language:' |
| 327 | ], |
| 328 | 'translator' => [ |
| 329 | 'value' => 'N/A', |
| 330 | 'label' => 'Translator:' |
| 331 | ], |
| 332 | ] |
| 333 | |
| 334 | ]; |
| 335 | } |
| 336 | |
| 337 | // Fallback for missing cover |
| 338 | // Fallback for missing cover |
| 339 | if (empty($book_data['cover_url'])) { |
| 340 | $book_data['cover_url'] = RSWPTHEMES_AWT_PLUGIN_URL . 'includes/assets/images/book-placeholder.png'; |
| 341 | } |
| 342 | |
| 343 | // Back Link URL |
| 344 | $books_archive_url = get_post_type_archive_link('book'); |
| 345 | |
| 346 | // CSS Variables for Container |
| 347 | $css_variables = [ |
| 348 | '--awt-section-bg' => $section_bg_color, |
| 349 | '--awt-title-color' => $title_color, |
| 350 | '--awt-accent-color' => $accent_color, |
| 351 | '--awt-btn-bg' => $btn_bg_color, |
| 352 | ]; |
| 353 | $style_attr = ''; |
| 354 | foreach ($css_variables as $var => $value) { |
| 355 | if (!empty($value)) { |
| 356 | $style_attr .= "{$var}: {$value}; "; |
| 357 | } |
| 358 | } |
| 359 | ?> |
| 360 | |
| 361 | <div class="awt-book-details-container" style="<?php echo esc_attr($style_attr); ?>"> |
| 362 | |
| 363 | <?php if (isset($attributes['detailsStyle']) && $attributes['detailsStyle'] === 'elegant'): ?> |
| 364 | |
| 365 | <!-- ELEGANT STYLE --> |
| 366 | <section class="py-16 md:py-24 border-b border-gray-100" style="background-color: var(--awt-section-bg);"> |
| 367 | <div class="awt-container container mx-auto px-6 max-w-6xl"> |
| 368 | <?php if (!$use_placeholder && $books_archive_url): ?> |
| 369 | <a href="<?php echo esc_url($books_archive_url); ?>" |
| 370 | class="text-slate-500 hover:text-slate-900 font-medium text-sm mb-8 inline-flex items-center transition-colors" |
| 371 | style="color: var(--awt-accent-color);"> |
| 372 | <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"></path></svg> |
| 373 | <?php echo esc_html($label_back); ?> |
| 374 | </a> |
| 375 | <?php endif; ?> |
| 376 | |
| 377 | <div class="grid grid-cols-1 lg:grid-cols-12 gap-12 lg:gap-16 items-start"> |
| 378 | |
| 379 | <!-- LEFT COL: Cover & Gallery --> |
| 380 | <div class="lg:col-span-5 space-y-8"> |
| 381 | <div class="relative group"> |
| 382 | <img src="<?php echo esc_url($book_data['cover_url']); ?>" |
| 383 | alt="<?php echo esc_attr(sprintf(__('Book cover for %s', 'author-website-templates'), $book_data['title'])); ?>" |
| 384 | class="rounded shadow-xl w-full mx-auto hover:shadow-2xl transition-all duration-300"> |
| 385 | </div> |
| 386 | |
| 387 | <?php if ($show_gallery && !empty($book_data['gallery_images'])): |
| 388 | // Check for valid images |
| 389 | $valid_images = []; |
| 390 | if(is_array($book_data['gallery_images'])){ |
| 391 | foreach($book_data['gallery_images'] as $img){ |
| 392 | if(is_array($img) && !empty($img['upload_image'])) $valid_images[] = $img['upload_image']; |
| 393 | elseif(is_string($img) && !empty($img)) $valid_images[] = $img; |
| 394 | } |
| 395 | } |
| 396 | ?> |
| 397 | <?php if (!empty($valid_images)): ?> |
| 398 | <div> |
| 399 | <h4 class="text-sm font-bold text-slate-800 uppercase tracking-widest mb-4 border-b border-gray-200 pb-2" style="color: var(--awt-title-color);"> |
| 400 | <?php echo esc_html($label_peek); ?> |
| 401 | </h4> |
| 402 | <div class="grid grid-cols-3 gap-4"> |
| 403 | <?php foreach ($valid_images as $img_url): ?> |
| 404 | <img src="<?php echo esc_url($img_url); ?>" alt="Interior art" class="rounded shadow-sm hover:opacity-80 transition-opacity cursor-pointer"> |
| 405 | <?php endforeach; ?> |
| 406 | </div> |
| 407 | </div> |
| 408 | <?php endif; ?> |
| 409 | <?php endif; ?> |
| 410 | </div> |
| 411 | |
| 412 | <!-- RIGHT COL: Details --> |
| 413 | <div class="lg:col-span-7 space-y-10"> |
| 414 | <div> |
| 415 | <span class="inline-block py-1 px-3 bg-slate-800 text-white text-xs font-bold uppercase tracking-wider rounded mb-4" style="background-color: var(--awt-title-color);"> |
| 416 | <?php echo esc_html($label_latest); ?> |
| 417 | </span> |
| 418 | <h1 class="text-4xl md:text-5xl font-serif font-bold text-slate-800 mb-4 leading-tight" style="color: var(--awt-title-color);"> |
| 419 | <?php echo esc_html($book_data['title']); ?> |
| 420 | </h1> |
| 421 | <p class="text-xl text-slate-500 font-light"> |
| 422 | <?php echo esc_html($label_illustrated); ?> <span class="font-bold text-slate-800" style="color: var(--awt-title-color);"><?php echo esc_html($book_data['author_name']); ?></span> |
| 423 | </p> |
| 424 | |
| 425 | <?php if ($show_price && (!empty($book_data['regular_price']) || !empty($book_data['sale_price']))): |
| 426 | $book_data['regular_price'] = str_replace('$', '', $book_data['regular_price']); |
| 427 | $book_data['sale_price'] = str_replace('$', '', $book_data['sale_price']); |
| 428 | ?> |
| 429 | <div class="mt-4 text-lg font-bold"> |
| 430 | <?php if (!empty($book_data['sale_price'])): ?> |
| 431 | <span class="line-through text-slate-400 mr-2"><?php echo esc_html($currenySign . $book_data['regular_price']); ?></span> |
| 432 | <span class="text-2xl text-slate-900" style="color: var(--awt-accent-color);"><?php echo esc_html($currenySign . $book_data['sale_price']); ?></span> |
| 433 | <?php else: ?> |
| 434 | <span class="text-2xl text-slate-900" style="color: var(--awt-accent-color);"><?php echo esc_html($currenySign . $book_data['regular_price']); ?></span> |
| 435 | <?php endif; ?> |
| 436 | </div> |
| 437 | <?php endif; ?> |
| 438 | </div> |
| 439 | |
| 440 | <?php if ($show_buy_buttons): ?> |
| 441 | <div class="bg-white p-8 rounded border border-gray-200 shadow-sm"> |
| 442 | <h3 class="text-lg font-bold text-slate-800 mb-6 text-center uppercase tracking-wide" style="color: var(--awt-title-color);"> |
| 443 | <?php echo esc_html($label_order); ?> |
| 444 | </h3> |
| 445 | <div class="grid grid-cols-2 md:grid-cols-3 gap-4"> |
| 446 | <?php if (!empty($book_data['primary_btn_link'])): ?> |
| 447 | <a href="<?php echo esc_url($book_data['primary_btn_link']); ?>" |
| 448 | class="px-6 py-3 rounded font-medium transition-all duration-300 ease-in-out border border-transparent text-sm uppercase tracking-wider text-center bg-slate-900 text-white hover:bg-slate-800 shadow-sm hover:shadow-md" |
| 449 | style="background-color: var(--awt-btn-bg); color: var(--awt-title-color);"> |
| 450 | <?php echo esc_html(!empty($book_data['primary_btn_text']) ? $book_data['primary_btn_text'] : __('Buy Now', 'author-website-templates')); ?> |
| 451 | </a> |
| 452 | <?php endif; ?> |
| 453 | |
| 454 | <?php if (!empty($book_data['additional_stores']) && is_array($book_data['additional_stores'])): ?> |
| 455 | <?php foreach ($book_data['additional_stores'] as $store): |
| 456 | $store_name = isset($store['website_name']) ? $store['website_name'] : ''; |
| 457 | $store_url = isset($store['book_url']) ? $store['book_url'] : ''; |
| 458 | if (empty($store_name) || empty($store_url)) continue; |
| 459 | ?> |
| 460 | <a href="<?php echo esc_url($store_url); ?>" |
| 461 | class="px-6 py-3 rounded font-medium transition-all duration-300 ease-in-out border border-gray-200 text-sm uppercase tracking-wider text-center bg-white text-slate-800 hover:border-slate-800 hover:bg-gray-50" |
| 462 | target="_blank"> |
| 463 | <?php echo esc_html($store_name); ?> |
| 464 | </a> |
| 465 | <?php endforeach; ?> |
| 466 | <?php endif; ?> |
| 467 | </div> |
| 468 | </div> |
| 469 | <?php endif; ?> |
| 470 | |
| 471 | <?php if ($show_description && !empty($book_data['description'])): ?> |
| 472 | <div> |
| 473 | <h3 class="text-2xl font-serif font-bold text-slate-800 mb-4" style="color: var(--awt-title-color);"> |
| 474 | <?php echo esc_html($label_about); ?> |
| 475 | </h3> |
| 476 | <div class="text-lg text-slate-500 leading-relaxed space-y-4 font-light"> |
| 477 | <?php echo wpautop(wp_kses_post($book_data['description'])); ?> |
| 478 | </div> |
| 479 | </div> |
| 480 | <?php endif; ?> |
| 481 | |
| 482 | <?php if ($show_meta && !empty($book_data['details'])): ?> |
| 483 | <div> |
| 484 | <h3 class="text-2xl font-serif font-bold text-slate-800 mb-4" style="color: var(--awt-title-color);"> |
| 485 | <?php echo esc_html($label_details); ?> |
| 486 | </h3> |
| 487 | <ul class="grid grid-cols-1 sm:grid-cols-2 gap-y-3 gap-x-8 text-slate-700 bg-white p-6 rounded border border-gray-100 text-sm"> |
| 488 | <?php foreach ($book_data['details'] as $key => $field): |
| 489 | $value = $field['value'] ?? ''; |
| 490 | if(empty($value)) continue; |
| 491 | if(isset($field['condition']) && is_callable($field['condition']) && !$field['condition']($value)) continue; |
| 492 | if(isset($field['wrapper']) && is_callable($field['wrapper'])) $value = $field['wrapper']($value); |
| 493 | |
| 494 | // Basic escape check |
| 495 | if(!isset($field['escape']) || $field['escape'] === 'esc_html') $value = esc_html($value); |
| 496 | elseif($field['escape'] === 'wp_kses_post') $value = wp_kses_post($value); |
| 497 | ?> |
| 498 | <li class="flex justify-between border-b border-gray-50 pb-2"> |
| 499 | <span class="font-bold text-slate-500"><?php echo esc_html($field['label']); ?></span> |
| 500 | <span><?php echo $value; ?></span> |
| 501 | </li> |
| 502 | <?php endforeach; ?> |
| 503 | </ul> |
| 504 | </div> |
| 505 | <?php endif; ?> |
| 506 | |
| 507 | </div> |
| 508 | </div> |
| 509 | </div> |
| 510 | </section> |
| 511 | |
| 512 | <?php else: ?> |
| 513 | |
| 514 | <!-- FUN (DEFAULT) STYLE --> |
| 515 | <section class="awt-book-details py-16 md:py-24" style="background-color: var(--awt-section-bg);"> |
| 516 | <div class="awt-container container mx-auto px-6 max-w-6xl"> |
| 517 | <?php if (!$use_placeholder && $books_archive_url): ?> |
| 518 | <a href="<?php echo esc_url($books_archive_url); ?>" class="font-bold hover:opacity-80 mb-8 inline-block" |
| 519 | style="color: var(--awt-accent-color);"> |
| 520 | ← <?php echo esc_html($label_back); ?> |
| 521 | </a> |
| 522 | <?php endif; ?> |
| 523 | |
| 524 | <div class="grid grid-cols-1 lg:grid-cols-2 gap-12 lg:gap-16 items-start"> |
| 525 | |
| 526 | <div class="space-y-6"> |
| 527 | <img src="<?php echo esc_url($book_data['cover_url']); ?>" |
| 528 | alt="<?php echo esc_attr(sprintf(__('Book cover for %s', 'author-website-templates'), $book_data['title'])); ?>" |
| 529 | class="rounded-lg shadow-2xl w-full max-w-lg mx-auto transform -rotate-2 transition-all duration-300 hover:rotate-2"> |
| 530 | |
| 531 | <?php if ($show_gallery && !empty($book_data['gallery_images']) && is_array($book_data['gallery_images'])): |
| 532 | // Verify if any image actually exists |
| 533 | $has_images = false; |
| 534 | foreach ($book_data['gallery_images'] as $item) { |
| 535 | if ((is_array($item) && !empty($item['upload_image'])) || (is_string($item) && !empty($item))) { |
| 536 | $has_images = true; |
| 537 | break; |
| 538 | } |
| 539 | } |
| 540 | ?> |
| 541 | <?php if ($has_images): ?> |
| 542 | <div> |
| 543 | <h4 class="text-2xl font-black pt-4 mb-4" style="color: var(--awt-title-color);"> |
| 544 | <?php echo esc_html($label_peek); ?> |
| 545 | </h4> |
| 546 | <div class="grid grid-cols-3 gap-4"> |
| 547 | <?php foreach ($book_data['gallery_images'] as $index => $image_data): |
| 548 | $img_url = ''; |
| 549 | if (is_array($image_data) && isset($image_data['upload_image'])) { |
| 550 | $img_url = $image_data['upload_image']; |
| 551 | } elseif (is_string($image_data)) { |
| 552 | $img_url = $image_data; |
| 553 | } |
| 554 | if (empty($img_url)) |
| 555 | continue; |
| 556 | ?> |
| 557 | <img src="<?php echo esc_url($img_url); ?>" |
| 558 | alt="<?php esc_attr_e('Interior preview', 'author-website-templates'); ?>" |
| 559 | class="rounded-md shadow-md transition-all hover:scale-105 hover:shadow-lg"> |
| 560 | <?php endforeach; ?> |
| 561 | </div> |
| 562 | </div> |
| 563 | <?php endif; ?> |
| 564 | <?php endif; ?> |
| 565 | <?php if ($show_formats && !empty($book_data['formats']) && is_array($book_data['formats'])): ?> |
| 566 | <div class="pt-4"> |
| 567 | <div class="grid grid-cols-2 gap-3"> |
| 568 | <?php foreach ($book_data['formats'] as $format): |
| 569 | $format_name = isset($format['name']) ? $format['name'] : ''; |
| 570 | $format_price = isset($format['price']) ? $format['price'] : ''; |
| 571 | $format_link = isset($format['link']) ? $format['link'] : ''; |
| 572 | if (empty($format_name)) |
| 573 | continue; |
| 574 | ?> |
| 575 | |
| 576 | <a href="<?php echo esc_url($format_link); ?>" class="block no-underline" target="_blank" |
| 577 | rel="noopener"> |
| 578 | <div class="text-center p-3 rounded-lg border-2 transition-all hover:shadow-md bg-white" |
| 579 | style="border-color: var(--awt-btn-bg);"> |
| 580 | |
| 581 | <div class="font-black text-sm uppercase" style="color: var(--awt-title-color);"> |
| 582 | <?php echo esc_html($format_name); ?> |
| 583 | </div> |
| 584 | |
| 585 | <?php if (!empty($format_price)): ?> |
| 586 | <div class="text-lg font-bold mt-1" style="color: var(--awt-accent-color);"> |
| 587 | <?php echo esc_html($format_price); ?> |
| 588 | </div> |
| 589 | <?php endif; ?> |
| 590 | </div> |
| 591 | </a> |
| 592 | |
| 593 | <?php endforeach; ?> |
| 594 | </div> |
| 595 | </div> |
| 596 | <?php endif; ?> |
| 597 | |
| 598 | </div> |
| 599 | |
| 600 | <div class="space-y-8"> |
| 601 | <div> |
| 602 | <span class="block font-bold uppercase tracking-wider" style="color: var(--awt-accent-color);"> |
| 603 | <?php echo esc_html($label_latest); ?> |
| 604 | </span> |
| 605 | <h1 class="text-4xl md:text-6xl font-black my-2 leading-tight" |
| 606 | style="color: var(--awt-title-color);"> |
| 607 | <?php echo esc_html($book_data['title']); ?> |
| 608 | </h1> |
| 609 | <p class="text-2xl font-bold" style="color: var(--awt-title-color); opacity: 0.8;"> |
| 610 | <?php echo esc_html(sprintf('%s %s', $label_illustrated, $book_data['author_name'])); ?> |
| 611 | </p> |
| 612 | |
| 613 | <?php if ($show_price && (!empty($book_data['regular_price']) || !empty($book_data['sale_price']))): ?> |
| 614 | <div class="mt-4 text-lg font-bold"> |
| 615 | <?php if (!empty($book_data['sale_price'])): ?> |
| 616 | <span class="line-through" |
| 617 | style="color: var(--awt-title-color); opacity: 0.5; margin-right: 0.5rem;"> |
| 618 | <?php echo esc_html($currenySign . $book_data['regular_price']); ?> |
| 619 | </span> |
| 620 | <span class="text-2xl" style="color: var(--awt-accent-color);"> |
| 621 | <?php echo esc_html($currenySign . $book_data['sale_price']); ?> |
| 622 | </span> |
| 623 | <?php else: ?> |
| 624 | <span class="text-2xl" style="color: var(--awt-accent-color);"> |
| 625 | <?php echo esc_html($currenySign . $book_data['regular_price']); ?> |
| 626 | </span> |
| 627 | <?php endif; ?> |
| 628 | </div> |
| 629 | <?php endif; ?> |
| 630 | </div> |
| 631 | |
| 632 | <?php if ($show_buy_buttons && (!empty($book_data['primary_btn_link']) || !empty($book_data['additional_stores']))): ?> |
| 633 | <div class="bg-white p-6 rounded-xl shadow-lg" |
| 634 | style="border: 2px solid calc(var(--awt-btn-bg) * 1);"> |
| 635 | <!-- Note: Calc hack or RGBA needed for opacity, stuck with solid for vars unless using HEX->RGB. Keeping simple for now or using inline styles for border if desired, but user asked for vars. |
| 636 | The original was: style="border: 2px solid <?php echo $btn_bg_color; ?>30;" which is HEX opacity. |
| 637 | For CSS vars, we'll lose the opacity unless we convert. Let's stick to the color var for now. --> |
| 638 | <h3 class="text-3xl font-black mb-6 text-center" style="color: var(--awt-title-color);"> |
| 639 | <?php echo esc_html($label_order); ?> |
| 640 | </h3> |
| 641 | |
| 642 | <div class="flex flex-wrap gap-4 justify-center"> |
| 643 | <?php if (!empty($book_data['primary_btn_link'])): ?> |
| 644 | <a href="<?php echo esc_url($book_data['primary_btn_link']); ?>" |
| 645 | class="px-8 py-3 rounded-full font-black text-lg transition-all hover:scale-105 shadow-lg" |
| 646 | style="background-color: var(--awt-btn-bg); color: #000;" target="_blank"> |
| 647 | <?php echo esc_html(!empty($book_data['primary_btn_text']) ? $book_data['primary_btn_text'] : __('Buy Now', 'author-website-templates')); ?> |
| 648 | </a> |
| 649 | <?php endif; ?> |
| 650 | |
| 651 | <?php if (!empty($book_data['additional_stores']) && is_array($book_data['additional_stores'])): ?> |
| 652 | <?php foreach ($book_data['additional_stores'] as $store): |
| 653 | $store_name = isset($store['website_name']) ? $store['website_name'] : ''; |
| 654 | $store_url = isset($store['book_url']) ? $store['book_url'] : ''; |
| 655 | if (empty($store_name) || empty($store_url)) |
| 656 | continue; |
| 657 | ?> |
| 658 | <a href="<?php echo esc_url($store_url); ?>" |
| 659 | class="px-8 py-3 rounded-full font-black text-lg transition-all hover:scale-105 bg-white shadow-lg" |
| 660 | style="color: var(--awt-title-color);" target="_blank"> |
| 661 | <?php echo esc_html($store_name); ?> |
| 662 | </a> |
| 663 | <?php endforeach; ?> |
| 664 | <?php endif; ?> |
| 665 | </div> |
| 666 | </div> |
| 667 | <?php endif; ?> |
| 668 | |
| 669 | <?php if ($show_description && !empty($book_data['description'])): ?> |
| 670 | <div> |
| 671 | <h3 class="text-3xl font-black mb-4" style="color: var(--awt-title-color);"> |
| 672 | <?php echo esc_html($label_about); ?> |
| 673 | </h3> |
| 674 | <div class="text-lg leading-relaxed space-y-4" |
| 675 | style="color: var(--awt-title-color); opacity: 0.8;"> |
| 676 | <?php echo wpautop(wp_kses_post($book_data['description'])); ?> |
| 677 | </div> |
| 678 | </div> |
| 679 | <?php endif; ?> |
| 680 | |
| 681 | <?php if ($show_meta && !empty($book_data['details'])): ?> |
| 682 | <div> |
| 683 | <h3 class="text-3xl font-black mb-4" style="color: var(--awt-title-color);"> |
| 684 | <?php echo esc_html($label_details); ?> |
| 685 | </h3> |
| 686 | <ul class="list-none space-y-2 bg-white p-6 rounded-lg shadow-sm" |
| 687 | style="color: var(--awt-title-color); opacity: 0.8;"> |
| 688 | |
| 689 | <?php foreach ($book_data['details'] as $key => $field): |
| 690 | |
| 691 | // Skip if value empty |
| 692 | $value = $field['value'] ?? ''; |
| 693 | if (empty($value)) |
| 694 | continue; |
| 695 | |
| 696 | // Check condition (if exists) |
| 697 | if (isset($field['condition']) && is_callable($field['condition'])) { |
| 698 | if (!$field['condition']($value)) |
| 699 | continue; |
| 700 | } |
| 701 | |
| 702 | // Apply wrapper (if exists) |
| 703 | if (isset($field['wrapper']) && is_callable($field['wrapper'])) { |
| 704 | $value = $field['wrapper']($value); |
| 705 | } |
| 706 | |
| 707 | // Escape handling |
| 708 | if (isset($field['escape'])) { |
| 709 | if ($field['escape'] === 'esc_html') { |
| 710 | $value = esc_html($value); |
| 711 | } elseif ($field['escape'] === 'wp_kses_post') { |
| 712 | $value = wp_kses_post($value); |
| 713 | } elseif ($field['escape'] === false) { |
| 714 | // skip escape |
| 715 | } |
| 716 | } else { |
| 717 | // default escape |
| 718 | $value = esc_html($value); |
| 719 | } |
| 720 | |
| 721 | ?> |
| 722 | <li> |
| 723 | <strong |
| 724 | style="color: var(--awt-title-color);"><?php echo esc_html($field['label']); ?></strong> |
| 725 | <span><?php echo $value; ?></span> |
| 726 | </li> |
| 727 | |
| 728 | <?php endforeach; ?> |
| 729 | |
| 730 | </ul> |
| 731 | |
| 732 | </div> |
| 733 | <?php endif; ?> |
| 734 | </div> |
| 735 | </div> |
| 736 | </div> |
| 737 | </section> |
| 738 | <?php endif; ?> |
| 739 | </div> |