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/mega-menu-link.php
<?php
defined( 'GTM_CURRENT_MENU_ITEM_CLASS' ) || define( 'GTM_CURRENT_MENU_ITEM_CLASS', 'current-menu-item' );
defined( 'GTM_ANCESTOR_MENU_ITEM_CLASS' ) || define( 'GTM_ANCESTOR_MENU_ITEM_CLASS', 'current-menu-ancestor' );

function gtm_render_block_mega_menu_link( $attributes, $content, $block ) {
	$current_url     = gtm_get_current_url();
	$url             = gtm_render_block_mega_menu_link__get_url( $attributes );
	$newtab          = $attributes['opensInNewTab'] ? 'target="_blank"' : '';
	$wrapper_classes = [];

	// Add current menu item class
	if ( $current_url === untrailingslashit( $url ) ) {
		$wrapper_classes[] = GTM_CURRENT_MENU_ITEM_CLASS;
	}

	// Add ancestor menu class
	$isAncestorMenu = strpos( $content, GTM_CURRENT_MENU_ITEM_CLASS ) !== false;
	if ( $isAncestorMenu ) {
		$wrapper_classes[] = GTM_ANCESTOR_MENU_ITEM_CLASS;
	}

	$hasInnerBlocks = ! empty( $block->inner_blocks );
	$inner_html     = '';

	$aria = gtm_html_attributes( [
		'role'          => 'menuitem',
		'aria-label'    => wp_strip_all_tags( $attributes['label'] ?? '', true ),
		'aria-haspopup' => $hasInnerBlocks ? 'true' : 'false',
	] );
	$inner_html .= sprintf( '<a class="wp-block-gtm-mega-menu-link__content" href="%s" rel="%s" %s %s >', esc_url( $url ), esc_attr( $attributes['rel'] ?? '' ), $newtab, $aria );

	if ( ! empty( $attributes['icon'] ) ) {
		$inner_html .= '<div class="wp-block-gtm-mega-menu-link__icon-container">';
		$inner_html .= '<i class="gtm-icon ' . esc_attr( $attributes['icon'] ) . '"></i>';
		$inner_html .= '</div>';
	}

	if ( ! empty( $attributes['label'] ) || ! empty( $attributes['description'] ) ) {
		$inner_html .= '<div class="wp-block-gtm-mega-menu-link__label-container">';
		$inner_html .= '<div class="wp-block-gtm-mega-menu-link__label"><span>';
		$inner_html .= wp_kses_post( $attributes['label'] ?? '' );
		$inner_html .= '</span></div>';

		if ( ! empty( $attributes['description'] ) ) {
			$inner_html .= '<div class="wp-block-gtm-mega-menu-link__description">';
			$inner_html .= wp_kses_post( $attributes['description'] ?? '' );
			$inner_html .= '</div>';
		}

		$inner_html .= '</div>'; // Label container
	}

	if ( $hasInnerBlocks ) {
		$inner_html .= '<span class="wp-block-gtm-mega-menu-link__submenu-icon">';
		$inner_html .= '<i class="gtm-basic-icon-chevron-down"></i>';
		$inner_html .= '</span>';
	}

	$inner_html .= '</a>';

	if ( $hasInnerBlocks ) {
		$inner_html .= '<div class="wp-block-gtm-mega-menu-link__submenu-container" role="menu">';
		$inner_html .= $content;
		$inner_html .= '</div>';
	}

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

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

function gtm_render_block_mega_menu_link__get_url( $attributes ) {
	switch ( $attributes['kind'] ?? '' ) {
	case "post-type":
		$url = get_permalink( $attributes['id'] );
		break;
	case "taxonomy":
		$url = get_term_link( $attributes['id'] );
		break;
	default:
		$url = $attributes['url'];
	}

	return is_wp_error( $url ) ? '' : $url;
}

/**
 * Registers the `gtm/mega-menu-link` block on the server.
 */
function gtm_register_block_mega_menu_link() {
	gtm_register_block_type( 'mega-menu-link', [
		'render_callback' => 'gtm_render_block_mega_menu_link',
	] );
}

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

add_filter( 'gtm.BlockStyleCompiler.gtm/mega-menu-link', 'gtm_compile_block_css_mega_menu_link', 10, 3 );
function gtm_compile_block_css_mega_menu_link( $output, $attributes, $blockName ) {
	$block_style = ['classes' => [], 'style' => []];

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

	if ( $attributes['submenuAlign'] ) {
		$block_style['classes'][] = "gtm-has-submenu-align-{$attributes['submenuAlign']}";
	}

	if ( $attributes['isTopLevelLink'] ) {
		$block_style['classes'][] = "gtm-is-top-level-menu";
	}

	/* Link */

	gtm_css_compileCssVar( $block_style, "mega-menu-link-radius", gtm_css_parseBorderRadiusValue( $attributes['linkRadius'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-link-padding", gtm_css_parseResponsiveBoxProps( $attributes['linkPadding'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-link-bg", gtm_css_parseColorValue( $attributes['linkBg'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-hover-bg", gtm_css_parseColorValue( $attributes['linkHoverBg'] ) );

	/* Icon */

	gtm_css_compileCssVar( $block_style, "mega-menu-link-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-link-icon-size", $attributes['iconSize'] );
	gtm_css_compileCssVar( $block_style, "mega-menu-link-icon-color", gtm_css_parseColorValue( $attributes['iconColor'] ) );
	gtm_css_compileCssVar( $block_style, "mega-menu-link-icon-hover-color", gtm_css_parseColorValue( $attributes['iconHoverColor'] ) );

	/* Label */

	gtm_css_compileCssVar( $block_style, "mega-menu-link-label-typography", gtm_css_parseTypographyProps( $attributes['labelTypography'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-link-label-color", gtm_css_parseColorValue( $attributes['labelColor'] ) );
	gtm_css_compileCssVar( $block_style, "mega-menu-link-label-hover-color", gtm_css_parseColorValue( $attributes['labelHoverColor'] ) );

	/* Description */

	gtm_css_compileCssVar( $block_style, "mega-menu-link-description-spacing", gtm_css_parseSpacingValue( $attributes['descriptionSpacing'] ) );

	gtm_css_compileCssVar( $block_style, "mega-menu-link-description-typography", gtm_css_parseTypographyProps( $attributes['descriptionTypography'] ) );
	gtm_css_compileCssVar( $block_style, "mega-menu-link-description-color", gtm_css_parseColorValue( $attributes['descriptionColor'] ) );
	gtm_css_compileCssVar( $block_style, "mega-menu-link-description-hover-color", gtm_css_parseColorValue( $attributes['descriptionHoverColor'] ) );

	/* Submenu */

	gtm_css_compileCssVar( $block_style, "mega-menu-link-submenu-width", gtm_css_parseSpacingValue( $attributes['submenuWidth'] ) );

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