static function import_forced($force = '') { // conditionally imports old settings only if they exist // see if upgrading from an older version $old_global_options = get_option('si_contact_form_gb'); if ($old_global_options) { // import now require_once FSCF_PATH . 'includes/class-fscf-import.php'; FSCF_Import::import_old_version($force); } else { // old options did not exist self::$global_options = FSCF_Util::get_global_options(); // Is this is a really old version, prior to 2.6.5 (earlier versions did not have global options) $temp = get_option('si_contact_form'); if (!empty($temp)) { FSCF_Util::add_admin_notice(__('<b>Warning</b>: Fast Secure Contact Form cannot import settings because the previous version is too old. Installed as new.', 'si-contact-form'), 'error'); self::$global_options['import_success'] = false; self::$global_options['import_msg'] = true; update_option('fs_contact_global', self::$global_options); } } return; }
static function add_form() { // Add a new form check_admin_referer('fs_contact_options-options', 'fs_options'); self::$global_options = FSCF_Util::get_global_options(); // Find the next form number // When forms are deleted, their form number is NOT reused self::$global_options['form_list'][self::$current_form] = __('New Form', 'si-contact-form'); // 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 // 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'])); update_option('fs_contact_global', self::$global_options); echo '<div id="message" class="updated fade"><p>' . sprintf(__('Form %d has been added.', 'si-contact-form'), self::$current_form) . '</p></div>'; return; }
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 vcita_disable_init_msg($form_params, $global_options) { if ($global_options['vcita_initialized'] == 'true') { echo "<div class='scheduler_not_conected_note'>A confirmation email has been sent to "; echo $form_params['vcita_email']; echo " Please make sure you have received the email.</div><br />"; $glob_options = FSCF_Util::get_global_options(); $glob_options['vcita_initialized'] = 'false'; update_option('fs_contact_global', $glob_options); } }
static function get_contact_list($frm_id, $email_to) { // Returns a list of email contacts for display // $email_to = email to list from form settings if (!self::$global_options) { self::$global_options = FSCF_Util::get_global_options(); } $contacts = array(); $contacts[] = ''; // dummy entry to take up key 0 // Check for a shortcode mail-to value. Allowed shortcode email_to: // Webmaster,user1@example.com (must have name,email) // multiple emails allowed // Webmaster,user1@example.com;user2@example.com if (self::$global_options['enable_php_sessions'] == 'true') { // this feature only works when PHP sessions are enabled if (!empty($_SESSION["fsc_shortcode_email_to_{$frm_id}"]) && preg_match("/,/", $_SESSION["fsc_shortcode_email_to_{$frm_id}"])) { list($key, $value) = preg_split('#(?<!\\\\)\\,#', $_SESSION["fsc_shortcode_email_to_{$frm_id}"]); //string will be split by "," but "\," will be ignored $key = trim(str_replace('\\,', ',', $key)); // "\," changes to "," $value = trim(str_replace(';', ',', $value)); // ";" changes to "," if ($key != '' && $value != '') { $contacts[] = array('CONTACT' => FSCF_Util::clean_input($key), 'EMAIL' => FSCF_Util::clean_input($value)); } } else { unset($_SESSION["fsc_shortcode_email_to_{$frm_id}"]); } } if (count($contacts) == 1) { // Nothing from shortcode, so generate the mail-to list from the settings. // The drop down list array will be made automatically by this code // checks for properly configured Email To: addresses in options. $contacts_test = trim($email_to); if (!preg_match("/,/", $contacts_test)) { if (FSCF_Util::validate_email($contacts_test)) { // user1@example.com $contacts[] = array('CONTACT' => __('Webmaster', 'si-contact-form'), 'EMAIL' => $contacts_test); } } else { $ctf_ct_arr = explode("\n", $contacts_test); if (is_array($ctf_ct_arr)) { foreach ($ctf_ct_arr as $line) { // echo '|'.$line.'|' ; list($key, $value) = preg_split('#(?<!\\\\)\\,#', $line); //string will be split by "," but "\," will be ignored $key = trim(str_replace('\\,', ',', $key)); // "\," changes to "," $value = trim($value); if ($key != '' && $value != '') { if (!preg_match("/;/", $value)) { // just one email here // Webmaster,user1@example.com $value = str_replace('[cc]', '', $value); $value = str_replace('[bcc]', '', $value); if (FSCF_Util::validate_email($value)) { $contacts[] = array('CONTACT' => esc_html($key), 'EMAIL' => $value); } } else { // multiple emails here // Webmaster,user1@example.com;user2@example.com;user3@example.com;[cc]user4@example.com;[bcc]user5@example.com $multi_cc_arr = explode(";", $value); $multi_cc_string = ''; foreach ($multi_cc_arr as $multi_cc) { $multi_cc_t = str_replace('[cc]', '', $multi_cc); $multi_cc_t = str_replace('[bcc]', '', $multi_cc_t); if (FSCF_Util::validate_email($multi_cc_t)) { $multi_cc_string .= "{$multi_cc},"; } } if ($multi_cc_string != '') { // multi cc emails $contacts[] = array('CONTACT' => esc_html($key), 'EMAIL' => rtrim($multi_cc_string, ',')); } } } } // end foreach } // end if (is_array($ctf_ct_arr) ) { } // end else } // end outer if unset($contacts[0]); // remove dummy entry.. the array keys now start with 1 return $contacts; }
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 }