HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/block-library/review-breakdown.php
<?php

/**
 * Registers the `gtm/review-breakdown` block on the server.
 */
function gtm_register_block_review_breakdown() {
	gtm_register_block_type( 'review-breakdown', [
		'render_callback' => 'gtm_render_block_review_breakdown',
	] );
}

function gtm_render_block_review_breakdown( $attr, $content, $block ) {
	if ( ! isset( $block->context['gtmReviewBreakdown'] ) ) {
		return '';
	}

	$inner_html = '<div class="wp-block-gtm-review-breakdown__container">';
	$breakdown  = $block->context['gtmReviewBreakdown'];

	foreach ( $breakdown as $item ) {
		$inner_html .= sprintf( '<div class="wp-block-gtm-review-breakdown__item" style="--gtm-review-breakdown-score-multiplier: %s">', esc_attr( $item['score'] / 100 ) );

		$inner_html .= sprintf( '<div class="wp-block-gtm-review-breakdown__item-title"><span>%s</span></div>', esc_html( $item['label'] ) );

		if ( "points" == $attr['design'] ) {
			$inner_html .= sprintf( '<div class="wp-block-gtm-review-breakdown__item-score"><span>%s</span></div>', esc_html( number_format_i18n( $item['score'] / 10, 1 ) ) );

		} else if ( "percentage" == $attr['design'] ) {
			$inner_html .= sprintf( '<div class="wp-block-gtm-review-breakdown__item-score"><span>%s%%</span></div>', esc_html( number_format_i18n( $item['score'] ) ) );

		} else if ( "stars" == $attr['design'] ) {
			$inner_html .= '<div class="wp-block-gtm-review-breakdown__item-score"><span><span class="gtm-stars"></span></span></div>';

		}

		if ( in_array( $attr['design'], ['points', 'percentage'] ) ) {
			$inner_html .= '<div class="wp-block-gtm-review-breakdown__item-bar"><span class="wp-block-gtm-review-breakdown__item-bar__inner"></span></div>';

		}

		$inner_html .= '</div>'; // wp-block-gtm-review-breakdown__item
	}

	$inner_html .= '</div>';
	$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );

	return sprintf(
		'<div %1$s>%2$s</div>',
		$wrapper_attributes,
		$inner_html
	);
}

add_action( 'init', 'gtm_register_block_review_breakdown', 20 );

add_filter( 'gtm.BlockStyleCompiler.gtm/review-breakdown', 'gtm_compile_block_css_review_breakdown', 10, 3 );
function gtm_compile_block_css_review_breakdown( $output, $attributes, $blockName ) {
	$block_style = ['classes' => [], 'style' => []];

	$hasStars = in_array( $attributes['design'], ['stars'] );

	$block_style['classes'][] = 'gtm-block';
	$block_style['classes'][] = 'gtm-has-breakdown-' . $attributes['design'];

	gtm_css_compileCssVar( $block_style, "review-breakdown-item-spacing", gtm_css_parseSpacingValue( $attributes['itemSpacing'] ) );

	if ( $hasStars ) {
		gtm_css_compileCssVar( $block_style, "review-breakdown-star-size", $attributes['starSize'] );

	} else {
		gtm_css_compileCssVar( $block_style, "review-breakdown-bar-height", $attributes['barHeight'] );
		gtm_css_compileCssVar( $block_style, "review-breakdown-bar-radius", gtm_css_parseBorderRadiusValue( $attributes['barRadius'] ) );
		gtm_css_compileCssVar( $block_style, "review-breakdown-bar-shadow", gtm_css_parseShadowValue( $attributes['barShadow'] ) );
		gtm_css_compileCssVar( $block_style, "review-breakdown-bar-spacing", gtm_css_parseSpacingValue( $attributes['barSpacing'] ) );
	}

	gtm_css_compileCssVar( $block_style, "review-breakdown-indicator-bg", gtm_css_parseColorValue( $attributes['indicatorBg'] ) );

	gtm_css_compileCssVar( $block_style, "review-breakdown-indicator-color", gtm_css_parseColorValue( $attributes['indicatorColor'] ) );

	gtm_css_compileCssVar( $block_style, "review-breakdown-title-typography", gtm_css_parseTypographyProps( $attributes['labelTypography'] ) );

	if ( ! $hasStars ) {
		gtm_css_compileCssVar( $block_style, "review-breakdown-number-padding", gtm_css_parseResponsiveBoxProps( $attributes['scorePadding'] ) );

		gtm_css_compileCssVar( $block_style, "review-breakdown-number-radius", gtm_css_parseBorderRadiusValue( $attributes['scoreRadius'] ) );

		gtm_css_compileCssVar( $block_style, "review-breakdown-number-color", gtm_css_parseColorValue( $attributes['scoreColor'] ) );

		gtm_css_compileCssVar( $block_style, "review-breakdown-number-bg", gtm_css_parseColorValue( $attributes['scoreBg'] ) );

		gtm_css_compileCssVar( $block_style, "review-breakdown-number-typography", gtm_css_parseTypographyProps( $attributes['scoreTypography'] ) );
	}

	// Apply to output
	$block_style['style'] = ['{{BLOCK}}' => $block_style['style']];

	return [
		'classes' => array_merge( $output['classes'], $block_style['classes'] ),
		'style'   => array_replace_recursive( $output['style'], $block_style['style'] ),
	];
}