Ejemplo n.º 1
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 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;
 }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
 static function get_field_defaults()
 {
     // Default array for a single field
     self::$field_defaults = array('standard' => '0', 'options' => '', 'default' => '', 'inline' => 'false', 'req' => 'false', 'disable' => 'false', 'follow' => 'false', 'hide_label' => 'false', 'placeholder' => 'false', 'label' => __('New Field:', 'si-contact-form'), 'slug' => '', 'type' => 'text', 'max_len' => '', 'label_css' => '', 'input_css' => '', 'attributes' => '', 'regex' => '', 'regex_error' => '', 'notes' => '', 'notes_after' => '');
     return self::$field_defaults;
 }
Ejemplo n.º 5
0
    static function display_captcha()
    {
        // this function adds the captcha to the contact form
        $captchaRequiresError = '';
        $enable_php_sessions = 0;
        if (self::$global_options['enable_php_sessions'] == 'true') {
            $enable_php_sessions = 1;
        }
        $string = '';
        // Test for some required things, print error message right here if not OK.
        // Code moved in from function captchaCheckRequires() -- only called once
        $captcha_ok = true;
        // Test for some required things, print error message if not OK.
        if (!extension_loaded('gd') || !function_exists('gd_info')) {
            $captchaRequiresError .= '<p ' . self::get_this_css('error_style') . '>' . __('ERROR: si-contact-form.php plugin says GD image support not detected in PHP!', 'si-contact-form') . '</p>';
            $captchaRequiresError .= '<p>' . __('Contact your web host and ask them why GD image support is not enabled for PHP.', 'si-contact-form') . '</p>';
            $captcha_ok = false;
        }
        if (!function_exists('imagepng')) {
            $captchaRequiresError .= '<p ' . self::get_this_css('error_style') . '>' . __('ERROR: si-contact-form.php plugin says imagepng function not detected in PHP!', 'si-contact-form') . '</p>';
            $captchaRequiresError .= '<p>' . __('Contact your web host and ask them why imagepng function is not enabled for PHP.', 'si-contact-form') . '</p>';
            $captcha_ok = false;
        }
        if (!@strtolower(ini_get('safe_mode')) == 'on' && !file_exists(FSCF_CAPTCHA_PATH . '/securimage.php')) {
            $captchaRequiresError .= '<p ' . self::get_this_css('error_style') . '>' . __('ERROR: si-contact-form.php plugin says captcha_library not found.', 'si-contact-form') . '</p>';
            $captcha_ok = false;
        }
        if ($captcha_ok) {
            // the captch html
            $string = "\n<div " . self::get_this_css('title_style') . ">\n</div>\n" . '<div id="fscf_captcha_image_div' . self::$form_id_num . '" ';
            // url for captcha image
            $captcha_url_cf = FSCF_Util::get_captcha_url_cf();
            $securimage_show_url = $captcha_url_cf . '/securimage_show.php?';
            $securimage_size = 'width="175" height="60"';
            if (self::$form_options['captcha_small'] == 'true') {
                $securimage_show_url .= 'ctf_sm_captcha=1&amp;';
                $securimage_size = 'width="132" height="45"';
            }
            $parseUrl = parse_url($captcha_url_cf);
            $securimage_url = $parseUrl['path'];
            if (!$enable_php_sessions) {
                // no sessions
                self::init_temp_dir(FSCF_CAPTCHA_PATH . '/cache/');
                // clean out old captcha cache files
                self::clean_temp_dir(FSCF_CAPTCHA_PATH . '/cache/');
                // pick new prefix token
                $prefix_length = 16;
                $prefix_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
                $prefix = '';
                $prefix_count = strlen($prefix_characters);
                while ($prefix_length--) {
                    $prefix .= $prefix_characters[mt_rand(0, $prefix_count - 1)];
                }
                $securimage_show_rf_url = $securimage_show_url . 'prefix=';
                $securimage_show_url .= 'prefix=' . $prefix;
            } else {
                // no session
                $securimage_show_rf_url = $securimage_show_url . 'ctf_form_num=' . self::$form_id_num;
                $securimage_show_url .= 'ctf_form_num=' . self::$form_id_num;
            }
            $string .= self::$form_options['captcha_small'] == 'true' ? self::get_this_css('captcha_div_style_sm') : self::get_this_css('captcha_div_style_m');
            $string .= ">\n" . '      <img id="fscf_captcha_image' . self::$form_id_num . '" ';
            $string .= self::get_this_css('captcha_image_style');
            $string .= ' src="' . $securimage_show_url . '" ' . $securimage_size . ' alt="';
            $string .= self::$form_options['tooltip_captcha'] != '' ? esc_html(self::$form_options['tooltip_captcha']) : esc_html(__('CAPTCHA Image', 'si-contact-form'));
            $string .= '" title="';
            $string .= self::$form_options['tooltip_captcha'] != '' ? esc_html(self::$form_options['tooltip_captcha']) : esc_html(__('CAPTCHA Image', 'si-contact-form'));
            $string .= '" />' . "\n";
            if (!$enable_php_sessions) {
                // no sessions
                $string .= '      <input id="fscf_captcha_prefix' . self::$form_id_num . '" type="hidden" name="fscf_captcha_prefix' . self::$form_id_num . '" value="' . esc_attr($prefix) . '" />' . "\n";
            }
            $string .= '     <div id="fscf_captcha_refresh' . self::$form_id_num . '">' . "\n";
            $string .= '        <a href="#" rel="nofollow" title="';
            $string .= self::$form_options['tooltip_refresh'] != '' ? esc_html(self::$form_options['tooltip_refresh']) : esc_html(__('Refresh Image', 'si-contact-form'));
            if (!$enable_php_sessions) {
                // no sessions
                $string .= '" onclick="fscf_captcha_refresh(\'' . self::$form_id_num . '\',\'' . $securimage_url . '\',\'' . $securimage_show_rf_url . '\'); return false;">' . "\n";
            } else {
                $string .= '" onclick="document.getElementById(\'fscf_captcha_image' . self::$form_id_num . '\').src = \'' . $securimage_show_url . '&amp;sid=\'' . ' + Math.random(); return false;">' . "\n";
            }
            $string .= '        <img src="' . $captcha_url_cf . '/images/refresh.png" width="22" height="20" alt="';
            $string .= self::$form_options['tooltip_refresh'] != '' ? esc_html(self::$form_options['tooltip_refresh']) : esc_html(__('Refresh Image', 'si-contact-form'));
            $string .= '" ';
            $string .= self::get_this_css('captcha_reload_image_style');
            $string .= ' onclick="this.blur();" /></a>
     </div>
</div>

<div id="fscf_captcha_field' . self::$form_id_num . '" ' . self::get_this_css('title_style') . '>
     <label ' . self::get_this_css('label_style') . ' for="fscf_captcha_code' . self::$form_id_num . '">';
            $string .= self::$form_options['title_capt'] != '' ? self::$form_options['title_capt'] : __('CAPTCHA Code:', 'si-contact-form');
            $string .= self::$req_field_ind . '</label>
</div>
<div ' . self::get_this_css('field_div_style') . '>' . self::echo_if_error('captcha') . "\n     <input " . self::get_this_css('captcha_input_style') . ' type="text" value="" id="fscf_captcha_code' . self::$form_id_num . '" name="captcha_code" ' . self::$aria_required . ' />';
            $string .= "\n</div>";
        } else {
            $string .= $captchaRequiresError;
        }
        return $string;
    }
 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
 }
Ejemplo n.º 7
0
define('FSCF_MESSAGE_FIELD', '4');
global $fscf_special_slugs;
// List of reserve slug names
$fscf_special_slugs = array('f_name', 'm_name', 'mi_name', 'l_name', 'email2', 'mailto_id', 'subject_id');
/********************
 * Includes
 ********************/
require_once FSCF_PATH . 'includes/class-fscf-util.php';
require_once FSCF_PATH . 'includes/class-fscf-display.php';
require_once FSCF_PATH . 'includes/class-fscf-process.php';
if (is_admin()) {
    require_once FSCF_PATH . 'includes/class-fscf-action.php';
    require_once FSCF_PATH . 'includes/class-fscf-options.php';
}
// Initialize plugin settings and hooks
FSCF_Util::setup();
register_activation_hook(__FILE__, 'FSCF_Util::import');
if (!class_exists('siContactForm')) {
    class siContactForm
    {
        function si_contact_form_short_code($atts)
        {
            // backwards compatibility with manual PHP call from 3.xx
            echo FSCF_Display::process_short_code($atts);
        }
    }
}
$si_contact_form = new siContactForm();
// Show activation time errors
//echo get_option( 'plugin_error' );
// end of file