PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.1
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 +203 -39 6.36.22.1 View file →
@@ -4,8 +4,24 @@
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 +
8 24 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
9 25 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
10 26
11 27 $values = array(
@@ -44,9 +60,9 @@
44 60
45 61 if ( ! $form || ! isset( $form->id ) ) {
46 62 $form = FrmForm::getOne( $field->form_id );
47 63 }
48 - }
64 + }//end foreach
49 65
50 66 FrmAppHelper::unserialize_or_decode( $form->options );
51 67 if ( is_array( $form->options ) ) {
52 68 $values = array_merge( $values, $form->options );
@@ -65,9 +81,9 @@
65 81 *
66 82 * @param object $field
67 83 */
68 84 private static function prepare_field_default_value( &$field ) {
69 - //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array
85 + // If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array.
70 86 $return_array = FrmField::is_field_with_multiple_values( $field );
71 87
72 88 /**
73 89 * Do any shortcodes in default value and allow customization of default value.
@@ -85,13 +101,13 @@
85 101 * This function is used when the form is first loaded and on all page turns *for a new entry*
86 102 *
87 103 * @since 2.0.13
88 104 *
89 - * @param object $field - this is passed by reference since it is an object
90 - * @param boolean $reset
91 - * @param array $args
105 + * @param object $field - this is passed by reference since it is an object.
106 + * @param bool $reset
107 + * @param array $args
92 108 *
93 - * @return string|array $new_value
109 + * @return array|string $new_value
94 110 */
95 111 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
96 112 $new_value = $field->default_value;
97 113
@@ -111,11 +127,11 @@
111 127 *
112 128 * @since 2.01.0
113 129 *
114 130 * @param object $field
115 - * @param array $args
131 + * @param array $args
116 132 *
117 - * @return boolean $value_is_posted
133 + * @return bool $value_is_posted
118 134 */
119 135 public static function value_is_posted( $field, $args ) {
120 136 $value_is_posted = false;
121 137 if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -196,10 +212,13 @@
196 212
197 213 if ( ! FrmAppHelper::pro_is_installed() ) {
198 214 return '';
199 215 }
216 + if ( is_callable( 'FrmProEntriesHelper::prepare_child_display_value' ) ) {
217 + return FrmProEntriesHelper::prepare_child_display_value( $entry, $field, $atts );
218 + }
200 219
201 - // This is an embeded form.
220 + // This is an embedded form.
202 221 if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
203 222 // This is a repeating section.
204 223 $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
205 224 } else {
@@ -232,12 +251,12 @@
232 251 unset( $child_entry );
233 252 }
234 253
235 254 $sep = ', ';
236 - if ( strpos( implode( ' ', (array) $field_value ), '<img' ) !== false ) {
255 + if ( strpos( implode( ' ', $field_value ), '<img' ) !== false ) {
237 256 $sep = '<br/>';
238 257 }
239 - $val = implode( $sep, (array) $field_value );
258 + $val = implode( $sep, $field_value );
240 259
241 260 return FrmAppHelper::kses( $val, 'all' );
242 261 }
243 262
@@ -244,10 +263,10 @@
244 263 /**
245 264 * Prepare the saved value for display
246 265 *
247 266 * @param array|string $value
248 - * @param object $field
249 - * @param array $atts
267 + * @param object $field
268 + * @param array $atts
250 269 *
251 270 * @return string
252 271 */
253 272 public static function display_value( $value, $field, $atts = array() ) {
@@ -266,9 +285,9 @@
266 285 );
267 286
268 287 $atts = wp_parse_args( $atts, $defaults );
269 288
270 - if ( FrmField::is_image( $field ) || $field->type == 'star' ) {
289 + if ( FrmField::is_image( $field ) || $field->type === 'star' ) {
271 290 $atts['truncate'] = false;
272 291 $atts['html'] = true;
273 292 }
274 293
@@ -273,8 +292,12 @@
273 292 }
274 293
275 294 $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
276 295
296 + if ( is_string( $field->field_options ) ) {
297 + $field->field_options = array();
298 + }
299 +
277 300 if ( ! isset( $field->field_options['post_field'] ) ) {
278 301 $field->field_options['post_field'] = '';
279 302 }
280 303
@@ -281,9 +304,9 @@
281 304 if ( ! isset( $field->field_options['custom_field'] ) ) {
282 305 $field->field_options['custom_field'] = '';
283 306 }
284 307
285 - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
308 + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
286 309 $atts['pre_truncate'] = $atts['truncate'];
287 310 $atts['truncate'] = true;
288 311 $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
289 312
@@ -304,9 +327,9 @@
304 327 if ( $value == $unfiltered_value ) {
305 328 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
306 329 }
307 330
308 - if ( $atts['truncate'] && $atts['type'] != 'url' ) {
331 + if ( $atts['truncate'] && $atts['type'] !== 'url' ) {
309 332 $value = FrmAppHelper::truncate( $value, 50 );
310 333 }
311 334
312 335 if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
@@ -317,9 +340,9 @@
317 340 }
318 341
319 342 public static function set_posted_value( $field, $value, $args ) {
320 343 // If validating a field with "other" opt, set back to prev value now.
321 - if ( isset( $args['other'] ) && $args['other'] ) {
344 + if ( ! empty( $args['other'] ) ) {
322 345 $value = $args['temp_value'];
323 346 }
324 347 if ( empty( $args['parent_field_id'] ) ) {
325 348 $_POST['item_meta'][ $field->id ] = $value;
@@ -385,11 +408,11 @@
385 408 * Check if field has an "Other" option and if any other values are posted
386 409 *
387 410 * @since 2.0
388 411 *
389 - * @param object $field
390 - * @param string|array $value
391 - * @param array $args
412 + * @param object $field
413 + * @param array|string $value
414 + * @param array $args
392 415 */
393 416 public static function maybe_set_other_validation( $field, &$value, &$args ) {
394 417 $args['other'] = false;
395 418 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
@@ -426,11 +449,11 @@
426 449 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
427 450 *
428 451 * @since 2.0
429 452 *
430 - * @param object $field
431 - * @param string|array $value
432 - * @param array $args
453 + * @param object $field
454 + * @param array|string $value
455 + * @param array $args
433 456 */
434 457 public static function set_other_repeating_vals( $field, &$value, &$args ) {
435 458 if ( ! $args['parent_field_id'] ) {
436 459 return;
@@ -458,12 +481,12 @@
458 481 * Needs to accommodate for times when other opt is selected, but no other free text is entered
459 482 *
460 483 * @since 2.0
461 484 *
462 - * @param string|array $value
463 - * @param string|array $other_vals (usually of posted values)
464 - * @param object $field
465 - * @param array $args
485 + * @param array|string $value
486 + * @param array|string $other_vals (usually of posted values).
487 + * @param object $field
488 + * @param array $args
466 489 */
467 490 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
468 491 // Checkboxes and multi-select dropdowns.
469 492 if ( is_array( $value ) && $field->type === 'checkbox' ) {
@@ -505,10 +528,10 @@
505 528 }
506 529 }
507 530 } elseif ( $field->options[ $other_key ] == $value ) {
508 531 $value = $other_vals;
509 - }
510 - }
532 + }//end if
533 + }//end if
511 534 }
512 535
513 536 /**
514 537 * Add submitted values to a string for spam checking.
@@ -544,9 +567,9 @@
544 567 * @return string
545 568 */
546 569 public static function get_browser( $u_agent ) {
547 570 $bname = __( 'Unknown', 'formidable' );
548 - $platform = __( 'Unknown', 'formidable' );
571 + $platform = $bname;
549 572 $ub = '';
550 573
551 574 // Get the operating system
552 575 if ( preg_match( '/windows|win32/i', $u_agent ) ) {
@@ -566,9 +589,9 @@
566 589 'Netscape' => 'Netscape',
567 590 'Firefox' => 'Mozilla Firefox',
568 591 );
569 592
570 - // Next get the name of the useragent yes seperately and for good reason
593 + // Next get the name of the useragent yes separately and for good reason.
571 594 if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
572 595 $bname = 'Internet Explorer';
573 596 $ub = 'MSIE';
574 597 } else {
@@ -583,16 +606,17 @@
583 606
584 607 // finally get the correct version number
585 608 $known = array( 'Version', $ub, 'other' );
586 609 $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
587 - preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
610 + // Get the matching numbers.
611 + preg_match_all( $pattern, $u_agent, $matches );
588 612
589 613 // see how many we have
590 614 $i = count( $matches['browser'] );
591 615
592 616 if ( $i > 1 ) {
593 - //we will have two since we are not using 'other' argument yet
594 - //see if version is before or after the name
617 + // We will have two since we are not using 'other' argument yet
618 + // see if version is before or after the name.
595 619 if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
596 620 $version = $matches['version'][0];
597 621 } else {
598 622 $version = $matches['version'][1];
@@ -640,9 +664,9 @@
640 664 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
641 665 </a>
642 666 </div>
643 667 <?php
644 - }
668 + }//end foreach
645 669 }
646 670
647 671 /**
648 672 * @since 3.0
@@ -650,9 +674,9 @@
650 674 private static function get_action_links( $id, $entry ) {
651 675 $page = FrmAppHelper::get_param( 'frm_action' );
652 676 $actions = array();
653 677
654 - if ( $page != 'show' ) {
678 + if ( $page !== 'show' ) {
655 679 $actions['frm_view'] = array(
656 680 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
657 681 'label' => __( 'View Entry', 'formidable' ),
658 682 'icon' => 'frm_icon_font frm_save_icon',
@@ -664,14 +688,15 @@
664 688 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
665 689 'label' => __( 'Delete Entry', 'formidable' ),
666 690 'icon' => 'frm_icon_font frm_delete_icon',
667 691 'data' => array(
668 - 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
692 + 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
693 + 'frmverify-btn' => 'frm-button-red',
669 694 ),
670 695 );
671 696 }
672 697
673 - if ( $page == 'show' ) {
698 + if ( $page === 'show' ) {
674 699 $actions['frm_print'] = array(
675 700 'url' => '#',
676 701 'label' => __( 'Print Entry', 'formidable' ),
677 702 'data' => array(
@@ -692,8 +717,18 @@
692 717 ),
693 718 'icon' => 'frm_icon_font frm_email_icon',
694 719 );
695 720
721 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
722 + $actions['frm_download_pdf'] = array(
723 + 'url' => '#',
724 + 'label' => __( 'Download as PDF', 'formidable' ),
725 + 'class' => 'frm_noallow',
726 + 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
727 + 'icon' => 'frm_icon_font frm_download_icon',
728 + );
729 + }
730 +
696 731 $actions['frm_edit'] = array(
697 732 'url' => '#',
698 733 'label' => __( 'Edit Entry', 'formidable' ),
699 734 'class' => 'frm_noallow',
@@ -708,11 +743,35 @@
708 743 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
709 744 }
710 745
711 746 /**
747 + * Gets data attributes for PDFs addon upgrade link.
748 + *
749 + * @param string $medium The source of the upgrade link used for analytics data.
750 + * @return array
751 + */
752 + private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
753 + $data = array(
754 + 'oneclick' => '',
755 + 'requires' => '',
756 + 'upgrade' => __( 'Forms to PDF', 'formidable' ),
757 + 'medium' => $medium,
758 + );
759 +
760 + $upgrading = FrmAddonsController::install_link( 'pdfs' );
761 + if ( isset( $upgrading['url'] ) ) {
762 + $data['oneclick'] = json_encode( $upgrading );
763 + } else {
764 + $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
765 + }
766 +
767 + return $data;
768 + }
769 +
770 + /**
712 771 * @since 5.0.15
713 772 *
714 - * @param string|int $entry_id
773 + * @param int|string $entry_id
715 774 * @return void
716 775 */
717 776 public static function maybe_render_captcha_score( $entry_id ) {
718 777 $query = array(
@@ -729,6 +788,111 @@
729 788 echo '</div>';
730 789 return;
731 790 }
732 791 }
792 + }
793 +
794 + /**
795 + * Return entry status based on is_draft column value.
796 + *
797 + * @since 6.5
798 + *
799 + * @param int $status is_draft column.
800 + *
801 + * @return int
802 + */
803 + public static function get_entry_status( $status ) {
804 + $statuses = self::get_entry_statuses();
805 +
806 + if ( array_key_exists( $status, $statuses ) ) {
807 + return $status;
808 + }
809 +
810 + if ( empty( $status ) ) {
811 + // If the status is empty, let's default to 0.
812 + return self::SUBMITTED_ENTRY_STATUS;
813 + }
814 +
815 + // 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.
816 + return self::DRAFT_ENTRY_STATUS;
817 + }
818 +
819 + /**
820 + * Return entry status label based on passed value.
821 + *
822 + * @since 6.5
823 + *
824 + * @param int $status is_draft column.
825 + *
826 + * @return string
827 + */
828 + public static function get_entry_status_label( $status ) {
829 + $statuses = self::get_entry_statuses();
830 +
831 + return $statuses[ self::get_entry_status( $status ) ];
832 + }
833 +
834 + /**
835 + * Get all entry statuses.
836 + *
837 + * @since 6.5
838 + * @since 6.6 function went from private to public.
839 + *
840 + * @return array<string>
841 + */
842 + public static function get_entry_statuses() {
843 +
844 + $default_entry_statuses = array(
845 + self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
846 + self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
847 + );
848 +
849 + /**
850 + * Register entry status.
851 + *
852 + * "2" is used in abandonment-addon and reserved for "In progress".
853 + * "3" is used in abandonment-addon and reserved for "Abandoned".
854 + *
855 + * @since 6.5
856 + *
857 + * @param array<string> $extended_entry_status Entry statuses.
858 + */
859 + $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
860 +
861 + if ( ! is_array( $extended_entry_status ) ) {
862 + _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
863 + $extended_entry_status = array();
864 + }
865 +
866 + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
867 +
868 + return $existing_entry_statuses;
869 + }
870 +
871 + /**
872 + * @since 6.17
873 + *
874 + * @return int
875 + */
876 + public static function get_visible_unread_inbox_count() {
877 + $menu_name = FrmAppHelper::get_menu_name();
878 + if ( ! in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
879 + return 0;
880 + }
881 +
882 + $inbox = new FrmInbox();
883 + $inbox_count = count( $inbox->unread() );
884 +
885 + if ( ! $inbox_count ) {
886 + return 0;
887 + }
888 +
889 + if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
890 + $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
891 + if ( ! $inbox_count ) {
892 + return 0;
893 + }
894 + }
895 +
896 + return $inbox_count;
733 897 }
734 898 }