controller.php
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
add_action( 'wp_loaded', 'wpcf7_control_init' );
function wpcf7_control_init() {
if ( ! isset( $_SERVER['REQUEST_METHOD'] ) ) {
return;
}
if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) {
if ( isset( $_GET['_wpcf7_is_ajax_call'] ) ) {
wpcf7_ajax_onload();
}
}
if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
if ( isset( $_POST['_wpcf7_is_ajax_call'] ) ) {
wpcf7_ajax_json_echo();
}
wpcf7_submit_nonajax();
}
}
function wpcf7_ajax_onload() {
$echo = '';
$items = array();
if ( isset( $_GET['_wpcf7'] )
&& $contact_form = wpcf7_contact_form( (int) $_GET['_wpcf7'] ) ) {
$items = apply_filters( 'wpcf7_ajax_onload', $items );
}
$echo = wp_json_encode( $items );
if ( wpcf7_is_xhr() ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
echo $echo;
}
exit();
}
function wpcf7_ajax_json_echo() {
$echo = '';
if ( isset( $_POST['_wpcf7'] ) ) {
$id = (int) $_POST['_wpcf7'];
$unit_tag = wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] );
if ( $contact_form = wpcf7_contact_form( $id ) ) {
$items = array(
'mailSent' => false,
'into' => '#' . $unit_tag,
'captcha' => null );
$result = $contact_form->submit( true );
if ( ! empty( $result['message'] ) ) {
$items['message'] = $result['message'];
}
if ( 'mail_sent' == $result['status'] ) {
$items['mailSent'] = true;
}
if ( 'validation_failed' == $result['status'] ) {
$invalids = array();
foreach ( $result['invalid_fields'] as $name => $field ) {
$invalids[] = array(
'into' => 'span.wpcf7-form-control-wrap.'
. sanitize_html_class( $name ),
'message' => $field['reason'],
'idref' => $field['idref'] );
}
$items['invalids'] = $invalids;
}
if ( 'spam' == $result['status'] ) {
$items['spam'] = true;
}
if ( ! empty( $result['scripts_on_sent_ok'] ) ) {
$items['onSentOk'] = $result['scripts_on_sent_ok'];
}
if ( ! empty( $result['scripts_on_submit'] ) ) {
$items['onSubmit'] = $result['scripts_on_submit'];
}
$items = apply_filters( 'wpcf7_ajax_json_echo', $items, $result );
}
}
$echo = wp_json_encode( $items );
if ( wpcf7_is_xhr() ) {
@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
echo $echo;
} else {
@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
echo '<textarea>' . $echo . '</textarea>';
}
exit();
}
function wpcf7_is_xhr() {
if ( ! isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) )
return false;
return $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
}
function wpcf7_submit_nonajax() {
if ( ! isset( $_POST['_wpcf7'] ) )
return;
if ( $contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] ) ) {
$contact_form->submit();
}
}
add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 );
function wpcf7_widget_text_filter( $content ) {
if ( ! preg_match( '/\[[\r\n\t ]*contact-form(-7)?[\r\n\t ].*?\]/', $content ) )
return $content;
$content = do_shortcode( $content );
return $content;
}
add_action( 'wp_enqueue_scripts', 'wpcf7_do_enqueue_scripts' );
function wpcf7_do_enqueue_scripts() {
if ( wpcf7_load_js() ) {
wpcf7_enqueue_scripts();
}
if ( wpcf7_load_css() ) {
wpcf7_enqueue_styles();
}
}
function wpcf7_enqueue_scripts() {
// jquery.form.js originally bundled with WordPress is out of date and deprecated
// so we need to deregister it and re-register the latest one
wp_deregister_script( 'jquery-form' );
wp_register_script( 'jquery-form',
wpcf7_plugin_url( 'includes/js/jquery.form.min.js' ),
array( 'jquery' ), '3.51.0-2014.06.20', true );
$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', 'jquery-form' ), WPCF7_VERSION, $in_footer );
$_wpcf7 = array(
'loaderUrl' => wpcf7_ajax_loader(),
'recaptchaEmpty' =>
__( 'Please verify that you are not a robot.', 'contact-form-7' ),
'sending' => __( 'Sending ...', 'contact-form-7' ) );
if ( defined( 'WP_CACHE' ) && 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 );
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.10.3', 'screen' );
}
}