From 9415bbca12c01c39da58e0ed2c4e6b44ff833e5d Mon Sep 17 00:00:00 2001 From: donncha Date: Thu, 30 Nov 2006 18:54:22 +0000 Subject: WP Merge to 4559 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@816 7be80a69-a1ef-0310-a953-fb0f7c49ff36 --- wp-admin/import/wordpress.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'wp-admin/import/wordpress.php') diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index ac965b8..109d0a7 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -69,6 +69,8 @@ class WP_Import { $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata); preg_match_all('|(.*?)|is', $importdata, $this->posts); $this->posts = $this->posts[1]; + preg_match_all('|(.*?)|is', $importdata, $this->categories); + $this->categories = $this->categories[1]; } function get_wp_authors() { @@ -160,6 +162,35 @@ class WP_Import { $this->wp_authors_form(); } + function process_categories() { + global $wpdb; + + $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories"); + + while ( $c = array_shift($this->categories) ) { + $cat_name = trim(str_replace(array (''), '', $this->get_tag( $c, 'wp:cat_name' ))); + + // If the category exists we leave it alone + if ( in_array($cat_name, $cat_names) ) + continue; + + $category_nicename = $this->get_tag( $c, 'wp:category_nicename' ); + $posts_private = (int) $this->get_tag( $c, 'wp:posts_private' ); + $links_private = (int) $this->get_tag( $c, 'wp:links_private' ); + + $parent = $this->get_tag( $c, 'wp:category_parent' ); + + if ( empty($parent) ) + $category_parent = '0'; + else + $category_parent = (int) category_exists($parent); + + $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name'); + + $cat_ID = wp_insert_category($catarr); + } + } + function process_posts() { global $wpdb; $i = -1; @@ -189,7 +220,7 @@ class WP_Import { $cat_index = 0; foreach ($categories as $category) { - $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category)); + $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array (''), '', $category))); $cat_index++; } @@ -260,6 +291,7 @@ class WP_Import { $this->file = get_attached_file($this->id); $this->get_authors_from_post(); $this->get_entries(); + $this->process_categories(); $this->process_posts(); } -- cgit