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