PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 15.9.2
Jetpack – WP Security, Backup, Speed, & Growth v15.9.2
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / extensions / blocks / story / story.php
jetpack / extensions / blocks / story Last commit date
story.php 3 months ago
story.php
521 lines
1 <?php
2 /**
3 * Story Block.
4 *
5 * @since 8.6.1
6 *
7 * @package automattic/jetpack
8 */
9
10 namespace Automattic\Jetpack\Extensions\Story;
11
12 use Automattic\Jetpack\Blocks;
13 use Automattic\Jetpack\Connection\Connection_Assets;
14 use Automattic\Jetpack\Post_Media\Images;
15 use Jetpack;
16 use Jetpack_Gutenberg;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit( 0 );
20 }
21
22 const EMBED_SIZE = array( 360, 640 ); // twice as many pixels for retina displays.
23 const CROP_UP_TO = 0.2;
24 const MAX_BULLETS = 7;
25 const IMAGE_BREAKPOINTS = '(max-width: 460px) 576w, (max-width: 614px) 768w, 120vw'; // 120vw to match the 20% CROP_UP_TO ratio
26
27 /**
28 * Registers the block for use in Gutenberg
29 * This is done via an action so that we can disable
30 * registration if we need to.
31 */
32 function register_block() {
33 Blocks::jetpack_register_block(
34 __DIR__,
35 array( 'render_callback' => __NAMESPACE__ . '\render_block' )
36 );
37 }
38 add_action( 'init', __NAMESPACE__ . '\register_block' );
39
40 /**
41 * Compare 2 urls and return true if they likely correspond to the same resource.
42 * Ignore scheme, ports, query params and hashes and only compare hostname and pathname.
43 *
44 * @param string $url1 - First url used in comparison.
45 * @param string $url2 - Second url used in comparison.
46 *
47 * @return boolean
48 */
49 function is_same_resource( $url1, $url2 ) {
50 $url1_parsed = wp_parse_url( $url1 );
51 $url2_parsed = wp_parse_url( $url2 );
52 return isset( $url1_parsed['host'] ) &&
53 isset( $url2_parsed['host'] ) &&
54 isset( $url1_parsed['path'] ) &&
55 isset( $url2_parsed['path'] ) &&
56 $url1_parsed['host'] === $url2_parsed['host'] &&
57 $url1_parsed['path'] === $url2_parsed['path'];
58 }
59
60 /**
61 * Enrich media files retrieved from the story block attributes
62 * with extra information we can retrieve from the media library.
63 *
64 * @param array $media_files - List of media, each as an array containing the media attributes.
65 *
66 * @return array $media_files
67 */
68 function enrich_media_files( $media_files ) {
69 return array_filter(
70 array_map(
71 function ( $media_file ) {
72 if ( ! is_array( $media_file ) || ! isset( $media_file['type'] ) ) {
73 return null;
74 }
75 if ( 'image' === $media_file['type'] ) {
76 return enrich_image_meta( $media_file );
77 }
78 // VideoPress videos can sometimes have type 'file', and mime 'video/videopress' or 'video/mp4'.
79 // Let's fix `type` for those.
80 if (
81 'file' === $media_file['type']
82 && isset( $media_file['mime'] )
83 && str_starts_with( $media_file['mime'], 'video' )
84 ) {
85 $media_file['type'] = 'video';
86 }
87 if ( 'video' !== $media_file['type'] ) { // we only support images and videos at this point.
88 return null;
89 }
90 return enrich_video_meta( $media_file );
91 },
92 $media_files
93 )
94 );
95 }
96
97 /**
98 * Enrich image information with extra data we can retrieve from the media library.
99 * Add missing `width`, `height`, `srcset`, `sizes`, `title`, `alt` and `caption` properties to the image.
100 *
101 * @param array $media_file - An array containing the media attributes for a specific image.
102 *
103 * @return array $media_file_enriched
104 */
105 function enrich_image_meta( $media_file ) {
106 $attachment_id = $media_file['id'] ?? null;
107 $image = wp_get_attachment_image_src( $attachment_id, 'full', false );
108 if ( ! $image ) {
109 return $media_file;
110 }
111 list( $src, $width, $height ) = $image;
112 // Bail if url stored in block attributes is different than the media library one for that id.
113 if ( isset( $media_file['url'] ) && ! is_same_resource( $media_file['url'], $src ) ) {
114 return $media_file;
115 }
116 $image_meta = wp_get_attachment_metadata( $attachment_id );
117 if ( ! is_array( $image_meta ) ) {
118 return $media_file;
119 }
120 $size_array = array( absint( $width ), absint( $height ) );
121 return array_merge(
122 $media_file,
123 array(
124 'width' => absint( $width ),
125 'height' => absint( $height ),
126 'srcset' => wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id ),
127 'sizes' => IMAGE_BREAKPOINTS,
128 'title' => get_the_title( $attachment_id ),
129 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
130 'caption' => wp_get_attachment_caption( $attachment_id ),
131 )
132 );
133 }
134
135 /**
136 * Enrich video information with extra data we can retrieve from the media library.
137 * Add missing `width`, `height`, `alt`, `url`, `title`, `caption` and `poster` properties to the image.
138 *
139 * @param array $media_file - An array containing the media attributes for a specific video.
140 *
141 * @return array $media_file_enriched
142 */
143 function enrich_video_meta( $media_file ) {
144 $attachment_id = $media_file['id'] ?? null;
145 $video_meta = wp_get_attachment_metadata( $attachment_id );
146 if ( ! $video_meta ) {
147 return $media_file;
148 }
149
150 $video_url = ! empty( $video_meta['original']['url'] ) ? $video_meta['original']['url'] : wp_get_attachment_url( $attachment_id );
151
152 // Set the poster attribute for the video tag if a poster image is available.
153 $poster_url = null;
154 if ( ! empty( $video_meta['videopress']['poster'] ) ) {
155 $poster_url = $video_meta['videopress']['poster'];
156 } elseif ( ! empty( $video_meta['thumb'] ) ) {
157 $poster_url = str_replace( wp_basename( $video_url ), $video_meta['thumb'], $video_url );
158 }
159
160 if ( $poster_url ) {
161 // Use the global content width for thumbnail resize so we match the `w=` query parameter
162 // that jetpack is going to add when "Enable site accelerator" is enabled for images.
163 $content_width = (int) Jetpack::get_content_width();
164 $new_width = $content_width > 0 ? $content_width : EMBED_SIZE[0];
165 $poster_url = add_query_arg( 'w', $new_width, $poster_url );
166 }
167
168 return array_merge(
169 $media_file,
170 array(
171 'width' => absint( ! empty( $video_meta['width'] ) ? $video_meta['width'] : ( $media_file['width'] ?? 0 ) ),
172 'height' => absint( ! empty( $video_meta['height'] ) ? $video_meta['height'] : ( $media_file['height'] ?? 0 ) ),
173 'alt' => ! empty( $video_meta['videopress']['description'] ) ? $video_meta['videopress']['description'] : ( $media_file['alt'] ?? '' ),
174 'url' => $video_url,
175 'title' => get_the_title( $attachment_id ),
176 'caption' => wp_get_attachment_caption( $attachment_id ),
177 'poster' => $poster_url,
178 )
179 );
180 }
181
182 /**
183 * Render an image inside a slide
184 *
185 * @param array $media - Image information.
186 *
187 * @return string
188 */
189 function render_image( $media ) {
190 $src = '';
191 $width = null;
192 $height = null;
193
194 if ( empty( $media['id'] ) || empty( $media['url'] ) ) {
195 return __( 'Error retrieving media', 'jetpack' );
196 }
197 $image = wp_get_attachment_image_src( $media['id'], 'full', false );
198 if ( $image ) {
199 list( $src, $width, $height ) = $image;
200 }
201
202 // if image does not match.
203 if ( ! $image || isset( $media['url'] ) && ! is_same_resource( $media['url'], $src ?? '' ) ) {
204 $width = $media['width'] ?? null;
205 $height = $media['height'] ?? null;
206 $title = $media['title'] ?? '';
207 $alt = $media['alt'] ?? '';
208 return sprintf(
209 '<img
210 title="%1$s"
211 alt="%2$s"
212 class="wp-block-jetpack-story_image wp-story-image %3$s"
213 src="%4$s"
214 />',
215 esc_attr( $title ),
216 esc_attr( $alt ),
217 $width && $height ? get_image_crop_class( $width, $height ) : '',
218 esc_attr( $media['url'] )
219 );
220 }
221
222 $crop_class = get_image_crop_class( $width, $height );
223 // need to specify the size of the embed so it picks an image that is large enough for the `src` attribute
224 // `sizes` is optimized for 1080x1920 (9:16) images
225 // Note that the Story block does not have thumbnail support, it will load the right
226 // image based on the viewport size only.
227 return wp_get_attachment_image(
228 $media['id'],
229 EMBED_SIZE,
230 false,
231 array(
232 'class' => sprintf( 'wp-story-image wp-image-%d %s', $media['id'], $crop_class ),
233 'sizes' => IMAGE_BREAKPOINTS,
234 'title' => get_the_title( $media['id'] ),
235 )
236 );
237 }
238
239 /**
240 * Return the css crop class if image width and height requires it
241 *
242 * @param int $width - Image width.
243 * @param int $height - Image height.
244 *
245 * @return string The CSS class which will display a cropped image
246 */
247 function get_image_crop_class( $width, $height ) {
248 $crop_class = '';
249 $width = (int) $width;
250 $height = (int) $height;
251 if ( ! $width || ! $height ) {
252 return $crop_class;
253 }
254 $media_aspect_ratio = $width / $height;
255 $target_aspect_ratio = EMBED_SIZE[0] / EMBED_SIZE[1];
256 if ( $media_aspect_ratio >= $target_aspect_ratio ) {
257 // image wider than canvas.
258 $media_too_wide_to_crop = $media_aspect_ratio > $target_aspect_ratio / ( 1 - CROP_UP_TO );
259 if ( ! $media_too_wide_to_crop ) {
260 $crop_class = 'wp-story-crop-wide';
261 }
262 } else {
263 // image narrower than canvas.
264 $media_too_narrow_to_crop = $media_aspect_ratio < $target_aspect_ratio * ( 1 - CROP_UP_TO );
265 if ( ! $media_too_narrow_to_crop ) {
266 $crop_class = 'wp-story-crop-narrow';
267 }
268 }
269 return $crop_class;
270 }
271
272 /**
273 * Returns a URL for the site icon.
274 *
275 * @param int $size - Size for (square) sitei icon.
276 * @param string $fallback - Fallback URL to use if no site icon is found.
277 *
278 * @return string
279 */
280 function get_blavatar_or_site_icon_url( $size, $fallback ) {
281 $image_array = Images::from_blavatar( get_the_ID(), $size );
282 if ( ! empty( $image_array ) ) {
283 return $image_array[0]['src'];
284 } else {
285 return $fallback;
286 }
287 }
288
289 /**
290 * Render a video inside a slide
291 *
292 * @param array $media - Video information.
293 *
294 * @return string
295 */
296 function render_video( $media ) {
297 if ( empty( $media['id'] ) || empty( $media['mime'] ) || empty( $media['url'] ) ) {
298 return __( 'Error retrieving media', 'jetpack' );
299 }
300
301 if ( ! empty( $media['poster'] ) ) {
302 return render_image(
303 array_merge(
304 $media,
305 array(
306 'type' => 'image',
307 'url' => $media['poster'],
308 )
309 )
310 );
311 }
312
313 return sprintf(
314 '<video
315 title="%1$s"
316 type="%2$s"
317 class="wp-story-video intrinsic-ignore wp-video-%3$s"
318 data-id="%3$d"
319 src="%4$s">
320 </video>',
321 esc_attr( get_the_title( $media['id'] ) ),
322 esc_attr( $media['mime'] ),
323 absint( $media['id'] ),
324 esc_attr( $media['url'] )
325 );
326 }
327
328 /**
329 * Pick a thumbnail to render a static/embedded story
330 *
331 * @param array $media_files - list of Media files.
332 *
333 * @return string
334 */
335 function render_static_slide( $media_files ) {
336 $media_template = '';
337 if ( empty( $media_files ) ) {
338 return '';
339 }
340
341 // find an image to showcase.
342 foreach ( $media_files as $media ) {
343 switch ( $media['type'] ) {
344 case 'image':
345 $media_template = render_image( $media );
346 break 2;
347 case 'video':
348 // ignore videos without a poster image.
349 if ( empty( $media['poster'] ) ) {
350 continue 2;
351 }
352 $media_template = render_video( $media );
353 break 2;
354 }
355 }
356
357 // if no "static" media was found for the thumbnail try to render a video tag without poster.
358 if ( empty( $media_template ) ) {
359 // enrich_media_files() may return an array with no zero-index, so use reset()
360 $media_template = render_video( reset( $media_files ) );
361 }
362
363 return sprintf(
364 '<div class="wp-story-slide" style="display: block;">
365 <figure>%s</figure>
366 </div>',
367 $media_template
368 );
369 }
370
371 /**
372 * Render the top right icon on top of the story embed
373 *
374 * @param array $settings - The block settings.
375 *
376 * @return string
377 */
378 function render_top_right_icon( $settings ) {
379 $show_slide_count = $settings['showSlideCount'] ?? false;
380 $slide_count = isset( $settings['slides'] ) ? count( $settings['slides'] ) : 0;
381 if ( $show_slide_count ) {
382 // Render the story block icon along with the slide count.
383 return sprintf(
384 '<div class="wp-story-embed-icon">
385 <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false">
386 <path d="M0 0h24v24H0z" fill="none"></path>
387 <path fill-rule="evenodd" clip-rule="evenodd" d="M6 3H14V17H6L6 3ZM4 3C4 1.89543 4.89543 1 6 1H14C15.1046 1 16 1.89543 16 3V17C16 18.1046 15.1046 19 14 19H6C4.89543 19 4 18.1046 4 17V3ZM18 5C19.1046 5 20 5.89543 20 7V21C20 22.1046 19.1046 23 18 23H10C8.89543 23 8 22.1046 8 21H18V5Z"></path>
388 </svg>
389 <span>%d</span>
390 </div>',
391 $slide_count
392 );
393 } else {
394 // Render the Fullscreen Gridicon.
395 return (
396 '<div class="wp-story-embed-icon-expand">
397 <svg class="gridicon gridicons-fullscreen" role="img" height="24" width="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
398 <g>
399 <path d="M21 3v6h-2V6.41l-3.29 3.3-1.42-1.42L17.59 5H15V3zM3 3v6h2V6.41l3.29 3.3 1.42-1.42L6.41 5H9V3zm18 18v-6h-2v2.59l-3.29-3.29-1.41 1.41L17.59 19H15v2zM9 21v-2H6.41l3.29-3.29-1.41-1.42L5 17.59V15H3v6z"></path>
400 </g>
401 </svg>
402 </div>'
403 );
404 }
405 }
406
407 /**
408 * Render a pagination bullet
409 *
410 * @param int $slide_index - The slide index it corresponds to.
411 * @param string $class_name - Optional css class name(s) to customize the bullet element.
412 *
413 * @return string
414 */
415 function render_pagination_bullet( $slide_index, $class_name = '' ) {
416 return sprintf(
417 '<div class="wp-story-pagination-bullet %s" aria-label="%s">
418 <div class="wp-story-pagination-bullet-bar"></div>
419 </div>',
420 esc_attr( $class_name ),
421 /* translators: %d is the slide number (1, 2, 3...) */
422 sprintf( __( 'Go to slide %d', 'jetpack' ), $slide_index )
423 );
424 }
425
426 /**
427 * Render pagination on top of the story embed
428 *
429 * @param array $settings - The block settings.
430 *
431 * @return string
432 */
433 function render_pagination( $settings ) {
434 $show_slide_count = $settings['showSlideCount'] ?? false;
435 if ( $show_slide_count ) {
436 return '';
437 }
438 $slide_count = isset( $settings['slides'] ) ? count( $settings['slides'] ) : 0;
439 $bullet_count = min( $slide_count, MAX_BULLETS );
440 $bullet_ellipsis = $slide_count > $bullet_count
441 ? render_pagination_bullet( $bullet_count + 1, 'wp-story-pagination-ellipsis' )
442 : '';
443 return sprintf(
444 '<div class="wp-story-pagination wp-story-pagination-bullets">
445 %s
446 </div>',
447 implode( "\n", array_map( __NAMESPACE__ . '\render_pagination_bullet', range( 1, $bullet_count ) ) ) . $bullet_ellipsis
448 );
449 }
450
451 /**
452 * Render story block
453 *
454 * @param array $attributes - Block attributes.
455 *
456 * @return string
457 */
458 function render_block( $attributes ) {
459 // Let's use a counter to have a different id for each story rendered in the same context.
460 static $story_block_counter = 0;
461
462 if ( 0 === $story_block_counter ) {
463 // @todo Fix the webpack tree shaking so the block's view.js no longer depends on jetpack-connection, then remove this.
464 Connection_Assets::register_assets();
465 }
466
467 Jetpack_Gutenberg::load_assets_as_required( __DIR__ );
468
469 $media_files = isset( $attributes['mediaFiles'] ) ? enrich_media_files( $attributes['mediaFiles'] ) : array();
470 $settings_from_attributes = $attributes['settings'] ?? array();
471
472 $settings = array_merge(
473 $settings_from_attributes,
474 array(
475 'slides' => $media_files,
476 )
477 );
478
479 /* translators: Placehodlder if the Story block can't find a post title to use. */
480 $story_title = in_the_loop() ? get_the_title() : __( 'Story', 'jetpack' );
481
482 return sprintf(
483 '<div class="%1$s" data-id="%2$s" data-settings="%3$s">
484 <div class="wp-story-app">
485 <div class="wp-story-display-contents" style="display: contents;">
486 <a class="wp-story-container" href="%4$s" title="%5$s">
487 <div class="wp-story-meta">
488 <div class="wp-story-icon">
489 <img alt="%6$s" src="%7$s" width="40" height="40">
490 </div>
491 <div>
492 <div class="wp-story-title">
493 %8$s
494 </div>
495 </div>
496 </div>
497 <div class="wp-story-wrapper">
498 %9$s
499 </div>
500 <div class="wp-story-overlay">
501 %10$s
502 </div>
503 %11$s
504 </a>
505 </div>
506 </div>
507 </div>',
508 esc_attr( Blocks::classes( Blocks::get_block_feature( __DIR__ ), $attributes, array( 'wp-story', 'aligncenter' ) ) ),
509 esc_attr( 'wp-story-' . get_the_ID() . '-' . strval( ++$story_block_counter ) ),
510 filter_var( wp_json_encode( $settings, JSON_UNESCAPED_SLASHES ), FILTER_SANITIZE_SPECIAL_CHARS ),
511 get_permalink() . '?wp-story-load-in-fullscreen=true&amp;wp-story-play-on-load=true',
512 __( 'Play story in new tab', 'jetpack' ),
513 __( 'Site icon', 'jetpack' ),
514 esc_attr( get_blavatar_or_site_icon_url( 80, includes_url( 'images/w-logo-blue.png' ) ) ),
515 esc_html( $story_title ),
516 render_static_slide( $media_files ),
517 render_top_right_icon( $settings ),
518 render_pagination( $settings )
519 );
520 }
521