<?php
/**
 * Template used to display arguments used to build the carousel modal.
 *
 * @html-template Jetpack_Tiled_Gallery_Layout::partial
 * @package automattic/jetpack
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit( 0 );
}

// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- HTML template, let Phan handle it.

$item = $context['item'];

// Only emit the EXIF metadata when the option to display it is enabled, to
// avoid bloating the markup on sites that have turned EXIF off. Mirrors the
// gating in Jetpack_Carousel::add_data_to_images().
// See https://github.com/Automattic/jetpack/issues/32862.
$display_exif     = 1 === (int) Jetpack_Options::get_option_and_ensure_autoload( 'carousel_display_exif', 1 );
$fuzzy_image_meta = '';

if ( $display_exif ) {
	$image_meta = $item->fuzzy_image_meta(); // See https://github.com/Automattic/jetpack/issues/2765 .
	if ( isset( $image_meta['keywords'] ) ) {
		unset( $image_meta['keywords'] );
	}

	// Using JSON_HEX_AMP avoids breakage due to `esc_attr()` refusing to double-encode.
	$fuzzy_image_meta = (string) wp_json_encode( map_deep( $image_meta, 'strval' ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT );
}

?>
data-attachment-id="<?php echo esc_attr( $item->image->ID ); ?>"
data-orig-file="<?php echo esc_url( wp_get_attachment_url( $item->image->ID ) ); ?>"
data-orig-size="<?php echo esc_attr( $item->meta_width() ); ?>,<?php echo esc_attr( $item->meta_height() ); ?>"
data-comments-opened="<?php echo esc_attr( comments_open( $item->image->ID ) ); ?>"
<?php if ( $display_exif ) : ?>
data-image-meta="<?php echo esc_attr( $fuzzy_image_meta ); ?>"
<?php endif; ?>
<?php // The two lines below use `esc_attr( htmlspecialchars( ) )` because esc_attr tries to be too smart and won't double-encode, and we need that here. ?>
data-image-title="<?php echo esc_attr( htmlspecialchars( wptexturize( $item->image->post_title ), ENT_COMPAT ) ); ?>"
data-image-description="<?php echo esc_attr( htmlspecialchars( wpautop( wptexturize( $item->image->post_content ) ), ENT_COMPAT ) ); ?>"
data-medium-file="<?php echo esc_url( $item->medium_file() ); ?>"
data-large-file="<?php echo esc_url( $item->large_file() ); ?>"
