PluginProbe
Elementor Website Builder – more than just a page builder / 3.35.7
Elementor Website Builder – more than just a page builder v3.35.7
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 4.0.7 All 451 releases
← All changes | modules/interactions/validation.php +28 -114 4.3.0-beta13.35.7 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\Interactions;
4 4
5 -use Elementor\Modules\Interactions\Validators\Breakpoints_Value as BreakpointsValueValidator;
6 -use Elementor\Modules\Interactions\Validators\Custom_Effect_Value;
7 -use Elementor\Modules\Interactions\Validators\String_Value as StringValueValidator;
8 -use Elementor\Modules\Interactions\Validators\Trigger_Value as TriggerValueValidator;
9 -
10 5 if ( ! defined( 'ABSPATH' ) ) {
11 6 exit; // Exit if accessed directly.
12 7 }
13 8
@@ -14,12 +9,12 @@
14 9 class Validation {
15 10 private $elements_to_interactions_counter = [];
16 11 private $max_number_of_interactions = 5;
17 12
18 - private const VALID_EFFECTS = [ 'fade', 'slide', 'scale', 'custom' ];
13 + private const VALID_TRIGGERS = [ 'load', 'scrollIn', 'scrollOut', 'scrollOn' ];
14 + private const VALID_EFFECTS = [ 'fade', 'slide', 'scale' ];
19 15 private const VALID_TYPES = [ 'in', 'out' ];
20 - private const VALID_DIRECTIONS = [ '', 'left', 'right', 'top', 'bottom', 'top-left', 'top-right', 'bottom-left', 'bottom-right' ];
21 - private const VALID_REPEAT_MODES = [ '', 'loop', 'times' ];
16 + private const VALID_DIRECTIONS = [ '', 'left', 'right', 'top', 'bottom' ];
22 17
23 18 public function sanitize( $document ) {
24 19 return $this->sanitize_document_data( $document );
25 20 }
@@ -68,11 +63,8 @@
68 63 }
69 64
70 65 private function decode_interactions( $interactions ) {
71 66 if ( is_array( $interactions ) ) {
72 - if ( isset( $interactions['items']['$$type'] ) && 'array' === $interactions['items']['$$type'] ) {
73 - return isset( $interactions['items']['value'] ) ? $interactions['items']['value'] : [];
74 - }
75 67 return isset( $interactions['items'] ) ? $interactions['items'] : [];
76 68 }
77 69
78 70 if ( is_string( $interactions ) ) {
@@ -77,11 +69,8 @@
77 69
78 70 if ( is_string( $interactions ) ) {
79 71 $decoded = json_decode( $interactions, true );
80 72 if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded ) ) {
81 - if ( isset( $decoded['items']['$$type'] ) && 'array' === $decoded['items']['$$type'] ) {
82 - return isset( $decoded['items']['value'] ) ? $decoded['items']['value'] : [];
83 - }
84 73 return isset( $decoded['items'] ) ? $decoded['items'] : [];
85 74 }
86 75 }
87 76
@@ -140,9 +129,9 @@
140 129 if ( isset( $value['interaction_id'] ) && ! $this->is_valid_string_prop( $value, 'interaction_id' ) ) {
141 130 return false;
142 131 }
143 132
144 - if ( ! $this->is_valid_trigger_prop( $value ) ) {
133 + if ( ! $this->is_valid_string_prop( $value, 'trigger', self::VALID_TRIGGERS ) ) {
145 134 return false;
146 135 }
147 136
148 137 if ( ! $this->is_valid_animation_prop( $value ) ) {
@@ -148,37 +137,31 @@
148 137 if ( ! $this->is_valid_animation_prop( $value ) ) {
149 138 return false;
150 139 }
151 140
152 - if ( ! $this->is_valid_breakpoints_prop( $value ) ) {
153 - return false;
154 - }
155 -
156 141 return true;
157 142 }
158 143
159 - private function is_valid_trigger_prop( $data ) {
160 - if ( ! array_key_exists( 'trigger', $data ) ) {
144 + private function is_valid_string_prop( $data, $key, $allowed_values = null ) {
145 + if ( ! isset( $data[ $key ] ) || ! is_array( $data[ $key ] ) ) {
161 146 return false;
162 147 }
163 148
164 - return TriggerValueValidator::is_valid( $data['trigger'] );
165 - }
149 + $prop = $data[ $key ];
166 150
167 - private function is_valid_breakpoints_prop( $data ) {
168 - if ( array_key_exists( 'breakpoints', $data ) ) {
169 - return BreakpointsValueValidator::is_valid( $data['breakpoints'] );
151 + if ( ! isset( $prop['$$type'] ) || 'string' !== $prop['$$type'] ) {
152 + return false;
170 153 }
171 154
172 - return true;
173 - }
155 + if ( ! isset( $prop['value'] ) || ! is_string( $prop['value'] ) ) {
156 + return false;
157 + }
174 158
175 - private function is_valid_string_prop( $data, $key, $allowed_values = null ) {
176 - if ( ! isset( $data[ $key ] ) ) {
159 + if ( null !== $allowed_values && ! in_array( $prop['value'], $allowed_values, true ) ) {
177 160 return false;
178 161 }
179 162
180 - return StringValueValidator::is_valid( $data[ $key ], $allowed_values );
163 + return true;
181 164 }
182 165
183 166 private function is_valid_boolean_prop( $data, $key ) {
184 167 if ( ! isset( $data[ $key ] ) || ! is_array( $data[ $key ] ) ) {
@@ -238,35 +221,33 @@
238 221 if ( ! isset( $data['config'] ) || ! is_array( $data['config'] ) ) {
239 222 return false;
240 223 }
241 224
242 - $config_value = $data['config']['value'];
225 + $config = $data['config'];
243 226
244 - if ( isset( $config_value['replay'] ) && ! $this->is_valid_boolean_prop( $config_value, 'replay' ) ) {
227 + if ( ! isset( $config['$$type'] ) || 'config' !== $config['$$type'] ) {
245 228 return false;
246 229 }
247 230
248 - if ( isset( $config_value['easing'] ) && ! $this->is_valid_string_prop( $config_value, 'easing' ) ) {
231 + if ( ! isset( $config['value'] ) || ! is_array( $config['value'] ) ) {
249 232 return false;
250 233 }
251 234
252 - if ( isset( $config_value['relativeTo'] ) && ! $this->is_valid_string_prop( $config_value, 'relativeTo' ) ) {
253 - return false;
254 - }
235 + $config_value = $config['value'];
255 236
256 - if ( isset( $config_value['repeat'] ) && ! $this->is_valid_string_prop( $config_value, 'repeat', self::VALID_REPEAT_MODES ) ) {
237 + if ( isset( $config_value['replay'] ) && ! $this->is_valid_boolean_prop( $config_value, 'replay' ) ) {
257 238 return false;
258 239 }
259 240
260 - if ( isset( $config_value['times'] ) && ! $this->is_valid_number_prop_in_range( $config_value, 'times', 1 ) ) {
241 + if ( isset( $config_value['relativeTo'] ) && ! $this->is_valid_string_prop( $config_value, 'relativeTo' ) ) {
261 242 return false;
262 243 }
263 244
264 - if ( isset( $config_value['start'] ) && ! $this->is_valid_size_prop_in_range( $config_value, 'start', 0, 100 ) ) {
245 + if ( isset( $config_value['offsetTop'] ) && ! $this->is_valid_number_prop_in_range( $config_value, 'offsetTop', 0, 100 ) ) {
265 246 return false;
266 247 }
267 248
268 - if ( isset( $config_value['end'] ) && ! $this->is_valid_size_prop_in_range( $config_value, 'end', 0, 100 ) ) {
249 + if ( isset( $config_value['offsetBottom'] ) && ! $this->is_valid_number_prop_in_range( $config_value, 'offsetBottom', 0, 100 ) ) {
269 250 return false;
270 251 }
271 252
272 253 return true;
@@ -298,9 +279,10 @@
298 279 if ( ! $this->is_valid_string_prop( $animation_value, 'type', self::VALID_TYPES ) ) {
299 280 return false;
300 281 }
301 282
302 - if ( array_key_exists( 'direction', $animation_value ) && ! $this->is_valid_string_prop( $animation_value, 'direction', self::VALID_DIRECTIONS ) ) {
283 + // Validate direction (can be empty string)
284 + if ( ! $this->is_valid_string_prop( $animation_value, 'direction', self::VALID_DIRECTIONS ) ) {
303 285 return false;
304 286 }
305 287
306 288 // Validate timing_config
@@ -311,12 +293,8 @@
311 293 if ( isset( $animation_value['config'] ) && ! $this->is_valid_config_prop( $animation_value ) ) {
312 294 return false;
313 295 }
314 296
315 - if ( ! Custom_Effect_Value::is_valid( $animation_value ) ) {
316 - return false;
317 - }
318 -
319 297 return true;
320 298 }
321 299
322 300 private function is_valid_timing_config( $data ) {
@@ -335,79 +313,15 @@
335 313 }
336 314
337 315 $timing_value = $timing['value'];
338 316
339 - // Validate duration (accepts both 'number' and 'size' formats)
340 - if ( ! $this->is_valid_timing_value( $timing_value, 'duration', 0 ) ) {
317 + // Validate duration
318 + if ( ! $this->is_valid_number_prop( $timing_value, 'duration' ) ) {
341 319 return false;
342 320 }
343 321
344 - // Validate delay (accepts both 'number' and 'size' formats)
345 - if ( ! $this->is_valid_timing_value( $timing_value, 'delay', 0 ) ) {
346 - return false;
347 - }
348 -
349 - return true;
350 - }
351 -
352 - /**
353 - * Validate timing value that can be either 'number' or 'size' type.
354 - * - number format: {$$type: 'number', value: 123}
355 - * - size format: {$$type: 'size', value: {size: 123, unit: 'ms'}}
356 - */
357 - private function is_valid_timing_value( $data, $key, $min = null, $max = null ) {
358 - if ( ! isset( $data[ $key ] ) || ! is_array( $data[ $key ] ) ) {
359 - return false;
360 - }
361 -
362 - $prop = $data[ $key ];
363 -
364 - if ( ! isset( $prop['$$type'] ) ) {
365 - return false;
366 - }
367 -
368 - // Accept 'number' format
369 - if ( 'number' === $prop['$$type'] ) {
370 - return $this->is_valid_number_prop_in_range( $data, $key, $min, $max );
371 - }
372 -
373 - // Accept 'size' format
374 - if ( 'size' === $prop['$$type'] ) {
375 - return $this->is_valid_size_prop_in_range( $data, $key, $min, $max );
376 - }
377 -
378 - return false;
379 - }
380 -
381 - /**
382 - * Validate size prop: {$$type: 'size', value: {size: X, unit: 'ms'}}
383 - */
384 - private function is_valid_size_prop_in_range( $data, $key, $min = null, $max = null ) {
385 - if ( ! isset( $data[ $key ] ) || ! is_array( $data[ $key ] ) ) {
386 - return false;
387 - }
388 -
389 - $prop = $data[ $key ];
390 -
391 - if ( ! isset( $prop['$$type'] ) || 'size' !== $prop['$$type'] ) {
392 - return false;
393 - }
394 -
395 - if ( ! isset( $prop['value'] ) || ! is_array( $prop['value'] ) ) {
396 - return false;
397 - }
398 -
399 - if ( ! isset( $prop['value']['size'] ) || ! is_numeric( $prop['value']['size'] ) ) {
400 - return false;
401 - }
402 -
403 - $value = (float) $prop['value']['size'];
404 -
405 - if ( null !== $min && $value < $min ) {
406 - return false;
407 - }
408 -
409 - if ( null !== $max && $value > $max ) {
322 + // Validate delay
323 + if ( ! $this->is_valid_number_prop( $timing_value, 'delay' ) ) {
410 324 return false;
411 325 }
412 326
413 327 return true;