PK P\fO wp-contact-form-7.phpnu W+A $value ) );
update_option( 'wpcf7', $option );
}
}
add_action( 'plugins_loaded', 'wpcf7' );
function wpcf7() {
wpcf7_load_textdomain();
WPCF7::load_modules();
/* Shortcodes */
add_shortcode( 'contact-form-7', 'wpcf7_contact_form_tag_func' );
add_shortcode( 'contact-form', 'wpcf7_contact_form_tag_func' );
}
add_action( 'init', 'wpcf7_init' );
function wpcf7_init() {
wpcf7_get_request_uri();
wpcf7_register_post_types();
do_action( 'wpcf7_init' );
}
add_action( 'admin_init', 'wpcf7_upgrade' );
function wpcf7_upgrade() {
$old_ver = WPCF7::get_option( 'version', '0' );
$new_ver = WPCF7_VERSION;
if ( $old_ver == $new_ver ) {
return;
}
do_action( 'wpcf7_upgrade', $new_ver, $old_ver );
WPCF7::update_option( 'version', $new_ver );
}
/* Install and default settings */
add_action( 'activate_' . WPCF7_PLUGIN_BASENAME, 'wpcf7_install' );
function wpcf7_install() {
if ( $opt = get_option( 'wpcf7' ) ) {
return;
}
wpcf7_load_textdomain();
wpcf7_register_post_types();
wpcf7_upgrade();
if ( get_posts( array( 'post_type' => 'wpcf7_contact_form' ) ) ) {
return;
}
$contact_form = WPCF7_ContactForm::get_template(
array(
'title' => sprintf( __( 'Contact form %d', 'contact-form-7' ), 1 ),
)
);
$contact_form->save();
WPCF7::update_option( 'bulk_validate',
array(
'timestamp' => current_time( 'timestamp' ),
'version' => WPCF7_VERSION,
'count_valid' => 1,
'count_invalid' => 0,
)
);
}
PK P\v modules/akismet.phpnu W+A $value ) {
if ( ! in_array( $key, (array) $ignore ) )
$c["$key"] = $value;
}
return wpcf7_akismet_comment_check( $c );
}
function wpcf7_akismet_is_available() {
if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) { // Akismet v3.0+
return (bool) Akismet::get_api_key();
}
if ( function_exists( 'akismet_get_key' ) ) {
return (bool) akismet_get_key();
}
return false;
}
function wpcf7_akismet_submitted_params() {
$params = array(
'author' => '',
'author_email' => '',
'author_url' => '',
'content' => '' );
$has_akismet_option = false;
foreach ( (array) $_POST as $key => $val ) {
if ( '_wpcf7' == substr( $key, 0, 6 ) || '_wpnonce' == $key ) {
continue;
}
if ( is_array( $val ) ) {
$val = implode( ', ', wpcf7_array_flatten( $val ) );
}
$val = trim( $val );
if ( 0 == strlen( $val ) ) {
continue;
}
if ( $tags = wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
$tag = $tags[0];
$tag = new WPCF7_FormTag( $tag );
$akismet = $tag->get_option( 'akismet',
'(author|author_email|author_url)', true );
if ( $akismet ) {
$has_akismet_option = true;
if ( 'author' == $akismet ) {
$params[$akismet] = trim( $params[$akismet] . ' ' . $val );
} elseif ( '' == $params[$akismet] ) {
$params[$akismet] = $val;
}
}
}
$params['content'] .= "\n\n" . $val;
}
if ( ! $has_akismet_option ) {
return false;
}
$params['content'] = trim( $params['content'] );
return $params;
}
function wpcf7_akismet_comment_check( $comment ) {
global $akismet_api_host, $akismet_api_port;
$spam = false;
$query_string = wpcf7_build_query( $comment );
if ( is_callable( array( 'Akismet', 'http_post' ) ) ) { // Akismet v3.0+
$response = Akismet::http_post( $query_string, 'comment-check' );
} else {
$response = akismet_http_post( $query_string, $akismet_api_host,
'/1.1/comment-check', $akismet_api_port );
}
if ( 'true' == $response[1] ) {
$spam = true;
}
if ( $submission = WPCF7_Submission::get_instance() ) {
$submission->akismet = array( 'comment' => $comment, 'spam' => $spam );
}
return apply_filters( 'wpcf7_akismet_comment_check', $spam, $comment );
}
PK P\u& & modules/select.phpnu W+A true, 'selectable-values' => true ) );
}
function wpcf7_select_form_tag_handler( $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$multiple = $tag->has_option( 'multiple' );
$include_blank = $tag->has_option( 'include_blank' );
$first_as_label = $tag->has_option( 'first_as_label' );
if ( $tag->has_option( 'size' ) ) {
$size = $tag->get_option( 'size', 'int', true );
if ( $size ) {
$atts['size'] = $size;
} elseif ( $multiple ) {
$atts['size'] = 4;
} else {
$atts['size'] = 1;
}
}
$values = $tag->values;
$labels = $tag->labels;
if ( $data = (array) $tag->get_data_option() ) {
$values = array_merge( $values, array_values( $data ) );
$labels = array_merge( $labels, array_values( $data ) );
}
$defaults = array();
$default_choice = $tag->get_default_option( null, 'multiple=1' );
foreach ( $default_choice as $value ) {
$key = array_search( $value, $values, true );
if ( false !== $key ) {
$defaults[] = (int) $key + 1;
}
}
if ( $matches = $tag->get_first_match_option( '/^default:([0-9_]+)$/' ) ) {
$defaults = array_merge( $defaults, explode( '_', $matches[1] ) );
}
$defaults = array_unique( $defaults );
$shifted = false;
if ( $include_blank || empty( $values ) ) {
array_unshift( $labels, '---' );
array_unshift( $values, '' );
$shifted = true;
} elseif ( $first_as_label ) {
$values[0] = '';
}
$html = '';
$hangover = wpcf7_get_hangover( $tag->name );
foreach ( $values as $key => $value ) {
$selected = false;
if ( $hangover ) {
if ( $multiple ) {
$selected = in_array( esc_sql( $value ), (array) $hangover );
} else {
$selected = ( $hangover == esc_sql( $value ) );
}
} else {
if ( ! $shifted && in_array( (int) $key + 1, (array) $defaults ) ) {
$selected = true;
} elseif ( $shifted && in_array( (int) $key, (array) $defaults ) ) {
$selected = true;
}
}
$item_atts = array(
'value' => $value,
'selected' => $selected ? 'selected' : '' );
$item_atts = wpcf7_format_atts( $item_atts );
$label = isset( $labels[$key] ) ? $labels[$key] : $value;
$html .= sprintf( '%2$s ',
$item_atts, esc_html( $label ) );
}
if ( $multiple ) {
$atts['multiple'] = 'multiple';
}
$atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
'%3$s %4$s ',
sanitize_html_class( $tag->name ), $atts, $html, $validation_error );
return $html;
}
/* Validation filter */
add_filter( 'wpcf7_validate_select', 'wpcf7_select_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_select*', 'wpcf7_select_validation_filter', 10, 2 );
function wpcf7_select_validation_filter( $result, $tag ) {
$tag = new WPCF7_FormTag( $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;
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25 );
function wpcf7_add_tag_generator_menu() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'menu', __( 'drop-down menu', 'contact-form-7' ),
'wpcf7_tag_generator_menu' );
}
function wpcf7_tag_generator_menu( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$description = __( "Generate a form-tag for a drop-down menu. For more details, see %s.", 'contact-form-7' );
$desc_link = wpcf7_link( __( 'https://contactform7.com/checkboxes-radio-buttons-and-menus/', 'contact-form-7' ), __( 'Checkboxes, Radio Buttons and Menus', 'contact-form-7' ) );
?>
true ) );
}
function wpcf7_file_form_tag_handler( $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option( '40' );
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$atts['type'] = 'file';
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
' %3$s ',
sanitize_html_class( $tag->name ), $atts, $validation_error );
return $html;
}
/* Encode type filter */
add_filter( 'wpcf7_form_enctype', 'wpcf7_file_form_enctype_filter' );
function wpcf7_file_form_enctype_filter( $enctype ) {
$multipart = (bool) wpcf7_scan_form_tags( array( 'type' => array( 'file', 'file*' ) ) );
if ( $multipart ) {
$enctype = 'multipart/form-data';
}
return $enctype;
}
/* Validation + upload handling filter */
add_filter( 'wpcf7_validate_file', 'wpcf7_file_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_file*', 'wpcf7_file_validation_filter', 10, 2 );
function wpcf7_file_validation_filter( $result, $tag ) {
$tag = new WPCF7_FormTag( $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, 'as-is' );
$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;
}
/* Messages */
add_filter( 'wpcf7_messages', 'wpcf7_file_messages' );
function wpcf7_file_messages( $messages ) {
return array_merge( $messages, array(
'upload_failed' => array(
'description' => __( "Uploading a file fails for any reason", 'contact-form-7' ),
'default' => __( "There was an unknown error uploading the file.", 'contact-form-7' )
),
'upload_file_type_invalid' => array(
'description' => __( "Uploaded file is not allowed for file type", 'contact-form-7' ),
'default' => __( "You are not allowed to upload files of this type.", 'contact-form-7' )
),
'upload_file_too_large' => array(
'description' => __( "Uploaded file is too large", 'contact-form-7' ),
'default' => __( "The file is too big.", 'contact-form-7' )
),
'upload_failed_php_error' => array(
'description' => __( "Uploading a file fails for PHP error", 'contact-form-7' ),
'default' => __( "There was an error uploading the file.", 'contact-form-7' )
)
) );
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_file', 50 );
function wpcf7_add_tag_generator_file() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'file', __( 'file', 'contact-form-7' ),
'wpcf7_tag_generator_file' );
}
function wpcf7_tag_generator_file( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$type = 'file';
$description = __( "Generate a form-tag for a file uploading field. For more details, see %s.", 'contact-form-7' );
$desc_link = wpcf7_link( __( 'https://contactform7.com/file-uploading-and-attachment/', 'contact-form-7' ), __( 'File Uploading and Attachment', 'contact-form-7' ) );
?>
scan_form_tags(
array( 'type' => array( 'file', 'file*' ) ) );
if ( ! $has_tags ) {
return;
}
$uploads_dir = wpcf7_upload_tmp_dir();
wpcf7_init_uploads();
if ( ! is_dir( $uploads_dir ) || ! wp_is_writable( $uploads_dir ) ) {
$message = sprintf( __( 'This contact form contains file uploading fields, but the temporary folder for the files (%s) does not exist or is not writable. You can create the folder or change its permission manually.', 'contact-form-7' ), $uploads_dir );
echo '' . esc_html( $message ) . '
';
}
}
/* File uploading functions */
function wpcf7_init_uploads() {
$dir = wpcf7_upload_tmp_dir();
wp_mkdir_p( $dir );
$htaccess_file = trailingslashit( $dir ) . '.htaccess';
if ( file_exists( $htaccess_file ) ) {
return;
}
if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
fwrite( $handle, "Deny from all\n" );
fclose( $handle );
}
}
function wpcf7_maybe_add_random_dir( $dir ) {
do {
$rand_max = mt_getrandmax();
$rand = zeroise( mt_rand( 0, $rand_max ), strlen( $rand_max ) );
$dir_new = path_join( $dir, $rand );
} while ( file_exists( $dir_new ) );
if ( wp_mkdir_p( $dir_new ) ) {
return $dir_new;
}
return $dir;
}
function wpcf7_upload_tmp_dir() {
if ( defined( 'WPCF7_UPLOADS_TMP_DIR' ) )
return WPCF7_UPLOADS_TMP_DIR;
else
return wpcf7_upload_dir( 'dir' ) . '/wpcf7_uploads';
}
add_action( 'template_redirect', 'wpcf7_cleanup_upload_files', 20 );
function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
if ( is_admin() || 'GET' != $_SERVER['REQUEST_METHOD']
|| is_robots() || is_feed() || is_trackback() ) {
return;
}
$dir = trailingslashit( wpcf7_upload_tmp_dir() );
if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) {
return;
}
$seconds = absint( $seconds );
$max = absint( $max );
$count = 0;
if ( $handle = @opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "." || $file == ".." || $file == ".htaccess" ) {
continue;
}
$mtime = @filemtime( $dir . $file );
if ( $mtime && time() < $mtime + $seconds ) { // less than $seconds old
continue;
}
wpcf7_rmdir_p( path_join( $dir, $file ) );
$count += 1;
if ( $max <= $count ) {
break;
}
}
closedir( $handle );
}
}
PK P\El modules/quiz.phpnu W+A true ) );
}
function wpcf7_quiz_form_tag_handler( $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option( '40' );
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
$atts['autocomplete'] = 'off';
$atts['aria-required'] = 'true';
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$pipes = $tag->pipes;
if ( $pipes instanceof WPCF7_Pipes && ! $pipes->zero() ) {
$pipe = $pipes->random_pipe();
$question = $pipe->before;
$answer = $pipe->after;
} else {
// default quiz
$question = '1+1=?';
$answer = '2';
}
$answer = wpcf7_canonicalize( $answer );
$atts['type'] = 'text';
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
'%2$s %6$s ',
sanitize_html_class( $tag->name ),
esc_html( $question ), $atts, $tag->name,
wp_hash( $answer, 'wpcf7_quiz' ), $validation_error );
return $html;
}
/* Validation filter */
add_filter( 'wpcf7_validate_quiz', 'wpcf7_quiz_validation_filter', 10, 2 );
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;
}
/* Ajax echo filter */
add_filter( 'wpcf7_ajax_onload', 'wpcf7_quiz_ajax_refill' );
add_filter( 'wpcf7_ajax_json_echo', 'wpcf7_quiz_ajax_refill' );
function wpcf7_quiz_ajax_refill( $items ) {
if ( ! is_array( $items ) )
return $items;
$fes = wpcf7_scan_form_tags( array( 'type' => 'quiz' ) );
if ( empty( $fes ) )
return $items;
$refill = array();
foreach ( $fes as $fe ) {
$name = $fe['name'];
$pipes = $fe['pipes'];
if ( empty( $name ) )
continue;
if ( $pipes instanceof WPCF7_Pipes && ! $pipes->zero() ) {
$pipe = $pipes->random_pipe();
$question = $pipe->before;
$answer = $pipe->after;
} else {
// default quiz
$question = '1+1=?';
$answer = '2';
}
$answer = wpcf7_canonicalize( $answer );
$refill[$name] = array( $question, wp_hash( $answer, 'wpcf7_quiz' ) );
}
if ( ! empty( $refill ) )
$items['quiz'] = $refill;
return $items;
}
/* Messages */
add_filter( 'wpcf7_messages', 'wpcf7_quiz_messages' );
function wpcf7_quiz_messages( $messages ) {
return array_merge( $messages, array( 'quiz_answer_not_correct' => array(
'description' => __( "Sender doesn't enter the correct answer to the quiz", 'contact-form-7' ),
'default' => __( "The answer to the quiz is incorrect.", 'contact-form-7' )
) ) );
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_quiz', 40 );
function wpcf7_add_tag_generator_quiz() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'quiz', __( 'quiz', 'contact-form-7' ),
'wpcf7_tag_generator_quiz' );
}
function wpcf7_tag_generator_quiz( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$type = 'quiz';
$description = __( "Generate a form-tag for a question-answer pair. For more details, see %s.", 'contact-form-7' );
$desc_link = wpcf7_link( __( 'https://contactform7.com/quiz/', 'contact-form-7' ), __( 'Quiz', 'contact-form-7' ) );
?>
true ) );
}
function wpcf7_text_form_tag_handler( $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type, 'wpcf7-text' );
if ( in_array( $tag->basetype, array( 'email', 'url', 'tel' ) ) ) {
$class .= ' wpcf7-validates-as-' . $tag->basetype;
}
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['size'] = $tag->get_size_option( '40' );
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] && $atts['minlength']
&& $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
$atts['autocomplete'] = $tag->get_option( 'autocomplete',
'[-0-9a-zA-Z]+', true );
if ( $tag->has_option( 'readonly' ) ) {
$atts['readonly'] = 'readonly';
}
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = (string) reset( $tag->values );
if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
$atts['placeholder'] = $value;
$value = '';
}
$value = $tag->get_default_option( $value );
$value = wpcf7_get_hangover( $tag->name, $value );
$atts['value'] = $value;
if ( wpcf7_support_html5() ) {
$atts['type'] = $tag->basetype;
} else {
$atts['type'] = 'text';
}
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
' %3$s ',
sanitize_html_class( $tag->name ), $atts, $validation_error );
return $html;
}
/* Validation filter */
add_filter( 'wpcf7_validate_text', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text*', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_email', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_email*', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_url', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_url*', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_tel', 'wpcf7_text_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_tel*', 'wpcf7_text_validation_filter', 10, 2 );
function wpcf7_text_validation_filter( $result, $tag ) {
$tag = new WPCF7_FormTag( $tag );
$name = $tag->name;
$value = isset( $_POST[$name] )
? trim( wp_unslash( strtr( (string) $_POST[$name], "\n", " " ) ) )
: '';
if ( 'text' == $tag->basetype ) {
if ( $tag->is_required() && '' == $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
}
}
if ( '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' ) );
}
}
if ( 'url' == $tag->basetype ) {
if ( $tag->is_required() && '' == $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
} elseif ( '' != $value && ! wpcf7_is_url( $value ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_url' ) );
}
}
if ( 'tel' == $tag->basetype ) {
if ( $tag->is_required() && '' == $value ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
} elseif ( '' != $value && ! wpcf7_is_tel( $value ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'invalid_tel' ) );
}
}
if ( '' !== $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( stripslashes( $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;
}
/* Messages */
add_filter( 'wpcf7_messages', 'wpcf7_text_messages' );
function wpcf7_text_messages( $messages ) {
return array_merge( $messages, array(
'invalid_email' => array(
'description' => __( "Email address that the sender entered is invalid", 'contact-form-7' ),
'default' => __( "The e-mail address entered is invalid.", 'contact-form-7' )
),
'invalid_url' => array(
'description' => __( "URL that the sender entered is invalid", 'contact-form-7' ),
'default' => __( "The URL is invalid.", 'contact-form-7' )
),
'invalid_tel' => array(
'description' => __( "Telephone number that the sender entered is invalid", 'contact-form-7' ),
'default' => __( "The telephone number is invalid.", 'contact-form-7' )
) ) );
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_text', 15 );
function wpcf7_add_tag_generator_text() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'text', __( 'text', 'contact-form-7' ),
'wpcf7_tag_generator_text' );
$tag_generator->add( 'email', __( 'email', 'contact-form-7' ),
'wpcf7_tag_generator_text' );
$tag_generator->add( 'url', __( 'URL', 'contact-form-7' ),
'wpcf7_tag_generator_text' );
$tag_generator->add( 'tel', __( 'tel', 'contact-form-7' ),
'wpcf7_tag_generator_text' );
}
function wpcf7_tag_generator_text( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$type = $args['id'];
if ( ! in_array( $type, array( 'email', 'url', 'tel' ) ) ) {
$type = 'text';
}
if ( 'text' == $type ) {
$description = __( "Generate a form-tag for a single-line plain text input field. For more details, see %s.", 'contact-form-7' );
} elseif ( 'email' == $type ) {
$description = __( "Generate a form-tag for a single-line email address input field. For more details, see %s.", 'contact-form-7' );
} elseif ( 'url' == $type ) {
$description = __( "Generate a form-tag for a single-line URL input field. For more details, see %s.", 'contact-form-7' );
} elseif ( 'tel' == $type ) {
$description = __( "Generate a form-tag for a single-line telephone number input field. For more details, see %s.", 'contact-form-7' );
}
$desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text Fields', 'contact-form-7' ) );
?>
locale();
foreach ( (array) $options as $option ) {
$option = explode( '.', $option );
$type = $option[0];
$args['group'] = isset( $option[1] ) ? $option[1] : null;
if ( $list = listo( $type, $args ) ) {
$data = array_merge( (array) $data, $list );
}
}
return $data;
}
PK P\IH modules/response.phpnu W+A form_response_output();
}
}
PK P\:< < modules/textarea.phpnu W+A true ) );
}
function wpcf7_textarea_form_tag_handler( $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['cols'] = $tag->get_cols_option( '40' );
$atts['rows'] = $tag->get_rows_option( '10' );
$atts['maxlength'] = $tag->get_maxlength_option();
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
$atts['autocomplete'] = $tag->get_option( 'autocomplete',
'[-0-9a-zA-Z]+', true );
if ( $tag->has_option( 'readonly' ) ) {
$atts['readonly'] = 'readonly';
}
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
$atts['aria-invalid'] = $validation_error ? 'true' : 'false';
$value = empty( $tag->content )
? (string) reset( $tag->values )
: $tag->content;
if ( $tag->has_option( 'placeholder' ) || $tag->has_option( 'watermark' ) ) {
$atts['placeholder'] = $value;
$value = '';
}
$value = $tag->get_default_option( $value );
$value = wpcf7_get_hangover( $tag->name, $value );
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts( $atts );
$html = sprintf(
'%4$s ',
sanitize_html_class( $tag->name ), $atts,
esc_textarea( $value ), $validation_error );
return $html;
}
/* Validation filter */
add_filter( 'wpcf7_validate_textarea', 'wpcf7_textarea_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_textarea*', 'wpcf7_textarea_validation_filter', 10, 2 );
function wpcf7_textarea_validation_filter( $result, $tag ) {
$tag = new WPCF7_FormTag( $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 ( '' !== $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( stripslashes( $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;
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20 );
function wpcf7_add_tag_generator_textarea() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'textarea', __( 'text area', 'contact-form-7' ),
'wpcf7_tag_generator_textarea' );
}
function wpcf7_tag_generator_textarea( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$type = 'textarea';
$description = __( "Generate a form-tag for a multi-line text input field. For more details, see %s.", 'contact-form-7' );
$desc_link = wpcf7_link( __( 'https://contactform7.com/text-fields/', 'contact-form-7' ), __( 'Text Fields', 'contact-form-7' ) );
?>
sitekeys = WPCF7::get_option( 'recaptcha' );
}
public function get_title() {
return __( 'reCAPTCHA', 'contact-form-7' );
}
public function is_active() {
$sitekey = $this->get_sitekey();
$secret = $this->get_secret( $sitekey );
return $sitekey && $secret;
}
public function get_categories() {
return array( 'captcha' );
}
public function icon() {
}
public function link() {
echo sprintf( '%2$s ',
'https://www.google.com/recaptcha/intro/index.html',
'google.com/recaptcha' );
}
public function get_sitekey() {
if ( empty( $this->sitekeys ) || ! is_array( $this->sitekeys ) ) {
return false;
}
$sitekeys = array_keys( $this->sitekeys );
return $sitekeys[0];
}
public function get_secret( $sitekey ) {
$sitekeys = (array) $this->sitekeys;
if ( isset( $sitekeys[$sitekey] ) ) {
return $sitekeys[$sitekey];
} else {
return false;
}
}
public function verify( $response_token ) {
$is_human = false;
if ( empty( $response_token ) ) {
return $is_human;
}
$url = self::VERIFY_URL;
$sitekey = $this->get_sitekey();
$secret = $this->get_secret( $sitekey );
$response = wp_safe_remote_post( $url, array(
'body' => array(
'secret' => $secret,
'response' => $response_token,
'remoteip' => $_SERVER['REMOTE_ADDR'] ) ) );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
return $is_human;
}
$response = wp_remote_retrieve_body( $response );
$response = json_decode( $response, true );
$is_human = isset( $response['success'] ) && true == $response['success'];
return $is_human;
}
private function menu_page_url( $args = '' ) {
$args = wp_parse_args( $args, array() );
$url = menu_page_url( 'wpcf7-integration', false );
$url = add_query_arg( array( 'service' => 'recaptcha' ), $url );
if ( ! empty( $args) ) {
$url = add_query_arg( $args, $url );
}
return $url;
}
public function load( $action = '' ) {
if ( 'setup' == $action ) {
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
check_admin_referer( 'wpcf7-recaptcha-setup' );
$sitekey = isset( $_POST['sitekey'] ) ? trim( $_POST['sitekey'] ) : '';
$secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
if ( $sitekey && $secret ) {
WPCF7::update_option( 'recaptcha', array( $sitekey => $secret ) );
$redirect_to = $this->menu_page_url( array(
'message' => 'success' ) );
} elseif ( '' === $sitekey && '' === $secret ) {
WPCF7::update_option( 'recaptcha', null );
$redirect_to = $this->menu_page_url( array(
'message' => 'success' ) );
} else {
$redirect_to = $this->menu_page_url( array(
'action' => 'setup',
'message' => 'invalid' ) );
}
wp_safe_redirect( $redirect_to );
exit();
}
}
}
public function admin_notice( $message = '' ) {
if ( 'invalid' == $message ) {
echo sprintf(
'',
esc_html( __( "ERROR", 'contact-form-7' ) ),
esc_html( __( "Invalid key values.", 'contact-form-7' ) ) );
}
if ( 'success' == $message ) {
echo sprintf( '',
esc_html( __( 'Settings saved.', 'contact-form-7' ) ) );
}
}
public function display( $action = '' ) {
?>
display_setup();
return;
}
if ( $this->is_active() ) {
$sitekey = $this->get_sitekey();
$secret = $this->get_secret( $sitekey );
?>
__( 'CAPTCHA', 'contact-form-7' ) );
foreach ( $categories as $name => $category ) {
$integration->add_category( $name, $category );
}
$services = array(
'recaptcha' => WPCF7_RECAPTCHA::get_instance() );
foreach ( $services as $name => $service ) {
$integration->add_service( $name, $service );
}
}
add_action( 'wpcf7_enqueue_scripts', 'wpcf7_recaptcha_enqueue_scripts' );
function wpcf7_recaptcha_enqueue_scripts() {
$url = 'https://www.google.com/recaptcha/api.js';
$url = add_query_arg( array(
'onload' => 'recaptchaCallback',
'render' => 'explicit' ), $url );
wp_register_script( 'google-recaptcha', $url, array(), '2.0', true );
}
add_action( 'wp_footer', 'wpcf7_recaptcha_callback_script' );
function wpcf7_recaptcha_callback_script() {
if ( ! wp_script_is( 'google-recaptcha', 'enqueued' ) ) {
return;
}
?>
is_active() ) {
wpcf7_add_form_tag( 'recaptcha', 'wpcf7_recaptcha_form_tag_handler' );
}
}
function wpcf7_recaptcha_form_tag_handler( $tag ) {
if ( ! wp_script_is( 'google-recaptcha', 'registered' ) ) {
wpcf7_recaptcha_enqueue_scripts();
}
wp_enqueue_script( 'google-recaptcha' );
$tag = new WPCF7_FormTag( $tag );
$atts = array();
$recaptcha = WPCF7_RECAPTCHA::get_instance();
$atts['data-sitekey'] = $recaptcha->get_sitekey();
$atts['data-theme'] = $tag->get_option( 'theme', '(dark|light)', true );
$atts['data-type'] = $tag->get_option( 'type', '(audio|image)', true );
$atts['data-size'] = $tag->get_option( 'size', '(compact|normal)', true );
$atts['data-tabindex'] = $tag->get_option( 'tabindex', 'int', true );
$atts['data-callback'] = $tag->get_option( 'callback', '', true );
$atts['data-expired-callback'] =
$tag->get_option( 'expired_callback', '', true );
$atts['class'] = $tag->get_class_option(
wpcf7_form_controls_class( $tag->type, 'g-recaptcha' ) );
$atts['id'] = $tag->get_id_option();
$html = sprintf( '
', wpcf7_format_atts( $atts ) );
$html .= wpcf7_recaptcha_noscript(
array( 'sitekey' => $atts['data-sitekey'] ) );
$html = sprintf( '%s
', $html );
return $html;
}
function wpcf7_recaptcha_noscript( $args = '' ) {
$args = wp_parse_args( $args, array(
'sitekey' => '' ) );
if ( empty( $args['sitekey'] ) ) {
return;
}
$url = add_query_arg( 'k', $args['sitekey'],
'https://www.google.com/recaptcha/api/fallback' );
ob_start();
?>
scan_form_tags( array( 'type' => 'recaptcha' ) );
if ( empty( $tags ) ) {
return $spam;
}
$recaptcha = WPCF7_RECAPTCHA::get_instance();
if ( ! $recaptcha->is_active() ) {
return $spam;
}
$response_token = wpcf7_recaptcha_response();
$spam = ! $recaptcha->verify( $response_token );
return $spam;
}
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_recaptcha', 45 );
function wpcf7_add_tag_generator_recaptcha() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'recaptcha', __( 'reCAPTCHA', 'contact-form-7' ),
'wpcf7_tag_generator_recaptcha', array( 'nameless' => 1 ) );
}
function wpcf7_tag_generator_recaptcha( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
$recaptcha = WPCF7_RECAPTCHA::get_instance();
if ( ! $recaptcha->is_active() ) {
?>