| @@ -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,11 +114,14 @@ | ||
| 114 | 114 | $response = array( |
| 115 | 115 | 'message' => $message, |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - } | |
| 118 | + }//end if | |
| 119 | 119 | |
| 120 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 120 | + /** | |
| 121 | + * @since 6.18 Added `url` to the $args. | |
| 122 | + */ | |
| 123 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 121 | 124 | |
| 122 | 125 | echo wp_json_encode( $response ); |
| 123 | 126 | wp_die(); |
| 124 | 127 | } |
| @@ -162,9 +165,9 @@ | ||
| 162 | 165 | if ( empty( $selected_form ) ) { |
| 163 | 166 | return; |
| 164 | 167 | } |
| 165 | 168 | |
| 166 | - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 169 | + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 167 | 170 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 168 | 171 | return; |
| 169 | 172 | } |
| 170 | 173 | |
| @@ -173,13 +176,13 @@ | ||
| 173 | 176 | |
| 174 | 177 | /** |
| 175 | 178 | * @since 4.06.02 |
| 176 | 179 | * |
| 180 | + * @param array $form | |
| 177 | 181 | * @param string $value |
| 178 | - * @param array $form | |
| 179 | 182 | */ |
| 180 | 183 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 181 | - if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 184 | + if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { | |
| 182 | 185 | return $form[ $value ]; |
| 183 | 186 | } |
| 184 | 187 | |
| 185 | 188 | return ''; |
| @@ -188,17 +191,16 @@ | ||
| 188 | 191 | /** |
| 189 | 192 | * @since 4.06.02 |
| 190 | 193 | * |
| 191 | 194 | * @param array $form The posted form values. |
| 192 | - * | |
| 193 | - * @return array The array of created pages. | |
| 195 | + * @return array|null The array of created pages. | |
| 194 | 196 | */ |
| 195 | 197 | private static function create_pages_for_import( $form ) { |
| 196 | - if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 197 | - return; | |
| 198 | + if ( empty( $form['pages'] ) ) { | |
| 199 | + return null; | |
| 198 | 200 | } |
| 199 | 201 | |
| 200 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 202 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 201 | 203 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 202 | 204 | |
| 203 | 205 | $page_ids = array(); |
| 204 | 206 | foreach ( (array) $form['pages'] as $for => $name ) { |
| @@ -210,9 +212,9 @@ | ||
| 210 | 212 | if ( $for === 'view' ) { |
| 211 | 213 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 212 | 214 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 213 | 215 | } elseif ( $for === 'form' ) { |
| 214 | - $item_key = $form_key; | |
| 216 | + $item_key = $form_key; | |
| 215 | 217 | $shortcode = '[formidable id=%1$s]'; |
| 216 | 218 | } else { |
| 217 | 219 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 218 | 220 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -229,9 +231,9 @@ | ||
| 229 | 231 | 'post_type' => 'page', |
| 230 | 232 | 'post_content' => sprintf( $shortcode, $item_key ), |
| 231 | 233 | ) |
| 232 | 234 | ); |
| 233 | - } | |
| 235 | + }//end foreach | |
| 234 | 236 | |
| 235 | 237 | return $page_ids; |
| 236 | 238 | } |
| 237 | 239 | |
| @@ -295,15 +297,15 @@ | ||
| 295 | 297 | } |
| 296 | 298 | |
| 297 | 299 | /** |
| 298 | 300 | * @param string[] $errors |
| 299 | - * @param string $message | |
| 301 | + * @param string $message | |
| 300 | 302 | * |
| 301 | 303 | * @return void |
| 302 | 304 | */ |
| 303 | 305 | public static function form( $errors = array(), $message = '' ) { |
| 304 | 306 | $where = array( |
| 305 | - 'status' => array( null, '', 'published' ), | |
| 307 | + 'status' => array( null, '', 'published' ), | |
| 306 | 308 | ); |
| 307 | 309 | $forms = FrmForm::getAll( $where, 'name' ); |
| 308 | 310 | |
| 309 | 311 | $export_types = array( |
| @@ -343,9 +345,10 @@ | ||
| 343 | 345 | |
| 344 | 346 | return; |
| 345 | 347 | } |
| 346 | 348 | |
| 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; | |
| 349 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 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; | |
| 348 | 351 | if ( ! $has_file ) { |
| 349 | 352 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 350 | 353 | self::form( $errors ); |
| 351 | 354 | |
| @@ -351,9 +354,9 @@ | ||
| 351 | 354 | |
| 352 | 355 | return; |
| 353 | 356 | } |
| 354 | 357 | |
| 355 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 358 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 356 | 359 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 357 | 360 | |
| 358 | 361 | if ( ! is_uploaded_file( $file ) ) { |
| 359 | 362 | unset( $file ); |
| @@ -362,10 +365,8 @@ | ||
| 362 | 365 | |
| 363 | 366 | return; |
| 364 | 367 | } |
| 365 | 368 | |
| 366 | - //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); | |
| 367 | - | |
| 368 | 369 | $export_format = array( |
| 369 | 370 | 'xml' => array( |
| 370 | 371 | 'name' => 'XML', |
| 371 | 372 | 'support' => 'forms', |
| @@ -373,9 +374,9 @@ | ||
| 373 | 374 | ), |
| 374 | 375 | ); |
| 375 | 376 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 376 | 377 | |
| 377 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 378 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 378 | 379 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 379 | 380 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 380 | 381 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 381 | 382 | // allow other file types to be imported |
| @@ -435,9 +436,10 @@ | ||
| 435 | 436 | wp_die(); |
| 436 | 437 | } |
| 437 | 438 | |
| 438 | 439 | /** |
| 439 | - * @param array $args | |
| 440 | + * @param string[] $type | |
| 441 | + * @param array $args | |
| 440 | 442 | * |
| 441 | 443 | * @psalm-param array{ids?: mixed} $args |
| 442 | 444 | * |
| 443 | 445 | * @return void |
| @@ -476,9 +478,9 @@ | ||
| 476 | 478 | $query_vars = array(); |
| 477 | 479 | |
| 478 | 480 | switch ( $tb_type ) { |
| 479 | 481 | case 'forms': |
| 480 | - //add forms | |
| 482 | + // Add forms. | |
| 481 | 483 | if ( $args['ids'] ) { |
| 482 | 484 | $where[] = array( |
| 483 | 485 | 'or' => 1, |
| 484 | 486 | $table . '.id' => $args['ids'], |
| @@ -536,15 +538,15 @@ | ||
| 536 | 538 | $where['pm.meta_value >'] = 1; |
| 537 | 539 | } else { |
| 538 | 540 | $where['pm.meta_value'] = $args['ids']; |
| 539 | 541 | } |
| 540 | - } | |
| 542 | + }//end switch | |
| 541 | 543 | |
| 542 | 544 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 543 | 545 | unset( $tb_type ); |
| 544 | - } | |
| 546 | + }//end foreach | |
| 545 | 547 | |
| 546 | - $filename = self::get_file_name( $args, $type, $records ); | |
| 548 | + $filename = self::get_file_name( $args, $records ); | |
| 547 | 549 | |
| 548 | 550 | header( 'Content-Description: File Transfer' ); |
| 549 | 551 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 550 | 552 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -553,18 +555,39 @@ | ||
| 553 | 555 | include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; |
| 554 | 556 | } |
| 555 | 557 | |
| 556 | 558 | /** |
| 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 | + /** | |
| 557 | 580 | * @return void |
| 558 | 581 | */ |
| 559 | 582 | private static function prepare_types_array( &$type ) { |
| 560 | 583 | $type = (array) $type; |
| 561 | - if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 584 | + if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 562 | 585 | // make sure the form is included if there are entries |
| 563 | 586 | $type[] = 'forms'; |
| 564 | 587 | } |
| 565 | 588 | |
| 566 | - if ( in_array( 'forms', $type ) ) { | |
| 589 | + if ( in_array( 'forms', $type, true ) ) { | |
| 567 | 590 | // include actions with forms |
| 568 | 591 | $type[] = 'actions'; |
| 569 | 592 | } |
| 570 | 593 | } |
| @@ -574,16 +597,14 @@ | ||
| 574 | 597 | * Use the nme of the form if only one form is exported. |
| 575 | 598 | * |
| 576 | 599 | * @since 3.06 |
| 577 | 600 | * |
| 578 | - * @param array $type | |
| 601 | + * @param array $args | |
| 579 | 602 | * @param array $records |
| 580 | - * @param array $args | |
| 581 | - * | |
| 582 | 603 | * @return string |
| 583 | 604 | */ |
| 584 | - private static function get_file_name( $args, $type, $records ) { | |
| 585 | - $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 605 | + private static function get_file_name( $args, $records ) { | |
| 606 | + $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 586 | 607 | if ( $has_one_form ) { |
| 587 | 608 | // one form is being exported |
| 588 | 609 | $selected_form_id = reset( $args['ids'] ); |
| 589 | 610 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -603,9 +624,9 @@ | ||
| 603 | 624 | if ( ! empty( $sitename ) ) { |
| 604 | 625 | $sitename .= '.'; |
| 605 | 626 | } |
| 606 | 627 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 607 | - } | |
| 628 | + }//end if | |
| 608 | 629 | |
| 609 | 630 | /** |
| 610 | 631 | * @since 5.3 |
| 611 | 632 | * |
| @@ -642,9 +663,12 @@ | ||
| 642 | 663 | $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' ); |
| 643 | 664 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 644 | 665 | } |
| 645 | 666 | |
| 646 | - set_time_limit( 0 ); //Remove time limit to execute this function | |
| 667 | + // Remove time limit to execute this function. | |
| 668 | + if ( function_exists( 'set_time_limit' ) ) { | |
| 669 | + set_time_limit( 0 ); | |
| 670 | + } | |
| 647 | 671 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 648 | 672 | if ( (int) $mem_limit < 256 ) { |
| 649 | 673 | wp_raise_memory_limit(); |
| 650 | 674 | } |
| @@ -699,9 +723,9 @@ | ||
| 699 | 723 | * |
| 700 | 724 | * @since 2.0.19 |
| 701 | 725 | * @since 5.0.16 function went from private to public. |
| 702 | 726 | * |
| 703 | - * @param int $form_id | |
| 727 | + * @param int $form_id | |
| 704 | 728 | * @param object $form |
| 705 | 729 | * |
| 706 | 730 | * @return array $csv_fields |
| 707 | 731 | */ |