rebase from live enviornment
This commit is contained in:
306
wp/plugins/contact-form-7/modules/acceptance.php
Normal file
306
wp/plugins/contact-form-7/modules/acceptance.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [acceptance]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_acceptance', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_acceptance() {
|
||||
wpcf7_add_form_tag( 'acceptance',
|
||||
'wpcf7_acceptance_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_acceptance_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';
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'invert' ) ) {
|
||||
$class .= ' invert';
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
$class .= ' optional';
|
||||
}
|
||||
|
||||
$atts = array(
|
||||
'class' => trim( $class ),
|
||||
);
|
||||
|
||||
$item_atts = array(
|
||||
'type' => 'checkbox',
|
||||
'name' => $tag->name,
|
||||
'value' => '1',
|
||||
'tabindex' => $tag->get_option( 'tabindex', 'signed_int', true ),
|
||||
'checked' => $tag->has_option( 'default:on' ),
|
||||
'class' => $tag->get_class_option() ? $tag->get_class_option() : null,
|
||||
'id' => $tag->get_id_option(),
|
||||
);
|
||||
|
||||
if ( $validation_error ) {
|
||||
$item_atts['aria-invalid'] = 'true';
|
||||
$item_atts['aria-describedby'] = wpcf7_get_validation_error_reference(
|
||||
$tag->name
|
||||
);
|
||||
} else {
|
||||
$item_atts['aria-invalid'] = 'false';
|
||||
}
|
||||
|
||||
$item_atts = wpcf7_format_atts( $item_atts );
|
||||
|
||||
$content = empty( $tag->content )
|
||||
? (string) reset( $tag->values )
|
||||
: $tag->content;
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $content ) {
|
||||
if ( $tag->has_option( 'label_first' ) ) {
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-list-item-label">%2$s</span><input %1$s />',
|
||||
$item_atts,
|
||||
$content
|
||||
);
|
||||
} else {
|
||||
$html = sprintf(
|
||||
'<input %1$s /><span class="wpcf7-list-item-label">%2$s</span>',
|
||||
$item_atts,
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-list-item"><label>%s</label></span>',
|
||||
$html
|
||||
);
|
||||
|
||||
} else {
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-list-item"><input %1$s /></span>',
|
||||
$item_atts
|
||||
);
|
||||
}
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><span %2$s>%3$s</span>%4$s</span>',
|
||||
esc_attr( $tag->name ),
|
||||
wpcf7_format_atts( $atts ),
|
||||
$html,
|
||||
$validation_error
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
/* Validation filter */
|
||||
|
||||
add_filter( 'wpcf7_validate_acceptance',
|
||||
'wpcf7_acceptance_validation_filter', 10, 2 );
|
||||
|
||||
function wpcf7_acceptance_validation_filter( $result, $tag ) {
|
||||
if ( ! wpcf7_acceptance_as_validation() ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$name = $tag->name;
|
||||
$value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
|
||||
|
||||
$invert = $tag->has_option( 'invert' );
|
||||
|
||||
if ( $invert and $value
|
||||
or ! $invert and ! $value ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'accept_terms' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Acceptance filter */
|
||||
|
||||
add_filter( 'wpcf7_acceptance', 'wpcf7_acceptance_filter', 10, 2 );
|
||||
|
||||
function wpcf7_acceptance_filter( $accepted, $submission ) {
|
||||
$tags = wpcf7_scan_form_tags( array( 'type' => 'acceptance' ) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$name = $tag->name;
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = ( ! empty( $_POST[$name] ) ? 1 : 0 );
|
||||
|
||||
$content = empty( $tag->content )
|
||||
? (string) reset( $tag->values )
|
||||
: $tag->content;
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $value and $content ) {
|
||||
$submission->add_consent( $name, $content );
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'optional' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$invert = $tag->has_option( 'invert' );
|
||||
|
||||
if ( $invert and $value
|
||||
or ! $invert and ! $value ) {
|
||||
$accepted = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $accepted;
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_form_class_attr',
|
||||
'wpcf7_acceptance_form_class_attr', 10, 1 );
|
||||
|
||||
function wpcf7_acceptance_form_class_attr( $class_attr ) {
|
||||
if ( wpcf7_acceptance_as_validation() ) {
|
||||
return $class_attr . ' wpcf7-acceptance-as-validation';
|
||||
}
|
||||
|
||||
return $class_attr;
|
||||
}
|
||||
|
||||
function wpcf7_acceptance_as_validation() {
|
||||
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $contact_form->is_true( 'acceptance_as_validation' );
|
||||
}
|
||||
|
||||
add_filter( 'wpcf7_mail_tag_replaced_acceptance',
|
||||
'wpcf7_acceptance_mail_tag', 10, 4 );
|
||||
|
||||
function wpcf7_acceptance_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
|
||||
$form_tag = $mail_tag->corresponding_form_tag();
|
||||
|
||||
if ( ! $form_tag ) {
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
if ( ! empty( $submitted ) ) {
|
||||
$replaced = __( 'Consented', 'contact-form-7' );
|
||||
} else {
|
||||
$replaced = __( 'Not consented', 'contact-form-7' );
|
||||
}
|
||||
|
||||
$content = empty( $form_tag->content )
|
||||
? (string) reset( $form_tag->values )
|
||||
: $form_tag->content;
|
||||
|
||||
if ( ! $html ) {
|
||||
$content = wp_strip_all_tags( $content );
|
||||
}
|
||||
|
||||
$content = trim( $content );
|
||||
|
||||
if ( $content ) {
|
||||
$replaced = sprintf(
|
||||
/* translators: 1: 'Consented' or 'Not consented', 2: conditions */
|
||||
_x( '%1$s: %2$s', 'mail output for acceptance checkboxes',
|
||||
'contact-form-7' ),
|
||||
$replaced,
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_acceptance', 35, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_acceptance() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'acceptance', __( 'acceptance', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_acceptance' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_acceptance( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'acceptance';
|
||||
|
||||
$description = __( "Generate a form-tag for an acceptance checkbox. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/acceptance-checkbox/', 'contact-form-7' ), __( 'Acceptance checkbox', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-content' ); ?>"><?php echo esc_html( __( 'Condition', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="content" class="oneline large-text" id="<?php echo esc_attr( $args['content'] . '-content' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="optional" class="option" checked="checked" /> <?php echo esc_html( __( 'Make this checkbox optional', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
313
wp/plugins/contact-form-7/modules/akismet/akismet.php
Normal file
313
wp/plugins/contact-form-7/modules/akismet/akismet.php
Normal file
@@ -0,0 +1,313 @@
|
||||
<?php
|
||||
/**
|
||||
* The Akismet integration module
|
||||
*
|
||||
* @link https://akismet.com/development/api/
|
||||
*/
|
||||
|
||||
wpcf7_include_module_file( 'akismet/service.php' );
|
||||
|
||||
|
||||
add_action(
|
||||
'wpcf7_init',
|
||||
'wpcf7_akismet_register_service',
|
||||
30, 0
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers the Akismet service.
|
||||
*/
|
||||
function wpcf7_akismet_register_service() {
|
||||
$integration = WPCF7_Integration::get_instance();
|
||||
|
||||
$integration->add_service( 'akismet',
|
||||
WPCF7_Akismet::get_instance()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
add_filter( 'wpcf7_spam', 'wpcf7_akismet', 10, 2 );
|
||||
|
||||
function wpcf7_akismet( $spam, $submission ) {
|
||||
if ( $spam ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
if ( ! wpcf7_akismet_is_available() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! $params = wpcf7_akismet_submitted_params() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$comment = array(
|
||||
'comment_type' => 'contact-form',
|
||||
'comment_author' => $params['author'],
|
||||
'comment_author_email' => $params['author_email'],
|
||||
'comment_author_url' => $params['author_url'],
|
||||
'comment_content' => $params['content'],
|
||||
'blog' => home_url(),
|
||||
'blog_lang' => get_locale(),
|
||||
'blog_charset' => get_option( 'blog_charset' ),
|
||||
'user_ip' => $submission->get_meta( 'remote_ip' ),
|
||||
'user_agent' => $submission->get_meta( 'user_agent' ),
|
||||
'referrer' => isset( $_SERVER['HTTP_REFERER'] )
|
||||
? $_SERVER['HTTP_REFERER'] : '',
|
||||
);
|
||||
|
||||
$datetime = date_create_immutable(
|
||||
'@' . $submission->get_meta( 'timestamp' )
|
||||
);
|
||||
|
||||
if ( $datetime ) {
|
||||
$comment['comment_date_gmt'] = $datetime->format( DATE_ATOM );
|
||||
}
|
||||
|
||||
if ( $permalink = get_permalink() ) {
|
||||
$comment['permalink'] = $permalink;
|
||||
}
|
||||
|
||||
$server_vars = array_diff_key(
|
||||
$_SERVER,
|
||||
array_flip( array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ) )
|
||||
);
|
||||
|
||||
$comment = array_merge( $comment, $server_vars );
|
||||
|
||||
$comment = apply_filters( 'wpcf7_akismet_parameters', $comment );
|
||||
|
||||
if ( wpcf7_akismet_comment_check( $comment ) ) {
|
||||
$spam = true;
|
||||
|
||||
$submission->add_spam_log( array(
|
||||
'agent' => 'akismet',
|
||||
'reason' => __( "Akismet returns a spam response.", 'contact-form-7' ),
|
||||
) );
|
||||
} else {
|
||||
$spam = false;
|
||||
}
|
||||
|
||||
return $spam;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if Akismet is active and has a valid API key.
|
||||
*/
|
||||
function wpcf7_akismet_is_available() {
|
||||
if ( is_callable( array( 'Akismet', 'get_api_key' ) ) ) {
|
||||
return (bool) Akismet::get_api_key();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of parameters based on the current form submission.
|
||||
* Returns false if Akismet is not active on the contact form.
|
||||
*/
|
||||
function wpcf7_akismet_submitted_params() {
|
||||
$akismet_tags = array_filter(
|
||||
wpcf7_scan_form_tags(),
|
||||
static function ( $tag ) {
|
||||
$akismet_option = $tag->get_option( 'akismet',
|
||||
'(author|author_email|author_url)',
|
||||
true
|
||||
);
|
||||
|
||||
return (bool) $akismet_option;
|
||||
}
|
||||
);
|
||||
|
||||
if ( ! $akismet_tags ) { // Akismet is not active on this contact form.
|
||||
return false;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'author' => '',
|
||||
'author_email' => '',
|
||||
'author_url' => '',
|
||||
'content' => '',
|
||||
);
|
||||
|
||||
foreach ( (array) $_POST as $key => $val ) {
|
||||
if ( '_wpcf7' == substr( $key, 0, 6 )
|
||||
or '_wpnonce' == $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$vals = array_filter(
|
||||
wpcf7_array_flatten( $val ),
|
||||
static function ( $val ) {
|
||||
return '' !== trim( $val );
|
||||
}
|
||||
);
|
||||
|
||||
if ( empty( $vals ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $tags = wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
|
||||
$tag = $tags[0];
|
||||
|
||||
$akismet_option = $tag->get_option( 'akismet',
|
||||
'(author|author_email|author_url)',
|
||||
true
|
||||
);
|
||||
|
||||
if ( 'author' === $akismet_option ) {
|
||||
$params['author'] = sprintf(
|
||||
'%s %s',
|
||||
$params['author'],
|
||||
implode( ' ', $vals )
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'author_email' === $akismet_option
|
||||
and '' === $params['author_email'] ) {
|
||||
$params['author_email'] = $vals[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'author_url' === $akismet_option
|
||||
and '' === $params['author_url'] ) {
|
||||
$params['author_url'] = $vals[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
$vals = array_filter(
|
||||
$vals,
|
||||
static function ( $val ) use ( $tag ) {
|
||||
if ( wpcf7_form_tag_supports( $tag->type, 'selectable-values' )
|
||||
and in_array( $val, $tag->labels ) ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if ( $vals ) {
|
||||
$params['content'] .= "\n\n" . implode( ', ', $vals );
|
||||
}
|
||||
}
|
||||
|
||||
$params = array_map( 'trim', $params );
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends data to Akismet.
|
||||
*
|
||||
* @param array $comment Submission and environment data.
|
||||
* @return bool True if Akismet called it spam, or false otherwise.
|
||||
*/
|
||||
function wpcf7_akismet_comment_check( $comment ) {
|
||||
$spam = false;
|
||||
$query_string = wpcf7_build_query( $comment );
|
||||
|
||||
if ( is_callable( array( 'Akismet', 'http_post' ) ) ) {
|
||||
$response = Akismet::http_post( $query_string, 'comment-check' );
|
||||
} else {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
if ( 'true' == $response[1] ) {
|
||||
$spam = true;
|
||||
}
|
||||
|
||||
if ( $submission = WPCF7_Submission::get_instance() ) {
|
||||
$submission->push( 'akismet', array(
|
||||
'comment' => $comment,
|
||||
'spam' => $spam,
|
||||
) );
|
||||
}
|
||||
|
||||
return apply_filters( 'wpcf7_akismet_comment_check', $spam, $comment );
|
||||
}
|
||||
|
||||
|
||||
add_filter( 'wpcf7_posted_data', 'wpcf7_akismet_posted_data', 10, 1 );
|
||||
|
||||
/**
|
||||
* Removes Akismet-related properties from the posted data.
|
||||
*
|
||||
* This does not affect the $_POST variable itself.
|
||||
*
|
||||
* @link https://plugins.trac.wordpress.org/browser/akismet/tags/5.0/_inc/akismet-frontend.js
|
||||
*/
|
||||
function wpcf7_akismet_posted_data( $posted_data ) {
|
||||
if ( wpcf7_akismet_is_available() ) {
|
||||
$posted_data = array_diff_key(
|
||||
$posted_data,
|
||||
array(
|
||||
'ak_bib' => '',
|
||||
'ak_bfs' => '',
|
||||
'ak_bkpc' => '',
|
||||
'ak_bkp' => '',
|
||||
'ak_bmc' => '',
|
||||
'ak_bmcc' => '',
|
||||
'ak_bmk' => '',
|
||||
'ak_bck' => '',
|
||||
'ak_bmmc' => '',
|
||||
'ak_btmc' => '',
|
||||
'ak_bsc' => '',
|
||||
'ak_bte' => '',
|
||||
'ak_btec' => '',
|
||||
'ak_bmm' => '',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $posted_data;
|
||||
}
|
||||
|
||||
|
||||
add_filter(
|
||||
'wpcf7_default_template',
|
||||
'wpcf7_akismet_default_template',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_akismet_default_template( $template, $prop ) {
|
||||
if ( ! wpcf7_akismet_is_available() ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ( 'form' === $prop ) {
|
||||
$template = str_replace(
|
||||
array(
|
||||
'[text* your-name ',
|
||||
'[email* your-email ',
|
||||
),
|
||||
array(
|
||||
'[text* your-name akismet:author ',
|
||||
'[email* your-email akismet:author_email ',
|
||||
),
|
||||
$template
|
||||
);
|
||||
|
||||
$privacy_notice = sprintf( '%s %s',
|
||||
__( "This form uses Akismet to reduce spam.", 'contact-form-7' ),
|
||||
wpcf7_link(
|
||||
'https://akismet.com/privacy/',
|
||||
__( "Learn how your data is processed.", 'contact-form-7' ),
|
||||
array(
|
||||
'target' => '_blank',
|
||||
'rel' => 'nofollow noopener',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$template .= "\n\n" . $privacy_notice;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
70
wp/plugins/contact-form-7/modules/akismet/service.php
Normal file
70
wp/plugins/contact-form-7/modules/akismet/service.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'WPCF7_Service' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class WPCF7_Akismet extends WPCF7_Service {
|
||||
|
||||
private static $instance;
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if ( empty( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
public function get_title() {
|
||||
return __( 'Akismet', 'contact-form-7' );
|
||||
}
|
||||
|
||||
|
||||
public function is_active() {
|
||||
return wpcf7_akismet_is_available();
|
||||
}
|
||||
|
||||
|
||||
public function get_categories() {
|
||||
return array( 'spam_protection' );
|
||||
}
|
||||
|
||||
|
||||
public function icon() {
|
||||
}
|
||||
|
||||
|
||||
public function link() {
|
||||
echo wpcf7_link(
|
||||
'https://akismet.com/',
|
||||
'akismet.com'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function display( $action = '' ) {
|
||||
echo sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html( __( "CAPTCHAs are designed to distinguish spambots from humans, and are therefore helpless against human spammers. In contrast to CAPTCHAs, Akismet checks form submissions against the global database of spam; this means Akismet is a comprehensive solution against spam. This is why we consider Akismet to be the centerpiece of the spam prevention strategy.", 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
echo sprintf(
|
||||
'<p><strong>%s</strong></p>',
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ),
|
||||
__( 'Spam filtering with Akismet', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
if ( $this->is_active() ) {
|
||||
echo sprintf(
|
||||
'<p class="dashicons-before dashicons-yes">%s</p>',
|
||||
esc_html( __( "Akismet is active on this site.", 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
306
wp/plugins/contact-form-7/modules/checkbox.php
Normal file
306
wp/plugins/contact-form-7/modules/checkbox.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [checkbox], [checkbox*], and [radio]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_checkbox', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_checkbox() {
|
||||
wpcf7_add_form_tag( array( 'checkbox', 'checkbox*', 'radio' ),
|
||||
'wpcf7_checkbox_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'selectable-values' => true,
|
||||
'multiple-controls-container' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_checkbox_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';
|
||||
}
|
||||
|
||||
$label_first = $tag->has_option( 'label_first' );
|
||||
$use_label_element = $tag->has_option( 'use_label_element' );
|
||||
$exclusive = $tag->has_option( 'exclusive' );
|
||||
$free_text = $tag->has_option( 'free_text' );
|
||||
$multiple = false;
|
||||
|
||||
if ( 'checkbox' == $tag->basetype ) {
|
||||
$multiple = ! $exclusive;
|
||||
} else { // radio
|
||||
$exclusive = false;
|
||||
}
|
||||
|
||||
if ( $exclusive ) {
|
||||
$class .= ' wpcf7-exclusive-checkbox';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
|
||||
if ( $validation_error ) {
|
||||
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
|
||||
$tag->name
|
||||
);
|
||||
}
|
||||
|
||||
$tabindex = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
if ( false !== $tabindex ) {
|
||||
$tabindex = (int) $tabindex;
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$count = 0;
|
||||
|
||||
if ( $data = (array) $tag->get_data_option() ) {
|
||||
if ( $free_text ) {
|
||||
$tag->values = array_merge(
|
||||
array_slice( $tag->values, 0, -1 ),
|
||||
array_values( $data ),
|
||||
array_slice( $tag->values, -1 ) );
|
||||
$tag->labels = array_merge(
|
||||
array_slice( $tag->labels, 0, -1 ),
|
||||
array_values( $data ),
|
||||
array_slice( $tag->labels, -1 ) );
|
||||
} else {
|
||||
$tag->values = array_merge( $tag->values, array_values( $data ) );
|
||||
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
|
||||
}
|
||||
}
|
||||
|
||||
$values = $tag->values;
|
||||
$labels = $tag->labels;
|
||||
|
||||
$default_choice = $tag->get_default_option( null, array(
|
||||
'multiple' => $multiple,
|
||||
) );
|
||||
|
||||
$hangover = wpcf7_get_hangover( $tag->name, $multiple ? array() : '' );
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( $hangover ) {
|
||||
$checked = in_array( $value, (array) $hangover, true );
|
||||
} else {
|
||||
$checked = in_array( $value, (array) $default_choice, true );
|
||||
}
|
||||
|
||||
if ( isset( $labels[$key] ) ) {
|
||||
$label = $labels[$key];
|
||||
} else {
|
||||
$label = $value;
|
||||
}
|
||||
|
||||
$item_atts = array(
|
||||
'type' => $tag->basetype,
|
||||
'name' => $tag->name . ( $multiple ? '[]' : '' ),
|
||||
'value' => $value,
|
||||
'checked' => $checked,
|
||||
'tabindex' => $tabindex,
|
||||
);
|
||||
|
||||
$item_atts = wpcf7_format_atts( $item_atts );
|
||||
|
||||
if ( $label_first ) { // put label first, input last
|
||||
$item = sprintf(
|
||||
'<span class="wpcf7-list-item-label">%1$s</span><input %2$s />',
|
||||
esc_html( $label ),
|
||||
$item_atts
|
||||
);
|
||||
} else {
|
||||
$item = sprintf(
|
||||
'<input %2$s /><span class="wpcf7-list-item-label">%1$s</span>',
|
||||
esc_html( $label ),
|
||||
$item_atts
|
||||
);
|
||||
}
|
||||
|
||||
if ( $use_label_element ) {
|
||||
$item = '<label>' . $item . '</label>';
|
||||
}
|
||||
|
||||
if ( false !== $tabindex and 0 < $tabindex ) {
|
||||
$tabindex += 1;
|
||||
}
|
||||
|
||||
$class = 'wpcf7-list-item';
|
||||
$count += 1;
|
||||
|
||||
if ( 1 == $count ) {
|
||||
$class .= ' first';
|
||||
}
|
||||
|
||||
if ( count( $values ) == $count ) { // last round
|
||||
$class .= ' last';
|
||||
|
||||
if ( $free_text ) {
|
||||
$free_text_name = $tag->name . '_free_text';
|
||||
|
||||
$free_text_atts = array(
|
||||
'name' => $free_text_name,
|
||||
'class' => 'wpcf7-free-text',
|
||||
'tabindex' => $tabindex,
|
||||
);
|
||||
|
||||
if ( wpcf7_is_posted()
|
||||
and isset( $_POST[$free_text_name] ) ) {
|
||||
$free_text_atts['value'] = wp_unslash( $_POST[$free_text_name] );
|
||||
}
|
||||
|
||||
$free_text_atts = wpcf7_format_atts( $free_text_atts );
|
||||
|
||||
$item .= sprintf( ' <input type="text" %s />', $free_text_atts );
|
||||
|
||||
$class .= ' has-free-text';
|
||||
}
|
||||
}
|
||||
|
||||
$item = '<span class="' . esc_attr( $class ) . '">' . $item . '</span>';
|
||||
$html .= $item;
|
||||
}
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><span %2$s>%3$s</span>%4$s</span>',
|
||||
esc_attr( $tag->name ),
|
||||
wpcf7_format_atts( $atts ),
|
||||
$html,
|
||||
$validation_error
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
add_action(
|
||||
'wpcf7_swv_create_schema',
|
||||
'wpcf7_swv_add_checkbox_rules',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_checkbox_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'type' => array( 'checkbox*', 'radio' ),
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'required', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_required' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init',
|
||||
'wpcf7_add_tag_generator_checkbox_and_radio', 30, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_checkbox_and_radio() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'checkbox', __( 'checkboxes', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_checkbox' );
|
||||
$tag_generator->add( 'radio', __( 'radio buttons', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_checkbox' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_checkbox( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = $args['id'];
|
||||
|
||||
if ( 'radio' != $type ) {
|
||||
$type = 'checkbox';
|
||||
}
|
||||
|
||||
if ( 'checkbox' == $type ) {
|
||||
$description = __( "Generate a form-tag for a group of checkboxes. For more details, see %s.", 'contact-form-7' );
|
||||
} elseif ( 'radio' == $type ) {
|
||||
$description = __( "Generate a form-tag for a group of radio buttons. 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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<?php if ( 'checkbox' == $type ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
|
||||
<label><input type="checkbox" name="label_first" class="option" /> <?php echo esc_html( __( 'Put a label first, a checkbox last', 'contact-form-7' ) ); ?></label><br />
|
||||
<label><input type="checkbox" name="use_label_element" class="option" checked="checked" /> <?php echo esc_html( __( 'Wrap each item with label element', 'contact-form-7' ) ); ?></label>
|
||||
<?php if ( 'checkbox' == $type ) : ?>
|
||||
<br /><label><input type="checkbox" name="exclusive" class="option" /> <?php echo esc_html( __( 'Make checkboxes exclusive', 'contact-form-7' ) ); ?></label>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?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',
|
||||
20, 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() );
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?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;
|
||||
}
|
||||
@@ -0,0 +1,315 @@
|
||||
<?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 );
|
||||
}
|
||||
|
||||
}
|
||||
93
wp/plugins/contact-form-7/modules/constant-contact/doi.php
Normal file
93
wp/plugins/contact-form-7/modules/constant-contact/doi.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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 );
|
||||
}
|
||||
469
wp/plugins/contact-form-7/modules/constant-contact/service.php
Normal file
469
wp/plugins/contact-form-7/modules/constant-contact/service.php
Normal file
@@ -0,0 +1,469 @@
|
||||
<?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 sprintf( '<a href="%1$s">%2$s</a>',
|
||||
'https://constant-contact.evyy.net/c/1293104/205991/3411',
|
||||
'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':
|
||||
echo sprintf(
|
||||
'<div class="notice notice-success"><p>%s</p></div>',
|
||||
esc_html( __( "Connection established.", 'contact-form-7' ) )
|
||||
);
|
||||
break;
|
||||
case 'failed':
|
||||
echo sprintf(
|
||||
'<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "Error", 'contact-form-7' ) ),
|
||||
esc_html( __( "Failed to establish connection. Please double-check your configuration.", 'contact-form-7' ) )
|
||||
);
|
||||
break;
|
||||
case 'updated':
|
||||
echo sprintf(
|
||||
'<div class="notice notice-success"><p>%s</p></div>',
|
||||
esc_html( __( "Configuration updated.", 'contact-form-7' ) )
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function display( $action = '' ) {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
69
wp/plugins/contact-form-7/modules/count.php
Normal file
69
wp/plugins/contact-form-7/modules/count.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [count], Twitter-like character count
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_count', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_count() {
|
||||
wpcf7_add_form_tag( 'count',
|
||||
'wpcf7_count_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'zero-controls-container' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_count_form_tag_handler( $tag ) {
|
||||
if ( empty( $tag->name ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$targets = wpcf7_scan_form_tags( array( 'name' => $tag->name ) );
|
||||
$maxlength = $minlength = null;
|
||||
|
||||
while ( $targets ) {
|
||||
$target = array_shift( $targets );
|
||||
|
||||
if ( 'count' != $target->type ) {
|
||||
$maxlength = $target->get_maxlength_option();
|
||||
$minlength = $target->get_minlength_option();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $maxlength and $minlength
|
||||
and $maxlength < $minlength ) {
|
||||
$maxlength = $minlength = null;
|
||||
}
|
||||
|
||||
if ( $tag->has_option( 'down' ) ) {
|
||||
$value = (int) $maxlength;
|
||||
$class = 'wpcf7-character-count down';
|
||||
} else {
|
||||
$value = '0';
|
||||
$class = 'wpcf7-character-count up';
|
||||
}
|
||||
|
||||
$atts = array();
|
||||
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['class'] = $tag->get_class_option( $class );
|
||||
$atts['data-target-name'] = $tag->name;
|
||||
$atts['data-starting-value'] = $value;
|
||||
$atts['data-current-value'] = $value;
|
||||
$atts['data-maximum-value'] = $maxlength;
|
||||
$atts['data-minimum-value'] = $minlength;
|
||||
|
||||
$html = sprintf(
|
||||
'<span %1$s>%2$s</span>',
|
||||
wpcf7_format_atts( $atts ),
|
||||
$value
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
268
wp/plugins/contact-form-7/modules/date.php
Normal file
268
wp/plugins/contact-form-7/modules/date.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?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' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_date( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'date';
|
||||
|
||||
$description = __( "Generate a form-tag for a date input field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/date-field/', 'contact-form-7' ), __( 'Date field', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
|
||||
<input type="date" name="min" class="date option" />
|
||||
</label>
|
||||
–
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
|
||||
<input type="date" name="max" class="date option" />
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
90
wp/plugins/contact-form-7/modules/disallowed-list.php
Normal file
90
wp/plugins/contact-form-7/modules/disallowed-list.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
add_filter( 'wpcf7_spam', 'wpcf7_disallowed_list', 10, 2 );
|
||||
|
||||
function wpcf7_disallowed_list( $spam, $submission ) {
|
||||
if ( $spam ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
$target = wpcf7_array_flatten( $submission->get_posted_data() );
|
||||
$target[] = $submission->get_meta( 'remote_ip' );
|
||||
$target[] = $submission->get_meta( 'user_agent' );
|
||||
$target = implode( "\n", $target );
|
||||
|
||||
$word = wpcf7_check_disallowed_list( $target );
|
||||
|
||||
$word = wpcf7_apply_filters_deprecated(
|
||||
'wpcf7_submission_is_blacklisted',
|
||||
array( $word, $submission ),
|
||||
'5.3',
|
||||
'wpcf7_submission_has_disallowed_words'
|
||||
);
|
||||
|
||||
$word = apply_filters(
|
||||
'wpcf7_submission_has_disallowed_words',
|
||||
$word,
|
||||
$submission
|
||||
);
|
||||
|
||||
if ( $word ) {
|
||||
if ( is_bool( $word ) ) {
|
||||
$reason = __( "Disallowed words are used.", 'contact-form-7' );
|
||||
} else {
|
||||
$reason = sprintf(
|
||||
__( "Disallowed words (%s) are used.", 'contact-form-7' ),
|
||||
implode( ', ', (array) $word )
|
||||
);
|
||||
}
|
||||
|
||||
$submission->add_spam_log( array(
|
||||
'agent' => 'disallowed_list',
|
||||
'reason' => $reason,
|
||||
) );
|
||||
}
|
||||
|
||||
$spam = (bool) $word;
|
||||
|
||||
return $spam;
|
||||
}
|
||||
|
||||
function wpcf7_check_disallowed_list( $target ) {
|
||||
$mod_keys = get_option( 'disallowed_keys' );
|
||||
|
||||
if ( is_scalar( $mod_keys ) ) {
|
||||
$mod_keys = trim( $mod_keys );
|
||||
} else {
|
||||
$mod_keys = '';
|
||||
}
|
||||
|
||||
if ( '' === $mod_keys ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( explode( "\n", $mod_keys ) as $word ) {
|
||||
$word = trim( $word );
|
||||
$length = strlen( $word );
|
||||
|
||||
if ( $length < 2 or 256 < $length ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) );
|
||||
|
||||
if ( preg_match( $pattern, $target ) ) {
|
||||
return $word;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function wpcf7_blacklist_check( $target ) {
|
||||
wpcf7_deprecated_function(
|
||||
__FUNCTION__,
|
||||
'5.3',
|
||||
'wpcf7_check_disallowed_list'
|
||||
);
|
||||
|
||||
return wpcf7_check_disallowed_list( $target );
|
||||
}
|
||||
42
wp/plugins/contact-form-7/modules/doi-helper.php
Normal file
42
wp/plugins/contact-form-7/modules/doi-helper.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Double Opt-In Helper module
|
||||
*
|
||||
* @link https://contactform7.com/doi-helper/
|
||||
*/
|
||||
|
||||
|
||||
add_action( 'wpcf7_doi', 'wpcf7_doihelper_start_session', 10, 3 );
|
||||
|
||||
/**
|
||||
* Starts a double opt-in session.
|
||||
*/
|
||||
function wpcf7_doihelper_start_session( $agent_name, $args, &$token ) {
|
||||
if ( isset( $token ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'doihelper_start_session' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
if ( ! $submission ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contact_form = $submission->get_contact_form();
|
||||
|
||||
$do_doi = apply_filters( 'wpcf7_do_doi',
|
||||
! $contact_form->is_false( 'doi' ),
|
||||
$agent_name,
|
||||
$args
|
||||
);
|
||||
|
||||
if ( ! $do_doi ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$token = doihelper_start_session( $agent_name, $args );
|
||||
}
|
||||
212
wp/plugins/contact-form-7/modules/file.php
Normal file
212
wp/plugins/contact-form-7/modules/file.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [file] and [file*]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_file', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_file() {
|
||||
wpcf7_add_form_tag( array( 'file', 'file*' ),
|
||||
'wpcf7_file_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'file-uploading' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_file_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['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['capture'] = $tag->get_option( 'capture', '(user|environment)', true );
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$atts['accept'] = wpcf7_acceptable_filetypes(
|
||||
$tag->get_option( 'filetypes' ), 'attr'
|
||||
);
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
$atts['type'] = 'file';
|
||||
$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_file_rules',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_file_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'basetype' => array( 'file' ),
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
if ( $tag->is_required() ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'requiredfile', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_required' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'file', array(
|
||||
'field' => $tag->name,
|
||||
'accept' => explode( ',', wpcf7_acceptable_filetypes(
|
||||
$tag->get_option( 'filetypes' ), 'attr'
|
||||
) ),
|
||||
'error' => wpcf7_get_message( 'upload_file_type_invalid' ),
|
||||
) )
|
||||
);
|
||||
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'maxfilesize', array(
|
||||
'field' => $tag->name,
|
||||
'threshold' => $tag->get_limit_option(),
|
||||
'error' => wpcf7_get_message( 'upload_file_too_large' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_filter( 'wpcf7_mail_tag_replaced_file', 'wpcf7_file_mail_tag', 10, 4 );
|
||||
add_filter( 'wpcf7_mail_tag_replaced_file*', 'wpcf7_file_mail_tag', 10, 4 );
|
||||
|
||||
function wpcf7_file_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
$uploaded_files = $submission->uploaded_files();
|
||||
$name = $mail_tag->field_name();
|
||||
|
||||
if ( ! empty( $uploaded_files[$name] ) ) {
|
||||
$paths = (array) $uploaded_files[$name];
|
||||
$paths = array_map( 'wp_basename', $paths );
|
||||
|
||||
$replaced = wpcf7_flat_join( $paths, array(
|
||||
'separator' => wp_get_list_item_separator(),
|
||||
) );
|
||||
}
|
||||
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_file', 50, 0 );
|
||||
|
||||
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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-limit' ); ?>"><?php echo esc_html( __( "File size limit (bytes)", 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="limit" class="filesize oneline option" id="<?php echo esc_attr( $args['content'] . '-limit' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>"><?php echo esc_html( __( 'Acceptable file types', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="filetypes" class="filetype oneline option" id="<?php echo esc_attr( $args['content'] . '-filetypes' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To attach the file uploaded through this field to mail, you need to insert the corresponding mail-tag (%s) into the File Attachments field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
337
wp/plugins/contact-form-7/modules/flamingo.php
Normal file
337
wp/plugins/contact-form-7/modules/flamingo.php
Normal file
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
** Module for Flamingo plugin.
|
||||
** http://wordpress.org/extend/plugins/flamingo/
|
||||
**/
|
||||
|
||||
add_action( 'wpcf7_submit', 'wpcf7_flamingo_submit', 10, 2 );
|
||||
|
||||
function wpcf7_flamingo_submit( $contact_form, $result ) {
|
||||
if ( ! class_exists( 'Flamingo_Contact' )
|
||||
or ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $contact_form->in_demo_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cases = (array) apply_filters( 'wpcf7_flamingo_submit_if',
|
||||
array( 'spam', 'mail_sent', 'mail_failed' )
|
||||
);
|
||||
|
||||
if ( empty( $result['status'] )
|
||||
or ! in_array( $result['status'], $cases ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$submission = WPCF7_Submission::get_instance();
|
||||
|
||||
if ( ! $submission
|
||||
or ! $posted_data = $submission->get_posted_data() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $submission->get_meta( 'do_not_store' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Exclude do-not-store form-tag values.
|
||||
$posted_data = array_filter(
|
||||
$posted_data,
|
||||
static function ( $name ) use ( $contact_form ) {
|
||||
return ! $contact_form->scan_form_tags( array(
|
||||
'name' => $name,
|
||||
'feature' => 'do-not-store',
|
||||
) );
|
||||
},
|
||||
ARRAY_FILTER_USE_KEY
|
||||
);
|
||||
|
||||
$email = wpcf7_flamingo_get_value( 'email', $contact_form );
|
||||
$name = wpcf7_flamingo_get_value( 'name', $contact_form );
|
||||
$subject = wpcf7_flamingo_get_value( 'subject', $contact_form );
|
||||
|
||||
$meta = array();
|
||||
|
||||
$special_mail_tags = array( 'serial_number', 'remote_ip',
|
||||
'user_agent', 'url', 'date', 'time', 'post_id', 'post_name',
|
||||
'post_title', 'post_url', 'post_author', 'post_author_email',
|
||||
'site_title', 'site_description', 'site_url', 'site_admin_email',
|
||||
'user_login', 'user_email', 'user_display_name',
|
||||
);
|
||||
|
||||
foreach ( $special_mail_tags as $smt ) {
|
||||
$tagname = sprintf( '_%s', $smt );
|
||||
|
||||
$mail_tag = new WPCF7_MailTag(
|
||||
sprintf( '[%s]', $tagname ),
|
||||
$tagname,
|
||||
''
|
||||
);
|
||||
|
||||
$meta[$smt] = apply_filters( 'wpcf7_special_mail_tags', null,
|
||||
$tagname, false, $mail_tag
|
||||
);
|
||||
}
|
||||
|
||||
$timestamp = $submission->get_meta( 'timestamp' );
|
||||
|
||||
if ( $timestamp and $datetime = date_create( '@' . $timestamp ) ) {
|
||||
$datetime->setTimezone( wp_timezone() );
|
||||
$last_contacted = $datetime->format( 'Y-m-d H:i:s' );
|
||||
} else {
|
||||
$last_contacted = '0000-00-00 00:00:00';
|
||||
}
|
||||
|
||||
if ( 'mail_sent' == $result['status'] ) {
|
||||
$flamingo_contact = Flamingo_Contact::add( array(
|
||||
'email' => $email,
|
||||
'name' => $name,
|
||||
'last_contacted' => $last_contacted,
|
||||
) );
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel_id = isset( $post_meta['channel'] )
|
||||
? (int) $post_meta['channel']
|
||||
: wpcf7_flamingo_add_channel(
|
||||
$contact_form->name(),
|
||||
$contact_form->title()
|
||||
);
|
||||
|
||||
if ( $channel_id ) {
|
||||
if ( ! isset( $post_meta['channel'] )
|
||||
or $post_meta['channel'] !== $channel_id ) {
|
||||
$post_meta = empty( $post_meta ) ? array() : (array) $post_meta;
|
||||
$post_meta = array_merge( $post_meta, array(
|
||||
'channel' => $channel_id,
|
||||
) );
|
||||
|
||||
update_post_meta( $contact_form->id(), '_flamingo', $post_meta );
|
||||
}
|
||||
|
||||
$channel = get_term( $channel_id,
|
||||
Flamingo_Inbound_Message::channel_taxonomy
|
||||
);
|
||||
|
||||
if ( ! $channel or is_wp_error( $channel ) ) {
|
||||
$channel = 'contact-form-7';
|
||||
} else {
|
||||
$channel = $channel->slug;
|
||||
}
|
||||
} else {
|
||||
$channel = 'contact-form-7';
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'channel' => $channel,
|
||||
'status' => $submission->get_status(),
|
||||
'subject' => $subject,
|
||||
'from' => trim( sprintf( '%s <%s>', $name, $email ) ),
|
||||
'from_name' => $name,
|
||||
'from_email' => $email,
|
||||
'fields' => $posted_data,
|
||||
'meta' => $meta,
|
||||
'akismet' => $submission->pull( 'akismet' ),
|
||||
'spam' => ( 'spam' == $result['status'] ),
|
||||
'consent' => $submission->collect_consent(),
|
||||
'timestamp' => $timestamp,
|
||||
'posted_data_hash' => $submission->get_posted_data_hash(),
|
||||
);
|
||||
|
||||
if ( $args['spam'] ) {
|
||||
$args['spam_log'] = $submission->get_spam_log();
|
||||
}
|
||||
|
||||
$args['recaptcha'] = $submission->pull( 'recaptcha' );
|
||||
|
||||
$args = apply_filters( 'wpcf7_flamingo_inbound_message_parameters', $args );
|
||||
|
||||
$flamingo_inbound = Flamingo_Inbound_Message::add( $args );
|
||||
|
||||
if ( empty( $flamingo_contact ) ) {
|
||||
$flamingo_contact_id = 0;
|
||||
} elseif ( method_exists( $flamingo_contact, 'id' ) ) {
|
||||
$flamingo_contact_id = $flamingo_contact->id();
|
||||
} else {
|
||||
$flamingo_contact_id = $flamingo_contact->id;
|
||||
}
|
||||
|
||||
if ( empty( $flamingo_inbound ) ) {
|
||||
$flamingo_inbound_id = 0;
|
||||
} elseif ( method_exists( $flamingo_inbound, 'id' ) ) {
|
||||
$flamingo_inbound_id = $flamingo_inbound->id();
|
||||
} else {
|
||||
$flamingo_inbound_id = $flamingo_inbound->id;
|
||||
}
|
||||
|
||||
$result += array(
|
||||
'flamingo_contact_id' => absint( $flamingo_contact_id ),
|
||||
'flamingo_inbound_id' => absint( $flamingo_inbound_id ),
|
||||
);
|
||||
|
||||
do_action( 'wpcf7_after_flamingo', $result );
|
||||
}
|
||||
|
||||
function wpcf7_flamingo_get_value( $field, $contact_form ) {
|
||||
if ( empty( $field )
|
||||
or empty( $contact_form ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$value = '';
|
||||
|
||||
if ( in_array( $field, array( 'email', 'name', 'subject' ) ) ) {
|
||||
$template = $contact_form->pref( 'flamingo_' . $field );
|
||||
|
||||
if ( null === $template ) {
|
||||
$template = sprintf( '[your-%s]', $field );
|
||||
} else {
|
||||
$template = trim( wpcf7_strip_quote( $template ) );
|
||||
}
|
||||
|
||||
$value = wpcf7_mail_replace_tags( $template );
|
||||
}
|
||||
|
||||
$value = apply_filters( 'wpcf7_flamingo_get_value', $value,
|
||||
$field, $contact_form
|
||||
);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function wpcf7_flamingo_add_channel( $slug, $name = '' ) {
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$parent = term_exists( 'contact-form-7',
|
||||
Flamingo_Inbound_Message::channel_taxonomy
|
||||
);
|
||||
|
||||
if ( ! $parent ) {
|
||||
$parent = wp_insert_term( __( 'Contact Form 7', 'contact-form-7' ),
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array( 'slug' => 'contact-form-7' )
|
||||
);
|
||||
|
||||
if ( is_wp_error( $parent ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$parent = (int) $parent['term_id'];
|
||||
|
||||
if ( ! is_taxonomy_hierarchical( Flamingo_Inbound_Message::channel_taxonomy ) ) {
|
||||
// backward compat for Flamingo 1.0.4 and lower
|
||||
return $parent;
|
||||
}
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
$name = $slug;
|
||||
}
|
||||
|
||||
$channel = term_exists( $slug,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
$parent
|
||||
);
|
||||
|
||||
if ( ! $channel ) {
|
||||
$channel = wp_insert_term( $name,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array( 'slug' => $slug, 'parent' => $parent )
|
||||
);
|
||||
|
||||
if ( is_wp_error( $channel ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) $channel['term_id'];
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_after_update', 'wpcf7_flamingo_update_channel', 10, 1 );
|
||||
|
||||
function wpcf7_flamingo_update_channel( $contact_form ) {
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel = isset( $post_meta['channel'] )
|
||||
? get_term( $post_meta['channel'],
|
||||
Flamingo_Inbound_Message::channel_taxonomy
|
||||
)
|
||||
: get_term_by( 'slug', $contact_form->name(),
|
||||
Flamingo_Inbound_Message::channel_taxonomy
|
||||
);
|
||||
|
||||
if ( ! $channel or is_wp_error( $channel ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $channel->name !== wp_unslash( $contact_form->title() ) ) {
|
||||
wp_update_term( $channel->term_id,
|
||||
Flamingo_Inbound_Message::channel_taxonomy,
|
||||
array(
|
||||
'name' => $contact_form->title(),
|
||||
'slug' => $contact_form->name(),
|
||||
'parent' => $channel->parent,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_flamingo_serial_number', 10, 4 );
|
||||
|
||||
/**
|
||||
* Returns output string of a special mail-tag.
|
||||
*
|
||||
* @param string $output The string to be output.
|
||||
* @param string $name The tag name of the special mail-tag.
|
||||
* @param bool $html Whether the mail-tag is used in an HTML content.
|
||||
* @param WPCF7_MailTag $mail_tag An object representation of the mail-tag.
|
||||
* @return string Output of the given special mail-tag.
|
||||
*/
|
||||
function wpcf7_flamingo_serial_number( $output, $name, $html, $mail_tag = null ) {
|
||||
if ( ! $mail_tag instanceof WPCF7_MailTag ) {
|
||||
wpcf7_doing_it_wrong(
|
||||
sprintf( '%s()', __FUNCTION__ ),
|
||||
__( 'The fourth parameter ($mail_tag) must be an instance of the WPCF7_MailTag class.', 'contact-form-7' ),
|
||||
'5.2.2'
|
||||
);
|
||||
}
|
||||
|
||||
if ( '_serial_number' != $name ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'Flamingo_Inbound_Message' )
|
||||
or ! method_exists( 'Flamingo_Inbound_Message', 'count' ) ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
if ( ! $contact_form = WPCF7_ContactForm::get_current() ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$post_meta = get_post_meta( $contact_form->id(), '_flamingo', true );
|
||||
|
||||
$channel_id = isset( $post_meta['channel'] )
|
||||
? (int) $post_meta['channel']
|
||||
: wpcf7_flamingo_add_channel(
|
||||
$contact_form->name(), $contact_form->title()
|
||||
);
|
||||
|
||||
if ( $channel_id ) {
|
||||
return 1 + (int) Flamingo_Inbound_Message::count(
|
||||
array( 'channel_id' => $channel_id )
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
36
wp/plugins/contact-form-7/modules/hidden.php
Normal file
36
wp/plugins/contact-form-7/modules/hidden.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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;
|
||||
}
|
||||
35
wp/plugins/contact-form-7/modules/listo.php
Normal file
35
wp/plugins/contact-form-7/modules/listo.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
** Retrieve list data from the Listo plugin.
|
||||
** Listo http://wordpress.org/plugins/listo/
|
||||
**/
|
||||
|
||||
add_filter( 'wpcf7_form_tag_data_option', 'wpcf7_listo', 10, 3 );
|
||||
|
||||
function wpcf7_listo( $data, $options, $args ) {
|
||||
if ( ! function_exists( 'listo' ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$contact_form = wpcf7_get_current_contact_form();
|
||||
$args['locale'] = $contact_form->locale();
|
||||
|
||||
foreach ( (array) $options as $option ) {
|
||||
$option = explode( '.', $option );
|
||||
$type = $option[0];
|
||||
|
||||
if ( isset( $option[1] ) ) {
|
||||
$args['group'] = $option[1];
|
||||
} else {
|
||||
unset( $args['group'] );
|
||||
}
|
||||
|
||||
if ( $list = listo( $type, $args ) ) {
|
||||
$data = array_merge( (array) $data, $list );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
292
wp/plugins/contact-form-7/modules/number.php
Normal file
292
wp/plugins/contact-form-7/modules/number.php
Normal file
@@ -0,0 +1,292 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for the following types of tags:
|
||||
** [number] and [number*] # Number
|
||||
** [range] and [range*] # Range
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_number', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_number() {
|
||||
wpcf7_add_form_tag( array( 'number', 'number*', 'range', 'range*' ),
|
||||
'wpcf7_number_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_number_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-number';
|
||||
|
||||
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_option( 'min', 'signed_num', true );
|
||||
$atts['max'] = $tag->get_option( 'max', 'signed_num', true );
|
||||
$atts['step'] = $tag->get_option( 'step', 'num', 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 );
|
||||
|
||||
$value = wpcf7_get_hangover( $tag->name, $value );
|
||||
|
||||
$atts['value'] = $value;
|
||||
|
||||
if ( 'range' === $tag->basetype ) {
|
||||
if ( ! wpcf7_is_number( $atts['min'] ) ) {
|
||||
$atts['min'] = '0';
|
||||
}
|
||||
|
||||
if ( ! wpcf7_is_number( $atts['max'] ) ) {
|
||||
$atts['max'] = '100';
|
||||
}
|
||||
|
||||
if ( '' === $atts['value'] ) {
|
||||
if ( $atts['min'] < $atts['max'] ) {
|
||||
$atts['value'] = ( $atts['min'] + $atts['max'] ) / 2;
|
||||
} else {
|
||||
$atts['value'] = $atts['min'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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_number_rules',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_number_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'basetype' => array( 'number', 'range' ),
|
||||
) );
|
||||
|
||||
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( 'number', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_number' ),
|
||||
) )
|
||||
);
|
||||
|
||||
$min = $tag->get_option( 'min', 'signed_num', true );
|
||||
$max = $tag->get_option( 'max', 'signed_num', true );
|
||||
|
||||
if ( 'range' === $tag->basetype ) {
|
||||
if ( ! wpcf7_is_number( $min ) ) {
|
||||
$min = '0';
|
||||
}
|
||||
|
||||
if ( ! wpcf7_is_number( $max ) ) {
|
||||
$max = '100';
|
||||
}
|
||||
}
|
||||
|
||||
if ( wpcf7_is_number( $min ) ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'minnumber', array(
|
||||
'field' => $tag->name,
|
||||
'threshold' => $min,
|
||||
'error' => wpcf7_get_message( 'number_too_small' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( wpcf7_is_number( $max ) ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'maxnumber', array(
|
||||
'field' => $tag->name,
|
||||
'threshold' => $max,
|
||||
'error' => wpcf7_get_message( 'number_too_large' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_number_messages', 10, 1 );
|
||||
|
||||
function wpcf7_number_messages( $messages ) {
|
||||
return array_merge( $messages, array(
|
||||
'invalid_number' => array(
|
||||
'description' => __( "Number format that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' => __( "Please enter a number.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'number_too_small' => array(
|
||||
'description' => __( "Number is smaller than minimum limit", 'contact-form-7' ),
|
||||
'default' => __( "This field has a too small number.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'number_too_large' => array(
|
||||
'description' => __( "Number is larger than maximum limit", 'contact-form-7' ),
|
||||
'default' => __( "This field has a too large number.", 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_number', 18, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_number() {
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'number', __( 'number', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_number' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_number( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
$type = 'number';
|
||||
|
||||
$description = __( "Generate a form-tag for a field for numeric value input. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/number-fields/', 'contact-form-7' ), __( 'Number fields', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<select name="tagtype">
|
||||
<option value="number" selected="selected"><?php echo esc_html( __( 'Spinbox', 'contact-form-7' ) ); ?></option>
|
||||
<option value="range"><?php echo esc_html( __( 'Slider', 'contact-form-7' ) ); ?></option>
|
||||
</select>
|
||||
<br />
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Range', 'contact-form-7' ) ); ?></legend>
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Min', 'contact-form-7' ) ); ?>
|
||||
<input type="number" name="min" class="numeric option" />
|
||||
</label>
|
||||
–
|
||||
<label>
|
||||
<?php echo esc_html( __( 'Max', 'contact-form-7' ) ); ?>
|
||||
<input type="number" name="max" class="numeric option" />
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
273
wp/plugins/contact-form-7/modules/quiz.php
Normal file
273
wp/plugins/contact-form-7/modules/quiz.php
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [quiz]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_quiz', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_quiz() {
|
||||
wpcf7_add_form_tag( 'quiz',
|
||||
'wpcf7_quiz_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'do-not-store' => true,
|
||||
'not-for-mail' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_quiz_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';
|
||||
$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';
|
||||
}
|
||||
|
||||
$pipes = $tag->pipes;
|
||||
|
||||
if ( $pipes instanceof WPCF7_Pipes
|
||||
and ! $pipes->zero() ) {
|
||||
$pipe = $pipes->random_pipe();
|
||||
$question = $pipe->before;
|
||||
$answer = $pipe->after;
|
||||
} else {
|
||||
// default quiz
|
||||
$question = '1+1=?';
|
||||
$answer = '2';
|
||||
}
|
||||
|
||||
$answer = wpcf7_canonicalize( $answer, array(
|
||||
'strip_separators' => true,
|
||||
) );
|
||||
|
||||
$atts['type'] = 'text';
|
||||
$atts['name'] = $tag->name;
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><label><span class="wpcf7-quiz-label">%2$s</span> <input %3$s /></label><input type="hidden" name="_wpcf7_quiz_answer_%4$s" value="%5$s" />%6$s</span>',
|
||||
esc_attr( $tag->name ),
|
||||
esc_html( $question ),
|
||||
wpcf7_format_atts( $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 ) {
|
||||
$name = $tag->name;
|
||||
|
||||
$answer = isset( $_POST[$name] ) ? wp_unslash( $_POST[$name] ) : '';
|
||||
|
||||
$answer = wpcf7_canonicalize( $answer, array(
|
||||
'strip_separators' => true,
|
||||
) );
|
||||
|
||||
$answer_hash = wp_hash( $answer, 'wpcf7_quiz' );
|
||||
|
||||
$expected_hash = isset( $_POST['_wpcf7_quiz_answer_' . $name] )
|
||||
? (string) $_POST['_wpcf7_quiz_answer_' . $name]
|
||||
: '';
|
||||
|
||||
if ( ! hash_equals( $expected_hash, $answer_hash ) ) {
|
||||
$result->invalidate( $tag, wpcf7_get_message( 'quiz_answer_not_correct' ) );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/* Ajax echo filter */
|
||||
|
||||
add_filter( 'wpcf7_refill_response', 'wpcf7_quiz_ajax_refill', 10, 1 );
|
||||
add_filter( 'wpcf7_feedback_response', 'wpcf7_quiz_ajax_refill', 10, 1 );
|
||||
|
||||
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
|
||||
and ! $pipes->zero() ) {
|
||||
$pipe = $pipes->random_pipe();
|
||||
$question = $pipe->before;
|
||||
$answer = $pipe->after;
|
||||
} else {
|
||||
// default quiz
|
||||
$question = '1+1=?';
|
||||
$answer = '2';
|
||||
}
|
||||
|
||||
$answer = wpcf7_canonicalize( $answer, array(
|
||||
'strip_separators' => true,
|
||||
) );
|
||||
|
||||
$refill[$name] = array( $question, wp_hash( $answer, 'wpcf7_quiz' ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $refill ) ) {
|
||||
$items['quiz'] = $refill;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/* Mail-tag replacement */
|
||||
|
||||
add_filter( 'wpcf7_mail_tag_replaced_quiz', 'wpcf7_quiz_mail_tag', 10, 4 );
|
||||
|
||||
function wpcf7_quiz_mail_tag( $replaced, $submitted, $html, $mail_tag ) {
|
||||
$field_name = $mail_tag->field_name();
|
||||
$submitted = isset( $_POST[$field_name] ) ? $_POST[$field_name] : '';
|
||||
$replaced = $submitted;
|
||||
|
||||
if ( $html ) {
|
||||
$replaced = esc_html( $replaced );
|
||||
$replaced = wptexturize( $replaced );
|
||||
}
|
||||
|
||||
return $replaced;
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_quiz_messages', 10, 1 );
|
||||
|
||||
function wpcf7_quiz_messages( $messages ) {
|
||||
$messages = array_merge( $messages, array(
|
||||
'quiz_answer_not_correct' => array(
|
||||
'description' =>
|
||||
__( "Sender does not enter the correct answer to the quiz", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "The answer to the quiz is incorrect.", 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_quiz', 40, 0 );
|
||||
|
||||
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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Questions and answers', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Questions and answers', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea><br />
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One pipe-separated question-answer pair (e.g. The capital of Brazil?|Rio) per line.", 'contact-form-7' ) ); ?></span></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
703
wp/plugins/contact-form-7/modules/really-simple-captcha.php
Normal file
703
wp/plugins/contact-form-7/modules/really-simple-captcha.php
Normal file
@@ -0,0 +1,703 @@
|
||||
<?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 = isset( $_POST[$captchac] ) ? (string) $_POST[$captchac] : '';
|
||||
$response = isset( $_POST[$name] ) ? (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;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_captcha', 46, 0 );
|
||||
|
||||
function wpcf7_add_tag_generator_captcha() {
|
||||
if ( ! wpcf7_use_really_simple_captcha() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tag_generator = WPCF7_TagGenerator::get_instance();
|
||||
$tag_generator->add( 'captcha',
|
||||
__( 'CAPTCHA (Really Simple CAPTCHA)', 'contact-form-7' ),
|
||||
'wpcf7_tag_generator_captcha' );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_captcha( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
if ( ! class_exists( 'ReallySimpleCaptcha' ) ) {
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php
|
||||
echo sprintf(
|
||||
/* translators: %s: link labeled 'Really Simple CAPTCHA' */
|
||||
esc_html( __( "To use CAPTCHA, you first need to install and activate %s plugin.", 'contact-form-7' ) ),
|
||||
wpcf7_link( 'https://wordpress.org/plugins/really-simple-captcha/', 'Really Simple CAPTCHA' )
|
||||
);
|
||||
?></legend>
|
||||
</fieldset>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$description = __( "Generate form-tags for a CAPTCHA image and corresponding response input field. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/captcha/', 'contact-form-7' ), __( 'CAPTCHA', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="form-table scope captchac">
|
||||
<caption><?php echo esc_html( __( "Image settings", 'contact-form-7' ) ); ?></caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchac-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchac-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchac-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchac-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<table class="form-table scope captchar">
|
||||
<caption><?php echo esc_html( __( "Input field settings", 'contact-form-7' ) ); ?></caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchar-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchar-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-captchar-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-captchar-class' ); ?>" /></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="captcha" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/* 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 );
|
||||
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html( $message ) . '</p></div>';
|
||||
}
|
||||
|
||||
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' );
|
||||
|
||||
echo '<div class="notice notice-warning"><p>' . esc_html( $message ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'dependencies' => array(),
|
||||
'version' => WPCF7_VERSION,
|
||||
);
|
||||
1
wp/plugins/contact-form-7/modules/recaptcha/index.js
Normal file
1
wp/plugins/contact-form-7/modules/recaptcha/index.js
Normal file
@@ -0,0 +1 @@
|
||||
document.addEventListener("DOMContentLoaded",(e=>{var t;wpcf7_recaptcha={...null!==(t=wpcf7_recaptcha)&&void 0!==t?t:{}};const c=wpcf7_recaptcha.sitekey,{homepage:n,contactform:a}=wpcf7_recaptcha.actions,o=e=>{const{action:t,func:n,params:a}=e;grecaptcha.execute(c,{action:t}).then((e=>{const c=new CustomEvent("wpcf7grecaptchaexecuted",{detail:{action:t,token:e}});document.dispatchEvent(c)})).then((()=>{"function"==typeof n&&n(...a)})).catch((e=>console.error(e)))};if(grecaptcha.ready((()=>{o({action:n})})),document.addEventListener("change",(e=>{o({action:a})})),"undefined"!=typeof wpcf7&&"function"==typeof wpcf7.submit){const e=wpcf7.submit;wpcf7.submit=(t,c={})=>{o({action:a,func:e,params:[t,c]})}}document.addEventListener("wpcf7grecaptchaexecuted",(e=>{const t=document.querySelectorAll('form.wpcf7-form input[name="_wpcf7_recaptcha_response"]');for(let c=0;c<t.length;c++)t[c].setAttribute("value",e.detail.token)}))}));
|
||||
270
wp/plugins/contact-form-7/modules/recaptcha/recaptcha.php
Normal file
270
wp/plugins/contact-form-7/modules/recaptcha/recaptcha.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* reCAPTCHA module main file
|
||||
*
|
||||
* @link https://contactform7.com/recaptcha/
|
||||
*/
|
||||
|
||||
wpcf7_include_module_file( 'recaptcha/service.php' );
|
||||
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_recaptcha_register_service', 40, 0 );
|
||||
|
||||
/**
|
||||
* Registers the reCAPTCHA service.
|
||||
*/
|
||||
function wpcf7_recaptcha_register_service() {
|
||||
$integration = WPCF7_Integration::get_instance();
|
||||
|
||||
$integration->add_service( 'recaptcha',
|
||||
WPCF7_RECAPTCHA::get_instance()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
add_action(
|
||||
'wp_enqueue_scripts',
|
||||
'wpcf7_recaptcha_enqueue_scripts',
|
||||
20, 0
|
||||
);
|
||||
|
||||
/**
|
||||
* Enqueues frontend scripts for reCAPTCHA.
|
||||
*/
|
||||
function wpcf7_recaptcha_enqueue_scripts() {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url = 'https://www.google.com/recaptcha/api.js';
|
||||
|
||||
if ( apply_filters( 'wpcf7_use_recaptcha_net', false ) ) {
|
||||
$url = 'https://www.recaptcha.net/recaptcha/api.js';
|
||||
}
|
||||
|
||||
wp_register_script( 'google-recaptcha',
|
||||
add_query_arg(
|
||||
array(
|
||||
'render' => $service->get_sitekey(),
|
||||
),
|
||||
$url
|
||||
),
|
||||
array(),
|
||||
'3.0',
|
||||
true
|
||||
);
|
||||
|
||||
$assets = array();
|
||||
$asset_file = wpcf7_plugin_path( 'modules/recaptcha/index.asset.php' );
|
||||
|
||||
if ( file_exists( $asset_file ) ) {
|
||||
$assets = include( $asset_file );
|
||||
}
|
||||
|
||||
$assets = wp_parse_args( $assets, array(
|
||||
'dependencies' => array(),
|
||||
'version' => WPCF7_VERSION,
|
||||
) );
|
||||
|
||||
wp_register_script(
|
||||
'wpcf7-recaptcha',
|
||||
wpcf7_plugin_url( 'modules/recaptcha/index.js' ),
|
||||
array_merge(
|
||||
$assets['dependencies'],
|
||||
array(
|
||||
'google-recaptcha',
|
||||
'wp-polyfill',
|
||||
)
|
||||
),
|
||||
$assets['version'],
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'wpcf7-recaptcha' );
|
||||
|
||||
wp_localize_script( 'wpcf7-recaptcha',
|
||||
'wpcf7_recaptcha',
|
||||
array(
|
||||
'sitekey' => $service->get_sitekey(),
|
||||
'actions' => apply_filters( 'wpcf7_recaptcha_actions', array(
|
||||
'homepage' => 'homepage',
|
||||
'contactform' => 'contactform',
|
||||
) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
add_filter(
|
||||
'wpcf7_form_hidden_fields',
|
||||
'wpcf7_recaptcha_add_hidden_fields',
|
||||
100, 1
|
||||
);
|
||||
|
||||
/**
|
||||
* Adds hidden form field for reCAPTCHA.
|
||||
*/
|
||||
function wpcf7_recaptcha_add_hidden_fields( $fields ) {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
return array_merge( $fields, array(
|
||||
'_wpcf7_recaptcha_response' => '',
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
add_filter( 'wpcf7_spam', 'wpcf7_recaptcha_verify_response', 9, 2 );
|
||||
|
||||
/**
|
||||
* Verifies reCAPTCHA token on the server side.
|
||||
*/
|
||||
function wpcf7_recaptcha_verify_response( $spam, $submission ) {
|
||||
if ( $spam ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return $spam;
|
||||
}
|
||||
|
||||
$token = isset( $_POST['_wpcf7_recaptcha_response'] )
|
||||
? trim( $_POST['_wpcf7_recaptcha_response'] ) : '';
|
||||
|
||||
if ( $service->verify( $token ) ) { // Human
|
||||
$spam = false;
|
||||
} else { // Bot
|
||||
$spam = true;
|
||||
|
||||
if ( '' === $token ) {
|
||||
$submission->add_spam_log( array(
|
||||
'agent' => 'recaptcha',
|
||||
'reason' => __(
|
||||
'reCAPTCHA response token is empty.',
|
||||
'contact-form-7'
|
||||
),
|
||||
) );
|
||||
} else {
|
||||
$submission->add_spam_log( array(
|
||||
'agent' => 'recaptcha',
|
||||
'reason' => sprintf(
|
||||
__(
|
||||
'reCAPTCHA score (%1$.2f) is lower than the threshold (%2$.2f).',
|
||||
'contact-form-7'
|
||||
),
|
||||
$service->get_last_score(),
|
||||
$service->get_threshold()
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
return $spam;
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_recaptcha_add_form_tag_recaptcha', 10, 0 );
|
||||
|
||||
/**
|
||||
* Registers form-tag types for reCAPTCHA.
|
||||
*/
|
||||
function wpcf7_recaptcha_add_form_tag_recaptcha() {
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wpcf7_add_form_tag( 'recaptcha',
|
||||
'__return_empty_string', // no output
|
||||
array( 'display-block' => true )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wpcf7_upgrade', 'wpcf7_upgrade_recaptcha_v2_v3', 10, 2 );
|
||||
|
||||
/**
|
||||
* Adds warnings for users upgrading from reCAPTCHA v2 to v3.
|
||||
*/
|
||||
function wpcf7_upgrade_recaptcha_v2_v3( $new_ver, $old_ver ) {
|
||||
if ( version_compare( '5.1-dev', $old_ver, '<=' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$service = WPCF7_RECAPTCHA::get_instance();
|
||||
|
||||
if ( ! $service->is_active() or $service->get_global_sitekey() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Maybe v2 keys are used now. Warning necessary.
|
||||
WPCF7::update_option( 'recaptcha_v2_v3_warning', true );
|
||||
WPCF7::update_option( 'recaptcha', null );
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wpcf7_admin_menu', 'wpcf7_admin_init_recaptcha_v2_v3', 10, 0 );
|
||||
|
||||
/**
|
||||
* Adds filters and actions for warnings.
|
||||
*/
|
||||
function wpcf7_admin_init_recaptcha_v2_v3() {
|
||||
if ( ! WPCF7::get_option( 'recaptcha_v2_v3_warning' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'wpcf7_admin_menu_change_notice',
|
||||
'wpcf7_admin_menu_change_notice_recaptcha_v2_v3',
|
||||
10, 1
|
||||
);
|
||||
|
||||
add_action(
|
||||
'wpcf7_admin_warnings',
|
||||
'wpcf7_admin_warnings_recaptcha_v2_v3',
|
||||
5, 3
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increments the admin menu counter for the Integration page.
|
||||
*/
|
||||
function wpcf7_admin_menu_change_notice_recaptcha_v2_v3( $counts ) {
|
||||
$counts['wpcf7-integration'] += 1;
|
||||
return $counts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints warnings on the admin screen.
|
||||
*/
|
||||
function wpcf7_admin_warnings_recaptcha_v2_v3( $page, $action, $object ) {
|
||||
if ( 'wpcf7-integration' !== $page ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
esc_html( __(
|
||||
"API keys for reCAPTCHA v3 are different from those for v2; keys for v2 do not work with the v3 API. You need to register your sites again to get new keys for v3. For details, see %s.",
|
||||
'contact-form-7'
|
||||
) ),
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
|
||||
__( 'reCAPTCHA (v3)', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
echo sprintf(
|
||||
'<div class="notice notice-warning"><p>%s</p></div>',
|
||||
$message
|
||||
);
|
||||
}
|
||||
362
wp/plugins/contact-form-7/modules/recaptcha/service.php
Normal file
362
wp/plugins/contact-form-7/modules/recaptcha/service.php
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'WPCF7_Service' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class WPCF7_RECAPTCHA extends WPCF7_Service {
|
||||
|
||||
private static $instance;
|
||||
private $sitekeys;
|
||||
private $last_score;
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if ( empty( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
private function __construct() {
|
||||
$this->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( 'spam_protection' );
|
||||
}
|
||||
|
||||
|
||||
public function icon() {
|
||||
}
|
||||
|
||||
|
||||
public function link() {
|
||||
echo wpcf7_link(
|
||||
'https://www.google.com/recaptcha/intro/index.html',
|
||||
'google.com/recaptcha'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function get_global_sitekey() {
|
||||
static $sitekey = '';
|
||||
|
||||
if ( $sitekey ) {
|
||||
return $sitekey;
|
||||
}
|
||||
|
||||
if ( defined( 'WPCF7_RECAPTCHA_SITEKEY' ) ) {
|
||||
$sitekey = WPCF7_RECAPTCHA_SITEKEY;
|
||||
}
|
||||
|
||||
$sitekey = apply_filters( 'wpcf7_recaptcha_sitekey', $sitekey );
|
||||
|
||||
return $sitekey;
|
||||
}
|
||||
|
||||
|
||||
public function get_global_secret() {
|
||||
static $secret = '';
|
||||
|
||||
if ( $secret ) {
|
||||
return $secret;
|
||||
}
|
||||
|
||||
if ( defined( 'WPCF7_RECAPTCHA_SECRET' ) ) {
|
||||
$secret = WPCF7_RECAPTCHA_SECRET;
|
||||
}
|
||||
|
||||
$secret = apply_filters( 'wpcf7_recaptcha_secret', $secret );
|
||||
|
||||
return $secret;
|
||||
}
|
||||
|
||||
|
||||
public function get_sitekey() {
|
||||
if ( $this->get_global_sitekey() and $this->get_global_secret() ) {
|
||||
return $this->get_global_sitekey();
|
||||
}
|
||||
|
||||
if ( empty( $this->sitekeys )
|
||||
or ! is_array( $this->sitekeys ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sitekeys = array_keys( $this->sitekeys );
|
||||
|
||||
return $sitekeys[0];
|
||||
}
|
||||
|
||||
|
||||
public function get_secret( $sitekey ) {
|
||||
if ( $this->get_global_sitekey() and $this->get_global_secret() ) {
|
||||
return $this->get_global_secret();
|
||||
}
|
||||
|
||||
$sitekeys = (array) $this->sitekeys;
|
||||
|
||||
if ( isset( $sitekeys[$sitekey] ) ) {
|
||||
return $sitekeys[$sitekey];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function log( $url, $request, $response ) {
|
||||
wpcf7_log_remote_request( $url, $request, $response );
|
||||
}
|
||||
|
||||
|
||||
public function verify( $token ) {
|
||||
$is_human = false;
|
||||
|
||||
if ( empty( $token ) or ! $this->is_active() ) {
|
||||
return $is_human;
|
||||
}
|
||||
|
||||
$endpoint = 'https://www.google.com/recaptcha/api/siteverify';
|
||||
|
||||
$sitekey = $this->get_sitekey();
|
||||
$secret = $this->get_secret( $sitekey );
|
||||
|
||||
$request = array(
|
||||
'body' => array(
|
||||
'secret' => $secret,
|
||||
'response' => $token,
|
||||
),
|
||||
);
|
||||
|
||||
$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 $is_human;
|
||||
}
|
||||
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
$response_body = json_decode( $response_body, true );
|
||||
|
||||
$this->last_score = $score = isset( $response_body['score'] )
|
||||
? $response_body['score']
|
||||
: 0;
|
||||
|
||||
$threshold = $this->get_threshold();
|
||||
$is_human = $threshold < $score;
|
||||
|
||||
$is_human = apply_filters( 'wpcf7_recaptcha_verify_response',
|
||||
$is_human, $response_body );
|
||||
|
||||
if ( $submission = WPCF7_Submission::get_instance() ) {
|
||||
$submission->push( 'recaptcha', array(
|
||||
'version' => '3.0',
|
||||
'threshold' => $threshold,
|
||||
'response' => $response_body,
|
||||
) );
|
||||
}
|
||||
|
||||
return $is_human;
|
||||
}
|
||||
|
||||
|
||||
public function get_threshold() {
|
||||
return apply_filters( 'wpcf7_recaptcha_threshold', 0.50 );
|
||||
}
|
||||
|
||||
|
||||
public function get_last_score() {
|
||||
return $this->last_score;
|
||||
}
|
||||
|
||||
|
||||
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' => 'recaptcha' ), $url );
|
||||
|
||||
if ( ! empty( $args ) ) {
|
||||
$url = add_query_arg( $args, $url );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
protected function save_data() {
|
||||
WPCF7::update_option( 'recaptcha', $this->sitekeys );
|
||||
}
|
||||
|
||||
|
||||
protected function reset_data() {
|
||||
$this->sitekeys = null;
|
||||
$this->save_data();
|
||||
}
|
||||
|
||||
|
||||
public function load( $action = '' ) {
|
||||
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
check_admin_referer( 'wpcf7-recaptcha-setup' );
|
||||
|
||||
if ( ! empty( $_POST['reset'] ) ) {
|
||||
$this->reset_data();
|
||||
$redirect_to = $this->menu_page_url( 'action=setup' );
|
||||
} else {
|
||||
$sitekey = isset( $_POST['sitekey'] ) ? trim( $_POST['sitekey'] ) : '';
|
||||
$secret = isset( $_POST['secret'] ) ? trim( $_POST['secret'] ) : '';
|
||||
|
||||
if ( $sitekey and $secret ) {
|
||||
$this->sitekeys = array( $sitekey => $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',
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( WPCF7::get_option( 'recaptcha_v2_v3_warning' ) ) {
|
||||
WPCF7::update_option( 'recaptcha_v2_v3_warning', false );
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function admin_notice( $message = '' ) {
|
||||
if ( 'invalid' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "Error", 'contact-form-7' ) ),
|
||||
esc_html( __( "Invalid key values.", 'contact-form-7' ) ) );
|
||||
}
|
||||
|
||||
if ( 'success' == $message ) {
|
||||
echo sprintf( '<div class="notice notice-success"><p>%s</p></div>',
|
||||
esc_html( __( 'Settings saved.', 'contact-form-7' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function display( $action = '' ) {
|
||||
echo sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html( __( "reCAPTCHA protects you against spam and other types of automated abuse. With Contact Form 7’s reCAPTCHA integration module, you can block abusive form submissions by spam bots.", 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
echo sprintf(
|
||||
'<p><strong>%s</strong></p>',
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/recaptcha/', 'contact-form-7' ),
|
||||
__( 'reCAPTCHA (v3)', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
if ( $this->is_active() ) {
|
||||
echo sprintf(
|
||||
'<p class="dashicons-before dashicons-yes">%s</p>',
|
||||
esc_html( __( "reCAPTCHA is active on this site.", '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() {
|
||||
$sitekey = $this->is_active() ? $this->get_sitekey() : '';
|
||||
$secret = $this->is_active() ? $this->get_secret( $sitekey ) : '';
|
||||
|
||||
?>
|
||||
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
|
||||
<?php wp_nonce_field( 'wpcf7-recaptcha-setup' ); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="sitekey"><?php echo esc_html( __( 'Site Key', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( $sitekey );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="sitekey" name="sitekey" />',
|
||||
esc_attr( $sitekey )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="sitekey" name="sitekey" class="regular-text code" />',
|
||||
esc_attr( $sitekey )
|
||||
);
|
||||
}
|
||||
?></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, 4, 4 ) );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%1$s" id="secret" name="secret" />',
|
||||
esc_attr( $secret )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%1$s" id="secret" name="secret" class="regular-text code" />',
|
||||
esc_attr( $secret )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
if ( $this->is_active() ) {
|
||||
if ( $this->get_global_sitekey() and $this->get_global_secret() ) {
|
||||
// nothing
|
||||
} else {
|
||||
submit_button(
|
||||
_x( 'Remove Keys', 'API keys', 'contact-form-7' ),
|
||||
'small', 'reset'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
submit_button( __( 'Save Changes', 'contact-form-7' ) );
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
118
wp/plugins/contact-form-7/modules/reflection.php
Normal file
118
wp/plugins/contact-form-7/modules/reflection.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?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;
|
||||
}
|
||||
23
wp/plugins/contact-form-7/modules/response.php
Normal file
23
wp/plugins/contact-form-7/modules/response.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
235
wp/plugins/contact-form-7/modules/select.php
Normal file
235
wp/plugins/contact-form-7/modules/select.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for [select] and [select*]
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_select', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_select() {
|
||||
wpcf7_add_form_tag( array( 'select', 'select*' ),
|
||||
'wpcf7_select_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
'selectable-values' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_select_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['class'] = $tag->get_class_option( $class );
|
||||
$atts['id'] = $tag->get_id_option();
|
||||
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
|
||||
|
||||
$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';
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $data = (array) $tag->get_data_option() ) {
|
||||
$tag->values = array_merge( $tag->values, array_values( $data ) );
|
||||
$tag->labels = array_merge( $tag->labels, array_values( $data ) );
|
||||
}
|
||||
|
||||
$values = $tag->values;
|
||||
$labels = $tag->labels;
|
||||
|
||||
$default_choice = $tag->get_default_option( null, array(
|
||||
'multiple' => $multiple,
|
||||
) );
|
||||
|
||||
if ( $include_blank
|
||||
or empty( $values ) ) {
|
||||
array_unshift(
|
||||
$labels,
|
||||
__( '—Please choose an option—', 'contact-form-7' )
|
||||
);
|
||||
array_unshift( $values, '' );
|
||||
} elseif ( $first_as_label ) {
|
||||
$values[0] = '';
|
||||
}
|
||||
|
||||
$html = '';
|
||||
$hangover = wpcf7_get_hangover( $tag->name );
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( $hangover ) {
|
||||
$selected = in_array( $value, (array) $hangover, true );
|
||||
} else {
|
||||
$selected = in_array( $value, (array) $default_choice, true );
|
||||
}
|
||||
|
||||
$item_atts = array(
|
||||
'value' => $value,
|
||||
'selected' => $selected,
|
||||
);
|
||||
|
||||
$label = isset( $labels[$key] ) ? $labels[$key] : $value;
|
||||
|
||||
$html .= sprintf(
|
||||
'<option %1$s>%2$s</option>',
|
||||
wpcf7_format_atts( $item_atts ),
|
||||
esc_html( $label )
|
||||
);
|
||||
}
|
||||
|
||||
$atts['multiple'] = (bool) $multiple;
|
||||
$atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap" data-name="%1$s"><select %2$s>%3$s</select>%4$s</span>',
|
||||
esc_attr( $tag->name ),
|
||||
wpcf7_format_atts( $atts ),
|
||||
$html,
|
||||
$validation_error
|
||||
);
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
add_action(
|
||||
'wpcf7_swv_create_schema',
|
||||
'wpcf7_swv_add_select_rules',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_select_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'type' => array( 'select*' ),
|
||||
) );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'required', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_required' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_menu', 25, 0 );
|
||||
|
||||
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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Options', 'contact-form-7' ) ); ?></legend>
|
||||
<textarea name="values" class="values" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>"></textarea>
|
||||
<label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><span class="description"><?php echo esc_html( __( "One option per line.", 'contact-form-7' ) ); ?></span></label><br />
|
||||
<label><input type="checkbox" name="multiple" class="option" /> <?php echo esc_html( __( 'Allow multiple selections', 'contact-form-7' ) ); ?></label><br />
|
||||
<label><input type="checkbox" name="include_blank" class="option" /> <?php echo esc_html( __( 'Insert a blank item as the first option', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="select" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
<?php
|
||||
|
||||
add_filter(
|
||||
'wpcf7_pre_construct_contact_form_properties',
|
||||
'wpcf7_sendinblue_register_property',
|
||||
10, 2
|
||||
);
|
||||
|
||||
/**
|
||||
* Registers the sendinblue contact form property.
|
||||
*/
|
||||
function wpcf7_sendinblue_register_property( $properties, $contact_form ) {
|
||||
$service = WPCF7_Sendinblue::get_instance();
|
||||
|
||||
if ( $service->is_active() ) {
|
||||
$properties += array(
|
||||
'sendinblue' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
|
||||
add_action(
|
||||
'wpcf7_save_contact_form',
|
||||
'wpcf7_sendinblue_save_contact_form',
|
||||
10, 3
|
||||
);
|
||||
|
||||
/**
|
||||
* Saves the sendinblue property value.
|
||||
*/
|
||||
function wpcf7_sendinblue_save_contact_form( $contact_form, $args, $context ) {
|
||||
$service = WPCF7_Sendinblue::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prop = isset( $_POST['wpcf7-sendinblue'] )
|
||||
? (array) $_POST['wpcf7-sendinblue']
|
||||
: array();
|
||||
|
||||
$prop = wp_parse_args(
|
||||
$prop,
|
||||
array(
|
||||
'enable_contact_list' => false,
|
||||
'contact_lists' => array(),
|
||||
'enable_transactional_email' => false,
|
||||
'email_template' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
$prop['contact_lists'] = array_map( 'absint', $prop['contact_lists'] );
|
||||
|
||||
$prop['email_template'] = absint( $prop['email_template'] );
|
||||
|
||||
$contact_form->set_properties( array(
|
||||
'sendinblue' => $prop,
|
||||
) );
|
||||
}
|
||||
|
||||
|
||||
add_filter(
|
||||
'wpcf7_editor_panels',
|
||||
'wpcf7_sendinblue_editor_panels',
|
||||
10, 1
|
||||
);
|
||||
|
||||
/**
|
||||
* Builds the editor panel for the sendinblue property.
|
||||
*/
|
||||
function wpcf7_sendinblue_editor_panels( $panels ) {
|
||||
$service = WPCF7_Sendinblue::get_instance();
|
||||
|
||||
if ( ! $service->is_active() ) {
|
||||
return $panels;
|
||||
}
|
||||
|
||||
$contact_form = WPCF7_ContactForm::get_current();
|
||||
|
||||
$prop = wp_parse_args(
|
||||
$contact_form->prop( 'sendinblue' ),
|
||||
array(
|
||||
'enable_contact_list' => false,
|
||||
'contact_lists' => array(),
|
||||
'enable_transactional_email' => false,
|
||||
'email_template' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
$editor_panel = static function () use ( $prop, $service ) {
|
||||
|
||||
$description = sprintf(
|
||||
esc_html(
|
||||
__( "You can set up the Brevo integration here. For details, see %s.", 'contact-form-7' )
|
||||
),
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
|
||||
__( 'Brevo integration', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
$lists = $service->get_lists();
|
||||
$templates = $service->get_templates();
|
||||
|
||||
?>
|
||||
<h2><?php echo esc_html( __( 'Brevo', '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-sendinblue-enable-contact-list">
|
||||
<input type="checkbox" name="wpcf7-sendinblue[enable_contact_list]" id="wpcf7-sendinblue-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-sendinblue[contact_lists][]',
|
||||
'value' => $list['id'],
|
||||
'checked' => in_array( $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://my.sendinblue.com/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>
|
||||
<tr class="<?php echo $prop['enable_transactional_email'] ? '' : 'inactive'; ?>">
|
||||
<th scope="row">
|
||||
<?php
|
||||
|
||||
echo esc_html( __( 'Welcome email', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
</th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text">
|
||||
<?php
|
||||
|
||||
echo esc_html( __( 'Welcome email', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
</legend>
|
||||
<label for="wpcf7-sendinblue-enable-transactional-email">
|
||||
<input type="checkbox" name="wpcf7-sendinblue[enable_transactional_email]" id="wpcf7-sendinblue-enable-transactional-email" value="1" <?php checked( $prop['enable_transactional_email'] ); ?> />
|
||||
<?php
|
||||
|
||||
echo esc_html(
|
||||
__( "Send a welcome email to new contacts", 'contact-form-7' )
|
||||
);
|
||||
|
||||
?>
|
||||
</label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<?php
|
||||
|
||||
if ( $templates ) {
|
||||
echo sprintf(
|
||||
'<legend>%1$s</legend>',
|
||||
esc_html( __( 'Select an email template:', 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
echo '<select name="wpcf7-sendinblue[email_template]">';
|
||||
|
||||
echo sprintf(
|
||||
'<option %1$s>%2$s</option>',
|
||||
wpcf7_format_atts( array(
|
||||
'value' => 0,
|
||||
'selected' => 0 === $prop['email_template'],
|
||||
) ),
|
||||
esc_html( __( '— Select —', 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
foreach ( $templates as $template ) {
|
||||
echo sprintf(
|
||||
'<option %1$s>%2$s</option>',
|
||||
wpcf7_format_atts( array(
|
||||
'value' => $template['id'],
|
||||
'selected' => $prop['email_template'] === $template['id'],
|
||||
) ),
|
||||
esc_html( $template['name'] )
|
||||
);
|
||||
}
|
||||
|
||||
echo '</select>';
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<legend>%1$s</legend>',
|
||||
esc_html( __( 'You have no active email template 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://my.sendinblue.com/camp/lists/template',
|
||||
'target' => '_blank',
|
||||
'rel' => 'external noreferrer noopener',
|
||||
) ),
|
||||
esc_html( __( 'Manage your email templates', 'contact-form-7' ) ),
|
||||
esc_html( __( '(opens in a new tab)', 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
<?php
|
||||
};
|
||||
|
||||
$panels += array(
|
||||
'sendinblue-panel' => array(
|
||||
'title' => __( 'Brevo', 'contact-form-7' ),
|
||||
'callback' => $editor_panel,
|
||||
),
|
||||
);
|
||||
|
||||
return $panels;
|
||||
}
|
||||
101
wp/plugins/contact-form-7/modules/sendinblue/doi.php
Normal file
101
wp/plugins/contact-form-7/modules/sendinblue/doi.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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 );
|
||||
}
|
||||
228
wp/plugins/contact-form-7/modules/sendinblue/sendinblue.php
Normal file
228
wp/plugins/contact-form-7/modules/sendinblue/sendinblue.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?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 = implode( ' ', (array) $params['SMS'] );
|
||||
$sms = trim( $sms );
|
||||
|
||||
$plus = '+' == substr( $sms, 0, 1 ) ? '+' : '';
|
||||
$sms = preg_replace( '/[^0-9]/', '', $sms );
|
||||
|
||||
if ( 6 < strlen( $sms ) and strlen( $sms ) < 18 ) {
|
||||
$params['SMS'] = $plus . $sms;
|
||||
} else { // Invalid phone 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 = apply_filters(
|
||||
'wpcf7_sendinblue_collect_parameters',
|
||||
$params
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
||||
386
wp/plugins/contact-form-7/modules/sendinblue/service.php
Normal file
386
wp/plugins/contact-form-7/modules/sendinblue/service.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
if ( ! class_exists( 'WPCF7_Service' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
class WPCF7_Sendinblue extends WPCF7_Service {
|
||||
use WPCF7_Sendinblue_API;
|
||||
|
||||
private static $instance;
|
||||
private $api_key;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( empty( self::$instance ) ) {
|
||||
self::$instance = new self;
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$option = WPCF7::get_option( 'sendinblue' );
|
||||
|
||||
if ( isset( $option['api_key'] ) ) {
|
||||
$this->api_key = $option['api_key'];
|
||||
}
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return __( 'Brevo', 'contact-form-7' );
|
||||
}
|
||||
|
||||
public function is_active() {
|
||||
return (bool) $this->get_api_key();
|
||||
}
|
||||
|
||||
public function get_api_key() {
|
||||
return $this->api_key;
|
||||
}
|
||||
|
||||
public function get_categories() {
|
||||
return array( 'email_marketing' );
|
||||
}
|
||||
|
||||
public function icon() {
|
||||
}
|
||||
|
||||
public function link() {
|
||||
echo wpcf7_link(
|
||||
'https://www.brevo.com/',
|
||||
'brevo.com'
|
||||
);
|
||||
}
|
||||
|
||||
protected function log( $url, $request, $response ) {
|
||||
wpcf7_log_remote_request( $url, $request, $response );
|
||||
}
|
||||
|
||||
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' => 'sendinblue' ), $url );
|
||||
|
||||
if ( ! empty( $args ) ) {
|
||||
$url = add_query_arg( $args, $url );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
protected function save_data() {
|
||||
WPCF7::update_option( 'sendinblue', array(
|
||||
'api_key' => $this->api_key,
|
||||
) );
|
||||
}
|
||||
|
||||
protected function reset_data() {
|
||||
$this->api_key = null;
|
||||
$this->save_data();
|
||||
}
|
||||
|
||||
public function load( $action = '' ) {
|
||||
if ( 'setup' == $action and 'POST' == $_SERVER['REQUEST_METHOD'] ) {
|
||||
check_admin_referer( 'wpcf7-sendinblue-setup' );
|
||||
|
||||
if ( ! empty( $_POST['reset'] ) ) {
|
||||
$this->reset_data();
|
||||
$redirect_to = $this->menu_page_url( 'action=setup' );
|
||||
} else {
|
||||
$this->api_key = isset( $_POST['api_key'] )
|
||||
? trim( $_POST['api_key'] )
|
||||
: '';
|
||||
|
||||
$confirmed = $this->confirm_key();
|
||||
|
||||
if ( true === $confirmed ) {
|
||||
$redirect_to = $this->menu_page_url( array(
|
||||
'message' => 'success',
|
||||
) );
|
||||
|
||||
$this->save_data();
|
||||
} elseif ( false === $confirmed ) {
|
||||
$redirect_to = $this->menu_page_url( array(
|
||||
'action' => 'setup',
|
||||
'message' => 'unauthorized',
|
||||
) );
|
||||
} else {
|
||||
$redirect_to = $this->menu_page_url( array(
|
||||
'action' => 'setup',
|
||||
'message' => 'invalid',
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
wp_safe_redirect( $redirect_to );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function admin_notice( $message = '' ) {
|
||||
if ( 'unauthorized' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "Error", 'contact-form-7' ) ),
|
||||
esc_html( __( "You have not been authenticated. Make sure the provided API key is correct.", 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'invalid' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "Error", 'contact-form-7' ) ),
|
||||
esc_html( __( "Invalid key values.", 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'success' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-success"><p>%s</p></div>',
|
||||
esc_html( __( 'Settings saved.', 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function display( $action = '' ) {
|
||||
echo sprintf(
|
||||
'<p>%s</p>',
|
||||
esc_html( __( "Store and organize your contacts while protecting user privacy on Brevo, the leading CRM & email marketing platform in Europe. Brevo offers unlimited contacts and advanced marketing features.", 'contact-form-7' ) )
|
||||
);
|
||||
|
||||
echo sprintf(
|
||||
'<p><strong>%s</strong></p>',
|
||||
wpcf7_link(
|
||||
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
|
||||
__( 'Brevo integration', 'contact-form-7' )
|
||||
)
|
||||
);
|
||||
|
||||
if ( $this->is_active() ) {
|
||||
echo sprintf(
|
||||
'<p class="dashicons-before dashicons-yes">%s</p>',
|
||||
esc_html( __( "Brevo is active on this site.", '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() {
|
||||
$api_key = $this->get_api_key();
|
||||
|
||||
?>
|
||||
<form method="post" action="<?php echo esc_url( $this->menu_page_url( 'action=setup' ) ); ?>">
|
||||
<?php wp_nonce_field( 'wpcf7-sendinblue-setup' ); ?>
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="publishable"><?php echo esc_html( __( 'API key', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><?php
|
||||
if ( $this->is_active() ) {
|
||||
echo esc_html( wpcf7_mask_password( $api_key, 4, 8 ) );
|
||||
echo sprintf(
|
||||
'<input type="hidden" value="%s" id="api_key" name="api_key" />',
|
||||
esc_attr( $api_key )
|
||||
);
|
||||
} else {
|
||||
echo sprintf(
|
||||
'<input type="text" aria-required="true" value="%s" id="api_key" name="api_key" class="regular-text code" />',
|
||||
esc_attr( $api_key )
|
||||
);
|
||||
}
|
||||
?></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
if ( $this->is_active() ) {
|
||||
submit_button(
|
||||
_x( 'Remove key', 'API keys', 'contact-form-7' ),
|
||||
'small', 'reset'
|
||||
);
|
||||
} else {
|
||||
submit_button( __( 'Save changes', 'contact-form-7' ) );
|
||||
}
|
||||
?>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trait for the Sendinblue API (v3).
|
||||
*
|
||||
* @link https://developers.sendinblue.com/reference
|
||||
*/
|
||||
trait WPCF7_Sendinblue_API {
|
||||
|
||||
|
||||
public function confirm_key() {
|
||||
$endpoint = 'https://api.sendinblue.com/v3/account';
|
||||
|
||||
$request = array(
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_get( $endpoint, $request );
|
||||
$response_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 === $response_code ) { // 200 OK
|
||||
return true;
|
||||
} elseif ( 401 === $response_code ) { // 401 Unauthorized
|
||||
return false;
|
||||
} elseif ( 400 <= $response_code ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_lists() {
|
||||
$endpoint = add_query_arg(
|
||||
array(
|
||||
'limit' => 50,
|
||||
'offset' => 0,
|
||||
),
|
||||
'https://api.sendinblue.com/v3/contacts/lists'
|
||||
);
|
||||
|
||||
$request = array(
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_get( $endpoint, $request );
|
||||
$response_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 === $response_code ) { // 200 OK
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
$response_body = json_decode( $response_body, true );
|
||||
|
||||
if ( empty( $response_body['lists'] ) ) {
|
||||
return array();
|
||||
} else {
|
||||
return (array) $response_body['lists'];
|
||||
}
|
||||
} elseif ( 400 <= $response_code ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function get_templates() {
|
||||
$endpoint = add_query_arg(
|
||||
array(
|
||||
'templateStatus' => 'true',
|
||||
'limit' => 100,
|
||||
'offset' => 0,
|
||||
),
|
||||
'https://api.sendinblue.com/v3/smtp/templates'
|
||||
);
|
||||
|
||||
$request = array(
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
);
|
||||
|
||||
$response = wp_remote_get( $endpoint, $request );
|
||||
$response_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 200 === $response_code ) { // 200 OK
|
||||
$response_body = wp_remote_retrieve_body( $response );
|
||||
$response_body = json_decode( $response_body, true );
|
||||
|
||||
if ( empty( $response_body['templates'] ) ) {
|
||||
return array();
|
||||
} else {
|
||||
return (array) $response_body['templates'];
|
||||
}
|
||||
} elseif ( 400 <= $response_code ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function create_contact( $properties ) {
|
||||
$endpoint = 'https://api.sendinblue.com/v3/contacts';
|
||||
|
||||
$request = array(
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
'body' => wp_json_encode( $properties ),
|
||||
);
|
||||
|
||||
$response = wp_remote_post( $endpoint, $request );
|
||||
$response_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( in_array( $response_code, array( 201, 204 ), true ) ) {
|
||||
$contact_id = wp_remote_retrieve_body( $response );
|
||||
return $contact_id;
|
||||
} elseif ( 400 <= $response_code ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function send_email( $properties ) {
|
||||
$endpoint = 'https://api.sendinblue.com/v3/smtp/email';
|
||||
|
||||
$request = array(
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'API-Key' => $this->get_api_key(),
|
||||
),
|
||||
'body' => wp_json_encode( $properties ),
|
||||
);
|
||||
|
||||
$response = wp_remote_post( $endpoint, $request );
|
||||
$response_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
|
||||
if ( 201 === $response_code ) { // 201 Transactional email sent
|
||||
$message_id = wp_remote_retrieve_body( $response );
|
||||
return $message_id;
|
||||
} elseif ( 400 <= $response_code ) {
|
||||
if ( WP_DEBUG ) {
|
||||
$this->log( $endpoint, $request, $response );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
154
wp/plugins/contact-form-7/modules/stripe/api.php
Normal file
154
wp/plugins/contact-form-7/modules/stripe/api.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
6
wp/plugins/contact-form-7/modules/stripe/index.asset.php
Normal file
6
wp/plugins/contact-form-7/modules/stripe/index.asset.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
'dependencies' => array(),
|
||||
'version' => WPCF7_VERSION,
|
||||
);
|
||||
1
wp/plugins/contact-form-7/modules/stripe/index.js
Normal file
1
wp/plugins/contact-form-7/modules/stripe/index.js
Normal file
@@ -0,0 +1 @@
|
||||
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)}))}));
|
||||
260
wp/plugins/contact-form-7/modules/stripe/service.php
Normal file
260
wp/plugins/contact-form-7/modules/stripe/service.php
Normal file
@@ -0,0 +1,260 @@
|
||||
<?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 = isset( $_POST['publishable'] ) ?
|
||||
trim( $_POST['publishable'] ) : '';
|
||||
$secret = isset( $_POST['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 ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-error"><p><strong>%1$s</strong>: %2$s</p></div>',
|
||||
esc_html( __( "Error", 'contact-form-7' ) ),
|
||||
esc_html( __( "Invalid key values.", 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'success' == $message ) {
|
||||
echo sprintf(
|
||||
'<div class="notice notice-success"><p>%s</p></div>',
|
||||
esc_html( __( 'Settings saved.', 'contact-form-7' ) )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
346
wp/plugins/contact-form-7/modules/stripe/stripe.php
Normal file
346
wp/plugins/contact-form-7/modules/stripe/stripe.php
Normal file
@@ -0,0 +1,346 @@
|
||||
<?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 = array();
|
||||
|
||||
$asset_file = wpcf7_plugin_path( 'modules/stripe/index.asset.php' );
|
||||
|
||||
if ( file_exists( $asset_file ) ) {
|
||||
$assets = include( $asset_file );
|
||||
}
|
||||
|
||||
$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'],
|
||||
true
|
||||
);
|
||||
|
||||
$api_keys = $service->get_api_keys();
|
||||
|
||||
if ( $api_keys['publishable'] ) {
|
||||
wp_localize_script( 'wpcf7-stripe', 'wpcf7_stripe', array(
|
||||
'publishable_key' => $api_keys['publishable'],
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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="" />'
|
||||
);
|
||||
}
|
||||
18
wp/plugins/contact-form-7/modules/stripe/style.css
Normal file
18
wp/plugins/contact-form-7/modules/stripe/style.css
Normal file
@@ -0,0 +1,18 @@
|
||||
.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;
|
||||
}
|
||||
92
wp/plugins/contact-form-7/modules/submit.php
Normal file
92
wp/plugins/contact-form-7/modules/submit.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?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( 'nameless' => 1 ) );
|
||||
}
|
||||
|
||||
function wpcf7_tag_generator_submit( $contact_form, $args = '' ) {
|
||||
$args = wp_parse_args( $args, array() );
|
||||
|
||||
$description = __( "Generate a form-tag for a submit button. For more details, see %s.", 'contact-form-7' );
|
||||
|
||||
$desc_link = wpcf7_link( __( 'https://contactform7.com/submit-button/', 'contact-form-7' ), __( 'Submit button', 'contact-form-7' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Label', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="submit" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
324
wp/plugins/contact-form-7/modules/text.php
Normal file
324
wp/plugins/contact-form-7/modules/text.php
Normal file
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
/**
|
||||
** A base module for the following types of tags:
|
||||
** [text] and [text*] # Single-line text
|
||||
** [email] and [email*] # Email address
|
||||
** [url] and [url*] # URL
|
||||
** [tel] and [tel*] # Telephone number
|
||||
**/
|
||||
|
||||
/* form_tag handler */
|
||||
|
||||
add_action( 'wpcf7_init', 'wpcf7_add_form_tag_text', 10, 0 );
|
||||
|
||||
function wpcf7_add_form_tag_text() {
|
||||
wpcf7_add_form_tag(
|
||||
array( 'text', 'text*', 'email', 'email*', 'url', 'url*', 'tel', 'tel*' ),
|
||||
'wpcf7_text_form_tag_handler',
|
||||
array(
|
||||
'name-attr' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function wpcf7_text_form_tag_handler( $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'] 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 = (string) reset( $tag->values );
|
||||
|
||||
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['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_text_rules',
|
||||
10, 2
|
||||
);
|
||||
|
||||
function wpcf7_swv_add_text_rules( $schema, $contact_form ) {
|
||||
$tags = $contact_form->scan_form_tags( array(
|
||||
'basetype' => array( 'text', 'email', 'url', 'tel' ),
|
||||
) );
|
||||
|
||||
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 ( 'email' === $tag->basetype ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'email', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_email' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'url' === $tag->basetype ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'url', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_url' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'tel' === $tag->basetype ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'tel', array(
|
||||
'field' => $tag->name,
|
||||
'error' => wpcf7_get_message( 'invalid_tel' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
|
||||
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() ) {
|
||||
$schema->add_rule(
|
||||
wpcf7_swv_create_rule( 'maxlength', array(
|
||||
'field' => $tag->name,
|
||||
'threshold' => absint( $maxlength ),
|
||||
'error' => wpcf7_get_message( 'invalid_too_long' ),
|
||||
) )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Messages */
|
||||
|
||||
add_filter( 'wpcf7_messages', 'wpcf7_text_messages', 10, 1 );
|
||||
|
||||
function wpcf7_text_messages( $messages ) {
|
||||
$messages = array_merge( $messages, array(
|
||||
'invalid_email' => array(
|
||||
'description' =>
|
||||
__( "Email address that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "Please enter an email address.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'invalid_url' => array(
|
||||
'description' =>
|
||||
__( "URL that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "Please enter a URL.", 'contact-form-7' ),
|
||||
),
|
||||
|
||||
'invalid_tel' => array(
|
||||
'description' =>
|
||||
__( "Telephone number that the sender entered is invalid", 'contact-form-7' ),
|
||||
'default' =>
|
||||
__( "Please enter a telephone number.", 'contact-form-7' ),
|
||||
),
|
||||
) );
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
|
||||
/* Tag generator */
|
||||
|
||||
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_text', 15, 0 );
|
||||
|
||||
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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<?php if ( in_array( $type, array( 'text', 'email', 'url' ) ) ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Akismet', 'contact-form-7' ) ); ?></legend>
|
||||
|
||||
<?php if ( 'text' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's name", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php elseif ( 'email' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author_email" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's email address", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php elseif ( 'url' == $type ) : ?>
|
||||
<label>
|
||||
<input type="checkbox" name="akismet:author_url" class="option" />
|
||||
<?php echo esc_html( __( "This field requires author's URL", 'contact-form-7' ) ); ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
208
wp/plugins/contact-form-7/modules/textarea.php
Normal file
208
wp/plugins/contact-form-7/modules/textarea.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?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();
|
||||
$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() ) {
|
||||
$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' );
|
||||
}
|
||||
|
||||
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' ) );
|
||||
|
||||
?>
|
||||
<div class="control-box">
|
||||
<fieldset>
|
||||
<legend><?php echo sprintf( esc_html( $description ), $desc_link ); ?></legend>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<legend class="screen-reader-text"><?php echo esc_html( __( 'Field type', 'contact-form-7' ) ); ?></legend>
|
||||
<label><input type="checkbox" name="required" /> <?php echo esc_html( __( 'Required field', 'contact-form-7' ) ); ?></label>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-name' ); ?>"><?php echo esc_html( __( 'Name', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="name" class="tg-name oneline" id="<?php echo esc_attr( $args['content'] . '-name' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-values' ); ?>"><?php echo esc_html( __( 'Default value', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="values" class="oneline" id="<?php echo esc_attr( $args['content'] . '-values' ); ?>" /><br />
|
||||
<label><input type="checkbox" name="placeholder" class="option" /> <?php echo esc_html( __( 'Use this text as the placeholder of the field', 'contact-form-7' ) ); ?></label></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-id' ); ?>"><?php echo esc_html( __( 'Id attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="id" class="idvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-id' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row"><label for="<?php echo esc_attr( $args['content'] . '-class' ); ?>"><?php echo esc_html( __( 'Class attribute', 'contact-form-7' ) ); ?></label></th>
|
||||
<td><input type="text" name="class" class="classvalue oneline option" id="<?php echo esc_attr( $args['content'] . '-class' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div class="insert-box">
|
||||
<input type="text" name="<?php echo $type; ?>" class="tag code" readonly="readonly" onfocus="this.select()" />
|
||||
|
||||
<div class="submitbox">
|
||||
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'contact-form-7' ) ); ?>" />
|
||||
</div>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<p class="description mail-tag"><label for="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>"><?php echo sprintf( esc_html( __( "To use the value input through this field in a mail field, you need to insert the corresponding mail-tag (%s) into the field on the Mail tab.", 'contact-form-7' ) ), '<strong><span class="mail-tag"></span></strong>' ); ?><input type="text" class="mail-tag code hidden" readonly="readonly" id="<?php echo esc_attr( $args['content'] . '-mailtag' ); ?>" /></label></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
Reference in New Issue
Block a user