Completed
Push — update/calendly-embed-code ( 001c02...b82934 )
by
unknown
08:51
created

google-calendar.php ➔ load_assets()   B

Complexity

Conditions 7
Paths 24

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 24
nop 1
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
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
 * Google Calendar block registration/dependency declaration.
33
 *
34
 * @param array $attr Array containing the Google Calendar block attributes.
35
 * @return string
36
 */
37
function load_assets( $attr ) {
38
	$width   = isset( $attr['width'] ) ? $attr['width'] : '800';
39
	$height  = isset( $attr['height'] ) ? $attr['height'] : '600';
40
	$url     = isset( $attr['url'] ) ? $attr['url'] : '';
41
	$classes = \Jetpack_Gutenberg::block_classes( 'google-calendar', $attr );
42
43
	if ( empty( $url ) ) {
44
		return;
45
	}
46
47
	if ( class_exists( 'Jetpack_AMP_Support' ) && \Jetpack_AMP_Support::is_amp_request() ) {
48
		return sprintf(
49
			'<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>',
50
			esc_attr( $classes ),
51
			esc_url( $url ),
52
			absint( $width ),
53
			absint( $height )
54
		);
55
	} else {
56
		return sprintf(
57
			'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" width="%3$d" height="%4$d"></iframe></div>',
58
			esc_attr( $classes ),
59
			esc_url( $url ),
60
			absint( $width ),
61
			absint( $height )
62
		);
63
	}
64
}
65