post_content );
// Return early if empty to prevent DOMDocument::loadHTML fatal.
if ( empty( $content ) ) {
return;
}
/* Suppress warnings */
libxml_use_internal_errors( true );
@$post_html->loadHTML( $content ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
libxml_use_internal_errors( false );
$xpath = new \DOMXPath( $post_html );
$container = $xpath->query( '//div[ contains( @class, "wp-block-jetpack-map" ) ]' )->item( $map_block_counter - 1 );
/* Check that we have a block matching the counter position */
if ( ! $container ) {
return;
}
/* Compile scripts and styles */
ob_start();
add_filter( 'jetpack_is_amp_request', '__return_false' );
Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
wp_scripts()->do_items();
wp_styles()->do_items();
add_filter( 'jetpack_is_amp_request', '__return_true' );
$head_content = ob_get_clean();
/* Put together a new complete document containing only the requested block markup and the scripts/styles needed to render it */
$block_markup = $post_html->saveHTML( $container );
$access_token = Jetpack_Mapbox_Helper::get_access_token();
$page_html = sprintf(
'%s%s',
$head_content,
preg_replace( '/(?<=
$points,
'zoom' => 8,
'mapCenter' => array(
'lng' => $points[0]['coordinates']['longitude'],
'lat' => $points[0]['coordinates']['latitude'],
),
);
$list_items = array_map(
function ( $point ) {
$link = add_query_arg(
array(
'api' => 1,
'query' => $point['coordinates']['latitude'] . ',' . $point['coordinates']['longitude'],
),
'https://www.google.com/maps/search/'
);
return sprintf( '
%s', esc_url( $link ), $point['title'] );
},
$points
);
$map_block = '' . PHP_EOL;
$map_block .= sprintf(
'
',
esc_html( wp_json_encode( $map_block_data['points'] ) ),
$map_block_data['zoom'],
esc_html( wp_json_encode( $map_block_data['mapCenter'] ) )
);
$map_block .= '
' . implode( "\n", $list_items ) . '
';
$map_block .= '
' . PHP_EOL;
$map_block .= '';
return $map_block;
}