PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
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 +348 -459 1.0.02.1.39 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.39 Free
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2025 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,136 @@
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);
157 + // Check Publishing Assignments
158 + if (!$this->pass())
159 + {
160 + return false;
161 + }
162 +
163 + $fbox = $this->box;
164 +
165 + /**
166 + * Runs before rendering the box.
167 + */
168 + do_action('firebox/box/before_render', $this->box);
169 +
170 + $this->prepare();
171 +
172 + $css = $this->getCustomCSS();
173 +
174 + add_action('wp_enqueue_scripts', function() use ($fbox, $css) {
175 + // Loads all media files.
176 + $this->loadBoxMedia($fbox);
177 +
178 + // Load CSS
179 + if ($css)
180 + {
181 + wp_add_inline_style('firebox', $css);
182 + }
183 +
184 +
185 + });
186 +
187 + // Allow to manipulate the box before rendering
188 + $this->box = apply_filters('firebox/box/edit', $this->box);
189 +
190 + // payload
191 + $payload = [
192 + 'box' => $this->box,
193 + 'params' => $this->params,
194 + ];
195 +
196 + // print campaign HTML
197 + add_action('wp_footer', function() use ($payload) {
198 + echo $this->getFinalCampaignHTML($payload); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
199 + });
200 +
201 + return true;
107 202 }
108 203
109 - /**
110 - * Render box
111 - *
112 - * @return string
113 - */
114 - public function render($box = null)
204 + public function renderEmbed()
115 205 {
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;
206 + // Check Publishing Assignments
207 + if (!$this->pass())
208 + {
209 + return false;
121 210 }
122 211
123 - // if a box was given to the function, use these settings instead
124 - if ($box)
125 - {
126 - $this->boxSettings = $box;
127 - }
212 + /**
213 + * Runs before rendering the box.
214 + */
215 + do_action('firebox/box/before_render', $this->box);
128 216
129 - // if we have box settings, then set up our box with these settings
130 - if ($this->boxSettings)
131 - {
132 - $box = $this->boxSettings;
133 - }
217 + $this->prepare();
218 +
219 + // Loads all media files.
220 + $this->loadBoxMedia($this->box);
134 221
135 - // Check Publishing Assignments
136 - if (!$this->pass($box))
137 - {
138 - return;
139 - }
222 + $css = $this->getCustomCSS();
140 223
141 - // get settings params
142 - $params = BoxHelper::getParams();
224 + wp_register_style('fireboxStyle', false);
225 + wp_enqueue_style('fireboxStyle');
143 226
144 - if (!did_action('wp_enqueue_scripts'))
227 + // Load CSS
228 + if ($css)
145 229 {
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 - });
230 + wp_add_inline_style('fireboxStyle', $css);
153 231 }
154 - else
155 - {
156 - // load box media
157 - $this->loadBoxMedia($box, $params);
158 - }
159 232
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 233
182 - /**
183 - * Runs before rendering the box.
184 - */
185 - do_action('firebox/box/before_render', $box);
234 +
235 + // Allow to manipulate the box before rendering
236 + $this->box = apply_filters('firebox/box/edit', $this->box);
186 237
187 - // after we prepare it, update box settings
188 - $this->boxSettings = $box;
189 -
190 238 // payload
191 239 $payload = [
192 - 'box' => $box,
193 - 'params' => $params,
240 + 'box' => $this->box,
241 + 'params' => $this->params,
194 242 ];
195 -
243 +
196 244 // return box template
197 - add_action('wp_footer', function() use ($box, $payload) {
198 - echo firebox()->renderer->public->render('box', $payload, true);
199 - });
245 + return $this->getFinalCampaignHTML($payload);
200 246 }
201 -
247 +
248 + public function getFinalCampaignHTML($payload)
249 + {
250 + $html = firebox()->renderer->public->render('box', $payload, true);
251 +
252 + /**
253 + * Runs after rendering the box.
254 + */
255 + return apply_filters('firebox/box/after_render', $html, $payload['box']);
256 + }
257 +
202 258 /**
259 + * Gets the Custom CSS of the popup.
260 + *
261 + * @return string
262 + */
263 + public function getCustomCSS()
264 + {
265 + return $this->box->params->get('customcss', '');
266 + }
267 +
268 + /**
203 269 * Send a helpful object to JavaScript files
204 270 *
205 271 * @return void
206 272 */
@@ -211,48 +277,31 @@
211 277 return;
212 278 }
213 279 self::$loadedLocalizedScript = true;
214 280
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 - );
281 + $data = [
282 + 'ajax_url' => admin_url('admin-ajax.php'),
283 + 'nonce' => wp_create_nonce('fbox_js_nonce'),
284 + 'site_url' => site_url('/'),
285 + 'referrer' => isset($_SERVER['HTTP_REFERER']) ? sanitize_url(wp_unslash($_SERVER['HTTP_REFERER'])) : ''
286 + ];
221 287
222 - wp_localize_script('firebox', 'fbox_js_object', $data);
288 + wp_add_inline_script('firebox-main', 'const fbox_js_object = ' . wp_json_encode($data), 'before');
223 289 }
224 290
225 291 /**
226 292 * Load Box Media
227 293 *
228 - * @param array $box
229 - * @param array $params
230 - *
231 294 * @return void
232 295 */
233 - public function loadBoxMedia($box, $params)
296 + public function loadBoxMedia($box)
234 297 {
235 298 $box = new Registry($box);
236 - $params = new Registry($params);
237 299
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 300 /**
252 301 * Velocity
253 302 */
254 - if ($params->get('loadVelocity', true))
303 + if ($this->params->get('loadVelocity', true))
255 304 {
256 305 wp_enqueue_script(
257 306 'firebox-velocity',
258 307 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js',
@@ -257,16 +306,16 @@
257 306 'firebox-velocity',
258 307 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js',
259 308 [],
260 309 FBOX_VERSION,
261 - false
310 + true
262 311 );
263 312 wp_enqueue_script(
264 313 'firebox-velocity-ui',
265 314 FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.ui.js',
266 - [],
315 + ['firebox-velocity'],
267 316 FBOX_VERSION,
268 - false
317 + true
269 318 );
270 319
271 320 /**
272 321 * Animations
@@ -275,11 +324,11 @@
275 324 {
276 325 wp_enqueue_script(
277 326 'firebox-animations',
278 327 FBOX_MEDIA_PUBLIC_URL . 'js/animations.js',
279 - [],
328 + ['firebox-velocity-ui'],
280 329 FBOX_VERSION,
281 - false
330 + true
282 331 );
283 332 }
284 333 }
285 334
@@ -286,15 +335,23 @@
286 335 /**
287 336 * FireBox JS
288 337 */
289 338 wp_enqueue_script(
290 - 'firebox',
339 + 'firebox-main',
291 340 FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js',
292 341 [],
293 342 FBOX_VERSION,
294 - false
343 + true
295 344 );
296 345
346 + // Add Custom Javascript
347 + $custom_code = $box->get('params.data.customcode', '');
348 + if (is_string($custom_code) && !empty($custom_code))
349 + {
350 + $custom_code = html_entity_decode(stripslashes($custom_code));
351 + wp_add_inline_script('firebox-main', $custom_code, 'after');
352 + }
353 +
297 354 // run above the main JS script to run only once
298 355 self::setJSObject();
299 356
300 357 /**
@@ -299,16 +356,15 @@
299 356
300 357 /**
301 358 * FireBox CSS
302 359 */
303 - if ($params->get('loadCSS', true))
360 + if ($this->params->get('loadCSS', true))
304 361 {
305 362 wp_enqueue_style(
306 363 'firebox',
307 364 FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css',
308 365 [],
309 - FBOX_VERSION,
310 - false
366 + FBOX_VERSION
311 367 );
312 368 }
313 369
314 370 /**
@@ -318,76 +374,47 @@
318 374 {
319 375 wp_enqueue_script(
320 376 'firebox-pageslide-mode',
321 377 FBOX_MEDIA_PUBLIC_URL . 'js/pageslide_mode.js',
322 - [],
378 + ['firebox-main'],
323 379 FBOX_VERSION,
324 - false
380 + true
325 381 );
326 382 }
327 383
328 384
329 -
330 - $this->loadThemeCSSOverrides();
331 385 }
332 386
333 387 /**
334 - * Some themes require overrides to preserve as much as we can the styling of the popups.
388 + * Prepares the box before rendering
335 389 *
336 390 * @return void
337 391 */
338 - private function loadThemeCSSOverrides()
392 + public function prepare()
339 393 {
340 - $active_theme = wp_get_theme();
341 - $theme = $active_theme->template;
394 + $this->css = new Styling\CSS($this->box);
342 395
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 396 $cParam = BoxHelper::getParams();
374 397 $cParam = new Registry($cParam);
375 398
376 - $box->post_content = apply_filters('the_content', $box->post_content);
377 -
378 - $css_class_prefix = 'fb-';
399 + $this->box->post_content = apply_filters('the_content', $this->box->post_content);
379 400
380 - $position = $box->params->get('position', '');
381 - $position = !is_string($position) ? '' : $position;
382 -
383 401 /* Classes */
384 402 $css_class = [
385 - $box->ID,
386 - $position
403 + $this->box->ID
387 404 ];
405 +
406 + if ($this->box->params->get('mode') === 'popup')
407 + {
408 + $position = $this->box->params->get('position', '');
409 + $position = !is_string($position) ? '' : $position;
410 + if ($position)
411 + {
412 + $css_class[] = $position;
413 + }
414 + }
388 415
389 - $rtl = $box->params->get('rtl', '0');
416 + $rtl = $this->box->params->get('rtl', '0');
390 417 if ($rtl == '1')
391 418 {
392 419 $css_class[] = 'rtl';
393 420 }
@@ -393,18 +420,18 @@
393 420 }
394 421
395 422 self::prefixCSSClasses($css_class);
396 423
397 - // class suffix
398 - $classSuffix = $box->params->get('classsuffix', '');
424 + // Class suffix
425 + $classSuffix = $this->box->params->get('classsuffix', '');
399 426 $classSuffix = is_string($classSuffix) ? $classSuffix : '';
400 427
401 428 $css_class[] = $classSuffix;
402 429
403 - $box->classes = $css_class;
430 + $this->box->classes = $css_class;
404 431
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';
432 + // Box shadow
433 + $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 434
408 435 $dialog_css_classes = [
409 436 $boxshadow != '0' ? 'shd' . $boxshadow : null
410 437 ];
@@ -409,276 +436,140 @@
409 436 $boxshadow != '0' ? 'shd' . $boxshadow : null
410 437 ];
411 438
412 439 // Align Content
413 - $aligncontent = is_string($box->params->get('aligncontent')) ? explode(' ', $box->params->get('aligncontent')) : [];
440 + $aligncontent = is_string($this->box->params->get('aligncontent')) ? explode(' ', $this->box->params->get('aligncontent')) : [];
414 441 $dialog_css_classes = array_merge($dialog_css_classes, $aligncontent);
415 442
416 443 self::prefixCSSClasses($dialog_css_classes);
417 - $box->dialog_classes = $dialog_css_classes;
444 + $this->box->dialog_classes = $dialog_css_classes;
418 445
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 446 $trigger_point_methods = [
480 - 'pageheight' => 'onScrollDepth',
481 - 'element' => 'onElementVisibility',
482 - 'pageready' => 'onPageReady',
447 + 'pageready' => 'onPageReady',
483 448 'pageload' => 'onPageLoad',
484 - 'userleave' => 'onExit',
485 449 'onclick' => 'onClick',
486 450 'elementHover' => 'onHover',
487 - 'ondemand' => 'onDemand'
451 + 'ondemand' => 'onDemand',
452 +
488 453 ];
489 454
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 - ]);
455 + /* Other Settings */
456 + $animation_duration = $this->box->params->get('duration') ? (float) $this->box->params->get('duration') : 0;
496 457
497 - /* Other Settings */
498 - $scroll_depth = $box->params->get('scroll_depth', 'percentage');
499 - $scroll_depth = !is_array($scroll_depth) ? $scroll_depth : '';
458 + $delay = in_array($this->box->params->get('triggermethod'), ['floatingbutton', 'onexternallink']) ? 0 : (int) $this->box->params->get('triggerdelay') * 1000;
500 459
501 - $animation_duration = $box->params->get('duration') ? (float) $box->params->get('duration') : 0;
502 -
460 + $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');
461 +
462 + $trigger_element = is_scalar($this->box->params->get('triggerelement', '')) ? $this->box->params->get('triggerelement', '') : '';
463 +
503 464 // 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'),
465 + $this->box->settings = [
466 + 'name' => $this->box->post_title,
467 + 'trigger' => $trigger_method,
468 + 'trigger_selector' => $trigger_method === 'onExternalLink' ? '' : rtrim($trigger_element, ','),
469 + 'delay' => $delay,
470 +
471 + 'animation_open' => $this->box->params->get('animationin'),
472 + 'animation_close' => $this->box->params->get('animationout'),
518 473 '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'),
474 + 'prevent_default' => (bool) $this->box->params->get('preventdefault', true),
475 + 'backdrop' => (bool) $this->box->params->get('overlay'),
476 + 'backdrop_color' => $this->box->params->get('overlay_color'),
477 + 'backdrop_click' => (bool) $this->box->params->get('overlayclick'),
478 + 'disable_page_scroll' => (bool) $this->box->params->get('preventpagescroll'),
479 + 'test_mode' => (bool) $this->box->params->get('testmode'),
525 480 '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')
481 + 'auto_focus' => (bool) $this->box->params->get('autofocus', false),
482 + 'mode' => $this->box->params->get('mode')
529 483 ];
530 484
531 - // set padding and margin for other devices as well
532 - self::setResponsiveCSS($box);
485 + // Apply Popup CSS
486 + $this->box->params->set('customcss', $this->box->params->get('customcss') . $this->css->getCSS());
533 487
534 - self::replaceBoxSmartTags($box);
488 + $this->replaceBoxSmartTags();
535 489 }
536 490
537 491 /**
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 492 * Replaces all box smart tags
600 493 *
601 - * @param object $box
602 - *
603 494 * @return object
604 495 */
605 - public static function replaceBoxSmartTags(&$box)
496 + public function replaceBoxSmartTags()
606 497 {
607 498 $tags = new \FPFramework\Base\SmartTags\SmartTags();
608 499
609 500 // register FB Smart Tags
610 - $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $box);
501 + $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $this->box);
611 502
612 - $box = $tags->replace($box);
503 + $this->box = $tags->replace($this->box);
613 504 }
614 505
615 506 /**
616 507 * Checks if a box passes assignments
617 508 *
618 - * @param object $box
619 - *
620 509 * @return boolean
621 510 */
622 - public function pass($box)
511 + public function pass()
623 512 {
624 - if (!$box || !is_object($box))
513 + if (!$this->box || !is_object($this->box))
625 514 {
626 515 return false;
627 516 }
628 517
629 - // set box settings if empty
630 - if (empty($this->boxSettings))
631 - {
632 - $this->boxSettings = $box;
633 - }
518 + // Check first local assignments
519 + if (!$this->passLocalAssignments())
520 + {
521 + return false;
522 + }
634 523
635 - // Prepare boxes that mirror other boxes assignments
636 - if ($box->params->get('mirror', false) && $mirror_box_id = $box->params->get('mirror_box'))
524 + $displayConditionsType = $this->box->params->get('display_conditions_type', '');
525 +
526 + // If empty, display popup sitewide
527 + if (empty($displayConditionsType) || $displayConditionsType === 'all')
637 528 {
638 - $box->params->merge(self::getAssignmentsForMirroring($mirror_box_id));
529 + return true;
639 530 }
531 +
532 + // Mirror Display Conditions of another popup.
533 + if ($displayConditionsType == 'mirror' && $mirror_box_id = $this->box->params->get('mirror_box'))
534 + {
535 + $this->box->params->merge(self::getAssignmentsForMirroring($mirror_box_id));
536 + }
640 537
641 - // Check first local assignments
642 - if (!$this->passLocalAssignments($box))
538 + // Get a recursive array of all rules
539 + $rules = $this->box->params->get('rules', []);
540 + $rules = is_string($rules) ? json_decode($rules, true) : json_decode(wp_json_encode($rules), true);
541 +
542 + // If testmode is enabled disable the User Groups condition
543 + if ($this->box->params->get('testmode'))
643 544 {
644 - return false;
545 + foreach ($rules as $key => &$group)
546 + {
547 + foreach ($group['rules'] as $_key => &$rule)
548 + {
549 + if (!isset($rule['name']) || empty($rule['name']))
550 + {
551 + continue;
552 + }
553 +
554 + if ($rule['name'] === 'WP\UserGroup')
555 + {
556 + unset($group['rules'][$_key]);
557 + }
558 + }
559 + }
645 560 }
646 561
647 - // If testmode is enabled disable the User Groups assignment
648 - if ($box->params->get('testmode'))
649 - {
650 - $box->params->set('assignments.assign_grouplevel.selection', '0');
651 - }
652 -
653 - $globalAssignments = $this->passGlobalAssignments($box);
654 -
655 - // Check framework based assignments
656 - return $globalAssignments;
562 + // Check framework based conditions
563 + return \FPFramework\Base\Conditions\ConditionBuilder::pass($rules, $this->factory);
657 564 }
658 565
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 566 /**
674 - * Check if a box passes local assignments
567 + * Check if a box passes local conditions
675 568 *
676 - * @param object $box
677 - *
678 569 * @return boolean
679 570 */
680 - private function passLocalAssignments($box)
571 + private function passLocalAssignments()
681 572 {
682 573 $localAssignments = new \FireBox\Core\FB\Assignments($this, $this->factory);
683 574 return $localAssignments->passAll();
684 575 }
@@ -689,13 +580,13 @@
689 580 * @param int $box_id
690 581 *
691 582 * @return object
692 583 */
693 - private static function getAssignmentsForMirroring($box_id)
584 + private function getAssignmentsForMirroring($box_id)
694 585 {
695 586 $payload = [
696 587 'where' => [
697 - 'ID' => ' = ' . $box_id,
588 + 'ID' => ' = ' . intval($box_id),
698 589 'post_status' => " = 'publish'",
699 590 'post_type' => " = 'firebox'"
700 591 ]
701 592 ];
@@ -700,9 +591,9 @@
700 591 ]
701 592 ];
702 593
703 594 // Load box
704 - if (!$box = firebox()->models->box->getResults($payload))
595 + if (!$box = firebox()->tables->box->getResults($payload))
705 596 {
706 597 return;
707 598 }
708 599
@@ -709,29 +600,11 @@
709 600 $box = $box[0];
710 601
711 602 // get meta options for box
712 603 $meta = get_post_meta($box_id, 'fpframework_meta_settings', true);
713 - $box->params = $meta;
604 + $box->params = new Registry($meta);
714 605
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);
606 + return new Registry(['rules' => $box->params->get('rules')]);
734 607 }
735 608
736 609 /**
737 610 * Prefixes the CSS classes
@@ -799,69 +672,85 @@
799 672 }
800 673
801 674 firebox()->log->track($box_id, 2, $box_log_id);
802 675 }
803 -
676 +
804 677 /**
805 - * Get box impressions
678 + * Get total box impressions
806 679 *
807 680 * @param array $payload
808 681 *
809 682 * @return array
810 683 */
811 - public function getImpressions($payload)
684 + public function getTotalImpressions($payload)
812 685 {
813 - return firebox()->models->boxlog->getResults($payload);
686 + $impressions = firebox()->tables->boxlog->getResults($payload);
687 +
688 + return count($impressions);
814 689 }
815 -
690 +
816 691 /**
817 - * Get total box impressions
692 + * Returns the cookie instance.
818 693 *
819 - * @param array $payload
820 - *
821 - * @return array
694 + * @return mixed
822 695 */
823 - public function getTotalImpressions($payload)
696 + public function getCookie()
824 697 {
825 - return count($this->getImpressions($payload));
698 + if (!$this->box)
699 + {
700 + return;
701 + }
702 +
703 + return new Cookie($this->box);
826 704 }
827 705
828 706 /**
829 - * Return the box settings
707 + * Returns the box.
830 708 *
831 709 * @return object
832 710 */
833 - public function getBoxSettings()
711 + public function getBox()
834 712 {
835 - return $this->boxSettings;
713 + return $this->box;
836 714 }
837 715
838 716 /**
839 - * Sets the box settings
717 + * Sets the box.
840 718 *
841 - * @param object $settings
719 + * @param object $box
842 720 *
843 - * @return object
721 + * @return Box
844 722 */
845 - public function setBoxSettings($settings)
723 + public function setBox($box)
846 724 {
847 - $this->boxSettings = $settings;
725 + $this->box = $box;
726 +
727 + return $this;
848 728 }
849 729
850 - /**
851 - * Returns the box cookie
852 - *
853 - * @param string $cookie
854 - *
855 - * @return mixed
856 - */
857 - public function getCookie($cookie = null)
730 + public function getParams()
858 731 {
859 - $cookie = $cookie ? $cookie : (isset($this->boxSettings->ID) ? $this->boxSettings->ID : null);
860 - if (!isset($cookie))
732 + return $this->params;
733 + }
734 +
735 + public function setParams($params)
736 + {
737 + $this->params = $params;
738 +
739 + return $this;
740 + }
741 +
742 + public function getCampaignParams()
743 + {
744 + return isset($this->box->params) ? $this->box->params : null;
745 + }
746 +
747 + public function setCampaignParams($params)
748 + {
749 + if (isset($this->box->params))
861 750 {
862 - return;
751 + $this->box->params = $params;
863 752 }
864 -
865 - return new Cookie($cookie);
753 +
754 + return $this;
866 755 }
867 756 }