Contact Form 7 - Version 3.7

Version Description

  • Support free_text option that allows checkbox/radio to have an additional free text field.
  • Restore floating-tip style validation error as an option.
  • Support html_id and html_class attributes in [contact-form-7] shortcode.
  • Fixed bug that Flamingo stored submissions in demo-mode.
  • Fixed bug where auto-p function wrapped [response] with p.
  • The jQuery Form Plugin (jquery.form.js) has been updated to 3.48.0.
  • Translation for Haitian has been created. Translations for German, Hungarian, Czech, Turkish, Lithuanian, French, Basque, and Brazilian Portuguese have been updated.
Download this release

Release Info

Developer takayukister
Plugin Icon 128x128 Contact Form 7
Version 3.7
Comparing to
See all releases

Code changes from version 3.6 to 3.7

admin/admin.php CHANGED
@@ -47,7 +47,7 @@ function wpcf7_set_screen_options( $result, $option, $value ) {
47
}
48
49
function wpcf7_load_contact_form_admin() {
50
- global $wpcf7_contact_form, $plugin_page;
51
52
$action = wpcf7_current_action();
53
@@ -139,8 +139,6 @@ function wpcf7_load_contact_form_admin() {
139
140
$query['post'] = $new_contact_form->id;
141
$query['message'] = 'created';
142
- } else {
143
- $query['post'] = $contact_form->id;
144
}
145
146
$redirect_to = add_query_arg( $query, menu_page_url( 'wpcf7', false ) );
@@ -218,7 +216,9 @@ function wpcf7_load_contact_form_admin() {
218
'option' => 'cfseven_contact_forms_per_page' ) );
219
}
220
221
- $wpcf7_contact_form = $post;
222
}
223
224
add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_scripts' );
@@ -256,10 +256,7 @@ function wpcf7_admin_enqueue_scripts( $hook_suffix ) {
256
}
257
258
function wpcf7_admin_management_page() {
259
- global $wpcf7_contact_form;
260
-
261
- if ( $wpcf7_contact_form ) {
262
- $post =& $wpcf7_contact_form;
263
$post_id = $post->initial ? -1 : $post->id;
264
265
require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
@@ -299,10 +296,7 @@ function wpcf7_admin_management_page() {
299
}
300
301
function wpcf7_admin_add_new_page() {
302
- global $wpcf7_contact_form;
303
-
304
- if ( $wpcf7_contact_form ) {
305
- $post =& $wpcf7_contact_form;
306
$post_id = -1;
307
308
require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
@@ -369,22 +363,6 @@ function wpcf7_add_meta_boxes( $post_id ) {
369
370
/* Misc */
371
372
- add_action( 'wpcf7_admin_notices', 'wpcf7_admin_before_subsubsub' );
373
-
374
- function wpcf7_admin_before_subsubsub() {
375
- // wpcf7_admin_before_subsubsub is deprecated. Use wpcf7_admin_notices instead.
376
-
377
- $current_screen = get_current_screen();
378
-
379
- if ( 'toplevel_page_wpcf7' != $current_screen->id )
380
- return;
381
-
382
- if ( empty( $_GET['post'] ) || ! $contact_form = wpcf7_contact_form( $_GET['post'] ) )
383
- return;
384
-
385
- do_action_ref_array( 'wpcf7_admin_before_subsubsub', array( &$contact_form ) );
386
- }
387
-
388
add_action( 'wpcf7_admin_notices', 'wpcf7_admin_updated_message' );
389
390
function wpcf7_admin_updated_message() {
47
}
48
49
function wpcf7_load_contact_form_admin() {
50
+ global $plugin_page;
51
52
$action = wpcf7_current_action();
53
139
140
$query['post'] = $new_contact_form->id;
141
$query['message'] = 'created';
142
}
143
144
$redirect_to = add_query_arg( $query, menu_page_url( 'wpcf7', false ) );
216
'option' => 'cfseven_contact_forms_per_page' ) );
217
}
218
219
+ if ( $post ) {
220
+ WPCF7_ContactForm::set_current( $post );
221
+ }
222
}
223
224
add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_scripts' );
256
}
257
258
function wpcf7_admin_management_page() {
259
+ if ( $post = wpcf7_get_current_contact_form() ) {
260
$post_id = $post->initial ? -1 : $post->id;
261
262
require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
296
}
297
298
function wpcf7_admin_add_new_page() {
299
+ if ( $post = wpcf7_get_current_contact_form() ) {
300
$post_id = -1;
301
302
require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
363
364
/* Misc */
365
366
add_action( 'wpcf7_admin_notices', 'wpcf7_admin_updated_message' );
367
368
function wpcf7_admin_updated_message() {
admin/css/styles.css CHANGED
@@ -13,34 +13,6 @@ div.wrap div.cf7com-links a {
13
font-weight: bold;
14
}
15
16
- div.wrap div.donation {
17
- border-width: 1px;
18
- border-style: solid;
19
- padding: 0 0.6em;
20
- margin: 5px 0 15px;
21
- -webkit-border-radius: 3px;
22
- border-radius: 3px;
23
- background-color: #ffffe0;
24
- border-color: #e6db55;
25
- }
26
-
27
- div.wrap div.donation p {
28
- margin: .7em 0;
29
- line-height: 1;
30
- padding: 2px;
31
- font-size: 107%;
32
- }
33
-
34
- div.wrap div.donation p a {
35
- color: #3f3f3f;
36
- text-decoration: none;
37
- }
38
-
39
- div.wrap div.donation p a.button {
40
- margin-left: 1em;
41
- font-weight: bold;
42
- }
43
-
44
#titlediv {
45
margin-bottom: 20px;
46
position: relative;
@@ -80,18 +52,19 @@ div.actions-link input.delete {
80
}
81
82
input#wpcf7-title {
83
- color: #555;
84
border: none;
85
- font: bold 20px serif;
86
cursor: pointer;
87
background-color: transparent;
88
box-shadow: none;
89
}
90
91
input#wpcf7-title.focus {
92
- color: #333;
93
border: 1px solid #aaa;
94
- font: normal 13px Verdana, Arial, Helvetica, sans-serif;
95
cursor: text;
96
background-color: transparent;
97
box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
@@ -107,12 +80,7 @@ p.tagcode {
107
}
108
109
input#contact-form-anchor-text, input#contact-form-anchor-text-old {
110
- color: #fff;
111
- background: #7e4e0b;
112
- border: none;
113
width: 100%;
114
- -webkit-border-radius: 6px;
115
- border-radius: 6px;
116
}
117
118
.postbox .half, .postbox .half-left, .postbox .half-right {
@@ -166,12 +134,10 @@ div.tag-generator {
166
}
167
168
div.tg-pane {
169
- border: 1px dashed #999;
170
- background: #f1f1f1;
171
margin: 1ex 0 0 0;
172
padding: 10px;
173
- -webkit-border-radius: 6px;
174
- border-radius: 6px;
175
line-height: 140%;
176
}
177
@@ -200,16 +166,11 @@ div.tg-pane table td {
200
201
div.tg-pane input.tag, div.tg-pane input.mail-tag {
202
width: 100%;
203
- border: none;
204
- color: #fff;
205
- background-color: #7e4e0b;
206
- -webkit-border-radius: 6px;
207
- border-radius: 6px;
208
}
209
210
div.tg-pane input.mail-tag {
211
- width: 50%;
212
- background-color: #404f03;
213
}
214
215
div.tg-mail-tag {
@@ -217,12 +178,6 @@ div.tg-mail-tag {
217
text-align: right;
218
}
219
220
- div.tg-pane span.arrow {
221
- font-family: monospace;
222
- font-size: 1.2em;
223
- color: #333;
224
- }
225
-
226
div.tg-pane input.tg-name {
227
border-color: #555;
228
}
@@ -259,14 +214,24 @@ span.tg-closebutton {
259
}
260
261
div.tg-panetitle {
262
- font: bold 132% sans-serif;
263
- margin: 0 0 10px;
264
- color: #777;
265
}
266
267
input.shortcode-in-list-table {
268
width: 100%;
269
- border: none;
270
}
271
272
/* welcome panel */
13
font-weight: bold;
14
}
15
16
#titlediv {
17
margin-bottom: 20px;
18
position: relative;
52
}
53
54
input#wpcf7-title {
55
+ color: #5f5f5f;
56
border: none;
57
+ font-weight: bold;
58
+ font-size: 1.5em;
59
cursor: pointer;
60
background-color: transparent;
61
box-shadow: none;
62
+ width: 80%;
63
}
64
65
input#wpcf7-title.focus {
66
+ color: #3f3f3f;
67
border: 1px solid #aaa;
68
cursor: text;
69
background-color: transparent;
70
box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
80
}
81
82
input#contact-form-anchor-text, input#contact-form-anchor-text-old {
83
width: 100%;
84
}
85
86
.postbox .half, .postbox .half-left, .postbox .half-right {
134
}
135
136
div.tg-pane {
137
+ border: 1px solid #e1e1e1;
138
+ background: #f7f7f7;
139
margin: 1ex 0 0 0;
140
padding: 10px;
141
line-height: 140%;
142
}
143
166
167
div.tg-pane input.tag, div.tg-pane input.mail-tag {
168
width: 100%;
169
+ font-size: 90%;
170
}
171
172
div.tg-pane input.mail-tag {
173
+ width: 65%;
174
}
175
176
div.tg-mail-tag {
178
text-align: right;
179
}
180
181
div.tg-pane input.tg-name {
182
border-color: #555;
183
}
214
}
215
216
div.tg-panetitle {
217
+ font-weight: bold;
218
+ font-size: 1.5em;
219
+ margin: 0 0 .5em;
220
+ color: #5f5f5f;
221
+ }
222
+
223
+ .fixed .column-title {
224
+ width: 32%;
225
}
226
227
input.shortcode-in-list-table {
228
width: 100%;
229
+ font-size: 90%;
230
+ }
231
+
232
+ input[readonly].code {
233
+ background: #f3f3f3;
234
+ color: #3f3f3f;
235
}
236
237
/* welcome panel */
admin/edit-contact-form.php CHANGED
@@ -42,19 +42,19 @@ if ( $post ) :
42
<div id="poststuff" class="metabox-holder">
43
44
<div id="titlediv">
45
- <input type="text" id="wpcf7-title" name="wpcf7-title" size="40" value="<?php echo esc_attr( $post->title ); ?>"<?php echo $disabled; ?> />
46
47
<?php if ( ! $post->initial ) : ?>
48
<p class="tagcode">
49
<?php echo esc_html( __( "Copy this code and paste it into your post, page or text widget content.", 'contact-form-7' ) ); ?><br />
50
51
- <input type="text" id="contact-form-anchor-text" onfocus="this.select();" readonly="readonly" />
52
</p>
53
54
<p class="tagcode" style="display: none;">
55
<?php echo esc_html( __( "Old code is also available.", 'contact-form-7' ) ); ?><br />
56
57
- <input type="text" id="contact-form-anchor-text-old" onfocus="this.select();" readonly="readonly" />
58
</p>
59
<?php endif; ?>
60
42
<div id="poststuff" class="metabox-holder">
43
44
<div id="titlediv">
45
+ <input type="text" id="wpcf7-title" name="wpcf7-title" size="80" value="<?php echo esc_attr( $post->title ); ?>"<?php echo $disabled; ?> />
46
47
<?php if ( ! $post->initial ) : ?>
48
<p class="tagcode">
49
<?php echo esc_html( __( "Copy this code and paste it into your post, page or text widget content.", 'contact-form-7' ) ); ?><br />
50
51
+ <input type="text" id="contact-form-anchor-text" onfocus="this.select();" readonly="readonly" class="wp-ui-text-highlight code" />
52
</p>
53
54
<p class="tagcode" style="display: none;">
55
<?php echo esc_html( __( "Old code is also available.", 'contact-form-7' ) ); ?><br />
56
57
+ <input type="text" id="contact-form-anchor-text-old" onfocus="this.select();" readonly="readonly" class="wp-ui-text-highlight code" />
58
</p>
59
<?php endif; ?>
60
admin/includes/class-contact-forms-list-table.php CHANGED
@@ -56,7 +56,7 @@ class WPCF7_Contact_Form_List_Table extends WP_List_Table {
56
57
$this->items = WPCF7_ContactForm::find( $args );
58
59
- $total_items = WPCF7_ContactForm::$found_items;
60
$total_pages = ceil( $total_items / $per_page );
61
62
$this->set_pagination_args( array(
@@ -138,8 +138,10 @@ class WPCF7_Contact_Form_List_Table extends WP_List_Table {
138
$output = '';
139
140
foreach ( $shortcodes as $shortcode ) {
141
- $output .= "\n" . '<input type="text" onfocus="this.select();" readonly="readonly"
142
- value="' . esc_attr( $shortcode ) . '" class="shortcode-in-list-table" />';
143
}
144
145
return trim( $output );
56
57
$this->items = WPCF7_ContactForm::find( $args );
58
59
+ $total_items = WPCF7_ContactForm::count();
60
$total_pages = ceil( $total_items / $per_page );
61
62
$this->set_pagination_args( array(
138
$output = '';
139
140
foreach ( $shortcodes as $shortcode ) {
141
+ $output .= "\n" . '<input type="text"'
142
+ . ' onfocus="this.select();" readonly="readonly"'
143
+ . ' value="' . esc_attr( $shortcode ) . '"'
144
+ . ' class="shortcode-in-list-table wp-ui-text-highlight code" />';
145
}
146
147
return trim( $output );
includes/classes.php CHANGED
@@ -4,23 +4,62 @@ class WPCF7_ContactForm {
4
5
const post_type = 'wpcf7_contact_form';
6
7
- public static $found_items = 0;
8
9
- var $initial = false;
10
11
- var $id;
12
- var $name;
13
- var $title;
14
15
- var $unit_tag;
16
17
- var $responses_count = 0;
18
- var $scanned_form_tags;
19
20
- var $posted_data;
21
- var $uploaded_files = array();
22
23
- var $skip_mail = false;
24
25
public static function register_post_type() {
26
register_post_type( self::post_type, array(
@@ -89,7 +128,43 @@ class WPCF7_ContactForm {
89
do_action_ref_array( 'wpcf7_contact_form', array( &$this ) );
90
}
91
92
- function get_properties() {
93
$prop_names = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
94
95
$properties = array();
@@ -101,7 +176,7 @@ class WPCF7_ContactForm {
101
}
102
103
// Return true if this form is the same one as currently POSTed.
104
- function is_posted() {
105
if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
106
return false;
107
@@ -111,7 +186,7 @@ class WPCF7_ContactForm {
111
return false;
112
}
113
114
- function clear_post() {
115
$fes = $this->form_scan_shortcode();
116
117
foreach ( $fes as $fe ) {
@@ -127,8 +202,12 @@ class WPCF7_ContactForm {
127
128
/* Generating Form HTML */
129
130
- function form_html() {
131
- global $wpcf7;
132
133
$form = '<div class="wpcf7" id="' . $this->unit_tag . '">';
134
@@ -141,20 +220,32 @@ class WPCF7_ContactForm {
141
142
$url = apply_filters( 'wpcf7_form_action_url', $url );
143
144
$class = 'wpcf7-form';
145
146
if ( $this->is_posted() ) {
147
- if ( empty( $wpcf7->result['valid'] ) )
148
$class .= ' invalid';
149
- elseif ( ! empty( $wpcf7->result['spam'] ) )
150
$class .= ' spam';
151
- elseif ( ! empty( $wpcf7->result['mail_sent'] ) )
152
$class .= ' sent';
153
else
154
$class .= ' failed';
155
}
156
157
- $class = apply_filters( 'wpcf7_form_class_attr', $class );
158
159
$enctype = apply_filters( 'wpcf7_form_enctype', '' );
160
@@ -162,6 +253,7 @@ class WPCF7_ContactForm {
162
wpcf7_support_html5() ? ' novalidate="novalidate"' : '' );
163
164
$form .= '<form action="' . esc_url_raw( $url ) . '" method="post"'
165
. ' class="' . esc_attr( $class ) . '"'
166
. $enctype . $novalidate . '>' . "\n";
167
@@ -179,7 +271,7 @@ class WPCF7_ContactForm {
179
return $form;
180
}
181
182
- function form_hidden_fields() {
183
$hidden_fields = array(
184
'_wpcf7' => $this->id,
185
'_wpcf7_version' => WPCF7_VERSION,
@@ -200,28 +292,28 @@ class WPCF7_ContactForm {
200
return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
201
}
202
203
- function form_response_output() {
204
- global $wpcf7;
205
-
206
$class = 'wpcf7-response-output';
207
$role = '';
208
$content = '';
209
210
if ( $this->is_posted() ) { // Post response output for non-AJAX
211
212
- if ( empty( $wpcf7->result['valid'] ) )
213
$class .= ' wpcf7-validation-errors';
214
- elseif ( ! empty( $wpcf7->result['spam'] ) )
215
$class .= ' wpcf7-spam-blocked';
216
- elseif ( ! empty( $wpcf7->result['mail_sent'] ) )
217
$class .= ' wpcf7-mail-sent-ok';
218
else
219
$class .= ' wpcf7-mail-sent-ng';
220
221
$role = 'alert';
222
223
- if ( ! empty( $wpcf7->result['message'] ) )
224
- $content = $wpcf7->result['message'];
225
226
} else {
227
$class .= ' wpcf7-display-none';
@@ -240,16 +332,16 @@ class WPCF7_ContactForm {
240
$output, $class, $content, $this );
241
}
242
243
- function validation_error( $name ) {
244
- global $wpcf7;
245
-
246
if ( ! $this->is_posted() )
247
return '';
248
249
- if ( ! isset( $wpcf7->result['invalid_reasons'][$name] ) )
250
return '';
251
252
- $ve = trim( $wpcf7->result['invalid_reasons'][$name] );
253
254
if ( empty( $ve ) )
255
return '';
@@ -262,29 +354,28 @@ class WPCF7_ContactForm {
262
263
/* Form Elements */
264
265
- function form_do_shortcode() {
266
- global $wpcf7_shortcode_manager;
267
-
268
$form = $this->form;
269
270
if ( WPCF7_AUTOP ) {
271
- $form = $wpcf7_shortcode_manager->normalize_shortcode( $form );
272
$form = wpcf7_autop( $form );
273
}
274
275
- $form = $wpcf7_shortcode_manager->do_shortcode( $form );
276
- $this->scanned_form_tags = $wpcf7_shortcode_manager->scanned_tags;
277
278
return $form;
279
}
280
281
- function form_scan_shortcode( $cond = null ) {
282
- global $wpcf7_shortcode_manager;
283
284
if ( ! empty( $this->scanned_form_tags ) ) {
285
$scanned = $this->scanned_form_tags;
286
} else {
287
- $scanned = $wpcf7_shortcode_manager->scan_shortcode( $this->form );
288
$this->scanned_form_tags = $scanned;
289
}
290
@@ -328,11 +419,11 @@ class WPCF7_ContactForm {
328
return array_values( $scanned );
329
}
330
331
- function form_elements() {
332
return apply_filters( 'wpcf7_form_elements', $this->form_do_shortcode() );
333
}
334
335
- function setup_posted_data() {
336
$posted_data = (array) $_POST;
337
338
$fes = $this->form_scan_shortcode();
@@ -370,7 +461,7 @@ class WPCF7_ContactForm {
370
return $this->posted_data;
371
}
372
373
- function submit( $ajax = false ) {
374
$result = array(
375
'status' => 'init',
376
'valid' => true,
@@ -401,7 +492,12 @@ class WPCF7_ContactForm {
401
$result['spam'] = true;
402
403
} elseif ( $this->mail() ) {
404
- $result['status'] = 'mail_sent';
405
$result['mail_sent'] = true;
406
$result['message'] = $this->message( 'mail_sent_ok' );
407
@@ -437,12 +533,14 @@ class WPCF7_ContactForm {
437
438
do_action_ref_array( 'wpcf7_submit', array( &$this, $result ) );
439
440
return $result;
441
}
442
443
/* Validate */
444
445
- function validate() {
446
$fes = $this->form_scan_shortcode();
447
448
$result = array( 'valid' => true, 'reason' => array() );
@@ -456,13 +554,13 @@ class WPCF7_ContactForm {
456
return $result;
457
}
458
459
- function accepted() {
460
$accepted = true;
461
462
return apply_filters( 'wpcf7_acceptance', $accepted );
463
}
464
465
- function spam() {
466
$spam = false;
467
468
if ( WPCF7_VERIFY_NONCE && ! $this->verify_nonce() )
@@ -474,11 +572,11 @@ class WPCF7_ContactForm {
474
return apply_filters( 'wpcf7_spam', $spam );
475
}
476
477
- function verify_nonce() {
478
return wpcf7_verify_nonce( $_POST['_wpnonce'], $this->id );
479
}
480
481
- function blacklist_check() {
482
$target = wpcf7_array_flatten( $this->posted_data );
483
$target[] = $_SERVER['REMOTE_ADDR'];
484
$target[] = $_SERVER['HTTP_USER_AGENT'];
@@ -490,7 +588,7 @@ class WPCF7_ContactForm {
490
491
/* Mail */
492
493
- function mail() {
494
if ( $this->in_demo_mode() )
495
$this->skip_mail = true;
496
@@ -519,7 +617,7 @@ class WPCF7_ContactForm {
519
return false;
520
}
521
522
- function setup_mail_template( $mail_template, $name = '' ) {
523
$defaults = array(
524
'subject' => '', 'sender' => '', 'body' => '',
525
'recipient' => '', 'additional_headers' => '',
@@ -535,7 +633,7 @@ class WPCF7_ContactForm {
535
return $mail_template;
536
}
537
538
- function compose_mail( $mail_template, $send = true ) {
539
$this->mail_template_in_process = $mail_template;
540
541
$use_html = (bool) $mail_template['use_html'];
@@ -582,7 +680,7 @@ class WPCF7_ContactForm {
582
return compact( 'subject', 'sender', 'body', 'recipient', 'headers', 'attachments' );
583
}
584
585
- function replace_mail_tags( $content, $html = false ) {
586
$regex = '/(\[?)\[[\t ]*'
587
. '([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name
588
. '((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values
@@ -596,11 +694,11 @@ class WPCF7_ContactForm {
596
return preg_replace_callback( $regex, $callback, $content );
597
}
598
599
- function mail_callback_html( $matches ) {
600
return $this->mail_callback( $matches, true );
601
}
602
603
- function mail_callback( $matches, $html = false ) {
604
// allow [[foo]] syntax for escaping a tag
605
if ( $matches[1] == '[' && $matches[4] == ']' )
606
return substr( $matches[0], 1, -1 );
@@ -662,7 +760,7 @@ class WPCF7_ContactForm {
662
return $tag;
663
}
664
665
- function format( $original, $format ) {
666
$original = (array) $original;
667
668
foreach ( $original as $key => $value ) {
@@ -674,7 +772,7 @@ class WPCF7_ContactForm {
674
return $original;
675
}
676
677
- function mail_attachments( $template ) {
678
$attachments = array();
679
680
foreach ( (array) $this->uploaded_files as $name => $path ) {
@@ -699,7 +797,7 @@ class WPCF7_ContactForm {
699
700
/* Message */
701
702
- function message( $status ) {
703
$messages = $this->messages;
704
$message = isset( $messages[$status] ) ? $messages[$status] : '';
705
@@ -710,7 +808,7 @@ class WPCF7_ContactForm {
710
711
/* Additional settings */
712
713
- function additional_setting( $name, $max = 1 ) {
714
$tmp_settings = (array) explode( "\n", $this->additional_settings );
715
716
$count = 0;
@@ -731,8 +829,8 @@ class WPCF7_ContactForm {
731
return $values;
732
}
733
734
- function in_demo_mode() {
735
- $settings = $this->additional_setting( 'demo_mode', false );
736
737
foreach ( $settings as $setting ) {
738
if ( in_array( $setting, array( 'on', 'true', '1' ) ) )
@@ -742,9 +840,13 @@ class WPCF7_ContactForm {
742
return false;
743
}
744
745
/* Upgrade */
746
747
- function upgrade() {
748
if ( is_array( $this->mail ) ) {
749
if ( ! isset( $this->mail['recipient'] ) )
750
$this->mail['recipient'] = get_option( 'admin_email' );
@@ -760,7 +862,7 @@ class WPCF7_ContactForm {
760
761
/* Save */
762
763
- function save() {
764
$props = $this->get_properties();
765
766
$post_content = implode( "\n", wpcf7_array_flatten( $props ) );
@@ -800,8 +902,8 @@ class WPCF7_ContactForm {
800
return $post_id;
801
}
802
803
- function copy() {
804
- $new = new WPCF7_ContactForm();
805
$new->initial = true;
806
$new->title = $this->title . '_copy';
807
$new->locale = $this->locale;
@@ -816,7 +918,7 @@ class WPCF7_ContactForm {
816
return $new;
817
}
818
819
- function delete() {
820
if ( $this->initial )
821
return;
822
@@ -859,45 +961,15 @@ function wpcf7_get_contact_form_by_title( $title ) {
859
}
860
861
function wpcf7_get_contact_form_default_pack( $args = '' ) {
862
- global $l10n;
863
-
864
- $defaults = array( 'locale' => null, 'title' => '' );
865
- $args = wp_parse_args( $args, $defaults );
866
-
867
- $locale = $args['locale'];
868
- $title = $args['title'];
869
-
870
- if ( $locale ) {
871
- $mo_orig = $l10n['contact-form-7'];
872
- wpcf7_load_textdomain( $locale );
873
- }
874
-
875
- $contact_form = new WPCF7_ContactForm();
876
- $contact_form->initial = true;
877
- $contact_form->title = ( $title ? $title : __( 'Untitled', 'contact-form-7' ) );
878
- $contact_form->locale = ( $locale ? $locale : get_locale() );
879
-
880
- $props = $contact_form->get_properties();
881
-
882
- foreach ( $props as $prop => $value )
883
- $contact_form->{$prop} = wpcf7_get_default_template( $prop );
884
-
885
- $contact_form = apply_filters_ref_array( 'wpcf7_contact_form_default_pack',
886
- array( &$contact_form, $args ) );
887
-
888
- if ( isset( $mo_orig ) )
889
- $l10n['contact-form-7'] = $mo_orig;
890
891
return $contact_form;
892
}
893
894
function wpcf7_get_current_contact_form() {
895
- global $wpcf7_contact_form;
896
-
897
- if ( ! is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
898
- return null;
899
-
900
- return $wpcf7_contact_form;
901
}
902
903
function wpcf7_is_posted() {
4
5
const post_type = 'wpcf7_contact_form';
6
7
+ private static $found_items = 0;
8
+ private static $current = null;
9
+ private static $submission = array(); // result of submit() process
10
11
+ public $initial = false;
12
+ public $id;
13
+ public $name;
14
+ public $title;
15
+ public $unit_tag;
16
+ public $responses_count = 0;
17
+ public $scanned_form_tags;
18
+ public $posted_data;
19
+ public $uploaded_files = array();
20
+ public $skip_mail = false;
21
22
+ public static function count() {
23
+ return self::$found_items;
24
+ }
25
+
26
+ public static function set_current( self $obj ) {
27
+ self::$current = $obj;
28
+ }
29
30
+ public static function get_current() {
31
+ return self::$current;
32
+ }
33
34
+ public static function reset_current() {
35
+ self::$current = null;
36
+ }
37
38
+ private static function add_submission_status( $id, $status ) {
39
+ self::$submission[$id] = (array) $status;
40
+ }
41
42
+ private static function get_submission_status( $id ) {
43
+ if ( isset( self::$submission[$id] ) ) {
44
+ return (array) self::$submission[$id];
45
+ }
46
+ }
47
+
48
+ private static function get_unit_tag( $id = 0 ) {
49
+ static $global_count = 0;
50
+
51
+ $global_count += 1;
52
+
53
+ if ( in_the_loop() ) {
54
+ $unit_tag = sprintf( 'wpcf7-f%1$d-p%2$d-o%3$d',
55
+ absint( $id ), get_the_ID(), $global_count );
56
+ } else {
57
+ $unit_tag = sprintf( 'wpcf7-f%1$d-o%2$d',
58
+ absint( $id ), $global_count );
59
+ }
60
+
61
+ return $unit_tag;
62
+ }
63
64
public static function register_post_type() {
65
register_post_type( self::post_type, array(
128
do_action_ref_array( 'wpcf7_contact_form', array( &$this ) );
129
}
130
131
+ public static function generate_default_package( $args = '' ) {
132
+ global $l10n;
133
+
134
+ $defaults = array( 'locale' => null, 'title' => '' );
135
+ $args = wp_parse_args( $args, $defaults );
136
+
137
+ $locale = $args['locale'];
138
+ $title = $args['title'];
139
+
140
+ if ( $locale ) {
141
+ $mo_orig = $l10n['contact-form-7'];
142
+ wpcf7_load_textdomain( $locale );
143
+ }
144
+
145
+ $contact_form = new self;
146
+ $contact_form->initial = true;
147
+ $contact_form->title =
148
+ ( $title ? $title : __( 'Untitled', 'contact-form-7' ) );
149
+ $contact_form->locale = ( $locale ? $locale : get_locale() );
150
+
151
+ $props = $contact_form->get_properties();
152
+
153
+ foreach ( $props as $prop => $value ) {
154
+ $contact_form->{$prop} = wpcf7_get_default_template( $prop );
155
+ }
156
+
157
+ $contact_form = apply_filters( 'wpcf7_contact_form_default_pack',
158
+ $contact_form, $args );
159
+
160
+ if ( isset( $mo_orig ) ) {
161
+ $l10n['contact-form-7'] = $mo_orig;
162
+ }
163
+
164
+ return $contact_form;
165
+ }
166
+
167
+ public function get_properties() {
168
$prop_names = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
169
170
$properties = array();
176
}
177
178
// Return true if this form is the same one as currently POSTed.
179
+ public function is_posted() {
180
if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
181
return false;
182
186
return false;
187
}
188
189
+ public function clear_post() {
190
$fes = $this->form_scan_shortcode();
191
192
foreach ( $fes as $fe ) {
202
203
/* Generating Form HTML */
204
205
+ public function form_html( $atts = array() ) {
206
+ $atts = wp_parse_args( $atts, array(
207
+ 'html_id' => '',
208
+ 'html_class' => '' ) );
209
+
210
+ $this->unit_tag = self::get_unit_tag( $this->id );
211
212
$form = '<div class="wpcf7" id="' . $this->unit_tag . '">';
213
220
221
$url = apply_filters( 'wpcf7_form_action_url', $url );
222
223
+ $id_attr = apply_filters( 'wpcf7_form_id_attr',
224
+ preg_replace( '/[^A-Za-z0-9:._-]/', '', $atts['html_id'] ) );
225
+
226
$class = 'wpcf7-form';
227
228
+ $result = self::get_submission_status( $this->id );
229
+
230
if ( $this->is_posted() ) {
231
+ if ( empty( $result['valid'] ) )
232
$class .= ' invalid';
233
+ elseif ( ! empty( $result['spam'] ) )
234
$class .= ' spam';
235
+ elseif ( ! empty( $result['mail_sent'] ) )
236
$class .= ' sent';
237
else
238
$class .= ' failed';
239
}
240
241
+ $atts['html_class'] = array_unique( array_map( 'sanitize_html_class',
242
+ explode( ' ', $atts['html_class'] ) ) );
243
+
244
+ if ( $atts['html_class'] ) {
245
+ $class .= ' ' . implode( ' ', $atts['html_class'] );
246
+ }
247
+
248
+ $class = apply_filters( 'wpcf7_form_class_attr', trim( $class ) );
249
250
$enctype = apply_filters( 'wpcf7_form_enctype', '' );
251
253
wpcf7_support_html5() ? ' novalidate="novalidate"' : '' );
254
255
$form .= '<form action="' . esc_url_raw( $url ) . '" method="post"'
256
+ . ( $id_attr ? ' id="' . esc_attr( $id_attr ) . '"' : '' )
257
. ' class="' . esc_attr( $class ) . '"'
258
. $enctype . $novalidate . '>' . "\n";
259
271
return $form;
272
}
273
274
+ public function form_hidden_fields() {
275
$hidden_fields = array(
276
'_wpcf7' => $this->id,
277
'_wpcf7_version' => WPCF7_VERSION,
292
return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
293
}
294
295
+ public function form_response_output() {
296
$class = 'wpcf7-response-output';
297
$role = '';
298
$content = '';
299
300
if ( $this->is_posted() ) { // Post response output for non-AJAX
301
302
+ $result = self::get_submission_status( $this->id );
303
+
304
+ if ( empty( $result['valid'] ) )
305
$class .= ' wpcf7-validation-errors';
306
+ elseif ( ! empty( $result['spam'] ) )
307
$class .= ' wpcf7-spam-blocked';
308
+ elseif ( ! empty( $result['mail_sent'] ) )
309
$class .= ' wpcf7-mail-sent-ok';
310
else
311
$class .= ' wpcf7-mail-sent-ng';
312
313
$role = 'alert';
314
315
+ if ( ! empty( $result['message'] ) )
316
+ $content = $result['message'];
317
318
} else {
319
$class .= ' wpcf7-display-none';
332
$output, $class, $content, $this );
333
}
334
335
+ public function validation_error( $name ) {
336
if ( ! $this->is_posted() )
337
return '';
338
339
+ $result = self::get_submission_status( $this->id );
340
+
341
+ if ( ! isset( $result['invalid_reasons'][$name] ) )
342
return '';
343
344
+ $ve = trim( $result['invalid_reasons'][$name] );
345
346
if ( empty( $ve ) )
347
return '';
354
355
/* Form Elements */
356
357
+ public function form_do_shortcode() {
358
+ $manager = WPCF7_ShortcodeManager::get_instance();
359
$form = $this->form;
360
361
if ( WPCF7_AUTOP ) {
362
+ $form = $manager->normalize_shortcode( $form );
363
$form = wpcf7_autop( $form );
364
}
365
366
+ $form = $manager->do_shortcode( $form );
367
+ $this->scanned_form_tags = $manager->get_scanned_tags();
368
369
return $form;
370
}
371
372
+ public function form_scan_shortcode( $cond = null ) {
373
+ $manager = WPCF7_ShortcodeManager::get_instance();
374
375
if ( ! empty( $this->scanned_form_tags ) ) {
376
$scanned = $this->scanned_form_tags;
377
} else {
378
+ $scanned = $manager->scan_shortcode( $this->form );
379
$this->scanned_form_tags = $scanned;
380
}
381
419
return array_values( $scanned );
420
}
421
422
+ public function form_elements() {
423
return apply_filters( 'wpcf7_form_elements', $this->form_do_shortcode() );
424
}
425
426
+ public function setup_posted_data() {
427
$posted_data = (array) $_POST;
428
429
$fes = $this->form_scan_shortcode();
461
return $this->posted_data;
462
}
463
464
+ public function submit( $ajax = false ) {
465
$result = array(
466
'status' => 'init',
467
'valid' => true,
492
$result['spam'] = true;
493
494
} elseif ( $this->mail() ) {
495
+ if ( $this->in_demo_mode() ) {
496
+ $result['status'] = 'demo_mode';
497
+ } else {
498
+ $result['status'] = 'mail_sent';
499
+ }
500
+
501
$result['mail_sent'] = true;
502
$result['message'] = $this->message( 'mail_sent_ok' );
503
533
534
do_action_ref_array( 'wpcf7_submit', array( &$this, $result ) );
535
536
+ self::add_submission_status( $this->id, $result );
537
+
538
return $result;
539
}
540
541
/* Validate */
542
543
+ public function validate() {
544
$fes = $this->form_scan_shortcode();
545
546
$result = array( 'valid' => true, 'reason' => array() );
554
return $result;
555
}
556
557
+ public function accepted() {
558
$accepted = true;
559
560
return apply_filters( 'wpcf7_acceptance', $accepted );
561
}
562
563
+ public function spam() {
564
$spam = false;
565
566
if ( WPCF7_VERIFY_NONCE && ! $this->verify_nonce() )
572
return apply_filters( 'wpcf7_spam', $spam );
573
}
574
575
+ public function verify_nonce() {
576
return wpcf7_verify_nonce( $_POST['_wpnonce'], $this->id );
577
}
578
579
+ public function blacklist_check() {
580
$target = wpcf7_array_flatten( $this->posted_data );
581
$target[] = $_SERVER['REMOTE_ADDR'];
582
$target[] = $_SERVER['HTTP_USER_AGENT'];
588
589
/* Mail */
590
591
+ public function mail() {
592
if ( $this->in_demo_mode() )
593
$this->skip_mail = true;
594
617
return false;
618
}
619
620
+ public function setup_mail_template( $mail_template, $name = '' ) {
621
$defaults = array(
622
'subject' => '', 'sender' => '', 'body' => '',
623
'recipient' => '', 'additional_headers' => '',
633
return $mail_template;
634
}
635
636
+ public function compose_mail( $mail_template, $send = true ) {
637
$this->mail_template_in_process = $mail_template;
638
639
$use_html = (bool) $mail_template['use_html'];
680
return compact( 'subject', 'sender', 'body', 'recipient', 'headers', 'attachments' );
681
}
682
683
+ public function replace_mail_tags( $content, $html = false ) {
684
$regex = '/(\[?)\[[\t ]*'
685
. '([a-zA-Z_][0-9a-zA-Z:._-]*)' // [2] = name
686
. '((?:[\t ]+"[^"]*"|[\t ]+\'[^\']*\')*)' // [3] = values
694
return preg_replace_callback( $regex, $callback, $content );
695
}
696
697
+ private function mail_callback_html( $matches ) {
698
return $this->mail_callback( $matches, true );
699
}
700
701
+ private function mail_callback( $matches, $html = false ) {
702
// allow [[foo]] syntax for escaping a tag
703
if ( $matches[1] == '[' && $matches[4] == ']' )
704
return substr( $matches[0], 1, -1 );
760
return $tag;
761
}
762
763
+ public function format( $original, $format ) {
764
$original = (array) $original;
765
766
foreach ( $original as $key => $value ) {
772
return $original;
773
}
774
775
+ public function mail_attachments( $template ) {
776
$attachments = array();
777
778
foreach ( (array) $this->uploaded_files as $name => $path ) {
797
798
/* Message */
799
800
+ public function message( $status ) {
801
$messages = $this->messages;
802
$message = isset( $messages[$status] ) ? $messages[$status] : '';
803
808
809
/* Additional settings */
810
811
+ public function additional_setting( $name, $max = 1 ) {
812
$tmp_settings = (array) explode( "\n", $this->additional_settings );
813
814
$count = 0;
829
return $values;
830
}
831
832
+ public function is_true( $name ) {
833
+ $settings = $this->additional_setting( $name, false );
834
835
foreach ( $settings as $setting ) {
836
if ( in_array( $setting, array( 'on', 'true', '1' ) ) )
840
return false;
841
}
842
843
+ public function in_demo_mode() {
844
+ return $this->is_true( 'demo_mode' );
845
+ }
846
+
847
/* Upgrade */
848
849
+ public function upgrade() {
850
if ( is_array( $this->mail ) ) {
851
if ( ! isset( $this->mail['recipient'] ) )
852
$this->mail['recipient'] = get_option( 'admin_email' );
862
863
/* Save */
864
865
+ public function save() {
866
$props = $this->get_properties();
867
868
$post_content = implode( "\n", wpcf7_array_flatten( $props ) );
902
return $post_id;
903
}
904
905
+ public function copy() {
906
+ $new = new self;
907
$new->initial = true;
908
$new->title = $this->title . '_copy';
909
$new->locale = $this->locale;
918
return $new;
919
}
920
921
+ public function delete() {
922
if ( $this->initial )
923
return;
924
961
}
962
963
function wpcf7_get_contact_form_default_pack( $args = '' ) {
964
+ $contact_form = WPCF7_ContactForm::generate_default_package( $args );
965
966
return $contact_form;
967
}
968
969
function wpcf7_get_current_contact_form() {
970
+ if ( $current = WPCF7_ContactForm::get_current() ) {
971
+ return $current;
972
+ }
973
}
974
975
function wpcf7_is_posted() {
includes/controller.php CHANGED
@@ -9,19 +9,19 @@ function wpcf7_control_init() {
9
}
10
11
function wpcf7_ajax_onload() {
12
- global $wpcf7_contact_form;
13
-
14
- if ( 'GET' != $_SERVER['REQUEST_METHOD'] || ! isset( $_GET['_wpcf7_is_ajax_call'] ) )
15
return;
16
17
$echo = '';
18
19
if ( isset( $_GET['_wpcf7'] ) ) {
20
- $id = (int) $_GET['_wpcf7'];
21
-
22
- if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) {
23
- $items = apply_filters( 'wpcf7_ajax_onload', array() );
24
- $wpcf7_contact_form = null;
25
}
26
}
27
@@ -36,8 +36,6 @@ function wpcf7_ajax_onload() {
36
}
37
38
function wpcf7_ajax_json_echo() {
39
- global $wpcf7_contact_form;
40
-
41
if ( 'POST' != $_SERVER['REQUEST_METHOD'] || ! isset( $_POST['_wpcf7_is_ajax_call'] ) )
42
return;
43
@@ -47,14 +45,15 @@ function wpcf7_ajax_json_echo() {
47
$id = (int) $_POST['_wpcf7'];
48
$unit_tag = wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] );
49
50
- if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) ) {
51
52
$items = array(
53
'mailSent' => false,
54
'into' => '#' . $unit_tag,
55
'captcha' => null );
56
57
- $result = $wpcf7_contact_form->submit( true );
58
59
if ( ! empty( $result['message'] ) )
60
$items['message'] = $result['message'];
@@ -85,7 +84,7 @@ function wpcf7_ajax_json_echo() {
85
86
$items = apply_filters( 'wpcf7_ajax_json_echo', $items, $result );
87
88
- $wpcf7_contact_form = null;
89
}
90
}
91
@@ -110,52 +109,26 @@ function wpcf7_is_xhr() {
110
}
111
112
function wpcf7_submit_nonajax() {
113
- global $wpcf7, $wpcf7_contact_form;
114
-
115
if ( ! isset( $_POST['_wpcf7'] ) )
116
return;
117
118
- $id = (int) $_POST['_wpcf7'];
119
-
120
- if ( $wpcf7_contact_form = wpcf7_contact_form( $id ) )
121
- $wpcf7->result = $wpcf7_contact_form->submit();
122
-
123
- $wpcf7_contact_form = null;
124
- }
125
-
126
- add_action( 'the_post', 'wpcf7_the_post' );
127
-
128
- function wpcf7_the_post() {
129
- global $wpcf7;
130
-
131
- $wpcf7->processing_within = 'p' . get_the_ID();
132
- $wpcf7->unit_count = 0;
133
- }
134
135
- add_action( 'loop_end', 'wpcf7_loop_end' );
136
137
- function wpcf7_loop_end() {
138
- global $wpcf7;
139
-
140
- $wpcf7->processing_within = '';
141
}
142
143
add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 );
144
145
function wpcf7_widget_text_filter( $content ) {
146
- global $wpcf7;
147
-
148
if ( ! preg_match( '/\[[\r\n\t ]*contact-form(-7)?[\r\n\t ].*?\]/', $content ) )
149
return $content;
150
151
- $wpcf7->widget_count += 1;
152
- $wpcf7->processing_within = 'w' . $wpcf7->widget_count;
153
- $wpcf7->unit_count = 0;
154
-
155
$content = do_shortcode( $content );
156
157
- $wpcf7->processing_within = '';
158
-
159
return $content;
160
}
161
@@ -169,54 +142,40 @@ function wpcf7_add_shortcodes() {
169
}
170
171
function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
172
- global $wpcf7, $wpcf7_contact_form;
173
-
174
if ( is_feed() )
175
return '[contact-form-7]';
176
177
if ( 'contact-form-7' == $code ) {
178
- $atts = shortcode_atts( array( 'id' => 0, 'title' => '' ), $atts );
179
180
$id = (int) $atts['id'];
181
$title = trim( $atts['title'] );
182
183
- if ( ! $wpcf7_contact_form = wpcf7_contact_form( $id ) )
184
- $wpcf7_contact_form = wpcf7_get_contact_form_by_title( $title );
185
186
} else {
187
if ( is_string( $atts ) )
188
$atts = explode( ' ', $atts, 2 );
189
190
$id = (int) array_shift( $atts );
191
- $wpcf7_contact_form = wpcf7_get_contact_form_by_old_id( $id );
192
}
193
194
- if ( ! $wpcf7_contact_form )
195
return '[contact-form-7 404 "Not Found"]';
196
197
- if ( $wpcf7->processing_within ) { // Inside post content or text widget
198
- $wpcf7->unit_count += 1;
199
- $unit_count = $wpcf7->unit_count;
200
- $processing_within = $wpcf7->processing_within;
201
-
202
- } else { // Inside template
203
-
204
- if ( ! isset( $wpcf7->global_unit_count ) )
205
- $wpcf7->global_unit_count = 0;
206
-
207
- $wpcf7->global_unit_count += 1;
208
- $unit_count = 1;
209
- $processing_within = 't' . $wpcf7->global_unit_count;
210
- }
211
-
212
- $unit_tag = 'wpcf7-f' . $wpcf7_contact_form->id . '-' . $processing_within . '-o' . $unit_count;
213
- $wpcf7_contact_form->unit_tag = $unit_tag;
214
215
- $form = $wpcf7_contact_form->form_html();
216
217
- $wpcf7_contact_form = null;
218
219
- return $form;
220
}
221
222
if ( WPCF7_LOAD_JS )
@@ -228,7 +187,7 @@ function wpcf7_enqueue_scripts() {
228
wp_deregister_script( 'jquery-form' );
229
wp_register_script( 'jquery-form',
230
wpcf7_plugin_url( 'includes/js/jquery.form.min.js' ),
231
- array( 'jquery' ), '3.46.0-2013.11.21', true );
232
233
$in_footer = true;
234
if ( 'header' === WPCF7_LOAD_JS )
9
}
10
11
function wpcf7_ajax_onload() {
12
+ if ( 'GET' != $_SERVER['REQUEST_METHOD']
13
+ || ! isset( $_GET['_wpcf7_is_ajax_call'] ) ) {
14
return;
15
+ }
16
17
$echo = '';
18
+ $items = array();
19
20
if ( isset( $_GET['_wpcf7'] ) ) {
21
+ if ( $contact_form = wpcf7_contact_form( (int) $_GET['_wpcf7'] ) ) {
22
+ WPCF7_ContactForm::set_current( $contact_form );
23
+ $items = apply_filters( 'wpcf7_ajax_onload', $items );
24
+ WPCF7_ContactForm::reset_current();
25
}
26
}
27
36
}
37
38
function wpcf7_ajax_json_echo() {
39
if ( 'POST' != $_SERVER['REQUEST_METHOD'] || ! isset( $_POST['_wpcf7_is_ajax_call'] ) )
40
return;
41
45
$id = (int) $_POST['_wpcf7'];
46
$unit_tag = wpcf7_sanitize_unit_tag( $_POST['_wpcf7_unit_tag'] );
47
48
+ if ( $contact_form = wpcf7_contact_form( $id ) ) {
49
+ WPCF7_ContactForm::set_current( $contact_form );
50
51
$items = array(
52
'mailSent' => false,
53
'into' => '#' . $unit_tag,
54
'captcha' => null );
55
56
+ $result = $contact_form->submit( true );
57
58
if ( ! empty( $result['message'] ) )
59
$items['message'] = $result['message'];
84
85
$items = apply_filters( 'wpcf7_ajax_json_echo', $items, $result );
86
87
+ WPCF7_ContactForm::reset_current();
88
}
89
}
90
109
}
110
111
function wpcf7_submit_nonajax() {
112
if ( ! isset( $_POST['_wpcf7'] ) )
113
return;
114
115
+ if ( $contact_form = wpcf7_contact_form( (int) $_POST['_wpcf7'] ) ) {
116
+ WPCF7_ContactForm::set_current( $contact_form );
117
118
+ $contact_form->submit();
119
120
+ WPCF7_ContactForm::reset_current();
121
+ }
122
}
123
124
add_filter( 'widget_text', 'wpcf7_widget_text_filter', 9 );
125
126
function wpcf7_widget_text_filter( $content ) {
127
if ( ! preg_match( '/\[[\r\n\t ]*contact-form(-7)?[\r\n\t ].*?\]/', $content ) )
128
return $content;
129
130
$content = do_shortcode( $content );
131
132
return $content;
133
}
134
142
}
143
144
function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
145
if ( is_feed() )
146
return '[contact-form-7]';
147
148
if ( 'contact-form-7' == $code ) {
149
+ $atts = shortcode_atts( array(
150
+ 'id' => 0,
151
+ 'title' => '',
152
+ 'html_id' => '',
153
+ 'html_class' => '' ), $atts );
154
155
$id = (int) $atts['id'];
156
$title = trim( $atts['title'] );
157
158
+ if ( ! $contact_form = wpcf7_contact_form( $id ) )
159
+ $contact_form = wpcf7_get_contact_form_by_title( $title );
160
161
} else {
162
if ( is_string( $atts ) )
163
$atts = explode( ' ', $atts, 2 );
164
165
$id = (int) array_shift( $atts );
166
+ $contact_form = wpcf7_get_contact_form_by_old_id( $id );
167
}
168
169
+ if ( ! $contact_form )
170
return '[contact-form-7 404 "Not Found"]';
171
172
+ WPCF7_ContactForm::set_current( $contact_form );
173
174
+ $html = $contact_form->form_html( $atts );
175
176
+ WPCF7_ContactForm::reset_current();
177
178
+ return $html;
179
}
180
181
if ( WPCF7_LOAD_JS )
187
wp_deregister_script( 'jquery-form' );
188
wp_register_script( 'jquery-form',
189
wpcf7_plugin_url( 'includes/js/jquery.form.min.js' ),
190
+ array( 'jquery' ), '3.48.0-2013.12.28', true );
191
192
$in_footer = true;
193
if ( 'header' === WPCF7_LOAD_JS )
includes/css/styles-rtl.css CHANGED
@@ -2,6 +2,11 @@ span.wpcf7-not-valid-tip {
2
direction: rtl;
3
}
4
5
span.wpcf7-list-item {
6
margin-left: 0;
7
margin-right: 0.5em;
2
direction: rtl;
3
}
4
5
+ .use-floating-validation-tip span.wpcf7-not-valid-tip {
6
+ left: auto;
7
+ right: 20%;
8
+ }
9
+
10
span.wpcf7-list-item {
11
margin-left: 0;
12
margin-right: 0.5em;
includes/css/styles.css CHANGED
@@ -34,6 +34,16 @@ span.wpcf7-not-valid-tip {
34
display: block;
35
}
36
37
span.wpcf7-list-item {
38
margin-left: 0.5em;
39
}
34
display: block;
35
}
36
37
+ .use-floating-validation-tip span.wpcf7-not-valid-tip {
38
+ position: absolute;
39
+ top: 20%;
40
+ left: 20%;
41
+ z-index: 100;
42
+ border: 1px solid #ff0000;
43
+ background: #fff;
44
+ padding: .2em .8em;
45
+ }
46
+
47
span.wpcf7-list-item {
48
margin-left: 0.5em;
49
}
includes/formatting.php CHANGED
@@ -1,9 +1,10 @@
1
<?php
2
3
function wpcf7_autop( $pee, $br = 1 ) {
4
-
5
- if ( trim( $pee ) === '' )
6
return '';
7
$pee = $pee . "\n"; // just to make things a little easier, pad the end
8
$pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
9
// Space things out a little
@@ -11,17 +12,26 @@ function wpcf7_autop( $pee, $br = 1 ) {
11
$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)';
12
$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
13
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
14
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
15
if ( strpos( $pee, '<object' ) !== false ) {
16
$pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
17
$pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
18
}
19
$pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
20
// make paragraphs, including one at the end
21
$pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
22
$pee = '';
23
- foreach ( $pees as $tinkle )
24
$pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
25
$pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
26
$pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee );
27
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
@@ -30,6 +40,10 @@ function wpcf7_autop( $pee, $br = 1 ) {
30
$pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
31
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
32
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
33
if ( $br ) {
34
/* wpcf7: add textarea */
35
$pee = preg_replace_callback( '/<(script|style|textarea).*?<\/\\1>/s', create_function( '$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ), $pee );
1
<?php
2
3
function wpcf7_autop( $pee, $br = 1 ) {
4
+ if ( trim( $pee ) === '' ) {
5
return '';
6
+ }
7
+
8
$pee = $pee . "\n"; // just to make things a little easier, pad the end
9
$pee = preg_replace( '|<br />\s*<br />|', "\n\n", $pee );
10
// Space things out a little
12
$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)';
13
$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
14
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
15
+
16
+ /* wpcf7: take care of [response] tag */
17
+ $pee = preg_replace( '!(\[response[^]]*\])!', "\n$1\n\n", $pee );
18
+
19
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
20
+
21
if ( strpos( $pee, '<object' ) !== false ) {
22
$pee = preg_replace( '|\s*<param([^>]*)>\s*|', "<param$1>", $pee ); // no pee inside object/embed
23
$pee = preg_replace( '|\s*</embed>\s*|', '</embed>', $pee );
24
}
25
+
26
$pee = preg_replace( "/\n\n+/", "\n\n", $pee ); // take care of duplicates
27
// make paragraphs, including one at the end
28
$pees = preg_split( '/\n\s*\n/', $pee, -1, PREG_SPLIT_NO_EMPTY );
29
$pee = '';
30
+
31
+ foreach ( $pees as $tinkle ) {
32
$pee .= '<p>' . trim( $tinkle, "\n" ) . "</p>\n";
33
+ }
34
+
35
$pee = preg_replace( '|<p>\s*</p>|', '', $pee ); // under certain strange conditions it could create a P of entirely whitespace
36
$pee = preg_replace( '!<p>([^<]+)</(div|address|form|fieldset)>!', "<p>$1</p></$2>", $pee );
37
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee ); // don't pee all over a tag
40
$pee = str_replace( '</blockquote></p>', '</p></blockquote>', $pee );
41
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
42
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
43
+
44
+ /* wpcf7: take care of [response] tag */
45
+ $pee = preg_replace( '!<p>\s*(\[response[^]]*\])\s*</p>!', "$1", $pee );
46
+
47
if ( $br ) {
48
/* wpcf7: add textarea */
49
$pee = preg_replace_callback( '/<(script|style|textarea).*?<\/\\1>/s', create_function( '$matches', 'return str_replace("\n", "<WPPreserveNewline />", $matches[0]);' ), $pee );
includes/functions.php CHANGED
@@ -144,22 +144,13 @@ function wpcf7_upload_dir( $type = false ) {
144
return $uploads;
145
}
146
147
- if ( ! function_exists( 'wp_is_writable' ) ) {
148
- /*
149
- * wp_is_writable exists in WordPress 3.6+
150
- * http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/functions.php#L1437
151
- * We will be able to remove this function definition
152
- * after moving required WordPress version up to 3.6.
153
- */
154
- function wp_is_writable( $path ) {
155
- if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) )
156
- return win_is_writable( $path );
157
- else
158
- return @is_writable( $path );
159
- }
160
- }
161
-
162
function wpcf7_l10n() {
163
$l10n = array(
164
'af' => __( 'Afrikaans', 'contact-form-7' ),
165
'sq' => __( 'Albanian', 'contact-form-7' ),
@@ -190,6 +181,7 @@ function wpcf7_l10n() {
190
'ka_GE' => __( 'Georgian', 'contact-form-7' ),
191
'de_DE' => __( 'German', 'contact-form-7' ),
192
'el' => __( 'Greek', 'contact-form-7' ),
193
'he_IL' => __( 'Hebrew', 'contact-form-7' ),
194
'hi_IN' => __( 'Hindi', 'contact-form-7' ),
195
'hu_HU' => __( 'Hungarian', 'contact-form-7' ),
@@ -389,9 +381,13 @@ function wpcf7_load_modules() {
389
}
390
391
function wpcf7_get_request_uri() {
392
- global $wpcf7;
393
394
- return (string) $wpcf7->request_uri;
395
}
396
397
function wpcf7_register_post_types() {
144
return $uploads;
145
}
146
147
function wpcf7_l10n() {
148
+ static $l10n = array();
149
+
150
+ if ( ! empty( $l10n ) ) {
151
+ return $l10n;
152
+ }
153
+
154
$l10n = array(
155
'af' => __( 'Afrikaans', 'contact-form-7' ),
156
'sq' => __( 'Albanian', 'contact-form-7' ),
181
'ka_GE' => __( 'Georgian', 'contact-form-7' ),
182
'de_DE' => __( 'German', 'contact-form-7' ),
183
'el' => __( 'Greek', 'contact-form-7' ),
184
+ 'ht' => __( 'Haitian', 'contact-form-7' ),
185
'he_IL' => __( 'Hebrew', 'contact-form-7' ),
186
'hi_IN' => __( 'Hindi', 'contact-form-7' ),
187
'hu_HU' => __( 'Hungarian', 'contact-form-7' ),
381
}
382
383
function wpcf7_get_request_uri() {
384
+ static $request_uri = '';
385
+
386
+ if ( empty( $request_uri ) ) {
387
+ $request_uri = add_query_arg( array() );
388
+ }
389
390
+ return esc_url_raw( $request_uri );
391
}
392
393
function wpcf7_register_post_types() {
includes/js/jquery.form.js CHANGED
@@ -1,6 +1,6 @@
1
/*!
2
* jQuery Form Plugin
3
- * version: 3.46.0-2013.11.21
4
* Requires jQuery v1.5 or later
5
* Copyright (c) 2013 M. Alsup
6
* Examples and documentation at: http://malsup.com/jquery/form/
@@ -12,6 +12,7 @@
12
13
// AMD support
14
(function (factory) {
15
if (typeof define === 'function' && define.amd) {
16
// using AMD; register as anon module
17
define(['jquery'], factory);
@@ -75,11 +76,13 @@ var hasProp = !!$.fn.prop;
75
// contains inputs with names like "action" or "method"; in those
76
// cases "prop" returns the element
77
$.fn.attr2 = function() {
78
- if ( ! hasProp )
79
return this.attr.apply(this, arguments);
80
var val = this.prop.apply(this, arguments);
81
- if ( ( val && val.jquery ) || typeof val === 'string' )
82
return val;
83
return this.attr.apply(this, arguments);
84
};
85
@@ -257,8 +260,9 @@ $.fn.ajaxSubmit = function(options) {
257
$form.removeData('jqxhr').data('jqxhr', jqxhr);
258
259
// clear element array
260
- for (var k=0; k < elements.length; k++)
261
elements[k] = null;
262
263
// fire 'notify' event
264
this.trigger('form-submit-notify', [this, options]);
@@ -290,9 +294,11 @@ $.fn.ajaxSubmit = function(options) {
290
291
if (options.extraData) {
292
var serializedData = deepSerialize(options.extraData);
293
- for (i=0; i < serializedData.length; i++)
294
- if (serializedData[i])
295
formdata.append(serializedData[i][0], serializedData[i][1]);
296
}
297
298
options.data = null;
@@ -327,12 +333,15 @@ $.fn.ajaxSubmit = function(options) {
327
var beforeSend = s.beforeSend;
328
s.beforeSend = function(xhr, o) {
329
//Send FormData() provided by user
330
- if (options.formData)
331
o.data = options.formData;
332
- else
333
o.data = formdata;
334
- if(beforeSend)
335
beforeSend.call(this, xhr, o);
336
};
337
return $.ajax(s);
338
}
@@ -351,10 +360,12 @@ $.fn.ajaxSubmit = function(options) {
351
// ensure that every serialized input is still enabled
352
for (i=0; i < elements.length; i++) {
353
el = $(elements[i]);
354
- if ( hasProp )
355
el.prop('disabled', false);
356
- else
357
el.removeAttr('disabled');
358
}
359
}
360
@@ -364,10 +375,12 @@ $.fn.ajaxSubmit = function(options) {
364
if (s.iframeTarget) {
365
$io = $(s.iframeTarget);
366
n = $io.attr2('name');
367
- if (!n)
368
- $io.attr2('name', id);
369
- else
370
id = n;
371
}
372
else {
373
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
@@ -399,12 +412,15 @@ $.fn.ajaxSubmit = function(options) {
399
400
$io.attr('src', s.iframeSrc); // abort op in progress
401
xhr.error = e;
402
- if (s.error)
403
s.error.call(s.context, xhr, e, status);
404
- if (g)
405
$.event.trigger("ajaxError", [xhr, s, e]);
406
- if (s.complete)
407
s.complete.call(s.context, xhr, e);
408
}
409
};
410
@@ -491,7 +507,10 @@ $.fn.ajaxSubmit = function(options) {
491
// take a breath so that pending repaints get some cpu time before the upload starts
492
function doSubmit() {
493
// make sure form attrs are set
494
- var t = $form.attr2('target'), a = $form.attr2('action');
495
496
// update form attrs in IE friendly way
497
form.setAttribute('target',id);
@@ -520,14 +539,16 @@ $.fn.ajaxSubmit = function(options) {
520
try {
521
var state = getDoc(io).readyState;
522
log('state = ' + state);
523
- if (state && state.toLowerCase() == 'uninitialized')
524
setTimeout(checkState,50);
525
}
526
catch(e) {
527
log('Server abort: ' , e, ' (', e.name, ')');
528
cb(SERVER_ABORT);
529
- if (timeoutHandle)
530
clearTimeout(timeoutHandle);
531
timeoutHandle = undefined;
532
}
533
}
@@ -556,10 +577,12 @@ $.fn.ajaxSubmit = function(options) {
556
// add iframe to doc and submit the form
557
$io.appendTo('body');
558
}
559
- if (io.attachEvent)
560
io.attachEvent('onload', cb);
561
- else
562
io.addEventListener('load', cb, false);
563
setTimeout(checkState,15);
564
565
try {
@@ -573,6 +596,7 @@ $.fn.ajaxSubmit = function(options) {
573
finally {
574
// reset attrs and remove "extra" input elements
575
form.setAttribute('action',a);
576
if(t) {
577
form.setAttribute('target', t);
578
} else {
@@ -614,13 +638,16 @@ $.fn.ajaxSubmit = function(options) {
614
615
if (!doc || doc.location.href == s.iframeSrc) {
616
// response not received yet
617
- if (!timedOut)
618
return;
619
}
620
- if (io.detachEvent)
621
io.detachEvent('onload', cb);
622
- else
623
io.removeEventListener('load', cb, false);
624
625
var status = 'success', errMsg;
626
try {
@@ -647,8 +674,9 @@ $.fn.ajaxSubmit = function(options) {
647
var docRoot = doc.body ? doc.body : doc.documentElement;
648
xhr.responseText = docRoot ? docRoot.innerHTML : null;
649
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
650
- if (isXml)
651
s.dataType = 'xml';
652
xhr.getResponseHeader = function(header){
653
var headers = {'content-type': s.dataType};
654
return headers[header.toLowerCase()];
@@ -711,42 +739,52 @@ $.fn.ajaxSubmit = function(options) {
711
712
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
713
if (status === 'success') {
714
- if (s.success)
715
s.success.call(s.context, data, 'success', xhr);
716
deferred.resolve(xhr.responseText, 'success', xhr);
717
- if (g)
718
$.event.trigger("ajaxSuccess", [xhr, s]);
719
}
720
else if (status) {
721
- if (errMsg === undefined)
722
errMsg = xhr.statusText;
723
- if (s.error)
724
s.error.call(s.context, xhr, status, errMsg);
725
deferred.reject(xhr, 'error', errMsg);
726
- if (g)
727
$.event.trigger("ajaxError", [xhr, s, errMsg]);
728
}
729
730
- if (g)
731
$.event.trigger("ajaxComplete", [xhr, s]);
732
733
if (g && ! --$.active) {
734
$.event.trigger("ajaxStop");
735
}
736
737
- if (s.complete)
738
s.complete.call(s.context, xhr, status);
739
740
callbackProcessed = true;
741
- if (s.timeout)
742
clearTimeout(timeoutHandle);
743
744
// clean up
745
setTimeout(function() {
746
- if (!s.iframeTarget)
747
$io.remove();
748
- else //adding else to clean up existing iframe response.
749
$io.attr('src', s.iframeSrc);
750
xhr.responseXML = null;
751
}, 100);
752
}
@@ -774,8 +812,9 @@ $.fn.ajaxSubmit = function(options) {
774
data = xml ? xhr.responseXML : xhr.responseText;
775
776
if (xml && data.documentElement.nodeName === 'parsererror') {
777
- if ($.error)
778
$.error('parsererror');
779
}
780
if (s && s.dataFilter) {
781
data = s.dataFilter(data, type);
@@ -907,8 +946,23 @@ $.fn.formToArray = function(semantic, elements) {
907
}
908
909
var form = this[0];
910
var els = semantic ? form.getElementsByTagName('*') : form.elements;
911
- if (!els) {
912
return a;
913
}
914
@@ -931,15 +985,17 @@ $.fn.formToArray = function(semantic, elements) {
931
932
v = $.fieldValue(el, true);
933
if (v && v.constructor == Array) {
934
- if (elements)
935
elements.push(el);
936
for(j=0, jmax=v.length; j < jmax; j++) {
937
a.push({name: n, value: v[j]});
938
}
939
}
940
else if (feature.fileapi && el.type == 'file') {
941
- if (elements)
942
elements.push(el);
943
var files = el.files;
944
if (files.length) {
945
for (j=0; j < files.length; j++) {
@@ -952,8 +1008,9 @@ $.fn.formToArray = function(semantic, elements) {
952
}
953
}
954
else if (v !== null && typeof v != 'undefined') {
955
- if (elements)
956
elements.push(el);
957
a.push({name: n, value: v, type: el.type, required: el.required});
958
}
959
}
@@ -1049,10 +1106,12 @@ $.fn.fieldValue = function(successful) {
1049
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
1050
continue;
1051
}
1052
- if (v.constructor == Array)
1053
$.merge(val, v);
1054
- else
1055
val.push(v);
1056
}
1057
return val;
1058
};
@@ -1086,7 +1145,7 @@ $.fieldValue = function(el, successful) {
1086
if (op.selected) {
1087
var v = op.value;
1088
if (!v) { // extra pain for IE...
1089
- v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
1090
}
1091
if (one) {
1092
return v;
@@ -1142,8 +1201,9 @@ $.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
1142
// $('#myForm').clearForm('.special:hidden')
1143
// the above would clean hidden inputs that have the class of 'special'
1144
if ( (includeHidden === true && /hidden/.test(t)) ||
1145
- (typeof includeHidden == 'string' && $(this).is(includeHidden)) )
1146
this.value = '';
1147
}
1148
});
1149
};
@@ -1202,8 +1262,9 @@ $.fn.ajaxSubmit.debug = false;
1202
1203
// helper fn for console logging
1204
function log() {
1205
- if (!$.fn.ajaxSubmit.debug)
1206
return;
1207
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
1208
if (window.console && window.console.log) {
1209
window.console.log(msg);
1
/*!
2
* jQuery Form Plugin
3
+ * version: 3.48.0-2013.12.28
4
* Requires jQuery v1.5 or later
5
* Copyright (c) 2013 M. Alsup
6
* Examples and documentation at: http://malsup.com/jquery/form/
12
13
// AMD support
14
(function (factory) {
15
+ "use strict";
16
if (typeof define === 'function' && define.amd) {
17
// using AMD; register as anon module
18
define(['jquery'], factory);
76
// contains inputs with names like "action" or "method"; in those
77
// cases "prop" returns the element
78
$.fn.attr2 = function() {
79
+ if ( ! hasProp ) {
80
return this.attr.apply(this, arguments);
81
+ }
82
var val = this.prop.apply(this, arguments);
83
+ if ( ( val && val.jquery ) || typeof val === 'string' ) {
84
return val;
85
+ }
86
return this.attr.apply(this, arguments);
87
};
88
260
$form.removeData('jqxhr').data('jqxhr', jqxhr);
261
262
// clear element array
263
+ for (var k=0; k < elements.length; k++) {
264
elements[k] = null;
265
+ }
266
267
// fire 'notify' event
268
this.trigger('form-submit-notify', [this, options]);
294
295
if (options.extraData) {
296
var serializedData = deepSerialize(options.extraData);
297
+ for (i=0; i < serializedData.length; i++) {
298
+ if (serializedData[i]) {
299
formdata.append(serializedData[i][0], serializedData[i][1]);
300
+ }
301
+ }
302
}
303
304
options.data = null;
333
var beforeSend = s.beforeSend;
334
s.beforeSend = function(xhr, o) {
335
//Send FormData() provided by user
336
+ if (options.formData) {
337
o.data = options.formData;
338
+ }
339
+ else {
340
o.data = formdata;
341
+ }
342
+ if(beforeSend) {
343
beforeSend.call(this, xhr, o);
344
+ }
345
};
346
return $.ajax(s);
347
}
360
// ensure that every serialized input is still enabled
361
for (i=0; i < elements.length; i++) {
362
el = $(elements[i]);
363
+ if ( hasProp ) {
364
el.prop('disabled', false);
365
+ }
366
+ else {
367
el.removeAttr('disabled');
368
+ }
369
}
370
}
371
375
if (s.iframeTarget) {
376
$io = $(s.iframeTarget);
377
n = $io.attr2('name');
378
+ if (!n) {
379
+ $io.attr2('name', id);
380
+ }
381
+ else {
382
id = n;
383
+ }
384
}
385
else {
386
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
412
413
$io.attr('src', s.iframeSrc); // abort op in progress
414
xhr.error = e;
415
+ if (s.error) {
416
s.error.call(s.context, xhr, e, status);
417
+ }
418
+ if (g) {
419
$.event.trigger("ajaxError", [xhr, s, e]);
420
+ }
421
+ if (s.complete) {
422
s.complete.call(s.context, xhr, e);
423
+ }
424
}
425
};
426
507
// take a breath so that pending repaints get some cpu time before the upload starts
508
function doSubmit() {
509
// make sure form attrs are set
510
+ var t = $form.attr2('target'),
511
+ a = $form.attr2('action'),
512
+ mp = 'multipart/form-data',
513
+ et = $form.attr('enctype') || $form.attr('encoding') || mp;
514
515
// update form attrs in IE friendly way
516
form.setAttribute('target',id);
539
try {
540
var state = getDoc(io).readyState;
541
log('state = ' + state);
542
+ if (state && state.toLowerCase() == 'uninitialized') {
543
setTimeout(checkState,50);
544
+ }
545
}
546
catch(e) {
547
log('Server abort: ' , e, ' (', e.name, ')');
548
cb(SERVER_ABORT);
549
+ if (timeoutHandle) {
550
clearTimeout(timeoutHandle);
551
+ }
552
timeoutHandle = undefined;
553
}
554
}
577
// add iframe to doc and submit the form
578
$io.appendTo('body');
579
}
580
+ if (io.attachEvent) {
581
io.attachEvent('onload', cb);
582
+ }
583
+ else {
584
io.addEventListener('load', cb, false);
585
+ }
586
setTimeout(checkState,15);
587
588
try {
596
finally {
597
// reset attrs and remove "extra" input elements
598
form.setAttribute('action',a);
599
+ form.setAttribute('enctype', et); // #380
600
if(t) {
601
form.setAttribute('target', t);
602
} else {
638
639
if (!doc || doc.location.href == s.iframeSrc) {
640
// response not received yet
641
+ if (!timedOut) {
642
return;
643
+ }
644
}
645
+ if (io.detachEvent) {
646
io.detachEvent('onload', cb);
647
+ }
648
+ else {
649
io.removeEventListener('load', cb, false);
650
+ }
651
652
var status = 'success', errMsg;
653
try {
674
var docRoot = doc.body ? doc.body : doc.documentElement;
675
xhr.responseText = docRoot ? docRoot.innerHTML : null;
676
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
677
+ if (isXml) {
678
s.dataType = 'xml';
679
+ }
680
xhr.getResponseHeader = function(header){
681
var headers = {'content-type': s.dataType};
682
return headers[header.toLowerCase()];
739
740
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
741
if (status === 'success') {
742
+ if (s.success) {
743
s.success.call(s.context, data, 'success', xhr);
744
+ }
745
deferred.resolve(xhr.responseText, 'success', xhr);
746
+ if (g) {
747
$.event.trigger("ajaxSuccess", [xhr, s]);
748
+ }
749
}
750
else if (status) {
751
+ if (errMsg === undefined) {
752
errMsg = xhr.statusText;
753
+ }
754
+ if (s.error) {
755
s.error.call(s.context, xhr, status, errMsg);
756
+ }
757
deferred.reject(xhr, 'error', errMsg);
758
+ if (g) {
759
$.event.trigger("ajaxError", [xhr, s, errMsg]);
760
+ }
761
}
762
763
+ if (g) {
764
$.event.trigger("ajaxComplete", [xhr, s]);
765
+ }
766
767
if (g && ! --$.active) {
768
$.event.trigger("ajaxStop");
769
}
770
771
+ if (s.complete) {
772
s.complete.call(s.context, xhr, status);
773
+ }
774
775
callbackProcessed = true;
776
+ if (s.timeout) {
777
clearTimeout(timeoutHandle);
778
+ }
779
780
// clean up
781
setTimeout(function() {
782
+ if (!s.iframeTarget) {
783
$io.remove();
784
+ }
785
+ else { //adding else to clean up existing iframe response.
786
$io.attr('src', s.iframeSrc);
787
+ }
788
xhr.responseXML = null;
789
}, 100);
790
}
812
data = xml ? xhr.responseXML : xhr.responseText;
813
814
if (xml && data.documentElement.nodeName === 'parsererror') {
815
+ if ($.error) {
816
$.error('parsererror');
817
+ }
818
}
819
if (s && s.dataFilter) {
820
data = s.dataFilter(data, type);
946
}
947
948
var form = this[0];
949
+ var formId = this.attr('id');
950
var els = semantic ? form.getElementsByTagName('*') : form.elements;
951
+ var els2;
952
+
953
+ if ( els ) {
954
+ els = $(els).get(); // convert to standard array
955
+ }
956
+
957
+ // #386; account for inputs outside the form which use the 'form' attribute
958
+ if ( formId ) {
959
+ els2 = $(':input[form=' + formId + ']').get();
960
+ if ( els2.length ) {
961
+ els = (els || []).concat(els2);
962
+ }
963
+ }
964
+
965
+ if (!els || !els.length) {
966
return a;
967
}
968
985
986
v = $.fieldValue(el, true);
987
if (v && v.constructor == Array) {
988
+ if (elements) {
989
elements.push(el);
990
+ }
991
for(j=0, jmax=v.length; j < jmax; j++) {
992
a.push({name: n, value: v[j]});
993
}
994
}
995
else if (feature.fileapi && el.type == 'file') {
996
+ if (elements) {
997
elements.push(el);
998
+ }
999
var files = el.files;
1000
if (files.length) {
1001
for (j=0; j < files.length; j++) {
1008
}
1009
}
1010
else if (v !== null && typeof v != 'undefined') {
1011
+ if (elements) {
1012
elements.push(el);
1013
+ }
1014
a.push({name: n, value: v, type: el.type, required: el.required});
1015
}
1016
}
1106
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
1107
continue;
1108
}
1109
+ if (v.constructor == Array) {
1110
$.merge(val, v);
1111
+ }
1112
+ else {
1113
val.push(v);
1114
+ }
1115
}
1116
return val;
1117
};
1145
if (op.selected) {
1146
var v = op.value;
1147
if (!v) { // extra pain for IE...
1148
+ v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
1149
}
1150
if (one) {
1151
return v;
1201
// $('#myForm').clearForm('.special:hidden')
1202
// the above would clean hidden inputs that have the class of 'special'
1203
if ( (includeHidden === true && /hidden/.test(t)) ||
1204
+ (typeof includeHidden == 'string' && $(this).is(includeHidden)) ) {
1205
this.value = '';
1206
+ }
1207
}
1208
});
1209
};
1262
1263
// helper fn for console logging
1264
function log() {
1265
+ if (!$.fn.ajaxSubmit.debug) {
1266
return;
1267
+ }
1268
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
1269
if (window.console && window.console.log) {
1270
window.console.log(msg);
includes/js/jquery.form.min.js CHANGED
@@ -1,7 +1,7 @@
1
/*
2
- * jQuery Form Plugin; v20131121
3
* http://jquery.malsup.com/form/
4
* Copyright (c) 2013 M. Alsup; Dual licensed: MIT/GPL
5
* https://github.com/malsup/form#copyright-and-license
6
*/
7
- ;(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e("undefined"!=typeof jQuery?jQuery:window.Zepto)})(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=this;if(i.clk=r,"image"==r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n={};n.fileapi=void 0!==e("<input type='file'/>").get(0).files,n.formdata=void 0!==window.FormData;var i=!!e.fn.prop;e.fn.attr2=function(){if(!i)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t){function r(r){var a,n,i=e.param(r,t.traditional).split("&"),o=i.length,s=[];for(a=0;o>a;a++)i[a]=i[a].replace(/\+/g," "),n=i[a].split("="),s.push([decodeURIComponent(n[0]),decodeURIComponent(n[1])]);return s}function o(a){for(var n=new FormData,i=0;a.length>i;i++)n.append(a[i].name,a[i].value);if(t.extraData){var o=r(t.extraData);for(i=0;o.length>i;i++)o[i]&&n.append(o[i][0],o[i][1])}t.data=null;var s=e.extend(!0,{},e.ajaxSettings,t,{contentType:!1,processData:!1,cache:!1,type:u||"POST"});t.uploadProgress&&(s.xhr=function(){var r=e.ajaxSettings.xhr();return r.upload&&r.upload.addEventListener("progress",function(e){var r=0,a=e.loaded||e.position,n=e.total;e.lengthComputable&&(r=Math.ceil(100*(a/n))),t.uploadProgress(e,a,n,r)},!1),r}),s.data=null;var c=s.beforeSend;return s.beforeSend=function(e,r){r.data=t.formData?t.formData:n,c&&c.call(this,e,r)},e.ajax(s)}function s(r){function n(e){var t=null;try{e.contentWindow&&(t=e.contentWindow.document)}catch(r){a("cannot get iframe.contentWindow document: "+r)}if(t)return t;try{t=e.contentDocument?e.contentDocument:e.document}catch(r){a("cannot get iframe.contentDocument: "+r),t=e.document}return t}function o(){function t(){try{var e=n(g).readyState;a("state = "+e),e&&"uninitialized"==e.toLowerCase()&&setTimeout(t,50)}catch(r){a("Server abort: ",r," (",r.name,")"),s(k),j&&clearTimeout(j),j=void 0}}var r=f.attr2("target"),i=f.attr2("action");w.setAttribute("target",p),(!u||/post/i.test(u))&&w.setAttribute("method","POST"),i!=m.url&&w.setAttribute("action",m.url),m.skipEncodingOverride||u&&!/post/i.test(u)||f.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(j=setTimeout(function(){T=!0,s(D)},m.timeout));var o=[];try{if(m.extraData)for(var c in m.extraData)m.extraData.hasOwnProperty(c)&&(e.isPlainObject(m.extraData[c])&&m.extraData[c].hasOwnProperty("name")&&m.extraData[c].hasOwnProperty("value")?o.push(e('<input type="hidden" name="'+m.extraData[c].name+'">').val(m.extraData[c].value).appendTo(w)[0]):o.push(e('<input type="hidden" name="'+c+'">').val(m.extraData[c]).appendTo(w)[0]));m.iframeTarget||v.appendTo("body"),g.attachEvent?g.attachEvent("onload",s):g.addEventListener("load",s,!1),setTimeout(t,15);try{w.submit()}catch(l){var d=document.createElement("form").submit;d.apply(w)}}finally{w.setAttribute("action",i),r?w.setAttribute("target",r):f.removeAttr("target"),e(o).remove()}}function s(t){if(!x.aborted&&!F){if(M=n(g),M||(a("cannot access response document"),t=k),t===D&&x)return x.abort("timeout"),S.reject(x,"timeout"),void 0;if(t==k&&x)return x.abort("server abort"),S.reject(x,"error","server abort"),void 0;if(M&&M.location.href!=m.iframeSrc||T){g.detachEvent?g.detachEvent("onload",s):g.removeEventListener("load",s,!1);var r,i="success";try{if(T)throw"timeout";var o="xml"==m.dataType||M.XMLDocument||e.isXMLDoc(M);if(a("isXml="+o),!o&&window.opera&&(null===M.body||!M.body.innerHTML)&&--O)return a("requeing onLoad callback, DOM not available"),setTimeout(s,250),void 0;var u=M.body?M.body:M.documentElement;x.responseText=u?u.innerHTML:null,x.responseXML=M.XMLDocument?M.XMLDocument:M,o&&(m.dataType="xml"),x.getResponseHeader=function(e){var t={"content-type":m.dataType};return t[e.toLowerCase()]},u&&(x.status=Number(u.getAttribute("status"))||x.status,x.statusText=u.getAttribute("statusText")||x.statusText);var c=(m.dataType||"").toLowerCase(),l=/(json|script|text)/.test(c);if(l||m.textarea){var f=M.getElementsByTagName("textarea")[0];if(f)x.responseText=f.value,x.status=Number(f.getAttribute("status"))||x.status,x.statusText=f.getAttribute("statusText")||x.statusText;else if(l){var p=M.getElementsByTagName("pre")[0],h=M.getElementsByTagName("body")[0];p?x.responseText=p.textContent?p.textContent:p.innerText:h&&(x.responseText=h.textContent?h.textContent:h.innerText)}}else"xml"==c&&!x.responseXML&&x.responseText&&(x.responseXML=X(x.responseText));try{E=_(x,c,m)}catch(b){i="parsererror",x.error=r=b||i}}catch(b){a("error caught: ",b),i="error",x.error=r=b||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&300>x.status||304===x.status?"success":"error"),"success"===i?(m.success&&m.success.call(m.context,E,"success",x),S.resolve(x.responseText,"success",x),d&&e.event.trigger("ajaxSuccess",[x,m])):i&&(void 0===r&&(r=x.statusText),m.error&&m.error.call(m.context,x,i,r),S.reject(x,"error",r),d&&e.event.trigger("ajaxError",[x,m,r])),d&&e.event.trigger("ajaxComplete",[x,m]),d&&!--e.active&&e.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,x,i),F=!0,m.timeout&&clearTimeout(j),setTimeout(function(){m.iframeTarget?v.attr("src",m.iframeSrc):v.remove(),x.responseXML=null},100)}}}var c,l,m,d,p,v,g,x,b,y,T,j,w=f[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(l=0;h.length>l;l++)c=e(h[l]),i?c.prop("disabled",!1):c.removeAttr("disabled");if(m=e.extend(!0,{},e.ajaxSettings,t),m.context=m.context||m,p="jqFormIO"+(new Date).getTime(),m.iframeTarget?(v=e(m.iframeTarget),y=v.attr2("name"),y?p=y:v.attr2("name",p)):(v=e('<iframe name="'+p+'" src="'+m.iframeSrc+'" />'),v.css({position:"absolute",top:"-1000px",left:"-1000px"})),g=v[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{g.contentWindow.document.execCommand&&g.contentWindow.document.execCommand("Stop")}catch(n){}v.attr("src",m.iframeSrc),x.error=r,m.error&&m.error.call(m.context,x,r,t),d&&e.event.trigger("ajaxError",[x,m,r]),m.complete&&m.complete.call(m.context,x,r)}},d=m.global,d&&0===e.active++&&e.event.trigger("ajaxStart"),d&&e.event.trigger("ajaxSend",[x,m]),m.beforeSend&&m.beforeSend.call(m.context,x,m)===!1)return m.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;b=w.clk,b&&(y=b.name,y&&!b.disabled&&(m.extraData=m.extraData||{},m.extraData[y]=b.value,"image"==b.type&&(m.extraData[y+".x"]=w.clk_x,m.extraData[y+".y"]=w.clk_y)));var D=1,k=2,A=e("meta[name=csrf-token]").attr("content"),L=e("meta[name=csrf-param]").attr("content");L&&A&&(m.extraData=m.extraData||{},m.extraData[L]=A),m.forceSync?o():setTimeout(o,10);var E,M,F,O=50,X=e.parseXML||function(e,t){return window.ActiveXObject?(t=new ActiveXObject("Microsoft.XMLDOM"),t.async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!=t.documentElement.nodeName?t:null},C=e.parseJSON||function(e){return window.eval("("+e+")")},_=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i="xml"===r||!r&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&("json"===r||!r&&n.indexOf("json")>=0?o=C(o):("script"===r||!r&&n.indexOf("javascript")>=0)&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var u,c,l,f=this;"function"==typeof t?t={success:t}:void 0===t&&(t={}),u=t.type||this.attr2("method"),c=t.url||this.attr2("action"),l="string"==typeof c?e.trim(c):"",l=l||window.location.href||"",l&&(l=(l.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:l,success:e.ajaxSettings.success,type:u||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&t.beforeSerialize(this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var d=t.traditional;void 0===d&&(d=e.ajaxSettings.traditional);var p,h=[],v=this.formToArray(t.semantic,h);if(t.data&&(t.extraData=t.data,p=e.param(t.data,d)),t.beforeSubmit&&t.beforeSubmit(v,this,t)===!1)return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[v,this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var g=e.param(v,d);p&&(g=g?g+"&"+p:p),"GET"==t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+g,t.data=null):t.data=g;var x=[];if(t.resetForm&&x.push(function(){f.resetForm()}),t.clearForm&&x.push(function(){f.clearForm(t.includeHidden)}),!t.dataType&&t.target){var b=t.success||function(){};x.push(function(r){var a=t.replaceTarget?"replaceWith":"html";e(t.target)[a](r).each(b,arguments)})}else t.success&&x.push(t.success);if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=x.length;o>i;i++)x[i].apply(n,[e,r,a||f,f])},t.error){var y=t.error;t.error=function(e,r,a){var n=t.context||this;y.apply(n,[e,r,a,f])}}if(t.complete){var T=t.complete;t.complete=function(e,r){var a=t.context||this;T.apply(a,[e,r,f])}}var j=e("input[type=file]:enabled",this).filter(function(){return""!==e(this).val()}),w=j.length>0,S="multipart/form-data",D=f.attr("enctype")==S||f.attr("encoding")==S,k=n.fileapi&&n.formdata;a("fileAPI :"+k);var A,L=(w||D)&&!k;t.iframe!==!1&&(t.iframe||L)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){A=s(v)}):A=s(v):A=(w||D)&&k?o(v):e.ajax(t),f.removeData("jqxhr").data("jqxhr",A);for(var E=0;h.length>E;E++)h[E]=null;return this.trigger("form-submit-notify",[this,t]),this},e.fn.ajaxForm=function(n){if(n=n||{},n.delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var i={s:this.selector,c:this.context};return!e.isReady&&i.s?(a("DOM not ready, queuing ajaxForm"),e(function(){e(i.s,i.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,r).on("submit.form-plugin",this.selector,n,t).on("click.form-plugin",this.selector,n,r),this):this.ajaxFormUnbind().bind("submit.form-plugin",n,t).bind("click.form-plugin",n,r)},e.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r){var a=[];if(0===this.length)return a;var i=this[0],o=t?i.getElementsByTagName("*"):i.elements;if(!o)return a;var s,u,c,l,f,m,d;for(s=0,m=o.length;m>s;s++)if(f=o[s],c=f.name,c&&!f.disabled)if(t&&i.clk&&"image"==f.type)i.clk==f&&(a.push({name:c,value:e(f).val(),type:f.type}),a.push({name:c+".x",value:i.clk_x},{name:c+".y",value:i.clk_y}));else if(l=e.fieldValue(f,!0),l&&l.constructor==Array)for(r&&r.push(f),u=0,d=l.length;d>u;u++)a.push({name:c,value:l[u]});else if(n.fileapi&&"file"==f.type){r&&r.push(f);var p=f.files;if(p.length)for(u=0;p.length>u;u++)a.push({name:c,value:p[u],type:f.type});else a.push({name:c,value:"",type:f.type})}else null!==l&&l!==void 0&&(r&&r.push(f),a.push({name:c,value:l,type:f.type,required:f.required}));if(!t&&i.clk){var h=e(i.clk),v=h[0];c=v.name,c&&!v.disabled&&"image"==v.type&&(a.push({name:c,value:h.val()}),a.push({name:c+".x",value:i.clk_x},{name:c+".y",value:i.clk_y}))}return a},e.fn.formSerialize=function(t){return e.param(this.formToArray(t))},e.fn.fieldSerialize=function(t){var r=[];return this.each(function(){var a=this.name;if(a){var n=e.fieldValue(this,t);if(n&&n.constructor==Array)for(var i=0,o=n.length;o>i;i++)r.push({name:a,value:n[i]});else null!==n&&n!==void 0&&r.push({name:this.name,value:n})}}),e.param(r)},e.fn.fieldValue=function(t){for(var r=[],a=0,n=this.length;n>a;a++){var i=this[a],o=e.fieldValue(i,t);null===o||void 0===o||o.constructor==Array&&!o.length||(o.constructor==Array?e.merge(r,o):r.push(o))}return r},e.fieldValue=function(t,r){var a=t.name,n=t.type,i=t.tagName.toLowerCase();if(void 0===r&&(r=!0),r&&(!a||t.disabled||"reset"==n||"button"==n||("checkbox"==n||"radio"==n)&&!t.checked||("submit"==n||"image"==n)&&t.form&&t.form.clk!=t||"select"==i&&-1==t.selectedIndex))return null;if("select"==i){var o=t.selectedIndex;if(0>o)return null;for(var s=[],u=t.options,c="select-one"==n,l=c?o+1:u.length,f=c?o:0;l>f;f++){var m=u[f];if(m.selected){var d=m.value;if(d||(d=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),c)return d;s.push(d)}}return s}return e(t).val()},e.fn.clearForm=function(t){return this.each(function(){e("input,select,textarea",this).clearFields(t)})},e.fn.clearFields=e.fn.clearInputs=function(t){var r=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)#x2F;i;return this.each(function(){var a=this.type,n=this.tagName.toLowerCase();r.test(a)||"textarea"==n?this.value="":"checkbox"==a||"radio"==a?this.checked=!1:"select"==n?this.selectedIndex=-1:"file"==a?/MSIE/.test(navigator.userAgent)?e(this).replaceWith(e(this).clone(!0)):e(this).val(""):t&&(t===!0&&/hidden/.test(a)||"string"==typeof t&&e(this).is(t))&&(this.value="")})},e.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},e.fn.enable=function(e){return void 0===e&&(e=!0),this.each(function(){this.disabled=!e})},e.fn.selected=function(t){return void 0===t&&(t=!0),this.each(function(){var r=this.type;if("checkbox"==r||"radio"==r)this.checked=t;else if("option"==this.tagName.toLowerCase()){var a=e(this).parent("select");t&&a[0]&&"select-one"==a[0].type&&a.find("option").selected(!1),this.selected=t}})},e.fn.ajaxSubmit.debug=!1});
1
/*
2
+ * jQuery Form Plugin; v20131228
3
* http://jquery.malsup.com/form/
4
* Copyright (c) 2013 M. Alsup; Dual licensed: MIT/GPL
5
* https://github.com/malsup/form#copyright-and-license
6
*/
7
+ ;!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):a("undefined"!=typeof jQuery?jQuery:window.Zepto)}(function(a){"use strict";function b(b){var c=b.data;b.isDefaultPrevented()||(b.preventDefault(),a(b.target).ajaxSubmit(c))}function c(b){var c=b.target,d=a(c);if(!d.is("[type=submit],[type=image]")){var e=d.closest("[type=submit]");if(0===e.length)return;c=e[0]}var f=this;if(f.clk=c,"image"==c.type)if(void 0!==b.offsetX)f.clk_x=b.offsetX,f.clk_y=b.offsetY;else if("function"==typeof a.fn.offset){var g=d.offset();f.clk_x=b.pageX-g.left,f.clk_y=b.pageY-g.top}else f.clk_x=b.pageX-c.offsetLeft,f.clk_y=b.pageY-c.offsetTop;setTimeout(function(){f.clk=f.clk_x=f.clk_y=null},100)}function d(){if(a.fn.ajaxSubmit.debug){var b="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(b):window.opera&&window.opera.postError&&window.opera.postError(b)}}var e={};e.fileapi=void 0!==a("<input type='file'/>").get(0).files,e.formdata=void 0!==window.FormData;var f=!!a.fn.prop;a.fn.attr2=function(){if(!f)return this.attr.apply(this,arguments);var a=this.prop.apply(this,arguments);return a&&a.jquery||"string"==typeof a?a:this.attr.apply(this,arguments)},a.fn.ajaxSubmit=function(b){function c(c){var d,e,f=a.param(c,b.traditional).split("&"),g=f.length,h=[];for(d=0;g>d;d++)f[d]=f[d].replace(/\+/g," "),e=f[d].split("="),h.push([decodeURIComponent(e[0]),decodeURIComponent(e[1])]);return h}function g(d){for(var e=new FormData,f=0;f<d.length;f++)e.append(d[f].name,d[f].value);if(b.extraData){var g=c(b.extraData);for(f=0;f<g.length;f++)g[f]&&e.append(g[f][0],g[f][1])}b.data=null;var h=a.extend(!0,{},a.ajaxSettings,b,{contentType:!1,processData:!1,cache:!1,type:i||"POST"});b.uploadProgress&&(h.xhr=function(){var c=a.ajaxSettings.xhr();return c.upload&&c.upload.addEventListener("progress",function(a){var c=0,d=a.loaded||a.position,e=a.total;a.lengthComputable&&(c=Math.ceil(d/e*100)),b.uploadProgress(a,d,e,c)},!1),c}),h.data=null;var j=h.beforeSend;return h.beforeSend=function(a,c){c.data=b.formData?b.formData:e,j&&j.call(this,a,c)},a.ajax(h)}function h(c){function e(a){var b=null;try{a.contentWindow&&(b=a.contentWindow.document)}catch(c){d("cannot get iframe.contentWindow document: "+c)}if(b)return b;try{b=a.contentDocument?a.contentDocument:a.document}catch(c){d("cannot get iframe.contentDocument: "+c),b=a.document}return b}function g(){function b(){try{var a=e(r).readyState;d("state = "+a),a&&"uninitialized"==a.toLowerCase()&&setTimeout(b,50)}catch(c){d("Server abort: ",c," (",c.name,")"),h(A),w&&clearTimeout(w),w=void 0}}var c=l.attr2("target"),f=l.attr2("action"),g="multipart/form-data",j=l.attr("enctype")||l.attr("encoding")||g;x.setAttribute("target",o),(!i||/post/i.test(i))&&x.setAttribute("method","POST"),f!=m.url&&x.setAttribute("action",m.url),m.skipEncodingOverride||i&&!/post/i.test(i)||l.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"}),m.timeout&&(w=setTimeout(function(){v=!0,h(z)},m.timeout));var k=[];try{if(m.extraData)for(var n in m.extraData)m.extraData.hasOwnProperty(n)&&(a.isPlainObject(m.extraData[n])&&m.extraData[n].hasOwnProperty("name")&&m.extraData[n].hasOwnProperty("value")?k.push(a('<input type="hidden" name="'+m.extraData[n].name+'">').val(m.extraData[n].value).appendTo(x)[0]):k.push(a('<input type="hidden" name="'+n+'">').val(m.extraData[n]).appendTo(x)[0]));m.iframeTarget||q.appendTo("body"),r.attachEvent?r.attachEvent("onload",h):r.addEventListener("load",h,!1),setTimeout(b,15);try{x.submit()}catch(p){var s=document.createElement("form").submit;s.apply(x)}}finally{x.setAttribute("action",f),x.setAttribute("enctype",j),c?x.setAttribute("target",c):l.removeAttr("target"),a(k).remove()}}function h(b){if(!s.aborted&&!F){if(E=e(r),E||(d("cannot access response document"),b=A),b===z&&s)return s.abort("timeout"),y.reject(s,"timeout"),void 0;if(b==A&&s)return s.abort("server abort"),y.reject(s,"error","server abort"),void 0;if(E&&E.location.href!=m.iframeSrc||v){r.detachEvent?r.detachEvent("onload",h):r.removeEventListener("load",h,!1);var c,f="success";try{if(v)throw"timeout";var g="xml"==m.dataType||E.XMLDocument||a.isXMLDoc(E);if(d("isXml="+g),!g&&window.opera&&(null===E.body||!E.body.innerHTML)&&--G)return d("requeing onLoad callback, DOM not available"),setTimeout(h,250),void 0;var i=E.body?E.body:E.documentElement;s.responseText=i?i.innerHTML:null,s.responseXML=E.XMLDocument?E.XMLDocument:E,g&&(m.dataType="xml"),s.getResponseHeader=function(a){var b={"content-type":m.dataType};return b[a.toLowerCase()]},i&&(s.status=Number(i.getAttribute("status"))||s.status,s.statusText=i.getAttribute("statusText")||s.statusText);var j=(m.dataType||"").toLowerCase(),k=/(json|script|text)/.test(j);if(k||m.textarea){var l=E.getElementsByTagName("textarea")[0];if(l)s.responseText=l.value,s.status=Number(l.getAttribute("status"))||s.status,s.statusText=l.getAttribute("statusText")||s.statusText;else if(k){var o=E.getElementsByTagName("pre")[0],p=E.getElementsByTagName("body")[0];o?s.responseText=o.textContent?o.textContent:o.innerText:p&&(s.responseText=p.textContent?p.textContent:p.innerText)}}else"xml"==j&&!s.responseXML&&s.responseText&&(s.responseXML=H(s.responseText));try{D=J(s,j,m)}catch(t){f="parsererror",s.error=c=t||f}}catch(t){d("error caught: ",t),f="error",s.error=c=t||f}s.aborted&&(d("upload aborted"),f=null),s.status&&(f=s.status>=200&&s.status<300||304===s.status?"success":"error"),"success"===f?(m.success&&m.success.call(m.context,D,"success",s),y.resolve(s.responseText,"success",s),n&&a.event.trigger("ajaxSuccess",[s,m])):f&&(void 0===c&&(c=s.statusText),m.error&&m.error.call(m.context,s,f,c),y.reject(s,"error",c),n&&a.event.trigger("ajaxError",[s,m,c])),n&&a.event.trigger("ajaxComplete",[s,m]),n&&!--a.active&&a.event.trigger("ajaxStop"),m.complete&&m.complete.call(m.context,s,f),F=!0,m.timeout&&clearTimeout(w),setTimeout(function(){m.iframeTarget?q.attr("src",m.iframeSrc):q.remove(),s.responseXML=null},100)}}}var j,k,m,n,o,q,r,s,t,u,v,w,x=l[0],y=a.Deferred();if(y.abort=function(a){s.abort(a)},c)for(k=0;k<p.length;k++)j=a(p[k]),f?j.prop("disabled",!1):j.removeAttr("disabled");if(m=a.extend(!0,{},a.ajaxSettings,b),m.context=m.context||m,o="jqFormIO"+(new Date).getTime(),m.iframeTarget?(q=a(m.iframeTarget),u=q.attr2("name"),u?o=u:q.attr2("name",o)):(q=a('<iframe name="'+o+'" src="'+m.iframeSrc+'" />'),q.css({position:"absolute",top:"-1000px",left:"-1000px"})),r=q[0],s={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(b){var c="timeout"===b?"timeout":"aborted";d("aborting upload... "+c),this.aborted=1;try{r.contentWindow.document.execCommand&&r.contentWindow.document.execCommand("Stop")}catch(e){}q.attr("src",m.iframeSrc),s.error=c,m.error&&m.error.call(m.context,s,c,b),n&&a.event.trigger("ajaxError",[s,m,c]),m.complete&&m.complete.call(m.context,s,c)}},n=m.global,n&&0===a.active++&&a.event.trigger("ajaxStart"),n&&a.event.trigger("ajaxSend",[s,m]),m.beforeSend&&m.beforeSend.call(m.context,s,m)===!1)return m.global&&a.active--,y.reject(),y;if(s.aborted)return y.reject(),y;t=x.clk,t&&(u=t.name,u&&!t.disabled&&(m.extraData=m.extraData||{},m.extraData[u]=t.value,"image"==t.type&&(m.extraData[u+".x"]=x.clk_x,m.extraData[u+".y"]=x.clk_y)));var z=1,A=2,B=a("meta[name=csrf-token]").attr("content"),C=a("meta[name=csrf-param]").attr("content");C&&B&&(m.extraData=m.extraData||{},m.extraData[C]=B),m.forceSync?g():setTimeout(g,10);var D,E,F,G=50,H=a.parseXML||function(a,b){return window.ActiveXObject?(b=new ActiveXObject("Microsoft.XMLDOM"),b.async="false",b.loadXML(a)):b=(new DOMParser).parseFromString(a,"text/xml"),b&&b.documentElement&&"parsererror"!=b.documentElement.nodeName?b:null},I=a.parseJSON||function(a){return window.eval("("+a+")")},J=function(b,c,d){var e=b.getResponseHeader("content-type")||"",f="xml"===c||!c&&e.indexOf("xml")>=0,g=f?b.responseXML:b.responseText;return f&&"parsererror"===g.documentElement.nodeName&&a.error&&a.error("parsererror"),d&&d.dataFilter&&(g=d.dataFilter(g,c)),"string"==typeof g&&("json"===c||!c&&e.indexOf("json")>=0?g=I(g):("script"===c||!c&&e.indexOf("javascript")>=0)&&a.globalEval(g)),g};return y}if(!this.length)return d("ajaxSubmit: skipping submit process - no element selected"),this;var i,j,k,l=this;"function"==typeof b?b={success:b}:void 0===b&&(b={}),i=b.type||this.attr2("method"),j=b.url||this.attr2("action"),k="string"==typeof j?a.trim(j):"",k=k||window.location.href||"",k&&(k=(k.match(/^([^#]+)/)||[])[1]),b=a.extend(!0,{url:k,success:a.ajaxSettings.success,type:i||a.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},b);var m={};if(this.trigger("form-pre-serialize",[this,b,m]),m.veto)return d("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(b.beforeSerialize&&b.beforeSerialize(this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var n=b.traditional;void 0===n&&(n=a.ajaxSettings.traditional);var o,p=[],q=this.formToArray(b.semantic,p);if(b.data&&(b.extraData=b.data,o=a.param(b.data,n)),b.beforeSubmit&&b.beforeSubmit(q,this,b)===!1)return d("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[q,this,b,m]),m.veto)return d("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var r=a.param(q,n);o&&(r=r?r+"&"+o:o),"GET"==b.type.toUpperCase()?(b.url+=(b.url.indexOf("?")>=0?"&":"?")+r,b.data=null):b.data=r;var s=[];if(b.resetForm&&s.push(function(){l.resetForm()}),b.clearForm&&s.push(function(){l.clearForm(b.includeHidden)}),!b.dataType&&b.target){var t=b.success||function(){};s.push(function(c){var d=b.replaceTarget?"replaceWith":"html";a(b.target)[d](c).each(t,arguments)})}else b.success&&s.push(b.success);if(b.success=function(a,c,d){for(var e=b.context||this,f=0,g=s.length;g>f;f++)s[f].apply(e,[a,c,d||l,l])},b.error){var u=b.error;b.error=function(a,c,d){var e=b.context||this;u.apply(e,[a,c,d,l])}}if(b.complete){var v=b.complete;b.complete=function(a,c){var d=b.context||this;v.apply(d,[a,c,l])}}var w=a("input[type=file]:enabled",this).filter(function(){return""!==a(this).val()}),x=w.length>0,y="multipart/form-data",z=l.attr("enctype")==y||l.attr("encoding")==y,A=e.fileapi&&e.formdata;d("fileAPI :"+A);var B,C=(x||z)&&!A;b.iframe!==!1&&(b.iframe||C)?b.closeKeepAlive?a.get(b.closeKeepAlive,function(){B=h(q)}):B=h(q):B=(x||z)&&A?g(q):a.ajax(b),l.removeData("jqxhr").data("jqxhr",B);for(var D=0;D<p.length;D++)p[D]=null;return this.trigger("form-submit-notify",[this,b]),this},a.fn.ajaxForm=function(e){if(e=e||{},e.delegation=e.delegation&&a.isFunction(a.fn.on),!e.delegation&&0===this.length){var f={s:this.selector,c:this.context};return!a.isReady&&f.s?(d("DOM not ready, queuing ajaxForm"),a(function(){a(f.s,f.c).ajaxForm(e)}),this):(d("terminating; zero elements found by selector"+(a.isReady?"":" (DOM not ready)")),this)}return e.delegation?(a(document).off("submit.form-plugin",this.selector,b).off("click.form-plugin",this.selector,c).on("submit.form-plugin",this.selector,e,b).on("click.form-plugin",this.selector,e,c),this):this.ajaxFormUnbind().bind("submit.form-plugin",e,b).bind("click.form-plugin",e,c)},a.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")},a.fn.formToArray=function(b,c){var d=[];if(0===this.length)return d;var f,g=this[0],h=this.attr("id"),i=b?g.getElementsByTagName("*"):g.elements;if(i&&(i=a(i).get()),h&&(f=a(":input[form="+h+"]").get(),f.length&&(i=(i||[]).concat(f))),!i||!i.length)return d;var j,k,l,m,n,o,p;for(j=0,o=i.length;o>j;j++)if(n=i[j],l=n.name,l&&!n.disabled)if(b&&g.clk&&"image"==n.type)g.clk==n&&(d.push({name:l,value:a(n).val(),type:n.type}),d.push({name:l+".x",value:g.clk_x},{name:l+".y",value:g.clk_y}));else if(m=a.fieldValue(n,!0),m&&m.constructor==Array)for(c&&c.push(n),k=0,p=m.length;p>k;k++)d.push({name:l,value:m[k]});else if(e.fileapi&&"file"==n.type){c&&c.push(n);var q=n.files;if(q.length)for(k=0;k<q.length;k++)d.push({name:l,value:q[k],type:n.type});else d.push({name:l,value:"",type:n.type})}else null!==m&&"undefined"!=typeof m&&(c&&c.push(n),d.push({name:l,value:m,type:n.type,required:n.required}));if(!b&&g.clk){var r=a(g.clk),s=r[0];l=s.name,l&&!s.disabled&&"image"==s.type&&(d.push({name:l,value:r.val()}),d.push({name:l+".x",value:g.clk_x},{name:l+".y",value:g.clk_y}))}return d},a.fn.formSerialize=function(b){return a.param(this.formToArray(b))},a.fn.fieldSerialize=function(b){var c=[];return this.each(function(){var d=this.name;if(d){var e=a.fieldValue(this,b);if(e&&e.constructor==Array)for(var f=0,g=e.length;g>f;f++)c.push({name:d,value:e[f]});else null!==e&&"undefined"!=typeof e&&c.push({name:this.name,value:e})}}),a.param(c)},a.fn.fieldValue=function(b){for(var c=[],d=0,e=this.length;e>d;d++){var f=this[d],g=a.fieldValue(f,b);null===g||"undefined"==typeof g||g.constructor==Array&&!g.length||(g.constructor==Array?a.merge(c,g):c.push(g))}return c},a.fieldValue=function(b,c){var d=b.name,e=b.type,f=b.tagName.toLowerCase();if(void 0===c&&(c=!0),c&&(!d||b.disabled||"reset"==e||"button"==e||("checkbox"==e||"radio"==e)&&!b.checked||("submit"==e||"image"==e)&&b.form&&b.form.clk!=b||"select"==f&&-1==b.selectedIndex))return null;if("select"==f){var g=b.selectedIndex;if(0>g)return null;for(var h=[],i=b.options,j="select-one"==e,k=j?g+1:i.length,l=j?g:0;k>l;l++){var m=i[l];if(m.selected){var n=m.value;if(n||(n=m.attributes&&m.attributes.value&&!m.attributes.value.specified?m.text:m.value),j)return n;h.push(n)}}return h}return a(b).val()},a.fn.clearForm=function(b){return this.each(function(){a("input,select,textarea",this).clearFields(b)})},a.fn.clearFields=a.fn.clearInputs=function(b){var c=/^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)#x2F;i;return this.each(function(){var d=this.type,e=this.tagName.toLowerCase();c.test(d)||"textarea"==e?this.value="":"checkbox"==d||"radio"==d?this.checked=!1:"select"==e?this.selectedIndex=-1:"file"==d?/MSIE/.test(navigator.userAgent)?a(this).replaceWith(a(this).clone(!0)):a(this).val(""):b&&(b===!0&&/hidden/.test(d)||"string"==typeof b&&a(this).is(b))&&(this.value="")})},a.fn.resetForm=function(){return this.each(function(){("function"==typeof this.reset||"object"==typeof this.reset&&!this.reset.nodeType)&&this.reset()})},a.fn.enable=function(a){return void 0===a&&(a=!0),this.each(function(){this.disabled=!a})},a.fn.selected=function(b){return void 0===b&&(b=!0),this.each(function(){var c=this.type;if("checkbox"==c||"radio"==c)this.checked=b;else if("option"==this.tagName.toLowerCase()){var d=a(this).parent("select");b&&d[0]&&"select-one"==d[0].type&&d.find("option").selected(!1),this.selected=b}})},a.fn.ajaxSubmit.debug=!1});
includes/js/scripts.js CHANGED
@@ -46,6 +46,8 @@
46
47
this.find('.wpcf7-exclusive-checkbox').wpcf7ExclusiveCheckbox();
48
49
this.find('[placeholder]').wpcf7Placeholder();
50
51
if (_wpcf7.jqueryUi && ! _wpcf7.supportHtml5.date) {
@@ -199,10 +201,53 @@
199
});
200
};
201
202
$.fn.wpcf7NotValidTip = function(message) {
203
return this.each(function() {
204
- var into = $(this);
205
- into.hide().append('<span role="alert" class="wpcf7-not-valid-tip">' + message + '</span>').slideDown('fast');
206
});
207
};
208
46
47
this.find('.wpcf7-exclusive-checkbox').wpcf7ExclusiveCheckbox();
48
49
+ this.find('.wpcf7-list-item.has-free-text').wpcf7ToggleCheckboxFreetext();
50
+
51
this.find('[placeholder]').wpcf7Placeholder();
52
53
if (_wpcf7.jqueryUi && ! _wpcf7.supportHtml5.date) {
201
});
202
};
203
204
+ $.fn.wpcf7ToggleCheckboxFreetext = function() {
205
+ return this.each(function() {
206
+ var $wrap = $(this).closest('.wpcf7-form-control');
207
+
208
+ if ($(this).find(':checkbox, :radio').is(':checked')) {
209
+ $(this).find(':input.wpcf7-free-text').prop('disabled', false);
210
+ } else {
211
+ $(this).find(':input.wpcf7-free-text').prop('disabled', true);
212
+ }
213
+
214
+ $wrap.find(':checkbox, :radio').change(function() {
215
+ var $cb = $('.has-free-text', $wrap).find(':checkbox, :radio');
216
+ var $freetext = $(':input.wpcf7-free-text', $wrap);
217
+
218
+ if ($cb.is(':checked')) {
219
+ $freetext.prop('disabled', false).focus();
220
+ } else {
221
+ $freetext.prop('disabled', true);
222
+ }
223
+ });
224
+ });
225
+ };
226
+
227
$.fn.wpcf7NotValidTip = function(message) {
228
return this.each(function() {
229
+ var $into = $(this);
230
+ $into.hide().append('<span role="alert" class="wpcf7-not-valid-tip">' + message + '</span>').slideDown('fast');
231
+
232
+ if ($into.is('.use-floating-validation-tip *')) {
233
+ $('.wpcf7-not-valid-tip', $into).mouseover(function() {
234
+ $(this).wpcf7FadeOut();
235
+ });
236
+
237
+ $(':input', $into).focus(function() {
238
+ $('.wpcf7-not-valid-tip', $into).not(':hidden').wpcf7FadeOut();
239
+ });
240
+ }
241
+ });
242
+ };
243
+
244
+ $.fn.wpcf7FadeOut = function() {
245
+ return this.each(function() {
246
+ $(this).animate({
247
+ opacity: 0
248
+ }, 'fast', function() {
249
+ $(this).css({'z-index': -100});
250
+ });
251
});
252
};
253
includes/pipe.php CHANGED
@@ -2,11 +2,14 @@
2
3
class WPCF7_Pipe {
4
5
- var $before = '';
6
- var $after = '';
7
8
- function WPCF7_Pipe( $text ) {
9
$pipe_pos = strpos( $text, '|' );
10
if ( false === $pipe_pos ) {
11
$this->before = $this->after = trim( $text );
12
} else {
@@ -18,31 +21,30 @@ class WPCF7_Pipe {
18
19
class WPCF7_Pipes {
20
21
- var $pipes = array();
22
-
23
- function WPCF7_Pipes( $texts ) {
24
- if ( ! is_array( $texts ) )
25
- return;
26
27
foreach ( $texts as $text ) {
28
$this->add_pipe( $text );
29
}
30
}
31
32
- function add_pipe( $text ) {
33
$pipe = new WPCF7_Pipe( $text );
34
$this->pipes[] = $pipe;
35
}
36
37
- function do_pipe( $before ) {
38
foreach ( $this->pipes as $pipe ) {
39
- if ( $pipe->before == $before )
40
return $pipe->after;
41
}
42
return $before;
43
}
44
45
- function collect_befores() {
46
$befores = array();
47
48
foreach ( $this->pipes as $pipe ) {
@@ -52,11 +54,21 @@ class WPCF7_Pipes {
52
return $befores;
53
}
54
55
- function zero() {
56
return empty( $this->pipes );
57
}
58
59
- function random_pipe() {
60
if ( $this->zero() )
61
return null;
62
2
3
class WPCF7_Pipe {
4
5
+ public $before = '';
6
+ public $after = '';
7
+
8
+ public function __construct( $text ) {
9
+ $text = (string) $text;
10
11
$pipe_pos = strpos( $text, '|' );
12
+
13
if ( false === $pipe_pos ) {
14
$this->before = $this->after = trim( $text );
15
} else {
21
22
class WPCF7_Pipes {
23
24
+ private $pipes = array();
25
26
+ public function __construct( array $texts ) {
27
foreach ( $texts as $text ) {
28
$this->add_pipe( $text );
29
}
30
}
31
32
+ private function add_pipe( $text ) {
33
$pipe = new WPCF7_Pipe( $text );
34
$this->pipes[] = $pipe;
35
}
36
37
+ public function do_pipe( $before ) {
38
foreach ( $this->pipes as $pipe ) {
39
+ if ( $pipe->before == $before ) {
40
return $pipe->after;
41
+ }
42
}
43
+
44
return $before;
45
}
46
47
+ public function collect_befores() {
48
$befores = array();
49
50
foreach ( $this->pipes as $pipe ) {
54
return $befores;
55
}
56
57
+ public function collect_afters() {
58
+ $afters = array();
59
+
60
+ foreach ( $this->pipes as $pipe ) {
61
+ $afters[] = $pipe->after;
62
+ }
63
+
64
+ return $afters;
65
+ }
66
+
67
+ public function zero() {
68
return empty( $this->pipes );
69
}
70
71
+ public function random_pipe() {
72
if ( $this->zero() )
73
return null;
74
includes/shortcodes.php CHANGED
@@ -2,15 +2,31 @@
2
3
class WPCF7_ShortcodeManager {
4
5
- var $shortcode_tags = array();
6
7
// Taggs scanned at the last time of do_shortcode()
8
- var $scanned_tags = null;
9
10
// Executing shortcodes (true) or just scanning (false)
11
- var $exec = true;
12
13
- function add_shortcode( $tag, $func, $has_name = false ) {
14
if ( ! is_callable( $func ) )
15
return;
16
@@ -23,11 +39,11 @@ class WPCF7_ShortcodeManager {
23
}
24
}
25
26
- function remove_shortcode( $tag ) {
27
unset( $this->shortcode_tags[$tag] );
28
}
29
30
- function normalize_shortcode( $content ) {
31
if ( empty( $this->shortcode_tags ) || ! is_array( $this->shortcode_tags ) )
32
return $content;
33
@@ -36,7 +52,7 @@ class WPCF7_ShortcodeManager {
36
array( &$this, 'normalize_space_cb' ), $content );
37
}
38
39
- function normalize_space_cb( $m ) {
40
// allow [[foo]] syntax for escaping a tag
41
if ( $m[1] == '[' && $m[6] == ']' )
42
return $m[0];
@@ -57,7 +73,7 @@ class WPCF7_ShortcodeManager {
57
return $result;
58
}
59
60
- function do_shortcode( $content, $exec = true ) {
61
$this->exec = (bool) $exec;
62
$this->scanned_tags = array();
63
@@ -69,12 +85,12 @@ class WPCF7_ShortcodeManager {
69
array( &$this, 'do_shortcode_tag' ), $content );
70
}
71
72
- function scan_shortcode( $content ) {
73
$this->do_shortcode( $content, false );
74
return $this->scanned_tags;
75
}
76
77
- function get_shortcode_regex() {
78
$tagnames = array_keys( $this->shortcode_tags );
79
$tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
80
@@ -84,7 +100,7 @@ class WPCF7_ShortcodeManager {
84
. '(\]?)';
85
}
86
87
- function do_shortcode_tag( $m ) {
88
// allow [[foo]] syntax for escaping a tag
89
if ( $m[1] == '[' && $m[6] == ']' ) {
90
return substr( $m[0], 1, -1 );
@@ -152,7 +168,7 @@ class WPCF7_ShortcodeManager {
152
}
153
}
154
155
- function shortcode_parse_atts( $text ) {
156
$atts = array( 'options' => array(), 'values' => array() );
157
$text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
158
$text = stripcslashes( trim( $text ) );
@@ -177,31 +193,21 @@ class WPCF7_ShortcodeManager {
177
}
178
179
function wpcf7_add_shortcode( $tag, $func, $has_name = false ) {
180
- global $wpcf7_shortcode_manager;
181
182
- if ( is_a( $wpcf7_shortcode_manager, 'WPCF7_ShortcodeManager' ) )
183
- return $wpcf7_shortcode_manager->add_shortcode( $tag, $func, $has_name );
184
}
185
186
function wpcf7_remove_shortcode( $tag ) {
187
- global $wpcf7_shortcode_manager;
188
189
- if ( is_a( $wpcf7_shortcode_manager, 'WPCF7_ShortcodeManager' ) )
190
- return $wpcf7_shortcode_manager->remove_shortcode( $tag );
191
}
192
193
function wpcf7_do_shortcode( $content ) {
194
- global $wpcf7_shortcode_manager;
195
-
196
- if ( is_a( $wpcf7_shortcode_manager, 'WPCF7_ShortcodeManager' ) )
197
- return $wpcf7_shortcode_manager->do_shortcode( $content );
198
- }
199
-
200
- function wpcf7_get_shortcode_regex() {
201
- global $wpcf7_shortcode_manager;
202
203
- if ( is_a( $wpcf7_shortcode_manager, 'WPCF7_ShortcodeManager' ) )
204
- return $wpcf7_shortcode_manager->get_shortcode_regex();
205
}
206
207
class WPCF7_Shortcode {
@@ -331,6 +337,32 @@ class WPCF7_Shortcode {
331
return $default;
332
}
333
334
public function get_first_match_option( $pattern ) {
335
foreach( (array) $this->options as $option ) {
336
if ( preg_match( $pattern, $option, $matches ) )
2
3
class WPCF7_ShortcodeManager {
4
5
+ private static $instance;
6
+
7
+ private $shortcode_tags = array();
8
9
// Taggs scanned at the last time of do_shortcode()
10
+ private $scanned_tags = null;
11
12
// Executing shortcodes (true) or just scanning (false)
13
+ private $exec = true;
14
+
15
+ private function __construct() {}
16
+
17
+ public static function get_instance() {
18
+ if ( empty( self::$instance ) ) {
19
+ self::$instance = new self;
20
+ }
21
22
+ return self::$instance;
23
+ }
24
+
25
+ public function get_scanned_tags() {
26