Completed
Push — renovate/webpack-cli-3.x ( a49c46...d89017 )
by
unknown
44:08 queued 37:51
created

google-calendar.php ➔ is_available()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 0
dl 0
loc 17
rs 9.3888
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A google-calendar.php ➔ register_block() 0 8 1
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
	$height  = isset( $attr['height'] ) ? $attr['height'] : '600';
39
	$url     = isset( $attr['url'] )
40
		? \Jetpack_Gutenberg::validate_block_embed_url( $attr['url'], array( 'calendar.google.com' ) ) :
41
		'';
42
	$classes = \Jetpack_Gutenberg::block_classes( 'google-calendar', $attr );
43
44
	\Jetpack_Gutenberg::load_assets_as_required( 'google-calendar' );
45
46
	if ( empty( $url ) ) {
47
		return;
48
	}
49
50
	if ( class_exists( 'Jetpack_AMP_Support' ) && \Jetpack_AMP_Support::is_amp_request() ) {
51
		return sprintf(
52
			'<div class="%1$s"><amp-iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" height="%3$d" sandbox="allow-scripts allow-same-origin" layout="responsive"></amp-iframe></div>',
53
			esc_attr( $classes ),
54
			esc_url( $url ),
55
			absint( $height )
56
		);
57
	} else {
58
		return sprintf(
59
			'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" height="%3$d"></iframe></div>',
60
			esc_attr( $classes ),
61
			esc_url( $url ),
62
			absint( $height )
63
		);
64
	}
65
}
66