static function define_ads()
    {
        // HTML code for new ads should be added to this array as strings
        // The optimum size is 300 x 250px (set in fscf-styles-admin.css)
        $vcita = '	<a href="' . admin_url('plugins.php?page=si-contact-form/si-contact-form.php&amp;fscf_form=' . self::$current_form) . '&fscf_tab=7">
        <img src="' . plugins_url('si-contact-form/includes/images/vcita_banner.jpg') . '" class="fscf_centered" /></a>
';
        $sharasale1 = '  <a href="http://www.shareasale.com/r.cfm?b=415758&u=861636&m=41388&urllink=&afftrack=" target="_blank">
        <img src="' . plugins_url('si-contact-form/includes/images/Feature-Fast-300x250.jpeg') . '" class="fscf_centered" /></a>
';
        $sharasale2 = '  <a href="http://www.shareasale.com/r.cfm?b=415758&u=861636&m=41388&urllink=&afftrack=" target="_blank">
        <img src="' . plugins_url('si-contact-form/includes/images/WPE_Orange_300x250.jpg') . '" class="fscf_centered" /></a>
';
        $sharasale3 = '  <a href="http://www.shareasale.com/r.cfm?b=415758&u=861636&m=41388&urllink=&afftrack=" target="_blank">
        <img src="' . plugins_url('si-contact-form/includes/images/WPE_New_300x250.jpg') . '" class="fscf_centered" /></a>
';
        $hostgator = '
        ' . sprintf(__('"I recommend <a href="%s" target="_blank">HostGator Web Hosting</a>. All my sites are hosted there. The prices are great and they offer compatibility for WordPress. If you click this link and start an account at HostGator, I get a small commission." - Mike Challis', 'si-contact-form'), 'http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=mchallis-fscwp&amp;page=http://www.hostgator.com/apps/wordpress-hosting.shtml') . '
    <a href="http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=mchallis-fscwp&amp;page=http://www.hostgator.com/apps/wordpress-hosting.shtml" target="_blank"><img title="' . esc_attr(__('Web Site Hosting', 'si-contact-form')) . '" alt="' . esc_attr(__('Web Site Hosting', 'si-contact-form')) . '" src="' . plugins_url('si-contact-form/includes/images/hostgator-blog.gif') . '" width="100" height="100" /></a>
';
        $show_vcita = 0;
        if (self::$form_options['vcita_scheduling_button'] != 'true') {
            $show_vcita = 1;
        }
        self::$ads = array();
        if ($show_vcita) {
            self::$ads[] = $vcita;
        }
        self::$ads[] = $sharasale1;
        self::$ads[] = $hostgator;
        if ($show_vcita) {
            self::$ads[] = $vcita;
        }
        self::$ads[] = $sharasale2;
        self::$ads[] = $hostgator;
        if ($show_vcita) {
            self::$ads[] = $vcita;
        }
        self::$ads[] = $sharasale3;
        self::$ads[] = $hostgator;
    }
 static function reset_form()
 {
     // Reset the current form to the defaults, but preserve the name
     check_admin_referer('fs_contact_options-options', 'fs_options');
     self::get_options();
     $form_name = self::$form_options['form_name'];
     self::$form_options = self::$form_defaults;
     self::$form_options['form_name'] = $form_name;
     update_option(self::$form_option_name, self::$form_options);
     echo '<div id="message" class="updated fade"><p>' . sprintf(__('Form %d has been reset to the default settings.', 'si-contact-form'), self::$current_form) . '</p></div>';
 }
Example #3
0
 static function convert_form_options($old_options, $max_fields)
 {
     // Converts form options from version 3.x to 4.x
     // Returns converted options array
     global $fscf_special_slugs;
     // List of reserve slug names
     //print_r($old_options); exit;
     // Start with the current version form defaults
     $new_options = FSCF_Util::get_form_defaults();
     foreach ($new_options as $key => $val) {
         //if ( ! empty($old_options[$key]) ) // caused empty  Welcome introduction to appear filled in
         if (isset($old_options[$key])) {
             $new_options[$key] = stripslashes($old_options[$key]);
         }
     }
     // ***** Import fields *****
     // Keep a list of slugs so we can be sure they are unique
     $slug_list = $fscf_special_slugs;
     // Standard fields should already have been added by defaults
     // Import standard field settings
     $std_fields = array('name', 'email', 'subject', 'message');
     // This assumes that the standard fields in the form defaults are in the same order as
     //   the names in the above array
     foreach ($std_fields as $key => $val) {
         if ('subject' == $val) {
             // was there an optional subject select list?
             if (!empty($old_options['email_subject_list'])) {
                 $new_options['fields'][$key]['options'] = $old_options['email_subject_list'];
                 $new_options['fields'][$key]['type'] = 'select';
             }
         }
         // Make sure this goes to the correct field!
         $test = 'name' == $val ? 'full_name' : $val;
         $slug_list[] = $test;
         if ($new_options['fields'][$key]['slug'] == $test) {
             // name_type, etc. could be 'required', 'not_required', or 'not_available'
             if ('not_required' == $old_options[$val . '_type']) {
                 // Standard fields are required by default, so change this
                 $new_options['fields'][$key]['req'] = 'false';
             } else {
                 if ('not_available' == $old_options[$val . '_type']) {
                     $new_options['fields'][$key]['disable'] = 'true';
                 }
             }
         } else {
             // Error: this is the wrong field!
             // This could happen if the standard fields in the default form are in a different
             // order than in $std_fields
         }
     }
     // end foreach $std_fields
     //print_r($new_options);
     // Import the old "extra fields"
     // This will ignore any field properties no longer used
     for ($fld = 1; $fld <= $max_fields; $fld++) {
         $old_type = $old_options['ex_field' . $fld . '_type'];
         if (!empty($old_options['ex_field' . $fld . '_label']) || 'fieldset' == $old_type || 'fieldset-close' == $old_type) {
             // Add a new field with the default properties
             $new_field = FSCF_Util::get_field_defaults();
             foreach ($new_field as $key => $val) {
                 $old_prop = 'ex_field' . $fld . '_' . $key;
                 // Need special treatment for: default option / default_text
                 // Need to parse and reformat select options lists, checkboxres, etc.
                 switch ($key) {
                     case "default":
                         // The old version has both default_text and default_option
                         if (in_array($old_type, self::$select_type_fields) && $old_options['ex_field' . $fld . '_default'] > 0) {
                             $new_field['default'] = $old_options['ex_field' . $fld . '_default'];
                         } else {
                             if (!empty($old_options['ex_field' . $fld . '_default_text'])) {
                                 $new_field['default'] = stripslashes($old_options['ex_field' . $fld . '_default_text']);
                             }
                         }
                         break;
                     case "label":
                         if (empty($old_options['ex_field' . $fld . '_label']) && ('fieldset' == $old_type || 'fieldset-close' == $old_type)) {
                             $old_options['ex_field' . $fld . '_label'] = sprintf(__('Field %s', 'si-contact-form'), $fld);
                         }
                         // Check for options added to the label (e.g. Color:,Red;Green;Blue ), etc.
                         $new_field[$key] = $old_options[$old_prop];
                         if (in_array($old_type, self::$select_type_fields) && 'checkbox' != $old_type) {
                             $new_field = self::parse_label($new_field);
                         }
                         if ('checkbox' == $old_type) {
                             // label might have \, (not needed in 4.x version, remove it)
                             $new_field['label'] = str_replace('\\,', ',', $new_field['label']);
                             // "\," changes to ","
                             $new_field['label'] = stripslashes($new_field['label']);
                         }
                         break;
                     default:
                         if (!empty($old_options[$old_prop])) {
                             $new_field[$key] = stripslashes($old_options[$old_prop]);
                         }
                 }
                 // End switch
             }
             // end foreach $new_field
             // Create the slug for the field from the field label
             // the sanitize title function encodes UTF-8 characters, so we need to undo that
             // this line croaked on some chinese characters
             //$new_field['slug'] = substr( urldecode(sanitize_title_with_dashes(remove_accents($new_field['label']))), 0, FSCF_MAX_SLUG_LEN );
             //echo 'slug before:'.$new_field['label']."<br>\n";
             $new_field['slug'] = remove_accents($new_field['label']);
             $new_field['slug'] = preg_replace('~([^a-zA-Z\\d_ .-])~', '', $new_field['slug']);
             $new_field['slug'] = substr(urldecode(sanitize_title_with_dashes($new_field['slug'])), 0, FSCF_MAX_SLUG_LEN);
             if ($new_field['slug'] == '') {
                 $new_field['slug'] = 'na';
             }
             if ('-' == substr($new_field['slug'], strlen($new_field['slug']) - 1, 1)) {
                 $new_field['slug'] = substr($new_field['slug'], 0, strlen($new_field['slug']) - 1);
             }
             // Make sure the slug is unique
             $new_field['slug'] = FSCF_Options::check_slug($new_field['slug'], $slug_list);
             //echo 'slug jafter:'.$new_field['slug']."<br>\n";
             $slug_list[] = $new_field['slug'];
             $new_options['fields'][] = $new_field;
         }
         // end if old field label not empty
     }
     // for loop through fields
     return $new_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
 }