| @@ 440-492 (lines=53) @@ | ||
| 437 | $image_tags = $dom_doc->getElementsByTagName( 'img' ); |
|
| 438 | ||
| 439 | // For each image Tag, make sure it can be added to the $images array, and add it. |
|
| 440 | foreach ( $image_tags as $image_tag ) { |
|
| 441 | $img_src = $image_tag->getAttribute( 'src' ); |
|
| 442 | ||
| 443 | if ( empty( $img_src ) ) { |
|
| 444 | continue; |
|
| 445 | } |
|
| 446 | ||
| 447 | // Do not grab smiley images that were automatically created by WP when entering text smilies. |
|
| 448 | if ( stripos( $img_src, '/smilies/' ) ) { |
|
| 449 | continue; |
|
| 450 | } |
|
| 451 | ||
| 452 | $meta = array( |
|
| 453 | 'width' => (int) $image_tag->getAttribute( 'width' ), |
|
| 454 | 'height' => (int) $image_tag->getAttribute( 'height' ), |
|
| 455 | 'alt_text' => $image_tag->getAttribute( 'alt' ), |
|
| 456 | ); |
|
| 457 | ||
| 458 | /** |
|
| 459 | * Filters the switch to ignore minimum image size requirements. Can be used |
|
| 460 | * to add custom logic to image dimensions, like only enforcing one of the dimensions, |
|
| 461 | * or disabling it entirely. |
|
| 462 | * |
|
| 463 | * @since 6.4.0 |
|
| 464 | * |
|
| 465 | * @param bool $ignore Should the image dimensions be ignored? |
|
| 466 | * @param array $meta Array containing image dimensions parsed from the markup. |
|
| 467 | */ |
|
| 468 | $ignore_dimensions = apply_filters( 'jetpack_postimages_ignore_minimum_dimensions', false, $meta ); |
|
| 469 | ||
| 470 | // Must be larger than 200x200 (or user-specified). |
|
| 471 | if ( |
|
| 472 | ! $ignore_dimensions |
|
| 473 | && ( |
|
| 474 | empty( $meta['width'] ) |
|
| 475 | || empty( $meta['height'] ) |
|
| 476 | || $meta['width'] < $width |
|
| 477 | || $meta['height'] < $height |
|
| 478 | ) |
|
| 479 | ) { |
|
| 480 | continue; |
|
| 481 | } |
|
| 482 | ||
| 483 | $images[] = array( |
|
| 484 | 'type' => 'image', |
|
| 485 | 'from' => 'html', |
|
| 486 | 'src' => $img_src, |
|
| 487 | 'src_width' => $meta['width'], |
|
| 488 | 'src_height' => $meta['height'], |
|
| 489 | 'href' => $html_info['post_url'], |
|
| 490 | 'alt_text' => $meta['alt_text'], |
|
| 491 | ); |
|
| 492 | } |
|
| 493 | return $images; |
|
| 494 | } |
|
| 495 | ||
| @@ 440-492 (lines=53) @@ | ||
| 437 | $image_tags = $dom_doc->getElementsByTagName( 'img' ); |
|
| 438 | ||
| 439 | // For each image Tag, make sure it can be added to the $images array, and add it. |
|
| 440 | foreach ( $image_tags as $image_tag ) { |
|
| 441 | $img_src = $image_tag->getAttribute( 'src' ); |
|
| 442 | ||
| 443 | if ( empty( $img_src ) ) { |
|
| 444 | continue; |
|
| 445 | } |
|
| 446 | ||
| 447 | // Do not grab smiley images that were automatically created by WP when entering text smilies. |
|
| 448 | if ( stripos( $img_src, '/smilies/' ) ) { |
|
| 449 | continue; |
|
| 450 | } |
|
| 451 | ||
| 452 | $meta = array( |
|
| 453 | 'width' => (int) $image_tag->getAttribute( 'width' ), |
|
| 454 | 'height' => (int) $image_tag->getAttribute( 'height' ), |
|
| 455 | 'alt_text' => $image_tag->getAttribute( 'alt' ), |
|
| 456 | ); |
|
| 457 | ||
| 458 | /** |
|
| 459 | * Filters the switch to ignore minimum image size requirements. Can be used |
|
| 460 | * to add custom logic to image dimensions, like only enforcing one of the dimensions, |
|
| 461 | * or disabling it entirely. |
|
| 462 | * |
|
| 463 | * @since 6.4.0 |
|
| 464 | * |
|
| 465 | * @param bool $ignore Should the image dimensions be ignored? |
|
| 466 | * @param array $meta Array containing image dimensions parsed from the markup. |
|
| 467 | */ |
|
| 468 | $ignore_dimensions = apply_filters( 'jetpack_postimages_ignore_minimum_dimensions', false, $meta ); |
|
| 469 | ||
| 470 | // Must be larger than 200x200 (or user-specified). |
|
| 471 | if ( |
|
| 472 | ! $ignore_dimensions |
|
| 473 | && ( |
|
| 474 | empty( $meta['width'] ) |
|
| 475 | || empty( $meta['height'] ) |
|
| 476 | || $meta['width'] < $width |
|
| 477 | || $meta['height'] < $height |
|
| 478 | ) |
|
| 479 | ) { |
|
| 480 | continue; |
|
| 481 | } |
|
| 482 | ||
| 483 | $images[] = array( |
|
| 484 | 'type' => 'image', |
|
| 485 | 'from' => 'html', |
|
| 486 | 'src' => $img_src, |
|
| 487 | 'src_width' => $meta['width'], |
|
| 488 | 'src_height' => $meta['height'], |
|
| 489 | 'href' => $html_info['post_url'], |
|
| 490 | 'alt_text' => $meta['alt_text'], |
|
| 491 | ); |
|
| 492 | } |
|
| 493 | return $images; |
|
| 494 | } |
|
| 495 | ||