| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Hooks\Handlers; |
| 4 |
|
| 5 |
use FluentCart\App\App; |
| 6 |
use FluentCart\App\Helpers\Helper; |
| 7 |
use FluentCart\App\Modules\StorageDrivers\Local\Local; |
| 8 |
use FluentCart\App\Modules\StorageDrivers\S3\S3; |
| 9 |
use FluentCart\App\Vite; |
| 10 |
use FluentCart\Api\StorageDrivers; |
| 11 |
|
| 12 |
class GlobalStorageHandler |
| 13 |
{ |
| 14 |
public function register() |
| 15 |
{ |
| 16 |
add_action('fluentcart_loaded', [$this, 'init']); |
| 17 |
} |
| 18 |
|
| 19 |
public function init() |
| 20 |
{ |
| 21 |
add_action('init', function () { |
| 22 |
(new Local())->init(); |
| 23 |
(new S3())->init(); |
| 24 |
|
| 25 |
if (!App::isProActive()) { |
| 26 |
add_filter('fluent_cart/storage/get_global_storage_drivers', [$this, 'registerPromoR2Driver'], 20, 2); |
| 27 |
} |
| 28 |
|
| 29 |
//This hook will allow others to register their storage driver with ours |
| 30 |
do_action('fluent_cart/register_storage_drivers'); |
| 31 |
},9); |
| 32 |
|
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
public function getSettings($driver) |
| 37 |
{ |
| 38 |
$storageDrivers = new StorageDrivers(); |
| 39 |
return $storageDrivers->getSettings($driver); |
| 40 |
} |
| 41 |
|
| 42 |
public function getAll() |
| 43 |
{ |
| 44 |
$storageDrivers = new StorageDrivers(); |
| 45 |
return $storageDrivers->getAll(); |
| 46 |
} |
| 47 |
|
| 48 |
public function getStatus($driver) |
| 49 |
{ |
| 50 |
$storageDrivers = new StorageDrivers(); |
| 51 |
return $storageDrivers->getStatus($driver); |
| 52 |
} |
| 53 |
|
| 54 |
public function getAllActive() |
| 55 |
{ |
| 56 |
$storageDrivers = new StorageDrivers(); |
| 57 |
return $storageDrivers->getActive(); |
| 58 |
} |
| 59 |
|
| 60 |
public function registerPromoR2Driver($drivers, $args) |
| 61 |
{ |
| 62 |
if (isset($drivers['r2'])) { |
| 63 |
return $drivers; |
| 64 |
} |
| 65 |
|
| 66 |
$drivers['r2'] = [ |
| 67 |
'title' => __('Cloudflare R2', 'fluent-cart'), |
| 68 |
'route' => '', |
| 69 |
'description' => __('Store downloadable product files in Cloudflare R2. Available in FluentCart Pro.', 'fluent-cart'), |
| 70 |
'logo' => $this->getPromoR2Logo(), |
| 71 |
'dark_logo' => $this->getPromoR2DarkLogo(), |
| 72 |
'status' => false, |
| 73 |
'brand_color' => '#f38020', |
| 74 |
'has_bucket' => true, |
| 75 |
'requires_pro' => true, |
| 76 |
'upgrade_url' => Helper::getUpgradeUrl('feature_lock_storage_r2'), |
| 77 |
'instance' => new class { |
| 78 |
public function isEnabled() |
| 79 |
{ |
| 80 |
return false; |
| 81 |
} |
| 82 |
} |
| 83 |
]; |
| 84 |
|
| 85 |
return $drivers; |
| 86 |
} |
| 87 |
|
| 88 |
public function getPromoR2Logo() |
| 89 |
{ |
| 90 |
return Vite::getAssetUrl('images/storage-drivers/r2.svg'); |
| 91 |
} |
| 92 |
|
| 93 |
public function getPromoR2DarkLogo() |
| 94 |
{ |
| 95 |
return Vite::getAssetUrl('images/storage-drivers/r2.svg'); |
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|