From a366ee01ef9b0b3af60d37a91a5fe9108c8e447c Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 21 Sep 2007 18:34:28 +0000 Subject: [PATCH] Export and import of post tags. fixes #4682 git-svn-id: http://svn.automattic.com/wordpress/trunk@6149 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/export.php | 23 ++++++++++++++++++++++- wp-admin/import/wordpress.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/wp-admin/export.php b/wp-admin/export.php index 27fbe523b..c8090e4dd 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -141,6 +141,27 @@ function wxr_tag_description($t) { echo '' . wxr_cdata($t->description) . ''; } +function wxr_post_taxonomy() { + $categories = get_the_category(); + $tags = get_the_tags(); + $cat_names = array(); + $tag_names = array(); + $the_list = ''; + $filter = 'rss'; + + if ( !empty($categories) ) foreach ( (array) $categories as $category ) { + $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); + $the_list .= "\n\t\t\n"; + } + + if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { + $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); + $the_list .= "\n\t\t\n"; + } + + echo $the_list; +} + print '\n"; ?> @@ -201,7 +222,7 @@ print '\n"; - + diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index df1b67bd0..d15f3a43b 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -316,6 +316,15 @@ class WP_Import { $post_content = str_replace('
', '
', $post_content); $post_content = str_replace('
', '
', $post_content); + preg_match_all('|(.*?)|is', $post, $tags); + $tags = $tags[1]; + + $tag_index = 0; + foreach ($tags as $tag) { + $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array (''), '', $tag))); + $tag_index++; + } + preg_match_all('|(.*?)|is', $post, $categories); $categories = $categories[1]; @@ -372,6 +381,25 @@ class WP_Import { } wp_set_post_categories($post_id, $post_cats); } + + // Add tags. + if (count($tags) > 0) { + $post_tags = array(); + foreach ($tags as $tag) { + $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); + $tag_obj = get_term_by('slug', $slug, 'post_tag'); + $tag_id = 0; + if ( ! empty($tag_obj) ) + $tag_id = $tag_obj->term_id; + if ( $tag_id == 0 ) { + $tag = $wpdb->escape($tag); + $tag_id = wp_insert_term($tag, 'post_tag'); + $tag_id = $tag_id['term_id']; + } + $post_tags[] = $tag_id; + } + wp_set_post_tags($post_id, $post_tags); + } } // Now for comments