|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Google Calendar Block. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 8.3.0 |
|
6
|
|
|
* |
|
7
|
|
|
* @package Jetpack |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Jetpack\Google_Calendar_Block; |
|
11
|
|
|
|
|
12
|
|
|
const FEATURE_NAME = 'google-calendar'; |
|
13
|
|
|
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Registers the block for use in Gutenberg |
|
17
|
|
|
* This is done via an action so that we can disable |
|
18
|
|
|
* registration if we need to. |
|
19
|
|
|
*/ |
|
20
|
|
|
function register_block() { |
|
21
|
|
|
jetpack_register_block( |
|
22
|
|
|
BLOCK_NAME, |
|
23
|
|
|
array( |
|
24
|
|
|
'render_callback' => 'Jetpack\Google_Calendar_Block\load_assets', |
|
25
|
|
|
) |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
add_action( 'init', 'Jetpack\Google_Calendar_Block\register_block' ); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Set the availability of the block as the editor |
|
33
|
|
|
* is loaded |
|
34
|
|
|
*/ |
|
35
|
|
|
function set_availability() { |
|
36
|
|
|
\Jetpack_Gutenberg::set_extension_available( BLOCK_NAME ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
add_action( 'init', 'Jetpack\Google_Calendar_Block\set_availability' ); |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Google Calendar block registration/dependency declaration. |
|
43
|
|
|
* |
|
44
|
|
|
* @param array $attr Array containing the Google Calendar block attributes. |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
function load_assets( $attr ) { |
|
48
|
|
|
$width = isset( $attr['width'] ) ? $attr['width'] : '800'; |
|
49
|
|
|
$height = isset( $attr['height'] ) ? $attr['height'] : '600'; |
|
50
|
|
|
$url = isset( $attr['url'] ) ? $attr['url'] : ''; |
|
51
|
|
|
$classes = \Jetpack_Gutenberg::block_classes( 'google-calendar', $attr ); |
|
52
|
|
|
|
|
53
|
|
|
if ( empty( $url ) ) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if ( class_exists( 'Jetpack_AMP_Support' ) && \Jetpack_AMP_Support::is_amp_request() ) { |
|
58
|
|
|
return sprintf( |
|
59
|
|
|
'<div class="%1$s"><amp-iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" width="%3$d" height="%4$d" sandbox="allow-scripts allow-same-origin" layout="responsive"></amp-iframe></div>', |
|
60
|
|
|
esc_attr( $classes ), |
|
61
|
|
|
esc_url( $url ), |
|
62
|
|
|
absint( $width ), |
|
63
|
|
|
absint( $height ) |
|
64
|
|
|
); |
|
65
|
|
|
} else { |
|
66
|
|
|
return sprintf( |
|
67
|
|
|
'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" width="%3$d" height="%4$d"></iframe></div>', |
|
68
|
|
|
esc_attr( $classes ), |
|
69
|
|
|
esc_url( $url ), |
|
70
|
|
|
absint( $width ), |
|
71
|
|
|
absint( $height ) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|