From 4e751eb499febad3e76a9c832bce88386ad7cb85 Mon Sep 17 00:00:00 2001 From: Narek Zakaryan Date: Thu, 18 Apr 2019 15:49:55 +0500 Subject: [PATCH 1/5] Add filter to change the storage prefix This filter allows to change the $prefix variable when uploading to the storage, so if you want to upload all images to the certain folder in the bucket, you can do it by changing prefix --- classes/Tools/Storage/StorageTool.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/Tools/Storage/StorageTool.php b/classes/Tools/Storage/StorageTool.php index 5489ef4f..8e6cea82 100644 --- a/classes/Tools/Storage/StorageTool.php +++ b/classes/Tools/Storage/StorageTool.php @@ -1128,7 +1128,9 @@ private function processFile($upload_path, $filename, $data, $id = null, $preser } else { $prefix = ($preserveFilePath && isset($data['prefix'])) ? $data['prefix'].DIRECTORY_SEPARATOR : StorageSettings::prefix($id); } - + + $prefix = apply_filters( 'ilab_storage_prefix', $prefix ); + $parts = explode('/', $filename); $bucketFilename = array_pop($parts); From 804a401717697a3fa7f9170abb618cb5ec485dc7 Mon Sep 17 00:00:00 2001 From: Narek Zakaryan Date: Thu, 18 Jul 2019 16:53:14 +0500 Subject: [PATCH 2/5] import only product images --- classes/Tools/Storage/CLI/StorageCommands.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/classes/Tools/Storage/CLI/StorageCommands.php b/classes/Tools/Storage/CLI/StorageCommands.php index b4b3c758..555f5e86 100755 --- a/classes/Tools/Storage/CLI/StorageCommands.php +++ b/classes/Tools/Storage/CLI/StorageCommands.php @@ -67,10 +67,21 @@ public function import($args, $assoc_args) { } + $product_posts = new \WP_Query( + array( + 'post_type' => 'product', // adjust your custom post type name here + 'posts_per_page' => -1, + 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'), + 'fields' => 'ids' + ) + ); + $postArgs = [ 'post_type' => 'attachment', 'post_status' => 'inherit', + 'nopaging' => true, 'fields' => 'ids', + 'post_parent__in' => $product_posts->posts, ]; if (isset($assoc_args['limit'])) { From 9ce31fcab94f2321796a9fd064c697f840d2fe49 Mon Sep 17 00:00:00 2001 From: Narek Zakaryan Date: Fri, 19 Jul 2019 16:07:12 +0500 Subject: [PATCH 3/5] update version --- ilab-media-tools.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ilab-media-tools.php b/ilab-media-tools.php index b0a9b189..79908ec4 100755 --- a/ilab-media-tools.php +++ b/ilab-media-tools.php @@ -1,11 +1,11 @@ Date: Thu, 1 Aug 2019 14:06:47 +0500 Subject: [PATCH 4/5] add option to store the filesize in db meta --- classes/Tools/Storage/StorageTool.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/classes/Tools/Storage/StorageTool.php b/classes/Tools/Storage/StorageTool.php index 0d4c2dbe..42dd2018 100755 --- a/classes/Tools/Storage/StorageTool.php +++ b/classes/Tools/Storage/StorageTool.php @@ -1608,6 +1608,14 @@ public function processFile($upload_path, $filename, $data, $id = null, $preserv 'options' => $options ]; + /** + * Change by Novembit + * store filesize to meta + */ + if( file_exists( $upload_path.'/'.$filename ) ) { + $data['filesize'] = filesize( $upload_path.'/'.$filename ); + } + if(file_exists($upload_path.'/'.$filename)) { $ftype = wp_check_filetype($upload_path.'/'.$filename); if(!empty($ftype) && isset($ftype['type'])) { From cfcb3dd847c8d6caa460c96b3a088a01e86427e2 Mon Sep 17 00:00:00 2001 From: Rafik Israyelyan Date: Fri, 20 Sep 2019 11:00:49 +0400 Subject: [PATCH 5/5] Fix PHP notice addressing to https://gitlab.com/brandlight/open-source/brandlight/issues/1248 --- classes/Tools/Storage/StorageTool.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/Tools/Storage/StorageTool.php b/classes/Tools/Storage/StorageTool.php index 42dd2018..f7083e60 100755 --- a/classes/Tools/Storage/StorageTool.php +++ b/classes/Tools/Storage/StorageTool.php @@ -1368,12 +1368,14 @@ public function filterContent($content) { $textSize = null; $cleanedUrl = null; $size = 'full'; + $sizePrefix = '-'; + $sizeSeparator = 'x'; - if (preg_match('/(-[0-9x]+)\.(?:jpg|gif|png)/m', $matchedUrl, $sizeMatches)) { + if (preg_match("/({$sizePrefix}\d+{$sizeSeparator}\d+)\.(?:jpg|gif|png)/mi", $matchedUrl, $sizeMatches)) { $cleanedUrl = str_replace($sizeMatches[1], '', $matchedUrl); $id = attachment_url_to_postid($cleanedUrl); - $textSize = trim($sizeMatches[1], '-'); - $size = explode('x', $textSize); + $textSize = trim($sizeMatches[1], $sizePrefix); + $size = explode($sizeSeparator, $textSize); } else { $id = attachment_url_to_postid($matchedUrl); }