static function import_old_version($force = '') { // global $fscf_special_slugs; // List of reserve slug names // ***** Import global options ***** // upgrade import only back to version 2.5.6, because before that, there was no 'si_contact_form_gb' setting self::$old_global_options = get_option('si_contact_form_gb'); if (empty(self::$old_global_options)) { return; } //print_r(self::$old_global_options)."<br>\n"; self::$global_options = FSCF_Util::get_global_options(); // import a few global options $copy_fields = array('donated', 'vcita_dismiss'); foreach ($copy_fields as $field) { if (!empty(self::$old_global_options[$field])) { self::$global_options[$field] = self::$old_global_options[$field]; } } // import this global option // Highest form ID (used to assign ID to new form) // When forms are deleted, the remaining forms are NOT renumberd, so max_form_num might be greater than // the number of existing forms if (!empty(self::$old_global_options['max_forms'])) { self::$global_options['max_form_num'] = self::$old_global_options['max_forms']; } //print 'max_form_num:'.self::$global_options['max_form_num']."<br>\n"; // ***** Import form options ***** $max_fields_shim = 8; if ($force == 'force') { // force is when they pressed the button import from 3.xx, they are warned this replaces the 4.xx forms self::$global_options['form_list'] = array(); // delete current form list // delete current 4.xx forms delete_option('fs_contact_global'); // delete up to 100 forms (a unique configuration for each contact form) for ($i = 1; $i <= 100; $i++) { delete_option("fs_contact_form{$i}"); } } for ($frm = 1; $frm <= self::$global_options['max_form_num']; $frm++) { //print 'importing form:'.$frm."<br>\n"; $old_opt_name = 'si_contact_form'; $old_opt_name .= $frm == 1 ? '' : $frm; self::$old_form_options = get_option($old_opt_name); if (!self::$old_form_options) { continue; } if ($force == 'force') { } else { // Make sure that the options for this form doesn't already exist self::$form_options = FSCF_Util::get_form_options($frm, $use_defaults = false); if (self::$form_options) { continue; } } // if max fields is missing it will be 8, or the value of the last one in the loop. if (isset(self::$old_form_options['max_fields']) && self::$old_form_options['max_fields'] > 0) { $max_fields_shim = self::$old_form_options['max_fields']; } else { self::$old_form_options['max_fields'] = $max_fields_shim; } $new_form_options = self::convert_form_options(self::$old_form_options, self::$old_form_options['max_fields']); //print_r($new_form_options)."<br>\n"; // Save the imported form $form_option_name = 'fs_contact_form' . $frm; // Add form name to the form list... if ($new_form_options['form_name'] == '') { $new_form_options['form_name'] = __('imported', 'si-contact-form'); } self::$global_options['form_list'][$frm] = $new_form_options['form_name']; update_option($form_option_name, $new_form_options); } // end for loop (forms) self::$global_options['import_success'] = true; self::$global_options['import_msg'] = true; // recalibrate max_form_num to the highest form number (not count) ksort(self::$global_options['form_list']); self::$global_options['max_form_num'] = max(array_keys(self::$global_options['form_list'])); //print_r(self::$global_options)."<br>\n"; update_option('fs_contact_global', self::$global_options); // Display a notice on the admin page FSCF_Util::add_admin_notice(__('Fast Secure Contact Form has imported settings from the old version.', 'si-contact-form'), 'updated'); // Force reload of global and form options FSCF_Options::unload_options(); }
static function restore_settings() { // restores settings from a contact form settings backup file if (isset($_POST['si_contact_restore_type']) && check_admin_referer('fs_contact_options-options', 'fs_options')) { $bk_form_num = $_POST['si_contact_restore_type']; // form file upload if (isset($_FILES['si_contact_backup_file']) && !empty($_FILES['si_contact_backup_file'])) { $file = $_FILES['si_contact_backup_file']; } else { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file is required.', 'si-contact-form') . '</p></div>'; return; } if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error'] || !is_uploaded_file($file['tmp_name'])) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file upload failed.', 'si-contact-form') . '</p></div>'; return; } if (empty($file['tmp_name'])) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file is required.', 'si-contact-form') . '</p></div>'; return; } // check file type $file_type_pattern = '/\\.txt$/i'; if (!preg_match($file_type_pattern, $file['name'])) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file type not allowed.', 'si-contact-form') . '</p></div>'; return; } // check size $allowed_size = 1048576; // 1mb default if ($file['size'] > $allowed_size) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file size is too large.', 'si-contact-form') . '</p></div>'; return; } // get the uploaded file that contains all the data $ctf_backup_data = file_get_contents($file['tmp_name']); $ctf_backup_data_split = explode("@@@@SPLIT@@@@\r\n", $ctf_backup_data); $ctf_backup_array = unserialize($ctf_backup_data_split[1]); if (!isset($ctf_backup_array) || !is_array($ctf_backup_array) || !isset($ctf_backup_array[0]['backup_type'])) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Backup file contains invalid data.', 'si-contact-form') . '</p></div>'; return; } // Is this uploaded backup set from an older version? // Using the Restore tool, you can restore your backed up forms from 2.8 and newer. //$old_version = 0; //if ( isset($ctf_backup_array[0]['ctf_version']) || isset($ctf_backup_array[0]['captcha_disable_session'])) $old_version = 1; if (isset($ctf_backup_array[0]['fscf_version'])) { $old_version = 0; } if ($old_version) { require_once FSCF_PATH . 'includes/class-fscf-import.php'; } $ctf_backup_type = $ctf_backup_array[0]['backup_type']; unset($ctf_backup_array[0]['backup_type']); // is the uploaded file of the "all" type? if ($ctf_backup_type != 'all' && $bk_form_num == 'all') { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Selected All to restore, but backup file is a single form.', 'si-contact-form') . '</p></div>'; return; } // No errors detected, so restore the form(s) $glob_options = FSCF_Util::get_global_options(); // ********** Restore all ? ********** if ($ctf_backup_type == 'all' && $bk_form_num == 'all') { // all $forms_we_have = count($ctf_backup_array); // is the uploaded file of the "all" type? //if ( !isset( $ctf_backup_array[2] ) || !is_array( $ctf_backup_array[2] ) ) { // did not always work if ($forms_we_have < 2) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Selected All to restore, but backup form is missing.', 'si-contact-form') . '</p></div>'; return; } // import a few global options $copy_fields = array('donated', 'vcita_auto_install', 'vcita_dismiss'); foreach ($copy_fields as $field) { if (!empty($ctf_backup_array[0][$field])) { $glob_options[$field] = $ctf_backup_array[0][$field]; } } // import this global option // Highest form ID (used to assign ID to new form) // When forms are deleted, the remaining forms are NOT renumberd, so max_form_num might be greater than // the number of existing forms if (!empty($ctf_backup_array[0]['max_forms'])) { $glob_options['max_form_num'] = $ctf_backup_array[0]['max_forms']; } foreach ($ctf_backup_array as $id => $settings) { // skip the global options array if (0 == $id) { continue; } if ($old_version) { $settings = FSCF_Import::convert_form_options($settings, $ctf_backup_array[$id]['max_fields']); } if (!get_option("fs_contact_form{$id}")) { add_option("fs_contact_form{$id}", $settings, '', 'yes'); } else { update_option("fs_contact_form{$id}", $settings); } // Update the form name in the global forms list // sometimes the old version had empty form name $glob_options['form_list'][$id] = empty($settings['form_name']) ? 'imported' : $settings['form_name']; } // end foreach // Be sure that the forms are listed in ascending key order // Sort the forms list by key // recalibrate max_form_num to the highest form number (not count) ksort($glob_options['form_list']); $glob_options['max_form_num'] = max(array_keys($glob_options['form_list'])); // XXX uncomment this later? //error_reporting(0); // suppress errors because a different version backup may have uninitialized vars // success echo '<div id="message" class="updated fade"><p>' . __('All form settings have been restored from the backup file.', 'si-contact-form') . '</p></div>'; // end restoring all // ********** Restore single? ********** } else { if (is_numeric($bk_form_num)) { // single // form numbers do not need to match if (!get_option("fs_contact_form{$bk_form_num}")) { echo '<div id="message" class="updated fade"><p>' . __('Restore failed: Form to restore to does not exist.', 'si-contact-form') . '</p></div>'; return; } // is the uploaded file of the "single" type? if (!isset($ctf_backup_array[2]) || !is_array($ctf_backup_array[2])) { $settings = $ctf_backup_array[1]; } else { $settings = $ctf_backup_array[$bk_form_num]; } // "all" backup file // XXX uncomment this later? //error_reporting(0); // suppress errors because a different version backup may have uninitialized vars if ($old_version) { $settings = FSCF_Import::convert_form_options($settings, $ctf_backup_array[1]['max_fields']); } // Update the form name in the global forms list $glob_options['form_list'][$bk_form_num] = $settings['form_name']; update_option("fs_contact_form{$bk_form_num}", $settings); // Success echo '<div id="message" class="updated fade"><p>' . sprintf(__('Form %d settings have been restored from the backup file.', 'si-contact-form'), $bk_form_num) . '</p></div>'; } } // end restoring single // Update the global options to save the updated form list update_option('fs_contact_global', $glob_options); // Force reload of global and form options FSCF_Options::unload_options(); } // end action backup restore }