PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / extensions / blocks / gif / render.php

render.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at extensions/blocks/gif/render.php

71 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gif block render implementation.
4 *
5 * Loaded lazily from gif.php only when the block is rendered, to keep
6 * the render body out of the eager front-end PHP/opcache footprint.
7 *
8 * @package automattic/jetpack
9 */
10
11 namespace Automattic\Jetpack\Extensions\Gif;
12
13 use Automattic\Jetpack\Blocks;
14 use Jetpack_Gutenberg;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 0 );
18 }
19
20 /**
21 * Dynamic rendering of the block.
22 *
23 * @param array $attr - Array containing the gif block attributes.
24 *
25 * @return string
26 */
27 function render_implementation( $attr ) {
28 $padding_top = $attr['paddingTop'] ?? 0;
29 $style = 'padding-top:' . $padding_top;
30 $giphy_url = isset( $attr['giphyUrl'] )
31 ? Jetpack_Gutenberg::validate_block_embed_url( $attr['giphyUrl'], array( 'giphy.com' ) )
32 : null;
33 $search_text = $attr['searchText'] ?? '';
34 $caption = $attr['caption'] ?? null;
35
36 if ( ! $giphy_url ) {
37 return null;
38 }
39
40 $classes = Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr );
41
42 $placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) );
43
44 ob_start();
45 ?>
46 <div class="<?php echo esc_attr( $classes ); ?>">
47 <figure>
48 <?php if ( Blocks::is_amp_request() ) : ?>
49 <amp-iframe src="<?php echo esc_url( $giphy_url ); ?>" width="100" height="<?php echo absint( $padding_top ); ?>" sandbox="allow-scripts allow-same-origin" layout="responsive">
50 <div placeholder>
51 <?php echo wp_kses_post( $placeholder ); ?>
52 </div>
53 </amp-iframe>
54 <?php else : ?>
55 <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>">
56 <iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe>
57 </div>
58 <?php endif; ?>
59 <?php if ( $caption ) : ?>
60 <figcaption class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption>
61 <?php endif; ?>
62 </figure>
63 </div>
64 <?php
65 $html = ob_get_clean();
66
67 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
68
69 return $html;
70 }
71