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

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

451 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Contact Form 7
5 *
6 * Import contact form 7 forms
7 */
8 class WeForms_Importer_GF extends WeForms_Importer_Abstract {
9
10 function __construct() {
11 $this->id = 'gf';
12 $this->title = 'Gravity Form';
13 $this->shortcode = 'gravityform';
14
15 parent::__construct();
16 }
17
18 /**
19 * See if the plugin exists
20 *
21 * @return boolean
22 */
23 public function plugin_exists() {
24 return class_exists( 'GFForms' );
25 }
26
27 /**
28 * Get all forms
29 *
30 * @since 1.0.0
31 *
32 * @return [type]
33 */
34 public function get_forms() {
35 return GFAPI::get_forms();
36 }
37
38 /**
39 * Get form title
40 *
41 * @since 1.0.0
42 *
43 * @param array $form
44 *
45 * @return string
46 */
47 public function get_form_name( $form ) {
48 return $form['title'];
49 }
50
51 /**
52 * Mapping all form fileds
53 *
54 * @since 1.0.0
55 *
56 * @param array $form
57 *
58 * @return array
59 */
60 public function get_form_fields( $form ) {
61 $form_fields = array();
62
63 $form_tags = $form['fields'];
64
65 if ( ! $form_tags ) {
66 return;
67 }
68
69 foreach ( $form_tags as $menu_order => $field ) {
70
71 switch ( $field->type ) {
72
73 case 'text':
74 case 'email':
75 case 'date':
76 case 'url':
77
78 $form_fields[] = $this->get_form_field( $field->type, array(
79 'required' => $field->isRequired ? 'yes' : 'no',
80 'label' => $field->label,
81 'name' => $this->get_meta_key( $field ),
82 'css_class' => $field->cssClass,
83 'help' => $field->description,
84 'placeholder' => $field->placeholder,
85 ) );
86 break;
87
88 case 'textarea':
89
90 $form_fields[] = array(
91 'input_type' => 'textarea',
92 'template' => 'textarea_field',
93 'required' => $field->isRequired ? 'yes' : 'no',
94 'label' => $field->label,
95 'name' => $this->get_meta_key( $field ),
96 'css' => $field->cssClass,
97 'help' => $field->description,
98 'placeholder' => $field->placeholder,
99 'is_meta' => 'yes',
100 'rows' => 5,
101 'cols' => 25,
102 'default' => $field->defaultValue,
103 'rich' => $field->useRichTextEditor ? 'yes' : 'no',
104 'wpuf_cond' => $this->conditionals
105 );
106 break;
107
108 case 'select':
109 case 'radio':
110 case 'checkbox':
111 $form_fields[] = $this->get_form_field( $field->type, array(
112 'required' => $field->isRequired ? 'yes' : 'no',
113 'label' => $field->label,
114 'name' => $this->get_meta_key( $field ),
115 'css_class' => $field->cssClass,
116 'help' => $field->description,
117 'options' => $this->get_options( $field ),
118 ) );
119 break;
120
121
122 case 'multiselect':
123 $form_fields[] = array(
124 'input_type' => 'multiselect',
125 'template' => 'multiple_select',
126 'required' => $field->isRequired ? 'yes' : 'no',
127 'label' => $field->label,
128 'name' => $this->get_meta_key( $field ),
129 'is_meta' => 'yes',
130 'css' => $field->cssClass,
131 'help' => $field->description,
132 'selected' => array(),
133 'options' => $this->get_options( $field ),
134 'wpuf_cond' => $this->conditionals
135 );
136 break;
137
138 case 'number':
139 $form_fields[] = $this->get_form_field( $field->type, array(
140 'required' => $field->isRequired ? 'yes' : 'no',
141 'label' => $field->label,
142 'name' => $this->get_meta_key( $field ),
143 'css_class' => $field->cssClass,
144 'help' => $field->description,
145 'options' => $this->get_options( $field ),
146 'value' => $field->defaultValue,
147 'min' => $field->rangeMin,
148 'max' => $field->rangeMax,
149 ) );
150 break;
151
152 case 'address':
153 $form_fields[] = array(
154 'input_type' => 'address',
155 'template' => 'address_field',
156 'required' => $field->isRequired ? 'yes' : 'no',
157 'label' => $field->label,
158 'name' => $this->get_meta_key( $field ),
159 'is_meta' => 'yes',
160 'css_class' => $field->cssClass,
161 'help' => $field->description,
162 'address' => $this->get_address_field_data( $field )
163 );
164 break;
165
166 case 'fileupload':
167 $extenion_type = array();
168 $file_ext = explode( ',', $field->allowedExtensions );
169
170 foreach( $file_ext as $ext ) {
171 $allowed_ext = $this->get_file_type( $ext );
172 if ( $allowed_ext ) {
173 $extenion_type[] = $data;
174 }
175 }
176
177 $form_fields[] = $this->get_form_field( 'file', array(
178 'required' => $field->isRequired ? 'yes' : 'no',
179 'label' => $field->label,
180 'name' => $this->get_meta_key( $field ),
181 'css_class' => $field->cssClass,
182 'help' => $field->description,
183 'max_size' => !empty( $field->maxFileSize ) ? $field->maxFileSize * 1024 : 1024,
184 'extension' => array_unique( $extenion_type ),
185 ) );
186 break;
187
188 case 'hidden':
189 $form_fields[] = array(
190 'input_type' => 'hidden',
191 'template' => 'custom_hidden_field',
192 'label' => $field->label,
193 'name' => $this->get_meta_key( $field ),
194 'is_meta' => 'yes',
195 'meta_value' => $field->defaultValue,
196 'wpuf_cond' => ''
197 );
198
199 break;
200
201 case 'name':
202 if ( $this->get_name_format( $field ) ) {
203 $form_fields[] = array(
204 'input_type' => 'name',
205 'template' => 'name_field',
206 'required' => $field->isRequired ? 'yes' : 'no',
207 'label' => $field->label,
208 'name' => $this->get_meta_key( $field ),
209 'is_meta' => 'yes',
210 'css' => $field->cssClass,
211 'wpuf_cond' => $this->conditionals,
212 'format' => $this->get_name_format( $field ),
213 'first_name' => array(
214 'sub' => isset( $field->inputs[1]['label'] ) ? $field->inputs[1]['label'] : '',
215 'default' => isset( $field->inputs[1]['defaultValue'] ) ? $field->inputs[1]['defaultValue'] : '',
216 'placeholder' => isset( $field->inputs[1]['placeholder'] ) ? $field->inputs[1]['placeholder'] : ''
217 ),
218 'middle_name' => array(
219 'sub' => isset( $field->inputs[2]['label'] ) ? $field->inputs[2]['label'] : '',
220 'default' => isset( $field->inputs[2]['defaultValue'] ) ? $field->inputs[2]['defaultValue'] : '',
221 'placeholder' => isset( $field->inputs[2]['placeholder'] ) ? $field->inputs[2]['placeholder'] : ''
222 ),
223 'last_name' => array(
224 'sub' => isset( $field->inputs[3]['label'] ) ? $field->inputs[3]['label'] : '',
225 'default' => isset( $field->inputs[3]['defaultValue'] ) ? $field->inputs[3]['defaultValue'] : '',
226 'placeholder' => isset( $field->inputs[3]['placeholder'] ) ? $field->inputs[3]['placeholder'] : ''
227 ),
228 'hide_subs' => ''
229 );
230 }
231 break;
232
233 case 'captcha':
234 $form_fields[] = $this->get_form_field( 'recaptcha', array(
235 'required' => $field->isRequired ? 'yes' : 'no',
236 'label' => $field->label,
237 'name' => $this->get_meta_key( $field ),
238 'css_class' => $field->cssClass,
239 ) );
240 break;
241 }
242 }
243
244 return $form_fields;
245 }
246
247 /**
248 * Mapping form settings
249 *
250 * @since 1.0.0
251 *
252 * @param array $form
253 *
254 * @return array
255 */
256 public function get_form_settings( $form ) {
257 $default_settings = $this->get_default_form_settings();
258 $start_date = '';
259 $end_date = '';
260
261 if ( isset( $form['scheduleForm'] ) && $form['scheduleForm'] ) {
262 $start_time = sprintf( "%02d", $form['scheduleStartHour'] ) . ':' . sprintf( "%02d", $form['scheduleStartMinute'] ) . ' ' . $form['scheduleStartAmpm'];
263 $end_time = sprintf( "%02d", $form['scheduleEndHour'] ) . ':' . sprintf( "%02d", $form['scheduleEndMinute'] ) . ' ' . $form['scheduleEndAmpm'];
264 $start_date = date( 'Y-m-d H:i:s', strtotime( $form['scheduleStart'] . $start_time ) );
265 $end_date = date( 'Y-m-d H:i:s', strtotime( $form['scheduleEnd'] . $end_time ) );
266 }
267
268 $form_label_position = ! empty( $form['labelPlacement'] ) ? $form['labelPlacement'] : 'top_label';
269
270 $form_settings = array(
271 'redirect_to' => 'same',
272 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
273 'page_id' => '',
274 'url' => '',
275 'submit_text' => ! empty( $form['button']['text'] ) ? $form['button']['text'] : __( 'Submit Query', 'weforms' ),
276 'schedule_form' => ( isset( $form['scheduleForm'] ) && $form['scheduleForm'] ) ? 'true' : 'false',
277 'schedule_start' => $start_date,
278 'schedule_end' => $end_date,
279 'sc_pending_message' => ! empty( $form['schedulePendingMessage'] ) ? $form['schedulePendingMessage'] : '',
280 'sc_expired_message' => ! empty( $form['scheduleMessage'] ) ? $form['scheduleMessage'] : '' ,
281 'require_login' => ! empty( $form['requireLogin'] ) ? 'true' : 'false',
282 'req_login_message' => ! empty( $form['requireLoginMessage'] ) ? $form['requireLoginMessage'] : '',
283 'limit_entries' => ! empty( $form['limitEntries'] ) ? 'true' : 'false',
284 'limit_number' => ! empty( $form['limitEntriesCount'] ) ? $form['limitEntriesCount'] : '',
285 'limit_message' => ! empty( $form['limitEntriesMessage'] ) ? $form['limitEntriesMessage'] : '',
286 'label_position' => $this->get_label_position( $form_label_position ),
287 );
288
289 $settings = wp_parse_args( $form_settings, $default_settings );
290
291 return $settings;
292 }
293
294 /**
295 * Mapping form notification settings
296 *
297 * @since 1.0.0
298 *
299 * @param array $form
300 *
301 * @return array
302 */
303 public function get_form_notifications( $form ) {
304 $notifications = array();
305
306 if ( empty( $form['notifications'] ) ) {
307 return $notifications;
308 }
309
310 foreach ( $form['notifications'] as $key => $notification ) {
311 $notifications[] = array(
312 'active' => ( isset( $notification['isActive'] ) && $notification['isActive'] ) ? 'true' : 'false',
313 'name' => $notification['name'],
314 'subject' => str_replace( '[your-subject]', '{field:your-subject}', $notification['subject'] ),
315 'to' => $notification['to'],
316 'replyTo' => '{field:your-email}',
317 'message' => '{all_fields}',
318 'fromName' => '{site_name}',
319 'fromAddress' => '{admin_email}',
320 'cc' => '',
321 'bcc' => '',
322 );
323 }
324
325 return $notifications;
326 }
327
328 /**
329 * Get the form id
330 *
331 * @param mixed $form
332 *
333 * @return int
334 */
335 protected function get_form_id( $form ) {
336 return $form['id'];
337 }
338
339 /**
340 * Get unique meta key for field name
341 *
342 * @since 1.0.0
343 *
344 * @return string [slug format]
345 **/
346 public function get_meta_key( $field ) {
347 return str_replace( '-', '_', sanitize_title( $field->label . '-' . $field->id ) );
348 }
349
350 /**
351 * Get selecte, checkbox, multiselect and radio field options value
352 *
353 * @since 1.0.0
354 *
355 * @return void
356 **/
357 public function get_options( $field ) {
358 if ( empty( $field['choices'] ) ) {
359 return array();
360 }
361
362 return wp_list_pluck( $field['choices'], 'text', 'value' );
363 }
364
365 /**
366 * Get address field data
367 *
368 * @since 1.0.0
369 *
370 * @return void
371 **/
372 public function get_address_field_data( $field ) {
373 $address = array();
374 $address_data_key = array( 'street_address', 'street_address2', 'city_name', 'state', 'zip', 'country_select' );
375
376 foreach ( $address_data_key as $key => $value ) {
377 $address[$value] = array(
378 'checked' => ( isset( $field->inputs[$key]['isHidden'] ) && $field->inputs[$key]['isHidden'] ) ? '' : 'checked',
379 'type' => ( 'country_select' == $value ) ? 'select' : 'text',
380 'required' => $field->isRequired ? 'checked' : '',
381 'label' => ! empty( $field->inputs[$key]['customLabel'] ) ? $field->inputs[$key]['customLabel'] : $field->inputs[$key]['label'],
382 'value' => ! empty( $field->inputs[$key]['defaultValue'] ) ? $field->inputs[$key]['defaultValue'] : '',
383 'placeholder' => ! empty( $field->inputs[$key]['placeholder'] ) ? $field->inputs[$key]['placeholder'] : ''
384 );
385
386 if ( 'country_select' == $value ) {
387 $address[$value]['country_list_visibility_opt_name'] = 'all';
388 $address[$value]['country_select_hide_list'] = array();
389 $address[$value]['country_select_show_list'] = array();
390 }
391 }
392
393 return $address;
394 }
395
396 /**
397 * Get file type for upload files
398 *
399 * @param string $extension
400 *
401 * @return boolean|string
402 */
403 private function get_file_type( $extension ) {
404 $allowed_extensions = weforms_allowed_extensions();
405
406 foreach ($allowed_extensions as $type => $extensions) {
407 $_extensions = explode( ',', $extensions['ext'] );
408
409 if ( in_array( $extension, $_extensions ) ) {
410 return $type;
411 }
412 }
413
414 return false;
415 }
416
417 /**
418 * Get name format
419 *
420 * @since 1.0.0
421 *
422 * @return void
423 **/
424 private function get_name_format( $field ) {
425 if ( ! isset( $field->inputs[1]['isHidden'] ) && ! isset( $field->inputs[2]['isHidden'] ) && ! isset( $field->inputs[3]['isHidden'] ) ) {
426 return 'first-middle-last';
427 } else if ( ! isset( $field->inputs[1]['isHidden'] ) && ! isset( $field->inputs[3]['isHidden'] ) ) {
428 return 'first-last';
429 } else {
430 return false;
431 }
432 }
433
434 /**
435 * Get label placement position
436 *
437 * @since 1.0.0
438 *
439 * @return void
440 **/
441 public function get_label_position( $label ) {
442 $labels = array(
443 'top_label' => 'above',
444 'left_label' => 'left',
445 'right_label' => 'right'
446 );
447
448 return $labels[$label];
449 }
450
451 }