PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 All 503 releases
jetpack / extensions / blocks / google-calendar / render.php

render.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.1, at extensions/blocks/google-calendar/render.php

74 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Google Calendar block render implementation.
4 *
5 * Loaded lazily from google-calendar.php only when the block is rendered, to keep
6 * the render body out of the eager front-end PHP/opcache footprint.
7 *
8 * @package automattic/jetpack
9 */
10
11 namespace Automattic\Jetpack\Extensions\Google_Calendar;
12
13 use Automattic\Jetpack\Blocks;
14 use Jetpack_Gutenberg;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit( 0 );
18 }
19
20 /**
21 * Dynamic rendering of the block.
22 *
23 * @param array $attr Array containing the Google Calendar block attributes.
24 * @return string
25 */
26 function render_implementation( $attr ) {
27 $height = $attr['height'] ?? '600';
28 $url = isset( $attr['url'] )
29 ? Jetpack_Gutenberg::validate_block_embed_url( $attr['url'], array( 'calendar.google.com' ) ) :
30 '';
31 $classes = Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attr );
32
33 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
34
35 if ( empty( $url ) ) {
36 return '';
37 }
38
39 $sandbox = 'allow-scripts allow-same-origin allow-popups';
40 if ( Blocks::is_amp_request() ) {
41 $noscript_src = str_replace(
42 '//calendar.google.com/calendar/embed',
43 '//calendar.google.com/calendar/htmlembed',
44 $url
45 );
46
47 $iframe = sprintf(
48 '<amp-iframe src="%1$s" frameborder="0" scrolling="no" height="%2$d" layout="fixed-height" sandbox="%3$s">%4$s%5$s</amp-iframe>',
49 esc_url( $url ),
50 absint( $height ),
51 esc_attr( $sandbox ),
52 sprintf(
53 '<a href="%s" placeholder>%s</a>',
54 esc_url( $url ),
55 esc_html__( 'Google Calendar', 'jetpack' )
56 ),
57 sprintf(
58 '<noscript><iframe src="%1$s" frameborder="0" scrolling="no" sandbox="%2$s"></iframe></noscript>',
59 esc_url( $noscript_src ),
60 esc_attr( $sandbox )
61 )
62 );
63 } else {
64 $iframe = sprintf(
65 '<iframe src="%1$s" frameborder="0" style="border:0" scrolling="no" height="%2$d" width="100%%" sandbox="%3$s"></iframe>',
66 esc_url( $url ),
67 absint( $height ),
68 esc_attr( $sandbox )
69 );
70 }
71
72 return sprintf( '<div class="%s">%s</div>', esc_attr( $classes ), $iframe );
73 }
74