Skip to content

Commit

Permalink
Merge branch 'feature/cloud_files' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jawngee committed Sep 8, 2017
2 parents 646e4ae + 483723a commit eab7cf0
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 46 deletions.
3 changes: 2 additions & 1 deletion classes/tasks/ilab-s3-import-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function task($item) {
$file = _wp_relative_upload_path($upload_file);
$data = [ 'file' => $file ];
if (file_exists($upload_file)) {
$mime = trim(`file --mime-type -b {$upload_file}`);
$mime = mime_content_type($upload_file);

if ($mime == 'image/vnd.adobe.photoshop') {
$mime = 'application/vnd.adobe.photoshop';
}
Expand Down
99 changes: 61 additions & 38 deletions classes/tools/s3/ilab-media-s3-tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ILabMediaS3Tool extends ILabMediaToolBase {
private $key = null;
private $secret = null;
private $bucket = null;
private $endpoint = null;
private $docCdn = null;
private $cdn = null;
private $deleteOnUpload = false;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function __construct($toolName, $toolInfo, $toolManager)
$this->bucket = $this->getOption('ilab-media-s3-bucket', 'ILAB_AWS_S3_BUCKET');
$this->key = $this->getOption('ilab-media-s3-access-key', 'ILAB_AWS_S3_ACCESS_KEY');
$this->secret = $this->getOption('ilab-media-s3-secret', 'ILAB_AWS_S3_ACCESS_SECRET');
$this->endpoint = $this->getOption('ilab-media-s3-endpoint', 'ILAB_AWS_S3_ENDPOINT');
$this->deleteOnUpload = $this->getOption('ilab-media-s3-delete-uploads');
$this->deleteFromS3 = $this->getOption('ilab-media-s3-delete-from-s3');
$this->prefixFormat = $this->getOption('ilab-media-s3-prefix', '');
Expand Down Expand Up @@ -222,8 +224,12 @@ public function editAttachment($post_id) {
private function editDocumentAttachment() {
global $post;

if (empty($post)) {
return;
}

$meta = get_post_meta($post->ID, 'ilab_s3_info', true);
if (!isset($meta['s3'])) {
if (empty($meta) || !isset($meta['s3'])) {
return;
}

Expand Down Expand Up @@ -318,41 +324,49 @@ public function renderS3InfoMeta() {
global $post;

$meta = wp_get_attachment_metadata($post->ID);
if (empty($meta)) {
echo 'gay';

return;
}

if (!isset($meta['s3'])) {
$meta = get_post_meta($post->ID, 'ilab_s3_info', true);
}

if (!isset($meta['s3'])) {
if (empty($meta) || !isset($meta['s3'])) {
?>
Not uploaded to S3.
<?php
}
?>
<div class="misc-pub-section">
Bucket: <a href="https://console.aws.amazon.com/s3/buckets/<?php echo $meta['s3']['bucket']?>" target="_blank"><?php echo $meta['s3']['bucket']?></a>
</div>
<div class="misc-pub-section">
Path: <a href="https://console.aws.amazon.com/s3/buckets/<?php echo $meta['s3']['bucket']?>/<?php echo $meta['s3']['key']?>/details" target="_blank"><?php echo $meta['s3']['key']?></a>
</div>
<div class="misc-pub-section">
<label for="s3-access-acl">Access:</label>
<select id="s3-access-acl" name="s3-access-acl">
<option value="public-read" <?php echo (isset($meta['s3']['privacy']) && ($meta['s3']['privacy']=='public-read')) ? 'selected' : '' ?>>Public</option>
<option value="authenticated-read" <?php echo (isset($meta['s3']['privacy']) && ($meta['s3']['privacy']=='authenticated-read')) ? 'selected' : '' ?>>Authenticated Users</option>
</select>
</div>
<div class="misc-pub-section">
<label for="s3-cache-control">Cache-Control:</label>
<input type="text" class="widefat" name="s3-cache-control" id="s3-cache-control" value="<?php echo (isset($meta['s3']['options']) && isset($meta['s3']['options']['params']['CacheControl'])) ? $meta['s3']['options']['params']['CacheControl'] : '' ?>">
</div>
<div class="misc-pub-section">
<label for="s3-expires">Expires:</label>
<input type="text" class="widefat" name="s3-expires" id="s3-expires" value="<?php echo (isset($meta['s3']['options']) && isset($meta['s3']['options']['params']['Expires'])) ? $meta['s3']['options']['params']['Expires'] : '' ?>">
</div>
<div class="misc-pub-section">
<a href="<?php echo $meta['s3']['url']?>" target="_blank">View S3 URL</a></strong>
</div>
<?php
} else {
?>
<div class="misc-pub-section">
Bucket: <a href="https://console.aws.amazon.com/s3/buckets/<?php echo $meta['s3']['bucket']?>" target="_blank"><?php echo $meta['s3']['bucket']?></a>
</div>
<div class="misc-pub-section">
Path: <a href="https://console.aws.amazon.com/s3/buckets/<?php echo $meta['s3']['bucket']?>/<?php echo $meta['s3']['key']?>/details" target="_blank"><?php echo $meta['s3']['key']?></a>
</div>
<div class="misc-pub-section">
<label for="s3-access-acl">Access:</label>
<select id="s3-access-acl" name="s3-access-acl">
<option value="public-read" <?php echo (isset($meta['s3']['privacy']) && ($meta['s3']['privacy']=='public-read')) ? 'selected' : '' ?>>Public</option>
<option value="authenticated-read" <?php echo (isset($meta['s3']['privacy']) && ($meta['s3']['privacy']=='authenticated-read')) ? 'selected' : '' ?>>Authenticated Users</option>
</select>
</div>
<div class="misc-pub-section">
<label for="s3-cache-control">Cache-Control:</label>
<input type="text" class="widefat" name="s3-cache-control" id="s3-cache-control" value="<?php echo (isset($meta['s3']['options']) && isset($meta['s3']['options']['params']['CacheControl'])) ? $meta['s3']['options']['params']['CacheControl'] : '' ?>">
</div>
<div class="misc-pub-section">
<label for="s3-expires">Expires:</label>
<input type="text" class="widefat" name="s3-expires" id="s3-expires" value="<?php echo (isset($meta['s3']['options']) && isset($meta['s3']['options']['params']['Expires'])) ? $meta['s3']['options']['params']['Expires'] : '' ?>">
</div>
<div class="misc-pub-section">
<a href="<?php echo $meta['s3']['url']?>" target="_blank">View S3 URL</a></strong>
</div>
<?php
}

}


Expand All @@ -361,13 +375,19 @@ private function s3Client($insure_bucket=false)
if (!$this->s3enabled())
return null;

$s3=new \ILAB_Aws\S3\S3MultiRegionClient([
'version' => 'latest',
'credentials' => [
'key' => $this->key,
'secret' => $this->secret
]
]);
$config = [
'version' => 'latest',
'credentials' => [
'key' => $this->key,
'secret' => $this->secret
]
];

if ($this->endpoint) {
$config['endpoint'] = $this->endpoint;
}

$s3=new \ILAB_Aws\S3\S3MultiRegionClient($config);

if ($insure_bucket && !$this->skipBucketCheck) {
if (!$s3->doesBucketExist($this->bucket)) {
Expand Down Expand Up @@ -901,6 +921,8 @@ public function settingsChanged() {
}

public function renderImporter() {
$enabled = $this->s3enabled();

$status = get_option('ilab_s3_import_status', false);
$total = get_option('ilab_s3_import_total_count', 0);
$current = get_option('ilab_s3_import_current', 1);
Expand All @@ -924,7 +946,8 @@ public function renderImporter() {
'status' => ($status) ? 'running' : 'idle',
'total' => $total,
'progress' => $progress,
'current' => $current
'current' => $current,
'enabled' => $enabled
]);
}

Expand Down Expand Up @@ -1051,7 +1074,7 @@ public function prepareAttachmentForJS($response, $attachment, $meta ) {
if (empty($meta) || !isset($meta['s3'])) {
$meta = get_post_meta($attachment->ID, 'ilab_s3_info', true);
}

if (isset($meta['s3'])) {
$response['s3'] = $meta['s3'];

Expand Down
2 changes: 1 addition & 1 deletion ilab-media-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://interfacelab.com/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: 1.4.8
Version: 1.4.9
Author URI: http://interfacelab.io
*/

Expand Down
14 changes: 9 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
=== Media Cloud by ILAB ===
Contributors: interfacelab
Tags: media, images, cdn, uploads, crop, imgix, s3, cloudfront, aws, amazon s3, image editing, image editor, mirror, media library, offload, offload s3
Tags: media, images, cdn, uploads, crop, imgix, s3, cloudfront, aws, amazon s3, image editing, image editor, mirror, media library, offload, offload s3, minio, google cloud storage, digital ocean spaces
Requires at least: 4.4
Tested up to: 4.8.1
License: GPLv3 or later
Donate link: http://www2.jdrf.org/site/TR?fr_id=6912&pg=personal&px=11429802
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Stable tag: 1.4.8
Stable tag: 1.4.9

Automatically upload media to Amazon S3 and integrate with Imgix, a real-time image processing CDN. Boosts site
performance and simplifies workflows.
Expand All @@ -17,9 +17,9 @@ Media Cloud by ILAB is a suite of tools designed to enhance media handling in Wo

**NOTE**: This plugin requires PHP 5.5x or higher (PHP 7.x preferred)

= Upload to S3 =
Automatically copy media uploads to S3 and hosts your media directly
from S3 or CloudFront. Additionally, easily import your existing
= Upload to S3, Mini, Google Cloud Storage and Digital Ocean Spaces =
Automatically copy media uploads to S3 (and S3 compatible services) and hosts your media directly
from S3, CloudFront or any other CDN. Additionally, easily import your existing
media library to Amazon S3 with the push of a button.

= Integrate with Imgix =
Expand Down Expand Up @@ -98,6 +98,10 @@ No, I'm just one very enthusiastic customer.
5. Imgix settings.

== Changelog ==
= 1.4.9 =
* Compatibility with S3-compatible services like Minio, Google Cloud Storage (when in interoperability mode) and Digital Ocean Spaces. (thanks to Vladimir Pouzanov)
* Misc. fixes

= 1.4.7 =
* Fixed collision with Types plugin
* Added donation link. If you find this plugin useful, PLEASE donate to my JDRF fund raiser for finding a cure for type 1 diabetes.
Expand Down
12 changes: 12 additions & 0 deletions tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@
}
}
},
"ilab-media-s3-aws-custom-endpoint-settings": {
"title": "Custom End Point (Advanced)",
"description": "ILAB Media Cloud is compatible with any S3 compatible cloud storage server like Minio, Ceph RGW, Google Cloud Storage (when in <a href='https://cloud.google.com/storage/docs/migrating#migration-simple' target=_blank>interoperability mode</a>) or Digital Ocean Spaces. If you are using one of these services, specify the endpoint for the service's api here. <strong>IMPORTANT:</strong> If you are using Minio, your bucket must have a public read policy set for the entire bucket. See <a href='https://github.com/minio/minio/issues/3774' target=_blank>here</a> for more details.",
"options": {
"ilab-media-s3-endpoint": {
"title": "Custom Endpoint URL",
"description": "If you are supplying this value through a .env file, or environment variables, the key is: <strong>ILAB_AWS_S3_ENDPOINT</strong>",
"type": "text-field",
"watch": true
}
}
},
"ilab-media-s3-upload-handling-settings": {
"title": "Upload Handling",
"description": "The following options control how the S3 tool handles uploads.",
Expand Down
11 changes: 10 additions & 1 deletion views/s3/ilab-s3-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
height: 100%;
width: {{$progress}}%;
}

.tool-disabled {
padding: 10px 15px;
border: 1px solid #df8403;
}
</style>
<div class="wrap">
<h1>S3 Importer</h1>
Expand All @@ -27,10 +32,14 @@
<ol>
<li>If you upload any files while this process is running, you'll need to run this tool again after it finishes.</li>
<li>This process DOES NOT delete your files on your server, you'll have to do that yourself manually.</li>
<li>It's recommended that you have the S3 tool disabled in <a href="admin.php?page=media-tools-top">Tools Settings</a> before running this task.</li>
<li>You <strong>MUST HAVE</strong> S3 enabled and working in <a href="admin.php?page=media-tools-top">Tools Settings</a> before running this task.</li>
</ol>
<div style="margin-top: 2em;">
<?php if($enabled): ?>
<a href="#" class="ilab-ajax button">Import Uploads</a>
<?php else: ?>
<strong class="tool-disabled">Please <a href="admin.php?page=media-tools-top">enable S3</a> before using this tool.</strong>
<?php endif ?>
</div>
</div>
<div id="s3-importer-progress" {{($status!="running") ? 'style="display:none"':''}}>
Expand Down

0 comments on commit eab7cf0

Please sign in to comment.