PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.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
← All changes | includes/functions.php +1070 -1307 1.6.51.2.1 View file →
@@ -1,1307 +1,1070 @@
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 - $categories = [
23 - 'default' => [
24 - 'name' => 'Default Templates',
25 - 'icon' => 'fa fa-bars',
26 - ],
27 - 'registration' => [
28 - 'name' => 'Registration Templates',
29 - 'icon' => 'fa fa-user-plus',
30 - ],
31 - 'application' => [
32 - 'name' => 'Application Templates',
33 - 'icon' => 'fa fa-address-card-o',
34 - ],
35 - 'request' => [
36 - 'name' => 'Request Templates',
37 - 'icon' => 'fa fa-hand-paper-o',
38 - ],
39 - 'event' => [
40 - 'name' => 'Event Templates',
41 - 'icon' => 'fa fa-calendar',
42 - ],
43 - 'feedback' => [
44 - 'name' => 'Feedback Templates',
45 - 'icon' => 'fa fa-comments',
46 - ],
47 - 'employment' => [
48 - 'name' => 'Employment Templates',
49 - 'icon' => 'fa fa-suitcase',
50 - ],
51 - 'payment' => [
52 - 'name' => 'Payment Templates',
53 - 'icon' => 'fa fa-money',
54 - ],
55 - 'reservation' => [
56 - 'name' => 'Reservation Templates',
57 - 'icon' => 'fa fa-bandcamp',
58 - ],
59 - 'others' => [
60 - 'name' => 'Others Templates',
61 - 'icon' => 'fa fa-info-circle',
62 - ],
63 - ];
64 -
65 - return apply_filters( 'weforms_form_template_categories', $categories );
66 -}
67 -
68 -/**
69 - * Get entries by a form_id
70 - *
71 - * @param int $form_id
72 - * @param array $args
73 - *
74 - * @return object
75 - */
76 -function weforms_get_form_entries( $form_id, $args = [] ) {
77 - global $wpdb;
78 -
79 - $defaults = [
80 - 'number' => 10,
81 - 'offset' => 0,
82 - 'orderby' => 'created_at',
83 - 'status' => 'publish',
84 - 'order' => 'DESC',
85 - ];
86 -
87 - $r = wp_parse_args( $args, $defaults );
88 -
89 - $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at
90 - FROM ' . $wpdb->weforms_entries .
91 - ' WHERE form_id = ' . $form_id . ' AND status = \'' . $r['status'] . '\'' .
92 - ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'];
93 -
94 - if ( !empty( $r['offset'] ) && !empty( $r['number'] ) ) {
95 - $query .= ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
96 - }
97 -
98 - $results = $wpdb->get_results( $query );
99 -
100 - return $results;
101 -}
102 -
103 -/**
104 - * Count all entries from weForms_entries table
105 - *
106 - * @param array $args
107 - *
108 - * @return int $number
109 - */
110 -function weforms_count_entries( $args = [] ) {
111 - global $wpdb;
112 -
113 - $defaults = [
114 - 'number' => -1,
115 - 'offset' => 0,
116 - 'orderby' => 'created_at',
117 - 'status' => 'publish',
118 - 'order' => 'DESC',
119 - ];
120 -
121 - $r = wp_parse_args( $args, $defaults );
122 -
123 - $query = 'SELECT id, form_id, user_id, INET_NTOA( user_ip ) as ip_address, created_at
124 - FROM ' . $wpdb->weforms_entries .
125 - ' WHERE status = \'' . $r['status'] . '\'' .
126 - ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'];
127 -
128 - if ( !empty( $r['offset'] ) && !empty( $r['number'] ) ) {
129 - $query .= ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
130 - }
131 -
132 - $results = $wpdb->get_results( $query );
133 -
134 - return count( $results );
135 -}
136 -
137 -/**
138 - * Get payments by a form_id
139 - *
140 - * @param int $form_id
141 - * @param array $args
142 - *
143 - * @return object
144 - */
145 -function weforms_get_form_payments( $form_id, $args = [] ) {
146 - global $wpdb;
147 -
148 - $defaults = [
149 - 'number' => 10,
150 - 'offset' => 0,
151 - 'orderby' => 'created_at',
152 - 'order' => 'DESC',
153 - ];
154 -
155 - $r = wp_parse_args( $args, $defaults );
156 -
157 - $query = 'SELECT * FROM ' . $wpdb->prefix . 'weforms_payments' .
158 - ' WHERE form_id = ' . $form_id .
159 - ' ORDER BY ' . $r['orderby'] . ' ' . $r['order'] .
160 - ' LIMIT ' . $r['offset'] . ', ' . $r['number'];
161 -
162 - $results = $wpdb->get_results( $query );
163 -
164 - return $results;
165 -}
166 -
167 -/**
168 - * Get an entry by id
169 - *
170 - * @param int $entry_id
171 - *
172 - * @return object
173 - */
174 -function weforms_get_entry( $entry_id ) {
175 - global $wpdb;
176 -
177 - $cache_key = 'weforms-entry-' . $entry_id;
178 - $entry = wp_cache_get( $cache_key, 'weforms' );
179 -
180 - if ( false === $entry ) {
181 - $query = 'SELECT id, form_id, user_id, user_device, referer, INET_NTOA( user_ip ) as ip_address, created_at
182 - FROM ' . $wpdb->weforms_entries . '
183 - WHERE id = %d';
184 -
185 - $entry = $wpdb->get_row( $wpdb->prepare( $query, $entry_id ) );
186 - wp_cache_set( $cache_key, $entry );
187 - }
188 -
189 - return $entry;
190 -}
191 -
192 -/**
193 - * Insert a new entry
194 - *
195 - * @param array $args
196 - * @param array $fields
197 - *
198 - * @return WP_Error|int
199 - */
200 -function weforms_insert_entry( $args, $fields = [] ) {
201 - global $wpdb;
202 -
203 - $browser = weforms_get_browser();
204 -
205 - $defaults = [
206 - 'form_id' => 0,
207 - 'user_id' => get_current_user_id(),
208 - 'user_ip' => ip2long( weforms_get_client_ip() ),
209 - 'user_device' => $browser['name'] . '/' . $browser['platform'],
210 - 'referer' => isset( $_SERVER['HTTP_REFERER'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '',
211 - 'created_at' => current_time( 'mysql' )
212 - ];
213 -
214 - $r = wp_parse_args( $args, $defaults );
215 -
216 - if ( !$r['form_id'] ) {
217 - return new WP_Error( 'no-form-id', __( 'No form ID was found.', 'weforms' ) );
218 - }
219 -
220 - if ( !$fields ) {
221 - return new WP_Error( 'no-fields', __( 'No form fields were found.', 'weforms' ) );
222 - }
223 -
224 - $success = $wpdb->insert( $wpdb->weforms_entries, $r );
225 -
226 - if ( is_wp_error( $success ) || !$success ) {
227 - return new WP_Error( 'could-not-create', __( 'Could not create an entry', 'weforms' ) );
228 - }
229 -
230 - $entry_id = $wpdb->insert_id;
231 -
232 - foreach ( $fields as $key => $value ) {
233 - weforms_add_entry_meta( $entry_id, $key, $value );
234 - }
235 -
236 - return $entry_id;
237 -}
238 -
239 -/**
240 - * Change an entry status
241 - *
242 - * @param int $entry_id
243 - * @param string $status
244 - *
245 - * @return int|bool
246 - */
247 -function weforms_change_entry_status( $entry_id, $status ) {
248 - global $wpdb;
249 -
250 - return $wpdb->update(
251 - $wpdb->weforms_entries,
252 - [
253 - 'status' => $status,
254 - ],
255 - [
256 - 'id' => $entry_id,
257 - ],
258 - [ '%s' ],
259 - [ '%d' ]
260 - );
261 -}
262 -
263 -/**
264 - * Delete an entry
265 - *
266 - * @param int $entry_id
267 - *
268 - * @return int|bool
269 - */
270 -function weforms_delete_entry( $entry_id ) {
271 - global $wpdb;
272 -
273 - weforms_delete_entry_attachments( $entry_id );
274 -
275 - $deleted = $wpdb->delete(
276 - $wpdb->weforms_entries, [
277 - 'id' => $entry_id,
278 - ], [ '%d' ]
279 - );
280 -
281 - if ( $deleted ) {
282 - $wpdb->delete(
283 - $wpdb->weforms_entrymeta, [
284 - 'weforms_entry_id' => $entry_id,
285 - ], [ '%d' ]
286 - );
287 - }
288 -
289 - return $deleted;
290 -}
291 -
292 -/**
293 - * Delete attachments of an entry
294 - *
295 - * @param int $entry_id
296 - *
297 - * @since 1.3.5
298 - */
299 -function weforms_delete_entry_attachments( $entry_id ) {
300 - $entry = weforms_get_entry( $entry_id );
301 - $fields = weforms_get_form_field_labels( $entry->form_id );
302 -
303 - if ( !$fields ) {
304 - return false;
305 - }
306 -
307 - foreach ( $fields as $meta_key => $field ) {
308 - $value = weforms_get_entry_meta( $entry_id, $meta_key, true );
309 -
310 - if ( in_array( $field['type'], [ 'image_upload', 'file_upload' ] ) ) {
311 - if ( is_array( $value ) && $value ) {
312 - foreach ( $value as $attachment_id ) {
313 - wp_delete_attachment( $attachment_id, true );
314 - }
315 - }
316 - }
317 - }
318 -}
319 -
320 -/**
321 - * Add meta data field to an entry.
322 - *
323 - * @param int $entry_id entry ID
324 - * @param string $meta_key metadata name
325 - * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
326 - * @param bool $unique Optional. Whether the same key should not be added.
327 - * Default false.
328 - *
329 - * @return int|false meta ID on success, false on failure
330 - */
331 -function weforms_add_entry_meta( $entry_id, $meta_key, $meta_value, $unique = false ) {
332 - return add_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $unique );
333 -}
334 -
335 -/**
336 - * Retrieve entry meta field for a entry.
337 - *
338 - * @param int $entry_id entry ID
339 - * @param string $key Optional. The meta key to retrieve. By default, returns
340 - * data for all keys. Default empty.
341 - * @param bool $single Optional. Whether to return a single value. Default false.
342 - *
343 - * @return mixed Will be an array if $single is false. Will be value of meta data
344 - * field if $single is true.
345 - */
346 -function weforms_get_entry_meta( $entry_id, $key = '', $single = false ) {
347 - return get_metadata( 'weforms_entry', $entry_id, $key, $single );
348 -}
349 -
350 -/**
351 - * Update entry meta field based on entry ID.
352 - *
353 - * Use the $prev_value parameter to differentiate between meta fields with the
354 - * same key and entry ID.
355 - *
356 - * If the meta field for the entry does not exist, it will be added.
357 - *
358 - * @param int $entry_id entry ID
359 - * @param string $meta_key metadata key
360 - * @param mixed $meta_value Metadata value. Must be serializable if non-scalar.
361 - * @param mixed $prev_value Optional. Previous value to check before removing.
362 - * Default empty.
363 - *
364 - * @return int|bool meta ID if the key didn't exist, true on successful update,
365 - * false on failure
366 - */
367 -function weforms_update_entry_meta( $entry_id, $meta_key, $meta_value, $prev_value = '' ) {
368 - return update_metadata( 'weforms_entry', $entry_id, $meta_key, $meta_value, $prev_value );
369 -}
370 -
371 -/**
372 - * Delete everything from entry meta matching meta key.
373 - *
374 - * @param string $entry_meta_key key to search for when deleting
375 - *
376 - * @return bool whether the entry meta key was deleted from the database
377 - */
378 -function weforms_delete_entry_meta_by_key( $meta_key ) {
379 - return delete_metadata( 'weforms_entry', null, $meta_key, '', true );
380 -}
381 -
382 -/**
383 - * Retrieve entry meta fields, based on entry ID.
384 - *
385 - * The entry meta fields are retrieved from the cache where possible,
386 - * so the function is optimized to be called more than once.
387 - *
388 - * @since 1.2.0
389 - *
390 - * @param int $entry_id optional
391 - *
392 - * @return array entry meta for the given entry
393 - */
394 -function weforms_get_entry_custom( $entry_id = 0 ) {
395 - $entry_id = absint( $entry_id );
396 -
397 - return weforms_get_entry_meta( $entry_id );
398 -}
399 -
400 -/**
401 - * Retrieve meta field names for a entry.
402 - *
403 - * If there are no meta fields, then nothing (null) will be returned.
404 - *
405 - * @param int $entry_id optional
406 - *
407 - * @return array|void array of the keys, if retrieved
408 - */
409 -function weforms_get_entry_custom_keys( $entry_id = 0 ) {
410 - $custom = weforms_get_entry_custom( $entry_id );
411 -
412 - if ( !is_array( $custom ) ) {
413 - return false;
414 - }
415 -
416 - if ( $keys = array_keys( $custom ) ) {
417 - return $keys;
418 - }
419 -}
420 -
421 -/**
422 - * Get the number of entries count on a form
423 - *
424 - * @param int $form_id
425 - *
426 - * @return int
427 - */
428 -function weforms_count_form_entries( $form_id, $status = 'publish' ) {
429 - global $wpdb;
430 -
431 - return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM ' . $wpdb->weforms_entries . ' WHERE form_id = %d AND status = %s', $form_id, $status ) );
432 -}
433 -
434 -/**
435 - * Get the number of entries count on a form
436 - *
437 - * @param int $form_id
438 - *
439 - * @return int
440 - */
441 -function weforms_count_form_payments( $form_id ) {
442 - global $wpdb;
443 -
444 - if ( !class_exists( 'WeForms_Payment' ) ) {
445 - return 0;
446 - }
447 -
448 - return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count(id) FROM ' . $wpdb->prefix . 'weforms_payments' . ' WHERE form_id = %d', $form_id ) );
449 -}
450 -
451 -/**
452 - * Get the form author details
453 - *
454 - * @param int $form_id
455 - *
456 - * @return array
457 - */
458 -function weforms_get_form_author_details( $form_id ) {
459 - if ( empty( $form_id ) ) {
460 - return;
461 - }
462 -
463 - $author_details = [];
464 - $form = get_post( $form_id );
465 - $author_id = $form->post_author;
466 -
467 - $author_details['username'] = get_the_author_meta( 'user_login', $author_id );
468 - $author_details['avatar'] = get_avatar_url( $author_id );
469 -
470 - return $author_details;
471 -}
472 -
473 -/**
474 - * Get table column heads for a form
475 - *
476 - * For now, return only text type fields
477 - *
478 - * @param int $form_id
479 - *
480 - * @return array
481 - */
482 -function weforms_get_entry_columns( $form_id, $limit = 6 ) {
483 - $fields = weforms()->form->get( $form_id )->get_fields();
484 - $columns = [];
485 -
486 - // filter by input types
487 - if ( $limit ) {
488 - $fields = array_filter( $fields, function ( $item ) {
489 - return in_array( $item['template'], [ 'text_field', 'name_field', 'dropdown_field', 'radio_field', 'email_address', 'url_field', 'column_field' ] );
490 - } );
491 - }
492 -
493 - if ( $fields ) {
494 - foreach ( $fields as $field ) {
495 - if ( $field['template'] == 'column_field' ) {
496 - foreach ( $field['inner_fields'] as $c_field ) {
497 - $columns[ $c_field[0]['name'] ] = $c_field[0]['label'];
498 - }
499 - continue;
500 - }
501 - $columns[ $field['name'] ] = $field['label'];
502 - }
503 - }
504 -
505 - // if passed 0/false, return all columns
506 - if ( $limit && sizeof( $columns ) > $limit ) {
507 - $columns = array_slice( $columns, 0, $limit ); // max 6 columns
508 - }
509 -
510 - return apply_filters( 'weforms_get_entry_columns', $columns, $form_id );
511 -}
512 -
513 -/**
514 - * Get table column heads for a form
515 - *
516 - * For now, return only text type fields
517 - *
518 - * @param int $form_id
519 - *
520 - * @return array
521 - */
522 -function weforms_get_payment_columns( $form_id, $limit = 6 ) {
523 - $fields = weforms()->form->get( $form_id )->get_fields();
524 - $columns = [];
525 -
526 - // filter by input types
527 - if ( $limit ) {
528 - $fields = array_filter( $fields, function ( $item ) {
529 - return in_array( $item['template'], [ 'text_field', 'name_field', 'dropdown_field', 'radio_field', 'email_address', 'url_field' ] );
530 - } );
531 - }
532 -
533 - if ( $fields ) {
534 - foreach ( $fields as $field ) {
535 - $columns[ $field['name'] ] = $field['label'];
536 - }
537 - }
538 -
539 - // if passed 0/false, return all collumns
540 - if ( $limit && sizeof( $columns ) > $limit ) {
541 - $columns = array_slice( $columns, 0, $limit ); // max 6 columns
542 - }
543 -
544 - return apply_filters( 'weforms_get_entry_columns', $columns, $form_id );
545 -}
546 -
547 -/**
548 - * Get fields from a form by it's meta key
549 - *
550 - * @param int $form_id
551 - *
552 - * @return array
553 - */
554 -function weforms_get_form_field_labels( $form_id ) {
555 - $fields = weforms()->form->get( $form_id )->get_fields();
556 - $exclude = [ 'step_start', 'section_break', 'recaptcha', 'shortcode', 'action_hook' ];
557 -
558 - if ( !$fields ) {
559 - return false;
560 - }
561 -
562 - $data = [];
563 -
564 - foreach ( $fields as $field ) {
565 - if ( empty( $field['name'] ) ) {
566 - continue;
567 - }
568 -
569 - // exclude the fields
570 - if ( in_array( $field['template'], $exclude ) ) {
571 - continue;
572 - }
573 -
574 - $data[ $field['name'] ] = [
575 - 'label' => $field['label'],
576 - 'type' => $field['template'],
577 - ];
578 - }
579 -
580 - return $data;
581 -}
582 -
583 -/**
584 - * Get data from an entry
585 - *
586 - * @param int $entry_id
587 - * @param int $form_id
588 - *
589 - * @return false|array
590 - */
591 -function weforms_get_entry_data( $entry_id ) {
592 - $data = [];
593 - $entry = weforms_get_entry( $entry_id );
594 - $fields = weforms_get_form_field_labels( $entry->form_id );
595 -
596 - if ( !$fields ) {
597 - return false;
598 - }
599 -
600 - foreach ( $fields as $meta_key => $field ) {
601 - $value = weforms_get_entry_meta( $entry_id, $meta_key, true );
602 -
603 - if ( $field['type'] == 'textarea' ) {
604 - $data[ $meta_key ] = weforms_format_text( $value );
605 - } elseif ( $field['type'] == 'name' ) {
606 - $data[ $meta_key ] = implode( ' ', explode( WeForms::$field_separator, $value ) );
607 - } elseif ( in_array( $field['type'], [ 'image_upload', 'file_upload' ] ) ) {
608 - $data[ $meta_key ] = '';
609 -
610 - if ( is_array( $value ) && $value ) {
611 - foreach ( $value as $attachment_id ) {
612 - if ( $field['type'] == 'image_upload' ) {
613 - $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
614 - } else {
615 - $thumb = get_post_field( 'post_title', $attachment_id );
616 - }
617 -
618 - $full_size = wp_get_attachment_url( $attachment_id );
619 -
620 - $data[ $meta_key ] .= sprintf( '<a href="%s" target="_blank">%s</a> ', $full_size, $thumb );
621 - }
622 - }
623 - } elseif ( in_array( $field['type'], [ 'checkbox', 'multiselect' ] ) ) {
624 - $data[ $meta_key ] = explode( WeForms::$field_separator, $value );
625 - } elseif ( $field['type'] == 'map' ) {
626 - list( $lat, $long ) = explode( ',', $value );
627 -
628 - $data[ $meta_key ] = [
629 - 'lat' => $lat,
630 - 'long' => $long,
631 - ];
632 - } else {
633 - $data[ $meta_key ] = $value;
634 - }
635 - }
636 -
637 - return [
638 - 'fields' => $fields,
639 - 'data' => $data,
640 - ];
641 -}
642 -
643 -/**
644 - * Format a text and apply WP function callbacks
645 - *
646 - * @param string $content
647 - *
648 - * @return string
649 - */
650 -function weforms_format_text( $content ) {
651 - $content = wptexturize( $content );
652 - $content = convert_smilies( $content );
653 - $content = wpautop( $content );
654 - $content = make_clickable( $content );
655 -
656 - return $content;
657 -}
658 -
659 -/**
660 - * Get User Agent browser and OS type
661 - *
662 - * @return array
663 - */
664 -function weforms_get_browser() {
665 - $u_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
666 - $bname = 'Unknown';
667 - $platform = 'Unknown';
668 - $version = '';
669 -
670 - // first get the platform
671 - if ( preg_match( '/linux/i', $u_agent ) ) {
672 - $platform = 'Linux';
673 - } elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
674 - $platform = 'MAC OS';
675 - } elseif ( preg_match( '/windows|win32/i', $u_agent ) ) {
676 - $platform = 'Windows';
677 - }
678 -
679 - // next get the name of the useragent yes seperately and for good reason
680 - if ( preg_match( '/MSIE/i', $u_agent ) && !preg_match( '/Opera/i', $u_agent ) ) {
681 - $bname = 'Internet Explorer';
682 - $ub = 'MSIE';
683 - } elseif ( preg_match( '/Trident/i', $u_agent ) ) {
684 - // this condition is for IE11
685 - $bname = 'Internet Explorer';
686 - $ub = 'rv';
687 - } elseif ( preg_match( '/Firefox/i', $u_agent ) ) {
688 - $bname = 'Mozilla Firefox';
689 - $ub = 'Firefox';
690 - } elseif ( preg_match( '/Chrome/i', $u_agent ) ) {
691 - $bname = 'Google Chrome';
692 - $ub = 'Chrome';
693 - } elseif ( preg_match( '/Safari/i', $u_agent ) ) {
694 - $bname = 'Apple Safari';
695 - $ub = 'Safari';
696 - } elseif ( preg_match( '/Opera/i', $u_agent ) ) {
697 - $bname = 'Opera';
698 - $ub = 'Opera';
699 - } elseif ( preg_match( '/Netscape/i', $u_agent ) ) {
700 - $bname = 'Netscape';
701 - $ub = 'Netscape';
702 - }
703 -
704 - // finally get the correct version number
705 - // Added "|:"
706 - $known = [ 'Version', $ub, 'other' ];
707 - $pattern = '#(?<browser>' . join( '|', $known ) .
708 - ')[/|: ]+(?<version>[0-9.|a-zA-Z.]*)#';
709 -
710 - if ( !preg_match_all( $pattern, $u_agent, $matches ) ) {
711 - // we have no matching number just continue
712 - }
713 -
714 - // see how many we have
715 - $i = count( $matches['browser'] );
716 -
717 - if ( $i != 1 ) {
718 - // we will have two since we are not using 'other' argument yet
719 - // see if version is before or after the name
720 - if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
721 - $version = $matches['version'][0];
722 - } else {
723 - $version = $matches['version'][1];
724 - }
725 - } else {
726 - $version = $matches['version'][0];
727 - }
728 -
729 - // check if we have a number
730 - if ( $version == null || $version == '' ) {
731 - $version = '';
732 - }
733 -
734 - return [
735 - 'userAgent' => $u_agent,
736 - 'name' => $bname,
737 - 'version' => $version,
738 - 'platform' => $platform,
739 - 'pattern' => $pattern,
740 - ];
741 -}
742 -
743 -/**
744 - * Get form notification merge tags
745 - *
746 - * @since 1.0
747 - *
748 - * @return array
749 - */
750 -function weforms_get_merge_tags() {
751 - $tags = [
752 - 'form' => [
753 - 'title' => __( 'Form', 'weforms' ),
754 - 'tags' => [
755 - 'entry_id' => __( 'Entry ID', 'weforms' ),
756 - 'form_id' => __( 'Form ID', 'weforms' ),
757 - 'form_name' => __( 'Form Name', 'weforms' ),
758 - ],
759 - ],
760 - 'system' => [
761 - 'title' => __( 'System', 'weforms' ),
762 - 'tags' => [
763 - 'admin_email' => __( 'Site Administrator Email', 'weforms' ),
764 - 'date' => __( 'Date', 'weforms' ),
765 - 'site_name' => __( 'Site Title', 'weforms' ),
766 - 'site_url' => __( 'Site URL', 'weforms' ),
767 - 'page_title' => __( 'Embedded Page Title', 'weforms' ),
768 - ],
769 - ],
770 - 'user' => [
771 - 'title' => __( 'User', 'weforms' ),
772 - 'tags' => [
773 - 'ip_address' => __( 'IP Address', 'weforms' ),
774 - 'user_id' => __( 'User ID', 'weforms' ),
775 - 'first_name' => __( 'First Name', 'weforms' ),
776 - 'last_name' => __( 'Last Name', 'weforms' ),
777 - 'display_name' => __( 'Display Name', 'weforms' ),
778 - 'user_email' => __( 'Email', 'weforms' ),
779 - ],
780 - ],
781 - 'urls' => [
782 - 'title' => __( 'URL\'s', 'weforms' ),
783 - 'tags' => [
784 - 'url_page' => __( 'Embeded Page URL', 'weforms' ),
785 - 'url_referer' => __( 'Referer URL', 'weforms' ),
786 - 'url_login' => __( 'Login URL', 'weforms' ),
787 - 'url_logout' => __( 'Logout URL', 'weforms' ),
788 - 'url_register' => __( 'Register URL', 'weforms' ),
789 - 'url_lost_password' => __( 'Lost Password URL', 'weforms' ),
790 - 'personal_data_erase_confirm_url' => __( 'Personal Data Erase Confirmation URL', 'weforms' ),
791 - 'personal_data_export_confirm_url' => __( 'Personal Data Export Confirmation URL', 'weforms' ),
792 - ],
793 - ],
794 - ];
795 -
796 - return apply_filters( 'wpuf_cf_merge_tags', $tags );
797 -}
798 -
799 -/**
800 - * Record a form view count
801 - *
802 - * @param int $form_id
803 - *
804 - * @return void
805 - */
806 -function weforms_track_form_view( $form_id ) {
807 - // don't track administrators
808 - if ( current_user_can( 'administrator' ) ) {
809 - return;
810 - }
811 -
812 - // ability to turn this off if someone doesn't like this tracking
813 - $is_enabled = apply_filters( 'weforms_track_form_view', true );
814 -
815 - if ( !$is_enabled ) {
816 - return;
817 - }
818 -
819 - // increase the count
820 - $meta_key = '_weforms_view_count';
821 - $number = (int) get_post_meta( $form_id, $meta_key, true );
822 -
823 - update_post_meta( $form_id, $meta_key, ( $number + 1 ) );
824 -}
825 -
826 -/**
827 - * Get form view count of a form
828 - *
829 - * @param int $form_id
830 - *
831 - * @return int
832 - */
833 -function weforms_get_form_views( $form_id ) {
834 - return (int) get_post_meta( $form_id, '_weforms_view_count', true );
835 -}
836 -
837 -/**
838 - * Get the weForms global settings
839 - *
840 - * @param string $key
841 - * @param mixed $default
842 - *
843 - * @return mixed
844 - */
845 -function weforms_get_settings( $key = '', $default = '' ) {
846 - $settings = get_option( 'weforms_settings', [] );
847 - $settings = apply_filters( 'weforms_get_settings', $settings );
848 -
849 - if ( empty( $key ) ) {
850 - return $settings;
851 - }
852 -
853 - if ( isset( $settings[ $key ] ) ) {
854 - return $settings[ $key ];
855 - }
856 -
857 - return $default;
858 -}
859 -
860 -/**
861 - * Update Settings
862 - *
863 - * @param array $updated_settings
864 - *
865 - * @return array
866 - */
867 -function weforms_update_settings( $updated_settings = [] ) {
868 - $previuos_settings = weforms_get_settings();
869 -
870 - $settings = array_merge( $previuos_settings, $updated_settings );
871 -
872 - update_option( 'weforms_settings', $settings );
873 -
874 - return $settings;
875 -}
876 -
877 -/**
878 - * Form access capability for forms
879 - *
880 - * @since 1.0.5
881 - *
882 - * @return string
883 - */
884 -function weforms_form_access_capability() {
885 - return apply_filters( 'weforms_form_access_capability', 'manage_options' );
886 -}
887 -
888 -/**
889 - * Form access capability for forms
890 - *
891 - * @since 1.2.4
892 - *
893 - * @return string
894 - */
895 -function weforms_log_file_path() {
896 - return apply_filters( 'weforms_log_file_path', WP_CONTENT_DIR . '/weforms.log' );
897 -}
898 -
899 -/**
900 - * Clear the buffer
901 - *
902 - * prevents ajax breakage and endless loading icon. A LIFE SAVER!!!
903 - *
904 - * @since 1.1.0
905 - *
906 - * @return void
907 - */
908 -function weforms_clear_buffer() {
909 - if ( ob_get_length() > 0 ) {
910 - ob_clean();
911 - }
912 -}
913 -
914 -/**
915 - * Get the client IP address
916 - *
917 - * @since 1.1.0
918 - *
919 - * @return string
920 - */
921 -function weforms_get_client_ip() {
922 - $ipaddress = '';
923 -
924 - if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
925 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
926 - } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
927 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
928 - } elseif ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
929 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED'] ) );
930 - } elseif ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
931 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['HTTP_FORWARDED_FOR'] ) );
932 - } elseif ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
933 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['HTTP_FORWARDED'] ) );
934 - } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
935 - $ipaddress = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
936 - } else {
937 - $ipaddress = 'UNKNOWN';
938 - }
939 -
940 - return $ipaddress;
941 -}
942 -
943 -/**
944 - * Save form fields
945 - *
946 - * @since 1.1.0
947 - *
948 - * @param int $form_id
949 - * @param array $field
950 - * @param int $field_id
951 - * @param int $order
952 - *
953 - * @return int ID of updated or inserted post
954 - */
955 -function weforms_insert_form_field( $form_id, $field = [], $field_id = null, $order = 0 ) {
956 - $args = [
957 - 'post_type' => 'wpuf_input',
958 - 'post_parent' => $form_id,
959 - 'post_status' => 'publish',
960 - 'post_content' => maybe_serialize( wp_unslash( $field ) ),
961 - 'menu_order' => $order,
962 - ];
963 -
964 - if ( $field_id ) {
965 - $args['ID'] = $field_id;
966 - }
967 -
968 - if ( $field_id ) {
969 - return wp_update_post( $args );
970 - } else {
971 - return wp_insert_post( $args );
972 - }
973 -}
974 -
975 -/**
976 - * Allowed upload extensions
977 - *
978 - * @return array
979 - */
980 -function weforms_allowed_extensions() {
981 - $extesions = [
982 - 'images' => [
983 - 'ext' => 'jpg,jpeg,gif,png,bmp',
984 - 'label' => __( 'Images', 'weforms' ),
985 - ],
986 - 'audio' => [
987 - 'ext' => 'mp3,wav,ogg,wma,mka,m4a,ra,mid,midi',
988 - 'label' => __( 'Audio', 'weforms' ),
989 - ],
990 - 'video' => [
991 - 'ext' => 'avi,divx,flv,mov,ogv,mkv,mp4,m4v,divx,mpg,mpeg,mpe',
992 - 'label' => __( 'Videos', 'weforms' ),
993 - ],
994 - 'pdf' => [
995 - 'ext' => 'pdf',
996 - 'label' => __( 'PDF', 'weforms' ),
997 - ],
998 - 'office' => [
999 - 'ext' => 'doc,ppt,pps,xls,mdb,docx,xlsx,pptx,odt,odp,ods,odg,odc,odb,odf,rtf,txt',
1000 - 'label' => __( 'Office Documents', 'weforms' ),
1001 - ],
1002 - 'zip' => [
1003 - 'ext' => 'zip,gz,gzip,rar,7z',
1004 - 'label' => __( 'Zip Archives', 'weforms' ),
1005 - ],
1006 - 'exe' => [
1007 - 'ext' => 'exe',
1008 - 'label' => __( 'Executable Files', 'weforms' ),
1009 - ],
1010 - 'csv' => [
1011 - 'ext' => 'csv',
1012 - 'label' => __( 'CSV', 'weforms' ),
1013 - ],
1014 - ];
1015 -
1016 - return apply_filters( 'weforms_allowed_extensions', $extesions );
1017 -}
1018 -
1019 -/**
1020 - * Get form integration settings
1021 - *
1022 - * @since 1.1.0
1023 - *
1024 - * @param int $form_id
1025 - *
1026 - * @return array
1027 - */
1028 -function weforms_get_form_integrations( $form_id ) {
1029 - $integrations = get_post_meta( $form_id, 'integrations', true );
1030 -
1031 - if ( !$integrations ) {
1032 - return [];
1033 - }
1034 -
1035 - return $integrations;
1036 -}
1037 -
1038 -/**
1039 - * Check if an integration is active
1040 - *
1041 - * @since 1.1.0
1042 - *
1043 - * @param int $form_id
1044 - * @param string $integration_id
1045 - *
1046 - * @return bool
1047 - */
1048 -function weforms_is_integration_active( $form_id, $integration_id ) {
1049 - $integrations = weforms_get_form_integrations( $form_id );
1050 -
1051 - if ( !$integrations ) {
1052 - return false;
1053 - }
1054 -
1055 - foreach ( $integrations as $id => $integration ) {
1056 - if ( $integration_id == $id && $integration->enabled == true ) {
1057 - return $integration;
1058 - }
1059 - }
1060 -
1061 - return false;
1062 -}
1063 -
1064 -/**
1065 - * Get Flat UI Colors
1066 - *
1067 - * @return array
1068 - */
1069 -function weforms_get_flat_ui_colors() {
1070 - return [ '#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#34495e' ];
1071 -}
1072 -
1073 -/**
1074 - * Get default form settings
1075 - *
1076 - * @return array
1077 - */
1078 -function weforms_get_default_form_settings() {
1079 - return apply_filters(
1080 - 'weforms_get_default_form_settings', [
1081 - 'redirect_to' => 'same',
1082 - 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
1083 - 'page_id' => '',
1084 - 'url' => '',
1085 -
1086 - 'submit_text' => __( 'Submit Query', 'weforms' ),
1087 - 'submit_button_cond' => [
1088 - 'condition_status' => 'no',
1089 - 'cond_logic' => 'any',
1090 - 'conditions' => [
1091 - [
1092 - 'name' => '',
1093 - 'operator' => '=',
1094 - 'option' => '',
1095 - ],
1096 - ],
1097 - ],
1098 -
1099 - 'schedule_form' => 'false',
1100 - 'schedule_start' => '',
1101 - 'schedule_end' => '',
1102 - 'sc_pending_message' => __( 'Form submission hasn\'t been started yet', 'weforms' ),
1103 - 'sc_expired_message' => __( 'Form submission is now closed.', 'weforms' ),
1104 - 'require_login' => 'false',
1105 - 'req_login_message' => __( 'You need to login to submit a query.', 'weforms' ),
1106 - 'limit_entries' => 'false',
1107 - 'limit_number' => '100',
1108 - 'limit_message' => __( 'Sorry, we have reached the maximum number of submissions.', 'weforms' ),
1109 - 'label_position' => 'above',
1110 - 'use_theme_css' => 'wpuf-style',
1111 - 'quiz_form' => 'no',
1112 - 'shuffle_question_order' => 'no',
1113 - 'release_grade' => 'after_submission',
1114 - 'respondent_can_see' => [ 'missed_questions', 'correct_answers', 'point_values' ],
1115 - 'total_points' => 0,
1116 - 'enable_multistep' => false,
1117 - 'multistep_progressbar_type' => 'progressive',
1118 -
1119 - // payment
1120 - 'payment_paypal_images' => 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg',
1121 -
1122 - 'payment_paypal_label' => __( 'PayPal', 'weforms' ),
1123 - 'payment_stripe_label' => __( 'Credit Card', 'weforms' ),
1124 - 'payment_stripe_images' => [ 'visa', 'mastercard', 'amex', 'discover' ],
1125 -
1126 - 'payment_stripe_deactivate' => '',
1127 - 'stripe_mode' => 'live',
1128 - 'stripe_page_id' => '',
1129 -
1130 - 'stripe_override_keys' => '',
1131 - 'stripe_email' => '',
1132 - 'stripe_key' => '',
1133 - 'stripe_secret_key' => '',
1134 - 'stripe_key_test' => '',
1135 - 'stripe_secret_key_test' => '',
1136 -
1137 - 'stripe_prefill_email' => '',
1138 - 'stripe_user_email_field' => '',
1139 -
1140 - 'payment_paypal_deactivate' => '',
1141 - 'paypal_mode' => 'live',
1142 - 'paypal_type' => '_cart',
1143 -
1144 - 'paypal_override' => '',
1145 - 'paypal_email' => '',
1146 -
1147 - 'paypal_page_id' => '',
1148 -
1149 - 'paypal_prefill_email' => '',
1150 - 'paypal_user_email_field' => '',
1151 - ]
1152 - );
1153 -}
1154 -
1155 -/**
1156 - * Get default form settings
1157 - *
1158 - * @return array
1159 - */
1160 -function weforms_get_default_form_notification() {
1161 - return apply_filters(
1162 - 'weforms_get_default_form_notification', [
1163 - 'active' => 'true',
1164 -
1165 - 'type' => 'email',
1166 - 'smsTo' => '',
1167 - 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
1168 -
1169 - 'name' => __( 'Admin Notification', 'weforms' ),
1170 - 'subject' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
1171 - 'to' => '{admin_email}',
1172 - 'replyTo' => '{field:email}',
1173 - 'message' => '{all_fields}',
1174 - 'fromName' => '{site_name}',
1175 - 'fromAddress' => '{admin_email}',
1176 - 'cc' => '',
1177 - 'bcc' => '',
1178 - 'weforms_cond' => [
1179 - 'condition_status' => 'no',
1180 - 'cond_logic' => 'any',
1181 - 'conditions' => [
1182 - [
1183 - 'name' => '',
1184 - 'operator' => '=',
1185 - 'option' => '',
1186 - ],
1187 - ],
1188 - ],
1189 - ]
1190 - );
1191 -}
1192 -
1193 -/**
1194 - * weforms_get_pain_text
1195 - *
1196 - * @param $value mixed
1197 - *
1198 - * @return string
1199 - **/
1200 -function weforms_get_pain_text( $value ) {
1201 - if ( is_serialized( $value ) ) {
1202 - $value = unserialize( $value );
1203 - }
1204 -
1205 - if ( is_array( $value ) ) {
1206 - $string_value = [];
1207 - foreach ( $value as $key => $single_value ) {
1208 - if ( is_array( $single_value ) || is_serialized( $single_value ) ) {
1209 - $single_value = weforms_get_pain_text( $single_value );
1210 - }
1211 -
1212 - $single_value = ucwords( str_replace( [ '_', '-' ], ' ', $key ) ) . ': ' . ucwords( $single_value );
1213 -
1214 - $string_value[] = $single_value;
1215 - }
1216 -
1217 - $value = implode( WeForms::$field_separator, $string_value );
1218 - }
1219 -
1220 - $value = trim( strip_tags( $value ) );
1221 -
1222 - // escape spreadsheet special characters to prevent formula exploits.
1223 - $value = preg_match( '/^[=+@-]/', $value ) ? '\'' . $value : $value;
1224 -
1225 - return $value;
1226 -}
1227 -
1228 -/**
1229 - * Get countries
1230 - *
1231 - * @since 1.1.0
1232 - *
1233 - * @param string $type (optional)
1234 - *
1235 - * @return array|string
1236 - */
1237 -function weforms_get_countries( $type = 'array' ) {
1238 - $countries = include WEFORMS_INCLUDES . '/country-list.php';
1239 -
1240 - if ( $type == 'json' ) {
1241 - $countries = json_encode( $countries );
1242 - }
1243 -
1244 - return $countries;
1245 -}
1246 -
1247 -/**
1248 - * Get country name
1249 - *
1250 - * @since 1.3.7
1251 - *
1252 - * @param string $country_code (required)
1253 - *
1254 - * @return string
1255 - */
1256 -function get_country_name( $country_code ) {
1257 - if ( empty( $country_code ) ) {
1258 - return;
1259 - }
1260 -
1261 - $countries = weforms_get_countries();
1262 -
1263 - foreach ( $countries as $country ) {
1264 - if ( $country['code'] == $country_code ) {
1265 - return $country['name'];
1266 - }
1267 - }
1268 -}
1269 -
1270 -/**
1271 - * Localize countries
1272 - *
1273 - * @since 1.3.5
1274 - *
1275 - * @return array
1276 - */
1277 -function weforms_localized_countries( $script ) {
1278 - $script['countries'] = weforms_get_countries();
1279 -
1280 - return $script;
1281 -}
1282 -add_filter( 'weforms_localized_script', 'weforms_localized_countries' );
1283 -
1284 -function is_weforms_api_allowed_guest_submission() {
1285 - $permission = false;
1286 -
1287 - if ( current_user_can( 'read' ) ) {
1288 - $permission = true;
1289 - }
1290 -
1291 - return apply_filters( 'weforms_anonymous_entry_submit_permission', $permission );
1292 -}
1293 -
1294 -/**
1295 - * Clean variables using weforms_clean. Arrays are cleaned recursively.
1296 - * Non-scalar values are ignored.
1297 - *
1298 - * @param string|array $var Data to sanitize.
1299 - * @return string|array
1300 - */
1301 -function weforms_clean( $var ) {
1302 - if ( is_array( $var ) ) {
1303 - return array_map( 'weforms_clean', $var );
1304 - } else {
1305 - return is_scalar( $var ) ? sanitize_text_field( wp_unslash( $var ) ) : $var;
1306 - }
1307 -}
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 +/**
730 + * Update Settings
731 + *
732 + * @param array $updated_settings
733 + *
734 + * @return array
735 + */
736 +function weforms_update_settings( $updated_settings = array() ) {
737 +
738 + $previuos_settings = weforms_get_settings();
739 +
740 + $settings = array_merge( $previuos_settings, $updated_settings );
741 +
742 + update_option( 'weforms_settings', $settings );
743 +
744 + return $settings;
745 +}
746 +
747 +/**
748 + * Form access capability for forms
749 + *
750 + * @since 1.0.5
751 + *
752 + * @return string
753 + */
754 +function weforms_form_access_capability() {
755 + return apply_filters( 'weforms_form_access_capability', 'manage_options' );
756 +}
757 +
758 +/**
759 + * Clear the buffer
760 + *
761 + * prevents ajax breakage and endless loading icon. A LIFE SAVER!!!
762 + *
763 + * @since 1.1.0
764 + *
765 + * @return void
766 + */
767 +function weforms_clear_buffer() {
768 + ob_clean();
769 +}
770 +
771 +/**
772 + * Get the client IP address
773 + *
774 + * @since 1.1.0
775 + *
776 + * @return string
777 + */
778 +function weforms_get_client_ip() {
779 + $ipaddress = '';
780 +
781 + if ( isset($_SERVER['HTTP_CLIENT_IP'] ) ) {
782 + $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
783 + } else if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
784 + $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
785 + } else if ( isset( $_SERVER['HTTP_X_FORWARDED'] ) ) {
786 + $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
787 + } else if ( isset( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
788 + $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
789 + } else if ( isset( $_SERVER['HTTP_FORWARDED'] ) ) {
790 + $ipaddress = $_SERVER['HTTP_FORWARDED'];
791 + } else if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
792 + $ipaddress = $_SERVER['REMOTE_ADDR'];
793 + } else {
794 + $ipaddress = 'UNKNOWN';
795 + }
796 +
797 + return $ipaddress;
798 +}
799 +
800 +/**
801 + * Save form fields
802 + *
803 + * @since 1.1.0
804 + *
805 + * @param int $form_id
806 + * @param array $field
807 + * @param int $field_id
808 + * @param int $order
809 + *
810 + * @return int ID of updated or inserted post
811 + */
812 +function weforms_insert_form_field( $form_id, $field = array(), $field_id = null, $order = 0 ) {
813 +
814 + $args = array(
815 + 'post_type' => 'wpuf_input',
816 + 'post_parent' => $form_id,
817 + 'post_status' => 'publish',
818 + 'post_content' => maybe_serialize( wp_unslash( $field ) ),
819 + 'menu_order' => $order
820 + );
821 +
822 + if ( $field_id ) {
823 + $args['ID'] = $field_id;
824 + }
825 +
826 + if ( $field_id ) {
827 + return wp_update_post( $args );
828 + } else {
829 + return wp_insert_post( $args );
830 + }
831 +}
832 +
833 +/**
834 + * Allowed upload extensions
835 + *
836 + * @return array
837 + */
838 +function weforms_allowed_extensions() {
839 + $extesions = array(
840 + 'images' => array(
841 + 'ext' => 'jpg,jpeg,gif,png,bmp',
842 + 'label' => __( 'Images', 'weforms' )
843 + ),
844 + 'audio' => array(
845 + 'ext' => 'mp3,wav,ogg,wma,mka,m4a,ra,mid,midi',
846 + 'label' => __( 'Audio', 'weforms' )
847 + ),
848 + 'video' => array(
849 + 'ext' => 'avi,divx,flv,mov,ogv,mkv,mp4,m4v,divx,mpg,mpeg,mpe',
850 + 'label' => __( 'Videos', 'weforms' )
851 + ),
852 + 'pdf' => array(
853 + 'ext' => 'pdf',
854 + 'label' => __( 'PDF', 'weforms' )
855 + ),
856 + 'office' => array(
857 + 'ext' => 'doc,ppt,pps,xls,mdb,docx,xlsx,pptx,odt,odp,ods,odg,odc,odb,odf,rtf,txt',
858 + 'label' => __( 'Office Documents', 'weforms' )
859 + ),
860 + 'zip' => array(
861 + 'ext' => 'zip,gz,gzip,rar,7z',
862 + 'label' => __( 'Zip Archives' )
863 + ),
864 + 'exe' => array(
865 + 'ext' => 'exe',
866 + 'label' => __( 'Executable Files', 'weforms' )
867 + ),
868 + 'csv' => array(
869 + 'ext' => 'csv',
870 + 'label' => __( 'CSV', 'weforms' )
871 + )
872 + );
873 +
874 + return apply_filters( 'weforms_allowed_extensions', $extesions );
875 +}
876 +
877 +/**
878 + * Get form integration settings
879 + *
880 + * @since 1.1.0
881 + *
882 + * @param int $form_id
883 + *
884 + * @return array
885 + */
886 +function weforms_get_form_integrations( $form_id ) {
887 + $integrations = get_post_meta( $form_id, 'integrations', true );
888 +
889 + if ( ! $integrations ) {
890 + return array();
891 + }
892 +
893 + return $integrations;
894 +}
895 +
896 +
897 +/**
898 + * Check if an integration is active
899 + *
900 + * @since 1.1.0
901 + *
902 + * @param int $form_id
903 + * @param string $integration_id
904 + *
905 + * @return boolean
906 + */
907 +function weforms_is_integration_active( $form_id, $integration_id ) {
908 + $integrations = weforms_get_form_integrations( $form_id );
909 +
910 + if ( ! $integrations ) {
911 + return false;
912 + }
913 +
914 + foreach ($integrations as $id => $integration) {
915 + if ( $integration_id == $id && $integration->enabled == true ) {
916 + return $integration;
917 + }
918 + }
919 +
920 + return false;
921 +}
922 +
923 +
924 +/**
925 + * Get Flat UI Colors
926 + *
927 + * @return array
928 + */
929 +function weforms_get_flat_ui_colors() {
930 + return array( '#1abc9c', '#2ecc71', '#3498db', '#9b59b6', '#34495e' );
931 +}
932 +
933 +/**
934 + * Get default form settings
935 + *
936 + * @return array
937 + */
938 +function weforms_get_default_form_settings() {
939 + return apply_filters( 'weforms_get_default_form_settings', array(
940 + 'redirect_to' => 'same',
941 + 'message' => __( 'Thanks for contacting us! We will get in touch with you shortly.', 'weforms' ),
942 + 'page_id' => '',
943 + 'url' => '',
944 + 'submit_text' => __( 'Submit Query', 'weforms' ),
945 + 'schedule_form' => 'false',
946 + 'schedule_start' => '',
947 + 'schedule_end' => '',
948 + 'sc_pending_message' => __( 'Form submission hasn\'t been started yet', 'weforms' ),
949 + 'sc_expired_message' => __( 'Form submission is now closed.', 'weforms' ),
950 + 'require_login' => 'false',
951 + 'req_login_message' => __( 'You need to login to submit a query.', 'weforms' ),
952 + 'limit_entries' => 'false',
953 + 'limit_number' => '100',
954 + 'limit_message' => __( 'Sorry, we have reached the maximum number of submissions.', 'weforms' ),
955 + 'label_position' => 'above',
956 + 'enable_multistep' => false,
957 + 'multistep_progressbar_type' => 'progressive',
958 +
959 + // payment
960 +
961 + 'payment_paypal_images' => 'https://www.paypalobjects.com/webstatic/mktg/logo/AM_mc_vs_dc_ae.jpg',
962 +
963 + 'payment_paypal_label' => __( 'PayPal', 'weforms' ),
964 + 'payment_stripe_label' => __( 'Credit Card', 'weforms' ),
965 + 'payment_stripe_images' => array('visa','mastercard','amex','discover'),
966 +
967 + 'payment_stripe_deactivate' => '',
968 + 'stripe_mode' => 'live',
969 + 'stripe_page_id' => '',
970 +
971 + 'stripe_override_keys' => '',
972 + 'stripe_email' => '',
973 + 'stripe_key' => '',
974 + 'stripe_secret_key' => '',
975 + 'stripe_key_test' => '',
976 + 'stripe_secret_key_test' => '',
977 +
978 + 'stripe_prefill_email' => '',
979 + 'stripe_user_email_field' => '',
980 +
981 + 'payment_paypal_deactivate' => '',
982 + 'paypal_mode' => 'live',
983 + 'paypal_type' => '_cart',
984 +
985 + 'paypal_override' => '',
986 + 'paypal_email' => '',
987 +
988 + 'paypal_page_id' => '',
989 +
990 + 'paypal_prefill_email' => '',
991 + 'paypal_user_email_field' => '',
992 + ));
993 +}
994 +
995 +/**
996 + * Get default form settings
997 + *
998 + * @return array
999 + */
1000 +function weforms_get_default_form_notification() {
1001 + return apply_filters( 'weforms_get_default_form_notification', array(
1002 + 'active' => 'true',
1003 +
1004 + 'type' => 'email',
1005 + 'smsTo' => '',
1006 + 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
1007 +
1008 + 'name' => __( 'Admin Notification', 'weforms' ),
1009 + 'subject' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
1010 + 'to' => '{admin_email}',
1011 + 'replyTo' => '{field:email}',
1012 + 'message' => '{all_fields}',
1013 + 'fromName' => '{site_name}',
1014 + 'fromAddress' => '{admin_email}',
1015 + 'cc' => '',
1016 + 'bcc' => '',
1017 + 'weforms_cond' => array(
1018 + 'condition_status' => 'no',
1019 + 'cond_logic' => 'any',
1020 + 'conditions' => array(
1021 + array(
1022 + 'name' => '',
1023 + 'operator' => '=',
1024 + 'option' => ''
1025 + )
1026 + )
1027 + )
1028 + )
1029 + );
1030 +}
1031 +
1032 +/**
1033 + * weforms_get_pain_text
1034 + *
1035 + * @param $value mixed
1036 + *
1037 + * @return string
1038 + **/
1039 +function weforms_get_pain_text( $value ) {
1040 +
1041 + if ( is_serialized( $value ) ) {
1042 + $value = unserialize( $value );
1043 + }
1044 +
1045 + if ( is_array( $value ) ) {
1046 +
1047 + $string_value = array();
1048 +
1049 + if ( is_array( $value ) ) {
1050 +
1051 + foreach ( $value as $key => $single_value ) {
1052 +
1053 + if ( is_array( $single_value ) || is_serialized( $single_value ) ) {
1054 + $single_value = weforms_get_pain_text( $single_value );
1055 + }
1056 +
1057 + $single_value = ucwords( str_replace( array( "_", "-" ), " ", $key) ) . ': ' . ucwords( $single_value );
1058 +
1059 + $string_value[] = $single_value;
1060 + }
1061 +
1062 + $value = implode( WeForms::$field_separator , $string_value);
1063 + }
1064 +
1065 + }
1066 +
1067 + $value = trim( strip_tags( $value ) );
1068 +
1069 + return $value;
1070 +}