header(); if ( empty( $_GET['step'] ) ) { $step = 1; } else { $step = (int) $_GET['step']; } switch ($step) { case 1: $this->step1(); break; case 2: if ( isset( $_GET['import-id'] ) ) { $inserted_posts = History::get_imported_post_ids( $_GET['import-id'] ); } else { check_admin_referer( 'acsv-import-upload' ); set_time_limit( 0 ); $inserted_posts = $this->step2(); } if ( is_wp_error( $inserted_posts ) ) { echo '

' . $inserted_posts->get_error_message() . '

'; } else { self::delete_form( $inserted_posts ); } break; case 3: check_admin_referer( 'acsv-import-delete' ); if ( isset( $_POST['acsv-import-id'] ) && count( $_POST['acsv-import-id'] ) ) { foreach ( $_POST['acsv-import-id'] as $post_id ) { if ( intval( $post_id ) ) { wp_delete_post( $post_id, false ); } } echo '

'; if ( count( $_POST['acsv-import-id'] ) === 1 ) { echo '1 post moved to the Trash.'; } else { echo count( $_POST['acsv-import-id'] ) . ' posts moved to the Trash.'; } echo '

'; } else { echo '

Nothing to do.

'; } break; } $this->footer(); } /** * The form of the second step. * * @param none * @return none */ private function step2() { $file = wp_import_handle_upload(); if ( isset( $file['error'] ) ) { return new WP_Error( 'Error', esc_html( $file['error'] ) ); } else if ( ! file_exists( $file['file'] ) ) { return new WP_Error( 'Error', sprintf( __( 'The export file could not be found at %s. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer' ), esc_html( $file['file'] ) ) ); } $csv_file = get_attached_file( $file['id'] ); $post_objects = Main::get_post_objects( $csv_file ); if ( is_wp_error( $post_objects ) ) { echo '

'.__( 'Failed to open file.', 'advanced-csv-importer' ).'

'; wp_import_cleanup( $file['id'] ); return $post_objects; } else { $inserted_posts = Main::insert_posts( $post_objects ); wp_import_cleanup( $file['id'] ); return $inserted_posts; } } /** * The form of the first step. * * @param none * @return none */ private function step1() { $bytes = apply_filters( 'acsv_import_upload_size_limit', wp_max_upload_size() ); $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); echo '
'; if ( ! empty( $upload_dir['error'] ) ) { ?>


()

History

ID Title Date Success Failure
'; } /** * Open the div for upload interface. * * @param none * @return none */ private function header() { echo '
'; screen_icon(); echo '

' . __( 'Advanced CSV Importer', 'advanced-csv-importer' ) . '

'; $updates = get_plugin_updates(); $basename = plugin_basename( __FILE__ ); if ( isset( $updates[ $basename ] ) ) { $update = $updates[ $basename ]; echo '

'; printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'advanced-csv-importer' ), $update->update->new_version ); echo '

'; } } /** * Close the div for upload interface. * * @param none * @return none */ private function footer() { echo '
'; } /** * Returns the uri for upload * * @param none * @return The uri for upload. */ private function get_action() { return $this->action; } private function delete_form( $inserted_posts ) { $posts = History::post_ids_to_posts( $inserted_posts ); if ( ! $posts ) { echo '

Posts were already deleted.

'; return; } $success = History::get_num_success( $inserted_posts ); $fail = History::get_num_fail( $inserted_posts ); echo '

'; if ( $success === 1 ) { echo $success . ' post imported. '; } else { echo $success . ' posts imported. '; } if ( $fail === 1 ) { echo $fail . ' post failed to import. '; } else { echo $fail . ' posts failed to import. '; } echo '

'; echo '
'; wp_nonce_field( 'acsv-import-delete' ); echo ''; echo ''; echo ''; echo ''; foreach ( $posts as $p ) { printf( '', intval( $p['ID'] ), intval( $p['ID'] ), esc_html( $p['Title'] ), esc_html( $p['Type'] ), esc_html( $p['Status'] ), esc_html( $p['Author'] ), esc_html( $p['Date'] ) ); } echo '
TitleTypeStatusAuthorDate
%s%s%s%s%s
'; echo '

'; echo '
'; } }