Index: wp-admin/import/livejournal.php
===================================================================
--- wp-admin/import/livejournal.php (revision 11010)
+++ wp-admin/import/livejournal.php (working copy)
@@ -69,6 +69,10 @@
$post_content = str_replace(array (''), '', trim($post_content[1]));
$post_content = $this->unhtmlentities($post_content);
+ // Get tags
+ preg_match('|(.*?)|is', $post, $tags_input);
+ $tags_input = $tags_input[0];
+
// Clean up content
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
$post_content = str_replace('
', '
', $post_content);
@@ -83,7 +87,7 @@
printf(__('Post %s already exists.'), stripslashes($post_title));
} else {
printf(__('Importing post %s...'), stripslashes($post_title));
- $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
+ $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'tags_input');
$post_id = wp_insert_post($postdata);
if ( is_wp_error( $post_id ) )
return $post_id;
@@ -92,6 +96,31 @@
echo '';
break;
}
+
+ // Add tags.
+ $tags = explode(", ", $tags_input);
+ if (count($tags) > 0) {
+ printf(__('setting tags...'));
+ $post_tags = array();
+ foreach ($tags as $tag) {
+ if ( '' == $tag )
+ continue;
+ $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');
+ if ( is_wp_error($tag_id) )
+ continue;
+ $tag_id = $tag_id['term_id'];
+ }
+ $post_tags[] = intval($tag_id);
+ }
+ wp_set_post_tags($post_id, $post_tags);
+ }
}
preg_match_all('|(.*?)|is', $post, $comments);