Skip to content

Commit

Permalink
Built release for 0.5.4. For a full change log look at the notes with…
Browse files Browse the repository at this point in the history
…in the original/0.5.4 release.
  • Loading branch information
github-actions[bot] committed Apr 22, 2024
1 parent 964c11d commit 24ef5d2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 33 deletions.
2 changes: 1 addition & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"owner":"humanmade","repo":"smart-media","sha":"a4746bf63287998b1b8ffc10966876e240219471","ref":"refs/tags/0.5.3","tagName":"0.5.3","branch":"gh-actions","tags":["0.5.3"],"updated_at":"2024-04-09T09:03:44.323Z"}
{"owner":"humanmade","repo":"smart-media","sha":"239578e1130130b7d6ce58b5cd8f54347edbe78a","ref":"refs/tags/0.5.4","tagName":"0.5.4","branch":"gh-actions","tags":["0.5.4"],"updated_at":"2024-04-22T12:40:27.659Z"}

Large diffs are not rendered by default.

29 changes: 24 additions & 5 deletions inc/cropper/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,25 @@ function massage_meta_data_for_orientation( array $meta_data ) {
return $meta_data;
}

/**
* Check if this image matches the tachyon host and path. Allows subdomains.
*
* @param string $image Image HTML or URL.
* @return boolean
*/
function is_tachyon_url( string $image ) : bool {
if ( ! defined( 'TACHYON_URL' ) ) {
return false;
}

// TACHYON_URL can be filtered on output so this is the only reliable method to
// check an image is handled by Tachyon.
$uploads_dir = wp_upload_dir();
$tachyon_base_url = dirname( tachyon_url( $uploads_dir['baseurl'] . '/image.jpg' ) );

return strpos( $image, $tachyon_base_url ) !== false;
}

/**
* Add our special handlers for width & height attrs and srcset attributes.
*
Expand All @@ -910,7 +929,7 @@ function massage_meta_data_for_orientation( array $meta_data ) {
* @return string Full img tag with attributes that will replace the source img tag.
*/
function content_img_tag( string $filtered_image, string $context, int $attachment_id ) : string {
if ( ! defined( 'TACHYON_URL' ) || strpos( $filtered_image, TACHYON_URL ) === false ) {
if ( ! is_tachyon_url( $filtered_image ) ) {
return $filtered_image;
}

Expand Down Expand Up @@ -945,7 +964,7 @@ function content_img_tag( string $filtered_image, string $context, int $attachme
* @return bool The filtered value, defaults to <code>true</code>.
*/
function img_tag_add_attr( bool $value, string $image ) : bool {
return ! defined( 'TACHYON_URL' ) || strpos( $image, TACHYON_URL ) === false ? $value : false;
return ! is_tachyon_url( $image ) ? $value : false;
}

/**
Expand Down Expand Up @@ -1035,7 +1054,7 @@ function add_width_and_height_attr( $image, $image_meta ) : string {
if ( empty( $image_meta ) ) {
return $image;
}

$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

// Return early if we couldn't get the image source.
Expand Down Expand Up @@ -1073,7 +1092,7 @@ function add_srcset_and_sizes_attr( $image, $image_meta, $attachment_id ) : stri
if ( empty( $image_meta ) ) {
return $image;
}

$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

// Return early if we couldn't get the image source.
Expand Down Expand Up @@ -1151,7 +1170,7 @@ function image_srcset( array $sources, array $size_array, string $image_src, arr
list( $width, $height ) = array_map( 'absint', $size_array );

// Ensure this is _not_ a tachyon image, not always the case when parsing from post content.
if ( ! defined( 'TACHYON_URL' ) || strpos( $image_src, TACHYON_URL ) === false ) {
if ( ! is_tachyon_url( $image_src ) ) {
// If the aspect ratio requested matches a custom crop size, pull that
// crop (in case there's a user custom crop). Otherwise just use the
// given dimensions.
Expand Down
18 changes: 16 additions & 2 deletions inc/cropper/src/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ addFilter(

// Ensure Smart Media is supported by Asset Manager Framework.
addAction( 'amf.extend_toolbar', 'smartmedia/cropper', extend_toolbar => {
Media.view.Toolbar = extend_toolbar( Media.view.Toolbar, 'apply' );
Media.view.Toolbar = extend_toolbar( Media.view.Toolbar, 'apply' );
} );


Expand Down Expand Up @@ -158,9 +158,16 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( {
libraryState.get( 'selection' ).on( 'selection:single', () => {
const single = this.state( 'edit' ).get( 'selection' ).single();

if ( this._state === 'edit' ) {
return;
}

// Check that the attachment is a complete object. Built in placeholders
// exist for the cover block that can confuse things.
if ( ( ! isFeaturedImage && ! single.get( 'url' ) ) || ! single.get( 'id' ) ) {
if ( ! single.get( 'id' ) ) {
single.fetch().then( () => {
this.setState( 'edit' );
} );
return;
}

Expand All @@ -180,6 +187,9 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( {
}
}

// Set size back to full.
single.set( { size: 'full' } );

wp.media.view.settings.post.featuredImageId = single.get( 'id' );
}

Expand All @@ -192,6 +202,10 @@ Media.view.MediaFrame.Select = MediaFrameSelect.extend( {
wp.media.view.settings.post.featuredImageId = -1;
}

if ( this._state !== 'edit' ) {
return;
}

this.setState( libraryState.id );
} );
},
Expand Down
12 changes: 11 additions & 1 deletion inc/cropper/src/views/image-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const ImageEditor = Media.View.extend( {

// Reset to focal point or smart crop by default.
if ( ! crop.hasOwnProperty( 'x' ) ) {
const [ cropWidth, cropHeight ] = getMaxCrop( width, height, size.width, size.height );
if ( focalPoint.hasOwnProperty( 'x' ) ) {
const [ cropWidth, cropHeight ] = getMaxCrop( width, height, size.width, size.height );
this.setSelection( {
x: Math.min( width - cropWidth, Math.max( 0, focalPoint.x - ( cropWidth / 2 ) ) ),
y: Math.min( height - cropHeight, Math.max( 0, focalPoint.y - ( cropHeight / 2 ) ) ),
Expand All @@ -108,6 +108,16 @@ const ImageEditor = Media.View.extend( {
} )
.then( ( { topCrop } ) => {
this.setSelection( topCrop );
} )
.catch( error => {
console.error( error );
// Fallback to centered crop, can fail due to cross-origin canvas tainting.
this.setSelection( {
x: Math.max( 0 , ( width - cropWidth ) / 2 ),
y: Math.max( 0, ( height - cropHeight ) / 2 ),
width: cropWidth,
height: cropHeight,
} );
} );
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cropper.js": "/inc/cropper/build/cropper.88b7c347.js"
"cropper.js": "/inc/cropper/build/cropper.7fec5ab2.js"
}
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24ef5d2

Please sign in to comment.