' . __( 'Howdy! Import your feeds here from an OPML (.xml) export file.', WPRSS_TEXT_DOMAIN ) . '

'; echo '

' . __( "Click the button below, choose your file, and click 'Upload'.", WPRSS_TEXT_DOMAIN ) . '

'; echo '

' . __( 'We will take care of the rest.', WPRSS_TEXT_DOMAIN ) . '

'; // Show an import upload form that submits to the same page, with GET parameter step=1 wp_import_upload_form( 'admin.php?import=wprss_opml_importer&step=1' ); break; case 1: // Check referer check_admin_referer( 'import-upload' ); // If the handle_upload function returns true if ( $this->handle_upload() ) { // Get the uploaded file $file = get_attached_file( $this->id ); set_time_limit(0); // Parse the File and Import the feeds $this->parse_and_import( $file ); } break; } ?>
' . __( 'Sorry, an error has been encountered.', WPRSS_TEXT_DOMAIN ) . '
'; echo esc_html( $file['error'] ) . '

'; return false; // If the file does not exist, then show the error message and return FALSE } else if ( ! file_exists( $file['file'] ) ) { echo '

' . __( 'Sorry, it seems your uploaded file has been misplaced!', WPRSS_TEXT_DOMAIN ) . '
'; echo __( 'The uploaded file could not be found at ', WPRSS_TEXT_DOMAIN ) . '' . esc_html( $file['file'] ) . ''; echo __( 'It is likely that this was caused by a permissions problem.' , WPRSS_TEXT_DOMAIN ); echo '

'; return false; } $this->id = (int) $file['id']; return true; } /** * Imports the give OPML element as a wprss_feed * * @since 3.3 * @param $outline The outline OPML element */ private function import_opml_feed( $outline ) { // IF the necassary fields are not present in the element if ( !isset( $outline['title'] ) && !isset( $outline['xmlUrl'] ) ) { // Check if the element is an array if ( is_array( $outline ) ) { // Treat it as an array of sub elements $inserted_ids = array(); // Insert all sub outline elements foreach ( $outline as $key => $sub_outline ) { $inserted_ids[] = $this->import_opml_feed( $sub_outline ); } // Return the inserted IDs return $inserted_ids; } // IF not an array, return NULL else return NULL; } // Create an associative array, with the feed's properties $feed = apply_filters( 'wprss_opml_insert_feed', array( 'post_title' => $outline['title'], 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'wprss_feed' ) ); // Insert the post into the database and store the inserted ID $inserted_id = wp_insert_post( $feed ); // Update the post's meta update_post_meta( $inserted_id, 'wprss_url', $outline['xmlUrl'] ); // Trigger an action, to allow modifications to the inserted feed, based on the outline element do_action( 'wprss_opml_inserted_feed', $inserted_id, $outline ); // Return inserted ID return $inserted_id; } /** * Attempts to parse the given file as an OPML construct, and * import each found feed. * * @since 3.3 * @param file The OPML file to parse and import * @return void * @todo Use the parsed $opml object to import the feeds AND remove var_dump */ private function parse_and_import( $file ) { try { $opml = new WPRSS_OPML( $file ); // Show Success Message ?>

body as $opml_feed ) : $inserted_ids = $this->import_opml_feed( $opml_feed ); if ( !is_array( $inserted_ids ) ) { $inserted_ids = array( $inserted_ids ); } foreach ( $inserted_ids as $inserted_id ) : if ( $inserted_id !== NULL ) : $imported_feed = get_post( $inserted_id, 'ARRAY_A' ); ?>
getMessage(), WPRSS_TEXT_DOMAIN ) ) ?>