| @@ -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 | |
| @@ -134,9 +130,8 @@ | ||
| 134 | 130 | * 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 | 131 | * This is to make sure that the URL can't be exploited for a SSRF attack. |
| 136 | 132 | * |
| 137 | 133 | * @since 5.5.5 |
| 138 | - * | |
| 139 | 134 | * @param string $url |
| 140 | 135 | * |
| 141 | 136 | * @return bool True on success, False on error. |
| 142 | 137 | */ |
| @@ -150,13 +145,11 @@ | ||
| 150 | 145 | * @return mixed |
| 151 | 146 | */ |
| 152 | 147 | private static function get_posted_form() { |
| 153 | 148 | $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' ); |
| 154 | - | |
| 155 | 149 | if ( empty( $form ) ) { |
| 156 | 150 | return $form; |
| 157 | 151 | } |
| 158 | - | |
| 159 | 152 | $form = json_decode( $form, true ); |
| 160 | 153 | return $form; |
| 161 | 154 | } |
| 162 | 155 | |
| @@ -164,22 +157,17 @@ | ||
| 164 | 157 | * Get a different URL depending on the selection in the form. |
| 165 | 158 | * |
| 166 | 159 | * @since 4.06.02 |
| 167 | 160 | * |
| 168 | - * @param array $form The posted form values. | |
| 169 | - * @param string $url The URL to override. | |
| 170 | - * | |
| 171 | 161 | * @return void |
| 172 | 162 | */ |
| 173 | 163 | private static function override_url( $form, &$url ) { |
| 174 | 164 | $selected_form = self::get_selected_in_form( $form, 'form' ); |
| 175 | - | |
| 176 | 165 | if ( empty( $selected_form ) ) { |
| 177 | 166 | return; |
| 178 | 167 | } |
| 179 | 168 | |
| 180 | 169 | $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; |
| 181 | - | |
| 182 | 170 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 183 | 171 | return; |
| 184 | 172 | } |
| 185 | 173 | |
| @@ -190,10 +178,8 @@ | ||
| 190 | 178 | * @since 4.06.02 |
| 191 | 179 | * |
| 192 | 180 | * @param array $form |
| 193 | 181 | * @param string $value |
| 194 | - * | |
| 195 | - * @return string | |
| 196 | 182 | */ |
| 197 | 183 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 198 | 184 | if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { |
| 199 | 185 | return $form[ $value ]; |
| @@ -205,9 +191,8 @@ | ||
| 205 | 191 | /** |
| 206 | 192 | * @since 4.06.02 |
| 207 | 193 | * |
| 208 | 194 | * @param array $form The posted form values. |
| 209 | - * | |
| 210 | 195 | * @return array|null The array of created pages. |
| 211 | 196 | */ |
| 212 | 197 | private static function create_pages_for_import( $form ) { |
| 213 | 198 | if ( empty( $form['pages'] ) ) { |
| @@ -217,9 +202,8 @@ | ||
| 217 | 202 | $form_key = self::get_selected_in_form( $form, 'form' ); |
| 218 | 203 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 219 | 204 | |
| 220 | 205 | $page_ids = array(); |
| 221 | - | |
| 222 | 206 | foreach ( (array) $form['pages'] as $for => $name ) { |
| 223 | 207 | if ( empty( $name ) ) { |
| 224 | 208 | // Don't create a page if no title is given. |
| 225 | 209 | continue; |
| @@ -260,9 +244,8 @@ | ||
| 260 | 244 | * |
| 261 | 245 | * @since 3.06 |
| 262 | 246 | * |
| 263 | 247 | * @param object $xml The values included in the XML. |
| 264 | - * | |
| 265 | 248 | * @return void |
| 266 | 249 | */ |
| 267 | 250 | private static function set_new_form_name( &$xml ) { |
| 268 | 251 | if ( ! isset( $xml->form ) ) { |
| @@ -270,9 +253,8 @@ | ||
| 270 | 253 | } |
| 271 | 254 | |
| 272 | 255 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 273 | 256 | $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 274 | - | |
| 275 | 257 | if ( ! $name && ! $description ) { |
| 276 | 258 | return; |
| 277 | 259 | } |
| 278 | 260 | |
| @@ -277,9 +259,8 @@ | ||
| 277 | 259 | } |
| 278 | 260 | |
| 279 | 261 | // Get the main form ID. |
| 280 | 262 | $set_name = 0; |
| 281 | - | |
| 282 | 263 | foreach ( $xml->form as $form ) { |
| 283 | 264 | if ( empty( $form->parent_form_id ) ) { |
| 284 | 265 | $set_name = (int) $form->id; |
| 285 | 266 | } |
| @@ -357,9 +338,8 @@ | ||
| 357 | 338 | $errors = array(); |
| 358 | 339 | $message = ''; |
| 359 | 340 | |
| 360 | 341 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
| 361 | - | |
| 362 | 342 | if ( false !== $permission_error ) { |
| 363 | 343 | $errors[] = $permission_error; |
| 364 | 344 | self::form( $errors ); |
| 365 | 345 | |
| @@ -367,9 +347,8 @@ | ||
| 367 | 347 | } |
| 368 | 348 | |
| 369 | 349 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 370 | 350 | $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 | 351 | if ( ! $has_file ) { |
| 373 | 352 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 374 | 353 | self::form( $errors ); |
| 375 | 354 | |
| @@ -398,9 +377,8 @@ | ||
| 398 | 377 | |
| 399 | 378 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing |
| 400 | 379 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 401 | 380 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 402 | - | |
| 403 | 381 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 404 | 382 | // allow other file types to be imported |
| 405 | 383 | do_action( 'frm_before_import_' . $file_type ); |
| 406 | 384 | |
| @@ -433,9 +411,8 @@ | ||
| 433 | 411 | * @return void |
| 434 | 412 | */ |
| 435 | 413 | public static function export_xml() { |
| 436 | 414 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 437 | - | |
| 438 | 415 | if ( ! empty( $error ) ) { |
| 439 | 416 | wp_die( esc_html( $error ) ); |
| 440 | 417 | } |
| 441 | 418 | |
| @@ -459,10 +436,10 @@ | ||
| 459 | 436 | wp_die(); |
| 460 | 437 | } |
| 461 | 438 | |
| 462 | 439 | /** |
| 463 | - * @param array<string>|string $type | |
| 464 | - * @param array $args | |
| 440 | + * @param string[] $type | |
| 441 | + * @param array $args | |
| 465 | 442 | * |
| 466 | 443 | * @psalm-param array{ids?: mixed} $args |
| 467 | 444 | * |
| 468 | 445 | * @return void |
| @@ -471,15 +448,8 @@ | ||
| 471 | 448 | global $wpdb; |
| 472 | 449 | |
| 473 | 450 | self::prepare_types_array( $type ); |
| 474 | 451 | |
| 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 | 452 | $tables = array( |
| 483 | 453 | 'items' => $wpdb->prefix . 'frm_items', |
| 484 | 454 | 'forms' => $wpdb->prefix . 'frm_forms', |
| 485 | 455 | 'posts' => $wpdb->posts, |
| @@ -522,9 +492,8 @@ | ||
| 522 | 492 | break; |
| 523 | 493 | case 'actions': |
| 524 | 494 | $select = $table . '.ID'; |
| 525 | 495 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 526 | - | |
| 527 | 496 | if ( ! empty( $args['ids'] ) ) { |
| 528 | 497 | $where['menu_order'] = $args['ids']; |
| 529 | 498 | } |
| 530 | 499 | break; |
| @@ -539,12 +508,10 @@ | ||
| 539 | 508 | $frm_style = new FrmStyle(); |
| 540 | 509 | $default_style = $frm_style->get_default_style(); |
| 541 | 510 | $form_ids = $args['ids']; |
| 542 | 511 | $style_ids = array(); |
| 543 | - | |
| 544 | 512 | foreach ( $form_ids as $form_id ) { |
| 545 | 513 | $form_data = FrmForm::getOne( $form_id ); |
| 546 | - | |
| 547 | 514 | // For forms that have not been updated while running 2.0, check if custom_style is set. |
| 548 | 515 | if ( isset( $form_data->options['custom_style'] ) ) { |
| 549 | 516 | if ( 1 === absint( $form_data->options['custom_style'] ) ) { |
| 550 | 517 | $style_ids[] = $default_style->ID; |
| @@ -553,9 +520,8 @@ | ||
| 553 | 520 | } |
| 554 | 521 | } |
| 555 | 522 | unset( $form_id, $form_data ); |
| 556 | 523 | } |
| 557 | - | |
| 558 | 524 | $select = $table . '.ID'; |
| 559 | 525 | $where['post_type'] = 'frm_styles'; |
| 560 | 526 | |
| 561 | 527 | // Only export selected styles. |
| @@ -592,11 +558,9 @@ | ||
| 592 | 558 | /** |
| 593 | 559 | * Returns an array that has parent term slugs for the terms provided. |
| 594 | 560 | * |
| 595 | 561 | * @since 6.8.3 |
| 596 | - * | |
| 597 | 562 | * @param array $terms |
| 598 | - * | |
| 599 | 563 | * @return array |
| 600 | 564 | */ |
| 601 | 565 | public static function get_parent_terms_slugs( $terms ) { |
| 602 | 566 | $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); |
| @@ -612,17 +576,12 @@ | ||
| 612 | 576 | return $parent_slugs; |
| 613 | 577 | } |
| 614 | 578 | |
| 615 | 579 | /** |
| 616 | - * Prepare the types array. | |
| 617 | - * | |
| 618 | - * @param array<string>|string $type | |
| 619 | - * | |
| 620 | 580 | * @return void |
| 621 | 581 | */ |
| 622 | 582 | private static function prepare_types_array( &$type ) { |
| 623 | 583 | $type = (array) $type; |
| 624 | - | |
| 625 | 584 | if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { |
| 626 | 585 | // make sure the form is included if there are entries |
| 627 | 586 | $type[] = 'forms'; |
| 628 | 587 | } |
| @@ -640,14 +599,12 @@ | ||
| 640 | 599 | * @since 3.06 |
| 641 | 600 | * |
| 642 | 601 | * @param array $args |
| 643 | 602 | * @param array $records |
| 644 | - * | |
| 645 | 603 | * @return string |
| 646 | 604 | */ |
| 647 | 605 | private static function get_file_name( $args, $records ) { |
| 648 | 606 | $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; |
| 649 | - | |
| 650 | 607 | if ( $has_one_form ) { |
| 651 | 608 | // one form is being exported |
| 652 | 609 | $selected_form_id = reset( $args['ids'] ); |
| 653 | 610 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -653,9 +610,8 @@ | ||
| 653 | 610 | $filename = 'form-' . $selected_form_id . '.xml'; |
| 654 | 611 | |
| 655 | 612 | foreach ( $records['forms'] as $form_id ) { |
| 656 | 613 | $filename = 'form-' . $form_id . '.xml'; |
| 657 | - | |
| 658 | 614 | if ( $selected_form_id === $form_id ) { |
| 659 | 615 | $form = FrmForm::getOne( $form_id ); |
| 660 | 616 | $filename = $form->name !== '' ? $form->name : $form->form_key; |
| 661 | 617 | $filename = sanitize_title( $filename ) . '-form.xml'; |
| @@ -667,9 +623,8 @@ | ||
| 667 | 623 | |
| 668 | 624 | if ( ! empty( $sitename ) ) { |
| 669 | 625 | $sitename .= '.'; |
| 670 | 626 | } |
| 671 | - | |
| 672 | 627 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 673 | 628 | }//end if |
| 674 | 629 | |
| 675 | 630 | /** |
| @@ -686,9 +641,8 @@ | ||
| 686 | 641 | * @return void |
| 687 | 642 | */ |
| 688 | 643 | public static function generate_csv( $atts ) { |
| 689 | 644 | $form_ids = $atts['ids']; |
| 690 | - | |
| 691 | 645 | if ( empty( $form_ids ) ) { |
| 692 | 646 | wp_die( esc_html__( 'Please select a form', 'formidable' ) ); |
| 693 | 647 | } |
| 694 | 648 | self::csv( reset( $form_ids ) ); |
| @@ -698,12 +652,8 @@ | ||
| 698 | 652 | * Export to CSV |
| 699 | 653 | * |
| 700 | 654 | * @since 2.0.19 |
| 701 | 655 | * |
| 702 | - * @param false|int|string $form_id | |
| 703 | - * @param string $search | |
| 704 | - * @param string $fid | |
| 705 | - * | |
| 706 | 656 | * @return void |
| 707 | 657 | */ |
| 708 | 658 | public static function csv( $form_id = false, $search = '', $fid = '' ) { |
| 709 | 659 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| @@ -717,11 +667,9 @@ | ||
| 717 | 667 | // Remove time limit to execute this function. |
| 718 | 668 | if ( function_exists( 'set_time_limit' ) ) { |
| 719 | 669 | set_time_limit( 0 ); |
| 720 | 670 | } |
| 721 | - | |
| 722 | 671 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 723 | - | |
| 724 | 672 | if ( (int) $mem_limit < 256 ) { |
| 725 | 673 | wp_raise_memory_limit(); |
| 726 | 674 | } |
| 727 | 675 | |
| @@ -737,9 +685,8 @@ | ||
| 737 | 685 | $form_id = $form->id; |
| 738 | 686 | $form_cols = self::get_fields_for_csv_export( $form_id, $form ); |
| 739 | 687 | |
| 740 | 688 | $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); |
| 741 | - | |
| 742 | 689 | if ( ! empty( $item_id ) ) { |
| 743 | 690 | $item_id = explode( ',', $item_id ); |
| 744 | 691 | } |
| 745 | 692 | |
| @@ -784,9 +731,8 @@ | ||
| 784 | 731 | */ |
| 785 | 732 | public static function get_fields_for_csv_export( $form_id, $form ) { |
| 786 | 733 | $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' ); |
| 787 | 734 | $no_export_fields = FrmField::no_save_fields(); |
| 788 | - | |
| 789 | 735 | foreach ( $csv_fields as $k => $f ) { |
| 790 | 736 | if ( in_array( $f->type, $no_export_fields, true ) ) { |
| 791 | 737 | unset( $csv_fields[ $k ] ); |
| 792 | 738 | } |
| @@ -794,13 +740,8 @@ | ||
| 794 | 740 | |
| 795 | 741 | return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) ); |
| 796 | 742 | } |
| 797 | 743 | |
| 798 | - /** | |
| 799 | - * @param array $mimes | |
| 800 | - * | |
| 801 | - * @return array | |
| 802 | - */ | |
| 803 | 744 | public static function allow_mime( $mimes ) { |
| 804 | 745 | if ( ! isset( $mimes['csv'] ) ) { |
| 805 | 746 | // allow csv files |
| 806 | 747 | $mimes['csv'] = 'text/csv'; |