PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.12
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.12
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 +169 -38 6.3.1 → 6.12 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
@@ -281,9 +300,9 @@
281 300 if ( ! isset( $field->field_options['custom_field'] ) ) {
282 301 $field->field_options['custom_field'] = '';
283 302 }
284 303
285 - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) {
304 + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
286 305 $atts['pre_truncate'] = $atts['truncate'];
287 306 $atts['truncate'] = true;
288 307 $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
289 308
@@ -304,9 +323,9 @@
304 323 if ( $value == $unfiltered_value ) {
305 324 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
306 325 }
307 326
308 - if ( $atts['truncate'] && $atts['type'] != 'url' ) {
327 + if ( $atts['truncate'] && $atts['type'] !== 'url' ) {
309 328 $value = FrmAppHelper::truncate( $value, 50 );
310 329 }
311 330
312 331 if ( ! $atts['keepjs'] && ! is_array( $value ) ) {
@@ -317,9 +336,9 @@
317 336 }
318 337
319 338 public static function set_posted_value( $field, $value, $args ) {
320 339 // If validating a field with "other" opt, set back to prev value now.
321 - if ( isset( $args['other'] ) && $args['other'] ) {
340 + if ( ! empty( $args['other'] ) ) {
322 341 $value = $args['temp_value'];
323 342 }
324 343 if ( empty( $args['parent_field_id'] ) ) {
325 344 $_POST['item_meta'][ $field->id ] = $value;
@@ -385,11 +404,11 @@
385 404 * Check if field has an "Other" option and if any other values are posted
386 405 *
387 406 * @since 2.0
388 407 *
389 - * @param object $field
390 - * @param string|array $value
391 - * @param array $args
408 + * @param object $field
409 + * @param array|string $value
410 + * @param array $args
392 411 */
393 412 public static function maybe_set_other_validation( $field, &$value, &$args ) {
394 413 $args['other'] = false;
395 414 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
@@ -426,11 +445,11 @@
426 445 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
427 446 *
428 447 * @since 2.0
429 448 *
430 - * @param object $field
431 - * @param string|array $value
432 - * @param array $args
449 + * @param object $field
450 + * @param array|string $value
451 + * @param array $args
433 452 */
434 453 public static function set_other_repeating_vals( $field, &$value, &$args ) {
435 454 if ( ! $args['parent_field_id'] ) {
436 455 return;
@@ -458,12 +477,12 @@
458 477 * Needs to accommodate for times when other opt is selected, but no other free text is entered
459 478 *
460 479 * @since 2.0
461 480 *
462 - * @param string|array $value
463 - * @param string|array $other_vals (usually of posted values)
464 - * @param object $field
465 - * @param array $args
481 + * @param array|string $value
482 + * @param array|string $other_vals (usually of posted values).
483 + * @param object $field
484 + * @param array $args
466 485 */
467 486 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
468 487 // Checkboxes and multi-select dropdowns.
469 488 if ( is_array( $value ) && $field->type === 'checkbox' ) {
@@ -505,10 +524,10 @@
505 524 }
506 525 }
507 526 } elseif ( $field->options[ $other_key ] == $value ) {
508 527 $value = $other_vals;
509 - }
510 - }
528 + }//end if
529 + }//end if
511 530 }
512 531
513 532 /**
514 533 * Add submitted values to a string for spam checking.
@@ -544,9 +563,9 @@
544 563 * @return string
545 564 */
546 565 public static function get_browser( $u_agent ) {
547 566 $bname = __( 'Unknown', 'formidable' );
548 - $platform = __( 'Unknown', 'formidable' );
567 + $platform = $bname;
549 568 $ub = '';
550 569
551 570 // Get the operating system
552 571 if ( preg_match( '/windows|win32/i', $u_agent ) ) {
@@ -566,9 +585,9 @@
566 585 'Netscape' => 'Netscape',
567 586 'Firefox' => 'Mozilla Firefox',
568 587 );
569 588
570 - // Next get the name of the useragent yes seperately and for good reason
589 + // Next get the name of the useragent yes separately and for good reason.
571 590 if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
572 591 $bname = 'Internet Explorer';
573 592 $ub = 'MSIE';
574 593 } else {
@@ -583,16 +602,17 @@
583 602
584 603 // finally get the correct version number
585 604 $known = array( 'Version', $ub, 'other' );
586 605 $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
587 - preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers
606 + // Get the matching numbers.
607 + preg_match_all( $pattern, $u_agent, $matches );
588 608
589 609 // see how many we have
590 610 $i = count( $matches['browser'] );
591 611
592 612 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
613 + // We will have two since we are not using 'other' argument yet
614 + // see if version is before or after the name.
595 615 if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
596 616 $version = $matches['version'][0];
597 617 } else {
598 618 $version = $matches['version'][1];
@@ -640,9 +660,9 @@
640 660 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
641 661 </a>
642 662 </div>
643 663 <?php
644 - }
664 + }//end foreach
645 665 }
646 666
647 667 /**
648 668 * @since 3.0
@@ -650,9 +670,9 @@
650 670 private static function get_action_links( $id, $entry ) {
651 671 $page = FrmAppHelper::get_param( 'frm_action' );
652 672 $actions = array();
653 673
654 - if ( $page != 'show' ) {
674 + if ( $page !== 'show' ) {
655 675 $actions['frm_view'] = array(
656 676 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
657 677 'label' => __( 'View Entry', 'formidable' ),
658 678 'icon' => 'frm_icon_font frm_save_icon',
@@ -669,9 +689,9 @@
669 689 ),
670 690 );
671 691 }
672 692
673 - if ( $page == 'show' ) {
693 + if ( $page === 'show' ) {
674 694 $actions['frm_print'] = array(
675 695 'url' => '#',
676 696 'label' => __( 'Print Entry', 'formidable' ),
677 697 'data' => array(
@@ -692,8 +712,18 @@
692 712 ),
693 713 'icon' => 'frm_icon_font frm_email_icon',
694 714 );
695 715
716 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
717 + $actions['frm_download_pdf'] = array(
718 + 'url' => '#',
719 + 'label' => __( 'Download as PDF', 'formidable' ),
720 + 'class' => 'frm_noallow',
721 + 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
722 + 'icon' => 'frm_icon_font frm_download_icon',
723 + );
724 + }
725 +
696 726 $actions['frm_edit'] = array(
697 727 'url' => '#',
698 728 'label' => __( 'Edit Entry', 'formidable' ),
699 729 'class' => 'frm_noallow',
@@ -708,11 +738,35 @@
708 738 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
709 739 }
710 740
711 741 /**
742 + * Gets data attributes for PDFs addon upgrade link.
743 + *
744 + * @param string $medium The source of the upgrade link used for analytics data.
745 + * @return array
746 + */
747 + private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
748 + $data = array(
749 + 'oneclick' => '',
750 + 'requires' => '',
751 + 'upgrade' => __( 'Forms to PDF', 'formidable' ),
752 + 'medium' => $medium,
753 + );
754 +
755 + $upgrading = FrmAddonsController::install_link( 'pdfs' );
756 + if ( isset( $upgrading['url'] ) ) {
757 + $data['oneclick'] = json_encode( $upgrading );
758 + } else {
759 + $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
760 + }
761 +
762 + return $data;
763 + }
764 +
765 + /**
712 766 * @since 5.0.15
713 767 *
714 - * @param string|int $entry_id
768 + * @param int|string $entry_id
715 769 * @return void
716 770 */
717 771 public static function maybe_render_captcha_score( $entry_id ) {
718 772 $query = array(
@@ -729,6 +783,83 @@
729 783 echo '</div>';
730 784 return;
731 785 }
732 786 }
787 + }
788 +
789 + /**
790 + * Return entry status based on is_draft column value.
791 + *
792 + * @since 6.5
793 + *
794 + * @param int $status is_draft column.
795 + *
796 + * @return int
797 + */
798 + public static function get_entry_status( $status ) {
799 + $statuses = self::get_entry_statuses();
800 +
801 + if ( array_key_exists( $status, $statuses ) ) {
802 + return $status;
803 + }
804 +
805 + if ( empty( $status ) ) {
806 + // If the status is empty, let's default to 0.
807 + return self::SUBMITTED_ENTRY_STATUS;
808 + }
809 +
810 + // 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.
811 + return self::DRAFT_ENTRY_STATUS;
812 + }
813 +
814 + /**
815 + * Return entry status label based on passed value.
816 + *
817 + * @since 6.5
818 + *
819 + * @param int $status is_draft column.
820 + *
821 + * @return string
822 + */
823 + public static function get_entry_status_label( $status ) {
824 + $statuses = self::get_entry_statuses();
825 +
826 + return $statuses[ self::get_entry_status( $status ) ];
827 + }
828 +
829 + /**
830 + * Get all entry statuses.
831 + *
832 + * @since 6.5
833 + * @since 6.6 function went from private to public.
834 + *
835 + * @return array<string>
836 + */
837 + public static function get_entry_statuses() {
838 +
839 + $default_entry_statuses = array(
840 + self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
841 + self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
842 + );
843 +
844 + /**
845 + * Register entry status.
846 + *
847 + * "2" is used in abandonment-addon and reserved for "In progress".
848 + * "3" is used in abandonment-addon and reserved for "Abandoned".
849 + *
850 + * @since 6.5
851 + *
852 + * @param array<string> $extended_entry_status Entry statuses.
853 + */
854 + $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
855 +
856 + if ( ! is_array( $extended_entry_status ) ) {
857 + _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
858 + $extended_entry_status = array();
859 + }
860 +
861 + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
862 +
863 + return $existing_entry_statuses;
733 864 }
734 865 }