PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.9
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.9
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
firebox / Inc / Core / Controllers / BoxImport.php

BoxImport.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.9, at Inc/Core/Controllers/BoxImport.php

220 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.9 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Controllers;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Base\Form;
20
21 class BoxImport extends BaseController
22 {
23 /**
24 * The form settings name
25 *
26 * @var string
27 */
28 const settings_name = 'firebox_import';
29
30 /**
31 * Render the page content
32 *
33 * @return void
34 */
35 public function render()
36 {
37 // page content
38 add_action('firebox/settings_page', [$this, 'settingsPageContent']);
39
40 // render layout
41 firebox()->renderer->admin->render('pages/settings');
42 }
43
44 /**
45 * Import box
46 *
47 * @param array $input
48 *
49 * @return void
50 */
51 public function processBoxesImport($input)
52 {
53 // run a quick security check
54 if (!check_admin_referer('fpf_form_nonce_firebox_import', 'fpf_form_nonce_firebox_import'))
55 {
56 return; // get out if we didn't click the Activate button
57 }
58
59 if (!isset($_FILES['file']))
60 {
61 return;
62 }
63
64 $file = $_FILES['file'];
65
66 // ensure a file was given
67 if (!is_array($file) || !isset($file['name']) || empty($file['name']))
68 {
69 \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_PLEASE_SELECT_A_FILE_TO_UPLOAD'));
70 return;
71 }
72
73 $ext = explode('.', $file['name']);
74
75 // ensure given file plugin was given
76 if (!in_array($ext[count($ext) - 1], ['fbox']))
77 {
78 \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_PLEASE_CHOOSE_A_VALID_FILE'));
79 return;
80 }
81
82 $publish_all = isset($input['publish_all']) ? $input['publish_all'] : 0;
83
84 // read file contents
85 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
86 $data = file_get_contents($file['tmp_name']);
87
88 // if empty data file then abort
89 if (empty($data))
90 {
91 \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_FILE_EMPTY'));
92 return;
93 }
94
95 $items = json_decode($data, true);
96
97 // Scalar JSON (e.g. "123") is valid JSON but not an export payload
98 if (!$items || !is_array($items))
99 {
100 \FPFramework\Libs\AdminNotice::displayError(firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR'));
101 return;
102 }
103
104 if (is_null($items))
105 {
106 $items = [];
107 }
108
109 if (!$items)
110 {
111 return;
112 }
113
114 // import all boxes
115 if (!$new_box_id = $this->importBoxes($items, $publish_all))
116 {
117 \FPFramework\Libs\AdminNotice::displayError(firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR'));
118 return;
119 }
120
121 \FPFramework\Libs\AdminNotice::displaySuccess(fpframework()->_('FPF_ITEMS_SAVED'));
122 return $new_box_id;
123 }
124
125 /**
126 * Imports boxes data
127 *
128 * @param array $items
129 * @param int $publish_all
130 *
131 * @return boolean
132 */
133 protected function importBoxes($items, $publish_all = 0)
134 {
135 $success = true;
136
137 foreach ($items as $item)
138 {
139 // The .fbox contents are user-supplied; validate the shape before
140 // using it or a hand-edited file fatals instead of erroring.
141 if (!is_array($item) || !isset($item['meta']))
142 {
143 $success = false;
144 break;
145 }
146
147 // get meta
148 $meta = $item['meta'];
149
150 // remote meta from item
151 unset($item['meta']);
152
153 if (!isset($item['box']) || !is_array($item['box']))
154 {
155 $success = false;
156 break;
157 }
158
159 $box = $item['box'];
160
161 if (!isset($box['post_content']) || !is_string($box['post_content']))
162 {
163 $box['post_content'] = '';
164 }
165
166 // remove ID
167 $box['ID'] = '';
168
169 $factory = new \FPFramework\Base\Factory();
170
171 $tz = wp_timezone();
172 $date_without_tz = $factory->getDate();
173 $date_with_tz = $factory->getDate()->setTimezone($tz);
174
175 $box['post_date'] = $date_with_tz->format('Y-m-d H:i:s');
176 $box['post_date_gmt'] = $date_without_tz->format('Y-m-d H:i:s');
177
178 \FireBox\Core\Helpers\Form\Form::ensureUniqueFormIDs($box['post_content']);
179
180 // set publish status
181 if (in_array($publish_all, [0, 1]))
182 {
183 $box['post_status'] = ($publish_all == 0) ? 'draft' : 'publish';
184 }
185
186 // insert new box
187 if (!$new_box_id = firebox()->tables->box->insert((object) $box))
188 {
189 $success = false;
190 break;
191 }
192
193 // add meta options for new box
194 // TODO: In the future, use "firebox_meta". This is a temporary fix for backwards compatibility.
195 $checkMeta = (array) $meta;
196 $meta_key = isset($checkMeta['width']) ? 'firebox_meta' : 'fpframework_meta_settings';
197 update_post_meta($new_box_id, $meta_key, wp_slash($meta));
198 $success = $new_box_id;
199 }
200
201 return $success;
202 }
203
204 /**
205 * What the settings page will contain
206 *
207 * @return void
208 */
209 public function settingsPageContent()
210 {
211 $form = new Form(\FireBox\Core\Admin\Forms\Import::getSettings(), [
212 'fields_name_prefix' => self::settings_name,
213 'section_name' => self::settings_name,
214 'class' => 'settings-ui-inner-fields',
215 'button_label' => 'FPF_IMPORT'
216 ]);
217
218 echo $form->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
219 }
220 }