PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.8
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.8
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.8, at Inc/Core/FB/MetaMigrator.php

703 lines 22.2 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.8 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 $new_meta[$key] = array_key_exists($new_meta[$key], $animation_map) ? $animation_map[$new_meta[$key]] : $new_meta[$key];
486
487 // Validate page slide animation in/out
488 if (isset($new_meta['mode']) && $new_meta['mode'] === 'pageslide')
489 {
490 $isFadeAnimation = in_array($new_meta[$key], $fade_animations);
491 $isSlideAnimation = in_array($new_meta[$key], $slide_animations);
492
493 if ($key === 'animationin')
494 {
495 if (!$isFadeAnimation && !$isSlideAnimation)
496 {
497 $new_meta[$key] = 'slideInDown';
498 }
499 }
500 else if ($key === 'animationout')
501 {
502 if (!$isFadeAnimation && !$isSlideAnimation)
503 {
504 $new_meta[$key] = 'slideOutUp';
505 }
506 }
507 }
508 }
509
510 /**
511 * Migrate shadow settings
512 *
513 * @param string $key
514 * @param array $new_meta
515 * @param bool $valueExistsInNewMeta
516 * @return void
517 */
518 public function migrateShadow($key, &$new_meta, $valueExistsInNewMeta)
519 {
520 if ($valueExistsInNewMeta)
521 {
522 return;
523 }
524
525 $new_meta[$key] = isset($new_meta[$key]) && $new_meta[$key] != '0';
526 }
527
528 /**
529 * Migrate floating button message settings
530 *
531 * @param string $key
532 * @param array $new_meta
533 * @param array $defaults
534 * @param bool $valueExistsInNewMeta
535 * @return void
536 */
537 public function migrateFloatingButtonMessage($key, &$new_meta, $defaults, $valueExistsInNewMeta)
538 {
539 if ($valueExistsInNewMeta)
540 {
541 return;
542 }
543
544 if (isset($new_meta[$key]) && empty($new_meta[$key]))
545 {
546 $new_meta[$key] = $defaults['floatingbutton_message'];
547 }
548 else if (isset($new_meta[$key]['fontsize']) && is_numeric($new_meta[$key]['fontsize']))
549 {
550 $new_meta[$key]['fontsize'] = $new_meta[$key]['fontsize'] . 'px';
551 }
552 }
553
554 /**
555 * Migrate overlay enabled setting
556 *
557 * @param string $key
558 * @param array $new_meta
559 * @param bool $valueExistsInNewMeta
560 * @return void
561 */
562 public function migrateOverlayEnabled($key, &$new_meta, $valueExistsInNewMeta)
563 {
564 if ($valueExistsInNewMeta)
565 {
566 return;
567 }
568
569 $overlay = isset($new_meta[$key]) ? (int) $new_meta[$key] : 0;
570 $new_meta[$key] = $overlay == 1;
571 }
572
573 /**
574 * Migrate overlay click setting
575 *
576 * @param string $key
577 * @param array $new_meta
578 * @param bool $valueExistsInNewMeta
579 * @return void
580 */
581 public function migrateOverlayClick($key, &$new_meta, $valueExistsInNewMeta)
582 {
583 if ($valueExistsInNewMeta)
584 {
585 return;
586 }
587
588 $overlayClick = isset($new_meta[$key]) ? (int) $new_meta[$key] : 0;
589 $new_meta[$key] = !empty($overlayClick) && $overlayClick != 0;
590 }
591
592 /**
593 * Migrate overlay blur radius setting
594 *
595 * @param string $key
596 * @param array $new_meta
597 * @param bool $valueExistsInNewMeta
598 * @return void
599 */
600 public function migrateOverlayBlurRadius($key, &$new_meta, $valueExistsInNewMeta)
601 {
602 if ($valueExistsInNewMeta)
603 {
604 return;
605 }
606
607 $overlayBlurRadius = isset($new_meta[$key]) ? (int) $new_meta[$key] : 0;
608 if (empty($overlayBlurRadius) || $overlayBlurRadius == 0)
609 {
610 $new_meta[$key] = 0;
611 }
612 elseif ($overlayBlurRadius <= 10)
613 {
614 $new_meta[$key] = 2;
615 }
616 elseif ($overlayBlurRadius <= 30)
617 {
618 $new_meta[$key] = 14;
619 } else {
620 $new_meta[$key] = 45;
621 }
622 }
623
624 /**
625 * Migrate trigger method setting
626 *
627 * @param string $key
628 * @param array $new_meta
629 * @param array $legacy_meta
630 * @param bool $valueExistsInNewMeta
631 * @return void
632 */
633 public function migrateTriggerMethod($key, &$new_meta, $legacy_meta, $valueExistsInNewMeta)
634 {
635 if ($valueExistsInNewMeta)
636 {
637 return;
638 }
639
640 if (isset($new_meta[$key]))
641 {
642 if ($new_meta[$key] === 'pageready')
643 {
644 $new_meta[$key] = 'pageload';
645 $new_meta['early_trigger'] = true;
646 }
647 else if ($new_meta[$key] === 'floatingbutton')
648 {
649 $floating_button_position = isset($legacy_meta['floating_button_position']) ? $legacy_meta['floating_button_position'] : null;
650
651 if ($floating_button_position)
652 {
653 $new_meta['position'] = $floating_button_position;
654 }
655 }
656 }
657 }
658
659 /**
660 * Migrate scroll depth setting
661 *
662 * @param string $key
663 * @param array $new_meta
664 * @param array $legacy_meta
665 * @param bool $valueExistsInNewMeta
666 * @return void
667 */
668 public function migrateScrollDepth($key, &$new_meta, $legacy_meta, $valueExistsInNewMeta)
669 {
670 if ($valueExistsInNewMeta)
671 {
672 return;
673 }
674
675 $scroll_amount = isset($legacy_meta['scroll_amount']) ? $legacy_meta['scroll_amount'] : 0;
676
677 if ($scroll_amount)
678 {
679 $_value = isset($scroll_amount['value']) ? $scroll_amount['value'] : '80';
680 $_unit = isset($scroll_amount['unit']) ? $scroll_amount['unit'] : '%';
681 $new_meta[$key] = $_value . $_unit;
682 }
683 }
684
685 /**
686 * Migrate firing frequency toggle setting
687 *
688 * @param string $key
689 * @param array $new_meta
690 * @param bool $valueExistsInNewMeta
691 * @return void
692 */
693 public function migrateFiringFrequencyToggle($key, &$new_meta, $valueExistsInNewMeta)
694 {
695 if ($valueExistsInNewMeta)
696 {
697 return;
698 }
699
700 $new_meta[$key] = $new_meta[$key] == '1';
701 }
702 }
703