function wpcf7_text_custom_validation_message($result, $tag)
{
    $cmtagobj = new WPCF7_Shortcode($tag);
    $post_id = sanitize_text_field($_POST['_wpcf7']);
    $name = $cmtagobj->name;
    $key = "_cf7cm_" . $name;
    $val = get_post_meta($post_id, $key, true);
    $enable = get_post_meta($post_id, '_cf7cm_enable_errors');
    if ($enable[0] != 0) {
        $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
        if ('text' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            }
        }
        if ('email' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_email($value)) {
                $key = "_cf7cm_" . $name . "-valid";
                $val = get_post_meta($post_id, $key, true);
                if ($val) {
                    $result->invalidate($cmtagobj, $val);
                } else {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_email'));
                }
            }
        }
        if ('url' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_url($value)) {
                $result->invalidate($cmtagobj, wpcf7_get_message('invalid_url'));
            }
        }
        if ('tel' == $cmtagobj->basetype) {
            if ($cmtagobj->is_required() && '' == $value) {
                $result->invalidate($cmtagobj, $val);
            } elseif ('' != $value && !wpcf7_is_tel($value)) {
                $result->invalidate($cmtagobj, wpcf7_get_message('invalid_tel'));
            }
        }
        if (!empty($value)) {
            $maxlength = $cmtagobj->get_maxlength_option();
            $minlength = $cmtagobj->get_minlength_option();
            if ($maxlength && $minlength && $maxlength < $minlength) {
                $maxlength = $minlength = null;
            }
            $code_units = wpcf7_count_code_units($value);
            if (false !== $code_units) {
                if ($maxlength && $maxlength < $code_units) {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_too_long'));
                } elseif ($minlength && $code_units < $minlength) {
                    $result->invalidate($cmtagobj, wpcf7_get_message('invalid_too_short'));
                }
            }
        }
    }
    return $result;
}
示例#2
0
function wpcf7_date_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $min = $tag->get_date_option('min');
    $max = $tag->get_date_option('max');
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    if ($tag->is_required() && '' == $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
    } elseif ('' != $value && !wpcf7_is_date($value)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_date');
    } elseif ('' != $value && !empty($min) && $value < $min) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('date_too_early');
    } elseif ('' != $value && !empty($max) && $max < $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('date_too_late');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#3
0
function wpcf7_birthday_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('birthday' == $tag->type && $value != '') {
        if (preg_match('@^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[0-2])$@', $value) != 1) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_birthday');
        }
    }
    if ('birthday*' == $tag->type) {
        if ($value == '') {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } else {
            if (preg_match('@^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[0-2])$@', $value) != 1) {
                $result['valid'] = false;
                $result['reason'][$name] = wpcf7_get_message('invalid_birthday');
            }
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#4
0
function wpcf7_number_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    $min = $tag->get_option('min', 'signed_int', true);
    $max = $tag->get_option('max', 'signed_int', true);
    if ($tag->is_required() && '' == $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
    } elseif ('' != $value && !wpcf7_is_number($value)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_number');
    } elseif ('' != $value && '' != $min && (double) $value < (double) $min) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('number_too_small');
    } elseif ('' != $value && '' != $max && (double) $max < (double) $value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('number_too_large');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#5
0
function wpcf7_quiz_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $answer = isset($_POST[$name]) ? wpcf7_canonicalize($_POST[$name]) : '';
    $answer_hash = wp_hash($answer, 'wpcf7_quiz');
    $expected_hash = isset($_POST['_wpcf7_quiz_answer_' . $name]) ? (string) $_POST['_wpcf7_quiz_answer_' . $name] : '';
    if ($answer_hash != $expected_hash) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('quiz_answer_not_correct');
    }
    return $result;
}
示例#6
0
文件: quiz.php 项目: rotoballer/emily
function wpcf7_quiz_validation_filter($result, $tag)
{
    $type = $tag['type'];
    $name = $tag['name'];
    $answer = wpcf7_canonicalize($_POST[$name]);
    $answer_hash = wp_hash($answer, 'wpcf7_quiz');
    $expected_hash = $_POST['_wpcf7_quiz_answer_' . $name];
    if ($answer_hash != $expected_hash) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('quiz_answer_not_correct');
    }
    return $result;
}
示例#7
0
function wpcf7_quiz_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $answer = isset($_POST[$name]) ? wpcf7_canonicalize($_POST[$name]) : '';
    $answer = wp_unslash($answer);
    $answer_hash = wp_hash($answer, 'wpcf7_quiz');
    $expected_hash = isset($_POST['_wpcf7_quiz_answer_' . $name]) ? (string) $_POST['_wpcf7_quiz_answer_' . $name] : '';
    if ($answer_hash != $expected_hash) {
        $result->invalidate($tag, wpcf7_get_message('quiz_answer_not_correct'));
    }
    return $result;
}
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result->invalidate($tag, wpcf7_get_message('accept_terms'));
    }
    return $result;
}
示例#9
0
function wpcf7_textarea_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ('textarea*' == $type) {
        if ('' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    return $result;
}
 public function recaptcha_validation_filter($result, $tag)
 {
     global $wdm_recaptcha_settings_values;
     $site_key = $wdm_recaptcha_settings_values->get_option('general_site_key');
     $secret_key = $wdm_recaptcha_settings_values->get_option('general_secret_key');
     //if site key and secret key are available, then validate captcha
     if (!empty($site_key) && !empty($secret_key)) {
         $tag = new WPCF7_Shortcode($tag);
         $type = $tag->type;
         $name = !empty($tag->name) ? $tag->name : 'recaptcha';
         $recaptcha_value = isset($_POST['g-recaptcha-response']) ? (string) $_POST['g-recaptcha-response'] : '';
         //cf7 4.1 replaced results array structure to object
         $result_type = gettype($result);
         if ($result_type === 'object') {
             if (0 == strlen(trim($recaptcha_value))) {
                 //recaptcha is uncheked
                 $result->invalidate($tag, wpcf7_get_message('no_re_uncheked'));
             } else {
                 $captcha_value = $this->check_recaptcha($recaptcha_value);
                 if (!$captcha_value) {
                     //google returned false
                     $result->invalidate($tag, wpcf7_get_message('no_re_bot_detected'));
                 }
             }
         } else {
             if (0 == strlen(trim($recaptcha_value))) {
                 //recaptcha is uncheked
                 $result['valid'] = false;
                 $reason = array($name => wpcf7_get_message('no_re_uncheked'));
                 $result['reason'] = array_merge($result['reason'], $reason);
             } else {
                 $captcha_value = $this->check_recaptcha($recaptcha_value);
                 if (!$captcha_value) {
                     //google returned false
                     $result['valid'] = false;
                     $reason = array($name => wpcf7_get_message('no_re_bot_detected'));
                     $result['reason'] = array_merge($result['reason'], $reason);
                 }
                 if ($captcha_value && true == $result['valid']) {
                     //reset captcha if form was submitted successfully
                 }
             }
         }
     }
     return $result;
 }
示例#11
0
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = $tag->has_option('invert');
    if ($invert && $value || !$invert && !$value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('accept_terms');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#12
0
function wpcf7_acceptance_validation_filter($result, $tag)
{
    if (!wpcf7_acceptance_as_validation()) {
        return $result;
    }
    $name = $tag['name'];
    if (empty($name)) {
        return $result;
    }
    $options = (array) $tag['options'];
    $value = !empty($_POST[$name]) ? 1 : 0;
    $invert = (bool) preg_grep('%^invert$%', $options);
    if ($invert && $value || !$invert && !$value) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('accept_terms');
    }
    return $result;
}
示例#13
0
function wpcf7_date_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $min = $tag->get_date_option('min');
    $max = $tag->get_date_option('max');
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    } elseif ('' != $value && !wpcf7_is_date($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_date'));
    } elseif ('' != $value && !empty($min) && $value < $min) {
        $result->invalidate($tag, wpcf7_get_message('date_too_early'));
    } elseif ('' != $value && !empty($max) && $max < $value) {
        $result->invalidate($tag, wpcf7_get_message('date_too_late'));
    }
    return $result;
}
示例#14
0
function wpcf7_number_validation_filter($result, $tag)
{
    $tag = new WPCF7_FormTag($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(strtr((string) $_POST[$name], "\n", " ")) : '';
    $min = $tag->get_option('min', 'signed_int', true);
    $max = $tag->get_option('max', 'signed_int', true);
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    } elseif ('' != $value && !wpcf7_is_number($value)) {
        $result->invalidate($tag, wpcf7_get_message('invalid_number'));
    } elseif ('' != $value && '' != $min && (double) $value < (double) $min) {
        $result->invalidate($tag, wpcf7_get_message('number_too_small'));
    } elseif ('' != $value && '' != $max && (double) $max < (double) $value) {
        $result->invalidate($tag, wpcf7_get_message('number_too_large'));
    }
    return $result;
}
function cf7ic_check_if_spam($result, $tag)
{
    $type = $tag['type'];
    $name = $tag['name'];
    $value = $_POST[$name];
    // Allow Contact Forms without [cf7ic] to send
    if ($_POST['cf7ic_exists']) {
        if (!empty($_POST['kc_honeypot']) || $_POST['kc_captcha'] != "kc_human") {
            $result['valid'] = false;
            $result['reason'] = array($name => wpcf7_get_message('spam'));
        }
        return $result;
    }
    // Allow Contact Forms without [cf7ic] to send
    if ($_POST['cf7ic_exists'] != "true") {
        return $result;
    }
}
function wpcf7_mathcaptcha_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    if (!is_admin() && isset($_POST[$name])) {
        $cf7_version = get_option('wpcf7', '1.0.0');
        if (is_array($cf7_version) && isset($cf7_version['version'])) {
            $cf7_version = $cf7_version['version'];
        }
        if ($_POST[$name] !== '') {
            $session_id = isset($_POST[$name . '-sn']) && $_POST[$name . '-sn'] !== '' ? Math_Captcha()->cookie_session->session_ids['multi'][$_POST[$name . '-sn']] : '';
            if ($session_id !== '' && get_transient('cf7_' . $session_id) !== false) {
                if (strcmp(get_transient('cf7_' . $session_id), sha1(AUTH_KEY . $_POST[$name] . $session_id, false)) !== 0) {
                    if (version_compare($cf7_version, '4.1.0', '>=')) {
                        $result->invalidate($tag, wpcf7_get_message('wrong_mathcaptcha'));
                    } else {
                        $result['valid'] = false;
                        $result['reason'][$name] = wpcf7_get_message('wrong_mathcaptcha');
                    }
                }
            } else {
                if (version_compare($cf7_version, '4.1.0', '>=')) {
                    $result->invalidate($tag, wpcf7_get_message('time_mathcaptcha'));
                } else {
                    $result['valid'] = false;
                    $result['reason'][$name] = wpcf7_get_message('time_mathcaptcha');
                }
            }
        } else {
            if (version_compare($cf7_version, '4.1.0', '>=')) {
                $result->invalidate($tag, wpcf7_get_message('fill_mathcaptcha'));
            } else {
                $result['valid'] = false;
                $result['reason'][$name] = wpcf7_get_message('fill_mathcaptcha');
            }
        }
    }
    return $result;
}
function wpcf7_hashcash_validation_filter($result, $tag)
{
    if (!class_exists('WP_Hashcash')) {
        die("WP_Hashcash Class is not available.");
    }
    $instance = WP_Hashcash::get_instance();
    $tag = new WPCF7_Shortcode($tag);
    $hashcashid = $_POST['hashcashid'];
    if (!$hashcashid) {
        die("hashcashid value is not available.");
    }
    $type = $tag->type;
    $name = $tag->name;
    $op = wpcf7_hashcash_options($tag->options);
    $hashcash_result = $instance->verify_hash($hashcashid, $op['complexity']);
    if ($hashcash_result !== 'ok') {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('hashcash_error');
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#18
0
function wpcf7_select_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    if (isset($_POST[$name]) && is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            if ('' === $value) {
                unset($_POST[$name][$key]);
            }
        }
    }
    $empty = !isset($_POST[$name]) || empty($_POST[$name]) && '0' !== $_POST[$name];
    if ($tag->is_required() && $empty) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    return $result;
}
示例#19
0
function wpcf7_text_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('text*' == $tag->type) {
        if ('' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if ('email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_email');
        }
    }
    if ('url' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_url($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_url');
        }
    }
    if ('tel' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $value && !wpcf7_is_tel($value)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_tel');
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
function wpcf7_akismet_display_message($message, $status)
{
    if ('spam' == $status && empty($message)) {
        $message = wpcf7_get_message('akismet_says_spam');
    }
    return $message;
}
示例#21
0
function wpcf7_file_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $id = $tag->get_id_option();
    $file = isset($_FILES[$name]) ? $_FILES[$name] : null;
    if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error']) {
        $result->invalidate($tag, wpcf7_get_message('upload_failed_php_error'));
        return $result;
    }
    if (empty($file['tmp_name']) && $tag->is_required()) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        return $result;
    }
    if (!is_uploaded_file($file['tmp_name'])) {
        return $result;
    }
    $allowed_file_types = array();
    if ($file_types_a = $tag->get_option('filetypes')) {
        foreach ($file_types_a as $file_types) {
            $file_types = explode('|', $file_types);
            foreach ($file_types as $file_type) {
                $file_type = trim($file_type, '.');
                $file_type = str_replace(array('.', '+', '*', '?'), array('\\.', '\\+', '\\*', '\\?'), $file_type);
                $allowed_file_types[] = $file_type;
            }
        }
    }
    $allowed_file_types = array_unique($allowed_file_types);
    $file_type_pattern = implode('|', $allowed_file_types);
    $allowed_size = 1048576;
    // default size 1 MB
    if ($file_size_a = $tag->get_option('limit')) {
        $limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/';
        foreach ($file_size_a as $file_size) {
            if (preg_match($limit_pattern, $file_size, $matches)) {
                $allowed_size = (int) $matches[1];
                if (!empty($matches[2])) {
                    $kbmb = strtolower($matches[2]);
                    if ('kb' == $kbmb) {
                        $allowed_size *= 1024;
                    } elseif ('mb' == $kbmb) {
                        $allowed_size *= 1024 * 1024;
                    }
                }
                break;
            }
        }
    }
    /* File type validation */
    // Default file-type restriction
    if ('' == $file_type_pattern) {
        $file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
    }
    $file_type_pattern = trim($file_type_pattern, '|');
    $file_type_pattern = '(' . $file_type_pattern . ')';
    $file_type_pattern = '/\\.' . $file_type_pattern . '$/i';
    if (!preg_match($file_type_pattern, $file['name'])) {
        $result->invalidate($tag, wpcf7_get_message('upload_file_type_invalid'));
        return $result;
    }
    /* File size validation */
    if ($file['size'] > $allowed_size) {
        $result->invalidate($tag, wpcf7_get_message('upload_file_too_large'));
        return $result;
    }
    wpcf7_init_uploads();
    // Confirm upload dir
    $uploads_dir = wpcf7_upload_tmp_dir();
    $uploads_dir = wpcf7_maybe_add_random_dir($uploads_dir);
    $filename = $file['name'];
    $filename = wpcf7_canonicalize($filename);
    $filename = sanitize_file_name($filename);
    $filename = wpcf7_antiscript_file_name($filename);
    $filename = wp_unique_filename($uploads_dir, $filename);
    $new_file = trailingslashit($uploads_dir) . $filename;
    if (false === @move_uploaded_file($file['tmp_name'], $new_file)) {
        $result->invalidate($tag, wpcf7_get_message('upload_failed'));
        return $result;
    }
    // Make sure the uploaded file is only readable for the owner process
    @chmod($new_file, 0400);
    if ($submission = WPCF7_Submission::get_instance()) {
        $submission->add_uploaded_file($name, $new_file);
    }
    return $result;
}
示例#22
0
function wpcf7_captcha_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $captchac = '_wpcf7_captcha_challenge_' . $name;
    $prefix = isset($_POST[$captchac]) ? (string) $_POST[$captchac] : '';
    $response = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ($prefix) {
        if (!wpcf7_check_captcha($prefix, $response)) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('captcha_not_match');
        }
        wpcf7_remove_captcha($prefix);
    }
    return $result;
}
function wpcf7_confirm_email_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->basetype;
    $name = $tag->name;
    $values = $tag->values;
    $value = isset($_POST[$name]) ? trim(wp_unslash(strtr((string) $_POST[$name], "\n", " "))) : '';
    if ('confirm_email' == $tag->basetype) {
        if ($tag->is_required() && '' == $value) {
            $result->invalidate($tag, wpcf7_get_message('invalid_required'));
        } elseif ('' != $value && !wpcf7_is_email($value)) {
            $result->invalidate($tag, wpcf7_get_message('invalid_email'));
        } elseif ($value != $_POST['your-email']) {
            $result->invalidate($tag, wpcf7_get_message('invalid_confirm_email'));
        }
    }
    return $result;
}
/**
 * Validate email domain.
 *
 * This is the validator function of [email]. Does robottrap_mx action on invalid email domain.
 *
 * @param object $result WPCF7 result object.
 * @param string $tag    Source of the tag.
 *
 * @return object The modified WPCF7 object.
 */
function wpcf7_robottrap_domain_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $value = isset($_POST[$name]) ? trim(wp_unslash(sanitize_text_field((string) $_POST[$name]))) : '';
    if (!$result->is_valid($name) || '' === $value) {
        return $result;
    }
    $domain = sanitize_text_field(substr(strrchr($value, '@'), 1));
    if (empty($domain) || !checkdnsrr($domain, 'MX')) {
        /**
         * Counteraction for empty or MX-less domain part of email addresses
         *
         * Usually this is a spammer robot.
         *
         * @param string $domain  Email domain.
         */
        do_action('robottrap_mx', $domain);
        $result->invalidate($tag, wpcf7_get_message('spam'));
    }
    return $result;
}
function wpcf7_captcha_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $captchac = '_wpcf7_captcha_challenge_' . $name;
    $prefix = isset($_POST[$captchac]) ? (string) $_POST[$captchac] : '';
    $response = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    $response = wpcf7_canonicalize($response);
    if (0 == strlen($prefix) || !wpcf7_check_captcha($prefix, $response)) {
        $result->invalidate($tag, wpcf7_get_message('captcha_not_match'));
    }
    if (0 != strlen($prefix)) {
        wpcf7_remove_captcha($prefix);
    }
    return $result;
}
示例#26
0
function wpcf7_file_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    $file = isset($_FILES[$name]) ? $_FILES[$name] : null;
    if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error']) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_failed_php_error');
        return $result;
    }
    if (empty($file['tmp_name']) && $tag->is_required()) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('invalid_required');
        return $result;
    }
    if (!is_uploaded_file($file['tmp_name'])) {
        return $result;
    }
    $allowed_file_types = array();
    if ($file_types_a = $tag->get_option('filetypes')) {
        foreach ($file_types_a as $file_types) {
            $file_types = explode('|', $file_types);
            foreach ($file_types as $file_type) {
                $file_type = trim($file_type, '.');
                $file_type = str_replace(array('.', '+', '*', '?'), array('\\.', '\\+', '\\*', '\\?'), $file_type);
                $allowed_file_types[] = $file_type;
            }
        }
    }
    $allowed_file_types = array_unique($allowed_file_types);
    $file_type_pattern = implode('|', $allowed_file_types);
    $allowed_size = 1048576;
    // default size 1 MB
    if ($file_size_a = $tag->get_option('limit')) {
        $limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/';
        foreach ($file_size_a as $file_size) {
            if (preg_match($limit_pattern, $file_size, $matches)) {
                $allowed_size = (int) $matches[1];
                if (!empty($matches[2])) {
                    $kbmb = strtolower($matches[2]);
                    if ('kb' == $kbmb) {
                        $allowed_size *= 1024;
                    } elseif ('mb' == $kbmb) {
                        $allowed_size *= 1024 * 1024;
                    }
                }
                break;
            }
        }
    }
    /* File type validation */
    // Default file-type restriction
    if ('' == $file_type_pattern) {
        $file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
    }
    $file_type_pattern = trim($file_type_pattern, '|');
    $file_type_pattern = '(' . $file_type_pattern . ')';
    $file_type_pattern = '/\\.' . $file_type_pattern . '$/i';
    if (!preg_match($file_type_pattern, $file['name'])) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_file_type_invalid');
        return $result;
    }
    /* File size validation */
    if ($file['size'] > $allowed_size) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_file_too_large');
        return $result;
    }
    $uploads_dir = wpcf7_upload_tmp_dir();
    wpcf7_init_uploads();
    // Confirm upload dir
    $filename = $file['name'];
    // If you get script file, it's a danger. Make it TXT file.
    if (preg_match('/\\.(php|pl|py|rb|cgi)\\d?$/', $filename)) {
        $filename .= '.txt';
    }
    $filename = wp_unique_filename($uploads_dir, $filename);
    $new_file = trailingslashit($uploads_dir) . $filename;
    if (false === @move_uploaded_file($file['tmp_name'], $new_file)) {
        $result['valid'] = false;
        $result['reason'][$name] = wpcf7_get_message('upload_failed');
        return $result;
    }
    // Make sure the uploaded file is only readable for the owner process
    @chmod($new_file, 0400);
    if ($contact_form = wpcf7_get_current_contact_form()) {
        $contact_form->uploaded_files[$name] = $new_file;
        if (empty($contact_form->posted_data[$name])) {
            $contact_form->posted_data[$name] = $filename;
        }
    }
    return $result;
}
示例#27
0
function wpcf7_select_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $name = $tag->name;
    if (isset($_POST[$name]) && is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            if ('' === $value) {
                unset($_POST[$name][$key]);
            }
        }
    }
    if ($tag->is_required()) {
        if (!isset($_POST[$name]) || empty($_POST[$name]) && '0' !== $_POST[$name]) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if (isset($result['reason'][$name]) && ($id = $tag->get_id_option())) {
        $result['idref'][$name] = $id;
    }
    return $result;
}
示例#28
0
function wpcf7_text_validation_filter($result, $tag)
{
    $type = $tag['type'];
    $name = $tag['name'];
    $_POST[$name] = trim(strtr((string) $_POST[$name], "\n", " "));
    if ('text*' == $type) {
        if ('' == $_POST[$name]) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    if ('email' == $type || 'email*' == $type) {
        if ('email*' == $type && '' == $_POST[$name]) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        } elseif ('' != $_POST[$name] && !is_email($_POST[$name])) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_email');
        }
    }
    return $result;
}
示例#29
0
function wpcf7_select_validation_filter($result, $tag)
{
    $type = $tag['type'];
    $name = $tag['name'];
    $values = $tag['values'];
    if (is_array($_POST[$name])) {
        foreach ($_POST[$name] as $key => $value) {
            $value = stripslashes($value);
            if (!in_array($value, (array) $values)) {
                // Not in given choices.
                unset($_POST[$name][$key]);
            }
        }
    } else {
        $value = stripslashes($_POST[$name]);
        if (!in_array($value, (array) $values)) {
            //  Not in given choices.
            $_POST[$name] = '';
        }
    }
    if ('select*' == $type) {
        if (empty($_POST[$name]) || !is_array($_POST[$name]) && '---' == $_POST[$name] || is_array($_POST[$name]) && 1 == count($_POST[$name]) && '---' == $_POST[$name][0]) {
            $result['valid'] = false;
            $result['reason'][$name] = wpcf7_get_message('invalid_required');
        }
    }
    return $result;
}
示例#30
-1
function wpcf7_textarea_validation_filter($result, $tag)
{
    $tag = new WPCF7_Shortcode($tag);
    $type = $tag->type;
    $name = $tag->name;
    $value = isset($_POST[$name]) ? (string) $_POST[$name] : '';
    if ($tag->is_required() && '' == $value) {
        $result->invalidate($tag, wpcf7_get_message('invalid_required'));
    }
    if (!empty($value)) {
        $maxlength = $tag->get_maxlength_option();
        $minlength = $tag->get_minlength_option();
        if ($maxlength && $minlength && $maxlength < $minlength) {
            $maxlength = $minlength = null;
        }
        $code_units = wpcf7_count_code_units($value);
        if (false !== $code_units) {
            if ($maxlength && $maxlength < $code_units) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_long'));
            } elseif ($minlength && $code_units < $minlength) {
                $result->invalidate($tag, wpcf7_get_message('invalid_too_short'));
            }
        }
    }
    return $result;
}