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/class-form.php +411 -561 1.6.81.2.1 View file →
@@ -1,561 +1,411 @@
1 -<?php
2 -
3 -/**
4 - * The Form Class
5 - *
6 - * @since 1.1.0
7 - */
8 -class WeForms_Form {
9 -
10 - /**
11 - * The form id
12 - *
13 - * @var int
14 - */
15 - public $id = 0;
16 -
17 - /**
18 - * The form title
19 - *
20 - * @var string
21 - */
22 - public $name = '';
23 -
24 - /**
25 - * Holds the post data object
26 - *
27 - * @var WP_post|null
28 - */
29 - public $data = null;
30 -
31 - /**
32 - * Form fields
33 - *
34 - * @var array
35 - */
36 - public $form_fields = [];
37 -
38 - /**
39 - * The Constructor
40 - *
41 - * @param int|WP_Post $form
42 - */
43 - public function __construct( $form = null ) {
44 - if ( is_numeric( $form ) ) {
45 - $the_post = get_post( $form );
46 -
47 - if ( $the_post ) {
48 - $this->id = $the_post->ID;
49 - $this->name = $the_post->post_title;
50 - $this->data = $the_post;
51 - }
52 - } elseif ( is_a( $form, 'WP_Post' ) ) {
53 - $this->id = $form->ID;
54 - $this->name = $form->post_title;
55 - $this->data = $form;
56 - }
57 - }
58 -
59 - /**
60 - * Get the form ID
61 - *
62 - * @return int
63 - */
64 - public function get_id() {
65 - return $this->id;
66 - }
67 -
68 - /**
69 - * Get the form name
70 - *
71 - * @return string
72 - */
73 - public function get_name() {
74 - return $this->name;
75 - }
76 -
77 - /**
78 - * Get all form fields of this form
79 - *
80 - * @return array
81 - */
82 - public function get_fields() {
83 -
84 - // return if already fetched
85 - if ( $this->form_fields ) {
86 - return $this->form_fields;
87 - }
88 -
89 - $fields = get_children( [
90 - 'post_parent' => $this->id,
91 - 'post_status' => 'publish',
92 - 'post_type' => 'wpuf_input',
93 - 'numberposts' => '-1',
94 - 'orderby' => 'menu_order',
95 - 'order' => 'ASC',
96 - ] );
97 -
98 - $form_fields = [];
99 -
100 - foreach ( $fields as $key => $content ) {
101 - $field = maybe_unserialize( $content->post_content );
102 -
103 - if ( empty( $field['template'] ) ) {
104 - continue;
105 - }
106 -
107 - $field['id'] = $content->ID;
108 -
109 - // Add inline property for radio and checkbox fields
110 - $inline_supported_fields = apply_filters( 'inline_supported_fields_list', [ 'radio_field', 'checkbox_field' ] );
111 -
112 - if ( in_array( $field['template'], $inline_supported_fields ) ) {
113 - if ( !isset( $field['inline'] ) ) {
114 - $field['inline'] = 'no';
115 - }
116 - }
117 -
118 - // Add 'selected' property
119 - $option_based_fields = apply_filters( 'option_based_fields_list', [ 'dropdown_field', 'multiple_select', 'radio_field', 'checkbox_field' ] );
120 -
121 - if ( in_array( $field['template'], $option_based_fields ) ) {
122 - if ( !isset( $field['selected'] ) ) {
123 - if ( 'dropdown_field' === $field['template'] || 'radio_field' === $field['template'] ) {
124 - $field['selected'] = '';
125 - } else {
126 - $field['selected'] = [];
127 - }
128 - }
129 - }
130 -
131 - // Add 'multiple' key for template:repeat
132 - if ( 'repeat_field' === $field['template'] && !isset( $field['multiple'] ) ) {
133 - $field['multiple'] = '';
134 - }
135 -
136 - if ( 'recaptcha' === $field['template'] ) {
137 - $field['name'] = 'recaptcha';
138 - $field['enable_no_captcha'] = isset( $field['enable_no_captcha'] ) ? $field['enable_no_captcha'] : '';
139 - $field['recaptcha_theme'] = isset( $field['recaptcha_theme'] ) ? $field['recaptcha_theme'] : 'light';
140 - }
141 -
142 - $form_fields[] = apply_filters( 'weforms-get-form-field', $field, $this->id );
143 - }
144 -
145 - $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields, $this->id );
146 -
147 - return $this->form_fields;
148 - }
149 -
150 - /**
151 - * Check if any perticular field template is used in a form
152 - *
153 - * @return array
154 - */
155 - public function has_field( $field_template ) {
156 - foreach ( $this->get_fields() as $key => $field ) {
157 - if ( isset( $field['template'] ) && $field['template'] == $field_template ) {
158 - return true;
159 - }
160 - }
161 - }
162 -
163 - /**
164 - * Get all fields by a template
165 - *
166 - * @return array
167 - */
168 - public function search_fields( $field_template ) {
169 - $fields = [];
170 -
171 - foreach ( $this->get_fields() as $key => $field ) {
172 - if ( isset( $field['template'] ) && $field['template'] == $field_template ) {
173 - $fields[] = $field;
174 - }
175 - }
176 -
177 - return $fields;
178 - }
179 -
180 - /**
181 - * Search fileds and get the first one
182 - *
183 - * @return array
184 - */
185 - public function search_field( $field_template ) {
186 - $fields = $this->search_fields( $field_template );
187 -
188 - return isset( $fields[0] ) ? $fields[0] : [];
189 - }
190 -
191 - /**
192 - * Get formatted field name/values
193 - *
194 - * @return array
195 - */
196 - public function get_field_values() {
197 - $values = [];
198 - $fields = $this->get_fields();
199 -
200 - if ( !$fields ) {
201 - return $values;
202 - }
203 -
204 - $ignore_fields = apply_filters( 'ignore_fields_list', [ 'recaptcha', 'section_break' ] );
205 - $options_fields = apply_filters( 'option_fields_list', [ 'dropdown_field', 'radio_field', 'multiple_select', 'checkbox_field' ] );
206 -
207 - foreach ( $fields as $field ) {
208 - if ( in_array( $field['template'], $ignore_fields ) ) {
209 - continue;
210 - }
211 -
212 - // Prepare column field data
213 - if ( $field['template'] == 'column_field' ) {
214 - $inner_columns = $field['inner_fields'];
215 -
216 - if ( !empty( $inner_columns ) ) {
217 - foreach ( $inner_columns as $column => $column_fields ) {
218 - if ( !empty( $column_fields ) ) {
219 - foreach ( $column_fields as $field_obj ) {
220 - if ( in_array( $field_obj['template'], $ignore_fields ) ) {
221 - continue;
222 - }
223 -
224 - if ( !isset( $field_obj['name'] ) ) {
225 - continue;
226 - }
227 -
228 - $field_value = [
229 - 'label' => isset( $field_obj['label'] ) ? $field_obj['label'] : '',
230 - 'type' => $field_obj['template'],
231 - ];
232 -
233 - // put options if this is an option field
234 - if ( in_array( $field_obj['template'], $options_fields ) ) {
235 - $field_value['options'] = $field_obj['options'];
236 - }
237 -
238 - $values[ $field_obj['name'] ] = array_merge( $field_obj, $field_value );
239 - }
240 - }
241 - }
242 - }
243 - }
244 -
245 - if ( !isset( $field['name'] ) ) {
246 - continue;
247 - }
248 -
249 - $value = [
250 - 'label' => isset( $field['label'] ) ? $field['label'] : '',
251 - 'type' => $field['template'],
252 - ];
253 -
254 - // put options if this is an option field
255 - if ( in_array( $field['template'], $options_fields ) ) {
256 - $value['options'] = $field['options'];
257 - }
258 -
259 - $values[ $field['name'] ] = array_merge( $field, $value );
260 - }
261 -
262 - return apply_filters( 'weforms_get_field_values', $values );
263 - }
264 -
265 - /**
266 - * Get form settings
267 - *
268 - * @return array
269 - */
270 - public function get_settings() {
271 - $settings = get_post_meta( $this->id, 'wpuf_form_settings', true );
272 - $default = weforms_get_default_form_settings();
273 -
274 - return apply_filters( 'weforms-get-form-settings', array_merge( $default, $settings ), $this->id );
275 - }
276 -
277 - /**
278 - * Check if the form submission is open
279 - *
280 - * @return bool|WP_Error
281 - */
282 - public function is_submission_open() {
283 - $settings = $this->get_settings();
284 -
285 - $needs_login = ( isset( $settings['require_login'] ) && $settings['require_login'] == 'true' ) ? true : false;
286 - $has_limit = ( isset( $settings['limit_entries'] ) && $settings['limit_entries'] == 'true' ) ? true : false;
287 - $is_scheduled = ( isset( $settings['schedule_form'] ) && $settings['schedule_form'] == 'true' ) ? true : false;
288 -
289 - if ( $this->data->post_status != 'publish' ) {
290 - return new WP_Error( 'needs-publish', __( 'The form is not published yet.', 'weforms' ) );
291 - }
292 -
293 - if ( $needs_login && !is_user_logged_in() ) {
294 - return new WP_Error( 'needs-login', $settings['req_login_message'] );
295 - }
296 -
297 - if ( $has_limit ) {
298 - $limit = (int) $settings['limit_number'];
299 - $form_entries = $this->num_form_entries();
300 -
301 - if ( $limit <= $form_entries ) {
302 - return new WP_Error( 'entry-limit', $settings['limit_message'] );
303 - }
304 - }
305 -
306 - if ( $is_scheduled ) {
307 - $start_time = strtotime( $settings['schedule_start'] );
308 - $end_time = strtotime( $settings['schedule_end'] );
309 - $current_time = current_time( 'timestamp' );
310 -
311 - // too early?
312 - if ( $current_time < $start_time ) {
313 - return new WP_Error( 'form-pending', $settings['sc_pending_message'] );
314 - } elseif ( $current_time > $end_time ) {
315 - return new WP_Error( 'form-expired', $settings['sc_expired_message'] );
316 - }
317 - }
318 -
319 - return apply_filters( 'weforms_is_submission_open', true, $settings, $this );
320 - }
321 -
322 - /**
323 - * Get form notifications
324 - *
325 - * @return array
326 - */
327 - public function get_notifications() {
328 - $notifications = get_post_meta( $this->id, 'notifications', true );
329 - $defualt = weforms_get_default_form_notification();
330 -
331 - if ( !$notifications ) {
332 - $notifications = [];
333 - }
334 -
335 - $notifications = array_map( function ( $notification ) use ( $defualt ) {
336 - if ( empty( $notification ) ) {
337 - $notification = [];
338 - }
339 -
340 - return array_merge( $defualt, $notification );
341 - }, $notifications );
342 -
343 - return $notifications;
344 - }
345 -
346 - /**
347 - * Get all the integrations
348 - *
349 - * @return array
350 - */
351 - public function get_integrations() {
352 - $integrations = get_post_meta( $this->id, 'integrations', true );
353 -
354 - if ( !$integrations ) {
355 - return [];
356 - }
357 -
358 - return $integrations;
359 - }
360 -
361 - /**
362 - * Get entries of this form
363 - *
364 - * @return \WeForms_Form_Entry_Manager
365 - */
366 - public function entries() {
367 - return new WeForms_Form_Entry_Manager( $this->id, $this );
368 - }
369 -
370 - /**
371 - * Get number of form entries
372 - *
373 - * @return int
374 - */
375 - public function num_form_entries() {
376 - return weforms_count_form_entries( $this->id );
377 - }
378 -
379 - /**
380 - * Get number of form payments
381 - *
382 - * @return int
383 - */
384 - public function num_form_payments() {
385 - return weforms_count_form_payments( $this->id );
386 - }
387 -
388 - /**
389 - * Get form author details
390 - *
391 - * @return array
392 - */
393 - public function get_form_author_details() {
394 - return weforms_get_form_author_details( $this->id );
395 - }
396 -
397 - /**
398 - * Get the number of form views
399 - *
400 - * @return int
401 - */
402 - public function num_form_views() {
403 - return weforms_get_form_views( $this->id );
404 - }
405 -
406 - /**
407 - * prepare_entries
408 - *
409 - * @return array
410 - */
411 - public function prepare_entries( $args = [] ) {
412 - $fields = weforms()->fields->get_fields();
413 - $form_fields = $this->get_fields();
414 -
415 - $entry_fields = [];
416 -
417 - $ignore_list = apply_filters( 'wefroms_entry_ignore_list', [
418 - 'recaptcha', 'section_break', 'step_start',
419 - ] );
420 -
421 - foreach ( $form_fields as $field ) {
422 - if ( in_array( $field['template'], $ignore_list ) ) {
423 - continue;
424 - }
425 -
426 - if ( !array_key_exists( $field['template'], $fields ) ) {
427 - continue;
428 - }
429 -
430 - // Prepare column field data
431 - if ( $field['template'] == 'column_field' ) {
432 - $inner_columns = $field['inner_fields'];
433 -
434 - if ( !empty( $inner_columns ) ) {
435 - foreach ( $inner_columns as $column => $column_fields ) {
436 - if ( !empty( $column_fields ) ) {
437 - foreach ( $column_fields as $field_obj ) {
438 - if ( in_array( $field_obj['template'], $ignore_list ) ) {
439 - continue;
440 - }
441 -
442 - $fieldClass = $fields[ $field_obj['template'] ];
443 - $entry_fields[ $field_obj['name'] ] = $fieldClass->prepare_entry( $field_obj );
444 - }
445 - }
446 - }
447 - }
448 - }
449 -
450 - $field_class = $fields[ $field['template'] ];
451 -
452 - $entry_fields[ $field['name'] ] = $field_class->prepare_entry( $field, $args );
453 - }
454 -
455 - return apply_filters( 'weforms_prepare_entries', $entry_fields );
456 - }
457 -
458 - /**
459 - * Check if the form submission is open On API
460 - *
461 - * @return bool|WP_Error
462 - */
463 - public function is_api_form_submission_open() {
464 - $response = [];
465 - $settings = $this->get_settings();
466 - $form_entries = $this->num_form_entries();
467 - $needs_login = isset( $settings['require_login'] ) ? $settings['require_login'] : 'false';
468 - $limit_entries = isset( $settings['limit_entries'] ) ? $settings['limit_entries'] : 'false';
469 - $schedule_form = isset( $settings['schedule_form'] ) ? $settings['schedule_form'] : 'false';
470 - $limit_number = isset( $settings['limit_number'] ) ? $settings['limit_number'] : '';
471 - $schedule_start = isset( $settings['schedule_start'] ) ? $settings['schedule_start'] : '';
472 - $schedule_end = isset( $settings['schedule_end'] ) ? $settings['schedule_end'] : '';
473 - $schedule_start_date = date_i18n( 'M d, Y', strtotime( $schedule_start ) );
474 - $schedule_end_date = date_i18n( 'M d, Y', strtotime( $schedule_end ) );
475 -
476 - if ( $this->data->post_status != 'publish' ) {
477 - $response['type'] = __( 'Closed', 'weforms' );
478 - }
479 -
480 - if ( $this->isFormStatusClosed( $settings, $form_entries ) ) {
481 - $response['type'] = __( 'Closed', 'weforms' );
482 - } else {
483 - $response['type'] = __( 'Open', 'weforms' );
484 - }
485 -
486 - if ( $limit_entries === 'true' ) {
487 - if ( $schedule_form === 'true' && $this->isExpiredForm( $schedule_end ) ) {
488 - $response['message'] = __( "Expired at {$schedule_end_date}", 'weforms' );
489 - } elseif ( $schedule_form === 'true' && $this->isPendingForm( $schedule_start ) ) {
490 - $response['message'] = __( "Starts at {$schedule_start_date}", 'weforms' );
491 - } elseif ( $form_entries >= $limit_number ) {
492 - $response['message'] = __( 'Reached maximum entry limit', 'weforms' );
493 - } else {
494 - $remaining_entries = $limit_number - $form_entries;
495 - $response['message'] = __( "{$remaining_entries} entries remaining ", 'weforms' );
496 - }
497 - } elseif ( $schedule_form === 'true' ) {
498 - if ( $this->isPendingForm( $schedule_start ) ) {
499 - $response['message'] = __( "Starts at {$schedule_start_date}", 'weforms' );
500 - } elseif ( $this->isExpiredForm( $schedule_end ) ) {
501 - $response['message'] = __( "Expired at {$schedule_end_date}", 'weforms' );
502 - } elseif ( $this->isOpenForm( $schedule_start, $schedule_end ) ) {
503 - $response['message'] = __( "Expires at {$schedule_end_date}", 'weforms' );
504 - }
505 - } elseif ( $needs_login === 'true' ) {
506 - $response['message'] =__( 'Requires login', 'weforms' );
507 - }
508 -
509 - return apply_filters( 'weforms_is_submission_open', $response, $settings, $this );
510 - }
511 -
512 - public function isPendingForm( $scheduleStart ) {
513 - $currentTime = current_time( 'timestamp' );
514 - $startTime = strtotime( $scheduleStart );
515 -
516 - if ( $currentTime < $startTime ) {
517 - return true;
518 - }
519 -
520 - return false;
521 - }
522 -
523 - public function isExpiredForm( $scheduleEnd ) {
524 - $currentTime = current_time( 'timestamp' );
525 - $endTime = strtotime( $scheduleEnd );
526 -
527 - if ( $currentTime > $endTime ) {
528 - return true;
529 - }
530 -
531 - return false;
532 - }
533 -
534 - public function isOpenForm( $scheduleStart, $scheduleEnd ) {
535 - $currentTime = current_time( 'timestamp' );
536 - $startTime = strtotime( $scheduleStart );
537 - $endTime = strtotime( $scheduleEnd );
538 -
539 - if ( $currentTime > $startTime && $currentTime < $endTime ) {
540 - return true;
541 - }
542 -
543 - return false;
544 - }
545 -
546 - public function isFormStatusClosed( $formSettings, $entries ) {
547 - if ( $formSettings['schedule_form'] === 'true' && $this->isPendingForm( $formSettings['schedule_start'] ) ) {
548 - return true;
549 - }
550 -
551 - if ( $formSettings['schedule_form'] === 'true' && $this->isExpiredForm( $formSettings['schedule_end'] ) ) {
552 - return true;
553 - }
554 -
555 - if ( $formSettings['limit_entries'] === 'true' && $entries >= $formSettings['limit_number'] ) {
556 - return true;
557 - }
558 -
559 - return false;
560 - }
561 -}
1 +<?php
2 +
3 +/**
4 + * The Form Class
5 + *
6 + * @since 1.1.0
7 + */
8 +class WeForms_Form {
9 +
10 + /**
11 + * The form id
12 + *
13 + * @var integer
14 + */
15 + public $id = 0;
16 +
17 + /**
18 + * The form title
19 + *
20 + * @var string
21 + */
22 + public $name = '';
23 +
24 + /**
25 + * Holds the post data object
26 + *
27 + * @var null|WP_post
28 + */
29 + public $data = null;
30 +
31 + /**
32 + * Form fields
33 + *
34 + * @var array
35 + */
36 + public $form_fields = array();
37 +
38 + /**
39 + * The Constructor
40 + *
41 + * @param int|WP_Post $form
42 + */
43 + public function __construct( $form = null ) {
44 +
45 + if ( is_numeric( $form ) ) {
46 +
47 + $the_post = get_post( $form );
48 +
49 + if ( $the_post ) {
50 + $this->id = $the_post->ID;
51 + $this->name = $the_post->post_title;
52 + $this->data = $the_post;
53 + }
54 +
55 + } elseif ( is_a( $form, 'WP_Post' ) ) {
56 + $this->id = $form->ID;
57 + $this->name = $form->post_title;
58 + $this->data = $form;
59 + }
60 + }
61 +
62 + /**
63 + * Get the form ID
64 + *
65 + * @return integer
66 + */
67 + public function get_id() {
68 + return $this->id;
69 + }
70 +
71 + /**
72 + * Get the form name
73 + *
74 + * @return string
75 + */
76 + public function get_name() {
77 + return $this->name;
78 + }
79 +
80 + /**
81 + * Get all form fields of this form
82 + *
83 + * @return array
84 + */
85 + public function get_fields() {
86 +
87 + // return if already fetched
88 + if ( $this->form_fields ) {
89 + return $this->form_fields;
90 + }
91 +
92 + $fields = get_children(array(
93 + 'post_parent' => $this->id,
94 + 'post_status' => 'publish',
95 + 'post_type' => 'wpuf_input',
96 + 'numberposts' => '-1',
97 + 'orderby' => 'menu_order',
98 + 'order' => 'ASC',
99 + ));
100 +
101 + $form_fields = array();
102 +
103 + foreach ( $fields as $key => $content ) {
104 +
105 + $field = maybe_unserialize( $content->post_content );
106 +
107 + if ( empty( $field['template'] ) ) {
108 + continue;
109 + }
110 +
111 +
112 + $field['id'] = $content->ID;
113 +
114 + // Add inline property for radio and checkbox fields
115 + $inline_supported_fields = apply_filters( 'inline_supported_fields_list', array( 'radio_field', 'checkbox_field' ) );
116 + if ( in_array( $field['template'] , $inline_supported_fields ) ) {
117 + if ( ! isset( $field['inline'] ) ) {
118 + $field['inline'] = 'no';
119 + }
120 + }
121 +
122 + // Add 'selected' property
123 + $option_based_fields = apply_filters( 'option_based_fields_list', array( 'dropdown_field', 'multiple_select', 'radio_field', 'checkbox_field' ) );
124 + if ( in_array( $field['template'] , $option_based_fields ) ) {
125 + if ( ! isset( $field['selected'] ) ) {
126 +
127 + if ( 'dropdown_field' === $field['template'] || 'radio_field' === $field['template'] ) {
128 + $field['selected'] = '';
129 + } else {
130 + $field['selected'] = array();
131 + }
132 +
133 + }
134 + }
135 +
136 + // Add 'multiple' key for template:repeat
137 + if ( 'repeat_field' === $field['template'] && ! isset( $field['multiple'] ) ) {
138 + $field['multiple'] = '';
139 + }
140 +
141 + if ( 'recaptcha' === $field['template'] ) {
142 + $field['name'] = 'recaptcha';
143 + $field['enable_no_captcha'] = isset( $field['enable_no_captcha'] ) ? $field['enable_no_captcha'] : '';
144 +
145 + }
146 +
147 + if ( 'custom_html' === $field['template'] ) {
148 + $field['name'] = 'custom_html';
149 + }
150 +
151 + $form_fields[] = apply_filters( 'weforms-get-form-field', $field );
152 + }
153 +
154 + $this->form_fields = apply_filters( 'weforms-get-form-fields', $form_fields );
155 +
156 + return $this->form_fields;
157 + }
158 +
159 + /**
160 + * Check if any perticular field template is used in a form
161 + *
162 + * @return array
163 + */
164 + public function has_field( $field_template ) {
165 +
166 + foreach ( $this->get_fields() as $key => $field) {
167 + if ( isset( $field['template'] ) && $field['template'] == $field_template) {
168 + return true;
169 + }
170 + }
171 + }
172 +
173 +
174 + /**
175 + * Get all fields by a template
176 + *
177 + * @return array
178 + */
179 + public function search_fields( $field_template ) {
180 +
181 + $fields = array();
182 +
183 + foreach ( $this->get_fields() as $key => $field) {
184 + if ( isset( $field['template'] ) && $field['template'] == $field_template) {
185 + $fields[] = $field;
186 + }
187 + }
188 +
189 + return $fields;
190 + }
191 +
192 + /**
193 + * Search fileds and get the first one
194 + *
195 + * @return array
196 + */
197 + public function search_field( $field_template ) {
198 +
199 + $fields = $this->search_fields($field_template);
200 +
201 + return isset($fields[0]) ? $fields[0] : array();
202 + }
203 +
204 + /**
205 + * Get formatted field name/values
206 + *
207 + * @return array
208 + */
209 + public function get_field_values() {
210 + $values = array();
211 + $fields = $this->get_fields();
212 +
213 + if ( ! $fields ) {
214 + return $values;
215 + }
216 +
217 + $ignore_fields = apply_filters( 'ignore_fields_list', array( 'recaptcha', 'section_break' ) );
218 + $options_fields = apply_filters( 'option_fields_list', array( 'dropdown_field', 'radio_field', 'multiple_select', 'checkbox_field' ) );
219 +
220 + foreach ($fields as $field) {
221 +
222 + if ( in_array( $field['template'], $ignore_fields ) ) {
223 + continue;
224 + }
225 +
226 + if ( ! isset( $field['name'] ) ) {
227 + continue;
228 + }
229 +
230 + $value = array(
231 + 'label' => isset( $field['label'] ) ? $field['label'] : '',
232 + 'type' => $field['template'],
233 + );
234 +
235 + // put options if this is an option field
236 + if ( in_array( $field['template'], $options_fields ) ) {
237 + $value['options'] = $field['options'];
238 + }
239 +
240 + $values[ $field['name'] ] = array_merge( $field, $value);
241 + }
242 +
243 + return apply_filters( 'weforms_get_field_values', $values );;
244 + }
245 +
246 + /**
247 + * Get form settings
248 + *
249 + * @return array
250 + */
251 + public function get_settings() {
252 +
253 + $settings = get_post_meta( $this->id, 'wpuf_form_settings', true );
254 + $default = weforms_get_default_form_settings();
255 +
256 + return array_merge( $default, $settings);
257 + }
258 +
259 + /**
260 + * Check if the form submission is open
261 + *
262 + * @return boolean|WP_Error
263 + */
264 + public function is_submission_open() {
265 + $settings = $this->get_settings();
266 +
267 + $needs_login = ( isset( $settings['require_login'] ) && $settings['require_login'] == 'true' ) ? true : false;
268 + $has_limit = ( isset( $settings['limit_entries'] ) && $settings['limit_entries'] == 'true' ) ? true : false;
269 + $is_scheduled = ( isset( $settings['schedule_form'] ) && $settings['schedule_form'] == 'true' ) ? true : false;
270 +
271 + if ( $this->data->post_status != 'publish' ) {
272 + return new WP_Error( 'needs-publish', __( 'The form is not published yet.', 'weforms' ) );
273 + }
274 +
275 + if ( $needs_login && !is_user_logged_in() ) {
276 + return new WP_Error( 'needs-login', $settings['req_login_message'] );
277 + }
278 +
279 + if ( $has_limit ) {
280 + $limit = (int) $settings['limit_number'];
281 + $form_entries = $this->num_form_entries();
282 +
283 + if ( $limit < $form_entries ) {
284 + return new WP_Error( 'entry-limit', $settings['limit_message'] );
285 + }
286 + }
287 +
288 + if ( $is_scheduled ) {
289 + $start_time = strtotime( $settings['schedule_start'] );
290 + $end_time = strtotime( $settings['schedule_end'] );
291 + $current_time = current_time( 'timestamp' );
292 +
293 + // too early?
294 + if ( $current_time < $start_time ) {
295 + return new WP_Error( 'form-pending', $settings['sc_pending_message'] );
296 + } elseif ( $current_time > $end_time ) {
297 + return new WP_Error( 'form-expired', $settings['sc_expired_message'] );
298 + }
299 + }
300 +
301 + return true;
302 + }
303 +
304 + /**
305 + * Get form notifications
306 + *
307 + * @return array
308 + */
309 + public function get_notifications() {
310 + $notifications = get_post_meta( $this->id, 'notifications', true );
311 + $defualt = weforms_get_default_form_notification();
312 +
313 + if ( ! $notifications ) {
314 + $notifications = array();
315 + }
316 +
317 + $notifications = array_map( function( $notification ) use ( $defualt ) {
318 + return array_merge( $defualt, $notification);
319 + }, $notifications);
320 +
321 + return $notifications;
322 + }
323 +
324 + /**
325 + * Get all the integrations
326 + *
327 + * @return array
328 + */
329 + public function get_integrations() {
330 + $integrations = get_post_meta( $this->id, 'integrations', true );
331 +
332 + if ( ! $integrations ) {
333 + return array();
334 + }
335 +
336 + return $integrations;
337 + }
338 +
339 + /**
340 + * Get entries of this form
341 + *
342 + * @return \WeForms_Form_Entry_Manager
343 + */
344 + public function entries() {
345 + return new WeForms_Form_Entry_Manager( $this->id, $this );
346 + }
347 +
348 + /**
349 + * Get number of form entries
350 + *
351 + * @return integer
352 + */
353 + public function num_form_entries() {
354 + return weforms_count_form_entries( $this->id );
355 + }
356 +
357 + /**
358 + * Get number of form payments
359 + *
360 + * @return integer
361 + */
362 + public function num_form_payments() {
363 + return weforms_count_form_payments( $this->id );
364 + }
365 +
366 + /**
367 + * Get the number of form views
368 + *
369 + * @return integer
370 + */
371 + public function num_form_views() {
372 + return weforms_get_form_views( $this->id );
373 + }
374 +
375 +
376 + /**
377 + * prepare_entries
378 + *
379 + * @return array
380 + */
381 + public function prepare_entries() {
382 +
383 + $fields = weforms()->fields->get_fields();
384 + $form_fields = $this->get_fields();
385 +
386 + $entry_fields = array();
387 +
388 + $ignore_list = apply_filters('wefroms_entry_ignore_list', array(
389 + 'section_break',
390 + 'custom_html',
391 + 'recaptcha'
392 + ) );
393 +
394 + foreach ($form_fields as $field) {
395 +
396 + if ( in_array( $field['template'], $ignore_list ) ) {
397 + continue;
398 + }
399 +
400 + if ( ! array_key_exists( $field['template'], $fields ) ) {
401 + continue;
402 + }
403 +
404 + $field_class = $fields[ $field['template'] ];
405 +
406 + $entry_fields[ $field['name'] ] = $field_class->prepare_entry( $field );
407 + }
408 +
409 + return apply_filters( 'weforms_prepare_entries', $entry_fields );
410 + }
411 +}