select.php 0000644 00000014412 14720676231 0006546 0 ustar 00 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(
'%2$s ',
wpcf7_format_atts( $item_atts ),
esc_html( $label )
);
}
$atts['multiple'] = (bool) $multiple;
$atts['name'] = $tag->name . ( $multiple ? '[]' : '' );
$html = sprintf(
'%3$s %4$s ',
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' ),
) )
);
}
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_select_enum_rules',
20, 2
);
function wpcf7_swv_add_select_enum_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'select' ),
) );
$values = array_reduce(
$tags,
function ( $values, $tag ) {
if ( ! isset( $values[$tag->name] ) ) {
$values[$tag->name] = array();
}
$tag_values = array_merge(
(array) $tag->values,
(array) $tag->get_data_option()
);
if ( $tag->has_option( 'first_as_label' ) ) {
$tag_values = array_slice( $tag_values, 1 );
}
$values[$tag->name] = array_merge(
$values[$tag->name],
$tag_values
);
return $values;
},
array()
);
foreach ( $values as $field => $field_values ) {
$field_values = array_map(
static function ( $value ) {
return html_entity_decode(
(string) $value,
ENT_QUOTES | ENT_HTML5,
'UTF-8'
);
},
$field_values
);
$field_values = array_filter(
array_unique( $field_values ),
static function ( $value ) {
return '' !== $value;
}
);
$schema->add_rule(
wpcf7_swv_create_rule( 'enum', array(
'field' => $field,
'accept' => array_values( $field_values ),
'error' => $contact_form->filter_message(
__( "Undefined value was submitted through this field.", 'contact-form-7' )
),
) )
);
}
}
/* 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',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_menu( $contact_form, $options ) {
$field_types = array(
'select' => array(
'display_name' => __( 'Drop-down menu', 'contact-form-7' ),
'heading' => __( 'Drop-down menu form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a drop-down menu .', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?>
print( 'field_type', array(
'with_required' => true,
'select_options' => array(
'select' => $field_types['select']['display_name'],
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'selectable_values', array(
'first_as_label' => true,
) );
?>
print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
add_service( 'sendinblue',
WPCF7_Sendinblue::get_instance()
);
}
add_action( 'wpcf7_submit', 'wpcf7_sendinblue_submit', 10, 2 );
/**
* Callback to the wpcf7_submit action hook. Creates a contact
* based on the submission.
*/
function wpcf7_sendinblue_submit( $contact_form, $result ) {
if ( $contact_form->in_demo_mode() ) {
return;
}
$service = WPCF7_Sendinblue::get_instance();
if ( ! $service->is_active() ) {
return;
}
if ( empty( $result['posted_data_hash'] ) ) {
return;
}
if ( empty( $result['status'] )
or ! in_array( $result['status'], array( 'mail_sent', 'mail_failed' ) ) ) {
return;
}
$submission = WPCF7_Submission::get_instance();
$consented = true;
foreach ( $contact_form->scan_form_tags( 'feature=name-attr' ) as $tag ) {
if ( $tag->has_option( 'consent_for:sendinblue' )
and null == $submission->get_posted_data( $tag->name ) ) {
$consented = false;
break;
}
}
if ( ! $consented ) {
return;
}
$prop = wp_parse_args(
$contact_form->prop( 'sendinblue' ),
array(
'enable_contact_list' => false,
'contact_lists' => array(),
'enable_transactional_email' => false,
'email_template' => 0,
)
);
if ( ! $prop['enable_contact_list'] ) {
return;
}
$attributes = wpcf7_sendinblue_collect_parameters();
$params = array(
'contact' => array(),
'email' => array(),
);
if ( ! empty( $attributes['EMAIL'] ) or ! empty( $attributes['SMS'] ) ) {
$params['contact'] = apply_filters(
'wpcf7_sendinblue_contact_parameters',
array(
'email' => $attributes['EMAIL'],
'attributes' => (object) $attributes,
'listIds' => (array) $prop['contact_lists'],
'updateEnabled' => false,
)
);
}
if ( $prop['enable_transactional_email'] and $prop['email_template'] ) {
$first_name = isset( $attributes['FIRSTNAME'] )
? trim( $attributes['FIRSTNAME'] )
: '';
$last_name = isset( $attributes['LASTNAME'] )
? trim( $attributes['LASTNAME'] )
: '';
if ( $first_name or $last_name ) {
$email_to_name = sprintf(
/* translators: 1: first name, 2: last name */
_x( '%1$s %2$s', 'personal name', 'contact-form-7' ),
$first_name,
$last_name
);
} else {
$email_to_name = '';
}
$params['email'] = apply_filters(
'wpcf7_sendinblue_email_parameters',
array(
'templateId' => absint( $prop['email_template'] ),
'to' => array(
array(
'name' => $email_to_name,
'email' => $attributes['EMAIL'],
),
),
'params' => (object) $attributes,
'tags' => array( 'Contact Form 7' ),
)
);
}
if ( is_email( $attributes['EMAIL'] ) ) {
$token = null;
do_action_ref_array( 'wpcf7_doi', array(
'wpcf7_sendinblue',
array(
'email_to' => $attributes['EMAIL'],
'properties' => $params,
),
&$token,
) );
if ( isset( $token ) ) {
return;
}
}
if ( ! empty( $params['contact'] ) ) {
$contact_id = $service->create_contact( $params['contact'] );
if ( $contact_id and ! empty( $params['email'] ) ) {
$service->send_email( $params['email'] );
}
}
}
/**
* Collects parameters for Sendinblue contact data based on submission.
*
* @return array Sendinblue contact parameters.
*/
function wpcf7_sendinblue_collect_parameters() {
$params = array();
$submission = WPCF7_Submission::get_instance();
foreach ( (array) $submission->get_posted_data() as $name => $val ) {
$name = strtoupper( $name );
if ( 'YOUR-' == substr( $name, 0, 5 ) ) {
$name = substr( $name, 5 );
}
if ( $val ) {
$params += array(
$name => $val,
);
}
}
if ( isset( $params['SMS'] ) ) {
$sms = trim( implode( ' ', (array) $params['SMS'] ) );
$sms = preg_replace( '/[#*].*$/', '', $sms ); // Remove extension
$is_international = false ||
str_starts_with( $sms, '+' ) ||
str_starts_with( $sms, '00' );
if ( $is_international ) {
$sms = preg_replace( '/^[+0]+/', '', $sms );
}
$sms = preg_replace( '/[^0-9]/', '', $sms );
if ( $is_international and 6 < strlen( $sms ) and strlen( $sms ) < 16 ) {
$params['SMS'] = '+' . $sms;
} else { // Invalid telephone number
unset( $params['SMS'] );
}
}
if ( isset( $params['NAME'] ) ) {
$your_name = implode( ' ', (array) $params['NAME'] );
$your_name = explode( ' ', $your_name );
if ( ! isset( $params['LASTNAME'] ) ) {
$params['LASTNAME'] = implode(
' ',
array_slice( $your_name, 1 )
);
}
if ( ! isset( $params['FIRSTNAME'] ) ) {
$params['FIRSTNAME'] = implode(
' ',
array_slice( $your_name, 0, 1 )
);
}
}
$params = array_map(
function ( $param ) {
if ( is_array( $param ) ) {
$param = wpcf7_array_flatten( $param );
$param = reset( $param );
}
return $param;
},
$params
);
$params = apply_filters(
'wpcf7_sendinblue_collect_parameters',
$params
);
return $params;
}
sendinblue/service.php 0000644 00000022305 14720676231 0011057 0 ustar 00 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://get.brevo.com/wpcf7-integration',
'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 = 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 ) {
wp_admin_notice(
sprintf(
'%1$s : %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "You have not been authenticated. Make sure the provided API key is correct.", 'contact-form-7' ) )
),
'type=error'
);
}
if ( 'invalid' === $message ) {
wp_admin_notice(
sprintf(
'%1$s : %2$s',
esc_html( __( "Error", 'contact-form-7' ) ),
esc_html( __( "Invalid key values.", 'contact-form-7' ) )
),
'type=error'
);
}
if ( 'success' === $message ) {
wp_admin_notice(
esc_html( __( "Settings saved.", 'contact-form-7' ) ),
'type=success'
);
}
}
public function display( $action = '' ) {
echo sprintf(
'%s
',
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(
'%s
',
wpcf7_link(
__( 'https://contactform7.com/sendinblue-integration/', 'contact-form-7' ),
__( 'Brevo integration', 'contact-form-7' )
)
);
if ( $this->is_active() ) {
echo sprintf(
'%s
',
esc_html( __( "Brevo is active on this site.", 'contact-form-7' ) )
);
}
if ( 'setup' == $action ) {
$this->display_setup();
} else {
echo sprintf(
'%2$s
',
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();
?>
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( $options = '' ) {
$options = wp_parse_args( $options, array(
'limit' => 50,
'offset' => 0,
) );
$endpoint = add_query_arg(
$options,
'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;
}
}
sendinblue/contact-form-properties.php 0000644 00000016441 14720676231 0014211 0 ustar 00 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 = (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 = wpcf7_sendinblue_get_lists();
$templates = $service->get_templates();
?>
array(
'title' => __( 'Brevo', 'contact-form-7' ),
'callback' => $editor_panel,
),
);
return $panels;
}
/**
* Retrieves contact lists from Brevo's database.
*/
function wpcf7_sendinblue_get_lists() {
static $lists = array();
$service = WPCF7_Sendinblue::get_instance();
if ( ! empty( $lists ) or ! $service->is_active() ) {
return $lists;
}
$limit = 50;
$offset = 0;
while ( count( $lists ) < $limit * 10 ) {
$lists_next = (array) $service->get_lists( array(
'limit' => $limit,
'offset' => $offset,
) );
if ( ! empty( $lists_next ) ) {
$lists = array_merge( $lists, $lists_next );
}
if ( count( $lists_next ) < $limit ) {
break;
}
$offset += $limit;
}
return $lists;
}
sendinblue/doi.php 0000644 00000004433 14720676231 0010174 0 ustar 00 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 );
}
number.php 0000644 00000014441 14720676231 0006561 0 ustar 00 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(
' %3$s ',
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',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_number( $contact_form, $options ) {
$field_types = array(
'number' => array(
'display_name' => __( 'Number field', 'contact-form-7' ),
'heading' => __( 'Number field form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a number input field .', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?>
print( 'field_type', array(
'with_required' => true,
'select_options' => array(
'number' => __( 'Spinbox', 'contact-form-7' ),
'range' => __( 'Slider', 'contact-form-7' ),
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'min_max', array(
'title' => __( 'Range', 'contact-form-7' ),
'min_option' => 'min:',
'max_option' => 'max:',
) );
$tgg->print( 'default_value', array(
'type' => 'number',
'with_placeholder' => false,
) );
?>
print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
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(
'%2$s ',
wpcf7_format_atts( $atts ),
$value
);
return $html;
}
textarea.php 0000644 00000011613 14720676231 0007104 0 ustar 00 true )
);
}
function wpcf7_textarea_form_tag_handler( $tag ) {
if ( empty( $tag->name ) ) {
return '';
}
$validation_error = wpcf7_get_validation_error( $tag->name );
$class = wpcf7_form_controls_class( $tag->type );
if ( $validation_error ) {
$class .= ' wpcf7-not-valid';
}
$atts = array();
$atts['cols'] = $tag->get_cols_option( '40' );
$atts['rows'] = $tag->get_rows_option( '10' );
$atts['maxlength'] = $tag->get_maxlength_option( '2000' );
$atts['minlength'] = $tag->get_minlength_option();
if ( $atts['maxlength'] and $atts['minlength']
and $atts['maxlength'] < $atts['minlength'] ) {
unset( $atts['maxlength'], $atts['minlength'] );
}
$atts['class'] = $tag->get_class_option( $class );
$atts['id'] = $tag->get_id_option();
$atts['tabindex'] = $tag->get_option( 'tabindex', 'signed_int', true );
$atts['readonly'] = $tag->has_option( 'readonly' );
$atts['autocomplete'] = $tag->get_option(
'autocomplete', '[-0-9a-zA-Z]+', true
);
if ( $tag->is_required() ) {
$atts['aria-required'] = 'true';
}
if ( $validation_error ) {
$atts['aria-invalid'] = 'true';
$atts['aria-describedby'] = wpcf7_get_validation_error_reference(
$tag->name
);
} else {
$atts['aria-invalid'] = 'false';
}
$value = empty( $tag->content )
? (string) reset( $tag->values )
: $tag->content;
if ( $tag->has_option( 'placeholder' )
or $tag->has_option( 'watermark' ) ) {
$atts['placeholder'] = $value;
$value = '';
}
$value = $tag->get_default_option( $value );
$value = wpcf7_get_hangover( $tag->name, $value );
$atts['name'] = $tag->name;
$html = sprintf(
'%4$s ',
esc_attr( $tag->name ),
wpcf7_format_atts( $atts ),
esc_textarea( $value ),
$validation_error
);
return $html;
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_textarea_rules',
10, 2
);
function wpcf7_swv_add_textarea_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'textarea' ),
) );
foreach ( $tags as $tag ) {
if ( $tag->is_required() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'required', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_required' ),
) )
);
}
if ( $minlength = $tag->get_minlength_option() ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'minlength', array(
'field' => $tag->name,
'threshold' => absint( $minlength ),
'error' => wpcf7_get_message( 'invalid_too_short' ),
) )
);
}
if ( $maxlength = $tag->get_maxlength_option( '2000' ) ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'maxlength', array(
'field' => $tag->name,
'threshold' => absint( $maxlength ),
'error' => wpcf7_get_message( 'invalid_too_long' ),
) )
);
}
}
}
/* Tag generator */
add_action( 'wpcf7_admin_init', 'wpcf7_add_tag_generator_textarea', 20, 0 );
function wpcf7_add_tag_generator_textarea() {
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->add( 'textarea',
__( 'text area', 'contact-form-7' ),
'wpcf7_tag_generator_textarea',
array( 'version' => '2' )
);
}
function wpcf7_tag_generator_textarea( $contact_form, $options ) {
$field_types = array(
'textarea' => array(
'display_name' => __( 'Text area', 'contact-form-7' ),
'heading' => __( 'Text area form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a multi-line plain text input area .', 'contact-form-7' ),
),
);
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?>
print( 'field_type', array(
'with_required' => true,
'select_options' => array(
'textarea' => $field_types['textarea']['display_name'],
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'min_max', array(
'title' => __( 'Length', 'contact-form-7' ),
'min_option' => 'minlength:',
'max_option' => 'maxlength:',
) );
$tgg->print( 'default_value', array(
'with_placeholder' => true,
'use_content' => true,
) );
?>
print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
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(
'%1$s ',
esc_html( $label ),
$item_atts
);
} else {
$item = sprintf(
'%1$s ',
esc_html( $label ),
$item_atts
);
}
if ( $use_label_element ) {
$item = '' . $item . ' ';
}
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 = sprintf( '_wpcf7_free_text_%s', $tag->name );
$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( ' ', $free_text_atts );
$class .= ' has-free-text';
}
}
$item = '' . $item . ' ';
$html .= $item;
}
$html = sprintf(
'%3$s %4$s ',
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(
'basetype' => array( 'checkbox', 'radio' ),
) );
foreach ( $tags as $tag ) {
if ( $tag->is_required() or 'radio' === $tag->type ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'required', array(
'field' => $tag->name,
'error' => wpcf7_get_message( 'invalid_required' ),
) )
);
}
if ( 'radio' === $tag->type or $tag->has_option( 'exclusive' ) ) {
$schema->add_rule(
wpcf7_swv_create_rule( 'maxitems', array(
'field' => $tag->name,
'threshold' => 1,
'error' => $contact_form->filter_message(
__( "Too many items are selected.", 'contact-form-7' )
),
) )
);
}
}
}
add_action(
'wpcf7_swv_create_schema',
'wpcf7_swv_add_checkbox_enum_rules',
20, 2
);
function wpcf7_swv_add_checkbox_enum_rules( $schema, $contact_form ) {
$tags = $contact_form->scan_form_tags( array(
'basetype' => array( 'checkbox', 'radio' ),
) );
$values = array_reduce(
$tags,
function ( $values, $tag ) {
if ( $tag->has_option( 'free_text' ) ) {
$values[$tag->name] = 'free_text';
}
if (
isset( $values[$tag->name] ) and
! is_array( $values[$tag->name] ) // Maybe 'free_text'
) {
return $values;
}
if ( ! isset( $values[$tag->name] ) ) {
$values[$tag->name] = array();
}
$tag_values = array_merge(
(array) $tag->values,
(array) $tag->get_data_option()
);
$values[$tag->name] = array_merge(
$values[$tag->name],
$tag_values
);
return $values;
},
array()
);
foreach ( $values as $field => $field_values ) {
if ( ! is_array( $field_values ) ) { // Maybe 'free_text'
continue;
}
$field_values = array_map(
static function ( $value ) {
return html_entity_decode(
(string) $value,
ENT_QUOTES | ENT_HTML5,
'UTF-8'
);
},
$field_values
);
$field_values = array_filter(
array_unique( $field_values ),
static function ( $value ) {
return '' !== $value;
}
);
$schema->add_rule(
wpcf7_swv_create_rule( 'enum', array(
'field' => $field,
'accept' => array_values( $field_values ),
'error' => $contact_form->filter_message(
__( "Undefined value was submitted through this field.", 'contact-form-7' )
),
) )
);
}
}
add_filter( 'wpcf7_posted_data_checkbox',
'wpcf7_posted_data_checkbox',
10, 3
);
add_filter( 'wpcf7_posted_data_checkbox*',
'wpcf7_posted_data_checkbox',
10, 3
);
add_filter( 'wpcf7_posted_data_radio',
'wpcf7_posted_data_checkbox',
10, 3
);
function wpcf7_posted_data_checkbox( $value, $value_orig, $form_tag ) {
if ( $form_tag->has_option( 'free_text' ) ) {
$value = (array) $value;
$free_text_name = sprintf( '_wpcf7_free_text_%s', $form_tag->name );
$free_text = wp_unslash( $_POST[$free_text_name] ?? '' );
$last_val = array_pop( $value );
if ( isset( $last_val ) ) {
$last_val = sprintf( '%s %s', $last_val, $free_text );
$value[] = trim( $last_val );
}
}
return $value;
}
/* 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();
$basetypes = array(
'checkbox' => __( 'checkboxes', 'contact-form-7' ),
'radio' => __( 'radio buttons', 'contact-form-7' ),
);
foreach ( $basetypes as $id => $title ) {
$tag_generator->add( $id, $title,
'wpcf7_tag_generator_checkbox',
array( 'version' => '2' )
);
}
}
function wpcf7_tag_generator_checkbox( $contact_form, $options ) {
$field_types = array(
'checkbox' => array(
'display_name' => __( 'Checkboxes', 'contact-form-7' ),
'heading' => __( 'Checkboxes form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a group of checkboxes .', 'contact-form-7' ),
),
'radio' => array(
'display_name' => __( 'Radio buttons', 'contact-form-7' ),
'heading' => __( 'Radio buttons form-tag generator', 'contact-form-7' ),
'description' => __( 'Generates a form-tag for a group of radio buttons .', 'contact-form-7' ),
),
);
$basetype = $options['id'];
if ( ! in_array( $basetype, array_keys( $field_types ) ) ) {
$basetype = 'checkbox';
}
$tgg = new WPCF7_TagGeneratorGenerator( $options['content'] );
?>
array( 'href' => true ),
'strong' => array(),
),
array( 'http', 'https' )
);
echo $description;
?>
print( 'field_type', array(
'with_required' => 'checkbox' === $basetype,
'select_options' => array(
$basetype => $field_types[$basetype]['display_name'],
),
) );
$tgg->print( 'field_name' );
$tgg->print( 'class_attr' );
$tgg->print( 'selectable_values', array(
'use_label_element' => 'checked',
) );
?>
print( 'insert_box_content' );
$tgg->print( 'mail_tag_tip' );
?>
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;
}
recaptcha/index.js 0000644 00000001646 14720676231 0010162 0 ustar 00 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