PluginProbe
Elementor Website Builder – more than just a page builder / 3.33.0-beta1
Elementor Website Builder – more than just a page builder v3.33.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 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 All 457 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 3.33.0-beta1, at app/modules/import-export-customization/data/routes/process-media.php

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