Skip to content

Commit

Permalink
3.3.11
Browse files Browse the repository at this point in the history
* Added us-east-2 region for Wasabi
* You can now bulk change the privacy for a selection of files in your media library.  To do this, switch to list view in the media library, select the images you want to change, select *Change Privacy to Public* or *Change Privacy to Private* from the Bulk Actions dropdown and then click *Apply*.
* Media Library now displays a lock for uploads that are private.
* For private upload the WordPress admin will use signed URLs to display media, but only in the admin (unless you have use presigned URLs enabled).
* Fix for font issue in latest LearnDash
  • Loading branch information
jawngee committed Dec 12, 2019
1 parent fd64f16 commit 4baa215
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 16 deletions.
7 changes: 7 additions & 0 deletions classes/Storage/Driver/Backblaze/BackblazeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ public function region() {
public function insureACL($key, $acl) {
}

public function updateACL($key, $acl) {
}

public function canUpdateACL() {
return false;
}

public function exists($key) {
if(!$this->client) {
throw new InvalidStorageSettingsException('Storage settings are invalid');
Expand Down
8 changes: 8 additions & 0 deletions classes/Storage/Driver/GoogleCloud/GoogleStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ public function insureACL($key, $acl) {
}
}

public function updateACL($key, $acl) {
$this->insureACL($key, $acl);
}

public function canUpdateACL() {
return true;
}

public function exists($key) {
if(!$this->client) {
throw new InvalidStorageSettingsException('Storage settings are invalid');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GoogleStorageSettings extends ToolSettings {
*/
protected $settingsMap = [
'bucket' => ['mcloud-storage-google-bucket', ['ILAB_CLOUD_GOOGLE_BUCKET', 'ILAB_AWS_S3_BUCKET', 'ILAB_CLOUD_BUCKET'], null],
'useBucketPolicyOnly' => ['mcloud-storage-bucket-policy-only', false],
'useBucketPolicyOnly' => ['mcloud-storage-bucket-policy-only', null, false],
'usePresignedURLs' => ['mcloud-storage-use-presigned-urls', null, false],
'presignedURLExpiration' => ['mcloud-storage-presigned-expiration', null, 300],
'usePresignedURLsForImages' => ['mcloud-storage-use-presigned-urls-images', null, false],
Expand Down
19 changes: 19 additions & 0 deletions classes/Storage/Driver/S3/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,25 @@ public function insureACL($key, $acl) {

}

public function updateACL($key, $acl) {
try {
$result = $this->client->putObjectAcl([
'ACL' => $acl,
'Bucket' => $this->settings->bucket,
'Key' => $key
]);

return $result;
} catch (\Exception $ex) {
Logger::error("Error changing ACL for '$key' to '$acl'. Exception: ".$ex->getMessage());
return false;
}
}

public function canUpdateACL() {
return true;
}

public function exists($key) {
if(!$this->client) {
throw new InvalidStorageSettingsException('Storage settings are invalid');
Expand Down
3 changes: 2 additions & 1 deletion classes/Storage/Driver/S3/WasabiStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public static function configureWizard($builder = null) {
->passwordField('mcloud-storage-s3-secret', 'Secret', '', null)
->textField('mcloud-storage-s3-bucket', 'Bucket', 'The name of bucket you wish to store your media in.', null)
->selectField('mcloud-storage-wasabi-region', 'Region', '', null, [
'us-east-1' => 'US East',
'us-east-1' => 'US East 1',
'us-east-2' => 'US East 2',
'us-west-1' => 'US West',
'eu-central-1' => 'EU'
])
Expand Down
26 changes: 20 additions & 6 deletions classes/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,28 @@ public function delete($key);
*/
public function info($key);

/**
* Insures the ACL is set on the given key.
* @param $key
* @param $acl
* @return mixed
*/
/**
* Insures the ACL is set on the given key.
* @param $key
* @param $acl
* @return mixed
*/
public function insureACL($key, $acl);

/**
* Changes the ACL on a given key.
* @param $key
* @param $acl
*/
public function updateACL($key, $acl);

/**
* Determines if this driver can update ACLs
*
* @return bool
*/
public function canUpdateACL();

/**
* Generates a presigned URL for an item in a bucket.
*
Expand Down
93 changes: 90 additions & 3 deletions classes/Tools/Storage/StorageTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use GuzzleHttp\Client ;
use ILAB\MediaCloud\Storage\FileInfo ;
use ILAB\MediaCloud\Storage\StorageConstants ;
use ILAB\MediaCloud\Storage\StorageException ;
use ILAB\MediaCloud\Storage\StorageInterface ;
use ILAB\MediaCloud\Storage\StorageManager ;
Expand Down Expand Up @@ -3171,11 +3172,17 @@ function ( $column_name, $id ) {

if ( $column_name == "cloud" ) {
$meta = wp_get_attachment_metadata( $id );
if ( empty($meta) && !isset( $meta['s3'] ) ) {
$meta = get_post_meta( $id, 'ilab_s3_info', true );
}

if ( !empty($meta) && isset( $meta['s3'] ) ) {
$privacy = arrayPath( $meta, 's3/privacy', null );
$mimeType = ( isset( $meta['s3']['mime-type'] ) ? $meta['s3']['mime-type'] : '' );
$cloudIcon = ILAB_PUB_IMG_URL . '/ilab-cloud-icon.svg';
echo "<a class='media-cloud-info-link' data-post-id='{$id}' data-container='list' data-mime-type='{$mimeType}' href='" . $meta['s3']['url'] . "' target=_blank><img src='{$cloudIcon}' width='24'></a>" ;
$lockIcon = ILAB_PUB_IMG_URL . '/ilab-icon-lock.svg';
$lockImg = ( !empty($privacy) && $privacy === StorageConstants::ACL_PRIVATE_READ ? "<img class='mcloud-lock' src='{$lockIcon}' height='22'>" : '' );
echo "<a class='media-cloud-info-link' data-post-id='{$id}' data-container='list' data-mime-type='{$mimeType}' href='" . $meta['s3']['url'] . "' target=_blank><img src='{$cloudIcon}' width='24'>{$lockImg}</a>" ;
}

}
Expand All @@ -3184,6 +3191,70 @@ function ( $column_name, $id ) {
10,
2
);
add_filter( 'bulk_actions-upload', function ( $actions ) {

if ( $this->client()->canUpdateACL() ) {
$actions['mcloud-make-private'] = "Change Privacy to Private";
$actions['mcloud-make-public'] = "Change Privacy to Public";
}

return $actions;
} );
add_filter(
'handle_bulk_actions-upload',
function ( $redirect_to, $action_name, $post_ids ) {

if ( in_array( $action_name, [ 'mcloud-make-private', 'mcloud-make-public' ] ) ) {
$privacy = ( $action_name === 'mcloud-make-private' ? StorageConstants::ACL_PRIVATE_READ : StorageConstants::ACL_PUBLIC_READ );
foreach ( $post_ids as $postId ) {
$attachmentMeta = true;
$updated = false;
$meta = wp_get_attachment_metadata( $postId );

if ( empty($meta) || !isset( $meta['s3'] ) ) {
$attachmentMeta = false;
$meta = get_post_meta( $postId, 'ilab_s3_info', true );
if ( empty($meta) ) {
continue;
}
}

$key = arrayPath( $meta, 's3/key', null );

if ( !empty($key) ) {
$updated = true;
$this->client()->updateACL( $key, $privacy );
$meta['s3']['privacy'] = $privacy;
}

$sizes = arrayPath( $meta, 'sizes', [] );
foreach ( $sizes as $sizeKey => $sizeData ) {
$key = arrayPath( $sizeData, 's3/key', null );

if ( !empty($key) ) {
$updated = true;
$this->client()->updateACL( $key, $privacy );
$meta['sizes'][$sizeKey]['s3']['privacy'] = $privacy;
}

}
if ( $updated ) {

if ( $attachmentMeta ) {
update_post_meta( $postId, '_wp_attachment_metadata', $meta );
} else {
update_post_meta( $postId, 'ilab_s3_info', $meta );
}

}
}
}

return $redirect_to;
},
1000,
3
);
} );
add_action( 'wp_enqueue_media', function () {
add_action( 'admin_head', function () {
Expand Down Expand Up @@ -3340,6 +3411,14 @@ private function hookMediaGrid()
add_action( 'admin_head', function () {
?>
<style>
.mcloud-grid-lock {
display: none;
position: absolute;
right: 34px;
bottom: 5px;
z-index: 5;
}

.ilab-s3-logo {
display: none;
position: absolute;
Expand All @@ -3351,6 +3430,10 @@ private function hookMediaGrid()
.has-s3 > .ilab-s3-logo {
display: block;
}

.has-s3 > .mcloud-grid-lock {
display: block;
}
</style>
<?php
} );
Expand All @@ -3371,7 +3454,9 @@ private function hookMediaGrid()
echo $additionalIcons ;
?><img data-post-id="{{data.id}}" data-container="grid" data-mime-type="{{data.type}}" src="<?php
echo ILAB_PUB_IMG_URL . '/ilab-cloud-icon.svg' ;
?>" width="29" height="18" class="ilab-s3-logo">\n';
?>" width="29" height="18" class="ilab-s3-logo"><# if (data.hasOwnProperty("s3") && (data.s3.privacy=="authenticated-read")) {#><img src="<?php
echo ILAB_PUB_IMG_URL . '/ilab-icon-lock.svg' ;
?>" height="18" class="mcloud-grid-lock"><#}#>\n';
txt = txt.replace(search, replace);
attachTemplate.text(txt);
}
Expand All @@ -3387,7 +3472,9 @@ private function hookMediaGrid()
echo $additionalIcons ;
?><img data-post-id="{{data.id}}" data-container="grid" data-mime-type="{{data.type}}" src="<?php
echo ILAB_PUB_IMG_URL . '/ilab-cloud-icon.svg' ;
?>" width="29" height="18" class="ilab-s3-logo">\n';
?>" width="29" height="18" class="ilab-s3-logo"><# if (data.hasOwnProperty("s3") && (data.s3.privacy=="authenticated-read")) {#><img src="<?php
echo ILAB_PUB_IMG_URL . '/ilab-icon-lock.svg' ;
?>" height="18" class="mcloud-grid-lock"><#}#>\n';
txt = txt.replace(search, replace);
attachTemplate.text(txt);
}
Expand Down
3 changes: 2 additions & 1 deletion config/storage/wasabi.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"display-order" => 11,
"type" => "select",
"options" => [
'us-east-1' => 'US East',
'us-east-1' => 'US East 1',
'us-east-2' => 'US East 2',
'us-west-1' => 'US West',
'eu-central-1' => 'EU',
],
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: 3.3.10
Version: 3.3.11
Author URI: http://interfacelab.io
*/
// Copyright (c) 2016 Interfacelab LLC. All rights reserved.
Expand Down Expand Up @@ -93,7 +93,7 @@
}

// Version Defines
define( 'MEDIA_CLOUD_VERSION', '3.3.10' );
define( 'MEDIA_CLOUD_VERSION', '3.3.11' );
define( 'MEDIA_CLOUD_INFO_VERSION', '1.0.0' );
// Directory defines
define( 'ILAB_TOOLS_DIR', dirname( __FILE__ ) );
Expand Down
2 changes: 1 addition & 1 deletion public/css/ilab-media-cloud.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/img/ilab-icon-lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 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.4
Tested up to: 5.3
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 3.3.10
Stable tag: 3.3.11
Requires PHP: 5.6.4

Automatically store media on Amazon S3, Google Cloud Storage, DigitalOcean Spaces + others. Serve CSS/JS assets through CDNs. Integrate with Imgix.
Expand Down Expand Up @@ -108,6 +108,15 @@ No, I'm just one very enthusiastic customer.

== Changelog ==

= 3.3.11 =

* Added us-east-2 region for Wasabi
* You can now bulk change the privacy for a selection of files in your media library. To do this, switch to list view in the media library, select the images you want to change, select *Change Privacy to Public* or *Change Privacy to Private* from the Bulk Actions dropdown and then click *Apply*.
* Media Library now displays a lock for uploads that are private.
* For private upload the WordPress admin will use signed URLs to display media, but only in the admin (unless you have use presigned URLs enabled).
* Fix for font issue in latest LearnDash


= 3.3.10 =

* CRITICAL FIX. Previous version introduced a library that could cause issues on some systems, it has been fixed in this version. Please update ASAP.
Expand Down

0 comments on commit 4baa215

Please sign in to comment.