| @@ -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 ( ! empty( $pages ) ) { | |
| 105 | - $post_id = end( $pages ); | |
| 104 | + if ( isset( $pages ) && ! 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'] ) ) { |
| @@ -116,12 +116,9 @@ | ||
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | }//end if |
| 119 | 119 | |
| 120 | - /** | |
| 121 | - * @since 6.18 Added `url` to the $args. | |
| 122 | - */ | |
| 123 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 120 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 124 | 121 | |
| 125 | 122 | echo wp_json_encode( $response ); |
| 126 | 123 | wp_die(); |
| 127 | 124 | } |
| @@ -165,9 +162,9 @@ | ||
| 165 | 162 | if ( empty( $selected_form ) ) { |
| 166 | 163 | return; |
| 167 | 164 | } |
| 168 | 165 | |
| 169 | - $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 ] : ''; | |
| 170 | 167 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 171 | 168 | return; |
| 172 | 169 | } |
| 173 | 170 | |
| @@ -180,9 +177,9 @@ | ||
| 180 | 177 | * @param array $form |
| 181 | 178 | * @param string $value |
| 182 | 179 | */ |
| 183 | 180 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 184 | - if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { | |
| 181 | + if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 185 | 182 | return $form[ $value ]; |
| 186 | 183 | } |
| 187 | 184 | |
| 188 | 185 | return ''; |
| @@ -191,16 +188,17 @@ | ||
| 191 | 188 | /** |
| 192 | 189 | * @since 4.06.02 |
| 193 | 190 | * |
| 194 | 191 | * @param array $form The posted form values. |
| 195 | - * @return array|null The array of created pages. | |
| 192 | + * | |
| 193 | + * @return array The array of created pages. | |
| 196 | 194 | */ |
| 197 | 195 | private static function create_pages_for_import( $form ) { |
| 198 | - if ( empty( $form['pages'] ) ) { | |
| 199 | - return null; | |
| 196 | + if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 197 | + return; | |
| 200 | 198 | } |
| 201 | 199 | |
| 202 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 200 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 203 | 201 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 204 | 202 | |
| 205 | 203 | $page_ids = array(); |
| 206 | 204 | foreach ( (array) $form['pages'] as $for => $name ) { |
| @@ -212,9 +210,9 @@ | ||
| 212 | 210 | if ( $for === 'view' ) { |
| 213 | 211 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 214 | 212 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 215 | 213 | } elseif ( $for === 'form' ) { |
| 216 | - $item_key = $form_key; | |
| 214 | + $item_key = $form_key; | |
| 217 | 215 | $shortcode = '[formidable id=%1$s]'; |
| 218 | 216 | } else { |
| 219 | 217 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 220 | 218 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -303,9 +301,9 @@ | ||
| 303 | 301 | * @return void |
| 304 | 302 | */ |
| 305 | 303 | public static function form( $errors = array(), $message = '' ) { |
| 306 | 304 | $where = array( |
| 307 | - 'status' => array( null, '', 'published' ), | |
| 305 | + 'status' => array( null, '', 'published' ), | |
| 308 | 306 | ); |
| 309 | 307 | $forms = FrmForm::getAll( $where, 'name' ); |
| 310 | 308 | |
| 311 | 309 | $export_types = array( |
| @@ -345,9 +343,8 @@ | ||
| 345 | 343 | |
| 346 | 344 | return; |
| 347 | 345 | } |
| 348 | 346 | |
| 349 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 350 | 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; |
| 351 | 348 | if ( ! $has_file ) { |
| 352 | 349 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 353 | 350 | self::form( $errors ); |
| @@ -354,9 +351,9 @@ | ||
| 354 | 351 | |
| 355 | 352 | return; |
| 356 | 353 | } |
| 357 | 354 | |
| 358 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 355 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 359 | 356 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 360 | 357 | |
| 361 | 358 | if ( ! is_uploaded_file( $file ) ) { |
| 362 | 359 | unset( $file ); |
| @@ -374,9 +371,9 @@ | ||
| 374 | 371 | ), |
| 375 | 372 | ); |
| 376 | 373 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 377 | 374 | |
| 378 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 375 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 379 | 376 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 380 | 377 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 381 | 378 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 382 | 379 | // allow other file types to be imported |
| @@ -544,9 +541,9 @@ | ||
| 544 | 541 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 545 | 542 | unset( $tb_type ); |
| 546 | 543 | }//end foreach |
| 547 | 544 | |
| 548 | - $filename = self::get_file_name( $args, $records ); | |
| 545 | + $filename = self::get_file_name( $args, $type, $records ); | |
| 549 | 546 | |
| 550 | 547 | header( 'Content-Description: File Transfer' ); |
| 551 | 548 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 552 | 549 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -555,39 +552,18 @@ | ||
| 555 | 552 | include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; |
| 556 | 553 | } |
| 557 | 554 | |
| 558 | 555 | /** |
| 559 | - * Returns an array that has parent term slugs for the terms provided. | |
| 560 | - * | |
| 561 | - * @since 6.8.3 | |
| 562 | - * @param array $terms | |
| 563 | - * @return array | |
| 564 | - */ | |
| 565 | - public static function get_parent_terms_slugs( $terms ) { | |
| 566 | - $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); | |
| 567 | - $parent_slugs = array(); | |
| 568 | - | |
| 569 | - if ( ! $parent_term_ids ) { | |
| 570 | - return $parent_slugs; | |
| 571 | - } | |
| 572 | - | |
| 573 | - $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' ); | |
| 574 | - $parent_slugs = wp_list_pluck( $results, 'slug', 'term_id' ); | |
| 575 | - | |
| 576 | - return $parent_slugs; | |
| 577 | - } | |
| 578 | - | |
| 579 | - /** | |
| 580 | 556 | * @return void |
| 581 | 557 | */ |
| 582 | 558 | private static function prepare_types_array( &$type ) { |
| 583 | 559 | $type = (array) $type; |
| 584 | - if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 560 | + if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 585 | 561 | // make sure the form is included if there are entries |
| 586 | 562 | $type[] = 'forms'; |
| 587 | 563 | } |
| 588 | 564 | |
| 589 | - if ( in_array( 'forms', $type, true ) ) { | |
| 565 | + if ( in_array( 'forms', $type ) ) { | |
| 590 | 566 | // include actions with forms |
| 591 | 567 | $type[] = 'actions'; |
| 592 | 568 | } |
| 593 | 569 | } |
| @@ -598,13 +574,15 @@ | ||
| 598 | 574 | * |
| 599 | 575 | * @since 3.06 |
| 600 | 576 | * |
| 601 | 577 | * @param array $args |
| 578 | + * @param array $type | |
| 602 | 579 | * @param array $records |
| 580 | + * | |
| 603 | 581 | * @return string |
| 604 | 582 | */ |
| 605 | - private static function get_file_name( $args, $records ) { | |
| 606 | - $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 583 | + private static function get_file_name( $args, $type, $records ) { | |
| 584 | + $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 607 | 585 | if ( $has_one_form ) { |
| 608 | 586 | // one form is being exported |
| 609 | 587 | $selected_form_id = reset( $args['ids'] ); |
| 610 | 588 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -664,11 +642,9 @@ | ||
| 664 | 642 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 665 | 643 | } |
| 666 | 644 | |
| 667 | 645 | // Remove time limit to execute this function. |
| 668 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 669 | - set_time_limit( 0 ); | |
| 670 | - } | |
| 646 | + set_time_limit( 0 ); | |
| 671 | 647 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 672 | 648 | if ( (int) $mem_limit < 256 ) { |
| 673 | 649 | wp_raise_memory_limit(); |
| 674 | 650 | } |