PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev3
Elementor Website Builder – more than just a page builder v3.32.0-dev3
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
← All changes | modules/cloud-kit-library/connect/cloud-kits.php +13 -61 4.3.0-beta33.32.0-dev3 View file →
@@ -10,15 +10,10 @@
10 10
11 11 class Cloud_Kits extends Library {
12 12 const THRESHOLD_UNLIMITED = -1;
13 13 const FAILED_TO_FETCH_QUOTA_KEY = 'failed-to-fetch-quota';
14 -
15 - const FAILED_TO_UPLOAD_KIT = 'cloud-upload-failed';
16 -
17 14 const INSUFFICIENT_QUOTA_KEY = 'insufficient-quota';
18 15
19 - const INSUFFICIENT_STORAGE_QUOTA = 'insufficient-storage-quota';
20 -
21 16 public function get_title() {
22 17 return esc_html__( 'Cloud Kits', 'elementor' );
23 18 }
24 19
@@ -38,19 +33,16 @@
38 33 /**
39 34 * @return array|\WP_Error
40 35 */
41 36 public function get_quota() {
42 - if ( ! $this->is_connected() ) {
43 - return new \WP_Error( 'not_connected', esc_html__( 'Not connected', 'elementor' ) );
44 - }
45 -
46 37 return $this->http_request( 'GET', 'quota/kits', [], [
47 38 'return_type' => static::HTTP_RETURN_TYPE_ARRAY,
48 - 'with_error_data' => true,
49 39 ] );
50 40 }
51 41
52 - public function validate_quota( $quota ) {
42 + public function validate_quota() {
43 + $quota = $this->get_quota();
44 +
53 45 if ( is_wp_error( $quota ) ) {
54 46 throw new \Error( static::FAILED_TO_FETCH_QUOTA_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
55 47 }
56 48
@@ -61,24 +53,8 @@
61 53 throw new \Error( static::INSUFFICIENT_QUOTA_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
62 54 }
63 55 }
64 56
65 - public function validate_storage_quota( $intended_usage, $quota ) {
66 - if ( is_wp_error( $quota ) ) {
67 - throw new \Error( static::FAILED_TO_FETCH_QUOTA_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
68 - }
69 -
70 - if ( empty( $quota['storage']['currentUsage'] ) ) {
71 - return;
72 - }
73 -
74 - $has_quota = $quota['storage']['currentUsage'] + $intended_usage < $quota['storage']['threshold'];
75 -
76 - if ( ! $has_quota ) {
77 - throw new \Error( static::INSUFFICIENT_STORAGE_QUOTA ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
78 - }
79 - }
80 -
81 57 public function check_eligibility() {
82 58 $quota = $this->get_quota();
83 59
84 60 if ( is_wp_error( $quota ) ) {
@@ -93,12 +69,10 @@
93 69 'subscription_id' => ! empty( $quota['subscriptionId'] ) ? $quota['subscriptionId'] : '',
94 70 ];
95 71 }
96 72
97 - public function create_kit( $title, $description, $content_file_data, $preview_file_data, array $includes, string $media_format = 'link', $file_size = 0 ) {
98 - $quota = $this->get_quota();
99 - $this->validate_quota( $quota );
100 - $this->validate_storage_quota( $file_size, $quota );
73 + public function create_kit( $title, $description, $content_file_data, $preview_file_data, array $includes ) {
74 + $this->validate_quota();
101 75
102 76 $endpoint = 'kits';
103 77
104 78 $boundary = wp_generate_password( 24, false );
@@ -111,9 +85,8 @@
111 85 [
112 86 'title' => $title,
113 87 'description' => $description,
114 88 'includes' => wp_json_encode( $includes ),
115 - 'mediaFormat' => $media_format,
116 89 ],
117 90 [
118 91 'previewFile' => [
119 92 'filename' => 'preview.png',
@@ -133,15 +106,17 @@
133 106 $response = $this->http_request( 'POST', $endpoint, $payload, [
134 107 'return_type' => static::HTTP_RETURN_TYPE_ARRAY,
135 108 ] );
136 109
137 - if ( is_wp_error( $response ) || empty( $response['id'] ) ) {
138 - throw new \Exception( static::FAILED_TO_UPLOAD_KIT, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
110 + if ( empty( $response['id'] ) ) {
111 + $error_message = esc_html__( 'Failed to create kit: Invalid response', 'elementor' );
112 + throw new \Exception( $error_message, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
139 113 }
140 114
141 115 if ( empty( $response['uploadUrl'] ) ) {
142 116 $this->delete_kit( $response['id'] );
143 - throw new \Exception( static::FAILED_TO_UPLOAD_KIT, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
117 + $error_message = esc_html__( 'Failed to create kit: No upload URL provided', 'elementor' );
118 + throw new \Exception( $error_message, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
144 119 }
145 120
146 121 $upload_success = $this->upload_content_file( $response['uploadUrl'], $content_file_data );
147 122
@@ -146,15 +121,16 @@
146 121 $upload_success = $this->upload_content_file( $response['uploadUrl'], $content_file_data );
147 122
148 123 if ( ! $upload_success ) {
149 124 $this->delete_kit( $response['id'] );
150 - throw new \Exception( static::FAILED_TO_UPLOAD_KIT, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
125 + $error_message = esc_html__( 'Failed to create kit: Content upload failed', 'elementor' );
126 + throw new \Exception( $error_message, Exceptions::INTERNAL_SERVER_ERROR ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
151 127 }
152 128
153 129 return $response;
154 130 }
155 131
156 - public function upload_content_file( $upload_url, $content_file_data ) {
132 + private function upload_content_file( $upload_url, $content_file_data ) {
157 133 $upload_response = wp_remote_request( $upload_url, [
158 134 'method' => 'PUT',
159 135 'body' => $content_file_data,
160 136 'headers' => [
@@ -212,32 +188,8 @@
212 188
213 189 $body .= "--{$boundary}--{$eol}";
214 190
215 191 return $body;
216 - }
217 -
218 - public function update_kit( $id, array $kit_data ) {
219 - $endpoint = 'kits/' . $id;
220 -
221 - $request = $this->http_request(
222 - 'PATCH',
223 - $endpoint,
224 - [
225 - 'body' => wp_json_encode( $kit_data ),
226 - 'headers' => [
227 - 'Content-Type' => 'application/json',
228 - ],
229 - ],
230 - [
231 - 'return_type' => static::HTTP_RETURN_TYPE_ARRAY,
232 - ],
233 - );
234 -
235 - if ( is_wp_error( $request ) ) {
236 - return false;
237 - }
238 -
239 - return true;
240 192 }
241 193
242 194 protected function init() {}
243 195 }