PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
← All changes | Inc/Core/Helpers/BoxHelper.php +131 -52 1.0.102.1.39 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.10 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\Helpers;
@@ -20,24 +20,53 @@
20 20
21 21 class BoxHelper
22 22 {
23 23 /**
24 + * Get box meta
25 + *
26 + * @param int $id
27 + *
28 + * @return array
29 + */
30 + public static function getMeta($id)
31 + {
32 + return get_post_meta($id, 'fpframework_meta_settings', true);
33 + }
34 +
35 + /**
24 36 * Gets all Boxes.
25 - * We use get_posts instead of firebox()->tables->box->getResults
26 - * as we need it on Widgets initialization where we don't have the framework
27 - * available yet to query the database with our wrapper
28 37 *
38 + * @param array $status
39 + * @param int $limit
40 + *
29 41 * @return array
30 42 */
31 - public static function getAllBoxes($status = 'publish')
43 + public static function getAllBoxes($status = ['publish'], $limit = -1)
32 44 {
33 - $payload = [
45 + // cache key
46 + $hash = md5('firebox_getAllBoxes_' . implode(',', $status));
47 +
48 + // check cache
49 + if ($data = wp_cache_get($hash))
50 + {
51 + return $data;
52 + }
53 +
54 + $args = [
34 55 'post_status' => $status,
35 56 'post_type' => 'firebox',
36 - 'numberposts' => -1
57 + 'posts_per_page' => $limit
37 58 ];
59 +
60 + // Get the query.
61 + $query = new \WP_Query($args);
38 62
39 - return get_posts($payload);
63 + wp_reset_postdata();
64 +
65 + // set cache
66 + wp_cache_set($hash, $query);
67 +
68 + return $query;
40 69 }
41 70
42 71 /**
43 72 * Retrieves all boxes in a key => value array of ID => title
@@ -50,9 +79,9 @@
50 79 {
51 80 return [];
52 81 }
53 82
54 - return self::produceKeyValueBoxes($boxes);
83 + return self::produceKeyValueBoxes($boxes->posts);
55 84 }
56 85
57 86 /**
58 87 * Produce a key,value pair of boxes containg their ID,title
@@ -219,48 +248,58 @@
219 248 return $params;
220 249 }
221 250
222 251 /**
223 - * Finds and returns the box from $_GET['template']
252 + * Returns the box template from the URL using the "template" query string.
224 253 *
225 - * @return mixed
254 + * @return array
226 255 */
227 - public static function getBoxFromTemplate()
256 + public static function getBoxFromTemplateURL()
228 257 {
229 - $template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : '';
230 -
231 - if (empty($template))
258 + if (!isset($_GET['fpf_use_template'])) //phpcs:ignore WordPress.Security.NonceVerification.Recommended
232 259 {
233 - return '';
260 + return;
234 261 }
235 262
236 - return firebox()->library->find($template);
237 - }
238 -
239 - /**
240 - * Transforms an array of key,value to inline CSS
241 - *
242 - * @param array $array
243 - *
244 - * @return string
245 - */
246 - public static function arrayToCSSS($array)
247 - {
248 - $array = array_filter($array);
263 + // $template must be an integer
264 + $template = isset($_GET['template']) ? intval($_GET['template']) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Recommended
265 + if (empty($template) || $template === 'blank')
266 + {
267 + return;
268 + }
269 +
270 + $local_template_path = \FPFramework\Helpers\WPHelper::getPluginUploadsDirectory('firebox', 'templates') . '/template.json';
271 + if (!file_exists($local_template_path))
272 + {
273 + return;
274 + }
275 +
276 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
277 + $local_template = file_get_contents($local_template_path);
278 + if (!$local_template = json_decode($local_template, true))
279 + {
280 + return;
281 + }
249 282
250 - if (empty($array))
251 - {
252 - return '';
253 - }
283 + if (!isset($local_template['id']))
284 + {
285 + return;
286 + }
254 287
255 - $styles = '';
288 + if (!isset($local_template['template']))
289 + {
290 + return;
291 + }
256 292
257 - foreach ($array as $key => $value)
258 - {
259 - $styles .= $key . ':' . $value . ';';
260 - }
293 + if ((int) $local_template['id'] !== (int) $template)
294 + {
295 + return;
296 + }
261 297
262 - return $styles;
298 + // Find images and save them locally.
299 + $local_template['template']['post_content'] = \FPFramework\Helpers\WPHelper::downloadAndReplaceImages($local_template['template']['post_content']);
300 +
301 + return $local_template;
263 302 }
264 303
265 304 /**
266 305 * Duplicates a box
@@ -290,17 +329,30 @@
290 329 $box = $box[0];
291 330 $box->ID = '';
292 331 $box->post_title = 'Copy of ' . $box->post_title;
293 332 $box->post_status = 'draft';
294 -
333 +
334 + $factory = new \FPFramework\Base\Factory();
335 +
336 + $tz = wp_timezone();
337 + $date_without_tz = $factory->getDate();
338 + $date_with_tz = $factory->getDate()->setTimezone($tz);
339 +
340 + $box->post_date = $date_with_tz->format('Y-m-d H:i:s');
341 + $box->post_date_gmt = $date_without_tz->format('Y-m-d H:i:s');
342 +
343 + Form\Form::ensureUniqueFormIDs($box->post_content);
344 +
345 + // get meta options
346 + $meta = self::getMeta($box_id);
347 +
295 348 // insert new box
296 349 $new_box_id = firebox()->tables->box->insert($box);
297 350
298 - // get meta options
299 - $meta = get_post_meta($box_id, 'fpframework_meta_settings', true);
351 + // add meta options for new box
352 + update_post_meta($new_box_id, 'fpframework_meta_settings', wp_slash($meta));
300 353
301 - // add meta options for new box
302 - update_post_meta($new_box_id, 'fpframework_meta_settings', $meta);
354 + return true;
303 355 }
304 356
305 357 /**
306 358 * Reset Box Stats
@@ -360,9 +412,9 @@
360 412 }
361 413
362 414 foreach ($boxes as $box)
363 415 {
364 - $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true);
416 + $meta = self::getMeta($box->ID);
365 417
366 418 $exported[] = [
367 419 'box' => $box,
368 420 'meta' => $meta
@@ -368,16 +420,15 @@
368 420 'meta' => $meta
369 421 ];
370 422 }
371 423
372 - $string = json_encode($exported);
373 -
374 424 // SET DOCUMENT HEADER
375 - if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#', $_SERVER['HTTP_USER_AGENT']))
425 + $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : '';
426 + if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#', $userAgent))
376 427 {
377 428 $UserBrowser = "Opera";
378 429 }
379 - elseif (preg_match('#MSIE ([0-9].[0-9]{1,2})#', $_SERVER['HTTP_USER_AGENT']))
430 + elseif (preg_match('#MSIE ([0-9].[0-9]{1,2})#', $userAgent))
380 431 {
381 432 $UserBrowser = "IE";
382 433 }
383 434 else
@@ -403,8 +454,36 @@
403 454 header('Pragma: no-cache');
404 455 }
405 456
406 457 // PRINT STRING
407 - echo $string;
408 - die;
458 + echo wp_json_encode($exported);
459 + die();
460 + }
461 +
462 + /**
463 + * Returns the last date viewed of a campaign.
464 + *
465 + * @param int $id
466 + *
467 + * @return string
468 + */
469 + public static function getCampaignLastDateViewed($id = null)
470 + {
471 + if (!$id)
472 + {
473 + return;
474 + }
475 +
476 + $last_date_viewed = firebox()->tables->boxlog->getResults([
477 + 'select' => [
478 + 'date as last_date_viewed'
479 + ],
480 + 'where' => [
481 + 'box' => ' = ' . esc_sql($id),
482 + ],
483 + 'orderby' => ' date desc',
484 + 'limit' => 1
485 + ]);
486 +
487 + return isset($last_date_viewed[0]->last_date_viewed) ? get_date_from_gmt($last_date_viewed[0]->last_date_viewed) : null;
409 488 }
410 489 }