PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 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 All 504 releases
← All changes | _inc/lib/class.media-extractor.php +21 -10 13.5.216.3-a.1 View file →
@@ -5,8 +5,10 @@
5 5 *
6 6 * @package automattic/jetpack
7 7 */
8 8
9 +use Automattic\Jetpack\Post_Media\Images;
10 +
9 11 /**
10 12 * Class with methods to extract metadata from a post/page about videos, images, links, mentions embedded
11 13 * in or attached to the post/page.
12 14 *
@@ -31,12 +33,14 @@
31 33 *
32 34 * @var string[]
33 35 */
34 36 private static $keeper_shortcodes = array(
37 + 'audio',
35 38 'youtube',
36 39 'vimeo',
37 40 'hulu',
38 41 'ted',
42 + 'video',
39 43 'wpvideo',
40 44 'videopress',
41 45 );
42 46
@@ -79,9 +83,9 @@
79 83 if ( self::IMAGES & $what_to_extract ) {
80 84 $extracted = self::get_image_fields( $post, array(), $extract_alt_text );
81 85
82 86 // Turn off images so we can safely call extract_from_content() below.
83 - $what_to_extract = $what_to_extract - self::IMAGES;
87 + $what_to_extract -= self::IMAGES;
84 88 }
85 89
86 90 if ( function_exists( 'restore_current_blog' ) ) {
87 91 restore_current_blog();
@@ -196,8 +200,13 @@
196 200 if ( function_exists( $shortcode_get_id_func ) ) {
197 201 $id = call_user_func( $shortcode_get_id_func, $attr );
198 202 } elseif ( method_exists( $shortcode_class_name, $shortcode_get_id_method ) ) {
199 203 $id = call_user_func( array( $shortcode_class_name, $shortcode_get_id_method ), $attr );
204 + } elseif ( 'video' === $shortcode ) {
205 + $id = $attr['src'] ?? $attr['url'] ?? $attr['mp4'] ?? $attr['m4v'] ?? $attr['webm'] ?? $attr['ogv'] ?? $attr['wmv'] ?? $attr['flv'] ?? null;
206 + } elseif ( 'audio' === $shortcode ) {
207 + preg_match( '#(https?://(?:[^\s"|\']+)\.(?:mp3|ogg|flac|m4a|wav))([ "\'|]|$)#', implode( ' ', $attr ), $audio_matches );
208 + $id = $audio_matches[1] ?? null;
200 209 }
201 210 if ( ! empty( $id )
202 211 && ( ! isset( $shortcode_details[ $shortcode_name ] ) || ! in_array( $id, $shortcode_details[ $shortcode_name ], true ) ) ) {
203 212 $shortcode_details[ $shortcode_name ][] = $id;
@@ -339,9 +348,13 @@
339 348 list( $proto, $link_all_but_proto ) = explode( '://', $link_raw ); // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
340 349
341 350 // Check whether this "link" is really an embed.
342 351 foreach ( $oembed->providers as $matchmask => $data ) {
343 - list( $providerurl, $regex ) = $data; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
352 + // Guard against malformed oEmbed providers.
353 + if ( ! isset( $data[0] ) ) {
354 + continue;
355 + }
356 + $regex = $data[1] ?? false;
344 357
345 358 // Turn the asterisk-type provider URLs into regex.
346 359 if ( ! $regex ) {
347 360 $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i';
@@ -375,9 +388,9 @@
375 388
376 389 /**
377 390 * Get image fields for matching images.
378 391 *
379 - * @uses Jetpack_PostImages
392 + * @uses Images
380 393 *
381 394 * @param WP_Post $post A post object.
382 395 * @param array $args Optional args, see defaults list for details.
383 396 * @param boolean $extract_alt_text Should alt_text be extracted, defaults to false.
@@ -400,9 +413,9 @@
400 413 $image_list = array();
401 414 $image_booleans = array();
402 415 $image_booleans['gallery'] = 0;
403 416
404 - $from_featured_image = Jetpack_PostImages::from_thumbnail( $post->ID, $args['width'], $args['height'] );
417 + $from_featured_image = Images::from_thumbnail( $post->ID, $args['width'], $args['height'] );
405 418 if ( ! empty( $from_featured_image ) ) {
406 419 if ( $extract_alt_text ) {
407 420 $image_list = array_merge( $image_list, self::reduce_extracted_images( $from_featured_image ) );
408 421 } else {
@@ -410,9 +423,9 @@
410 423 $image_list = array_merge( $image_list, $srcs );
411 424 }
412 425 }
413 426
414 - $from_slideshow = Jetpack_PostImages::from_slideshow( $post->ID, $args['width'], $args['height'] );
427 + $from_slideshow = Images::from_slideshow( $post->ID, $args['width'], $args['height'] );
415 428 if ( ! empty( $from_slideshow ) ) {
416 429 if ( $extract_alt_text ) {
417 430 $image_list = array_merge( $image_list, self::reduce_extracted_images( $from_slideshow ) );
418 431 } else {
@@ -420,9 +433,9 @@
420 433 $image_list = array_merge( $image_list, $srcs );
421 434 }
422 435 }
423 436
424 - $from_gallery = Jetpack_PostImages::from_gallery( $post->ID );
437 + $from_gallery = Images::from_gallery( $post->ID );
425 438 if ( ! empty( $from_gallery ) ) {
426 439 if ( $extract_alt_text ) {
427 440 $image_list = array_merge( $image_list, self::reduce_extracted_images( $from_gallery ) );
428 441 } else {
@@ -502,11 +515,9 @@
502 515 $retval['image'][] = $img;
503 516 }
504 517 }
505 518 $image_booleans['image'] = count( $retval['image'] );
506 - if ( ! empty( $image_booleans ) ) {
507 - $retval['has'] = $image_booleans;
508 - }
519 + $retval['has'] = $image_booleans;
509 520 return $retval;
510 521 } else {
511 522 return array();
512 523 }
@@ -522,9 +533,9 @@
522 533 * @return array Image URLs extracted from the HTML, stripped of query params and de-duped
523 534 */
524 535 public static function get_images_from_html( $html, $images_already_extracted, $extract_alt_text = false ) {
525 536 $image_list = $images_already_extracted;
526 - $from_html = Jetpack_PostImages::from_html( $html );
537 + $from_html = Images::from_html( $html );
527 538 // early return if no image in html.
528 539 if ( empty( $from_html ) ) {
529 540 return $image_list;
530 541 }