PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / app / modules / import-export-customization / data / routes / process-media.php

process-media.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at app/modules/import-export-customization/data/routes/process-media.php

110 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\App\Modules\ImportExportCustomization\Data\Routes;
3
4 use Elementor\Plugin;
5 use Elementor\App\Modules\ImportExportCustomization\Data\Response;
6 use Elementor\App\Modules\ImportExportCustomization\Module as ImportExportCustomizationModule;
7 use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary;
8 use Elementor\Utils as ElementorUtils;
9 use Elementor\App\Modules\ImportExportCustomization\Data\Routes\Traits\Handles_Quota_Errors;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly.
13 }
14
15 class Process_Media extends Base_Route {
16 use Handles_Quota_Errors;
17
18 protected function get_route(): string {
19 return 'process-media';
20 }
21
22 protected function get_method(): string {
23 return \WP_REST_Server::CREATABLE;
24 }
25
26 protected function callback( $request ): \WP_REST_Response {
27 /**
28 * @var $module ImportExportCustomizationModule
29 */
30 $module = Plugin::$instance->app->get_component( 'import-export-customization' );
31
32 $cloud_kit_library_app = $this->get_cloud_kit_library_app();
33
34 if ( $cloud_kit_library_app && ! $cloud_kit_library_app->is_connected() ) {
35 return Response::error( ImportExportCustomizationModule::MEDIA_PROCESSING_ERROR, 'Cloud Library is not connected' );
36 }
37
38 $media_urls = $request->get_param( 'media_urls' );
39 $kit = $request->get_param( 'kit' );
40 $quota = null;
41
42 try {
43 if ( empty( $media_urls ) || ! is_array( $media_urls ) ) {
44 throw new \Error( 'Invalid media URLs provided' );
45 }
46
47 $media_collector = new \Elementor\TemplateLibrary\Classes\Media_Collector();
48 $zip_path = $media_collector->process_media_collection( $media_urls );
49
50 if ( $cloud_kit_library_app ) {
51 $quota = $cloud_kit_library_app->get_quota();
52 $cloud_kit_library_app->validate_storage_quota( filesize( $zip_path ), $quota );
53 }
54
55 if ( ! $zip_path ) {
56 throw new \Error( 'Failed to process media' );
57 }
58
59 $zip_file = ElementorUtils::file_get_contents( $zip_path );
60
61 $upload_success = false;
62 if ( $cloud_kit_library_app ) {
63 $upload_success = $cloud_kit_library_app->upload_content_file( $kit['mediaUploadUrl'], $zip_file );
64 $cloud_kit_library_app->update_kit( $kit['id'], [ 'mediaFileId' => $upload_success ? $kit['mediaFileId'] : null ] );
65 }
66
67 $media_collector->cleanup();
68
69 return Response::success( [
70 'success' => true,
71 'message' => 'Media processed and uploaded successfully',
72 ] );
73
74 } catch ( \Error |\Exception $e ) {
75 Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [
76 'meta' => [
77 'trace' => $e->getTraceAsString(),
78 ],
79 ] );
80
81 if ( $cloud_kit_library_app ) {
82 $cloud_kit_library_app->update_kit( $kit['id'], [ 'mediaFileId' => null ] );
83 }
84
85 if ( $module->is_third_party_class( $e->getTrace()[0]['class'] ) ) {
86 return Response::error( ImportExportCustomizationModule::THIRD_PARTY_ERROR, $e->getMessage() );
87 }
88
89 if ( $this->is_quota_error( $e->getMessage() ) ) {
90 return $this->get_quota_error_response( $quota, $kit );
91 }
92
93 return Response::error( ImportExportCustomizationModule::MEDIA_PROCESSING_ERROR, $e->getMessage() );
94 }
95 }
96
97 protected function get_args(): array {
98 return [
99 'media_urls' => [
100 'type' => 'array',
101 'description' => 'Array of media URLs to process',
102 'required' => true,
103 'items' => [
104 'type' => 'string',
105 ],
106 ],
107 ];
108 }
109 }
110