← All changes
|
extensions/blocks/google-calendar/google-calendar.php
+9
-47
13.7.2
→
16.3-a.7
View file →
| @@ -9,10 +9,13 @@ | ||
| 9 | 9 | |
| 10 | 10 | namespace Automattic\Jetpack\Extensions\Google_Calendar; |
| 11 | 11 | |
| 12 | 12 | use Automattic\Jetpack\Blocks; |
| 13 | -use Jetpack_Gutenberg; | |
| 14 | 13 | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit( 0 ); | |
| 16 | +} | |
| 17 | + | |
| 15 | 18 | /** |
| 16 | 19 | * Registers the block for use in Gutenberg |
| 17 | 20 | * This is done via an action so that we can disable |
| 18 | 21 | * registration if we need to. |
| @@ -29,55 +32,14 @@ | ||
| 29 | 32 | |
| 30 | 33 | /** |
| 31 | 34 | * Google Calendar block registration/dependency declaration. |
| 32 | 35 | * |
| 36 | + * The render implementation lives in render.php and is only loaded when the | |
| 37 | + * block is actually rendered, keeping it out of the eager front-end path. | |
| 38 | + * | |
| 33 | 39 | * @param array $attr Array containing the Google Calendar block attributes. |
| 34 | 40 | * @return string |
| 35 | 41 | */ |
| 36 | 42 | function load_assets( $attr ) { |
| 37 | - $height = isset( $attr['height'] ) ? $attr['height'] : '600'; | |
| 38 | - $url = isset( $attr['url'] ) | |
| 39 | - ? Jetpack_Gutenberg::validate_block_embed_url( $attr['url'], array( 'calendar.google.com' ) ) : | |
| 40 | - ''; | |
| 41 | - $classes = Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr ); | |
| 42 | - | |
| 43 | - Jetpack_Gutenberg::load_assets_as_required( __DIR__ ); | |
| 44 | - | |
| 45 | - if ( empty( $url ) ) { | |
| 46 | - return ''; | |
| 47 | - } | |
| 48 | - | |
| 49 | - $sandbox = 'allow-scripts allow-same-origin allow-popups'; | |
| 50 | - if ( Blocks::is_amp_request() ) { | |
| 51 | - $noscript_src = str_replace( | |
| 52 | - '//calendar.google.com/calendar/embed', | |
| 53 | - '//calendar.google.com/calendar/htmlembed', | |
| 54 | - $url | |
| 55 | - ); | |
| 56 | - | |
| 57 | - $iframe = sprintf( | |
| 58 | - '<amp-iframe src="%1$s" frameborder="0" scrolling="no" height="%2$d" layout="fixed-height" sandbox="%3$s">%4$s%5$s</amp-iframe>', | |
| 59 | - esc_url( $url ), | |
| 60 | - absint( $height ), | |
| 61 | - esc_attr( $sandbox ), | |
| 62 | - sprintf( | |
| 63 | - '<a href="%s" placeholder>%s</a>', | |
| 64 | - esc_url( $url ), | |
| 65 | - esc_html__( 'Google Calendar', 'jetpack' ) | |
| 66 | - ), | |
| 67 | - sprintf( | |
| 68 | - '<noscript><iframe src="%1$s" frameborder="0" scrolling="no" sandbox="%2$s"></iframe></noscript>', | |
| 69 | - esc_url( $noscript_src ), | |
| 70 | - esc_attr( $sandbox ) | |
| 71 | - ) | |
| 72 | - ); | |
| 73 | - } else { | |
| 74 | - $iframe = sprintf( | |
| 75 | - '<iframe src="%1$s" frameborder="0" style="border:0" scrolling="no" height="%2$d" width="100%%" sandbox="%3$s"></iframe>', | |
| 76 | - esc_url( $url ), | |
| 77 | - absint( $height ), | |
| 78 | - esc_attr( $sandbox ) | |
| 79 | - ); | |
| 80 | - } | |
| 81 | - | |
| 82 | - return sprintf( '<div class="%s">%s</div>', esc_attr( $classes ), $iframe ); | |
| 43 | + require_once __DIR__ . '/render.php'; | |
| 44 | + return render_implementation( $attr ); | |
| 83 | 45 | } |