PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,26 @@
<?php
add_filter( 'map_meta_cap', 'wpcf7_map_meta_cap', 10, 4 );
function wpcf7_map_meta_cap( $caps, $cap, $user_id, $args ) {
$meta_caps = array(
'wpcf7_edit_contact_form' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_edit_contact_forms' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_read_contact_form' => WPCF7_ADMIN_READ_CAPABILITY,
'wpcf7_read_contact_forms' => WPCF7_ADMIN_READ_CAPABILITY,
'wpcf7_delete_contact_form' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_delete_contact_forms' => WPCF7_ADMIN_READ_WRITE_CAPABILITY,
'wpcf7_manage_integration' => 'manage_options',
'wpcf7_submit' => 'read',
);
$meta_caps = apply_filters( 'wpcf7_map_meta_cap', $meta_caps );
$caps = array_diff( $caps, array_keys( $meta_caps ) );
if ( isset( $meta_caps[$cap] ) ) {
$caps[] = $meta_caps[$cap];
}
return $caps;
}

View File

@ -0,0 +1,643 @@
<?php
class WPCF7_ConfigValidator {
const error = 100;
const error_maybe_empty = 101;
const error_invalid_mailbox_syntax = 102;
const error_email_not_in_site_domain = 103;
const error_html_in_message = 104;
const error_multiple_controls_in_label = 105;
const error_file_not_found = 106;
const error_unavailable_names = 107;
const error_invalid_mail_header = 108;
const error_deprecated_settings = 109;
const error_file_not_in_content_dir = 110;
public static function get_doc_link( $error_code = '' ) {
$url = __( 'https://contactform7.com/configuration-errors/',
'contact-form-7' );
if ( '' !== $error_code ) {
$error_code = strtr( $error_code, '_', '-' );
$url = sprintf( '%s/%s', untrailingslashit( $url ), $error_code );
}
return esc_url( $url );
}
private $contact_form;
private $errors = array();
public function __construct( WPCF7_ContactForm $contact_form ) {
$this->contact_form = $contact_form;
}
public function contact_form() {
return $this->contact_form;
}
public function is_valid() {
return ! $this->count_errors();
}
public function count_errors( $args = '' ) {
$args = wp_parse_args( $args, array(
'section' => '',
'code' => '',
) );
$count = 0;
foreach ( $this->errors as $key => $errors ) {
if ( preg_match( '/^mail_[0-9]+\.(.*)$/', $key, $matches ) ) {
$key = sprintf( 'mail.%s', $matches[1] );
}
if ( $args['section']
and $key != $args['section']
and preg_replace( '/\..*$/', '', $key, 1 ) != $args['section'] ) {
continue;
}
foreach ( $errors as $error ) {
if ( empty( $error ) ) {
continue;
}
if ( $args['code'] and $error['code'] != $args['code'] ) {
continue;
}
$count += 1;
}
}
return $count;
}
public function collect_error_messages() {
$error_messages = array();
foreach ( $this->errors as $section => $errors ) {
$error_messages[$section] = array();
foreach ( $errors as $error ) {
if ( empty( $error['args']['message'] ) ) {
$message = $this->get_default_message( $error['code'] );
} elseif ( empty( $error['args']['params'] ) ) {
$message = $error['args']['message'];
} else {
$message = $this->build_message(
$error['args']['message'],
$error['args']['params'] );
}
$link = '';
if ( ! empty( $error['args']['link'] ) ) {
$link = $error['args']['link'];
}
$error_messages[$section][] = array(
'message' => $message,
'link' => esc_url( $link ),
);
}
}
return $error_messages;
}
public function build_message( $message, $params = '' ) {
$params = wp_parse_args( $params, array() );
foreach ( $params as $key => $val ) {
if ( ! preg_match( '/^[0-9A-Za-z_]+$/', $key ) ) { // invalid key
continue;
}
$placeholder = '%' . $key . '%';
if ( false !== stripos( $message, $placeholder ) ) {
$message = str_ireplace( $placeholder, $val, $message );
}
}
return $message;
}
public function get_default_message( $code ) {
switch ( $code ) {
case self::error_maybe_empty:
return __( "There is a possible empty field.", 'contact-form-7' );
case self::error_invalid_mailbox_syntax:
return __( "Invalid mailbox syntax is used.", 'contact-form-7' );
case self::error_email_not_in_site_domain:
return __( "Sender email address does not belong to the site domain.", 'contact-form-7' );
case self::error_html_in_message:
return __( "HTML tags are used in a message.", 'contact-form-7' );
case self::error_multiple_controls_in_label:
return __( "Multiple form controls are in a single label element.", 'contact-form-7' );
case self::error_invalid_mail_header:
return __( "There are invalid mail header fields.", 'contact-form-7' );
case self::error_deprecated_settings:
return __( "Deprecated settings are used.", 'contact-form-7' );
default:
return '';
}
}
public function add_error( $section, $code, $args = '' ) {
$args = wp_parse_args( $args, array(
'message' => '',
'params' => array(),
) );
if ( ! isset( $this->errors[$section] ) ) {
$this->errors[$section] = array();
}
$this->errors[$section][] = array( 'code' => $code, 'args' => $args );
return true;
}
public function remove_error( $section, $code ) {
if ( empty( $this->errors[$section] ) ) {
return;
}
foreach ( (array) $this->errors[$section] as $key => $error ) {
if ( isset( $error['code'] )
and $error['code'] == $code ) {
unset( $this->errors[$section][$key] );
}
}
}
public function validate() {
$this->errors = array();
$this->validate_form();
$this->validate_mail( 'mail' );
$this->validate_mail( 'mail_2' );
$this->validate_messages();
$this->validate_additional_settings();
do_action( 'wpcf7_config_validator_validate', $this );
return $this->is_valid();
}
public function save() {
if ( $this->contact_form->initial() ) {
return;
}
delete_post_meta( $this->contact_form->id(), '_config_errors' );
if ( $this->errors ) {
update_post_meta( $this->contact_form->id(), '_config_errors',
$this->errors );
}
}
public function restore() {
$config_errors = get_post_meta(
$this->contact_form->id(), '_config_errors', true );
foreach ( (array) $config_errors as $section => $errors ) {
if ( empty( $errors ) ) {
continue;
}
if ( ! is_array( $errors ) ) { // for back-compat
$code = $errors;
$this->add_error( $section, $code );
} else {
foreach ( (array) $errors as $error ) {
if ( ! empty( $error['code'] ) ) {
$code = $error['code'];
$args = isset( $error['args'] ) ? $error['args'] : '';
$this->add_error( $section, $code, $args );
}
}
}
}
}
public function replace_mail_tags_with_minimum_input( $matches ) {
// allow [[foo]] syntax for escaping a tag
if ( $matches[1] == '[' && $matches[4] == ']' ) {
return substr( $matches[0], 1, -1 );
}
$tag = $matches[0];
$tagname = $matches[2];
$values = $matches[3];
$mail_tag = new WPCF7_MailTag( $tag, $tagname, $values );
$field_name = $mail_tag->field_name();
$example_email = 'example@example.com';
$example_text = 'example';
$example_blank = '';
$form_tags = $this->contact_form->scan_form_tags(
array( 'name' => $field_name ) );
if ( $form_tags ) {
$form_tag = new WPCF7_FormTag( $form_tags[0] );
$is_required = ( $form_tag->is_required() || 'radio' == $form_tag->type );
if ( ! $is_required ) {
return $example_blank;
}
if ( wpcf7_form_tag_supports( $form_tag->type, 'selectable-values' ) ) {
if ( $form_tag->pipes instanceof WPCF7_Pipes ) {
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
$before_pipes = $form_tag->pipes->collect_befores();
$last_item = array_pop( $before_pipes );
} else {
$after_pipes = $form_tag->pipes->collect_afters();
$last_item = array_pop( $after_pipes );
}
} else {
$last_item = array_pop( $form_tag->values );
}
if ( $last_item and wpcf7_is_mailbox_list( $last_item ) ) {
return $example_email;
} else {
return $example_text;
}
}
if ( 'email' == $form_tag->basetype ) {
return $example_email;
} else {
return $example_text;
}
} else { // maybe special mail tag
// for back-compat
$field_name = preg_replace( '/^wpcf7\./', '_', $field_name );
if ( '_site_admin_email' == $field_name ) {
return get_bloginfo( 'admin_email', 'raw' );
} elseif ( '_user_agent' == $field_name ) {
return $example_text;
} elseif ( '_user_email' == $field_name ) {
return $this->contact_form->is_true( 'subscribers_only' )
? $example_email
: $example_blank;
} elseif ( '_user_' == substr( $field_name, 0, 6 ) ) {
return $this->contact_form->is_true( 'subscribers_only' )
? $example_text
: $example_blank;
} elseif ( '_' == substr( $field_name, 0, 1 ) ) {
return '_email' == substr( $field_name, -6 )
? $example_email
: $example_text;
}
}
return $tag;
}
public function validate_form() {
$section = 'form.body';
$form = $this->contact_form->prop( 'form' );
$this->detect_multiple_controls_in_label( $section, $form );
$this->detect_unavailable_names( $section, $form );
}
public function detect_multiple_controls_in_label( $section, $content ) {
$pattern = '%<label(?:[ \t\n]+.*?)?>(.+?)</label>%s';
if ( preg_match_all( $pattern, $content, $matches ) ) {
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
foreach ( $matches[1] as $insidelabel ) {
$tags = $form_tags_manager->scan( $insidelabel );
$fields_count = 0;
foreach ( $tags as $tag ) {
$is_multiple_controls_container = wpcf7_form_tag_supports(
$tag->type, 'multiple-controls-container' );
$is_zero_controls_container = wpcf7_form_tag_supports(
$tag->type, 'zero-controls-container' );
if ( $is_multiple_controls_container ) {
$fields_count += count( $tag->values );
if ( $tag->has_option( 'free_text' ) ) {
$fields_count += 1;
}
} elseif ( $is_zero_controls_container ) {
$fields_count += 0;
} elseif ( ! empty( $tag->name ) ) {
$fields_count += 1;
}
if ( 1 < $fields_count ) {
return $this->add_error( $section,
self::error_multiple_controls_in_label, array(
'link' => self::get_doc_link( 'multiple_controls_in_label' ),
)
);
}
}
}
}
return false;
}
public function detect_unavailable_names( $section, $content ) {
$public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat',
'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence',
'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order',
'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second',
'name', 'category_name', 'tag', 'feed', 'author_name', 'static',
'pagename', 'page_id', 'error', 'attachment', 'attachment_id',
'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term',
'cpage', 'post_type', 'embed' );
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
$ng_named_tags = $form_tags_manager->filter( $content,
array( 'name' => $public_query_vars ) );
$ng_names = array();
foreach ( $ng_named_tags as $tag ) {
$ng_names[] = sprintf( '"%s"', $tag->name );
}
if ( $ng_names ) {
$ng_names = array_unique( $ng_names );
return $this->add_error( $section,
self::error_unavailable_names,
array(
'message' =>
/* translators: %names%: a list of form control names */
__( "Unavailable names (%names%) are used for form controls.", 'contact-form-7' ),
'params' => array( 'names' => implode( ', ', $ng_names ) ),
'link' => self::get_doc_link( 'unavailable_names' ),
)
);
}
return false;
}
public function validate_mail( $template = 'mail' ) {
$components = (array) $this->contact_form->prop( $template );
if ( ! $components ) {
return;
}
if ( 'mail' != $template
and empty( $components['active'] ) ) {
return;
}
$components = wp_parse_args( $components, array(
'subject' => '',
'sender' => '',
'recipient' => '',
'additional_headers' => '',
'body' => '',
'attachments' => '',
) );
$callback = array( $this, 'replace_mail_tags_with_minimum_input' );
$subject = $components['subject'];
$subject = new WPCF7_MailTaggedText( $subject,
array( 'callback' => $callback ) );
$subject = $subject->replace_tags();
$subject = wpcf7_strip_newline( $subject );
$this->detect_maybe_empty( sprintf( '%s.subject', $template ), $subject );
$sender = $components['sender'];
$sender = new WPCF7_MailTaggedText( $sender,
array( 'callback' => $callback ) );
$sender = $sender->replace_tags();
$sender = wpcf7_strip_newline( $sender );
if ( ! $this->detect_invalid_mailbox_syntax( sprintf( '%s.sender', $template ), $sender )
and ! wpcf7_is_email_in_site_domain( $sender ) ) {
$this->add_error( sprintf( '%s.sender', $template ),
self::error_email_not_in_site_domain, array(
'link' => self::get_doc_link( 'email_not_in_site_domain' ),
)
);
}
$recipient = $components['recipient'];
$recipient = new WPCF7_MailTaggedText( $recipient,
array( 'callback' => $callback ) );
$recipient = $recipient->replace_tags();
$recipient = wpcf7_strip_newline( $recipient );
$this->detect_invalid_mailbox_syntax(
sprintf( '%s.recipient', $template ), $recipient );
$additional_headers = $components['additional_headers'];
$additional_headers = new WPCF7_MailTaggedText( $additional_headers,
array( 'callback' => $callback ) );
$additional_headers = $additional_headers->replace_tags();
$additional_headers = explode( "\n", $additional_headers );
$mailbox_header_types = array( 'reply-to', 'cc', 'bcc' );
$invalid_mail_header_exists = false;
foreach ( $additional_headers as $header ) {
$header = trim( $header );
if ( '' === $header ) {
continue;
}
if ( ! preg_match( '/^([0-9A-Za-z-]+):(.*)$/', $header, $matches ) ) {
$invalid_mail_header_exists = true;
} else {
$header_name = $matches[1];
$header_value = trim( $matches[2] );
if ( in_array( strtolower( $header_name ), $mailbox_header_types ) ) {
$this->detect_invalid_mailbox_syntax(
sprintf( '%s.additional_headers', $template ),
$header_value, array(
'message' =>
__( "Invalid mailbox syntax is used in the %name% field.", 'contact-form-7' ),
'params' => array( 'name' => $header_name ) ) );
} elseif ( empty( $header_value ) ) {
$invalid_mail_header_exists = true;
}
}
}
if ( $invalid_mail_header_exists ) {
$this->add_error( sprintf( '%s.additional_headers', $template ),
self::error_invalid_mail_header, array(
'link' => self::get_doc_link( 'invalid_mail_header' ),
)
);
}
$body = $components['body'];
$body = new WPCF7_MailTaggedText( $body,
array( 'callback' => $callback ) );
$body = $body->replace_tags();
$this->detect_maybe_empty( sprintf( '%s.body', $template ), $body );
if ( '' !== $components['attachments'] ) {
$has_file_not_found = false;
$has_file_not_in_content_dir = false;
foreach ( explode( "\n", $components['attachments'] ) as $line ) {
$line = trim( $line );
if ( '' === $line
or '[' == substr( $line, 0, 1 ) ) {
continue;
}
$has_file_not_found = $this->detect_file_not_found(
sprintf( '%s.attachments', $template ), $line
);
if ( ! $has_file_not_found
and ! $has_file_not_in_content_dir ) {
$has_file_not_in_content_dir = $this->detect_file_not_in_content_dir(
sprintf( '%s.attachments', $template ), $line
);
}
}
}
}
public function detect_invalid_mailbox_syntax( $section, $content, $args = '' ) {
$args = wp_parse_args( $args, array(
'link' => self::get_doc_link( 'invalid_mailbox_syntax' ),
'message' => '',
'params' => array(),
) );
if ( ! wpcf7_is_mailbox_list( $content ) ) {
return $this->add_error( $section,
self::error_invalid_mailbox_syntax, $args );
}
return false;
}
public function detect_maybe_empty( $section, $content ) {
if ( '' === $content ) {
return $this->add_error( $section,
self::error_maybe_empty, array(
'link' => self::get_doc_link( 'maybe_empty' ),
)
);
}
return false;
}
public function detect_file_not_found( $section, $content ) {
$path = path_join( WP_CONTENT_DIR, $content );
if ( ! is_readable( $path )
or ! is_file( $path ) ) {
return $this->add_error( $section,
self::error_file_not_found,
array(
'message' =>
__( "Attachment file does not exist at %path%.", 'contact-form-7' ),
'params' => array( 'path' => $content ),
'link' => self::get_doc_link( 'file_not_found' ),
)
);
}
return false;
}
public function detect_file_not_in_content_dir( $section, $content ) {
$path = path_join( WP_CONTENT_DIR, $content );
if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
return $this->add_error( $section,
self::error_file_not_in_content_dir,
array(
'message' =>
__( "It is not allowed to use files outside the wp-content directory.", 'contact-form-7' ),
'link' => self::get_doc_link( 'file_not_in_content_dir' ),
)
);
}
return false;
}
public function validate_messages() {
$messages = (array) $this->contact_form->prop( 'messages' );
if ( ! $messages ) {
return;
}
if ( isset( $messages['captcha_not_match'] )
and ! wpcf7_use_really_simple_captcha() ) {
unset( $messages['captcha_not_match'] );
}
foreach ( $messages as $key => $message ) {
$section = sprintf( 'messages.%s', $key );
$this->detect_html_in_message( $section, $message );
}
}
public function detect_html_in_message( $section, $content ) {
$stripped = wp_strip_all_tags( $content );
if ( $stripped != $content ) {
return $this->add_error( $section,
self::error_html_in_message,
array(
'link' => self::get_doc_link( 'html_in_message' ),
)
);
}
return false;
}
public function validate_additional_settings() {
$deprecated_settings_used =
$this->contact_form->additional_setting( 'on_sent_ok' ) ||
$this->contact_form->additional_setting( 'on_submit' );
if ( $deprecated_settings_used ) {
return $this->add_error( 'additional_settings.body',
self::error_deprecated_settings,
array(
'link' => self::get_doc_link( 'deprecated_settings' ),
)
);
}
}
}

View File

@ -0,0 +1,268 @@
<?php
function wpcf7_contact_form( $id ) {
return WPCF7_ContactForm::get_instance( $id );
}
function wpcf7_get_contact_form_by_old_id( $old_id ) {
global $wpdb;
$q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
. $wpdb->prepare( " AND meta_value = %d", $old_id );
if ( $new_id = $wpdb->get_var( $q ) ) {
return wpcf7_contact_form( $new_id );
}
}
function wpcf7_get_contact_form_by_title( $title ) {
$page = get_page_by_title( $title, OBJECT, WPCF7_ContactForm::post_type );
if ( $page ) {
return wpcf7_contact_form( $page->ID );
}
return null;
}
function wpcf7_get_current_contact_form() {
if ( $current = WPCF7_ContactForm::get_current() ) {
return $current;
}
}
function wpcf7_is_posted() {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return false;
}
return $contact_form->is_posted();
}
function wpcf7_get_hangover( $name, $default = null ) {
if ( ! wpcf7_is_posted() ) {
return $default;
}
$submission = WPCF7_Submission::get_instance();
if ( ! $submission
or $submission->is( 'mail_sent' ) ) {
return $default;
}
return isset( $_POST[$name] ) ? wp_unslash( $_POST[$name] ) : $default;
}
function wpcf7_get_validation_error( $name ) {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return '';
}
return $contact_form->validation_error( $name );
}
function wpcf7_get_message( $status ) {
if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
return '';
}
return $contact_form->message( $status );
}
function wpcf7_form_controls_class( $type, $default = '' ) {
$type = trim( $type );
$default = array_filter( explode( ' ', $default ) );
$classes = array_merge( array( 'wpcf7-form-control' ), $default );
$typebase = rtrim( $type, '*' );
$required = ( '*' == substr( $type, -1 ) );
$classes[] = 'wpcf7-' . $typebase;
if ( $required ) {
$classes[] = 'wpcf7-validates-as-required';
}
$classes = array_unique( $classes );
return implode( ' ', $classes );
}
function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
if ( is_feed() ) {
return '[contact-form-7]';
}
if ( 'contact-form-7' == $code ) {
$atts = shortcode_atts(
array(
'id' => 0,
'title' => '',
'html_id' => '',
'html_name' => '',
'html_class' => '',
'output' => 'form',
),
$atts, 'wpcf7'
);
$id = (int) $atts['id'];
$title = trim( $atts['title'] );
if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
$contact_form = wpcf7_get_contact_form_by_title( $title );
}
} else {
if ( is_string( $atts ) ) {
$atts = explode( ' ', $atts, 2 );
}
$id = (int) array_shift( $atts );
$contact_form = wpcf7_get_contact_form_by_old_id( $id );
}
if ( ! $contact_form ) {
return '[contact-form-7 404 "Not Found"]';
}
return $contact_form->form_html( $atts );
}
function wpcf7_save_contact_form( $args = '', $context = 'save' ) {
$args = wp_parse_args( $args, array(
'id' => -1,
'title' => null,
'locale' => null,
'form' => null,
'mail' => null,
'mail_2' => null,
'messages' => null,
'additional_settings' => null,
) );
$args['id'] = (int) $args['id'];
if ( -1 == $args['id'] ) {
$contact_form = WPCF7_ContactForm::get_template();
} else {
$contact_form = wpcf7_contact_form( $args['id'] );
}
if ( empty( $contact_form ) ) {
return false;
}
if ( null !== $args['title'] ) {
$contact_form->set_title( $args['title'] );
}
if ( null !== $args['locale'] ) {
$contact_form->set_locale( $args['locale'] );
}
$properties = $contact_form->get_properties();
$properties['form'] = wpcf7_sanitize_form(
$args['form'], $properties['form'] );
$properties['mail'] = wpcf7_sanitize_mail(
$args['mail'], $properties['mail'] );
$properties['mail']['active'] = true;
$properties['mail_2'] = wpcf7_sanitize_mail(
$args['mail_2'], $properties['mail_2'] );
$properties['messages'] = wpcf7_sanitize_messages(
$args['messages'], $properties['messages'] );
$properties['additional_settings'] = wpcf7_sanitize_additional_settings(
$args['additional_settings'], $properties['additional_settings'] );
$contact_form->set_properties( $properties );
do_action( 'wpcf7_save_contact_form', $contact_form, $args, $context );
if ( 'save' == $context ) {
$contact_form->save();
}
return $contact_form;
}
function wpcf7_sanitize_form( $input, $default = '' ) {
if ( null === $input ) {
return $default;
}
$output = trim( $input );
return $output;
}
function wpcf7_sanitize_mail( $input, $defaults = array() ) {
$defaults = wp_parse_args( $defaults, array(
'active' => false,
'subject' => '',
'sender' => '',
'recipient' => '',
'body' => '',
'additional_headers' => '',
'attachments' => '',
'use_html' => false,
'exclude_blank' => false,
) );
$input = wp_parse_args( $input, $defaults );
$output = array();
$output['active'] = (bool) $input['active'];
$output['subject'] = trim( $input['subject'] );
$output['sender'] = trim( $input['sender'] );
$output['recipient'] = trim( $input['recipient'] );
$output['body'] = trim( $input['body'] );
$output['additional_headers'] = '';
$headers = str_replace( "\r\n", "\n", $input['additional_headers'] );
$headers = explode( "\n", $headers );
foreach ( $headers as $header ) {
$header = trim( $header );
if ( '' !== $header ) {
$output['additional_headers'] .= $header . "\n";
}
}
$output['additional_headers'] = trim( $output['additional_headers'] );
$output['attachments'] = trim( $input['attachments'] );
$output['use_html'] = (bool) $input['use_html'];
$output['exclude_blank'] = (bool) $input['exclude_blank'];
return $output;
}
function wpcf7_sanitize_messages( $input, $defaults = array() ) {
$output = array();
foreach ( wpcf7_messages() as $key => $val ) {
if ( isset( $input[$key] ) ) {
$output[$key] = trim( $input[$key] );
} elseif ( isset( $defaults[$key] ) ) {
$output[$key] = $defaults[$key];
}
}
return $output;
}
function wpcf7_sanitize_additional_settings( $input, $default = '' ) {
if ( null === $input ) {
return $default;
}
$output = trim( $input );
return $output;
}

View File

@ -0,0 +1,201 @@
<?php
class WPCF7_ContactFormTemplate {
public static function get_default( $prop = 'form' ) {
if ( 'form' == $prop ) {
$template = self::form();
} elseif ( 'mail' == $prop ) {
$template = self::mail();
} elseif ( 'mail_2' == $prop ) {
$template = self::mail_2();
} elseif ( 'messages' == $prop ) {
$template = self::messages();
} else {
$template = null;
}
return apply_filters( 'wpcf7_default_template', $template, $prop );
}
public static function form() {
$template = sprintf(
'
<label> %2$s %1$s
[text* your-name] </label>
<label> %3$s %1$s
[email* your-email] </label>
<label> %4$s
[text your-subject] </label>
<label> %5$s
[textarea your-message] </label>
[submit "%6$s"]',
__( '(required)', 'contact-form-7' ),
__( 'Your Name', 'contact-form-7' ),
__( 'Your Email', 'contact-form-7' ),
__( 'Subject', 'contact-form-7' ),
__( 'Your Message', 'contact-form-7' ),
__( 'Send', 'contact-form-7' ) );
return trim( $template );
}
public static function mail() {
$template = array(
'subject' =>
/* translators: 1: blog name, 2: [your-subject] */
sprintf(
_x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
get_bloginfo( 'name' ), '[your-subject]' ),
'sender' => sprintf( '%s <%s>',
get_bloginfo( 'name' ), self::from_email() ),
'body' =>
/* translators: %s: [your-name] <[your-email]> */
sprintf( __( 'From: %s', 'contact-form-7' ),
'[your-name] <[your-email]>' ) . "\n"
/* translators: %s: [your-subject] */
. sprintf( __( 'Subject: %s', 'contact-form-7' ),
'[your-subject]' ) . "\n\n"
. __( 'Message Body:', 'contact-form-7' )
. "\n" . '[your-message]' . "\n\n"
. '-- ' . "\n"
/* translators: 1: blog name, 2: blog URL */
. sprintf(
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
get_bloginfo( 'name' ),
get_bloginfo( 'url' ) ),
'recipient' => get_option( 'admin_email' ),
'additional_headers' => 'Reply-To: [your-email]',
'attachments' => '',
'use_html' => 0,
'exclude_blank' => 0,
);
return $template;
}
public static function mail_2() {
$template = array(
'active' => false,
'subject' =>
/* translators: 1: blog name, 2: [your-subject] */
sprintf(
_x( '%1$s "%2$s"', 'mail subject', 'contact-form-7' ),
get_bloginfo( 'name' ), '[your-subject]' ),
'sender' => sprintf( '%s <%s>',
get_bloginfo( 'name' ), self::from_email() ),
'body' =>
__( 'Message Body:', 'contact-form-7' )
. "\n" . '[your-message]' . "\n\n"
. '-- ' . "\n"
/* translators: 1: blog name, 2: blog URL */
. sprintf(
__( 'This e-mail was sent from a contact form on %1$s (%2$s)', 'contact-form-7' ),
get_bloginfo( 'name' ),
get_bloginfo( 'url' ) ),
'recipient' => '[your-email]',
'additional_headers' => sprintf( 'Reply-To: %s',
get_option( 'admin_email' ) ),
'attachments' => '',
'use_html' => 0,
'exclude_blank' => 0,
);
return $template;
}
public static function from_email() {
$admin_email = get_option( 'admin_email' );
$sitename = strtolower( $_SERVER['SERVER_NAME'] );
if ( wpcf7_is_localhost() ) {
return $admin_email;
}
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
if ( strpbrk( $admin_email, '@' ) == '@' . $sitename ) {
return $admin_email;
}
return 'wordpress@' . $sitename;
}
public static function messages() {
$messages = array();
foreach ( wpcf7_messages() as $key => $arr ) {
$messages[$key] = $arr['default'];
}
return $messages;
}
}
function wpcf7_messages() {
$messages = array(
'mail_sent_ok' => array(
'description'
=> __( "Sender's message was sent successfully", 'contact-form-7' ),
'default'
=> __( "Thank you for your message. It has been sent.", 'contact-form-7' ),
),
'mail_sent_ng' => array(
'description'
=> __( "Sender's message failed to send", 'contact-form-7' ),
'default'
=> __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
),
'validation_error' => array(
'description'
=> __( "Validation errors occurred", 'contact-form-7' ),
'default'
=> __( "One or more fields have an error. Please check and try again.", 'contact-form-7' ),
),
'spam' => array(
'description'
=> __( "Submission was referred to as spam", 'contact-form-7' ),
'default'
=> __( "There was an error trying to send your message. Please try again later.", 'contact-form-7' ),
),
'accept_terms' => array(
'description'
=> __( "There are terms that the sender must accept", 'contact-form-7' ),
'default'
=> __( "You must accept the terms and conditions before sending your message.", 'contact-form-7' ),
),
'invalid_required' => array(
'description'
=> __( "There is a field that the sender must fill in", 'contact-form-7' ),
'default'
=> __( "The field is required.", 'contact-form-7' ),
),
'invalid_too_long' => array(
'description'
=> __( "There is a field with input that is longer than the maximum allowed length", 'contact-form-7' ),
'default'
=> __( "The field is too long.", 'contact-form-7' ),
),
'invalid_too_short' => array(
'description'
=> __( "There is a field with input that is shorter than the minimum allowed length", 'contact-form-7' ),
'default'
=> __( "The field is too short.", 'contact-form-7' ),
)
);
return apply_filters( 'wpcf7_messages', $messages );
}

View File

@ -0,0 +1,935 @@
<?php
class WPCF7_ContactForm {
const post_type = 'wpcf7_contact_form';
private static $found_items = 0;
private static $current = null;
private $id;
private $name;
private $title;
private $locale;
private $properties = array();
private $unit_tag;
private $responses_count = 0;
private $scanned_form_tags;
private $shortcode_atts = array();
public static function count() {
return self::$found_items;
}
public static function get_current() {
return self::$current;
}
public static function register_post_type() {
register_post_type( self::post_type, array(
'labels' => array(
'name' => __( 'Contact Forms', 'contact-form-7' ),
'singular_name' => __( 'Contact Form', 'contact-form-7' ),
),
'rewrite' => false,
'query_var' => false,
'public' => false,
'capability_type' => 'page',
'capabilities' => array(
'edit_post' => 'wpcf7_edit_contact_form',
'read_post' => 'wpcf7_read_contact_form',
'delete_post' => 'wpcf7_delete_contact_form',
'edit_posts' => 'wpcf7_edit_contact_forms',
'edit_others_posts' => 'wpcf7_edit_contact_forms',
'publish_posts' => 'wpcf7_edit_contact_forms',
'read_private_posts' => 'wpcf7_edit_contact_forms',
),
) );
}
public static function find( $args = '' ) {
$defaults = array(
'post_status' => 'any',
'posts_per_page' => -1,
'offset' => 0,
'orderby' => 'ID',
'order' => 'ASC',
);
$args = wp_parse_args( $args, $defaults );
$args['post_type'] = self::post_type;
$q = new WP_Query();
$posts = $q->query( $args );
self::$found_items = $q->found_posts;
$objs = array();
foreach ( (array) $posts as $post ) {
$objs[] = new self( $post );
}
return $objs;
}
public static function get_template( $args = '' ) {
global $l10n;
$defaults = array( 'locale' => null, 'title' => '' );
$args = wp_parse_args( $args, $defaults );
$locale = $args['locale'];
$title = $args['title'];
if ( $locale ) {
$mo_orig = $l10n['contact-form-7'];
wpcf7_load_textdomain( $locale );
}
self::$current = $contact_form = new self;
$contact_form->title =
( $title ? $title : __( 'Untitled', 'contact-form-7' ) );
$contact_form->locale = ( $locale ? $locale : get_user_locale() );
$properties = $contact_form->get_properties();
foreach ( $properties as $key => $value ) {
$properties[$key] = WPCF7_ContactFormTemplate::get_default( $key );
}
$contact_form->properties = $properties;
$contact_form = apply_filters( 'wpcf7_contact_form_default_pack',
$contact_form, $args );
if ( isset( $mo_orig ) ) {
$l10n['contact-form-7'] = $mo_orig;
}
return $contact_form;
}
public static function get_instance( $post ) {
$post = get_post( $post );
if ( ! $post
or self::post_type != get_post_type( $post ) ) {
return false;
}
return self::$current = new self( $post );
}
private static function get_unit_tag( $id = 0 ) {
static $global_count = 0;
$global_count += 1;
if ( in_the_loop() ) {
$unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d',
absint( $id ), get_the_ID(), $global_count );
} else {
$unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d',
absint( $id ), $global_count );
}
return $unit_tag;
}
private function __construct( $post = null ) {
$post = get_post( $post );
if ( $post
and self::post_type == get_post_type( $post ) ) {
$this->id = $post->ID;
$this->name = $post->post_name;
$this->title = $post->post_title;
$this->locale = get_post_meta( $post->ID, '_locale', true );
$properties = $this->get_properties();
foreach ( $properties as $key => $value ) {
if ( metadata_exists( 'post', $post->ID, '_' . $key ) ) {
$properties[$key] = get_post_meta( $post->ID, '_' . $key, true );
} elseif ( metadata_exists( 'post', $post->ID, $key ) ) {
$properties[$key] = get_post_meta( $post->ID, $key, true );
}
}
$this->properties = $properties;
$this->upgrade();
}
do_action( 'wpcf7_contact_form', $this );
}
public function __get( $name ) {
$message = __( '<code>%1$s</code> property of a <code>WPCF7_ContactForm</code> object is <strong>no longer accessible</strong>. Use <code>%2$s</code> method instead.', 'contact-form-7' );
if ( 'id' == $name ) {
if ( WP_DEBUG ) {
trigger_error( sprintf( $message, 'id', 'id()' ) );
}
return $this->id;
} elseif ( 'title' == $name ) {
if ( WP_DEBUG ) {
trigger_error( sprintf( $message, 'title', 'title()' ) );
}
return $this->title;
} elseif ( $prop = $this->prop( $name ) ) {
if ( WP_DEBUG ) {
trigger_error(
sprintf( $message, $name, 'prop(\'' . $name . '\')' ) );
}
return $prop;
}
}
public function initial() {
return empty( $this->id );
}
public function prop( $name ) {
$props = $this->get_properties();
return isset( $props[$name] ) ? $props[$name] : null;
}
public function get_properties() {
$properties = (array) $this->properties;
$properties = wp_parse_args( $properties, array(
'form' => '',
'mail' => array(),
'mail_2' => array(),
'messages' => array(),
'additional_settings' => '',
) );
$properties = (array) apply_filters( 'wpcf7_contact_form_properties',
$properties, $this );
return $properties;
}
public function set_properties( $properties ) {
$defaults = $this->get_properties();
$properties = wp_parse_args( $properties, $defaults );
$properties = array_intersect_key( $properties, $defaults );
$this->properties = $properties;
}
public function id() {
return $this->id;
}
public function name() {
return $this->name;
}
public function title() {
return $this->title;
}
public function set_title( $title ) {
$title = strip_tags( $title );
$title = trim( $title );
if ( '' === $title ) {
$title = __( 'Untitled', 'contact-form-7' );
}
$this->title = $title;
}
public function locale() {
if ( wpcf7_is_valid_locale( $this->locale ) ) {
return $this->locale;
} else {
return '';
}
}
public function set_locale( $locale ) {
$locale = trim( $locale );
if ( wpcf7_is_valid_locale( $locale ) ) {
$this->locale = $locale;
} else {
$this->locale = 'en_US';
}
}
public function shortcode_attr( $name ) {
if ( isset( $this->shortcode_atts[$name] ) ) {
return (string) $this->shortcode_atts[$name];
}
}
// Return true if this form is the same one as currently POSTed.
public function is_posted() {
if ( ! WPCF7_Submission::get_instance() ) {
return false;
}
if ( empty( $_POST['_wpcf7_unit_tag'] ) ) {
return false;
}
return $this->unit_tag == $_POST['_wpcf7_unit_tag'];
}
/* Generating Form HTML */
public function form_html( $args = '' ) {
$args = wp_parse_args( $args, array(
'html_id' => '',
'html_name' => '',
'html_class' => '',
'output' => 'form',
) );
$this->shortcode_atts = $args;
if ( 'raw_form' == $args['output'] ) {
return '<pre class="wpcf7-raw-form"><code>'
. esc_html( $this->prop( 'form' ) ) . '</code></pre>';
}
if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
$notice = __(
"This contact form is available only for logged in users.",
'contact-form-7' );
$notice = sprintf(
'<p class="wpcf7-subscribers-only">%s</p>',
esc_html( $notice ) );
return apply_filters( 'wpcf7_subscribers_only_notice', $notice, $this );
}
$this->unit_tag = self::get_unit_tag( $this->id );
$lang_tag = str_replace( '_', '-', $this->locale );
if ( preg_match( '/^([a-z]+-[a-z]+)-/i', $lang_tag, $matches ) ) {
$lang_tag = $matches[1];
}
$html = sprintf( '<div %s>',
wpcf7_format_atts( array(
'role' => 'form',
'class' => 'wpcf7',
'id' => $this->unit_tag,
( get_option( 'html_type' ) == 'text/html' ) ? 'lang' : 'xml:lang'
=> $lang_tag,
'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
) )
);
$html .= "\n" . $this->screen_reader_response() . "\n";
$url = wpcf7_get_request_uri();
if ( $frag = strstr( $url, '#' ) ) {
$url = substr( $url, 0, -strlen( $frag ) );
}
$url .= '#' . $this->unit_tag;
$url = apply_filters( 'wpcf7_form_action_url', $url );
$id_attr = apply_filters( 'wpcf7_form_id_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_id'] ) );
$name_attr = apply_filters( 'wpcf7_form_name_attr',
preg_replace( '/[^A-Za-z0-9:._-]/', '', $args['html_name'] ) );
$class = 'wpcf7-form';
if ( $this->is_posted() ) {
$submission = WPCF7_Submission::get_instance();
switch ( $submission->get_status() ) {
case 'validation_failed':
$class .= ' invalid';
break;
case 'acceptance_missing':
$class .= ' unaccepted';
break;
case 'spam':
$class .= ' spam';
break;
case 'aborted':
$class .= ' aborted';
break;
case 'mail_sent':
$class .= ' sent';
break;
case 'mail_failed':
$class .= ' failed';
break;
default:
$class .= sprintf( ' custom-%s',
preg_replace( '/[^0-9a-z]+/i', '-', $submission->get_status() )
);
}
}
if ( $args['html_class'] ) {
$class .= ' ' . $args['html_class'];
}
if ( $this->in_demo_mode() ) {
$class .= ' demo';
}
$class = explode( ' ', $class );
$class = array_map( 'sanitize_html_class', $class );
$class = array_filter( $class );
$class = array_unique( $class );
$class = implode( ' ', $class );
$class = apply_filters( 'wpcf7_form_class_attr', $class );
$enctype = apply_filters( 'wpcf7_form_enctype', '' );
$autocomplete = apply_filters( 'wpcf7_form_autocomplete', '' );
$novalidate = apply_filters( 'wpcf7_form_novalidate',
wpcf7_support_html5() );
$atts = array(
'action' => esc_url( $url ),
'method' => 'post',
'class' => $class,
'enctype' => wpcf7_enctype_value( $enctype ),
'autocomplete' => $autocomplete,
'novalidate' => $novalidate ? 'novalidate' : '',
);
if ( '' !== $id_attr ) {
$atts['id'] = $id_attr;
}
if ( '' !== $name_attr ) {
$atts['name'] = $name_attr;
}
$atts = wpcf7_format_atts( $atts );
$html .= sprintf( '<form %s>', $atts ) . "\n";
$html .= $this->form_hidden_fields();
$html .= $this->form_elements();
if ( ! $this->responses_count ) {
$html .= $this->form_response_output();
}
$html .= '</form>';
$html .= '</div>';
return $html;
}
private function form_hidden_fields() {
$hidden_fields = array(
'_wpcf7' => $this->id(),
'_wpcf7_version' => WPCF7_VERSION,
'_wpcf7_locale' => $this->locale(),
'_wpcf7_unit_tag' => $this->unit_tag,
'_wpcf7_container_post' => 0,
);
if ( in_the_loop() ) {
$hidden_fields['_wpcf7_container_post'] = (int) get_the_ID();
}
if ( $this->nonce_is_active() ) {
$hidden_fields['_wpnonce'] = wpcf7_create_nonce();
}
$hidden_fields += (array) apply_filters(
'wpcf7_form_hidden_fields', array() );
$content = '';
foreach ( $hidden_fields as $name => $value ) {
$content .= sprintf(
'<input type="hidden" name="%1$s" value="%2$s" />',
esc_attr( $name ), esc_attr( $value ) ) . "\n";
}
return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
}
public function form_response_output() {
$class = 'wpcf7-response-output';
$role = '';
$content = '';
if ( $this->is_posted() ) { // Post response output for non-AJAX
$role = 'alert';
$submission = WPCF7_Submission::get_instance();
$content = $submission->get_response();
switch ( $submission->get_status() ) {
case 'validation_failed':
$class .= ' wpcf7-validation-errors';
break;
case 'acceptance_missing':
$class .= ' wpcf7-acceptance-missing';
break;
case 'spam':
$class .= ' wpcf7-spam-blocked';
break;
case 'aborted':
$class .= ' wpcf7-aborted';
break;
case 'mail_sent':
$class .= ' wpcf7-mail-sent-ok';
break;
case 'mail_failed':
$class .= ' wpcf7-mail-sent-ng';
break;
default:
$class .= sprintf( ' wpcf7-custom-%s',
preg_replace( '/[^0-9a-z]+/i', '-', $submission->get_status() )
);
}
} else {
$class .= ' wpcf7-display-none';
}
$atts = array(
'class' => trim( $class ),
'role' => trim( $role ),
);
$atts = wpcf7_format_atts( $atts );
$output = sprintf( '<div %1$s>%2$s</div>',
$atts, esc_html( $content ) );
$output = apply_filters( 'wpcf7_form_response_output',
$output, $class, $content, $this );
$this->responses_count += 1;
return $output;
}
public function screen_reader_response() {
$class = 'screen-reader-response';
$role = '';
$content = '';
if ( $this->is_posted() ) { // Post response output for non-AJAX
$role = 'alert';
$submission = WPCF7_Submission::get_instance();
if ( $response = $submission->get_response() ) {
$content = esc_html( $response );
}
if ( $invalid_fields = $submission->get_invalid_fields() ) {
$content .= "\n" . '<ul>' . "\n";
foreach ( (array) $invalid_fields as $name => $field ) {
if ( $field['idref'] ) {
$link = sprintf( '<a href="#%1$s">%2$s</a>',
esc_attr( $field['idref'] ),
esc_html( $field['reason'] ) );
$content .= sprintf( '<li>%s</li>', $link );
} else {
$content .= sprintf( '<li>%s</li>',
esc_html( $field['reason'] ) );
}
$content .= "\n";
}
$content .= '</ul>' . "\n";
}
}
$atts = array(
'class' => trim( $class ),
'role' => trim( $role ) );
$atts = wpcf7_format_atts( $atts );
$output = sprintf( '<div %1$s>%2$s</div>',
$atts, $content );
return $output;
}
public function validation_error( $name ) {
$error = '';
if ( $this->is_posted() ) {
$submission = WPCF7_Submission::get_instance();
if ( $invalid_field = $submission->get_invalid_field( $name ) ) {
$error = trim( $invalid_field['reason'] );
}
}
if ( ! $error ) {
return $error;
}
$error = sprintf(
'<span role="alert" class="wpcf7-not-valid-tip">%s</span>',
esc_html( $error ) );
return apply_filters( 'wpcf7_validation_error', $error, $name, $this );
}
/* Form Elements */
public function replace_all_form_tags() {
$manager = WPCF7_FormTagsManager::get_instance();
$form = $this->prop( 'form' );
if ( wpcf7_autop_or_not() ) {
$form = $manager->normalize( $form );
$form = wpcf7_autop( $form );
}
$form = $manager->replace_all( $form );
$this->scanned_form_tags = $manager->get_scanned_tags();
return $form;
}
public function form_do_shortcode() {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_ContactForm::replace_all_form_tags' );
return $this->replace_all_form_tags();
}
public function scan_form_tags( $cond = null ) {
$manager = WPCF7_FormTagsManager::get_instance();
if ( empty( $this->scanned_form_tags ) ) {
$this->scanned_form_tags = $manager->scan( $this->prop( 'form' ) );
}
$tags = $this->scanned_form_tags;
return $manager->filter( $tags, $cond );
}
public function form_scan_shortcode( $cond = null ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_ContactForm::scan_form_tags' );
return $this->scan_form_tags( $cond );
}
public function form_elements() {
return apply_filters( 'wpcf7_form_elements',
$this->replace_all_form_tags() );
}
public function collect_mail_tags( $args = '' ) {
$manager = WPCF7_FormTagsManager::get_instance();
$args = wp_parse_args( $args, array(
'include' => array(),
'exclude' => $manager->collect_tag_types( 'not-for-mail' ),
) );
$tags = $this->scan_form_tags();
$mailtags = array();
foreach ( (array) $tags as $tag ) {
$type = $tag->basetype;
if ( empty( $type ) ) {
continue;
} elseif ( ! empty( $args['include'] ) ) {
if ( ! in_array( $type, $args['include'] ) ) {
continue;
}
} elseif ( ! empty( $args['exclude'] ) ) {
if ( in_array( $type, $args['exclude'] ) ) {
continue;
}
}
$mailtags[] = $tag->name;
}
$mailtags = array_unique( array_filter( $mailtags ) );
return apply_filters( 'wpcf7_collect_mail_tags', $mailtags, $args, $this );
}
public function suggest_mail_tags( $for = 'mail' ) {
$mail = wp_parse_args( $this->prop( $for ),
array(
'active' => false,
'recipient' => '',
'sender' => '',
'subject' => '',
'body' => '',
'additional_headers' => '',
'attachments' => '',
'use_html' => false,
'exclude_blank' => false,
)
);
$mail = array_filter( $mail );
foreach ( (array) $this->collect_mail_tags() as $mail_tag ) {
$pattern = sprintf( '/\[(_[a-z]+_)?%s([ \t]+[^]]+)?\]/',
preg_quote( $mail_tag, '/' ) );
$used = preg_grep( $pattern, $mail );
echo sprintf(
'<span class="%1$s">[%2$s]</span>',
'mailtag code ' . ( $used ? 'used' : 'unused' ),
esc_html( $mail_tag ) );
}
}
public function submit( $args = '' ) {
$args = wp_parse_args( $args, array(
'skip_mail' =>
( $this->in_demo_mode()
|| $this->is_true( 'skip_mail' )
|| ! empty( $this->skip_mail ) ),
) );
if ( $this->is_true( 'subscribers_only' )
and ! current_user_can( 'wpcf7_submit', $this->id() ) ) {
$result = array(
'contact_form_id' => $this->id(),
'status' => 'error',
'message' => __(
"This contact form is available only for logged in users.",
'contact-form-7' ),
);
return $result;
}
$submission = WPCF7_Submission::get_instance( $this, array(
'skip_mail' => $args['skip_mail'],
) );
$result = array(
'contact_form_id' => $this->id(),
'status' => $submission->get_status(),
'message' => $submission->get_response(),
'demo_mode' => $this->in_demo_mode(),
);
if ( $submission->is( 'validation_failed' ) ) {
$result['invalid_fields'] = $submission->get_invalid_fields();
}
do_action( 'wpcf7_submit', $this, $result );
return $result;
}
/* Message */
public function message( $status, $filter = true ) {
$messages = $this->prop( 'messages' );
$message = isset( $messages[$status] ) ? $messages[$status] : '';
if ( $filter ) {
$message = $this->filter_message( $message, $status );
}
return $message;
}
public function filter_message( $message, $status = '' ) {
$message = wp_strip_all_tags( $message );
$message = wpcf7_mail_replace_tags( $message, array( 'html' => true ) );
$message = apply_filters( 'wpcf7_display_message', $message, $status );
return $message;
}
/* Additional settings */
public function additional_setting( $name, $max = 1 ) {
$settings = (array) explode( "\n", $this->prop( 'additional_settings' ) );
$pattern = '/^([a-zA-Z0-9_]+)[\t ]*:(.*)$/';
$count = 0;
$values = array();
foreach ( $settings as $setting ) {
if ( preg_match( $pattern, $setting, $matches ) ) {
if ( $matches[1] != $name ) {
continue;
}
if ( ! $max or $count < (int) $max ) {
$values[] = trim( $matches[2] );
$count += 1;
}
}
}
return $values;
}
public function is_true( $name ) {
$settings = $this->additional_setting( $name, false );
foreach ( $settings as $setting ) {
if ( in_array( $setting, array( 'on', 'true', '1' ) ) ) {
return true;
}
}
return false;
}
public function in_demo_mode() {
return $this->is_true( 'demo_mode' );
}
public function nonce_is_active() {
$is_active = WPCF7_VERIFY_NONCE;
if ( $this->is_true( 'subscribers_only' ) ) {
$is_active = true;
}
return (bool) apply_filters( 'wpcf7_verify_nonce', $is_active, $this );
}
/* Upgrade */
private function upgrade() {
$mail = $this->prop( 'mail' );
if ( is_array( $mail )
and ! isset( $mail['recipient'] ) ) {
$mail['recipient'] = get_option( 'admin_email' );
}
$this->properties['mail'] = $mail;
$messages = $this->prop( 'messages' );
if ( is_array( $messages ) ) {
foreach ( wpcf7_messages() as $key => $arr ) {
if ( ! isset( $messages[$key] ) ) {
$messages[$key] = $arr['default'];
}
}
}
$this->properties['messages'] = $messages;
}
/* Save */
public function save() {
$props = $this->get_properties();
$post_content = implode( "\n", wpcf7_array_flatten( $props ) );
if ( $this->initial() ) {
$post_id = wp_insert_post( array(
'post_type' => self::post_type,
'post_status' => 'publish',
'post_title' => $this->title,
'post_content' => trim( $post_content ),
) );
} else {
$post_id = wp_update_post( array(
'ID' => (int) $this->id,
'post_status' => 'publish',
'post_title' => $this->title,
'post_content' => trim( $post_content ),
) );
}
if ( $post_id ) {
foreach ( $props as $prop => $value ) {
update_post_meta( $post_id, '_' . $prop,
wpcf7_normalize_newline_deep( $value ) );
}
if ( wpcf7_is_valid_locale( $this->locale ) ) {
update_post_meta( $post_id, '_locale', $this->locale );
}
if ( $this->initial() ) {
$this->id = $post_id;
do_action( 'wpcf7_after_create', $this );
} else {
do_action( 'wpcf7_after_update', $this );
}
do_action( 'wpcf7_after_save', $this );
}
return $post_id;
}
public function copy() {
$new = new self;
$new->title = $this->title . '_copy';
$new->locale = $this->locale;
$new->properties = $this->properties;
return apply_filters( 'wpcf7_copy', $new, $this );
}
public function delete() {
if ( $this->initial() ) {
return;
}
if ( wp_delete_post( $this->id, true ) ) {
$this->id = 0;
return true;
}
return false;
}
public function shortcode( $args = '' ) {
$args = wp_parse_args( $args, array(
'use_old_format' => false ) );
$title = str_replace( array( '"', '[', ']' ), '', $this->title );
if ( $args['use_old_format'] ) {
$old_unit_id = (int) get_post_meta( $this->id, '_old_cf7_unit_id', true );
if ( $old_unit_id ) {
$shortcode = sprintf( '[contact-form %1$d "%2$s"]', $old_unit_id, $title );
} else {
$shortcode = '';
}
} else {
$shortcode = sprintf( '[contact-form-7 id="%1$d" title="%2$s"]',
$this->id, $title );
}
return apply_filters( 'wpcf7_contact_form_shortcode',
$shortcode, $args, $this );
}
}

View File

@ -0,0 +1,104 @@
<?php
add_action( 'parse_request', 'wpcf7_control_init', 20, 0 );
function wpcf7_control_init() {
if ( WPCF7_Submission::is_restful() ) {
return;
}
if ( isset( $_POST['_wpcf7'] ) ) {
$contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] );
if ( $contact_form ) {
$contact_form->submit();
}
}
}
add_action( 'wp_enqueue_scripts', 'wpcf7_do_enqueue_scripts', 10, 0 );
function wpcf7_do_enqueue_scripts() {
if ( wpcf7_load_js() ) {
wpcf7_enqueue_scripts();
}
if ( wpcf7_load_css() ) {
wpcf7_enqueue_styles();
}
}
function wpcf7_enqueue_scripts() {
$in_footer = true;
if ( 'header' === wpcf7_load_js() ) {
$in_footer = false;
}
wp_enqueue_script( 'contact-form-7',
wpcf7_plugin_url( 'includes/js/scripts.js' ),
array( 'jquery' ), WPCF7_VERSION, $in_footer );
$wpcf7 = array(
'apiSettings' => array(
'root' => esc_url_raw( rest_url( 'contact-form-7/v1' ) ),
'namespace' => 'contact-form-7/v1',
),
);
if ( defined( 'WP_CACHE' ) and WP_CACHE ) {
$wpcf7['cached'] = 1;
}
if ( wpcf7_support_html5_fallback() ) {
$wpcf7['jqueryUi'] = 1;
}
wp_localize_script( 'contact-form-7', 'wpcf7', $wpcf7 );
do_action( 'wpcf7_enqueue_scripts' );
}
function wpcf7_script_is() {
return wp_script_is( 'contact-form-7' );
}
function wpcf7_enqueue_styles() {
wp_enqueue_style( 'contact-form-7',
wpcf7_plugin_url( 'includes/css/styles.css' ),
array(), WPCF7_VERSION, 'all' );
if ( wpcf7_is_rtl() ) {
wp_enqueue_style( 'contact-form-7-rtl',
wpcf7_plugin_url( 'includes/css/styles-rtl.css' ),
array(), WPCF7_VERSION, 'all' );
}
do_action( 'wpcf7_enqueue_styles' );
}
function wpcf7_style_is() {
return wp_style_is( 'contact-form-7' );
}
/* HTML5 Fallback */
add_action( 'wp_enqueue_scripts', 'wpcf7_html5_fallback', 20, 0 );
function wpcf7_html5_fallback() {
if ( ! wpcf7_support_html5_fallback() ) {
return;
}
if ( wpcf7_script_is() ) {
wp_enqueue_script( 'jquery-ui-datepicker' );
wp_enqueue_script( 'jquery-ui-spinner' );
}
if ( wpcf7_style_is() ) {
wp_enqueue_style( 'jquery-ui-smoothness',
wpcf7_plugin_url(
'includes/js/jquery-ui/themes/smoothness/jquery-ui.min.css' ),
array(), '1.11.4', 'screen' );
}
}

View File

@ -0,0 +1,12 @@
span.wpcf7-not-valid-tip {
direction: rtl;
}
.use-floating-validation-tip span.wpcf7-not-valid-tip {
left: auto;
right: 20%;
}
span.wpcf7-list-item {
margin: 0 1em 0 0;
}

View File

@ -0,0 +1,110 @@
div.wpcf7 {
margin: 0;
padding: 0;
}
div.wpcf7 .screen-reader-response {
position: absolute;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
height: 1px;
width: 1px;
margin: 0;
padding: 0;
border: 0;
}
div.wpcf7-response-output {
margin: 2em 0.5em 1em;
padding: 0.2em 1em;
border: 2px solid #ff0000;
}
div.wpcf7-mail-sent-ok {
border: 2px solid #398f14;
}
div.wpcf7-mail-sent-ng,
div.wpcf7-aborted {
border: 2px solid #ff0000;
}
div.wpcf7-spam-blocked {
border: 2px solid #ffa500;
}
div.wpcf7-validation-errors,
div.wpcf7-acceptance-missing {
border: 2px solid #f7e700;
}
.wpcf7-form-control-wrap {
position: relative;
}
span.wpcf7-not-valid-tip {
color: #f00;
font-size: 1em;
font-weight: normal;
display: block;
}
.use-floating-validation-tip span.wpcf7-not-valid-tip {
position: absolute;
top: 20%;
left: 20%;
z-index: 100;
border: 1px solid #ff0000;
background: #fff;
padding: .2em .8em;
}
span.wpcf7-list-item {
display: inline-block;
margin: 0 0 0 1em;
}
span.wpcf7-list-item-label::before,
span.wpcf7-list-item-label::after {
content: " ";
}
.wpcf7-display-none {
display: none;
}
div.wpcf7 .ajax-loader {
visibility: hidden;
display: inline-block;
background-image: url('../../images/ajax-loader.gif');
width: 16px;
height: 16px;
border: none;
padding: 0;
margin: 0 0 0 4px;
vertical-align: middle;
}
div.wpcf7 .ajax-loader.is-active {
visibility: visible;
}
div.wpcf7 div.ajax-error {
display: none;
}
div.wpcf7 .placeheld {
color: #888;
}
div.wpcf7 input[type="file"] {
cursor: pointer;
}
div.wpcf7 input[type="file"]:disabled {
cursor: default;
}
div.wpcf7 .wpcf7-submit:disabled {
cursor: not-allowed;
}

View File

@ -0,0 +1,367 @@
<?php
class WPCF7_FormTag implements ArrayAccess {
public $type;
public $basetype;
public $name = '';
public $options = array();
public $raw_values = array();
public $values = array();
public $pipes;
public $labels = array();
public $attr = '';
public $content = '';
public function __construct( $tag = array() ) {
if ( is_array( $tag )
or $tag instanceof self ) {
foreach ( $tag as $key => $value ) {
if ( property_exists( __CLASS__, $key ) ) {
$this->{$key} = $value;
}
}
}
}
public function is_required() {
return ( '*' == substr( $this->type, -1 ) );
}
public function has_option( $opt ) {
$pattern = sprintf( '/^%s(:.+)?$/i', preg_quote( $opt, '/' ) );
return (bool) preg_grep( $pattern, $this->options );
}
public function get_option( $opt, $pattern = '', $single = false ) {
$preset_patterns = array(
'date' => '([0-9]{4}-[0-9]{2}-[0-9]{2}|today(.*))',
'int' => '[0-9]+',
'signed_int' => '-?[0-9]+',
'class' => '[-0-9a-zA-Z_]+',
'id' => '[-0-9a-zA-Z_]+',
);
if ( isset( $preset_patterns[$pattern] ) ) {
$pattern = $preset_patterns[$pattern];
}
if ( '' == $pattern ) {
$pattern = '.+';
}
$pattern = sprintf( '/^%s:%s$/i', preg_quote( $opt, '/' ), $pattern );
if ( $single ) {
$matches = $this->get_first_match_option( $pattern );
if ( ! $matches ) {
return false;
}
return substr( $matches[0], strlen( $opt ) + 1 );
} else {
$matches_a = $this->get_all_match_options( $pattern );
if ( ! $matches_a ) {
return false;
}
$results = array();
foreach ( $matches_a as $matches ) {
$results[] = substr( $matches[0], strlen( $opt ) + 1 );
}
return $results;
}
}
public function get_id_option() {
return $this->get_option( 'id', 'id', true );
}
public function get_class_option( $default = '' ) {
if ( is_string( $default ) ) {
$default = explode( ' ', $default );
}
$options = array_merge(
(array) $default,
(array) $this->get_option( 'class', 'class' ) );
$options = array_filter( array_unique( $options ) );
return implode( ' ', $options );
}
public function get_size_option( $default = '' ) {
$option = $this->get_option( 'size', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options( '%^([0-9]*)/[0-9]*$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] )
and '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_maxlength_option( $default = '' ) {
$option = $this->get_option( 'maxlength', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^(?:[0-9]*x?[0-9]*)?/([0-9]+)$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] ) && '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_minlength_option( $default = '' ) {
$option = $this->get_option( 'minlength', 'int', true );
if ( $option ) {
return $option;
} else {
return $default;
}
}
public function get_cols_option( $default = '' ) {
$option = $this->get_option( 'cols', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[1] ) && '' !== $matches[1] ) {
return $matches[1];
}
}
return $default;
}
public function get_rows_option( $default = '' ) {
$option = $this->get_option( 'rows', 'int', true );
if ( $option ) {
return $option;
}
$matches_a = $this->get_all_match_options(
'%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
foreach ( (array) $matches_a as $matches ) {
if ( isset( $matches[2] )
and '' !== $matches[2] ) {
return $matches[2];
}
}
return $default;
}
public function get_date_option( $opt ) {
$option = $this->get_option( $opt, 'date', true );
if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $option ) ) {
return $option;
}
if ( preg_match( '/^today(?:([+-][0-9]+)([a-z]*))?/', $option, $matches ) ) {
$number = isset( $matches[1] ) ? (int) $matches[1] : 0;
$unit = isset( $matches[2] ) ? $matches[2] : '';
if ( ! preg_match( '/^(day|month|year|week)s?$/', $unit ) ) {
$unit = 'days';
}
$date = gmdate( 'Y-m-d',
strtotime( sprintf( 'today %1$s %2$s', $number, $unit ) ) );
return $date;
}
return false;
}
public function get_default_option( $default = '', $args = '' ) {
$args = wp_parse_args( $args, array(
'multiple' => false,
'shifted' => false,
) );
$options = (array) $this->get_option( 'default' );
$values = array();
if ( empty( $options ) ) {
return $args['multiple'] ? $values : $default;
}
foreach ( $options as $opt ) {
$opt = sanitize_key( $opt );
if ( 'user_' == substr( $opt, 0, 5 )
and is_user_logged_in() ) {
$primary_props = array( 'user_login', 'user_email', 'user_url' );
$opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
$user = wp_get_current_user();
$user_prop = $user->get( $opt );
if ( ! empty( $user_prop ) ) {
if ( $args['multiple'] ) {
$values[] = $user_prop;
} else {
return $user_prop;
}
}
} elseif ( 'post_meta' == $opt and in_the_loop() ) {
if ( $args['multiple'] ) {
$values = array_merge( $values,
get_post_meta( get_the_ID(), $this->name ) );
} else {
$val = (string) get_post_meta( get_the_ID(), $this->name, true );
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'get' == $opt and isset( $_GET[$this->name] ) ) {
$vals = (array) $_GET[$this->name];
$vals = array_map( 'wpcf7_sanitize_query_var', $vals );
if ( $args['multiple'] ) {
$values = array_merge( $values, $vals );
} else {
$val = isset( $vals[0] ) ? (string) $vals[0] : '';
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'post' == $opt and isset( $_POST[$this->name] ) ) {
$vals = (array) $_POST[$this->name];
$vals = array_map( 'wpcf7_sanitize_query_var', $vals );
if ( $args['multiple'] ) {
$values = array_merge( $values, $vals );
} else {
$val = isset( $vals[0] ) ? (string) $vals[0] : '';
if ( strlen( $val ) ) {
return $val;
}
}
} elseif ( 'shortcode_attr' == $opt ) {
if ( $contact_form = WPCF7_ContactForm::get_current() ) {
$val = $contact_form->shortcode_attr( $this->name );
if ( strlen( $val ) ) {
if ( $args['multiple'] ) {
$values[] = $val;
} else {
return $val;
}
}
}
} elseif ( preg_match( '/^[0-9_]+$/', $opt ) ) {
$nums = explode( '_', $opt );
foreach ( $nums as $num ) {
$num = absint( $num );
$num = $args['shifted'] ? $num : $num - 1;
if ( isset( $this->values[$num] ) ) {
if ( $args['multiple'] ) {
$values[] = $this->values[$num];
} else {
return $this->values[$num];
}
}
}
}
}
if ( $args['multiple'] ) {
$values = array_unique( $values );
return $values;
} else {
return $default;
}
}
public function get_data_option( $args = '' ) {
$options = (array) $this->get_option( 'data' );
return apply_filters( 'wpcf7_form_tag_data_option', null, $options, $args );
}
public function get_first_match_option( $pattern ) {
foreach( (array) $this->options as $option ) {
if ( preg_match( $pattern, $option, $matches ) ) {
return $matches;
}
}
return false;
}
public function get_all_match_options( $pattern ) {
$result = array();
foreach( (array) $this->options as $option ) {
if ( preg_match( $pattern, $option, $matches ) ) {
$result[] = $matches;
}
}
return $result;
}
public function offsetSet( $offset, $value ) {
if ( property_exists( __CLASS__, $offset ) ) {
$this->{$offset} = $value;
}
}
public function offsetGet( $offset ) {
if ( property_exists( __CLASS__, $offset ) ) {
return $this->{$offset};
}
return null;
}
public function offsetExists( $offset ) {
return property_exists( __CLASS__, $offset );
}
public function offsetUnset( $offset ) {
}
}

View File

@ -0,0 +1,368 @@
<?php
function wpcf7_add_form_tag( $tag, $func, $features = '' ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->add( $tag, $func, $features );
}
function wpcf7_remove_form_tag( $tag ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->remove( $tag );
}
function wpcf7_replace_all_form_tags( $content ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->replace_all( $content );
}
function wpcf7_scan_form_tags( $cond = null ) {
$contact_form = WPCF7_ContactForm::get_current();
if ( $contact_form ) {
return $contact_form->scan_form_tags( $cond );
}
return array();
}
function wpcf7_form_tag_supports( $tag, $feature ) {
$manager = WPCF7_FormTagsManager::get_instance();
return $manager->tag_type_supports( $tag, $feature );
}
class WPCF7_FormTagsManager {
private static $instance;
private $tag_types = array();
private $scanned_tags = null; // Tags scanned at the last time of scan()
private function __construct() {}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function get_scanned_tags() {
return $this->scanned_tags;
}
public function add( $tag, $func, $features = '' ) {
if ( ! is_callable( $func ) ) {
return;
}
if ( true === $features ) { // for back-compat
$features = array( 'name-attr' => true );
}
$features = wp_parse_args( $features, array() );
$tags = array_filter( array_unique( (array) $tag ) );
foreach ( $tags as $tag ) {
$tag = $this->sanitize_tag_type( $tag );
if ( ! $this->tag_type_exists( $tag ) ) {
$this->tag_types[$tag] = array(
'function' => $func,
'features' => $features,
);
}
}
}
public function tag_type_exists( $tag ) {
return isset( $this->tag_types[$tag] );
}
public function tag_type_supports( $tag, $feature ) {
$feature = array_filter( (array) $feature );
if ( isset( $this->tag_types[$tag]['features'] ) ) {
return (bool) array_intersect(
array_keys( array_filter( $this->tag_types[$tag]['features'] ) ),
$feature );
}
return false;
}
public function collect_tag_types( $feature = null, $invert = false ) {
$tag_types = array_keys( $this->tag_types );
if ( empty( $feature ) ) {
return $tag_types;
}
$output = array();
foreach ( $tag_types as $tag ) {
if ( ! $invert && $this->tag_type_supports( $tag, $feature )
|| $invert && ! $this->tag_type_supports( $tag, $feature ) ) {
$output[] = $tag;
}
}
return $output;
}
private function sanitize_tag_type( $tag ) {
$tag = preg_replace( '/[^a-zA-Z0-9_*]+/', '_', $tag );
$tag = rtrim( $tag, '_' );
$tag = strtolower( $tag );
return $tag;
}
public function remove( $tag ) {
unset( $this->tag_types[$tag] );
}
public function normalize( $content ) {
if ( empty( $this->tag_types ) ) {
return $content;
}
$content = preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'normalize_callback' ),
$content );
return $content;
}
private function normalize_callback( $m ) {
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '['
and $m[6] == ']' ) {
return $m[0];
}
$tag = $m[2];
$attr = trim( preg_replace( '/[\r\n\t ]+/', ' ', $m[3] ) );
$attr = strtr( $attr, array( '<' => '&lt;', '>' => '&gt;' ) );
$content = trim( $m[5] );
$content = str_replace( "\n", '<WPPreserveNewline />', $content );
$result = $m[1] . '[' . $tag
. ( $attr ? ' ' . $attr : '' )
. ( $m[4] ? ' ' . $m[4] : '' )
. ']'
. ( $content ? $content . '[/' . $tag . ']' : '' )
. $m[6];
return $result;
}
public function replace_all( $content ) {
return $this->scan( $content, true );
}
public function scan( $content, $replace = false ) {
$this->scanned_tags = array();
if ( empty( $this->tag_types ) ) {
if ( $replace ) {
return $content;
} else {
return $this->scanned_tags;
}
}
if ( $replace ) {
$content = preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'replace_callback' ),
$content );
return $content;
} else {
preg_replace_callback(
'/' . $this->tag_regex() . '/s',
array( $this, 'scan_callback' ),
$content );
return $this->scanned_tags;
}
}
public function filter( $input, $cond ) {
if ( is_array( $input ) ) {
$tags = $input;
} elseif ( is_string( $input ) ) {
$tags = $this->scan( $input );
} else {
$tags = $this->scanned_tags;
}
if ( empty( $tags ) ) {
return array();
}
$cond = wp_parse_args( $cond, array(
'type' => array(),
'name' => array(),
'feature' => '',
) );
$type = array_filter( (array) $cond['type'] );
$name = array_filter( (array) $cond['name'] );
$feature = is_string( $cond['feature'] ) ? trim( $cond['feature'] ) : '';
if ( '!' == substr( $feature, 0, 1 ) ) {
$feature_negative = true;
$feature = trim( substr( $feature, 1 ) );
} else {
$feature_negative = false;
}
$output = array();
foreach ( $tags as $tag ) {
$tag = new WPCF7_FormTag( $tag );
if ( $type and ! in_array( $tag->type, $type, true ) ) {
continue;
}
if ( $name and ! in_array( $tag->name, $name, true ) ) {
continue;
}
if ( $feature ) {
if ( ! $this->tag_type_supports( $tag->type, $feature )
and ! $feature_negative ) {
continue;
} elseif ( $this->tag_type_supports( $tag->type, $feature )
and $feature_negative ) {
continue;
}
}
$output[] = $tag;
}
return $output;
}
private function tag_regex() {
$tagnames = array_keys( $this->tag_types );
$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
return '(\[?)'
. '\[(' . $tagregexp . ')(?:[\r\n\t ](.*?))?(?:[\r\n\t ](\/))?\]'
. '(?:([^[]*?)\[\/\2\])?'
. '(\]?)';
}
private function replace_callback( $m ) {
return $this->scan_callback( $m, true );
}
private function scan_callback( $m, $replace = false ) {
// allow [[foo]] syntax for escaping a tag
if ( $m[1] == '['
and $m[6] == ']' ) {
return substr( $m[0], 1, -1 );
}
$tag = $m[2];
$attr = $this->parse_atts( $m[3] );
$scanned_tag = array(
'type' => $tag,
'basetype' => trim( $tag, '*' ),
'name' => '',
'options' => array(),
'raw_values' => array(),
'values' => array(),
'pipes' => null,
'labels' => array(),
'attr' => '',
'content' => '',
);
if ( is_array( $attr ) ) {
if ( is_array( $attr['options'] ) ) {
if ( $this->tag_type_supports( $tag, 'name-attr' )
and ! empty( $attr['options'] ) ) {
$scanned_tag['name'] = array_shift( $attr['options'] );
if ( ! wpcf7_is_name( $scanned_tag['name'] ) ) {
return $m[0]; // Invalid name is used. Ignore this tag.
}
}
$scanned_tag['options'] = (array) $attr['options'];
}
$scanned_tag['raw_values'] = (array) $attr['values'];
if ( WPCF7_USE_PIPE ) {
$pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['pipes'] = $pipes;
} else {
$scanned_tag['values'] = $scanned_tag['raw_values'];
}
$scanned_tag['labels'] = $scanned_tag['values'];
} else {
$scanned_tag['attr'] = $attr;
}
$scanned_tag['values'] = array_map( 'trim', $scanned_tag['values'] );
$scanned_tag['labels'] = array_map( 'trim', $scanned_tag['labels'] );
$content = trim( $m[5] );
$content = preg_replace( "/<br[\r\n\t ]*\/?>$/m", '', $content );
$scanned_tag['content'] = $content;
$scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag, $replace );
$scanned_tag = new WPCF7_FormTag( $scanned_tag );
$this->scanned_tags[] = $scanned_tag;
if ( $replace ) {
$func = $this->tag_types[$tag]['function'];
return $m[1] . call_user_func( $func, $scanned_tag ) . $m[6];
} else {
return $m[0];
}
}
private function parse_atts( $text ) {
$atts = array( 'options' => array(), 'values' => array() );
$text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
$text = stripcslashes( trim( $text ) );
$pattern = '%^([-+*=0-9a-zA-Z:.!?#$&@_/|\%\r\n\t ]*?)((?:[\r\n\t ]*"[^"]*"|[\r\n\t ]*\'[^\']*\')*)$%';
if ( preg_match( $pattern, $text, $match ) ) {
if ( ! empty( $match[1] ) ) {
$atts['options'] = preg_split( '/[\r\n\t ]+/', trim( $match[1] ) );
}
if ( ! empty( $match[2] ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $match[2], $matched_values );
$atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
}
} else {
$atts = $text;
}
return $atts;
}
}

View File

@ -0,0 +1,381 @@
<?php
function wpcf7_autop( $pee, $br = 1 ) {
if ( trim( $pee ) === '' ) {
return '';
}
$pee = $pee . "\n"; // just to make things a little easier, pad the end
$pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
// Space things out a little
/* wpcf7: remove select and input */
$allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
/* wpcf7: take care of [response], [recaptcha], and [hidden] tags */
$form_tags_manager = WPCF7_FormTagsManager::get_instance();
$block_hidden_form_tags = $form_tags_manager->collect_tag_types(
array( 'display-block', 'display-hidden' ) );
$block_hidden_form_tags = sprintf( '(?:%s)',
implode( '|', $block_hidden_form_tags ) );
$pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])!',
"\n$1\n\n", $pee );
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
if ( strpos( $pee, '<object' ) !== false ) {
$pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
$pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
}
$pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
// make paragraphs, including one at the end
$pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
$pee = '';
foreach ( $pees as $tinkle ) {
$pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
}
$pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
$pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee );
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
$pee = preg_replace( "|<p>(<li.+?)</p>|", "$1", $pee ); // problem with nested lists
$pee = preg_replace( '|<p><blockquote([^>]*)>|i', "<blockquote$1><p>", $pee );
$pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
/* wpcf7: take care of [response], [recaptcha], and [hidden] tag */
$pee = preg_replace( '!<p>\s*(\[' . $block_hidden_form_tags . '[^]]*\])!',
"$1", $pee );
$pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])\s*</p>!',
"$1", $pee );
if ( $br ) {
/* wpcf7: add textarea */
$pee = preg_replace_callback(
'/<(script|style|textarea).*?<\/\\1>/s',
'wpcf7_autop_preserve_newline_callback', $pee );
$pee = preg_replace( '|(?<!<br />)\s*\n|', "<br />\n", $pee ); // optionally make line breaks
$pee = str_replace( '<WPPreserveNewline />', "\n", $pee );
/* wpcf7: remove extra <br /> just added before [response], [recaptcha], and [hidden] tags */
$pee = preg_replace( '!<br />\n(\[' . $block_hidden_form_tags . '[^]]*\])!',
"\n$1", $pee );
}
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*<br />!', "$1", $pee );
$pee = preg_replace( '!<br />(\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee );
if ( strpos( $pee, '<pre' ) !== false ) {
$pee = preg_replace_callback( '!(<pre[^>]*>)(.*?)</pre>!is',
'clean_pre', $pee );
}
$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
return $pee;
}
function wpcf7_autop_preserve_newline_callback( $matches ) {
return str_replace( "\n", '<WPPreserveNewline />', $matches[0] );
}
function wpcf7_sanitize_query_var( $text ) {
$text = wp_unslash( $text );
$text = wp_check_invalid_utf8( $text );
if ( false !== strpos( $text, '<' ) ) {
$text = wp_pre_kses_less_than( $text );
$text = wp_strip_all_tags( $text );
}
$text = preg_replace( '/%[a-f0-9]{2}/i', '', $text );
$text = preg_replace( '/ +/', ' ', $text );
$text = trim( $text, ' ' );
return $text;
}
function wpcf7_strip_quote( $text ) {
$text = trim( $text );
if ( preg_match( '/^"(.*)"$/s', $text, $matches ) ) {
$text = $matches[1];
} elseif ( preg_match( "/^'(.*)'$/s", $text, $matches ) ) {
$text = $matches[1];
}
return $text;
}
function wpcf7_strip_quote_deep( $arr ) {
if ( is_string( $arr ) ) {
return wpcf7_strip_quote( $arr );
}
if ( is_array( $arr ) ) {
$result = array();
foreach ( $arr as $key => $text ) {
$result[$key] = wpcf7_strip_quote_deep( $text );
}
return $result;
}
}
function wpcf7_normalize_newline( $text, $to = "\n" ) {
if ( ! is_string( $text ) ) {
return $text;
}
$nls = array( "\r\n", "\r", "\n" );
if ( ! in_array( $to, $nls ) ) {
return $text;
}
return str_replace( $nls, $to, $text );
}
function wpcf7_normalize_newline_deep( $arr, $to = "\n" ) {
if ( is_array( $arr ) ) {
$result = array();
foreach ( $arr as $key => $text ) {
$result[$key] = wpcf7_normalize_newline_deep( $text, $to );
}
return $result;
}
return wpcf7_normalize_newline( $arr, $to );
}
function wpcf7_strip_newline( $str ) {
$str = (string) $str;
$str = str_replace( array( "\r", "\n" ), '', $str );
return trim( $str );
}
function wpcf7_canonicalize( $text, $strto = 'lower' ) {
if ( function_exists( 'mb_convert_kana' )
and 'UTF-8' == get_option( 'blog_charset' ) ) {
$text = mb_convert_kana( $text, 'asKV', 'UTF-8' );
}
if ( 'lower' == $strto ) {
$text = strtolower( $text );
} elseif ( 'upper' == $strto ) {
$text = strtoupper( $text );
}
$text = trim( $text );
return $text;
}
/**
* Check whether a string is a valid NAME token.
*
* ID and NAME tokens must begin with a letter ([A-Za-z])
* and may be followed by any number of letters, digits ([0-9]),
* hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
*
* @see http://www.w3.org/TR/html401/types.html#h-6.2
*
* @return bool True if it is a valid name, false if not.
*/
function wpcf7_is_name( $string ) {
return preg_match( '/^[A-Za-z][-A-Za-z0-9_:.]*$/', $string );
}
function wpcf7_sanitize_unit_tag( $tag ) {
$tag = preg_replace( '/[^A-Za-z0-9_-]/', '', $tag );
return $tag;
}
function wpcf7_is_email( $email ) {
$result = is_email( $email );
return apply_filters( 'wpcf7_is_email', $result, $email );
}
function wpcf7_is_url( $url ) {
$result = ( false !== filter_var( $url, FILTER_VALIDATE_URL ) );
return apply_filters( 'wpcf7_is_url', $result, $url );
}
function wpcf7_is_tel( $tel ) {
$result = preg_match( '%^[+]?[0-9()/ -]*$%', $tel );
return apply_filters( 'wpcf7_is_tel', $result, $tel );
}
function wpcf7_is_number( $number ) {
$result = is_numeric( $number );
return apply_filters( 'wpcf7_is_number', $result, $number );
}
function wpcf7_is_date( $date ) {
$result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/', $date, $matches );
if ( $result ) {
$result = checkdate( $matches[2], $matches[3], $matches[1] );
}
return apply_filters( 'wpcf7_is_date', $result, $date );
}
function wpcf7_is_mailbox_list( $mailbox_list ) {
if ( ! is_array( $mailbox_list ) ) {
$mailbox_text = (string) $mailbox_list;
$mailbox_text = wp_unslash( $mailbox_text );
$mailbox_text = preg_replace( '/\\\\(?:\"|\')/', 'esc-quote',
$mailbox_text );
$mailbox_text = preg_replace( '/(?:\".*?\"|\'.*?\')/', 'quoted-string',
$mailbox_text );
$mailbox_list = explode( ',', $mailbox_text );
}
$addresses = array();
foreach ( $mailbox_list as $mailbox ) {
if ( ! is_string( $mailbox ) ) {
return false;
}
$mailbox = trim( $mailbox );
if ( preg_match( '/<(.+)>$/', $mailbox, $matches ) ) {
$addr_spec = $matches[1];
} else {
$addr_spec = $mailbox;
}
if ( ! wpcf7_is_email( $addr_spec ) ) {
return false;
}
$addresses[] = $addr_spec;
}
return $addresses;
}
function wpcf7_is_email_in_domain( $email, $domain ) {
$email_list = wpcf7_is_mailbox_list( $email );
$domain = strtolower( $domain );
foreach ( $email_list as $email ) {
$email_domain = substr( $email, strrpos( $email, '@' ) + 1 );
$email_domain = strtolower( $email_domain );
$domain_parts = explode( '.', $domain );
do {
$site_domain = implode( '.', $domain_parts );
if ( $site_domain == $email_domain ) {
continue 2;
}
array_shift( $domain_parts );
} while ( $domain_parts );
return false;
}
return true;
}
function wpcf7_is_email_in_site_domain( $email ) {
if ( wpcf7_is_localhost() ) {
return true;
}
$site_domain = strtolower( $_SERVER['SERVER_NAME'] );
if ( preg_match( '/^[0-9.]+$/', $site_domain ) ) { // 123.456.789.012
return true;
}
if ( wpcf7_is_email_in_domain( $email, $site_domain ) ) {
return true;
}
$home_url = home_url();
// for interoperability with WordPress MU Domain Mapping plugin
if ( is_multisite()
and function_exists( 'domain_mapping_siteurl' ) ) {
$domain_mapping_siteurl = domain_mapping_siteurl( false );
if ( $domain_mapping_siteurl ) {
$home_url = $domain_mapping_siteurl;
}
}
if ( preg_match( '%^https?://([^/]+)%', $home_url, $matches ) ) {
$site_domain = strtolower( $matches[1] );
if ( $site_domain != strtolower( $_SERVER['SERVER_NAME'] )
and wpcf7_is_email_in_domain( $email, $site_domain ) ) {
return true;
}
}
return false;
}
function wpcf7_antiscript_file_name( $filename ) {
$filename = basename( $filename );
$parts = explode( '.', $filename );
if ( count( $parts ) < 2 ) {
return $filename;
}
$script_pattern = '/^(php|phtml|pl|py|rb|cgi|asp|aspx)\d?$/i';
$filename = array_shift( $parts );
$extension = array_pop( $parts );
foreach ( (array) $parts as $part ) {
if ( preg_match( $script_pattern, $part ) ) {
$filename .= '.' . $part . '_';
} else {
$filename .= '.' . $part;
}
}
if ( preg_match( $script_pattern, $extension ) ) {
$filename .= '.' . $extension . '_.txt';
} else {
$filename .= '.' . $extension;
}
return $filename;
}
function wpcf7_mask_password( $text, $length_unmasked = 0 ) {
$length = strlen( $text );
$length_unmasked = absint( $length_unmasked );
if ( 0 == $length_unmasked ) {
if ( 9 < $length ) {
$length_unmasked = 4;
} elseif ( 3 < $length ) {
$length_unmasked = 2;
} else {
$length_unmasked = $length;
}
}
$text = substr( $text, 0 - $length_unmasked );
$text = str_pad( $text, $length, '*', STR_PAD_LEFT );
return $text;
}

View File

@ -0,0 +1,433 @@
<?php
function wpcf7_plugin_path( $path = '' ) {
return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
}
function wpcf7_plugin_url( $path = '' ) {
$url = plugins_url( $path, WPCF7_PLUGIN );
if ( is_ssl()
and 'http:' == substr( $url, 0, 5 ) ) {
$url = 'https:' . substr( $url, 5 );
}
return $url;
}
function wpcf7_upload_dir( $type = false ) {
$uploads = wp_get_upload_dir();
$uploads = apply_filters( 'wpcf7_upload_dir', array(
'dir' => $uploads['basedir'],
'url' => $uploads['baseurl'],
) );
if ( 'dir' == $type ) {
return $uploads['dir'];
} if ( 'url' == $type ) {
return $uploads['url'];
}
return $uploads;
}
function wpcf7_verify_nonce( $nonce, $action = 'wp_rest' ) {
return wp_verify_nonce( $nonce, $action );
}
function wpcf7_create_nonce( $action = 'wp_rest' ) {
return wp_create_nonce( $action );
}
function wpcf7_blacklist_check( $target ) {
$mod_keys = trim( get_option( 'blacklist_keys' ) );
if ( empty( $mod_keys ) ) {
return false;
}
$words = explode( "\n", $mod_keys );
foreach ( (array) $words as $word ) {
$word = trim( $word );
if ( empty( $word )
or 256 < strlen( $word ) ) {
continue;
}
$pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) );
if ( preg_match( $pattern, $target ) ) {
return true;
}
}
return false;
}
function wpcf7_array_flatten( $input ) {
if ( ! is_array( $input ) ) {
return array( $input );
}
$output = array();
foreach ( $input as $value ) {
$output = array_merge( $output, wpcf7_array_flatten( $value ) );
}
return $output;
}
function wpcf7_flat_join( $input ) {
$input = wpcf7_array_flatten( $input );
$output = array();
foreach ( (array) $input as $value ) {
$output[] = trim( (string) $value );
}
return implode( ', ', $output );
}
function wpcf7_support_html5() {
return (bool) apply_filters( 'wpcf7_support_html5', true );
}
function wpcf7_support_html5_fallback() {
return (bool) apply_filters( 'wpcf7_support_html5_fallback', false );
}
function wpcf7_use_really_simple_captcha() {
return apply_filters( 'wpcf7_use_really_simple_captcha',
WPCF7_USE_REALLY_SIMPLE_CAPTCHA );
}
function wpcf7_validate_configuration() {
return apply_filters( 'wpcf7_validate_configuration',
WPCF7_VALIDATE_CONFIGURATION );
}
function wpcf7_autop_or_not() {
return (bool) apply_filters( 'wpcf7_autop_or_not', WPCF7_AUTOP );
}
function wpcf7_load_js() {
return apply_filters( 'wpcf7_load_js', WPCF7_LOAD_JS );
}
function wpcf7_load_css() {
return apply_filters( 'wpcf7_load_css', WPCF7_LOAD_CSS );
}
function wpcf7_format_atts( $atts ) {
$html = '';
$prioritized_atts = array( 'type', 'name', 'value' );
foreach ( $prioritized_atts as $att ) {
if ( isset( $atts[$att] ) ) {
$value = trim( $atts[$att] );
$html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
unset( $atts[$att] );
}
}
foreach ( $atts as $key => $value ) {
$key = strtolower( trim( $key ) );
if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) {
continue;
}
$value = trim( $value );
if ( '' !== $value ) {
$html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
}
}
$html = trim( $html );
return $html;
}
function wpcf7_link( $url, $anchor_text, $args = '' ) {
$defaults = array(
'id' => '',
'class' => '',
);
$args = wp_parse_args( $args, $defaults );
$args = array_intersect_key( $args, $defaults );
$atts = wpcf7_format_atts( $args );
$link = sprintf( '<a href="%1$s"%3$s>%2$s</a>',
esc_url( $url ),
esc_html( $anchor_text ),
$atts ? ( ' ' . $atts ) : '' );
return $link;
}
function wpcf7_get_request_uri() {
static $request_uri = '';
if ( empty( $request_uri ) ) {
$request_uri = add_query_arg( array() );
}
return esc_url_raw( $request_uri );
}
function wpcf7_register_post_types() {
if ( class_exists( 'WPCF7_ContactForm' ) ) {
WPCF7_ContactForm::register_post_type();
return true;
} else {
return false;
}
}
function wpcf7_version( $args = '' ) {
$defaults = array(
'limit' => -1,
'only_major' => false,
);
$args = wp_parse_args( $args, $defaults );
if ( $args['only_major'] ) {
$args['limit'] = 2;
}
$args['limit'] = (int) $args['limit'];
$ver = WPCF7_VERSION;
$ver = strtr( $ver, '_-+', '...' );
$ver = preg_replace( '/[^0-9.]+/', ".$0.", $ver );
$ver = preg_replace( '/[.]+/', ".", $ver );
$ver = trim( $ver, '.' );
$ver = explode( '.', $ver );
if ( -1 < $args['limit'] ) {
$ver = array_slice( $ver, 0, $args['limit'] );
}
$ver = implode( '.', $ver );
return $ver;
}
function wpcf7_version_grep( $version, array $input ) {
$pattern = '/^' . preg_quote( (string) $version, '/' ) . '(?:\.|$)/';
return preg_grep( $pattern, $input );
}
function wpcf7_enctype_value( $enctype ) {
$enctype = trim( $enctype );
if ( empty( $enctype ) ) {
return '';
}
$valid_enctypes = array(
'application/x-www-form-urlencoded',
'multipart/form-data',
'text/plain',
);
if ( in_array( $enctype, $valid_enctypes ) ) {
return $enctype;
}
$pattern = '%^enctype="(' . implode( '|', $valid_enctypes ) . ')"$%';
if ( preg_match( $pattern, $enctype, $matches ) ) {
return $matches[1]; // for back-compat
}
return '';
}
function wpcf7_rmdir_p( $dir ) {
if ( is_file( $dir ) ) {
$file = $dir;
if ( @unlink( $file ) ) {
return true;
}
$stat = stat( $file );
if ( @chmod( $file, $stat['mode'] | 0200 ) ) { // add write for owner
if ( @unlink( $file ) ) {
return true;
}
@chmod( $file, $stat['mode'] );
}
return false;
}
if ( ! is_dir( $dir ) ) {
return false;
}
if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "."
or $file == ".." ) {
continue;
}
wpcf7_rmdir_p( path_join( $dir, $file ) );
}
closedir( $handle );
}
if ( false !== ( $files = scandir( $dir ) )
and ! array_diff( $files, array( '.', '..' ) ) ) {
return rmdir( $dir );
}
return false;
}
/* From _http_build_query in wp-includes/functions.php */
function wpcf7_build_query( $args, $key = '' ) {
$sep = '&';
$ret = array();
foreach ( (array) $args as $k => $v ) {
$k = urlencode( $k );
if ( ! empty( $key ) ) {
$k = $key . '%5B' . $k . '%5D';
}
if ( null === $v ) {
continue;
} elseif ( false === $v ) {
$v = '0';
}
if ( is_array( $v ) or is_object( $v ) ) {
array_push( $ret, wpcf7_build_query( $v, $k ) );
} else {
array_push( $ret, $k . '=' . urlencode( $v ) );
}
}
return implode( $sep, $ret );
}
/**
* Returns the number of code units in a string.
*
* @see http://www.w3.org/TR/html5/infrastructure.html#code-unit-length
*
* @return int|bool The number of code units, or false if mb_convert_encoding is not available.
*/
function wpcf7_count_code_units( $string ) {
static $use_mb = null;
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
}
if ( ! $use_mb ) {
return false;
}
$string = (string) $string;
$string = str_replace( "\r\n", "\n", $string );
$encoding = mb_detect_encoding( $string, mb_detect_order(), true );
if ( $encoding ) {
$string = mb_convert_encoding( $string, 'UTF-16', $encoding );
} else {
$string = mb_convert_encoding( $string, 'UTF-16', 'UTF-8' );
}
$byte_count = mb_strlen( $string, '8bit' );
return floor( $byte_count / 2 );
}
function wpcf7_is_localhost() {
$server_name = strtolower( $_SERVER['SERVER_NAME'] );
return in_array( $server_name, array( 'localhost', '127.0.0.1' ) );
}
function wpcf7_deprecated_function( $function, $version, $replacement ) {
$trigger_error = apply_filters( 'deprecated_function_trigger_error', true );
if ( WP_DEBUG and $trigger_error ) {
if ( function_exists( '__' ) ) {
trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', 'contact-form-7' ), $function, $version, $replacement ) );
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
}
}
}
function wpcf7_log_remote_request( $url, $request, $response ) {
$log = sprintf(
/* translators: 1: response code, 2: response message, 3: URL */
__( 'HTTP Response: %1$s %2$s from %3$s', 'contact-form-7' ),
(int) wp_remote_retrieve_response_code( $response ),
wp_remote_retrieve_response_message( $response ),
$url
);
$log = apply_filters( 'wpcf7_log_remote_request',
$log, $url, $request, $response
);
if ( $log ) {
trigger_error( $log );
}
}
function wpcf7_anonymize_ip_addr( $ip_addr ) {
if ( ! function_exists( 'inet_ntop' )
or ! function_exists( 'inet_pton' ) ) {
return $ip_addr;
}
$packed = inet_pton( $ip_addr );
if ( false === $packed ) {
return $ip_addr;
}
if ( 4 == strlen( $packed ) ) { // IPv4
$mask = '255.255.255.0';
} elseif ( 16 == strlen( $packed ) ) { // IPv6
$mask = 'ffff:ffff:ffff:0000:0000:0000:0000:0000';
} else {
return $ip_addr;
}
return inet_ntop( $packed & inet_pton( $mask ) );
}
function wpcf7_is_file_path_in_content_dir( $path ) {
if ( 0 === strpos( realpath( $path ), realpath( WP_CONTENT_DIR ) ) ) {
return true;
}
if ( defined( 'UPLOADS' )
and 0 === strpos( realpath( $path ), realpath( ABSPATH . UPLOADS ) ) ) {
return true;
}
return false;
}

View File

@ -0,0 +1,321 @@
<?php
class WPCF7_Integration {
private static $instance;
private $services = array();
private $categories = array();
private function __construct() {}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function add_service( $name, WPCF7_Service $service ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->services[$name] ) ) {
return false;
}
$this->services[$name] = $service;
}
public function add_category( $name, $title ) {
$name = sanitize_key( $name );
if ( empty( $name )
or isset( $this->categories[$name] ) ) {
return false;
}
$this->categories[$name] = $title;
}
public function service_exists( $name = '' ) {
if ( '' == $name ) {
return (bool) count( $this->services );
} else {
return isset( $this->services[$name] );
}
}
public function get_service( $name ) {
if ( $this->service_exists( $name ) ) {
return $this->services[$name];
} else {
return false;
}
}
public function list_services( $args = '' ) {
$args = wp_parse_args( $args, array(
'include' => array(),
) );
$singular = false;
$services = (array) $this->services;
if ( ! empty( $args['include'] ) ) {
$services = array_intersect_key( $services,
array_flip( (array) $args['include'] ) );
if ( 1 == count( $services ) ) {
$singular = true;
}
}
if ( empty( $services ) ) {
return;
}
$action = wpcf7_current_action();
foreach ( $services as $name => $service ) {
$cats = array_intersect_key( $this->categories,
array_flip( $service->get_categories() ) );
?>
<div class="card<?php echo $service->is_active() ? ' active' : ''; ?>" id="<?php echo esc_attr( $name ); ?>">
<?php $service->icon(); ?>
<h2 class="title"><?php echo esc_html( $service->get_title() ); ?></h2>
<div class="infobox">
<?php echo esc_html( implode( ', ', $cats ) ); ?>
<br />
<?php $service->link(); ?>
</div>
<br class="clear" />
<div class="inside">
<?php
if ( $singular ) {
$service->display( $action );
} else {
$service->display();
}
?>
</div>
</div>
<?php
}
}
}
abstract class WPCF7_Service {
abstract public function get_title();
abstract public function is_active();
public function get_categories() {
return array();
}
public function icon() {
return '';
}
public function link() {
return '';
}
public function load( $action = '' ) {
}
public function display( $action = '' ) {
}
public function admin_notice( $message = '' ) {
}
}
class WPCF7_Service_OAuth2 extends WPCF7_Service {
protected $client_id = '';
protected $client_secret = '';
protected $access_token = '';
protected $refresh_token = '';
protected $authorization_endpoint = 'https://example.com/authorization';
protected $token_endpoint = 'https://example.com/token';
public function get_title() {
return '';
}
public function is_active() {
return ! empty( $this->access_token );
}
protected function save_data() {
}
protected function reset_data() {
}
protected function get_redirect_uri() {
return admin_url();
}
protected function menu_page_url( $args = '' ) {
return menu_page_url( 'wpcf7-integration', false );
}
public function load( $action = '' ) {
if ( 'auth_redirect' == $action ) {
$code = isset( $_GET['code'] ) ? $_GET['code'] : '';
if ( $code ) {
$this->request_token( $code );
}
wp_safe_redirect( $this->menu_page_url( 'action=setup' ) );
exit();
}
}
protected function authorize( $scope = '' ) {
$endpoint = add_query_arg(
array(
'response_type' => 'code',
'client_id' => $this->client_id,
'redirect_uri' => urlencode( $this->get_redirect_uri() ),
'scope' => $scope,
),
$this->authorization_endpoint
);
if ( wp_redirect( esc_url_raw( $endpoint ) ) ) {
exit();
}
}
protected function get_http_authorization_header( $scheme = 'basic' ) {
$scheme = strtolower( trim( $scheme ) );
switch ( $scheme ) {
case 'bearer':
return sprintf( 'Bearer %s', $this->access_token );
case 'basic':
default:
return sprintf( 'Basic %s',
base64_encode( $this->client_id . ':' . $this->client_secret )
);
}
}
protected function request_token( $authorization_code ) {
$endpoint = add_query_arg(
array(
'code' => $authorization_code,
'redirect_uri' => urlencode( $this->get_redirect_uri() ),
'grant_type' => 'authorization_code',
),
$this->token_endpoint
);
$request = array(
'headers' => array(
'Authorization' => $this->get_http_authorization_header( 'basic' ),
),
);
$response = wp_remote_post( esc_url_raw( $endpoint ), $request );
if ( WP_DEBUG
and 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
$this->log( $endpoint, $request, $response );
}
$response_body = wp_remote_retrieve_body( $response );
if ( empty( $response_body ) ) {
return $response;
}
$response_body = json_decode( $response_body, true );
$this->access_token = isset( $response_body['access_token'] )
? $response_body['access_token'] : null;
$this->refresh_token = isset( $response_body['refresh_token'] )
? $response_body['refresh_token'] : null;
$this->save_data();
return $response;
}
protected function refresh_token() {
$endpoint = add_query_arg(
array(
'refresh_token' => $this->refresh_token,
'grant_type' => 'refresh_token',
),
$this->token_endpoint
);
$request = array(
'headers' => array(
'Authorization' => $this->get_http_authorization_header( 'basic' ),
),
);
$response = wp_remote_post( esc_url_raw( $endpoint ), $request );
if ( WP_DEBUG
and 400 <= (int) wp_remote_retrieve_response_code( $response ) ) {
$this->log( $endpoint, $request, $response );
}
$response_body = wp_remote_retrieve_body( $response );
if ( empty( $response_body ) ) {
return $response;
}
$response_body = json_decode( $response_body, true );
$this->access_token = isset( $response_body['access_token'] )
? $response_body['access_token'] : null;
$this->refresh_token = isset( $response_body['refresh_token'] )
? $response_body['refresh_token'] : null;
$this->save_data();
return $response;
}
protected function remote_request( $url, $args = array() ) {
$request = $args = wp_parse_args( $args, array(
'refresh_token' => true,
) );
unset( $request['refresh_token'] );
$response = wp_remote_request( esc_url_raw( $url ), $request );
if ( 401 === wp_remote_retrieve_response_code( $response )
and $args['refresh_token'] ) {
$this->refresh_token();
$response = $this->remote_request( $url,
array_merge( $args, array( 'refresh_token' => false ) )
);
}
return $response;
}
protected function log( $url, $request, $response ) {
wpcf7_log_remote_request( $url, $request, $response );
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,410 @@
/*!
* jQuery UI CSS Framework 1.11.4
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*
* http://api.jqueryui.com/category/theming/
*
* To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Verdana%2CArial%2Csans-serif&fwDefault=normal&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=cccccc&bgTextureHeader=highlight_soft&bgImgOpacityHeader=75&borderColorHeader=aaaaaa&fcHeader=222222&iconColorHeader=222222&bgColorContent=ffffff&bgTextureContent=flat&bgImgOpacityContent=75&borderColorContent=aaaaaa&fcContent=222222&iconColorContent=222222&bgColorDefault=e6e6e6&bgTextureDefault=glass&bgImgOpacityDefault=75&borderColorDefault=d3d3d3&fcDefault=555555&iconColorDefault=888888&bgColorHover=dadada&bgTextureHover=glass&bgImgOpacityHover=75&borderColorHover=999999&fcHover=212121&iconColorHover=454545&bgColorActive=ffffff&bgTextureActive=glass&bgImgOpacityActive=65&borderColorActive=aaaaaa&fcActive=212121&iconColorActive=454545&bgColorHighlight=fbf9ee&bgTextureHighlight=glass&bgImgOpacityHighlight=55&borderColorHighlight=fcefa1&fcHighlight=363636&iconColorHighlight=2e83ff&bgColorError=fef1ec&bgTextureError=glass&bgImgOpacityError=95&borderColorError=cd0a0a&fcError=cd0a0a&iconColorError=cd0a0a&bgColorOverlay=aaaaaa&bgTextureOverlay=flat&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=aaaaaa&bgTextureShadow=flat&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=8px&offsetTopShadow=-8px&offsetLeftShadow=-8px&cornerRadiusShadow=8px
*/
/* Component containers
----------------------------------*/
.ui-widget {
font-family: Verdana,Arial,sans-serif;
font-size: 1.1em;
}
.ui-widget .ui-widget {
font-size: 1em;
}
.ui-widget input,
.ui-widget select,
.ui-widget textarea,
.ui-widget button {
font-family: Verdana,Arial,sans-serif;
font-size: 1em;
}
.ui-widget-content {
border: 1px solid #aaaaaa;
background: #ffffff url("images/ui-bg_flat_75_ffffff_40x100.png") 50% 50% repeat-x;
color: #222222;
}
.ui-widget-content a {
color: #222222;
}
.ui-widget-header {
border: 1px solid #aaaaaa;
background: #cccccc url("images/ui-bg_highlight-soft_75_cccccc_1x100.png") 50% 50% repeat-x;
color: #222222;
font-weight: bold;
}
.ui-widget-header a {
color: #222222;
}
/* Interaction states
----------------------------------*/
.ui-state-default,
.ui-widget-content .ui-state-default,
.ui-widget-header .ui-state-default {
border: 1px solid #d3d3d3;
background: #e6e6e6 url("images/ui-bg_glass_75_e6e6e6_1x400.png") 50% 50% repeat-x;
font-weight: normal;
color: #555555;
}
.ui-state-default a,
.ui-state-default a:link,
.ui-state-default a:visited {
color: #555555;
text-decoration: none;
}
.ui-state-hover,
.ui-widget-content .ui-state-hover,
.ui-widget-header .ui-state-hover,
.ui-state-focus,
.ui-widget-content .ui-state-focus,
.ui-widget-header .ui-state-focus {
border: 1px solid #999999;
background: #dadada url("images/ui-bg_glass_75_dadada_1x400.png") 50% 50% repeat-x;
font-weight: normal;
color: #212121;
}
.ui-state-hover a,
.ui-state-hover a:hover,
.ui-state-hover a:link,
.ui-state-hover a:visited,
.ui-state-focus a,
.ui-state-focus a:hover,
.ui-state-focus a:link,
.ui-state-focus a:visited {
color: #212121;
text-decoration: none;
}
.ui-state-active,
.ui-widget-content .ui-state-active,
.ui-widget-header .ui-state-active {
border: 1px solid #aaaaaa;
background: #ffffff url("images/ui-bg_glass_65_ffffff_1x400.png") 50% 50% repeat-x;
font-weight: normal;
color: #212121;
}
.ui-state-active a,
.ui-state-active a:link,
.ui-state-active a:visited {
color: #212121;
text-decoration: none;
}
/* Interaction Cues
----------------------------------*/
.ui-state-highlight,
.ui-widget-content .ui-state-highlight,
.ui-widget-header .ui-state-highlight {
border: 1px solid #fcefa1;
background: #fbf9ee url("images/ui-bg_glass_55_fbf9ee_1x400.png") 50% 50% repeat-x;
color: #363636;
}
.ui-state-highlight a,
.ui-widget-content .ui-state-highlight a,
.ui-widget-header .ui-state-highlight a {
color: #363636;
}
.ui-state-error,
.ui-widget-content .ui-state-error,
.ui-widget-header .ui-state-error {
border: 1px solid #cd0a0a;
background: #fef1ec url("images/ui-bg_glass_95_fef1ec_1x400.png") 50% 50% repeat-x;
color: #cd0a0a;
}
.ui-state-error a,
.ui-widget-content .ui-state-error a,
.ui-widget-header .ui-state-error a {
color: #cd0a0a;
}
.ui-state-error-text,
.ui-widget-content .ui-state-error-text,
.ui-widget-header .ui-state-error-text {
color: #cd0a0a;
}
.ui-priority-primary,
.ui-widget-content .ui-priority-primary,
.ui-widget-header .ui-priority-primary {
font-weight: bold;
}
.ui-priority-secondary,
.ui-widget-content .ui-priority-secondary,
.ui-widget-header .ui-priority-secondary {
opacity: .7;
filter:Alpha(Opacity=70); /* support: IE8 */
font-weight: normal;
}
.ui-state-disabled,
.ui-widget-content .ui-state-disabled,
.ui-widget-header .ui-state-disabled {
opacity: .35;
filter:Alpha(Opacity=35); /* support: IE8 */
background-image: none;
}
.ui-state-disabled .ui-icon {
filter:Alpha(Opacity=35); /* support: IE8 - See #6059 */
}
/* Icons
----------------------------------*/
/* states and images */
.ui-icon {
width: 16px;
height: 16px;
}
.ui-icon,
.ui-widget-content .ui-icon {
background-image: url("images/ui-icons_222222_256x240.png");
}
.ui-widget-header .ui-icon {
background-image: url("images/ui-icons_222222_256x240.png");
}
.ui-state-default .ui-icon {
background-image: url("images/ui-icons_888888_256x240.png");
}
.ui-state-hover .ui-icon,
.ui-state-focus .ui-icon {
background-image: url("images/ui-icons_454545_256x240.png");
}
.ui-state-active .ui-icon {
background-image: url("images/ui-icons_454545_256x240.png");
}
.ui-state-highlight .ui-icon {
background-image: url("images/ui-icons_2e83ff_256x240.png");
}
.ui-state-error .ui-icon,
.ui-state-error-text .ui-icon {
background-image: url("images/ui-icons_cd0a0a_256x240.png");
}
/* positioning */
.ui-icon-blank { background-position: 16px 16px; }
.ui-icon-carat-1-n { background-position: 0 0; }
.ui-icon-carat-1-ne { background-position: -16px 0; }
.ui-icon-carat-1-e { background-position: -32px 0; }
.ui-icon-carat-1-se { background-position: -48px 0; }
.ui-icon-carat-1-s { background-position: -64px 0; }
.ui-icon-carat-1-sw { background-position: -80px 0; }
.ui-icon-carat-1-w { background-position: -96px 0; }
.ui-icon-carat-1-nw { background-position: -112px 0; }
.ui-icon-carat-2-n-s { background-position: -128px 0; }
.ui-icon-carat-2-e-w { background-position: -144px 0; }
.ui-icon-triangle-1-n { background-position: 0 -16px; }
.ui-icon-triangle-1-ne { background-position: -16px -16px; }
.ui-icon-triangle-1-e { background-position: -32px -16px; }
.ui-icon-triangle-1-se { background-position: -48px -16px; }
.ui-icon-triangle-1-s { background-position: -64px -16px; }
.ui-icon-triangle-1-sw { background-position: -80px -16px; }
.ui-icon-triangle-1-w { background-position: -96px -16px; }
.ui-icon-triangle-1-nw { background-position: -112px -16px; }
.ui-icon-triangle-2-n-s { background-position: -128px -16px; }
.ui-icon-triangle-2-e-w { background-position: -144px -16px; }
.ui-icon-arrow-1-n { background-position: 0 -32px; }
.ui-icon-arrow-1-ne { background-position: -16px -32px; }
.ui-icon-arrow-1-e { background-position: -32px -32px; }
.ui-icon-arrow-1-se { background-position: -48px -32px; }
.ui-icon-arrow-1-s { background-position: -64px -32px; }
.ui-icon-arrow-1-sw { background-position: -80px -32px; }
.ui-icon-arrow-1-w { background-position: -96px -32px; }
.ui-icon-arrow-1-nw { background-position: -112px -32px; }
.ui-icon-arrow-2-n-s { background-position: -128px -32px; }
.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; }
.ui-icon-arrow-2-e-w { background-position: -160px -32px; }
.ui-icon-arrow-2-se-nw { background-position: -176px -32px; }
.ui-icon-arrowstop-1-n { background-position: -192px -32px; }
.ui-icon-arrowstop-1-e { background-position: -208px -32px; }
.ui-icon-arrowstop-1-s { background-position: -224px -32px; }
.ui-icon-arrowstop-1-w { background-position: -240px -32px; }
.ui-icon-arrowthick-1-n { background-position: 0 -48px; }
.ui-icon-arrowthick-1-ne { background-position: -16px -48px; }
.ui-icon-arrowthick-1-e { background-position: -32px -48px; }
.ui-icon-arrowthick-1-se { background-position: -48px -48px; }
.ui-icon-arrowthick-1-s { background-position: -64px -48px; }
.ui-icon-arrowthick-1-sw { background-position: -80px -48px; }
.ui-icon-arrowthick-1-w { background-position: -96px -48px; }
.ui-icon-arrowthick-1-nw { background-position: -112px -48px; }
.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; }
.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; }
.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; }
.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; }
.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; }
.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; }
.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; }
.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; }
.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; }
.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; }
.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; }
.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; }
.ui-icon-arrowreturn-1-w { background-position: -64px -64px; }
.ui-icon-arrowreturn-1-n { background-position: -80px -64px; }
.ui-icon-arrowreturn-1-e { background-position: -96px -64px; }
.ui-icon-arrowreturn-1-s { background-position: -112px -64px; }
.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; }
.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; }
.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; }
.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; }
.ui-icon-arrow-4 { background-position: 0 -80px; }
.ui-icon-arrow-4-diag { background-position: -16px -80px; }
.ui-icon-extlink { background-position: -32px -80px; }
.ui-icon-newwin { background-position: -48px -80px; }
.ui-icon-refresh { background-position: -64px -80px; }
.ui-icon-shuffle { background-position: -80px -80px; }
.ui-icon-transfer-e-w { background-position: -96px -80px; }
.ui-icon-transferthick-e-w { background-position: -112px -80px; }
.ui-icon-folder-collapsed { background-position: 0 -96px; }
.ui-icon-folder-open { background-position: -16px -96px; }
.ui-icon-document { background-position: -32px -96px; }
.ui-icon-document-b { background-position: -48px -96px; }
.ui-icon-note { background-position: -64px -96px; }
.ui-icon-mail-closed { background-position: -80px -96px; }
.ui-icon-mail-open { background-position: -96px -96px; }
.ui-icon-suitcase { background-position: -112px -96px; }
.ui-icon-comment { background-position: -128px -96px; }
.ui-icon-person { background-position: -144px -96px; }
.ui-icon-print { background-position: -160px -96px; }
.ui-icon-trash { background-position: -176px -96px; }
.ui-icon-locked { background-position: -192px -96px; }
.ui-icon-unlocked { background-position: -208px -96px; }
.ui-icon-bookmark { background-position: -224px -96px; }
.ui-icon-tag { background-position: -240px -96px; }
.ui-icon-home { background-position: 0 -112px; }
.ui-icon-flag { background-position: -16px -112px; }
.ui-icon-calendar { background-position: -32px -112px; }
.ui-icon-cart { background-position: -48px -112px; }
.ui-icon-pencil { background-position: -64px -112px; }
.ui-icon-clock { background-position: -80px -112px; }
.ui-icon-disk { background-position: -96px -112px; }
.ui-icon-calculator { background-position: -112px -112px; }
.ui-icon-zoomin { background-position: -128px -112px; }
.ui-icon-zoomout { background-position: -144px -112px; }
.ui-icon-search { background-position: -160px -112px; }
.ui-icon-wrench { background-position: -176px -112px; }
.ui-icon-gear { background-position: -192px -112px; }
.ui-icon-heart { background-position: -208px -112px; }
.ui-icon-star { background-position: -224px -112px; }
.ui-icon-link { background-position: -240px -112px; }
.ui-icon-cancel { background-position: 0 -128px; }
.ui-icon-plus { background-position: -16px -128px; }
.ui-icon-plusthick { background-position: -32px -128px; }
.ui-icon-minus { background-position: -48px -128px; }
.ui-icon-minusthick { background-position: -64px -128px; }
.ui-icon-close { background-position: -80px -128px; }
.ui-icon-closethick { background-position: -96px -128px; }
.ui-icon-key { background-position: -112px -128px; }
.ui-icon-lightbulb { background-position: -128px -128px; }
.ui-icon-scissors { background-position: -144px -128px; }
.ui-icon-clipboard { background-position: -160px -128px; }
.ui-icon-copy { background-position: -176px -128px; }
.ui-icon-contact { background-position: -192px -128px; }
.ui-icon-image { background-position: -208px -128px; }
.ui-icon-video { background-position: -224px -128px; }
.ui-icon-script { background-position: -240px -128px; }
.ui-icon-alert { background-position: 0 -144px; }
.ui-icon-info { background-position: -16px -144px; }
.ui-icon-notice { background-position: -32px -144px; }
.ui-icon-help { background-position: -48px -144px; }
.ui-icon-check { background-position: -64px -144px; }
.ui-icon-bullet { background-position: -80px -144px; }
.ui-icon-radio-on { background-position: -96px -144px; }
.ui-icon-radio-off { background-position: -112px -144px; }
.ui-icon-pin-w { background-position: -128px -144px; }
.ui-icon-pin-s { background-position: -144px -144px; }
.ui-icon-play { background-position: 0 -160px; }
.ui-icon-pause { background-position: -16px -160px; }
.ui-icon-seek-next { background-position: -32px -160px; }
.ui-icon-seek-prev { background-position: -48px -160px; }
.ui-icon-seek-end { background-position: -64px -160px; }
.ui-icon-seek-start { background-position: -80px -160px; }
/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */
.ui-icon-seek-first { background-position: -80px -160px; }
.ui-icon-stop { background-position: -96px -160px; }
.ui-icon-eject { background-position: -112px -160px; }
.ui-icon-volume-off { background-position: -128px -160px; }
.ui-icon-volume-on { background-position: -144px -160px; }
.ui-icon-power { background-position: 0 -176px; }
.ui-icon-signal-diag { background-position: -16px -176px; }
.ui-icon-signal { background-position: -32px -176px; }
.ui-icon-battery-0 { background-position: -48px -176px; }
.ui-icon-battery-1 { background-position: -64px -176px; }
.ui-icon-battery-2 { background-position: -80px -176px; }
.ui-icon-battery-3 { background-position: -96px -176px; }
.ui-icon-circle-plus { background-position: 0 -192px; }
.ui-icon-circle-minus { background-position: -16px -192px; }
.ui-icon-circle-close { background-position: -32px -192px; }
.ui-icon-circle-triangle-e { background-position: -48px -192px; }
.ui-icon-circle-triangle-s { background-position: -64px -192px; }
.ui-icon-circle-triangle-w { background-position: -80px -192px; }
.ui-icon-circle-triangle-n { background-position: -96px -192px; }
.ui-icon-circle-arrow-e { background-position: -112px -192px; }
.ui-icon-circle-arrow-s { background-position: -128px -192px; }
.ui-icon-circle-arrow-w { background-position: -144px -192px; }
.ui-icon-circle-arrow-n { background-position: -160px -192px; }
.ui-icon-circle-zoomin { background-position: -176px -192px; }
.ui-icon-circle-zoomout { background-position: -192px -192px; }
.ui-icon-circle-check { background-position: -208px -192px; }
.ui-icon-circlesmall-plus { background-position: 0 -208px; }
.ui-icon-circlesmall-minus { background-position: -16px -208px; }
.ui-icon-circlesmall-close { background-position: -32px -208px; }
.ui-icon-squaresmall-plus { background-position: -48px -208px; }
.ui-icon-squaresmall-minus { background-position: -64px -208px; }
.ui-icon-squaresmall-close { background-position: -80px -208px; }
.ui-icon-grip-dotted-vertical { background-position: 0 -224px; }
.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; }
.ui-icon-grip-solid-vertical { background-position: -32px -224px; }
.ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
.ui-icon-grip-diagonal-se { background-position: -80px -224px; }
/* Misc visuals
----------------------------------*/
/* Corner radius */
.ui-corner-all,
.ui-corner-top,
.ui-corner-left,
.ui-corner-tl {
border-top-left-radius: 4px;
}
.ui-corner-all,
.ui-corner-top,
.ui-corner-right,
.ui-corner-tr {
border-top-right-radius: 4px;
}
.ui-corner-all,
.ui-corner-bottom,
.ui-corner-left,
.ui-corner-bl {
border-bottom-left-radius: 4px;
}
.ui-corner-all,
.ui-corner-bottom,
.ui-corner-right,
.ui-corner-br {
border-bottom-right-radius: 4px;
}
/* Overlays */
.ui-widget-overlay {
background: #aaaaaa url("images/ui-bg_flat_0_aaaaaa_40x100.png") 50% 50% repeat-x;
opacity: .3;
filter: Alpha(Opacity=30); /* support: IE8 */
}
.ui-widget-shadow {
margin: -8px 0 0 -8px;
padding: 8px;
background: #aaaaaa url("images/ui-bg_flat_0_aaaaaa_40x100.png") 50% 50% repeat-x;
opacity: .3;
filter: Alpha(Opacity=30); /* support: IE8 */
border-radius: 8px;
}

View File

@ -0,0 +1,526 @@
( function( $ ) {
'use strict';
if ( typeof wpcf7 === 'undefined' || wpcf7 === null ) {
return;
}
wpcf7 = $.extend( {
cached: 0,
inputs: []
}, wpcf7 );
$( function() {
wpcf7.supportHtml5 = ( function() {
var features = {};
var input = document.createElement( 'input' );
features.placeholder = 'placeholder' in input;
var inputTypes = [ 'email', 'url', 'tel', 'number', 'range', 'date' ];
$.each( inputTypes, function( index, value ) {
input.setAttribute( 'type', value );
features[ value ] = input.type !== 'text';
} );
return features;
} )();
$( 'div.wpcf7 > form' ).each( function() {
var $form = $( this );
wpcf7.initForm( $form );
if ( wpcf7.cached ) {
wpcf7.refill( $form );
}
} );
} );
wpcf7.getId = function( form ) {
return parseInt( $( 'input[name="_wpcf7"]', form ).val(), 10 );
};
wpcf7.initForm = function( form ) {
var $form = $( form );
$form.submit( function( event ) {
if ( ! wpcf7.supportHtml5.placeholder ) {
$( '[placeholder].placeheld', $form ).each( function( i, n ) {
$( n ).val( '' ).removeClass( 'placeheld' );
} );
}
if ( typeof window.FormData === 'function' ) {
wpcf7.submit( $form );
event.preventDefault();
}
} );
$( '.wpcf7-submit', $form ).after( '<span class="ajax-loader"></span>' );
wpcf7.toggleSubmit( $form );
$form.on( 'click', '.wpcf7-acceptance', function() {
wpcf7.toggleSubmit( $form );
} );
// Exclusive Checkbox
$( '.wpcf7-exclusive-checkbox', $form ).on( 'click', 'input:checkbox', function() {
var name = $( this ).attr( 'name' );
$form.find( 'input:checkbox[name="' + name + '"]' ).not( this ).prop( 'checked', false );
} );
// Free Text Option for Checkboxes and Radio Buttons
$( '.wpcf7-list-item.has-free-text', $form ).each( function() {
var $freetext = $( ':input.wpcf7-free-text', this );
var $wrap = $( this ).closest( '.wpcf7-form-control' );
if ( $( ':checkbox, :radio', this ).is( ':checked' ) ) {
$freetext.prop( 'disabled', false );
} else {
$freetext.prop( 'disabled', true );
}
$wrap.on( 'change', ':checkbox, :radio', function() {
var $cb = $( '.has-free-text', $wrap ).find( ':checkbox, :radio' );
if ( $cb.is( ':checked' ) ) {
$freetext.prop( 'disabled', false ).focus();
} else {
$freetext.prop( 'disabled', true );
}
} );
} );
// Placeholder Fallback
if ( ! wpcf7.supportHtml5.placeholder ) {
$( '[placeholder]', $form ).each( function() {
$( this ).val( $( this ).attr( 'placeholder' ) );
$( this ).addClass( 'placeheld' );
$( this ).focus( function() {
if ( $( this ).hasClass( 'placeheld' ) ) {
$( this ).val( '' ).removeClass( 'placeheld' );
}
} );
$( this ).blur( function() {
if ( '' === $( this ).val() ) {
$( this ).val( $( this ).attr( 'placeholder' ) );
$( this ).addClass( 'placeheld' );
}
} );
} );
}
if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.date ) {
$form.find( 'input.wpcf7-date[type="date"]' ).each( function() {
$( this ).datepicker( {
dateFormat: 'yy-mm-dd',
minDate: new Date( $( this ).attr( 'min' ) ),
maxDate: new Date( $( this ).attr( 'max' ) )
} );
} );
}
if ( wpcf7.jqueryUi && ! wpcf7.supportHtml5.number ) {
$form.find( 'input.wpcf7-number[type="number"]' ).each( function() {
$( this ).spinner( {
min: $( this ).attr( 'min' ),
max: $( this ).attr( 'max' ),
step: $( this ).attr( 'step' )
} );
} );
}
// Character Count
$( '.wpcf7-character-count', $form ).each( function() {
var $count = $( this );
var name = $count.attr( 'data-target-name' );
var down = $count.hasClass( 'down' );
var starting = parseInt( $count.attr( 'data-starting-value' ), 10 );
var maximum = parseInt( $count.attr( 'data-maximum-value' ), 10 );
var minimum = parseInt( $count.attr( 'data-minimum-value' ), 10 );
var updateCount = function( target ) {
var $target = $( target );
var length = $target.val().length;
var count = down ? starting - length : length;
$count.attr( 'data-current-value', count );
$count.text( count );
if ( maximum && maximum < length ) {
$count.addClass( 'too-long' );
} else {
$count.removeClass( 'too-long' );
}
if ( minimum && length < minimum ) {
$count.addClass( 'too-short' );
} else {
$count.removeClass( 'too-short' );
}
};
$( ':input[name="' + name + '"]', $form ).each( function() {
updateCount( this );
$( this ).keyup( function() {
updateCount( this );
} );
} );
} );
// URL Input Correction
$form.on( 'change', '.wpcf7-validates-as-url', function() {
var val = $.trim( $( this ).val() );
if ( val
&& ! val.match( /^[a-z][a-z0-9.+-]*:/i )
&& -1 !== val.indexOf( '.' ) ) {
val = val.replace( /^\/+/, '' );
val = 'http://' + val;
}
$( this ).val( val );
} );
};
wpcf7.submit = function( form ) {
if ( typeof window.FormData !== 'function' ) {
return;
}
var $form = $( form );
$( '.ajax-loader', $form ).addClass( 'is-active' );
wpcf7.clearResponse( $form );
var formData = new FormData( $form.get( 0 ) );
var detail = {
id: $form.closest( 'div.wpcf7' ).attr( 'id' ),
status: 'init',
inputs: [],
formData: formData
};
$.each( $form.serializeArray(), function( i, field ) {
if ( '_wpcf7' == field.name ) {
detail.contactFormId = field.value;
} else if ( '_wpcf7_version' == field.name ) {
detail.pluginVersion = field.value;
} else if ( '_wpcf7_locale' == field.name ) {
detail.contactFormLocale = field.value;
} else if ( '_wpcf7_unit_tag' == field.name ) {
detail.unitTag = field.value;
} else if ( '_wpcf7_container_post' == field.name ) {
detail.containerPostId = field.value;
} else if ( field.name.match( /^_wpcf7_\w+_free_text_/ ) ) {
var owner = field.name.replace( /^_wpcf7_\w+_free_text_/, '' );
detail.inputs.push( {
name: owner + '-free-text',
value: field.value
} );
} else if ( field.name.match( /^_/ ) ) {
// do nothing
} else {
detail.inputs.push( field );
}
} );
wpcf7.triggerEvent( $form.closest( 'div.wpcf7' ), 'beforesubmit', detail );
var ajaxSuccess = function( data, status, xhr, $form ) {
detail.id = $( data.into ).attr( 'id' );
detail.status = data.status;
detail.apiResponse = data;
var $message = $( '.wpcf7-response-output', $form );
switch ( data.status ) {
case 'validation_failed':
$.each( data.invalidFields, function( i, n ) {
$( n.into, $form ).each( function() {
wpcf7.notValidTip( this, n.message );
$( '.wpcf7-form-control', this ).addClass( 'wpcf7-not-valid' );
$( '[aria-invalid]', this ).attr( 'aria-invalid', 'true' );
} );
} );
$message.addClass( 'wpcf7-validation-errors' );
$form.addClass( 'invalid' );
wpcf7.triggerEvent( data.into, 'invalid', detail );
break;
case 'acceptance_missing':
$message.addClass( 'wpcf7-acceptance-missing' );
$form.addClass( 'unaccepted' );
wpcf7.triggerEvent( data.into, 'unaccepted', detail );
break;
case 'spam':
$message.addClass( 'wpcf7-spam-blocked' );
$form.addClass( 'spam' );
wpcf7.triggerEvent( data.into, 'spam', detail );
break;
case 'aborted':
$message.addClass( 'wpcf7-aborted' );
$form.addClass( 'aborted' );
wpcf7.triggerEvent( data.into, 'aborted', detail );
break;
case 'mail_sent':
$message.addClass( 'wpcf7-mail-sent-ok' );
$form.addClass( 'sent' );
wpcf7.triggerEvent( data.into, 'mailsent', detail );
break;
case 'mail_failed':
$message.addClass( 'wpcf7-mail-sent-ng' );
$form.addClass( 'failed' );
wpcf7.triggerEvent( data.into, 'mailfailed', detail );
break;
default:
var customStatusClass = 'custom-'
+ data.status.replace( /[^0-9a-z]+/i, '-' );
$message.addClass( 'wpcf7-' + customStatusClass );
$form.addClass( customStatusClass );
}
wpcf7.refill( $form, data );
wpcf7.triggerEvent( data.into, 'submit', detail );
if ( 'mail_sent' == data.status ) {
$form.each( function() {
this.reset();
} );
wpcf7.toggleSubmit( $form );
}
if ( ! wpcf7.supportHtml5.placeholder ) {
$form.find( '[placeholder].placeheld' ).each( function( i, n ) {
$( n ).val( $( n ).attr( 'placeholder' ) );
} );
}
$message.html( '' ).append( data.message ).slideDown( 'fast' );
$message.attr( 'role', 'alert' );
$( '.screen-reader-response', $form.closest( '.wpcf7' ) ).each( function() {
var $response = $( this );
$response.html( '' ).attr( 'role', '' ).append( data.message );
if ( data.invalidFields ) {
var $invalids = $( '<ul></ul>' );
$.each( data.invalidFields, function( i, n ) {
if ( n.idref ) {
var $li = $( '<li></li>' ).append( $( '<a></a>' ).attr( 'href', '#' + n.idref ).append( n.message ) );
} else {
var $li = $( '<li></li>' ).append( n.message );
}
$invalids.append( $li );
} );
$response.append( $invalids );
}
$response.attr( 'role', 'alert' ).focus();
} );
};
$.ajax( {
type: 'POST',
url: wpcf7.apiSettings.getRoute(
'/contact-forms/' + wpcf7.getId( $form ) + '/feedback' ),
data: formData,
dataType: 'json',
processData: false,
contentType: false
} ).done( function( data, status, xhr ) {
ajaxSuccess( data, status, xhr, $form );
$( '.ajax-loader', $form ).removeClass( 'is-active' );
} ).fail( function( xhr, status, error ) {
var $e = $( '<div class="ajax-error"></div>' ).text( error.message );
$form.after( $e );
} );
};
wpcf7.triggerEvent = function( target, name, detail ) {
var $target = $( target );
/* DOM event */
var event = new CustomEvent( 'wpcf7' + name, {
bubbles: true,
detail: detail
} );
$target.get( 0 ).dispatchEvent( event );
/* jQuery event */
$target.trigger( 'wpcf7:' + name, detail );
$target.trigger( name + '.wpcf7', detail ); // deprecated
};
wpcf7.toggleSubmit = function( form, state ) {
var $form = $( form );
var $submit = $( 'input:submit', $form );
if ( typeof state !== 'undefined' ) {
$submit.prop( 'disabled', ! state );
return;
}
if ( $form.hasClass( 'wpcf7-acceptance-as-validation' ) ) {
return;
}
$submit.prop( 'disabled', false );
$( '.wpcf7-acceptance', $form ).each( function() {
var $span = $( this );
var $input = $( 'input:checkbox', $span );
if ( ! $span.hasClass( 'optional' ) ) {
if ( $span.hasClass( 'invert' ) && $input.is( ':checked' )
|| ! $span.hasClass( 'invert' ) && ! $input.is( ':checked' ) ) {
$submit.prop( 'disabled', true );
return false;
}
}
} );
};
wpcf7.notValidTip = function( target, message ) {
var $target = $( target );
$( '.wpcf7-not-valid-tip', $target ).remove();
$( '<span role="alert" class="wpcf7-not-valid-tip"></span>' )
.text( message ).appendTo( $target );
if ( $target.is( '.use-floating-validation-tip *' ) ) {
var fadeOut = function( target ) {
$( target ).not( ':hidden' ).animate( {
opacity: 0
}, 'fast', function() {
$( this ).css( { 'z-index': -100 } );
} );
};
$target.on( 'mouseover', '.wpcf7-not-valid-tip', function() {
fadeOut( this );
} );
$target.on( 'focus', ':input', function() {
fadeOut( $( '.wpcf7-not-valid-tip', $target ) );
} );
}
};
wpcf7.refill = function( form, data ) {
var $form = $( form );
var refillCaptcha = function( $form, items ) {
$.each( items, function( i, n ) {
$form.find( ':input[name="' + i + '"]' ).val( '' );
$form.find( 'img.wpcf7-captcha-' + i ).attr( 'src', n );
var match = /([0-9]+)\.(png|gif|jpeg)$/.exec( n );
$form.find( 'input:hidden[name="_wpcf7_captcha_challenge_' + i + '"]' ).attr( 'value', match[ 1 ] );
} );
};
var refillQuiz = function( $form, items ) {
$.each( items, function( i, n ) {
$form.find( ':input[name="' + i + '"]' ).val( '' );
$form.find( ':input[name="' + i + '"]' ).siblings( 'span.wpcf7-quiz-label' ).text( n[ 0 ] );
$form.find( 'input:hidden[name="_wpcf7_quiz_answer_' + i + '"]' ).attr( 'value', n[ 1 ] );
} );
};
if ( typeof data === 'undefined' ) {
$.ajax( {
type: 'GET',
url: wpcf7.apiSettings.getRoute(
'/contact-forms/' + wpcf7.getId( $form ) + '/refill' ),
beforeSend: function( xhr ) {
var nonce = $form.find( ':input[name="_wpnonce"]' ).val();
if ( nonce ) {
xhr.setRequestHeader( 'X-WP-Nonce', nonce );
}
},
dataType: 'json'
} ).done( function( data, status, xhr ) {
if ( data.captcha ) {
refillCaptcha( $form, data.captcha );
}
if ( data.quiz ) {
refillQuiz( $form, data.quiz );
}
} );
} else {
if ( data.captcha ) {
refillCaptcha( $form, data.captcha );
}
if ( data.quiz ) {
refillQuiz( $form, data.quiz );
}
}
};
wpcf7.clearResponse = function( form ) {
var $form = $( form );
$form.removeClass( 'invalid spam sent failed' );
$form.siblings( '.screen-reader-response' ).html( '' ).attr( 'role', '' );
$( '.wpcf7-not-valid-tip', $form ).remove();
$( '[aria-invalid]', $form ).attr( 'aria-invalid', 'false' );
$( '.wpcf7-form-control', $form ).removeClass( 'wpcf7-not-valid' );
$( '.wpcf7-response-output', $form )
.hide().empty().removeAttr( 'role' )
.removeClass( 'wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked' );
};
wpcf7.apiSettings.getRoute = function( path ) {
var url = wpcf7.apiSettings.root;
url = url.replace(
wpcf7.apiSettings.namespace,
wpcf7.apiSettings.namespace + path );
return url;
};
} )( jQuery );
/*
* Polyfill for Internet Explorer
* See https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
*/
( function () {
if ( typeof window.CustomEvent === "function" ) return false;
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event,
params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
} )();

View File

@ -0,0 +1,98 @@
<?php
function wpcf7_l10n() {
static $l10n = array();
if ( ! empty( $l10n ) ) {
return $l10n;
}
if ( ! is_admin() ) {
return $l10n;
}
require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
$api = translations_api( 'plugins', array(
'slug' => 'contact-form-7',
'version' => WPCF7_VERSION,
) );
if ( is_wp_error( $api )
or empty( $api['translations'] ) ) {
return $l10n;
}
foreach ( (array) $api['translations'] as $translation ) {
if ( ! empty( $translation['language'] )
and ! empty( $translation['english_name'] ) ) {
$l10n[$translation['language']] = $translation['english_name'];
}
}
return $l10n;
}
function wpcf7_is_valid_locale( $locale ) {
$pattern = '/^[a-z]{2,3}(?:_[a-zA-Z_]{2,})?$/';
return (bool) preg_match( $pattern, $locale );
}
function wpcf7_is_rtl( $locale = '' ) {
static $rtl_locales = array(
'ar' => 'Arabic',
'ary' => 'Moroccan Arabic',
'azb' => 'South Azerbaijani',
'fa_IR' => 'Persian',
'haz' => 'Hazaragi',
'he_IL' => 'Hebrew',
'ps' => 'Pashto',
'ug_CN' => 'Uighur',
);
if ( empty( $locale )
and function_exists( 'is_rtl' ) ) {
return is_rtl();
}
if ( empty( $locale ) ) {
$locale = get_locale();
}
return isset( $rtl_locales[$locale] );
}
function wpcf7_load_textdomain( $locale = null ) {
global $l10n;
$domain = 'contact-form-7';
if ( ( is_admin() ? get_user_locale() : get_locale() ) === $locale ) {
$locale = null;
}
if ( empty( $locale ) ) {
if ( is_textdomain_loaded( $domain ) ) {
return true;
} else {
return load_plugin_textdomain( $domain, false, $domain . '/languages' );
}
} else {
$mo_orig = $l10n[$domain];
unload_textdomain( $domain );
$mofile = $domain . '-' . $locale . '.mo';
$path = WP_PLUGIN_DIR . '/' . $domain . '/languages';
if ( $loaded = load_textdomain( $domain, $path . '/'. $mofile ) ) {
return $loaded;
} else {
$mofile = WP_LANG_DIR . '/plugins/' . $mofile;
return load_textdomain( $domain, $mofile );
}
$l10n[$domain] = $mo_orig;
}
return false;
}

View File

@ -0,0 +1,448 @@
<?php
class WPCF7_Mail {
private static $current = null;
private $name = '';
private $locale = '';
private $template = array();
private $use_html = false;
private $exclude_blank = false;
public static function get_current() {
return self::$current;
}
public static function send( $template, $name = '' ) {
self::$current = new self( $name, $template );
return self::$current->compose();
}
private function __construct( $name, $template ) {
$this->name = trim( $name );
$this->use_html = ! empty( $template['use_html'] );
$this->exclude_blank = ! empty( $template['exclude_blank'] );
$this->template = wp_parse_args( $template, array(
'subject' => '',
'sender' => '',
'body' => '',
'recipient' => '',
'additional_headers' => '',
'attachments' => '',
) );
if ( $submission = WPCF7_Submission::get_instance() ) {
$contact_form = $submission->get_contact_form();
$this->locale = $contact_form->locale();
}
}
public function name() {
return $this->name;
}
public function get( $component, $replace_tags = false ) {
$use_html = ( $this->use_html && 'body' == $component );
$exclude_blank = ( $this->exclude_blank && 'body' == $component );
$template = $this->template;
$component = isset( $template[$component] ) ? $template[$component] : '';
if ( $replace_tags ) {
$component = $this->replace_tags( $component, array(
'html' => $use_html,
'exclude_blank' => $exclude_blank,
) );
if ( $use_html
and ! preg_match( '%<html[>\s].*</html>%is', $component ) ) {
$component = $this->htmlize( $component );
}
}
return $component;
}
private function htmlize( $body ) {
if ( $this->locale ) {
$lang_atts = sprintf( ' %s',
wpcf7_format_atts( array(
'dir' => wpcf7_is_rtl( $this->locale ) ? 'rtl' : 'ltr',
'lang' => str_replace( '_', '-', $this->locale ),
) )
);
} else {
$lang_atts = '';
}
$header = apply_filters( 'wpcf7_mail_html_header',
'<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml"' . $lang_atts . '>
<head>
<title>' . esc_html( $this->get( 'subject', true ) ) . '</title>
</head>
<body>
', $this );
$footer = apply_filters( 'wpcf7_mail_html_footer',
'</body>
</html>', $this );
$html = $header . wpautop( $body ) . $footer;
return $html;
}
private function compose( $send = true ) {
$components = array(
'subject' => $this->get( 'subject', true ),
'sender' => $this->get( 'sender', true ),
'body' => $this->get( 'body', true ),
'recipient' => $this->get( 'recipient', true ),
'additional_headers' => $this->get( 'additional_headers', true ),
'attachments' => $this->attachments(),
);
$components = apply_filters( 'wpcf7_mail_components',
$components, wpcf7_get_current_contact_form(), $this );
if ( ! $send ) {
return $components;
}
$subject = wpcf7_strip_newline( $components['subject'] );
$sender = wpcf7_strip_newline( $components['sender'] );
$recipient = wpcf7_strip_newline( $components['recipient'] );
$body = $components['body'];
$additional_headers = trim( $components['additional_headers'] );
$attachments = $components['attachments'];
$headers = "From: $sender\n";
if ( $this->use_html ) {
$headers .= "Content-Type: text/html\n";
$headers .= "X-WPCF7-Content-Type: text/html\n";
} else {
$headers .= "X-WPCF7-Content-Type: text/plain\n";
}
if ( $additional_headers ) {
$headers .= $additional_headers . "\n";
}
return wp_mail( $recipient, $subject, $body, $headers, $attachments );
}
public function replace_tags( $content, $args = '' ) {
if ( true === $args ) {
$args = array( 'html' => true );
}
$args = wp_parse_args( $args, array(
'html' => false,
'exclude_blank' => false,
) );
return wpcf7_mail_replace_tags( $content, $args );
}
private function attachments( $template = null ) {
if ( ! $template ) {
$template = $this->get( 'attachments' );
}
$attachments = array();
if ( $submission = WPCF7_Submission::get_instance() ) {
$uploaded_files = $submission->uploaded_files();
foreach ( (array) $uploaded_files as $name => $path ) {
if ( false !== strpos( $template, "[${name}]" )
and ! empty( $path ) ) {
$attachments[] = $path;
}
}
}
foreach ( explode( "\n", $template ) as $line ) {
$line = trim( $line );
if ( '[' == substr( $line, 0, 1 ) ) {
continue;
}
$path = path_join( WP_CONTENT_DIR, $line );
if ( ! wpcf7_is_file_path_in_content_dir( $path ) ) {
// $path is out of WP_CONTENT_DIR
continue;
}
if ( is_readable( $path )
and is_file( $path ) ) {
$attachments[] = $path;
}
}
return $attachments;
}
}
function wpcf7_mail_replace_tags( $content, $args = '' ) {
$args = wp_parse_args( $args, array(
'html' => false,
'exclude_blank' => false,
) );
if ( is_array( $content ) ) {
foreach ( $content as $key => $value ) {
$content[$key] = wpcf7_mail_replace_tags( $value, $args );
}
return $content;
}
$content = explode( "\n", $content );
foreach ( $content as $num => $line ) {
$line = new WPCF7_MailTaggedText( $line, $args );
$replaced = $line->replace_tags();
if ( $args['exclude_blank'] ) {
$replaced_tags = $line->get_replaced_tags();
if ( empty( $replaced_tags )
or array_filter( $replaced_tags ) ) {
$content[$num] = $replaced;
} else {
unset( $content[$num] ); // Remove a line.
}
} else {
$content[$num] = $replaced;
}
}
$content = implode( "\n", $content );
return $content;
}
add_action( 'phpmailer_init', 'wpcf7_phpmailer_init', 10, 1 );
function wpcf7_phpmailer_init( $phpmailer ) {
$custom_headers = $phpmailer->getCustomHeaders();
$phpmailer->clearCustomHeaders();
$wpcf7_content_type = false;
foreach ( (array) $custom_headers as $custom_header ) {
$name = $custom_header[0];
$value = $custom_header[1];
if ( 'X-WPCF7-Content-Type' === $name ) {
$wpcf7_content_type = trim( $value );
} else {
$phpmailer->addCustomHeader( $name, $value );
}
}
if ( 'text/html' === $wpcf7_content_type ) {
$phpmailer->msgHTML( $phpmailer->Body );
} elseif ( 'text/plain' === $wpcf7_content_type ) {
$phpmailer->AltBody = '';
}
}
class WPCF7_MailTaggedText {
private $html = false;
private $callback = null;
private $content = '';
private $replaced_tags = array();
public function __construct( $content, $args = '' ) {
$args = wp_parse_args( $args, array(
'html' => false,
'callback' => null,
) );
$this->html = (bool) $args['html'];
if ( null !== $args['callback']
and is_callable( $args['callback'] ) ) {
$this->callback = $args['callback'];
} elseif ( $this->html ) {
$this->callback = array( $this, 'replace_tags_callback_html' );
} else {
$this->callback = array( $this, 'replace_tags_callback' );
}
$this->content = $content;
}
public function get_replaced_tags() {
return $this->replaced_tags;
}
public function replace_tags() {
$regex = '/(\[?)\[[\t ]*'
. '([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name
. '((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values
. '[\t ]*\](\]?)/';
return preg_replace_callback( $regex, $this->callback, $this->content );
}
private function replace_tags_callback_html( $matches ) {
return $this->replace_tags_callback( $matches, true );
}
private function replace_tags_callback( $matches, $html = false ) {
// allow [[foo]] syntax for escaping a tag
if ( $matches[1] == '['
and $matches[4] == ']' ) {
return substr( $matches[0], 1, -1 );
}
$tag = $matches[0];
$tagname = $matches[2];
$values = $matches[3];
$mail_tag = new WPCF7_MailTag( $tag, $tagname, $values );
$field_name = $mail_tag->field_name();
$submission = WPCF7_Submission::get_instance();
$submitted = $submission
? $submission->get_posted_data( $field_name )
: null;
if ( null !== $submitted ) {
if ( $mail_tag->get_option( 'do_not_heat' ) ) {
$submitted = isset( $_POST[$field_name] ) ? $_POST[$field_name] : '';
}
$replaced = $submitted;
if ( $format = $mail_tag->get_option( 'format' ) ) {
$replaced = $this->format( $replaced, $format );
}
$replaced = wpcf7_flat_join( $replaced );
if ( $html ) {
$replaced = esc_html( $replaced );
$replaced = wptexturize( $replaced );
}
if ( $form_tag = $mail_tag->corresponding_form_tag() ) {
$type = $form_tag->type;
$replaced = apply_filters(
"wpcf7_mail_tag_replaced_{$type}", $replaced,
$submitted, $html, $mail_tag );
}
$replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced,
$submitted, $html, $mail_tag );
$replaced = wp_unslash( trim( $replaced ) );
$this->replaced_tags[$tag] = $replaced;
return $replaced;
}
$special = apply_filters( 'wpcf7_special_mail_tags', null,
$mail_tag->tag_name(), $html, $mail_tag );
if ( null !== $special ) {
$this->replaced_tags[$tag] = $special;
return $special;
}
return $tag;
}
public function format( $original, $format ) {
$original = (array) $original;
foreach ( $original as $key => $value ) {
if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $value ) ) {
$original[$key] = mysql2date( $format, $value );
}
}
return $original;
}
}
class WPCF7_MailTag {
private $tag;
private $tagname = '';
private $name = '';
private $options = array();
private $values = array();
private $form_tag = null;
public function __construct( $tag, $tagname, $values ) {
$this->tag = $tag;
$this->name = $this->tagname = $tagname;
$this->options = array(
'do_not_heat' => false,
'format' => '',
);
if ( ! empty( $values ) ) {
preg_match_all( '/"[^"]*"|\'[^\']*\'/', $values, $matches );
$this->values = wpcf7_strip_quote_deep( $matches[0] );
}
if ( preg_match( '/^_raw_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['do_not_heat'] = true;
}
if ( preg_match( '/^_format_(.+)$/', $tagname, $matches ) ) {
$this->name = trim( $matches[1] );
$this->options['format'] = $this->values[0];
}
}
public function tag_name() {
return $this->tagname;
}
public function field_name() {
return $this->name;
}
public function get_option( $option ) {
return $this->options[$option];
}
public function values() {
return $this->values;
}
public function corresponding_form_tag() {
if ( $this->form_tag instanceof WPCF7_FormTag ) {
return $this->form_tag;
}
if ( $submission = WPCF7_Submission::get_instance() ) {
$contact_form = $submission->get_contact_form();
$tags = $contact_form->scan_form_tags( array(
'name' => $this->name,
'feature' => '! zero-controls-container',
) );
if ( $tags ) {
$this->form_tag = $tags[0];
}
}
return $this->form_tag;
}
}

View File

@ -0,0 +1,78 @@
<?php
class WPCF7_Pipe {
public $before = '';
public $after = '';
public function __construct( $text ) {
$text = (string) $text;
$pipe_pos = strpos( $text, '|' );
if ( false === $pipe_pos ) {
$this->before = $this->after = trim( $text );
} else {
$this->before = trim( substr( $text, 0, $pipe_pos ) );
$this->after = trim( substr( $text, $pipe_pos + 1 ) );
}
}
}
class WPCF7_Pipes {
private $pipes = array();
public function __construct( array $texts ) {
foreach ( $texts as $text ) {
$this->add_pipe( $text );
}
}
private function add_pipe( $text ) {
$pipe = new WPCF7_Pipe( $text );
$this->pipes[] = $pipe;
}
public function do_pipe( $before ) {
foreach ( $this->pipes as $pipe ) {
if ( $pipe->before == $before ) {
return $pipe->after;
}
}
return $before;
}
public function collect_befores() {
$befores = array();
foreach ( $this->pipes as $pipe ) {
$befores[] = $pipe->before;
}
return $befores;
}
public function collect_afters() {
$afters = array();
foreach ( $this->pipes as $pipe ) {
$afters[] = $pipe->after;
}
return $afters;
}
public function zero() {
return empty( $this->pipes );
}
public function random_pipe() {
if ( $this->zero() ) {
return null;
}
return $this->pipes[array_rand( $this->pipes )];
}
}

View File

@ -0,0 +1,323 @@
<?php
add_action( 'rest_api_init', 'wpcf7_rest_api_init', 10, 0 );
function wpcf7_rest_api_init() {
$namespace = 'contact-form-7/v1';
register_rest_route( $namespace,
'/contact-forms',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'wpcf7_rest_get_contact_forms',
),
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'wpcf7_rest_create_contact_form',
),
)
);
register_rest_route( $namespace,
'/contact-forms/(?P<id>\d+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'wpcf7_rest_get_contact_form',
),
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => 'wpcf7_rest_update_contact_form',
),
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => 'wpcf7_rest_delete_contact_form',
),
)
);
register_rest_route( $namespace,
'/contact-forms/(?P<id>\d+)/feedback',
array(
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'wpcf7_rest_create_feedback',
),
)
);
register_rest_route( $namespace,
'/contact-forms/(?P<id>\d+)/refill',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'wpcf7_rest_get_refill',
),
)
);
}
function wpcf7_rest_get_contact_forms( WP_REST_Request $request ) {
if ( ! current_user_can( 'wpcf7_read_contact_forms' ) ) {
return new WP_Error( 'wpcf7_forbidden',
__( "You are not allowed to access contact forms.", 'contact-form-7' ),
array( 'status' => 403 ) );
}
$args = array();
$per_page = $request->get_param( 'per_page' );
if ( null !== $per_page ) {
$args['posts_per_page'] = (int) $per_page;
}
$offset = $request->get_param( 'offset' );
if ( null !== $offset ) {
$args['offset'] = (int) $offset;
}
$order = $request->get_param( 'order' );
if ( null !== $order ) {
$args['order'] = (string) $order;
}
$orderby = $request->get_param( 'orderby' );
if ( null !== $orderby ) {
$args['orderby'] = (string) $orderby;
}
$search = $request->get_param( 'search' );
if ( null !== $search ) {
$args['s'] = (string) $search;
}
$items = WPCF7_ContactForm::find( $args );
$response = array();
foreach ( $items as $item ) {
$response[] = array(
'id' => $item->id(),
'slug' => $item->name(),
'title' => $item->title(),
'locale' => $item->locale(),
);
}
return rest_ensure_response( $response );
}
function wpcf7_rest_create_contact_form( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
if ( $id ) {
return new WP_Error( 'wpcf7_post_exists',
__( "Cannot create existing contact form.", 'contact-form-7' ),
array( 'status' => 400 ) );
}
if ( ! current_user_can( 'wpcf7_edit_contact_forms' ) ) {
return new WP_Error( 'wpcf7_forbidden',
__( "You are not allowed to create a contact form.", 'contact-form-7' ),
array( 'status' => 403 ) );
}
$args = $request->get_params();
$args['id'] = -1; // Create
$context = $request->get_param( 'context' );
$item = wpcf7_save_contact_form( $args, $context );
if ( ! $item ) {
return new WP_Error( 'wpcf7_cannot_save',
__( "There was an error saving the contact form.", 'contact-form-7' ),
array( 'status' => 500 ) );
}
$response = array(
'id' => $item->id(),
'slug' => $item->name(),
'title' => $item->title(),
'locale' => $item->locale(),
'properties' => $item->get_properties(),
'config_errors' => array(),
);
if ( wpcf7_validate_configuration() ) {
$config_validator = new WPCF7_ConfigValidator( $item );
$config_validator->validate();
$response['config_errors'] = $config_validator->collect_error_messages();
if ( 'save' == $context ) {
$config_validator->save();
}
}
return rest_ensure_response( $response );
}
function wpcf7_rest_get_contact_form( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 ) );
}
if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) {
return new WP_Error( 'wpcf7_forbidden',
__( "You are not allowed to access the requested contact form.", 'contact-form-7' ),
array( 'status' => 403 ) );
}
$response = array(
'id' => $item->id(),
'slug' => $item->name(),
'title' => $item->title(),
'locale' => $item->locale(),
'properties' => $item->get_properties(),
);
return rest_ensure_response( $response );
}
function wpcf7_rest_update_contact_form( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 ) );
}
if ( ! current_user_can( 'wpcf7_edit_contact_form', $id ) ) {
return new WP_Error( 'wpcf7_forbidden',
__( "You are not allowed to access the requested contact form.", 'contact-form-7' ),
array( 'status' => 403 ) );
}
$args = $request->get_params();
$context = $request->get_param( 'context' );
$item = wpcf7_save_contact_form( $args, $context );
if ( ! $item ) {
return new WP_Error( 'wpcf7_cannot_save',
__( "There was an error saving the contact form.", 'contact-form-7' ),
array( 'status' => 500 ) );
}
$response = array(
'id' => $item->id(),
'slug' => $item->name(),
'title' => $item->title(),
'locale' => $item->locale(),
'properties' => $item->get_properties(),
'config_errors' => array(),
);
if ( wpcf7_validate_configuration() ) {
$config_validator = new WPCF7_ConfigValidator( $item );
$config_validator->validate();
$response['config_errors'] = $config_validator->collect_error_messages();
if ( 'save' == $context ) {
$config_validator->save();
}
}
return rest_ensure_response( $response );
}
function wpcf7_rest_delete_contact_form( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 ) );
}
if ( ! current_user_can( 'wpcf7_delete_contact_form', $id ) ) {
return new WP_Error( 'wpcf7_forbidden',
__( "You are not allowed to access the requested contact form.", 'contact-form-7' ),
array( 'status' => 403 ) );
}
$result = $item->delete();
if ( ! $result ) {
return new WP_Error( 'wpcf7_cannot_delete',
__( "There was an error deleting the contact form.", 'contact-form-7' ),
array( 'status' => 500 ) );
}
$response = array( 'deleted' => true );
return rest_ensure_response( $response );
}
function wpcf7_rest_create_feedback( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 ) );
}
$result = $item->submit();
$unit_tag = $request->get_param( '_wpcf7_unit_tag' );
$response = array(
'into' => '#' . wpcf7_sanitize_unit_tag( $unit_tag ),
'status' => $result['status'],
'message' => $result['message'],
);
if ( 'validation_failed' == $result['status'] ) {
$invalid_fields = array();
foreach ( (array) $result['invalid_fields'] as $name => $field ) {
$invalid_fields[] = array(
'into' => 'span.wpcf7-form-control-wrap.'
. sanitize_html_class( $name ),
'message' => $field['reason'],
'idref' => $field['idref'],
);
}
$response['invalidFields'] = $invalid_fields;
}
$response = apply_filters( 'wpcf7_ajax_json_echo', $response, $result );
return rest_ensure_response( $response );
}
function wpcf7_rest_get_refill( WP_REST_Request $request ) {
$id = (int) $request->get_param( 'id' );
$item = wpcf7_contact_form( $id );
if ( ! $item ) {
return new WP_Error( 'wpcf7_not_found',
__( "The requested contact form was not found.", 'contact-form-7' ),
array( 'status' => 404 ) );
}
$response = apply_filters( 'wpcf7_ajax_onload', array() );
return rest_ensure_response( $response );
}

View File

@ -0,0 +1,101 @@
<?php
/**
* All the functions and classes in this file are deprecated.
* You shouldn't use them. The functions and classes will be
* removed in a later version.
*/
function wpcf7_add_shortcode( $tag, $func, $has_name = false ) {
wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_add_form_tag' );
return wpcf7_add_form_tag( $tag, $func, $has_name );
}
function wpcf7_remove_shortcode( $tag ) {
wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_remove_form_tag' );
return wpcf7_remove_form_tag( $tag );
}
function wpcf7_do_shortcode( $content ) {
wpcf7_deprecated_function( __FUNCTION__, '4.6',
'wpcf7_replace_all_form_tags' );
return wpcf7_replace_all_form_tags( $content );
}
function wpcf7_scan_shortcode( $cond = null ) {
wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_scan_form_tags' );
return wpcf7_scan_form_tags( $cond );
}
class WPCF7_ShortcodeManager {
private static $form_tags_manager;
private function __construct() {}
public static function get_instance() {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::get_instance' );
self::$form_tags_manager = WPCF7_FormTagsManager::get_instance();
return new self;
}
public function get_scanned_tags() {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::get_scanned_tags' );
return self::$form_tags_manager->get_scanned_tags();
}
public function add_shortcode( $tag, $func, $has_name = false ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::add' );
return self::$form_tags_manager->add( $tag, $func, $has_name );
}
public function remove_shortcode( $tag ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::remove' );
return self::$form_tags_manager->remove( $tag );
}
public function normalize_shortcode( $content ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::normalize' );
return self::$form_tags_manager->normalize( $content );
}
public function do_shortcode( $content, $exec = true ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::replace_all' );
if ( $exec ) {
return self::$form_tags_manager->replace_all( $content );
} else {
return self::$form_tags_manager->scan( $content );
}
}
public function scan_shortcode( $content ) {
wpcf7_deprecated_function( __METHOD__, '4.6',
'WPCF7_FormTagsManager::scan' );
return self::$form_tags_manager->scan( $content );
}
}
class WPCF7_Shortcode extends WPCF7_FormTag {
public function __construct( $tag ) {
wpcf7_deprecated_function( 'WPCF7_Shortcode', '4.6', 'WPCF7_FormTag' );
parent::__construct( $tag );
}
}

View File

@ -0,0 +1,168 @@
<?php
/**
** Special Mail Tags
** https://contactform7.com/special-mail-tags/
**/
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_special_mail_tag', 10, 3 );
function wpcf7_special_mail_tag( $output, $name, $html ) {
$name = preg_replace( '/^wpcf7\./', '_', $name ); // for back-compat
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
return $output;
}
if ( '_remote_ip' == $name ) {
if ( $remote_ip = $submission->get_meta( 'remote_ip' ) ) {
return $remote_ip;
} else {
return '';
}
}
if ( '_user_agent' == $name ) {
if ( $user_agent = $submission->get_meta( 'user_agent' ) ) {
return $html ? esc_html( $user_agent ) : $user_agent;
} else {
return '';
}
}
if ( '_url' == $name ) {
if ( $url = $submission->get_meta( 'url' ) ) {
return esc_url( $url );
} else {
return '';
}
}
if ( '_date' == $name
or '_time' == $name ) {
if ( $timestamp = $submission->get_meta( 'timestamp' ) ) {
if ( '_date' == $name ) {
return date_i18n( get_option( 'date_format' ), $timestamp );
}
if ( '_time' == $name ) {
return date_i18n( get_option( 'time_format' ), $timestamp );
}
}
return '';
}
if ( '_invalid_fields' == $name ) {
return count( $submission->get_invalid_fields() );
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_post_related_smt', 10, 3 );
function wpcf7_post_related_smt( $output, $name, $html ) {
if ( '_post_' != substr( $name, 0, 6 ) ) {
return $output;
}
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
return $output;
}
$post_id = (int) $submission->get_meta( 'container_post_id' );
if ( ! $post_id
or ! $post = get_post( $post_id ) ) {
return '';
}
if ( '_post_id' == $name ) {
return (string) $post->ID;
}
if ( '_post_name' == $name ) {
return $post->post_name;
}
if ( '_post_title' == $name ) {
return $html ? esc_html( $post->post_title ) : $post->post_title;
}
if ( '_post_url' == $name ) {
return get_permalink( $post->ID );
}
$user = new WP_User( $post->post_author );
if ( '_post_author' == $name ) {
return $user->display_name;
}
if ( '_post_author_email' == $name ) {
return $user->user_email;
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_site_related_smt', 10, 3 );
function wpcf7_site_related_smt( $output, $name, $html ) {
$filter = $html ? 'display' : 'raw';
if ( '_site_title' == $name ) {
return get_bloginfo( 'name', $filter );
}
if ( '_site_description' == $name ) {
return get_bloginfo( 'description', $filter );
}
if ( '_site_url' == $name ) {
return get_bloginfo( 'url', $filter );
}
if ( '_site_admin_email' == $name ) {
return get_bloginfo( 'admin_email', $filter );
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'wpcf7_user_related_smt', 10, 3 );
function wpcf7_user_related_smt( $output, $name, $html ) {
if ( '_user_' != substr( $name, 0, 6 )
or '_user_agent' == $name ) {
return $output;
}
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
return $output;
}
$user_id = (int) $submission->get_meta( 'current_user_id' );
if ( ! $user_id ) {
return '';
}
$primary_props = array( 'user_login', 'user_email', 'user_url' );
$opt = ltrim( $name, '_' );
$opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
$user = new WP_User( $user_id );
if ( $user->has_prop( $opt ) ) {
return $user->get( $opt );
}
return '';
}

View File

@ -0,0 +1,412 @@
<?php
class WPCF7_Submission {
private static $instance;
private $contact_form;
private $status = 'init';
private $posted_data = array();
private $uploaded_files = array();
private $skip_mail = false;
private $response = '';
private $invalid_fields = array();
private $meta = array();
private $consent = array();
private function __construct() {}
public static function get_instance( WPCF7_ContactForm $contact_form = null, $args = '' ) {
$args = wp_parse_args( $args, array(
'skip_mail' => false,
) );
if ( empty( self::$instance ) ) {
if ( null == $contact_form ) {
return null;
}
self::$instance = new self;
self::$instance->contact_form = $contact_form;
self::$instance->skip_mail = (bool) $args['skip_mail'];
self::$instance->setup_posted_data();
self::$instance->submit();
} elseif ( null != $contact_form ) {
return null;
}
return self::$instance;
}
public static function is_restful() {
return defined( 'REST_REQUEST' ) && REST_REQUEST;
}
public function get_status() {
return $this->status;
}
public function set_status( $status ) {
if ( preg_match( '/^[a-z][0-9a-z_]+$/', $status ) ) {
$this->status = $status;
return true;
}
return false;
}
public function is( $status ) {
return $this->status == $status;
}
public function get_response() {
return $this->response;
}
public function set_response( $response ) {
$this->response = $response;
return true;
}
public function get_contact_form() {
return $this->contact_form;
}
public function get_invalid_field( $name ) {
if ( isset( $this->invalid_fields[$name] ) ) {
return $this->invalid_fields[$name];
} else {
return false;
}
}
public function get_invalid_fields() {
return $this->invalid_fields;
}
public function get_posted_data( $name = '' ) {
if ( ! empty( $name ) ) {
if ( isset( $this->posted_data[$name] ) ) {
return $this->posted_data[$name];
} else {
return null;
}
}
return $this->posted_data;
}
private function setup_posted_data() {
$posted_data = (array) $_POST;
$posted_data = array_diff_key( $posted_data, array( '_wpnonce' => '' ) );
$posted_data = $this->sanitize_posted_data( $posted_data );
$tags = $this->contact_form->scan_form_tags();
foreach ( (array) $tags as $tag ) {
if ( empty( $tag->name ) ) {
continue;
}
$type = $tag->type;
$name = $tag->name;
$pipes = $tag->pipes;
$value_orig = $value = '';
if ( isset( $posted_data[$name] ) ) {
$value_orig = $value = $posted_data[$name];
}
if ( WPCF7_USE_PIPE
and $pipes instanceof WPCF7_Pipes
and ! $pipes->zero() ) {
if ( is_array( $value_orig ) ) {
$value = array();
foreach ( $value_orig as $v ) {
$value[] = $pipes->do_pipe( wp_unslash( $v ) );
}
} else {
$value = $pipes->do_pipe( wp_unslash( $value_orig ) );
}
}
$value = apply_filters( "wpcf7_posted_data_{$type}", $value,
$value_orig, $tag );
$posted_data[$name] = $value;
if ( $tag->has_option( 'consent_for:storage' )
and empty( $posted_data[$name] ) ) {
$this->meta['do_not_store'] = true;
}
}
$this->posted_data = apply_filters( 'wpcf7_posted_data', $posted_data );
return $this->posted_data;
}
private function sanitize_posted_data( $value ) {
if ( is_array( $value ) ) {
$value = array_map( array( $this, 'sanitize_posted_data' ), $value );
} elseif ( is_string( $value ) ) {
$value = wp_check_invalid_utf8( $value );
$value = wp_kses_no_null( $value );
}
return $value;
}
private function submit() {
if ( ! $this->is( 'init' ) ) {
return $this->status;
}
$this->meta = array_merge( $this->meta, array(
'remote_ip' => $this->get_remote_ip_addr(),
'user_agent' => isset( $_SERVER['HTTP_USER_AGENT'] )
? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '',
'url' => $this->get_request_url(),
'timestamp' => current_time( 'timestamp' ),
'unit_tag' =>
isset( $_POST['_wpcf7_unit_tag'] ) ? $_POST['_wpcf7_unit_tag'] : '',
'container_post_id' => isset( $_POST['_wpcf7_container_post'] )
? (int) $_POST['_wpcf7_container_post'] : 0,
'current_user_id' => get_current_user_id(),
) );
$contact_form = $this->contact_form;
if ( $contact_form->is_true( 'do_not_store' ) ) {
$this->meta['do_not_store'] = true;
}
if ( ! $this->validate() ) { // Validation error occured
$this->set_status( 'validation_failed' );
$this->set_response( $contact_form->message( 'validation_error' ) );
} elseif ( ! $this->accepted() ) { // Not accepted terms
$this->set_status( 'acceptance_missing' );
$this->set_response( $contact_form->message( 'accept_terms' ) );
} elseif ( $this->spam() ) { // Spam!
$this->set_status( 'spam' );
$this->set_response( $contact_form->message( 'spam' ) );
} elseif ( ! $this->before_send_mail() ) {
if ( 'init' == $this->get_status() ) {
$this->set_status( 'aborted' );
}
if ( '' === $this->get_response() ) {
$this->set_response( $contact_form->filter_message(
__( "Sending mail has been aborted.", 'contact-form-7' ) )
);
}
} elseif ( $this->mail() ) {
$this->set_status( 'mail_sent' );
$this->set_response( $contact_form->message( 'mail_sent_ok' ) );
do_action( 'wpcf7_mail_sent', $contact_form );
} else {
$this->set_status( 'mail_failed' );
$this->set_response( $contact_form->message( 'mail_sent_ng' ) );
do_action( 'wpcf7_mail_failed', $contact_form );
}
$this->remove_uploaded_files();
return $this->status;
}
private function get_remote_ip_addr() {
$ip_addr = '';
if ( isset( $_SERVER['REMOTE_ADDR'] )
and WP_Http::is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) {
$ip_addr = $_SERVER['REMOTE_ADDR'];
}
return apply_filters( 'wpcf7_remote_ip_addr', $ip_addr );
}
private function get_request_url() {
$home_url = untrailingslashit( home_url() );
if ( self::is_restful() ) {
$referer = isset( $_SERVER['HTTP_REFERER'] )
? trim( $_SERVER['HTTP_REFERER'] ) : '';
if ( $referer
and 0 === strpos( $referer, $home_url ) ) {
return esc_url_raw( $referer );
}
}
$url = preg_replace( '%(?<!:|/)/.*$%', '', $home_url )
. wpcf7_get_request_uri();
return $url;
}
private function validate() {
if ( $this->invalid_fields ) {
return false;
}
require_once WPCF7_PLUGIN_DIR . '/includes/validation.php';
$result = new WPCF7_Validation();
$tags = $this->contact_form->scan_form_tags();
foreach ( $tags as $tag ) {
$type = $tag->type;
$result = apply_filters( "wpcf7_validate_{$type}", $result, $tag );
}
$result = apply_filters( 'wpcf7_validate', $result, $tags );
$this->invalid_fields = $result->get_invalid_fields();
return $result->is_valid();
}
private function accepted() {
return apply_filters( 'wpcf7_acceptance', true, $this );
}
public function add_consent( $name, $conditions ) {
$this->consent[$name] = $conditions;
return true;
}
public function collect_consent() {
return (array) $this->consent;
}
private function spam() {
$spam = false;
if ( $this->contact_form->is_true( 'subscribers_only' )
and current_user_can( 'wpcf7_submit', $this->contact_form->id() ) ) {
return $spam;
}
$user_agent = (string) $this->get_meta( 'user_agent' );
if ( strlen( $user_agent ) < 2 ) {
$spam = true;
}
if ( ! $this->verify_nonce() ) {
$spam = true;
}
if ( $this->is_blacklisted() ) {
$spam = true;
}
return apply_filters( 'wpcf7_spam', $spam );
}
private function verify_nonce() {
if ( ! $this->contact_form->nonce_is_active() ) {
return true;
}
return wpcf7_verify_nonce( $_POST['_wpnonce'] );
}
private function is_blacklisted() {
$target = wpcf7_array_flatten( $this->posted_data );
$target[] = $this->get_meta( 'remote_ip' );
$target[] = $this->get_meta( 'user_agent' );
$target = implode( "\n", $target );
return (bool) apply_filters( 'wpcf7_submission_is_blacklisted',
wpcf7_blacklist_check( $target ), $this );
}
/* Mail */
private function before_send_mail() {
$abort = false;
do_action_ref_array( 'wpcf7_before_send_mail', array(
$this->contact_form,
&$abort,
$this,
) );
return ! $abort;
}
private function mail() {
$contact_form = $this->contact_form;
$skip_mail = apply_filters( 'wpcf7_skip_mail',
$this->skip_mail, $contact_form );
if ( $skip_mail ) {
return true;
}
$result = WPCF7_Mail::send( $contact_form->prop( 'mail' ), 'mail' );
if ( $result ) {
$additional_mail = array();
if ( $mail_2 = $contact_form->prop( 'mail_2' )
and $mail_2['active'] ) {
$additional_mail['mail_2'] = $mail_2;
}
$additional_mail = apply_filters( 'wpcf7_additional_mail',
$additional_mail, $contact_form );
foreach ( $additional_mail as $name => $template ) {
WPCF7_Mail::send( $template, $name );
}
return true;
}
return false;
}
public function uploaded_files() {
return $this->uploaded_files;
}
public function add_uploaded_file( $name, $file_path ) {
$this->uploaded_files[$name] = $file_path;
if ( empty( $this->posted_data[$name] ) ) {
$this->posted_data[$name] = basename( $file_path );
}
}
public function remove_uploaded_files() {
foreach ( (array) $this->uploaded_files as $name => $path ) {
wpcf7_rmdir_p( $path );
if ( $dir = dirname( $path )
and false !== ( $files = scandir( $dir ) )
and ! array_diff( $files, array( '.', '..' ) ) ) {
// remove parent dir if it's empty.
rmdir( $dir );
}
}
}
public function get_meta( $name ) {
if ( isset( $this->meta[$name] ) ) {
return $this->meta[$name];
}
}
}

View File

@ -0,0 +1,85 @@
<?php
add_action( 'wpcf7_upgrade', 'wpcf7_convert_to_cpt', 10, 2 );
function wpcf7_convert_to_cpt( $new_ver, $old_ver ) {
global $wpdb;
if ( ! version_compare( $old_ver, '3.0-dev', '<' ) ) {
return;
}
$old_rows = array();
$table_name = $wpdb->prefix . "contact_form_7";
if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) ) {
$old_rows = $wpdb->get_results( "SELECT * FROM $table_name" );
} elseif ( $opt = get_option( 'wpcf7' )
and ! empty( $opt['contact_forms'] ) ) {
foreach ( (array) $opt['contact_forms'] as $key => $value ) {
$old_rows[] = (object) array_merge(
$value,
array( 'cf7_unit_id' => $key )
);
}
}
foreach ( (array) $old_rows as $row ) {
$q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
. $wpdb->prepare( " AND meta_value = %d", $row->cf7_unit_id );
if ( $wpdb->get_var( $q ) ) {
continue;
}
$postarr = array(
'post_type' => 'wpcf7_contact_form',
'post_status' => 'publish',
'post_title' => maybe_unserialize( $row->title ),
);
$post_id = wp_insert_post( $postarr );
if ( $post_id ) {
update_post_meta( $post_id, '_old_cf7_unit_id', $row->cf7_unit_id );
$metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
foreach ( $metas as $meta ) {
update_post_meta( $post_id, '_' . $meta,
wpcf7_normalize_newline_deep( maybe_unserialize( $row->{$meta} ) ) );
}
}
}
}
add_action( 'wpcf7_upgrade', 'wpcf7_prepend_underscore', 10, 2 );
function wpcf7_prepend_underscore( $new_ver, $old_ver ) {
if ( version_compare( $old_ver, '3.0-dev', '<' ) ) {
return;
}
if ( ! version_compare( $old_ver, '3.3-dev', '<' ) ) {
return;
}
$posts = WPCF7_ContactForm::find( array(
'post_status' => 'any',
'posts_per_page' => -1,
) );
foreach ( $posts as $post ) {
$props = $post->get_properties();
foreach ( $props as $prop => $value ) {
if ( metadata_exists( 'post', $post->id(), '_' . $prop ) ) {
continue;
}
update_post_meta( $post->id(), '_' . $prop, $value );
delete_post_meta( $post->id(), $prop );
}
}
}

View File

@ -0,0 +1,84 @@
<?php
class WPCF7_Validation implements ArrayAccess {
private $invalid_fields = array();
private $container = array();
public function __construct() {
$this->container = array(
'valid' => true,
'reason' => array(),
'idref' => array(),
);
}
public function invalidate( $context, $message ) {
if ( $context instanceof WPCF7_FormTag ) {
$tag = $context;
} elseif ( is_array( $context ) ) {
$tag = new WPCF7_FormTag( $context );
} elseif ( is_string( $context ) ) {
$tags = wpcf7_scan_form_tags( array( 'name' => trim( $context ) ) );
$tag = $tags ? new WPCF7_FormTag( $tags[0] ) : null;
}
$name = ! empty( $tag ) ? $tag->name : null;
if ( empty( $name )
or ! wpcf7_is_name( $name ) ) {
return;
}
if ( $this->is_valid( $name ) ) {
$id = $tag->get_id_option();
if ( empty( $id )
or ! wpcf7_is_name( $id ) ) {
$id = null;
}
$this->invalid_fields[$name] = array(
'reason' => (string) $message,
'idref' => $id,
);
}
}
public function is_valid( $name = null ) {
if ( ! empty( $name ) ) {
return ! isset( $this->invalid_fields[$name] );
} else {
return empty( $this->invalid_fields );
}
}
public function get_invalid_fields() {
return $this->invalid_fields;
}
public function offsetSet( $offset, $value ) {
if ( isset( $this->container[$offset] ) ) {
$this->container[$offset] = $value;
}
if ( 'reason' == $offset
and is_array( $value ) ) {
foreach ( $value as $k => $v ) {
$this->invalidate( $k, $v );
}
}
}
public function offsetGet( $offset ) {
if ( isset( $this->container[$offset] ) ) {
return $this->container[$offset];
}
}
public function offsetExists( $offset ) {
return isset( $this->container[$offset] );
}
public function offsetUnset( $offset ) {
}
}