PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.08
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmEntriesHelper.php +32 -187 6.5.35.0.08 View file →
@@ -4,24 +4,8 @@
4 4 }
5 5
6 6 class FrmEntriesHelper {
7 7
8 - /**
9 - * "Submitted" entry status.
10 - *
11 - * @since 6.4.2
12 - * @var int
13 - */
14 - const SUBMITTED_ENTRY_STATUS = 0;
15 -
16 - /**
17 - * "Draft" entry status.
18 - *
19 - * @since 6.4.2
20 - * @var int
21 - */
22 - const DRAFT_ENTRY_STATUS = 1;
23 -
24 8 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
25 9 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
26 10
27 11 $values = array(
@@ -49,12 +33,8 @@
49 33 $field_array['original_default'] = $original_default;
50 34
51 35 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
52 36
53 - if ( ! is_array( $field->field_options ) ) {
54 - $field->field_options = array();
55 - }
56 -
57 37 $field_array = array_merge( $field->field_options, $field_array );
58 38
59 39 $values['fields'][] = $field_array;
60 40
@@ -133,15 +113,15 @@
133 113 * @return boolean $value_is_posted
134 114 */
135 115 public static function value_is_posted( $field, $args ) {
136 116 $value_is_posted = false;
137 - if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
117 + if ( $_POST ) {
138 118 $repeating = isset( $args['repeating'] ) && $args['repeating'];
139 119 if ( $repeating ) {
140 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
120 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) {
141 121 $value_is_posted = true;
142 122 }
143 - } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
123 + } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) {
144 124 $value_is_posted = true;
145 125 }
146 126 }
147 127
@@ -187,14 +167,8 @@
187 167
188 168 return $message;
189 169 }
190 170
191 - /**
192 - * @param stdClass $entry
193 - * @param stdClass $field
194 - * @param array $atts
195 - * @return string
196 - */
197 171 public static function prepare_display_value( $entry, $field, $atts ) {
198 172 $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
199 173
200 174 if ( FrmAppHelper::pro_is_installed() ) {
@@ -209,16 +183,14 @@
209 183 if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
210 184 return self::display_value( $field_value, $field, $atts );
211 185 }
212 186
213 - if ( ! FrmAppHelper::pro_is_installed() ) {
214 - return '';
215 - }
187 + // This is an embeded form.
188 + $val = '';
216 189
217 - // This is an embeded form.
218 190 if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
219 191 // This is a repeating section.
220 - $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
192 + $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) );
221 193 } else {
222 194 // Get all values for this field.
223 195 $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
224 196
@@ -228,10 +200,10 @@
228 200 }
229 201
230 202 $field_value = array();
231 203
232 - if ( empty( $child_entries ) ) {
233 - return '';
204 + if ( ! isset( $child_entries ) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) {
205 + return $val;
234 206 }
235 207
236 208 foreach ( $child_entries as $child_entry ) {
237 209 $atts['item_id'] = $child_entry->id;
@@ -311,9 +283,9 @@
311 283 return $value;
312 284 }
313 285
314 286 $unfiltered_value = $value;
315 - FrmFieldsHelper::prepare_field_value( $unfiltered_value, $field->type );
287 + FrmAppHelper::unserialize_or_decode( $unfiltered_value );
316 288
317 289 $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
318 290 $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
319 291
@@ -349,19 +321,22 @@
349 321 *
350 322 * @since 4.01
351 323 */
352 324 private static function set_parent_field_posted_value( $field, $value, $args ) {
353 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
354 - if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
355 - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
325 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) &&
326 + is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) {
327 +
328 + if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ||
329 + ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) {
330 + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array();
356 331 }
357 332 } else {
358 333 // All of the section was probably removed.
359 - $_POST['item_meta'][ $args['parent_field_id'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
360 - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
334 + $_POST['item_meta'][ $args['parent_field_id'] ] = array();
335 + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array();
361 336 }
362 337
363 - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
338 + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value;
364 339 }
365 340
366 341 public static function get_posted_value( $field, &$value, $args ) {
367 342 if ( is_array( $field ) ) {
@@ -366,12 +341,12 @@
366 341 public static function get_posted_value( $field, &$value, $args ) {
367 342 if ( is_array( $field ) ) {
368 343 $field_id = $field['id'];
369 344 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
370 - } elseif ( is_object( $field ) ) {
345 + } else if ( is_object( $field ) ) {
371 346 $field_id = $field->id;
372 347 $field_obj = FrmFieldFactory::get_field_object( $field );
373 - } elseif ( is_numeric( $field ) ) {
348 + } else if ( is_numeric( $field ) ) {
374 349 $field_id = $field;
375 350 $field_obj = FrmFieldFactory::get_field_object( $field );
376 351 } else {
377 352 $value = self::get_posted_meta( $field, $args );
@@ -389,11 +364,13 @@
389 364 */
390 365 private static function get_posted_meta( $field_id, $args ) {
391 366 if ( empty( $args['parent_field_id'] ) ) {
392 367 // Sanitizing is done next.
393 - $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
368 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
369 + $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : '';
394 370 } else {
395 - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
371 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
372 + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : '';
396 373 }
397 374 return $value;
398 375 }
399 376
@@ -422,9 +399,9 @@
422 399 // Get other value for fields in repeating section.
423 400 self::set_other_repeating_vals( $field, $value, $args );
424 401
425 402 // Check if there are any posted "Other" values.
426 - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
403 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) {
427 404
428 405 // Save original value.
429 406 $args['temp_value'] = $value;
430 407 $args['other'] = true;
@@ -429,9 +406,10 @@
429 406 $args['temp_value'] = $value;
430 407 $args['other'] = true;
431 408
432 409 // Sanitizing is done next.
433 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
410 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
411 + $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] );
434 412 FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
435 413
436 414 // Set the validation value now
437 415 self::set_other_validation_val( $value, $other_vals, $field, $args );
@@ -452,14 +430,15 @@
452 430 return;
453 431 }
454 432
455 433 // Check if there are any other posted "other" values for this field.
456 - if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
434 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) {
457 435 // Save original value
458 436 $args['temp_value'] = $value;
459 437 $args['other'] = true;
460 438
461 - $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
439 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
440 + $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] );
462 441 FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
463 442
464 443 // Set the validation value now.
465 444 self::set_other_validation_val( $value, $other_vals, $field, $args );
@@ -529,9 +508,8 @@
529 508 /**
530 509 * Add submitted values to a string for spam checking.
531 510 *
532 511 * @param array $values
533 - * @return string
534 512 */
535 513 public static function entry_array_to_string( $values ) {
536 514 $content = '';
537 515 foreach ( $values['item_meta'] as $val ) {
@@ -636,9 +614,9 @@
636 614
637 615 foreach ( $links as $link ) {
638 616 ?>
639 617 <div class="misc-pub-section">
640 - <a href="<?php echo esc_url( $link['url'] ); ?>"
618 + <a href="<?php echo esc_url( FrmAppHelper::maybe_full_screen_link( $link['url'] ) ); ?>"
641 619 <?php
642 620 if ( isset( $link['data'] ) ) {
643 621 foreach ( $link['data'] as $data => $value ) {
644 622 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
@@ -676,9 +654,9 @@
676 654 }
677 655
678 656 if ( current_user_can( 'frm_delete_entries' ) ) {
679 657 $actions['frm_delete'] = array(
680 - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
658 + 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ),
681 659 'label' => __( 'Delete Entry', 'formidable' ),
682 660 'icon' => 'frm_icon_font frm_delete_icon',
683 661 'data' => array(
684 662 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
@@ -708,18 +686,8 @@
708 686 ),
709 687 'icon' => 'frm_icon_font frm_email_icon',
710 688 );
711 689
712 - if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
713 - $actions['frm_download_pdf'] = array(
714 - 'url' => '#',
715 - 'label' => __( 'Download as PDF', 'formidable' ),
716 - 'class' => 'frm_noallow',
717 - 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
718 - 'icon' => 'frm_icon_font frm_download_icon',
719 - );
720 - }
721 -
722 690 $actions['frm_edit'] = array(
723 691 'url' => '#',
724 692 'label' => __( 'Edit Entry', 'formidable' ),
725 693 'class' => 'frm_noallow',
@@ -732,128 +700,5 @@
732 700 );
733 701
734 702 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
735 703 }
736 -
737 - /**
738 - * Gets data attributes for PDFs addon upgrade link.
739 - *
740 - * @param string $medium The source of the upgrade link used for analytics data.
741 - * @return array
742 - */
743 - private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
744 - $data = array(
745 - 'oneclick' => '',
746 - 'requires' => '',
747 - 'upgrade' => __( 'Forms to PDF', 'formidable' ),
748 - 'medium' => $medium,
749 - );
750 -
751 - $upgrading = FrmAddonsController::install_link( 'pdfs' );
752 - if ( isset( $upgrading['url'] ) ) {
753 - $data['oneclick'] = json_encode( $upgrading );
754 - } else {
755 - $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
756 - }
757 -
758 - return $data;
759 - }
760 -
761 - /**
762 - * @since 5.0.15
763 - *
764 - * @param string|int $entry_id
765 - * @return void
766 - */
767 - public static function maybe_render_captcha_score( $entry_id ) {
768 - $query = array(
769 - 'item_id' => (int) $entry_id,
770 - 'field_id' => 0,
771 - );
772 - $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
773 - foreach ( $metas_without_a_field as $meta ) {
774 - if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
775 - echo '<div class="misc-pub-section">';
776 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
777 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
778 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
779 - echo '</div>';
780 - return;
781 - }
782 - }
783 - }
784 -
785 - /**
786 - * Return entry status based on is_draft column value.
787 - *
788 - * @since 6.5
789 - *
790 - * @param int $status is_draft column.
791 - *
792 - * @return int
793 - */
794 - public static function get_entry_status( $status ) {
795 - $statuses = self::get_entry_statuses();
796 -
797 - if ( array_key_exists( $status, $statuses ) ) {
798 - return $status;
799 - }
800 -
801 - if ( empty( $status ) ) {
802 - return self::SUBMITTED_ENTRY_STATUS; // If the status is empty, let's default to 0.
803 - }
804 -
805 - return self::DRAFT_ENTRY_STATUS; // If it has a value that isn't in the array, let's default to 1. There may be old entries that don't have a value for is_draft.
806 - }
807 -
808 - /**
809 - * Return entry status label based on passed value.
810 - *
811 - * @since 6.5
812 - *
813 - * @param int $status is_draft column.
814 - *
815 - * @return string
816 - */
817 - public static function get_entry_status_label( $status ) {
818 - $statuses = self::get_entry_statuses();
819 -
820 - return $statuses[ self::get_entry_status( $status ) ];
821 - }
822 -
823 - /**
824 - * Get all entry statuses.
825 - *
826 - * @since 6.5
827 - *
828 - * @return array<string>
829 - */
830 - private static function get_entry_statuses() {
831 -
832 - $default_entry_statuses = array(
833 - self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
834 - self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
835 - );
836 -
837 - /**
838 - * Register entry status.
839 - *
840 - * "2" is used in abandonment-addon and reserved for "In progress".
841 - * "3" is used in abandonment-addon and reserved for "Abandoned".
842 - *
843 - * @since 6.5
844 - *
845 - * @param array<string> $extended_entry_status Entry statuses.
846 - */
847 - $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
848 -
849 - if ( ! is_array( $extended_entry_status ) ) {
850 - _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
851 - $extended_entry_status = array();
852 - }
853 -
854 - $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
855 -
856 - return $existing_entry_statuses;
857 - }
858 -
859 704 }