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-share.php
<?php

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

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

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

	ob_start();
	gtm_render_block_post_share_buttons( $attr['socials'] );
	$inner_html = ob_get_clean();

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

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

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

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

function gtm_render_block_post_share_buttons( $socials ) {
	foreach ( $socials as $network ) {
		if ( 'facebook' == $network ) {
			gtm_post_share_button_template(
				'facebook',
				esc_html__( 'Facebook', 'gutenmate' ),
				'gtm-basic-icon-facebook-f',
				'http://www.facebook.com/sharer.php?u=[url]'
			);

		} else if ( 'twitter' == $network ) {
			$share_text = get_option( 'gtm_share_twitter_username', '' ) ? esc_html__( ' via %40', 'gutenmate' ) . get_option( 'gtm_share_twitter_username', '' ) : '';

			gtm_post_share_button_template(
				'twitter',
				esc_html__( 'Twitter', 'gutenmate' ),
				'gtm-basic-icon-twitter',
				'https://twitter.com/intent/tweet?text=[title]' . $share_text . '&url=[url]'
			);

		} else if ( 'linkedin' == $network ) {
			gtm_post_share_button_template(
				'linkedin',
				esc_html__( 'Linkedin', 'gutenmate' ),
				'gtm-basic-icon-linkedin-in',
				'https://www.linkedin.com/shareArticle?mini=true&url=[url]&title=[title]'
			);

		} else if ( 'mix' == $network ) {
			gtm_post_share_button_template(
				'mix',
				esc_html__( 'Mix', 'gutenmate' ),
				'gtm-basic-icon-mix',
				'https://mix.com/add?url=[url]'
			);

		} else if ( 'pinterest' == $network ) {
			gtm_post_share_button_template(
				'pinterest',
				esc_html__( 'Pinterest', 'gutenmate' ),
				'gtm-basic-icon-pinterest-p',
				'https://www.pinterest.com/pin/create/button/?url=[url]&media=&description=[title]'
			);

		} else if ( 'reddit' == $network ) {
			gtm_post_share_button_template(
				'reddit',
				esc_html__( 'Reddit', 'gutenmate' ),
				'gtm-basic-icon-reddit-alien',
				'https://reddit.com/submit?url=[url]&title=[title]'
			);

		} else if ( 'buffer' == $network ) {
			gtm_post_share_button_template(
				'buffer',
				esc_html__( 'Buffer', 'gutenmate' ),
				'gtm-basic-icon-buffer',
				'https://buffer.com/add?url=[url]&text=[title]'
			);

		} else if ( 'tumblr' == $network ) {
			gtm_post_share_button_template(
				'tumblr',
				esc_html__( 'Tumblr', 'gutenmate' ),
				'gtm-basic-icon-tumblr',
				'https://www.tumblr.com/share/link?url=[url]&name=[title]'
			);

		} else if ( 'vk' == $network ) {
			gtm_post_share_button_template(
				'vk',
				esc_html__( 'VKontakte', 'gutenmate' ),
				'gtm-basic-icon-vk',
				'https://vk.com/share.php?url=[url]'
			);

		} else if ( 'pocket' == $network ) {
			gtm_post_share_button_template(
				'pocket',
				esc_html__( 'Pocket', 'gutenmate' ),
				'gtm-basic-icon-get-pocket',
				'https://getpocket.com/save?title=[title]&url=[url]'
			);

		} else if ( 'whatsapp' == $network && wp_is_mobile() ) {
			gtm_post_share_button_template(
				'whatsapp',
				esc_html__( 'WhatsApp', 'gutenmate' ),
				'gtm-basic-icon-whatsapp',
				'whatsapp://send?text=[title] - [url]'
			);

		} else if ( 'telegram' == $network && wp_is_mobile() ) {
			gtm_post_share_button_template(
				'telegram',
				esc_html__( 'Telegram', 'gutenmate' ),
				'gtm-basic-icon-telegram-plane',
				'tg://msg?text=[title] - [url]'
			);

		} else if ( 'viber' == $network && wp_is_mobile() ) {
			gtm_post_share_button_template(
				'viber',
				esc_html__( 'Viber', 'gutenmate' ),
				'gtm-basic-icon-viber',
				'viber://forward?text=[title] - [url]'
			);

		} else if ( 'email' == $network ) {
			gtm_post_share_button_template(
				'email',
				esc_html__( 'Email', 'gutenmate' ),
				'gtm-basic-icon-envelope',
				'mailto:?subject=[title]&body=[url]'
			);

		} else if ( 'print' == $network ) {
			gtm_post_share_button_template(
				'print',
				esc_html__( 'Print', 'gutenmate' ),
				'gtm-basic-icon-print',
				'javascript:window.print(); window.close();'
			);
		}
	}
}

function gtm_post_share_button_template( $social_slug, $label, $icon, $share_url ) {
	if ( in_the_loop() ) {
		$post = get_post( get_the_ID() );
	} else {
		$post = get_queried_object();
	}

	if ( 'print' == $social_slug ) {
		// Use label as tooltip if it is print icon or something else
		$tooltip = gtm_tooltip( $label );

		printf( '<a href="%1$s" class="wp-block-gtm-post-share__button wp-block-gtm-post-share__button-%2$s gtm-social-color-%2$s" data-share-to="%2$s" data-post-id="%4$s" rel="external nofollow noreferrer" %3$s>',
			'javascript:print()',
			esc_attr( $social_slug ),
			$tooltip,
			esc_attr( is_object( $post ) ? $post->ID : '' ) /* Avoid warning on editor */
		);

	} else {
		$tooltip = gtm_tooltip( sprintf( __( 'Share via %s', 'gutenmate' ), $label ) );

		$share_url = apply_filters( 'gtm-share-url-template', $share_url, $social_slug );

		if ( get_option( 'share_enable_short_link', false ) ) {
			$share_url = str_replace( '[url]', urlencode( wp_get_shortlink( $post->ID ) ), $share_url );

		} else {
			$share_url = str_replace( '[url]', urlencode( get_permalink( $post ) ), $share_url );

		}

		$share_url = str_replace( '[title]', urlencode( get_the_title( $post ) ), $share_url );

		printf( '<a href="%1$s" class="wp-block-gtm-post-share__button wp-block-gtm-post-share__button-%2$s gtm-social-color-%2$s" data-share-to="%2$s" data-post-id="%4$s" rel="external nofollow noreferrer" target="_blank" %3$s>',
			esc_url( $share_url ),
			esc_attr( $social_slug ),
			$tooltip,
			esc_attr( is_object( $post ) ? $post->ID : '' ) /* Avoid warning on editor */
		);
	}

	printf( '<i class="gtm-icon %s" aria-hidden="true"></i>', esc_attr( $icon ) );
	printf( '<span class="wp-block-gtm-post-share__label">%s</span>', esc_html( $label ) );
	echo '</a>';
}

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

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

	if ( $attributes['enableLabel'] ) {
		if ( $attributes['labelHideTablet'] ) {
			$block_style['classes'][] = 'gtm-has-post-share-hide-label-on-tablet';
		}

		if ( $attributes['labelHidePhone'] ) {
			$block_style['classes'][] = 'gtm-has-post-share-hide-label-on-phone';
		}
	}

	if ( $attributes['enableIcon'] ) {
		$block_style['classes'][] = 'gtm-has-post-share-enable-icon';
	}

	if ( $attributes['enableLabel'] ) {
		$block_style['classes'][] = 'gtm-has-post-share-enable-label';
	}

	gtm_css_compileCssVar( $block_style, "post-share-accent-color", gtm_css_parseColorValue( $attributes['accentColor'] ) );
	gtm_css_compileCssVar( $block_style, "post-share-accent-hover-color", gtm_css_parseColorValue( $attributes['accentHoverColor'] ) );

	gtm_css_compileCssVar( $block_style, "post-share-text-color", gtm_css_parseColorValue( $attributes['textColor'] ) );
	gtm_css_compileCssVar( $block_style, "post-share-text-hover-color", gtm_css_parseColorValue( $attributes['textHoverColor'] ) );

	gtm_css_compileCssVar( $block_style, "post-share-padding", gtm_css_parseResponsiveBoxProps( $attributes['padding'] ) );

	gtm_css_compileCssVar( $block_style, "post-share-radius", gtm_css_parseBorderRadiusValue( $attributes['radius'] ) );

	gtm_css_compileCssVar( $block_style, "post-share-shadow", gtm_css_parseShadowValue( $attributes['shadow'] ) );

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

	gtm_css_compileCssVar( $block_style, "post-share-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );

	gtm_css_compileCssVar( $block_style, "post-share-typography", gtm_css_parseTypographyProps( $attributes['typography'] ) );

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