{glyph}` * repeated `scale` times, using the same unicode glyphs (☆ / ★). * * @param int $count Star count (the rating scale). * @param string $glyph Star glyph. * * @return string */ public static function render_stars($count, $glyph) { $stars = ''; for ($i = 1; $i <= $count; $i++) { $stars .= '' . $glyph . ''; } return $stars; } /** * Server-side render for the Review module. * * Mirrors the D4 markup (and the VB edit component) exactly: *
* [figure (badge, overlay, img)] *
* [title] *
*
*
☆…
*
★…
*
* [(rating/scale)] *
* [description] * [button wrap] *
*
* * The star fill width on `.dtq-stars-act` is emitted by ModuleStylesTrait * (D4 used an inline `--active-width` custom property instead). * * @param array $attrs Block attributes. * @param string $content Block content (unused). * @param WP_Block $block Parsed block. * @param ModuleElements $elements Module elements helper. * * @return string */ public static function render_callback($attrs, $content, $block, $elements) { $advanced = $attrs['module']['advanced'] ?? []; $scale_raw = $advanced['scale']['desktop']['value'] ?? '5'; $rating = $advanced['rating']['desktop']['value'] ?? '5'; $scale = (int) $scale_raw; $show_number = ($advanced['showNumber']['desktop']['value'] ?? 'off') === 'on'; $use_light = ($advanced['useLightbox']['desktop']['value'] ?? 'off') === 'on'; $use_badge = ($advanced['useBadge']['desktop']['value'] ?? 'off') === 'on'; $use_button = ($advanced['useButton']['desktop']['value'] ?? 'off') === 'on'; $overlay_on = ($advanced['overlayOnHover']['desktop']['value'] ?? 'on') === 'on'; $hover_anim = $advanced['imgAnim']['desktop']['value'] ?? 'none'; // The D5 upload field stores the image as an object (`{ src, ... }`); // accept both that and a plain URL string. // A dynamic image is a structure with no src until resolved (#86). $image_val = DynamicValue::resolve($attrs['image']['innerContent']['desktop']['value'] ?? ''); $image_src = is_array($image_val) ? ($image_val['src'] ?? '') : $image_val; $image_alt = $attrs['image']['advanced']['alt']['desktop']['value'] ?? ''; // Badge. $badge_html = ''; if ($use_badge) { $badge_html = $elements->render(['attrName' => 'badge']); } // Figure (only when an image is set). Mirrors D4 `_render_image()`. $figure_html = ''; if (!empty($image_src)) { $overlay_html = ''; if ($overlay_on) { $overlay_icon = $advanced['overlayIcon']['desktop']['value'] ?? ''; if (is_array($overlay_icon)) { $overlay_uni = $overlay_icon['unicode'] ?? ''; $overlay_type = $overlay_icon['type'] ?? 'divi'; $overlay_wt = $overlay_icon['weight'] ?? '400'; } else { $overlay_parts = explode('||', (string) $overlay_icon); $overlay_uni = $overlay_parts[0] ?? ''; $overlay_type = $overlay_parts[1] ?? 'divi'; $overlay_wt = $overlay_parts[2] ?? '400'; } if ('' !== $overlay_uni) { $overlay_font = 'fa' === $overlay_type ? 'FontAwesome' : 'ETmodules'; dtq_inject_fa_icons($overlay_uni . '||' . $overlay_type . '||' . $overlay_wt); $overlay_html = sprintf( '
%3$s
', esc_attr($overlay_font), esc_attr($overlay_wt), dtq_resolve_icon_unicode($overlay_uni) ); } else { // D4 renders the overlay with an empty icon element. $overlay_html = '
'; } } // Lightbox: keep the exact D4 class/data hooks (`.dtq-lightbox` // + `data-mfp-src`) and conditionally load magnific popup on the // front end only (the VB renders the image plain, no popup). $lightbox_class = ''; if ($use_light) { $lightbox_class = ' dtq-lightbox'; if (function_exists('wp_enqueue_script')) { wp_enqueue_script('divi-torque-lite-magnific-popup'); wp_enqueue_style('divi-torque-lite-magnific-popup'); } } $figure_html = sprintf( '
%1$s%2$s%4$s
', $badge_html, $overlay_html, esc_url($image_src), esc_attr($image_alt), esc_attr($lightbox_class) ); } // Rating number (mirrors D4 `render_rarings_number()`). $number_html = ''; if ($show_number) { $number_html = '
(' . esc_html($rating) . '/' . esc_html($scale_raw) . ')
'; } // Title + description. $title_html = $elements->render(['attrName' => 'title']); $desc_html = $elements->render(['attrName' => 'description']); // Button. $button_html = ''; if ($use_button) { $button_html = sprintf( '
%1$s
', ButtonElement::render($attrs['button'] ?? [], 'dtq-btn-default dtq-rating-btn') ); } $ratings_html = sprintf( '
%1$s
%2$s
%3$s
', self::render_stars($scale, '☆'), self::render_stars($scale, '★'), $number_html ); $children = sprintf( '
%2$s
%3$s%4$s%5$s%6$s
', esc_attr($hover_anim), $figure_html, $title_html, $ratings_html, $desc_html, $button_html ); return Module::render( [ 'attrs' => $attrs, 'elements' => $elements, 'id' => $block->parsed_block['id'], 'name' => $block->block_type->name, 'moduleCategory' => $block->block_type->category, 'classnamesFunction' => [self::class, 'module_classnames'], 'stylesComponent' => [self::class, 'module_styles'], 'scriptDataComponent' => [self::class, 'module_script_data'], 'orderIndex' => $block->parsed_block['orderIndex'] ?? 0, 'storeInstance' => $block->parsed_block['storeInstance'] ?? null, 'children' => [ // Background pattern/mask and the box-shadow overlay are DOM, // not CSS. Without this call Divi renders them in the builder // and nowhere else, so the options silently do nothing on the // front end. $elements->style_components(['attrName' => 'module']), $children, ], ] ); } }