| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.14 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2026 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; |
| @@ -21,31 +21,8 @@ | ||
| 21 | 21 | |
| 22 | 22 | class Boxes |
| 23 | 23 | { |
| 24 | 24 | /** |
| 25 | - * A box instance | |
| 26 | - * | |
| 27 | - * @var Box | |
| 28 | - */ | |
| 29 | - protected $box; | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Factory | |
| 33 | - * | |
| 34 | - * @var Factory | |
| 35 | - */ | |
| 36 | - protected $factory; | |
| 37 | - | |
| 38 | - public function __construct($box = null, $factory = null) | |
| 39 | - { | |
| 40 | - if (!$factory) | |
| 41 | - { | |
| 42 | - $factory = new \FPFramework\Base\Factory(); | |
| 43 | - } | |
| 44 | - $this->factory = $factory; | |
| 45 | - } | |
| 46 | - | |
| 47 | - /** | |
| 48 | 25 | * Render boxes |
| 49 | 26 | * |
| 50 | 27 | * @return string |
| 51 | 28 | */ |
| @@ -55,8 +32,26 @@ | ||
| 55 | 32 | { |
| 56 | 33 | return; |
| 57 | 34 | } |
| 58 | 35 | |
| 36 | + // Session-dependent conditions (Pageviews, Time on Site) are stamped and evaluated | |
| 37 | + // in the browser, so the stamper must run on every page — not just pages where a | |
| 38 | + // campaign renders — for the pageview counter and session start to stay accurate. | |
| 39 | + // | |
| 40 | + // On pages where a campaign does render, the full runtime already contains the | |
| 41 | + // stamper, so only the standalone ~1 KB script is needed elsewhere. The priority | |
| 42 | + // runs late, after the per-box enqueues added from Box::render(). | |
| 43 | + if (BoxHelper::sessionConditionsInUse($boxes)) | |
| 44 | + { | |
| 45 | + add_action('wp_enqueue_scripts', function() | |
| 46 | + { | |
| 47 | + if (!wp_script_is('firebox-main', 'enqueued')) | |
| 48 | + { | |
| 49 | + wp_enqueue_script('firebox-session-stamp'); | |
| 50 | + } | |
| 51 | + }, 100); | |
| 52 | + } | |
| 53 | + | |
| 59 | 54 | return $this->renderAll($boxes); |
| 60 | 55 | } |
| 61 | 56 | |
| 62 | 57 | /** |
| @@ -68,16 +63,62 @@ | ||
| 68 | 63 | */ |
| 69 | 64 | public function renderAll($boxes) |
| 70 | 65 | { |
| 71 | 66 | $html = ''; |
| 72 | - | |
| 73 | - foreach ($boxes as $box) | |
| 67 | + | |
| 68 | + if ($boxes instanceof \WP_Query) | |
| 74 | 69 | { |
| 75 | - $this->prepare($box); | |
| 70 | + if (!$boxes->have_posts()) | |
| 71 | + { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + | |
| 75 | + // Backup global state | |
| 76 | + global $post, $authordata; | |
| 77 | + $originalPost = $post; | |
| 78 | + $originalAuthorData = $authordata; | |
| 79 | + | |
| 80 | + // Setup the post data for our custom query | |
| 81 | + while ($boxes->have_posts()) | |
| 82 | + { | |
| 83 | + $boxes->the_post(); | |
| 76 | 84 | |
| 77 | - $html .= $this->get_output($box); | |
| 85 | + global $post; | |
| 86 | + | |
| 87 | + $this->prepare($post); | |
| 88 | + | |
| 89 | + // If the mode is embed, abort. | |
| 90 | + if ($post->params->get('mode') == 'embed') | |
| 91 | + { | |
| 92 | + continue; | |
| 93 | + } | |
| 94 | + | |
| 95 | + $html .= $this->get_output($post); | |
| 96 | + } | |
| 97 | + | |
| 98 | + // Reset post data | |
| 99 | + wp_reset_postdata(); | |
| 100 | + | |
| 101 | + // Restore global state | |
| 102 | + $post = $originalPost; | |
| 103 | + $authordata = $originalAuthorData; | |
| 78 | 104 | } |
| 105 | + else if (is_array($boxes)) | |
| 106 | + { | |
| 107 | + foreach ($boxes as $box) | |
| 108 | + { | |
| 109 | + $this->prepare($box); | |
| 110 | + | |
| 111 | + // If the mode is embed, abort. | |
| 112 | + if ($box->params->get('mode') == 'embed') | |
| 113 | + { | |
| 114 | + continue; | |
| 115 | + } | |
| 79 | 116 | |
| 117 | + $html .= $this->get_output($box); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 80 | 121 | return $html; |
| 81 | 122 | } |
| 82 | 123 | |
| 83 | 124 | /** |
| @@ -88,10 +129,9 @@ | ||
| 88 | 129 | * @return void |
| 89 | 130 | */ |
| 90 | 131 | private function prepare(&$box) |
| 91 | 132 | { |
| 92 | - // get meta options for box | |
| 93 | - $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true); | |
| 133 | + $meta = BoxHelper::getMeta($box->ID); | |
| 94 | 134 | $box->params = new Registry($meta); |
| 95 | 135 | } |
| 96 | 136 | |
| 97 | 137 | /** |
| @@ -102,9 +142,9 @@ | ||
| 102 | 142 | * @return string |
| 103 | 143 | */ |
| 104 | 144 | private function get_output($box) |
| 105 | 145 | { |
| 106 | - $logged_and_admin = (is_user_logged_in() && current_user_can('manage_options')); | |
| 146 | + $logged_and_admin = (is_user_logged_in() && current_user_can('edit_fireboxes')); | |
| 107 | 147 | |
| 108 | 148 | $testmode = $box->params->get('testmode', false); |
| 109 | 149 | |
| 110 | 150 | // if box is in test mode only logged-in admin users can see it. |
| @@ -112,7 +152,7 @@ | ||
| 112 | 152 | { |
| 113 | 153 | return ''; |
| 114 | 154 | } |
| 115 | 155 | |
| 116 | - return firebox()->box->render($box); | |
| 156 | + return firebox()->box->setBox($box)->render(); | |
| 117 | 157 | } |
| 118 | 158 | } |