Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Interfacelab/ilab-media-tools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.5.15
Choose a base ref
...
head repository: Interfacelab/ilab-media-tools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 183 files changed
  • 1 contributor

Commits on Dec 8, 2022

  1. * Added wp mediacloud:storage syncAllLocal command to download all …

    …cloud storage files to your local server.
    
    * Added integration for WPForms to automatically upload files to the cloud. (Premium)
    * Added task to migrate existing WPForms entries to cloud storage. (Premium)
    * Added new **Generate EWW WebP** task to generate webp files from images on cloud storage.  EWWW Image Optimization
      plugin must be installed and activated and working in local mode (NOT cloud mode).  (Premium)
    * Added `wp mediacloud:storage makewebp` command to generate webp files using EWWW (see above).  (Premium)
    * Updated Freemius to latest version.
    jawngee committed Dec 8, 2022
    Copy the full SHA
    e55094c View commit details

Commits on Dec 9, 2022

  1. * Added --skip-processed flag to mediacloud:storage makewebp comm…

    …and to skip any attachments that already have webp
    
      metadata associated with them. (Premium)
    * Added a setting to *Cloud Storage* settings called *Force WebP* that forces Media Cloud to return .webp urls for images
      that have webp metadata associated with them.  Note this does not do any sort of content negotiation or browser
      sniffing, it simply returns the webp url for the image.  Consider that only IE 11 and much older versions of Safari
      do not support webp.
    jawngee committed Dec 9, 2022
    Copy the full SHA
    b9ebbd6 View commit details

Commits on Jul 21, 2023

  1. * IMPORTANT: This includes an important security fix for a third part…

    …y lib. Please update ASAP.
    
    * Added missing us-west-1 region to Rekognition
    jawngee committed Jul 21, 2023
    Copy the full SHA
    4a6c588 View commit details

Commits on Sep 27, 2023

  1. * Fix Clean Uploads task to deal with crusty databases that have URLs…

    … in the _wp_attached_file meta field.
    
    * Added `media-cloud/storage/verify/settings` filter to enable skipping cloud storage settings verification.  Only use this
      if you are using a strict IAM policy that prevents Media Cloud from verifying your settings.
    * System compatibility test now takes upload prefix into account when testing cloud storage
    * Deprecate Wasabi.  Wasabi is not a suitable cloud storage provider for Media Cloud's purpose.  If you are using Wasabi currently,
      nothing will change.  If you are not using Wasabi, you will not be able to add it as a cloud storage provider.
    * Massive performance improvement for multisite.
    * Some fixes for PHP 8.2.  Still don't recommend using 8.2 with WordPress.  8.1 and 8.0 work fine though.
    jawngee committed Sep 27, 2023
    Copy the full SHA
    b437125 View commit details

Commits on Mar 9, 2024

  1. * Update Freemius SDK

    * Fix for deprecation notices
    * Fix for issue with mux shortcode
    * Fix for bug in storage tool
    jawngee committed Mar 9, 2024
    Copy the full SHA
    c48a1cd View commit details

Commits on Mar 21, 2024

  1. * Migrating media now migrates .webp and .avif files regardless of wh…

    …at plugin generated them.
    
    * Added beta support for Bunny CDN as a storage provider.
        * Note that Bunny CDN doesn't support ACLs so it can't do signed URLs like other cloud storage providers, so it is not suitable for WooCommerce, EDD or anything else where you want to protect individual files.
        * You can protect directories though and any files in a specified directory will be signed.  This is probably a moving target  feature wise.
        * Also note that this works differently then Bunny's WordPress plugin.  Bunny's plugin works via pull where Media Cloud is  push (it uploads your media to Bunny CDN).  Which way is better is up to you to decide, though you can't use Bunny's plugin in a dev environment or on a localhost during dev.
        * Documentation is non existent at the moment but that will be remedied later next week.
    * Fixed Migrate to Mux task.
    * Fixes for some PHP 8.2 errors and notices.
    jawngee committed Mar 21, 2024
    Copy the full SHA
    4cf30db View commit details

Commits on Mar 22, 2024

  1. * Added beta support for Bunny CDN as a storage provider.

        * Note that Bunny CDN doesn't support ACLs so it can't do signed URLs like other cloud storage providers, so it is not suitable for WooCommerce, EDD or anything else where you want to protect individual files.
        * You can protect directories though and any files in a specified directory will be signed.  This is probably a moving target  feature wise.
        * Also note that this works differently then Bunny's WordPress plugin.  Bunny's plugin works via pull where Media Cloud is  push (it uploads your media to Bunny CDN).  Which way is better is up to you to decide, though you can't use Bunny's plugin in a dev environment or on a localhost during dev.
    * Added documentation for Bunny CDN
    * Fixed Migrate to Mux task.
    * Migrating media now migrates .webp and .avif files regardless of what plugin generated them.
    * Fixes for some PHP 8.2 errors and notices.
    jawngee committed Mar 22, 2024
    Copy the full SHA
    b2bb4ca View commit details

Commits on Mar 24, 2024

  1. Copy the full SHA
    18c4cdd View commit details

Commits on Apr 9, 2024

  1. * IMPORTANT UPDATE. Due to an issue with our build process Gutenberg …

    …blocks were excluded
    
    * Updated Freemius SDK
    * Fixed issue with weird dialogs displaying in admin (missing CSS files due to new build process)
    jawngee committed Apr 9, 2024
    Copy the full SHA
    74c3a00 View commit details
Showing with 52,689 additions and 46,525 deletions.
  1. +3 −3 classes/Tools/Debugging/System/SystemCompatibilityTool.php
  2. +127 −0 classes/Tools/Storage/CLI/StorageCommands.php
  3. +190 −0 classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNClient.php
  4. +30 −0 classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNSettings.php
  5. +497 −0 classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNStorage.php
  6. +4 −0 classes/Tools/Storage/Driver/S3/S3Storage.php
  7. +6 −0 classes/Tools/Storage/StorageContentHooks.php
  8. +1 −0 classes/Tools/Storage/StorageFile.php
  9. +115 −31 classes/Tools/Storage/StorageTool.php
  10. +7 −0 classes/Tools/Storage/StorageToolSettings.php
  11. +35 −3 classes/Tools/Storage/Tasks/CleanUploadsTask.php
  12. +3 −1 classes/Tools/Tasks/TasksTool.php
  13. +1 −1 classes/Tools/ToolsManager.php
  14. +14 −1 classes/Tools/Video/Driver/Mux/MuxHooks.php
  15. +2 −2 classes/Tools/Video/Player/VideoPlayerShortcode.php
  16. +2 −1 classes/Tools/Vision/Driver/Rekognition/RekognitionDriver.php
  17. +1 −1 classes/Tools/Vision/VisionDriver.php
  18. +30 −2 classes/Utilities/Environment.php
  19. +70 −0 classes/Utilities/Wildcard.php
  20. +2 −2 composer.json
  21. +34 −18 config/storage.config.php
  22. +79 −0 config/storage/bunnycdn.config.php
  23. +4 −3 config/wizard.config.php
  24. +1 −1 external/Freemius/assets/css/admin/account.css
  25. +1 −1 external/Freemius/assets/css/admin/add-ons.css
  26. +1 −1 external/Freemius/assets/css/admin/affiliation.css
  27. +1 −1 external/Freemius/assets/css/admin/checkout.css
  28. +1 −1 external/Freemius/assets/css/admin/clone-resolution.css
  29. +1 −1 external/Freemius/assets/css/admin/common.css
  30. +1 −1 external/Freemius/assets/css/admin/connect.css
  31. +1 −1 external/Freemius/assets/css/admin/debug.css
  32. +1 −1 external/Freemius/assets/css/admin/dialog-boxes.css
  33. +1 −1 external/Freemius/assets/css/admin/gdpr-optin-notice.css
  34. +1 −1 external/Freemius/assets/css/admin/optout.css
  35. +1 −1 external/Freemius/assets/css/admin/plugins.css
  36. +1 −1 external/Freemius/assets/css/customizer.css
  37. +1 −113 external/Freemius/assets/js/nojquery.ba-postmessage.js
  38. +0 −12 external/Freemius/assets/js/nojquery.ba-postmessage.min.js
  39. +1 −135 external/Freemius/assets/js/postmessage.js
  40. +1 −1 external/Freemius/config.php
  41. +26,448 −26,563 external/Freemius/includes/class-freemius.php
  42. +718 −687 external/Freemius/includes/class-fs-api.php
  43. +439 −0 external/Freemius/includes/class-fs-garbage-collector.php
  44. +430 −430 external/Freemius/includes/class-fs-options.php
  45. +1,589 −1,563 external/Freemius/includes/class-fs-plugin-updater.php
  46. +559 −558 external/Freemius/includes/class-fs-storage.php
  47. +47 −43 external/Freemius/includes/debug/class-fs-debug-bar-panel.php
  48. +4 −0 external/Freemius/includes/entities/class-fs-plugin-license.php
  49. +4 −0 external/Freemius/includes/entities/class-fs-plugin-plan.php
  50. +4 −0 external/Freemius/includes/entities/class-fs-plugin-tag.php
  51. +5 −0 external/Freemius/includes/entities/class-fs-plugin.php
  52. +5 −1 external/Freemius/includes/entities/class-fs-site.php
  53. +1,505 −1,404 external/Freemius/includes/fs-core-functions.php
  54. +418 −410 external/Freemius/includes/fs-essential-functions.php
  55. +126 −0 external/Freemius/includes/fs-html-escaping-functions.php
  56. +1,691 −1,644 external/Freemius/includes/fs-plugin-info-dialog.php
  57. +532 −532 external/Freemius/includes/managers/class-fs-admin-notice-manager.php
  58. +1,660 −1,660 external/Freemius/includes/managers/class-fs-clone-manager.php
  59. +0 −12 external/Freemius/includes/managers/class-fs-gdpr-manager.php
  60. +706 −697 external/Freemius/includes/managers/class-fs-permission-manager.php
  61. +40 −9 external/Freemius/includes/managers/class-fs-plan-manager.php
  62. +232 −232 external/Freemius/includes/managers/class-fs-plugin-manager.php
  63. +13 −13 external/Freemius/includes/sdk/Exceptions/ArgumentNotExistException.php
  64. +13 −13 external/Freemius/includes/sdk/Exceptions/EmptyArgumentException.php
  65. +78 −78 external/Freemius/includes/sdk/Exceptions/Exception.php
  66. +12 −12 external/Freemius/includes/sdk/Exceptions/InvalidArgumentException.php
  67. +16 −16 external/Freemius/includes/sdk/Exceptions/OAuthException.php
  68. +216 −216 external/Freemius/includes/sdk/FreemiusBase.php
  69. +745 −715 external/Freemius/includes/sdk/FreemiusWordPress.php
  70. +30 −30 external/Freemius/includes/supplements/fs-migration-2.5.1.php
  71. BIN external/Freemius/languages/freemius-cs_CZ.mo
  72. BIN external/Freemius/languages/freemius-da_DK.mo
  73. BIN external/Freemius/languages/freemius-de_DE.mo
  74. BIN external/Freemius/languages/freemius-en.mo
  75. BIN external/Freemius/languages/freemius-es_ES.mo
  76. BIN external/Freemius/languages/freemius-fr_FR.mo
  77. BIN external/Freemius/languages/freemius-he_IL.mo
  78. BIN external/Freemius/languages/freemius-hu_HU.mo
  79. BIN external/Freemius/languages/freemius-it_IT.mo
  80. BIN external/Freemius/languages/freemius-ja.mo
  81. BIN external/Freemius/languages/freemius-nl_NL.mo
  82. BIN external/Freemius/languages/freemius-ru_RU.mo
  83. BIN external/Freemius/languages/freemius-ta.mo
  84. BIN external/Freemius/languages/freemius-zh_CN.mo
  85. +684 −624 external/Freemius/languages/freemius.pot
  86. +3 −0 external/Freemius/require.php
  87. +29 −1 external/Freemius/start.php
  88. +1,129 −1,133 external/Freemius/templates/account.php
  89. +11 −11 external/Freemius/templates/account/billing.php
  90. +451 −451 external/Freemius/templates/account/partials/addon.php
  91. +353 −353 external/Freemius/templates/account/partials/site.php
  92. +501 −501 external/Freemius/templates/add-ons.php
  93. +67 −34 external/Freemius/templates/admin-notice.php
  94. +32 −0 external/Freemius/templates/api-connectivity-message-js.php
  95. +8 −5 external/Freemius/templates/checkout.php
  96. +14 −4 external/Freemius/templates/clone-resolution-js.php
  97. +1,044 −1,047 external/Freemius/templates/connect.php
  98. +42 −42 external/Freemius/templates/connect/permission.php
  99. +71 −71 external/Freemius/templates/connect/permissions-group.php
  100. +1 −1 external/Freemius/templates/contact.php
  101. +831 −827 external/Freemius/templates/debug.php
  102. +0 −62 external/Freemius/templates/firewall-issues-js.php
  103. +13 −4 external/Freemius/templates/forms/affiliation.php
  104. +212 −212 external/Freemius/templates/forms/data-debug-mode.php
  105. +666 −666 external/Freemius/templates/forms/deactivation/form.php
  106. +346 −346 external/Freemius/templates/forms/email-address-update.php
  107. +899 −890 external/Freemius/templates/forms/license-activation.php
  108. +183 −182 external/Freemius/templates/forms/optout.php
  109. +296 −296 external/Freemius/templates/forms/user-change.php
  110. +3 −2 external/Freemius/templates/gdpr-optin-js.php
  111. +545 −545 external/Freemius/templates/js/permissions.php
  112. +4 −4 external/Freemius/templates/partials/network-activation.php
  113. +1 −6 external/Freemius/templates/plugin-info/description.php
  114. +0 −5 external/Freemius/templates/plugin-info/screenshots.php
  115. +1 −1 external/Freemius/templates/powered-by.php
  116. +1 −1 external/Freemius/templates/pricing.php
  117. +3 −2 external/Freemius/templates/tabs-capture-js.php
  118. +189 −189 external/Freemius/templates/tabs.php
  119. +6 −2 ilab-media-tools.php
  120. +1 −1 lib/mcloud-aws/aws-sdk-php/src/ClientSideMonitoring/ConfigurationProvider.php
  121. +1 −1 lib/mcloud-aws/aws-sdk-php/src/DefaultsMode/ConfigurationProvider.php
  122. +1 −1 lib/mcloud-aws/aws-sdk-php/src/Endpoint/UseDualstackEndpoint/ConfigurationProvider.php
  123. +1 −1 lib/mcloud-aws/aws-sdk-php/src/Endpoint/UseFipsEndpoint/ConfigurationProvider.php
  124. +1 −1 lib/mcloud-aws/aws-sdk-php/src/EndpointDiscovery/ConfigurationProvider.php
  125. +1 −1 lib/mcloud-aws/aws-sdk-php/src/Retry/ConfigurationProvider.php
  126. +1 −1 lib/mcloud-aws/aws-sdk-php/src/S3/RegionalEndpoint/ConfigurationProvider.php
  127. +1 −1 lib/mcloud-aws/aws-sdk-php/src/S3/UseArnRegion/ConfigurationProvider.php
  128. +1 −1 lib/mcloud-aws/aws-sdk-php/src/Sts/RegionalEndpoints/ConfigurationProvider.php
  129. +1 −1 lib/mcloud-guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php
  130. +9 −3 lib/mcloud-illuminate/support/Collection.php
  131. +2 −1 lib/mcloud-illuminate/support/Traits/EnumeratesValues.php
  132. +4 −0 lib/mcloud-illuminate/support/helpers.php
  133. +2 −1 lib/mcloud-imgix/imgix-php/src/MediaCloud/Vendor/Imgix/UrlBuilder.php
  134. +115 −0 lib/mcloud-kraken-io/kraken-php/lib/MediaCloud/Vendor/Kraken.php
  135. +3,893 −0 lib/mcloud-kraken-io/kraken-php/lib/MediaCloud/Vendor/cacert.pem
  136. +5 −1 lib/mcloud-muxinc/mux-php/MuxPhp/Models/Asset.php
  137. +4 −0 lib/mcloud-muxinc/mux-php/MuxPhp/Models/AssetResponse.php
  138. +4 −0 lib/mcloud-muxinc/mux-php/MuxPhp/Models/CreateAssetRequest.php
  139. +4 −0 lib/mcloud-muxinc/mux-php/MuxPhp/Models/InputSettings.php
  140. +5 −1 lib/mcloud-muxinc/mux-php/MuxPhp/Models/PlaybackID.php
  141. +4 −2 lib/mcloud-nesbot/carbon/src/Carbon/Traits/Creator.php
  142. +117 −0 public/img/wizard-icon-bunnycdn.svg
  143. +102 −8 readme.txt
  144. +19 −1 vendor/autoload.php
  145. +28 −15 vendor/composer/ClassLoader.php
  146. +32 −10 vendor/composer/InstalledVersions.php
  147. +1 −1 vendor/composer/autoload_classmap.php
  148. +1 −1 vendor/composer/autoload_files.php
  149. +1 −1 vendor/composer/autoload_namespaces.php
  150. +1 −1 vendor/composer/autoload_psr4.php
  151. +15 −40 vendor/composer/autoload_real.php
  152. +4 −4 vendor/composer/autoload_static.php
  153. +7 −7 vendor/composer/installed.php
  154. +2 −2 vendor/composer/platform_check.php
  155. +1 −1 views/imgix/ilab-imgix-ui.blade.php
  156. +1 −1 views/storage/storage-browser.blade.php
  157. +1 −1 views/tasks/batch/buddypress-migrate.blade.php
  158. +1 −1 views/tasks/batch/clear-glide-cache.blade.php
  159. +9 −0 views/tasks/batch/generate-ewww-webp.blade.php
  160. +6 −0 views/tasks/batch/gravity-forms-migrate.blade.php
  161. +1 −1 views/tasks/batch/import-task.blade.php
  162. +9 −0 views/tasks/batch/instructions/generate-ewww-webp.blade.php
  163. +5 −0 views/tasks/batch/instructions/gravity-forms-migrate.blade.php
  164. +5 −0 views/tasks/batch/instructions/migrate-elementor-forms.blade.php
  165. +5 −0 views/tasks/batch/instructions/wp-forms-migrate.blade.php
  166. +6 −0 views/tasks/batch/migrate-elementor-forms.blade.php
  167. +1 −1 views/tasks/batch/migrate-task.blade.php
  168. +1 −1 views/tasks/batch/process-vision.blade.php
  169. +1 −1 views/tasks/batch/regenerate-filmstrip-task.blade.php
  170. +1 −1 views/tasks/batch/regenerate-thumbs-task.blade.php
  171. +1 −1 views/tasks/batch/unlink-media-task.blade.php
  172. +1 −1 views/tasks/batch/update-elementor.blade.php
  173. +1 −1 views/tasks/batch/update-image-privacy.blade.php
  174. +1 −1 views/tasks/batch/update-web-stories.blade.php
  175. +1 −1 views/tasks/batch/verify-library.blade.php
  176. +6 −0 views/tasks/batch/wp-forms-migrate.blade.php
  177. +1 −0 views/wizard/cloud-storage/providers/bunnycdn/description.blade.php
  178. +1 −0 views/wizard/cloud-storage/providers/bunnycdn/form.blade.php
  179. +3 −0 views/wizard/cloud-storage/providers/bunnycdn/intro.blade.php
  180. +2 −0 views/wizard/cloud-storage/providers/bunnycdn/success.blade.php
  181. +1 −0 views/wizard/cloud-storage/providers/bunnycdn/test.blade.php
  182. +16 −0 views/wizard/cloud-storage/providers/bunnycdn/tutorial/step-1.blade.php
  183. +12 −0 views/wizard/cloud-storage/providers/bunnycdn/tutorial/step-2.blade.php
6 changes: 3 additions & 3 deletions classes/Tools/Debugging/System/SystemCompatibilityTool.php
Original file line number Diff line number Diff line change
@@ -482,7 +482,7 @@ private function testUploadClient() {
$errors = [];

try {
$url = $storageTool->client()->upload('_troubleshooter/sample.txt',ILAB_TOOLS_DIR.'/public/text/sample-upload.txt', StorageToolSettings::privacy());
$url = $storageTool->client()->upload(StorageToolSettings::prefix() . '_troubleshooter/sample.txt',ILAB_TOOLS_DIR.'/public/text/sample-upload.txt', StorageToolSettings::privacy());
Tracker::trackView("System Test - Test Uploads - Success", "/system-test/uploads/success");
} catch (\Exception $ex) {
Tracker::trackView("System Test - Test Uploads - Error", "/system-test/uploads/error");
@@ -519,7 +519,7 @@ private function testPubliclyAccessible() {

try {
$result = null;
$url = $storageTool->client()->url('_troubleshooter/sample.txt');
$url = $storageTool->client()->url(StorageToolSettings::prefix() . '_troubleshooter/sample.txt');

$result = ilab_file_get_contents($url);

@@ -567,7 +567,7 @@ private function testDeletingFiles() {
$errors = [];

try {
$storageTool->client()->delete('_troubleshooter/sample.txt');
$storageTool->client()->delete(StorageToolSettings::prefix() . '_troubleshooter/sample.txt');
Tracker::trackView("System Test - Deleting - Success", "/system-test/delete/success");
} catch (\Exception $ex) {
$errors[] = $ex->getMessage();
127 changes: 127 additions & 0 deletions classes/Tools/Storage/CLI/StorageCommands.php
Original file line number Diff line number Diff line change
@@ -25,9 +25,11 @@
use MediaCloud\Plugin\Tools\Integrations\PlugIns\Elementor\Tasks\UpdateElementorTask ;
use MediaCloud\Plugin\Tools\Integrations\PlugIns\NextGenGallery\Tasks\MigrateNextGenTask ;
use MediaCloud\Plugin\Tools\Storage\StorageTool ;
use MediaCloud\Plugin\Tools\Storage\Tasks\GenerateEwwwWebPTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\MigrateFromOtherTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\MigrateTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\RegenerateThumbnailTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\SyncLocalTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\UnlinkTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\UpdateURLsTask ;
use MediaCloud\Plugin\Tools\Storage\Tasks\VerifyLibraryTask ;
@@ -80,6 +82,9 @@ class StorageCommands extends Command
* [--skip-thumbnails]
* : Skips uploading thumbnails. Requires Imgix.
*
* [--ignore-errors]
* : Ignores errors when they happen
*
* [--verify]
* : Verifies the migration and generates a report with the details
*
@@ -674,6 +679,69 @@ public function verify( $args, $assoc_args )
$this->runTask( $task, $options );
}

/**
* Syncs all files on cloud storage back to your local server. Note that this does not remove the cloud metadata, you must run `unlink` after if you want to do that.
*
* ## OPTIONS
*
* [--limit=<number>]
* : The maximum number of items to process, default is infinity.
*
* [--offset=<number>]
* : The starting offset to process. Cannot be used with page.
*
* [--page=<number>]
* : The starting offset to process. Page numbers start at 1. Cannot be used with offset.
*
* [--order-by=<string>]
* : The field to sort the items to be imported by. Valid values are 'date', 'title' and 'filename'.
* ---
* options:
* - date
* - title
* - filename
* ---
*
* [--order=<string>]
* : The sort order. Valid values are 'asc' and 'desc'.
* ---
* default: asc
* options:
* - asc
* - desc
* ---
*
* @when after_wp_load
*
* @param $args
* @param $assoc_args
*
* @throws \Exception
*/
public function syncAllLocal( $args, $assoc_args )
{
$options = $assoc_args;
if ( isset( $options['limit'] ) ) {

if ( isset( $options['page'] ) ) {
$options['offset'] = max( 0, ($assoc_args['page'] - 1) * $assoc_args['limit'] );
unset( $options['page'] );
}

}

if ( isset( $options['order-by'] ) ) {
$orderBy = $options['order-by'];
$dir = arrayPath( $options, 'order', 'asc' );
unset( $options['order-by'] );
unset( $options['order'] );
$options['sort-order'] = $orderBy . '-' . $dir;
}

$task = new SyncLocalTask();
$this->runTask( $task, $options );
}

/**
* Syncs cloud storage to the local file system
*
@@ -784,6 +852,53 @@ public function syncLocal( $args, $assoc_args )
$reporter->close();
}

/**
* Generates webp files for images on cloud storage.
*
* ## OPTIONS
*
* [--limit=<number>]
* : The maximum number of items to process, default is infinity.
*
* [--offset=<number>]
* : The starting offset to process. Cannot be used with page.
*
* [--page=<number>]
* : The starting offset to process. Page numbers start at 1. Cannot be used with offset.
*
* [--order-by=<string>]
* : The field to sort the items to be imported by. Valid values are 'date', 'title' and 'filename'.
* ---
* options:
* - date
* - title
* - filename
* ---
*
* [--order=<string>]
* : The sort order. Valid values are 'asc' and 'desc'.
* ---
* default: asc
* options:
* - asc
* - desc
* ---
*
* [--skip-processed]
* : Skips images that have already been processed.
*
* @when after_wp_load
*
* @param $args
* @param $assoc_args
*
* @throws \Exception
*/
public function makewebp( $args, $assoc_args )
{
self::Error( "Only available in the Premium version. To upgrade: https://mediacloud.press/pricing/" );
}

/**
* Replaces URLs in content with the cloud storage URL. This will only replace local URLs.
*
@@ -970,5 +1085,17 @@ public static function Register()
{
\WP_CLI::add_command( 'mediacloud:storage', __CLASS__ );
}

public static function Info( $string, $newline = false )
{
parent::Info( $string, $newline );
// TODO: Change the autogenerated stub
}

public static function Error( $string )
{
parent::Error( $string );
// TODO: Change the autogenerated stub
}

}
190 changes: 190 additions & 0 deletions classes/Tools/Storage/Driver/BunnyCDN/BunnyCDNClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<?php

namespace MediaCloud\Plugin\Tools\Storage\Driver\BunnyCDN;

use MediaCloud\Plugin\Tools\Storage\FileInfo;
use MediaCloud\Plugin\Tools\Storage\StorageException;
use MediaCloud\Plugin\Tools\Storage\StorageFile;
use MediaCloud\Plugin\Utilities\Logging\Logger;
use MediaCloud\Vendor\GuzzleHttp\Client;
use MediaCloud\Vendor\GuzzleHttp\RequestOptions;

class BunnyCDNClient {
protected $apiKey;
protected $storageZone;
protected $region;
protected $pullZone;

protected $client;

public function __construct($apiKey, $storageZone, $region, $pullZone) {
if (!function_exists('ftp_connect')) {
throw new StorageException("FTP Extension is required.");
}

$this->apiKey = $apiKey;
$this->storageZone = $storageZone;
$this->region = empty($region) ? '' : "{$region}.";
$this->pullZone = $pullZone;

$this->client = new Client();
}

public function upload($sourceFile, $destPath) {
$res = fopen($sourceFile, 'r');

$res = $this->client->put("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$destPath}", [
RequestOptions::HEADERS => [
'Content-Type' => 'application/octet-stream',
'AccessKey' => $this->apiKey
],
RequestOptions::BODY => $res
]);

$status = $res->getStatusCode();
return $status >= 200 && $status <= 299;
}

public function mkdir($path) {
if (!function_exists('ftp_connect')) {
return false;
}

$ftpId = ftp_connect("{$this->region}storage.bunnycdn.com");
$login = ftp_login($ftpId, $this->storageZone, $this->apiKey);
if (!$login) {
throw new StorageException("Invalid settings");
}

ftp_pasv($ftpId, true);
$result = ftp_mkdir($ftpId, $path);
ftp_close($ftpId);

return $result;
}

public function listFiles($path) {
$res = $this->client->get("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$path}/", [
RequestOptions::HEADERS => [
'AccessKey' => $this->apiKey
],
]);

$status = $res->getStatusCode();
if ($status >= 200 && $status <= 299) {
$listText = $res->getBody();
$list = json_decode($listText, true);

$files = [];
foreach($list as $file) {
if ($file['IsDirectory']) {
$key = ltrim(str_replace("/{$this->storageZone}/", "", $file['Path']) .'/'.$file['ObjectName'], '/');
$files[] = new StorageFile('DIR', $key);
} else {
$key = ltrim(str_replace("/{$this->storageZone}/", "", $file['Path']) .'/'.$file['ObjectName'], '/');
$files[] = new StorageFile('FILE', $key, null, $file['LastChanged'], $file['Length'], $this->pullZone.'/'.$key);
}

}

return $files;
}

return false;
}

public function deleteFile($file) {

$res = $this->client->delete("https://{$this->region}storage.bunnycdn.com/{$this->storageZone}/{$file}", [
RequestOptions::HEADERS => [
'AccessKey' => $this->apiKey
],
]);

$status = $res->getStatusCode();
return $status >= 200 && $status <= 299;
}

public function exists($file) {
if (!function_exists('ftp_connect')) {
return false;
}

$ftpId = ftp_connect("{$this->region}storage.bunnycdn.com");
$login = ftp_login($ftpId, $this->storageZone, $this->apiKey);
if (!$login) {
throw new StorageException("Invalid settings");
}

ftp_pasv($ftpId, true);
$result = ftp_size($ftpId, $file) >= 0;
ftp_close($ftpId);

return $result;
}

public function info($file) {
$url = "{$this->pullZone}/{$file}";
$res = $this->client->head($url);

$status = $res->getStatusCode();
if ($status >= 200 && $status <= 299) {
$headers = $res->getHeaders();
$size = !empty($headers['Content-Length']) ? $headers['Content-Length'][0] : 0;
$type = !empty($headers['Content-Type']) ? $headers['Content-Type'][0] : null;
return new FileInfo($file, $url, null, $size, $type, $size);
}

throw new StorageException("File does not exist.");
}

public function signUrl($token, $hostname, $path, $expirationTime, $isDirectory=false) {
$path = '/' . ltrim($path, '/');
$url = sprintf('%s%s', $hostname, $path);

$urlScheme = parse_url($url, PHP_URL_SCHEME);
$urlHost = parse_url($url, PHP_URL_HOST);
$urlPath = parse_url($url, PHP_URL_PATH);
$urlQuery = parse_url($url, PHP_URL_QUERY) ?? '';

$parameters = [];
parse_str($urlQuery, $parameters);

$signaturePath = $urlPath;
if ($isDirectory) {
$parameters['token_path'] = $signaturePath;
}

ksort($parameters);
$parameterData = '';
$parameterDataUrl = '';
if (sizeof($parameters) > 0) {
foreach ($parameters as $key => $value) {
if (strlen($parameterData) > 0) {
$parameterData .= '&';
}

$parameterDataUrl .= '&';
$parameterData .= sprintf('%s=%s', $key, $value);
$parameterDataUrl .= sprintf('%s=%s', $key, urlencode($value));
}
}

$expires = time() + $expirationTime;
$hashableBase = sprintf('%s%s%s', $token, $signaturePath, $expires);
$hashableBase .= $parameterData;

// Generate the token
$token = hash('sha256', $hashableBase, true);
$token = base64_encode($token);
$token = strtr($token, '+/', '-_');
$token = str_replace('=', '', $token);

if (true === $isDirectory) {
return sprintf('%s://%s/bcdn_token=%s&expires=%d%s%s', $urlScheme, $urlHost, $token, $expires, $parameterDataUrl, $urlPath);
}

return sprintf('%s://%s%s?token=%s%s&expires=%d', $urlScheme, $urlHost, $urlPath, $token, $parameterDataUrl, $expires);
}

}
Loading