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
|
|
|
/** |
9
|
|
|
* Map block. |
10
|
|
|
* |
11
|
|
|
* @since 6.8.0 |
12
|
|
|
*/ |
13
|
|
|
jetpack_register_block( |
14
|
|
|
'map', |
15
|
|
|
array( |
16
|
|
|
'render_callback' => 'jetpack_map_block_load_assets', |
17
|
|
|
) |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Map block registration/dependency declaration. |
22
|
|
|
* |
23
|
|
|
* @param array $attr - Array containing the map block attributes. |
24
|
|
|
* @param string $content - String containing the map block content. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
function jetpack_map_block_load_assets( $attr, $content ) { |
29
|
|
|
$dependencies = array( |
30
|
|
|
'lodash', |
31
|
|
|
'wp-element', |
32
|
|
|
'wp-i18n', |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$api_key = Jetpack_Options::get_option( 'mapbox_api_key' ); |
36
|
|
|
|
37
|
|
|
Jetpack_Gutenberg::load_assets_as_required( 'map', $dependencies ); |
38
|
|
|
|
39
|
|
|
return preg_replace( '/<div /', '<div data-api-key="' . esc_attr( $api_key ) . '" ', $content, 1 ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Tiled Gallery block. Depends on the Photon module. |
45
|
|
|
* |
46
|
|
|
* @since 6.9.0 |
47
|
|
|
*/ |
48
|
|
|
if ( |
49
|
|
|
( defined( 'IS_WPCOM' ) && IS_WPCOM ) || |
50
|
|
|
class_exists( 'Jetpack_Photon' ) && Jetpack::is_module_active( 'photon' ) |
51
|
|
|
) { |
52
|
|
|
jetpack_register_block( |
53
|
|
|
'tiled-gallery', |
54
|
|
|
array( |
55
|
|
|
'render_callback' => 'jetpack_tiled_gallery_load_block_assets', |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Tiled gallery block registration/dependency declaration. |
61
|
|
|
* |
62
|
|
|
* @param array $attr - Array containing the block attributes. |
63
|
|
|
* @param string $content - String containing the block content. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
function jetpack_tiled_gallery_load_block_assets( $attr, $content ) { |
68
|
|
|
$dependencies = array( |
69
|
|
|
'lodash', |
70
|
|
|
'wp-i18n', |
71
|
|
|
'wp-token-list', |
72
|
|
|
); |
73
|
|
|
Jetpack_Gutenberg::load_assets_as_required( 'tiled-gallery', $dependencies ); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Filter the output of the Tiled Galleries content. |
77
|
|
|
* |
78
|
|
|
* @module tiled-gallery |
79
|
|
|
* |
80
|
|
|
* @since 6.9.0 |
81
|
|
|
* |
82
|
|
|
* @param string $content Tiled Gallery block content. |
83
|
|
|
*/ |
84
|
|
|
return apply_filters( 'jetpack_tiled_galleries_block_content', $content ); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* GIF Block. |
90
|
|
|
* |
91
|
|
|
* @since 7.0.0 |
92
|
|
|
*/ |
93
|
|
|
jetpack_register_block( |
94
|
|
|
'gif', |
95
|
|
|
array( |
96
|
|
|
'render_callback' => 'jetpack_gif_block_render', |
97
|
|
|
) |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Gif block registration/dependency declaration. |
102
|
|
|
* |
103
|
|
|
* @param array $attr - Array containing the gif block attributes. |
104
|
|
|
* |
105
|
|
|
* @return string |
106
|
|
|
*/ |
107
|
|
|
function jetpack_gif_block_render( $attr ) { |
108
|
|
|
$align = isset( $attr['align'] ) ? $attr['align'] : 'center'; |
109
|
|
|
$padding_top = isset( $attr['paddingTop'] ) ? $attr['paddingTop'] : 0; |
110
|
|
|
$style = 'padding-top:' . $padding_top; |
111
|
|
|
$giphy_url = isset( $attr['giphyUrl'] ) ? $attr['giphyUrl'] : null; |
112
|
|
|
$search_text = isset( $attr['searchText'] ) ? $attr['searchText'] : ''; |
113
|
|
|
$caption = isset( $attr['caption'] ) ? $attr['caption'] : null; |
114
|
|
|
|
115
|
|
|
if ( ! $giphy_url ) { |
116
|
|
|
return null; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$classes = array( |
120
|
|
|
'wp-block-jetpack-gif', |
121
|
|
|
'align' . $align, |
122
|
|
|
); |
123
|
|
|
if ( isset( $attr['className'] ) ) { |
124
|
|
|
array_push( $classes, $attr['className'] ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
ob_start(); |
128
|
|
|
?> |
129
|
|
|
<div class="<?php echo esc_attr( implode( $classes, ' ' ) ); ?>"> |
130
|
|
|
<figure> |
131
|
|
|
<div class="wp-block-jetpack-gif-wrapper" style="<?php echo esc_attr( $style ); ?>"> |
132
|
|
|
<iframe src="<?php echo esc_url( $giphy_url ); ?>" |
133
|
|
|
title="<?php echo esc_attr( $search_text ); ?>"></iframe> |
134
|
|
|
</div> |
135
|
|
|
<?php if ( $caption ) : ?> |
136
|
|
|
<figcaption |
137
|
|
|
class="wp-block-jetpack-gif-caption gallery-caption"><?php echo wp_kses_post( $caption ); ?></figcaption> |
138
|
|
|
<?php endif; ?> |
139
|
|
|
</figure> |
140
|
|
|
</div> |
141
|
|
|
<?php |
142
|
|
|
$html = ob_get_clean(); |
143
|
|
|
|
144
|
|
|
Jetpack_Gutenberg::load_assets_as_required( 'gif' ); |
145
|
|
|
|
146
|
|
|
return $html; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Contact Info block and its child blocks. |
151
|
|
|
*/ |
152
|
|
|
jetpack_register_block( |
153
|
|
|
'contact-info', |
154
|
|
|
array( |
155
|
|
|
'render_callback' => 'jetpack_contact_info_block_load_assets', |
156
|
|
|
) |
157
|
|
|
); |
158
|
|
|
jetpack_register_block( |
159
|
|
|
'email', |
160
|
|
|
array( 'parent' => array( 'jetpack/contact-info' ) ) |
161
|
|
|
); |
162
|
|
|
jetpack_register_block( |
163
|
|
|
'address', |
164
|
|
|
array( 'parent' => array( 'jetpack/contact-info' ) ) |
165
|
|
|
); |
166
|
|
|
jetpack_register_block( |
167
|
|
|
'phone', |
168
|
|
|
array( 'parent' => array( 'jetpack/contact-info' ) ) |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Contact info block registration/dependency declaration. |
173
|
|
|
* |
174
|
|
|
* @param array $attr - Array containing the contact info block attributes. |
175
|
|
|
* @param string $content - String containing the contact info block content. |
176
|
|
|
* |
177
|
|
|
* @return string |
178
|
|
|
*/ |
179
|
|
|
function jetpack_contact_info_block_load_assets( $attr, $content ) { |
180
|
|
|
Jetpack_Gutenberg::load_assets_as_required( 'contact-info' ); |
181
|
|
|
return $content; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* VR Block. |
186
|
|
|
*/ |
187
|
|
|
jetpack_register_block( 'vr' ); |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Slideshow Block. |
191
|
|
|
*/ |
192
|
|
|
jetpack_register_block( |
193
|
|
|
'slideshow', |
194
|
|
|
array( |
195
|
|
|
'render_callback' => 'jetpack_slideshow_block_load_assets', |
196
|
|
|
) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Slideshow block registration/dependency declaration. |
201
|
|
|
* |
202
|
|
|
* @param array $attr - Array containing the slideshow block attributes. |
203
|
|
|
* @param string $content - String containing the slideshow block content. |
204
|
|
|
* |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
|
|
function jetpack_slideshow_block_load_assets( $attr, $content ) { |
208
|
|
|
$dependencies = array( |
209
|
|
|
'lodash', |
210
|
|
|
'wp-element', |
211
|
|
|
'wp-i18n', |
212
|
|
|
); |
213
|
|
|
Jetpack_Gutenberg::load_assets_as_required( 'slideshow', $dependencies ); |
214
|
|
|
|
215
|
|
|
return $content; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Business Hours Block. |
220
|
|
|
*/ |
221
|
|
|
jetpack_register_block( |
222
|
|
|
'business-hours', |
223
|
|
|
array( 'render_callback' => 'jetpack_business_hours_render' ) |
224
|
|
|
); |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Business Hours Block dynamic rending of the glock. |
228
|
|
|
* |
229
|
|
|
* @param array $attributes Array containing the business hours block attributes. |
230
|
|
|
* @param string $content String containing the business hours block content. |
231
|
|
|
* |
232
|
|
|
* @return string |
233
|
|
|
*/ |
234
|
|
|
function jetpack_business_hours_render( $attributes, $content ) { |
235
|
|
|
global $wp_locale; |
236
|
|
|
|
237
|
|
|
if ( empty( $attributes['hours'] ) || ! is_array( $attributes['hours'] ) ) { |
238
|
|
|
return $content; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$start_of_week = (int) get_option( 'start_of_week', 0 ); |
242
|
|
|
$time_format = get_option( 'time_format' ); |
243
|
|
|
$today = current_time( 'D' ); |
244
|
|
|
$custom_class_name = isset( $attributes['className'] ) ? $attributes['className'] : ''; |
|
|
|
|
245
|
|
|
$content = sprintf( |
246
|
|
|
'<dl class="jetpack-business-hours %s">', |
247
|
|
|
! empty( $attributes['className'] ) ? esc_attr( $attributes['className'] ) : '' |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
$days = array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ); |
251
|
|
|
|
252
|
|
|
if ( $start_of_week ) { |
253
|
|
|
$chunk1 = array_slice( $attributes['hours'], 0, $start_of_week ); |
254
|
|
|
$chunk2 = array_slice( $attributes['hours'], $start_of_week ); |
255
|
|
|
$attributes['hours'] = array_merge( $chunk2, $chunk1 ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
foreach ( $attributes['hours'] as $day => $hours ) { |
259
|
|
|
$opening = strtotime( $hours['opening'] ); |
260
|
|
|
$closing = strtotime( $hours['closing'] ); |
261
|
|
|
|
262
|
|
|
$content .= '<dt class="' . esc_attr( $day ) . '">' . |
263
|
|
|
ucfirst( $wp_locale->get_weekday( array_search( $day, $days ) ) ) . |
264
|
|
|
'</dt>'; |
265
|
|
|
$content .= '<dd class="' . esc_attr( $day ) . '">'; |
266
|
|
|
if ( $hours['opening'] && $hours['closing'] ) { |
267
|
|
|
$content .= sprintf( |
268
|
|
|
/* Translators: Business opening hours info. */ |
269
|
|
|
_x( 'From %1$s to %2$s', 'from business opening hour to closing hour', 'jetpack' ), |
270
|
|
|
date( $time_format, $opening ), |
271
|
|
|
date( $time_format, $closing ) |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
if ( $today === $day ) { |
275
|
|
|
$now = strtotime( current_time( 'H:i' ) ); |
276
|
|
|
if ( $now < $opening ) { |
277
|
|
|
$content .= '<br />'; |
278
|
|
|
$content .= esc_html( sprintf( |
279
|
|
|
/* Translators: Amount of time until business opens. */ |
280
|
|
|
_x( 'Opening in %s', 'Amount of time until business opens', 'jetpack' ), |
281
|
|
|
human_time_diff( $now, $opening ) |
282
|
|
|
) ); |
283
|
|
|
} elseif ( $now >= $opening && $now < $closing ) { |
284
|
|
|
$content .= '<br />'; |
285
|
|
|
$content .= esc_html( sprintf( |
286
|
|
|
/* Translators: Amount of time until business closes. */ |
287
|
|
|
_x( 'Closing in %s', 'Amount of time until business closes', 'jetpack' ), |
288
|
|
|
human_time_diff( $now, $closing ) |
289
|
|
|
) ); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
} else { |
293
|
|
|
$content .= esc_html__( 'CLOSED', 'jetpack' ); |
294
|
|
|
} |
295
|
|
|
$content .= '</dd>'; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
$content .= '</dl>'; |
299
|
|
|
|
300
|
|
|
return $content; |
301
|
|
|
} |
302
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.