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-comment-count.php
<?php

/**
 * Renders the `gtm/post-comment-count` 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 post comment count for the current post.
 */

function gtm_render_block_post_comment_count( $attr, $content, $block ) {

	// Will be displayed when we have at least one comment or comments are open
	if ( ! isset( $block->context['postId'] ) || ( ! comments_open( $block->context['postId'] ) && get_comments_number( $block->context['postId'] ) ) ) {
		return '';
	}

	$post_ID = $block->context['postId'];

	$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );

	$inner_html   = '';
	$counter      = wp_count_comments( $post_ID )->approved;
	$counter_text = '';
	if ( $attr['display'] == 'counter' ) {
		$counter_text = number_format_i18n( $counter );
	} else {
		$counter_text = sprintf( _n( "%s Comment", "%s Comments", $counter, 'gutenmate' ), $counter );
	}

	if ( $attr['display'] == 'icon' || $attr['display'] == 'counter' ) {
		$inner_html .= gtm_icon( ! empty( $attr['icon'] ) ? $attr['icon'] : 'comments' );
	}

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

	if ( empty( $attr['enableLink'] ) ) {
		$inner_html .= '<span class="wp-block-gtm-post-comment-count__count wp-block-gtm-post-comment-count__content">' . esc_html( $counter_text ) . '</span>';

	} else {
		$inner_html .= sprintf( '<a class="wp-block-gtm-post-comment-count__count wp-block-gtm-post-comment-count__content" href="%1$s">%2$s</a>', esc_url( get_comments_link() ), esc_html( $counter_text ) );

	}

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

/**
 * Registers the `gtm/post-comment-count` block on the server.
 */
function gtm_register_block_post_comment_count() {
	gtm_register_block_type( 'post-comment-count', [
		'render_callback' => 'gtm_render_block_post_comment_count',
	] );
}

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

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

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

	if ( $attributes['enableLink'] && $attributes['enableLinkUnderline'] ) {
		$block_style['classes'][] = 'gtm-has-post-comment-count-link-underline';
	}

	if ( $attributes['enableLink'] && $attributes['enableLinkHoverUnderline'] ) {
		$block_style['classes'][] = 'gtm-has-post-comment-count-link-hover-underline';
	}

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

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

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

	if ( $attributes['enableLink'] ) {
		gtm_css_compileCssVar( $block_style, "post-comment-count-link-color", gtm_css_parseColorValue( $attributes['linkColor'] ) );

		gtm_css_compileCssVar( $block_style, "post-comment-count-link-hover-color", gtm_css_parseColorValue( $attributes['linkHoverColor'] ) );
	}

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

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

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

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

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

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

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

		gtm_css_compileCssVar( $block_style, "post-comment-count-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'] ),
	];
}