Skip to content

Commit

Permalink
* Fix for broken Crop, Edit Image and Replace Image buttons in the me…
Browse files Browse the repository at this point in the history
…dia library.

* Fix for issue with image URLs
  • Loading branch information
jawngee committed Nov 8, 2022
1 parent 7601aee commit f453057
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions classes/Tools/Storage/Driver/S3/DigitalOceanStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ public static function settingsErrorOptionName() {
*/
public function upload($key, $fileName, $acl, $cacheControl=null, $expires=null, $contentType=null, $contentEncoding=null, $contentLength=null) {
$uploadedUrl = parent::upload($key, $fileName, $acl, $cacheControl, $expires, $contentType, $contentEncoding, $contentLength);
if ($uploadedUrl) {
if (empty(parse_url($uploadedUrl, PHP_URL_SCHEME))) {
if (!empty($uploadedUrl)) {
if (strpos($uploadedUrl, 'http') !== 0) {
$uploadedUrl = "https://{$uploadedUrl}";
}

if (!$this->settings->endPointPathStyle) {
$urlParts = parse_url($uploadedUrl);
if ($urlParts && strpos($urlParts['path'], "/{$this->settings->bucket}/") === 0) {
if ($urlParts && (strpos($urlParts['path'], "/{$this->settings->bucket}/") === 0)) {
$fixedPath = substr($urlParts['path'], strlen($this->settings->bucket) + 1);
$uploadedUrl = "${urlParts['scheme']}://{$this->settings->bucket}.${urlParts['host']}{$fixedPath}";
}
Expand Down
4 changes: 2 additions & 2 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ public function getAttachmentURL( $url, $post_id )
$new_url = str_replace( '//s3-.amazonaws', '//s3.amazonaws', $new_url );
}
}
if ( !parse_url( $new_url, PHP_URL_SCHEME ) ) {
if ( !empty($new_url) && strpos( $new_url, 'http' ) !== 0 ) {
$new_url = 'https://' . $new_url;
}
return ( $new_url ?: $url );
Expand Down Expand Up @@ -2450,7 +2450,7 @@ public function processFile(
StorageToolSettings::cacheControl(),
StorageToolSettings::expires()
);
if ( $url && !parse_url( $url, PHP_URL_SCHEME ) ) {
if ( !empty($url) && strpos( $url, 'http' ) !== 0 ) {
$url = 'https://' . $url;
}
Logger::info(
Expand Down
9 changes: 6 additions & 3 deletions classes/Tools/ToolsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,8 @@ private function hookMediaDetailButtons()
if ( arrayPath( $button, 'button_type', 'link' ) === 'button' ) {
$buttonHTML = "<button type='button' {$dataAttrs} class='button {$classes}' style='{$style}'>{$button['label']}</button>";
} else {
$buttonHTML = "<a href='{$button['url']}' {$dataAttrs} class='{$thickbox} button {$classes}' style='{$style}'>{$button['label']}</a>";
$buttonUrl = str_replace( '__ID__', '{{ data.id }}', $button['url'] );
$buttonHTML = "<a href='{$buttonUrl}' {$dataAttrs} class='{$thickbox} button {$classes}' style='{$style}'>{$button['label']}</a>";
}

if ( $button['type'] !== 'any' ) {
Expand All @@ -1121,7 +1122,8 @@ private function hookMediaDetailButtons()
}
}
$thickbox = ( arrayPath( $link, 'thickbox', true ) === true ? 'ilab-thickbox' : '' );
$linkHTML = "<a href='{$link['url']}' {$dataAttrs} class='{$thickbox} {$classes}' style='{$style}'>{$link['label']}</a> <span class='links-separator'>|</span>";
$linkUrl = str_replace( '__ID__', '{{ data.id }}', $link['url'] );
$linkHTML = "<a href='{$linkUrl}' {$dataAttrs} class='{$thickbox} {$classes}' style='{$style}'>{$link['label']}</a> <span class='links-separator'>|</span>";
if ( $link['type'] !== 'any' ) {

if ( isset( $link['cloudonly'] ) && $link['cloudonly'] === true ) {
Expand All @@ -1144,7 +1146,8 @@ private function hookMediaDetailButtons()
$dataAttrs .= "data-{$key}='{$value}' ";
}
}
$linkHTML = "<a href='{$link['url']}' {$dataAttrs} class='ilab-thickbox {$classes}' style='display: block; {$style}'>{$link['label']}</a>";
$linkUrl = str_replace( '__ID__', '{{ data.id }}', $link['url'] );
$linkHTML = "<a href='{$linkUrl}' {$dataAttrs} class='ilab-thickbox {$classes}' style='display: block; {$style}'>{$link['label']}</a>";
if ( $link['type'] !== 'any' ) {
$linkHTML = "<# if (data.type === '{$link['type']}') { #>\\n{$linkHTML}\\n<# } #>";
}
Expand Down
4 changes: 2 additions & 2 deletions ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: https://github.com/interfacelab/ilab-media-tools
Description: Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site performance and simplifies workflows.
Author: interfacelab
Version: 4.5.9
Version: 4.5.10
Requires PHP: 7.4
Author URI: http://interfacelab.io
*/
Expand Down Expand Up @@ -95,7 +95,7 @@
}

// Version Defines
define( 'MEDIA_CLOUD_VERSION', '4.5.9' );
define( 'MEDIA_CLOUD_VERSION', '4.5.10' );
define( 'MEDIA_CLOUD_INFO_VERSION', '4.0.2' );
define( 'MCLOUD_IS_BETA', false );
// Debugging
Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 4.9
Tested up to: 6.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 4.5.9
Stable tag: 4.5.10
Requires PHP: 7.4

Automatically store media on Amazon S3, Cloudflare R2, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix.
Expand Down Expand Up @@ -105,6 +105,11 @@ Imgix is a content delivery network with a twist. In addition to distributing y

== Changelog ==

= 4.5.10 - 11/09/2022 =

* Fix for broken Crop, Edit Image and Replace Image buttons in the media library.
* Fix for issue with image URLs

= 4.5.9 - 11/08/2022 =

* Fixed a bug with the AWS SDK with DigitalOcean that resulted in urls missing the scheme (eg the https:// part). This
Expand Down

0 comments on commit f453057

Please sign in to comment.