PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.2
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.2
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 / Box.php

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

868 lines 21.1 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 1.0.2 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2021 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 use FireBox\Core\Helpers\BoxHelper;
20 use FPFramework\Libs\Registry;
21 use FPFramework\Helpers\Fields\DimensionsHelper;
22
23 class Box
24 {
25 /**
26 * Send useful JS snippet once in first box
27 *
28 * @var boolean
29 */
30 static $loadedLocalizedScript = false;
31
32 /**
33 * The box settings
34 */
35 private $boxSettings;
36
37 /**
38 * The factory
39 *
40 * @var Factory
41 */
42 protected $factory;
43
44 public function __construct($boxSettings = null, $factory = null)
45 {
46 if (!$factory)
47 {
48 $factory = new \FPFramework\Base\Factory();
49 }
50
51 $this->boxSettings = $boxSettings;
52 $this->factory = $factory;
53 }
54
55 /**
56 * Gets published box.
57 *
58 * @param integer $id
59 * @param string $status
60 *
61 * @return array
62 */
63 public function get($id, $status = 'publish')
64 {
65 $payload = [
66 'where' => [
67 'ID' => ' = ' . $id,
68 'post_type' => " = 'firebox'"
69 ]
70 ];
71
72 // apply status if given
73 if ($status)
74 {
75 $payload['where']['post_status'] = ' = \'' . $status . '\'';
76 }
77
78 if (!$box = firebox()->models->box->getResults($payload))
79 {
80 return [];
81 }
82
83 if (!isset($box[0]))
84 {
85 return [];
86 }
87
88 $box = $box[0];
89
90 // get meta options for box
91 $meta = self::getMeta($id);
92 $box->params = new Registry($meta);
93
94 return $box;
95 }
96
97 /**
98 * Get box meta
99 *
100 * @param int $id
101 *
102 * @return array
103 */
104 public static function getMeta($id)
105 {
106 return get_post_meta($id, 'fpframework_meta_settings', true);
107 }
108
109 /**
110 * Render box
111 *
112 * @return string
113 */
114 public function render($box = null)
115 {
116 // we do not have a passed box or box settings from constructor, abort
117 // as we cannot render a box without any box parameters
118 if (!$box && !$this->boxSettings)
119 {
120 return;
121 }
122
123 // if a box was given to the function, use these settings instead
124 if ($box)
125 {
126 $this->boxSettings = $box;
127 }
128
129 // if we have box settings, then set up our box with these settings
130 if ($this->boxSettings)
131 {
132 $box = $this->boxSettings;
133 }
134
135 // Check Publishing Assignments
136 if (!$this->pass($box))
137 {
138 return;
139 }
140
141 // get settings params
142 $params = BoxHelper::getParams();
143
144 if (!did_action('wp_enqueue_scripts'))
145 {
146 /**
147 * Loads all media files.
148 */
149 add_action('wp_enqueue_scripts', function() use ($box, $params) {
150 // load box media
151 $this->loadBoxMedia($box, $params);
152 });
153 }
154 else
155 {
156 // load box media
157 $this->loadBoxMedia($box, $params);
158 }
159
160 self::prepare($box);
161
162 if (!did_action('wp_head'))
163 {
164 /**
165 * Custom CSS
166 */
167 add_action('wp_head', function() use ($box) {
168 if (!empty($box->params->get('customcss', '')))
169 {
170 echo '<style type="text/css">' . $box->params->get('customcss') . '</style>';
171 }
172 });
173 }
174 else
175 {
176 if (!empty($box->params->get('customcss', '')))
177 {
178 echo '<style type="text/css">' . $box->params->get('customcss') . '</style>';
179 }
180 }
181
182 /**
183 * Runs before rendering the box.
184 */
185 do_action('firebox/box/before_render', $box);
186
187 // after we prepare it, update box settings
188 $this->boxSettings = $box;
189
190 // payload
191 $payload = [
192 'box' => $box,
193 'params' => $params,
194 ];
195
196 // return box template
197 add_action('wp_footer', function() use ($box, $payload) {
198 echo firebox()->renderer->public->render('box', $payload, true);
199 });
200 }
201
202 /**
203 * Send a helpful object to JavaScript files
204 *
205 * @return void
206 */
207 public static function setJSObject()
208 {
209 if (self::$loadedLocalizedScript)
210 {
211 return;
212 }
213 self::$loadedLocalizedScript = true;
214
215 $data = array(
216 'ajax_url' => admin_url('admin-ajax.php'),
217 'nonce' => wp_create_nonce('fbox_js_nonce'),
218 'site_url' => site_url('/'),
219 'referrer' => wp_get_referer()
220 );
221
222 wp_localize_script('firebox', 'fbox_js_object', $data);
223 }
224
225 /**
226 * Load Box Media
227 *
228 * @param array $box
229 * @param array $params
230 *
231 * @return void
232 */
233 public function loadBoxMedia($box, $params)
234 {
235 $box = new Registry($box);
236 $params = new Registry($params);
237
238 // Add polyfills for Internet Explorer
239 $browser = $this->factory->getBrowser();
240 if ($browser['name'] == 'ie')
241 {
242 wp_enqueue_script(
243 'firebox-ie11-polyfill',
244 'https://polyfill.io/v3/polyfill.min.js?features=NodeList.prototype.forEach%2CElement.prototype.closest%2CArray.prototype.forEach%2CArray.prototype.find%2CIntersectionObserver%2CIntersectionObserverEntry',
245 [],
246 FBOX_VERSION,
247 false
248 );
249 }
250
251 /**
252 * Velocity
253 */
254 if ($params->get('loadVelocity', true))
255 {
256 wp_enqueue_script(
257 'firebox-velocity',
258 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js',
259 [],
260 FBOX_VERSION,
261 false
262 );
263 wp_enqueue_script(
264 'firebox-velocity-ui',
265 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.ui.js',
266 [],
267 FBOX_VERSION,
268 false
269 );
270
271 /**
272 * Animations
273 */
274 if (strpos($box->get('params.data.animationin'), 'firebox') !== false || strpos($box->get('params.data.animationout'), 'firebox') !== false)
275 {
276 wp_enqueue_script(
277 'firebox-animations',
278 FBOX_MEDIA_PUBLIC_URL . 'js/animations.js',
279 [],
280 FBOX_VERSION,
281 false
282 );
283 }
284 }
285
286 /**
287 * FireBox JS
288 */
289 wp_enqueue_script(
290 'firebox',
291 FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js',
292 [],
293 FBOX_VERSION,
294 false
295 );
296
297 // run above the main JS script to run only once
298 self::setJSObject();
299
300 /**
301 * FireBox CSS
302 */
303 if ($params->get('loadCSS', true))
304 {
305 wp_enqueue_style(
306 'firebox',
307 FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css',
308 [],
309 FBOX_VERSION,
310 false
311 );
312 }
313
314 /**
315 * Page Slide mode JS
316 */
317 if ($box->get('params.data.mode') == 'pageslide')
318 {
319 wp_enqueue_script(
320 'firebox-pageslide-mode',
321 FBOX_MEDIA_PUBLIC_URL . 'js/pageslide_mode.js',
322 [],
323 FBOX_VERSION,
324 false
325 );
326 }
327
328
329
330 $this->loadThemeCSSOverrides();
331 }
332
333 /**
334 * Some themes require overrides to preserve as much as we can the styling of the popups.
335 *
336 * @return void
337 */
338 private function loadThemeCSSOverrides()
339 {
340 $active_theme = wp_get_theme();
341 $theme = $active_theme->template;
342
343 /**
344 * This is the listed of the themes that we have created overrides
345 */
346 $themes = [
347 'twentytwentyone'
348 ];
349
350 if (!in_array($theme, $themes))
351 {
352 return;
353 }
354
355 wp_enqueue_style(
356 'firebox-theme-' . $theme . '-override',
357 FBOX_MEDIA_PUBLIC_URL . 'css/themes/' . $theme . '.css',
358 [],
359 FBOX_VERSION,
360 false
361 );
362 }
363
364 /**
365 * Prepares the box before rendering
366 *
367 * @param array $box
368 *
369 * @return void
370 */
371 public static function prepare(&$box)
372 {
373 $cParam = BoxHelper::getParams();
374 $cParam = new Registry($cParam);
375
376 $box->post_content = apply_filters('the_content', $box->post_content);
377
378 $css_class_prefix = 'fb-';
379
380 $position = $box->params->get('position', '');
381 $position = !is_string($position) ? '' : $position;
382
383 /* Classes */
384 $css_class = [
385 $box->ID,
386 $position
387 ];
388
389 $rtl = $box->params->get('rtl', '0');
390 if ($rtl == '1')
391 {
392 $css_class[] = 'rtl';
393 }
394
395 self::prefixCSSClasses($css_class);
396
397 // class suffix
398 $classSuffix = $box->params->get('classsuffix', '');
399 $classSuffix = is_string($classSuffix) ? $classSuffix : '';
400
401 $css_class[] = $classSuffix;
402
403 $box->classes = $css_class;
404
405 // box shadow
406 $boxshadow = (is_string($box->params->get('boxshadow', '1')) || is_int($box->params->get('boxshadow', '1'))) ? $box->params->get('boxshadow', '1') : '0';
407
408 $dialog_css_classes = [
409 $boxshadow != '0' ? 'shd' . $boxshadow : null
410 ];
411
412 // Align Content
413 $aligncontent = is_string($box->params->get('aligncontent')) ? explode(' ', $box->params->get('aligncontent')) : [];
414 $dialog_css_classes = array_merge($dialog_css_classes, $aligncontent);
415
416 self::prefixCSSClasses($dialog_css_classes);
417 $box->dialog_classes = $dialog_css_classes;
418
419 /* CSS */
420 // border
421 $border = is_string($box->params->get('bordertype', 'none')) ? $box->params->get('bordertype', 'none') : 'none';
422 $border_width = $box->params->get('borderwidth.value', 0) ? $box->params->get('borderwidth.value', 0) : 0;
423 $border_unit = is_string($box->params->get('borderwidth.unit', 'px')) ? $box->params->get('borderwidth.unit', 'px') : 0;
424 $border_color = is_string($box->params->get('bordercolor')) ? $box->params->get('bordercolor') : '';
425
426 $style = [
427 'background-color' => $box->params->get('backgroundcolor'),
428 'color' => $box->params->get('textcolor'),
429 'border' => $border == 'none' ? null : $border . ' ' . $border_width . $border_unit . ' ' . $border_color,
430 ];
431
432 // add shared properties
433 $shared_properties = [
434 'width' => [
435 'prefix_only' => true
436 ],
437 'height' => [
438 'prefix_only' => true
439 ],
440 'padding' => [],
441 'margin' => []
442 ];
443 foreach ($shared_properties as $prop => $prop_data)
444 {
445 // add dekstop property
446 $value = (array) $box->params->get($prop . '_control.' . $prop, []);
447 if (isset($value['desktop']))
448 {
449 $prefix_only = isset($prop_data['prefix_only']) ? (bool) $prop_data['prefix_only'] : false;
450
451 $desktop_value = DimensionsHelper::parseDimensionsData($value['desktop'], $prop, false, $prefix_only);
452 $style = array_merge($style, $desktop_value);
453 }
454 }
455
456 // add dekstop border_radius
457 $border_radius = (array) $box->params->get('borderradius_control.borderradius', []);
458 if (isset($border_radius['desktop']))
459 {
460 $desktop_border_radius = DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['desktop']);
461 $style = array_merge($style, $desktop_border_radius);
462 }
463
464 // Background Image
465 if ($box->params->get('bgimage', false))
466 {
467 $bgrepeat = is_string($box->params->get('bgrepeat')) ? $box->params->get('bgrepeat') : '';
468 $bgsize = is_string($box->params->get('bgsize')) ? $box->params->get('bgsize') : '';
469 $bgposition = is_string($box->params->get('bgposition')) ? $box->params->get('bgposition') : '';
470
471 $style['background-image'] = 'url(\'' . esc_url($box->params->get('bgimagefile')) . '\')';
472 $style['background-repeat'] = strtolower($bgrepeat);
473 $style['background-size'] = strtolower($bgsize);
474 $style['background-position'] = strtolower($bgposition);
475 }
476
477 $box->style = BoxHelper::arrayToCSSS($style);
478
479 $trigger_point_methods = [
480 'pageheight' => 'onScrollDepth',
481 'element' => 'onElementVisibility',
482 'pageready' => 'onPageReady',
483 'pageload' => 'onPageLoad',
484 'userleave' => 'onExit',
485 'onclick' => 'onClick',
486 'elementHover' => 'onHover',
487 'ondemand' => 'onDemand'
488 ];
489
490 // z index
491 $zindex = $box->params->get('zindex', 99999) != 99999 ? $box->params->get('zindex') : null;
492
493 $box->styles_container = BoxHelper::arrayToCSSS([
494 'z-index' => $zindex
495 ]);
496
497 /* Other Settings */
498 $scroll_depth = $box->params->get('scroll_depth', 'percentage');
499 $scroll_depth = !is_array($scroll_depth) ? $scroll_depth : '';
500
501 $animation_duration = $box->params->get('duration') ? (float) $box->params->get('duration') : 0;
502
503 // Use Namespaced classes for each trigger point and let them manipulate the settings dynamicaly.
504 $box->settings = [
505 'trigger' => (is_string($box->params->get('triggermethod'))) && array_key_exists($box->params->get('triggermethod'), $trigger_point_methods) ? $trigger_point_methods[$box->params->get('triggermethod')] : $box->params->get('triggermethod'),
506 'trigger_selector' => $box->params->get('triggerelement'),
507 'delay' => (int) $box->params->get('triggerdelay') * 1000,
508 'scroll_depth' => $scroll_depth,
509 'scroll_depth_value' => $scroll_depth == 'percentage' ? (int) $box->params->get('triggerpercentage') : (int) $box->params->get('scroll_pixel'),
510 'firing_frequency' => (int) $box->params->get('firing_frequency', 1),
511 'reverse_scroll_close' => (bool) $box->params->get('autohide'),
512 'threshold' => (float) $box->params->get('threshold', 0) / 100,
513 'close_out_viewport' => (bool) $box->params->get('close_out_viewport', false),
514 'exit_timer' => (int) $box->params->get('exittimer') * 1000,
515 'idle_time' => (int) $box->params->get('idle_time') * 1000,
516 'animation_open' => $box->params->get('animationin'),
517 'animation_close' => $box->params->get('animationout'),
518 'animation_duration' => (float) $animation_duration * 1000,
519 'prevent_default' => (bool) $box->params->get('preventdefault', true),
520 'backdrop' => (bool) $box->params->get('overlay'),
521 'backdrop_color' => $box->params->get('overlay_color'),
522 'backdrop_click' => (bool) $box->params->get('overlayclick'),
523 'disable_page_scroll' => (bool) $box->params->get('preventpagescroll'),
524 'test_mode' => (bool) $box->params->get('testmode'),
525 'debug' => (bool) $cParam->get('debug', false),
526 'ga_tracking' => (bool) $cParam->get('gaTrack', 0),
527 'ga_tracking_id' => $cParam->get('gaID', 0),
528 'ga_tracking_label' => $cParam->get('gaCategory'),
529 'auto_focus' => (bool) $box->params->get('autofocus', false)
530 ];
531
532 // set padding and margin for other devices as well
533 self::setResponsiveCSS($box);
534
535 self::replaceBoxSmartTags($box);
536 }
537
538 /**
539 * Sets all responsive CSS to use in box view
540 *
541 * @param object $box
542 *
543 * @return void
544 */
545 private static function setResponsiveCSS(&$box)
546 {
547 $tablet = '';
548 $mobile = '';
549
550 /**
551 * Handle width, height, padding, margin the same way.
552 */
553 $shared_properties = [
554 'width' => [
555 'prefix_only' => true
556 ],
557 'height' => [
558 'prefix_only' => true
559 ],
560 'padding' => [],
561 'margin' => []
562 ];
563
564 foreach ($shared_properties as $prop => $prop_settings)
565 {
566 $prop_data = (array) $box->params->get($prop . '_control.' . $prop, []);
567
568 $prefix_only = isset($prop_settings['prefix_only']) ? $prop_settings['prefix_only'] : false;
569
570 // assign each device CSS
571 if (isset($prop_data['tablet']))
572 {
573 $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['tablet'], $prop, true, $prefix_only));
574 }
575 if (isset($prop_data['mobile']))
576 {
577 $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['mobile'], $prop, true, $prefix_only));
578 }
579 }
580
581 // border radius requires a special method
582 $border_radius = (array) $box->params->get('borderradius_control.borderradius', []);
583 if (isset($border_radius['tablet']))
584 {
585 $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['tablet'], true));
586 }
587 if (isset($border_radius['mobile']))
588 {
589 $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['mobile'], true));
590 }
591
592 $responsive_css = [
593 'tablet' => $tablet,
594 'mobile' => $mobile
595 ];
596 $box->params->set('responsive_css', $responsive_css);
597 }
598
599 /**
600 * Replaces all box smart tags
601 *
602 * @param object $box
603 *
604 * @return object
605 */
606 public static function replaceBoxSmartTags(&$box)
607 {
608 $tags = new \FPFramework\Base\SmartTags\SmartTags();
609
610 // register FB Smart Tags
611 $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $box);
612
613 $box = $tags->replace($box);
614 }
615
616 /**
617 * Checks if a box passes assignments
618 *
619 * @param object $box
620 *
621 * @return boolean
622 */
623 public function pass($box)
624 {
625 if (!$box || !is_object($box))
626 {
627 return false;
628 }
629
630 // set box settings if empty
631 if (empty($this->boxSettings))
632 {
633 $this->boxSettings = $box;
634 }
635
636 // Prepare boxes that mirror other boxes assignments
637 if ($box->params->get('mirror', false) && $mirror_box_id = $box->params->get('mirror_box'))
638 {
639 $box->params->merge(self::getAssignmentsForMirroring($mirror_box_id));
640 }
641
642 // Check first local assignments
643 if (!$this->passLocalAssignments($box))
644 {
645 return false;
646 }
647
648 // If testmode is enabled disable the User Groups assignment
649 if ($box->params->get('testmode'))
650 {
651 $box->params->set('assignments.assign_grouplevel.selection', '0');
652 }
653
654 $globalAssignments = $this->passGlobalAssignments($box);
655
656 // Check framework based assignments
657 return $globalAssignments;
658 }
659
660 /**
661 * Passes framework based global assignments
662 *
663 * @param object $box
664 *
665 * @return boolean
666 */
667 private function passGlobalAssignments($box)
668 {
669 $assignments = new \FPFramework\Base\Assignments($this->factory);
670 $pass = $assignments->passAll($box, $box->params->get('assignmentMatchingMethod', 'and'));
671 return $pass;
672 }
673
674 /**
675 * Check if a box passes local assignments
676 *
677 * @param object $box
678 *
679 * @return boolean
680 */
681 private function passLocalAssignments($box)
682 {
683 $localAssignments = new \FireBox\Core\FB\Assignments($this, $this->factory);
684 return $localAssignments->passAll();
685 }
686
687 /**
688 * Gets assignments of mirrored box
689 *
690 * @param int $box_id
691 *
692 * @return object
693 */
694 private static function getAssignmentsForMirroring($box_id)
695 {
696 $payload = [
697 'where' => [
698 'ID' => ' = ' . $box_id,
699 'post_status' => " = 'publish'",
700 'post_type' => " = 'firebox'"
701 ]
702 ];
703
704 // Load box
705 if (!$box = firebox()->models->box->getResults($payload))
706 {
707 return;
708 }
709
710 $box = $box[0];
711
712 // get meta options for box
713 $meta = get_post_meta($box_id, 'fpframework_meta_settings', true);
714 $box->params = $meta;
715
716 // To prevent user frustration, we ignore the following assignments because they are not displayed in the Publishing Assignments.
717 $params_to_ignore = [
718 'assign_impressions'
719 ];
720
721 $assignments = [];
722
723 // Gather params to merge
724 foreach ($box->params as $param_key => $param_value)
725 {
726 if (strpos($param_key, 'assign') === false || in_array($param_key, $params_to_ignore))
727 {
728 continue;
729 }
730
731 $assignments[$param_key] = $param_value;
732 }
733
734 return new Registry($assignments);
735 }
736
737 /**
738 * Prefixes the CSS classes
739 *
740 * @param array $classes
741 * @param string $prefix
742 *
743 * @return void
744 */
745 private static function prefixCSSClasses(&$classes, $prefix = 'fb-')
746 {
747 $classes = array_filter($classes);
748
749 if (empty($classes))
750 {
751 return;
752 }
753
754 foreach ($classes as &$class)
755 {
756 $class = $prefix . $class;
757 }
758 }
759
760 /**
761 * Track box open
762 *
763 * @param integer $box_id
764 * @param string $page
765 * @param string $referrer
766 *
767 * @return void
768 */
769 public function logOpenEvent($box_id, $page = null, $referrer = null)
770 {
771 $box = $this->get($box_id, null);
772
773 // Do not track if statistics option is disabled
774 $track_open_event = (bool) (is_null($box->params->get('stats', null)) ? BoxHelper::getParams()->get('stats', 1) : $box->params->get('stats'));
775 if (!$track_open_event)
776 {
777 return;
778 }
779
780 return firebox()->log->track($box_id, 1, null, $page, $referrer);
781 }
782
783 /**
784 * Track box close
785 *
786 * @param integer $box_id
787 * @param integer $box_log_id
788 *
789 * @return void
790 */
791 public function logCloseEvent($box_id, $box_log_id)
792 {
793 $box = $this->get($box_id, null);
794
795 // Do not track if statistics option is disabled
796 $track_open_event = (bool) (is_null($box->params->get('stats', null)) ? BoxHelper::getParams()->get('stats', 1) : $box->params->get('stats'));
797 if (!$track_open_event)
798 {
799 return null;
800 }
801
802 firebox()->log->track($box_id, 2, $box_log_id);
803 }
804
805 /**
806 * Get box impressions
807 *
808 * @param array $payload
809 *
810 * @return array
811 */
812 public function getImpressions($payload)
813 {
814 return firebox()->models->boxlog->getResults($payload);
815 }
816
817 /**
818 * Get total box impressions
819 *
820 * @param array $payload
821 *
822 * @return array
823 */
824 public function getTotalImpressions($payload)
825 {
826 return count($this->getImpressions($payload));
827 }
828
829 /**
830 * Return the box settings
831 *
832 * @return object
833 */
834 public function getBoxSettings()
835 {
836 return $this->boxSettings;
837 }
838
839 /**
840 * Sets the box settings
841 *
842 * @param object $settings
843 *
844 * @return object
845 */
846 public function setBoxSettings($settings)
847 {
848 $this->boxSettings = $settings;
849 }
850
851 /**
852 * Returns the box cookie
853 *
854 * @param string $cookie
855 *
856 * @return mixed
857 */
858 public function getCookie($cookie = null)
859 {
860 $cookie = $cookie ? $cookie : (isset($this->boxSettings->ID) ? $this->boxSettings->ID : null);
861 if (!isset($cookie))
862 {
863 return;
864 }
865
866 return new Cookie($cookie);
867 }
868 }