PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.13
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / FB / MetaMigrator.php

MetaMigrator.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.13, at Inc/Core/FB/MetaMigrator.php

706 lines 22.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\FB;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Handles migration of legacy meta data to new meta format
21 */
22 class MetaMigrator
23 {
24 /**
25 * Apply a transformation to meta data
26 *
27 * @param string $transformType The type of transformation to apply
28 * @param string $key The meta key being transformed
29 * @param array $new_meta Reference to the new meta data
30 * @param array $legacy_meta The legacy meta data
31 * @param array $defaults Default values
32 * @param bool $valueExistsInNewMeta Whether the value already exists in new meta
33 * @return void
34 */
35 public function applyTransform($transformType, $key, &$new_meta, $legacy_meta, $defaults, $valueExistsInNewMeta)
36 {
37 switch ($transformType)
38 {
39 case 'migrate_unitvalue':
40 $this->migrateUnitValue($key, $new_meta, $valueExistsInNewMeta);
41 break;
42 case 'border_migration':
43 $this->migrateBorder($key, $new_meta, $legacy_meta, $valueExistsInNewMeta);
44 break;
45 case 'borderradius_migration':
46 $this->migrateBorderRadius($key, $new_meta, $valueExistsInNewMeta);
47 break;
48 case 'dimension':
49 $this->migrateDimension($key, $new_meta);
50 break;
51 case 'box_auto_close_migration':
52 $this->migrateBoxAutoClose($key, $new_meta);
53 break;
54 case 'actions_migration':
55 $this->migrateActions($key, $new_meta);
56 break;
57 case 'rules_migration':
58 $this->migrateRules($key, $new_meta, $defaults);
59 break;
60 case 'animation_migration':
61 $this->migrateAnimation($key, $new_meta, $valueExistsInNewMeta);
62 break;
63 case 'shadow_migration':
64 $this->migrateShadow($key, $new_meta, $valueExistsInNewMeta);
65 break;
66 case 'floatingbutton_message_migration':
67 $this->migrateFloatingButtonMessage($key, $new_meta, $defaults, $valueExistsInNewMeta);
68 break;
69 case 'overlay_enabled_migration':
70 $this->migrateOverlayEnabled($key, $new_meta, $valueExistsInNewMeta);
71 break;
72 case 'overlayclick_migration':
73 $this->migrateOverlayClick($key, $new_meta, $valueExistsInNewMeta);
74 break;
75 case 'overlayblurradius_migration':
76 $this->migrateOverlayBlurRadius($key, $new_meta, $valueExistsInNewMeta);
77 break;
78 case 'triggermethod_migration':
79 $this->migrateTriggerMethod($key, $new_meta, $legacy_meta, $valueExistsInNewMeta);
80 break;
81 case 'scroll_depth_migration':
82 $this->migrateScrollDepth($key, $new_meta, $legacy_meta, $valueExistsInNewMeta);
83 break;
84 case 'firing_frequency_toggle_migration':
85 $this->migrateFiringFrequencyToggle($key, $new_meta, $valueExistsInNewMeta);
86 break;
87 }
88 }
89
90 /**
91 * Migrate unit values
92 *
93 * @param string $key
94 * @param array $new_meta
95 * @param bool $valueExistsInNewMeta
96 * @return void
97 */
98 public function migrateUnitValue($key, &$new_meta, $valueExistsInNewMeta)
99 {
100 if ($valueExistsInNewMeta)
101 {
102 return;
103 }
104
105 if (!isset($new_meta[$key]) || !is_array($new_meta[$key]))
106 {
107 return;
108 }
109
110 foreach ($new_meta[$key] as $subkey => &$subvalue)
111 {
112 if (!isset($subvalue['value']) && !isset($subvalue['unit']))
113 {
114 continue;
115 }
116
117 $value = isset($subvalue['value']) ? $subvalue['value'] : '';
118 if (!$value)
119 {
120 $subvalue = '';
121
122 // if empty height, set to auto
123 if ($key === 'height')
124 {
125 $subvalue = 'auto';
126 }
127 continue;
128 }
129
130 $unit = isset($subvalue['unit']) ? $subvalue['unit'] : '';
131 $subvalue = $value . $unit;
132 }
133 }
134
135 /**
136 * Migrate border settings
137 *
138 * @param string $key
139 * @param array $new_meta
140 * @param array $legacy_meta
141 * @param bool $valueExistsInNewMeta
142 * @return void
143 */
144 public function migrateBorder($key, &$new_meta, $legacy_meta, $valueExistsInNewMeta)
145 {
146 if ($valueExistsInNewMeta)
147 {
148 return;
149 }
150
151 if (!isset($legacy_meta['bordertype']) || $legacy_meta['bordertype'] === 'none')
152 {
153 return;
154 }
155
156 $borderStyle = isset($legacy_meta['bordertype']) ? $legacy_meta['bordertype'] : 'solid';
157 if (!in_array($borderStyle, ['solid', 'dashed', 'dotted']))
158 {
159 $borderStyle = 'solid';
160 }
161
162 $new_meta['border'] = [
163 'width' => isset($legacy_meta['borderwidth']['value']) ? rtrim($legacy_meta['borderwidth']['value'], 'px') . 'px' : '',
164 'style' => $borderStyle,
165 'color' => isset($legacy_meta['bordercolor']) ? $legacy_meta['bordercolor'] : ''
166 ];
167 }
168
169 /**
170 * Migrate border radius settings
171 *
172 * @param string $key
173 * @param array $new_meta
174 * @param bool $valueExistsInNewMeta
175 * @return void
176 */
177 public function migrateBorderRadius($key, &$new_meta, $valueExistsInNewMeta)
178 {
179 if ($valueExistsInNewMeta)
180 {
181 return;
182 }
183
184 if (!isset($new_meta[$key]) || !is_array($new_meta[$key]))
185 {
186 return;
187 }
188
189 foreach ($new_meta[$key] as $breakpoint => &$values)
190 {
191 $unit = isset($values['unit']) ? $values['unit'] : 'px';
192
193 $values = [
194 'topLeft' => isset($values['top_left']) ? $values['top_left'] . $unit : '',
195 'topRight' => isset($values['top_right']) ? $values['top_right'] . $unit : '',
196 'bottomLeft' => isset($values['bottom_left']) ? $values['bottom_left'] . $unit : '',
197 'bottomRight' => isset($values['bottom_right']) ? $values['bottom_right'] . $unit : ''
198 ];
199 }
200 }
201
202 /**
203 * Migrate dimension values
204 *
205 * @param string $key
206 * @param array $new_meta
207 * @return void
208 */
209 public function migrateDimension($key, &$new_meta)
210 {
211 if (!is_array($new_meta[$key]) || !count($new_meta[$key]))
212 {
213 return;
214 }
215
216 foreach ($new_meta[$key] as $breakpoint => &$values)
217 {
218 $unit = isset($values['unit']) ? $values['unit'] : '';
219
220 if (!is_array($values) || !count($values))
221 {
222 continue;
223 }
224
225 foreach ($values as $_prop => &$val)
226 {
227 if (in_array($_prop, ['top', 'right', 'bottom', 'left']))
228 {
229 if ($val)
230 {
231 $val = $val . $unit;
232 }
233 } else {
234 unset($values[$_prop]);
235 }
236 }
237 }
238 }
239
240 /**
241 * Migrate box auto close setting
242 *
243 * @param string $key
244 * @param array $new_meta
245 * @return void
246 */
247 public function migrateBoxAutoClose($key, &$new_meta)
248 {
249 if (!is_array($new_meta[$key]) || !count($new_meta[$key]))
250 {
251 return;
252 }
253
254 $new_meta[$key] = ($new_meta[$key][0] === 'yes');
255 }
256
257 /**
258 * Migrate actions settings
259 *
260 * @param string $key
261 * @param array $new_meta
262 * @return void
263 */
264 public function migrateActions($key, &$new_meta)
265 {
266 if (!is_array($new_meta[$key]) || !count($new_meta[$key]))
267 {
268 return;
269 }
270
271 $actions = array_values($new_meta[$key]);
272 foreach ($actions as &$action)
273 {
274 $action['enabled'] = isset($action['enabled']) && $action['enabled'] == '1';
275 }
276
277 $new_meta[$key] = $actions;
278 }
279
280 /**
281 * Migrate rules settings
282 *
283 * @param string $key
284 * @param array $new_meta
285 * @param array $defaults
286 * @return void
287 */
288 public function migrateRules($key, &$new_meta, $defaults)
289 {
290 $rules = is_string($new_meta[$key]) ? json_decode($new_meta[$key], true) : $new_meta[$key];
291
292 if (empty($rules))
293 {
294 // Set default rules if empty
295 $new_meta[$key] = $defaults['rules'];
296 return;
297 }
298
299 $rules = array_values($rules);
300 foreach ($rules as &$set)
301 {
302 $set['enabled'] = isset($set['enabled']) && $set['enabled'] == '1';
303
304 if (!isset($set['rules']) || !is_array($set['rules']) || !count($set['rules']))
305 {
306 continue;
307 }
308
309 foreach ($set['rules'] as &$rule)
310 {
311 $rule['enabled'] = isset($rule['enabled']) && $rule['enabled'] == '1';
312
313 // Fix name
314 if (isset($rule['name']))
315 {
316 $rule['name'] = str_replace('\\\\', '\\', $rule['name']);
317 }
318
319 // Fix "params.exclude_shipping_cost"
320 if (isset($rule['params']['exclude_shipping_cost']))
321 {
322 $rule['params']['exclude_shipping_cost'] = isset($rule['params']['exclude_shipping_cost']) && $rule['params']['exclude_shipping_cost'] == '1';
323 }
324
325 // Migrate value from array of objects to array of values
326 $migrateValueConditions = [
327 'IP',
328 'Referrer',
329 'URL',
330 'Geo\City',
331 'Geo\Region'
332 ];
333 if (isset($rule['name']) && in_array($rule['name'], $migrateValueConditions))
334 {
335 if (isset($rule['value']) && is_array($rule['value']))
336 {
337 $migratedValues = [];
338 foreach ($rule['value'] as $item)
339 {
340 $old_value = isset($item['value']) ? $item['value'] : '';
341
342 if (!$old_value)
343 {
344 continue;
345 }
346
347 $migratedValues[] = $old_value;
348 }
349 $rule['value'] = $migratedValues;
350 }
351 }
352
353 // Fix regex
354 if (isset($rule['name']) && $rule['name'] === 'URL')
355 {
356 $rule['params']['regex'] = isset($rule['params']['regex']) && $rule['params']['regex'] == '1';
357 }
358
359 // Fix quantity operators for WooCommerce Cart Contains Products rule
360 if (isset($rule['name']) && in_array($rule['name'], ['WooCommerce\CartContainsProducts']))
361 {
362 $value = isset($rule['value']) ? $rule['value'] : [];
363
364 if (is_array($value))
365 {
366 foreach ($value as &$item)
367 {
368 if (isset($item['quantity_operator']))
369 {
370 if ($item['quantity_operator'] === 'less_than_equals')
371 {
372 $item['quantity_operator'] = 'less_than_or_equal_to';
373 }
374 elseif ($item['quantity_operator'] === 'greater_than_equals')
375 {
376 $item['quantity_operator'] = 'greater_than_or_equal_to';
377 }
378 }
379 }
380 }
381
382 $rule['value'] = $value;
383 }
384 }
385 }
386
387 $new_meta[$key] = $rules;
388 }
389
390 /**
391 * Migrate animation settings
392 *
393 * @param string $key
394 * @param array $new_meta
395 * @param bool $valueExistsInNewMeta
396 * @return void
397 */
398 public function migrateAnimation($key, &$new_meta, $valueExistsInNewMeta)
399 {
400 if ($valueExistsInNewMeta)
401 {
402 return;
403 }
404
405 // Fade animations
406 $fade_animations = [
407 'transition.fadeIn' => 'fadeIn',
408 'transition.fadeOut' => 'fadeOut',
409 'transition.slideUpIn' => 'fadeInUp',
410 'transition.slideDownIn' => 'fadeInDown',
411 'transition.slideLeftIn' => 'fadeInLeft',
412 'transition.slideRightIn' => 'fadeInRight',
413 'transition.slideUpBigIn' => 'fadeInUpBig',
414 'transition.slideDownBigIn' => 'fadeInDownBig',
415 'transition.slideLeftBigIn' => 'fadeInLeftBig',
416 'transition.slideRightBigIn' => 'fadeInRightBig',
417 'transition.slideUpOut' => 'fadeOutUp',
418 'transition.slideDownOut' => 'fadeOutDown',
419 'transition.slideLeftOut' => 'fadeOutLeft',
420 'transition.slideRightOut' => 'fadeOutRight',
421 'transition.slideUpBigOut' => 'fadeOutUpBig',
422 'transition.slideDownBigOut' => 'fadeOutDownBig',
423 'transition.slideLeftBigOut' => 'fadeOutLeftBig',
424 'transition.slideRightBigOut' => 'fadeOutRightBig',
425 ];
426
427 // Slide animations
428 $slide_animations = [
429 'slideDown' => 'slideInDown',
430 'slideUp' => 'slideOutUp',
431 'firebox.slideUpIn' => 'slideInUp',
432 'firebox.slideDownIn' => 'slideInDown',
433 'firebox.slideLeftIn' => 'slideInLeft',
434 'firebox.slideRightIn' => 'slideInRight',
435 'firebox.slideUpOut' => 'fadeOutDown',
436 'firebox.slideDownOut' => 'slideOutUp',
437 'firebox.slideLeftOut' => 'slideOutLeft',
438 'firebox.slideRightOut' => 'slideOutRight',
439 'transition.perspectiveUpIn' => 'slideInUp',
440 'transition.perspectiveDownIn' => 'slideInDown',
441 'transition.perspectiveLeftIn' => 'slideInLeft',
442 'transition.perspectiveRightIn' => 'slideInRight',
443 'transition.perspectiveUpOut' => 'slideOutUp',
444 'transition.perspectiveDownOut' => 'slideOutDown',
445 'transition.perspectiveLeftOut' => 'slideOutLeft',
446 'transition.perspectiveRightOut' => 'slideOutRight',
447 ];
448
449 $animation_map = array_merge([
450 // Other animations
451 'callout.bounce' => 'bounce',
452 'callout.shake' => 'shakeX',
453 'callout.flash' => 'flash',
454 'callout.pulse' => 'pulse',
455 'callout.swing' => 'swing',
456 'callout.tada' => 'tada',
457 'transition.swoopIn' => 'zoomIn',
458 'transition.whirlIn' => 'zoomIn',
459 'transition.shrinkIn' => 'zoomIn',
460 'transition.expandIn' => 'zoomIn',
461 'transition.flipXIn' => 'flipInX',
462 'transition.flipYIn' => 'flipInY',
463 'transition.flipBounceXIn' => 'flipInX',
464 'transition.flipBounceYIn' => 'flipInY',
465 'transition.bounceIn' => 'bounceIn',
466 'transition.bounceUpIn' => 'bounceInUp',
467 'transition.bounceDownIn' => 'bounceInDown',
468 'transition.bounceLeftIn' => 'bounceInLeft',
469 'transition.bounceRightIn' => 'bounceInRight',
470 'transition.swoopOut' => 'zoomOut',
471 'transition.whirlOut' => 'zoomOut',
472 'transition.shrinkOut' => 'zoomOut',
473 'transition.expandOut' => 'zoomOut',
474 'transition.flipXOut' => 'flipOutX',
475 'transition.flipYOut' => 'flipOutY',
476 'transition.flipBounceXOut' => 'flipOutX',
477 'transition.flipBounceYOut' => 'flipOutY',
478 'transition.bounceOut' => 'bounceOut',
479 'transition.bounceUpOut' => 'bounceOutUp',
480 'transition.bounceDownOut' => 'bounceOutDown',
481 'transition.bounceLeftOut' => 'bounceOutLeft',
482 'transition.bounceRightOut' => 'bounceOutRight',
483 ], $fade_animations, $slide_animations);
484
485 // A campaign with no animation stored leaves this null, and PHP 8.5 deprecates
486 // null as an array_key_exists() key. An empty key misses the map just as null did.
487 $current_animation = is_scalar($new_meta[$key]) ? (string) $new_meta[$key] : '';
488
489 $new_meta[$key] = array_key_exists($current_animation, $animation_map) ? $animation_map[$current_animation] : $new_meta[$key];
490
491 // Validate page slide animation in/out
492 if (isset($new_meta['mode']) && $new_meta['mode'] === 'pageslide')
493 {
494 $isFadeAnimation = in_array($new_meta[$key], $fade_animations);
495 $isSlideAnimation = in_array($new_meta[$key], $slide_animations);
496
497 if ($key === 'animationin')
498 {
499 if (!$isFadeAnimation && !$isSlideAnimation)
500 {
501 $new_meta[$key] = 'slideInDown';
502 }
503 }
504 else if ($key === 'animationout')
505 {
506 if (!$isFadeAnimation && !$isSlideAnimation)
507 {
508 $new_meta[$key] = 'slideOutUp';
509 }
510 }
511 }
512 }
513
514 /**
515 * Migrate shadow settings
516 *
517 * @param string $key
518 * @param array $new_meta
519 * @param bool $valueExistsInNewMeta
520 * @return void
521 */
522 public function migrateShadow($key, &$new_meta, $valueExistsInNewMeta)
523 {
524 if ($valueExistsInNewMeta || !isset($new_meta[$key]))
525 {
526 return;
527 }
528
529 $new_meta[$key] = $new_meta[$key] != '0';
530 }
531
532 /**
533 * Migrate floating button message settings
534 *
535 * @param string $key
536 * @param array $new_meta
537 * @param array $defaults
538 * @param bool $valueExistsInNewMeta
539 * @return void
540 */
541 public function migrateFloatingButtonMessage($key, &$new_meta, $defaults, $valueExistsInNewMeta)
542 {
543 if ($valueExistsInNewMeta)
544 {
545 return;
546 }
547
548 if (isset($new_meta[$key]) && empty($new_meta[$key]))
549 {
550 $new_meta[$key] = $defaults['floatingbutton_message'];
551 }
552 else if (isset($new_meta[$key]['fontsize']) && is_numeric($new_meta[$key]['fontsize']))
553 {
554 $new_meta[$key]['fontsize'] = $new_meta[$key]['fontsize'] . 'px';
555 }
556 }
557
558 /**
559 * Migrate overlay enabled setting
560 *
561 * @param string $key
562 * @param array $new_meta
563 * @param bool $valueExistsInNewMeta
564 * @return void
565 */
566 public function migrateOverlayEnabled($key, &$new_meta, $valueExistsInNewMeta)
567 {
568 if ($valueExistsInNewMeta || !isset($new_meta[$key]))
569 {
570 return;
571 }
572
573 $new_meta[$key] = ((int) $new_meta[$key]) == 1;
574 }
575
576 /**
577 * Migrate overlay click setting
578 *
579 * @param string $key
580 * @param array $new_meta
581 * @param bool $valueExistsInNewMeta
582 * @return void
583 */
584 public function migrateOverlayClick($key, &$new_meta, $valueExistsInNewMeta)
585 {
586 if ($valueExistsInNewMeta || !isset($new_meta[$key]))
587 {
588 return;
589 }
590
591 $overlayClick = (int) $new_meta[$key];
592 $new_meta[$key] = !empty($overlayClick) && $overlayClick != 0;
593 }
594
595 /**
596 * Migrate overlay blur radius setting
597 *
598 * @param string $key
599 * @param array $new_meta
600 * @param bool $valueExistsInNewMeta
601 * @return void
602 */
603 public function migrateOverlayBlurRadius($key, &$new_meta, $valueExistsInNewMeta)
604 {
605 if ($valueExistsInNewMeta)
606 {
607 return;
608 }
609
610 $overlayBlurRadius = isset($new_meta[$key]) ? (int) $new_meta[$key] : 0;
611 if (empty($overlayBlurRadius) || $overlayBlurRadius == 0)
612 {
613 $new_meta[$key] = 0;
614 }
615 elseif ($overlayBlurRadius <= 10)
616 {
617 $new_meta[$key] = 2;
618 }
619 elseif ($overlayBlurRadius <= 30)
620 {
621 $new_meta[$key] = 14;
622 } else {
623 $new_meta[$key] = 45;
624 }
625 }
626
627 /**
628 * Migrate trigger method setting
629 *
630 * @param string $key
631 * @param array $new_meta
632 * @param array $legacy_meta
633 * @param bool $valueExistsInNewMeta
634 * @return void
635 */
636 public function migrateTriggerMethod($key, &$new_meta, $legacy_meta, $valueExistsInNewMeta)
637 {
638 if ($valueExistsInNewMeta)
639 {
640 return;
641 }
642
643 if (isset($new_meta[$key]))
644 {
645 if ($new_meta[$key] === 'pageready')
646 {
647 $new_meta[$key] = 'pageload';
648 $new_meta['early_trigger'] = true;
649 }
650 else if ($new_meta[$key] === 'floatingbutton')
651 {
652 $floating_button_position = isset($legacy_meta['floating_button_position']) ? $legacy_meta['floating_button_position'] : null;
653
654 if ($floating_button_position)
655 {
656 $new_meta['position'] = $floating_button_position;
657 }
658 }
659 }
660 }
661
662 /**
663 * Migrate scroll depth setting
664 *
665 * @param string $key
666 * @param array $new_meta
667 * @param array $legacy_meta
668 * @param bool $valueExistsInNewMeta
669 * @return void
670 */
671 public function migrateScrollDepth($key, &$new_meta, $legacy_meta, $valueExistsInNewMeta)
672 {
673 if ($valueExistsInNewMeta)
674 {
675 return;
676 }
677
678 $scroll_amount = isset($legacy_meta['scroll_amount']) ? $legacy_meta['scroll_amount'] : 0;
679
680 if ($scroll_amount)
681 {
682 $_value = isset($scroll_amount['value']) ? $scroll_amount['value'] : '80';
683 $_unit = isset($scroll_amount['unit']) ? $scroll_amount['unit'] : '%';
684 $new_meta[$key] = $_value . $_unit;
685 }
686 }
687
688 /**
689 * Migrate firing frequency toggle setting
690 *
691 * @param string $key
692 * @param array $new_meta
693 * @param bool $valueExistsInNewMeta
694 * @return void
695 */
696 public function migrateFiringFrequencyToggle($key, &$new_meta, $valueExistsInNewMeta)
697 {
698 if ($valueExistsInNewMeta || !isset($new_meta[$key]))
699 {
700 return;
701 }
702
703 $new_meta[$key] = $new_meta[$key] == '1';
704 }
705 }
706