| @@ -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,11 +101,11 @@ | ||
| 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 | |
| 105 | + * @param object $field - this is passed by reference since it is an object. | |
| 90 | 106 | * @param boolean $reset |
| 91 | - * @param array $args | |
| 107 | + * @param array $args | |
| 92 | 108 | * |
| 93 | 109 | * @return string|array $new_value |
| 94 | 110 | */ |
| 95 | 111 | private static function get_field_value_for_new_entry( $field, $reset, $args ) { |
| @@ -111,9 +127,9 @@ | ||
| 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 | 133 | * @return boolean $value_is_posted |
| 118 | 134 | */ |
| 119 | 135 | public static function value_is_posted( $field, $args ) { |
| @@ -244,10 +260,10 @@ | ||
| 244 | 260 | /** |
| 245 | 261 | * Prepare the saved value for display |
| 246 | 262 | * |
| 247 | 263 | * @param array|string $value |
| 248 | - * @param object $field | |
| 249 | - * @param array $atts | |
| 264 | + * @param object $field | |
| 265 | + * @param array $atts | |
| 250 | 266 | * |
| 251 | 267 | * @return string |
| 252 | 268 | */ |
| 253 | 269 | public static function display_value( $value, $field, $atts = array() ) { |
| @@ -385,11 +401,11 @@ | ||
| 385 | 401 | * Check if field has an "Other" option and if any other values are posted |
| 386 | 402 | * |
| 387 | 403 | * @since 2.0 |
| 388 | 404 | * |
| 389 | - * @param object $field | |
| 405 | + * @param object $field | |
| 390 | 406 | * @param string|array $value |
| 391 | - * @param array $args | |
| 407 | + * @param array $args | |
| 392 | 408 | */ |
| 393 | 409 | public static function maybe_set_other_validation( $field, &$value, &$args ) { |
| 394 | 410 | $args['other'] = false; |
| 395 | 411 | if ( ! $value || ! FrmAppHelper::pro_is_installed() ) { |
| @@ -426,11 +442,11 @@ | ||
| 426 | 442 | * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
| 427 | 443 | * |
| 428 | 444 | * @since 2.0 |
| 429 | 445 | * |
| 430 | - * @param object $field | |
| 446 | + * @param object $field | |
| 431 | 447 | * @param string|array $value |
| 432 | - * @param array $args | |
| 448 | + * @param array $args | |
| 433 | 449 | */ |
| 434 | 450 | public static function set_other_repeating_vals( $field, &$value, &$args ) { |
| 435 | 451 | if ( ! $args['parent_field_id'] ) { |
| 436 | 452 | return; |
| @@ -459,11 +475,11 @@ | ||
| 459 | 475 | * |
| 460 | 476 | * @since 2.0 |
| 461 | 477 | * |
| 462 | 478 | * @param string|array $value |
| 463 | - * @param string|array $other_vals (usually of posted values) | |
| 464 | - * @param object $field | |
| 465 | - * @param array $args | |
| 479 | + * @param string|array $other_vals (usually of posted values). | |
| 480 | + * @param object $field | |
| 481 | + * @param array $args | |
| 466 | 482 | */ |
| 467 | 483 | public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
| 468 | 484 | // Checkboxes and multi-select dropdowns. |
| 469 | 485 | if ( is_array( $value ) && $field->type === 'checkbox' ) { |
| @@ -505,10 +521,10 @@ | ||
| 505 | 521 | } |
| 506 | 522 | } |
| 507 | 523 | } elseif ( $field->options[ $other_key ] == $value ) { |
| 508 | 524 | $value = $other_vals; |
| 509 | - } | |
| 510 | - } | |
| 525 | + }//end if | |
| 526 | + }//end if | |
| 511 | 527 | } |
| 512 | 528 | |
| 513 | 529 | /** |
| 514 | 530 | * Add submitted values to a string for spam checking. |
| @@ -583,16 +599,17 @@ | ||
| 583 | 599 | |
| 584 | 600 | // finally get the correct version number |
| 585 | 601 | $known = array( 'Version', $ub, 'other' ); |
| 586 | 602 | $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#'; |
| 587 | - preg_match_all( $pattern, $u_agent, $matches ); // get the matching numbers | |
| 603 | + // Get the matching numbers. | |
| 604 | + preg_match_all( $pattern, $u_agent, $matches ); | |
| 588 | 605 | |
| 589 | 606 | // see how many we have |
| 590 | 607 | $i = count( $matches['browser'] ); |
| 591 | 608 | |
| 592 | 609 | 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 | |
| 610 | + // We will have two since we are not using 'other' argument yet | |
| 611 | + // see if version is before or after the name. | |
| 595 | 612 | if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) { |
| 596 | 613 | $version = $matches['version'][0]; |
| 597 | 614 | } else { |
| 598 | 615 | $version = $matches['version'][1]; |
| @@ -640,9 +657,9 @@ | ||
| 640 | 657 | <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span> |
| 641 | 658 | </a> |
| 642 | 659 | </div> |
| 643 | 660 | <?php |
| 644 | - } | |
| 661 | + }//end foreach | |
| 645 | 662 | } |
| 646 | 663 | |
| 647 | 664 | /** |
| 648 | 665 | * @since 3.0 |
| @@ -692,8 +709,18 @@ | ||
| 692 | 709 | ), |
| 693 | 710 | 'icon' => 'frm_icon_font frm_email_icon', |
| 694 | 711 | ); |
| 695 | 712 | |
| 713 | + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) { | |
| 714 | + $actions['frm_download_pdf'] = array( | |
| 715 | + 'url' => '#', | |
| 716 | + 'label' => __( 'Download as PDF', 'formidable' ), | |
| 717 | + 'class' => 'frm_noallow', | |
| 718 | + 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ), | |
| 719 | + 'icon' => 'frm_icon_font frm_download_icon', | |
| 720 | + ); | |
| 721 | + } | |
| 722 | + | |
| 696 | 723 | $actions['frm_edit'] = array( |
| 697 | 724 | 'url' => '#', |
| 698 | 725 | 'label' => __( 'Edit Entry', 'formidable' ), |
| 699 | 726 | 'class' => 'frm_noallow', |
| @@ -708,8 +735,32 @@ | ||
| 708 | 735 | return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) ); |
| 709 | 736 | } |
| 710 | 737 | |
| 711 | 738 | /** |
| 739 | + * Gets data attributes for PDFs addon upgrade link. | |
| 740 | + * | |
| 741 | + * @param string $medium The source of the upgrade link used for analytics data. | |
| 742 | + * @return array | |
| 743 | + */ | |
| 744 | + private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) { | |
| 745 | + $data = array( | |
| 746 | + 'oneclick' => '', | |
| 747 | + 'requires' => '', | |
| 748 | + 'upgrade' => __( 'Forms to PDF', 'formidable' ), | |
| 749 | + 'medium' => $medium, | |
| 750 | + ); | |
| 751 | + | |
| 752 | + $upgrading = FrmAddonsController::install_link( 'pdfs' ); | |
| 753 | + if ( isset( $upgrading['url'] ) ) { | |
| 754 | + $data['oneclick'] = json_encode( $upgrading ); | |
| 755 | + } else { | |
| 756 | + $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 ); | |
| 757 | + } | |
| 758 | + | |
| 759 | + return $data; | |
| 760 | + } | |
| 761 | + | |
| 762 | + /** | |
| 712 | 763 | * @since 5.0.15 |
| 713 | 764 | * |
| 714 | 765 | * @param string|int $entry_id |
| 715 | 766 | * @return void |
| @@ -730,5 +781,83 @@ | ||
| 730 | 781 | return; |
| 731 | 782 | } |
| 732 | 783 | } |
| 733 | 784 | } |
| 785 | + | |
| 786 | + /** | |
| 787 | + * Return entry status based on is_draft column value. | |
| 788 | + * | |
| 789 | + * @since 6.5 | |
| 790 | + * | |
| 791 | + * @param int $status is_draft column. | |
| 792 | + * | |
| 793 | + * @return int | |
| 794 | + */ | |
| 795 | + public static function get_entry_status( $status ) { | |
| 796 | + $statuses = self::get_entry_statuses(); | |
| 797 | + | |
| 798 | + if ( array_key_exists( $status, $statuses ) ) { | |
| 799 | + return $status; | |
| 800 | + } | |
| 801 | + | |
| 802 | + if ( empty( $status ) ) { | |
| 803 | + // If the status is empty, let's default to 0. | |
| 804 | + return self::SUBMITTED_ENTRY_STATUS; | |
| 805 | + } | |
| 806 | + | |
| 807 | + // 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. | |
| 808 | + return self::DRAFT_ENTRY_STATUS; | |
| 809 | + } | |
| 810 | + | |
| 811 | + /** | |
| 812 | + * Return entry status label based on passed value. | |
| 813 | + * | |
| 814 | + * @since 6.5 | |
| 815 | + * | |
| 816 | + * @param int $status is_draft column. | |
| 817 | + * | |
| 818 | + * @return string | |
| 819 | + */ | |
| 820 | + public static function get_entry_status_label( $status ) { | |
| 821 | + $statuses = self::get_entry_statuses(); | |
| 822 | + | |
| 823 | + return $statuses[ self::get_entry_status( $status ) ]; | |
| 824 | + } | |
| 825 | + | |
| 826 | + /** | |
| 827 | + * Get all entry statuses. | |
| 828 | + * | |
| 829 | + * @since 6.5 | |
| 830 | + * @since 6.6 function went from private to public. | |
| 831 | + * | |
| 832 | + * @return array<string> | |
| 833 | + */ | |
| 834 | + public static function get_entry_statuses() { | |
| 835 | + | |
| 836 | + $default_entry_statuses = array( | |
| 837 | + self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ), | |
| 838 | + self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ), | |
| 839 | + ); | |
| 840 | + | |
| 841 | + /** | |
| 842 | + * Register entry status. | |
| 843 | + * | |
| 844 | + * "2" is used in abandonment-addon and reserved for "In progress". | |
| 845 | + * "3" is used in abandonment-addon and reserved for "Abandoned". | |
| 846 | + * | |
| 847 | + * @since 6.5 | |
| 848 | + * | |
| 849 | + * @param array<string> $extended_entry_status Entry statuses. | |
| 850 | + */ | |
| 851 | + $extended_entry_status = apply_filters( 'frm_entry_statuses', array() ); | |
| 852 | + | |
| 853 | + if ( ! is_array( $extended_entry_status ) ) { | |
| 854 | + _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' ); | |
| 855 | + $extended_entry_status = array(); | |
| 856 | + } | |
| 857 | + | |
| 858 | + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status ); | |
| 859 | + | |
| 860 | + return $existing_entry_statuses; | |
| 861 | + } | |
| 862 | + | |
| 734 | 863 | } |