From 5df9400ad90a32d7b3ef7f6cd66f51ce64ac5cca Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 23 Dec 2005 23:16:20 +0000 Subject: [PATCH] Enable MT importer. git-svn-id: http://svn.automattic.com/wordpress/trunk@3352 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/import/mt.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php index 4a505bac86..e80b1e549a 100644 --- a/wp-admin/import/mt.php +++ b/wp-admin/import/mt.php @@ -172,13 +172,13 @@ class MT_Import { } function process_posts() { + global $wpdb; $i = -1; echo "
    "; - foreach ($posts as $post) { + foreach ($this->posts as $post) { if ('' != trim($post)) { ++ $i; unset ($post_categories); - echo '
  1. '.__('Processing post...'); // Take the pings out first preg_match("|(-----\n\nPING:.*)|s", $post, $pings); @@ -224,7 +224,6 @@ class MT_Import { break; case 'TITLE' : $post_title = $wpdb->escape($value); - echo ''.stripslashes($post_title).'... '; break; case 'STATUS' : // "publish" and "draft" enumeration items match up; no change required @@ -252,15 +251,19 @@ class MT_Import { } break; case 'PRIMARY CATEGORY' : - $post_categories[] = $wpdb->escape($value); + if (! empty ($value) ) + $post_categories[] = $wpdb->escape($value); break; case 'CATEGORY' : - $post_categories[] = $wpdb->escape($value); + if (! empty ($value) ) + $post_categories[] = $wpdb->escape($value); break; case 'DATE' : $post_modified = strtotime($value); $post_modified = date('Y-m-d H:i:s', $post_modified); $post_modified_gmt = get_gmt_from_date("$post_modified"); + $post_date = $post_modified; + $post_date_gmt = $post_modified_gmt; break; default : // echo "\n$key: $value"; @@ -269,24 +272,28 @@ class MT_Import { } // End foreach // Let's check to see if it's in already - if ($post_id = posts_exists($post_title, '', $post_date)) { - _e('Post already imported.'); + if ($post_id = post_exists($post_title, '', $post_date)) { + echo '
  2. '; + printf(__('Post %s already exists.'), stripslashes($post_title)); } else { - $post_author = checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor + echo '
  3. '; + printf(__('Importing post %s...'), stripslashes($post_title)); + + $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); $post_id = wp_insert_post($postdata); // Add categories. if (0 != count($post_categories)) { - wp_create_categories($post_categories); + wp_create_categories($post_categories, $post_id); } - _e(' Post imported successfully...'); } $comment_post_ID = $post_id; // Now for comments $comments = explode("-----\nCOMMENT:", $comments[0]); + $num_comments = 0; foreach ($comments as $comment) { if ('' != trim($comment)) { // Author @@ -317,15 +324,18 @@ class MT_Import { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); - echo "Comment added."; + $num_comments++; } } } + if ( $num_comments ) + printf(__('(%s comments)'), $num_comments); // Finally the pings // fix the double newline on the first one $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]); $pings = explode("-----\nPING:", $pings[0]); + $num_pings = 0; foreach ($pings as $ping) { if ('' != trim($ping)) { // 'Author' @@ -362,10 +372,13 @@ class MT_Import { $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type'); $commentdata = wp_filter_comment($commentdata); wp_insert_comment($commentdata); - _e('Comment added.'); + $num_pings++; } } } + if ( $num_pings ) + printf(__('(%s pings)'), $num_pings); + echo "
  4. "; } flush(); @@ -412,5 +425,5 @@ class MT_Import { $mt_import = new MT_Import(); -//register_importer('mt', 'Movable Type', 'Import posts and comments from your Movable Type blog', array ($mt_import, 'dispatch')); +register_importer('mt', 'Movable Type', 'Import posts and comments from your Movable Type blog', array ($mt_import, 'dispatch')); ?>