| @@ -40,9 +40,8 @@ | ||
| 40 | 40 | /** |
| 41 | 41 | * Use the template link to install the XML template |
| 42 | 42 | * |
| 43 | 43 | * @since 3.06 |
| 44 | - * | |
| 45 | 44 | * @return void |
| 46 | 45 | */ |
| 47 | 46 | public static function install_template() { |
| 48 | 47 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| @@ -82,9 +81,8 @@ | ||
| 82 | 81 | |
| 83 | 82 | self::set_new_form_name( $xml ); |
| 84 | 83 | |
| 85 | 84 | $imported = FrmXMLHelper::import_xml_now( $xml, true ); |
| 86 | - | |
| 87 | 85 | if ( ! empty( $imported['form_status'] ) ) { |
| 88 | 86 | // Get the last form id in case there are child forms. |
| 89 | 87 | end( $imported['form_status'] ); |
| 90 | 88 | $form_id = key( $imported['form_status'] ); |
| @@ -92,9 +90,8 @@ | ||
| 92 | 90 | 'id' => $form_id, |
| 93 | 91 | 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', |
| 94 | 92 | 'success' => 1, |
| 95 | 93 | ); |
| 96 | - | |
| 97 | 94 | if ( ! empty( $imported['imported']['posts'] ) ) { |
| 98 | 95 | // Return the link to the last page created. |
| 99 | 96 | $pages = $imported['posts']; |
| 100 | 97 | } |
| @@ -113,9 +110,8 @@ | ||
| 113 | 110 | $message = $imported['error']; |
| 114 | 111 | } else { |
| 115 | 112 | $message = __( 'There was an error importing form', 'formidable' ); |
| 116 | 113 | } |
| 117 | - | |
| 118 | 114 | $response = array( |
| 119 | 115 | 'message' => $message, |
| 120 | 116 | ); |
| 121 | 117 | |
| @@ -120,12 +116,9 @@ | ||
| 120 | 116 | ); |
| 121 | 117 | |
| 122 | 118 | }//end if |
| 123 | 119 | |
| 124 | - /** | |
| 125 | - * @since 6.18 Added `url` to the $args. | |
| 126 | - */ | |
| 127 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 120 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 128 | 121 | |
| 129 | 122 | echo wp_json_encode( $response ); |
| 130 | 123 | wp_die(); |
| 131 | 124 | } |
| @@ -134,9 +127,8 @@ | ||
| 134 | 127 | * Make sure that the XML file we're trying to load is in fact an XML file, and that it's coming from our S3 bucket. |
| 135 | 128 | * This is to make sure that the URL can't be exploited for a SSRF attack. |
| 136 | 129 | * |
| 137 | 130 | * @since 5.5.5 |
| 138 | - * | |
| 139 | 131 | * @param string $url |
| 140 | 132 | * |
| 141 | 133 | * @return bool True on success, False on error. |
| 142 | 134 | */ |
| @@ -150,13 +142,11 @@ | ||
| 150 | 142 | * @return mixed |
| 151 | 143 | */ |
| 152 | 144 | private static function get_posted_form() { |
| 153 | 145 | $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' ); |
| 154 | - | |
| 155 | 146 | if ( empty( $form ) ) { |
| 156 | 147 | return $form; |
| 157 | 148 | } |
| 158 | - | |
| 159 | 149 | $form = json_decode( $form, true ); |
| 160 | 150 | return $form; |
| 161 | 151 | } |
| 162 | 152 | |
| @@ -164,22 +154,17 @@ | ||
| 164 | 154 | * Get a different URL depending on the selection in the form. |
| 165 | 155 | * |
| 166 | 156 | * @since 4.06.02 |
| 167 | 157 | * |
| 168 | - * @param array $form The posted form values. | |
| 169 | - * @param string $url The URL to override. | |
| 170 | - * | |
| 171 | 158 | * @return void |
| 172 | 159 | */ |
| 173 | 160 | private static function override_url( $form, &$url ) { |
| 174 | 161 | $selected_form = self::get_selected_in_form( $form, 'form' ); |
| 175 | - | |
| 176 | 162 | if ( empty( $selected_form ) ) { |
| 177 | 163 | return; |
| 178 | 164 | } |
| 179 | 165 | |
| 180 | 166 | $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; |
| 181 | - | |
| 182 | 167 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 183 | 168 | return; |
| 184 | 169 | } |
| 185 | 170 | |
| @@ -190,10 +175,8 @@ | ||
| 190 | 175 | * @since 4.06.02 |
| 191 | 176 | * |
| 192 | 177 | * @param array $form |
| 193 | 178 | * @param string $value |
| 194 | - * | |
| 195 | - * @return string | |
| 196 | 179 | */ |
| 197 | 180 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 198 | 181 | if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { |
| 199 | 182 | return $form[ $value ]; |
| @@ -205,9 +188,8 @@ | ||
| 205 | 188 | /** |
| 206 | 189 | * @since 4.06.02 |
| 207 | 190 | * |
| 208 | 191 | * @param array $form The posted form values. |
| 209 | - * | |
| 210 | 192 | * @return array|null The array of created pages. |
| 211 | 193 | */ |
| 212 | 194 | private static function create_pages_for_import( $form ) { |
| 213 | 195 | if ( empty( $form['pages'] ) ) { |
| @@ -217,9 +199,8 @@ | ||
| 217 | 199 | $form_key = self::get_selected_in_form( $form, 'form' ); |
| 218 | 200 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 219 | 201 | |
| 220 | 202 | $page_ids = array(); |
| 221 | - | |
| 222 | 203 | foreach ( (array) $form['pages'] as $for => $name ) { |
| 223 | 204 | if ( empty( $name ) ) { |
| 224 | 205 | // Don't create a page if no title is given. |
| 225 | 206 | continue; |
| @@ -260,9 +241,8 @@ | ||
| 260 | 241 | * |
| 261 | 242 | * @since 3.06 |
| 262 | 243 | * |
| 263 | 244 | * @param object $xml The values included in the XML. |
| 264 | - * | |
| 265 | 245 | * @return void |
| 266 | 246 | */ |
| 267 | 247 | private static function set_new_form_name( &$xml ) { |
| 268 | 248 | if ( ! isset( $xml->form ) ) { |
| @@ -270,9 +250,8 @@ | ||
| 270 | 250 | } |
| 271 | 251 | |
| 272 | 252 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 273 | 253 | $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 274 | - | |
| 275 | 254 | if ( ! $name && ! $description ) { |
| 276 | 255 | return; |
| 277 | 256 | } |
| 278 | 257 | |
| @@ -277,9 +256,8 @@ | ||
| 277 | 256 | } |
| 278 | 257 | |
| 279 | 258 | // Get the main form ID. |
| 280 | 259 | $set_name = 0; |
| 281 | - | |
| 282 | 260 | foreach ( $xml->form as $form ) { |
| 283 | 261 | if ( empty( $form->parent_form_id ) ) { |
| 284 | 262 | $set_name = (int) $form->id; |
| 285 | 263 | } |
| @@ -357,9 +335,8 @@ | ||
| 357 | 335 | $errors = array(); |
| 358 | 336 | $message = ''; |
| 359 | 337 | |
| 360 | 338 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
| 361 | - | |
| 362 | 339 | if ( false !== $permission_error ) { |
| 363 | 340 | $errors[] = $permission_error; |
| 364 | 341 | self::form( $errors ); |
| 365 | 342 | |
| @@ -367,9 +344,8 @@ | ||
| 367 | 344 | } |
| 368 | 345 | |
| 369 | 346 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 370 | 347 | $has_file = ! empty( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0; |
| 371 | - | |
| 372 | 348 | if ( ! $has_file ) { |
| 373 | 349 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 374 | 350 | self::form( $errors ); |
| 375 | 351 | |
| @@ -398,9 +374,8 @@ | ||
| 398 | 374 | |
| 399 | 375 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing |
| 400 | 376 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 401 | 377 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 402 | - | |
| 403 | 378 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 404 | 379 | // allow other file types to be imported |
| 405 | 380 | do_action( 'frm_before_import_' . $file_type ); |
| 406 | 381 | |
| @@ -433,9 +408,8 @@ | ||
| 433 | 408 | * @return void |
| 434 | 409 | */ |
| 435 | 410 | public static function export_xml() { |
| 436 | 411 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 437 | - | |
| 438 | 412 | if ( ! empty( $error ) ) { |
| 439 | 413 | wp_die( esc_html( $error ) ); |
| 440 | 414 | } |
| 441 | 415 | |
| @@ -459,10 +433,10 @@ | ||
| 459 | 433 | wp_die(); |
| 460 | 434 | } |
| 461 | 435 | |
| 462 | 436 | /** |
| 463 | - * @param array<string>|string $type | |
| 464 | - * @param array $args | |
| 437 | + * @param string[] $type | |
| 438 | + * @param array $args | |
| 465 | 439 | * |
| 466 | 440 | * @psalm-param array{ids?: mixed} $args |
| 467 | 441 | * |
| 468 | 442 | * @return void |
| @@ -471,15 +445,8 @@ | ||
| 471 | 445 | global $wpdb; |
| 472 | 446 | |
| 473 | 447 | self::prepare_types_array( $type ); |
| 474 | 448 | |
| 475 | - if ( ! is_array( $type ) ) { | |
| 476 | - // This shouldn't be possible. | |
| 477 | - // It is cast to array in prepare_types_array. | |
| 478 | - // This is just for static analysis. | |
| 479 | - return; | |
| 480 | - } | |
| 481 | - | |
| 482 | 449 | $tables = array( |
| 483 | 450 | 'items' => $wpdb->prefix . 'frm_items', |
| 484 | 451 | 'forms' => $wpdb->prefix . 'frm_forms', |
| 485 | 452 | 'posts' => $wpdb->posts, |
| @@ -522,9 +489,8 @@ | ||
| 522 | 489 | break; |
| 523 | 490 | case 'actions': |
| 524 | 491 | $select = $table . '.ID'; |
| 525 | 492 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 526 | - | |
| 527 | 493 | if ( ! empty( $args['ids'] ) ) { |
| 528 | 494 | $where['menu_order'] = $args['ids']; |
| 529 | 495 | } |
| 530 | 496 | break; |
| @@ -539,12 +505,10 @@ | ||
| 539 | 505 | $frm_style = new FrmStyle(); |
| 540 | 506 | $default_style = $frm_style->get_default_style(); |
| 541 | 507 | $form_ids = $args['ids']; |
| 542 | 508 | $style_ids = array(); |
| 543 | - | |
| 544 | 509 | foreach ( $form_ids as $form_id ) { |
| 545 | 510 | $form_data = FrmForm::getOne( $form_id ); |
| 546 | - | |
| 547 | 511 | // For forms that have not been updated while running 2.0, check if custom_style is set. |
| 548 | 512 | if ( isset( $form_data->options['custom_style'] ) ) { |
| 549 | 513 | if ( 1 === absint( $form_data->options['custom_style'] ) ) { |
| 550 | 514 | $style_ids[] = $default_style->ID; |
| @@ -553,9 +517,8 @@ | ||
| 553 | 517 | } |
| 554 | 518 | } |
| 555 | 519 | unset( $form_id, $form_data ); |
| 556 | 520 | } |
| 557 | - | |
| 558 | 521 | $select = $table . '.ID'; |
| 559 | 522 | $where['post_type'] = 'frm_styles'; |
| 560 | 523 | |
| 561 | 524 | // Only export selected styles. |
| @@ -592,11 +555,9 @@ | ||
| 592 | 555 | /** |
| 593 | 556 | * Returns an array that has parent term slugs for the terms provided. |
| 594 | 557 | * |
| 595 | 558 | * @since 6.8.3 |
| 596 | - * | |
| 597 | 559 | * @param array $terms |
| 598 | - * | |
| 599 | 560 | * @return array |
| 600 | 561 | */ |
| 601 | 562 | public static function get_parent_terms_slugs( $terms ) { |
| 602 | 563 | $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); |
| @@ -612,17 +573,12 @@ | ||
| 612 | 573 | return $parent_slugs; |
| 613 | 574 | } |
| 614 | 575 | |
| 615 | 576 | /** |
| 616 | - * Prepare the types array. | |
| 617 | - * | |
| 618 | - * @param array<string>|string $type | |
| 619 | - * | |
| 620 | 577 | * @return void |
| 621 | 578 | */ |
| 622 | 579 | private static function prepare_types_array( &$type ) { |
| 623 | 580 | $type = (array) $type; |
| 624 | - | |
| 625 | 581 | if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { |
| 626 | 582 | // make sure the form is included if there are entries |
| 627 | 583 | $type[] = 'forms'; |
| 628 | 584 | } |
| @@ -640,14 +596,12 @@ | ||
| 640 | 596 | * @since 3.06 |
| 641 | 597 | * |
| 642 | 598 | * @param array $args |
| 643 | 599 | * @param array $records |
| 644 | - * | |
| 645 | 600 | * @return string |
| 646 | 601 | */ |
| 647 | 602 | private static function get_file_name( $args, $records ) { |
| 648 | 603 | $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; |
| 649 | - | |
| 650 | 604 | if ( $has_one_form ) { |
| 651 | 605 | // one form is being exported |
| 652 | 606 | $selected_form_id = reset( $args['ids'] ); |
| 653 | 607 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -653,9 +607,8 @@ | ||
| 653 | 607 | $filename = 'form-' . $selected_form_id . '.xml'; |
| 654 | 608 | |
| 655 | 609 | foreach ( $records['forms'] as $form_id ) { |
| 656 | 610 | $filename = 'form-' . $form_id . '.xml'; |
| 657 | - | |
| 658 | 611 | if ( $selected_form_id === $form_id ) { |
| 659 | 612 | $form = FrmForm::getOne( $form_id ); |
| 660 | 613 | $filename = $form->name !== '' ? $form->name : $form->form_key; |
| 661 | 614 | $filename = sanitize_title( $filename ) . '-form.xml'; |
| @@ -667,9 +620,8 @@ | ||
| 667 | 620 | |
| 668 | 621 | if ( ! empty( $sitename ) ) { |
| 669 | 622 | $sitename .= '.'; |
| 670 | 623 | } |
| 671 | - | |
| 672 | 624 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 673 | 625 | }//end if |
| 674 | 626 | |
| 675 | 627 | /** |
| @@ -686,9 +638,8 @@ | ||
| 686 | 638 | * @return void |
| 687 | 639 | */ |
| 688 | 640 | public static function generate_csv( $atts ) { |
| 689 | 641 | $form_ids = $atts['ids']; |
| 690 | - | |
| 691 | 642 | if ( empty( $form_ids ) ) { |
| 692 | 643 | wp_die( esc_html__( 'Please select a form', 'formidable' ) ); |
| 693 | 644 | } |
| 694 | 645 | self::csv( reset( $form_ids ) ); |
| @@ -698,12 +649,8 @@ | ||
| 698 | 649 | * Export to CSV |
| 699 | 650 | * |
| 700 | 651 | * @since 2.0.19 |
| 701 | 652 | * |
| 702 | - * @param false|int|string $form_id | |
| 703 | - * @param string $search | |
| 704 | - * @param string $fid | |
| 705 | - * | |
| 706 | 653 | * @return void |
| 707 | 654 | */ |
| 708 | 655 | public static function csv( $form_id = false, $search = '', $fid = '' ) { |
| 709 | 656 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| @@ -717,11 +664,9 @@ | ||
| 717 | 664 | // Remove time limit to execute this function. |
| 718 | 665 | if ( function_exists( 'set_time_limit' ) ) { |
| 719 | 666 | set_time_limit( 0 ); |
| 720 | 667 | } |
| 721 | - | |
| 722 | 668 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 723 | - | |
| 724 | 669 | if ( (int) $mem_limit < 256 ) { |
| 725 | 670 | wp_raise_memory_limit(); |
| 726 | 671 | } |
| 727 | 672 | |
| @@ -737,9 +682,8 @@ | ||
| 737 | 682 | $form_id = $form->id; |
| 738 | 683 | $form_cols = self::get_fields_for_csv_export( $form_id, $form ); |
| 739 | 684 | |
| 740 | 685 | $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); |
| 741 | - | |
| 742 | 686 | if ( ! empty( $item_id ) ) { |
| 743 | 687 | $item_id = explode( ',', $item_id ); |
| 744 | 688 | } |
| 745 | 689 | |
| @@ -784,9 +728,8 @@ | ||
| 784 | 728 | */ |
| 785 | 729 | public static function get_fields_for_csv_export( $form_id, $form ) { |
| 786 | 730 | $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' ); |
| 787 | 731 | $no_export_fields = FrmField::no_save_fields(); |
| 788 | - | |
| 789 | 732 | foreach ( $csv_fields as $k => $f ) { |
| 790 | 733 | if ( in_array( $f->type, $no_export_fields, true ) ) { |
| 791 | 734 | unset( $csv_fields[ $k ] ); |
| 792 | 735 | } |
| @@ -794,13 +737,8 @@ | ||
| 794 | 737 | |
| 795 | 738 | return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) ); |
| 796 | 739 | } |
| 797 | 740 | |
| 798 | - /** | |
| 799 | - * @param array $mimes | |
| 800 | - * | |
| 801 | - * @return array | |
| 802 | - */ | |
| 803 | 741 | public static function allow_mime( $mimes ) { |
| 804 | 742 | if ( ! isset( $mimes['csv'] ) ) { |
| 805 | 743 | // allow csv files |
| 806 | 744 | $mimes['csv'] = 'text/csv'; |