function cntctfrm_check_form() { global $cntctfrm_error_message, $cntctfrm_options, $cntctfrm_related_plugins; if (empty($cntctfrm_related_plugins)) { cntctfrm_related_plugins(); } $contact_form_multi_active = cntctfrm_check_cf_multi_active(); $removed_filters = cntctfrm_handle_captcha_filters('remove_filters'); $language = isset($_POST['cntctfrm_language']) ? $_POST['cntctfrm_language'] : 'default'; $cntctfrm_path_of_uploaded_file = $cntctfrm_result = ""; /* Error messages array */ $cntctfrm_error_message = array(); $name = isset($_POST['cntctfrm_contact_name']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_name'])) : ""; $address = isset($_POST['cntctfrm_contact_address']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_address'])) : ""; $email = isset($_POST['cntctfrm_contact_email']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_email'])) : ""; $subject = isset($_POST['cntctfrm_contact_subject']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_subject'])) : ""; $message = isset($_POST['cntctfrm_contact_message']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_message'])) : ""; $phone = isset($_POST['cntctfrm_contact_phone']) ? htmlspecialchars(stripslashes($_POST['cntctfrm_contact_phone'])) : ""; $name = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $name))); $address = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $address))); $email = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $email))); $subject = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $subject))); $message = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $message))); $phone = strip_tags(preg_replace('/<[^>]*>/', '', preg_replace('/<script.*<\\/[^>]*>/', '', $phone))); /* check language and replace with en default if need */ if (!in_array($language, $cntctfrm_options['language'])) { foreach ($cntctfrm_options as $key => $value) { if (is_array($value) && array_key_exists('default', $value) && (!array_key_exists($language, $value) || isset($cntctfrm_options[$key][$language]) && $cntctfrm_options[$key][$language] == '')) { $cntctfrm_options[$key][$language] = $cntctfrm_options[$key]['default']; } } } if (1 == $cntctfrm_options['required_name_field'] && 1 == $cntctfrm_options['display_name_field']) { $cntctfrm_error_message['error_name'] = $cntctfrm_options['name_error'][$language]; } if (1 == $cntctfrm_options['required_address_field'] && 1 == $cntctfrm_options['display_address_field']) { $cntctfrm_error_message['error_address'] = $cntctfrm_options['address_error'][$language]; } if (1 == $cntctfrm_options['required_email_field']) { $cntctfrm_error_message['error_email'] = $cntctfrm_options['email_error'][$language]; } if (1 == $cntctfrm_options['required_subject_field']) { $cntctfrm_error_message['error_subject'] = $cntctfrm_options['subject_error'][$language]; } if (1 == $cntctfrm_options['required_message_field']) { $cntctfrm_error_message['error_message'] = $cntctfrm_options['message_error'][$language]; } if (1 == $cntctfrm_options['required_phone_field'] && 1 == $cntctfrm_options['display_phone_field']) { $cntctfrm_error_message['error_phone'] = $cntctfrm_options['phone_error'][$language]; } $cntctfrm_error_message['error_form'] = $cntctfrm_options['form_error'][$language]; if (1 == $cntctfrm_options['attachment']) { global $cntctfrm_path_of_uploaded_file, $cntctfrm_mime_type; $cntctfrm_mime_type = array('html' => 'text/html', 'htm' => 'text/html', 'txt' => 'text/plain', 'css' => 'text/css', 'gif' => 'image/gif', 'png' => 'image/x-png', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'bmp' => 'image/x-ms-bmp', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'csv' => 'text/csv', 'rtf' => 'application/rtf', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'docx' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.ms-excel', 'zip' => 'application/zip', 'rar' => 'application/rar', 'wav' => 'audio/wav', 'mp3' => 'audio/mp3', 'ppt' => 'application/vnd.ms-powerpoint', 'aar' => 'application/sb-replay', 'sce' => 'application/sb-scenario'); $cntctfrm_error_message['error_attachment'] = $cntctfrm_options['attachment_error'][$language]; } /* Check information wich was input in fields */ if (1 == $cntctfrm_options['display_name_field'] && 1 == $cntctfrm_options['required_name_field'] && "" != $name) { unset($cntctfrm_error_message['error_name']); } if (1 == $cntctfrm_options['display_address_field'] && 1 == $cntctfrm_options['required_address_field'] && "" != $address) { unset($cntctfrm_error_message['error_address']); } if (1 == $cntctfrm_options['required_email_field'] && "" != $email && is_email(trim(stripslashes($email)))) { unset($cntctfrm_error_message['error_email']); } if (1 == $cntctfrm_options['display_phone_field'] && 1 == $cntctfrm_options['required_phone_field'] && "" != $phone) { unset($cntctfrm_error_message['error_phone']); } if (1 == $cntctfrm_options['required_subject_field'] && "" != $subject) { unset($cntctfrm_error_message['error_subject']); } if (1 == $cntctfrm_options['required_message_field'] && "" != $message) { unset($cntctfrm_error_message['error_message']); } /* If captcha plugin exists */ $result = true; if (has_filter('cntctfrm_check_form')) { $result = apply_filters('cntctfrm_check_form', true); } cntctfrm_handle_captcha_filters('add_filters', $removed_filters); if (false === $result) { /* for CAPTCHA older than PRO - v1.0.7, PLUS - v1.1.0 v FREE - 1.2.5 */ $cntctfrm_error_message['error_captcha'] = $cntctfrm_options['captcha_error'][$language]; } else { if (!empty($result) && (is_string($result) || is_wp_error($result))) { $cntctfrm_error_message['error_captcha'] = is_string($result) ? $result : $result->get_error_message(); } } if (isset($_FILES["cntctfrm_contact_attachment"]["tmp_name"]) && "" != $_FILES["cntctfrm_contact_attachment"]["tmp_name"]) { $new_filename = 'cntctfrm_' . md5(sanitize_file_name($_FILES["cntctfrm_contact_attachment"]["name"]) . time() . $email . mt_rand()) . '_' . sanitize_file_name($_FILES["cntctfrm_contact_attachment"]["name"]); if (is_multisite()) { if (defined('UPLOADS')) { if (!is_dir(ABSPATH . UPLOADS)) { wp_mkdir_p(ABSPATH . UPLOADS); } $cntctfrm_path_of_uploaded_file = ABSPATH . UPLOADS . $new_filename; } else { if (defined('BLOGUPLOADDIR')) { if (!is_dir(BLOGUPLOADDIR)) { wp_mkdir_p(BLOGUPLOADDIR); } $cntctfrm_path_of_uploaded_file = BLOGUPLOADDIR . $new_filename; } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $cntctfrm_error_message['error_attachment'] = $uploads['error']; } else { $cntctfrm_path_of_uploaded_file = $uploads['path'] . "/" . $new_filename; } } } } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $cntctfrm_error_message['error_attachment'] = $uploads['error']; } else { $cntctfrm_path_of_uploaded_file = $uploads['path'] . "/" . $new_filename; } } $tmp_path = $_FILES["cntctfrm_contact_attachment"]["tmp_name"]; $path_info = pathinfo($cntctfrm_path_of_uploaded_file); if (array_key_exists(strtolower($path_info['extension']), $cntctfrm_mime_type)) { if (is_uploaded_file($tmp_path)) { if (move_uploaded_file($tmp_path, $cntctfrm_path_of_uploaded_file)) { do_action('cntctfrm_get_attachment_data', $cntctfrm_path_of_uploaded_file); unset($cntctfrm_error_message['error_attachment']); } else { $letter_upload_max_size = substr(ini_get('upload_max_filesize'), -1); /* $upload_max_size = substr( ini_get('upload_max_filesize'), 0, -1 ); */ $upload_max_size = '1'; switch (strtoupper($letter_upload_max_size)) { case 'P': $upload_max_size *= 1024; case 'T': $upload_max_size *= 1024; case 'G': $upload_max_size *= 1024; case 'M': $upload_max_size *= 1024; case 'K': $upload_max_size *= 1024; break; } if (isset($_FILES["cntctfrm_contact_attachment"]["size"]) && $_FILES["cntctfrm_contact_attachment"]["size"] <= $upload_max_size) { $cntctfrm_error_message['error_attachment'] = $cntctfrm_options['attachment_move_error'][$language]; } else { $cntctfrm_error_message['error_attachment'] = $cntctfrm_options['attachment_size_error'][$language]; } } } else { $cntctfrm_error_message['error_attachment'] = $cntctfrm_options['attachment_upload_error'][$language]; } } } else { unset($cntctfrm_error_message['error_attachment']); } if (1 == count($cntctfrm_error_message)) { if (has_filter('sbscrbr_cntctfrm_checkbox_check')) { $cntctfrm_sbscrbr_check = apply_filters('sbscrbr_cntctfrm_checkbox_check', array('form_id' => 'cntctfrm_' . $_POST['cntctfrm_form_submited'], 'email' => $email, 'name' => $name)); if (isset($cntctfrm_sbscrbr_check['response']) && $cntctfrm_sbscrbr_check['response']['type'] == 'error') { $cntctfrm_error_message['error_sbscrbr'] = $cntctfrm_sbscrbr_check['response']; return $cntctfrm_result; } } unset($cntctfrm_error_message['error_form']); /* If all is good - send mail */ $cntctfrm_result = cntctfrm_send_mail(); $save_emails = false; if (!$contact_form_multi_active && array_key_exists('contact-form-to-db', $cntctfrm_related_plugins)) { $save_emails = !empty($cntctfrm_related_plugins['contact-form-to-db']['options'][$cntctfrm_related_plugins['contact-form-to-db']['save_option']]); } else { $save_emails = !empty($cntctfrm_options['save_email_to_db']); } if ($save_emails) { do_action('cntctfrm_check_dispatch', $cntctfrm_result); } } return $cntctfrm_result; }
function cntctfrm_options_update($cntctfrm_options, $cntctfrm_option_defaults, $contact_form_multi_active) { global $cntctfrm_related_plugins; foreach ($cntctfrm_option_defaults as $key => $value) { if (isset($cntctfrm_options['cntctfrm_' . $key])) { $cntctfrm_options[$key] = $cntctfrm_options['cntctfrm_' . $key]; unset($cntctfrm_options['cntctfrm_' . $key]); } } foreach (array('display_captcha', 'display_google_captcha', 'display_subscribe', 'save_email_to_db') as $key) { if (isset($cntctfrm_options['cntctfrm_' . $key])) { $cntctfrm_options[$key] = $cntctfrm_options['cntctfrm_' . $key]; unset($cntctfrm_options['cntctfrm_' . $key]); } } if ($contact_form_multi_active) { if (empty($cntctfrm_related_plugins)) { cntctfrm_related_plugins(); } if (!isset($cntctfrm_options['display_captcha'])) { if (array_key_exists('captcha', $cntctfrm_related_plugins)) { $cntctfrm_options['display_captcha'] = $cntctfrm_related_plugins['captcha']['options'][$cntctfrm_related_plugins['captcha']['display_option']]; } else { $cntctfrm_options['display_captcha'] = false; } } if (!isset($cntctfrm_options['display_google_captcha'])) { if (array_key_exists('google-captcha', $cntctfrm_related_plugins)) { $cntctfrm_options['display_google_captcha'] = $cntctfrm_related_plugins['google-captcha']['options']['contact_form']; } else { $cntctfrm_options['display_google_captcha'] = false; } } if (!isset($cntctfrm_options['display_subscribe'])) { if (array_key_exists('subscriber', $cntctfrm_related_plugins)) { $cntctfrm_options['display_subscribe'] = $cntctfrm_related_plugins['subscriber']['options']['contact_form']; } else { $cntctfrm_options['display_subscribe'] = false; } } if (!isset($cntctfrm_options['save_email_to_db'])) { if (array_key_exists('contact-form-to-db', $cntctfrm_related_plugins)) { $cntctfrm_options['save_email_to_db'] = !empty($cntctfrm_related_plugins['contact-form-to-db']['options'][$cntctfrm_related_plugins['contact-form-to-db']['save_option']]) ? true : false; } else { $cntctfrm_options['save_email_to_db'] = false; } } } if (!isset($cntctfrm_options['cntctfrm_name_label']['default']) && isset($cntctfrm_options['cntctfrm_name_label']['en'])) { $cntctfrm_options['cntctfrm_name_label']['default'] = $cntctfrm_options['cntctfrm_name_label']['en']; unset($cntctfrm_options['cntctfrm_name_label']['en']); $cntctfrm_options['cntctfrm_address_label']['default'] = $cntctfrm_options['cntctfrm_address_label']['en']; unset($cntctfrm_options['cntctfrm_address_label']['en']); $cntctfrm_options['cntctfrm_email_label']['default'] = $cntctfrm_options['cntctfrm_email_label']['en']; unset($cntctfrm_options['cntctfrm_email_label']['en']); $cntctfrm_options['cntctfrm_phone_label']['default'] = $cntctfrm_options['cntctfrm_phone_label']['en']; unset($cntctfrm_options['cntctfrm_phone_label']['en']); $cntctfrm_options['cntctfrm_subject_label']['default'] = $cntctfrm_options['cntctfrm_subject_label']['en']; unset($cntctfrm_options['cntctfrm_subject_label']['en']); $cntctfrm_options['cntctfrm_message_label']['default'] = $cntctfrm_options['cntctfrm_message_label']['en']; unset($cntctfrm_options['cntctfrm_message_label']['en']); $cntctfrm_options['cntctfrm_attachment_label']['default'] = $cntctfrm_options['cntctfrm_attachment_label']['en']; unset($cntctfrm_options['cntctfrm_attachment_label']['en']); $cntctfrm_options['cntctfrm_attachment_tooltip']['default'] = $cntctfrm_options['cntctfrm_attachment_tooltip']['en']; unset($cntctfrm_options['cntctfrm_attachment_tooltip']['en']); $cntctfrm_options['cntctfrm_send_copy_label']['default'] = $cntctfrm_options['cntctfrm_send_copy_label']['en']; unset($cntctfrm_options['cntctfrm_send_copy_label']['en']); $cntctfrm_options['cntctfrm_submit_label']['default'] = $cntctfrm_options['cntctfrm_submit_label']['en']; unset($cntctfrm_options['cntctfrm_submit_label']['en']); $cntctfrm_options['cntctfrm_name_error']['default'] = $cntctfrm_options['cntctfrm_name_error']['en']; unset($cntctfrm_options['cntctfrm_name_error']['en']); $cntctfrm_options['cntctfrm_address_error']['default'] = $cntctfrm_options['cntctfrm_address_error']['en']; unset($cntctfrm_options['cntctfrm_address_error']['en']); $cntctfrm_options['cntctfrm_email_error']['default'] = $cntctfrm_options['cntctfrm_email_error']['en']; unset($cntctfrm_options['cntctfrm_email_error']['en']); $cntctfrm_options['cntctfrm_phone_error']['default'] = $cntctfrm_options['cntctfrm_phone_error']['en']; unset($cntctfrm_options['cntctfrm_phone_error']['en']); $cntctfrm_options['cntctfrm_subject_error']['default'] = $cntctfrm_options['cntctfrm_subject_error']['en']; unset($cntctfrm_options['cntctfrm_subject_error']['en']); $cntctfrm_options['cntctfrm_message_error']['default'] = $cntctfrm_options['cntctfrm_message_error']['en']; unset($cntctfrm_options['cntctfrm_message_error']['en']); $cntctfrm_options['cntctfrm_attachment_error']['default'] = $cntctfrm_options['cntctfrm_attachment_error']['en']; unset($cntctfrm_options['cntctfrm_attachment_error']['en']); $cntctfrm_options['cntctfrm_attachment_upload_error']['default'] = $cntctfrm_options['cntctfrm_attachment_upload_error']['en']; unset($cntctfrm_options['cntctfrm_attachment_upload_error']['en']); $cntctfrm_options['cntctfrm_attachment_move_error']['default'] = $cntctfrm_options['cntctfrm_attachment_move_error']['en']; unset($cntctfrm_options['cntctfrm_attachment_move_error']['en']); $cntctfrm_options['cntctfrm_attachment_size_error']['default'] = $cntctfrm_options['cntctfrm_attachment_size_error']['en']; unset($cntctfrm_options['cntctfrm_attachment_size_error']['en']); $cntctfrm_options['cntctfrm_captcha_error']['default'] = $cntctfrm_options['cntctfrm_captcha_error']['en']; unset($cntctfrm_options['cntctfrm_captcha_error']['en']); $cntctfrm_options['cntctfrm_form_error']['default'] = $cntctfrm_options['cntctfrm_form_error']['en']; unset($cntctfrm_options['cntctfrm_form_error']['en']); $cntctfrm_options['cntctfrm_thank_text']['default'] = $cntctfrm_options['cntctfrm_thank_text']['en']; unset($cntctfrm_options['cntctfrm_thank_text']['en']); } if (empty($cntctfrm_options['cntctfrm_language']) && isset($cntctfrm_options['cntctfrm_name_label']) && !is_array($cntctfrm_options['cntctfrm_name_label'])) { $cntctfrm_options['cntctfrm_name_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_name_label']['default']); $cntctfrm_options['cntctfrm_address_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_address_label']['default']); $cntctfrm_options['cntctfrm_email_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_email_label']['default']); $cntctfrm_options['cntctfrm_phone_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_phone_label']['default']); $cntctfrm_options['cntctfrm_subject_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_subject_label']['default']); $cntctfrm_options['cntctfrm_message_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_message_label']['default']); $cntctfrm_options['cntctfrm_attachment_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_label']['default']); $cntctfrm_options['cntctfrm_attachment_tooltip'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_tooltip']['default']); $cntctfrm_options['cntctfrm_send_copy_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_send_copy_label']['default']); $cntctfrm_options['cntctfrm_thank_text'] = array('default' => $cntctfrm_option_defaults['cntctfrm_thank_text']['default']); $cntctfrm_options['cntctfrm_submit_label'] = array('default' => $cntctfrm_option_defaults['cntctfrm_submit_label']['default']); $cntctfrm_options['cntctfrm_name_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_name_error']['default']); $cntctfrm_options['cntctfrm_address_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_address_error']['default']); $cntctfrm_options['cntctfrm_email_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_email_error']['default']); $cntctfrm_options['cntctfrm_phone_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_phone_error']['default']); $cntctfrm_options['cntctfrm_subject_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_subject_error']['default']); $cntctfrm_options['cntctfrm_message_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_message_error']['default']); $cntctfrm_options['cntctfrm_attachment_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_error']['default']); $cntctfrm_options['cntctfrm_attachment_upload_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_upload_error']['default']); $cntctfrm_options['cntctfrm_attachment_move_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_move_error']['default']); $cntctfrm_options['cntctfrm_attachment_size_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_attachment_size_error']['default']); $cntctfrm_options['cntctfrm_captcha_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_captcha_error']['default']); $cntctfrm_options['cntctfrm_form_error'] = array('default' => $cntctfrm_option_defaults['cntctfrm_form_error']['default']); } return $cntctfrm_options; }