| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | use Elementor\Plugin; |
| 7 | 7 | use Elementor\Core\Base\Module as BaseModule; |
| 8 | 8 | use Elementor\Modules\CloudKitLibrary\Connect\Cloud_Kits; |
| 9 | 9 | use Elementor\Core\Common\Modules\Connect\Module as ConnectModule; |
| 10 | -use Elementor\App\Modules\ImportExportCustomization\Module as ImportExportCustomization_Module; | |
| 10 | +use Elementor\App\Modules\ImportExport\Module as ImportExport_Module; | |
| 11 | 11 | use Elementor\App\Modules\KitLibrary\Connect\Kit_Library as Kit_Library_Api; |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | 14 | exit; // Exit if accessed directly. |
| @@ -26,19 +26,21 @@ | ||
| 26 | 26 | add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) { |
| 27 | 27 | $connect_module->register_app( 'cloud-kits', Cloud_Kits::get_class_name() ); |
| 28 | 28 | } ); |
| 29 | 29 | |
| 30 | - add_filter( 'elementor/export/kit/export-result', [ $this, 'handle_export_kit_result' ], 10, 6 ); | |
| 31 | - add_filter( 'elementor/import/kit/result/cloud', [ $this, 'handle_import_kit_from_cloud' ], 10, 1 ); | |
| 32 | - add_filter( 'elementor/import/kit_thumbnail', [ $this, 'handle_import_kit_thumbnail' ], 10, 3 ); | |
| 30 | + if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) { | |
| 31 | + add_filter( 'elementor/export/kit/export-result', [ $this, 'handle_export_kit_result' ], 10, 5 ); | |
| 32 | + add_filter( 'elementor/import/kit/result/cloud', [ $this, 'handle_import_kit_from_cloud' ], 10, 1 ); | |
| 33 | + add_filter( 'elementor/import/kit_thumbnail', [ $this, 'handle_import_kit_thumbnail' ], 10, 3 ); | |
| 33 | 34 | |
| 34 | - add_action( 'elementor/kit_library/registered', function () { | |
| 35 | - Plugin::$instance->data_manager_v2->register_controller( new Cloud_Kits_Controller() ); | |
| 36 | - } ); | |
| 35 | + add_action( 'elementor/kit_library/registered', function () { | |
| 36 | + Plugin::$instance->data_manager_v2->register_controller( new Cloud_Kits_Controller() ); | |
| 37 | + } ); | |
| 38 | + } | |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | public function handle_import_kit_thumbnail( $thumbnail, $kit_id, $referrer ) { |
| 40 | - if ( ImportExportCustomization_Module::REFERRER_KIT_LIBRARY === $referrer ) { | |
| 42 | + if ( ImportExport_Module::REFERRER_KIT_LIBRARY === $referrer ) { | |
| 41 | 43 | |
| 42 | 44 | if ( empty( $kit_id ) ) { |
| 43 | 45 | return ''; |
| 44 | 46 | } |
| @@ -52,9 +54,9 @@ | ||
| 52 | 54 | |
| 53 | 55 | return $kit->thumbnail; |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | - if ( ImportExportCustomization_Module::REFERRER_CLOUD === $referrer ) { | |
| 58 | + if ( ImportExport_Module::REFERRER_CLOUD === $referrer ) { | |
| 57 | 59 | if ( empty( $kit_id ) ) { |
| 58 | 60 | return ''; |
| 59 | 61 | } |
| 60 | 62 | |
| @@ -69,10 +71,10 @@ | ||
| 69 | 71 | |
| 70 | 72 | return $thumbnail; |
| 71 | 73 | } |
| 72 | 74 | |
| 73 | - public function handle_export_kit_result( $result, $source, $export, $settings, $file, $file_size ) { | |
| 74 | - if ( ImportExportCustomization_Module::EXPORT_SOURCE_CLOUD !== $source ) { | |
| 75 | + public function handle_export_kit_result( $result, $source, $export, $settings, $file ) { | |
| 76 | + if ( ImportExport_Module::EXPORT_SOURCE_CLOUD !== $source ) { | |
| 75 | 77 | return $result; |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | unset( $result['file'] ); |
| @@ -86,10 +88,8 @@ | ||
| 86 | 88 | $description, |
| 87 | 89 | $file, |
| 88 | 90 | $raw_screen_shot, |
| 89 | 91 | $settings['include'], |
| 90 | - $settings['customization']['content']['mediaFormat'] ?? 'link', | |
| 91 | - $file_size, | |
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | 94 | if ( is_wp_error( $kit ) ) { |
| 95 | 95 | return $kit; |
| @@ -105,46 +105,37 @@ | ||
| 105 | 105 | 'id' => $args['kit_id'], |
| 106 | 106 | ] ); |
| 107 | 107 | |
| 108 | 108 | if ( is_wp_error( $kit ) ) { |
| 109 | - throw new \Error( ImportExportCustomization_Module::CLOUD_KIT_LIBRARY_ERROR_LOADING_RESOURCE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 109 | + return $kit; | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | if ( empty( $kit['downloadUrl'] ) ) { |
| 113 | - throw new \Error( ImportExportCustomization_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 113 | + throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $data = [ | |
| 116 | + return [ | |
| 117 | 117 | 'file_name' => self::get_remote_kit_zip( $kit['downloadUrl'] ), |
| 118 | - 'referrer' => ImportExportCustomization_Module::REFERRER_CLOUD, | |
| 118 | + 'referrer' => ImportExport_Module::REFERRER_CLOUD, | |
| 119 | 119 | 'file_url' => $kit['downloadUrl'], |
| 120 | 120 | 'kit' => $kit, |
| 121 | 121 | ]; |
| 122 | - | |
| 123 | - if ( ! empty( $kit['mediaDownloadUrl'] ) ) { | |
| 124 | - $media_zip = self::get_remote_kit_zip( $kit['mediaDownloadUrl'], 'media.zip' ); | |
| 125 | - $data['media_file_name'] = $media_zip; | |
| 126 | - } | |
| 127 | - | |
| 128 | - return $data; | |
| 129 | 122 | } |
| 130 | 123 | |
| 131 | - public static function get_remote_kit_zip( $url, $file_name = 'kit.zip' ) { | |
| 132 | - $remote_zip_request = wp_safe_remote_get( $url, [ | |
| 133 | - 'timeout' => 300, | |
| 134 | - ] ); | |
| 124 | + public static function get_remote_kit_zip( $url ) { | |
| 125 | + $remote_zip_request = wp_safe_remote_get( $url ); | |
| 135 | 126 | |
| 136 | 127 | if ( is_wp_error( $remote_zip_request ) ) { |
| 137 | 128 | Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() ); |
| 138 | - throw new \Error( ImportExportCustomization_Module::CLOUD_KIT_LIBRARY_ERROR_LOADING_RESOURCE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 129 | + throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 139 | 130 | } |
| 140 | 131 | |
| 141 | 132 | if ( 200 !== $remote_zip_request['response']['code'] ) { |
| 142 | 133 | Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] ); |
| 143 | - throw new \Error( ImportExportCustomization_Module::CLOUD_KIT_LIBRARY_ERROR_LOADING_RESOURCE ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 134 | + throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 144 | 135 | } |
| 145 | 136 | |
| 146 | - return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], $file_name ); | |
| 137 | + return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); | |
| 147 | 138 | } |
| 148 | 139 | |
| 149 | 140 | public static function get_app(): Cloud_Kits { |
| 150 | 141 | $cloud_kits_app = Plugin::$instance->common->get_component( 'connect' )->get_app( 'cloud-kits' ); |