| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.13 Free | |
| 4 | + * @version 2.1.39 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 © 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,48 +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 | { |
| 46 | - $this->init($boxSettings, $factory); | |
| 71 | + if ($box) | |
| 72 | + { | |
| 73 | + $this->box = $this->prepareConstructorBox($box); | |
| 74 | + } | |
| 75 | + | |
| 76 | + if (!$factory) | |
| 77 | + { | |
| 78 | + $factory = new \FPFramework\Base\Factory(); | |
| 79 | + } | |
| 80 | + $this->factory = $factory; | |
| 81 | + | |
| 82 | + $this->params = new Registry(BoxHelper::getParams()); | |
| 47 | 83 | } |
| 48 | 84 | |
| 49 | - public function init($boxSettings = null, $factory = null) | |
| 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) | |
| 50 | 94 | { |
| 51 | - if (!$factory) | |
| 95 | + if (!is_object($box)) | |
| 52 | 96 | { |
| 53 | - $factory = new \FPFramework\Base\Factory(); | |
| 97 | + $box = $this->get($box); | |
| 54 | 98 | } |
| 55 | 99 | |
| 56 | - $this->boxSettings = $boxSettings; | |
| 57 | - $this->factory = $factory; | |
| 100 | + return $box; | |
| 58 | 101 | } |
| 59 | 102 | |
| 60 | 103 | /** |
| 61 | - * Gets published box. | |
| 104 | + * Get a box. | |
| 62 | 105 | * |
| 63 | - * @param integer $id | |
| 64 | - * @param string $status | |
| 106 | + * @param int $id | |
| 107 | + * @param string $status | |
| 65 | 108 | * |
| 66 | - * @return array | |
| 109 | + * @return object | |
| 67 | 110 | */ |
| 68 | - public function get($id, $status = null) | |
| 111 | + public function get($id = null, $status = null) | |
| 69 | 112 | { |
| 113 | + if (!$id) | |
| 114 | + { | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + | |
| 70 | 118 | $payload = [ |
| 71 | 119 | 'where' => [ |
| 72 | - 'ID' => ' = ' . esc_sql($id), | |
| 120 | + 'ID' => ' = ' . esc_sql(intval($id)), | |
| 73 | 121 | 'post_type' => " = 'firebox'" |
| 74 | 122 | ] |
| 75 | 123 | ]; |
| 76 | 124 | |
| @@ -89,155 +137,135 @@ | ||
| 89 | 137 | { |
| 90 | 138 | return []; |
| 91 | 139 | } |
| 92 | 140 | |
| 93 | - $box = $box[0]; | |
| 141 | + $this->box = $box[0]; | |
| 94 | 142 | |
| 95 | 143 | // get meta options for box |
| 96 | - $meta = self::getMeta($id); | |
| 97 | - $box->params = new Registry($meta); | |
| 144 | + $meta = \FireBox\Core\Helpers\BoxHelper::getMeta($id); | |
| 145 | + $this->box->params = new Registry($meta); | |
| 98 | 146 | |
| 99 | - return $box; | |
| 147 | + return $this->box; | |
| 100 | 148 | } |
| 101 | 149 | |
| 102 | 150 | /** |
| 103 | - * Get box meta | |
| 151 | + * Renders the box. | |
| 104 | 152 | * |
| 105 | - * @param int $id | |
| 106 | - * | |
| 107 | - * @return array | |
| 153 | + * @return void | |
| 108 | 154 | */ |
| 109 | - public static function getMeta($id) | |
| 155 | + public function render() | |
| 110 | 156 | { |
| 111 | - 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; | |
| 112 | 202 | } |
| 113 | 203 | |
| 114 | - /** | |
| 115 | - * Render box | |
| 116 | - * | |
| 117 | - * @return string | |
| 118 | - */ | |
| 119 | - public function render($box = null) | |
| 204 | + public function renderEmbed() | |
| 120 | 205 | { |
| 121 | - // we do not have a passed box or box settings from constructor, abort | |
| 122 | - // as we cannot render a box without any box parameters | |
| 123 | - if (!$box && !$this->boxSettings) | |
| 124 | - { | |
| 125 | - return; | |
| 206 | + // Check Publishing Assignments | |
| 207 | + if (!$this->pass()) | |
| 208 | + { | |
| 209 | + return false; | |
| 126 | 210 | } |
| 127 | 211 | |
| 128 | - // if a box was given to the function, use these settings instead | |
| 129 | - if ($box) | |
| 130 | - { | |
| 131 | - $this->boxSettings = $box; | |
| 132 | - } | |
| 212 | + /** | |
| 213 | + * Runs before rendering the box. | |
| 214 | + */ | |
| 215 | + do_action('firebox/box/before_render', $this->box); | |
| 133 | 216 | |
| 134 | - // if we have box settings, then set up our box with these settings | |
| 135 | - if ($this->boxSettings) | |
| 136 | - { | |
| 137 | - $box = $this->boxSettings; | |
| 138 | - } | |
| 217 | + $this->prepare(); | |
| 218 | + | |
| 219 | + // Loads all media files. | |
| 220 | + $this->loadBoxMedia($this->box); | |
| 139 | 221 | |
| 140 | - // Check Publishing Assignments | |
| 141 | - if (!$this->pass($box)) | |
| 142 | - { | |
| 143 | - return; | |
| 144 | - } | |
| 222 | + $css = $this->getCustomCSS(); | |
| 145 | 223 | |
| 146 | - // get settings params | |
| 147 | - $params = BoxHelper::getParams(); | |
| 224 | + wp_register_style('fireboxStyle', false); | |
| 225 | + wp_enqueue_style('fireboxStyle'); | |
| 148 | 226 | |
| 149 | - if (!did_action('wp_enqueue_scripts')) | |
| 227 | + // Load CSS | |
| 228 | + if ($css) | |
| 150 | 229 | { |
| 151 | - /** | |
| 152 | - * Loads all media files. | |
| 153 | - */ | |
| 154 | - add_action('wp_enqueue_scripts', function() use ($box, $params) { | |
| 155 | - // load box media | |
| 156 | - $this->loadBoxMedia($box, $params); | |
| 157 | - }); | |
| 230 | + wp_add_inline_style('fireboxStyle', $css); | |
| 158 | 231 | } |
| 159 | - else | |
| 160 | - { | |
| 161 | - // load box media | |
| 162 | - $this->loadBoxMedia($box, $params); | |
| 163 | - } | |
| 164 | 232 | |
| 165 | - self::prepare($box); | |
| 166 | - | |
| 167 | - if (!did_action('wp_head')) | |
| 168 | - { | |
| 169 | - /** | |
| 170 | - * Custom CSS | |
| 171 | - */ | |
| 172 | - add_action('wp_head', function() use ($box) { | |
| 173 | - if ($css = $this->getCustomCSS($box)) | |
| 174 | - { | |
| 175 | - echo '<style type="text/css" class="fb-' . esc_attr($box->ID) . '-style fb-responsive-style">' . $css . '</style>'; | |
| 176 | - } | |
| 177 | - }); | |
| 178 | - } | |
| 179 | - else | |
| 180 | - { | |
| 181 | - if ($css = $this->getCustomCSS($box)) | |
| 182 | - { | |
| 183 | - echo '<style type="text/css" class="fb-' . esc_attr($box->ID) . '-style fb-responsive-style">' . $css . '</style>'; | |
| 184 | - } | |
| 185 | - } | |
| 186 | 233 | |
| 187 | - /** | |
| 188 | - * Runs before rendering the box. | |
| 189 | - */ | |
| 190 | - 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); | |
| 191 | 237 | |
| 192 | - // after we prepare it, update box settings | |
| 193 | - $this->boxSettings = $box; | |
| 194 | - | |
| 195 | 238 | // payload |
| 196 | 239 | $payload = [ |
| 197 | - 'box' => $box, | |
| 198 | - 'params' => $params, | |
| 240 | + 'box' => $this->box, | |
| 241 | + 'params' => $this->params, | |
| 199 | 242 | ]; |
| 200 | - | |
| 243 | + | |
| 201 | 244 | // return box template |
| 202 | - add_action('wp_footer', function() use ($box, $payload) { | |
| 203 | - echo firebox()->renderer->public->render('box', $payload, true); | |
| 204 | - }); | |
| 245 | + return $this->getFinalCampaignHTML($payload); | |
| 205 | 246 | } |
| 206 | 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 | + | |
| 207 | 258 | /** |
| 208 | 259 | * Gets the Custom CSS of the popup. |
| 209 | 260 | * |
| 210 | - * @param object $box | |
| 211 | - * | |
| 212 | 261 | * @return string |
| 213 | 262 | */ |
| 214 | - private function getCustomCSS($box) | |
| 263 | + public function getCustomCSS() | |
| 215 | 264 | { |
| 216 | - $css = is_string($box->params->get('customcss')) ? $box->params->get('customcss') : ''; | |
| 265 | + return $this->box->params->get('customcss', ''); | |
| 266 | + } | |
| 217 | 267 | |
| 218 | - // add responsive CSS | |
| 219 | - if ($responsive_css = (array) $box->params->get('responsive_css', [])) | |
| 220 | - { | |
| 221 | - if (isset($responsive_css['tablet']) && !empty($responsive_css['tablet'])) | |
| 222 | - { | |
| 223 | - $css .= ' | |
| 224 | -@media only screen and (max-width: 768px) { | |
| 225 | - .fb-' . esc_attr($box->ID) . ' .fb-dialog { ' . esc_html($responsive_css['tablet']) . ' } | |
| 226 | -}'; | |
| 227 | - } | |
| 228 | - if (isset($responsive_css['mobile']) && !empty($responsive_css['mobile'])) | |
| 229 | - { | |
| 230 | - $css .= ' | |
| 231 | -@media only screen and (max-width: 468px) { | |
| 232 | - .fb-' . esc_attr($box->ID) . ' .fb-dialog { ' . esc_html($responsive_css['mobile']) . ' } | |
| 233 | -}'; | |
| 234 | - } | |
| 235 | - } | |
| 236 | - | |
| 237 | - return $css; | |
| 238 | - } | |
| 239 | - | |
| 240 | 268 | /** |
| 241 | 269 | * Send a helpful object to JavaScript files |
| 242 | 270 | * |
| 243 | 271 | * @return void |
| @@ -249,57 +277,31 @@ | ||
| 249 | 277 | return; |
| 250 | 278 | } |
| 251 | 279 | self::$loadedLocalizedScript = true; |
| 252 | 280 | |
| 253 | - $data = array( | |
| 254 | - 'ajax_url' => admin_url('admin-ajax.php'), | |
| 255 | - 'nonce' => wp_create_nonce('fbox_js_nonce'), | |
| 256 | - 'site_url' => site_url('/'), | |
| 257 | - 'referrer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '' | |
| 258 | - ); | |
| 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 | + ]; | |
| 259 | 287 | |
| 260 | - wp_localize_script('firebox', 'fbox_js_object', $data); | |
| 288 | + wp_add_inline_script('firebox-main', 'const fbox_js_object = ' . wp_json_encode($data), 'before'); | |
| 261 | 289 | } |
| 262 | 290 | |
| 263 | 291 | /** |
| 264 | 292 | * Load Box Media |
| 265 | 293 | * |
| 266 | - * @param array $box | |
| 267 | - * @param array $params | |
| 268 | - * | |
| 269 | 294 | * @return void |
| 270 | 295 | */ |
| 271 | - public function loadBoxMedia($box, $params) | |
| 296 | + public function loadBoxMedia($box) | |
| 272 | 297 | { |
| 273 | 298 | $box = new Registry($box); |
| 274 | - $params = new Registry($params); | |
| 275 | 299 | |
| 276 | 300 | /** |
| 277 | - * We require a CSS handle to register inline styles. | |
| 278 | - * | |
| 279 | - * For this case, we use this dummy style to add inline CSS for our popups | |
| 280 | - * even though the FireBox CSS file may not appear in the page. | |
| 281 | - */ | |
| 282 | - wp_register_style('firebox-custom-styles', false); | |
| 283 | - wp_enqueue_style('firebox-custom-styles'); | |
| 284 | - | |
| 285 | - // Add polyfills for Internet Explorer | |
| 286 | - $browser = $this->factory->getBrowser(); | |
| 287 | - if ($browser && is_array($browser) && array_key_exists('name', $browser) && $browser['name'] == 'ie') | |
| 288 | - { | |
| 289 | - wp_enqueue_script( | |
| 290 | - 'firebox-ie11-polyfill', | |
| 291 | - 'https://polyfill.io/v3/polyfill.min.js?features=NodeList.prototype.forEach%2CElement.prototype.closest%2CArray.prototype.forEach%2CArray.prototype.find%2CIntersectionObserver%2CIntersectionObserverEntry', | |
| 292 | - [], | |
| 293 | - FBOX_VERSION, | |
| 294 | - false | |
| 295 | - ); | |
| 296 | - } | |
| 297 | - | |
| 298 | - /** | |
| 299 | 301 | * Velocity |
| 300 | 302 | */ |
| 301 | - if ($params->get('loadVelocity', true)) | |
| 303 | + if ($this->params->get('loadVelocity', true)) | |
| 302 | 304 | { |
| 303 | 305 | wp_enqueue_script( |
| 304 | 306 | 'firebox-velocity', |
| 305 | 307 | FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js', |
| @@ -304,16 +306,16 @@ | ||
| 304 | 306 | 'firebox-velocity', |
| 305 | 307 | FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.js', |
| 306 | 308 | [], |
| 307 | 309 | FBOX_VERSION, |
| 308 | - false | |
| 310 | + true | |
| 309 | 311 | ); |
| 310 | 312 | wp_enqueue_script( |
| 311 | 313 | 'firebox-velocity-ui', |
| 312 | 314 | FBOX_MEDIA_PUBLIC_URL . 'js/vendor/velocity.ui.js', |
| 313 | - [], | |
| 315 | + ['firebox-velocity'], | |
| 314 | 316 | FBOX_VERSION, |
| 315 | - false | |
| 317 | + true | |
| 316 | 318 | ); |
| 317 | 319 | |
| 318 | 320 | /** |
| 319 | 321 | * Animations |
| @@ -322,11 +324,11 @@ | ||
| 322 | 324 | { |
| 323 | 325 | wp_enqueue_script( |
| 324 | 326 | 'firebox-animations', |
| 325 | 327 | FBOX_MEDIA_PUBLIC_URL . 'js/animations.js', |
| 326 | - [], | |
| 328 | + ['firebox-velocity-ui'], | |
| 327 | 329 | FBOX_VERSION, |
| 328 | - false | |
| 330 | + true | |
| 329 | 331 | ); |
| 330 | 332 | } |
| 331 | 333 | } |
| 332 | 334 | |
| @@ -333,15 +335,23 @@ | ||
| 333 | 335 | /** |
| 334 | 336 | * FireBox JS |
| 335 | 337 | */ |
| 336 | 338 | wp_enqueue_script( |
| 337 | - 'firebox', | |
| 339 | + 'firebox-main', | |
| 338 | 340 | FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js', |
| 339 | 341 | [], |
| 340 | 342 | FBOX_VERSION, |
| 341 | - false | |
| 343 | + true | |
| 342 | 344 | ); |
| 343 | 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 | + | |
| 344 | 354 | // run above the main JS script to run only once |
| 345 | 355 | self::setJSObject(); |
| 346 | 356 | |
| 347 | 357 | /** |
| @@ -346,16 +356,15 @@ | ||
| 346 | 356 | |
| 347 | 357 | /** |
| 348 | 358 | * FireBox CSS |
| 349 | 359 | */ |
| 350 | - if ($params->get('loadCSS', true)) | |
| 360 | + if ($this->params->get('loadCSS', true)) | |
| 351 | 361 | { |
| 352 | 362 | wp_enqueue_style( |
| 353 | 363 | 'firebox', |
| 354 | 364 | FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css', |
| 355 | 365 | [], |
| 356 | - FBOX_VERSION, | |
| 357 | - false | |
| 366 | + FBOX_VERSION | |
| 358 | 367 | ); |
| 359 | 368 | } |
| 360 | 369 | |
| 361 | 370 | /** |
| @@ -365,82 +374,47 @@ | ||
| 365 | 374 | { |
| 366 | 375 | wp_enqueue_script( |
| 367 | 376 | 'firebox-pageslide-mode', |
| 368 | 377 | FBOX_MEDIA_PUBLIC_URL . 'js/pageslide_mode.js', |
| 369 | - [], | |
| 378 | + ['firebox-main'], | |
| 370 | 379 | FBOX_VERSION, |
| 371 | - false | |
| 380 | + true | |
| 372 | 381 | ); |
| 373 | 382 | } |
| 374 | 383 | |
| 375 | 384 | |
| 376 | - | |
| 377 | - $this->loadThemeCSSOverrides(); | |
| 378 | 385 | } |
| 379 | 386 | |
| 380 | 387 | /** |
| 381 | - * Some themes require overrides to preserve as much as we can the styling of the popups. | |
| 382 | - * | |
| 383 | - * @return void | |
| 384 | - */ | |
| 385 | - private function loadThemeCSSOverrides() | |
| 386 | - { | |
| 387 | - $active_theme = wp_get_theme(); | |
| 388 | - $theme = $active_theme->template; | |
| 389 | - | |
| 390 | - /** | |
| 391 | - * This is the listed of the themes that we have created overrides | |
| 392 | - */ | |
| 393 | - $themes = [ | |
| 394 | - 'twentytwentyone' | |
| 395 | - ]; | |
| 396 | - | |
| 397 | - if (!in_array($theme, $themes)) | |
| 398 | - { | |
| 399 | - return; | |
| 400 | - } | |
| 401 | - | |
| 402 | - wp_enqueue_style( | |
| 403 | - 'firebox-theme-' . $theme . '-override', | |
| 404 | - FBOX_MEDIA_PUBLIC_URL . 'css/themes/' . $theme . '.css', | |
| 405 | - [], | |
| 406 | - FBOX_VERSION, | |
| 407 | - false | |
| 408 | - ); | |
| 409 | - } | |
| 410 | - | |
| 411 | - /** | |
| 412 | 388 | * Prepares the box before rendering |
| 413 | 389 | * |
| 414 | - * @param array $box | |
| 415 | - * | |
| 416 | 390 | * @return void |
| 417 | 391 | */ |
| 418 | - public static function prepare(&$box) | |
| 392 | + public function prepare() | |
| 419 | 393 | { |
| 420 | - global $post; | |
| 421 | - $original_post = $post; | |
| 394 | + $this->css = new Styling\CSS($this->box); | |
| 422 | 395 | |
| 423 | - $GLOBALS['post'] = $box; | |
| 424 | - setup_postdata($GLOBALS['post']); | |
| 425 | - | |
| 426 | 396 | $cParam = BoxHelper::getParams(); |
| 427 | 397 | $cParam = new Registry($cParam); |
| 428 | 398 | |
| 429 | - $box->post_content = apply_filters('the_content', $box->post_content); | |
| 430 | - | |
| 431 | - $css_class_prefix = 'fb-'; | |
| 399 | + $this->box->post_content = apply_filters('the_content', $this->box->post_content); | |
| 432 | 400 | |
| 433 | - $position = $box->params->get('position', ''); | |
| 434 | - $position = !is_string($position) ? '' : $position; | |
| 435 | - | |
| 436 | 401 | /* Classes */ |
| 437 | 402 | $css_class = [ |
| 438 | - $box->ID, | |
| 439 | - $position | |
| 403 | + $this->box->ID | |
| 440 | 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 | + } | |
| 441 | 415 | |
| 442 | - $rtl = $box->params->get('rtl', '0'); | |
| 416 | + $rtl = $this->box->params->get('rtl', '0'); | |
| 443 | 417 | if ($rtl == '1') |
| 444 | 418 | { |
| 445 | 419 | $css_class[] = 'rtl'; |
| 446 | 420 | } |
| @@ -446,18 +420,18 @@ | ||
| 446 | 420 | } |
| 447 | 421 | |
| 448 | 422 | self::prefixCSSClasses($css_class); |
| 449 | 423 | |
| 450 | - // class suffix | |
| 451 | - $classSuffix = $box->params->get('classsuffix', ''); | |
| 424 | + // Class suffix | |
| 425 | + $classSuffix = $this->box->params->get('classsuffix', ''); | |
| 452 | 426 | $classSuffix = is_string($classSuffix) ? $classSuffix : ''; |
| 453 | 427 | |
| 454 | 428 | $css_class[] = $classSuffix; |
| 455 | 429 | |
| 456 | - $box->classes = $css_class; | |
| 430 | + $this->box->classes = $css_class; | |
| 457 | 431 | |
| 458 | - // box shadow | |
| 459 | - $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'; | |
| 460 | 434 | |
| 461 | 435 | $dialog_css_classes = [ |
| 462 | 436 | $boxshadow != '0' ? 'shd' . $boxshadow : null |
| 463 | 437 | ]; |
| @@ -462,318 +436,140 @@ | ||
| 462 | 436 | $boxshadow != '0' ? 'shd' . $boxshadow : null |
| 463 | 437 | ]; |
| 464 | 438 | |
| 465 | 439 | // Align Content |
| 466 | - $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')) : []; | |
| 467 | 441 | $dialog_css_classes = array_merge($dialog_css_classes, $aligncontent); |
| 468 | 442 | |
| 469 | 443 | self::prefixCSSClasses($dialog_css_classes); |
| 470 | - $box->dialog_classes = $dialog_css_classes; | |
| 444 | + $this->box->dialog_classes = $dialog_css_classes; | |
| 471 | 445 | |
| 472 | - /* CSS */ | |
| 473 | - // border | |
| 474 | - $border = is_string($box->params->get('bordertype', 'none')) ? $box->params->get('bordertype', 'none') : 'none'; | |
| 475 | - $border_width = $box->params->get('borderwidth.value', 0) ? $box->params->get('borderwidth.value', 0) : 0; | |
| 476 | - $border_unit = is_string($box->params->get('borderwidth.unit', 'px')) ? $box->params->get('borderwidth.unit', 'px') : 0; | |
| 477 | - $border_color = is_string($box->params->get('bordercolor')) ? $box->params->get('bordercolor') : ''; | |
| 478 | - | |
| 479 | - $style = [ | |
| 480 | - 'background' => $box->params->get('backgroundcolor'), | |
| 481 | - 'color' => $box->params->get('textcolor'), | |
| 482 | - 'border' => $border == 'none' ? null : $border . ' ' . $border_width . $border_unit . ' ' . $border_color, | |
| 483 | - ]; | |
| 484 | - | |
| 485 | - // add shared properties | |
| 486 | - $shared_properties = [ | |
| 487 | - 'width' => [ | |
| 488 | - 'prefix_only' => true | |
| 489 | - ], | |
| 490 | - 'height' => [ | |
| 491 | - 'prefix_only' => true | |
| 492 | - ], | |
| 493 | - 'padding' => [], | |
| 494 | - 'margin' => [] | |
| 495 | - ]; | |
| 496 | - foreach ($shared_properties as $prop => $prop_data) | |
| 497 | - { | |
| 498 | - // add dekstop property | |
| 499 | - $value = (array) $box->params->get($prop . '_control.' . $prop, []); | |
| 500 | - if (isset($value['desktop'])) | |
| 501 | - { | |
| 502 | - $prefix_only = isset($prop_data['prefix_only']) ? (bool) $prop_data['prefix_only'] : false; | |
| 503 | - | |
| 504 | - $desktop_value = DimensionsHelper::parseDimensionsData($value['desktop'], $prop, false, $prefix_only); | |
| 505 | - $style = array_merge($style, $desktop_value); | |
| 506 | - } | |
| 507 | - } | |
| 508 | - | |
| 509 | - // add dekstop border_radius | |
| 510 | - $border_radius = (array) $box->params->get('borderradius_control.borderradius', []); | |
| 511 | - if (isset($border_radius['desktop'])) | |
| 512 | - { | |
| 513 | - $desktop_border_radius = DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['desktop']); | |
| 514 | - $style = array_merge($style, $desktop_border_radius); | |
| 515 | - } | |
| 516 | - | |
| 517 | - // Background Image | |
| 518 | - if ($box->params->get('bgimage', false)) | |
| 519 | - { | |
| 520 | - $bgrepeat = is_string($box->params->get('bgrepeat')) ? $box->params->get('bgrepeat') : ''; | |
| 521 | - $bgsize = is_string($box->params->get('bgsize')) ? $box->params->get('bgsize') : ''; | |
| 522 | - $bgposition = is_string($box->params->get('bgposition')) ? $box->params->get('bgposition') : ''; | |
| 523 | - | |
| 524 | - $style['background-image'] = 'url(\'' . esc_url($box->params->get('bgimagefile')) . '\')'; | |
| 525 | - $style['background-repeat'] = strtolower($bgrepeat); | |
| 526 | - $style['background-size'] = strtolower($bgsize); | |
| 527 | - $style['background-position'] = strtolower($bgposition); | |
| 528 | - } | |
| 529 | - | |
| 530 | - $box->style = BoxHelper::arrayToCSSS($style); | |
| 531 | - | |
| 532 | 446 | $trigger_point_methods = [ |
| 533 | - 'pageheight' => 'onScrollDepth', | |
| 534 | - 'element' => 'onElementVisibility', | |
| 535 | - 'pageready' => 'onPageReady', | |
| 447 | + 'pageready' => 'onPageReady', | |
| 536 | 448 | 'pageload' => 'onPageLoad', |
| 537 | - 'userleave' => 'onExit', | |
| 538 | 449 | 'onclick' => 'onClick', |
| 539 | 450 | 'elementHover' => 'onHover', |
| 540 | - 'ondemand' => 'onDemand' | |
| 451 | + 'ondemand' => 'onDemand', | |
| 452 | + | |
| 541 | 453 | ]; |
| 542 | 454 | |
| 543 | 455 | /* Other Settings */ |
| 544 | - $scroll_depth = $box->params->get('scroll_depth', 'percentage'); | |
| 545 | - $scroll_depth = is_string($scroll_depth) ? $scroll_depth : ''; | |
| 456 | + $animation_duration = $this->box->params->get('duration') ? (float) $this->box->params->get('duration') : 0; | |
| 546 | 457 | |
| 547 | - $animation_duration = $box->params->get('duration') ? (float) $box->params->get('duration') : 0; | |
| 548 | - | |
| 458 | + $delay = in_array($this->box->params->get('triggermethod'), ['floatingbutton', 'onexternallink']) ? 0 : (int) $this->box->params->get('triggerdelay') * 1000; | |
| 459 | + | |
| 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 | + | |
| 549 | 464 | // Use Namespaced classes for each trigger point and let them manipulate the settings dynamicaly. |
| 550 | - $box->settings = [ | |
| 551 | - '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'), | |
| 552 | - 'trigger_selector' => $box->params->get('triggerelement'), | |
| 553 | - 'delay' => (int) $box->params->get('triggerdelay') * 1000, | |
| 554 | - 'scroll_depth' => $scroll_depth, | |
| 555 | - 'scroll_depth_value' => $scroll_depth == 'percentage' ? (int) $box->params->get('triggerpercentage') : (int) $box->params->get('scroll_pixel'), | |
| 556 | - 'firing_frequency' => (int) $box->params->get('firing_frequency', 1), | |
| 557 | - 'reverse_scroll_close' => (bool) $box->params->get('autohide'), | |
| 558 | - 'threshold' => (float) $box->params->get('threshold', 0) / 100, | |
| 559 | - 'close_out_viewport' => (bool) $box->params->get('close_out_viewport', false), | |
| 560 | - 'exit_timer' => (int) $box->params->get('exittimer') * 1000, | |
| 561 | - 'idle_time' => (int) $box->params->get('idle_time') * 1000, | |
| 562 | - 'animation_open' => $box->params->get('animationin'), | |
| 563 | - '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'), | |
| 564 | 473 | 'animation_duration' => (float) $animation_duration * 1000, |
| 565 | - 'prevent_default' => (bool) $box->params->get('preventdefault', true), | |
| 566 | - 'backdrop' => (bool) $box->params->get('overlay'), | |
| 567 | - 'backdrop_color' => $box->params->get('overlay_color'), | |
| 568 | - 'backdrop_click' => (bool) $box->params->get('overlayclick'), | |
| 569 | - 'disable_page_scroll' => (bool) $box->params->get('preventpagescroll'), | |
| 570 | - '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'), | |
| 571 | 480 | 'debug' => (bool) $cParam->get('debug', false), |
| 572 | - 'ga_tracking' => (bool) $cParam->get('gaTrack', 0), | |
| 573 | - 'ga_tracking_id' => $cParam->get('gaID', 0), | |
| 574 | - 'ga_tracking_label' => $cParam->get('gaCategory'), | |
| 575 | - 'auto_focus' => (bool) $box->params->get('autofocus', false) | |
| 481 | + 'auto_focus' => (bool) $this->box->params->get('autofocus', false), | |
| 482 | + 'mode' => $this->box->params->get('mode') | |
| 576 | 483 | ]; |
| 577 | 484 | |
| 578 | - $box->styles_container = BoxHelper::arrayToCSSS([ | |
| 579 | - 'z-index' => $box->params->get('zindex', 99999) != 99999 ? $box->params->get('zindex') : null | |
| 580 | - ]); | |
| 485 | + // Apply Popup CSS | |
| 486 | + $this->box->params->set('customcss', $this->box->params->get('customcss') . $this->css->getCSS()); | |
| 581 | 487 | |
| 582 | - // Let's start using CSS vars for each box settings. | |
| 583 | - $cssVars = [ | |
| 584 | - 'animation_duration' => (float) $animation_duration . 's' | |
| 585 | - ]; | |
| 586 | - | |
| 587 | - // Enqueue firebox custom inline CSS | |
| 588 | - $cssVarsForm = self::cssVarsToString($cssVars, '.fb-' . $box->ID); | |
| 589 | - if (!did_action('wp_enqueue_scripts')) | |
| 590 | - { | |
| 591 | - add_action('wp_enqueue_scripts', function() use ($cssVarsForm) { | |
| 592 | - wp_add_inline_style('firebox-custom-styles', $cssVarsForm); | |
| 593 | - }); | |
| 594 | - } | |
| 595 | - else | |
| 596 | - { | |
| 597 | - wp_add_inline_style('firebox-custom-styles', $cssVarsForm); | |
| 598 | - } | |
| 599 | - | |
| 600 | - // set padding and margin for other devices as well | |
| 601 | - self::setResponsiveCSS($box); | |
| 602 | - | |
| 603 | - self::replaceBoxSmartTags($box); | |
| 604 | - | |
| 605 | - $GLOBALS['post'] = $original_post; | |
| 606 | - wp_reset_postdata(); | |
| 488 | + $this->replaceBoxSmartTags(); | |
| 607 | 489 | } |
| 608 | 490 | |
| 609 | 491 | /** |
| 610 | - * Converts an array of CSS variables to its corresponding strings. | |
| 611 | - * | |
| 612 | - * @param array $cssVars | |
| 613 | - * @param string $namespace | |
| 614 | - * | |
| 615 | - * @return string | |
| 616 | - */ | |
| 617 | - private static function cssVarsToString($cssVars, $namespace) | |
| 618 | - { | |
| 619 | - $output = ''; | |
| 620 | - | |
| 621 | - foreach ($cssVars as $key => $value) | |
| 622 | - { | |
| 623 | - $output .= '--' . $key . ': ' . $value . ';' . "\n"; | |
| 624 | - } | |
| 625 | - | |
| 626 | - return $namespace . ' { | |
| 627 | - ' . $output . ' | |
| 628 | - } | |
| 629 | - '; | |
| 630 | - } | |
| 631 | - | |
| 632 | - /** | |
| 633 | - * Sets all responsive CSS to use in box view | |
| 634 | - * | |
| 635 | - * @param object $box | |
| 636 | - * | |
| 637 | - * @return void | |
| 638 | - */ | |
| 639 | - private static function setResponsiveCSS(&$box) | |
| 640 | - { | |
| 641 | - $tablet = ''; | |
| 642 | - $mobile = ''; | |
| 643 | - | |
| 644 | - /** | |
| 645 | - * Handle width, height, padding, margin the same way. | |
| 646 | - */ | |
| 647 | - $shared_properties = [ | |
| 648 | - 'width' => [ | |
| 649 | - 'prefix_only' => true | |
| 650 | - ], | |
| 651 | - 'height' => [ | |
| 652 | - 'prefix_only' => true | |
| 653 | - ], | |
| 654 | - 'padding' => [], | |
| 655 | - 'margin' => [] | |
| 656 | - ]; | |
| 657 | - | |
| 658 | - foreach ($shared_properties as $prop => $prop_settings) | |
| 659 | - { | |
| 660 | - $prop_data = (array) $box->params->get($prop . '_control.' . $prop, []); | |
| 661 | - | |
| 662 | - $prefix_only = isset($prop_settings['prefix_only']) ? $prop_settings['prefix_only'] : false; | |
| 663 | - | |
| 664 | - // assign each device CSS | |
| 665 | - if (isset($prop_data['tablet'])) | |
| 666 | - { | |
| 667 | - $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['tablet'], $prop, true, $prefix_only)); | |
| 668 | - } | |
| 669 | - if (isset($prop_data['mobile'])) | |
| 670 | - { | |
| 671 | - $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsData($prop_data['mobile'], $prop, true, $prefix_only)); | |
| 672 | - } | |
| 673 | - } | |
| 674 | - | |
| 675 | - // border radius requires a special method | |
| 676 | - $border_radius = (array) $box->params->get('borderradius_control.borderradius', []); | |
| 677 | - if (isset($border_radius['tablet'])) | |
| 678 | - { | |
| 679 | - $tablet .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['tablet'], true)); | |
| 680 | - } | |
| 681 | - if (isset($border_radius['mobile'])) | |
| 682 | - { | |
| 683 | - $mobile .= BoxHelper::arrayToCSSS(DimensionsHelper::parseDimensionsBorderRadiusData($border_radius['mobile'], true)); | |
| 684 | - } | |
| 685 | - | |
| 686 | - $responsive_css = [ | |
| 687 | - 'tablet' => $tablet, | |
| 688 | - 'mobile' => $mobile | |
| 689 | - ]; | |
| 690 | - $box->params->set('responsive_css', $responsive_css); | |
| 691 | - } | |
| 692 | - | |
| 693 | - /** | |
| 694 | 492 | * Replaces all box smart tags |
| 695 | 493 | * |
| 696 | - * @param object $box | |
| 697 | - * | |
| 698 | 494 | * @return object |
| 699 | 495 | */ |
| 700 | - public static function replaceBoxSmartTags(&$box) | |
| 496 | + public function replaceBoxSmartTags() | |
| 701 | 497 | { |
| 702 | 498 | $tags = new \FPFramework\Base\SmartTags\SmartTags(); |
| 703 | 499 | |
| 704 | 500 | // register FB Smart Tags |
| 705 | - $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); | |
| 706 | 502 | |
| 707 | - $box = $tags->replace($box); | |
| 503 | + $this->box = $tags->replace($this->box); | |
| 708 | 504 | } |
| 709 | 505 | |
| 710 | 506 | /** |
| 711 | 507 | * Checks if a box passes assignments |
| 712 | 508 | * |
| 713 | - * @param object $box | |
| 714 | - * | |
| 715 | 509 | * @return boolean |
| 716 | 510 | */ |
| 717 | - public function pass($box) | |
| 511 | + public function pass() | |
| 718 | 512 | { |
| 719 | - if (!$box || !is_object($box)) | |
| 513 | + if (!$this->box || !is_object($this->box)) | |
| 720 | 514 | { |
| 721 | 515 | return false; |
| 722 | 516 | } |
| 723 | 517 | |
| 724 | - // set box settings if empty | |
| 725 | - if (empty($this->boxSettings)) | |
| 726 | - { | |
| 727 | - $this->boxSettings = $box; | |
| 728 | - } | |
| 518 | + // Check first local assignments | |
| 519 | + if (!$this->passLocalAssignments()) | |
| 520 | + { | |
| 521 | + return false; | |
| 522 | + } | |
| 729 | 523 | |
| 730 | - // Prepare boxes that mirror other boxes assignments | |
| 731 | - 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') | |
| 732 | 528 | { |
| 733 | - $box->params->merge(self::getAssignmentsForMirroring($mirror_box_id)); | |
| 529 | + return true; | |
| 734 | 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 | + } | |
| 735 | 537 | |
| 736 | - // Check first local assignments | |
| 737 | - 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')) | |
| 738 | 544 | { |
| 739 | - 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 | + } | |
| 740 | 560 | } |
| 741 | 561 | |
| 742 | - // If testmode is enabled disable the User Groups assignment | |
| 743 | - if ($box->params->get('testmode')) | |
| 744 | - { | |
| 745 | - $box->params->set('assignments.assign_grouplevel.selection', '0'); | |
| 746 | - } | |
| 747 | - | |
| 748 | - $globalAssignments = $this->passGlobalAssignments($box); | |
| 749 | - | |
| 750 | - // Check framework based assignments | |
| 751 | - return $globalAssignments; | |
| 562 | + // Check framework based conditions | |
| 563 | + return \FPFramework\Base\Conditions\ConditionBuilder::pass($rules, $this->factory); | |
| 752 | 564 | } |
| 753 | 565 | |
| 754 | - /** | |
| 755 | - * Passes framework based global assignments | |
| 756 | - * | |
| 757 | - * @param object $box | |
| 758 | - * | |
| 759 | - * @return boolean | |
| 760 | - */ | |
| 761 | - private function passGlobalAssignments($box) | |
| 762 | - { | |
| 763 | - $assignments = new \FPFramework\Base\Assignments($this->factory); | |
| 764 | - $pass = $assignments->passAll($box, $box->params->get('assignmentMatchingMethod', 'and')); | |
| 765 | - return $pass; | |
| 766 | - } | |
| 767 | - | |
| 768 | 566 | /** |
| 769 | - * Check if a box passes local assignments | |
| 567 | + * Check if a box passes local conditions | |
| 770 | 568 | * |
| 771 | - * @param object $box | |
| 772 | - * | |
| 773 | 569 | * @return boolean |
| 774 | 570 | */ |
| 775 | - private function passLocalAssignments($box) | |
| 571 | + private function passLocalAssignments() | |
| 776 | 572 | { |
| 777 | 573 | $localAssignments = new \FireBox\Core\FB\Assignments($this, $this->factory); |
| 778 | 574 | return $localAssignments->passAll(); |
| 779 | 575 | } |
| @@ -784,9 +580,9 @@ | ||
| 784 | 580 | * @param int $box_id |
| 785 | 581 | * |
| 786 | 582 | * @return object |
| 787 | 583 | */ |
| 788 | - private static function getAssignmentsForMirroring($box_id) | |
| 584 | + private function getAssignmentsForMirroring($box_id) | |
| 789 | 585 | { |
| 790 | 586 | $payload = [ |
| 791 | 587 | 'where' => [ |
| 792 | 588 | 'ID' => ' = ' . intval($box_id), |
| @@ -804,29 +600,11 @@ | ||
| 804 | 600 | $box = $box[0]; |
| 805 | 601 | |
| 806 | 602 | // get meta options for box |
| 807 | 603 | $meta = get_post_meta($box_id, 'fpframework_meta_settings', true); |
| 808 | - $box->params = $meta; | |
| 604 | + $box->params = new Registry($meta); | |
| 809 | 605 | |
| 810 | - // To prevent user frustration, we ignore the following assignments because they are not displayed in the Publishing Assignments. | |
| 811 | - $params_to_ignore = [ | |
| 812 | - 'assign_impressions' | |
| 813 | - ]; | |
| 814 | - | |
| 815 | - $assignments = []; | |
| 816 | - | |
| 817 | - // Gather params to merge | |
| 818 | - foreach ($box->params as $param_key => $param_value) | |
| 819 | - { | |
| 820 | - if (strpos($param_key, 'assign') === false || in_array($param_key, $params_to_ignore)) | |
| 821 | - { | |
| 822 | - continue; | |
| 823 | - } | |
| 824 | - | |
| 825 | - $assignments[$param_key] = $param_value; | |
| 826 | - } | |
| 827 | - | |
| 828 | - return new Registry($assignments); | |
| 606 | + return new Registry(['rules' => $box->params->get('rules')]); | |
| 829 | 607 | } |
| 830 | 608 | |
| 831 | 609 | /** |
| 832 | 610 | * Prefixes the CSS classes |
| @@ -894,69 +672,85 @@ | ||
| 894 | 672 | } |
| 895 | 673 | |
| 896 | 674 | firebox()->log->track($box_id, 2, $box_log_id); |
| 897 | 675 | } |
| 898 | - | |
| 676 | + | |
| 899 | 677 | /** |
| 900 | - * Get box impressions | |
| 678 | + * Get total box impressions | |
| 901 | 679 | * |
| 902 | 680 | * @param array $payload |
| 903 | 681 | * |
| 904 | 682 | * @return array |
| 905 | 683 | */ |
| 906 | - public function getImpressions($payload) | |
| 684 | + public function getTotalImpressions($payload) | |
| 907 | 685 | { |
| 908 | - return firebox()->tables->boxlog->getResults($payload); | |
| 686 | + $impressions = firebox()->tables->boxlog->getResults($payload); | |
| 687 | + | |
| 688 | + return count($impressions); | |
| 909 | 689 | } |
| 910 | - | |
| 690 | + | |
| 911 | 691 | /** |
| 912 | - * Get total box impressions | |
| 692 | + * Returns the cookie instance. | |
| 913 | 693 | * |
| 914 | - * @param array $payload | |
| 915 | - * | |
| 916 | - * @return array | |
| 694 | + * @return mixed | |
| 917 | 695 | */ |
| 918 | - public function getTotalImpressions($payload) | |
| 696 | + public function getCookie() | |
| 919 | 697 | { |
| 920 | - return count($this->getImpressions($payload)); | |
| 698 | + if (!$this->box) | |
| 699 | + { | |
| 700 | + return; | |
| 701 | + } | |
| 702 | + | |
| 703 | + return new Cookie($this->box); | |
| 921 | 704 | } |
| 922 | 705 | |
| 923 | 706 | /** |
| 924 | - * Return the box settings | |
| 707 | + * Returns the box. | |
| 925 | 708 | * |
| 926 | 709 | * @return object |
| 927 | 710 | */ |
| 928 | - public function getBoxSettings() | |
| 711 | + public function getBox() | |
| 929 | 712 | { |
| 930 | - return $this->boxSettings; | |
| 713 | + return $this->box; | |
| 931 | 714 | } |
| 932 | 715 | |
| 933 | 716 | /** |
| 934 | - * Sets the box settings | |
| 717 | + * Sets the box. | |
| 935 | 718 | * |
| 936 | - * @param object $settings | |
| 719 | + * @param object $box | |
| 937 | 720 | * |
| 938 | - * @return object | |
| 721 | + * @return Box | |
| 939 | 722 | */ |
| 940 | - public function setBoxSettings($settings) | |
| 723 | + public function setBox($box) | |
| 941 | 724 | { |
| 942 | - $this->boxSettings = $settings; | |
| 725 | + $this->box = $box; | |
| 726 | + | |
| 727 | + return $this; | |
| 943 | 728 | } |
| 944 | 729 | |
| 945 | - /** | |
| 946 | - * Returns the box cookie | |
| 947 | - * | |
| 948 | - * @param string $cookie | |
| 949 | - * | |
| 950 | - * @return mixed | |
| 951 | - */ | |
| 952 | - public function getCookie($cookie = null) | |
| 730 | + public function getParams() | |
| 953 | 731 | { |
| 954 | - $cookie = $cookie ? $cookie : (isset($this->boxSettings->ID) ? $this->boxSettings->ID : null); | |
| 955 | - 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)) | |
| 956 | 750 | { |
| 957 | - return; | |
| 751 | + $this->box->params = $params; | |
| 958 | 752 | } |
| 959 | - | |
| 960 | - return new Cookie($cookie); | |
| 753 | + | |
| 754 | + return $this; | |
| 961 | 755 | } |
| 962 | 756 | } |