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