| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.1.1 Free | |
| 4 | + * @version 2.0.12 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 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; |
| @@ -168,14 +168,16 @@ | ||
| 168 | 168 | |
| 169 | 169 | add_action('wp_enqueue_scripts', function() use ($fbox, $css) { |
| 170 | 170 | // Loads all media files. |
| 171 | 171 | $this->loadBoxMedia($fbox); |
| 172 | - | |
| 172 | + | |
| 173 | 173 | // Load CSS |
| 174 | 174 | if ($css) |
| 175 | 175 | { |
| 176 | 176 | wp_add_inline_style('firebox', $css); |
| 177 | 177 | } |
| 178 | + | |
| 179 | + | |
| 178 | 180 | }); |
| 179 | 181 | |
| 180 | 182 | /** |
| 181 | 183 | * Runs before rendering the box. |
| @@ -220,9 +222,9 @@ | ||
| 220 | 222 | $data = array( |
| 221 | 223 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 222 | 224 | 'nonce' => wp_create_nonce('fbox_js_nonce'), |
| 223 | 225 | 'site_url' => site_url('/'), |
| 224 | - 'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '' | |
| 226 | + 'referrer' => isset($_SERVER['HTTP_REFERER']) ? sanitize_text_field($_SERVER['HTTP_REFERER']) : '' | |
| 225 | 227 | ); |
| 226 | 228 | |
| 227 | 229 | wp_localize_script('firebox', 'fbox_js_object', $data); |
| 228 | 230 | } |
| @@ -372,9 +374,9 @@ | ||
| 372 | 374 | $cParam = BoxHelper::getParams(); |
| 373 | 375 | $cParam = new Registry($cParam); |
| 374 | 376 | |
| 375 | 377 | $this->box->post_content = apply_filters('the_content', $this->box->post_content); |
| 376 | - | |
| 378 | + | |
| 377 | 379 | $position = $this->box->params->get('position', ''); |
| 378 | 380 | $position = !is_string($position) ? '' : $position; |
| 379 | 381 | |
| 380 | 382 | /* Classes */ |
| @@ -413,16 +415,14 @@ | ||
| 413 | 415 | self::prefixCSSClasses($dialog_css_classes); |
| 414 | 416 | $this->box->dialog_classes = $dialog_css_classes; |
| 415 | 417 | |
| 416 | 418 | $trigger_point_methods = [ |
| 417 | - 'pageheight' => 'onScrollDepth', | |
| 418 | - 'element' => 'onElementVisibility', | |
| 419 | - 'pageready' => 'onPageReady', | |
| 419 | + 'pageready' => 'onPageReady', | |
| 420 | 420 | 'pageload' => 'onPageLoad', |
| 421 | - 'userleave' => 'onExit', | |
| 422 | 421 | 'onclick' => 'onClick', |
| 423 | 422 | 'elementHover' => 'onHover', |
| 424 | - 'ondemand' => 'onDemand' | |
| 423 | + 'ondemand' => 'onDemand', | |
| 424 | + | |
| 425 | 425 | ]; |
| 426 | 426 | |
| 427 | 427 | /* Other Settings */ |
| 428 | 428 | $scroll_depth = $this->box->params->get('scroll_depth', 'percentage'); |
| @@ -433,17 +433,10 @@ | ||
| 433 | 433 | // Use Namespaced classes for each trigger point and let them manipulate the settings dynamicaly. |
| 434 | 434 | $this->box->settings = [ |
| 435 | 435 | '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'), |
| 436 | 436 | 'trigger_selector' => $this->box->params->get('triggerelement'), |
| 437 | - 'delay' => (int) $this->box->params->get('triggerdelay') * 1000, | |
| 438 | - 'scroll_depth' => $scroll_depth, | |
| 439 | - 'scroll_depth_value' => $scroll_depth == 'percentage' ? (int) $this->box->params->get('triggerpercentage') : (int) $this->box->params->get('scroll_pixel'), | |
| 440 | - 'firing_frequency' => (int) $this->box->params->get('firing_frequency', 1), | |
| 441 | - 'reverse_scroll_close' => (bool) $this->box->params->get('autohide'), | |
| 442 | - 'threshold' => (float) $this->box->params->get('threshold', 0) / 100, | |
| 443 | - 'close_out_viewport' => (bool) $this->box->params->get('close_out_viewport', false), | |
| 444 | - 'exit_timer' => (int) $this->box->params->get('exittimer') * 1000, | |
| 445 | - 'idle_time' => (int) $this->box->params->get('idle_time') * 1000, | |
| 437 | + 'delay' => $this->box->params->get('triggermethod') === 'floatingbutton' ? 0 : (int) $this->box->params->get('triggerdelay') * 1000, | |
| 438 | + | |
| 446 | 439 | 'animation_open' => $this->box->params->get('animationin'), |
| 447 | 440 | 'animation_close' => $this->box->params->get('animationout'), |
| 448 | 441 | 'animation_duration' => (float) $animation_duration * 1000, |
| 449 | 442 | 'prevent_default' => (bool) $this->box->params->get('preventdefault', true), |
| @@ -452,11 +445,9 @@ | ||
| 452 | 445 | 'backdrop_click' => (bool) $this->box->params->get('overlayclick'), |
| 453 | 446 | 'disable_page_scroll' => (bool) $this->box->params->get('preventpagescroll'), |
| 454 | 447 | 'test_mode' => (bool) $this->box->params->get('testmode'), |
| 455 | 448 | 'debug' => (bool) $cParam->get('debug', false), |
| 456 | - 'ga_tracking' => (bool) $cParam->get('gaTrack', 0), | |
| 457 | - 'ga_tracking_id' => $cParam->get('gaID', 0), | |
| 458 | - 'ga_tracking_label' => $cParam->get('gaCategory'), | |
| 449 | + | |
| 459 | 450 | 'auto_focus' => (bool) $this->box->params->get('autofocus', false) |
| 460 | 451 | ]; |
| 461 | 452 | |
| 462 | 453 | // Apply Popup CSS |
| @@ -491,44 +482,55 @@ | ||
| 491 | 482 | { |
| 492 | 483 | return false; |
| 493 | 484 | } |
| 494 | 485 | |
| 495 | - // Prepare boxes that mirror other boxes assignments | |
| 496 | - if ($this->box->params->get('mirror', false) && $mirror_box_id = $this->box->params->get('mirror_box')) | |
| 486 | + // Check first local assignments | |
| 487 | + if (!$this->passLocalAssignments()) | |
| 497 | 488 | { |
| 498 | - $this->box->params->merge($this->getAssignmentsForMirroring($mirror_box_id)); | |
| 489 | + return false; | |
| 499 | 490 | } |
| 500 | 491 | |
| 501 | - // Check first local assignments | |
| 502 | - if (!$this->passLocalAssignments()) | |
| 492 | + $displayConditionsType = $this->box->params->get('display_conditions_type', ''); | |
| 493 | + | |
| 494 | + // If empty, display popup sitewide | |
| 495 | + if (empty($displayConditionsType) || $displayConditionsType === 'all') | |
| 503 | 496 | { |
| 504 | - return false; | |
| 497 | + return true; | |
| 505 | 498 | } |
| 499 | + | |
| 500 | + // Mirror Display Conditions of another popup. | |
| 501 | + if ($displayConditionsType == 'mirror' && $mirror_box_id = $this->box->params->get('mirror_box')) | |
| 502 | + { | |
| 503 | + $this->box->params->merge(self::getAssignmentsForMirroring($mirror_box_id)); | |
| 504 | + } | |
| 506 | 505 | |
| 506 | + // Get a recursive array of all rules | |
| 507 | + $rules = json_decode(json_encode($this->box->params->get('rules', [])), true); | |
| 508 | + | |
| 507 | 509 | // If testmode is enabled disable the User Groups assignment |
| 508 | 510 | if ($this->box->params->get('testmode')) |
| 509 | 511 | { |
| 510 | - $this->box->params->set('assignments.assign_grouplevel.selection', '0'); | |
| 511 | - } | |
| 512 | - | |
| 513 | - $globalAssignments = $this->passGlobalAssignments(); | |
| 514 | - | |
| 512 | + foreach ($rules as $key => &$group) | |
| 513 | + { | |
| 514 | + foreach ($group['rules'] as $_key => &$rule) | |
| 515 | + { | |
| 516 | + if (!isset($rule['name']) || empty($rule['name'])) | |
| 517 | + { | |
| 518 | + continue; | |
| 519 | + } | |
| 520 | + | |
| 521 | + if ($rule['name'] === 'WP\UserGroup') | |
| 522 | + { | |
| 523 | + unset($group['rules'][$_key]); | |
| 524 | + } | |
| 525 | + } | |
| 526 | + } | |
| 527 | + } | |
| 528 | + | |
| 515 | 529 | // Check framework based assignments |
| 516 | - return $globalAssignments; | |
| 530 | + return \FPFramework\Base\Conditions\ConditionBuilder::pass($rules, $this->factory); | |
| 517 | 531 | } |
| 518 | 532 | |
| 519 | - /** | |
| 520 | - * Passes framework based global assignments | |
| 521 | - * | |
| 522 | - * @return boolean | |
| 523 | - */ | |
| 524 | - private function passGlobalAssignments() | |
| 525 | - { | |
| 526 | - $assignments = new \FPFramework\Base\Assignments($this->factory); | |
| 527 | - $pass = $assignments->passAll($this->box, $this->box->params->get('assignmentMatchingMethod', 'and')); | |
| 528 | - return $pass; | |
| 529 | - } | |
| 530 | - | |
| 531 | 533 | /** |
| 532 | 534 | * Check if a box passes local assignments |
| 533 | 535 | * |
| 534 | 536 | * @return boolean |
| @@ -565,29 +567,11 @@ | ||
| 565 | 567 | $box = $box[0]; |
| 566 | 568 | |
| 567 | 569 | // get meta options for box |
| 568 | 570 | $meta = get_post_meta($box_id, 'fpframework_meta_settings', true); |
| 569 | - $box->params = $meta; | |
| 571 | + $box->params = new Registry($meta); | |
| 570 | 572 | |
| 571 | - // To prevent user frustration, we ignore the following assignments because they are not displayed in the Publishing Assignments. | |
| 572 | - $params_to_ignore = [ | |
| 573 | - 'assign_impressions' | |
| 574 | - ]; | |
| 575 | - | |
| 576 | - $assignments = []; | |
| 577 | - | |
| 578 | - // Gather params to merge | |
| 579 | - foreach ($box->params as $param_key => $param_value) | |
| 580 | - { | |
| 581 | - if (strpos($param_key, 'assign') === false || in_array($param_key, $params_to_ignore)) | |
| 582 | - { | |
| 583 | - continue; | |
| 584 | - } | |
| 585 | - | |
| 586 | - $assignments[$param_key] = $param_value; | |
| 587 | - } | |
| 588 | - | |
| 589 | - return new Registry($assignments); | |
| 573 | + return new Registry(['rules' => $box->params->get('rules')]); | |
| 590 | 574 | } |
| 591 | 575 | |
| 592 | 576 | /** |
| 593 | 577 | * Prefixes the CSS classes |