Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply the extracted dimensions to images determined to need them #1117

Merged
merged 2 commits into from
May 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions includes/sanitizers/class-amp-img-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,29 @@ private function determine_dimensions( $need_dimensions ) {
if ( ! $node instanceof DOMElement ) {
continue;
}
$height = $dimensions && isset( $dimensions['height'] ) ? $dimensions['height'] : self::FALLBACK_HEIGHT;
$width = $dimensions && isset( $dimensions['width'] ) ? $dimensions['width'] : self::FALLBACK_WIDTH;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think $this->args['content_max_width'] should be used here if available. It got removed in #979.

$class = $node->getAttribute( 'class' );
if ( ! $class ) {
$class = '';
}
if (
! is_numeric( $node->getAttribute( 'width' ) ) &&
! is_numeric( $node->getAttribute( 'height' ) )
) {
$height = self::FALLBACK_HEIGHT;
$width = self::FALLBACK_WIDTH;
$node->setAttribute( 'width', $width );
$node->setAttribute( 'height', $height );
$class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size' : 'amp-wp-unknown-size';
$node->setAttribute( 'class', $class );
$node->setAttribute( 'class', trim( $class . ' amp-wp-unknown-size' ) );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is amp-wp-unknown-size even true here? Shouldn't it only be true if the FALLBACK_HEIGHT or FALLBACK_WIDTH are used? Otherwise, if we have $dimensions then we do know the size.

} elseif (
! is_numeric( $node->getAttribute( 'height' ) )
) {
$height = self::FALLBACK_HEIGHT;
$node->setAttribute( 'height', $height );
$class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size amp-wp-unknown-height' : 'amp-wp-unknown-size amp-wp-unknown-height';
$node->setAttribute( 'class', $class );
$node->setAttribute( 'class', trim( $class . ' amp-wp-unknown-size amp-wp-unknown-height' ) );
} elseif (
! is_numeric( $node->getAttribute( 'width' ) )
) {
$width = self::FALLBACK_WIDTH;
$node->setAttribute( 'width', $width );
$class = $node->hasAttribute( 'class' ) ? $node->getAttribute( 'class' ) . ' amp-wp-unknown-size amp-wp-unknown-width' : 'amp-wp-unknown-size amp-wp-unknown-width';
$node->setAttribute( 'class', $class );
$node->setAttribute( 'class', trim( $class . ' amp-wp-unknown-size amp-wp-unknown-width' ) );
}
}
}
Expand Down