Contact Form 7 - Version 4.6

Version Description

  • Ajax loader: HTML markup changed to <span> to be easily customizable with CSS.
  • Appends a proper header and footer to HTML mail content automatically.
  • [_serial_number] special mail-tag.
  • New form-tag type for hidden fields.
  • default:shortcode_attr form-tag option.
  • WPCF7_Shortcode, WPCF7_ShortcodeManager, wpcf7_add_shortcode(), wpcf7_scan_shortcode(), and some other classes and functions have become deprecated.
  • Removed all language files from the languages folder. Translations have moved to translate.wordpress.org.
Download this release

Release Info

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

Code changes from version 4.5.1 to 4.6

Files changed (85) hide show
  1. admin/css/styles-rtl.css +33 -0
  2. admin/css/styles.css +29 -9
  3. admin/includes/class-contact-forms-list-table.php +2 -1
  4. admin/includes/welcome-panel.php +12 -20
  5. includes/config-validator.php +5 -5
  6. includes/contact-form.php +43 -26
  7. includes/controller.php +1 -3
  8. includes/css/styles-rtl.css +2 -3
  9. includes/css/styles.css +19 -3
  10. includes/form-tag.php +321 -0
  11. includes/form-tags-manager.php +259 -0
  12. includes/formatting.php +21 -13
  13. includes/functions.php +16 -9
  14. includes/js/scripts.js +3 -7
  15. includes/mail.php +68 -47
  16. includes/pipe.php +2 -3
  17. includes/shortcodes.php +55 -468
  18. includes/submission.php +12 -5
  19. includes/upgrade.php +10 -7
  20. includes/validation.php +4 -6
  21. languages/contact-form-7-af.mo +0 -0
  22. languages/contact-form-7-ar.mo +0 -0
  23. languages/contact-form-7-bel.mo +0 -0
  24. languages/contact-form-7-bg_BG.mo +0 -0
  25. languages/contact-form-7-bn_BD.mo +0 -0
  26. languages/contact-form-7-bn_IN.mo +0 -0
  27. languages/contact-form-7-bs_BA.mo +0 -0
  28. languages/contact-form-7-ca.mo +0 -0
  29. languages/contact-form-7-ckb.mo +0 -0
  30. languages/contact-form-7-el.mo +0 -0
  31. languages/contact-form-7-eo.mo +0 -0
  32. languages/contact-form-7-eu.mo +0 -0
  33. languages/contact-form-7-fa_IR.mo +0 -0
  34. languages/contact-form-7-ga.mo +0 -0
  35. languages/contact-form-7-gl_ES.mo +0 -0
  36. languages/contact-form-7-gu.mo +0 -0
  37. languages/contact-form-7-hi_IN.mo +0 -0
  38. languages/contact-form-7-ht.mo +0 -0
  39. languages/contact-form-7-hy.mo +0 -0
  40. languages/contact-form-7-id_ID.mo +0 -0
  41. languages/contact-form-7-ka_GE.mo +0 -0
  42. languages/contact-form-7-ko_KR.mo +0 -0
  43. languages/contact-form-7-lt_LT.mo +0 -0
  44. languages/contact-form-7-lv.mo +0 -0
  45. languages/contact-form-7-mk_MK.mo +0 -0
  46. languages/contact-form-7-ml_IN.mo +0 -0
  47. languages/contact-form-7-ms_MY.mo +0 -0
  48. languages/contact-form-7-mt_MT.mo +0 -0
  49. languages/contact-form-7-nb_NO.mo +0 -0
  50. languages/contact-form-7-pa_IN.mo +0 -0
  51. languages/contact-form-7-si_LK.mo +0 -0
  52. languages/contact-form-7-sl_SI.mo +0 -0
  53. languages/contact-form-7-sq.mo +0 -0
  54. languages/contact-form-7-sr_RS.mo +0 -0
  55. languages/contact-form-7-ta_IN.mo +0 -0
  56. languages/contact-form-7-th.mo +0 -0
  57. languages/contact-form-7-tl.mo +0 -0
  58. languages/contact-form-7-uk.mo +0 -0
  59. languages/contact-form-7-vi.mo +0 -0
  60. languages/contact-form-7-zh_CN.mo +0 -0
  61. languages/contact-form-7-zh_TW.mo +0 -0
  62. languages/contact-form-7.pot +0 -1459
  63. languages/readme.txt +3 -8
  64. modules/acceptance.php +19 -14
  65. modules/akismet.php +2 -4
  66. modules/checkbox.php +23 -18
  67. modules/count.php +8 -8
  68. modules/date.php +16 -12
  69. modules/file.php +10 -10
  70. modules/flamingo.php +30 -2
  71. modules/hidden.php +32 -0
  72. modules/listo.php +0 -2
  73. modules/number.php +16 -12
  74. modules/quiz.php +8 -8
  75. modules/really-simple-captcha.php +10 -10
  76. modules/recaptcha.php +6 -6
  77. modules/response.php +7 -5
  78. modules/select.php +14 -11
  79. modules/submit.php +8 -7
  80. modules/text.php +8 -8
  81. modules/textarea.php +8 -8
  82. readme.txt +13 -3
  83. settings.php +3 -0
  84. uninstall.php +6 -7
  85. wp-contact-form-7.php +3 -3
admin/css/styles-rtl.css CHANGED
@@ -1,3 +1,18 @@
1
.tag-generator-panel {
2
text-align: right;
3
}
@@ -15,6 +30,24 @@
15
float: left;
16
}
17
18
.card {
19
border-left: 1px solid #e5e5e5;
20
border-right: 4px solid #e5e5e5;
1
+ #misc-publishing-actions .misc-pub-section::before {
2
+ right: -1px;
3
+ padding: 0 0 0 2px;
4
+ }
5
+
6
+ /*
7
+ * Tabs
8
+ */
9
+ #contact-form-editor-tabs {
10
+ padding: 9px 10px 0 15px;
11
+ }
12
+
13
+ /*
14
+ * Form Tab
15
+ */
16
.tag-generator-panel {
17
text-align: right;
18
}
30
float: left;
31
}
32
33
+ /*
34
+ * Mail Tab
35
+ */
36
+ .contact-form-editor-box-mail span.mailtag {
37
+ margin: 0 4px 0 0;
38
+ }
39
+
40
+ /*
41
+ * Welcome Panel
42
+ */
43
+ .welcome-panel .welcome-panel-column,
44
+ .welcome-panel .welcome-panel-column:first-child {
45
+ padding: 0 0 0 2%;
46
+ }
47
+
48
+ /*
49
+ * Integration
50
+ */
51
.card {
52
border-left: 1px solid #e5e5e5;
53
border-right: 4px solid #e5e5e5;
admin/css/styles.css CHANGED
@@ -177,7 +177,7 @@ ul.config-error li a.external {
177
}
178
179
/*
180
- * Form Panel
181
*/
182
#tag-generator-list a.button {
183
font-size: 12px;
@@ -288,7 +288,7 @@ ul.config-error li a.external {
288
}
289
290
/*
291
- * Mail Panel
292
*/
293
.contact-form-editor-box-mail span.mailtag {
294
display: inline-block;
@@ -303,7 +303,7 @@ ul.config-error li a.external {
303
}
304
305
/*
306
- * Messages Panel
307
*/
308
#messages-panel p.description {
309
margin: 5px 0 10px;
@@ -323,20 +323,40 @@ ul.config-error li a.external {
323
/*
324
* Welcome Panel
325
*/
326
.welcome-panel h3 {
327
font-size: 16px;
328
font-weight: 600;
329
line-height: 2.1em;
330
- margin: 1.33em 0 0;
331
}
332
333
- .welcome-panel p.message {
334
- line-height: 1.4em;
335
- margin-right: 25px;
336
}
337
338
- .welcome-panel li {
339
- margin-bottom: 12px;
340
}
341
342
.welcome-panel-close {
177
}
178
179
/*
180
+ * Form Tab
181
*/
182
#tag-generator-list a.button {
183
font-size: 12px;
288
}
289
290
/*
291
+ * Mail Tab
292
*/
293
.contact-form-editor-box-mail span.mailtag {
294
display: inline-block;
303
}
304
305
/*
306
+ * Messages Tab
307
*/
308
#messages-panel p.description {
309
margin: 5px 0 10px;
323
/*
324
* Welcome Panel
325
*/
326
+ .welcome-panel .welcome-panel-column,
327
+ .welcome-panel .welcome-panel-column:first-child {
328
+ width: 48%;
329
+ padding: 0 2% 0 0;
330
+ margin: 0 0 1em 0;
331
+ }
332
+
333
+ @media screen and (max-width: 870px) {
334
+ .welcome-panel .welcome-panel-column,
335
+ .welcome-panel .welcome-panel-column:first-child {
336
+ display: block;
337
+ float: none;
338
+ width: 100%;
339
+ }
340
+ }
341
+
342
.welcome-panel h3 {
343
font-size: 16px;
344
font-weight: 600;
345
line-height: 2.1em;
346
+ margin: 1em 0 1.2em;
347
}
348
349
+ .welcome-panel h3 .dashicons {
350
+ position: relative;
351
+ top: -2px;
352
+ display: inline-block;
353
+ width: 60px;
354
+ color: #575757;
355
+ font-size: 40px;
356
}
357
358
+ .welcome-panel p a {
359
+ font-weight: bold;
360
}
361
362
.welcome-panel-close {
admin/includes/class-contact-forms-list-table.php CHANGED
@@ -1,7 +1,8 @@
1
<?php
2
3
- if ( ! class_exists( 'WP_List_Table' ) )
4
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
6
class WPCF7_Contact_Form_List_Table extends WP_List_Table {
7
1
<?php
2
3
+ if ( ! class_exists( 'WP_List_Table' ) ) {
4
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
+ }
6
7
class WPCF7_Contact_Form_List_Table extends WP_List_Table {
8
admin/includes/welcome-panel.php CHANGED
@@ -17,31 +17,23 @@ function wpcf7_welcome_panel() {
17
18
<div class="welcome-panel-content">
19
<div class="welcome-panel-column-container">
20
- <div class="welcome-panel-column">
21
- <h3><?php echo esc_html( __( 'Contact Form 7 Needs Your Support', 'contact-form-7' ) ); ?></h3>
22
- <p class="message"><?php echo esc_html( __( "It is hard to continue development and support for this plugin without contributions from users like you. If you enjoy using Contact Form 7 and find it useful, please consider making a donation.", 'contact-form-7' ) ); ?></p>
23
- <p><?php echo wpcf7_link( __( 'http://contactform7.com/donate/', 'contact-form-7' ), __( 'Donate', 'contact-form-7' ), array( 'class' => 'button button-primary' ) ); ?></p>
24
- </div>
25
26
<div class="welcome-panel-column">
27
- <h3><?php echo esc_html( __( 'Get Started', 'contact-form-7' ) ); ?></h3>
28
- <ul>
29
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/getting-started-with-contact-form-7/', 'contact-form-7' ), __( 'Getting Started with Contact Form 7', 'contact-form-7' ) ); ?></li>
30
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/admin-screen/', 'contact-form-7' ), __( 'Admin Screen', 'contact-form-7' ) ); ?></li>
31
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/tag-syntax/', 'contact-form-7' ), __( 'How Tags Work', 'contact-form-7' ) ); ?></li>
32
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/setting-up-mail/', 'contact-form-7' ), __( 'Setting Up Mail', 'contact-form-7' ) ); ?></li>
33
- </ul>
34
</div>
35
36
<div class="welcome-panel-column">
37
- <h3><?php echo esc_html( __( 'Did You Know?', 'contact-form-7' ) ); ?></h3>
38
- <ul>
39
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ), __( 'Spam Filtering with Akismet', 'contact-form-7' ) ); ?></li>
40
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/save-submitted-messages-with-flamingo/', 'contact-form-7' ), __( 'Save Messages with Flamingo', 'contact-form-7' ) ); ?></li>
41
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/selectable-recipient-with-pipes/', 'contact-form-7' ), __( 'Selectable Recipient with Pipes', 'contact-form-7' ) ); ?></li>
42
- <li><?php echo wpcf7_link( __( 'http://contactform7.com/tracking-form-submissions-with-google-analytics/', 'contact-form-7' ), __( 'Tracking with Google Analytics', 'contact-form-7' ) ); ?></li>
43
- </ul>
44
</div>
45
</div>
46
</div>
47
</div>
@@ -61,7 +53,7 @@ function wpcf7_admin_ajax_welcome_panel() {
61
}
62
63
if ( empty( $_POST['visible'] ) ) {
64
- $vers[] = WPCF7_VERSION;
65
}
66
67
$vers = array_unique( $vers );
17
18
<div class="welcome-panel-content">
19
<div class="welcome-panel-column-container">
20
21
<div class="welcome-panel-column">
22
+ <h3><span class="dashicons dashicons-shield"></span> <?php echo esc_html( __( "Getting spammed? You have protection.", 'contact-form-7' ) ); ?></h3>
23
+
24
+ <p><?php echo esc_html( __( "Spammers target everything; your contact forms aren&#8217;t an exception. Before you get spammed, protect your contact forms with the powerful anti-spam features Contact Form 7 provides.", 'contact-form-7' ) ); ?></p>
25
+
26
+ <p><?php echo sprintf( esc_html( __( 'Contact Form 7 supports spam-filtering with %1$s. Intelligent %2$s blocks annoying spambots. Plus, using %3$s, you can block messages containing specified keywords or those sent from specified IP addresses.', 'contact-form-7' ) ), wpcf7_link( __( 'http://contactform7.com/spam-filtering-with-akismet/', 'contact-form-7' ), __( 'Akismet', 'contact-form-7' ) ), wpcf7_link( __( 'http://contactform7.com/recaptcha/', 'contact-form-7' ), __( 'reCAPTCHA', 'contact-form-7' ) ), wpcf7_link( __( 'http://contactform7.com/comment-blacklist/', 'contact-form-7' ), __( 'comment blacklist', 'contact-form-7' ) ) ); ?></p>
27
</div>
28
29
<div class="welcome-panel-column">
30
+ <h3><span class="dashicons dashicons-editor-help"></span> <?php echo esc_html( __( "Before you cry over spilt mail&#8230;", 'contact-form-7' ) ); ?></h3>
31
+
32
+ <p><?php echo esc_html( __( "Contact Form 7 doesn&#8217;t store submitted messages anywhere. Therefore, you may lose important messages forever if your mail server has issues or you make a mistake in mail configuration.", 'contact-form-7' ) ); ?></p>
33
+
34
+ <p><?php echo sprintf( esc_html( __( 'Install a message storage plugin before this happens to you. %s saves all messages through contact forms into the database. Flamingo is a free WordPress plugin created by the same author as Contact Form 7.', 'contact-form-7' ) ), wpcf7_link( __( 'http://contactform7.com/save-submitted-messages-with-flamingo/', 'contact-form-7' ), __( 'Flamingo', 'contact-form-7' ) ) ); ?></p>
35
</div>
36
+
37
</div>
38
</div>
39
</div>
53
}
54
55
if ( empty( $_POST['visible'] ) ) {
56
+ $vers[] = wpcf7_version( 'only_major=1' );
57
}
58
59
$vers = array_unique( $vers );
includes/config-validator.php CHANGED
@@ -175,14 +175,14 @@ class WPCF7_ConfigValidator {
175
$pattern = '%<label(?:[ \t\n]+.*?)?>(.+?)</label>%s';
176
177
if ( preg_match_all( $pattern, $body, $matches ) ) {
178
- $manager = WPCF7_ShortcodeManager::get_instance();
179
180
foreach ( $matches[1] as $insidelabel ) {
181
- $tags = $manager->scan_shortcode( $insidelabel );
182
$fields_count = 0;
183
184
foreach ( $tags as $tag ) {
185
- $tag = new WPCF7_Shortcode( $tag );
186
187
if ( in_array( $tag->basetype, array( 'checkbox', 'radio' ) ) ) {
188
$fields_count += count( $tag->values );
@@ -362,11 +362,11 @@ class WPCF7_ConfigValidator {
362
$example_text = 'example';
363
$example_blank = '';
364
365
- $form_tags = $this->contact_form->form_scan_shortcode(
366
array( 'name' => $tagname ) );
367
368
if ( $form_tags ) {
369
- $form_tag = new WPCF7_Shortcode( $form_tags[0] );
370
371
$is_required = ( $form_tag->is_required() || 'radio' == $form_tag->type );
372
175
$pattern = '%<label(?:[ \t\n]+.*?)?>(.+?)</label>%s';
176
177
if ( preg_match_all( $pattern, $body, $matches ) ) {
178
+ $manager = WPCF7_FormTagsManager::get_instance();
179
180
foreach ( $matches[1] as $insidelabel ) {
181
+ $tags = $manager->scan( $insidelabel );
182
$fields_count = 0;
183
184
foreach ( $tags as $tag ) {
185
+ $tag = new WPCF7_FormTag( $tag );
186
187
if ( in_array( $tag->basetype, array( 'checkbox', 'radio' ) ) ) {
188
$fields_count += count( $tag->values );
362
$example_text = 'example';
363
$example_blank = '';
364
365
+ $form_tags = $this->contact_form->scan_form_tags(
366
array( 'name' => $tagname ) );
367
368
if ( $form_tags ) {
369
+ $form_tag = new WPCF7_FormTag( $form_tags[0] );
370
371
$is_required = ( $form_tag->is_required() || 'radio' == $form_tag->type );
372
includes/contact-form.php CHANGED
@@ -14,6 +14,7 @@ class WPCF7_ContactForm {
14
private $unit_tag;
15
private $responses_count = 0;
16
private $scanned_form_tags;
17
18
public static function count() {
19
return self::$found_items;
@@ -101,9 +102,7 @@ class WPCF7_ContactForm {
101
return false;
102
}
103
104
- self::$current = $contact_form = new self( $post );
105
-
106
- return $contact_form;
107
}
108
109
private static function get_unit_tag( $id = 0 ) {
@@ -229,6 +228,12 @@ class WPCF7_ContactForm {
229
$this->title = $title;
230
}
231
232
// Return true if this form is the same one as currently POSTed.
233
public function is_posted() {
234
if ( ! WPCF7_Submission::get_instance() ) {
@@ -251,6 +256,8 @@ class WPCF7_ContactForm {
251
'html_class' => '',
252
'output' => 'form' ) );
253
254
if ( 'raw_form' == $args['output'] ) {
255
return '<pre class="wpcf7-raw-form"><code>'
256
. esc_html( $this->prop( 'form' ) ) . '</code></pre>';
@@ -496,28 +503,35 @@ class WPCF7_ContactForm {
496
497
/* Form Elements */
498
499
- public function form_do_shortcode() {
500
- $manager = WPCF7_ShortcodeManager::get_instance();
501
$form = $this->prop( 'form' );
502
503
if ( WPCF7_AUTOP ) {
504
- $form = $manager->normalize_shortcode( $form );
505
$form = wpcf7_autop( $form );
506
}
507
508
- $form = $manager->do_shortcode( $form );
509
$this->scanned_form_tags = $manager->get_scanned_tags();
510
511
return $form;
512
}
513
514
- public function form_scan_shortcode( $cond = null ) {
515
- $manager = WPCF7_ShortcodeManager::get_instance();
516
517
if ( ! empty( $this->scanned_form_tags ) ) {
518
$scanned = $this->scanned_form_tags;
519
} else {
520
- $scanned = $manager->scan_shortcode( $this->prop( 'form' ) );
521
$this->scanned_form_tags = $scanned;
522
}
523
@@ -563,8 +577,16 @@ class WPCF7_ContactForm {
563
return array_values( $scanned );
564
}
565
566
public function form_elements() {
567
- return apply_filters( 'wpcf7_form_elements', $this->form_do_shortcode() );
568
}
569
570
public function collect_mail_tags( $args = '' ) {
@@ -573,7 +595,7 @@ class WPCF7_ContactForm {
573
'exclude' => array(
574
'acceptance', 'captchac', 'captchar', 'quiz', 'count' ) ) );
575
576
- $tags = $this->form_scan_shortcode();
577
$mailtags = array();
578
579
foreach ( (array) $tags as $tag ) {
@@ -674,15 +696,17 @@ class WPCF7_ContactForm {
674
/* Additional settings */
675
676
public function additional_setting( $name, $max = 1 ) {
677
- $tmp_settings = (array) explode( "\n", $this->prop( 'additional_settings' ) );
678
679
$count = 0;
680
$values = array();
681
682
- foreach ( $tmp_settings as $setting ) {
683
- if ( preg_match('/^([a-zA-Z0-9_]+)[\t ]*:(.*)#x2F;', $setting, $matches ) ) {
684
- if ( $matches[1] != $name )
685
continue;
686
687
if ( ! $max || $count < (int) $max ) {
688
$values[] = trim( $matches[2] );
@@ -698,8 +722,9 @@ class WPCF7_ContactForm {
698
$settings = $this->additional_setting( $name, false );
699
700
foreach ( $settings as $setting ) {
701
- if ( in_array( $setting, array( 'on', 'true', '1' ) ) )
702
return true;
703
}
704
705
return false;
@@ -890,14 +915,6 @@ function wpcf7_get_message( $status ) {
890
return $contact_form->message( $status );
891
}
892
893
- function wpcf7_scan_shortcode( $cond = null ) {
894
- if ( ! $contact_form = wpcf7_get_current_contact_form() ) {
895
- return array();
896
- }
897
-
898
- return $contact_form->form_scan_shortcode( $cond );
899
- }
900
-
901
function wpcf7_form_controls_class( $type, $default = '' ) {
902
$type = trim( $type );
903
$default = array_filter( explode( ' ', $default ) );
@@ -930,7 +947,7 @@ function wpcf7_contact_form_tag_func( $atts, $content = null, $code = '' ) {
930
'html_id' => '',
931
'html_name' => '',
932
'html_class' => '',
933
- 'output' => 'form' ), $atts );
934
935
$id = (int) $atts['id'];
936
$title = trim( $atts['title'] );
14
private $unit_tag;
15
private $responses_count = 0;
16
private $scanned_form_tags;
17
+ private $shortcode_atts = array();
18
19
public static function count() {
20
return self::$found_items;
102
return false;
103
}
104
105
+ return self::$current = new self( $post );
106
}
107
108
private static function get_unit_tag( $id = 0 ) {
228
$this->title = $title;
229
}
230
231
+ public function shortcode_attr( $name ) {
232
+ if ( isset( $this->shortcode_atts[$name] ) ) {
233
+ return (string) $this->shortcode_atts[$name];
234
+ }
235
+ }
236
+
237
// Return true if this form is the same one as currently POSTed.
238
public function is_posted() {
239
if ( ! WPCF7_Submission::get_instance() ) {
256
'html_class' => '',
257
'output' => 'form' ) );
258
259
+ $this->shortcode_atts = $args;
260
+
261
if ( 'raw_form' == $args['output'] ) {
262
return '<pre class="wpcf7-raw-form"><code>'
263
. esc_html( $this->prop( 'form' ) ) . '</code></pre>';
503
504
/* Form Elements */
505
506
+ public function replace_all_form_tags() {
507
+ $manager = WPCF7_FormTagsManager::get_instance();
508
$form = $this->prop( 'form' );
509
510
if ( WPCF7_AUTOP ) {
511
+ $form = $manager->normalize( $form );
512
$form = wpcf7_autop( $form );
513
}
514
515
+ $form = $manager->replace_all( $form );
516
$this->scanned_form_tags = $manager->get_scanned_tags();
517
518
return $form;
519
}
520
521
+ public function form_do_shortcode() {
522
+ wpcf7_deprecated_function( __METHOD__, '4.6',
523
+ 'WPCF7_ContactForm::replace_all_form_tags' );
524
+
525
+ return $this->replace_all_form_tags();
526
+ }
527
+
528
+ public function scan_form_tags( $cond = null ) {
529
+ $manager = WPCF7_FormTagsManager::get_instance();
530
531
if ( ! empty( $this->scanned_form_tags ) ) {
532
$scanned = $this->scanned_form_tags;
533
} else {
534
+ $scanned = $manager->scan( $this->prop( 'form' ) );
535
$this->scanned_form_tags = $scanned;
536
}
537
577
return array_values( $scanned );
578
}
579
580
+ public function form_scan_shortcode( $cond = null ) {
581
+ wpcf7_deprecated_function( __METHOD__, '4.6',
582
+ 'WPCF7_ContactForm::scan_form_tags' );
583
+
584
+ return $this->scan_form_tags( $cond );
585
+ }
586
+
587
public function form_elements() {
588
+ return apply_filters( 'wpcf7_form_elements',
589
+ $this->replace_all_form_tags() );
590
}
591
592
public function collect_mail_tags( $args = '' ) {
595
'exclude' => array(
596
'acceptance', 'captchac', 'captchar', 'quiz', 'count' ) ) );
597
598
+ $tags = $this->scan_form_tags();
599
$mailtags = array();
600
601
foreach ( (array) $tags as $tag ) {
696
/* Additional settings */
697
698
public function additional_setting( $name, $max = 1 ) {
699
+ $settings = (array) explode( "\n", $this->prop( 'additional_settings' ) );
700
701
+ $pattern = '/^([a-zA-Z0-9_]+)[\t ]*:(.*)#x2F;';
702
$count = 0;
703
$values = array();
704
705
+ foreach ( $settings as $setting ) {
706
+ if ( preg_match( $pattern, $setting, $matches ) ) {
707
+ if ( $matches[1] != $name ) {
708
continue;
709
+ }
710
711
if ( ! $max || $count < (int) $max ) {
712
$values[] = trim( $matches[2] );
722
$settings = $this->additional_setting( $name, false );
723
724
foreach ( $settings as $setting ) {
725
+ if ( in_array( $setting, array( 'on', 'true', '1' ) ) ) {
726
return true;
727
+ }
728
}
729
730
return false;
915
return $contact_form->message( $status );
916
}
917
918
function wpcf7_form_controls_class( $type, $default = '' ) {
919
$type = trim( $type );
920
$default = array_filter( explode( ' ', $default ) );
947
'html_id' => '',
948
'html_name' => '',
949
'html_class' => '',
950
+ 'output' => 'form' ), $atts, 'wpcf7' );
951
952
$id = (int) $atts['id'];
953
$title = trim( $atts['title'] );
includes/controller.php CHANGED
@@ -165,12 +165,10 @@ function wpcf7_enqueue_scripts() {
165
array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer );
166
167
$_wpcf7 = array(
168
- 'loaderUrl' => wpcf7_ajax_loader(),
169
'recaptcha' => array(
170
'messages' => array(
171
'empty' => __( 'Please verify that you are not a robot.',
172
- 'contact-form-7' ) ) ),
173
- 'sending' => __( 'Sending ...', 'contact-form-7' ) );
174
175
if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
176
$_wpcf7['cached'] = 1;
165
array( 'jquery', 'jquery-form' ), WPCF7_VERSION, $in_footer );
166
167
$_wpcf7 = array(
168
'recaptcha' => array(
169
'messages' => array(
170
'empty' => __( 'Please verify that you are not a robot.',
171
+ 'contact-form-7' ) ) ) );
172
173
if ( defined( 'WP_CACHE' ) && WP_CACHE ) {
174
$_wpcf7['cached'] = 1;
includes/css/styles-rtl.css CHANGED
@@ -2,12 +2,11 @@ span.wpcf7-not-valid-tip {
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;
13
}
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: 0 1em 0 0;
12
}
includes/css/styles.css CHANGED
@@ -56,17 +56,33 @@ span.wpcf7-not-valid-tip {
56
}
57
58
span.wpcf7-list-item {
59
- margin-left: 0.5em;
60
}
61
62
.wpcf7-display-none {
63
display: none;
64
}
65
66
- div.wpcf7 img.ajax-loader {
67
border: none;
68
vertical-align: middle;
69
- margin-left: 4px;
70
}
71
72
div.wpcf7 div.ajax-error {
56
}
57
58
span.wpcf7-list-item {
59
+ display: inline-block;
60
+ margin: 0 0 0 1em;
61
+ }
62
+
63
+ span.wpcf7-list-item-label::before,
64
+ span.wpcf7-list-item-label::after {
65
+ content: " ";
66
}
67
68
.wpcf7-display-none {
69
display: none;
70
}
71
72
+ div.wpcf7 .ajax-loader {
73
+ visibility: hidden;
74
+ display: inline-block;
75
+ background-image: url('../../images/ajax-loader.gif');
76
+ width: 16px;
77
+ height: 16px;
78
border: none;
79
+ padding: 0;
80
+ margin: 0 0 0 4px;
81
vertical-align: middle;
82
+ }
83
+
84
+ div.wpcf7 .ajax-loader.is-active {
85
+ visibility: visible;
86
}
87
88
div.wpcf7 div.ajax-error {
includes/form-tag.php ADDED
@@ -0,0 +1,321 @@
1
+ <?php
2
+
3
+ class WPCF7_FormTag {
4
+
5
+ public $type;
6
+ public $basetype;
7
+ public $name = '';
8
+ public $options = array();
9
+ public $raw_values = array();
10
+ public $values = array();
11
+ public $pipes;
12
+ public $labels = array();
13
+ public $attr = '';
14
+ public $content = '';
15
+
16
+ public function __construct( $tag ) {
17
+ foreach ( $tag as $key => $value ) {
18
+ if ( property_exists( __CLASS__, $key ) ) {
19
+ $this->{$key} = $value;
20
+ }
21
+ }
22
+ }
23
+
24
+ public function is_required() {
25
+ return ( '*' == substr( $this->type, -1 ) );
26
+ }
27
+
28
+ public function has_option( $opt ) {
29
+ $pattern = sprintf( '/^%s(:.+)?#x2F;i', preg_quote( $opt, '/' ) );
30
+ return (bool) preg_grep( $pattern, $this->options );
31
+ }
32
+
33
+ public function get_option( $opt, $pattern = '', $single = false ) {
34
+ $preset_patterns = array(
35
+ 'date' => '([0-9]{4}-[0-9]{2}-[0-9]{2}|today(.*))',
36
+ 'int' => '[0-9]+',
37
+ 'signed_int' => '-?[0-9]+',
38
+ 'class' => '[-0-9a-zA-Z_]+',
39
+ 'id' => '[-0-9a-zA-Z_]+' );
40
+
41
+ if ( isset( $preset_patterns[$pattern] ) ) {
42
+ $pattern = $preset_patterns[$pattern];
43
+ }
44
+
45
+ if ( '' == $pattern ) {
46
+ $pattern = '.+';
47
+ }
48
+
49
+ $pattern = sprintf( '/^%s:%s#x2F;i', preg_quote( $opt, '/' ), $pattern );
50
+
51
+ if ( $single ) {
52
+ $matches = $this->get_first_match_option( $pattern );
53
+
54
+ if ( ! $matches ) {
55
+ return false;
56
+ }
57
+
58
+ return substr( $matches[0], strlen( $opt ) + 1 );
59
+ } else {
60
+ $matches_a = $this->get_all_match_options( $pattern );
61
+
62
+ if ( ! $matches_a ) {
63
+ return false;
64
+ }
65
+
66
+ $results = array();
67
+
68
+ foreach ( $matches_a as $matches ) {
69
+ $results[] = substr( $matches[0], strlen( $opt ) + 1 );
70
+ }
71
+
72
+ return $results;
73
+ }
74
+ }
75
+
76
+ public function get_id_option() {
77
+ return $this->get_option( 'id', 'id', true );
78
+ }
79
+
80
+ public function get_class_option( $default = '' ) {
81
+ if ( is_string( $default ) ) {
82
+ $default = explode( ' ', $default );
83
+ }
84
+
85
+ $options = array_merge(
86
+ (array) $default,
87
+ (array) $this->get_option( 'class', 'class' ) );
88
+
89
+ $options = array_filter( array_unique( $options ) );
90
+
91
+ return implode( ' ', $options );
92
+ }
93
+
94
+ public function get_size_option( $default = '' ) {
95
+ $option = $this->get_option( 'size', 'int', true );
96
+
97
+ if ( $option ) {
98
+ return $option;
99
+ }
100
+
101
+ $matches_a = $this->get_all_match_options( '%^([0-9]*)/[0-9]*$%' );
102
+
103
+ foreach ( (array) $matches_a as $matches ) {
104
+ if ( isset( $matches[1] ) && '' !== $matches[1] ) {
105
+ return $matches[1];
106
+ }
107
+ }
108
+
109
+ return $default;
110
+ }
111
+
112
+ public function get_maxlength_option( $default = '' ) {
113
+ $option = $this->get_option( 'maxlength', 'int', true );
114
+
115
+ if ( $option ) {
116
+ return $option;
117
+ }
118
+
119
+ $matches_a = $this->get_all_match_options(
120
+ '%^(?:[0-9]*x?[0-9]*)?/([0-9]+)$%' );
121
+
122
+ foreach ( (array) $matches_a as $matches ) {
123
+ if ( isset( $matches[1] ) && '' !== $matches[1] ) {
124
+ return $matches[1];
125
+ }
126
+ }
127
+
128
+ return $default;
129
+ }
130
+
131
+ public function get_minlength_option( $default = '' ) {
132
+ $option = $this->get_option( 'minlength', 'int', true );
133
+
134
+ if ( $option ) {
135
+ return $option;
136
+ } else {
137
+ return $default;
138
+ }
139
+ }
140
+
141
+ public function get_cols_option( $default = '' ) {
142
+ $option = $this->get_option( 'cols', 'int', true );
143
+
144
+ if ( $option ) {
145
+ return $option;
146
+ }
147
+
148
+ $matches_a = $this->get_all_match_options(
149
+ '%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
150
+
151
+ foreach ( (array) $matches_a as $matches ) {
152
+ if ( isset( $matches[1] ) && '' !== $matches[1] ) {
153
+ return $matches[1];
154
+ }
155
+ }
156
+
157
+ return $default;
158
+ }
159
+
160
+ public function get_rows_option( $default = '' ) {
161
+ $option = $this->get_option( 'rows', 'int', true );
162
+
163
+ if ( $option ) {
164
+ return $option;
165
+ }
166
+
167
+ $matches_a = $this->get_all_match_options(
168
+ '%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
169
+
170
+ foreach ( (array) $matches_a as $matches ) {
171
+ if ( isset( $matches[2] ) && '' !== $matches[2] ) {
172
+ return $matches[2];
173
+ }
174
+ }
175
+
176
+ return $default;
177
+ }
178
+
179
+ public function get_date_option( $opt ) {
180
+ $option = $this->get_option( $opt, 'date', true );
181
+
182
+ if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}#x2F;', $option ) ) {
183
+ return $option;
184
+ }
185
+
186
+ if ( preg_match( '/^today(?:([+-][0-9]+)([a-z]*))?/', $option, $matches ) ) {
187
+ $number = isset( $matches[1] ) ? (int) $matches[1] : 0;
188
+ $unit = isset( $matches[2] ) ? $matches[2] : '';
189
+
190
+ if ( ! preg_match( '/^(day|month|year|week)s?#x2F;', $unit ) ) {
191
+ $unit = 'days';
192
+ }
193
+
194
+ $date = gmdate( 'Y-m-d',
195
+ strtotime( sprintf( 'today %1$s %2$s', $number, $unit ) ) );
196
+ return $date;
197
+ }
198
+
199
+ return false;
200
+ }
201
+
202
+ public function get_default_option( $default = '', $args = '' ) {
203
+ $args = wp_parse_args( $args, array(
204
+ 'multiple' => false ) );
205
+
206
+ $options = (array) $this->get_option( 'default' );
207
+ $values = array();
208
+
209
+ if ( empty( $options ) ) {
210
+ return $args['multiple'] ? $values : $default;
211
+ }
212
+
213
+ foreach ( $options as $opt ) {
214
+ $opt = sanitize_key( $opt );
215
+
216
+ if ( 'user_' == substr( $opt, 0, 5 ) && is_user_logged_in() ) {
217
+ $primary_props = array( 'user_login', 'user_email', 'user_url' );
218
+ $opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
219
+
220
+ $user = wp_get_current_user();
221
+ $user_prop = $user->get( $opt );
222
+
223
+ if ( ! empty( $user_prop ) ) {
224
+ if ( $args['multiple'] ) {
225
+ $values[] = $user_prop;
226
+ } else {
227
+ return $user_prop;
228
+ }
229
+ }
230
+
231
+ } elseif ( 'post_meta' == $opt && in_the_loop() ) {
232
+ if ( $args['multiple'] ) {
233
+ $values = array_merge( $values,
234
+ get_post_meta( get_the_ID(), $this->name ) );
235
+ } else {
236
+ $val = (string) get_post_meta( get_the_ID(), $this->name, true );
237
+
238
+ if ( strlen( $val ) ) {
239
+ return $val;
240
+ }
241
+ }
242
+
243
+ } elseif ( 'get' == $opt && isset( $_GET[$this->name] ) ) {
244
+ $vals = (array) $_GET[$this->name];
245
+ $vals = array_map( 'wpcf7_sanitize_query_var', $vals );
246
+
247
+ if ( $args['multiple'] ) {
248
+ $values = array_merge( $values, $vals );
249
+ } else {
250
+ $val = isset( $vals[0] ) ? (string) $vals[0] : '';
251
+
252
+ if ( strlen( $val ) ) {
253
+ return $val;
254
+ }
255
+ }
256
+
257
+ } elseif ( 'post' == $opt && isset( $_POST[$this->name] ) ) {
258
+ $vals = (array) $_POST[$this->name];
259
+ $vals = array_map( 'wpcf7_sanitize_query_var', $vals );
260
+
261
+ if ( $args['multiple'] ) {
262
+ $values = array_merge( $values, $vals );
263
+ } else {
264
+ $val = isset( $vals[0] ) ? (string) $vals[0] : '';
265
+
266
+ if ( strlen( $val ) ) {
267
+ return $val;
268
+ }
269
+ }
270
+
271
+ } elseif ( 'shortcode_attr' == $opt ) {
272
+ if ( $contact_form = WPCF7_ContactForm::get_current() ) {
273
+ $val = $contact_form->shortcode_attr( $this->name );
274
+
275
+ if ( strlen( $val ) ) {
276
+ if ( $args['multiple'] ) {
277
+ $values[] = $val;
278
+ } else {
279
+ return $val;
280
+ }
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ if ( $args['multiple'] ) {
287
+ $values = array_unique( $values );
288
+ return $values;
289
+ } else {
290
+ return $default;
291
+ }
292
+ }
293
+
294
+ public function get_data_option( $args = '' ) {
295
+ $options = (array) $this->get_option( 'data' );
296
+
297
+ return apply_filters( 'wpcf7_form_tag_data_option', null, $options, $args );
298
+ }
299
+
300
+ public function get_first_match_option( $pattern ) {
301
+ foreach( (array) $this->options as $option ) {
302
+ if ( preg_match( $pattern, $option, $matches ) ) {
303
+ return $matches;
304
+ }
305
+ }
306
+
307
+ return false;
308
+ }
309
+
310
+ public function get_all_match_options( $pattern ) {
311
+ $result = array();
312
+
313
+ foreach( (array) $this->options as $option ) {
314
+ if ( preg_match( $pattern, $option, $matches ) ) {
315
+ $result[] = $matches;
316
+ }
317
+ }
318
+
319
+ return $result;
320
+ }
321
+ }
includes/form-tags-manager.php ADDED
@@ -0,0 +1,259 @@
1
+ <?php
2
+
3
+ function wpcf7_add_form_tag( $tag, $func, $has_name = false ) {
4
+ $manager = WPCF7_FormTagsManager::get_instance();
5
+
6
+ return $manager->add( $tag, $func, $has_name );
7
+ }
8
+
9
+ function wpcf7_remove_form_tag( $tag ) {
10
+ $manager = WPCF7_FormTagsManager::get_instance();
11
+
12
+ return $manager->remove( $tag );
13
+ }
14
+
15
+ function wpcf7_replace_all_form_tags( $content ) {
16
+ $manager = WPCF7_FormTagsManager::get_instance();
17
+
18
+ return $manager->replace_all( $content );
19
+ }
20
+
21
+ function wpcf7_scan_form_tags( $cond = null ) {
22
+ $contact_form = WPCF7_ContactForm::get_current();
23
+
24
+ if ( $contact_form ) {
25
+ return $contact_form->scan_form_tags( $cond );
26
+ }
27
+
28
+ return array();
29
+ }
30
+
31
+ class WPCF7_FormTagsManager {
32
+
33
+ private static $instance;
34
+
35
+ private $tags = array();
36
+ private $scanned_tags = null; // Tags scanned at the last time of scan()
37
+
38
+ private function __construct() {}
39
+
40
+ public static function get_instance() {
41
+ if ( empty( self::$instance ) ) {
42
+ self::$instance = new self;
43
+ }
44
+
45
+ return self::$instance;
46
+ }
47
+
48
+ public function get_scanned_tags() {
49
+ return $this->scanned_tags;
50
+ }
51
+
52
+ public function add( $tag, $func, $has_name = false ) {
53
+ if ( ! is_callable( $func ) ) {
54
+ return;
55
+ }
56
+
57
+ $tags = array_filter( array_unique( (array) $tag ) );
58
+
59
+ foreach ( $tags as $tag ) {
60
+ $tag = $this->sanitize_tag_type( $tag );
61
+
62
+ if ( ! $this->tag_type_exists( $tag ) ) {
63
+ $this->tags[$tag] = array(
64
+ 'function' => $func,
65
+ 'has_name' => (boolean) $has_name );
66
+ }
67
+ }
68
+ }
69
+
70
+ public function tag_type_exists( $tag ) {
71
+ return isset( $this->tags[$tag] );
72
+ }
73
+
74
+ private function sanitize_tag_type( $tag ) {
75
+ $tag = preg_replace( '/[^a-zA-Z0-9_*]+/', '_', $tag );
76
+ $tag = rtrim( $tag, '_' );
77
+ $tag = strtolower( $tag );
78
+ return $tag;
79
+ }
80
+
81
+ public function remove( $tag ) {
82
+ unset( $this->tags[$tag] );
83
+ }
84
+
85
+ public function normalize( $content ) {
86
+ if ( empty( $this->tags ) ) {
87
+ return $content;
88
+ }
89
+
90
+ $content = preg_replace_callback(
91
+ '/' . $this->tag_regex() . '/s',
92
+ array( $this, 'normalize_callback' ),
93
+ $content );
94
+
95
+ return $content;
96
+ }
97
+
98
+ private function normalize_callback( $m ) {
99
+ // allow [[foo]] syntax for escaping a tag
100
+ if ( $m[1] == '[' && $m[6] == ']' ) {
101
+ return $m[0];
102
+ }
103
+
104
+ $tag = $m[2];
105
+
106
+ $attr = trim( preg_replace( '/[\r\n\t ]+/', ' ', $m[3] ) );
107
+ $attr = strtr( $attr, array( '<' => '&lt;', '>' => '&gt;' ) );
108
+
109
+ $content = trim( $m[5] );
110
+ $content = str_replace( "\n", '<WPPreserveNewline />', $content );
111
+
112
+ $result = $m[1] . '[' . $tag
113
+ . ( $attr ? ' ' . $attr : '' )
114
+ . ( $m[4] ? ' ' . $m[4] : '' )
115
+ . ']'
116
+ . ( $content ? $content . '[/' . $tag . ']' : '' )
117
+ . $m[6];
118
+
119
+ return $result;
120
+ }
121
+
122
+ public function replace_all( $content ) {
123
+ return $this->scan( $content, true );
124
+ }
125
+
126
+ public function scan( $content, $replace = false ) {
127
+ $this->scanned_tags = array();
128
+
129
+ if ( empty( $this->tags ) ) {
130
+ if ( $replace ) {
131
+ return $content;
132
+ } else {
133
+ return $this->scanned_tags;
134
+ }
135
+ }
136
+
137
+ if ( $replace ) {
138
+ $content = preg_replace_callback(
139
+ '/' . $this->tag_regex() . '/s',
140
+ array( $this, 'replace_callback' ),
141
+ $content );
142
+
143
+ return $content;
144
+ } else {
145
+ preg_replace_callback(
146
+ '/' . $this->tag_regex() . '/s',
147
+ array( $this, 'scan_callback' ),
148
+ $content );
149
+
150
+ return $this->scanned_tags;
151
+ }
152
+ }
153
+
154
+ private function tag_regex() {
155
+ $tagnames = array_keys( $this->tags );
156
+ $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
157
+
158
+ return '(\[?)'
159
+ . '\[(' . $tagregexp . ')(?:[\r\n\t ](.*?))?(?:[\r\n\t ](\/))?\]'
160
+ . '(?:([^[]*?)\[\/\2\])?'
161
+ . '(\]?)';
162
+ }
163
+
164
+ private function replace_callback( $m ) {
165
+ return $this->scan_callback( $m, true );
166
+ }
167
+
168
+ private function scan_callback( $m, $replace = false ) {
169
+ // allow [[foo]] syntax for escaping a tag
170
+ if ( $m[1] == '[' && $m[6] == ']' ) {
171
+ return substr( $m[0], 1, -1 );
172
+ }
173
+
174
+ $tag = $m[2];
175
+ $attr = $this->parse_atts( $m[3] );
176
+
177
+ $scanned_tag = array(
178
+ 'type' => $tag,
179
+ 'basetype' => trim( $tag, '*' ),
180
+ 'name' => '',
181
+ 'options' => array(),
182
+ 'raw_values' => array(),
183
+ 'values' => array(),
184
+ 'pipes' => null,
185
+ 'labels' => array(),
186
+ 'attr' => '',
187
+ 'content' => '' );
188
+
189
+ if ( is_array( $attr ) ) {
190
+ if ( is_array( $attr['options'] ) ) {
191
+ if ( $this->tags[$tag]['has_name'] && ! empty( $attr['options'] ) ) {
192
+ $scanned_tag['name'] = array_shift( $attr['options'] );
193
+
194
+ if ( ! wpcf7_is_name( $scanned_tag['name'] ) ) {
195
+ return $m[0]; // Invalid name is used. Ignore this tag.
196
+ }
197
+ }
198
+
199
+ $scanned_tag['options'] = (array) $attr['options'];
200
+ }
201
+
202
+ $scanned_tag['raw_values'] = (array) $attr['values'];
203
+
204
+ if ( WPCF7_USE_PIPE ) {
205
+ $pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
206
+ $scanned_tag['values'] = $pipes->collect_befores();
207
+ $scanned_tag['pipes'] = $pipes;
208
+ } else {
209
+ $scanned_tag['values'] = $scanned_tag['raw_values'];
210
+ }
211
+
212
+ $scanned_tag['labels'] = $scanned_tag['values'];
213
+
214
+ } else {
215
+ $scanned_tag['attr'] = $attr;
216
+ }
217
+
218
+ $scanned_tag['values'] = array_map( 'trim', $scanned_tag['values'] );
219
+ $scanned_tag['labels'] = array_map( 'trim', $scanned_tag['labels'] );
220
+
221
+ $content = trim( $m[5] );
222
+ $content = preg_replace( "/<br[\r\n\t ]*\/?>#x2F;m", '', $content );
223
+ $scanned_tag['content'] = $content;
224
+
225
+ $scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag, $replace );
226
+
227
+ $this->scanned_tags[] = $scanned_tag;
228
+
229
+ if ( $replace ) {
230
+ $func = $this->tags[$tag]['function'];
231
+ return $m[1] . call_user_func( $func, $scanned_tag ) . $m[6];
232
+ } else {
233
+ return $m[0];
234
+ }
235
+ }
236
+
237
+ private function parse_atts( $text ) {
238
+ $atts = array( 'options' => array(), 'values' => array() );
239
+ $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
240
+ $text = stripcslashes( trim( $text ) );
241
+
242
+ $pattern = '%^([-+*=0-9a-zA-Z:.!?#amp;@_/|\%\r\n\t ]*?)((?:[\r\n\t ]*"[^"]*"|[\r\n\t ]*\'[^\']*\')*)$%';
243
+
244
+ if ( preg_match( $pattern, $text, $match ) ) {
245
+ if ( ! empty( $match[1] ) ) {
246
+ $atts['options'] = preg_split( '/[\r\n\t ]+/', trim( $match[1] ) );
247
+ }
248
+
249
+ if ( ! empty( $match[2] ) ) {
250
+ preg_match_all( '/"[^"]*"|\'[^\']*\'/', $match[2], $matched_values );
251
+ $atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
252
+ }
253
+ } else {
254
+ $atts = $text;
255
+ }
256
+
257
+ return $atts;
258
+ }
259
+ }
includes/formatting.php CHANGED
@@ -13,8 +13,9 @@ function wpcf7_autop( $pee, $br = 1 ) {
13
$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
14
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
15
16
- /* wpcf7: take care of [response] and [recaptcha] tag */
17
- $pee = preg_replace( '!(\[(?:response|recaptcha)[^]]*\])!',
18
"\n$1\n\n", $pee );
19
20
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
@@ -42,10 +43,10 @@ function wpcf7_autop( $pee, $br = 1 ) {
42
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
43
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
44
45
- /* wpcf7: take care of [response] and [recaptcha] tag */
46
- $pee = preg_replace( '!<p>\s*(\[(?:response|recaptcha)[^]]*\])!',
47
"$1", $pee );
48
- $pee = preg_replace( '!(\[(?:response|recaptcha)[^]]*\])\s*</p>!',
49
"$1", $pee );
50
51
if ( $br ) {
@@ -82,36 +83,41 @@ function wpcf7_sanitize_query_var( $text ) {
82
function wpcf7_strip_quote( $text ) {
83
$text = trim( $text );
84
85
- if ( preg_match( '/^"(.*)"#x2F;', $text, $matches ) )
86
$text = $matches[1];
87
- elseif ( preg_match( "/^'(.*)'#x2F;", $text, $matches ) )
88
$text = $matches[1];
89
90
return $text;
91
}
92
93
function wpcf7_strip_quote_deep( $arr ) {
94
- if ( is_string( $arr ) )
95
return wpcf7_strip_quote( $arr );
96
97
if ( is_array( $arr ) ) {
98
$result = array();
99
100
- foreach ( $arr as $key => $text )
101
$result[$key] = wpcf7_strip_quote_deep( $text );
102
103
return $result;
104
}
105
}
106
107
function wpcf7_normalize_newline( $text, $to = "\n" ) {
108
- if ( ! is_string( $text ) )
109
return $text;
110
111
$nls = array( "\r\n", "\r", "\n" );
112
113
- if ( ! in_array( $to, $nls ) )
114
return $text;
115
116
return str_replace( $nls, $to, $text );
117
}
@@ -120,8 +126,9 @@ function wpcf7_normalize_newline_deep( $arr, $to = "\n" ) {
120
if ( is_array( $arr ) ) {
121
$result = array();
122
123
- foreach ( $arr as $key => $text )
124
$result[$key] = wpcf7_normalize_newline_deep( $text, $to );
125
126
return $result;
127
}
@@ -189,8 +196,9 @@ function wpcf7_is_number( $number ) {
189
function wpcf7_is_date( $date ) {
190
$result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})#x2F;', $date, $matches );
191
192
- if ( $result )
193
$result = checkdate( $matches[2], $matches[3], $matches[1] );
194
195
return apply_filters( 'wpcf7_is_date', $result, $date );
196
}
13
$pee = preg_replace( '!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee );
14
$pee = preg_replace( '!(</' . $allblocks . '>)!', "$1\n\n", $pee );
15
16
+ /* wpcf7: take care of [response], [recaptcha], and [hidden] tags */
17
+ $block_hidden_form_tags = '(?:response|recaptcha|hidden)';
18
+ $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])!',
19
"\n$1\n\n", $pee );
20
21
$pee = str_replace( array( "\r\n", "\r" ), "\n", $pee ); // cross-platform newlines
43
$pee = preg_replace( '!<p>\s*(</?' . $allblocks . '[^>]*>)!', "$1", $pee );
44
$pee = preg_replace( '!(</?' . $allblocks . '[^>]*>)\s*</p>!', "$1", $pee );
45
46
+ /* wpcf7: take care of [response], [recaptcha], and [hidden] tag */
47
+ $pee = preg_replace( '!<p>\s*(\[' . $block_hidden_form_tags . '[^]]*\])!',
48
"$1", $pee );
49
+ $pee = preg_replace( '!(\[' . $block_hidden_form_tags . '[^]]*\])\s*</p>!',
50
"$1", $pee );
51
52
if ( $br ) {
83
function wpcf7_strip_quote( $text ) {
84
$text = trim( $text );
85
86
+ if ( preg_match( '/^"(.*)"#x2F;s', $text, $matches ) ) {
87
$text = $matches[1];
88
+ } elseif ( preg_match( "/^'(.*)'#x2F;s", $text, $matches ) ) {
89
$text = $matches[1];
90
+ }
91
92
return $text;
93
}
94
95
function wpcf7_strip_quote_deep( $arr ) {
96
+ if ( is_string( $arr ) ) {
97
return wpcf7_strip_quote( $arr );
98
+ }
99
100
if ( is_array( $arr ) ) {
101
$result = array();
102
103
+ foreach ( $arr as $key => $text ) {
104
$result[$key] = wpcf7_strip_quote_deep( $text );
105
+ }
106
107
return $result;
108
}
109
}
110
111
function wpcf7_normalize_newline( $text, $to = "\n" ) {
112
+ if ( ! is_string( $text ) ) {
113
return $text;
114
+ }
115
116
$nls = array( "\r\n", "\r", "\n" );
117
118
+ if ( ! in_array( $to, $nls ) ) {
119
return $text;
120
+ }
121
122
return str_replace( $nls, $to, $text );
123
}
126
if ( is_array( $arr ) ) {
127
$result = array();
128
129
+ foreach ( $arr as $key => $text ) {
130
$result[$key] = wpcf7_normalize_newline_deep( $text, $to );
131
+ }
132
133
return $result;
134
}
196
function wpcf7_is_date( $date ) {
197
$result = preg_match( '/^([0-9]{4,})-([0-9]{2})-([0-9]{2})#x2F;', $date, $matches );
198
199
+ if ( $result ) {
200
$result = checkdate( $matches[2], $matches[3], $matches[1] );
201
+ }
202
203
return apply_filters( 'wpcf7_is_date', $result, $date );
204
}
includes/functions.php CHANGED
@@ -15,26 +15,21 @@ function wpcf7_plugin_url( $path = '' ) {
15
}
16
17
function wpcf7_upload_dir( $type = false ) {
18
- $uploads = wp_upload_dir();
19
20
$uploads = apply_filters( 'wpcf7_upload_dir', array(
21
'dir' => $uploads['basedir'],
22
'url' => $uploads['baseurl'] ) );
23
24
- if ( 'dir' == $type )
25
return $uploads['dir'];
26
- if ( 'url' == $type )
27
return $uploads['url'];
28
29
return $uploads;
30
}
31
32
- function wpcf7_ajax_loader() {
33
- $url = wpcf7_plugin_url( 'images/ajax-loader.gif' );
34
-
35
- return apply_filters( 'wpcf7_ajax_loader', $url );
36
- }
37
-
38
function wpcf7_verify_nonce( $nonce, $action = -1 ) {
39
if ( substr( wp_hash( $action, 'nonce' ), -12, 10 ) == $nonce )
40
return true;
@@ -347,3 +342,15 @@ function wpcf7_is_localhost() {
347
$server_name = strtolower( $_SERVER['SERVER_NAME'] );
348
return in_array( $server_name, array( 'localhost', '127.0.0.1' ) );
349
}
15
}
16
17
function wpcf7_upload_dir( $type = false ) {
18
+ $uploads = wp_get_upload_dir();
19
20
$uploads = apply_filters( 'wpcf7_upload_dir', array(
21
'dir' => $uploads['basedir'],
22
'url' => $uploads['baseurl'] ) );
23
24
+ if ( 'dir' == $type ) {
25
return $uploads['dir'];
26
+ } if ( 'url' == $type ) {
27
return $uploads['url'];
28
+ }
29
30
return $uploads;
31
}
32
33
function wpcf7_verify_nonce( $nonce, $action = -1 ) {
34
if ( substr( wp_hash( $action, 'nonce' ), -12, 10 ) == $nonce )
35
return true;
342
$server_name = strtolower( $_SERVER['SERVER_NAME'] );
343
return in_array( $server_name, array( 'localhost', '127.0.0.1' ) );
344
}
345
+
346
+ function wpcf7_deprecated_function( $function, $version, $replacement ) {
347
+ $trigger_error = apply_filters( 'deprecated_function_trigger_error', true );
348
+
349
+ if ( WP_DEBUG && $trigger_error ) {
350
+ if ( function_exists( '__' ) ) {
351
+ trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', 'contact-form-7' ), $function, $version, $replacement ) );
352
+ } else {
353
+ trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since Contact Form 7 version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
354
+ }
355
+ }
356
+ }
includes/js/scripts.js CHANGED
@@ -15,7 +15,7 @@
15
beforeSubmit: function(arr, $form, options) {
16
$form.wpcf7ClearResponseOutput();
17
$form.find('[aria-invalid]').attr('aria-invalid', 'false');
18
- $form.find('img.ajax-loader').css({ visibility: 'visible' });
19
return true;
20
},
21
beforeSerialize: function($form, options) {
@@ -199,11 +199,7 @@
199
200
$.fn.wpcf7AjaxLoader = function() {
201
return this.each(function() {
202
- var loader = $('<img class="ajax-loader" />')
203
- .attr({ src: _wpcf7.loaderUrl, alt: _wpcf7.sending })
204
- .css('visibility', 'hidden');
205
-
206
- $(this).after(loader);
207
});
208
};
209
@@ -394,7 +390,7 @@
394
return this.each(function() {
395
$(this).find('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked').removeAttr('role');
396
$(this).find('span.wpcf7-not-valid-tip').remove();
397
- $(this).find('img.ajax-loader').css({ visibility: 'hidden' });
398
});
399
};
400
15
beforeSubmit: function(arr, $form, options) {
16
$form.wpcf7ClearResponseOutput();
17
$form.find('[aria-invalid]').attr('aria-invalid', 'false');
18
+ $form.find('.ajax-loader').addClass('is-active');
19
return true;
20
},
21
beforeSerialize: function($form, options) {
199
200
$.fn.wpcf7AjaxLoader = function() {
201
return this.each(function() {
202
+ $(this).after('<span class="ajax-loader"></span>');
203
});
204
};
205
390
return this.each(function() {
391
$(this).find('div.wpcf7-response-output').hide().empty().removeClass('wpcf7-mail-sent-ok wpcf7-mail-sent-ng wpcf7-validation-errors wpcf7-spam-blocked').removeAttr('role');
392
$(this).find('span.wpcf7-not-valid-tip').remove();
393
+ $(this).find('.ajax-loader').removeClass('is-active');
394
});
395
};
396
includes/mail.php CHANGED
@@ -6,61 +6,87 @@ class WPCF7_Mail {
6
7
private $name = '';
8
private $template = array();
9
10
- public static function send( $template, $name = '' ) {
11
- $instance = new self;
12
- $instance->name = trim( $name );
13
- $instance->setup_template( $template );
14
-
15
- self::$current = $instance;
16
-
17
- return $instance->compose();
18
}
19
20
- private function __construct() {}
21
-
22
- public function name() {
23
- return $this->name;
24
}
25
26
- public static function get_current() {
27
- return self::$current;
28
- }
29
30
- private function setup_template( $template ) {
31
- $defaults = array(
32
'subject' => '', 'sender' => '', 'body' => '',
33
'recipient' => '', 'additional_headers' => '',
34
- 'attachments' => '', 'use_html' => false,
35
- 'exclude_blank' => false );
36
37
- $this->template = wp_parse_args( $template, $defaults );
38
}
39
40
- private function compose( $send = true ) {
41
$template = $this->template;
42
- $use_html = (bool) $template['use_html'];
43
44
- $subject = $this->replace_tags( $template['subject'] );
45
- $sender = $this->replace_tags( $template['sender'] );
46
- $recipient = $this->replace_tags( $template['recipient'] );
47
- $additional_headers = $this->replace_tags( $template['additional_headers'] );
48
49
- if ( $use_html ) {
50
- $body = $this->replace_tags( $template['body'], true );
51
- $body = wpautop( $body );
52
- } else {
53
- $body = $this->replace_tags( $template['body'] );
54
}
55
56
- $attachments = $this->attachments( $template['attachments'] );
57
58
- $components = compact( 'subject', 'sender', 'body',
59
- 'recipient', 'additional_headers', 'attachments' );
60
61
$components = apply_filters( 'wpcf7_mail_components',
62
$components, wpcf7_get_current_contact_form(), $this );
63
64
$subject = wpcf7_strip_newline( $components['subject'] );
65
$sender = wpcf7_strip_newline( $components['sender'] );
66
$recipient = wpcf7_strip_newline( $components['recipient'] );
@@ -70,7 +96,7 @@ class WPCF7_Mail {
70
71
$headers = "From: $sender\n";
72
73
- if ( $use_html ) {
74
$headers .= "Content-Type: text/html\n";
75
$headers .= "X-WPCF7-Content-Type: text/html\n";
76
} else {
@@ -81,25 +107,22 @@ class WPCF7_Mail {
81
$headers .= $additional_headers . "\n";
82
}
83
84
- if ( $send ) {
85
- return wp_mail( $recipient, $subject, $body, $headers, $attachments );
86
- }
87
-
88
- $components = compact( 'subject', 'sender', 'body',
89
- 'recipient', 'headers', 'attachments' );
90
-
91
- return $components;
92
}
93
94
public function replace_tags( $content, $html = false ) {
95
$args = array(
96
'html' => $html,
97
- 'exclude_blank' => $this->template['exclude_blank'] );
98
99
return wpcf7_mail_replace_tags( $content, $args );
100
}
101
102
- private function attachments( $template ) {
103
$attachments = array();
104
105
if ( $submission = WPCF7_Submission::get_instance() ) {
@@ -402,5 +425,3 @@ function wpcf7_special_mail_tag( $output, $name, $html ) {
402
403
return $output;
404
}
405
-
406
- ?>
6
7
private $name = '';
8
private $template = array();
9
+ private $use_html = false;
10
+ private $exclude_blank = false;
11
12
+ public static function get_current() {
13
+ return self::$current;
14
}
15
16
+ public static function send( $template, $name = '' ) {
17
+ self::$current = new self( $name, $template );
18
+ return self::$current->compose();
19
}
20
21
+ private function __construct( $name, $template ) {
22
+ $this->name = trim( $name );
23
+ $this->use_html = ! empty( $template['use_html'] );
24
+ $this->exclude_blank = ! empty( $template['exclude_blank'] );
25
26
+ $this->template = wp_parse_args( $template, array(
27
'subject' => '', 'sender' => '', 'body' => '',
28
'recipient' => '', 'additional_headers' => '',
29
+ 'attachments' => '' ) );
30
+ }
31
32
+ public function name() {
33
+ return $this->name;
34
}
35
36
+ public function get( $component, $replace_tags = false ) {
37
+ $use_html = ( $this->use_html && 'body' == $component );
38
$template = $this->template;
39
+ $component = isset( $template[$component] ) ? $template[$component] : '';
40
41
+ if ( $replace_tags ) {
42
+ if ( $use_html ) {
43
+ $component = $this->replace_tags( $component, true );
44
45
+ if ( ! preg_match( '%<html[>\s].*</html>%is', $component ) ) {
46
+ $component = $this->htmlize( $component );
47
+ }
48
+ } else {
49
+ $component = $this->replace_tags( $component );
50
+ }
51
}
52
53
+ return $component;
54
+ }
55
+
56
+ private function htmlize( $body ) {
57
+ $header = apply_filters( 'wpcf7_mail_html_header',
58
+ '<!doctype html>
59
+ <html xmlns="http://www.w3.org/1999/xhtml">
60
+ <head>
61
+ <title>' . esc_html( $this->get( 'subject', true ) ) . '</title>
62
+ </head>
63
+ <body>
64
+ ', $this );
65
+
66
+ $footer = apply_filters( 'wpcf7_mail_html_footer',
67
+ '</body>
68
+ </html>', $this );
69
+
70
+ $html = $header . wpautop( $body ) . $footer;
71
+ return $html;
72
+ }
73
74
+ private function compose( $send = true ) {
75
+ $components = array(
76
+ 'subject' => $this->get( 'subject', true ),
77
+ 'sender' => $this->get( 'sender', true ),
78
+ 'body' => $this->get( 'body', true ),
79
+ 'recipient' => $this->get( 'recipient', true ),
80
+ 'additional_headers' => $this->get( 'additional_headers', true ),
81
+ 'attachments' => $this->attachments() );
82
83
$components = apply_filters( 'wpcf7_mail_components',
84
$components, wpcf7_get_current_contact_form(), $this );
85
86
+ if ( ! $send ) {
87
+ return $components;
88
+ }
89
+
90
$subject = wpcf7_strip_newline( $components['subject'] );
91
$sender = wpcf7_strip_newline( $components['sender'] );
92
$recipient = wpcf7_strip_newline( $components['recipient'] );
96
97
$headers = "From: $sender\n";
98
99
+ if ( $this->use_html ) {
100
$headers .= "Content-Type: text/html\n";
101
$headers .= "X-WPCF7-Content-Type: text/html\n";
102
} else {
107
$headers .= $additional_headers . "\n";
108
}
109
110
+ return wp_mail( $recipient, $subject, $body, $headers, $attachments );
111
}
112
113
public function replace_tags( $content, $html = false ) {
114
$args = array(
115
'html' => $html,
116
+ 'exclude_blank' => $this->exclude_blank );
117
118
return wpcf7_mail_replace_tags( $content, $args );
119
}
120
121
+ private function attachments( $template = null ) {
122
+ if ( ! $template ) {
123
+ $template = $this->get( 'attachments' );
124
+ }
125
+
126
$attachments = array();
127
128
if ( $submission = WPCF7_Submission::get_instance() ) {
425
426
return $output;
427
}
includes/pipe.php CHANGED
@@ -69,11 +69,10 @@ class WPCF7_Pipes {
69
}
70
71
public function random_pipe() {
72
- if ( $this->zero() )
73
return null;
74
75
return $this->pipes[array_rand( $this->pipes )];
76
}
77
}
78
-
79
- ?>
69
}
70
71
public function random_pipe() {
72
+ if ( $this->zero() ) {
73
return null;
74
+ }
75
76
return $this->pipes[array_rand( $this->pipes )];
77
}
78
}
includes/shortcodes.php CHANGED
@@ -1,514 +1,101 @@
1
<?php
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
- return $this->scanned_tags;
27
- }
28
-
29
- public function add_shortcode( $tag, $func, $has_name = false ) {
30
- if ( ! is_callable( $func ) )
31
- return;
32
-
33
- $tags = array_filter( array_unique( (array) $tag ) );
34
-
35
- foreach ( $tags as $tag ) {
36
- $tag = $this->sanitize_tag_type( $tag );
37
-
38
- $this->shortcode_tags[$tag] = array(
39
- 'function' => $func,
40
- 'has_name' => (boolean) $has_name );
41
- }
42
- }
43
-
44
- private function sanitize_tag_type( $tag ) {
45
- $tag = preg_replace( '/[^a-zA-Z0-9_*]+/', '_', $tag );
46
- $tag = rtrim( $tag, '_' );
47
- $tag = strtolower( $tag );
48
- return $tag;
49
- }
50
-
51
- public function remove_shortcode( $tag ) {
52
- unset( $this->shortcode_tags[$tag] );
53
- }
54
-
55
- public function normalize_shortcode( $content ) {
56
- if ( empty( $this->shortcode_tags ) || ! is_array( $this->shortcode_tags ) )
57
- return $content;
58
-
59
- $pattern = $this->get_shortcode_regex();
60
- return preg_replace_callback( '/' . $pattern . '/s',
61
- array( $this, 'normalize_space_cb' ), $content );
62
- }
63
-
64
- private function normalize_space_cb( $m ) {
65
- // allow [[foo]] syntax for escaping a tag
66
- if ( $m[1] == '[' && $m[6] == ']' )
67
- return $m[0];
68
-
69
- $tag = $m[2];
70
- $attr = trim( preg_replace( '/[\r\n\t ]+/', ' ', $m[3] ) );
71
- $content = trim( $m[5] );
72
-
73
- $content = str_replace( "\n", '<WPPreserveNewline />', $content );
74
-
75
- $result = $m[1] . '[' . $tag
76
- . ( $attr ? ' ' . $attr : '' )
77
- . ( $m[4] ? ' ' . $m[4] : '' )
78
- . ']'
79
- . ( $content ? $content . '[/' . $tag . ']' : '' )
80
- . $m[6];
81
-
82
- return $result;
83
- }
84
-
85
- public function do_shortcode( $content, $exec = true ) {
86
- $this->exec = (bool) $exec;
87
- $this->scanned_tags = array();
88
-
89
- if ( empty( $this->shortcode_tags ) || ! is_array( $this->shortcode_tags ) )
90
- return $content;
91
-
92
- $pattern = $this->get_shortcode_regex();
93
- return preg_replace_callback( '/' . $pattern . '/s',
94
- array( $this, 'do_shortcode_tag' ), $content );
95
- }
96
-
97
- public function scan_shortcode( $content ) {
98
- $this->do_shortcode( $content, false );
99
- return $this->scanned_tags;
100
- }
101
-
102
- private function get_shortcode_regex() {
103
- $tagnames = array_keys( $this->shortcode_tags );
104
- $tagregexp = join( '|', array_map( 'preg_quote', $tagnames ) );
105
-
106
- return '(\[?)'
107
- . '\[(' . $tagregexp . ')(?:[\r\n\t ](.*?))?(?:[\r\n\t ](\/))?\]'
108
- . '(?:([^[]*?)\[\/\2\])?'
109
- . '(\]?)';
110
- }
111
-
112
- private function do_shortcode_tag( $m ) {
113
- // allow [[foo]] syntax for escaping a tag
114
- if ( $m[1] == '[' && $m[6] == ']' ) {
115
- return substr( $m[0], 1, -1 );
116
- }
117
-
118
- $tag = $m[2];
119
- $attr = $this->shortcode_parse_atts( $m[3] );
120
-
121
- $scanned_tag = array(
122
- 'type' => $tag,
123
- 'basetype' => trim( $tag, '*' ),
124
- 'name' => '',
125
- 'options' => array(),
126
- 'raw_values' => array(),
127
- 'values' => array(),
128
- 'pipes' => null,
129
- 'labels' => array(),
130
- 'attr' => '',
131
- 'content' => '' );
132
-
133
- if ( is_array( $attr ) ) {
134
- if ( is_array( $attr['options'] ) ) {
135
- if ( $this->shortcode_tags[$tag]['has_name'] && ! empty( $attr['options'] ) ) {
136
- $scanned_tag['name'] = array_shift( $attr['options'] );
137
-
138
- if ( ! wpcf7_is_name( $scanned_tag['name'] ) )
139
- return $m[0]; // Invalid name is used. Ignore this tag.
140
- }
141
-
142
- $scanned_tag['options'] = (array) $attr['options'];
143
- }
144
-
145
- $scanned_tag['raw_values'] = (array) $attr['values'];
146
-
147
- if ( WPCF7_USE_PIPE ) {
148
- $pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
149
- $scanned_tag['values'] = $pipes->collect_befores();
150
- $scanned_tag['pipes'] = $pipes;
151
- } else {
152
- $scanned_tag['values'] = $scanned_tag['raw_values'];
153
- }
154
-
155
- $scanned_tag['labels'] = $scanned_tag['values'];
156
-
157
- } else {
158
- $scanned_tag['attr'] = $attr;
159
- }
160
-
161
- $scanned_tag['values'] = array_map( 'trim', $scanned_tag['values'] );
162
- $scanned_tag['labels'] = array_map( 'trim', $scanned_tag['labels'] );
163
-
164
- $content = trim( $m[5] );
165
- $content = preg_replace( "/<br[\r\n\t ]*\/?>#x2F;m", '', $content );
166
- $scanned_tag['content'] = $content;
167
-
168
- $scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag, $this->exec );
169
-
170
- $this->scanned_tags[] = $scanned_tag;
171
-
172
- if ( $this->exec ) {
173
- $func = $this->shortcode_tags[$tag]['function'];
174
- return $m[1] . call_user_func( $func, $scanned_tag ) . $m[6];
175
- } else {
176
- return $m[0];
177
- }
178
- }
179
-
180
- private function shortcode_parse_atts( $text ) {
181
- $atts = array( 'options' => array(), 'values' => array() );
182
- $text = preg_replace( "/[\x{00a0}\x{200b}]+/u", " ", $text );
183
- $text = stripcslashes( trim( $text ) );
184
-
185
- $pattern = '%^([-+*=0-9a-zA-Z:.!?#amp;@_/|\%\r\n\t ]*?)((?:[\r\n\t ]*"[^"]*"|[\r\n\t ]*\'[^\']*\')*)$%';
186
-
187
- if ( preg_match( $pattern, $text, $match ) ) {
188
- if ( ! empty( $match[1] ) ) {
189
- $atts['options'] = preg_split( '/[\r\n\t ]+/', trim( $match[1] ) );
190
- }
191
- if ( ! empty( $match[2] ) ) {
192
- preg_match_all( '/"[^"]*"|\'[^\']*\'/', $match[2], $matched_values );
193
- $atts['values'] = wpcf7_strip_quote_deep( $matched_values[0] );
194
- }
195
- } else {
196
- $atts = $text;
197
- }
198
-
199
- return $atts;
200
- }
201
-
202
- }
203
204
function wpcf7_add_shortcode( $tag, $func, $has_name = false ) {
205
- $manager = WPCF7_ShortcodeManager::get_instance();
206
207
- return $manager->add_shortcode( $tag, $func, $has_name );
208
}
209
210
function wpcf7_remove_shortcode( $tag ) {
211
- $manager = WPCF7_ShortcodeManager::get_instance();
212
213
- return $manager->remove_shortcode( $tag );
214
}
215
216
function wpcf7_do_shortcode( $content ) {
217
- $manager = WPCF7_ShortcodeManager::get_instance();
218
219
- return $manager->do_shortcode( $content );
220
}
221
222
- class WPCF7_Shortcode {
223
-
224
- public $type;
225
- public $basetype;
226
- public $name = '';
227
- public $options = array();
228
- public $raw_values = array();
229
- public $values = array();
230
- public $pipes;
231
- public $labels = array();
232
- public $attr = '';
233
- public $content = '';
234
235
- public function __construct( $tag ) {
236
- foreach ( $tag as $key => $value ) {
237
- if ( property_exists( __CLASS__, $key ) )
238
- $this->{$key} = $value;
239
- }
240
- }
241
-
242
- public function is_required() {
243
- return ( '*' == substr( $this->type, -1 ) );
244
- }
245
-
246
- public function has_option( $opt ) {
247
- $pattern = sprintf( '/^%s(:.+)?#x2F;i', preg_quote( $opt, '/' ) );
248
- return (bool) preg_grep( $pattern, $this->options );
249
- }
250
-
251
- public function get_option( $opt, $pattern = '', $single = false ) {
252
- $preset_patterns = array(
253
- 'date' => '([0-9]{4}-[0-9]{2}-[0-9]{2}|today(.*))',
254
- 'int' => '[0-9]+',
255
- 'signed_int' => '-?[0-9]+',
256
- 'class' => '[-0-9a-zA-Z_]+',
257
- 'id' => '[-0-9a-zA-Z_]+' );
258
-
259
- if ( isset( $preset_patterns[$pattern] ) )
260
- $pattern = $preset_patterns[$pattern];
261
-
262
- if ( '' == $pattern )
263
- $pattern = '.+';
264
-
265
- $pattern = sprintf( '/^%s:%s#x2F;i', preg_quote( $opt, '/' ), $pattern );
266
-
267
- if ( $single ) {
268
- $matches = $this->get_first_match_option( $pattern );
269
-
270
- if ( ! $matches )
271
- return false;
272
-
273
- return substr( $matches[0], strlen( $opt ) + 1 );
274
- } else {
275
- $matches_a = $this->get_all_match_options( $pattern );
276
-
277
- if ( ! $matches_a )
278
- return false;
279
-
280
- $results = array();
281
-
282
- foreach ( $matches_a as $matches )
283
- $results[] = substr( $matches[0], strlen( $opt ) + 1 );
284
-
285
- return $results;
286
- }
287
- }
288
-
289
- public function get_id_option() {
290
- return $this->get_option( 'id', 'id', true );
291
- }
292
-
293
- public function get_class_option( $default = '' ) {
294
- if ( is_string( $default ) )
295
- $default = explode( ' ', $default );
296
-
297
- $options = array_merge(
298
- (array) $default,
299
- (array) $this->get_option( 'class', 'class' ) );
300
-
301
- $options = array_filter( array_unique( $options ) );
302
-
303
- return implode( ' ', $options );
304
- }
305
-
306
- public function get_size_option( $default = '' ) {
307
- $option = $this->get_option( 'size', 'int', true );
308
-
309
- if ( $option ) {
310
- return $option;
311
- }
312
-
313
- $matches_a = $this->get_all_match_options( '%^([0-9]*)/[0-9]*$%' );
314
-
315
- foreach ( (array) $matches_a as $matches ) {
316
- if ( isset( $matches[1] ) && '' !== $matches[1] )
317
- return $matches[1];
318
- }
319
-
320
- return $default;
321
- }
322
323
- public function get_maxlength_option( $default = '' ) {
324
- $option = $this->get_option( 'maxlength', 'int', true );
325
326
- if ( $option ) {
327
- return $option;
328
- }
329
330
- $matches_a = $this->get_all_match_options(
331
- '%^(?:[0-9]*x?[0-9]*)?/([0-9]+)$%' );
332
333
- foreach ( (array) $matches_a as $matches ) {
334
- if ( isset( $matches[1] ) && '' !== $matches[1] )
335
- return $matches[1];
336
- }
337
338
- return $default;
339
}
340
341
- public function get_minlength_option( $default = '' ) {
342
- $option = $this->get_option( 'minlength', 'int', true );
343
344
- if ( $option ) {
345
- return $option;
346
- } else {
347
- return $default;
348
- }
349
}
350
351
- public function get_cols_option( $default = '' ) {
352
- $option = $this->get_option( 'cols', 'int', true );
353
-
354
- if ( $option ) {
355
- return $option;
356
- }
357
-
358
- $matches_a = $this->get_all_match_options(
359
- '%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
360
-
361
- foreach ( (array) $matches_a as $matches ) {
362
- if ( isset( $matches[1] ) && '' !== $matches[1] )
363
- return $matches[1];
364
- }
365
366
- return $default;
367
}
368
369
- public function get_rows_option( $default = '' ) {
370
- $option = $this->get_option( 'rows', 'int', true );
371
-
372
- if ( $option ) {
373
- return $option;
374
- }
375
-
376
- $matches_a = $this->get_all_match_options(
377
- '%^([0-9]*)x([0-9]*)(?:/[0-9]+)?$%' );
378
-
379
- foreach ( (array) $matches_a as $matches ) {
380
- if ( isset( $matches[2] ) && '' !== $matches[2] )
381
- return $matches[2];
382
- }
383
384
- return $default;
385
}
386
387
- public function get_date_option( $opt ) {
388
- $option = $this->get_option( $opt, 'date', true );
389
-
390
- if ( preg_match( '/^[0-9]{4}-[0-9]{2}-[0-9]{2}#x2F;', $option ) ) {
391
- return $option;
392
- }
393
-
394
- if ( preg_match( '/^today(?:([+-][0-9]+)([a-z]*))?/', $option, $matches ) ) {
395
- $number = isset( $matches[1] ) ? (int) $matches[1] : 0;
396
- $unit = isset( $matches[2] ) ? $matches[2] : '';
397
-
398
- if ( ! preg_match( '/^(day|month|year|week)s?#x2F;', $unit ) ) {
399
- $unit = 'days';
400
- }
401
-
402
- $date = gmdate( 'Y-m-d',
403
- strtotime( sprintf( 'today %1$s %2$s', $number, $unit ) ) );
404
- return $date;
405
- }
406
407
- return false;
408
}
409
410
- public function get_default_option( $default = '', $args = '' ) {
411
- $args = wp_parse_args( $args, array(
412
- 'multiple' => false ) );
413
-
414
- $options = (array) $this->get_option( 'default' );
415
- $values = array();
416
-
417
- if ( empty( $options ) ) {
418
- return $args['multiple'] ? $values : $default;
419
- }
420
-
421
- foreach ( $options as $opt ) {
422
- $opt = sanitize_key( $opt );
423
-
424
- if ( 'user_' == substr( $opt, 0, 5 ) && is_user_logged_in() ) {
425
- $primary_props = array( 'user_login', 'user_email', 'user_url' );
426
- $opt = in_array( $opt, $primary_props ) ? $opt : substr( $opt, 5 );
427
-
428
- $user = wp_get_current_user();
429
- $user_prop = $user->get( $opt );
430
-
431
- if ( ! empty( $user_prop ) ) {
432
- if ( $args['multiple'] ) {
433
- $values[] = $user_prop;
434
- } else {
435
- return $user_prop;
436
- }
437
- }
438
-
439
- } elseif ( 'post_meta' == $opt && in_the_loop() ) {
440
- if ( $args['multiple'] ) {
441
- $values = array_merge( $values,
442
- get_post_meta( get_the_ID(), $this->name ) );
443
- } else {
444
- $val = (string) get_post_meta( get_the_ID(), $this->name, true );
445
-
446
- if ( strlen( $val ) ) {
447
- return $val;
448
- }
449
- }
450
-
451
- } elseif ( 'get' == $opt && isset( $_GET[$this->name] ) ) {
452
- $vals = (array) $_GET[$this->name];
453
- $vals = array_map( 'wpcf7_sanitize_query_var', $vals );
454
-
455
- if ( $args['multiple'] ) {
456
- $values = array_merge( $values, $vals );
457
- } else {
458
- $val = isset( $vals[0] ) ? (string) $vals[0] : '';
459
-
460
- if ( strlen( $val ) ) {
461
- return $val;
462
- }
463
- }
464
-
465
- } elseif ( 'post' == $opt && isset( $_POST[$this->name] ) ) {
466
- $vals = (array) $_POST[$this->name];
467
- $vals = array_map( 'wpcf7_sanitize_query_var', $vals );
468
-
469
- if ( $args['multiple'] ) {
470
- $values = array_merge( $values, $vals );
471
- } else {
472
- $val = isset( $vals[0] ) ? (string) $vals[0] : '';
473
-
474
- if ( strlen( $val ) ) {
475
- return $val;
476
- }
477
- }
478
- }
479
- }
480
481
- if ( $args['multiple'] ) {
482
- $values = array_unique( $values );
483
- return $values;
484
} else {
485
- return $default;
486
}
487
}
488
489
- public function get_data_option( $args = '' ) {
490
- $options = (array) $this->get_option( 'data' );
491
-
492
- return apply_filters( 'wpcf7_form_tag_data_option', null, $options, $args );
493
- }
494
-
495
- public function get_first_match_option( $pattern ) {
496
- foreach( (array) $this->options as $option ) {
497
- if ( preg_match( $pattern, $option, $matches ) )
498
- return $matches;
499
- }
500
501
- return false;
502
}
503
504
- public function get_all_match_options( $pattern ) {
505
- $result = array();
506
507
- foreach( (array) $this->options as $option ) {
508
- if ( preg_match( $pattern, $option, $matches ) )
509
- $result[] = $matches;
510
- }
511
512
- return $result;
513
}
514
}
1
<?php
2
+ /**
3
+ * All the functions and classes in this file are deprecated.
4
+ * You shouldn't use them. The functions and classes will be
5
+ * removed in a later version.
6
+ */
7
8
function wpcf7_add_shortcode( $tag, $func, $has_name = false ) {
9
+ wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_add_form_tag' );
10
11
+ return wpcf7_add_form_tag( $tag, $func, $has_name );
12
}
13
14
function wpcf7_remove_shortcode( $tag ) {
15
+ wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_remove_form_tag' );
16
17
+ return wpcf7_remove_form_tag( $tag );
18
}
19
20
function wpcf7_do_shortcode( $content ) {
21
+ wpcf7_deprecated_function( __FUNCTION__, '4.6',
22
+ 'wpcf7_replace_all_form_tags' );
23
24
+ return wpcf7_replace_all_form_tags( $content );
25
}
26
27
+ function wpcf7_scan_shortcode( $cond = null ) {
28
+ wpcf7_deprecated_function( __FUNCTION__, '4.6', 'wpcf7_scan_form_tags' );
29
30
+ return wpcf7_scan_form_tags( $cond );
31
+ }
32
33
+ class WPCF7_ShortcodeManager {
34
35
+ private static $form_tags_manager;
36
37
+ private function __construct() {}
38
39
+ public static function get_instance() {
40
+ wpcf7_deprecated_function( __METHOD__, '4.6',
41
+ 'WPCF7_FormTagsManager::get_instance' );
42
43
+ self::$form_tags_manager = WPCF7_FormTagsManager::get_instance();
44
+ return new self;
45
}
46
47
+ public function get_scanned_tags() {
48
+ wpcf7_deprecated_function( __METHOD__, '4.6',
49
+ 'WPCF7_FormTagsManager::get_scanned_tags' );
50
51
+ return self::$form_tags_manager->get_scanned_tags();
52
}
53
54
+ public function add_shortcode( $tag, $func, $has_name = false ) {
55
+ wpcf7_deprecated_function( __METHOD__, '4.6',
56
+ 'WPCF7_FormTagsManager::add' );
57
58
+ return self::$form_tags_manager->add( $tag, $func, $has_name );
59
}
60
61
+ public function remove_shortcode( $tag ) {
62