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

functions.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.2.0, at includes/functions.php

1,006 lines 27.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Get a single form
5 *
6 * @since 1.0.3
7 *
8 * @param int $form_id
9 *
10 * @return false|WP_Post
11 */
12 function weform_get_form( $form_id ) {
13 return weforms()->form->get( $form_id );
14 }
15
16 /**
17 * Get contact form templates
18 *
19 * @return array
20 */
21 function weforms_get_form_template_categories() {
22
23 $categories = array(
24 'default' => array(
25 'name' => 'Default Templates',
26 'icon' => 'fa fa-bars',
27 ),
28 // 'registration' => array(
29 // 'name' => 'Registration Templates',
30 // 'icon' => 'fa fa-user-plus',
31 // ),
32 'event' => array(
33 'name' => 'Event Templates',
34 'icon' => 'fa fa-calendar',
35 ),
36 'application' => array(
37 'name' => 'Application Templates',
38 'icon' => 'fa fa-address-card-o',
39 ),
40 );
41
42 return apply_filters( 'weforms_form_template_categories', $categories );
43 }
44
45 /**
46 * Get entries by a form_id
47 *
48 * @param int $form_id
49 * @param array $args
50 *
51 * @return Object
52 */
53 function weforms_get_form_entries( $form_id, $args = array() ) {
54 global $wpdb;
55
56 $defaults = array(
57 'number' => 10,
58 'offset' => 0,
59 'orderby' => 'created_at',
60 'status' => 'publish',
61 'order' => 'DESC',
62 );
63
64 $r = wp_parse_args( $args, $defaults );
65
66 $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at
67 FROM ' . $wpdb->weforms_entries .
68 ' WHERE form_id = ' . $form_id . ' AND status = \'' . $r['status'] . '\''.
69 ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'];
70
71 if ( !empty( $r['offset'] ) && !empty( $r['number'] ) ) {
72 $query .= ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
73 }
74
75 $results = $wpdb->get_results( $query );
76
77 return $results;
78 }
79
80 /**
81 * Get payments by a form_id
82 *
83 * @param int $form_id
84 * @param array $args
85 *
86 * @return Object
87 */
88 function weforms_get_form_payments( $form_id, $args = array() ) {
89 global $wpdb;
90
91 $defaults = array(
92 'number' => 10,
93 'offset' => 0,
94 'orderby' => 'created_at',
95 'order' => 'DESC',
96 );
97
98 $r = wp_parse_args( $args, $defaults );
99
100 $query = 'SELECT * FROM ' . $wpdb->prefix . 'weforms_payments' .
101 ' WHERE form_id = ' . $form_id .
102 ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'] .
103 ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
104
105 $results = $wpdb->get_results( $query );
106
107 return $results;
108 }
109
110 /**
111 * Get an entry by id
112 *
113 * @param int $entry_id
114 *
115 * @return Object
116 */
117 function weforms_get_entry( $entry_id ) {
118 global $wpdb;
119
120 $cache_key = 'weforms-entry-' . $entry_id;
121 $entry = wp_cache_get( $cache_key, 'weforms' );
122
123 if ( false === $entry ) {
124 $query = 'SELECT id, form_id, user_id, user_device, referer, INET_NTOA( user_ip ) as ip_address, created_at
125 FROM ' . $wpdb->weforms_entries . '
126 WHERE id = %d';
127
128 $entry = $wpdb->get_row( $wpdb->prepare( $query, $entry_id ) );
129 wp_cache_set( $cache_key, $entry );
130 }
131
132 return $entry;
133 }
134
135 /**
136 * Insert a new entry
137 *
138 * @param array $args
139 * @param array $fields
140 *
141 * @return WP_Error|integer
142 */
143 function weforms_insert_entry( $args, $fields = array() ) {
144 global $wpdb;
145
146 $browser = weforms_get_browser();
147
148 $defaults = array(
149 'form_id' => 0,
150 'user_id' => get_current_user_id(),
151 'user_ip' => ip2long( weforms_get_client_ip() ),
152 'user_device' => $browser['name'] . '/' . $browser['platform'],
153 'referer' => $_SERVER['HTTP_REFERER'],
154 'created_at' => current_time( 'mysql' )
155 );
156
157 $r = wp_parse_args( $args, $defaults );
158
159 if ( !$r['form_id'] ) {
160 return new WP_Error( 'no-form-id', __( 'No form ID was found.', 'weforms' ) );
161 }
162
163 if ( !$fields ) {
164 return new WP_Error( 'no-fields', __( 'No form fields were found.', 'weforms' ) );
165 }
166
167 $success = $wpdb->insert( $wpdb->weforms_entries, $r );
168
169 if ( is_wp_error( $success ) || !$success ) {
170 return new WP_Error( 'could-not-create', __( 'Could not create an entry', 'weforms' ) );
171 }
172
173 $entry_id = $wpdb->insert_id;
174
175 foreach ($fields as $key => $value) {
176 weforms_add_entry_meta( $entry_id, $key, $value );
177 }
178
179 return $entry_id;
180 }
181
182 /**
183 * Change an entry status
184 *
185 * @param int $entry_id
186 * @param string $status
187 *
188 * @return int|boolean
189 */
190 function weforms_change_entry_status( $entry_id, $status ) {
191 global $wpdb;
192
193 return $wpdb->update( $wpdb->weforms_entries,
194 array( 'status' => $status ),
195 array( 'id' => $entry_id ),
196 array( '%s' ),
197 array( '%d' )
198 );
199 }
200
201 /**
202 * Delete an entry
203 *
204 * @param int $entry_id
205 *
206 * @return int|boolean
207 */
208 function weforms_delete_entry( $entry_id ) {
209 global $wpdb;
210
211 return $wpdb->delete( $wpdb->weforms_entries, array( 'id' => $entry_id ), array( '%d' ) );
212 }
213
214 /**
215 * Add meta data field to an entry.
216 *
217 * @param int $entry_id Entry ID.
218 * @param string $meta_key Metadata name.
219 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
220 * @param bool $unique Optional. Whether the same key should not be added.
221 * Default false.
222 * @return int|false Meta ID on success, false on failure.
223 */
224 function weforms_add_entry_meta( $entry_id, $meta_key, $meta_value, $unique = false ) {
225 return add_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $unique);
226 }
227
228 /**
229 * Retrieve entry meta field for a entry.
230 *
231 * @param int $entry_id Entry ID.
232 * @param string $key Optional. The meta key to retrieve. By default, returns
233 * data for all keys. Default empty.
234 * @param bool $single Optional. Whether to return a single value. Default false.
235 * @return mixed Will be an array if $single is false. Will be value of meta data
236 * field if $single is true.
237 */
238 function weforms_get_entry_meta( $entry_id, $key = '', $single = false ) {
239 return get_metadata( 'weforms_entry', $entry_id, $key, $single );
240 }
241
242 /**
243 * Update entry meta field based on entry ID.
244 *
245 * Use the $prev_value parameter to differentiate between meta fields with the
246 * same key and entry ID.
247 *
248 * If the meta field for the entry does not exist, it will be added.
249 *
250 * @param int $entry_id entry ID.
251 * @param string $meta_key Metadata key.
252 * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
253 * @param mixed $prev_value Optional. Previous value to check before removing.
254 * Default empty.
255 * @return int|bool Meta ID if the key didn't exist, true on successful update,
256 * false on failure.
257 */
258 function weforms_update_entry_meta( $entry_id, $meta_key, $meta_value, $prev_value = '' ) {
259 return update_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $prev_value);
260 }
261
262 /**
263 * Delete everything from entry meta matching meta key.
264 *
265 * @param string $entry_meta_key Key to search for when deleting.
266 * @return bool Whether the entry meta key was deleted from the database.
267 */
268 function weforms_delete_entry_meta_by_key( $meta_key ) {
269 return delete_metadata( 'weforms_entry', null, $meta_key, '', true );
270 }
271
272 /**
273 * Retrieve entry meta fields, based on entry ID.
274 *
275 * The entry meta fields are retrieved from the cache where possible,
276 * so the function is optimized to be called more than once.
277 *
278 * @since 1.2.0
279 *
280 * @param int $entry_id Optional.
281 * @return array entry meta for the given entry.
282 */
283 function weforms_get_entry_custom( $entry_id = 0 ) {
284 $entry_id = absint( $entry_id );
285
286 return weforms_get_entry_meta( $entry_id );
287 }
288
289 /**
290 * Retrieve meta field names for a entry.
291 *
292 * If there are no meta fields, then nothing (null) will be returned.
293 *
294 * @param int $entry_id Optional.
295 * @return array|void Array of the keys, if retrieved.
296 */
297 function weforms_get_entry_custom_keys( $entry_id = 0 ) {
298 $custom = weforms_get_entry_custom( $entry_id );
299
300 if ( !is_array( $custom ) ) {
301 return false;
302 }
303
304 if ( $keys = array_keys($custom) ) {
305 return $keys;
306 }
307 }
308
309 /**
310 * Get the number of entries count on a form
311 *
312 * @param int $form_id
313 *
314 * @return int
315 */
316 function weforms_count_form_entries( $form_id, $status = 'publish' ) {
317 global $wpdb;
318
319 return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM ' . $wpdb->weforms_entries . ' WHERE form_id = %d AND status = %s', $form_id, $status ) );
320 }
321
322 /**
323 * Get the number of entries count on a form
324 *
325 * @param int $form_id
326 *
327 * @return int
328 */
329 function weforms_count_form_payments( $form_id ) {
330 global $wpdb;
331
332 if ( ! class_exists( 'WeForms_Payment' ) ) {
333 return 0;
334 }
335
336 return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM ' . $wpdb->prefix . 'weforms_payments' . ' WHERE form_id = %d', $form_id) );
337 }
338
339 /**
340 * Get table column heads for a form
341 *
342 * For now, return only text type fields
343 *
344 * @param int $form_id
345 *
346 * @return array
347 */
348 function weforms_get_entry_columns( $form_id, $limit = 6 ) {
349 $fields = weforms()->form->get( $form_id )->get_fields();
350 $columns = array();
351
352 // filter by input types
353 if ( $limit ) {
354
355 $fields = array_filter( $fields, function($item) {
356 return in_array( $item['template'], array( 'text_field', 'name_field', 'dropdown_field', 'radio_field', 'email_address', 'url_field' ) );
357 } );
358 }
359
360 if ( $fields ) {
361 foreach ($fields as $field) {
362 $columns[ $field['name'] ] = $field['label'];
363 }
364 }
365
366 // if passed 0/false, return all collumns
367 if ( $limit && sizeof($columns) > $limit ) {
368 $columns = array_slice( $columns, 0, $limit ); // max 6 columns
369 }
370
371 return apply_filters('weforms_get_entry_columns', $columns, $form_id);
372 }
373
374 /**
375 * Get table column heads for a form
376 *
377 * For now, return only text type fields
378 *
379 * @param int $form_id
380 *
381 * @return array
382 */
383 function weforms_get_payment_columns( $form_id, $limit = 6 ) {
384 $fields = weforms()->form->get( $form_id )->get_fields();
385 $columns = array();
386
387 // filter by input types
388 if ( $limit ) {
389
390 $fields = array_filter( $fields, function($item) {
391 return in_array( $item['template'], array( 'text_field', 'name_field', 'dropdown_field', 'radio_field', 'email_address', 'url_field' ) );
392 } );
393 }
394
395 if ( $fields ) {
396 foreach ($fields as $field) {
397 $columns[ $field['name'] ] = $field['label'];
398 }
399 }
400
401 // if passed 0/false, return all collumns
402 if ( $limit && sizeof($columns) > $limit ) {
403 $columns = array_slice( $columns, 0, $limit ); // max 6 columns
404 }
405
406 return apply_filters('weforms_get_entry_columns', $columns, $form_id);
407 }
408
409 /**
410 * Get fields from a form by it's meta key
411 *
412 * @param int $form_id
413 *
414 * @return array
415 */
416 function weforms_get_form_field_labels( $form_id ) {
417 $fields = weforms()->form->get( $form_id )->get_fields();
418 $exclude = array( 'step_start', 'section_break', 'recaptcha', 'shortcode', 'action_hook' );
419
420 if ( ! $fields ) {
421 return false;
422 }
423
424 $data = array();
425 foreach ($fields as $field) {
426 if ( empty( $field['name'] ) ) {
427 continue;
428 }
429
430 // exclude the fields
431 if ( in_array( $field['template'], $exclude ) ) {
432 continue;
433 }
434
435 $data[ $field['name'] ] = array(
436 'label' => $field['label'],
437 'type' => $field['template']
438 );
439 }
440
441 return $data;
442 }
443
444 /**
445 * Get data from an entry
446 *
447 * @param int $entry_id
448 * @param int $form_id
449 *
450 * @return false|array
451 */
452 function weforms_get_entry_data( $entry_id ) {
453 $data = array();
454 $entry = weforms_get_entry( $entry_id );
455 $fields = weforms_get_form_field_labels( $entry->form_id );
456
457 if ( ! $fields ) {
458 return false;
459 }
460
461 foreach ($fields as $meta_key => $field ) {
462 $value = weforms_get_entry_meta( $entry_id, $meta_key, true );
463
464 if ( $field['type'] == 'textarea' ) {
465
466 $data[ $meta_key ] = weforms_format_text( $value );
467
468 } elseif ( $field['type'] == 'name' ) {
469
470 $data[ $meta_key ] = implode( ' ', explode( WeForms::$field_separator, $value ) );
471
472 } elseif ( in_array( $field['type'], array( 'image_upload', 'file_upload' ) ) ) {
473
474 $data[ $meta_key ] = '';
475
476 if ( is_array( $value ) && $value ) {
477
478 foreach ($value as $attachment_id) {
479
480 if ( $field['type'] == 'image_upload' ) {
481 $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
482 } else {
483 $thumb = get_post_field( 'post_title', $attachment_id );
484 }
485
486 $full_size = wp_get_attachment_url( $attachment_id );
487
488 $data[ $meta_key ] .= sprintf( '<a href="%s" target="_blank">%s</a> ', $full_size, $thumb );
489 }
490 }
491
492 } elseif ( in_array( $field['type'], array( 'checkbox', 'multiselect' ) ) ) {
493
494 $data[ $meta_key ] = explode( WeForms::$field_separator, $value );
495
496 } elseif ( $field['type'] == 'map' ) {
497
498 list( $lat, $long ) = explode( ',', $value );
499
500 $data[ $meta_key ] = array( 'lat' => $lat, 'long' => $long );
501
502 } else {
503 $data[ $meta_key ] = $value;
504 }
505 }
506
507 return array(
508 'fields' => $fields,
509 'data' => $data
510 );
511 }
512
513 /**
514 * Format a text and apply WP function callbacks
515 *
516 * @param string $content
517 *
518 * @return string
519 */
520 function weforms_format_text( $content ) {
521 $content = wptexturize( $content );
522 $content = convert_smilies( $content );
523 $content = wpautop( $content );
524 $content = make_clickable( $content );
525
526 return $content;
527 }
528
529 /**
530 * Get User Agent browser and OS type
531 *
532 * @return array
533 */
534 function weforms_get_browser() {
535 $u_agent = $_SERVER['HTTP_USER_AGENT'];
536 $bname = 'Unknown';
537 $platform = 'Unknown';
538 $version = "";
539
540 // first get the platform
541 if (preg_match('/linux/i', $u_agent)) {
542 $platform = 'Linux';
543 } elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
544 $platform = 'MAC OS';
545 } elseif (preg_match('/windows|win32/i', $u_agent)) {
546 $platform = 'Windows';
547 }
548
549 // next get the name of the useragent yes seperately and for good reason
550 if ( preg_match('/MSIE/i',$u_agent) && !preg_match( '/Opera/i',$u_agent ) ) {
551 $bname = 'Internet Explorer';
552 $ub = "MSIE";
553 } elseif(preg_match('/Trident/i',$u_agent)) {
554 // this condition is for IE11
555 $bname = 'Internet Explorer';
556 $ub = "rv";
557 } elseif(preg_match('/Firefox/i',$u_agent)) {
558 $bname = 'Mozilla Firefox';
559 $ub = "Firefox";
560 } elseif(preg_match('/Chrome/i',$u_agent)) {
561 $bname = 'Google Chrome';
562 $ub = "Chrome";
563 } elseif(preg_match('/Safari/i',$u_agent)) {
564 $bname = 'Apple Safari';
565 $ub = "Safari";
566 } elseif(preg_match('/Opera/i',$u_agent)) {
567 $bname = 'Opera';
568 $ub = "Opera";
569 } elseif(preg_match('/Netscape/i',$u_agent)) {
570 $bname = 'Netscape';
571 $ub = "Netscape";
572 }
573
574 // finally get the correct version number
575 // Added "|:"
576 $known = array('Version', $ub, 'other');
577 $pattern = '#(?<browser>' . join('|', $known) .
578 ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#';
579 if (!preg_match_all($pattern, $u_agent, $matches)) {
580 // we have no matching number just continue
581 }
582
583 // see how many we have
584 $i = count($matches['browser']);
585
586 if ($i != 1) {
587 //we will have two since we are not using 'other' argument yet
588 //see if version is before or after the name
589 if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
590 $version= $matches['version'][0];
591 } else {
592 $version= $matches['version'][1];
593 }
594 } else {
595 $version= $matches['version'][0];
596 }
597
598 // check if we have a number
599 if ( $version == null || $version == '' ) {
600 $version = '';
601 }
602
603 return array(
604 'userAgent' => $u_agent,
605 'name' => $bname,
606 'version' => $version,
607 'platform' => $platform,
608 'pattern' => $pattern
609 );
610 }
611
612 /**
613 * Get form notification merge tags
614 *
615 * @since 1.0
616 *
617 * @return array
618 */
619 function weforms_get_merge_tags() {
620 $tags = array(
621 'form' => array(
622 'title' => __( 'Form', 'weforms' ),
623 'tags' => array(
624 'entry_id' => __( 'Entry ID', 'weforms' ),
625 'form_id' => __( 'Form ID', 'weforms' ),
626 'form_name' => __( 'Form Name', 'weforms' )
627 )
628 ),
629 'system' => array(
630 'title' => __( 'System', 'weforms' ),
631 'tags' => array(
632 'admin_email' => __( 'Site Administrator Email', 'weforms' ),
633 'date' => __( 'Date', 'weforms' ),
634 'site_name' => __( 'Site Title', 'weforms' ),
635 'site_url' => __( 'Site URL', 'weforms' ),
636 'page_title' => __( 'Embedded Page Title', 'weforms' ),
637 )
638 ),
639 'user' => array(
640 'title' => __( 'User', 'weforms' ),
641 'tags' => array(
642 'ip_address' => __( 'IP Address', 'weforms' ),
643 'user_id' => __( 'User ID', 'weforms' ),
644 'first_name' => __( 'First Name', 'weforms' ),
645 'last_name' => __( 'Last Name', 'weforms' ),
646 'display_name' => __( 'Display Name', 'weforms' ),
647 'user_email' => __( 'Email', 'weforms' ),
648 )
649 ),
650 'urls' => array(
651 'title' => __( 'URL\'s', 'weforms' ),
652 'tags' => array(
653 'url_page' => __( 'Embeded Page URL', 'weforms' ),
654 'url_referer' => __( 'Referer URL', 'weforms' ),
655 'url_login' => __( 'Login URL', 'weforms' ),
656 'url_logout' => __( 'Logout URL', 'weforms' ),
657 'url_register' => __( 'Register URL', 'weforms' ),
658 'url_lost_password' => __( 'Lost Password URL', 'weforms' ),
659 )
660 ),
661 );
662
663 return apply_filters( 'wpuf_cf_merge_tags', $tags );
664 }
665
666 /**
667 * Record a form view count
668 *
669 * @param int $form_id
670 *
671 * @return void
672 */
673 function weforms_track_form_view( $form_id ) {
674 // don't track administrators
675 if ( current_user_can( 'administrator' ) ) {
676 return;
677 }
678
679 // ability to turn this off if someone doesn't like this tracking
680 $is_enabled = apply_filters( 'weforms_track_form_view', true );
681
682 if ( !$is_enabled ) {
683 return;
684 }
685
686 // increase the count
687 $meta_key = '_weforms_view_count';
688 $number = (int) get_post_meta( $form_id, $meta_key, true );
689
690 update_post_meta( $form_id, $meta_key, ( $number + 1 ) );
691 }
692
693 /**
694 * Get form view count of a form
695 *
696 * @param int $form_id
697 *
698 * @return int
699 */
700 function weforms_get_form_views( $form_id ) {
701 return (int) get_post_meta( $form_id, '_weforms_view_count', true );
702 }
703
704 /**
705 * Get the weForms global settings
706 *
707 * @param string $key
708 * @param mixed $default
709 *
710 * @return mixed
711 */
712 function weforms_get_settings( $key = '', $default = '' ) {
713
714 $settings = get_option( 'weforms_settings', array() );
715 $settings = apply_filters( 'weforms_get_settings', $settings );
716
717 if ( empty( $key ) ) {
718 return $settings;
719 }
720
721 if ( isset( $settings[ $key ] ) ) {
722 return $settings[ $key ];
723 }
724
725 return $default;
726 }
727
728 /**
729 * Form access capability for forms
730 *
731 * @since 1.0.5
732 *
733 * @return string
734 */
735 function weforms_form_access_capability() {
736 return apply_filters( 'weforms_form_access_capability', 'manage_options' );
737 }
738
739 /**
740 * Clear the buffer
741 *
742 * prevents ajax breakage and endless loading icon. A LIFE SAVER!!!
743 *
744 * @since 1.1.0
745 *
746 * @return void
747 */
748 function weforms_clear_buffer() {
749 ob_clean();
750 }
751
752 /**
753 * Get the client IP address
754 *
755 * @since 1.1.0
756 *
757 * @return string
758 */
759 function weforms_get_client_ip() {
760 $ipaddress = '';
761
762 if ( isset($_SERVER['HTTP_CLIENT_IP'] ) ) {
763 $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
764 } else if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
765 $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
766 } else if ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
767 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
768 } else if ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
769 $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
770 } else if ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
771 $ipaddress = $_SERVER['HTTP_FORWARDED'];
772 } else if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
773 $ipaddress = $_SERVER['REMOTE_ADDR'];
774 } else {
775 $ipaddress = 'UNKNOWN';
776 }
777
778 return $ipaddress;
779 }
780
781 /**
782 * Save form fields
783 *
784 * @since 1.1.0
785 *
786 * @param int $form_id
787 * @param array $field
788 * @param int $field_id
789 * @param int $order
790 *
791 * @return int ID of updated or inserted post
792 */
793 function weforms_insert_form_field( $form_id, $field = array(), $field_id = null, $order = 0 ) {
794
795 $args = array(
796 'post_type' => 'wpuf_input',
797 'post_parent' => $form_id,
798 'post_status' => 'publish',
799 'post_content' => maybe_serialize( wp_unslash( $field ) ),
800 'menu_order' => $order
801 );
802
803 if ( $field_id ) {
804 $args['ID'] = $field_id;
805 }
806
807 if ( $field_id ) {
808 return wp_update_post( $args );
809 } else {
810 return wp_insert_post( $args );
811 }
812 }
813
814 /**
815 * Allowed upload extensions
816 *
817 * @return array
818 */
819 function weforms_allowed_extensions() {
820 $extesions = array(
821 'images' => array(
822 'ext' => 'jpg,jpeg,gif,png,bmp',
823 'label' => __( 'Images', 'weforms' )
824 ),
825 'audio' => array(
826 'ext' => 'mp3,wav,ogg,wma,mka,m4a,ra,mid,midi',
827 'label' => __( 'Audio', 'weforms' )
828 ),
829 'video' => array(
830 'ext' => 'avi,divx,flv,mov,ogv,mkv,mp4,m4v,divx,mpg,mpeg,mpe',
831 'label' => __( 'Videos', 'weforms' )
832 ),
833 'pdf' => array(
834 'ext' => 'pdf',
835 'label' => __( 'PDF', 'weforms' )
836 ),
837 'office' => array(
838 'ext' => 'doc,ppt,pps,xls,mdb,docx,xlsx,pptx,odt,odp,ods,odg,odc,odb,odf,rtf,txt',
839 'label' => __( 'Office Documents', 'weforms' )
840 ),
841 'zip' => array(
842 'ext' => 'zip,gz,gzip,rar,7z',
843 'label' => __( 'Zip Archives' )
844 ),
845 'exe' => array(
846 'ext' => 'exe',
847 'label' => __( 'Executable Files', 'weforms' )
848 ),
849 'csv' => array(
850 'ext' => 'csv',
851 'label' => __( 'CSV', 'weforms' )
852 )
853 );
854
855 return apply_filters( 'weforms_allowed_extensions', $extesions );
856 }
857
858 /**
859 * Get form integration settings
860 *
861 * @since 1.1.0
862 *
863 * @param int $form_id
864 *
865 * @return array
866 */
867 function weforms_get_form_integrations( $form_id ) {
868 $integrations = get_post_meta( $form_id, 'integrations', true );
869
870 if ( ! $integrations ) {
871 return array();
872 }
873
874 return $integrations;
875 }
876
877
878 /**
879 * Check if an integration is active
880 *
881 * @since 1.1.0
882 *
883 * @param int $form_id
884 * @param string $integration_id
885 *
886 * @return boolean
887 */
888 function weforms_is_integration_active( $form_id, $integration_id ) {
889 $integrations = weforms_get_form_integrations( $form_id );
890
891 if ( ! $integrations ) {
892 return false;
893 }
894
895 foreach ($integrations as $id => $integration) {
896 if ( $integration_id == $id && $integration->enabled == true ) {
897 return $integration;
898 }
899 }
900
901 return false;
902 }
903
904
905 /**
906 * Get Flat UI Colors
907 *
908 * @return array
909 */
910 function weforms_get_flat_ui_colors() {
911 return array( '#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#34495e' );
912 }
913
914 /**
915 * Get default form settings
916 *
917 * @return array
918 */
919 function weforms_get_default_form_settings() {
920 return apply_filters( 'weforms_get_default_form_settings', array(
921 'redirect_to' => 'same',
922 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
923 'page_id' => '',
924 'url' => '',
925 'submit_text' => __( 'Submit Query', 'weforms' ),
926 'schedule_form' => 'false',
927 'schedule_start' => '',
928 'schedule_end' => '',
929 'sc_pending_message' => __( 'Form submission hasn\'t been started yet', 'weforms' ),
930 'sc_expired_message' => __( 'Form submission is now closed.', 'weforms' ),
931 'require_login' => 'false',
932 'req_login_message' => __( 'You need to login to submit a query.', 'weforms' ),
933 'limit_entries' => 'false',
934 'limit_number' => '100',
935 'limit_message' => __( 'Sorry, we have reached the maximum number of submissions.', 'weforms' ),
936 'label_position' => 'above',
937 'enable_multistep' => false,
938 'multistep_progressbar_type' => 'progressive',
939
940 // payment
941
942 'payment_paypal_images' => 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg',
943
944 'payment_paypal_label' => __( 'PayPal', 'weforms' ),
945 'payment_stripe_label' => __( 'Credit Card', 'weforms' ),
946 'payment_stripe_images' => array('visa','mastercard','amex','discover'),
947
948 'payment_stripe_deactivate' => '',
949 'stripe_mode' => 'live',
950 'stripe_page_id' => '',
951
952 'stripe_override_keys' => '',
953 'stripe_email' => '',
954 'stripe_key' => '',
955 'stripe_secret_key' => '',
956 'stripe_key_test' => '',
957 'stripe_secret_key_test' => '',
958
959 'stripe_prefill_email' => '',
960 'stripe_user_email_field' => '',
961
962 'payment_paypal_deactivate' => '',
963 'paypal_mode' => 'live',
964 'paypal_type' => '_cart',
965
966 'paypal_override' => '',
967 'paypal_email' => '',
968
969 'paypal_page_id' => '',
970
971 'paypal_prefill_email' => '',
972 'paypal_user_email_field' => '',
973 ));
974 }
975
976 /**
977 * Get default form settings
978 *
979 * @return array
980 */
981 function weforms_get_default_form_notification() {
982 return apply_filters( 'weforms_get_default_form_notification', array(
983 'active' => 'true',
984 'name' => __( 'Admin Notification', 'weforms' ),
985 'subject' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
986 'to' => '{admin_email}',
987 'replyTo' => '{field:email}',
988 'message' => '{all_fields}',
989 'fromName' => '{site_name}',
990 'fromAddress' => '{admin_email}',
991 'cc' => '',
992 'bcc' => '',
993 'weforms_cond' => array(
994 'condition_status' => 'no',
995 'cond_logic' => 'any',
996 'conditions' => array(
997 array(
998 'name' => '',
999 'operator' => '=',
1000 'option' => ''
1001 )
1002 )
1003 )
1004 )
1005 );
1006 }