wp/wp-content/plugins/wordpress-importer/wordpress-importer.php
changeset 7 cf61fcea0001
parent 0 d970ebf37754
--- a/wp/wp-content/plugins/wordpress-importer/wordpress-importer.php	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-content/plugins/wordpress-importer/wordpress-importer.php	Mon Oct 14 17:39:30 2019 +0200
@@ -1,11 +1,11 @@
 <?php
 /*
 Plugin Name: WordPress Importer
-Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/
+Plugin URI: https://wordpress.org/plugins/wordpress-importer/
 Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
 Author: wordpressdotorg
-Author URI: http://wordpress.org/
-Version: 0.6.1
+Author URI: https://wordpress.org/
+Version: 0.6.4
 Text Domain: wordpress-importer
 License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */
@@ -63,8 +63,6 @@
 	var $url_remap = array();
 	var $featured_images = array();
 
-	function WP_Import() { /* nothing */ }
-
 	/**
 	 * Registered callback function for the WordPress Importer
 	 *
@@ -416,6 +414,7 @@
 				'cat_name' => $cat['cat_name'],
 				'category_description' => $category_description
 			);
+			$catarr = wp_slash( $catarr );
 
 			$id = wp_insert_category( $catarr );
 			if ( ! is_wp_error( $id ) ) {
@@ -428,6 +427,8 @@
 				echo '<br />';
 				continue;
 			}
+
+			$this->process_termmeta( $cat, $id['term_id'] );
 		}
 
 		unset( $this->categories );
@@ -454,6 +455,7 @@
 				continue;
 			}
 
+			$tag = wp_slash( $tag );
 			$tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
 			$tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
 
@@ -468,6 +470,8 @@
 				echo '<br />';
 				continue;
 			}
+
+			$this->process_termmeta( $tag, $id['term_id'] );
 		}
 
 		unset( $this->tags );
@@ -500,6 +504,7 @@
 				$parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
 				if ( is_array( $parent ) ) $parent = $parent['term_id'];
 			}
+			$term = wp_slash( $term );
 			$description = isset( $term['term_description'] ) ? $term['term_description'] : '';
 			$termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
 
@@ -514,12 +519,75 @@
 				echo '<br />';
 				continue;
 			}
+
+			$this->process_termmeta( $term, $id['term_id'] );
 		}
 
 		unset( $this->terms );
 	}
 
 	/**
+	 * Add metadata to imported term.
+	 *
+	 * @since 0.6.2
+	 *
+	 * @param array $term    Term data from WXR import.
+	 * @param int   $term_id ID of the newly created term.
+	 */
+	protected function process_termmeta( $term, $term_id ) {
+		if ( ! isset( $term['termmeta'] ) ) {
+			$term['termmeta'] = array();
+		}
+
+		/**
+		 * Filters the metadata attached to an imported term.
+		 *
+		 * @since 0.6.2
+		 *
+		 * @param array $termmeta Array of term meta.
+		 * @param int   $term_id  ID of the newly created term.
+		 * @param array $term     Term data from the WXR import.
+		 */
+		$term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
+
+		if ( empty( $term['termmeta'] ) ) {
+			return;
+		}
+
+		foreach ( $term['termmeta'] as $meta ) {
+			/**
+			 * Filters the meta key for an imported piece of term meta.
+			 *
+			 * @since 0.6.2
+			 *
+			 * @param string $meta_key Meta key.
+			 * @param int    $term_id  ID of the newly created term.
+			 * @param array  $term     Term data from the WXR import.
+			 */
+			$key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
+			if ( ! $key ) {
+				continue;
+			}
+
+			// Export gets meta straight from the DB so could have a serialized string
+			$value = maybe_unserialize( $meta['value'] );
+
+			add_term_meta( $term_id, $key, $value );
+
+			/**
+			 * Fires after term meta is imported.
+			 *
+			 * @since 0.6.2
+			 *
+			 * @param int    $term_id ID of the newly created term.
+			 * @param string $key     Meta key.
+			 * @param mixed  $value   Meta value.
+			 */
+			do_action( 'import_term_meta', $term_id, $key, $value );
+		}
+	}
+
+	/**
 	 * Create new posts based on import information
 	 *
 	 * Posts marked as having a parent which doesn't exist will become top level items.
@@ -555,10 +623,26 @@
 			$post_type_object = get_post_type_object( $post['post_type'] );
 
 			$post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
+
+			/**
+			* Filter ID of the existing post corresponding to post currently importing.
+			*
+			* Return 0 to force the post to be imported. Filter the ID to be something else
+			* to override which existing post is mapped to the imported post.
+			*
+			* @see post_exists()
+			* @since 0.6.2
+			*
+			* @param int   $post_exists  Post ID, or 0 if post did not exist.
+			* @param array $post         The post array to be inserted.
+			*/
+			$post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
+
 			if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
 				printf( __('%s &#8220;%s&#8221; already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) );
 				echo '<br />';
 				$comment_post_ID = $post_id = $post_exists;
+				$this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
 			} else {
 				$post_parent = (int) $post['post_parent'];
 				if ( $post_parent ) {
@@ -592,6 +676,8 @@
 				$original_post_ID = $post['post_id'];
 				$postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
 
+				$postdata = wp_slash( $postdata );
+
 				if ( 'attachment' == $postdata['post_type'] ) {
 					$remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
 
@@ -700,6 +786,7 @@
 					if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
 						if ( isset( $inserted_comments[$comment['comment_parent']] ) )
 							$comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
+						$comment = wp_slash( $comment );
 						$comment = wp_filter_comment( $comment );
 						$inserted_comments[$key] = wp_insert_comment( $comment );
 						do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
@@ -795,7 +882,7 @@
 		}
 
 		foreach ( $item['postmeta'] as $meta )
-			$$meta['key'] = $meta['value'];
+			${$meta['key']} = $meta['value'];
 
 		if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) {
 			$_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)];
@@ -902,7 +989,13 @@
 			return new WP_Error( 'upload_dir_error', $upload['error'] );
 
 		// fetch the remote url and write it to the placeholder file
-		$headers = wp_get_http( $url, $upload['file'] );
+		$remote_response = wp_safe_remote_get( $url, array(
+			'timeout' => 300,
+            		'stream' => true,
+            		'filename' => $upload['file'],
+        	) );
+
+		$headers = wp_remote_retrieve_headers( $remote_response );
 
 		// request failed
 		if ( ! $headers ) {
@@ -910,10 +1003,12 @@
 			return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
 		}
 
+		$remote_response_code = wp_remote_retrieve_response_code( $remote_response );
+
 		// make sure the fetch was successful
-		if ( $headers['response'] != '200' ) {
+		if ( $remote_response_code != '200' ) {
 			@unlink( $upload['file'] );
-			return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($headers['response']), get_status_header_desc($headers['response']) ) );
+			return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($remote_response_code), get_status_header_desc($remote_response_code) ) );
 		}
 
 		$filesize = filesize( $upload['file'] );
@@ -962,8 +1057,10 @@
 			if ( isset( $this->processed_posts[$parent_id] ) )
 				$local_parent_id = $this->processed_posts[$parent_id];
 
-			if ( $local_child_id && $local_parent_id )
+			if ( $local_child_id && $local_parent_id ) {
 				$wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
+				clean_post_cache( $local_child_id );
+			}
 		}
 
 		// all other posts/terms are imported, retry menu items with missing associated object
@@ -1029,7 +1126,6 @@
 	// Display import page title
 	function header() {
 		echo '<div class="wrap">';
-		screen_icon();
 		echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';
 
 		$updates = get_plugin_updates();
@@ -1107,7 +1203,7 @@
 	 * Added to http_request_timeout filter to force timeout at 60 seconds during import
 	 * @return int 60
 	 */
-	function bump_request_timeout() {
+	function bump_request_timeout( $val ) {
 		return 60;
 	}
 
@@ -1120,7 +1216,7 @@
 } // class_exists( 'WP_Importer' )
 
 function wordpress_importer_init() {
-	load_plugin_textdomain( 'wordpress-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
+	load_plugin_textdomain( 'wordpress-importer' );
 
 	/**
 	 * WordPress Importer object for registering the import callback