| Conditions | 9 |
| Paths | 80 |
| Total Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | function jetpack_gif_block_render( $attr ) { |
||
| 25 | $padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0; |
||
| 26 | $style = 'padding-top:' . $padding_top; |
||
| 27 | $giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null; |
||
| 28 | $search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : ''; |
||
| 29 | $caption = isset( $attr['caption'] ) ? $attr['caption'] : null; |
||
| 30 | |||
| 31 | if ( ! $giphy_url ) { |
||
| 32 | return null; |
||
| 33 | } |
||
| 34 | |||
| 35 | $classes = Jetpack_Gutenberg::block_classes( 'gif', $attr ); |
||
| 36 | |||
| 37 | $placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) ); |
||
| 38 | |||
| 39 | ob_start(); |
||
| 40 | ?> |
||
| 41 | <div class="<?php echo esc_attr( $classes ); ?>"> |
||
| 42 | <figure> |
||
| 43 | <?php if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) : ?> |
||
| 44 | <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"> |
||
| 45 | <div placeholder> |
||
| 46 | <?php echo wp_kses_post( $placeholder ); ?> |
||
| 47 | </div> |
||
| 48 | </amp-iframe> |
||
| 49 | <?php else : ?> |
||
| 50 | <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
||
| 51 | <iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
||
| 52 | </div> |
||
| 53 | <?php endif; ?> |
||
| 54 | <?php if ( $caption ) : ?> |
||
| 55 | <figcaption class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption> |
||
| 56 | <?php endif; ?> |
||
| 57 | </figure> |
||
| 58 | </div> |
||
| 59 | <?php |
||
| 60 | $html = ob_get_clean(); |
||
| 61 | |||
| 62 | Jetpack_Gutenberg::load_assets_as_required( 'gif' ); |
||
| 63 | |||
| 64 | return $html; |
||
| 65 | } |
||
| 66 |