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/breadly/block-library/post-review.php
<?php

/**
 * Renders the `gtm/post-review` block on the server.
 *
 * @param array    $attributes Block attributes.
 * @param string   $content    Block default content.
 * @param WP_Block $block      Block instance.
 * @return string Returns the featured image for the current post.
 */
function gtm_render_block_post_review( $attr, $content, $block ) {

	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$post_ID            = $block->context['postId'];
	$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );

	$inner_html = '';

	$gtm_review_score = get_post_meta( $post_ID, 'gtm_review_score', true );

	if ( is_numeric( $gtm_review_score ) ) {
		if ( $attr['display'] == 'icon' ) {
			$inner_html .= gtm_icon( ! empty( $attr['icon'] ) ? $attr['icon'] : 'review' );
		}

		if ( ! empty( $attr['label'] ) ) {
			$inner_html .= '<span class="wp-block-gtm-post-review__label">' . $attr['label'] . '</span>';
		}

		$inner_html .= '<span class="wp-block-gtm-post-review__score wp-block-gtm-post-review__content">';

		if ( $attr['format'] == 'points' ) {
			$calculatedScore = number_format_i18n( $gtm_review_score / 10, 1 );
			$inner_html .= sprintf(
				_n( "%s Point", "%s Points", $calculatedScore, 'gutenmate' ),
				$calculatedScore
			);
		} else if ( $attr['format'] == 'stars' ) {
			$calculatedScore = number_format_i18n( $gtm_review_score / 20, 1 );
			$inner_html .= sprintf(
				_n( "%s Point", "%s Points", $calculatedScore, 'gutenmate' ),
				$calculatedScore
			);
		} else if ( $attr['format'] == 'percentage' ) {
			$calculatedScore = number_format_i18n( $gtm_review_score, 0 );
			$inner_html .= $calculatedScore . '%';
		}

		$inner_html .= '</span>';

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

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

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

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

	$block_style['classes'][] = 'gtm-block';

	//Label
	gtm_css_compileCssVar( $block_style, "post-review-label-typography", gtm_css_parseTypographyProps( $attributes['labelTypography'] ) );

	gtm_css_compileCssVar( $block_style, "post-review-label-spacing", gtm_css_parseSpacingValue( $attributes['labelSpacing'] ) );

	gtm_css_compileCssVar( $block_style, "post-review-label-color", gtm_css_parseColorValue( $attributes['labelColor'] ) );

	if ( $attributes['display'] !== 'name' ) {
		gtm_css_compileCssVar( $block_style, "post-review-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );

		gtm_css_compileCssVar( $block_style, "post-review-icon-size", $attributes['iconSize'] );

		gtm_css_compileCssVar( $block_style, "post-review-icon-width", $attributes['iconWidth'] );

		gtm_css_compileCssVar( $block_style, 'post-review-icon-radius', gtm_css_parseBorderRadiusValue( $attributes['iconRadius'] ) );

		gtm_css_compileCssVar( $block_style, "post-review-icon-color", gtm_css_parseColorValue( $attributes['iconColor'] ) );

		gtm_css_compileCssVar( $block_style, "post-review-icon-bg", gtm_css_parseColorValue( $attributes['iconBg'] ) );

		gtm_css_compileCssVar( $block_style, "post-review-icon-hover-color", gtm_css_parseColorValue( $attributes['iconHoverColor'] ) );

		gtm_css_compileCssVar( $block_style, "post-review-icon-hover-bg", gtm_css_parseColorValue( $attributes['iconHoverBg'] ) );
	}

	// 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'] ),
	];
}