PK �NFZ�1
I7 I7 really-simple-captcha.phpnu �[��� <?php
/**
** A base module for [captchac] and [captchar]
**/
/* form_tag handler */
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_captcha', 10, 0 );
function wpcf7_add_form_tag_captcha() {
// CAPTCHA-Challenge (image)
wpcf7_add_form_tag( 'captchac',
'wpcf7_captchac_form_tag_handler',
array(
'name-attr' => true,
'zero-controls-container' => true,
'not-for-mail' => true,
)
);
// CAPTCHA-Response (input)
wpcf7_add_form_tag( 'captchar',
'wpcf7_captchar_form_tag_handler',
array(
'name-attr' => true,
'do-not-store' => true,
'not-for-mail' => true,
)
);
}
function wpcf7_captchac_form_tag_handler( $tag ) {
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
$error = sprintf(
/* translators: %s: link labeled 'Really Simple CAPTCHA' */
esc_html( __( "To use CAPTCHA, you need %s plugin installed.", 'contact-form-7' ) ),
wpcf7_link( 'https://wordpress.org/plugins/really-simple-captcha/', 'Really Simple CAPTCHA' )
);
return sprintf( '<em>%s</em>', $error );
}
if ( empty( $tag->name ) ) {
return '';
}
$class = wpcf7_form_controls_class( $tag->type );
$class .= ' wpcf7-captcha-' . str_replace( ':', '', $tag->name );
$atts = array();
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$op = array( // Default
'img_size' => array( 72, 24 ),
'base' => array( 6, 18 ),
'font_size' => 14,
'font_char_width' => 15,
);
$op = array_merge( $op, wpcf7_captchac_options( $tag->options ) );
if ( ! $filename = wpcf7_generate_captcha( $op ) ) {
return '';
}
if ( ! empty( $op['img_size'] ) ) {
if ( isset( $op['img_size'][0] ) ) {
$atts['width'] = $op['img_size'][0];
}
if ( isset( $op['img_size'][1] ) ) {
$atts['height'] = $op['img_size'][1];
}
}
$atts['alt'] = 'captcha';
$atts['src'] = wpcf7_captcha_url( $filename );
$atts = wpcf7_format_atts( $atts );
$prefix = substr( $filename, 0, strrpos( $filename, '.' ) );
$html = sprintf(
'<input type="hidden" name="%1$s" value="%2$s" /><img %3$s />',
esc_attr( sprintf( '_wpcf7_captcha_challenge_%s', $tag->name ) ),
esc_attr( $prefix ),
$atts
);
return $html;
}
function wpcf7_captchar_form_tag_handler( $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'] and $atts['minlength']
and $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', 'signed_int', true );
$atts['autocomplete'] = 'off';
if ( $validation_error ) {
$atts['aria-invalid'] = 'true';
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
} else {
$atts['aria-invalid'] = 'false';
}
$value = (string) reset( $tag->values );
if ( wpcf7_is_posted() ) {
$value = '';
}
if ( $tag->has_option( 'placeholder' )
or $tag->has_option( 'watermark' ) ) {
$atts['placeholder'] = $value;
$value = '';
}
$atts['value'] = $value;
$atts['type'] = 'text';
$atts['name'] = $tag->name;
$html = sprintf(
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><input %2$s />%3$s</span>',
esc_attr( $tag->name ),
wpcf7_format_atts( $atts ),
$validation_error
);
return $html;
}
/* Validation filter */
add_filter( 'wpcf7_validate_captchar',
'wpcf7_captcha_validation_filter', 10, 2 );
function wpcf7_captcha_validation_filter( $result, $tag ) {
$type = $tag->type;
$name = $tag->name;
$captchac = '_wpcf7_captcha_challenge_' . $name;
$prefix = (string) ( $_POST[$captchac] ?? '' );
$response = (string) ( $_POST[$name] ?? '' );
$response = wpcf7_canonicalize( $response );
if ( 0 === strlen( $prefix )
or ! wpcf7_check_captcha( $prefix, $response ) ) {
$result->invalidate( $tag, wpcf7_get_message( 'captcha_not_match' ) );
}
if ( 0 !== strlen( $prefix ) ) {
wpcf7_remove_captcha( $prefix );
}
return $result;
}
/* Ajax echo filter */
add_filter( 'wpcf7_refill_response', 'wpcf7_captcha_ajax_refill', 10, 1 );
add_filter( 'wpcf7_feedback_response', 'wpcf7_captcha_ajax_refill', 10, 1 );
function wpcf7_captcha_ajax_refill( $items ) {
if ( ! is_array( $items ) ) {
return $items;
}
$tags = wpcf7_scan_form_tags( array( 'type' => 'captchac' ) );
if ( empty( $tags ) ) {
return $items;
}
$refill = array();
foreach ( $tags as $tag ) {
$name = $tag->name;
$options = $tag->options;
if ( empty( $name ) ) {
continue;
}
$op = wpcf7_captchac_options( $options );
if ( $filename = wpcf7_generate_captcha( $op ) ) {
$captcha_url = wpcf7_captcha_url( $filename );
$refill[$name] = $captcha_url;
}
}
if ( ! empty( $refill ) ) {
$items['captcha'] = $refill;
}
return $items;
}
/* Messages */
add_filter( 'wpcf7_messages', 'wpcf7_captcha_messages', 10, 1 );
function wpcf7_captcha_messages( $messages ) {
$messages = array_merge( $messages, array(
'captcha_not_match' => array(
'description' =>
__( "The code that sender entered does not match the CAPTCHA", 'contact-form-7' ),
'default' =>
__( 'Your entered code is incorrect.', 'contact-form-7' ),
),
) );
return $messages;
}
/* Warning message */
add_action( 'wpcf7_admin_warnings',
'wpcf7_captcha_display_warning_message', 10, 3 );
function wpcf7_captcha_display_warning_message( $page, $action, $object ) {
if ( $object instanceof WPCF7_ContactForm ) {
$contact_form = $object;
} else {
return;
}
$has_tags = (bool) $contact_form->scan_form_tags(
array( 'type' => array( 'captchac' ) ) );
if ( ! $has_tags ) {
return;
}
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
return;
}
$uploads_dir = wpcf7_captcha_tmp_dir();
wpcf7_init_captcha();
if ( ! is_dir( $uploads_dir ) or ! wp_is_writable( $uploads_dir ) ) {
$message = sprintf( __( 'This contact form contains CAPTCHA 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 );
wp_admin_notice( esc_html( $message ), 'type=warning' );
}
if (
! function_exists( 'imagecreatetruecolor' ) or
! function_exists( 'imagettftext' )
) {
$message = __( "This contact form contains CAPTCHA fields, but the necessary libraries (GD and FreeType) are not available on your server.", 'contact-form-7' );
wp_admin_notice( esc_html( $message ), 'type=warning' );
}
}
/* CAPTCHA functions */
function wpcf7_init_captcha() {
static $captcha = null;
if ( $captcha ) {
return $captcha;
}
if ( class_exists( 'ReallySimpleCaptcha' ) ) {
$captcha = new ReallySimpleCaptcha();
} else {
return false;
}
$dir = trailingslashit( wpcf7_captcha_tmp_dir() );
$captcha->tmp_dir = $dir;
if ( is_callable( array( $captcha, 'make_tmp_dir' ) ) ) {
$result = $captcha->make_tmp_dir();
if ( ! $result ) {
return false;
}
return $captcha;
}
$result = wp_mkdir_p( $dir );
if ( ! $result ) {
return false;
}
$htaccess_file = path_join( $dir, '.htaccess' );
if ( file_exists( $htaccess_file ) ) {
list( $first_line_comment ) = (array) file(
$htaccess_file,
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
);
if ( '# Apache 2.4+' === $first_line_comment ) {
return $captcha;
}
}
if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
fwrite( $handle, "# Apache 2.4+\n" );
fwrite( $handle, "<IfModule authz_core_module>\n" );
fwrite( $handle, " Require all denied\n" );
fwrite( $handle, ' <FilesMatch "^\w+\.(jpe?g|gif|png)$">' . "\n" );
fwrite( $handle, " Require all granted\n" );
fwrite( $handle, " </FilesMatch>\n" );
fwrite( $handle, "</IfModule>\n" );
fwrite( $handle, "\n" );
fwrite( $handle, "# Apache 2.2\n" );
fwrite( $handle, "<IfModule !authz_core_module>\n" );
fwrite( $handle, " Order deny,allow\n" );
fwrite( $handle, " Deny from all\n" );
fwrite( $handle, ' <FilesMatch "^\w+\.(jpe?g|gif|png)$">' . "\n" );
fwrite( $handle, " Allow from all\n" );
fwrite( $handle, " </FilesMatch>\n" );
fwrite( $handle, "</IfModule>\n" );
fclose( $handle );
}
return $captcha;
}
/**
* Returns the directory path for Really Simple CAPTCHA files.
*
* @return string Directory path.
*/
function wpcf7_captcha_tmp_dir() {
if ( defined( 'WPCF7_CAPTCHA_TMP_DIR' ) ) {
$dir = path_join( WP_CONTENT_DIR, WPCF7_CAPTCHA_TMP_DIR );
wp_mkdir_p( $dir );
if ( wpcf7_is_file_path_in_content_dir( $dir ) ) {
return $dir;
}
}
$dir = path_join( wpcf7_upload_dir( 'dir' ), 'wpcf7_captcha' );
wp_mkdir_p( $dir );
return $dir;
}
function wpcf7_captcha_tmp_url() {
if ( defined( 'WPCF7_CAPTCHA_TMP_URL' ) ) {
return WPCF7_CAPTCHA_TMP_URL;
} else {
return path_join( wpcf7_upload_dir( 'url' ), 'wpcf7_captcha' );
}
}
function wpcf7_captcha_url( $filename ) {
$url = path_join( wpcf7_captcha_tmp_url(), $filename );
if ( is_ssl()
and 'http:' == substr( $url, 0, 5 ) ) {
$url = 'https:' . substr( $url, 5 );
}
return apply_filters( 'wpcf7_captcha_url', sanitize_url( $url ) );
}
function wpcf7_generate_captcha( $options = null ) {
if ( ! $captcha = wpcf7_init_captcha() ) {
return false;
}
if ( ! is_dir( $captcha->tmp_dir )
or ! wp_is_writable( $captcha->tmp_dir ) ) {
return false;
}
$img_type = imagetypes();
if ( $img_type & IMG_PNG ) {
$captcha->img_type = 'png';
} elseif ( $img_type & IMG_GIF ) {
$captcha->img_type = 'gif';
} elseif ( $img_type & IMG_JPG ) {
$captcha->img_type = 'jpeg';
} else {
return false;
}
if ( is_array( $options ) ) {
if ( isset( $options['img_size'] ) ) {
$captcha->img_size = $options['img_size'];
}
if ( isset( $options['base'] ) ) {
$captcha->base = $options['base'];
}
if ( isset( $options['font_size'] ) ) {
$captcha->font_size = $options['font_size'];
}
if ( isset( $options['font_char_width'] ) ) {
$captcha->font_char_width = $options['font_char_width'];
}
if ( isset( $options['fg'] ) ) {
$captcha->fg = $options['fg'];
}
if ( isset( $options['bg'] ) ) {
$captcha->bg = $options['bg'];
}
}
$prefix = wp_rand();
$captcha_word = $captcha->generate_random_word();
return $captcha->generate_image( $prefix, $captcha_word );
}
function wpcf7_check_captcha( $prefix, $response ) {
if ( ! $captcha = wpcf7_init_captcha() ) {
return false;
}
return $captcha->check( $prefix, $response );
}
function wpcf7_remove_captcha( $prefix ) {
if ( ! $captcha = wpcf7_init_captcha() ) {
return false;
}
// Contact Form 7 generates $prefix with wp_rand()
if ( preg_match( '/[^0-9]/', $prefix ) ) {
return false;
}
$captcha->remove( $prefix );
}
add_action( 'shutdown', 'wpcf7_cleanup_captcha_files', 20, 0 );
function wpcf7_cleanup_captcha_files() {
if ( ! $captcha = wpcf7_init_captcha() ) {
return false;
}
if ( is_callable( array( $captcha, 'cleanup' ) ) ) {
return $captcha->cleanup();
}
$dir = trailingslashit( wpcf7_captcha_tmp_dir() );
if ( ! is_dir( $dir )
or ! is_readable( $dir )
or ! wp_is_writable( $dir ) ) {
return false;
}
if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( ! preg_match( '/^[0-9]+\.(php|txt|png|gif|jpeg)$/', $file ) ) {
continue;
}
$stat = stat( path_join( $dir, $file ) );
if ( $stat['mtime'] + HOUR_IN_SECONDS < time() ) {
@unlink( path_join( $dir, $file ) );
}
}
closedir( $handle );
}
}
function wpcf7_captchac_options( $options ) {
if ( ! is_array( $options ) ) {
return array();
}
$op = array();
$image_size_array = preg_grep( '%^size:[smlSML]$%', $options );
if ( $image_size = array_shift( $image_size_array ) ) {
preg_match( '%^size:([smlSML])$%', $image_size, $is_matches );
switch ( strtolower( $is_matches[1] ) ) {
case 's':
$op['img_size'] = array( 60, 20 );
$op['base'] = array( 6, 15 );
$op['font_size'] = 11;
$op['font_char_width'] = 13;
break;
case 'l':
$op['img_size'] = array( 84, 28 );
$op['base'] = array( 6, 20 );
$op['font_size'] = 17;
$op['font_char_width'] = 19;
break;
case 'm':
default:
$op['img_size'] = array( 72, 24 );
$op['base'] = array( 6, 18 );
$op['font_size'] = 14;
$op['font_char_width'] = 15;
}
}
$fg_color_array = preg_grep(
'%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options );
if ( $fg_color = array_shift( $fg_color_array ) ) {
preg_match( '%^fg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%',
$fg_color, $fc_matches );
if ( 3 == strlen( $fc_matches[1] ) ) {
$r = substr( $fc_matches[1], 0, 1 );
$g = substr( $fc_matches[1], 1, 1 );
$b = substr( $fc_matches[1], 2, 1 );
$op['fg'] = array(
hexdec( $r . $r ),
hexdec( $g . $g ),
hexdec( $b . $b ),
);
} elseif ( 6 == strlen( $fc_matches[1] ) ) {
$r = substr( $fc_matches[1], 0, 2 );
$g = substr( $fc_matches[1], 2, 2 );
$b = substr( $fc_matches[1], 4, 2 );
$op['fg'] = array(
hexdec( $r ),
hexdec( $g ),
hexdec( $b ),
);
}
}
$bg_color_array = preg_grep(
'%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%', $options );
if ( $bg_color = array_shift( $bg_color_array ) ) {
preg_match( '%^bg:#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$%',
$bg_color, $bc_matches );
if ( 3 == strlen( $bc_matches[1] ) ) {
$r = substr( $bc_matches[1], 0, 1 );
$g = substr( $bc_matches[1], 1, 1 );
$b = substr( $bc_matches[1], 2, 1 );
$op['bg'] = array(
hexdec( $r . $r ),
hexdec( $g . $g ),
hexdec( $b . $b ),
);
} elseif ( 6 == strlen( $bc_matches[1] ) ) {
$r = substr( $bc_matches[1], 0, 2 );
$g = substr( $bc_matches[1], 2, 2 );
$b = substr( $bc_matches[1], 4, 2 );
$op['bg'] = array(
hexdec( $r ),
hexdec( $g ),
hexdec( $b ),
);
}
}
return $op;
}
PK �NFZ�H��? ?
submit.phpnu �[��� <?php
/**
** A base module for [submit]
**/
/* form_tag handler */
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_submit', 10, 0 );
function wpcf7_add_form_tag_submit() {
wpcf7_add_form_tag( 'submit', 'wpcf7_submit_form_tag_handler' );
}
function wpcf7_submit_form_tag_handler( $tag ) {
$class = wpcf7_form_controls_class( $tag->type, 'has-spinner' );
$atts = array();
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
$value = isset( $tag->values[0] ) ? $tag->values[0] : '';
if ( empty( $value ) ) {
$value = __( 'Send', 'contact-form-7' );
}
$atts['type'] = 'submit';
$atts['value'] = $value;
$atts = wpcf7_format_atts( $atts );
$html = sprintf( '<input %1$s />', $atts );
return $html;
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_submit', 55, 0 );
function wpcf7_add_tag_generator_submit() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'submit', __( 'submit', 'contact-form-7' ),
'wpcf7_tag_generator_submit',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_submit( $contact_form, $options ) {
$field_types = array(
'submit' => array(
'display_name' => __( 'Submit button', 'contact-form-7' ),
'heading' => __( 'Submit button form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/submit-button/">submit button</a>.', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
<header class="description-box">
<h3><?php
echo esc_html( $field_types['submit']['heading'] );
?></h3>
<p><?php
$description = wp_kses(
$field_types['submit']['description'],
array(
'a' => array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?></p>
</header>
<div class="control-box">
<?php
$tgg->print( 'field_type', array(
'select_options' => array(
'submit' => $field_types['submit']['display_name'],
),
) );
$tgg->print( 'class_attr' );
$tgg->print( 'default_value', array(
'title' => __( 'Label', 'contact-form-7' ),
) );
?>
</div>
<footer class="insert-box">
<?php
$tgg->print( 'insert_box_content' );
?>
</footer>
<?php
}
PK �NFZ����� � date.phpnu �[��� <?php
/**
** A base module for the following types of tags:
** [date] and [date*] # Date
**/
/* form_tag handler */
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_date', 10, 0 );
function wpcf7_add_form_tag_date() {
wpcf7_add_form_tag( array( 'date', 'date*' ),
'wpcf7_date_form_tag_handler',
array(
'name-attr' => true,
)
);
}
function wpcf7_date_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
$class .= ' wpcf7-validates-as-date';
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', 'signed_int', true );
$atts['min'] = $tag->get_date_option( 'min' );
$atts['max'] = $tag->get_date_option( 'max' );
$atts['step'] = $tag->get_option( 'step', 'int', true );
$atts['readonly'] = $tag->has_option( 'readonly' );
$atts['autocomplete'] = $tag->get_option(
'autocomplete', '[-0-9a-zA-Z]+', true
);
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
if ( $validation_error ) {
$atts['aria-invalid'] = 'true';
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
} else {
$atts['aria-invalid'] = 'false';
}
$value = (string) reset( $tag->values );
if ( $tag->has_option( 'placeholder' )
or $tag->has_option( 'watermark' ) ) {
$atts['placeholder'] = $value;
$value = '';
}
$value = $tag->get_default_option( $value );
if ( $value ) {
$datetime_obj = date_create_immutable(
preg_replace( '/[_]+/', ' ', $value ),
wp_timezone()
);
if ( $datetime_obj ) {
$value = $datetime_obj->format( 'Y-m-d' );
}
}
$value = wpcf7_get_hangover( $tag->name, $value );
$atts['value'] = $value;
$atts['type'] = $tag->basetype;
$atts['name'] = $tag->name;
$html = sprintf(
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><input %2$s />%3$s</span>',
esc_attr( $tag->name ),
wpcf7_format_atts( $atts ),
$validation_error
);
return $html;
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_date_rules',
10, 2
);
function wpcf7_swv_add_date_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'date' ),
) );
foreach ( $tags as $tag ) {
if ( $tag->is_required() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'required', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_required' ),
) )
);
}
$schema->add_rule(
wpcf7_swv_create_rule( 'date', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_date' ),
) )
);
$min = $tag->get_date_option( 'min' );
$max = $tag->get_date_option( 'max' );
if ( false !== $min ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'mindate', array(
'field' => $tag->name,
'threshold' => $min,
'error' => wpcf7_get_message( 'date_too_early' ),
) )
);
}
if ( false !== $max ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'maxdate', array(
'field' => $tag->name,
'threshold' => $max,
'error' => wpcf7_get_message( 'date_too_late' ),
) )
);
}
}
}
/* Messages */
add_filter( 'wpcf7_messages', 'wpcf7_date_messages', 10, 1 );
function wpcf7_date_messages( $messages ) {
return array_merge( $messages, array(
'invalid_date' => array(
'description' => __( "Date format that the sender entered is invalid", 'contact-form-7' ),
'default' => __( "Please enter a date in YYYY-MM-DD format.", 'contact-form-7' ),
),
'date_too_early' => array(
'description' => __( "Date is earlier than minimum limit", 'contact-form-7' ),
'default' => __( "This field has a too early date.", 'contact-form-7' ),
),
'date_too_late' => array(
'description' => __( "Date is later than maximum limit", 'contact-form-7' ),
'default' => __( "This field has a too late date.", 'contact-form-7' ),
),
) );
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_date', 19, 0 );
function wpcf7_add_tag_generator_date() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'date', __( 'date', 'contact-form-7' ),
'wpcf7_tag_generator_date',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_date( $contact_form, $options ) {
$field_types = array(
'date' => array(
'display_name' => __( 'Date field', 'contact-form-7' ),
'heading' => __( 'Date field form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/date-field/">date input field</a>.', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
<header class="description-box">
<h3><?php
echo esc_html( $field_types['date']['heading'] );
?></h3>
<p><?php
$description = wp_kses(
$field_types['date']['description'],
array(
'a' => array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?></p>
</header>
<div class="control-box">
<?php
$tgg->print( 'field_type', array(
'with_required' => true,
'select_options' => array(
'date' => $field_types['date']['display_name'],
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'min_max', array(
'type' => 'date',
'title' => __( 'Range', 'contact-form-7' ),
'min_option' => 'min:',
'max_option' => 'max:',
) );
$tgg->print( 'default_value', array(
'type' => 'date',
'with_placeholder' => false,
) );
?>
</div>
<footer class="insert-box">
<?php
$tgg->print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
</footer>
<?php
}
PK �NFZt�P� reflection.phpnu �[��� <?php
/**
* Reflection module
*
* @link https://contactform7.com/reflection/
*/
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_reflection', 10, 0 );
/**
* Registers reflection-related form-tag types.
*/
function wpcf7_add_form_tag_reflection() {
wpcf7_add_form_tag( 'reflection',
'wpcf7_reflection_form_tag_handler',
array(
'name-attr' => true,
'display-block' => true,
'not-for-mail' => true,
)
);
wpcf7_add_form_tag( 'output',
'wpcf7_output_form_tag_handler',
array(
'name-attr' => true,
'not-for-mail' => true,
)
);
}
/**
* The form-tag handler for the reflection type.
*/
function wpcf7_reflection_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$values = $tag->values ? $tag->values : array( '' );
if ( ! wpcf7_get_validation_error( $tag->name ) ) {
$hangover = array_filter( (array) wpcf7_get_hangover( $tag->name ) );
if ( $hangover ) {
$values = $hangover;
}
}
$content = array_reduce(
$values,
static function ( $carry, $item ) use ( $tag ) {
$output_tag = sprintf(
'<output %1$s>%2$s</output>',
wpcf7_format_atts( array(
'name' => $tag->name,
'data-default' => $item,
) ),
( '' !== $item ) ? esc_html( $item ) : ' '
);
return $carry . $output_tag;
},
''
);
$html = sprintf(
'<fieldset %1$s>%2$s</fieldset>',
wpcf7_format_atts( array(
'data-reflection-of' => $tag->name,
'class' => $tag->get_class_option(
wpcf7_form_controls_class( $tag->type )
),
'id' => $tag->get_id_option(),
) ),
$content
);
return $html;
}
/**
* The form-tag handler for the output type.
*/
function wpcf7_output_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$value = (string) reset( $tag->values );
if ( ! wpcf7_get_validation_error( $tag->name ) ) {
$hangover = array_filter( (array) wpcf7_get_hangover( $tag->name ) );
if ( $hangover ) {
$value = (string) reset( $hangover );
}
}
$html = sprintf(
'<output %1$s>%2$s</output>',
wpcf7_format_atts( array(
'data-reflection-of' => $tag->name,
'data-default' => $value,
'name' => $tag->name,
'class' => $tag->get_class_option(
wpcf7_form_controls_class( $tag->type )
),
'id' => $tag->get_id_option(),
) ),
esc_html( $value )
);
return $html;
}
PK �NFZ0{P%O O stripe/stripe.phpnu �[��� <?php
/**
* Stripe module main file
*
* @link https://contactform7.com/stripe-integration/
*/
wpcf7_include_module_file( 'stripe/service.php' );
wpcf7_include_module_file( 'stripe/api.php' );
add_action(
'wpcf7_init',
'wpcf7_stripe_register_service',
50, 0
);
/**
* Registers the Stripe service.
*/
function wpcf7_stripe_register_service() {
$integration = WPCF7_Integration::get_instance();
$integration->add_service( 'stripe',
WPCF7_Stripe::get_instance()
);
}
add_action(
'wpcf7_enqueue_scripts',
'wpcf7_stripe_enqueue_scripts',
10, 0
);
/**
* Enqueues scripts and styles for the Stripe module.
*/
function wpcf7_stripe_enqueue_scripts() {
$service = WPCF7_Stripe::get_instance();
if ( ! $service->is_active() ) {
return;
}
wp_enqueue_style( 'wpcf7-stripe',
wpcf7_plugin_url( 'modules/stripe/style.css' ),
array(), WPCF7_VERSION, 'all'
);
wp_register_script(
'stripe',
'https://js.stripe.com/v3/',
array(),
null
);
$assets = include(
wpcf7_plugin_path( 'modules/stripe/index.asset.php' )
);
$assets = wp_parse_args( $assets, array(
'dependencies' => array(),
'version' => WPCF7_VERSION,
) );
wp_enqueue_script(
'wpcf7-stripe',
wpcf7_plugin_url( 'modules/stripe/index.js' ),
array_merge(
$assets['dependencies'],
array(
'wp-polyfill',
'contact-form-7',
'stripe',
)
),
$assets['version'],
array( 'in_footer' => true )
);
$api_keys = $service->get_api_keys();
if ( $api_keys['publishable'] ) {
wp_add_inline_script( 'wpcf7-stripe',
sprintf(
'var wpcf7_stripe = %s;',
wp_json_encode( array(
'publishable_key' => $api_keys['publishable'],
), JSON_PRETTY_PRINT )
),
'before'
);
}
}
add_filter(
'wpcf7_skip_spam_check',
'wpcf7_stripe_skip_spam_check',
10, 2
);
/**
* Skips the spam check if it is not necessary.
*
* @return bool True if the spam check is not necessary.
*/
function wpcf7_stripe_skip_spam_check( $skip_spam_check, $submission ) {
$service = WPCF7_Stripe::get_instance();
if ( ! $service->is_active() ) {
return $skip_spam_check;
}
if ( ! empty( $_POST['_wpcf7_stripe_payment_intent'] ) ) {
$pi_id = trim( $_POST['_wpcf7_stripe_payment_intent'] );
$payment_intent = $service->api()->retrieve_payment_intent( $pi_id );
if ( isset( $payment_intent['status'] )
and ( 'succeeded' === $payment_intent['status'] ) ) {
$submission->push( 'payment_intent', $pi_id );
}
}
if ( ! empty( $submission->pull( 'payment_intent' ) )
and $submission->verify_posted_data_hash() ) {
$skip_spam_check = true;
}
return $skip_spam_check;
}
add_action(
'wpcf7_before_send_mail',
'wpcf7_stripe_before_send_mail',
10, 3
);
/**
* Creates Stripe's Payment Intent.
*/
function wpcf7_stripe_before_send_mail( $contact_form, &$abort, $submission ) {
$service = WPCF7_Stripe::get_instance();
if ( ! $service->is_active() ) {
return;
}
$tags = $contact_form->scan_form_tags( array( 'type' => 'stripe' ) );
if ( ! $tags ) {
return;
}
if ( ! empty( $submission->pull( 'payment_intent' ) ) ) {
return;
}
$tag = $tags[0];
$amount = $tag->get_option( 'amount', 'int', true );
$currency = $tag->get_option( 'currency', '[a-zA-Z]{3}', true );
$payment_intent_params = apply_filters(
'wpcf7_stripe_payment_intent_parameters',
array(
'amount' => $amount ? absint( $amount ) : null,
'currency' => $currency ? strtolower( $currency ) : null,
'receipt_email' => $submission->get_posted_data( 'your-email' ),
)
);
$payment_intent = $service->api()->create_payment_intent(
$payment_intent_params
);
if ( $payment_intent ) {
$submission->add_result_props( array(
'stripe' => array(
'payment_intent' => array(
'id' => $payment_intent['id'],
'client_secret' => $payment_intent['client_secret'],
),
),
) );
$submission->set_status( 'payment_required' );
$submission->set_response(
__( "Payment is required. Please pay by credit card.", 'contact-form-7' )
);
}
$abort = true;
}
/**
* Returns payment link URL.
*
* @param string $pi_id Payment Intent ID.
* @return string The URL.
*/
function wpcf7_stripe_get_payment_link( $pi_id ) {
return sprintf(
'https://dashboard.stripe.com/payments/%s',
urlencode( $pi_id )
);
}
add_filter(
'wpcf7_special_mail_tags',
'wpcf7_stripe_smt',
10, 4
);
/**
* Registers the [_stripe_payment_link] special mail-tag.
*/
function wpcf7_stripe_smt( $output, $tag_name, $html, $mail_tag = null ) {
if ( '_stripe_payment_link' === $tag_name ) {
$submission = WPCF7_Submission::get_instance();
$pi_id = $submission->pull( 'payment_intent' );
if ( ! empty( $pi_id ) ) {
$output = wpcf7_stripe_get_payment_link( $pi_id );
}
}
return $output;
}
add_filter(
'wpcf7_flamingo_inbound_message_parameters',
'wpcf7_stripe_add_flamingo_inbound_message_params',
10, 1
);
/**
* Adds Stripe-related meta data to Flamingo Inbound Message parameters.
*/
function wpcf7_stripe_add_flamingo_inbound_message_params( $args ) {
$submission = WPCF7_Submission::get_instance();
$pi_id = $submission->pull( 'payment_intent' );
if ( empty( $pi_id ) ) {
return $args;
}
$pi_link = wpcf7_stripe_get_payment_link( $pi_id );
$meta = (array) $args['meta'];
$meta['stripe_payment_link'] = $pi_link;
$args['meta'] = $meta;
return $args;
}
add_action(
'wpcf7_init',
'wpcf7_add_form_tag_stripe',
10, 0
);
/**
* Registers the stripe form-tag handler.
*/
function wpcf7_add_form_tag_stripe() {
wpcf7_add_form_tag(
'stripe',
'wpcf7_stripe_form_tag_handler',
array(
'display-block' => true,
'singular' => true,
)
);
}
/**
* Defines the stripe form-tag handler.
*
* @return string HTML content that replaces a stripe form-tag.
*/
function wpcf7_stripe_form_tag_handler( $tag ) {
$card_element = sprintf(
'<div %s></div>',
wpcf7_format_atts( array(
'class' => 'card-element wpcf7-form-control',
'aria-invalid' => 'false',
) )
);
$card_element = sprintf(
'<div class="wpcf7-form-control-wrap hidden">%s</div>',
$card_element
);
$button_1_label = __( 'Proceed to checkout', 'contact-form-7' );
if ( isset( $tag->values[0] ) ) {
$button_1_label = trim( $tag->values[0] );
}
$button_1 = sprintf(
'<button %1$s>%2$s</button>',
wpcf7_format_atts( array(
'type' => 'submit',
'class' => 'first',
) ),
esc_html( $button_1_label )
);
$button_2_label = __( 'Complete payment', 'contact-form-7' );
if ( isset( $tag->values[1] ) ) {
$button_2_label = trim( $tag->values[1] );
}
$button_2 = sprintf(
'<button %1$s>%2$s</button>',
wpcf7_format_atts( array(
'type' => 'button',
'class' => 'second hidden',
) ),
esc_html( $button_2_label )
);
$buttons = sprintf(
'<span class="buttons has-spinner">%1$s %2$s</span>',
$button_1, $button_2
);
return sprintf(
'<div class="wpcf7-stripe">%1$s %2$s %3$s</div>',
$card_element,
$buttons,
'<input type="hidden" name="_wpcf7_stripe_payment_intent" value="" />'
);
}
PK �NFZ�+��| | stripe/service.phpnu �[��� <?php
if ( ! class_exists( 'WPCF7_Service' ) ) {
return;
}
class WPCF7_Stripe extends WPCF7_Service {
private static $instance;
private $api_keys;
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
$option = WPCF7::get_option( 'stripe' );
if ( isset( $option['api_keys']['publishable'] )
and isset( $option['api_keys']['secret'] ) ) {
$this->api_keys = array(
'publishable' => $option['api_keys']['publishable'],
'secret' => $option['api_keys']['secret'],
);
}
}
public function get_title() {
return __( 'Stripe', 'contact-form-7' );
}
public function is_active() {
return (bool) $this->get_api_keys();
}
public function api() {
if ( $this->is_active() ) {
$api = new WPCF7_Stripe_API( $this->api_keys['secret'] );
return $api;
}
}
public function get_api_keys() {
return $this->api_keys;
}
public function get_categories() {
return array( 'payments' );
}
public function icon() {
}
public function link() {
echo wpcf7_link(
'https://stripe.com/',
'stripe.com'
);
}
protected function menu_page_url( $args = '' ) {
$args = wp_parse_args( $args, array() );
$url = menu_page_url( 'wpcf7-integration', false );
$url = add_query_arg( array( 'service' => 'stripe' ), $url );
if ( ! empty( $args ) ) {
$url = add_query_arg( $args, $url );
}
return $url;
}
protected function save_data() {
WPCF7::update_option( 'stripe', array(
'api_keys' => $this->api_keys,
) );
}
protected function reset_data() {
$this->api_keys = null;
$this->save_data();
}
public function load( $action = '' ) {
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
check_admin_referer( 'wpcf7-stripe-setup' );
if ( ! empty( $_POST['reset'] ) ) {
$this->reset_data();
$redirect_to = $this->menu_page_url( 'action=setup' );
} else {
$publishable = trim( $_POST['publishable'] ?? '' );
$secret = trim( $_POST['secret'] ?? '' );
if ( $publishable and $secret ) {
$this->api_keys = array(
'publishable' => $publishable,
'secret' => $secret,
);
$this->save_data();
$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 ) {
wp_admin_notice(
sprintf(
'<strong>%1$s</strong>: %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "Invalid key values.", 'contact-form-7' ) )
),
'type=error'
);
}
if ( 'success' === $message ) {
wp_admin_notice(
esc_html( __( "Settings saved.", 'contact-form-7' ) ),
'type=success'
);
}
}
public function display( $action = '' ) {
echo sprintf(
'<p>%s</p>',
// https://stripe.com/docs/partners/support#intro
esc_html( __( "Stripe is a simple and powerful way to accept payments online. Stripe has no setup fees, no monthly fees, and no hidden costs. Millions of businesses rely on Stripe’s software tools to accept payments securely and expand globally.", 'contact-form-7' ) )
);
echo sprintf(
'<p><strong>%s</strong></p>',
wpcf7_link(
__( 'https://contactform7.com/stripe-integration/', 'contact-form-7' ),
__( 'Stripe integration', 'contact-form-7' )
)
);
if ( $this->is_active() ) {
echo sprintf(
'<p class="dashicons-before dashicons-yes">%s</p>',
esc_html( __( "Stripe is active on this site.", 'contact-form-7' ) )
);
}
if ( 'setup' == $action ) {
$this->display_setup();
} elseif ( is_ssl() or WP_DEBUG ) {
echo sprintf(
'<p><a href="%1$s" class="button">%2$s</a></p>',
esc_url( $this->menu_page_url( 'action=setup' ) ),
esc_html( __( 'Setup Integration', 'contact-form-7' ) )
);
} else {
echo sprintf(
'<p class="dashicons-before dashicons-warning">%s</p>',
esc_html( __( "Stripe is not available on this site. It requires an HTTPS-enabled site.", 'contact-form-7' ) )
);
}
}
private function display_setup() {
$api_keys = $this->get_api_keys();
if ( $api_keys ) {
$publishable = $api_keys['publishable'];
$secret = $api_keys['secret'];
} else {
$publishable = '';
$secret = '';
}
?>
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
<?php wp_nonce_field( 'wpcf7-stripe-setup' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="publishable"><?php echo esc_html( __( 'Publishable Key', 'contact-form-7' ) ); ?></label></th>
<td><?php
if ( $this->is_active() ) {
echo esc_html( $publishable );
echo sprintf(
'<input type="hidden" value="%s" id="publishable" name="publishable" />',
esc_attr( $publishable )
);
} else {
echo sprintf(
'<input type="text" aria-required="true" value="%s" id="publishable" name="publishable" class="regular-text code" />',
esc_attr( $publishable )
);
}
?></td>
</tr>
<tr>
<th scope="row"><label for="secret"><?php echo esc_html( __( 'Secret Key', 'contact-form-7' ) ); ?></label></th>
<td><?php
if ( $this->is_active() ) {
echo esc_html( wpcf7_mask_password( $secret ) );
echo sprintf(
'<input type="hidden" value="%s" id="secret" name="secret" />',
esc_attr( $secret )
);
} else {
echo sprintf(
'<input type="text" aria-required="true" value="%s" id="secret" name="secret" class="regular-text code" />',
esc_attr( $secret )
);
}
?></td>
</tr>
</tbody>
</table>
<?php
if ( $this->is_active() ) {
submit_button(
_x( 'Remove Keys', 'API keys', 'contact-form-7' ),
'small', 'reset'
);
} else {
submit_button( __( 'Save Changes', 'contact-form-7' ) );
}
?>
</form>
<?php
}
}
PK �NFZ�AD; ; stripe/style.cssnu �[��� .wpcf7 .wpcf7-stripe .wpcf7-form-control-wrap {
margin: .6em 0;
}
.wpcf7 .wpcf7-stripe .wpcf7-form-control {
display: block;
background: #f6f7f7;
padding: 12px 12px;
border: 1px solid #787c82;
}
.wpcf7 .wpcf7-stripe button:disabled {
cursor: not-allowed;
}
.wpcf7 .wpcf7-stripe .hidden {
display: none;
}
PK �NFZ���Y stripe/index.jsnu �[��� document.addEventListener("DOMContentLoaded",(e=>{const t=()=>{const e=document.querySelectorAll("form.wpcf7-form .wpcf7-stripe");for(let t=0;t<e.length;t++){let r=e[t];r.querySelector("button").disabled=!0;let i=document.createElement("span");i.setAttribute("class","wpcf7-not-valid-tip"),i.insertAdjacentText("beforeend","This form includes a payment widget that requires a modern browser to work."),r.appendChild(i)}};if(void 0===window.wpcf7_stripe)return console.error("window.wpcf7_stripe is not defined."),void t();if("function"!=typeof window.Stripe)return console.error("window.Stripe is not defined."),void t();if("function"!=typeof wpcf7.submit)return console.error("wpcf7.submit is not defined."),void t();const r=Stripe(wpcf7_stripe.publishable_key),i=r.elements();document.addEventListener("wpcf7submit",(e=>{const t=e.detail.unitTag,s=`${t}-ve-stripe-card-element`,n=document.querySelector(`#${t} form`),o=n.closest(".wpcf7").querySelector(".screen-reader-response"),d=n.querySelector(".wpcf7-stripe .wpcf7-form-control-wrap"),c=n.querySelector(".wpcf7-stripe button.first"),a=n.querySelector(".wpcf7-stripe button.second"),l=n.querySelector('[name="_wpcf7_stripe_payment_intent"]');if(!l)return;l.setAttribute("value","");const u=e=>{const t=o.querySelector("ul"),r=t.querySelector(`li#${s}`);r&&r.remove();const i=document.createElement("li");i.setAttribute("id",s),i.insertAdjacentText("beforeend",e.message),t.appendChild(i)},p=e=>{const t=d.querySelector(".wpcf7-form-control");t.classList.add("wpcf7-not-valid"),t.setAttribute("aria-describedby",s);const r=document.createElement("span");r.setAttribute("class","wpcf7-not-valid-tip"),r.setAttribute("aria-hidden","true"),r.insertAdjacentText("beforeend",e.message),d.appendChild(r),d.querySelectorAll("[aria-invalid]").forEach((e=>{e.setAttribute("aria-invalid","true")})),t.closest(".use-floating-validation-tip")&&(t.addEventListener("focus",(e=>{r.setAttribute("style","display: none")})),r.addEventListener("mouseover",(e=>{r.setAttribute("style","display: none")})))},f=()=>{o.querySelectorAll(`ul li#${s}`).forEach((e=>{e.remove()})),d.querySelectorAll(".wpcf7-not-valid-tip").forEach((e=>{e.remove()})),d.querySelectorAll("[aria-invalid]").forEach((e=>{e.setAttribute("aria-invalid","false")})),d.querySelectorAll(".wpcf7-form-control").forEach((e=>{e.removeAttribute("aria-describedby"),e.classList.remove("wpcf7-not-valid")}))};if("payment_required"===e.detail.status){const s=e.detail.apiResponse.stripe.payment_intent;s.id&&l.setAttribute("value",s.id);const o=i.getElement("card")||i.create("card");o.mount(`#${t} .wpcf7-stripe .card-element`),o.clear(),d.classList.remove("hidden"),c.classList.add("hidden"),a.classList.remove("hidden"),a.disabled=!0,o.addEventListener("change",(e=>{if(f(),e.error){const t={message:e.error.message};u(t),p(t),a.disabled=!0}else a.disabled=!1})),a.addEventListener("click",(e=>{f(),a.disabled=!0,n.classList.add("submitting"),wpcf7.blocked||r.confirmCardPayment(s.client_secret,{payment_method:{card:o}}).then((e=>{if(e.error){e.error.decline_code&&["fraudulent","lost_card","merchant_blacklist","pickup_card","restricted_card","security_violation","service_not_allowed","stolen_card","transaction_not_allowed"].includes(e.error.decline_code)&&(wpcf7.blocked=!0),n.classList.remove("submitting");const t={message:e.error.message};u(t),p(t)}else"succeeded"===e.paymentIntent.status&&wpcf7.submit(n)}))}))}else d.classList.add("hidden"),c.classList.remove("hidden"),a.classList.add("hidden"),["mail_sent","mail_failed"].includes(e.detail.status)&&(c.disabled=!0)}))}));PK �NFZ���
�
stripe/api.phpnu �[��� <?php
/**
* Class for the Stripe API.
*
* @link https://stripe.com/docs/api
*/
class WPCF7_Stripe_API {
const api_version = '2022-11-15';
const partner_id = 'pp_partner_HHbvqLh1AaO7Am';
const app_name = 'WordPress Contact Form 7';
const app_url = 'https://contactform7.com/stripe-integration/';
private $secret;
/**
* Constructor.
*
* @param string $secret Secret key.
*/
public function __construct( $secret ) {
$this->secret = $secret;
}
/**
* Sends a debug information for a remote request to the PHP error log.
*
* @param string $url URL to retrieve.
* @param array $request Request arguments.
* @param array|WP_Error $response The response or WP_Error on failure.
*/
private function log( $url, $request, $response ) {
wpcf7_log_remote_request( $url, $request, $response );
}
/**
* Returns default set of HTTP request headers used for Stripe API.
*
* @link https://stripe.com/docs/building-plugins#setappinfo
*
* @return array An associative array of headers.
*/
private function default_headers() {
$app_info = array(
'name' => self::app_name,
'partner_id' => self::partner_id,
'url' => self::app_url,
'version' => WPCF7_VERSION,
);
$ua = array(
'lang' => 'php',
'lang_version' => PHP_VERSION,
'application' => $app_info,
);
$headers = array(
'Authorization' => sprintf( 'Bearer %s', $this->secret ),
'Stripe-Version' => self::api_version,
'X-Stripe-Client-User-Agent' => wp_json_encode( $ua ),
'User-Agent' => sprintf(
'%1$s/%2$s (%3$s)',
self::app_name,
WPCF7_VERSION,
self::app_url
),
);
return $headers;
}
/**
* Creates a Payment Intent.
*
* @link https://stripe.com/docs/api/payment_intents/create
*
* @param string|array $args Optional. Arguments to control behavior.
* @return array|bool An associative array if 200 OK, false otherwise.
*/
public function create_payment_intent( $args = '' ) {
$args = wp_parse_args( $args, array(
'amount' => 0,
'currency' => '',
'receipt_email' => '',
) );
if ( ! is_email( $args['receipt_email'] ) ) {
unset( $args['receipt_email'] );
}
$endpoint = 'https://api.stripe.com/v1/payment_intents';
$request = array(
'headers' => $this->default_headers(),
'body' => $args,
);
$response = wp_remote_post( sanitize_url( $endpoint ), $request );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
return $response_body;
}
/**
* Retrieve a Payment Intent.
*
* @link https://stripe.com/docs/api/payment_intents/retrieve
*
* @param string $id Payment Intent identifier.
* @return array|bool An associative array if 200 OK, false otherwise.
*/
public function retrieve_payment_intent( $id ) {
$endpoint = sprintf(
'https://api.stripe.com/v1/payment_intents/%s',
urlencode( $id )
);
$request = array(
'headers' => $this->default_headers(),
);
$response = wp_remote_get( sanitize_url( $endpoint ), $request );
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$response_body = json_decode( $response_body, true );
return $response_body;
}
}
PK �NFZ8ܤQ Q stripe/index.asset.phpnu �[��� <?php
return array(
'dependencies' => array(),
'version' => WPCF7_VERSION,
);
PK �NFZc��7� � textarea.phpnu �[��� <?php
/**
** A base module for [textarea] and [textarea*]
**/
/* form_tag handler */
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_textarea', 10, 0 );
function wpcf7_add_form_tag_textarea() {
wpcf7_add_form_tag( array( 'textarea', 'textarea*' ),
'wpcf7_textarea_form_tag_handler', array( 'name-attr' => true )
);
}
function wpcf7_textarea_form_tag_handler( $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( '2000' );
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] and $atts['minlength']
and $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', 'signed_int', true );
$atts['readonly'] = $tag->has_option( 'readonly' );
$atts['autocomplete'] = $tag->get_option(
'autocomplete', '[-0-9a-zA-Z]+', true
);
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
if ( $validation_error ) {
$atts['aria-invalid'] = 'true';
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
} else {
$atts['aria-invalid'] = 'false';
}
$value = empty( $tag->content )
? (string) reset( $tag->values )
: $tag->content;
if ( $tag->has_option( 'placeholder' )
or $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;
$html = sprintf(
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><textarea %2$s>%3$s</textarea>%4$s</span>',
esc_attr( $tag->name ),
wpcf7_format_atts( $atts ),
esc_textarea( $value ),
$validation_error
);
return $html;
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_textarea_rules',
10, 2
);
function wpcf7_swv_add_textarea_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'textarea' ),
) );
foreach ( $tags as $tag ) {
if ( $tag->is_required() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'required', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_required' ),
) )
);
}
if ( $minlength = $tag->get_minlength_option() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'minlength', array(
'field' => $tag->name,
'threshold' => absint( $minlength ),
'error' => wpcf7_get_message( 'invalid_too_short' ),
) )
);
}
if ( $maxlength = $tag->get_maxlength_option( '2000' ) ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'maxlength', array(
'field' => $tag->name,
'threshold' => absint( $maxlength ),
'error' => wpcf7_get_message( 'invalid_too_long' ),
) )
);
}
}
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20, 0 );
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',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_textarea( $contact_form, $options ) {
$field_types = array(
'textarea' => array(
'display_name' => __( 'Text area', 'contact-form-7' ),
'heading' => __( 'Text area form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a <a href="https://contactform7.com/text-fields/">multi-line plain text input area</a>.', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
<header class="description-box">
<h3><?php
echo esc_html( $field_types['textarea']['heading'] );
?></h3>
<p><?php
$description = wp_kses(
$field_types['textarea']['description'],
array(
'a' => array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?></p>
</header>
<div class="control-box">
<?php
$tgg->print( 'field_type', array(
'with_required' => true,
'select_options' => array(
'textarea' => $field_types['textarea']['display_name'],
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'min_max', array(
'title' => __( 'Length', 'contact-form-7' ),
'min_option' => 'minlength:',
'max_option' => 'maxlength:',
) );
$tgg->print( 'default_value', array(
'with_placeholder' => true,
'use_content' => true,
) );
?>
</div>
<footer class="insert-box">
<?php
$tgg->print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
</footer>
<?php
}
PK �NFZ��G
hidden.phpnu �[��� <?php
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_hidden', 10, 0 );
function wpcf7_add_form_tag_hidden() {
wpcf7_add_form_tag( 'hidden',
'wpcf7_hidden_form_tag_handler',
array(
'name-attr' => true,
'display-hidden' => true,
)
);
}
function wpcf7_hidden_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$atts = array();
$class = wpcf7_form_controls_class( $tag->type );
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$value = (string) reset( $tag->values );
$value = $tag->get_default_option( $value );
$atts['value'] = $value;
$atts['type'] = 'hidden';
$atts['name'] = $tag->name;
$atts = wpcf7_format_atts( $atts );
$html = sprintf( '<input %s />', $atts );
return $html;
}
PK �NFZ|S�� � response.phpnu �[��� <?php
/**
** A base module for [response]
**/
/* form_tag handler */
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_response', 10, 0 );
function wpcf7_add_form_tag_response() {
wpcf7_add_form_tag( 'response',
'wpcf7_response_form_tag_handler',
array(
'display-block' => true,
)
);
}
function wpcf7_response_form_tag_handler( $tag ) {
if ( $contact_form = wpcf7_get_current_contact_form() ) {
return $contact_form->form_response_output();
}
}
PK �NFZ��\C0 C0 constant-contact/service.phpnu �[��� <?php
if ( ! class_exists( 'WPCF7_Service_OAuth2' ) ) {
return;
}
class WPCF7_ConstantContact extends WPCF7_Service_OAuth2 {
const service_name = 'constant_contact';
const authorization_endpoint
= 'https://authz.constantcontact.com/oauth2/default/v1/authorize';
const token_endpoint
= 'https://authz.constantcontact.com/oauth2/default/v1/token';
private static $instance;
protected $contact_lists = array();
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
private function __construct() {
$this->authorization_endpoint = self::authorization_endpoint;
$this->token_endpoint = self::token_endpoint;
$option = (array) WPCF7::get_option( self::service_name );
if ( isset( $option['client_id'] ) ) {
$this->client_id = $option['client_id'];
}
if ( isset( $option['client_secret'] ) ) {
$this->client_secret = $option['client_secret'];
}
if ( isset( $option['access_token'] ) ) {
$this->access_token = $option['access_token'];
}
if ( isset( $option['refresh_token'] ) ) {
$this->refresh_token = $option['refresh_token'];
}
if ( $this->is_active() ) {
if ( isset( $option['contact_lists'] ) ) {
$this->contact_lists = $option['contact_lists'];
}
}
add_action( 'wpcf7_admin_init', array( $this, 'auth_redirect' ) );
}
public function auth_redirect() {
$auth = isset( $_GET['auth'] ) ? trim( $_GET['auth'] ) : '';
if ( self::service_name === $auth
and current_user_can( 'wpcf7_manage_integration' ) ) {
$redirect_to = add_query_arg(
array(
'service' => self::service_name,
'action' => 'auth_redirect',
'code' => isset( $_GET['code'] ) ? trim( $_GET['code'] ) : '',
'state' => isset( $_GET['state'] ) ? trim( $_GET['state'] ) : '',
),
menu_page_url( 'wpcf7-integration', false )
);
wp_safe_redirect( $redirect_to );
exit();
}
}
protected function save_data() {
$option = array_merge(
(array) WPCF7::get_option( self::service_name ),
array(
'client_id' => $this->client_id,
'client_secret' => $this->client_secret,
'access_token' => $this->access_token,
'refresh_token' => $this->refresh_token,
'contact_lists' => $this->contact_lists,
)
);
WPCF7::update_option( self::service_name, $option );
}
protected function reset_data() {
$this->client_id = '';
$this->client_secret = '';
$this->access_token = '';
$this->refresh_token = '';
$this->contact_lists = array();
$this->save_data();
}
public function get_title() {
return __( 'Constant Contact', 'contact-form-7' );
}
public function get_categories() {
return array( 'email_marketing' );
}
public function icon() {
}
public function link() {
echo 'constantcontact.com';
}
protected function get_redirect_uri() {
return admin_url( '/?auth=' . self::service_name );
}
protected function menu_page_url( $args = '' ) {
$args = wp_parse_args( $args, array() );
$url = menu_page_url( 'wpcf7-integration', false );
$url = add_query_arg( array( 'service' => self::service_name ), $url );
if ( ! empty( $args ) ) {
$url = add_query_arg( $args, $url );
}
return $url;
}
public function load( $action = '' ) {
if ( 'auth_redirect' == $action ) {
$code = isset( $_GET['code'] ) ? urldecode( $_GET['code'] ) : '';
$state = isset( $_GET['state'] ) ? urldecode( $_GET['state'] ) : '';
if ( $code and $state
and wpcf7_verify_nonce( $state, 'wpcf7_constant_contact_authorize' ) ) {
$response = $this->request_token( $code );
}
if ( ! empty( $this->access_token ) ) {
$message = 'success';
} else {
$message = 'failed';
}
wp_safe_redirect( $this->menu_page_url(
array(
'action' => 'setup',
'message' => $message,
)
) );
exit();
}
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
check_admin_referer( 'wpcf7-constant-contact-setup' );
if ( ! empty( $_POST['reset'] ) ) {
$this->reset_data();
} else {
$this->client_id = isset( $_POST['client_id'] )
? trim( $_POST['client_id'] ) : '';
$this->client_secret = isset( $_POST['client_secret'] )
? trim( $_POST['client_secret'] ) : '';
$this->save_data();
$this->authorize( 'contact_data offline_access' );
}
wp_safe_redirect( $this->menu_page_url( 'action=setup' ) );
exit();
}
}
protected function authorize( $scope = '' ) {
$endpoint = add_query_arg(
array_map( 'urlencode', array(
'response_type' => 'code',
'client_id' => $this->client_id,
'redirect_uri' => $this->get_redirect_uri(),
'scope' => $scope,
'state' => wpcf7_create_nonce( 'wpcf7_constant_contact_authorize' ),
) ),
$this->authorization_endpoint
);
if ( wp_redirect( sanitize_url( $endpoint ) ) ) {
exit();
}
}
public function email_exists( $email ) {
$endpoint = add_query_arg(
array(
'email' => $email,
'status' => 'all',
),
'https://api.cc.email/v3/contacts'
);
$request = array(
'method' => 'GET',
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
),
);
$response = $this->remote_request( $endpoint, $request );
if ( 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
if ( empty( $response_body ) ) {
return false;
}
$response_body = json_decode( $response_body, true );
return ! empty( $response_body['contacts'] );
}
public function create_contact( $properties ) {
$endpoint = 'https://api.cc.email/v3/contacts';
$request = array(
'method' => 'POST',
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
),
'body' => wp_json_encode( $properties ),
);
$response = $this->remote_request( $endpoint, $request );
if ( 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
}
public function get_contact_lists() {
$endpoint = 'https://api.cc.email/v3/contact_lists';
$request = array(
'method' => 'GET',
'headers' => array(
'Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8',
),
);
$response = $this->remote_request( $endpoint, $request );
if ( 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
if ( WP_DEBUG ) {
$this->log( $endpoint, $request, $response );
}
return false;
}
$response_body = wp_remote_retrieve_body( $response );
if ( empty( $response_body ) ) {
return false;
}
$response_body = json_decode( $response_body, true );
if ( ! empty( $response_body['lists'] ) ) {
return (array) $response_body['lists'];
} else {
return array();
}
}
public function update_contact_lists( $selection = array() ) {
$contact_lists = array();
$contact_lists_on_api = $this->get_contact_lists();
if ( false !== $contact_lists_on_api ) {
foreach ( (array) $contact_lists_on_api as $list ) {
if ( isset( $list['list_id'] ) ) {
$list_id = trim( $list['list_id'] );
} else {
continue;
}
if ( isset( $this->contact_lists[$list_id]['selected'] ) ) {
$list['selected'] = $this->contact_lists[$list_id]['selected'];
} else {
$list['selected'] = array();
}
$contact_lists[$list_id] = $list;
}
} else {
$contact_lists = $this->contact_lists;
}
foreach ( (array) $selection as $key => $ids_or_names ) {
foreach( $contact_lists as $list_id => $list ) {
if ( in_array( $list['list_id'], (array) $ids_or_names, true )
or in_array( $list['name'], (array) $ids_or_names, true ) ) {
$contact_lists[$list_id]['selected'][$key] = true;
} else {
unset( $contact_lists[$list_id]['selected'][$key] );
}
}
}
$this->contact_lists = $contact_lists;
if ( $selection ) {
$this->save_data();
}
return $this->contact_lists;
}
public function admin_notice( $message = '' ) {
switch ( $message ) {
case 'success':
wp_admin_notice(
esc_html( __( "Connection established.", 'contact-form-7' ) ),
'type=success'
);
break;
case 'failed':
wp_admin_notice(
sprintf(
'<strong>%1$s</strong>: %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "Failed to establish connection. Please double-check your configuration.", 'contact-form-7' ) )
),
'type=error'
);
break;
case 'updated':
wp_admin_notice(
esc_html( __( "Configuration updated.", 'contact-form-7' ) ),
'type=success'
);
break;
}
}
public function display( $action = '' ) {
echo sprintf(
'<p><strong>%1$s</strong> %2$s</p>',
esc_html( __( 'Warning:', 'contact-form-7' ) ),
wpcf7_link(
__( 'https://contactform7.com/2024/02/02/we-end-the-constant-contact-integration/', 'contact-form-7' ),
__( "This feature is deprecated. You are not recommended to use it.", 'contact-form-7' )
)
);
echo sprintf(
'<p>%s</p>',
esc_html( __( "The Constant Contact integration module allows you to send contact data collected through your contact forms to the Constant Contact API. You can create reliable email subscription services in a few easy steps.", 'contact-form-7' ) )
);
echo sprintf(
'<p><strong>%s</strong></p>',
wpcf7_link(
__( 'https://contactform7.com/constant-contact-integration/', 'contact-form-7' ),
__( 'Constant Contact integration', 'contact-form-7' )
)
);
if ( $this->is_active() ) {
echo sprintf(
'<p class="dashicons-before dashicons-yes">%s</p>',
esc_html( __( "This site is connected to the Constant Contact API.", 'contact-form-7' ) )
);
}
if ( 'setup' == $action ) {
$this->display_setup();
} else {
echo sprintf(
'<p><a href="%1$s" class="button">%2$s</a></p>',
esc_url( $this->menu_page_url( 'action=setup' ) ),
esc_html( __( 'Setup Integration', 'contact-form-7' ) )
);
}
}
private function display_setup() {
?>
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
<?php wp_nonce_field( 'wpcf7-constant-contact-setup' ); ?>
<table class="form-table">
<tbody>
<tr>
<th scope="row"><label for="client_id"><?php echo esc_html( __( 'API Key', 'contact-form-7' ) ); ?></label></th>
<td><?php
if ( $this->is_active() ) {
echo esc_html( $this->client_id );
echo sprintf(
'<input type="hidden" value="%1$s" id="client_id" name="client_id" />',
esc_attr( $this->client_id )
);
} else {
echo sprintf(
'<input type="text" aria-required="true" value="%1$s" id="client_id" name="client_id" class="regular-text code" />',
esc_attr( $this->client_id )
);
}
?></td>
</tr>
<tr>
<th scope="row"><label for="client_secret"><?php echo esc_html( __( 'App Secret', 'contact-form-7' ) ); ?></label></th>
<td><?php
if ( $this->is_active() ) {
echo esc_html( wpcf7_mask_password( $this->client_secret, 4, 4 ) );
echo sprintf(
'<input type="hidden" value="%1$s" id="client_secret" name="client_secret" />',
esc_attr( $this->client_secret )
);
} else {
echo sprintf(
'<input type="text" aria-required="true" value="%1$s" id="client_secret" name="client_secret" class="regular-text code" />',
esc_attr( $this->client_secret )
);
}
?></td>
</tr>
<tr>
<th scope="row"><label for="redirect_uri"><?php echo esc_html( __( 'Redirect URI', 'contact-form-7' ) ); ?></label></th>
<td><?php
echo sprintf(
'<input type="text" value="%1$s" id="redirect_uri" name="redirect_uri" class="large-text code" readonly="readonly" onfocus="this.select();" style="font-size: 11px;" />',
$this->get_redirect_uri()
);
?>
<p class="description"><?php echo esc_html( __( "Set this URL as the redirect URI.", 'contact-form-7' ) ); ?></p>
</td>
</tr>
</tbody>
</table>
<?php
if ( $this->is_active() ) {
submit_button(
_x( 'Reset Keys', 'API keys', 'contact-form-7' ),
'small', 'reset'
);
} else {
submit_button(
__( 'Connect to the Constant Contact API', 'contact-form-7' )
);
}
?>
</form>
<?php
}
}
PK �NFZ�Гk�
�
% constant-contact/constant-contact.phpnu �[��� <?php
/**
* Constant Contact module main file
*
* @link https://contactform7.com/constant-contact-integration/
*/
wpcf7_include_module_file( 'constant-contact/service.php' );
wpcf7_include_module_file( 'constant-contact/contact-post-request.php' );
wpcf7_include_module_file( 'constant-contact/contact-form-properties.php' );
wpcf7_include_module_file( 'constant-contact/doi.php' );
add_action(
'wpcf7_init',
'wpcf7_constant_contact_register_service',
120, 0
);
/**
* Registers the Constant Contact service.
*/
function wpcf7_constant_contact_register_service() {
$integration = WPCF7_Integration::get_instance();
$service = WPCF7_ConstantContact::get_instance();
$integration->add_service( 'constant_contact', $service );
}
add_action( 'wpcf7_submit', 'wpcf7_constant_contact_submit', 10, 2 );
/**
* Callback to the wpcf7_submit action hook. Creates a contact
* based on the submission.
*/
function wpcf7_constant_contact_submit( $contact_form, $result ) {
$service = WPCF7_ConstantContact::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( $contact_form->in_demo_mode() ) {
return;
}
$do_submit = true;
if ( empty( $result['status'] )
or ! in_array( $result['status'], array( 'mail_sent' ) ) ) {
$do_submit = false;
}
$prop = $contact_form->prop( 'constant_contact' );
if ( empty( $prop['enable_contact_list'] ) ) {
$do_submit = false;
}
$do_submit = apply_filters( 'wpcf7_constant_contact_submit',
$do_submit, $contact_form, $result
);
if ( ! $do_submit ) {
return;
}
$submission = WPCF7_Submission::get_instance();
$consented = true;
foreach ( $contact_form->scan_form_tags( 'feature=name-attr' ) as $tag ) {
if ( $tag->has_option( 'consent_for:constant_contact' )
and null == $submission->get_posted_data( $tag->name ) ) {
$consented = false;
break;
}
}
if ( ! $consented ) {
return;
}
$request_builder_class_name = apply_filters(
'wpcf7_constant_contact_contact_post_request_builder',
'WPCF7_ConstantContact_ContactPostRequest'
);
if ( ! class_exists( $request_builder_class_name ) ) {
return;
}
$request_builder = new $request_builder_class_name;
$request_builder->build( $submission );
if ( ! $request_builder->is_valid() ) {
return;
}
$email = $request_builder->get_email_address();
if ( $email ) {
if ( $service->email_exists( $email ) ) {
return;
}
$token = null;
do_action_ref_array( 'wpcf7_doi', array(
'wpcf7_constant_contact',
array(
'email_to' => $email,
'properties' => $request_builder->to_array(),
),
&$token,
) );
if ( isset( $token ) ) {
return;
}
}
$service->create_contact( $request_builder->to_array() );
}
PK �NFZ�ϳ@+ + ) constant-contact/contact-post-request.phpnu �[��� <?php
class WPCF7_ConstantContact_ContactPostRequest {
private $email_address;
private $first_name;
private $last_name;
private $job_title;
private $company_name;
private $create_source;
private $birthday_month;
private $birthday_day;
private $anniversary;
private $custom_fields = array();
private $phone_numbers = array();
private $street_addresses = array();
private $list_memberships = array();
public function __construct() {
}
public function build( WPCF7_Submission $submission ) {
$this->set_create_source( 'Contact' );
$this->set_first_name(
$submission->get_posted_string( 'your-first-name' )
);
$this->set_last_name(
$submission->get_posted_string( 'your-last-name' )
);
if ( ! ( $this->first_name || $this->last_name )
and $your_name = $submission->get_posted_string( 'your-name' ) ) {
$your_name = preg_split( '/[\s]+/', $your_name, 2 );
$this->set_first_name( array_shift( $your_name ) );
$this->set_last_name( array_shift( $your_name ) );
}
$this->set_email_address(
$submission->get_posted_string( 'your-email' ),
'implicit'
);
$this->set_job_title(
$submission->get_posted_string( 'your-job-title' )
);
$this->set_company_name(
$submission->get_posted_string( 'your-company-name' )
);
$this->set_birthday(
$submission->get_posted_string( 'your-birthday-month' ),
$submission->get_posted_string( 'your-birthday-day' )
);
if ( ! ( $this->birthday_month && $this->birthday_day ) ) {
$date = $submission->get_posted_string( 'your-birthday' );
if ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})$/', $date, $matches ) ) {
$this->set_birthday( $matches[2], $matches[3] );
}
}
$this->set_anniversary(
$submission->get_posted_string( 'your-anniversary' )
);
$this->add_phone_number(
$submission->get_posted_string( 'your-phone-number' )
);
$this->add_street_address(
$submission->get_posted_string( 'your-address-street' ),
$submission->get_posted_string( 'your-address-city' ),
$submission->get_posted_string( 'your-address-state' ),
$submission->get_posted_string( 'your-address-postal-code' ),
$submission->get_posted_string( 'your-address-country' )
);
$service_option = (array) WPCF7::get_option( 'constant_contact' );
$contact_lists = isset( $service_option['contact_lists'] )
? $service_option['contact_lists'] : array();
$contact_form = $submission->get_contact_form();
$prop = $contact_form->prop( 'constant_contact' );
if ( ! empty( $prop['enable_contact_list'] )
and ! empty( $prop['contact_lists'] ) ) {
foreach ( (array) $prop['contact_lists'] as $list_id ) {
$this->add_list_membership( $list_id );
}
}
}
public function is_valid() {
return $this->create_source
&& ( $this->email_address || $this->first_name || $this->last_name );
}
public function to_array() {
$output = array(
'email_address' => $this->email_address,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'job_title' => $this->job_title,
'company_name' => $this->company_name,
'create_source' => $this->create_source,
'birthday_month' => $this->birthday_month,
'birthday_day' => $this->birthday_day,
'anniversary' => $this->anniversary,
'custom_fields' => $this->custom_fields,
'phone_numbers' => $this->phone_numbers,
'street_addresses' => $this->street_addresses,
'list_memberships' => $this->list_memberships,
);
return array_filter( $output );
}
public function get_email_address() {
if ( isset( $this->email_address['address'] ) ) {
return $this->email_address['address'];
}
return '';
}
public function set_email_address( $address, $permission_to_send = '' ) {
if ( ! wpcf7_is_email( $address )
or 80 < $this->strlen( $address ) ) {
return false;
}
$types_of_permission = array(
'implicit', 'explicit', 'deprecate', 'pending',
'unsubscribe', 'temp_hold', 'not_set',
);
if ( ! in_array( $permission_to_send, $types_of_permission ) ) {
$permission_to_send = 'implicit';
}
return $this->email_address = array(
'address' => $address,
'permission_to_send' => $permission_to_send,
);
}
public function set_first_name( $first_name ) {
$first_name = trim( $first_name );
if ( empty( $first_name )
or 50 < $this->strlen( $first_name ) ) {
return false;
}
return $this->first_name = $first_name;
}
public function set_last_name( $last_name ) {
$last_name = trim( $last_name );
if ( empty( $last_name )
or 50 < $this->strlen( $last_name ) ) {
return false;
}
return $this->last_name = $last_name;
}
public function set_job_title( $job_title ) {
$job_title = trim( $job_title );
if ( empty( $job_title )
or 50 < $this->strlen( $job_title ) ) {
return false;
}
return $this->job_title = $job_title;
}
public function set_company_name( $company_name ) {
$company_name = trim( $company_name );
if ( empty( $company_name )
or 50 < $this->strlen( $company_name ) ) {
return false;
}
return $this->company_name = $company_name;
}
public function set_create_source( $create_source ) {
if ( ! in_array( $create_source, array( 'Contact', 'Account' ) ) ) {
return false;
}
return $this->create_source = $create_source;
}
public function set_birthday( $month, $day ) {
$month = (int) $month;
$day = (int) $day;
if ( $month < 1 || 12 < $month
or $day < 1 || 31 < $day ) {
return false;
}
$this->birthday_month = $month;
$this->birthday_day = $day;
return array( $this->birthday_month, $this->birthday_day );
}
public function set_anniversary( $anniversary ) {
$pattern = sprintf(
'#^(%s)$#',
implode( '|', array(
'\d{1,2}/\d{1,2}/\d{4}',
'\d{4}/\d{1,2}/\d{1,2}',
'\d{4}-\d{1,2}-\d{1,2}',
'\d{1,2}-\d{1,2}-\d{4}',
) )
);
if ( ! preg_match( $pattern, $anniversary ) ) {
return false;
}
return $this->anniversary = $anniversary;
}
public function add_custom_field( $custom_field_id, $value ) {
$uuid_pattern = '/^[0-9a-f-]+$/i';
$value = trim( $value );
if ( 25 <= count( $this->custom_fields )
or ! preg_match( $uuid_pattern, $custom_field_id )
or 255 < $this->strlen( $value ) ) {
return false;
}
return $this->custom_fields[] = array(
'custom_field_id' => $custom_field_id,
'value' => $value,
);
}
public function add_phone_number( $phone_number, $kind = 'home' ) {
$phone_number = trim( $phone_number );
if ( empty( $phone_number )
or ! wpcf7_is_tel( $phone_number )
or 25 < $this->strlen( $phone_number )
or 2 <= count( $this->phone_numbers )
or ! in_array( $kind, array( 'home', 'work', 'other' ) ) ) {
return false;
}
return $this->phone_numbers[] = array(
'phone_number' => $phone_number,
'kind' => $kind,
);
}
public function add_street_address( $street, $city, $state, $postal_code, $country, $kind = 'home' ) {
$street = trim( $street );
$city = trim( $city );
$state = trim( $state );
$postal_code = trim( $postal_code );
$country = trim( $country );
if ( ! ( $street || $city || $state || $postal_code || $country )
or 1 <= count( $this->street_addresses )
or ! in_array( $kind, array( 'home', 'work', 'other' ) )
or 255 < $this->strlen( $street )
or 50 < $this->strlen( $city )
or 50 < $this->strlen( $state )
or 50 < $this->strlen( $postal_code )
or 50 < $this->strlen( $country ) ) {
return false;
}
return $this->street_addresses[] = array(
'kind' => $kind,
'street' => $street,
'city' => $city,
'state' => $state,
'postal_code' => $postal_code,
'country' => $country,
);
}
public function add_list_membership( $list_id ) {
$uuid_pattern = '/^[0-9a-f-]+$/i';
if ( 50 <= count( $this->list_memberships )
or ! preg_match( $uuid_pattern, $list_id ) ) {
return false;
}
return $this->list_memberships[] = $list_id;
}
protected function strlen( $text ) {
return wpcf7_count_code_units( $text );
}
}
PK �NFZ[�A� � constant-contact/doi.phpnu �[��� <?php
/**
* Double Opt-In Helper-related functions
*
* @link https://contactform7.com/doi-helper/
*/
add_action(
'doihelper_init',
'wpcf7_constant_contact_doi_register_agent',
10, 0
);
/**
* Registers wpcf7_constant_contact as an agent.
*/
function wpcf7_constant_contact_doi_register_agent() {
if ( ! function_exists( 'doihelper_register_agent' ) ) {
return;
}
doihelper_register_agent( 'wpcf7_constant_contact', array(
'optin_callback' => apply_filters(
'wpcf7_constant_contact_doi_optin_callback',
'wpcf7_constant_contact_doi_default_optin_callback'
),
'email_callback' => apply_filters(
'wpcf7_constant_contact_doi_email_callback',
'wpcf7_constant_contact_doi_default_email_callback'
),
) );
}
/**
* Default optin_callback function.
*/
function wpcf7_constant_contact_doi_default_optin_callback( $properties ) {
$service = WPCF7_ConstantContact::get_instance();
if ( $service->is_active() ) {
$service->create_contact( $properties );
}
}
/**
* Default email_callback function.
*/
function wpcf7_constant_contact_doi_default_email_callback( $args ) {
if ( ! isset( $args['token'] ) or ! isset( $args['email_to'] ) ) {
return;
}
$site_title = wp_specialchars_decode(
get_bloginfo( 'name' ),
ENT_QUOTES
);
$link = add_query_arg(
array( 'doitoken' => $args['token'] ),
home_url()
);
$to = $args['email_to'];
$subject = sprintf(
/* translators: %s: blog name */
__( 'Opt-in confirmation from %s', 'contact-form-7' ),
$site_title
);
$message = sprintf(
/* translators: 1: blog name, 2: confirmation link */
__( 'Hello,
This is a confirmation email sent from %1$s.
We have received your submission to our web form, according to which you have allowed us to add you to our contact list. But, the process has not yet been completed. To complete it, please click the following link.
%2$s
If it was not your intention, or if you have no idea why you received this message, please do not click on the link, and ignore this message. We will never collect or use your personal data without your clear consent.
Sincerely,
%1$s', 'contact-form-7' ),
$site_title,
$link
);
wp_mail( $to, $subject, $message );
}
PK �NFZ��q/� � , constant-contact/contact-form-properties.phpnu �[��� <?php
add_filter(
'wpcf7_pre_construct_contact_form_properties',
'wpcf7_constant_contact_register_property',
10, 2
);
/**
* Registers the constant_contact contact form property.
*/
function wpcf7_constant_contact_register_property( $properties, $contact_form ) {
$service = WPCF7_ConstantContact::get_instance();
if ( $service->is_active() ) {
$properties += array(
'constant_contact' => array(),
);
}
return $properties;
}
add_filter(
'wpcf7_contact_form_property_constant_contact',
'wpcf7_constant_contact_setup_property',
10, 2
);
/**
* Sets up the constant_contact property value. For back-compat, this attempts
* to take over the value from old settings if the property is empty.
*/
function wpcf7_constant_contact_setup_property( $property, $contact_form ) {
if ( ! empty( $property ) ) {
$property = wp_parse_args(
$property,
array(
'enable_contact_list' => false,
'contact_lists' => array(),
)
);
return $property;
}
$property = array(
'enable_contact_list' => true,
'contact_lists' => array(),
);
if ( $contact_form->initial() ) {
return $property;
}
$service_option = (array) WPCF7::get_option( 'constant_contact' );
$property['enable_contact_list'] = ! $contact_form->is_false(
'constant_contact'
);
if ( isset( $service_option['contact_lists'] ) ) {
$contact_lists = (array) $service_option['contact_lists'];
$contact_lists_selected = array();
foreach ( $contact_lists as $list ) {
if ( empty( $list['selected'] ) ) {
continue;
}
foreach ( (array) $list['selected'] as $key => $val ) {
if ( ! isset( $contact_lists_selected[$key] ) ) {
$contact_lists_selected[$key] = array();
}
$contact_lists_selected[$key][] = $list['list_id'];
}
}
$related_keys = array(
sprintf( 'wpcf7_contact_form:%d', $contact_form->id() ),
'default',
);
foreach ( $related_keys as $key ) {
if ( ! empty( $contact_lists_selected[$key] ) ) {
$property['contact_lists'] = $contact_lists_selected[$key];
break;
}
}
}
return $property;
}
add_action(
'wpcf7_save_contact_form',
'wpcf7_constant_contact_save_contact_form',
10, 1
);
/**
* Saves the constant_contact property value.
*/
function wpcf7_constant_contact_save_contact_form( $contact_form ) {
$service = WPCF7_ConstantContact::get_instance();
if ( ! $service->is_active() ) {
return;
}
$prop = isset( $_POST['wpcf7-ctct'] )
? (array) $_POST['wpcf7-ctct']
: array();
$prop = wp_parse_args(
$prop,
array(
'enable_contact_list' => false,
'contact_lists' => array(),
)
);
$contact_form->set_properties( array(
'constant_contact' => $prop,
) );
}
add_filter(
'wpcf7_editor_panels',
'wpcf7_constant_contact_editor_panels',
10, 1
);
/**
* Builds the editor panel for the constant_contact property.
*/
function wpcf7_constant_contact_editor_panels( $panels ) {
$service = WPCF7_ConstantContact::get_instance();
if ( ! $service->is_active() ) {
return $panels;
}
$contact_form = WPCF7_ContactForm::get_current();
$prop = wp_parse_args(
$contact_form->prop( 'constant_contact' ),
array(
'enable_contact_list' => false,
'contact_lists' => array(),
)
);
$editor_panel = static function () use ( $prop, $service ) {
$description = sprintf(
esc_html(
__( "You can set up the Constant Contact integration here. For details, see %s.", 'contact-form-7' )
),
wpcf7_link(
__( 'https://contactform7.com/constant-contact-integration/', 'contact-form-7' ),
__( 'Constant Contact integration', 'contact-form-7' )
)
);
$lists = $service->get_contact_lists();
?>
<h2><?php echo esc_html( __( 'Constant Contact', 'contact-form-7' ) ); ?></h2>
<fieldset>
<legend><?php echo $description; ?></legend>
<table class="form-table" role="presentation">
<tbody>
<tr class="<?php echo $prop['enable_contact_list'] ? '' : 'inactive'; ?>">
<th scope="row">
<?php
echo esc_html( __( 'Contact lists', 'contact-form-7' ) );
?>
</th>
<td>
<fieldset>
<legend class="screen-reader-text">
<?php
echo esc_html( __( 'Contact lists', 'contact-form-7' ) );
?>
</legend>
<label for="wpcf7-ctct-enable-contact-list">
<input type="checkbox" name="wpcf7-ctct[enable_contact_list]" id="wpcf7-ctct-enable-contact-list" value="1" <?php checked( $prop['enable_contact_list'] ); ?> />
<?php
echo esc_html(
__( "Add form submitters to your contact lists", 'contact-form-7' )
);
?>
</label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row"></th>
<td>
<fieldset>
<?php
if ( $lists ) {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'Select lists to which contacts are added:', 'contact-form-7' ) )
);
echo '<ul>';
foreach ( $lists as $list ) {
echo sprintf(
'<li><label><input %1$s /> %2$s</label></li>',
wpcf7_format_atts( array(
'type' => 'checkbox',
'name' => 'wpcf7-ctct[contact_lists][]',
'value' => $list['list_id'],
'checked' => in_array( $list['list_id'], $prop['contact_lists'] ),
) ),
esc_html( $list['name'] )
);
}
echo '</ul>';
} else {
echo sprintf(
'<legend>%1$s</legend>',
esc_html( __( 'You have no contact list yet.', 'contact-form-7' ) )
);
}
?>
</fieldset>
<?php
echo sprintf(
'<p><a %1$s>%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
wpcf7_format_atts( array(
'href' => 'https://app.constantcontact.com/pages/contacts/ui#lists',
'target' => '_blank',
'rel' => 'external noreferrer noopener',
) ),
esc_html( __( 'Manage your contact lists', 'contact-form-7' ) ),
esc_html( __( '(opens in a new tab)', 'contact-form-7' ) )
);
?>
</td>
</tr>
</tbody>
</table>
</fieldset>
<?php
};
$panels += array(
'ctct-panel' => array(
'title' => __( 'Constant Contact', 'contact-form-7' ),
'callback' => $editor_panel,
),
);
return $panels;
}
PK �NFZ�K5� � sendinblue/sendinblue.phpnu �[��� <?php
/**
* Brevo module main file
*
* @link https://contactform7.com/sendinblue-integration/
*/
wpcf7_include_module_file( 'sendinblue/service.php' );
wpcf7_include_module_file( 'sendinblue/contact-form-properties.php' );
wpcf7_include_module_file( 'sendinblue/doi.php' );
add_action( 'wpcf7_init', 'wpcf7_sendinblue_register_service', 10, 0 );
/**
* Registers the Sendinblue service.
*/
function wpcf7_sendinblue_register_service() {
$integration = WPCF7_Integration::get_instance();
$integration->add_service( 'sendinblue',
WPCF7_Sendinblue::get_instance()
);
}
add_action( 'wpcf7_submit', 'wpcf7_sendinblue_submit', 10, 2 );
/**
* Callback to the wpcf7_submit action hook. Creates a contact
* based on the submission.
*/
function wpcf7_sendinblue_submit( $contact_form, $result ) {
if ( $contact_form->in_demo_mode() ) {
return;
}
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( empty( $result['posted_data_hash'] ) ) {
return;
}
if ( empty( $result['status'] )
or ! in_array( $result['status'], array( 'mail_sent', 'mail_failed' ) ) ) {
return;
}
$submission = WPCF7_Submission::get_instance();
$consented = true;
foreach ( $contact_form->scan_form_tags( 'feature=name-attr' ) as $tag ) {
if ( $tag->has_option( 'consent_for:sendinblue' )
and null == $submission->get_posted_data( $tag->name ) ) {
$consented = false;
break;
}
}
if ( ! $consented ) {
return;
}
$prop = wp_parse_args(
$contact_form->prop( 'sendinblue' ),
array(
'enable_contact_list' => false,
'contact_lists' => array(),
'enable_transactional_email' => false,
'email_template' => 0,
)
);
if ( ! $prop['enable_contact_list'] ) {
return;
}
$attributes = wpcf7_sendinblue_collect_parameters();
$params = array(
'contact' => array(),
'email' => array(),
);
if ( ! empty( $attributes['EMAIL'] ) or ! empty( $attributes['SMS'] ) ) {
$params['contact'] = apply_filters(
'wpcf7_sendinblue_contact_parameters',
array(
'email' => $attributes['EMAIL'],
'attributes' => (object) $attributes,
'listIds' => (array) $prop['contact_lists'],
'updateEnabled' => false,
)
);
}
if ( $prop['enable_transactional_email'] and $prop['email_template'] ) {
$first_name = isset( $attributes['FIRSTNAME'] )
? trim( $attributes['FIRSTNAME'] )
: '';
$last_name = isset( $attributes['LASTNAME'] )
? trim( $attributes['LASTNAME'] )
: '';
if ( $first_name or $last_name ) {
$email_to_name = sprintf(
/* translators: 1: first name, 2: last name */
_x( '%1$s %2$s', 'personal name', 'contact-form-7' ),
$first_name,
$last_name
);
} else {
$email_to_name = '';
}
$params['email'] = apply_filters(
'wpcf7_sendinblue_email_parameters',
array(
'templateId' => absint( $prop['email_template'] ),
'to' => array(
array(
'name' => $email_to_name,
'email' => $attributes['EMAIL'],
),
),
'params' => (object) $attributes,
'tags' => array( 'Contact Form 7' ),
)
);
}
if ( is_email( $attributes['EMAIL'] ) ) {
$token = null;
do_action_ref_array( 'wpcf7_doi', array(
'wpcf7_sendinblue',
array(
'email_to' => $attributes['EMAIL'],
'properties' => $params,
),
&$token,
) );
if ( isset( $token ) ) {
return;
}
}
if ( ! empty( $params['contact'] ) ) {
$contact_id = $service->create_contact( $params['contact'] );
if ( $contact_id and ! empty( $params['email'] ) ) {
$service->send_email( $params['email'] );
}
}
}
/**
* Collects parameters for Sendinblue contact data based on submission.
*
* @return array Sendinblue contact parameters.
*/
function wpcf7_sendinblue_collect_parameters() {
$params = array();
$submission = WPCF7_Submission::get_instance();
foreach ( (array) $submission->get_posted_data() as $name => $val ) {
$name = strtoupper( $name );
if ( 'YOUR-' == substr( $name, 0, 5 ) ) {
$name = substr( $name, 5 );
}
if ( $val ) {
$params += array(
$name => $val,
);
}
}
if ( isset( $params['SMS'] ) ) {
$sms = trim( implode( ' ', (array) $params['SMS'] ) );
$sms = preg_replace( '/[#*].*$/', '', $sms ); // Remove extension
$is_international = false ||
str_starts_with( $sms, '+' ) ||
str_starts_with( $sms, '00' );
if ( $is_international ) {
$sms = preg_replace( '/^[+0]+/', '', $sms );
}
$sms = preg_replace( '/[^0-9]/', '', $sms );
if ( $is_international and 6 < strlen( $sms ) and strlen( $sms ) < 16 ) {
$params['SMS'] = '+' . $sms;
} else { // Invalid telephone number
unset( $params['SMS'] );
}
}
if ( isset( $params['NAME'] ) ) {
$your_name = implode( ' ', (array) $params['NAME'] );
$your_name = explode( ' ', $your_name );
if ( ! isset( $params['LASTNAME'] ) ) {
$params['LASTNAME'] = implode(
' ',
array_slice( $your_name, 1 )
);
}
if ( ! isset( $params['FIRSTNAME'] ) ) {
$params['FIRSTNAME'] = implode(
' ',
array_slice( $your_name, 0, 1 )
);
}
}
$params = array_map(
function ( $param ) {
if ( is_array( $param ) ) {
$param = wpcf7_array_flatten( $param );
$param = reset( $param );
}
return $param;
},
$params
);
$params = apply_filters(
'wpcf7_sendinblue_collect_parameters',
$params
);
return $params;
}
PK �NFZ��7� sendinblue/doi.phpnu �[��� <?php
/**
* Double Opt-In Helper-related functions
*
* @link https://contactform7.com/doi-helper/
*/
add_action(
'doihelper_init',
'wpcf7_sendinblue_doi_register_agent',
10, 0
);
/**
* Registers wpcf7_sendinblue as an agent.
*/
function wpcf7_sendinblue_doi_register_agent() {
if ( ! function_exists( 'doihelper_register_agent' ) ) {
return;
}
doihelper_register_agent( 'wpcf7_sendinblue', array(
'optin_callback' => apply_filters(
'wpcf7_sendinblue_doi_optin_callback',
'wpcf7_sendinblue_doi_default_optin_callback'
),
'email_callback' => apply_filters(
'wpcf7_sendinblue_doi_email_callback',
'wpcf7_sendinblue_doi_default_email_callback'
),
) );
}
/**
* Default optin_callback function.
*/
function wpcf7_sendinblue_doi_default_optin_callback( $properties ) {
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( ! empty( $properties['contact'] ) ) {
$contact_id = $service->create_contact( $properties['contact'] );
if ( $contact_id and ! empty( $properties['email'] ) ) {
$service->send_email( $properties['email'] );
}
}
}
/**
* Default email_callback function.
*/
function wpcf7_sendinblue_doi_default_email_callback( $args ) {
if ( ! isset( $args['token'] ) or ! isset( $args['email_to'] ) ) {
return;
}
$site_title = wp_specialchars_decode(
get_bloginfo( 'name' ),
ENT_QUOTES
);
$link = add_query_arg(
array( 'doitoken' => $args['token'] ),
home_url()
);
$to = $args['email_to'];
$subject = sprintf(
/* translators: %s: blog name */
__( 'Opt-in confirmation from %s', 'contact-form-7' ),
$site_title
);
$message = sprintf(
/* translators: 1: blog name, 2: confirmation link */
__( 'Hello,
This is a confirmation email sent from %1$s.
We have received your submission to our web form, according to which you have allowed us to add you to our contact list. But, the process has not yet been completed. To complete it, please click the following link.
%2$s
If it was not your intention, or if you have no idea why you received this message, please do not click on the link, and ignore this message. We will never collect or use your personal data without your clear consent.
Sincerely,
%1$s', 'contact-form-7' ),
$site_title,
$link
);
wp_mail( $to, $subject, $message );
}
PK �NFZ�*! ! &