kollapsminoriteten/wp-content/plugins/jetpack/extensions/blocks/google-calendar/google-calendar.php

68 lines
1.7 KiB
PHP
Raw Normal View History

2020-03-03 18:49:45 +01:00
<?php
/**
* Google Calendar Block.
*
* @since 8.3.0
*
* @package Jetpack
*/
2020-05-06 17:20:49 +02:00
namespace Automattic\Jetpack\Extensions\Google_Calendar;
use Jetpack_AMP_Support;
use Jetpack_Gutenberg;
2020-03-03 18:49:45 +01:00
const FEATURE_NAME = 'google-calendar';
const BLOCK_NAME = 'jetpack/' . FEATURE_NAME;
/**
* Registers the block for use in Gutenberg
* This is done via an action so that we can disable
* registration if we need to.
*/
function register_block() {
jetpack_register_block(
BLOCK_NAME,
array(
2020-05-06 17:20:49 +02:00
'render_callback' => __NAMESPACE__ . '\load_assets',
2020-03-03 18:49:45 +01:00
)
);
}
2020-05-06 17:20:49 +02:00
add_action( 'init', __NAMESPACE__ . '\register_block' );
2020-03-03 18:49:45 +01:00
/**
* Google Calendar block registration/dependency declaration.
*
* @param array $attr Array containing the Google Calendar block attributes.
* @return string
*/
function load_assets( $attr ) {
$height = isset( $attr['height'] ) ? $attr['height'] : '600';
$url = isset( $attr['url'] )
2020-05-06 17:20:49 +02:00
? Jetpack_Gutenberg::validate_block_embed_url( $attr['url'], array( 'calendar.google.com' ) ) :
2020-03-03 18:49:45 +01:00
'';
2020-05-06 17:20:49 +02:00
$classes = Jetpack_Gutenberg::block_classes( FEATURE_NAME, $attr );
Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME );
2020-03-03 18:49:45 +01:00
if ( empty( $url ) ) {
return;
}
2020-05-06 17:20:49 +02:00
if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
2020-03-03 18:49:45 +01:00
return sprintf(
2020-05-06 17:20:49 +02:00
'<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>',
2020-03-03 18:49:45 +01:00
esc_attr( $classes ),
esc_url( $url ),
absint( $height )
);
} else {
return sprintf(
2020-05-06 17:20:49 +02:00
'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" height="%3$d"></iframe></div>',
2020-03-03 18:49:45 +01:00
esc_attr( $classes ),
esc_url( $url ),
absint( $height )
);
}
}