PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.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 +173 -38 6.36.16.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',
@@ -669,9 +693,9 @@
669 693 ),
670 694 );
671 695 }
672 696
673 - if ( $page == 'show' ) {
697 + if ( $page === 'show' ) {
674 698 $actions['frm_print'] = array(
675 699 'url' => '#',
676 700 'label' => __( 'Print Entry', 'formidable' ),
677 701 'data' => array(
@@ -692,8 +716,18 @@
692 716 ),
693 717 'icon' => 'frm_icon_font frm_email_icon',
694 718 );
695 719
720 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
721 + $actions['frm_download_pdf'] = array(
722 + 'url' => '#',
723 + 'label' => __( 'Download as PDF', 'formidable' ),
724 + 'class' => 'frm_noallow',
725 + 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
726 + 'icon' => 'frm_icon_font frm_download_icon',
727 + );
728 + }
729 +
696 730 $actions['frm_edit'] = array(
697 731 'url' => '#',
698 732 'label' => __( 'Edit Entry', 'formidable' ),
699 733 'class' => 'frm_noallow',
@@ -708,11 +742,35 @@
708 742 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
709 743 }
710 744
711 745 /**
746 + * Gets data attributes for PDFs addon upgrade link.
747 + *
748 + * @param string $medium The source of the upgrade link used for analytics data.
749 + * @return array
750 + */
751 + private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
752 + $data = array(
753 + 'oneclick' => '',
754 + 'requires' => '',
755 + 'upgrade' => __( 'Forms to PDF', 'formidable' ),
756 + 'medium' => $medium,
757 + );
758 +
759 + $upgrading = FrmAddonsController::install_link( 'pdfs' );
760 + if ( isset( $upgrading['url'] ) ) {
761 + $data['oneclick'] = json_encode( $upgrading );
762 + } else {
763 + $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
764 + }
765 +
766 + return $data;
767 + }
768 +
769 + /**
712 770 * @since 5.0.15
713 771 *
714 - * @param string|int $entry_id
772 + * @param int|string $entry_id
715 773 * @return void
716 774 */
717 775 public static function maybe_render_captcha_score( $entry_id ) {
718 776 $query = array(
@@ -729,6 +787,83 @@
729 787 echo '</div>';
730 788 return;
731 789 }
732 790 }
791 + }
792 +
793 + /**
794 + * Return entry status based on is_draft column value.
795 + *
796 + * @since 6.5
797 + *
798 + * @param int $status is_draft column.
799 + *
800 + * @return int
801 + */
802 + public static function get_entry_status( $status ) {
803 + $statuses = self::get_entry_statuses();
804 +
805 + if ( array_key_exists( $status, $statuses ) ) {
806 + return $status;
807 + }
808 +
809 + if ( empty( $status ) ) {
810 + // If the status is empty, let's default to 0.
811 + return self::SUBMITTED_ENTRY_STATUS;
812 + }
813 +
814 + // 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.
815 + return self::DRAFT_ENTRY_STATUS;
816 + }
817 +
818 + /**
819 + * Return entry status label based on passed value.
820 + *
821 + * @since 6.5
822 + *
823 + * @param int $status is_draft column.
824 + *
825 + * @return string
826 + */
827 + public static function get_entry_status_label( $status ) {
828 + $statuses = self::get_entry_statuses();
829 +
830 + return $statuses[ self::get_entry_status( $status ) ];
831 + }
832 +
833 + /**
834 + * Get all entry statuses.
835 + *
836 + * @since 6.5
837 + * @since 6.6 function went from private to public.
838 + *
839 + * @return array<string>
840 + */
841 + public static function get_entry_statuses() {
842 +
843 + $default_entry_statuses = array(
844 + self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
845 + self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
846 + );
847 +
848 + /**
849 + * Register entry status.
850 + *
851 + * "2" is used in abandonment-addon and reserved for "In progress".
852 + * "3" is used in abandonment-addon and reserved for "Abandoned".
853 + *
854 + * @since 6.5
855 + *
856 + * @param array<string> $extended_entry_status Entry statuses.
857 + */
858 + $extended_entry_status = apply_filters( 'frm_entry_statuses', array() );
859 +
860 + if ( ! is_array( $extended_entry_status ) ) {
861 + _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
862 + $extended_entry_status = array();
863 + }
864 +
865 + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
866 +
867 + return $existing_entry_statuses;
733 868 }
734 869 }