From a3f1d78597234750f9d5ef54717535cb185870ab Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Thu, 29 Jun 2017 14:30:25 +0100 Subject: [PATCH 1/5] Added support for specifying a custom endpoint. --- classes/tools/s3/ilab-media-s3-tool.php | 24 ++++++++++++++++-------- tools.json | 6 ++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/classes/tools/s3/ilab-media-s3-tool.php b/classes/tools/s3/ilab-media-s3-tool.php index dc7a0620..67cf2a42 100644 --- a/classes/tools/s3/ilab-media-s3-tool.php +++ b/classes/tools/s3/ilab-media-s3-tool.php @@ -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; @@ -57,6 +58,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', ''); @@ -361,13 +363,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 && (!$s3->doesBucketExist($this->bucket))) return null; @@ -1034,7 +1042,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']; diff --git a/tools.json b/tools.json index c124fee6..16566887 100644 --- a/tools.json +++ b/tools.json @@ -398,6 +398,12 @@ "description": "If you are supplying this value through a .env file, or environment variables, the key is: ILAB_AWS_S3_BUCKET", "type": "text-field", "watch": true + }, + "ilab-media-s3-endpoint": { + "title": "Custom Endpoint URL", + "description": "If you are not running on AWS, but instead use S3-compatible server like Minio or Ceph RGW, specify your endpoint (e.g. http://mystorage.example.com) here. If you are supplying this value through a .env file, or environment variables, the key is: ILAB_AWS_S3_ENDPOINT", + "type": "text-field", + "watch": true } } }, From 62c3b42cbcb264e0459e39485cdae8fc136b2eaf Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Sat, 9 Sep 2017 02:11:54 +0700 Subject: [PATCH 2/5] Clean up the layout for the custom endpoint setting. --- tools.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools.json b/tools.json index 3869fa84..614ee061 100644 --- a/tools.json +++ b/tools.json @@ -398,10 +398,16 @@ "description": "If you are supplying this value through a .env file, or environment variables, the key is: ILAB_AWS_S3_BUCKET", "type": "text-field", "watch": true - }, + } + } + }, + "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 interoperability mode) or Digital Ocean Spaces. If you are using one of these services, specify the endpoint for the service's api here. IMPORTANT: If you are using Minio, your bucket must have a public read policy set for the entire bucket. See here for more details.", + "options": { "ilab-media-s3-endpoint": { "title": "Custom Endpoint URL", - "description": "If you are not running on AWS, but instead use S3-compatible server like Minio or Ceph RGW, specify your endpoint (e.g. http://mystorage.example.com) here. If you are supplying this value through a .env file, or environment variables, the key is: ILAB_AWS_S3_ENDPOINT", + "description": "If you are supplying this value through a .env file, or environment variables, the key is: ILAB_AWS_S3_ENDPOINT", "type": "text-field", "watch": true } From 9f9be03d87c79f1124cf71aa45c3db8dedfa022d Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Sat, 9 Sep 2017 02:42:55 +0700 Subject: [PATCH 3/5] Fix for S3 Info panel. --- classes/tools/s3/ilab-media-s3-tool.php | 64 ++++++++++++++----------- ilab-media-tools.php | 2 +- readme.txt | 14 ++++-- views/s3/ilab-s3-importer.php | 2 +- 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/classes/tools/s3/ilab-media-s3-tool.php b/classes/tools/s3/ilab-media-s3-tool.php index 87262886..af9a59f5 100644 --- a/classes/tools/s3/ilab-media-s3-tool.php +++ b/classes/tools/s3/ilab-media-s3-tool.php @@ -320,41 +320,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. -
- Bucket: -
-
- Path: -
-
- - -
-
- - -
-
- - -
- - +
+ Bucket: +
+
+ Path: +
+
+ + +
+
+ + +
+
+ + +
+ +
  • If you upload any files while this process is running, you'll need to run this tool again after it finishes.
  • This process DOES NOT delete your files on your server, you'll have to do that yourself manually.
  • -
  • It's recommended that you have the S3 tool disabled in Tools Settings before running this task.
  • +
  • You MUST HAVE S3 enabled and working in Tools Settings before running this task.
  • Import Uploads From fce523edfcb32b5bcb8775e4c7ea58b0404d6ef6 Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Sat, 9 Sep 2017 03:09:04 +0700 Subject: [PATCH 4/5] Remove shell command to determine mime type. --- views/s3/ilab-s3-importer.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/views/s3/ilab-s3-importer.php b/views/s3/ilab-s3-importer.php index 999494b1..54159b08 100644 --- a/views/s3/ilab-s3-importer.php +++ b/views/s3/ilab-s3-importer.php @@ -17,6 +17,11 @@ height: 100%; width: {{$progress}}%; } + + .tool-disabled { + padding: 10px 15px; + border: 1px solid #df8403; + }

    S3 Importer

    @@ -30,7 +35,11 @@
  • You MUST HAVE S3 enabled and working in Tools Settings before running this task.
  • + Import Uploads + + Please enable S3 before using this tool. +
    From 483723ab6b63f2031b9fd22aa53cb64e017a1ff8 Mon Sep 17 00:00:00 2001 From: Jon Gilkison Date: Sat, 9 Sep 2017 03:09:33 +0700 Subject: [PATCH 5/5] Remove shell command to determine mime type. Disable S3 Importer if S3 is not enabled. --- classes/tasks/ilab-s3-import-process.php | 3 ++- classes/tools/s3/ilab-media-s3-tool.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/classes/tasks/ilab-s3-import-process.php b/classes/tasks/ilab-s3-import-process.php index 9a8d9467..5230308b 100644 --- a/classes/tasks/ilab-s3-import-process.php +++ b/classes/tasks/ilab-s3-import-process.php @@ -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'; } diff --git a/classes/tools/s3/ilab-media-s3-tool.php b/classes/tools/s3/ilab-media-s3-tool.php index af9a59f5..e329b7b3 100644 --- a/classes/tools/s3/ilab-media-s3-tool.php +++ b/classes/tools/s3/ilab-media-s3-tool.php @@ -224,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; } @@ -917,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); @@ -940,7 +946,8 @@ public function renderImporter() { 'status' => ($status) ? 'running' : 'idle', 'total' => $total, 'progress' => $progress, - 'current' => $current + 'current' => $current, + 'enabled' => $enabled ]); }