source: trunk/www.guidonia.net/wp/wp-content/plugins/contact-form-7/admin/admin.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 13.5 KB
Line 
1<?php
2
3function wpcf7_admin_has_edit_cap() {
4 return current_user_can( WPCF7_ADMIN_READ_WRITE_CAPABILITY );
5}
6
7function wpcf7_admin_add_pages() {
8
9 if ( isset( $_POST['wpcf7-save'] ) && wpcf7_admin_has_edit_cap() ) {
10 $id = $_POST['wpcf7-id'];
11 check_admin_referer( 'wpcf7-save_' . $id );
12
13 if ( ! $contact_form = wpcf7_contact_form( $id ) ) {
14 $contact_form = new WPCF7_ContactForm();
15 $contact_form->initial = true;
16 }
17
18 $title = trim( $_POST['wpcf7-title'] );
19 $form = trim( $_POST['wpcf7-form'] );
20 $mail = array(
21 'subject' => trim( $_POST['wpcf7-mail-subject'] ),
22 'sender' => trim( $_POST['wpcf7-mail-sender'] ),
23 'body' => trim( $_POST['wpcf7-mail-body'] ),
24 'recipient' => trim( $_POST['wpcf7-mail-recipient'] ),
25 'additional_headers' => trim( $_POST['wpcf7-mail-additional-headers'] ),
26 'attachments' => trim( $_POST['wpcf7-mail-attachments'] ),
27 'use_html' => ( 1 == $_POST['wpcf7-mail-use-html'] ) ? true : false
28 );
29 $mail_2 = array(
30 'active' => ( 1 == $_POST['wpcf7-mail-2-active'] ) ? true : false,
31 'subject' => trim( $_POST['wpcf7-mail-2-subject'] ),
32 'sender' => trim( $_POST['wpcf7-mail-2-sender'] ),
33 'body' => trim( $_POST['wpcf7-mail-2-body'] ),
34 'recipient' => trim( $_POST['wpcf7-mail-2-recipient'] ),
35 'additional_headers' => trim( $_POST['wpcf7-mail-2-additional-headers'] ),
36 'attachments' => trim( $_POST['wpcf7-mail-2-attachments'] ),
37 'use_html' => ( 1 == $_POST['wpcf7-mail-2-use-html'] ) ? true : false
38 );
39 $messages = array(
40 'mail_sent_ok' => trim( $_POST['wpcf7-message-mail-sent-ok'] ),
41 'mail_sent_ng' => trim( $_POST['wpcf7-message-mail-sent-ng'] ),
42 'akismet_says_spam' => trim( $_POST['wpcf7-message-akismet-says-spam'] ),
43 'validation_error' => trim( $_POST['wpcf7-message-validation-error'] ),
44 'accept_terms' => trim( $_POST['wpcf7-message-accept-terms'] ),
45 'invalid_email' => trim( $_POST['wpcf7-message-invalid-email'] ),
46 'invalid_required' => trim( $_POST['wpcf7-message-invalid-required'] ),
47 'quiz_answer_not_correct' => trim( $_POST['wpcf7-message-quiz-answer-not-correct'] ),
48 'captcha_not_match' => trim( $_POST['wpcf7-message-captcha-not-match'] ),
49 'upload_failed' => trim( $_POST['wpcf7-message-upload-failed'] ),
50 'upload_file_type_invalid' => trim( $_POST['wpcf7-message-upload-file-type-invalid'] ),
51 'upload_file_too_large' => trim( $_POST['wpcf7-message-upload-file-too-large'] ),
52 'upload_failed_php_error' => trim( $_POST['wpcf7-message-upload-failed-php-error'] )
53 );
54 $additional_settings = trim( $_POST['wpcf7-additional-settings'] );
55
56 $query = array();
57 $query['message'] = ( $contact_form->initial ) ? 'created' : 'saved';
58
59 $contact_form->title = $title;
60 $contact_form->form = $form;
61 $contact_form->mail = $mail;
62 $contact_form->mail_2 = $mail_2;
63 $contact_form->messages = $messages;
64 $contact_form->additional_settings = $additional_settings;
65
66 $contact_form->save();
67
68 $query['contactform'] = $contact_form->id;
69 $redirect_to = wpcf7_admin_url( 'admin.php', $query );
70 wp_redirect( $redirect_to );
71 exit();
72 } elseif ( isset( $_POST['wpcf7-copy'] ) && wpcf7_admin_has_edit_cap() ) {
73 $id = $_POST['wpcf7-id'];
74 check_admin_referer( 'wpcf7-copy_' . $id );
75
76 $query = array();
77
78 if ( $contact_form = wpcf7_contact_form( $id ) ) {
79 $new_contact_form = $contact_form->copy();
80 $new_contact_form->save();
81
82 $query['contactform'] = $new_contact_form->id;
83 $query['message'] = 'created';
84 } else {
85 $query['contactform'] = $contact_form->id;
86 }
87
88 $redirect_to = wpcf7_admin_url( 'admin.php', $query );
89 wp_redirect( $redirect_to );
90 exit();
91 } elseif ( isset( $_POST['wpcf7-delete'] ) && wpcf7_admin_has_edit_cap() ) {
92 $id = $_POST['wpcf7-id'];
93 check_admin_referer( 'wpcf7-delete_' . $id );
94
95 if ( $contact_form = wpcf7_contact_form( $id ) )
96 $contact_form->delete();
97
98 $redirect_to = wpcf7_admin_url( 'admin.php', array( 'message' => 'deleted' ) );
99 wp_redirect( $redirect_to );
100 exit();
101 } elseif ( isset( $_GET['wpcf7-create-table'] ) ) {
102 check_admin_referer( 'wpcf7-create-table' );
103
104 $query = array();
105
106 if ( ! wpcf7_table_exists() && current_user_can( 'activate_plugins' ) ) {
107 wpcf7_install();
108 if ( wpcf7_table_exists() ) {
109 $query['message'] = 'table_created';
110 } else {
111 $query['message'] = 'table_not_created';
112 }
113 }
114
115 wp_redirect( wpcf7_admin_url( 'admin.php', $query ) );
116 exit();
117 }
118
119 add_menu_page( __( 'Contact Form 7', 'wpcf7' ), __( 'Contact', 'wpcf7' ),
120 WPCF7_ADMIN_READ_CAPABILITY, wpcf7_plugin_path( 'admin/admin.php' ),
121 'wpcf7_admin_management_page' );
122
123 wpcf7_add_contact_page( __( 'Edit Contact Forms', 'wpcf7' ), __( 'Edit', 'wpcf7' ),
124 WPCF7_ADMIN_READ_CAPABILITY, wpcf7_plugin_path( 'admin/admin.php' ),
125 'wpcf7_admin_management_page' );
126}
127
128add_action( 'admin_menu', 'wpcf7_admin_add_pages', 9 );
129
130function wpcf7_add_contact_page( $page_title, $menu_title, $access_level,
131 $file, $function = '', $icon_url = '' ) {
132
133 add_submenu_page( wpcf7_plugin_path( 'admin/admin.php' ),
134 $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '' );
135}
136
137function wpcf7_admin_head() {
138 global $plugin_page;
139
140 if ( ! isset( $plugin_page ) || 0 !== strpos( $plugin_page, WPCF7_PLUGIN_NAME ) )
141 return;
142
143 $admin_stylesheet_url = wpcf7_plugin_url( 'admin/admin-stylesheet.css' );
144 echo '<link rel="stylesheet" href="' . $admin_stylesheet_url . '" type="text/css" />';
145
146 if ( 'rtl' == get_bloginfo( 'text_direction' ) ) {
147 $admin_stylesheet_rtl_url = wpcf7_plugin_url( 'admin/admin-stylesheet-rtl.css' );
148 echo '<link rel="stylesheet" href="' . $admin_stylesheet_rtl_url . '" type="text/css" />';
149 }
150
151?>
152<script type="text/javascript">
153//<![CDATA[
154var _wpcf7 = {
155 captchaMod: <?php echo ( class_exists( 'ReallySimpleCaptcha' ) ) ? 'true' : 'false' ?>
156};
157//]]>
158</script>
159<?php
160}
161
162add_action( 'admin_head', 'wpcf7_admin_head' );
163
164function wpcf7_admin_load_js() {
165 global $pagenow;
166
167 if ( ! is_admin() )
168 return;
169
170 if ( 'admin.php' != $pagenow )
171 return;
172
173 if ( false === strpos( $_GET['page'], 'contact-form-7' ) )
174 return;
175
176 wp_enqueue_script( 'wpcf7-admin', wpcf7_plugin_url( 'admin/wpcf7-admin.js' ), array('jquery'), WPCF7_VERSION, true );
177 wp_localize_script( 'wpcf7-admin', '_wpcf7L10n', array(
178 'optional' => __( 'optional', 'wpcf7' ),
179 'generateTag' => __( 'Generate Tag', 'wpcf7' ),
180 'textField' => __( 'Text field', 'wpcf7' ),
181 'emailField' => __( 'Email field', 'wpcf7' ),
182 'textArea' => __( 'Text area', 'wpcf7' ),
183 'menu' => __( 'Drop-down menu', 'wpcf7' ),
184 'checkboxes' => __( 'Checkboxes', 'wpcf7' ),
185 'radioButtons' => __( 'Radio buttons', 'wpcf7' ),
186 'acceptance' => __( 'Acceptance', 'wpcf7' ),
187 'isAcceptanceDefaultOn' => __( "Make this checkbox checked by default?", 'wpcf7' ),
188 'isAcceptanceInvert' => __( "Make this checkbox work inversely?", 'wpcf7' ),
189 'isAcceptanceInvertMeans' => __( "* That means visitor who accepts the term unchecks it.", 'wpcf7' ),
190 'captcha' => __( 'CAPTCHA', 'wpcf7' ),
191 'quiz' => __( 'Quiz', 'wpcf7' ),
192 'quizzes' => __( 'Quizzes', 'wpcf7' ),
193 'quizFormatDesc' => __( "* quiz|answer (e.g. 1+1=?|2)", 'wpcf7' ),
194 'fileUpload' => __( 'File upload', 'wpcf7' ),
195 'bytes' => __( 'bytes', 'wpcf7' ),
196 'submit' => __( 'Submit button', 'wpcf7' ),
197 'tagName' => __( 'Name', 'wpcf7' ),
198 'isRequiredField' => __( 'Required field?', 'wpcf7' ),
199 'allowsMultipleSelections' => __( 'Allow multiple selections?', 'wpcf7' ),
200 'insertFirstBlankOption' => __( 'Insert a blank item as the first option?', 'wpcf7' ),
201 'makeCheckboxesExclusive' => __( 'Make checkboxes exclusive?', 'wpcf7' ),
202 'menuChoices' => __( 'Choices', 'wpcf7' ),
203 'label' => __( 'Label', 'wpcf7' ),
204 'defaultValue' => __( 'Default value', 'wpcf7' ),
205 'akismet' => __( 'Akismet', 'wpcf7' ),
206 'akismetAuthor' => __( "This field requires author's name", 'wpcf7' ),
207 'akismetAuthorUrl' => __( "This field requires author's URL", 'wpcf7' ),
208 'akismetAuthorEmail' => __( "This field requires author's email address", 'wpcf7' ),
209 'generatedTag' => __( "Copy this code and paste it into the form left.", 'wpcf7' ),
210 'fgColor' => __( "Foreground color", 'wpcf7' ),
211 'bgColor' => __( "Background color", 'wpcf7' ),
212 'imageSize' => __( "Image size", 'wpcf7' ),
213 'imageSizeSmall' => __( "Small", 'wpcf7' ),
214 'imageSizeMedium' => __( "Medium", 'wpcf7' ),
215 'imageSizeLarge' => __( "Large", 'wpcf7' ),
216 'imageSettings' => __( "Image settings", 'wpcf7' ),
217 'inputFieldSettings' => __( "Input field settings", 'wpcf7' ),
218 'tagForImage' => __( "For image", 'wpcf7' ),
219 'tagForInputField' => __( "For input field", 'wpcf7' ),
220 'oneChoicePerLine' => __( "* One choice per line.", 'wpcf7' ),
221 'show' => __( "Show", 'wpcf7' ),
222 'hide' => __( "Hide", 'wpcf7' ),
223 'fileSizeLimit' => __( "File size limit", 'wpcf7' ),
224 'acceptableFileTypes' => __( "Acceptable file types", 'wpcf7' ),
225 'needReallySimpleCaptcha' => __( "Note: To use CAPTCHA, you need Really Simple CAPTCHA plugin installed.", 'wpcf7' )
226 ) );
227}
228
229add_action( 'wp_print_scripts', 'wpcf7_admin_load_js' );
230
231function wpcf7_admin_management_page() {
232 global $wp_version;
233
234 switch ( $_GET['message'] ) {
235 case 'created':
236 $updated_message = __( "Contact form created.", 'wpcf7' );
237 break;
238 case 'saved':
239 $updated_message = __( "Contact form saved.", 'wpcf7' );
240 break;
241 case 'deleted':
242 $updated_message = __( "Contact form deleted.", 'wpcf7' );
243 break;
244 case 'table_created':
245 $updated_message = __( "Database table created.", 'wpcf7' );
246 break;
247 case 'table_not_created':
248 $updated_message = __( "Failed to create database table.", 'wpcf7' );
249 break;
250 }
251
252 $contact_forms = wpcf7_contact_forms();
253
254 $id = $_POST['wpcf7-id'];
255
256 if ( 'new' == $_GET['contactform'] ) {
257 $unsaved = true;
258 $current = -1;
259 $cf = wpcf7_contact_form_default_pack();
260 } elseif ( $cf = wpcf7_contact_form( $_GET['contactform'] ) ) {
261 $current = (int) $_GET['contactform'];
262 } else {
263 $first = reset( $contact_forms ); // Returns first item
264 $current = $first->id;
265 $cf = wpcf7_contact_form( $current );
266 }
267
268 require_once WPCF7_PLUGIN_DIR . '/admin/admin-panel.php';
269}
270
271/* Install and default settings */
272
273function wpcf7_install() {
274 global $wpdb;
275
276 if ( wpcf7_table_exists() )
277 return; // Exists already
278
279 $table_name = wpcf7_table_name();
280
281 $charset_collate = '';
282 if ( $wpdb->has_cap( 'collation' ) ) {
283 if ( ! empty( $wpdb->charset ) )
284 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
285 if ( ! empty( $wpdb->collate ) )
286 $charset_collate .= " COLLATE $wpdb->collate";
287 }
288
289 $wpdb->query( "CREATE TABLE IF NOT EXISTS $table_name (
290 cf7_unit_id bigint(20) unsigned NOT NULL auto_increment,
291 title varchar(200) NOT NULL default '',
292 form text NOT NULL,
293 mail text NOT NULL,
294 mail_2 text NOT NULL,
295 messages text NOT NULL,
296 additional_settings text NOT NULL,
297 PRIMARY KEY (cf7_unit_id)) $charset_collate;" );
298
299 if ( ! wpcf7_table_exists() )
300 return false; // Failed to create
301
302 $legacy_data = get_option( 'wpcf7' );
303 if ( is_array( $legacy_data ) ) {
304 foreach ( $legacy_data['contact_forms'] as $key => $value ) {
305 $wpdb->insert( $table_name, array(
306 'cf7_unit_id' => $key,
307 'title' => $value['title'],
308 'form' => maybe_serialize( $value['form'] ),
309 'mail' => maybe_serialize( $value['mail'] ),
310 'mail_2' => maybe_serialize( $value['mail_2'] ),
311 'messages' => maybe_serialize( $value['messages'] ),
312 'additional_settings' => maybe_serialize( $value['additional_settings'] )
313 ), array( '%d', '%s', '%s', '%s', '%s', '%s', '%s' ) );
314 }
315
316 // delete_option( 'wpcf7' ); // Comment out for downgrading case for a while
317 } else {
318 wpcf7_load_plugin_textdomain();
319
320 $wpdb->insert( $table_name, array(
321 'title' => __( 'Contact form', 'wpcf7' ) . ' 1',
322 'form' => maybe_serialize( wpcf7_default_form_template() ),
323 'mail' => maybe_serialize( wpcf7_default_mail_template() ),
324 'mail_2' => maybe_serialize ( wpcf7_default_mail_2_template() ),
325 'messages' => maybe_serialize( wpcf7_default_messages_template() ) ) );
326 }
327}
328
329add_action( 'activate_' . WPCF7_PLUGIN_BASENAME, 'wpcf7_install' );
330
331/* Misc */
332
333function wpcf7_admin_url( $file, $query = array() ) {
334 $file = trim( $file, ' /' );
335 if ( 'admin/' != substr( $file, 0, 6 ) )
336 $file = 'admin/' . $file;
337
338 $path = 'admin.php';
339 $path .= '?page=' . WPCF7_PLUGIN_NAME . '/' . $file;
340
341 if ( $query = build_query( $query ) )
342 $path .= '&' . $query;
343
344 $url = admin_url( $path );
345
346 return $url;
347}
348
349function wpcf7_plugin_action_links( $links, $file ) {
350 if ( $file != WPCF7_PLUGIN_BASENAME )
351 return $links;
352
353 $url = wpcf7_admin_url( 'admin.php' );
354
355 $settings_link = '<a href="' . $url . '">' . esc_html( __( 'Settings', 'wpcf7' ) ) . '</a>';
356
357 array_unshift( $links, $settings_link );
358
359 return $links;
360}
361
362add_filter( 'plugin_action_links', 'wpcf7_plugin_action_links', 10, 2 );
363
364function wpcf7_donation_link() {
365 if ( ! WPCF7_SHOW_DONATION_LINK )
366 return;
367
368 if ( 'new' == $_GET['contactform'] || ! empty($_GET['message']) )
369 return;
370
371 $num = mt_rand(0, 99);
372 if ($num >= 10) // 90%
373 return;
374
375 $texts = array(
376 __( "Contact Form 7 needs your support. Please donate today.", 'wpcf7' ),
377 __( "Is this plugin useful for you? If you like it, please help the developer.", 'wpcf7' ),
378 __( "Your contribution is needed for making this plugin better.", 'wpcf7' ),
379 __( "Developing a plugin and providing user support is really hard work. Please help.", 'wpcf7' ) );
380
381 $text = $texts[array_rand( $texts )];
382
383?>
384<div class="donation">
385<p><a href="http://www.pledgie.com/campaigns/3117">
386<img alt="Click here to lend your support to: Support Contact Form 7 and make a donation at www.pledgie.com !" src="http://www.pledgie.com/campaigns/3117.png?skin_name=chrome" border="0" width="149" height="37" /></a>
387<em><?php echo esc_html( $text ); ?></em>
388</p>
389</div>
390<?php
391}
392
393?>
Note: See TracBrowser for help on using the repository browser.