PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.14
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 +254 -407 1.0.02.1.14 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.0 Free
4 + * @version 2.1.14 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 © 2024 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,43 +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 {
71 + if ($box)
72 + {
73 + $this->box = $this->prepareConstructorBox($box);
74 + }
75 +
46 76 if (!$factory)
47 77 {
48 78 $factory = new \FPFramework\Base\Factory();
49 79 }
80 + $this->factory = $factory;
81 +
82 + $this->params = new Registry(BoxHelper::getParams());
83 + }
84 +
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)
94 + {
95 + if (!is_object($box))
96 + {
97 + $box = $this->get($box);
98 + }
50 99
51 - $this->boxSettings = $boxSettings;
52 - $this->factory = $factory;
100 + return $box;
53 101 }
54 102
55 103 /**
56 - * Gets published box.
104 + * Get a box.
57 105 *
58 - * @param integer $id
59 - * @param string $status
106 + * @param int $id
107 + * @param string $status
60 108 *
61 - * @return array
109 + * @return object
62 110 */
63 - public function get($id, $status = 'publish')
111 + public function get($id = null, $status = null)
64 112 {
113 + if (!$id)
114 + {
115 + return;
116 + }
117 +
65 118 $payload = [
66 119 'where' => [
67 - 'ID' => ' = ' . $id,
120 + 'ID' => ' = ' . esc_sql(intval($id)),
68 121 'post_type' => " = 'firebox'"
69 122 ]
70 123 ];
71 124
@@ -71,12 +124,12 @@
71 124
72 125 // apply status if given
73 126 if ($status)
74 127 {
75 - $payload['where']['post_status'] = ' = \'' . $status . '\'';
128 + $payload['where']['post_status'] = ' = \'' . esc_sql($status) . '\'';
76 129 }
77 130
78 - if (!$box = firebox()->models->box->getResults($payload))
131 + if (!$box = firebox()->tables->box->getResults($payload))
79 132 {
80 133 return [];
81 134 }
82 135
@@ -84,123 +137,89 @@
84 137 {
85 138 return [];
86 139 }
87 140
88 - $box = $box[0];
141 + $this->box = $box[0];
89 142
90 143 // get meta options for box
91 - $meta = self::getMeta($id);
92 - $box->params = new Registry($meta);
144 + $meta = \FireBox\Core\Helpers\BoxHelper::getMeta($id);
145 + $this->box->params = new Registry($meta);
93 146
94 - return $box;
147 + return $this->box;
95 148 }
96 149
97 150 /**
98 - * Get box meta
151 + * Renders the box.
99 152 *
100 - * @param int $id
101 - *
102 - * @return array
153 + * @return void
103 154 */
104 - public static function getMeta($id)
155 + public function render()
105 156 {
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))
157 + // Check Publishing Assignments
158 + if (!$this->pass())
137 159 {
138 160 return;
139 161 }
140 162
141 - // get settings params
142 - $params = BoxHelper::getParams();
163 + $fbox = $this->box;
164 +
165 + add_action('wp_enqueue_scripts', function() use ($fbox) {
166 + // Loads all media files.
167 + $this->loadBoxMedia($fbox);
168 + });
143 169
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 - }
170 + /**
171 + * Runs before rendering the box.
172 + */
173 + do_action('firebox/box/before_render', $this->box);
159 174
160 - self::prepare($box);
175 + $this->prepare();
176 +
177 + $css = $this->getCustomCSS();
161 178
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', '')))
179 + add_action('wp_enqueue_scripts', function() use ($fbox, $css) {
180 + // Load CSS
181 + if ($css)
177 182 {
178 - echo '<style type="text/css">' . $box->params->get('customcss') . '</style>';
183 + wp_add_inline_style('firebox', $css);
179 184 }
180 - }
185 +
186 +
187 + });
181 188
182 - /**
183 - * Runs before rendering the box.
184 - */
185 - do_action('firebox/box/before_render', $box);
189 + // Allow to manipulate the box before rendering
190 + $this->box = apply_filters('firebox/box/edit', $this->box);
186 191
187 - // after we prepare it, update box settings
188 - $this->boxSettings = $box;
189 -
190 192 // payload
191 193 $payload = [
192 - 'box' => $box,
193 - 'params' => $params,
194 + 'box' => $this->box,
195 + 'params' => $this->params,
194 196 ];
195 197
196 198 // return box template
197 - add_action('wp_footer', function() use ($box, $payload) {
198 - echo firebox()->renderer->public->render('box', $payload, true);
199 + add_action('wp_footer', function() use ($payload) {
200 + $html = firebox()->renderer->public->render('box', $payload, true);
201 +
202 + /**
203 + * Runs after rendering the box.
204 + */
205 + $html = apply_filters('firebox/box/after_render', $html, $payload['box']);
206 +
207 + echo $html;
199 208 });
200 209 }
201 -
210 +
202 211 /**
212 + * Gets the Custom CSS of the popup.
213 + *
214 + * @return string
215 + */
216 + private function getCustomCSS()
217 + {
218 + return $this->box->params->get('customcss', '');
219 + }
220 +
221 + /**
203 222 * Send a helpful object to JavaScript files
204 223 *
205 224 * @return void
206 225 */
@@ -212,12 +231,12 @@
212 231 }
213 232 self::$loadedLocalizedScript = true;
214 233
215 234 $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()
235 + 'ajax_url' => admin_url('admin-ajax.php'),
236 + 'nonce' => wp_create_nonce('fbox_js_nonce'),
237 + 'site_url' => site_url('/'),
238 + 'referrer' => isset($_SERVER['HTTP_REFERER']) ? sanitize_text_field($_SERVER['HTTP_REFERER']) : ''
220 239 );
221 240
222 241 wp_localize_script('firebox', 'fbox_js_object', $data);
223 242 }
@@ -224,21 +243,17 @@
224 243
225 244 /**
226 245 * Load Box Media
227 246 *
228 - * @param array $box
229 - * @param array $params
230 - *
231 247 * @return void
232 248 */
233 - public function loadBoxMedia($box, $params)
249 + public function loadBoxMedia($box)
234 250 {
235 251 $box = new Registry($box);
236 - $params = new Registry($params);
237 252
238 253 // Add polyfills for Internet Explorer
239 254 $browser = $this->factory->getBrowser();
240 - if ($browser['name'] == 'ie')
255 + if ($browser && is_array($browser) && array_key_exists('name', $browser) && $browser['name'] === 'ie')
241 256 {
242 257 wp_enqueue_script(
243 258 'firebox-ie11-polyfill',
244 259 'https://polyfill.io/v3/polyfill.min.js?features=NodeList.prototype.forEach%2CElement.prototype.closest%2CArray.prototype.forEach%2CArray.prototype.find%2CIntersectionObserver%2CIntersectionObserverEntry',
@@ -243,9 +258,9 @@
243 258 'firebox-ie11-polyfill',
244 259 'https://polyfill.io/v3/polyfill.min.js?features=NodeList.prototype.forEach%2CElement.prototype.closest%2CArray.prototype.forEach%2CArray.prototype.find%2CIntersectionObserver%2CIntersectionObserverEntry',
245 260 [],
246 261 FBOX_VERSION,
247 - false
262 + true
248 263 );
249 264 }
250 265
251 266 /**
@@ -250,9 +265,9 @@
250 265
251 266 /**
252 267 * Velocity
253 268 */
254 - if ($params->get('loadVelocity', true))
269 + if ($this->params->get('loadVelocity', true))
255 270 {
256 271 wp_enqueue_script(
257 272 'firebox-velocity',
258 273 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js',
@@ -257,9 +272,9 @@
257 272 'firebox-velocity',
258 273 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js',
259 274 [],
260 275 FBOX_VERSION,
261 - false
276 + true
262 277 );
263 278 wp_enqueue_script(
264 279 'firebox-velocity-ui',
265 280 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.ui.js',
@@ -264,9 +279,9 @@
264 279 'firebox-velocity-ui',
265 280 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.ui.js',
266 281 [],
267 282 FBOX_VERSION,
268 - false
283 + true
269 284 );
270 285
271 286 /**
272 287 * Animations
@@ -277,9 +292,9 @@
277 292 'firebox-animations',
278 293 FBOX_MEDIA_PUBLIC_URL . 'js/animations.js',
279 294 [],
280 295 FBOX_VERSION,
281 - false
296 + true
282 297 );
283 298 }
284 299 }
285 300
@@ -290,9 +305,9 @@
290 305 'firebox',
291 306 FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js',
292 307 [],
293 308 FBOX_VERSION,
294 - false
309 + true
295 310 );
296 311
297 312 // run above the main JS script to run only once
298 313 self::setJSObject();
@@ -299,16 +314,15 @@
299 314
300 315 /**
301 316 * FireBox CSS
302 317 */
303 - if ($params->get('loadCSS', true))
318 + if ($this->params->get('loadCSS', true))
304 319 {
305 320 wp_enqueue_style(
306 321 'firebox',
307 322 FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css',
308 323 [],
309 - FBOX_VERSION,
310 - false
324 + FBOX_VERSION
311 325 );
312 326 }
313 327
314 328 /**
@@ -320,9 +334,9 @@
320 334 'firebox-pageslide-mode',
321 335 FBOX_MEDIA_PUBLIC_URL . 'js/pageslide_mode.js',
322 336 [],
323 337 FBOX_VERSION,
324 - false
338 + true
325 339 );
326 340 }
327 341
328 342
@@ -355,10 +369,9 @@
355 369 wp_enqueue_style(
356 370 'firebox-theme-' . $theme . '-override',
357 371 FBOX_MEDIA_PUBLIC_URL . 'css/themes/' . $theme . '.css',
358 372 [],
359 - FBOX_VERSION,
360 - false
373 + FBOX_VERSION
361 374 );
362 375 }
363 376
364 377 /**
@@ -363,31 +376,29 @@
363 376
364 377 /**
365 378 * Prepares the box before rendering
366 379 *
367 - * @param array $box
368 - *
369 380 * @return void
370 381 */
371 - public static function prepare(&$box)
382 + public function prepare()
372 383 {
384 + $this->css = new Styling\CSS($this->box);
385 +
373 386 $cParam = BoxHelper::getParams();
374 387 $cParam = new Registry($cParam);
375 388
376 - $box->post_content = apply_filters('the_content', $box->post_content);
377 -
378 - $css_class_prefix = 'fb-';
389 + $this->box->post_content = apply_filters('the_content', $this->box->post_content);
379 390
380 - $position = $box->params->get('position', '');
391 + $position = $this->box->params->get('position', '');
381 392 $position = !is_string($position) ? '' : $position;
382 393
383 394 /* Classes */
384 395 $css_class = [
385 - $box->ID,
396 + $this->box->ID,
386 397 $position
387 398 ];
388 399
389 - $rtl = $box->params->get('rtl', '0');
400 + $rtl = $this->box->params->get('rtl', '0');
390 401 if ($rtl == '1')
391 402 {
392 403 $css_class[] = 'rtl';
393 404 }
@@ -393,18 +404,18 @@
393 404 }
394 405
395 406 self::prefixCSSClasses($css_class);
396 407
397 - // class suffix
398 - $classSuffix = $box->params->get('classsuffix', '');
408 + // Class suffix
409 + $classSuffix = $this->box->params->get('classsuffix', '');
399 410 $classSuffix = is_string($classSuffix) ? $classSuffix : '';
400 411
401 412 $css_class[] = $classSuffix;
402 413
403 - $box->classes = $css_class;
414 + $this->box->classes = $css_class;
404 415
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';
416 + // Box shadow
417 + $boxshadow = (is_string($this->box->params->get('boxshadow', '1')) || is_int($this->box->params->get('boxshadow', '1'))) ? $this->box->params->get('boxshadow', '1') : '0';
407 418
408 419 $dialog_css_classes = [
409 420 $boxshadow != '0' ? 'shd' . $boxshadow : null
410 421 ];
@@ -409,276 +420,141 @@
409 420 $boxshadow != '0' ? 'shd' . $boxshadow : null
410 421 ];
411 422
412 423 // Align Content
413 - $aligncontent = is_string($box->params->get('aligncontent')) ? explode(' ', $box->params->get('aligncontent')) : [];
424 + $aligncontent = is_string($this->box->params->get('aligncontent')) ? explode(' ', $this->box->params->get('aligncontent')) : [];
414 425 $dialog_css_classes = array_merge($dialog_css_classes, $aligncontent);
415 426
416 427 self::prefixCSSClasses($dialog_css_classes);
417 - $box->dialog_classes = $dialog_css_classes;
428 + $this->box->dialog_classes = $dialog_css_classes;
418 429
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 430 $trigger_point_methods = [
480 - 'pageheight' => 'onScrollDepth',
481 - 'element' => 'onElementVisibility',
482 - 'pageready' => 'onPageReady',
431 + 'pageready' => 'onPageReady',
483 432 'pageload' => 'onPageLoad',
484 - 'userleave' => 'onExit',
485 433 'onclick' => 'onClick',
486 434 'elementHover' => 'onHover',
487 - 'ondemand' => 'onDemand'
435 + 'ondemand' => 'onDemand',
436 +
488 437 ];
489 438
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 - ]);
439 + /* Other Settings */
440 + $scroll_depth = $this->box->params->get('scroll_depth', 'percentage');
441 + $scroll_depth = is_string($scroll_depth) ? $scroll_depth : '';
496 442
497 - /* Other Settings */
498 - $scroll_depth = $box->params->get('scroll_depth', 'percentage');
499 - $scroll_depth = !is_array($scroll_depth) ? $scroll_depth : '';
443 + $animation_duration = $this->box->params->get('duration') ? (float) $this->box->params->get('duration') : 0;
500 444
501 - $animation_duration = $box->params->get('duration') ? (float) $box->params->get('duration') : 0;
502 -
445 + $delay = in_array($this->box->params->get('triggermethod'), ['floatingbutton', 'onexternallink']) ? 0 : (int) $this->box->params->get('triggerdelay') * 1000;
446 +
447 + $trigger_method = (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');
448 +
449 + $trigger_element = is_scalar($this->box->params->get('triggerelement', '')) ? $this->box->params->get('triggerelement', '') : '';
450 +
503 451 // 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'),
452 + $this->box->settings = [
453 + 'name' => $this->box->post_title,
454 + 'trigger' => $trigger_method,
455 + 'trigger_selector' => $trigger_method === 'onExternalLink' ? '' : rtrim($trigger_element, ','),
456 + 'delay' => $delay,
457 +
458 + 'animation_open' => $this->box->params->get('animationin'),
459 + 'animation_close' => $this->box->params->get('animationout'),
518 460 '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'),
461 + 'prevent_default' => (bool) $this->box->params->get('preventdefault', true),
462 + 'backdrop' => (bool) $this->box->params->get('overlay'),
463 + 'backdrop_color' => $this->box->params->get('overlay_color'),
464 + 'backdrop_click' => (bool) $this->box->params->get('overlayclick'),
465 + 'disable_page_scroll' => (bool) $this->box->params->get('preventpagescroll'),
466 + 'test_mode' => (bool) $this->box->params->get('testmode'),
525 467 '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')
468 + 'auto_focus' => (bool) $this->box->params->get('autofocus', false)
529 469 ];
530 470
531 - // set padding and margin for other devices as well
532 - self::setResponsiveCSS($box);
471 + // Apply Popup CSS
472 + $this->box->params->set('customcss', $this->box->params->get('customcss') . $this->css->getCSS());
533 473
534 - self::replaceBoxSmartTags($box);
474 + $this->replaceBoxSmartTags();
535 475 }
536 476
537 477 /**
538 - * Sets all responsive CSS to use in box view
539 - *
540 - * @param object $box
541 - *
542 - * @return void
543 - */
544 - private static function setResponsiveCSS(&$box)
545 - {
546 - $tablet = '';
547 - $mobile = '';
548 -
549 - /**
550 - * Handle width, height, padding, margin the same way.
551 - */
552 - $shared_properties = [
553 - 'width' => [
554 - 'prefix_only' => true
555 - ],
556 - 'height' => [
557 - 'prefix_only' => true
558 - ],
559 - 'padding' => [],
560 - 'margin' => []
561 - ];
562 -
563 - foreach ($shared_properties as $prop => $prop_settings)
564 - {
565 - $prop_data = (array) $box->params->get($prop . '_control.' . $prop, []);
566 -
567 - $prefix_only = isset($prop_settings['prefix_only']) ? $prop_settings['prefix_only'] : false;
568 -
569 - // assign each device CSS
570 - if (isset($prop_data['tablet']))
571 - {
572 - $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['tablet'], $prop, true, $prefix_only));
573 - }
574 - if (isset($prop_data['mobile']))
575 - {
576 - $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['mobile'], $prop, true, $prefix_only));
577 - }
578 - }
579 -
580 - // border radius requires a special method
581 - $border_radius = (array) $box->params->get('borderradius_control.borderradius', []);
582 - if (isset($border_radius['tablet']))
583 - {
584 - $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['tablet'], true));
585 - }
586 - if (isset($border_radius['mobile']))
587 - {
588 - $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['mobile'], true));
589 - }
590 -
591 - $responsive_css = [
592 - 'tablet' => $tablet,
593 - 'mobile' => $mobile
594 - ];
595 - $box->params->set('responsive_css', $responsive_css);
596 - }
597 -
598 - /**
599 478 * Replaces all box smart tags
600 479 *
601 - * @param object $box
602 - *
603 480 * @return object
604 481 */
605 - public static function replaceBoxSmartTags(&$box)
482 + public function replaceBoxSmartTags()
606 483 {
607 484 $tags = new \FPFramework\Base\SmartTags\SmartTags();
608 485
609 486 // register FB Smart Tags
610 - $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $box);
487 + $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $this->box);
611 488
612 - $box = $tags->replace($box);
489 + $this->box = $tags->replace($this->box);
613 490 }
614 491
615 492 /**
616 493 * Checks if a box passes assignments
617 494 *
618 - * @param object $box
619 - *
620 495 * @return boolean
621 496 */
622 - public function pass($box)
497 + public function pass()
623 498 {
624 - if (!$box || !is_object($box))
499 + if (!$this->box || !is_object($this->box))
625 500 {
626 501 return false;
627 502 }
628 503
629 - // set box settings if empty
630 - if (empty($this->boxSettings))
631 - {
632 - $this->boxSettings = $box;
633 - }
504 + // Check first local assignments
505 + if (!$this->passLocalAssignments())
506 + {
507 + return false;
508 + }
634 509
635 - // Prepare boxes that mirror other boxes assignments
636 - if ($box->params->get('mirror', false) && $mirror_box_id = $box->params->get('mirror_box'))
510 + $displayConditionsType = $this->box->params->get('display_conditions_type', '');
511 +
512 + // If empty, display popup sitewide
513 + if (empty($displayConditionsType) || $displayConditionsType === 'all')
637 514 {
638 - $box->params->merge(self::getAssignmentsForMirroring($mirror_box_id));
515 + return true;
639 516 }
640 -
641 - // Check first local assignments
642 - if (!$this->passLocalAssignments($box))
517 +
518 + // Mirror Display Conditions of another popup.
519 + if ($displayConditionsType == 'mirror' && $mirror_box_id = $this->box->params->get('mirror_box'))
643 520 {
644 - return false;
521 + $this->box->params->merge(self::getAssignmentsForMirroring($mirror_box_id));
645 522 }
646 523
524 + // Get a recursive array of all rules
525 + $rules = json_decode(wp_json_encode($this->box->params->get('rules', [])), true);
526 +
647 527 // If testmode is enabled disable the User Groups assignment
648 - if ($box->params->get('testmode'))
528 + if ($this->box->params->get('testmode'))
649 529 {
650 - $box->params->set('assignments.assign_grouplevel.selection', '0');
651 - }
652 -
653 - $globalAssignments = $this->passGlobalAssignments($box);
654 -
530 + foreach ($rules as $key => &$group)
531 + {
532 + foreach ($group['rules'] as $_key => &$rule)
533 + {
534 + if (!isset($rule['name']) || empty($rule['name']))
535 + {
536 + continue;
537 + }
538 +
539 + if ($rule['name'] === 'WP\UserGroup')
540 + {
541 + unset($group['rules'][$_key]);
542 + }
543 + }
544 + }
545 + }
546 +
655 547 // Check framework based assignments
656 - return $globalAssignments;
548 + return \FPFramework\Base\Conditions\ConditionBuilder::pass($rules, $this->factory);
657 549 }
658 550
659 - /**
660 - * Passes framework based global assignments
661 - *
662 - * @param object $box
663 - *
664 - * @return boolean
665 - */
666 - private function passGlobalAssignments($box)
667 - {
668 - $assignments = new \FPFramework\Base\Assignments($this->factory);
669 - $pass = $assignments->passAll($box, $box->params->get('assignmentMatchingMethod', 'and'));
670 - return $pass;
671 - }
672 -
673 551 /**
674 552 * Check if a box passes local assignments
675 553 *
676 - * @param object $box
677 - *
678 554 * @return boolean
679 555 */
680 - private function passLocalAssignments($box)
556 + private function passLocalAssignments()
681 557 {
682 558 $localAssignments = new \FireBox\Core\FB\Assignments($this, $this->factory);
683 559 return $localAssignments->passAll();
684 560 }
@@ -689,13 +565,13 @@
689 565 * @param int $box_id
690 566 *
691 567 * @return object
692 568 */
693 - private static function getAssignmentsForMirroring($box_id)
569 + private function getAssignmentsForMirroring($box_id)
694 570 {
695 571 $payload = [
696 572 'where' => [
697 - 'ID' => ' = ' . $box_id,
573 + 'ID' => ' = ' . intval($box_id),
698 574 'post_status' => " = 'publish'",
699 575 'post_type' => " = 'firebox'"
700 576 ]
701 577 ];
@@ -700,9 +576,9 @@
700 576 ]
701 577 ];
702 578
703 579 // Load box
704 - if (!$box = firebox()->models->box->getResults($payload))
580 + if (!$box = firebox()->tables->box->getResults($payload))
705 581 {
706 582 return;
707 583 }
708 584
@@ -709,29 +585,11 @@
709 585 $box = $box[0];
710 586
711 587 // get meta options for box
712 588 $meta = get_post_meta($box_id, 'fpframework_meta_settings', true);
713 - $box->params = $meta;
589 + $box->params = new Registry($meta);
714 590
715 - // To prevent user frustration, we ignore the following assignments because they are not displayed in the Publishing Assignments.
716 - $params_to_ignore = [
717 - 'assign_impressions'
718 - ];
719 -
720 - $assignments = [];
721 -
722 - // Gather params to merge
723 - foreach ($box->params as $param_key => $param_value)
724 - {
725 - if (strpos($param_key, 'assign') === false || in_array($param_key, $params_to_ignore))
726 - {
727 - continue;
728 - }
729 -
730 - $assignments[$param_key] = $param_value;
731 - }
732 -
733 - return new Registry($assignments);
591 + return new Registry(['rules' => $box->params->get('rules')]);
734 592 }
735 593
736 594 /**
737 595 * Prefixes the CSS classes
@@ -799,22 +657,10 @@
799 657 }
800 658
801 659 firebox()->log->track($box_id, 2, $box_log_id);
802 660 }
803 -
661 +
804 662 /**
805 - * Get box impressions
806 - *
807 - * @param array $payload
808 - *
809 - * @return array
810 - */
811 - public function getImpressions($payload)
812 - {
813 - return firebox()->models->boxlog->getResults($payload);
814 - }
815 -
816 - /**
817 663 * Get total box impressions
818 664 *
819 665 * @param array $payload
820 666 *
@@ -821,47 +667,48 @@
821 667 * @return array
822 668 */
823 669 public function getTotalImpressions($payload)
824 670 {
825 - return count($this->getImpressions($payload));
671 + $impressions = firebox()->tables->boxlog->getResults($payload);
672 +
673 + return count($impressions);
826 674 }
827 675
828 676 /**
829 - * Return the box settings
677 + * Returns the cookie instance.
830 678 *
831 - * @return object
679 + * @return mixed
832 680 */
833 - public function getBoxSettings()
681 + public function getCookie()
834 682 {
835 - return $this->boxSettings;
683 + if (!$this->box)
684 + {
685 + return;
686 + }
687 +
688 + return new Cookie($this->box->id);
836 689 }
837 690
838 691 /**
839 - * Sets the box settings
692 + * Returns the box.
840 693 *
841 - * @param object $settings
842 - *
843 694 * @return object
844 695 */
845 - public function setBoxSettings($settings)
696 + public function getBox()
846 697 {
847 - $this->boxSettings = $settings;
698 + return $this->box;
848 699 }
849 700
850 701 /**
851 - * Returns the box cookie
702 + * Sets the box.
852 703 *
853 - * @param string $cookie
704 + * @param object $box
854 705 *
855 - * @return mixed
706 + * @return Box
856 707 */
857 - public function getCookie($cookie = null)
708 + public function setBox($box)
858 709 {
859 - $cookie = $cookie ? $cookie : (isset($this->boxSettings->ID) ? $this->boxSettings->ID : null);
860 - if (!isset($cookie))
861 - {
862 - return;
863 - }
864 -
865 - return new Cookie($cookie);
710 + $this->box = $box;
711 +
712 + return $this;
866 713 }
867 714 }