PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.2
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.2
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / importer / class-importer-abstract.php

class-importer-abstract.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.3.2, at includes/importer/class-importer-abstract.php

984 lines 34.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Importer Abstract Class
5 */
6 abstract class WeForms_Importer_Abstract {
7
8 /**
9 * The importer ID
10 *
11 * @var string
12 */
13 public $id = '';
14
15 /**
16 * The importer title
17 *
18 * @var string
19 */
20 public $title = '';
21
22 /**
23 * The shortcode (without bracket)
24 *
25 * @var string
26 */
27 public $shortcode = '';
28
29 /**
30 * The ajax action string
31 *
32 * @var string
33 */
34 protected $action = '';
35
36 /**
37 * Conditional stub
38 *
39 * @var array
40 */
41 public $conditionals = array(
42 'condition_status' => 'no',
43 'cond_field' => array(),
44 'cond_operator' => array( '=' ),
45 'cond_option' => array( '- select -' ),
46 'cond_logic' => 'all'
47 );
48
49 public function __construct() {
50 add_action( 'admin_notices', array( $this, 'maybe_show_notice' ) );
51
52 add_action( 'wp_ajax_weforms_import_xdismiss_' . $this->id, array( $this, 'dismiss_notice' ) );
53 add_action( 'wp_ajax_weforms_import_xforms_' . $this->id, array( $this, 'import_forms' ) );
54 add_action( 'wp_ajax_weforms_import_xreplace_' . $this->id, array( $this, 'replace_action' ) );
55 }
56
57 /**
58 * Get the importer name
59 *
60 * @return string
61 */
62 public function get_importer_name() {
63 return $this->title;
64 }
65
66 /**
67 * Get the shortcode ready for regular expression
68 *
69 * @return string
70 */
71 public function get_shortcode( $regex = false ) {
72
73 if ( $regex ) {
74 return preg_quote( $this->shortcode );
75 }
76
77 return $this->shortcode;
78 }
79
80 /**
81 * Get all the forms
82 *
83 * @return array
84 */
85 abstract protected function get_forms();
86
87 /**
88 * Get the form name
89 *
90 * @param mixed $form
91 *
92 * @return string
93 */
94 abstract protected function get_form_name( $form );
95
96 /**
97 * Get the form id
98 *
99 * @param mixed $form
100 *
101 * @return int
102 */
103 abstract protected function get_form_id( $form );
104
105 /**
106 * Get all form fields of a form
107 *
108 * @param mixed $form
109 *
110 * @return array
111 */
112 abstract protected function get_form_fields( $form );
113
114 /**
115 * Get form settings of a form
116 *
117 * @param mixed $form
118 *
119 * @return array
120 */
121 abstract protected function get_form_settings( $form );
122
123 /**
124 * Get form notifications of a form
125 *
126 * @param mixed $form
127 *
128 * @return array
129 */
130 abstract protected function get_form_notifications( $form );
131
132 /**
133 * Check if the plugin exists
134 *
135 * @return boolean
136 */
137 abstract protected function plugin_exists();
138
139 /**
140 * Show notice if the plugin found
141 *
142 * @return void
143 */
144 public function maybe_show_notice() {
145 if ( ! $this->plugin_exists() ) {
146 return;
147 }
148
149 if ( $this->is_dimissed() || !current_user_can( 'manage_options' ) ) {
150 return;
151 }
152
153 ?>
154 <div class="notice notice-info">
155 <p><strong><?php printf( __( '%s Detected', 'weforms' ), $this->get_importer_name() ); ?></strong></p>
156 <p><?php printf( __( 'Hey, looks like you have <strong>%s</strong> installed. Would you like to <strong>import</strong> the forms into weForms?', 'weforms' ), $this->get_importer_name() ); ?></p>
157
158 <p>
159 <a href="#" class="button button-primary weforms-import-<?php echo $this->id ;?>" id="weforms-import-<?php echo $this->id ;?>"><?php _e( 'Import Forms', 'weforms' ); ?></a>
160 <a href="#" class="button weforms-import-<?php echo $this->id ;?>" id="weforms-dimiss-<?php echo $this->id ;?>"><?php _e( 'No Thanks', 'weforms' ); ?></a>
161 </p>
162 </div>
163
164 <script type="text/javascript">
165 jQuery(function($) {
166 $('.notice').on('click', 'a#weforms-import-<?php echo $this->id ;?>', function(e) {
167 e.preventDefault();
168
169 var self = $(this);
170 self.addClass('updating-message');
171
172 wp.ajax.send( 'weforms_import_xforms_<?php echo $this->id ;?>', {
173 data: {
174 type: self.data('type'),
175 _wpnonce: '<?php echo wp_create_nonce( 'weforms' ); ?>'
176 },
177
178 success: function(response) {
179 var html = '<p><strong>' + response.title + '</strong></p>' +
180 '<p>' + response.message + '</p>' +
181 '<p>' + response.action + '</p>';
182
183 html += '<ul>';
184 _.each(response.refs, function(el, index) {
185 html += '<li><a target="_blank" href="admin.php?page=weforms#/form/' + el.weforms_id + '/edit">' + el.title + '</a> - <a href="admin.php?page=weforms#/form/' + el.weforms_id + '/edit" target="_blank" class="button button-small"><span class="dashicons dashicons-external"></span> Edit</a></li>';
186 });
187
188 html += '</ul>';
189 html += '<p>' + '<a href="#" class="button button-primary weforms-<?php echo $this->id ;?>-replace-action" data-type="replace"><?php _e( 'Replace Shortcodes', 'weforms' ); ?></a>&nbsp;' +
190 '<a href="#" class="button weforms-<?php echo $this->id ;?>-replace-action" data-type="skip"><?php _e( 'No Thanks', 'weforms' ); ?></a></p>';
191
192 self.closest('.notice').removeClass('notice-info').addClass('notice-success').html( html );
193 },
194
195 error: function(error) {
196 var html = '<p><strong>' + error.title + '</strong></p>' +
197 '<p>' + error.message + '</p>';
198
199 self.closest('.notice').removeClass('notice-info').addClass('notice-error').html( html );
200 },
201
202 complete: function() {
203 self.removeClass('updating-message');
204 }
205 });
206 });
207
208 $('.notice').on('click', '#weforms-dimiss-<?php echo $this->id ;?>', function(e) {
209 e.preventDefault();
210
211 $(this).closest('.notice').remove();
212 wp.ajax.send('weforms_import_xdismiss_<?php echo $this->id ;?>');
213 });
214
215 $('.notice').on('click', 'a.weforms-<?php echo $this->id ;?>-replace-action', function(e) {
216 e.preventDefault();
217
218 var self = $(this);
219 var notice = self.closest('.notice');
220
221 self.addClass('updating-message');
222
223 wp.ajax.send( 'weforms_import_xreplace_<?php echo $this->id ;?>', {
224 data: {
225 type: self.data('type'),
226 _wpnonce: '<?php echo wp_create_nonce( 'weforms' ); ?>'
227 },
228
229 success: function(response) {
230 notice.remove();
231
232 if ( 'replace' === self.data('type') ) {
233 alert( response );
234 }
235 },
236
237 error: function(error) {
238 notice.remove();
239 alert( error );
240 },
241
242 complete: function() {
243 self.removeClass('updating-message');
244 }
245 });
246
247 });
248 });
249 </script>
250 <?php
251 }
252
253 /**
254 * Import forms
255 *
256 * @return void
257 */
258 public function import_forms() {
259 check_ajax_referer( 'weforms' );
260
261 $this->check_caps();
262
263 // check if plugin installed
264 if ( ! $this->plugin_exists() ) {
265 wp_send_json_error( array(
266 'title' => __( 'Uh oh!', 'weforms' ),
267 'message' => sprintf( __( '%s is not installed.', 'weforms' ), $this->get_importer_name() )
268 ) );
269 }
270
271 $imported = 0;
272 $refs = array();
273 $forms = $this->get_forms();
274
275 if ( ! $forms ) {
276 wp_send_json_error( array(
277 'title' => __( 'Uh oh!', 'weforms' ),
278 'message' => __( 'No forms found!', 'weforms' )
279 ) );
280
281 $this->dismiss_prompt();
282 }
283
284 if ( $forms ) {
285 foreach ($forms as $form) {
286 $form_name = $this->get_form_name( $form );
287 $form_fields = $this->get_form_fields( $form );
288 $settings = $this->get_form_settings( $form );
289 $notifications = $this->get_form_notifications( $form );
290
291 if ( $form_fields ) {
292 $form_id = $this->insert_form( $form_name );
293
294 if ( is_wp_error( $form_id ) ) {
295 continue;
296 }
297
298 foreach ($form_fields as $menu_order => $form_field) {
299 $this->insert_form_field( $form_field, $form_id, $menu_order );
300 }
301
302 $this->update_settings( $form_id, $settings );
303 $this->update_notification( $form_id, $notifications );
304
305 $imported++;
306
307 $refs[ $this->get_form_id( $form ) ] = array(
308 'imported_id' => $this->get_form_id( $form ),
309 'weforms_id' => $form_id,
310 'title' => $form_name
311 );
312 }
313 }
314 }
315
316 $this->dismiss_prompt();
317 $this->update_refs( $refs );
318
319 wp_send_json_success( array(
320 'title' => sprintf( _n( '%s form imported', '%s forms imported', $imported, 'weforms' ), $imported ),
321 'message' => __( 'We have successfully imported these forms into weForms. You could check and edit in-case anything weird happended.', 'weforms' ),
322 'action' => sprintf( __( 'Do you want to <strong>replace</strong> %s shortcodes with weForms?', 'weforms' ), $this->get_importer_name() ),
323 'refs' => $refs
324 ) );
325 }
326
327 /**
328 * Replace contact form 7 shortcodes
329 *
330 * @return void
331 */
332 public function replace_action() {
333 check_ajax_referer( 'weforms' );
334
335 $this->check_caps();
336
337 if ( ! in_array( $_POST['type'], array( 'skip', 'replace' ) ) ) {
338 wp_send_json_error( __( 'Not a valid action type.', 'weforms' ) );
339 }
340
341 if ( 'skip' == $_POST['type'] ) {
342 wp_send_json_success();
343 }
344
345 $pages_query = new WP_Query( array(
346 'post_type' => 'page',
347 'posts_per_page' => -1,
348 's' => '[' . $this->get_shortcode()
349 ) );
350
351 if ( ! $pages_query->found_posts ) {
352 wp_send_json_error( __( 'No pages found with shortcode. Skipped!', 'weforms' ) );
353 }
354
355 $count = 0;
356 $refs = $this->get_refs();
357 $pages = $pages_query->get_posts();
358
359 foreach ($pages as $page) {
360 preg_match_all( '/\[(\[?)(' . $this->get_shortcode( true ) . '|)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/s', $page->post_content, $matches, PREG_SET_ORDER );
361
362 if ( empty( $matches ) ) {
363 continue;
364 }
365
366 foreach ( $matches as $shortcode ) {
367 $atts = shortcode_parse_atts( $shortcode[0] );
368
369 if ( isset( $atts['id'] ) && array_key_exists( $atts['id'], $refs ) ) {
370 $replace = sprintf( '[weforms id="%d"]', $refs[ $atts['id'] ]['weforms_id'] );
371
372 $post_content = str_replace( $shortcode[0], $replace, $page->post_content );
373
374 wp_update_post( array(
375 'ID' => $page->ID,
376 'post_content' => $post_content
377 ) );
378
379 $count++;
380 }
381 }
382 }
383
384 wp_send_json_success( sprintf( _n( 'Replaced %d form', 'Replaced %d forms', $count, 'weforms' ), $count ) );
385 }
386
387 /**
388 * Check capability if able to process
389 *
390 * @return void
391 */
392 public function check_caps() {
393 if ( ! current_user_can( 'manage_options' ) ) {
394 wp_send_json_error( __( 'You are not allowed.', 'weforms' ) );
395 }
396 }
397
398 /**
399 * If the prompt is dismissed
400 *
401 * @return boolean
402 */
403 public function is_dimissed() {
404 return 'yes' == get_option( 'weforms_dismiss_xnotice_' . $this->id );
405 }
406
407 /**
408 * Dismiss the prompt
409 *
410 * @return void
411 */
412 public function dismiss_prompt() {
413 update_option( 'weforms_dismiss_xnotice_' . $this->id, 'yes' );
414 }
415
416 /**
417 * Dismiss the notice
418 *
419 * @return void
420 */
421 public function dismiss_notice() {
422 $this->dismiss_prompt();
423
424 wp_send_json_success();
425 }
426
427 /**
428 * Get the imported form refs
429 *
430 * @return array
431 */
432 public function get_refs() {
433 return get_option( 'weforms_imported_xforms_' . $this->id, array() );
434 }
435
436 /**
437 * Update the imported reference forms
438 *
439 * @param array $refs
440 *
441 * @return void
442 */
443 public function update_refs( $refs ) {
444 update_option( 'weforms_imported_xforms_' . $this->id, $refs );
445 }
446
447 /**
448 * Get form field
449 *
450 * @param string $type
451 * @param array $args [description]
452 *
453 * @return array
454 */
455 public function get_form_field( $type, $args = array() ) {
456 $defaults = array(
457 'required' => 'no',
458 'label' => '',
459 'name' => '',
460 'help' => '',
461 'css_class' => '',
462 'placeholder' => '',
463 'value' => '',
464 'default' => '',
465 'options' => array(),
466 'step' => '',
467 'min' => '',
468 'max' => '',
469 'extension' => '',
470 'max_size' => '', // file size
471 'size' => '', // file size
472 'first_placeholder' => '',
473 'first_default' => '',
474 'middle_placeholder' => '',
475 'middle_default' => '',
476 'last_placeholder' => '',
477 'last_default' => '',
478 'first_name' => '',
479 'middle_name' => '',
480 'last_name' => '',
481 );
482
483 $args = wp_parse_args( $args, $defaults );
484
485 switch ( $type ) {
486 case 'text':
487 $field_content = array(
488 'input_type' => 'text',
489 'template' => 'text_field',
490 'required' => $args['required'],
491 'label' => $args['label'],
492 'name' => $args['name'],
493 'is_meta' => 'yes',
494 'help' => $args['help'],
495 'css' => $args['css_class'],
496 'placeholder' => $args['placeholder'],
497 'default' => $args['default'],
498 'size' => $args['size'],
499 'word_restriction' => '',
500 'wpuf_cond' => $this->conditionals
501 );
502 break;
503
504 case 'email':
505 $field_content = array(
506 'input_type' => 'email',
507 'template' => 'email_address',
508 'required' => $args['required'],
509 'label' => $args['label'],
510 'name' => $args['name'],
511 'is_meta' => 'yes',
512 'help' => $args['help'],
513 'css' => $args['css_class'],
514 'placeholder' => $args['placeholder'],
515 'default' => $args['default'],
516 'size' => $args['size'],
517 'word_restriction' => '',
518 'wpuf_cond' => $this->conditionals
519 );
520 break;
521
522 case 'textarea':
523 $field_content = array(
524 'input_type' => 'textarea',
525 'template' => 'textarea_field',
526 'required' => $args['required'],
527 'label' => $args['label'],
528 'name' => $args['name'],
529 'is_meta' => 'yes',
530 'help' => $args['help'],
531 'css' => $args['css_class'],
532 'rows' => 5,
533 'cols' => 25,
534 'placeholder' => $args['placeholder'],
535 'default' => $args['default'],
536 'rich' => 'no',
537 'word_restriction' => '',
538 'wpuf_cond' => $this->conditionals
539 );
540 break;
541
542 case 'select':
543 $field_content = array(
544 'input_type' => 'select',
545 'template' => 'dropdown_field',
546 'required' => $args['required'],
547 'label' => $args['label'],
548 'name' => $args['name'],
549 'is_meta' => 'yes',
550 'help' => '',
551 'css' => $args['css_class'],
552 'selected' => '',
553 'inline' => 'no',
554 'options' => $args['options'],
555 'wpuf_cond' => $this->conditionals
556 );
557 break;
558
559 case 'multiselect':
560 $field_content = array(
561 'input_type' => 'multiselect',
562 'template' => 'multiple_select',
563 'required' => $args['required'],
564 'label' => $args['label'],
565 'name' => $args['name'],
566 'is_meta' => 'yes',
567 'help' => '',
568 'css' => $args['css_class'],
569 'selected' => '',
570 'first' => __( '- select -', 'weforms' ),
571 'options' => $args['options'],
572 'wpuf_cond' => $this->conditionals
573 );
574 break;
575
576 case 'date':
577 $field_content = array(
578 'input_type' => 'date',
579 'template' => 'date_field',
580 'required' => $args['required'],
581 'label' => $args['label'],
582 'name' => $args['name'],
583 'is_meta' => 'yes',
584 'help' => '',
585 'css' => $args['css_class'],
586 'format' => 'dd/mm/yy',
587 'time' => '',
588 'is_publish_time' => '',
589 'wpuf_cond' => $this->conditionals
590 );
591 break;
592
593 case 'range':
594 case 'number':
595
596 $field_content = array(
597 'input_type' => 'numeric_text',
598 'template' => 'numeric_text_field',
599 'required' => $args['required'],
600 'label' => $args['label'],
601 'name' => $args['name'],
602 'is_meta' => 'yes',
603 'help' => '',
604 'css' => $args['css_class'],
605 'placeholder' => $args['placeholder'],
606 'default' => $args['value'],
607 'size' => 40,
608 'step_text_field' => $args['step'],
609 'min_value_field' => $args['min'],
610 'max_value_field' => $args['max'],
611 'wpuf_cond' => $this->conditionals
612 );
613
614 break;
615
616 case 'url':
617 $field_content = array(
618 'input_type' => 'url',
619 'template' => 'website_url',
620 'required' => $args['required'],
621 'label' => $args['label'],
622 'name' => $args['name'],
623 'is_meta' => 'yes',
624 'help' => '',
625 'css' => $args['css_class'],
626 'placeholder' => '',
627 'default' => '',
628 'size' => 40,
629 'word_restriction' => '',
630 'wpuf_cond' => $this->conditionals
631 );
632
633 break;
634
635 case 'checkbox':
636 $field_content = array(
637 'input_type' => 'checkbox',
638 'template' => 'checkbox_field',
639 'required' => $args['required'],
640 'label' => $args['label'],
641 'name' => $args['name'],
642 'is_meta' => 'yes',
643 'help' => '',
644 'css' => $args['css_class'],
645 'selected' => '',
646 'inline' => 'no',
647 'options' => $args['options'],
648 'wpuf_cond' => $this->conditionals
649 );
650 break;
651
652 case 'radio':
653 $field_content = array(
654 'input_type' => 'radio',
655 'template' => 'radio_field',
656 'required' => $args['required'],
657 'label' => $args['label'],
658 'name' => $args['name'],
659 'is_meta' => 'yes',
660 'help' => '',
661 'css' => $args['css_class'],
662 'selected' => '',
663 'inline' => 'no',
664 'options' => $args['options'],
665 'wpuf_cond' => $this->conditionals
666 );
667 break;
668
669 case 'hidden':
670 $field_content = array(
671 'input_type' => 'hidden',
672 'template' => 'custom_hidden_field',
673 'label' => $args['label'],
674 'name' => $args['name'],
675 'is_meta' => 'yes',
676 'wpuf_cond' => $this->conditionals
677 );
678 break;
679
680 case 'section_break':
681 $field_content = array(
682 'input_type' => 'section_break',
683 'template' => 'section_break',
684 'label' => $args['label'],
685 'name' => $args['name'],
686 'wpuf_cond' => $this->conditionals
687 );
688 break;
689
690 case 'html':
691 $field_content = array(
692 'input_type' => 'html',
693 'template' => 'custom_html',
694 'label' => $args['label'],
695 'name' => $args['name'],
696 'html' => $args['default'],
697 'wpuf_cond' => $this->conditionals
698 );
699 break;
700
701 case 'toc':
702 $field_content = array(
703 'input_type' => 'toc',
704 'template' => 'toc',
705 'required' => $args['required'],
706 'name' => $args['name'],
707 'description' => $args['label'],
708 'is_meta' => 'yes',
709 'show_checkbox' => true,
710 'wpuf_cond' => $this->conditionals
711 );
712 break;
713
714 case 'recaptcha':
715 $field_content = array(
716 'input_type' => 'recaptcha',
717 'template' => 'recaptcha',
718 'required' => $args['required'],
719 'label' => $args['label'],
720 'name' => $args['name'],
721 'recaptcha_type' => 'enable_no_captcha',
722 'is_meta' => 'yes',
723 'help' => '',
724 'css' => $args['css_class'],
725 'placeholder' => '',
726 'default' => '',
727 'size' => 40,
728 'word_restriction' => '',
729 'wpuf_cond' => $this->conditionals
730 );
731 break;
732
733 case 'file':
734 $field_content = array(
735 'input_type' => 'file_upload',
736 'template' => 'file_upload',
737 'required' => $args['required'],
738 'label' => $args['label'],
739 'name' => $args['name'],
740 'is_meta' => 'yes',
741 'help' => $args['help'],
742 'css' => $args['css_class'],
743 'max_size' => $args['max_size'],
744 'count' => '1',
745 'extension' => $args['extension'],
746 'wpuf_cond' => $this->conditionals
747 );
748 break;
749
750 case 'name':
751 $field_content = array(
752 'input_type' => 'name',
753 'template' => 'name_field',
754 'required' => $args['required'],
755 'label' => $args['label'],
756 'name' => $args['name'],
757 'is_meta' => 'yes',
758 'format' => $args['format'],
759 'first_name' => $args['first_name'],
760 'middle_name' => $args['middle_name'],
761 'last_name' => $args['last_name'],
762 'hide_subs' => false,
763 'help' => $args['description'],
764 'css' => $args['css_class'],
765 'wpuf_cond' => $this->conditionals,
766 );
767 break;
768
769 case 'ratings':
770 $field_content = array(
771 'input_type' => 'ratings',
772 'template' => 'ratings',
773 'required' => $args['required'],
774 'label' => $args['label'],
775 'name' => $args['name'],
776 'is_meta' => 'yes',
777 'help' => '',
778 'css' => $args['css_class'],
779 'options' => $args['options'],
780 'wpuf_cond' => $this->conditionals
781 );
782 break;
783
784 case 'linear_scale':
785 $field_content = array(
786 'input_type' => 'linear_scale',
787 'template' => 'linear_scale',
788 'required' => $args['required'],
789 'label' => $args['label'],
790 'name' => $args['name'],
791 'is_meta' => 'yes',
792 'help' => '',
793 'css' => $args['css_class'],
794 'options' => $args['options'],
795 'wpuf_cond' => $this->conditionals
796 );
797 break;
798
799 case 'checkbox_grid':
800 $field_content = array(
801 'input_type' => 'checkbox_grid',
802 'template' => 'checkbox_grid',
803 'required' => $args['required'],
804 'label' => $args['label'],
805 'name' => $args['name'],
806 'is_meta' => 'yes',
807 'help' => '',
808 'css' => $args['css_class'],
809 'options' => $args['options'],
810 'wpuf_cond' => $this->conditionals
811 );
812 break;
813
814 case 'multiple_choice_grid':
815 $field_content = array(
816 'input_type' => 'multiple_choice_grid',
817 'template' => 'multiple_choice_grid',
818 'required' => $args['required'],
819 'label' => $args['label'],
820 'name' => $args['name'],
821 'is_meta' => 'yes',
822 'help' => '',
823 'css' => $args['css_class'],
824 'options' => $args['options'],
825 'wpuf_cond' => $this->conditionals
826 );
827 break;
828
829 case 'single_product':
830 $field_content = array(
831 'input_type' => 'single_product',
832 'template' => 'single_product',
833 'required' => $args['required'],
834 'label' => $args['label'],
835 'name' => $args['name'],
836 'is_meta' => 'yes',
837 'help' => '',
838 'css' => $args['css_class'],
839 'options' => $args['options'],
840 'wpuf_cond' => $this->conditionals
841 );
842 break;
843
844 case 'multiple_product':
845 $field_content = array(
846 'input_type' => 'multiple_product',
847 'template' => 'multiple_product',
848 'required' => $args['required'],
849 'label' => $args['label'],
850 'name' => $args['name'],
851 'is_meta' => 'yes',
852 'help' => '',
853 'css' => $args['css_class'],
854 'options' => $args['options'],
855 'wpuf_cond' => $this->conditionals
856 );
857 break;
858
859 case 'payment_method':
860 $field_content = array(
861 'input_type' => 'payment_method',
862 'template' => 'payment_method',
863 'required' => $args['required'],
864 'label' => $args['label'],
865 'name' => $args['name'],
866 'is_meta' => 'yes',
867 'help' => '',
868 'css' => $args['css_class'],
869 'options' => $args['options'],
870 'wpuf_cond' => $this->conditionals
871 );
872 break;
873
874 case 'total':
875 $field_content = array(
876 'input_type' => 'total',
877 'template' => 'total',
878 'required' => $args['required'],
879 'label' => $args['label'],
880 'name' => $args['name'],
881 'is_meta' => 'yes',
882 'help' => '',
883 'css' => $args['css_class'],
884 'options' => $args['options'],
885 'wpuf_cond' => $this->conditionals
886 );
887 break;
888 }
889
890 return $field_content;
891 }
892
893 /**
894 * Default form settings
895 *
896 * @return array
897 */
898 public function get_default_form_settings() {
899 $form_settings = array(
900 'redirect_to' => 'same',
901 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
902 'page_id' => '',
903 'url' => '',
904 'submit_text' => __( 'Submit Query', 'weforms' ),
905 'schedule_form' => 'false',
906 'schedule_start' => '',
907 'schedule_end' => '',
908 'sc_pending_message' => __( 'Form submission hasn\'t been started yet', 'weforms' ),
909 'sc_expired_message' => __( 'Form submission is now closed.', 'weforms' ),
910 'require_login' => 'false',
911 'req_login_message' => __( 'You need to login to submit a query.', 'weforms' ),
912 'limit_entries' => 'false',
913 'limit_number' => '1000',
914 'limit_message' => __( 'Sorry, we have reached the maximum number of submissions.', 'weforms' ),
915 'label_position' => 'above',
916 );
917
918 return $form_settings;
919 }
920
921 /**
922 * Insert a form
923 *
924 * @param string $form_name
925 *
926 * @return ID|WP_Error
927 */
928 public function insert_form( $form_name ) {
929 $weforms_form = array(
930 'post_title' => sprintf( '[%s] %s', strtoupper( $this->id ), $form_name ),
931 'post_type' => 'wpuf_contact_form',
932 'post_status' => 'publish',
933 'post_author' => get_current_user_id()
934 );
935
936 return wp_insert_post( $weforms_form );
937 }
938
939 /**
940 * Insert a form field
941 *
942 * @param array $field
943 * @param int $form_id
944 * @param int $menu_order
945 *
946 * @return int|WP_Error
947 */
948 public function insert_form_field( $field, $form_id, $menu_order ) {
949 $form_field = array(
950 'post_type' => 'wpuf_input',
951 'post_status' => 'publish',
952 'post_content' => maybe_serialize( $field ),
953 'post_parent' => $form_id,
954 'menu_order' => $menu_order
955 );
956
957 return wp_insert_post( $form_field );
958 }
959
960 /**
961 * Update form settings
962 *
963 * @param int $form_id
964 * @param array $settings
965 *
966 * @return void
967 */
968 public function update_settings( $form_id, $settings ) {
969 update_post_meta( $form_id, 'wpuf_form_settings', $settings );
970 }
971
972 /**
973 * Update Notification
974 *
975 * @param int $form_id
976 * @param array $notification
977 *
978 * @return void
979 */
980 public function update_notification( $form_id, $notifications ) {
981 update_post_meta( $form_id, 'notifications', $notifications );
982 }
983 }
984