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/post-title.php
<?php

/**
 * Renders the `gtm/post-title` 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 title for the current post.
 */
function gtm_render_block_post_title( $attr, $content, $block ) {

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

	$post_ID    = $block->context['postId'];
	$tag_name   = $attr['titleTag'];
	$post_title = get_the_title( $post_ID ) ?: esc_html__( '(No title)', 'gutenmate' );

	if ( ! empty( $attr['enableLink'] ) ) {
		$title = sprintf( '<%1$s class="wp-block-gtm-post-title__title"><a href="%3$s" rel="%4$s" target="%5$s">%2$s</a></%1$s>', $tag_name, $post_title, esc_url( get_permalink( $post_ID ) ), esc_attr( $attr['linkRel'] ), esc_attr( $attr['linkTarget'] ) );

	} else {
		$title = sprintf( '<%1$s class="wp-block-gtm-post-title__title">%2$s</%1$s>', $tag_name, $post_title );

	}

	if ( ! empty( $attr['enableTagline'] ) ) {
		if ( 'custom-excerpt' == $attr['taglineSource'] ) {
			$raw_tagline = gtm_get_custom_excerpt( $post_ID );
		} else { // Any excerpt content
			$raw_tagline = get_the_excerpt( $post_ID );
		}

		if ( ! empty( $raw_tagline ) ) {
			$title .= sprintf( '<div class="wp-block-gtm-post-title__tagline">%1$s</div>', wp_kses_post( $raw_tagline ) );
		}
	}

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

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

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

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

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

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

	if ( $attributes['enableLink'] ) {
		$block_style['classes'][] = "gtm-has-post-title-enable-link";

		if ( $attributes['enableTitleUnderline'] ) {
			$block_style['classes'][] = "gtm-has-post-title-link-underline";
		}
		if ( $attributes['enableTitleHoverUnderline'] ) {
			$block_style['classes'][] = "gtm-has-post-title-link-hover-underline";
		}
	}

	if ( $attributes['enableTagline'] ) {
		if ( $attributes['hideTaglineTablet'] ) {
			$block_style['classes'][] = "gtm-hide-post-title-tagline-on-tablet";
		}
		if ( $attributes['hideTaglinePhone'] ) {
			$block_style['classes'][] = "gtm-hide-post-title-tagline-on-phone";
		}
	}

	gtm_css_compileCssVar( $block_style, "post-title-typography", gtm_css_parseTypographyProps( $attributes['titleTypography'] ) );
	gtm_css_compileCssVar( $block_style, "post-title-max-width", $attributes['titleMaxWidth'] );
	if ( $attributes['enableTitleLineClamp'] ) {
		gtm_css_compileCssVar( $block_style, "post-title-line-clamp", $attributes['titleLineClamp'] );
	}
	gtm_css_compileCssVar( $block_style, "post-title-color", gtm_css_parseColorValue( $attributes['titleColor'] ) );
	gtm_css_compileCssVar( $block_style, "post-title-hover-color", gtm_css_parseColorValue( $attributes['titleHoverColor'] ) );

	if ( $attributes['enableTagline'] ) {
		gtm_css_compileCssVar( $block_style, "post-title-tagline-typography", gtm_css_parseTypographyProps( $attributes['taglineTypography'] ) );

		gtm_css_compileCssVar( $block_style, "post-title-tagline-max-width", $attributes['taglineMaxWidth'] );

		gtm_css_compileCssVar( $block_style, "post-title-tagline-spacing", gtm_css_parseSpacingValue( $attributes['taglineSpacing'] ) );

		if ( $attributes['enableTaglineLineClamp'] ) {
			gtm_css_compileCssVar( $block_style, "post-title-tagline-line-clamp", $attributes['taglineLineClamp'] );
		}

		gtm_css_compileCssVar( $block_style, "post-title-tagline-color", gtm_css_parseColorValue( $attributes['taglineColor'] ) );
	}

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