diff --git a/includes/vendor/amp/includes/sanitizers/class-amp-img-sanitizer.php b/includes/vendor/amp/includes/sanitizers/class-amp-img-sanitizer.php index fd4ee16e1..52478dd41 100644 --- a/includes/vendor/amp/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/vendor/amp/includes/sanitizers/class-amp-img-sanitizer.php @@ -71,46 +71,48 @@ public function sanitize() { */ private function determine_dimensions( $need_dimensions ) { $dimensions_by_url = AMP_Image_Dimension_Extractor::extract( array_keys( $need_dimensions ) ); - + $class = ""; foreach ( $dimensions_by_url as $url => $dimensions ) { foreach ( $need_dimensions[ $url ] as $node ) { - // Provide default dimensions for images whose dimensions we couldn't fetch. - if ( false === $dimensions ) { - $width = isset( $this->args['content_max_width'] ) ? $this->args['content_max_width'] : self::FALLBACK_WIDTH; - $height = self::FALLBACK_HEIGHT; - if ( isset( $dimensions['width'] ) ) { - $width = $dimensions['width']; - } - if ( isset( $dimensions['height'] ) ) { - $height = $dimensions['height']; + if ( ! $node instanceof DOMElement ) { + continue; + } + $class = $node->getAttribute( 'class' ); + if ( ! $class ) { + $class = ''; + } + if ( ! $dimensions ) { + $class .= ' amp-wp-unknown-size'; + } + $width = isset( $this->args['content_max_width'] ) ? $this->args['content_max_width'] : self::FALLBACK_WIDTH; + $height = self::FALLBACK_HEIGHT; + if ( isset( $dimensions['width'] ) ) { + $width = $dimensions['width']; + } + if ( isset( $dimensions['height'] ) ) { + $height = $dimensions['height']; + } + if ( ! is_numeric( $node->getAttribute( 'width' ) ) ) { + // Let width have the right aspect ratio based on the height attribute. + if ( is_numeric( $node->getAttribute( 'height' ) ) && isset( $dimensions['height'] ) && isset( $dimensions['width'] ) ) { + $width = ( floatval( $node->getAttribute( 'height' ) ) * $dimensions['width'] ) / $dimensions['height']; } - if ( ! is_numeric( $node->getAttribute( 'width' ) ) ) { - // Let width have the right aspect ratio based on the height attribute. - if ( is_numeric( $node->getAttribute( 'height' ) ) && isset( $dimensions['height'] ) && isset( $dimensions['width'] ) ) { - $width = ( floatval( $node->getAttribute( 'height' ) ) * $dimensions['width'] ) / $dimensions['height']; - } - $node->setAttribute( 'width', $width ); - if ( ! isset( $dimensions['width'] ) ) { - $class .= ' amp-wp-unknown-width'; - } + $node->setAttribute( 'width', $width ); + if ( ! isset( $dimensions['width'] ) ) { + $class .= ' amp-wp-unknown-width'; } - if ( ! is_numeric( $node->getAttribute( 'height' ) ) ) { - // Let height have the right aspect ratio based on the width attribute. - if ( is_numeric( $node->getAttribute( 'width' ) ) && isset( $dimensions['width'] ) && isset( $dimensions['height'] ) ) { - $height = ( floatval( $node->getAttribute( 'width' ) ) * $dimensions['height'] ) / $dimensions['width']; - } - $node->setAttribute( 'height', $height ); - if ( ! isset( $dimensions['height'] ) ) { - $class .= ' amp-wp-unknown-height'; - } + } + if ( ! is_numeric( $node->getAttribute( 'height' ) ) ) { + // Let height have the right aspect ratio based on the width attribute. + if ( is_numeric( $node->getAttribute( 'width' ) ) && isset( $dimensions['width'] ) && isset( $dimensions['height'] ) ) { + $height = ( floatval( $node->getAttribute( 'width' ) ) * $dimensions['height'] ) / $dimensions['width']; } - $node->setAttribute( 'width', $width ); $node->setAttribute( 'height', $height ); - $node->setAttribute( 'class', trim( $class ) ); - } else { - $node->setAttribute( 'width', $dimensions['width'] ); - $node->setAttribute( 'height', $dimensions['height'] ); + if ( ! isset( $dimensions['height'] ) ) { + $class .= ' amp-wp-unknown-height'; + } } + $node->setAttribute( 'class', trim( $class ) ); } } } diff --git a/includes/vendor/vendor-changelog.txt b/includes/vendor/vendor-changelog.txt index aa823cd92..4e51778a7 100644 --- a/includes/vendor/vendor-changelog.txt +++ b/includes/vendor/vendor-changelog.txt @@ -60,4 +60,5 @@ Reason: To extend the functionality of sidebars and Pagebuilder 33. Class AMP_Blacklist_Sanitizer updated #2835 34. class-amp-style-sanitizer.php updated #2745 35. Class AMP_Blacklist_Sanitizer updated for inernal links #2391 -36. Mobile detect library added from https://github.com/serbanghita/Mobile-Detect \ No newline at end of file +36. Mobile detect library added from https://github.com/serbanghita/Mobile-Detect +37. Class AMP_Img_Sanitizer Updated #2893 \ No newline at end of file