| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 3.1.8 Free | |
| 4 | + * @version 2.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2026 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 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\Controllers; |
| @@ -49,25 +49,14 @@ | ||
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | 51 | public function processBoxesImport($input) |
| 52 | 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 | - } | |
| 53 | + $file = $this->getUploadedFile(); | |
| 58 | 54 | |
| 59 | - if (!isset($_FILES['file'])) | |
| 60 | - { | |
| 61 | - return; | |
| 62 | - } | |
| 63 | - | |
| 64 | - $file = $_FILES['file']; | |
| 65 | - | |
| 66 | 55 | // ensure a file was given |
| 67 | 56 | if (!is_array($file) || !isset($file['name']) || empty($file['name'])) |
| 68 | 57 | { |
| 69 | - \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_PLEASE_SELECT_A_FILE_TO_UPLOAD')); | |
| 58 | + add_settings_error(self::settings_name, 'settings_updated', fpframework()->_('FPF_PLEASE_SELECT_A_FILE_TO_UPLOAD'), 'error'); | |
| 70 | 59 | return; |
| 71 | 60 | } |
| 72 | 61 | |
| 73 | 62 | $ext = explode('.', $file['name']); |
| @@ -74,9 +63,9 @@ | ||
| 74 | 63 | |
| 75 | 64 | // ensure given file plugin was given |
| 76 | 65 | if (!in_array($ext[count($ext) - 1], ['fbox'])) |
| 77 | 66 | { |
| 78 | - \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_PLEASE_CHOOSE_A_VALID_FILE')); | |
| 67 | + add_settings_error(self::settings_name, 'settings_updated', fpframework()->_('FPF_PLEASE_CHOOSE_A_VALID_FILE'), 'error'); | |
| 79 | 68 | return; |
| 80 | 69 | } |
| 81 | 70 | |
| 82 | 71 | $publish_all = isset($input['publish_all']) ? $input['publish_all'] : 0; |
| @@ -81,21 +70,20 @@ | ||
| 81 | 70 | |
| 82 | 71 | $publish_all = isset($input['publish_all']) ? $input['publish_all'] : 0; |
| 83 | 72 | |
| 84 | 73 | // read file contents |
| 85 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 86 | - $data = file_get_contents($file['tmp_name']); | |
| 74 | + $data = $this->getUploadedFileContents($file['tmp_name']); | |
| 87 | 75 | |
| 88 | 76 | // if empty data file then abort |
| 89 | 77 | if (empty($data)) |
| 90 | 78 | { |
| 91 | - \FPFramework\Libs\AdminNotice::displayError(fpframework()->_('FPF_FILE_EMPTY')); | |
| 79 | + add_settings_error(self::settings_name, 'settings_updated', fpframework()->_('FPF_FILE_EMPTY'), 'error'); | |
| 92 | 80 | return; |
| 93 | 81 | } |
| 94 | 82 | |
| 95 | 83 | if (!$items = json_decode($data, true)) |
| 96 | 84 | { |
| 97 | - \FPFramework\Libs\AdminNotice::displayError(firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR')); | |
| 85 | + add_settings_error(self::settings_name, 'settings_updated', firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR'), 'error'); | |
| 98 | 86 | return; |
| 99 | 87 | } |
| 100 | 88 | |
| 101 | 89 | if (is_null($items)) |
| @@ -110,17 +98,41 @@ | ||
| 110 | 98 | |
| 111 | 99 | // import all boxes |
| 112 | 100 | if (!$new_box_id = $this->importBoxes($items, $publish_all)) |
| 113 | 101 | { |
| 114 | - \FPFramework\Libs\AdminNotice::displayError(firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR')); | |
| 102 | + add_settings_error(self::settings_name, 'settings_updated', firebox()->_('FB_CAMPAIGN_IMPORT_CONTENTS_ERROR'), 'error'); | |
| 115 | 103 | return; |
| 116 | 104 | } |
| 117 | 105 | |
| 118 | - \FPFramework\Libs\AdminNotice::displaySuccess(fpframework()->_('FPF_ITEMS_SAVED')); | |
| 106 | + add_settings_error(self::settings_name, 'settings_updated', fpframework()->_('FPF_ITEMS_SAVED'), 'success'); | |
| 119 | 107 | return $new_box_id; |
| 120 | 108 | } |
| 121 | 109 | |
| 122 | 110 | /** |
| 111 | + * Returns the uploaded file | |
| 112 | + * | |
| 113 | + * @return mixed | |
| 114 | + */ | |
| 115 | + protected function getUploadedFile() | |
| 116 | + { | |
| 117 | + $file = isset($_FILES['file']) ? $_FILES['file'] : ''; | |
| 118 | + return $file; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Returns the contents of the file | |
| 123 | + * | |
| 124 | + * @param string $tmp_name | |
| 125 | + * | |
| 126 | + * @return string | |
| 127 | + */ | |
| 128 | + protected function getUploadedFileContents($tmp_name) | |
| 129 | + { | |
| 130 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | |
| 131 | + return file_get_contents($tmp_name); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 123 | 135 | * Imports boxes data |
| 124 | 136 | * |
| 125 | 137 | * @param array $items |
| 126 | 138 | * @param int $publish_all |
| @@ -164,10 +176,8 @@ | ||
| 164 | 176 | |
| 165 | 177 | $box['post_date'] = $date_with_tz->format('Y-m-d H:i:s'); |
| 166 | 178 | $box['post_date_gmt'] = $date_without_tz->format('Y-m-d H:i:s'); |
| 167 | 179 | |
| 168 | - \FireBox\Core\Helpers\Form\Form::ensureUniqueFormIDs($box['post_content']); | |
| 169 | - | |
| 170 | 180 | // set publish status |
| 171 | 181 | if (in_array($publish_all, [0, 1])) |
| 172 | 182 | { |
| 173 | 183 | $box['post_status'] = ($publish_all == 0) ? 'draft' : 'publish'; |
| @@ -180,12 +190,9 @@ | ||
| 180 | 190 | break; |
| 181 | 191 | } |
| 182 | 192 | |
| 183 | 193 | // add meta options for new box |
| 184 | - // TODO: In the future, use "firebox_meta". This is a temporary fix for backwards compatibility. | |
| 185 | - $checkMeta = (array) $meta; | |
| 186 | - $meta_key = isset($checkMeta['width']) ? 'firebox_meta' : 'fpframework_meta_settings'; | |
| 187 | - update_post_meta($new_box_id, $meta_key, wp_slash($meta)); | |
| 194 | + update_post_meta($new_box_id, 'fpframework_meta_settings', wp_slash($meta)); | |
| 188 | 195 | $success = $new_box_id; |
| 189 | 196 | } |
| 190 | 197 | |
| 191 | 198 | return $success; |
| @@ -204,7 +211,7 @@ | ||
| 204 | 211 | 'class' => 'settings-ui-inner-fields', |
| 205 | 212 | 'button_label' => 'FPF_IMPORT' |
| 206 | 213 | ]); |
| 207 | 214 | |
| 208 | - echo $form->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 215 | + echo $form->render(); | |
| 209 | 216 | } |
| 210 | 217 | } |