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