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