Contact Form 7 - Version 3.1

Version Description

  • Offer nonce verification for contact forms.
  • Add several options to retrieve logged-in user info as default value of field.
  • Introduce wpcf7_validate filter for validation independent from specific form tag type.
  • Search contact form by title when failed to find by ID.
  • Include all $_POST variables into $cf->posted_data and make them referable from mail.
  • Add watermark option to captchar (CAPTCHA-response) field.
  • Introduce wpcf7_ajax_loader() function and wpcf7_ajax_loader filter.
  • Introduce wpcf7_akismet_comment_check filter.
  • Introduce menu icons created by Takao Honda.
  • Translation for Azeri has been created.
  • Translations for Italian, Russian, Arabic, Danish, Persian, Romanian, and Portuguese have been updated.

=

Download this release

Release Info

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

Code changes from version 3.0.2.1 to 3.1

admin/admin.php CHANGED
@@ -1,330 +1,320 @@
1
- <?php
2
-
3
- function wpcf7_admin_has_edit_cap() {
4
- return current_user_can( WPCF7_ADMIN_READ_WRITE_CAPABILITY );
5
- }
6
-
7
- add_action( 'admin_init', 'wpcf7_admin_init' );
8
-
9
- function wpcf7_admin_init() {
10
- if ( ! wpcf7_admin_has_edit_cap() )
11
- return;
12
-
13
- if ( isset( $_POST['wpcf7-save'] ) ) {
14
- $id = $_POST['post_ID'];
15
- check_admin_referer( 'wpcf7-save_' . $id );
16
-
17
- if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
18
- $contact_form = new WPCF7_ContactForm();
19
- $contact_form->initial = true;
20
- }
21
-
22
- $contact_form->title = trim( $_POST['wpcf7-title'] );
23
-
24
- $form = trim( $_POST['wpcf7-form'] );
25
-
26
- $mail = array(
27
- 'subject' => trim( $_POST['wpcf7-mail-subject'] ),
28
- 'sender' => trim( $_POST['wpcf7-mail-sender'] ),
29
- 'body' => trim( $_POST['wpcf7-mail-body'] ),
30
- 'recipient' => trim( $_POST['wpcf7-mail-recipient'] ),
31
- 'additional_headers' => trim( $_POST['wpcf7-mail-additional-headers'] ),
32
- 'attachments' => trim( $_POST['wpcf7-mail-attachments'] ),
33
- 'use_html' =>
34
- isset( $_POST['wpcf7-mail-use-html'] ) && 1 == $_POST['wpcf7-mail-use-html']
35
- );
36
-
37
- $mail_2 = array(
38
- 'active' =>
39
- isset( $_POST['wpcf7-mail-2-active'] ) && 1 == $_POST['wpcf7-mail-2-active'],
40
- 'subject' => trim( $_POST['wpcf7-mail-2-subject'] ),
41
- 'sender' => trim( $_POST['wpcf7-mail-2-sender'] ),
42
- 'body' => trim( $_POST['wpcf7-mail-2-body'] ),
43
- 'recipient' => trim( $_POST['wpcf7-mail-2-recipient'] ),
44
- 'additional_headers' => trim( $_POST['wpcf7-mail-2-additional-headers'] ),
45
- 'attachments' => trim( $_POST['wpcf7-mail-2-attachments'] ),
46
- 'use_html' =>
47
- isset( $_POST['wpcf7-mail-2-use-html'] ) && 1 == $_POST['wpcf7-mail-2-use-html']
48
- );
49
-
50
- $messages = isset( $contact_form->messages ) ? $contact_form->messages : array();
51
-
52
- foreach ( wpcf7_messages() as $key => $arr ) {
53
- $field_name = 'wpcf7-message-' . strtr( $key, '_', '-' );
54
- if ( isset( $_POST[$field_name] ) )
55
- $messages[$key] = trim( $_POST[$field_name] );
56
- }
57
-
58
- $additional_settings = trim( $_POST['wpcf7-additional-settings'] );
59
-
60
- $props = apply_filters( 'wpcf7_contact_form_admin_posted_properties',
61
- compact( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' ) );
62
-
63
- foreach ( (array) $props as $key => $prop )
64
- $contact_form->{$key} = $prop;
65
-
66
- $query = array();
67
- $query['message'] = ( $contact_form->initial ) ? 'created' : 'saved';
68
-
69
- $contact_form->save();
70
-
71
- $query['contactform'] = $contact_form->id;
72
- $redirect_to = wpcf7_admin_url( $query );
73
- wp_safe_redirect( $redirect_to );
74
- exit();
75
- }
76
-
77
- if ( isset( $_POST['wpcf7-copy'] ) ) {
78
- $id = $_POST['post_ID'];
79
- check_admin_referer( 'wpcf7-copy_' . $id );
80
-
81
- $query = array();
82
-
83
- if ( $contact_form = wpcf7_contact_form( $id ) ) {
84
- $new_contact_form = $contact_form->copy();
85
- $new_contact_form->save();
86
-
87
- $query['contactform'] = $new_contact_form->id;
88
- $query['message'] = 'created';
89
- } else {
90
- $query['contactform'] = $contact_form->id;
91
- }
92
-
93
- $redirect_to = wpcf7_admin_url( $query );
94
- wp_safe_redirect( $redirect_to );
95
- exit();
96
- }
97
-
98
- if ( isset( $_POST['wpcf7-delete'] ) ) {
99
- $id = $_POST['post_ID'];
100
- check_admin_referer( 'wpcf7-delete_' . $id );
101
-
102
- if ( $contact_form = wpcf7_contact_form( $id ) )
103
- $contact_form->delete();
104
-
105
- $redirect_to = wpcf7_admin_url( array( 'message' => 'deleted' ) );
106
- wp_safe_redirect( $redirect_to );
107
- exit();
108
- }
109
- }
110
-
111
- add_action( 'admin_menu', 'wpcf7_admin_menu', 9 );
112
-
113
- function wpcf7_admin_menu() {
114
- add_menu_page( __( 'Contact Form 7', 'wpcf7' ), __( 'Contact', 'wpcf7' ),
115
- WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page' );
116
-
117
- add_submenu_page( 'wpcf7', __( 'Edit Contact Forms', 'wpcf7' ), __( 'Edit', 'wpcf7' ),
118
- WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page' );
119
- }
120
-
121
- add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_styles' );
122
-
123
- function wpcf7_admin_enqueue_styles() {
124
- global $plugin_page;
125
-
126
- if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page )
127
- return;
128
-
129
- wp_enqueue_style( 'thickbox' );
130
-
131
- wp_enqueue_style( 'contact-form-7-admin', wpcf7_plugin_url( 'admin/styles.css' ),
132
- array(), WPCF7_VERSION, 'all' );
133
-
134
- if ( wpcf7_is_rtl() ) {
135
- wp_enqueue_style( 'contact-form-7-admin-rtl',
136
- wpcf7_plugin_url( 'admin/styles-rtl.css' ), array(), WPCF7_VERSION, 'all' );
137
- }
138
- }
139
-
140
- add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_scripts' );
141
-
142
- function wpcf7_admin_enqueue_scripts() {
143
- global $plugin_page;
144
-
145
- if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page )
146
- return;
147
-
148
- wp_enqueue_script( 'thickbox' );
149
- wp_enqueue_script( 'postbox' );
150
-
151
- wp_enqueue_script( 'wpcf7-admin-taggenerator', wpcf7_plugin_url( 'admin/taggenerator.js' ),
152
- array( 'jquery' ), WPCF7_VERSION, true );
153
-
154
- wp_enqueue_script( 'wpcf7-admin', wpcf7_plugin_url( 'admin/scripts.js' ),
155
- array( 'jquery', 'wpcf7-admin-taggenerator' ), WPCF7_VERSION, true );
156
- wp_localize_script( 'wpcf7-admin', '_wpcf7L10n', array(
157
- 'generateTag' => __( 'Generate Tag', 'wpcf7' ) ) );
158
- }
159
-
160
- add_action( 'admin_footer', 'wpcf7_admin_footer' );
161
-
162
- function wpcf7_admin_footer() {
163
- global $plugin_page;
164
-
165
- if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page )
166
- return;
167
-
168
- ?>
169
- <script type="text/javascript">
170
- /* <![CDATA[ */
171
- var _wpcf7 = {
172
- pluginUrl: '<?php echo wpcf7_plugin_url(); ?>',
173
- tagGenerators: {
174
- <?php wpcf7_print_tag_generators(); ?>
175
- }
176
- };
177
- /* ]]> */
178
- </script>
179
- <?php
180
- }
181
-
182
- function wpcf7_admin_management_page() {
183
- $contact_forms = get_posts( array(
184
- 'numberposts' => -1,
185
- 'orderby' => 'ID',
186
- 'order' => 'ASC',
187
- 'post_type' => 'wpcf7_contact_form' ) );
188
-
189
- $cf = null;
190
- $unsaved = false;
191
-
192
- if ( ! isset( $_GET['contactform'] ) )
193
- $_GET['contactform'] = '';
194
-
195
- if ( 'new' == $_GET['contactform'] && wpcf7_admin_has_edit_cap() ) {
196
- $unsaved = true;
197
- $current = -1;
198
- $cf = wpcf7_get_contact_form_default_pack(
199
- array( 'locale' => ( isset( $_GET['locale'] ) ? $_GET['locale'] : '' ) ) );
200
- } elseif ( $cf = wpcf7_contact_form( $_GET['contactform'] ) ) {
201
- $current = (int) $_GET['contactform'];
202
- } else {
203
- $first = reset( $contact_forms ); // Returns first item
204
-
205
- if ( $first ) {
206
- $current = $first->ID;
207
- $cf = wpcf7_contact_form( $current );
208
- }
209
- }
210
-
211
- require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
212
- require_once WPCF7_PLUGIN_DIR . '/admin/edit.php';
213
- }
214
-
215
- /* Misc */
216
-
217
- add_filter( 'plugin_action_links', 'wpcf7_plugin_action_links', 10, 2 );
218
-
219
- function wpcf7_plugin_action_links( $links, $file ) {
220
- if ( $file != WPCF7_PLUGIN_BASENAME )
221
- return $links;
222
-
223
- $url = wpcf7_admin_url();
224
-
225
- $settings_link = '<a href="' . esc_attr( $url ) . '">'
226
- . esc_html( __( 'Settings', 'wpcf7' ) ) . '</a>';
227
-
228
- array_unshift( $links, $settings_link );
229
-
230
- return $links;
231
- }
232
-
233
- add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_cf7com_links', 9 );
234
-
235
- function wpcf7_cf7com_links( &$contact_form ) {
236
- $links = '<div class="cf7com-links">'
237
- . '<a href="' . esc_url_raw( __( 'http://contactform7.com/', 'wpcf7' ) ) . '" target="_blank">'
238
- . esc_html( __( 'Contactform7.com', 'wpcf7' ) ) . '</a>&ensp;'
239
- . '<a href="' . esc_url_raw( __( 'http://contactform7.com/docs/', 'wpcf7' ) ) . '" target="_blank">'
240
- . esc_html( __( 'Docs', 'wpcf7' ) ) . '</a> - '
241
- . '<a href="' . esc_url_raw( __( 'http://contactform7.com/faq/', 'wpcf7' ) ) . '" target="_blank">'
242
- . esc_html( __( 'FAQ', 'wpcf7' ) ) . '</a> - '
243
- . '<a href="' . esc_url_raw( __( 'http://contactform7.com/support/', 'wpcf7' ) ) . '" target="_blank">'
244
- . esc_html( __( 'Support', 'wpcf7' ) ) . '</a>'
245
- . '</div>';
246
-
247
- echo apply_filters( 'wpcf7_cf7com_links', $links );
248
- }
249
-
250
- add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_updated_message' );
251
-
252
- function wpcf7_updated_message( &$contact_form ) {
253
- if ( ! isset( $_GET['message'] ) )
254
- return;
255
-
256
- switch ( $_GET['message'] ) {
257
- case 'created':
258
- $updated_message = __( "Contact form created.", 'wpcf7' );
259
- break;
260
- case 'saved':
261
- $updated_message = __( "Contact form saved.", 'wpcf7' );
262
- break;
263
- case 'deleted':
264
- $updated_message = __( "Contact form deleted.", 'wpcf7' );
265
- break;
266
- }
267
-
268
- if ( ! $updated_message )
269
- return;
270
-
271
- ?>
272
- <div id="message" class="updated"><p><?php echo esc_html( $updated_message ); ?></p></div>
273
- <?php
274
- }
275
-
276
- add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_donation_link' );
277
-
278
- function wpcf7_donation_link( &$contact_form ) {
279
- if ( ! WPCF7_SHOW_DONATION_LINK )
280
- return;
281
-
282
- if ( 'new' == $_GET['contactform'] || ! empty( $_GET['message'] ) )
283
- return;
284
-
285
- $show_link = true;
286
-
287
- $num = mt_rand( 0, 99 );
288
-
289
- if ( $num >= 20 )
290
- $show_link = false;
291
-
292
- $show_link = apply_filters( 'wpcf7_show_donation_link', $show_link );
293
-
294
- if ( ! $show_link )
295
- return;
296
-
297
- $texts = array(
298
- __( "Contact Form 7 needs your support. Please donate today.", 'wpcf7' ),
299
- __( "Your contribution is needed for making this plugin better.", 'wpcf7' ) );
300
-
301
- $text = $texts[array_rand( $texts )];
302
-
303
- ?>
304
- <div class="donation">
305
- <p><a href="<?php echo esc_url_raw( __( 'http://contactform7.com/donate/', 'wpcf7' ) ); ?>"><?php echo esc_html( $text ); ?></a> <a href="<?php echo esc_url_raw( __( 'http://contactform7.com/donate/', 'wpcf7' ) ); ?>" class="button"><?php echo esc_html( __( "Donate", 'wpcf7' ) ); ?></a></p>
306
- </div>
307
- <?php
308
- }
309
-
310
- add_action( 'admin_notices', 'wpcf7_old_wp_version_error', 9 );
311
-
312
- function wpcf7_old_wp_version_error() {
313
- global $plugin_page;
314
-
315
- if ( 'wpcf7' != $plugin_page )
316
- return;
317
-
318
- $wp_version = get_bloginfo( 'version' );
319
-
320
- if ( ! version_compare( $wp_version, WPCF7_REQUIRED_WP_VERSION, '<' ) )
321
- return;
322
-
323
- ?>
324
- <div class="error">
325
- <p><?php echo sprintf( __( '<strong>Contact Form 7 %1$s requires WordPress %2$s or higher.</strong> Please <a href="%3$s">update WordPress</a> first.', 'wpcf7' ), WPCF7_VERSION, WPCF7_REQUIRED_WP_VERSION, admin_url( 'update-core.php' ) ); ?></p>
326
- </div>
327
- <?php
328
- }
329
-
330
?>
1
+ <?php
2
+
3
+ function wpcf7_admin_has_edit_cap() {
4
+ return current_user_can( WPCF7_ADMIN_READ_WRITE_CAPABILITY );
5
+ }
6
+
7
+ add_action( 'admin_init', 'wpcf7_admin_init' );
8
+
9
+ function wpcf7_admin_init() {
10
+ if ( ! wpcf7_admin_has_edit_cap() )
11
+ return;
12
+
13
+ if ( isset( $_POST['wpcf7-save'] ) ) {
14
+ $id = $_POST['post_ID'];
15
+ check_admin_referer( 'wpcf7-save_' . $id );
16
+
17
+ if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
18
+ $contact_form = new WPCF7_ContactForm();
19
+ $contact_form->initial = true;
20
+ }
21
+
22
+ $contact_form->title = trim( $_POST['wpcf7-title'] );
23
+
24
+ $form = trim( $_POST['wpcf7-form'] );
25
+
26
+ $mail = array(
27
+ 'subject' => trim( $_POST['wpcf7-mail-subject'] ),
28
+ 'sender' => trim( $_POST['wpcf7-mail-sender'] ),
29
+ 'body' => trim( $_POST['wpcf7-mail-body'] ),
30
+ 'recipient' => trim( $_POST['wpcf7-mail-recipient'] ),
31
+ 'additional_headers' => trim( $_POST['wpcf7-mail-additional-headers'] ),
32
+ 'attachments' => trim( $_POST['wpcf7-mail-attachments'] ),
33
+ 'use_html' =>
34
+ isset( $_POST['wpcf7-mail-use-html'] ) && 1 == $_POST['wpcf7-mail-use-html']
35
+ );
36
+
37
+ $mail_2 = array(
38
+ 'active' =>
39
+ isset( $_POST['wpcf7-mail-2-active'] ) && 1 == $_POST['wpcf7-mail-2-active'],
40
+ 'subject' => trim( $_POST['wpcf7-mail-2-subject'] ),
41
+ 'sender' => trim( $_POST['wpcf7-mail-2-sender'] ),
42
+ 'body' => trim( $_POST['wpcf7-mail-2-body'] ),
43
+ 'recipient' => trim( $_POST['wpcf7-mail-2-recipient'] ),
44
+ 'additional_headers' => trim( $_POST['wpcf7-mail-2-additional-headers'] ),
45
+ 'attachments' => trim( $_POST['wpcf7-mail-2-attachments'] ),
46
+ 'use_html' =>
47
+ isset( $_POST['wpcf7-mail-2-use-html'] ) && 1 == $_POST['wpcf7-mail-2-use-html']
48
+ );
49
+
50
+ $messages = isset( $contact_form->messages ) ? $contact_form->messages : array();
51
+
52
+ foreach ( wpcf7_messages() as $key => $arr ) {
53
+ $field_name = 'wpcf7-message-' . strtr( $key, '_', '-' );
54
+ if ( isset( $_POST[$field_name] ) )
55
+ $messages[$key] = trim( $_POST[$field_name] );
56
+ }
57
+
58
+ $additional_settings = trim( $_POST['wpcf7-additional-settings'] );
59
+
60
+ $props = apply_filters( 'wpcf7_contact_form_admin_posted_properties',
61
+ compact( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' ) );
62
+
63
+ foreach ( (array) $props as $key => $prop )
64
+ $contact_form->{$key} = $prop;
65
+
66
+ $query = array();
67
+ $query['message'] = ( $contact_form->initial ) ? 'created' : 'saved';
68
+
69
+ $contact_form->save();
70
+
71
+ $query['contactform'] = $contact_form->id;
72
+ $redirect_to = wpcf7_admin_url( $query );
73
+ wp_safe_redirect( $redirect_to );
74
+ exit();
75
+ }
76
+
77
+ if ( isset( $_POST['wpcf7-copy'] ) ) {
78
+ $id = $_POST['post_ID'];
79
+ check_admin_referer( 'wpcf7-copy_' . $id );
80
+
81
+ $query = array();
82
+
83
+ if ( $contact_form = wpcf7_contact_form( $id ) ) {
84
+ $new_contact_form = $contact_form->copy();
85
+ $new_contact_form->save();
86
+
87
+ $query['contactform'] = $new_contact_form->id;
88
+ $query['message'] = 'created';
89
+ } else {
90
+ $query['contactform'] = $contact_form->id;
91
+ }
92
+
93
+ $redirect_to = wpcf7_admin_url( $query );
94
+ wp_safe_redirect( $redirect_to );
95
+ exit();
96
+ }
97
+
98
+ if ( isset( $_POST['wpcf7-delete'] ) ) {
99
+ $id = $_POST['post_ID'];
100
+ check_admin_referer( 'wpcf7-delete_' . $id );
101
+
102
+ if ( $contact_form = wpcf7_contact_form( $id ) )
103
+ $contact_form->delete();
104
+
105
+ $redirect_to = wpcf7_admin_url( array( 'message' => 'deleted' ) );
106
+ wp_safe_redirect( $redirect_to );
107
+ exit();
108
+ }
109
+ }
110
+
111
+ add_action( 'admin_menu', 'wpcf7_admin_menu', 9 );
112
+
113
+ function wpcf7_admin_menu() {
114
+ add_menu_page( __( 'Contact Form 7', 'wpcf7' ), __( 'Contact', 'wpcf7' ),
115
+ WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page',
116
+ wpcf7_plugin_url( 'admin/images/menu-icon.png' ) );
117
+
118
+ add_submenu_page( 'wpcf7', __( 'Edit Contact Forms', 'wpcf7' ), __( 'Edit', 'wpcf7' ),
119
+ WPCF7_ADMIN_READ_CAPABILITY, 'wpcf7', 'wpcf7_admin_management_page' );
120
+ }
121
+
122
+ add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_styles' );
123
+
124
+ function wpcf7_admin_enqueue_styles() {
125
+ global $plugin_page;
126
+
127
+ if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page )
128
+ return;
129
+
130
+ wp_enqueue_style( 'thickbox' );
131
+
132
+ wp_enqueue_style( 'contact-form-7-admin', wpcf7_plugin_url( 'admin/styles.css' ),
133
+ array(), WPCF7_VERSION, 'all' );
134
+
135
+ if ( wpcf7_is_rtl() ) {
136
+ wp_enqueue_style( 'contact-form-7-admin-rtl',
137
+ wpcf7_plugin_url( 'admin/styles-rtl.css' ), array(), WPCF7_VERSION, 'all' );
138
+ }
139
+ }
140
+
141
+ add_action( 'admin_enqueue_scripts', 'wpcf7_admin_enqueue_scripts' );
142
+
143
+ function wpcf7_admin_enqueue_scripts() {
144
+ global $plugin_page, $wpcf7_tag_generators;
145
+
146
+ if ( ! isset( $plugin_page ) || 'wpcf7' != $plugin_page )
147
+ return;
148
+
149
+ wp_enqueue_script( 'thickbox' );
150
+ wp_enqueue_script( 'postbox' );
151
+
152
+ wp_enqueue_script( 'wpcf7-admin-taggenerator', wpcf7_plugin_url( 'admin/taggenerator.js' ),
153
+ array( 'jquery' ), WPCF7_VERSION, true );
154
+
155
+ wp_enqueue_script( 'wpcf7-admin', wpcf7_plugin_url( 'admin/scripts.js' ),
156
+ array( 'jquery', 'wpcf7-admin-taggenerator' ), WPCF7_VERSION, true );
157
+
158
+ $taggenerators = array();
159
+
160
+ foreach ( (array) $wpcf7_tag_generators as $name => $tg ) {
161
+ $taggenerators[$name] = array_merge(
162
+ (array) $tg['options'],
163
+ array( 'title' => $tg['title'], 'content' => $tg['content'] ) );
164
+ }
165
+
166
+ wp_localize_script( 'wpcf7-admin', '_wpcf7', array(
167
+ 'generateTag' => __( 'Generate Tag', 'wpcf7' ),
168
+ 'pluginUrl' => wpcf7_plugin_url(),
169
+ 'tagGenerators' => $taggenerators ) );
170
+ }
171
+
172
+ function wpcf7_admin_management_page() {
173
+ $contact_forms = get_posts( array(
174
+ 'numberposts' => -1,
175
+ 'orderby' => 'ID',
176
+ 'order' => 'ASC',
177
+ 'post_type' => 'wpcf7_contact_form' ) );
178
+
179
+ $cf = null;
180
+ $unsaved = false;
181
+
182
+ if ( ! isset( $_GET['contactform'] ) )
183
+ $_GET['contactform'] = '';
184
+
185
+ if ( 'new' == $_GET['contactform'] && wpcf7_admin_has_edit_cap() ) {
186
+ $unsaved = true;
187
+ $current = -1;
188
+ $cf = wpcf7_get_contact_form_default_pack(
189
+ array( 'locale' => ( isset( $_GET['locale'] ) ? $_GET['locale'] : '' ) ) );
190
+ } elseif ( $cf = wpcf7_contact_form( $_GET['contactform'] ) ) {
191
+ $current = (int) $_GET['contactform'];
192
+ } else {
193
+ $first = reset( $contact_forms ); // Returns first item
194
+
195
+ if ( $first ) {
196
+ $current = $first->ID;
197
+ $cf = wpcf7_contact_form( $current );
198
+ }
199
+ }
200
+
201
+ require_once WPCF7_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
202
+ require_once WPCF7_PLUGIN_DIR . '/admin/edit.php';
203
+ }
204
+
205
+ /* Misc */
206
+
207
+ add_filter( 'plugin_action_links', 'wpcf7_plugin_action_links', 10, 2 );
208
+
209
+ function wpcf7_plugin_action_links( $links, $file ) {
210
+ if ( $file != WPCF7_PLUGIN_BASENAME )
211
+ return $links;
212
+
213
+ $url = wpcf7_admin_url();
214
+
215
+ $settings_link = '<a href="' . esc_attr( $url ) . '">'
216
+ . esc_html( __( 'Settings', 'wpcf7' ) ) . '</a>';
217
+
218
+ array_unshift( $links, $settings_link );
219
+
220
+ return $links;
221
+ }
222
+
223
+ add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_cf7com_links', 9 );
224
+
225
+ function wpcf7_cf7com_links( &$contact_form ) {
226
+ $links = '<div class="cf7com-links">'
227
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/', 'wpcf7' ) ) . '" target="_blank">'
228
+ . esc_html( __( 'Contactform7.com', 'wpcf7' ) ) . '</a>&ensp;'
229
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/docs/', 'wpcf7' ) ) . '" target="_blank">'
230
+ . esc_html( __( 'Docs', 'wpcf7' ) ) . '</a> - '
231
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/faq/', 'wpcf7' ) ) . '" target="_blank">'
232
+ . esc_html( __( 'FAQ', 'wpcf7' ) ) . '</a> - '
233
+ . '<a href="' . esc_url_raw( __( 'http://contactform7.com/support/', 'wpcf7' ) ) . '" target="_blank">'
234
+ . esc_html( __( 'Support', 'wpcf7' ) ) . '</a>'
235
+ . '</div>';
236
+
237
+ echo apply_filters( 'wpcf7_cf7com_links', $links );
238
+ }
239
+
240
+ add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_updated_message' );
241
+
242
+ function wpcf7_updated_message( &$contact_form ) {
243
+ if ( ! isset( $_GET['message'] ) )
244
+ return;
245
+
246
+ switch ( $_GET['message'] ) {
247
+ case 'created':
248
+ $updated_message = __( "Contact form created.", 'wpcf7' );
249
+ break;
250
+ case 'saved':
251
+ $updated_message = __( "Contact form saved.", 'wpcf7' );
252
+ break;
253
+ case 'deleted':
254
+ $updated_message = __( "Contact form deleted.", 'wpcf7' );
255
+ break;
256
+ }
257
+
258
+ if ( ! $updated_message )
259
+ return;
260
+
261
+ ?>
262
+ <div id="message" class="updated"><p><?php echo esc_html( $updated_message ); ?></p></div>
263
+ <?php
264
+ }
265
+
266
+ add_action( 'wpcf7_admin_before_subsubsub', 'wpcf7_donation_link' );
267
+
268
+ function wpcf7_donation_link( &$contact_form ) {
269
+ if ( ! WPCF7_SHOW_DONATION_LINK )
270
+ return;
271
+
272
+ if ( 'new' == $_GET['contactform'] || ! empty( $_GET['message'] ) )
273
+ return;
274
+
275
+ $show_link = true;
276
+
277
+ $num = mt_rand( 0, 99 );
278
+
279
+ if ( $num >= 20 )
280
+ $show_link = false;
281
+
282
+ $show_link = apply_filters( 'wpcf7_show_donation_link', $show_link );
283
+
284
+ if ( ! $show_link )
285
+ return;
286
+
287
+ $texts = array(
288
+ __( "Contact Form 7 needs your support. Please donate today.", 'wpcf7' ),
289
+ __( "Your contribution is needed for making this plugin better.", 'wpcf7' ) );
290
+
291
+ $text = $texts[array_rand( $texts )];
292
+
293
+ ?>
294
+ <div class="donation">
295
+ <p><a href="<?php echo esc_url_raw( __( 'http://contactform7.com/donate/', 'wpcf7' ) ); ?>"><?php echo esc_html( $text ); ?></a> <a href="<?php echo esc_url_raw( __( 'http://contactform7.com/donate/', 'wpcf7' ) ); ?>" class="button"><?php echo esc_html( __( "Donate", 'wpcf7' ) ); ?></a></p>
296
+ </div>
297
+ <?php
298
+ }
299
+
300
+ add_action( 'admin_notices', 'wpcf7_old_wp_version_error', 9 );
301
+
302
+ function wpcf7_old_wp_version_error() {
303
+ global $plugin_page;
304
+
305
+ if ( 'wpcf7' != $plugin_page )
306
+ return;
307
+
308
+ $wp_version = get_bloginfo( 'version' );
309
+
310
+ if ( ! version_compare( $wp_version, WPCF7_REQUIRED_WP_VERSION, '<' ) )
311
+ return;
312
+
313
+ ?>
314
+ <div class="error">
315
+ <p><?php echo sprintf( __( '<strong>Contact Form 7 %1$s requires WordPress %2$s or higher.</strong> Please <a href="%3$s">update WordPress</a> first.', 'wpcf7' ), WPCF7_VERSION, WPCF7_REQUIRED_WP_VERSION, admin_url( 'update-core.php' ) ); ?></p>
316
+ </div>
317
+ <?php
318
+ }
319
+
320
?>
admin/edit.php CHANGED
@@ -1,159 +1,159 @@
1
- <div class="wrap">
2
-
3
- <?php screen_icon( 'edit-pages' ); ?>
4
-
5
- <h2><?php echo esc_html( __( 'Contact Form 7', 'wpcf7' ) ); ?></h2>
6
-
7
- <?php do_action_ref_array( 'wpcf7_admin_before_subsubsub', array( &$cf ) ); ?>
8
-
9
- <ul class="subsubsub">
10
- <?php
11
- $first = array_shift( $contact_forms );
12
- if ( ! is_null( $first ) ) : ?>
13
- <li><a href="<?php echo wpcf7_admin_url( array( 'contactform' => $first->ID ) ); ?>"<?php if ( $first->ID == $current ) echo ' class="current"'; ?>><?php echo esc_html( $first->post_title ); ?></a></li>
14
- <?php endif;
15
- foreach ( $contact_forms as $v ) : ?>
16
- <li>| <a href="<?php echo wpcf7_admin_url( array( 'contactform' => $v->ID ) ); ?>"<?php if ( $v->ID == $current ) echo ' class="current"'; ?>><?php echo esc_html( $v->post_title ); ?></a></li>
17
- <?php endforeach; ?>
18
-
19
- <?php if ( wpcf7_admin_has_edit_cap() ) : ?>
20
- <li class="addnew"><a class="button thickbox<?php if ( $unsaved ) echo ' current'; ?>" href="#TB_inline?height=300&width=400&inlineId=wpcf7-lang-select-modal"><?php echo esc_html( __( 'Add New', 'wpcf7' ) ); ?></a></li>
21
- <?php endif; ?>
22
- </ul>
23
-
24
- <br class="clear" />
25
-
26
- <?php if ( $cf ) : ?>
27
- <?php $disabled = ( wpcf7_admin_has_edit_cap() ) ? '' : ' disabled="disabled"'; ?>
28
-
29
- <form method="post" action="<?php echo wpcf7_admin_url( array( 'contactform' => $current ) ); ?>" id="wpcf7-admin-form-element"<?php do_action( 'wpcf7_post_edit_form_tag' ); ?>>
30
- <?php if ( wpcf7_admin_has_edit_cap() ) wp_nonce_field( 'wpcf7-save_' . $current ); ?>
31
- <input type="hidden" id="post_ID" name="post_ID" value="<?php echo (int) $current; ?>" />
32
- <input type="hidden" id="wpcf7-id" name="wpcf7-id" value="<?php echo (int) get_post_meta( $cf->id, '_old_cf7_unit_id', true ); ?>" />
33
-
34
- <div id="poststuff" class="metabox-holder">
35
-
36
- <div id="titlediv">
37
- <input type="text" id="wpcf7-title" name="wpcf7-title" size="40" value="<?php echo esc_attr( $cf->title ); ?>"<?php echo $disabled; ?> />
38
-
39
- <?php if ( ! $unsaved ) : ?>
40
- <p class="tagcode">
41
- <?php echo esc_html( __( "Copy this code and paste it into your post, page or text widget content.", 'wpcf7' ) ); ?><br />
42
-
43
- <input type="text" id="contact-form-anchor-text" onfocus="this.select();" readonly="readonly" />
44
- </p>
45
-
46
- <p class="tagcode" style="display: none;">
47
- <?php echo esc_html( __( "Old code is also available.", 'wpcf7' ) ); ?><br />
48
-
49
- <input type="text" id="contact-form-anchor-text-old" onfocus="this.select();" readonly="readonly" />
50
- </p>
51
- <?php endif; ?>
52
-
53
- <?php if ( wpcf7_admin_has_edit_cap() ) : ?>
54
- <div class="save-contact-form">
55
- <input type="submit" class="button" name="wpcf7-save" value="<?php echo esc_attr( __( 'Save', 'wpcf7' ) ); ?>" />
56
- </div>
57
- <?php endif; ?>
58
-
59
- <?php if ( wpcf7_admin_has_edit_cap() && ! $unsaved ) : ?>
60
- <div class="actions-link">
61
- <?php $copy_nonce = wp_create_nonce( 'wpcf7-copy_' . $current ); ?>
62
- <input type="submit" name="wpcf7-copy" class="copy" value="<?php echo esc_attr( __( 'Copy', 'wpcf7' ) ); ?>"
63
- <?php echo "onclick=\"this.form._wpnonce.value = '$copy_nonce'; return true;\""; ?> />
64
- |
65
-
66
- <?php $delete_nonce = wp_create_nonce( 'wpcf7-delete_' . $current ); ?>
67
- <input type="submit" name="wpcf7-delete" class="delete" value="<?php echo esc_attr( __( 'Delete', 'wpcf7' ) ); ?>"
68
- <?php echo "onclick=\"if (confirm('" .
69
- esc_js( __( "You are about to delete this contact form.\n 'Cancel' to stop, 'OK' to delete.", 'wpcf7' ) ) .
70
- "')) {this.form._wpnonce.value = '$delete_nonce'; return true;} return false;\""; ?> />
71
- </div>
72
- <?php endif; ?>
73
- </div>
74
-
75
- <?php
76
-
77
- if ( wpcf7_admin_has_edit_cap() ) {
78
- add_meta_box( 'formdiv', __( 'Form', 'wpcf7' ),
79
- 'wpcf7_form_meta_box', 'cfseven', 'form', 'core' );
80
-
81
- add_meta_box( 'maildiv', __( 'Mail', 'wpcf7' ),
82
- 'wpcf7_mail_meta_box', 'cfseven', 'mail', 'core' );
83
-
84
- add_meta_box( 'mail2div', __( 'Mail (2)', 'wpcf7' ),
85
- 'wpcf7_mail_meta_box', 'cfseven', 'mail_2', 'core',
86
- array(
87
- 'id' => 'wpcf7-mail-2',
88
- 'name' => 'mail_2',
89
- 'use' => __( 'Use mail (2)', 'wpcf7' ) ) );
90
-
91
- add_meta_box( 'messagesdiv', __( 'Messages', 'wpcf7' ),
92
- 'wpcf7_messages_meta_box', 'cfseven', 'messages', 'core' );
93
-
94
- add_meta_box( 'additionalsettingsdiv', __( 'Additional Settings', 'wpcf7' ),
95
- 'wpcf7_additional_settings_meta_box', 'cfseven', 'additional_settings', 'core' );
96
- }
97
-
98
- do_action_ref_array( 'wpcf7_admin_after_general_settings', array( &$cf ) );
99
-
100
- do_meta_boxes( 'cfseven', 'form', $cf );
101
-
102
- do_action_ref_array( 'wpcf7_admin_after_form', array( &$cf ) );
103
-
104
- do_meta_boxes( 'cfseven', 'mail', $cf );
105
-
106
- do_action_ref_array( 'wpcf7_admin_after_mail', array( &$cf ) );
107
-
108
- do_meta_boxes( 'cfseven', 'mail_2', $cf );
109
-
110
- do_action_ref_array( 'wpcf7_admin_after_mail_2', array( &$cf ) );
111
-
112
- do_meta_boxes( 'cfseven', 'messages', $cf );
113
-
114
- do_action_ref_array( 'wpcf7_admin_after_messages', array( &$cf ) );
115
-
116
- do_meta_boxes( 'cfseven', 'additional_settings', $cf );
117
-
118
- do_action_ref_array( 'wpcf7_admin_after_additional_settings', array( &$cf ) );
119
-
120
- wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
121
- wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
122
-
123
- ?>
124
- </div>
125
-
126
- </form>
127
-
128
- <?php endif; ?>
129
-
130
- </div>
131
-
132
- <div id="wpcf7-lang-select-modal" class="hidden">
133
- <?php
134
- $available_locales = wpcf7_l10n();
135
- $default_locale = get_locale();
136
-
137
- if ( ! isset( $available_locales[$default_locale] ) )
138
- $default_locale = 'en_US';
139
-
140
- ?>
141
- <h4><?php echo esc_html( sprintf( __( 'Use the default language (%s)', 'wpcf7' ), $available_locales[$default_locale] ) ); ?></h4>
142
- <p><a href="<?php echo wpcf7_admin_url( array( 'contactform' => 'new' ) ); ?>" class="button" /><?php echo esc_html( __( 'Add New', 'wpcf7' ) ); ?></a></p>
143
-
144
- <?php unset( $available_locales[$default_locale] ); ?>
145
- <h4><?php echo esc_html( __( 'Or', 'wpcf7' ) ); ?></h4>
146
- <form action="" method="get">
147
- <input type="hidden" name="page" value="wpcf7" />
148
- <input type="hidden" name="contactform" value="new" />
149
- <select name="locale">
150
- <option value="" selected="selected"><?php echo esc_html( __( '(select language)', 'wpcf7' ) ); ?></option>
151
- <?php foreach ( $available_locales as $code => $locale ) : ?>
152
- <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $locale ); ?></option>
153
- <?php endforeach; ?>
154
- </select>
155
- <input type="submit" class="button" value="<?php echo esc_attr( __( 'Add New', 'wpcf7' ) ); ?>" />
156
- </form>
157
- </div>
158
-
159
- <?php do_action_ref_array( 'wpcf7_admin_footer', array( &$cf ) ); ?>
1
+ <div class="wrap">
2
+
3
+ <?php screen_icon(); ?>
4
+
5
+ <h2><?php echo esc_html( __( 'Contact Form 7', 'wpcf7' ) ); ?></h2>
6
+
7
+ <?php do_action_ref_array( 'wpcf7_admin_before_subsubsub', array( &$cf ) ); ?>
8
+
9
+ <ul class="subsubsub">
10
+ <?php
11
+ $first = array_shift( $contact_forms );
12
+ if ( ! is_null( $first ) ) : ?>
13
+ <li><a href="<?php echo wpcf7_admin_url( array( 'contactform' => $first->ID ) ); ?>"<?php if ( $first->ID == $current ) echo ' class="current"'; ?>><?php echo esc_html( $first->post_title ); ?></a></li>
14
+ <?php endif;
15
+ foreach ( $contact_forms as $v ) : ?>
16
+ <li>| <a href="<?php echo wpcf7_admin_url( array( 'contactform' => $v->ID ) ); ?>"<?php if ( $v->ID == $current ) echo ' class="current"'; ?>><?php echo esc_html( $v->post_title ); ?></a></li>
17
+ <?php endforeach; ?>
18
+
19
+ <?php if ( wpcf7_admin_has_edit_cap() ) : ?>
20
+ <li class="addnew"><a class="button thickbox<?php if ( $unsaved ) echo ' current'; ?>" href="#TB_inline?height=300&width=400&inlineId=wpcf7-lang-select-modal"><?php echo esc_html( __( 'Add New', 'wpcf7' ) ); ?></a></li>
21
+ <?php endif; ?>
22
+ </ul>
23
+
24
+ <br class="clear" />
25
+
26
+ <?php if ( $cf ) : ?>
27
+ <?php $disabled = ( wpcf7_admin_has_edit_cap() ) ? '' : ' disabled="disabled"'; ?>
28
+
29
+ <form method="post" action="<?php echo wpcf7_admin_url( array( 'contactform' => $current ) ); ?>" id="wpcf7-admin-form-element"<?php do_action( 'wpcf7_post_edit_form_tag' ); ?>>
30
+ <?php if ( wpcf7_admin_has_edit_cap() ) wp_nonce_field( 'wpcf7-save_' . $current ); ?>
31
+ <input type="hidden" id="post_ID" name="post_ID" value="<?php echo (int) $current; ?>" />
32
+ <input type="hidden" id="wpcf7-id" name="wpcf7-id" value="<?php echo (int) get_post_meta( $cf->id, '_old_cf7_unit_id', true ); ?>" />
33
+
34
+ <div id="poststuff" class="metabox-holder">
35
+
36
+ <div id="titlediv">
37
+ <input type="text" id="wpcf7-title" name="wpcf7-title" size="40" value="<?php echo esc_attr( $cf->title ); ?>"<?php echo $disabled; ?> />
38
+
39
+ <?php if ( ! $unsaved ) : ?>
40
+ <p class="tagcode">
41
+ <?php echo esc_html( __( "Copy this code and paste it into your post, page or text widget content.", 'wpcf7' ) ); ?><br />
42
+
43
+ <input type="text" id="contact-form-anchor-text" onfocus="this.select();" readonly="readonly" />
44
+ </p>
45
+
46
+ <p class="tagcode" style="display: none;">
47
+ <?php echo esc_html( __( "Old code is also available.", 'wpcf7' ) ); ?><br />
48
+
49
+ <input type="text" id="contact-form-anchor-text-old" onfocus="this.select();" readonly="readonly" />
50
+ </p>
51
+ <?php endif; ?>
52
+
53
+ <?php if ( wpcf7_admin_has_edit_cap() ) : ?>
54
+ <div class="save-contact-form">
55
+ <input type="submit" class="button" name="wpcf7-save" value="<?php echo esc_attr( __( 'Save', 'wpcf7' ) ); ?>" />
56
+ </div>
57
+ <?php endif; ?>
58
+
59
+ <?php if ( wpcf7_admin_has_edit_cap() && ! $unsaved ) : ?>
60
+ <div class="actions-link">
61
+ <?php $copy_nonce = wp_create_nonce( 'wpcf7-copy_' . $current ); ?>
62
+ <input type="submit" name="wpcf7-copy" class="copy" value="<?php echo esc_attr( __( 'Copy', 'wpcf7' ) ); ?>"
63
+ <?php echo "onclick=\"this.form._wpnonce.value = '$copy_nonce'; return true;\""; ?> />
64
+ |
65
+
66
+ <?php $delete_nonce = wp_create_nonce( 'wpcf7-delete_' . $current ); ?>
67
+ <input type="submit" name="wpcf7-delete" class="delete" value="<?php echo esc_attr( __( 'Delete', 'wpcf7' ) ); ?>"
68
+ <?php echo "onclick=\"if (confirm('" .
69
+ esc_js( __( "You are about to delete this contact form.\n 'Cancel' to stop, 'OK' to delete.", 'wpcf7' ) ) .
70
+ "')) {this.form._wpnonce.value = '$delete_nonce'; return true;} return false;\""; ?> />
71
+ </div>
72
+ <?php endif; ?>
73
+ </div>
74
+
75
+ <?php
76
+
77
+ if ( wpcf7_admin_has_edit_cap() ) {
78
+ add_meta_box( 'formdiv', __( 'Form', 'wpcf7' ),
79
+ 'wpcf7_form_meta_box', 'cfseven', 'form', 'core' );
80
+
81
+ add_meta_box( 'maildiv', __( 'Mail', 'wpcf7' ),
82
+ 'wpcf7_mail_meta_box', 'cfseven', 'mail', 'core' );
83
+
84
+ add_meta_box( 'mail2div', __( 'Mail (2)', 'wpcf7' ),
85
+ 'wpcf7_mail_meta_box', 'cfseven', 'mail_2', 'core',
86
+ array(
87
+ 'id' => 'wpcf7-mail-2',
88
+ 'name' => 'mail_2',
89
+ 'use' => __( 'Use mail (2)', 'wpcf7' ) ) );
90
+
91
+ add_meta_box( 'messagesdiv', __( 'Messages', 'wpcf7' ),
92
+ 'wpcf7_messages_meta_box', 'cfseven', 'messages', 'core' );
93
+
94
+ add_meta_box( 'additionalsettingsdiv', __( 'Additional Settings', 'wpcf7' ),
95
+ 'wpcf7_additional_settings_meta_box', 'cfseven', 'additional_settings', 'core' );
96
+ }
97
+
98
+ do_action_ref_array( 'wpcf7_admin_after_general_settings', array( &$cf ) );
99
+
100
+ do_meta_boxes( 'cfseven', 'form', $cf );
101
+
102
+ do_action_ref_array( 'wpcf7_admin_after_form', array( &$cf ) );
103
+
104
+ do_meta_boxes( 'cfseven', 'mail', $cf );
105
+
106
+ do_action_ref_array( 'wpcf7_admin_after_mail', array( &$cf ) );
107
+
108
+ do_meta_boxes( 'cfseven', 'mail_2', $cf );
109
+
110
+ do_action_ref_array( 'wpcf7_admin_after_mail_2', array( &$cf ) );
111
+
112
+ do_meta_boxes( 'cfseven', 'messages', $cf );
113
+
114
+ do_action_ref_array( 'wpcf7_admin_after_messages', array( &$cf ) );
115
+
116
+ do_meta_boxes( 'cfseven', 'additional_settings', $cf );
117
+
118
+ do_action_ref_array( 'wpcf7_admin_after_additional_settings', array( &$cf ) );
119
+
120
+ wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
121
+ wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
122
+
123
+ ?>
124
+ </div>
125
+
126
+ </form>
127
+
128
+ <?php endif; ?>
129
+
130
+ </div>
131
+
132
+ <div id="wpcf7-lang-select-modal" class="hidden">
133
+ <?php
134
+ $available_locales = wpcf7_l10n();
135
+ $default_locale = get_locale();
136
+
137
+ if ( ! isset( $available_locales[$default_locale] ) )
138
+ $default_locale = 'en_US';
139
+
140
+ ?>
141
+ <h4><?php echo esc_html( sprintf( __( 'Use the default language (%s)', 'wpcf7' ), $available_locales[$default_locale] ) ); ?></h4>
142
+ <p><a href="<?php echo wpcf7_admin_url( array( 'contactform' => 'new' ) ); ?>" class="button" /><?php echo esc_html( __( 'Add New', 'wpcf7' ) ); ?></a></p>
143
+
144
+ <?php unset( $available_locales[$default_locale] ); ?>
145
+ <h4><?php echo esc_html( __( 'Or', 'wpcf7' ) ); ?></h4>
146
+ <form action="" method="get">
147
+ <input type="hidden" name="page" value="wpcf7" />
148
+ <input type="hidden" name="contactform" value="new" />
149
+ <select name="locale">
150
+ <option value="" selected="selected"><?php echo esc_html( __( '(select language)', 'wpcf7' ) ); ?></option>
151
+ <?php foreach ( $available_locales as $code => $locale ) : ?>
152
+ <option value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $locale ); ?></option>
153
+ <?php endforeach; ?>
154
+ </select>
155
+ <input type="submit" class="button" value="<?php echo esc_attr( __( 'Add New', 'wpcf7' ) ); ?>" />
156
+ </form>
157
+ </div>
158
+
159
+ <?php do_action_ref_array( 'wpcf7_admin_footer', array( &$cf ) ); ?>
{images → admin/images}/dropdown.gif RENAMED
File without changes
admin/images/menu-icon.png ADDED
Binary file
admin/images/screen-icon.png ADDED
Binary file
admin/scripts.js CHANGED
@@ -1,75 +1,75 @@
1
- (function($) {
2
-
3
- $(function() {
4
- try {
5
- $('div.cf7com-links').insertAfter($('div.wrap h2:first'));
6
-
7
- $.extend($.tgPanes, _wpcf7.tagGenerators);
8
- $('#taggenerator').tagGenerator(_wpcf7L10n.generateTag,
9
- { dropdownIconUrl: _wpcf7.pluginUrl + '/images/dropdown.gif' });
10
-
11
- $('input#wpcf7-title:disabled').css({cursor: 'default'});
12
-
13
- $('input#wpcf7-title').mouseover(function() {
14
- $(this).not('.focus').addClass('mouseover');
15
- });
16
-
17
- $('input#wpcf7-title').mouseout(function() {
18
- $(this).removeClass('mouseover');
19
- });
20
-
21
- $('input#wpcf7-title').focus(function() {
22
- $(this).addClass('focus').removeClass('mouseover');
23
- });
24
-
25
- $('input#wpcf7-title').blur(function() {
26
- $(this).removeClass('focus');
27
- });
28
-
29
- $('input#wpcf7-title').change(function() {
30
- updateTag();
31
- });
32
-
33
- updateTag();
34
-
35
- $('.check-if-these-fields-are-active').each(function(index) {
36
- if (! $(this).is(':checked'))
37
- $(this).parent().siblings('.mail-fields').hide();
38
-
39
- $(this).click(function() {
40
- if ($(this).parent().siblings('.mail-fields').is(':hidden')
41
- && $(this).is(':checked')) {
42
- $(this).parent().siblings('.mail-fields').slideDown('fast');
43
- } else if ($(this).parent().siblings('.mail-fields').is(':visible')
44
- && $(this).not(':checked')) {
45
- $(this).parent().siblings('.mail-fields').slideUp('fast');
46
- }
47
- });
48
- });
49
-
50
- postboxes.add_postbox_toggles('cfseven');
51
-
52
- } catch (e) {
53
- }
54
- });
55
-
56
- function updateTag() {
57
- var title = $('input#wpcf7-title').val();
58
-
59
- if (title)
60
- title = title.replace(/["'\[\]]/g, '');
61
-
62
- $('input#wpcf7-title').val(title);
63
- var postId = $('input#post_ID').val();
64
- var tag = '[contact-form-7 id="' + postId + '" title="' + title + '"]';
65
- $('input#contact-form-anchor-text').val(tag);
66
-
67
- var oldId = $('input#wpcf7-id').val();
68
-
69
- if (0 != oldId) {
70
- var tagOld = '[contact-form ' + oldId + ' "' + title + '"]';
71
- $('input#contact-form-anchor-text-old').val(tagOld).parent('p.tagcode').show();
72
- }
73
- }
74
-
75
})(jQuery);
1
+ (function($) {
2
+
3
+ $(function() {
4
+ try {
5
+ $('div.cf7com-links').insertAfter($('div.wrap h2:first'));
6
+
7
+ $.extend($.tgPanes, _wpcf7.tagGenerators);
8
+ $('#taggenerator').tagGenerator(_wpcf7.generateTag,
9
+ { dropdownIconUrl: _wpcf7.pluginUrl + '/admin/images/dropdown.gif' });
10
+
11
+ $('input#wpcf7-title:disabled').css({cursor: 'default'});
12
+
13
+ $('input#wpcf7-title').mouseover(function() {
14
+ $(this).not('.focus').addClass('mouseover');
15
+ });
16
+
17
+ $('input#wpcf7-title').mouseout(function() {
18
+ $(this).removeClass('mouseover');
19
+ });
20
+
21
+ $('input#wpcf7-title').focus(function() {
22
+ $(this).addClass('focus').removeClass('mouseover');
23
+ });
24
+
25
+ $('input#wpcf7-title').blur(function() {
26
+ $(this).removeClass('focus');
27
+ });
28
+
29
+ $('input#wpcf7-title').change(function() {
30
+ updateTag();
31
+ });
32
+
33
+ updateTag();
34
+
35
+ $('.check-if-these-fields-are-active').each(function(index) {
36
+ if (! $(this).is(':checked'))
37
+ $(this).parent().siblings('.mail-fields').hide();
38
+
39
+ $(this).click(function() {
40
+ if ($(this).parent().siblings('.mail-fields').is(':hidden')
41
+ && $(this).is(':checked')) {
42
+ $(this).parent().siblings('.mail-fields').slideDown('fast');
43
+ } else if ($(this).parent().siblings('.mail-fields').is(':visible')
44
+ && $(this).not(':checked')) {
45
+ $(this).parent().siblings('.mail-fields').slideUp('fast');
46
+ }
47
+ });
48
+ });
49
+
50
+ postboxes.add_postbox_toggles('cfseven');
51
+
52
+ } catch (e) {
53
+ }
54
+ });
55
+
56
+ function updateTag() {
57
+ var title = $('input#wpcf7-title').val();
58
+
59
+ if (title)
60
+ title = title.replace(/["'\[\]]/g, '');
61
+
62
+ $('input#wpcf7-title').val(title);
63
+ var postId = $('input#post_ID').val();
64
+ var tag = '[contact-form-7 id="' + postId + '" title="' + title + '"]';
65
+ $('input#contact-form-anchor-text').val(tag);
66
+
67
+ var oldId = $('input#wpcf7-id').val();
68
+
69
+ if (0 != oldId) {
70
+ var tagOld = '[contact-form ' + oldId + ' "' + title + '"]';
71
+ $('input#contact-form-anchor-text-old').val(tagOld).parent('p.tagcode').show();
72
+ }
73
+ }
74
+
75
})(jQuery);
admin/styles-rtl.css CHANGED
@@ -1,18 +1,18 @@
1
- ul.subsubsub li.addnew {
2
- margin-left: 0;
3
- margin-right: 0.5em;
4
- }
5
- div.save-contact-form {
6
- direction: rtl;
7
- }
8
- div.actions-link {
9
- right: auto;
10
- left: 0;
11
- }
12
- div.tg-pane table caption {
13
- text-align: right;
14
- }
15
- div.tg-dropdown {
16
- left: auto;
17
- right: 0;
18
}
1
+ ul.subsubsub li.addnew {
2
+ margin-left: 0;
3
+ margin-right: 0.5em;
4
+ }
5
+ div.save-contact-form {
6
+ direction: rtl;
7
+ }
8
+ div.actions-link {
9
+ right: auto;
10
+ left: 0;
11
+ }
12
+ div.tg-pane table caption {
13
+ text-align: right;
14
+ }
15
+ div.tg-dropdown {
16
+ left: auto;
17
+ right: 0;
18
}
admin/styles.css CHANGED
@@ -1,271 +1,275 @@
1
- div.wrap div.cf7com-links {
2
- text-align: right;
3
- font-size: .9em;
4
- margin-top: -1.6em;
5
- }
6
-
7
- div.wrap div.cf7com-links a {
8
- text-decoration: none;
9
- }
10
-
11
- div.wrap div.donation {
12
- border-width: 1px;
13
- border-style: solid;
14
- padding: 0 0.6em;
15
- margin: 5px 0 15px;
16
- -webkit-border-radius: 3px;
17
- border-radius: 3px;
18
- background-color: #ffffe0;
19
- border-color: #e6db55;
20
- text-align: center;
21
- }
22
-
23
- div.wrap div.donation p {
24
- margin: .7em 0;
25
- line-height: 1;
26
- padding: 2px;
27
- font-size: 107%;
28
- }
29
-
30
- div.wrap div.donation p a {
31
- font-weight: bold;
32
- color: #3f3f3f;
33
- }
34
-
35
- div.wrap div.donation p a.button {
36
- margin-left: 1em;
37
- }
38
-
39
- div.wrap ul.subsubsub {
40
- white-space: normal;
41
- }
42
-
43
- ul.subsubsub li.addnew {
44
- margin-left: 0.5em;
45
- }
46
-
47
- ul.subsubsub li.addnew a {
48
- color: #e6255b;
49
- }
50
-
51
- ul.subsubsub li.addnew a.current {
52
- border: 1px solid #bbb;
53
- }
54
-
55
- ul.subsubsub li.addnew a:hover,
56
- ul.subsubsub li.addnew a:active {
57
- color: #999;
58
- }
59
-
60
- #titlediv {
61
- margin-bottom: 20px;
62
- position: relative;
63
- border: 1px solid #c7c7c7;
64
- padding: 6px;
65
- }
66
-
67
- div.save-contact-form {
68
- padding: 1.4em 0 0 0;
69
- text-align: right;
70
- }
71
-
72
- div.actions-link {
73
- position: absolute;
74
- top: 0;
75
- right: 0;
76
- margin: 0;
77
- padding: 6px;
78
- }
79
-
80
- div.actions-link input {
81
- padding: 0;
82
- margin: 0;
83
- border: none;
84
- font-size: 11px;
85
- cursor: pointer;
86
- }
87
-
88
- div.actions-link input.copy {
89
- color: #006505;
90
- }
91
-
92
- div.actions-link input.delete {
93
- color: #bc0b0b;
94
- }
95
-
96
- input#wpcf7-title {
97
- color: #555;
98
- border: none;
99
- font: bold 20px serif;
100
- cursor: pointer;
101
- background-color: transparent;
102
- }
103
-
104
- input#wpcf7-title.focus {
105
- color: #333;
106
- border: 1px solid #777;
107
- font: normal 13px Verdana, Arial, Helvetica, sans-serif;
108
- cursor: text;
109
- background-color: transparent;
110
- }
111
-
112
- input#wpcf7-title.mouseover {
113
- background-color: #ffffdd;
114
- }
115
-
116
- p.tagcode {
117
- color: #333;
118
- margin: 2ex 0 1ex 0;
119
- }
120
-
121
- input#contact-form-anchor-text, input#contact-form-anchor-text-old {
122
- color: #fff;
123
- background: #7e4e0b;
124
- border: none;
125
- width: 100%;
126
- -webkit-border-radius: 6px;
127
- border-radius: 6px;
128
- }
129
-
130
- .postbox .half, .postbox .half-left, .postbox .half-right {
131
- float: left;
132
- width: 50%;
133
- }
134
-
135
- .postbox .half-right > * {
136
- margin-left: 10px;
137
- }
138
-
139
- .postbox .mail-field, .postbox .message-field {
140
- margin-top: 6px;
141
- margin-bottom: 8px;
142
- }
143
-
144
- .postbox .mail-field label, .postbox .message-field label {
145
- line-height: 1.4em;
146
- }
147
-
148
- div.pseudo-hr {
149
- border-bottom: 1px solid transparent;
150
- margin: 8px 0;
151
- }
152
-
153
- input, textarea {
154
- border: 1px solid #dfdfdf;
155
- }
156
-
157
- input.wide {
158
- width: 100%;
159
- }
160
-
161
- textarea {
162
- width: 100%;
163
- }
164
-
165
- label.disabled {
166
- color: #777;
167
- }
168
-
169
- div.tag-generator {
170
- position: relative;
171
- background: transparent;
172
- padding: 0 0 5px 1px;
173
- }
174
-
175
- div.tg-pane {
176
- border: 1px dashed #999;
177
- background: #f1f1f1;
178
- margin: 1ex 0 0 0;
179
- padding: 10px;
180
- -webkit-border-radius: 6px;
181
- border-radius: 6px;
182
- line-height: 140%;
183
- }
184
-
185
- div.tg-pane table {
186
- width: 100%;
187
- margin: 0 0 0.7em 0;
188
- }
189
-
190
- div.tg-pane table caption {
191
- text-align: left;
192
- padding: 0 0 0.2em 0;
193
- font-weight: bolder;
194
- color: #777;
195
- }
196
-
197
- div.tg-pane table code {
198
- background-color: inherit;
199
- }
200
-
201
- div.tg-pane table td {
202
- vertical-align: top;
203
- width: 50%;
204
- border: none;
205
- padding: 2px 0;
206
- }
207
-
208
- div.tg-pane input.tag, div.tg-pane input.mail-tag {
209
- width: 100%;
210
- border: none;
211
- color: #fff;
212
- background-color: #7e4e0b;
213
- -webkit-border-radius: 6px;
214
- border-radius: 6px;
215
- }
216
-
217
- div.tg-pane input.mail-tag {
218
- width: 50%;
219
- background-color: #404f03;
220
- }
221
-
222
- div.tg-mail-tag {
223
- margin-top: 2.4em;
224
- text-align: right;
225
- }
226
-
227
- div.tg-pane span.arrow {
228
- font-family: monospace;
229
- font-size: 1.2em;
230
- color: #333;
231
- }
232
-
233
- div.tg-pane input.tg-name {
234
- border-color: #555;
235
- }
236
-
237
- div.tg-pane input.oneline {
238
- width: 98%;
239
- font-size: smaller;
240
- }
241
-
242
- div.tg-pane textarea {
243
- width: 98%;
244
- height: 100px;
245
- font-size: smaller;
246
- }
247
-
248
- div.tg-pane div.tg-tag {
249
- margin: .4em 0;
250
- }
251
-
252
- div.tg-dropdown {
253
- position: absolute;
254
- top: 26px;
255
- left: 0;
256
- z-index: 10;
257
- border: 1px solid #ddd;
258
- }
259
-
260
- span.tg-closebutton {
261
- color: #777;
262
- font: bold 18px monospace;
263
- padding: 1px 4px;
264
- cursor: pointer;
265
- }
266
-
267
- div.tg-panetitle {
268
- font: bold 132% sans-serif;
269
- margin: 0 0 10px;
270
- color: #777;
271
}
1
+ #icon-wpcf7 {
2
+ background: transparent url(./images/screen-icon.png) no-repeat 2px 1px;
3
+ }
4
+
5
+ div.wrap div.cf7com-links {
6
+ text-align: right;
7
+ font-size: .9em;
8
+ margin-top: -1.6em;
9
+ }
10
+
11
+ div.wrap div.cf7com-links a {
12
+ text-decoration: none;
13
+ }
14
+
15
+ div.wrap div.donation {
16
+ border-width: 1px;
17
+ border-style: solid;
18
+ padding: 0 0.6em;
19
+ margin: 5px 0 15px;
20
+ -webkit-border-radius: 3px;
21
+ border-radius: 3px;
22
+ background-color: #ffffe0;
23
+ border-color: #e6db55;
24
+ text-align: center;
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
+ font-weight: bold;
36
+ color: #3f3f3f;
37
+ }
38
+
39
+ div.wrap div.donation p a.button {
40
+ margin-left: 1em;
41
+ }
42
+
43
+ div.wrap ul.subsubsub {
44
+ white-space: normal;
45
+ }
46
+
47
+ ul.subsubsub li.addnew {
48
+ margin-left: 0.5em;
49
+ }
50
+
51
+ ul.subsubsub li.addnew a {
52
+ color: #e6255b;
53
+ }
54
+
55
+ ul.subsubsub li.addnew a.current {
56
+ border: 1px solid #bbb;
57
+ }
58
+
59
+ ul.subsubsub li.addnew a:hover,
60
+ ul.subsubsub li.addnew a:active {
61
+ color: #999;
62
+ }
63
+
64
+ #titlediv {
65
+ margin-bottom: 20px;
66
+ position: relative;
67
+ border: 1px solid #c7c7c7;
68
+ padding: 6px;
69
+ }
70
+
71
+ div.save-contact-form {
72
+ padding: 1.4em 0 0 0;
73
+ text-align: right;
74
+ }
75
+
76
+ div.actions-link {
77
+ position: absolute;
78
+ top: 0;
79
+ right: 0;
80
+ margin: 0;
81
+ padding: 6px;
82
+ }
83
+
84
+ div.actions-link input {
85
+ padding: 0;
86
+ margin: 0;
87
+ border: none;
88
+ font-size: 11px;
89
+ cursor: pointer;
90
+ }
91
+
92
+ div.actions-link input.copy {
93
+ color: #006505;
94
+ }
95
+
96
+ div.actions-link input.delete {
97
+ color: #bc0b0b;
98
+ }
99
+
100
+ input#wpcf7-title {
101
+ color: #555;
102
+ border: none;
103
+ font: bold 20px serif;
104
+ cursor: pointer;
105
+ background-color: transparent;
106
+ }
107
+
108
+ input#wpcf7-title.focus {
109
+ color: #333;
110
+ border: 1px solid #777;
111
+ font: normal 13px Verdana, Arial, Helvetica, sans-serif;
112
+ cursor: text;
113
+ background-color: transparent;
114
+ }
115
+
116
+ input#wpcf7-title.mouseover {
117
+ background-color: #ffffdd;
118
+ }
119
+
120
+ p.tagcode {
121
+ color: #333;
122
+ margin: 2ex 0 1ex 0;
123
+ }
124
+
125
+ input#contact-form-anchor-text, input#contact-form-anchor-text-old {
126
+ color: #fff;
127
+ background: #7e4e0b;
128
+ border: none;
129
+ width: 100%;
130
+ -webkit-border-radius: 6px;
131
+ border-radius: 6px;
132
+ }
133
+
134
+ .postbox .half, .postbox .half-left, .postbox .half-right {
135
+ float: left;
136
+ width: 50%;
137
+ }
138
+
139
+ .postbox .half-right > * {
140
+ margin-left: 10px;
141
+ }
142
+
143
+ .postbox .mail-field, .postbox .message-field {
144
+ margin-top: 6px;
145
+ margin-bottom: 8px;
146
+ }
147
+
148
+ .postbox .mail-field label, .postbox .message-field label {
149
+ line-height: 1.4em;
150
+ }
151
+
152
+ div.pseudo-hr {
153
+ border-bottom: 1px solid transparent;
154
+ margin: 8px 0;
155
+ }
156
+
157
+ input, textarea {
158
+ border: 1px solid #dfdfdf;
159
+ }
160
+
161
+ input.wide {
162
+ width: 100%;
163
+ }
164
+
165
+ textarea {
166
+ width: 100%;
167
+ }
168
+
169
+ label.disabled {
170
+ color: #777;
171
+ }
172
+
173
+ div.tag-generator {
174
+ position: relative;
175
+ background: transparent;
176
+ padding: 0 0 5px 1px;
177
+ }
178
+
179
+ div.tg-pane {
180
+ border: 1px dashed #999;
181
+ background: #f1f1f1;
182
+ margin: 1ex 0 0 0;
183
+ padding: 10px;
184
+ -webkit-border-radius: 6px;
185
+ border-radius: 6px;
186
+ line-height: 140%;
187
+ }
188
+
189
+ div.tg-pane table {
190
+ width: 100%;
191
+ margin: 0 0 0.7em 0;
192
+ }
193
+
194
+ div.tg-pane table caption {
195
+ text-align: left;
196
+ padding: 0 0 0.2em 0;
197
+ font-weight: bolder;
198
+ color: #777;
199
+ }
200
+
201
+ div.tg-pane table code {
202
+ background-color: inherit;
203
+ }
204
+
205
+ div.tg-pane table td {
206
+ vertical-align: top;
207
+ width: 50%;
208
+ border: none;
209
+ padding: 2px 0;
210
+ }
211
+
212
+ div.tg-pane input.tag, div.tg-pane input.mail-tag {
213
+ width: 100%;
214
+ border: none;
215
+ color: #fff;
216
+ background-color: #7e4e0b;
217
+ -webkit-border-radius: 6px;
218
+ border-radius: 6px;
219
+ }
220
+
221
+ div.tg-pane input.mail-tag {
222
+ width: 50%;
223
+ background-color: #404f03;
224
+ }
225
+
226
+ div.tg-mail-tag {
227
+ margin-top: 2.4em;
228
+ text-align: right;
229
+ }
230
+
231
+ div.tg-pane span.arrow {
232
+ font-family: monospace;
233
+ font-size: 1.2em;
234
+ color: #333;
235
+ }
236
+
237
+ div.tg-pane input.tg-name {
238
+ border-color: #555;
239
+ }
240
+
241
+ div.tg-pane input.oneline {
242
+ width: 98%;
243
+ font-size: smaller;
244
+ }
245
+
246
+ div.tg-pane textarea {
247
+ width: 98%;
248
+ height: 100px;
249
+ font-size: smaller;
250
+ }
251
+
252
+ div.tg-pane div.tg-tag {
253
+ margin: .4em 0;
254
+ }
255
+
256
+ div.tg-dropdown {
257
+ position: absolute;
258
+ top: 26px;
259
+ left: 0;
260
+ z-index: 10;
261
+ border: 1px solid #ddd;
262
+ }
263
+
264
+ span.tg-closebutton {
265
+ color: #777;
266
+ font: bold 18px monospace;
267
+ padding: 1px 4px;
268
+ cursor: pointer;
269
+ }
270
+
271
+ div.tg-panetitle {
272
+ font: bold 132% sans-serif;
273
+ margin: 0 0 10px;
274
+ color: #777;
275
}
includes/classes.php CHANGED
@@ -1,577 +1,733 @@
1
- <?php
2
-
3
- class WPCF7_ContactForm {
4
-
5
- var $initial = false;
6
-
7
- var $id;
8
- var $title;
9
-
10
- var $unit_tag;
11
-
12
- var $responses_count = 0;
13
- var $scanned_form_tags;
14
-
15
- var $posted_data;
16
- var $uploaded_files = array();
17
-
18
- var $skip_mail = false;
19
-
20
- // Return true if this form is the same one as currently POSTed.
21
- function is_posted() {
22
- if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
23
- return false;
24
-
25
- if ( $this->unit_tag == $_POST['_wpcf7_unit_tag'] )
26
- return true;
27
-
28
- return false;
29
- }
30
-
31
- function clear_post() {
32
- $fes = $this->form_scan_shortcode();
33
-
34
- foreach ( $fes as $fe ) {
35
- if ( ! isset( $fe['name'] ) || empty( $fe['name'] ) )
36
- continue;
37
-
38
- $name = $fe['name'];
39
-
40
- if ( isset( $_POST[$name] ) )
41
- unset( $_POST[$name] );
42
- }
43
- }
44
-
45
- /* Generating Form HTML */
46
-
47
- function form_html() {
48
- $form = '<div class="wpcf7" id="' . $this->unit_tag . '">';
49
-
50
- $url = wpcf7_get_request_uri();
51
-
52
- if ( $frag = strstr( $url, '#' ) )
53
- $url = substr( $url, 0, -strlen( $frag ) );
54
-
55
- $url .= '#' . $this->unit_tag;
56
-
57
- $url = apply_filters( 'wpcf7_form_action_url', $url );
58
- $enctype = apply_filters( 'wpcf7_form_enctype', '' );
59
- $class = apply_filters( 'wpcf7_form_class_attr', 'wpcf7-form' );
60
-
61
- $form .= '<form action="' . esc_url_raw( $url ) . '" method="post"'
62
- . ' class="' . esc_attr( $class ) . '"' . $enctype . '>' . "\n";
63
- $form .= '<div style="display: none;">' . "\n";
64
- $form .= '<input type="hidden" name="_wpcf7" value="'
65
- . esc_attr( $this->id ) . '" />' . "\n";
66
- $form .= '<input type="hidden" name="_wpcf7_version" value="'
67
- . esc_attr( WPCF7_VERSION ) . '" />' . "\n";
68
- $form .= '<input type="hidden" name="_wpcf7_unit_tag" value="'
69
- . esc_attr( $this->unit_tag ) . '" />' . "\n";
70
- $form .= '</div>' . "\n";
71
- $form .= $this->form_elements();
72
-
73
- if ( ! $this->responses_count )
74
- $form .= $this->form_response_output();
75
-
76
- $form .= '</form>';
77
-
78
- $form .= '</div>';
79
-
80
- return $form;
81
- }
82
-
83
- function form_response_output() {
84
- $class = 'wpcf7-response-output';
85
- $content = '';
86
-
87
- if ( $this->is_posted() ) { // Post response output for non-AJAX
88
- if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['id'] == $this->id ) {
89
- if ( $_POST['_wpcf7_mail_sent']['ok'] ) {
90
- $class .= ' wpcf7-mail-sent-ok';
91
- $content = $_POST['_wpcf7_mail_sent']['message'];
92
- } else {
93
- $class .= ' wpcf7-mail-sent-ng';
94
- if ( $_POST['_wpcf7_mail_sent']['spam'] )
95
- $class .= ' wpcf7-spam-blocked';
96
- $content = $_POST['_wpcf7_mail_sent']['message'];
97
- }
98
- } elseif ( isset( $_POST['_wpcf7_validation_errors'] ) && $_POST['_wpcf7_validation_errors']['id'] == $this->id ) {
99
- $class .= ' wpcf7-validation-errors';
100
- $content = $this->message( 'validation_error' );
101
- }
102
- } else {
103
- $class .= ' wpcf7-display-none';
104
- }
105
-
106
- $class = ' class="' . $class . '"';
107
-
108
- return '<div' . $class . '>' . $content . '</div>';
109
- }
110
-
111
- function validation_error( $name ) {
112
- if ( ! $this->is_posted() )
113
- return '';
114
-
115
- if ( ! isset( $_POST['_wpcf7_validation_errors']['messages'][$name] ) )
116
- return '';
117
-
118
- $ve = trim( $_POST['_wpcf7_validation_errors']['messages'][$name] );
119
-
120
- if ( ! empty( $ve ) ) {
121
- $ve = '<span class="wpcf7-not-valid-tip-no-ajax">' . esc_html( $ve ) . '</span>';
122
- return apply_filters( 'wpcf7_validation_error', $ve, $name, $this );
123
- }
124
-
125
- return '';
126
- }
127
-
128
- /* Form Elements */
129
-
130
- function form_do_shortcode() {
131
- global $wpcf7_shortcode_manager;
132
-
133
- $form = $this->form;
134
-
135
- if ( WPCF7_AUTOP ) {
136
- $form = $wpcf7_shortcode_manager->normalize_shortcode( $form );
137
- $form = wpcf7_autop( $form );
138
- }
139
-
140
- $form = $wpcf7_shortcode_manager->do_shortcode( $form );
141
- $this->scanned_form_tags = $wpcf7_shortcode_manager->scanned_tags;
142
-
143
- return $form;
144
- }
145
-
146
- function form_scan_shortcode( $cond = null ) {
147
- global $wpcf7_shortcode_manager;
148
-
149
- if ( ! empty( $this->scanned_form_tags ) ) {
150
- $scanned = $this->scanned_form_tags;
151
- } else {
152
- $scanned = $wpcf7_shortcode_manager->scan_shortcode( $this->form );
153
- $this->scanned_form_tags = $scanned;
154
- }
155
-
156
- if ( empty( $scanned ) )
157
- return null;
158
-
159
- if ( ! is_array( $cond ) || empty( $cond ) )
160
- return $scanned;
161
-
162
- for ( $i = 0, $size = count( $scanned ); $i < $size; $i++ ) {
163
-
164
- if ( isset( $cond['type'] ) ) {
165
- if ( is_string( $cond['type'] ) && ! empty( $cond['type'] ) ) {
166
- if ( $scanned[$i]['type'] != $cond['type'] ) {
167
- unset( $scanned[$i] );
168
- continue;
169
- }
170
- } elseif ( is_array( $cond['type'] ) ) {
171
- if ( ! in_array( $scanned[$i]['type'], $cond['type'] ) ) {
172
- unset( $scanned[$i] );
173
- continue;
174
- }
175
- }
176
- }
177
-
178
- if ( isset( $cond['name'] ) ) {
179
- if ( is_string( $cond['name'] ) && ! empty( $cond['name'] ) ) {
180
- if ( $scanned[$i]['name'] != $cond['name'] ) {
181
- unset ( $scanned[$i] );
182
- continue;
183
- }
184
- } elseif ( is_array( $cond['name'] ) ) {
185
- if ( ! in_array( $scanned[$i]['name'], $cond['name'] ) ) {
186
- unset( $scanned[$i] );
187
- continue;
188
- }
189
- }
190
- }
191
- }
192
-
193
- return array_values( $scanned );
194
- }
195
-
196
- function form_elements() {
197
- return apply_filters( 'wpcf7_form_elements', $this->form_do_shortcode() );
198
- }
199
-
200
- /* Validate */
201
-
202
- function validate() {
203
- $fes = $this->form_scan_shortcode();
204
-
205
- $result = array( 'valid' => true, 'reason' => array() );
206
-
207
- foreach ( $fes as $fe ) {
208
- $result = apply_filters( 'wpcf7_validate_' . $fe['type'], $result, $fe );
209
- }
210
-
211
- return $result;
212
- }
213
-
214
- /* Mail */
215
-
216
- function mail() {
217
- $fes = $this->form_scan_shortcode();
218
-
219
- foreach ( $fes as $fe ) {
220
- if ( empty( $fe['name'] ) )
221
- continue;
222
-
223
- $name = $fe['name'];
224
- $pipes = $fe['pipes'];
225
- $value = $_POST[$name];
226
-
227
- if ( WPCF7_USE_PIPE && is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
228
- if ( is_array( $value) ) {
229
- $new_value = array();
230
- foreach ( $value as $v ) {
231
- $new_value[] = $pipes->do_pipe( stripslashes( $v ) );
232
- }
233
- $value = $new_value;
234
- } else {
235
- $value = $pipes->do_pipe( stripslashes( $value ) );
236
- }
237
- }
238
-
239
- $this->posted_data[$name] = $value;
240
- }
241
-
242
- if ( $this->in_demo_mode() )
243
- $this->skip_mail = true;
244
-
245
- do_action_ref_array( 'wpcf7_before_send_mail', array( &$this ) );
246
-
247
- if ( $this->skip_mail )
248
- return true;
249
-
250
- if ( $this->compose_and_send_mail( $this->mail ) ) {
251
- $additional_mail = array();
252
-
253
- if ( $this->mail_2['active'] )
254
- $additional_mail[] = $this->mail_2;
255
-
256
- $additional_mail = apply_filters_ref_array( 'wpcf7_additional_mail',
257
- array( $additional_mail, &$this ) );
258
-
259
- foreach ( $additional_mail as $mail )
260
- $this->compose_and_send_mail( $mail );
261
-
262
- return true;
263
- }
264
-
265
- return false;
266
- }
267
-
268
- function compose_and_send_mail( $mail_template ) {
269
- $regex = '/\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\]/';
270
-
271
- $use_html = (bool) $mail_template['use_html'];
272
-
273
- $callback = array( &$this, 'mail_callback' );
274
- $callback_html = array( &$this, 'mail_callback_html' );
275
-
276
- $subject = preg_replace_callback( $regex, $callback, $mail_template['subject'] );
277
- $sender = preg_replace_callback( $regex, $callback, $mail_template['sender'] );
278
- $recipient = preg_replace_callback( $regex, $callback, $mail_template['recipient'] );
279
- $additional_headers =
280
- preg_replace_callback( $regex, $callback, $mail_template['additional_headers'] );
281
-
282
- if ( $use_html ) {
283
- $body = preg_replace_callback( $regex, $callback_html, $mail_template['body'] );
284
- $body = wpautop( $body );
285
- } else {
286
- $body = preg_replace_callback( $regex, $callback, $mail_template['body'] );
287
- }
288
-
289
- $attachments = array();
290
-
291
- foreach ( (array) $this->uploaded_files as $name => $path ) {
292
- if ( false === strpos( $mail_template['attachments'], "[${name}]" ) || empty( $path ) )
293
- continue;
294
-
295
- $attachments[] = $path;
296
- }
297
-
298
- extract( apply_filters_ref_array( 'wpcf7_mail_components', array(
299
- compact( 'subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments' ),
300
- &$this ) ) );
301
-
302
- $headers = "From: $sender\n";
303
-
304
- if ( $use_html )
305
- $headers .= "Content-Type: text/html\n";
306
-
307
- $headers .= trim( $additional_headers ) . "\n";
308
-
309
- return @wp_mail( $recipient, $subject, $body, $headers, $attachments );
310
- }
311
-
312
- function mail_callback_html( $matches ) {
313
- return $this->mail_callback( $matches, true );
314
- }
315
-
316
- function mail_callback( $matches, $html = false ) {
317
- if ( isset( $this->posted_data[$matches[1]] ) ) {
318
- $submitted = $this->posted_data[$matches[1]];
319
-
320
- if ( is_array( $submitted ) )
321
- $replaced = join( ', ', $submitted );
322
- else
323
- $replaced = $submitted;
324
-
325
- if ( $html ) {
326
- $replaced = strip_tags( $replaced );
327
- $replaced = wptexturize( $replaced );
328
- }
329
-
330
- $replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced, $submitted );
331
-
332
- return stripslashes( $replaced );
333
- }
334
-
335
- if ( $special = apply_filters( 'wpcf7_special_mail_tags', '', $matches[1] ) )
336
- return $special;
337
-
338
- return $matches[0];
339
- }
340
-
341
- /* Message */
342
-
343
- function message( $status ) {
344
- $messages = $this->messages;
345
- $message = isset( $messages[$status] ) ? $messages[$status] : '';
346
-
347
- return apply_filters( 'wpcf7_display_message', $message, $status );
348
- }
349
-
350
- /* Additional settings */
351
-
352
- function additional_setting( $name, $max = 1 ) {
353
- $tmp_settings = (array) explode( "\n", $this->additional_settings );
354
-
355
- $count = 0;
356
- $values = array();
357
-
358
- foreach ( $tmp_settings as $setting ) {
359
- if ( preg_match('/^([a-zA-Z0-9_]+)\s*:(.*)#x2F;', $setting, $matches ) ) {
360
- if ( $matches[1] != $name )
361
- continue;
362
-
363
- if ( ! $max || $count < (int) $max ) {
364
- $values[] = trim( $matches[2] );
365
- $count += 1;
366
- }
367
- }
368
- }
369
-
370
- return $values;
371
- }
372
-
373
- function in_demo_mode() {
374
- $settings = $this->additional_setting( 'demo_mode', false );
375
-
376
- foreach ( $settings as $setting ) {
377
- if ( in_array( $setting, array( 'on', 'true', '1' ) ) )
378
- return true;
379
- }
380
-
381
- return false;
382
- }
383
-
384
- /* Upgrade */
385
-
386
- function upgrade() {
387
- if ( ! isset( $this->mail['recipient'] ) )
388
- $this->mail['recipient'] = get_option( 'admin_email' );
389
-
390
-
391
- if ( ! is_array( $this->messages ) )
392
- $this->messages = array();
393
-
394
-
395
- foreach ( wpcf7_messages() as $key => $arr ) {
396
- if ( ! isset( $this->messages[$key] ) )
397
- $this->messages[$key] = $arr['default'];
398
- }
399
- }
400
-
401
- /* Save */
402
-
403
- function save() {
404
- $postarr = array(
405
- 'ID' => (int) $this->id,
406
- 'post_type' => 'wpcf7_contact_form',
407
- 'post_status' => 'publish',
408
- 'post_title' => $this->title );
409
-
410
- $post_id = wp_insert_post( $postarr );
411
-
412
- if ( $post_id ) {
413
- $metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
414
-
415
- foreach ( $metas as $meta )
416
- update_post_meta( $post_id, $meta, wpcf7_normalize_newline_deep( $this->{$meta} ) );
417
-
418
- if ( $this->initial ) {
419
- $this->initial = false;
420
- $this->id = $post_id;
421
- do_action_ref_array( 'wpcf7_after_create', array( &$this ) );
422
- } else {
423
- do_action_ref_array( 'wpcf7_after_update', array( &$this ) );
424
- }
425
-
426
- do_action_ref_array( 'wpcf7_after_save', array( &$this ) );
427
- }
428
-
429
- return $post_id;
430
- }
431
-
432
- function copy() {
433
- $new = new WPCF7_ContactForm();
434
- $new->initial = true;
435
- $new->title = $this->title . '_copy';
436
-
437
- $new->form = $this->form;
438
- $new->mail = $this->mail;
439
- $new->mail_2 = $this->mail_2;
440
- $new->messages = $this->messages;
441
- $new->additional_settings = $this->additional_settings;
442
-
443
- $new = apply_filters_ref_array( 'wpcf7_copy', array( &$new, &$this ) );
444
-
445
- return $new;
446
- }
447
-
448
- function delete() {
449
- if ( $this->initial )
450
- return;
451
-
452
- wp_delete_post( $this->id, true );
453
-
454
- $this->initial = true;
455
- $this->id = null;
456
- }
457
- }
458
-
459
- function wpcf7_contact_form( $id ) {
460
- $post = get_post( $id );
461
-
462
- if ( empty( $post ) || 'wpcf7_contact_form' != get_post_type( $post ) )
463
- return false;
464
-
465
- $contact_form = new WPCF7_ContactForm();
466
- $contact_form->id = $post->ID;
467
- $contact_form->title = $post->post_title;
468
-
469
- $contact_form->form = get_post_meta( $post->ID, 'form', true );
470
- $contact_form->mail = get_post_meta( $post->ID, 'mail', true );
471
- $contact_form->mail_2 = get_post_meta( $post->ID, 'mail_2', true );
472
- $contact_form->messages = get_post_meta( $post->ID, 'messages', true );
473
- $contact_form->additional_settings = get_post_meta( $post->ID, 'additional_settings', true );
474
-
475
- $contact_form->upgrade();
476
-
477
- $contact_form = apply_filters_ref_array( 'wpcf7_contact_form', array( &$contact_form ) );
478
-
479
- return $contact_form;
480
- }
481
-
482
- function wpcf7_get_contact_form_by_old_id( $old_id ) {
483
- global $wpdb;
484
-
485
- $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
486
- . $wpdb->prepare( " AND meta_value = %d", $old_id );
487
-
488
- if ( $new_id = $wpdb->get_var( $q ) )
489
- return wpcf7_contact_form( $new_id );
490
- }
491
-
492
- function wpcf7_contact_form_default_pack( $locale = null ) {
493
- // For backward compatibility
494
-
495
- return wpcf7_get_contact_form_default_pack( array( 'locale' => $locale ) );
496
- }
497
-
498
- function wpcf7_get_contact_form_default_pack( $args = '' ) {
499
- global $l10n;
500
-
501
- $defaults = array( 'locale' => null, 'title' => '' );
502
- $args = wp_parse_args( $args, $defaults );
503
-
504
- $locale = $args['locale'];
505
- $title = $args['title'];
506
-
507
- if ( $locale && $locale != get_locale() ) {
508
- $mo_orig = $l10n['wpcf7'];
509
- unset( $l10n['wpcf7'] );
510
-
511
- if ( 'en_US' != $locale ) {
512
- $mofile = wpcf7_plugin_path( 'languages/wpcf7-' . $locale . '.mo' );
513
- if ( ! load_textdomain( 'wpcf7', $mofile ) ) {
514
- $l10n['wpcf7'] = $mo_orig;
515
- unset( $mo_orig );
516
- }
517
- }
518
- }
519
-
520
- $contact_form = new WPCF7_ContactForm();
521
- $contact_form->initial = true;
522
-
523
- $contact_form->title = ( $title ? $title : __( 'Untitled', 'wpcf7' ) );
524
-
525
- $contact_form->form = wpcf7_get_default_template( 'form' );
526
- $contact_form->mail = wpcf7_get_default_template( 'mail' );
527
- $contact_form->mail_2 = wpcf7_get_default_template( 'mail_2' );
528
- $contact_form->messages = wpcf7_get_default_template( 'messages' );
529
- $contact_form->additional_settings = wpcf7_get_default_template( 'additional_settings' );
530
-
531
- if ( isset( $mo_orig ) )
532
- $l10n['wpcf7'] = $mo_orig;
533
-
534
- $contact_form = apply_filters_ref_array( 'wpcf7_contact_form_default_pack',
535
- array( &$contact_form, $args ) );
536
-
537
- return $contact_form;
538
- }
539
-
540
- function wpcf7_get_current_contact_form() {
541
- global $wpcf7_contact_form;
542
-
543
- if ( ! is_a( $wpcf7_contact_form, 'WPCF7_ContactForm' ) )
544
- return null;
545
-
546
- return $wpcf7_contact_form;
547
- }
548
-
549
- function wpcf7_is_posted() {
550
- if ( ! $contact_form = wpcf7_get_current_contact_form() )
551
- return false;
552
-
553
- return $contact_form->is_posted();
554
- }
555
-
556
- function wpcf7_get_validation_error( $name ) {
557
- if ( ! $contact_form = wpcf7_get_current_contact_form() )
558
- return '';
559
-
560
- return $contact_form->validation_error( $name );
561
- }
562
-
563
- function wpcf7_get_message( $status ) {
564
- if ( ! $contact_form = wpcf7_get_current_contact_form() )
565
- return '';
566
-
567
- return $contact_form->message( $status );
568
- }
569
-
570
- function wpcf7_scan_shortcode( $cond = null ) {
571
- if ( ! $contact_form = wpcf7_get_current_contact_form() )
572
- return null;
573
-
574
- return $contact_form->form_scan_shortcode( $cond );
575
- }
576
-
577
?>
1
+ <?php
2
+
3
+ class WPCF7_ContactForm {
4
+
5
+ var $initial = false;
6
+
7
+ var $id;
8
+ var $title;
9
+
10
+ var $unit_tag;
11
+
12
+ var $responses_count = 0;
13
+ var $scanned_form_tags;
14
+
15
+ var $posted_data;
16
+ var $uploaded_files = array();
17
+
18
+ var $skip_mail = false;
19
+
20
+ // Return true if this form is the same one as currently POSTed.
21
+ function is_posted() {
22
+ if ( ! isset( $_POST['_wpcf7_unit_tag'] ) || empty( $_POST['_wpcf7_unit_tag'] ) )
23
+ return false;
24
+
25
+ if ( $this->unit_tag == $_POST['_wpcf7_unit_tag'] )
26
+ return true;
27
+
28
+ return false;
29
+ }
30
+
31
+ function clear_post() {
32
+ $fes = $this->form_scan_shortcode();
33
+
34
+ foreach ( $fes as $fe ) {
35
+ if ( ! isset( $fe['name'] ) || empty( $fe['name'] ) )
36
+ continue;
37
+
38
+ $name = $fe['name'];
39
+
40
+ if ( isset( $_POST[$name] ) )
41
+ unset( $_POST[$name] );
42
+ }
43
+ }
44
+
45
+ /* Generating Form HTML */
46
+
47
+ function form_html() {
48
+ $form = '<div class="wpcf7" id="' . $this->unit_tag . '">';
49
+
50
+ $url = wpcf7_get_request_uri();
51
+
52
+ if ( $frag = strstr( $url, '#' ) )
53
+ $url = substr( $url, 0, -strlen( $frag ) );
54
+
55
+ $url .= '#' . $this->unit_tag;
56
+
57
+ $url = apply_filters( 'wpcf7_form_action_url', $url );
58
+ $enctype = apply_filters( 'wpcf7_form_enctype', '' );
59
+ $class = apply_filters( 'wpcf7_form_class_attr', 'wpcf7-form' );
60
+
61
+ $form .= '<form action="' . esc_url_raw( $url ) . '" method="post"'
62
+ . ' class="' . esc_attr( $class ) . '"' . $enctype . '>' . "\n";
63
+
64
+ $form .= $this->form_hidden_fields();
65
+
66
+ $form .= $this->form_elements();
67
+
68
+ if ( ! $this->responses_count )
69
+ $form .= $this->form_response_output();
70
+
71
+ $form .= '</form>';
72
+
73
+ $form .= '</div>';
74
+
75
+ return $form;
76
+ }
77
+
78
+ function form_hidden_fields() {
79
+ $hidden_fields = array(
80
+ '_wpcf7' => $this->id,
81
+ '_wpcf7_version' => WPCF7_VERSION,
82
+ '_wpcf7_unit_tag' => $this->unit_tag );
83
+
84
+ if ( WPCF7_VERIFY_NONCE )
85
+ $hidden_fields['_wpnonce'] = wp_create_nonce( $this->unit_tag );
86
+
87
+ $content = '';
88
+
89
+ foreach ( $hidden_fields as $name => $value ) {
90
+ $content .= '<input type="hidden"'
91
+ . ' name="' . esc_attr( $name ) . '"'
92
+ . ' value="' . esc_attr( $value ) . '" />' . "\n";
93
+ }
94
+
95
+ return '<div style="display: none;">' . "\n" . $content . '</div>' . "\n";
96
+ }
97
+
98
+ function form_response_output() {
99
+ $class = 'wpcf7-response-output';
100
+ $content = '';
101
+
102
+ if ( $this->is_posted() ) { // Post response output for non-AJAX
103
+ if ( isset( $_POST['_wpcf7_mail_sent'] ) && $_POST['_wpcf7_mail_sent']['id'] == $this->id ) {
104
+ if ( $_POST['_wpcf7_mail_sent']['ok'] ) {
105
+ $class .= ' wpcf7-mail-sent-ok';
106
+ $content = $_POST['_wpcf7_mail_sent']['message'];
107
+ } else {
108
+ $class .= ' wpcf7-mail-sent-ng';
109
+ if ( $_POST['_wpcf7_mail_sent']['spam'] )
110
+ $class .= ' wpcf7-spam-blocked';
111
+ $content = $_POST['_wpcf7_mail_sent']['message'];
112
+ }
113
+ } elseif ( isset( $_POST['_wpcf7_validation_errors'] ) && $_POST['_wpcf7_validation_errors']['id'] == $this->id ) {
114
+ $class .= ' wpcf7-validation-errors';
115
+ $content = $this->message( 'validation_error' );
116
+ }
117
+ } else {
118
+ $class .= ' wpcf7-display-none';
119
+ }
120
+
121
+ $class = ' class="' . $class . '"';
122
+
123
+ return '<div' . $class . '>' . $content . '</div>';
124
+ }
125
+
126
+ function validation_error( $name ) {
127
+ if ( ! $this->is_posted() )
128
+ return '';
129
+
130
+ if ( ! isset( $_POST['_wpcf7_validation_errors']['messages'][$name] ) )
131
+ return '';
132
+
133
+ $ve = trim( $_POST['_wpcf7_validation_errors']['messages'][$name] );
134
+
135
+ if ( ! empty( $ve ) ) {
136
+ $ve = '<span class="wpcf7-not-valid-tip-no-ajax">' . esc_html( $ve ) . '</span>';
137
+ return apply_filters( 'wpcf7_validation_error', $ve, $name, $this );
138
+ }
139
+
140
+ return '';
141
+ }
142
+
143
+ /* Form Elements */
144
+
145
+ function form_do_shortcode() {
146
+ global $wpcf7_shortcode_manager;
147
+
148
+ $form = $this->form;
149
+
150
+ if ( WPCF7_AUTOP ) {
151
+ $form = $wpcf7_shortcode_manager->normalize_shortcode( $form );
152
+ $form = wpcf7_autop( $form );
153
+ }
154
+
155
+ $form = $wpcf7_shortcode_manager->do_shortcode( $form );
156
+ $this->scanned_form_tags = $wpcf7_shortcode_manager->scanned_tags;
157
+
158
+ return $form;
159
+ }
160
+
161
+ function form_scan_shortcode( $cond = null ) {
162
+ global $wpcf7_shortcode_manager;
163
+
164
+ if ( ! empty( $this->scanned_form_tags ) ) {
165
+ $scanned = $this->scanned_form_tags;
166
+ } else {
167
+ $scanned = $wpcf7_shortcode_manager->scan_shortcode( $this->form );
168
+ $this->scanned_form_tags = $scanned;
169
+ }
170
+
171
+ if ( empty( $scanned ) )
172
+ return null;
173
+
174
+ if ( ! is_array( $cond ) || empty( $cond ) )
175
+ return $scanned;
176
+
177
+ for ( $i = 0, $size = count( $scanned ); $i < $size; $i++ ) {
178
+
179
+ if ( isset( $cond['type'] ) ) {
180
+ if ( is_string( $cond['type'] ) && ! empty( $cond['type'] ) ) {
181
+ if ( $scanned[$i]['type'] != $cond['type'] ) {
182
+ unset( $scanned[$i] );
183
+ continue;
184
+ }
185
+ } elseif ( is_array( $cond['type'] ) ) {
186
+ if ( ! in_array( $scanned[$i]['type'], $cond['type'] ) ) {
187
+ unset( $scanned[$i] );
188
+ continue;
189
+ }
190
+ }
191
+ }
192
+
193
+ if ( isset( $cond['name'] ) ) {
194
+ if ( is_string( $cond['name'] ) && ! empty( $cond['name'] ) ) {
195
+ if ( $scanned[$i]['name'] != $cond['name'] ) {
196
+ unset ( $scanned[$i] );
197
+ continue;
198
+ }
199
+ } elseif ( is_array( $cond['name'] ) ) {
200
+ if ( ! in_array( $scanned[$i]['name'], $cond['name'] ) ) {
201
+ unset( $scanned[$i] );
202
+ continue;
203
+ }
204
+ }
205
+ }
206
+ }
207
+
208
+ return array_values( $scanned );
209
+ }
210
+
211
+ function form_elements() {
212
+ return apply_filters( 'wpcf7_form_elements', $this->form_do_shortcode() );
213
+ }
214
+
215
+ function setup_posted_data() {
216
+ $posted_data = (array) $_POST;
217
+
218
+ $fes = $this->form_scan_shortcode();
219
+
220
+ foreach ( $fes as $fe ) {
221
+ if ( empty( $fe['name'] ) )
222
+ continue;
223
+
224
+ $name = $fe['name'];
225
+ $pipes = $fe['pipes'];
226
+ $value = $_POST[$name];
227
+
228
+ if ( WPCF7_USE_PIPE && is_a( $pipes, 'WPCF7_Pipes' ) && ! $pipes->zero() ) {
229
+ if ( is_array( $value) ) {
230
+ $new_value = array();
231
+
232
+ foreach ( $value as $v )
233
+ $new_value[] = $pipes->do_pipe( stripslashes( $v ) );
234
+
235
+ $value = $new_value;
236
+ } else {
237
+ $value = $pipes->do_pipe( stripslashes( $value ) );
238
+ }
239
+ }
240
+
241
+ $posted_data[$name] = $value;
242
+ }
243
+
244
+ $this->posted_data = apply_filters( 'wpcf7_posted_data', $posted_data );
245
+
246
+ return $this->posted_data;
247
+ }
248
+
249
+ function submit( $ajax = false ) {
250
+ $result = array(
251
+ 'valid' => true,
252
+ 'invalid_reasons' => array(),
253
+ 'spam' => false,
254
+ 'message' => '',
255
+ 'mail_sent' => false,
256
+ 'scripts_on_sent_ok' => null );
257
+
258
+ $this->setup_posted_data();
259
+
260
+ $validation = $this->validate();
261
+
262
+ if ( ! $validation['valid'] ) { // Validation error occured
263
+ $result['valid'] = false;
264
+ $result['invalid_reasons'] = $validation['reason'];
265
+ $result['message'] = $this->message( 'validation_error' );
266
+
267
+ } elseif ( ! $this->accepted() ) { // Not accepted terms
268
+ $result['message'] = $this->message( 'accept_terms' );
269
+
270
+ } elseif ( $this->spam() ) { // Spam!
271
+ $result['message'] = $this->message( 'spam' );
272
+ $result['spam'] = true;
273
+
274
+ } elseif ( $this->mail() ) {
275
+ $result['mail_sent'] = true;
276
+ $result['message'] = $this->message( 'mail_sent_ok' );
277
+
278
+ do_action_ref_array( 'wpcf7_mail_sent', array( &$this ) );
279
+
280
+ if ( $ajax ) {
281
+ $on_sent_ok = $this->additional_setting( 'on_sent_ok', false );
282
+
283
+ if ( ! empty( $on_sent_ok ) )
284
+ $result['scripts_on_sent_ok'] = array_map( 'wpcf7_strip_quote', $on_sent_ok );
285
+ } else {
286
+ $this->clear_post();
287
+ }
288
+
289
+ } else {
290
+ $result['message'] = $this->message( 'mail_sent_ng' );
291
+ }
292
+
293
+ // remove upload files
294
+ foreach ( (array) $this->uploaded_files as $name => $path ) {
295
+ @unlink( $path );
296
+ }
297
+
298
+ return $result;
299
+ }
300
+
301
+ /* Validate */
302
+
303
+ function validate() {
304
+ $fes = $this->form_scan_shortcode();
305
+
306
+ $result = array( 'valid' => true, 'reason' => array() );
307
+
308
+ foreach ( $fes as $fe ) {
309
+ $result = apply_filters( 'wpcf7_validate_' . $fe['type'], $result, $fe );
310
+ }
311
+
312
+ $result = apply_filters( 'wpcf7_validate', $result );
313
+
314
+ return $result;
315
+ }
316
+
317
+ function accepted() {
318
+ $accepted = true;
319
+
320
+ return apply_filters( 'wpcf7_acceptance', $accepted );
321
+ }
322
+
323
+ function spam() {
324
+ $spam = false;
325
+
326
+ if ( WPCF7_VERIFY_NONCE && ! $this->verify_nonce() )
327
+ $spam = true;
328
+
329
+ return apply_filters( 'wpcf7_spam', $spam );
330
+ }
331
+
332
+ function verify_nonce() {
333
+ return wp_verify_nonce( $_POST['_wpnonce'], $_POST['_wpcf7_unit_tag'] );
334
+ }
335
+
336
+ /* Mail */
337
+
338
+ function mail() {
339
+ if ( $this->in_demo_mode() )
340
+ $this->skip_mail = true;
341
+
342
+ do_action_ref_array( 'wpcf7_before_send_mail', array( &$this ) );
343
+
344
+ if ( $this->skip_mail )
345
+ return true;
346
+
347
+ $result = $this->compose_mail( $this->setup_mail_template( $this->mail, 'mail' ) );
348
+
349
+ if ( $result ) {
350
+ $additional_mail = array();
351
+
352
+ if ( $this->mail_2['active'] )
353
+ $additional_mail[] = $this->setup_mail_template( $this->mail_2, 'mail_2' );
354
+
355
+ $additional_mail = apply_filters_ref_array( 'wpcf7_additional_mail',
356
+ array( $additional_mail, &$this ) );
357
+
358
+ foreach ( $additional_mail as $mail )
359
+ $this->compose_mail( $mail );
360
+
361
+ return true;
362
+ }
363
+
364
+ return false;
365
+ }
366
+
367
+ function setup_mail_template( $mail_template, $name = '' ) {
368
+ $defaults = array(
369
+ 'subject' => '', 'sender' => '', 'body' => '',
370
+ 'recipient' => '', 'additional_headers' => '',
371
+ 'attachments' => '', 'use_html' => false );
372
+
373
+ $mail_template = wp_parse_args( $mail_template, $defaults );
374
+
375
+ $name = trim( $name );
376
+
377
+ if ( ! empty( $name ) )
378
+ $mail_template['name'] = $name;
379
+
380
+ return $mail_template;
381
+ }
382
+
383
+ function compose_mail( $mail_template, $send = true ) {
384
+ $this->mail_template_in_process = $mail_template;
385
+
386
+ $regex = '/(\[?)\[\s*([a-zA-Z_][0-9a-zA-Z:._-]*)\s*\](\]?)/';
387
+
388
+ $use_html = (bool) $mail_template['use_html'];
389
+
390
+ $callback = array( &$this, 'mail_callback' );
391
+ $callback_html = array( &$this, 'mail_callback_html' );
392
+
393
+ $subject = preg_replace_callback( $regex, $callback, $mail_template['subject'] );
394
+ $sender = preg_replace_callback( $regex, $callback, $mail_template['sender'] );
395
+ $recipient = preg_replace_callback( $regex, $callback, $mail_template['recipient'] );
396
+ $additional_headers =
397
+ preg_replace_callback( $regex, $callback, $mail_template['additional_headers'] );
398
+
399
+ if ( $use_html ) {
400
+ $body = preg_replace_callback( $regex, $callback_html, $mail_template['body'] );
401
+ $body = wpautop( $body );
402
+ } else {
403
+ $body = preg_replace_callback( $regex, $callback, $mail_template['body'] );
404
+ }
405
+
406
+ $attachments = array();
407
+
408
+ foreach ( (array) $this->uploaded_files as $name => $path ) {
409
+ if ( false === strpos( $mail_template['attachments'], "[${name}]" ) || empty( $path ) )
410
+ continue;
411
+
412
+ $attachments[] = $path;
413
+ }
414
+
415
+ $components = compact(
416
+ 'subject', 'sender', 'body', 'recipient', 'additional_headers', 'attachments' );
417
+
418
+ $components = apply_filters_ref_array( 'wpcf7_mail_components',
419
+ array( $components, &$this ) );
420
+
421
+ extract( $components );
422
+
423
+ $headers = "From: $sender\n";
424
+
425
+ if ( $use_html )
426
+ $headers .= "Content-Type: text/html\n";
427
+
428
+ $headers .= trim( $additional_headers ) . "\n";
429
+
430
+ if ( $send )
431
+ return @wp_mail( $recipient, $subject, $body, $headers, $attachments );
432
+
433
+ return compact( 'subject', 'sender', 'body', 'recipient', 'headers', 'attachments' );
434
+ }
435
+
436
+ function mail_callback_html( $matches ) {
437
+ return $this->mail_callback( $matches, true );
438
+ }
439
+
440
+ function mail_callback( $matches, $html = false ) {
441
+ // allow [[foo]] syntax for escaping a tag
442
+ if ( $matches[1] == '[' && $matches[3] == ']' )
443
+ return substr( $matches[0], 1, -1 );
444
+
445
+ if ( isset( $this->posted_data[$matches[2]] ) ) {
446
+ $submitted = $this->posted_data[$matches[2]];
447
+
448
+ if ( is_array( $submitted ) )
449
+ $replaced = join( ', ', $submitted );
450
+ else
451
+ $replaced = $submitted;
452
+
453
+ if ( $html ) {
454
+ $replaced = strip_tags( $replaced );
455
+ $replaced = wptexturize( $replaced );
456
+ }
457
+
458
+ $replaced = apply_filters( 'wpcf7_mail_tag_replaced', $replaced, $submitted );
459
+
460
+ return stripslashes( $replaced );
461
+ }
462
+
463
+ if ( $special = apply_filters( 'wpcf7_special_mail_tags', '', $matches[2] ) )
464
+ return $special;
465
+
466
+ return $matches[0];
467
+ }
468
+
469
+ /* Message */
470
+
471
+ function message( $status ) {
472
+ $messages = $this->messages;
473
+ $message = isset( $messages[$status] ) ? $messages[$status] : '';
474
+
475
+ return apply_filters( 'wpcf7_display_message', $message, $status );
476
+ }
477
+
478
+ /* Additional settings */
479
+
480
+ function additional_setting( $name, $max = 1 ) {
481
+ $tmp_settings = (array) explode( "\n", $this->additional_settings );
482
+
483
+ $count = 0;
484
+ $values = array();
485
+
486
+ foreach ( $tmp_settings as $setting ) {
487
+ if ( preg_match('/^([a-zA-Z0-9_]+)\s*:(.*)#x2F;', $setting, $matches ) ) {
488
+ if ( $matches[1] != $name )
489
+ continue;
490
+
491
+ if ( ! $max || $count < (int) $max ) {
492
+ $values[] = trim( $matches[2] );
493
+ $count += 1;
494
+ }
495
+ }
496
+ }
497
+
498
+ return $values;
499
+ }
500
+
501
+ function in_demo_mode() {
502
+ $settings = $this->additional_setting( 'demo_mode', false );
503
+
504
+ foreach ( $settings as $setting ) {
505
+ if ( in_array( $setting, array( 'on', 'true', '1' ) ) )
506
+ return true;
507
+ }
508
+
509
+ return false;
510
+ }
511
+
512
+ /* Upgrade */
513
+
514
+ function upgrade() {
515
+ if ( ! isset( $this->mail['recipient'] ) )
516
+ $this->mail['recipient'] = get_option( 'admin_email' );
517
+
518
+
519
+ if ( ! is_array( $this->messages ) )
520
+ $this->messages = array();
521
+
522
+
523
+ foreach ( wpcf7_messages() as $key => $arr ) {
524
+ if ( ! isset( $this->messages[$key] ) )
525
+ $this->messages[$key] = $arr['default'];
526
+ }
527
+ }
528
+
529
+ /* Save */
530
+
531
+ function save() {
532
+ $postarr = array(
533
+ 'ID' => (int) $this->id,
534
+ 'post_type' => 'wpcf7_contact_form',
535
+ 'post_status' => 'publish',
536
+ 'post_title' => $this->title );
537
+
538
+ $post_id = wp_insert_post( $postarr );
539
+
540
+ if ( $post_id ) {
541
+ $metas = array( 'form', 'mail', 'mail_2', 'messages', 'additional_settings' );
542
+
543
+ foreach ( $metas as $meta )
544
+ update_post_meta( $post_id, $meta, wpcf7_normalize_newline_deep( $this->{$meta} ) );
545
+
546
+ if ( $this->initial ) {
547
+ $this->initial = false;
548
+ $this->id = $post_id;
549
+ do_action_ref_array( 'wpcf7_after_create', array( &$this ) );
550
+ } else {
551
+ do_action_ref_array( 'wpcf7_after_update', array( &$this ) );
552
+ }
553
+
554
+ do_action_ref_array( 'wpcf7_after_save', array( &$this ) );
555
+ }
556
+
557
+ return $post_id;
558
+ }
559
+
560
+ function copy() {
561
+ $new = new WPCF7_ContactForm();
562
+ $new->initial = true;
563
+ $new->title = $this->title . '_copy';
564
+
565
+ $new->form = $this->form;
566
+ $new->mail = $this->mail;
567
+ $new->mail_2 = $this->mail_2;
568
+ $new->messages = $this->messages;
569
+ $new->additional_settings = $this->additional_settings;
570
+
571
+ $new = apply_filters_ref_array( 'wpcf7_copy', array( &$new, &$this ) );
572
+
573
+ return $new;
574
+ }
575
+
576
+ function delete() {
577
+ if ( $this->initial )
578
+ return;
579
+
580
+ wp_delete_post( $this->id, true );
581
+
582
+ $this->initial = true;
583
+ $this->id = null;
584
+ }
585
+ }
586
+
587
+ function wpcf7_contact_form( $id ) {
588
+ $post = get_post( $id );
589
+
590
+ if ( empty( $post ) || 'wpcf7_contact_form' != get_post_type( $post ) )
591
+ return false;
592
+
593
+ $contact_form = new WPCF7_ContactForm();
594
+ $contact_form->id = $post->ID;
595
+ $contact_form->title = $post->post_title;
596
+
597
+ $contact_form->form = get_post_meta( $post->ID, 'form', true );
598
+ $contact_form->mail = get_post_meta( $post->ID, 'mail', true );
599
+ $contact_form->mail_2 = get_post_meta( $post->ID, 'mail_2', true );
600
+ $contact_form->messages = get_post_meta( $post->ID, 'messages', true );
601
+ $contact_form->additional_settings = get_post_meta( $post->ID, 'additional_settings', true );
602
+
603
+ $contact_form->upgrade();
604
+
605
+ $contact_form = apply_filters_ref_array( 'wpcf7_contact_form', array( &$contact_form ) );
606
+
607
+ return $contact_form;
608
+ }
609
+
610
+ function wpcf7_get_contact_form_by_old_id( $old_id ) {
611
+ global $wpdb;
612
+
613
+ $q = "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_old_cf7_unit_id'"
614
+ . $wpdb->prepare( " AND meta_value = %d", $old_id );
615
+
616
+ if ( $new_id = $wpdb->get_var( $q ) )
617
+ return wpcf7_contact_form( $new_id );
618
+ }
619
+
620
+ function wpcf7_get_contact_form_by_title( $title ) {
621
+ $page = get_page_by_title( $title, OBJECT, 'wpcf7_contact_form' );
622
+
623
+ if ( $page )
624
+ return wpcf7_contact_form( $page->ID );
625
+
626
+ return null;
627
+ }
628
+
629
+ function wpcf7_contact_form_default_pack( $locale = null ) {
630
+ // For backward compatibility
631
+
632
+ return wpcf7_get_contact_form_default_pack( array( 'locale' => $locale ) );
633
+ }
634
+
635
+ function wpcf7_get_contact_form_default_pack( $args = '' ) {
636
+ global $l10n;
637
+
638
+ $defaults = array( 'locale' => null, 'title' => '' );
639
+ $args = wp_parse_args( $args, $defaults );
640
+
641
+ $locale = $args['locale'];
642
+ $title = $args['title'];
643
+
644
+ if ( $locale && $locale != get_locale() ) {
645
+ $mo_orig = $l10n['wpcf7'];
646
+ unset( $l10n['wpcf7'] );
647
+
648
+ if ( 'en_US' != $locale ) {
649
+ $mofile = wpcf7_plugin_path( 'languages/wpcf7-' . $locale . '.mo' );
650
+ if ( ! load_textdomain( 'wpcf7', $mofile ) ) {
651
+ $l10n['wpcf7'] = $mo_orig;
652
+ unset( $mo_orig );
653
+ }
654
+ }
655
+ }
656
+
657