function cntctfrm_check_form() { global $error_message, $cntctfrm_options; $language = isset($_POST['cntctfrm_language']) ? $_POST['cntctfrm_language'] : 'en'; $path_of_uploaded_file = $cntctfrm_result = ""; /* Error messages array */ $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['cntctfrm_language'])) { foreach ($cntctfrm_options as $key => $value) { if (is_array($value) && array_key_exists('en', $value) && (!array_key_exists($language, $value) || isset($cntctfrm_options[$key][$language]) && $cntctfrm_options[$key][$language] == '')) { $cntctfrm_options[$key][$language] = $cntctfrm_options[$key]['en']; } } } if (1 == $cntctfrm_options['cntctfrm_required_name_field'] && 1 == $cntctfrm_options['cntctfrm_display_name_field']) { $error_message['error_name'] = $cntctfrm_options['cntctfrm_name_error'][$language]; } if (1 == $cntctfrm_options['cntctfrm_required_address_field'] && 1 == $cntctfrm_options['cntctfrm_display_address_field']) { $error_message['error_address'] = $cntctfrm_options['cntctfrm_address_error'][$language]; } if (1 == $cntctfrm_options['cntctfrm_required_email_field']) { $error_message['error_email'] = $cntctfrm_options['cntctfrm_email_error'][$language]; } if (1 == $cntctfrm_options['cntctfrm_required_subject_field']) { $error_message['error_subject'] = $cntctfrm_options['cntctfrm_subject_error'][$language]; } if (1 == $cntctfrm_options['cntctfrm_required_message_field']) { $error_message['error_message'] = $cntctfrm_options['cntctfrm_message_error'][$language]; } if (1 == $cntctfrm_options['cntctfrm_required_phone_field'] && 1 == $cntctfrm_options['cntctfrm_display_phone_field']) { $error_message['error_phone'] = $cntctfrm_options['cntctfrm_phone_error'][$language]; } $error_message['error_form'] = $cntctfrm_options['cntctfrm_form_error'][$language]; if (1 == $cntctfrm_options['cntctfrm_attachment']) { global $path_of_uploaded_file, $mime_type; $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', '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'); $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_error'][$language]; } /* Check information wich was input in fields */ if (1 == $cntctfrm_options['cntctfrm_display_name_field'] && 1 == $cntctfrm_options['cntctfrm_required_name_field'] && "" != $name) { unset($error_message['error_name']); } if (1 == $cntctfrm_options['cntctfrm_display_address_field'] && 1 == $cntctfrm_options['cntctfrm_required_address_field'] && "" != $address) { unset($error_message['error_address']); } if (1 == $cntctfrm_options['cntctfrm_required_email_field'] && "" != $email && is_email(trim(stripslashes($email)))) { unset($error_message['error_email']); } if (1 == $cntctfrm_options['cntctfrm_display_phone_field'] && 1 == $cntctfrm_options['cntctfrm_required_phone_field'] && "" != $phone) { unset($error_message['error_phone']); } if (1 == $cntctfrm_options['cntctfrm_required_subject_field'] && "" != $subject) { unset($error_message['error_subject']); } if (1 == $cntctfrm_options['cntctfrm_required_message_field'] && "" != $message) { unset($error_message['error_message']); } /* If captcha plugin exists */ if (!apply_filters('cntctfrm_check_form', $_POST)) { $error_message['error_captcha'] = $cntctfrm_options['cntctfrm_captcha_error'][$language]; } if (isset($_FILES["cntctfrm_contact_attachment"]["tmp_name"]) && "" != $_FILES["cntctfrm_contact_attachment"]["tmp_name"]) { if (is_multisite()) { if (defined('UPLOADS')) { if (!is_dir(ABSPATH . UPLOADS)) { wp_mkdir_p(ABSPATH . UPLOADS); } $path_of_uploaded_file = ABSPATH . UPLOADS . 'cntctfrm_' . md5($_FILES["cntctfrm_contact_attachment"]["name"] . time() . $email) . '_' . $_FILES["cntctfrm_contact_attachment"]["name"]; } else { if (defined('BLOGUPLOADDIR')) { if (!is_dir(BLOGUPLOADDIR)) { wp_mkdir_p(BLOGUPLOADDIR); } $path_of_uploaded_file = BLOGUPLOADDIR . 'cntctfrm_' . md5($_FILES["cntctfrm_contact_attachment"]["name"] . time() . $email) . '_' . $_FILES["cntctfrm_contact_attachment"]["name"]; } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $error_message['error_attachment'] = $uploads['error']; } else { $path_of_uploaded_file = $uploads['path'] . "/" . 'cntctfrm_' . md5($_FILES["cntctfrm_contact_attachment"]["name"] . time() . $email) . '_' . $_FILES["cntctfrm_contact_attachment"]["name"]; } } } } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $error_message['error_attachment'] = $uploads['error']; } else { $path_of_uploaded_file = $uploads['path'] . "/" . 'cntctfrm_' . md5($_FILES["cntctfrm_contact_attachment"]["name"] . time() . $email) . '_' . $_FILES["cntctfrm_contact_attachment"]["name"]; } } $tmp_path = $_FILES["cntctfrm_contact_attachment"]["tmp_name"]; $path_info = pathinfo($path_of_uploaded_file); if (array_key_exists(strtolower($path_info['extension']), $mime_type)) { if (is_uploaded_file($tmp_path)) { if (move_uploaded_file($tmp_path, $path_of_uploaded_file)) { do_action('cntctfrm_get_attachment_data', $path_of_uploaded_file); unset($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($upload_max_size) && isset($_FILES["cntctfrm_contact_attachment"]["size"]) && $_FILES["cntctfrm_contact_attachment"]["size"] <= $upload_max_size) { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_move_error'][$language]; } else { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_size_error'][$language]; } } } else { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_upload_error'][$language]; } } } else { unset($error_message['error_attachment']); } if (1 == count($error_message)) { unset($error_message['error_form']); /* If all is good - send mail */ $cntctfrm_result = cntctfrm_send_mail(); do_action('cntctfrm_check_dispatch', $cntctfrm_result); } return $cntctfrm_result; }
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_check_form() { global $error_message; global $cntctfrm_options; $path_of_uploaded_file = ''; if (empty($cntctfrm_options)) { $cntctfrm_options = get_option('cntctfrm_options'); } $result = ""; // Error messages array $error_message = array(); $error_message['error_name'] = __("Your name is required.", 'contact_form'); $error_message['error_email'] = __("A proper e-mail address is required.", 'contact_form'); $error_message['error_subject'] = __("Subject text is required.", 'contact_form'); $error_message['error_message'] = __("Message text is required.", 'contact_form'); $error_message['error_form'] = __("Please make corrections below and try again.", 'contact_form'); if ($cntctfrm_options['cntctfrm_attachment'] == 1) { global $path_of_uploaded_file; global $mime_type; $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', 'JPG' => 'image/jpeg', 'jpe' => 'image/jpeg', 'TIFF' => 'image/tiff', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'bmp' => 'image/x-ms-bmp', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'rtf' => 'application/rtf', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'docx' => 'application/mswor', 'zip' => 'application/zip', 'rar' => 'application/rar', 'wav' => 'audio/wav', 'mp3' => 'audio/mp3', 'ppt' => 'application/vnd.ms-powerpoint'); $error_message['error_attachment'] = __("Attachment is broken.", "contact_form"); } // Check information wich was input in fields if ("" != $_REQUEST['cntctfrm_contact_name']) { unset($error_message['error_name']); } if ("" != $_REQUEST['cntctfrm_contact_email'] && preg_match("/^(?:[a-z0-9]+(?:[a-z0-9\\-_\\.]+)?@[a-z0-9]+(?:[a-z0-9\\-\\.]+)?\\.[a-z]{2,5})\$/i", trim($_REQUEST['cntctfrm_contact_email']))) { unset($error_message['error_email']); } if ("" != $_REQUEST['cntctfrm_contact_subject']) { unset($error_message['error_subject']); } if ("" != $_REQUEST['cntctfrm_contact_message']) { unset($error_message['error_message']); } // If captcha plugin exists if (!apply_filters('cntctfrm_check_form', $_REQUEST)) { $error_message['error_captcha'] = __("Please complete the CAPTCHA.", 'contact_form'); } if (isset($_FILES["cntctfrm_contact_attachment"]["tmp_name"]) && $_FILES["cntctfrm_contact_attachment"]["tmp_name"] != "") { if (is_multisite()) { if (defined('UPLOADS')) { if (!is_dir(ABSPATH . UPLOADS)) { wp_mkdir_p(ABSPATH . UPLOADS); } $path_of_uploaded_file = ABSPATH . UPLOADS . $_FILES["cntctfrm_contact_attachment"]["name"]; } else { if (defined('BLOGUPLOADDIR')) { if (!is_dir(BLOGUPLOADDIR)) { wp_mkdir_p(BLOGUPLOADDIR); } $path_of_uploaded_file = BLOGUPLOADDIR . $_FILES["cntctfrm_contact_attachment"]["name"]; } } } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $error_message['error_attachment'] = $uploads['error']; } else { $path_of_uploaded_file = $uploads['path'] . "/" . $_FILES["cntctfrm_contact_attachment"]["name"]; } } $tmp_path = $_FILES["cntctfrm_contact_attachment"]["tmp_name"]; $path_info = pathinfo($path_of_uploaded_file); if (array_key_exists($path_info['extension'], $mime_type)) { if (is_uploaded_file($tmp_path)) { if (copy($tmp_path, $path_of_uploaded_file)) { unset($error_message['error_attachment']); } } } } else { unset($error_message['error_attachment']); } if (1 == count($error_message)) { unset($error_message['error_form']); // If all is good - send mail $result = cntctfrm_send_mail(); } return $result; }
function cntctfrm_check_form() { global $error_message; global $cntctfrm_options; $language = isset($_POST['cntctfrm_language']) ? $_POST['cntctfrm_language'] : 'en'; $path_of_uploaded_file = ''; if (empty($cntctfrm_options)) { $cntctfrm_options = get_option('cntctfrm_options'); } $cntctfrm_result = ""; // Error messages array $error_message = array(); $name = isset($_POST['cntctfrm_contact_name']) ? $_POST['cntctfrm_contact_name'] : ""; $address = isset($_POST['cntctfrm_contact_address']) ? $_POST['cntctfrm_contact_address'] : ""; $email = isset($_POST['cntctfrm_contact_email']) ? stripslashes($_POST['cntctfrm_contact_email']) : ""; $subject = isset($_POST['cntctfrm_contact_subject']) ? $_POST['cntctfrm_contact_subject'] : ""; $message = isset($_POST['cntctfrm_contact_message']) ? $_POST['cntctfrm_contact_message'] : ""; $phone = isset($_POST['cntctfrm_contact_phone']) ? $_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))); if ($cntctfrm_options['cntctfrm_required_name_field'] == 1) { $error_message['error_name'] = $cntctfrm_options['cntctfrm_name_error'][$language]; } if ($cntctfrm_options['cntctfrm_required_address_field'] == 1 && $cntctfrm_options['cntctfrm_display_address_field'] == 1) { $error_message['error_address'] = $cntctfrm_options['cntctfrm_address_error'][$language]; } if ($cntctfrm_options['cntctfrm_required_email_field'] == 1) { $error_message['error_email'] = $cntctfrm_options['cntctfrm_email_error'][$language]; } if ($cntctfrm_options['cntctfrm_required_subject_field'] == 1) { $error_message['error_subject'] = $cntctfrm_options['cntctfrm_subject_error'][$language]; } if ($cntctfrm_options['cntctfrm_required_message_field'] == 1) { $error_message['error_message'] = $cntctfrm_options['cntctfrm_message_error'][$language]; } if ($cntctfrm_options['cntctfrm_required_phone_field'] == 1 && $cntctfrm_options['cntctfrm_display_phone_field'] == 1) { $error_message['error_phone'] = $cntctfrm_options['cntctfrm_phone_error'][$language]; } $error_message['error_form'] = $cntctfrm_options['cntctfrm_form_error'][$language]; if ($cntctfrm_options['cntctfrm_attachment'] == 1) { global $path_of_uploaded_file; global $mime_type; $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', 'JPG' => 'image/jpeg', 'jpe' => 'image/jpeg', 'TIFF' => 'image/tiff', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'bmp' => 'image/x-ms-bmp', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'rtf' => 'application/rtf', 'pdf' => 'application/pdf', 'doc' => 'application/msword', 'docx' => 'application/mswor', 'xls' => 'application/vnd.ms-excel', 'zip' => 'application/zip', 'rar' => 'application/rar', 'wav' => 'audio/wav', 'mp3' => 'audio/mp3', 'ppt' => 'application/vnd.ms-powerpoint'); $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_error'][$language]; } // Check information wich was input in fields if ($cntctfrm_options['cntctfrm_required_name_field'] == 1 && "" != $name) { unset($error_message['error_name']); } if ($cntctfrm_options['cntctfrm_display_address_field'] == 1 && $cntctfrm_options['cntctfrm_required_address_field'] == 1 && "" != $address) { unset($error_message['error_address']); } if ($cntctfrm_options['cntctfrm_required_email_field'] == 1 && "" != $email && preg_match("/^(?:[a-z0-9']+(?:[a-z0-9\\-_\\.']+)?@[a-z0-9]+(?:[a-z0-9\\-\\.]+)?\\.[a-z]{2,5})\$/i", trim(stripslashes($email)))) { unset($error_message['error_email']); } if ($cntctfrm_options['cntctfrm_required_subject_field'] == 1 && "" != $subject) { unset($error_message['error_subject']); } if ($cntctfrm_options['cntctfrm_required_message_field'] == 1 && "" != $message) { unset($error_message['error_message']); } if ($cntctfrm_options['cntctfrm_display_phone_field'] == 1 && $cntctfrm_options['cntctfrm_required_phone_field'] == 1 && "" != $phone) { unset($error_message['error_phone']); } // If captcha plugin exists if (!apply_filters('cntctfrm_check_form', $_POST)) { $error_message['error_captcha'] = $cntctfrm_options['cntctfrm_captcha_error'][$language]; } if (isset($_FILES["cntctfrm_contact_attachment"]["tmp_name"]) && $_FILES["cntctfrm_contact_attachment"]["tmp_name"] != "") { if (is_multisite()) { if (defined('UPLOADS')) { if (!is_dir(ABSPATH . UPLOADS)) { wp_mkdir_p(ABSPATH . UPLOADS); } $path_of_uploaded_file = ABSPATH . UPLOADS . $_FILES["cntctfrm_contact_attachment"]["name"]; } else { if (defined('BLOGUPLOADDIR')) { if (!is_dir(BLOGUPLOADDIR)) { wp_mkdir_p(BLOGUPLOADDIR); } $path_of_uploaded_file = BLOGUPLOADDIR . $_FILES["cntctfrm_contact_attachment"]["name"]; } } } else { $uploads = wp_upload_dir(); if (!isset($uploads['path']) && isset($uploads['error'])) { $error_message['error_attachment'] = $uploads['error']; } else { $path_of_uploaded_file = $uploads['path'] . "/" . $_FILES["cntctfrm_contact_attachment"]["name"]; } } $tmp_path = $_FILES["cntctfrm_contact_attachment"]["tmp_name"]; $path_info = pathinfo($path_of_uploaded_file); if (array_key_exists($path_info['extension'], $mime_type)) { if (is_uploaded_file($tmp_path)) { if (move_uploaded_file($tmp_path, $path_of_uploaded_file)) { unset($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($upload_max_size) && isset($_FILES["cntctfrm_contact_attachment"]["size"]) && $_FILES["cntctfrm_contact_attachment"]["size"] <= $upload_max_size) { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_move_error'][$language]; } else { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_size_error'][$language]; } } } else { $error_message['error_attachment'] = $cntctfrm_options['cntctfrm_attachment_upload_error'][$language]; } } } else { unset($error_message['error_attachment']); } if (1 == count($error_message)) { unset($error_message['error_form']); // If all is good - send mail $cntctfrm_result = cntctfrm_send_mail(); } return $cntctfrm_result; }