| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | * @return void |
| 17 | 17 | */ |
| 18 | 18 | public static function add_default_templates() { |
| 19 | 19 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 20 | - // XML import is not enabled on your server | |
| 20 | + // XML import is not enabled on your server. | |
| 21 | 21 | return; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $set_err = libxml_use_internal_errors( true ); |
| @@ -87,9 +87,9 @@ | ||
| 87 | 87 | end( $imported['form_status'] ); |
| 88 | 88 | $form_id = key( $imported['form_status'] ); |
| 89 | 89 | $response = array( |
| 90 | 90 | 'id' => $form_id, |
| 91 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 91 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 92 | 92 | 'success' => 1, |
| 93 | 93 | ); |
| 94 | 94 | if ( ! empty( $imported['imported']['posts'] ) ) { |
| 95 | 95 | // Return the link to the last page created. |
| @@ -100,10 +100,10 @@ | ||
| 100 | 100 | // Create selected pages with the correct shortcodes. |
| 101 | 101 | $pages = self::create_pages_for_import( $form ); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - if ( isset( $pages ) && ! empty( $pages ) ) { | |
| 105 | - $post_id = end( $pages ); | |
| 104 | + if ( ! empty( $pages ) ) { | |
| 105 | + $post_id = end( $pages ); | |
| 106 | 106 | $response['redirect'] = get_permalink( $post_id ); |
| 107 | 107 | } |
| 108 | 108 | } else { |
| 109 | 109 | if ( isset( $imported['error'] ) ) { |
| @@ -114,9 +114,9 @@ | ||
| 114 | 114 | $response = array( |
| 115 | 115 | 'message' => $message, |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - } | |
| 118 | + }//end if | |
| 119 | 119 | |
| 120 | 120 | $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); |
| 121 | 121 | |
| 122 | 122 | echo wp_json_encode( $response ); |
| @@ -162,9 +162,9 @@ | ||
| 162 | 162 | if ( empty( $selected_form ) ) { |
| 163 | 163 | return; |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 166 | + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 167 | 167 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| @@ -173,13 +173,13 @@ | ||
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * @since 4.06.02 |
| 176 | 176 | * |
| 177 | + * @param array $form | |
| 177 | 178 | * @param string $value |
| 178 | - * @param array $form | |
| 179 | 179 | */ |
| 180 | 180 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 181 | - if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 181 | + if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { | |
| 182 | 182 | return $form[ $value ]; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return ''; |
| @@ -188,17 +188,16 @@ | ||
| 188 | 188 | /** |
| 189 | 189 | * @since 4.06.02 |
| 190 | 190 | * |
| 191 | 191 | * @param array $form The posted form values. |
| 192 | - * | |
| 193 | - * @return array The array of created pages. | |
| 192 | + * @return array|null The array of created pages. | |
| 194 | 193 | */ |
| 195 | 194 | private static function create_pages_for_import( $form ) { |
| 196 | - if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 197 | - return; | |
| 195 | + if ( empty( $form['pages'] ) ) { | |
| 196 | + return null; | |
| 198 | 197 | } |
| 199 | 198 | |
| 200 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 199 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 201 | 200 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 202 | 201 | |
| 203 | 202 | $page_ids = array(); |
| 204 | 203 | foreach ( (array) $form['pages'] as $for => $name ) { |
| @@ -210,9 +209,9 @@ | ||
| 210 | 209 | if ( $for === 'view' ) { |
| 211 | 210 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 212 | 211 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 213 | 212 | } elseif ( $for === 'form' ) { |
| 214 | - $item_key = $form_key; | |
| 213 | + $item_key = $form_key; | |
| 215 | 214 | $shortcode = '[formidable id=%1$s]'; |
| 216 | 215 | } else { |
| 217 | 216 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 218 | 217 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -229,9 +228,9 @@ | ||
| 229 | 228 | 'post_type' => 'page', |
| 230 | 229 | 'post_content' => sprintf( $shortcode, $item_key ), |
| 231 | 230 | ) |
| 232 | 231 | ); |
| 233 | - } | |
| 232 | + }//end foreach | |
| 234 | 233 | |
| 235 | 234 | return $page_ids; |
| 236 | 235 | } |
| 237 | 236 | |
| @@ -295,15 +294,15 @@ | ||
| 295 | 294 | } |
| 296 | 295 | |
| 297 | 296 | /** |
| 298 | 297 | * @param string[] $errors |
| 299 | - * @param string $message | |
| 298 | + * @param string $message | |
| 300 | 299 | * |
| 301 | 300 | * @return void |
| 302 | 301 | */ |
| 303 | 302 | public static function form( $errors = array(), $message = '' ) { |
| 304 | 303 | $where = array( |
| 305 | - 'status' => array( null, '', 'published' ), | |
| 304 | + 'status' => array( null, '', 'published' ), | |
| 306 | 305 | ); |
| 307 | 306 | $forms = FrmForm::getAll( $where, 'name' ); |
| 308 | 307 | |
| 309 | 308 | $export_types = array( |
| @@ -343,9 +342,10 @@ | ||
| 343 | 342 | |
| 344 | 343 | return; |
| 345 | 344 | } |
| 346 | 345 | |
| 347 | - $has_file = isset( $_FILES ) && isset( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0; | |
| 346 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 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; | |
| 348 | 348 | if ( ! $has_file ) { |
| 349 | 349 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 350 | 350 | self::form( $errors ); |
| 351 | 351 | |
| @@ -351,9 +351,9 @@ | ||
| 351 | 351 | |
| 352 | 352 | return; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 355 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 356 | 356 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 357 | 357 | |
| 358 | 358 | if ( ! is_uploaded_file( $file ) ) { |
| 359 | 359 | unset( $file ); |
| @@ -362,10 +362,8 @@ | ||
| 362 | 362 | |
| 363 | 363 | return; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); | |
| 367 | - | |
| 368 | 366 | $export_format = array( |
| 369 | 367 | 'xml' => array( |
| 370 | 368 | 'name' => 'XML', |
| 371 | 369 | 'support' => 'forms', |
| @@ -373,9 +371,9 @@ | ||
| 373 | 371 | ), |
| 374 | 372 | ); |
| 375 | 373 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 376 | 374 | |
| 377 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 375 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 378 | 376 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 379 | 377 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 380 | 378 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 381 | 379 | // allow other file types to be imported |
| @@ -435,9 +433,10 @@ | ||
| 435 | 433 | wp_die(); |
| 436 | 434 | } |
| 437 | 435 | |
| 438 | 436 | /** |
| 439 | - * @param array $args | |
| 437 | + * @param string[] $type | |
| 438 | + * @param array $args | |
| 440 | 439 | * |
| 441 | 440 | * @psalm-param array{ids?: mixed} $args |
| 442 | 441 | * |
| 443 | 442 | * @return void |
| @@ -476,9 +475,9 @@ | ||
| 476 | 475 | $query_vars = array(); |
| 477 | 476 | |
| 478 | 477 | switch ( $tb_type ) { |
| 479 | 478 | case 'forms': |
| 480 | - //add forms | |
| 479 | + // Add forms. | |
| 481 | 480 | if ( $args['ids'] ) { |
| 482 | 481 | $where[] = array( |
| 483 | 482 | 'or' => 1, |
| 484 | 483 | $table . '.id' => $args['ids'], |
| @@ -536,15 +535,15 @@ | ||
| 536 | 535 | $where['pm.meta_value >'] = 1; |
| 537 | 536 | } else { |
| 538 | 537 | $where['pm.meta_value'] = $args['ids']; |
| 539 | 538 | } |
| 540 | - } | |
| 539 | + }//end switch | |
| 541 | 540 | |
| 542 | 541 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 543 | 542 | unset( $tb_type ); |
| 544 | - } | |
| 543 | + }//end foreach | |
| 545 | 544 | |
| 546 | - $filename = self::get_file_name( $args, $type, $records ); | |
| 545 | + $filename = self::get_file_name( $args, $records ); | |
| 547 | 546 | |
| 548 | 547 | header( 'Content-Description: File Transfer' ); |
| 549 | 548 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 550 | 549 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -553,18 +552,39 @@ | ||
| 553 | 552 | include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; |
| 554 | 553 | } |
| 555 | 554 | |
| 556 | 555 | /** |
| 556 | + * Returns an array that has parent term slugs for the terms provided. | |
| 557 | + * | |
| 558 | + * @since 6.8.3 | |
| 559 | + * @param array $terms | |
| 560 | + * @return array | |
| 561 | + */ | |
| 562 | + public static function get_parent_terms_slugs( $terms ) { | |
| 563 | + $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); | |
| 564 | + $parent_slugs = array(); | |
| 565 | + | |
| 566 | + if ( ! $parent_term_ids ) { | |
| 567 | + return $parent_slugs; | |
| 568 | + } | |
| 569 | + | |
| 570 | + $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' ); | |
| 571 | + $parent_slugs = wp_list_pluck( $results, 'slug', 'term_id' ); | |
| 572 | + | |
| 573 | + return $parent_slugs; | |
| 574 | + } | |
| 575 | + | |
| 576 | + /** | |
| 557 | 577 | * @return void |
| 558 | 578 | */ |
| 559 | 579 | private static function prepare_types_array( &$type ) { |
| 560 | 580 | $type = (array) $type; |
| 561 | - if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 581 | + if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 562 | 582 | // make sure the form is included if there are entries |
| 563 | 583 | $type[] = 'forms'; |
| 564 | 584 | } |
| 565 | 585 | |
| 566 | - if ( in_array( 'forms', $type ) ) { | |
| 586 | + if ( in_array( 'forms', $type, true ) ) { | |
| 567 | 587 | // include actions with forms |
| 568 | 588 | $type[] = 'actions'; |
| 569 | 589 | } |
| 570 | 590 | } |
| @@ -574,16 +594,14 @@ | ||
| 574 | 594 | * Use the nme of the form if only one form is exported. |
| 575 | 595 | * |
| 576 | 596 | * @since 3.06 |
| 577 | 597 | * |
| 578 | - * @param array $type | |
| 598 | + * @param array $args | |
| 579 | 599 | * @param array $records |
| 580 | - * @param array $args | |
| 581 | - * | |
| 582 | 600 | * @return string |
| 583 | 601 | */ |
| 584 | - private static function get_file_name( $args, $type, $records ) { | |
| 585 | - $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 602 | + private static function get_file_name( $args, $records ) { | |
| 603 | + $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 586 | 604 | if ( $has_one_form ) { |
| 587 | 605 | // one form is being exported |
| 588 | 606 | $selected_form_id = reset( $args['ids'] ); |
| 589 | 607 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -603,9 +621,9 @@ | ||
| 603 | 621 | if ( ! empty( $sitename ) ) { |
| 604 | 622 | $sitename .= '.'; |
| 605 | 623 | } |
| 606 | 624 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 607 | - } | |
| 625 | + }//end if | |
| 608 | 626 | |
| 609 | 627 | /** |
| 610 | 628 | * @since 5.3 |
| 611 | 629 | * |
| @@ -642,9 +660,12 @@ | ||
| 642 | 660 | $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' ); |
| 643 | 661 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 644 | 662 | } |
| 645 | 663 | |
| 646 | - set_time_limit( 0 ); //Remove time limit to execute this function | |
| 664 | + // Remove time limit to execute this function. | |
| 665 | + if ( function_exists( 'set_time_limit' ) ) { | |
| 666 | + set_time_limit( 0 ); | |
| 667 | + } | |
| 647 | 668 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 648 | 669 | if ( (int) $mem_limit < 256 ) { |
| 649 | 670 | wp_raise_memory_limit(); |
| 650 | 671 | } |
| @@ -699,9 +720,9 @@ | ||
| 699 | 720 | * |
| 700 | 721 | * @since 2.0.19 |
| 701 | 722 | * @since 5.0.16 function went from private to public. |
| 702 | 723 | * |
| 703 | - * @param int $form_id | |
| 724 | + * @param int $form_id | |
| 704 | 725 | * @param object $form |
| 705 | 726 | * |
| 706 | 727 | * @return array $csv_fields |
| 707 | 728 | */ |