| @@ -4,21 +4,15 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmXMLController { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @return void | |
| 10 | - */ | |
| 11 | 8 | public static function menu() { |
| 12 | 9 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); |
| 13 | 10 | } |
| 14 | 11 | |
| 15 | - /** | |
| 16 | - * @return void | |
| 17 | - */ | |
| 18 | 12 | public static function add_default_templates() { |
| 19 | 13 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 20 | - // XML import is not enabled on your server. | |
| 14 | + // XML import is not enabled on your server | |
| 21 | 15 | return; |
| 22 | 16 | } |
| 23 | 17 | |
| 24 | 18 | $set_err = libxml_use_internal_errors( true ); |
| @@ -87,9 +81,9 @@ | ||
| 87 | 81 | end( $imported['form_status'] ); |
| 88 | 82 | $form_id = key( $imported['form_status'] ); |
| 89 | 83 | $response = array( |
| 90 | 84 | 'id' => $form_id, |
| 91 | - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 85 | + 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 92 | 86 | 'success' => 1, |
| 93 | 87 | ); |
| 94 | 88 | if ( ! empty( $imported['imported']['posts'] ) ) { |
| 95 | 89 | // Return the link to the last page created. |
| @@ -100,10 +94,10 @@ | ||
| 100 | 94 | // Create selected pages with the correct shortcodes. |
| 101 | 95 | $pages = self::create_pages_for_import( $form ); |
| 102 | 96 | } |
| 103 | 97 | |
| 104 | - if ( ! empty( $pages ) ) { | |
| 105 | - $post_id = end( $pages ); | |
| 98 | + if ( isset( $pages ) && ! empty( $pages ) ) { | |
| 99 | + $post_id = end( $pages ); | |
| 106 | 100 | $response['redirect'] = get_permalink( $post_id ); |
| 107 | 101 | } |
| 108 | 102 | } else { |
| 109 | 103 | if ( isset( $imported['error'] ) ) { |
| @@ -114,14 +108,11 @@ | ||
| 114 | 108 | $response = array( |
| 115 | 109 | 'message' => $message, |
| 116 | 110 | ); |
| 117 | 111 | |
| 118 | - }//end if | |
| 112 | + } | |
| 119 | 113 | |
| 120 | - /** | |
| 121 | - * @since 6.18 Added `url` to the $args. | |
| 122 | - */ | |
| 123 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 114 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 124 | 115 | |
| 125 | 116 | echo wp_json_encode( $response ); |
| 126 | 117 | wp_die(); |
| 127 | 118 | } |
| @@ -156,10 +147,8 @@ | ||
| 156 | 147 | /** |
| 157 | 148 | * Get a different URL depending on the selection in the form. |
| 158 | 149 | * |
| 159 | 150 | * @since 4.06.02 |
| 160 | - * | |
| 161 | - * @return void | |
| 162 | 151 | */ |
| 163 | 152 | private static function override_url( $form, &$url ) { |
| 164 | 153 | $selected_form = self::get_selected_in_form( $form, 'form' ); |
| 165 | 154 | if ( empty( $selected_form ) ) { |
| @@ -165,9 +154,9 @@ | ||
| 165 | 154 | if ( empty( $selected_form ) ) { |
| 166 | 155 | return; |
| 167 | 156 | } |
| 168 | 157 | |
| 169 | - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 158 | + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 170 | 159 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 171 | 160 | return; |
| 172 | 161 | } |
| 173 | 162 | |
| @@ -175,14 +164,11 @@ | ||
| 175 | 164 | } |
| 176 | 165 | |
| 177 | 166 | /** |
| 178 | 167 | * @since 4.06.02 |
| 179 | - * | |
| 180 | - * @param array $form | |
| 181 | - * @param string $value | |
| 182 | 168 | */ |
| 183 | 169 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 184 | - if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { | |
| 170 | + if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 185 | 171 | return $form[ $value ]; |
| 186 | 172 | } |
| 187 | 173 | |
| 188 | 174 | return ''; |
| @@ -191,16 +177,17 @@ | ||
| 191 | 177 | /** |
| 192 | 178 | * @since 4.06.02 |
| 193 | 179 | * |
| 194 | 180 | * @param array $form The posted form values. |
| 195 | - * @return array|null The array of created pages. | |
| 181 | + * | |
| 182 | + * @return array The array of created pages. | |
| 196 | 183 | */ |
| 197 | 184 | private static function create_pages_for_import( $form ) { |
| 198 | - if ( empty( $form['pages'] ) ) { | |
| 199 | - return null; | |
| 185 | + if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 186 | + return; | |
| 200 | 187 | } |
| 201 | 188 | |
| 202 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 189 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 203 | 190 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 204 | 191 | |
| 205 | 192 | $page_ids = array(); |
| 206 | 193 | foreach ( (array) $form['pages'] as $for => $name ) { |
| @@ -212,9 +199,9 @@ | ||
| 212 | 199 | if ( $for === 'view' ) { |
| 213 | 200 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 214 | 201 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 215 | 202 | } elseif ( $for === 'form' ) { |
| 216 | - $item_key = $form_key; | |
| 203 | + $item_key = $form_key; | |
| 217 | 204 | $shortcode = '[formidable id=%1$s]'; |
| 218 | 205 | } else { |
| 219 | 206 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 220 | 207 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -231,9 +218,9 @@ | ||
| 231 | 218 | 'post_type' => 'page', |
| 232 | 219 | 'post_content' => sprintf( $shortcode, $item_key ), |
| 233 | 220 | ) |
| 234 | 221 | ); |
| 235 | - }//end foreach | |
| 222 | + } | |
| 236 | 223 | |
| 237 | 224 | return $page_ids; |
| 238 | 225 | } |
| 239 | 226 | |
| @@ -278,11 +265,8 @@ | ||
| 278 | 265 | $form->form_key = FrmAppHelper::get_unique_key( $sanitized_form_name, 'frm_forms', 'form_key' ); |
| 279 | 266 | } |
| 280 | 267 | } |
| 281 | 268 | |
| 282 | - /** | |
| 283 | - * @return void | |
| 284 | - */ | |
| 285 | 269 | public static function route() { |
| 286 | 270 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 287 | 271 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 288 | 272 | FrmAppHelper::include_svg(); |
| @@ -287,25 +271,19 @@ | ||
| 287 | 271 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 288 | 272 | FrmAppHelper::include_svg(); |
| 289 | 273 | |
| 290 | 274 | if ( 'import_xml' === $action ) { |
| 291 | - self::import_xml(); | |
| 275 | + return self::import_xml(); | |
| 292 | 276 | } elseif ( 'export_xml' === $action ) { |
| 293 | - self::export_xml(); | |
| 277 | + return self::export_xml(); | |
| 294 | 278 | } elseif ( apply_filters( 'frm_xml_route', true, $action ) ) { |
| 295 | - self::form(); | |
| 279 | + return self::form(); | |
| 296 | 280 | } |
| 297 | 281 | } |
| 298 | 282 | |
| 299 | - /** | |
| 300 | - * @param string[] $errors | |
| 301 | - * @param string $message | |
| 302 | - * | |
| 303 | - * @return void | |
| 304 | - */ | |
| 305 | 283 | public static function form( $errors = array(), $message = '' ) { |
| 306 | 284 | $where = array( |
| 307 | - 'status' => array( null, '', 'published' ), | |
| 285 | + 'status' => array( null, '', 'published' ), | |
| 308 | 286 | ); |
| 309 | 287 | $forms = FrmForm::getAll( $where, 'name' ); |
| 310 | 288 | |
| 311 | 289 | $export_types = array( |
| @@ -327,14 +305,11 @@ | ||
| 327 | 305 | ), |
| 328 | 306 | ); |
| 329 | 307 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 330 | 308 | |
| 331 | - include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php'; | |
| 309 | + include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' ); | |
| 332 | 310 | } |
| 333 | 311 | |
| 334 | - /** | |
| 335 | - * @return void | |
| 336 | - */ | |
| 337 | 312 | public static function import_xml() { |
| 338 | 313 | $errors = array(); |
| 339 | 314 | $message = ''; |
| 340 | 315 | |
| @@ -345,10 +320,9 @@ | ||
| 345 | 320 | |
| 346 | 321 | return; |
| 347 | 322 | } |
| 348 | 323 | |
| 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; | |
| 324 | + $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; | |
| 351 | 325 | if ( ! $has_file ) { |
| 352 | 326 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 353 | 327 | self::form( $errors ); |
| 354 | 328 | |
| @@ -354,9 +328,9 @@ | ||
| 354 | 328 | |
| 355 | 329 | return; |
| 356 | 330 | } |
| 357 | 331 | |
| 358 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 332 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 359 | 333 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 360 | 334 | |
| 361 | 335 | if ( ! is_uploaded_file( $file ) ) { |
| 362 | 336 | unset( $file ); |
| @@ -365,8 +339,10 @@ | ||
| 365 | 339 | |
| 366 | 340 | return; |
| 367 | 341 | } |
| 368 | 342 | |
| 343 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); | |
| 344 | + | |
| 369 | 345 | $export_format = array( |
| 370 | 346 | 'xml' => array( |
| 371 | 347 | 'name' => 'XML', |
| 372 | 348 | 'support' => 'forms', |
| @@ -374,9 +350,9 @@ | ||
| 374 | 350 | ), |
| 375 | 351 | ); |
| 376 | 352 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 377 | 353 | |
| 378 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 354 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 379 | 355 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 380 | 356 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 381 | 357 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 382 | 358 | // allow other file types to be imported |
| @@ -406,11 +382,8 @@ | ||
| 406 | 382 | |
| 407 | 383 | self::form( $errors, $message ); |
| 408 | 384 | } |
| 409 | 385 | |
| 410 | - /** | |
| 411 | - * @return void | |
| 412 | - */ | |
| 413 | 386 | public static function export_xml() { |
| 414 | 387 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 415 | 388 | if ( ! empty( $error ) ) { |
| 416 | 389 | wp_die( esc_html( $error ) ); |
| @@ -435,16 +408,8 @@ | ||
| 435 | 408 | |
| 436 | 409 | wp_die(); |
| 437 | 410 | } |
| 438 | 411 | |
| 439 | - /** | |
| 440 | - * @param string[] $type | |
| 441 | - * @param array $args | |
| 442 | - * | |
| 443 | - * @psalm-param array{ids?: mixed} $args | |
| 444 | - * | |
| 445 | - * @return void | |
| 446 | - */ | |
| 447 | 412 | public static function generate_xml( $type, $args = array() ) { |
| 448 | 413 | global $wpdb; |
| 449 | 414 | |
| 450 | 415 | self::prepare_types_array( $type ); |
| @@ -478,9 +443,9 @@ | ||
| 478 | 443 | $query_vars = array(); |
| 479 | 444 | |
| 480 | 445 | switch ( $tb_type ) { |
| 481 | 446 | case 'forms': |
| 482 | - // Add forms. | |
| 447 | + //add forms | |
| 483 | 448 | if ( $args['ids'] ) { |
| 484 | 449 | $where[] = array( |
| 485 | 450 | 'or' => 1, |
| 486 | 451 | $table . '.id' => $args['ids'], |
| @@ -538,15 +503,15 @@ | ||
| 538 | 503 | $where['pm.meta_value >'] = 1; |
| 539 | 504 | } else { |
| 540 | 505 | $where['pm.meta_value'] = $args['ids']; |
| 541 | 506 | } |
| 542 | - }//end switch | |
| 507 | + } | |
| 543 | 508 | |
| 544 | 509 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 545 | 510 | unset( $tb_type ); |
| 546 | - }//end foreach | |
| 511 | + } | |
| 547 | 512 | |
| 548 | - $filename = self::get_file_name( $args, $records ); | |
| 513 | + $filename = self::get_file_name( $args, $type, $records ); | |
| 549 | 514 | |
| 550 | 515 | header( 'Content-Description: File Transfer' ); |
| 551 | 516 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 552 | 517 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -554,40 +519,16 @@ | ||
| 554 | 519 | echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n"; |
| 555 | 520 | include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; |
| 556 | 521 | } |
| 557 | 522 | |
| 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 | - /** | |
| 580 | - * @return void | |
| 581 | - */ | |
| 582 | 523 | private static function prepare_types_array( &$type ) { |
| 583 | 524 | $type = (array) $type; |
| 584 | - if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 525 | + if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 585 | 526 | // make sure the form is included if there are entries |
| 586 | 527 | $type[] = 'forms'; |
| 587 | 528 | } |
| 588 | 529 | |
| 589 | - if ( in_array( 'forms', $type, true ) ) { | |
| 530 | + if ( in_array( 'forms', $type ) ) { | |
| 590 | 531 | // include actions with forms |
| 591 | 532 | $type[] = 'actions'; |
| 592 | 533 | } |
| 593 | 534 | } |
| @@ -597,14 +538,14 @@ | ||
| 597 | 538 | * Use the nme of the form if only one form is exported. |
| 598 | 539 | * |
| 599 | 540 | * @since 3.06 |
| 600 | 541 | * |
| 601 | - * @param array $args | |
| 542 | + * @param array $type | |
| 602 | 543 | * @param array $records |
| 603 | 544 | * @return string |
| 604 | 545 | */ |
| 605 | - private static function get_file_name( $args, $records ) { | |
| 606 | - $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 546 | + private static function get_file_name( $args, $type, $records ) { | |
| 547 | + $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 607 | 548 | if ( $has_one_form ) { |
| 608 | 549 | // one form is being exported |
| 609 | 550 | $selected_form_id = reset( $args['ids'] ); |
| 610 | 551 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -624,9 +565,9 @@ | ||
| 624 | 565 | if ( ! empty( $sitename ) ) { |
| 625 | 566 | $sitename .= '.'; |
| 626 | 567 | } |
| 627 | 568 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 628 | - }//end if | |
| 569 | + } | |
| 629 | 570 | |
| 630 | 571 | /** |
| 631 | 572 | * @since 5.3 |
| 632 | 573 | * |
| @@ -634,13 +575,8 @@ | ||
| 634 | 575 | */ |
| 635 | 576 | return apply_filters( 'frm_xml_filename', $filename ); |
| 636 | 577 | } |
| 637 | 578 | |
| 638 | - /** | |
| 639 | - * @param array $atts | |
| 640 | - * | |
| 641 | - * @return void | |
| 642 | - */ | |
| 643 | 579 | public static function generate_csv( $atts ) { |
| 644 | 580 | $form_ids = $atts['ids']; |
| 645 | 581 | if ( empty( $form_ids ) ) { |
| 646 | 582 | wp_die( esc_html__( 'Please select a form', 'formidable' ) ); |
| @@ -651,10 +587,8 @@ | ||
| 651 | 587 | /** |
| 652 | 588 | * Export to CSV |
| 653 | 589 | * |
| 654 | 590 | * @since 2.0.19 |
| 655 | - * | |
| 656 | - * @return void | |
| 657 | 591 | */ |
| 658 | 592 | public static function csv( $form_id = false, $search = '', $fid = '' ) { |
| 659 | 593 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 660 | 594 | |
| @@ -663,12 +597,9 @@ | ||
| 663 | 597 | $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' ); |
| 664 | 598 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 665 | 599 | } |
| 666 | 600 | |
| 667 | - // Remove time limit to execute this function. | |
| 668 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 669 | - set_time_limit( 0 ); | |
| 670 | - } | |
| 601 | + set_time_limit( 0 ); //Remove time limit to execute this function | |
| 671 | 602 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 672 | 603 | if ( (int) $mem_limit < 256 ) { |
| 673 | 604 | wp_raise_memory_limit(); |
| 674 | 605 | } |
| @@ -723,9 +654,9 @@ | ||
| 723 | 654 | * |
| 724 | 655 | * @since 2.0.19 |
| 725 | 656 | * @since 5.0.16 function went from private to public. |
| 726 | 657 | * |
| 727 | - * @param int $form_id | |
| 658 | + * @param int $form_id | |
| 728 | 659 | * @param object $form |
| 729 | 660 | * |
| 730 | 661 | * @return array $csv_fields |
| 731 | 662 | */ |