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 +124 -68 1.0.42.1.39 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.4 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 © 2021 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,45 +20,51 @@
20 20
21 21 class BoxHelper
22 22 {
23 23 /**
24 - * 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
24 + * Get box meta
28 25 *
26 + * @param int $id
27 + *
29 28 * @return array
30 29 */
31 - public static function getAllBoxes($status = 'publish')
30 + public static function getMeta($id)
32 31 {
33 - $payload = [
34 - 'post_status' => $status,
35 - 'post_type' => 'firebox',
36 - 'numberposts' => -1
37 - ];
38 -
39 - return get_posts($payload);
32 + return get_post_meta($id, 'fpframework_meta_settings', true);
40 33 }
41 34
42 35 /**
43 - * Gets all Boxes WP Query.
36 + * Gets all Boxes.
44 37 *
38 + * @param array $status
39 + * @param int $limit
40 + *
45 41 * @return array
46 42 */
47 - public static function getAllBoxesWPQuery($status = 'publish')
43 + public static function getAllBoxes($status = ['publish'], $limit = -1)
48 44 {
49 - $payload = array(
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 = [
50 55 'post_status' => $status,
51 56 'post_type' => 'firebox',
52 - 'numberposts' => -1
53 - );
54 - $query = new \WP_Query($payload);
57 + 'posts_per_page' => $limit
58 + ];
59 +
60 + // Get the query.
61 + $query = new \WP_Query($args);
62 +
55 63 wp_reset_postdata();
56 64
57 - if (!$query->have_posts())
58 - {
59 - return [];
60 - }
65 + // set cache
66 + wp_cache_set($hash, $query);
61 67
62 68 return $query;
63 69 }
64 70
@@ -73,9 +79,9 @@
73 79 {
74 80 return [];
75 81 }
76 82
77 - return self::produceKeyValueBoxes($boxes);
83 + return self::produceKeyValueBoxes($boxes->posts);
78 84 }
79 85
80 86 /**
81 87 * Produce a key,value pair of boxes containg their ID,title
@@ -197,9 +203,9 @@
197 203 public static function getSelectedSearchItems($items)
198 204 {
199 205 $boxes = firebox()->tables->box->getResults([
200 206 'where' => [
201 - 'ID' => ' IN(' . implode(',', esc_sql($items)) . ')',
207 + 'ID' => ' IN(' . implode(',', array_map('intval', $items)) . ')',
202 208 'post_status' => " = 'publish'",
203 209 'post_type' => " = 'firebox'"
204 210 ]
205 211 ]);
@@ -242,48 +248,58 @@
242 248 return $params;
243 249 }
244 250
245 251 /**
246 - * Finds and returns the box from $_GET['template']
252 + * Returns the box template from the URL using the "template" query string.
247 253 *
248 - * @return mixed
254 + * @return array
249 255 */
250 - public static function getBoxFromTemplate()
256 + public static function getBoxFromTemplateURL()
251 257 {
252 - $template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : '';
253 -
254 - if (empty($template))
258 + if (!isset($_GET['fpf_use_template'])) //phpcs:ignore WordPress.Security.NonceVerification.Recommended
255 259 {
256 - return '';
260 + return;
257 261 }
258 262
259 - return firebox()->library->find($template);
260 - }
261 -
262 - /**
263 - * Transforms an array of key,value to inline CSS
264 - *
265 - * @param array $array
266 - *
267 - * @return string
268 - */
269 - public static function arrayToCSSS($array)
270 - {
271 - $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 + }
272 282
273 - if (empty($array))
274 - {
275 - return '';
276 - }
283 + if (!isset($local_template['id']))
284 + {
285 + return;
286 + }
277 287
278 - $styles = '';
288 + if (!isset($local_template['template']))
289 + {
290 + return;
291 + }
279 292
280 - foreach ($array as $key => $value)
281 - {
282 - $styles .= $key . ':' . $value . ';';
283 - }
293 + if ((int) $local_template['id'] !== (int) $template)
294 + {
295 + return;
296 + }
284 297
285 - 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;
286 302 }
287 303
288 304 /**
289 305 * Duplicates a box
@@ -313,17 +329,30 @@
313 329 $box = $box[0];
314 330 $box->ID = '';
315 331 $box->post_title = 'Copy of ' . $box->post_title;
316 332 $box->post_status = 'draft';
317 -
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 +
318 348 // insert new box
319 349 $new_box_id = firebox()->tables->box->insert($box);
320 350
321 - // get meta options
322 - $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));
323 353
324 - // add meta options for new box
325 - update_post_meta($new_box_id, 'fpframework_meta_settings', $meta);
354 + return true;
326 355 }
327 356
328 357 /**
329 358 * Reset Box Stats
@@ -383,9 +412,9 @@
383 412 }
384 413
385 414 foreach ($boxes as $box)
386 415 {
387 - $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true);
416 + $meta = self::getMeta($box->ID);
388 417
389 418 $exported[] = [
390 419 'box' => $box,
391 420 'meta' => $meta
@@ -391,16 +420,15 @@
391 420 'meta' => $meta
392 421 ];
393 422 }
394 423
395 - $string = json_encode($exported);
396 -
397 424 // SET DOCUMENT HEADER
398 - 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))
399 427 {
400 428 $UserBrowser = "Opera";
401 429 }
402 - 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))
403 431 {
404 432 $UserBrowser = "IE";
405 433 }
406 434 else
@@ -426,8 +454,36 @@
426 454 header('Pragma: no-cache');
427 455 }
428 456
429 457 // PRINT STRING
430 - echo $string;
431 - 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;
432 488 }
433 489 }