| 1 |
<?php |
| 2 |
/** |
| 3 |
* Load code specific to Gutenberg blocks which are not tied to a module. |
| 4 |
* This file is unusual, and is not an actual `module` as such. |
| 5 |
* It is included in ./module-extras.php |
| 6 |
*/ |
| 7 |
|
| 8 |
jetpack_register_block( |
| 9 |
'gif', |
| 10 |
array( |
| 11 |
'render_callback' => 'jetpack_gif_block_render', |
| 12 |
) |
| 13 |
); |
| 14 |
|
| 15 |
jetpack_register_block( |
| 16 |
'map', |
| 17 |
array( |
| 18 |
'render_callback' => 'jetpack_map_block_load_assets', |
| 19 |
) |
| 20 |
); |
| 21 |
|
| 22 |
jetpack_register_block( 'vr' ); |
| 23 |
|
| 24 |
/** |
| 25 |
* Tiled Gallery block. Depends on the Photon module. |
| 26 |
* |
| 27 |
* @since 6.9.0 |
| 28 |
*/ |
| 29 |
if ( |
| 30 |
( defined( 'IS_WPCOM' ) && IS_WPCOM ) || |
| 31 |
class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) |
| 32 |
) { |
| 33 |
jetpack_register_block( |
| 34 |
'tiled-gallery', |
| 35 |
array( |
| 36 |
'render_callback' => 'jetpack_tiled_gallery_load_block_assets', |
| 37 |
) |
| 38 |
); |
| 39 |
|
| 40 |
/** |
| 41 |
* Tiled gallery block registration/dependency declaration. |
| 42 |
* |
| 43 |
* @param array $attr - Array containing the block attributes. |
| 44 |
* @param string $content - String containing the block content. |
| 45 |
* |
| 46 |
* @return string |
| 47 |
*/ |
| 48 |
function jetpack_tiled_gallery_load_block_assets( $attr, $content ) { |
| 49 |
$dependencies = array( |
| 50 |
'lodash', |
| 51 |
'wp-i18n', |
| 52 |
'wp-token-list', |
| 53 |
); |
| 54 |
Jetpack_Gutenberg::load_assets_as_required( 'tiled-gallery', $dependencies ); |
| 55 |
|
| 56 |
/** |
| 57 |
* Filter the output of the Tiled Galleries content. |
| 58 |
* |
| 59 |
* @module tiled-gallery |
| 60 |
* |
| 61 |
* @since 6.9.0 |
| 62 |
* |
| 63 |
* @param string $content Tiled Gallery block content. |
| 64 |
*/ |
| 65 |
return apply_filters( 'jetpack_tiled_galleries_block_content', $content ); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Gif block registration/dependency declaration. |
| 71 |
* |
| 72 |
* @param array $attr - Array containing the map block attributes. |
| 73 |
* |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
function jetpack_gif_block_render( $attr ) { |
| 77 |
$align = isset( $attr['align'] ) ? $attr['align'] : 'center'; |
| 78 |
$padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0; |
| 79 |
$style = 'padding-top:' . $padding_top; |
| 80 |
$giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null; |
| 81 |
$search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : ''; |
| 82 |
$caption = isset( $attr['caption'] ) ? $attr['caption'] : null; |
| 83 |
|
| 84 |
if ( ! $giphy_url ) { |
| 85 |
return null; |
| 86 |
} |
| 87 |
|
| 88 |
$classes = array( |
| 89 |
'wp-block-jetpack-gif', |
| 90 |
'align' . $align, |
| 91 |
); |
| 92 |
if ( isset( $attr['className'] ) ) { |
| 93 |
array_push( $classes, $attr['className'] ); |
| 94 |
} |
| 95 |
|
| 96 |
ob_start(); |
| 97 |
?> |
| 98 |
<div class="<?php echo esc_attr( implode( $classes, ' ' ) ); ?>"> |
| 99 |
<figure> |
| 100 |
<div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
| 101 |
<iframe src="<?php echo esc_url( $giphy_url ); ?>" title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
| 102 |
</div> |
| 103 |
<?php if ( $caption ) : ?> |
| 104 |
<figcaption class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption> |
| 105 |
<?php endif; ?> |
| 106 |
</figure> |
| 107 |
</div> |
| 108 |
<?php |
| 109 |
$html = ob_get_clean(); |
| 110 |
|
| 111 |
Jetpack_Gutenberg::load_assets_as_required( 'gif' ); |
| 112 |
return $html; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Map block registration/dependency declaration. |
| 117 |
* |
| 118 |
* @param array $attr - Array containing the map block attributes. |
| 119 |
* @param string $content - String containing the map block content. |
| 120 |
* |
| 121 |
* @return string |
| 122 |
*/ |
| 123 |
function jetpack_map_block_load_assets( $attr, $content ) { |
| 124 |
$dependencies = array( |
| 125 |
'lodash', |
| 126 |
'wp-element', |
| 127 |
'wp-i18n', |
| 128 |
); |
| 129 |
|
| 130 |
$api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); |
| 131 |
|
| 132 |
Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies ); |
| 133 |
return preg_replace( '/<div /', '<div data-api-key="'. esc_attr( $api_key ) .'" ', $content, 1 ); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Register the Contact Info block and its child blocks. |
| 138 |
*/ |
| 139 |
jetpack_register_block( 'contact-info' ); |
| 140 |
jetpack_register_block( |
| 141 |
'email', |
| 142 |
array( 'parent' => array( 'jetpack/contact-info' ) ) |
| 143 |
); |
| 144 |
jetpack_register_block( |
| 145 |
'address', |
| 146 |
array( 'parent' => array( 'jetpack/contact-info' ) ) |
| 147 |
); |
| 148 |
jetpack_register_block( |
| 149 |
'phone', |
| 150 |
array( 'parent' => array( 'jetpack/contact-info' ) ) |
| 151 |
); |
| 152 |
|