Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * GIF Block. |
||
| 4 | * |
||
| 5 | * @since 7.0.0 |
||
| 6 | * |
||
| 7 | * @package Jetpack |
||
| 8 | */ |
||
| 9 | |||
| 10 | jetpack_register_block( |
||
| 11 | 'jetpack/gif', |
||
| 12 | array( |
||
| 13 | 'render_callback' => 'jetpack_gif_block_render', |
||
| 14 | ) |
||
| 15 | ); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Gif block registration/dependency declaration. |
||
| 19 | * |
||
| 20 | * @param array $attr - Array containing the gif block attributes. |
||
| 21 | * |
||
| 22 | * @return string |
||
| 23 | */ |
||
| 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'] ) |
||
| 28 | ? Jetpack_Gutenberg::validate_block_embed_url( $attr['giphyUrl'], array( 'giphy.com' ) ) |
||
| 29 | : null; |
||
| 30 | $search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : ''; |
||
| 31 | $caption = isset( $attr['caption'] ) ? $attr['caption'] : null; |
||
| 32 | |||
| 33 | if ( ! $giphy_url ) { |
||
|
0 ignored issues
–
show
|
|||
| 34 | return null; |
||
| 35 | } |
||
| 36 | |||
| 37 | $classes = Jetpack_Gutenberg::block_classes( 'gif', $attr ); |
||
| 38 | |||
| 39 | $placeholder = sprintf( '<a href="%s">%s</a>', esc_url( $giphy_url ), esc_attr( $search_text ) ); |
||
| 40 | |||
| 41 | ob_start(); |
||
| 42 | ?> |
||
| 43 | <div class="<?php echo esc_attr( $classes ); ?>"> |
||
| 44 | <figure> |
||
| 45 | <?php if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) : ?> |
||
| 46 | <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"> |
||
| 47 | <div placeholder> |
||
| 48 | <?php echo wp_kses_post( $placeholder ); ?> |
||
| 49 | </div> |
||
| 50 | </amp-iframe> |
||
| 51 | <?php else : ?> |
||
| 52 | <div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
||
| 53 | <iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
||
| 54 | </div> |
||
| 55 | <?php endif; ?> |
||
| 56 | <?php if ( $caption ) : ?> |
||
| 57 | <figcaption 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 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: