PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.1.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.1.1
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-wpforms.php

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

231 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPForms importer class
4 */
5 class WeForms_Importer_WPForms extends WeForms_Importer_Abstract {
6
7 function __construct() {
8 $this->id = 'wpforms';
9 $this->title = 'WPForms';
10 $this->shortcode = 'wpforms';
11
12 parent::__construct();
13 }
14
15 /**
16 * Check if the plugin exists
17 *
18 * @return boolean
19 */
20 public function plugin_exists() {
21 return function_exists( 'wpforms' );
22 }
23
24 /**
25 * Get all the forms
26 *
27 * @return array
28 */
29 public function get_forms() {
30 return wpforms()->form->get();
31 }
32
33 /**
34 * Parse a form to array
35 *
36 * @param string $form
37 *
38 * @return array
39 */
40 public function parse_form( $form ) {
41 return json_decode( $form->post_content, true );
42 }
43
44 /**
45 * Get the form name
46 *
47 * @param string $form
48 *
49 * @return string
50 */
51 public function get_form_name( $form ) {
52 return $form->post_title;
53 }
54
55 /**
56 * Get the form id
57 *
58 * @param mixed $form
59 *
60 * @return int
61 */
62 protected function get_form_id( $form ) {
63 return $form->ID;
64 }
65
66 /**
67 * Get form notifications of a form
68 *
69 * @param mixed $form
70 *
71 * @return array
72 */
73 public function get_form_notifications( $form ) {
74 $parsed = $this->parse_form( $form );
75 $notification = array_pop( $parsed['settings']['notifications'] );
76
77 $form_notifications = array(
78 array(
79 'active' => $settings['notification_enable'] ? true : false,
80 'name' => 'Admin Notification',
81 'subject' => $notification['subject'],
82 'to' => $notification['email'],
83 'replyTo' => $notification['replyto'],
84 'message' => $notification['message'],
85 'fromName' => $notification['sender_name'],
86 'fromAddress' => $notification['sender_address'],
87 'cc' => '',
88 'bcc' => '',
89 ),
90 );
91
92 return $form_notifications;
93 }
94
95 /**
96 * Get all form fields of a form
97 *
98 * @param mixed $form
99 *
100 * @return array
101 */
102 public function get_form_fields( $form ) {
103 $form_fields = array();
104 $parsed = $this->parse_form( $form );
105
106 if ( empty( $parsed['fields'] ) ) {
107 return $form_fields;
108 }
109
110 foreach ( $parsed['fields'] as $menu_order => $field ) {
111 switch ( $field['type'] ) {
112 case 'text':
113 case 'email':
114 case 'textarea':
115
116 $form_fields[] = $this->get_form_field( $field['type'], array(
117 'required' => ! empty( $field['required'] ) ? 'yes' : 'no',
118 'label' => $field['label'],
119 'name' => $field['id'],
120 'help' => $field['description'],
121 'css_class' => $field['css'],
122 'placeholder' => $field['placeholder'],
123 'default' => ! empty( $field['default_value'] ) ? $field['default_value'] : '',
124 ) );
125
126 break;
127
128 case 'select':
129 case 'radio':
130 case 'checkbox':
131
132 $form_fields[] = $this->get_form_field( $field['type'], array(
133 'required' => ! empty( $field['required'] ) ? 'yes' : 'no',
134 'label' => $field['label'],
135 'name' => $field['id'],
136 'help' => $field['description'],
137 'css_class' => $field['css'],
138 'placeholder' => $field['placeholder'],
139 'selected' => ! empty( $field['default_value'] ) ? $field['default_value'] : '',
140 'options' => $this->get_options( $field ),
141 ) );
142 break;
143
144 case 'name':
145
146 $form_fields[] = $this->get_form_field( $field['type'], array(
147 'required' => ! empty( $field['required'] ) ? 'yes' : 'no',
148 'label' => $field['label'],
149 'name' => $field['id'],
150 'help' => $field['description'],
151 'css_class' => $field['css'],
152 'format' => ( $field['format'] === 'first-last' ) ? 'first-last' : 'first-middle-last',
153 'hide_subs' => ! empty( $field['sublabel_hide'] ) ? true : false,
154 'first_name' => array(
155 'placeholder' => $field['first_placeholder'],
156 'default' => $field['first_default'],
157 'sub' => __( 'First', 'weforms' ),
158 ),
159 'middle_name' => array(
160 'placeholder' => $field['middle_placeholder'],
161 'default' => $field['middle_default'],
162 'sub' => __( 'Middle', 'weforms' ),
163 ),
164 'last_name' => array(
165 'placeholder' => $field['last_placeholder'],
166 'default' => $field['last_default'],
167 'sub' => __( 'Last', 'weforms' ),
168 ),
169 ) );
170 break;
171 }
172 }
173
174 return $form_fields;
175 }
176
177 public function get_form_settings( $form ) {
178 $default = $this->get_default_form_settings();
179 $parsed = $this->parse_form( $form );
180
181 $settings = $parsed['settings'];
182
183 // Settings mapping
184 switch ( $settings['confirmation_type'] ) {
185 case 'redirect':
186 $redirect_to = 'url';
187 break;
188
189 case 'page':
190 $redirect_to = 'page';
191 break;
192
193 case 'message':
194 default:
195 $redirect_to = 'same';
196 break;
197 }
198
199 $form_settings = wp_parse_args( array(
200 'message' => $settings['confirmation_message'],
201 'page_id' => $settings['confirmation_page'],
202 'url' => $settings['confirmation_redirect'],
203 'submit_text' => $settings['submit_text'],
204 'redirect_to' => $redirect_to,
205 ), $default );
206
207 return $form_settings;
208 }
209
210 /**
211 * Translate to wpuf field options array
212 *
213 * @param object $field
214 *
215 * @return array
216 */
217 private function get_options( $field ) {
218 $options = array();
219
220 if ( ! $field['choices'] ) {
221 return $options;
222 }
223
224 foreach ( $field['choices'] as $choice ) {
225 $options[ $choice['label'] ] = $choice['label'];
226 }
227
228 return $options;
229 }
230 }
231