PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.6
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.6
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 +90 -76 1.0.22.0.6 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.2 Free
4 + * @version 2.0.6 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 © 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\Helpers;
@@ -20,45 +20,50 @@
20 20
21 21 class BoxHelper
22 22 {
23 23 /**
24 - * Gets all Boxes.
25 - * We use get_posts instead of firebox()->models->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 + *
45 40 * @return array
46 41 */
47 - public static function getAllBoxesWPQuery($status = 'publish')
42 + public static function getAllBoxes($status = ['publish'])
48 43 {
49 - $payload = array(
44 + // cache key
45 + $hash = md5('firebox_getAllBoxes_' . implode(',', $status));
46 +
47 + // check cache
48 + if ($data = wp_cache_get($hash))
49 + {
50 + return $data;
51 + }
52 +
53 + $args = [
50 54 'post_status' => $status,
51 55 'post_type' => 'firebox',
52 - 'numberposts' => -1
53 - );
54 - $query = new \WP_Query($payload);
56 + 'posts_per_page' => -1
57 + ];
58 +
59 + // Get the query.
60 + $query = new \WP_Query($args);
61 +
55 62 wp_reset_postdata();
56 63
57 - if (!$query->have_posts())
58 - {
59 - return [];
60 - }
64 + // set cache
65 + wp_cache_set($hash, $query);
61 66
62 67 return $query;
63 68 }
64 69
@@ -73,9 +78,9 @@
73 78 {
74 79 return [];
75 80 }
76 81
77 - return self::produceKeyValueBoxes($boxes);
82 + return self::produceKeyValueBoxes($boxes->posts);
78 83 }
79 84
80 85 /**
81 86 * Produce a key,value pair of boxes containg their ID,title
@@ -113,9 +118,9 @@
113 118 {
114 119 return [];
115 120 }
116 121
117 - $boxes = firebox()->models->box->getResults([
122 + $boxes = firebox()->tables->box->getResults([
118 123 'where' => [
119 124 'ID' => ' NOT IN (' . esc_sql($id) . ')',
120 125 'post_status' => " = 'publish'",
121 126 'post_type' => " = 'firebox'"
@@ -147,9 +152,9 @@
147 152 }
148 153
149 154 $box = (int) $box;
150 155
151 - $box = firebox()->models->box->getResults([
156 + $box = firebox()->tables->box->getResults([
152 157 'where' => [
153 158 'ID' => " = '" . esc_sql($box) . "'"
154 159 ]
155 160 ]);
@@ -172,9 +177,9 @@
172 177 }
173 178
174 179 $box = (int) $box;
175 180
176 - $box = firebox()->models->box->getResults([
181 + $box = firebox()->tables->box->getResults([
177 182 'where' => [
178 183 'ID' => " = '" . esc_sql($box) . "'"
179 184 ]
180 185 ]);
@@ -195,11 +200,11 @@
195 200 * @return array
196 201 */
197 202 public static function getSelectedSearchItems($items)
198 203 {
199 - $boxes = firebox()->models->box->getResults([
204 + $boxes = firebox()->tables->box->getResults([
200 205 'where' => [
201 - 'ID' => ' IN(' . implode(',', esc_sql($items)) . ')',
206 + 'ID' => ' IN(' . implode(',', array_map('intval', $items)) . ')',
202 207 'post_status' => " = 'publish'",
203 208 'post_type' => " = 'firebox'"
204 209 ]
205 210 ]);
@@ -242,48 +247,57 @@
242 247 return $params;
243 248 }
244 249
245 250 /**
246 - * Finds and returns the box from $_GET['template']
251 + * Returns the box template from the URL using the "template" query string.
247 252 *
248 - * @return mixed
253 + * @return array
249 254 */
250 - public static function getBoxFromTemplate()
255 + public static function getBoxFromTemplateURL()
251 256 {
252 - $template = isset($_GET['template']) ? sanitize_text_field($_GET['template']) : '';
253 -
254 - if (empty($template))
257 + if (!isset($_GET['fpf_use_template']))
255 258 {
256 - return '';
259 + return;
257 260 }
258 261
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);
262 + // $template must be an integer
263 + $template = isset($_GET['template']) ? intval($_GET['template']) : '';
264 + if (empty($template) || $template === 'blank')
265 + {
266 + return;
267 + }
268 +
269 + $local_template_path = \FPFramework\Helpers\WPHelper::getPluginUploadsDirectory('firebox', 'templates') . '/template.json';
270 + if (!file_exists($local_template_path))
271 + {
272 + return;
273 + }
274 +
275 + $local_template = file_get_contents($local_template_path);
276 + if (!$local_template = json_decode($local_template, true))
277 + {
278 + return;
279 + }
272 280
273 - if (empty($array))
274 - {
275 - return '';
276 - }
281 + if (!isset($local_template['id']))
282 + {
283 + return;
284 + }
277 285
278 - $styles = '';
286 + if (!isset($local_template['template']))
287 + {
288 + return;
289 + }
279 290
280 - foreach ($array as $key => $value)
281 - {
282 - $styles .= $key . ':' . $value . ';';
283 - }
291 + if ((int) $local_template['id'] !== (int) $template)
292 + {
293 + return;
294 + }
284 295
285 - return $styles;
296 + // Find images and save them locally.
297 + $local_template['template']['post_content'] = \FPFramework\Helpers\WPHelper::downloadAndReplaceImages($local_template['template']['post_content']);
298 +
299 + return $local_template;
286 300 }
287 301
288 302 /**
289 303 * Duplicates a box
@@ -294,9 +308,9 @@
294 308 */
295 309 public static function duplicateBox($box_id)
296 310 {
297 311 // get box
298 - $box = firebox()->models->box->getResults([
312 + $box = firebox()->tables->box->getResults([
299 313 'where' => [
300 314 'ID' => " = '" . esc_sql($box_id) . "'",
301 315 'post_status' => " = '" . esc_sql(get_post_status($box_id)) . "'",
302 316 'post_type' => " = 'firebox'"
@@ -313,17 +327,19 @@
313 327 $box = $box[0];
314 328 $box->ID = '';
315 329 $box->post_title = 'Copy of ' . $box->post_title;
316 330 $box->post_status = 'draft';
317 -
318 - // insert new box
319 - $new_box_id = firebox()->models->box->insert($box);
320 331
332 + Form\Form::ensureUniqueFormIDs($box->post_content);
333 +
321 334 // get meta options
322 - $meta = get_post_meta($box_id, 'fpframework_meta_settings', true);
335 + $meta = self::getMeta($box_id);
323 336
337 + // insert new box
338 + $new_box_id = firebox()->tables->box->insert($box);
339 +
324 340 // add meta options for new box
325 - update_post_meta($new_box_id, 'fpframework_meta_settings', $meta);
341 + update_post_meta($new_box_id, 'fpframework_meta_settings', wp_slash($meta));
326 342 }
327 343
328 344 /**
329 345 * Reset Box Stats
@@ -333,16 +349,16 @@
333 349 * @return void
334 350 */
335 351 public static function resetBoxStats($box_ids)
336 352 {
337 - $logs_table = firebox()->models->boxlog->getFullTableName();
338 - $logs_details_table = firebox()->models->boxlogdetails->getFullTableName();
353 + $logs_table = firebox()->tables->boxlog->getFullTableName();
354 + $logs_details_table = firebox()->tables->boxlogdetails->getFullTableName();
339 355
340 356 // delete box logs details
341 - firebox()->models->boxlogdetails->executeRaw("DELETE FROM `$logs_details_table` WHERE log_id IN (SELECT id FROM `$logs_table` WHERE box IN (" . implode(",", $box_ids) . "))");
357 + firebox()->tables->boxlogdetails->executeRaw("DELETE FROM `$logs_details_table` WHERE log_id IN (SELECT id FROM `$logs_table` WHERE box IN (" . implode(",", $box_ids) . "))");
342 358
343 359 // delete box logs
344 - firebox()->models->boxlog->deleteRaw('WHERE box IN (' . implode(',', $box_ids) . ')');
360 + firebox()->tables->boxlog->deleteRaw('WHERE box IN (' . implode(',', $box_ids) . ')');
345 361 }
346 362
347 363 /**
348 364 * Exports boxes
@@ -353,9 +369,9 @@
353 369 */
354 370 public static function exportBoxes($box_ids)
355 371 {
356 372 // get boxes
357 - $boxes = firebox()->models->box->getResults([
373 + $boxes = firebox()->tables->box->getResults([
358 374 'where' => [
359 375 'ID' => ' IN (' . implode(',', esc_sql($box_ids)) . ')',
360 376 'post_type' => " = 'firebox'"
361 377 ]
@@ -383,9 +399,9 @@
383 399 }
384 400
385 401 foreach ($boxes as $box)
386 402 {
387 - $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true);
403 + $meta = self::getMeta($box->ID);
388 404
389 405 $exported[] = [
390 406 'box' => $box,
391 407 'meta' => $meta
@@ -391,10 +407,8 @@
391 407 'meta' => $meta
392 408 ];
393 409 }
394 410
395 - $string = json_encode($exported);
396 -
397 411 // SET DOCUMENT HEADER
398 412 if (preg_match('#Opera(/| )([0-9].[0-9]{1,2})#', $_SERVER['HTTP_USER_AGENT']))
399 413 {
400 414 $UserBrowser = "Opera";
@@ -426,8 +440,8 @@
426 440 header('Pragma: no-cache');
427 441 }
428 442
429 443 // PRINT STRING
430 - echo $string;
431 - die;
444 + echo wp_json_encode($exported);
445 + die();
432 446 }
433 447 }