| Conditions | 9 |
| Paths | 144 |
| Total Lines | 44 |
| 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 | /* TODO: replace with centralized block_class function */ |
||
| 36 | $align = isset( $attr['align'] ) ? $attr['align'] : 'center'; |
||
| 37 | $type = 'gif'; |
||
| 38 | $classes = array( |
||
| 39 | 'wp-block-jetpack-' . $type, |
||
| 40 | 'align' . $align, |
||
| 41 | ); |
||
| 42 | if ( isset( $attr['className'] ) ) { |
||
| 43 | array_push( $classes, $attr['className'] ); |
||
| 44 | } |
||
| 45 | $classes = implode( $classes, ' ' ); |
||
| 46 | |||
| 47 | ob_start(); |
||
| 48 | ?> |
||
| 49 | <div class="<?php echo esc_attr( $classes ); ?>"> |
||
| 50 | <figure> |
||
| 51 | <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
||
| 52 | <iframe src="<?php echo esc_url( $giphy_url ); ?>" |
||
| 53 | title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
||
| 54 | </div> |
||
| 55 | <?php if ( $caption ) : ?> |
||
| 56 | <figcaption |
||
| 57 | class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption> |
||
| 58 | <?php endif; ?> |
||
| 59 | </figure> |
||
| 60 | </div> |
||
| 61 | <?php |
||
| 62 | $html = ob_get_clean(); |
||
| 63 | |||
| 64 | Jetpack_Gutenberg::load_assets_as_required( 'gif' ); |
||
| 65 | |||
| 66 | return $html; |
||
| 67 | } |
||
| 68 |