Blogger to
The importer is running...
- Importing posts and users
$bgy/$bgmm ";
$posts = explode('', $archive);
for ($i = 1; $i < count($posts); $i = $i + 1) {
$postparts = explode('', $posts[$i]);
$postinfo = explode('|||', $postparts[0]);
$post_date = $postinfo[0];
$post_content = $postinfo[2];
// Don't try to re-use the original numbers
// because the new, longer numbers are too
// big to handle as ints.
//$post_number = $postinfo[3];
$post_title = $postinfo[4];
$post_author = trim(addslashes($postinfo[1]));
// we'll check the author is registered already
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$post_author'");
if (!$user) { // seems s/he's not, so let's register
$user_ip = '127.0.0.1';
$user_domain = 'localhost';
$user_browser = 'server';
$user_joindate = '1979-06-06 00:41:00'; // that's my birthdate (gmt+1) - I could choose any other date. You could change the date too. Just remember the year must be >=1970 or the world would just randomly fall on your head (everything might look fine, and then blam! major headache!)
$user_login = addslashes($post_author);
$pass1 = addslashes('password');
$user_nickname = addslashes($post_author);
$user_email = addslashes('user@wordpress.org');
$user_url = addslashes('');
$user_joindate = addslashes($user_joindate);
$result = $wpdb->query("
INSERT INTO $wpdb->users (
user_login,
user_pass,
user_nickname,
user_email,
user_url,
user_ip,
user_domain,
user_browser,
user_registered,
user_level,
user_idmode
) VALUES (
'$user_login',
'$pass1',
'$user_nickname',
'$user_email',
'$user_url',
'$user_ip',
'$user_domain',
'$user_browser',
'$user_joindate',
'1',
'nickname'
)");
echo ": Registered user $user_login";
}
$post_author_ID = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$post_author'");
$post_date = explode(' ', $post_date);
$post_date_Ymd = explode('/', $post_date[0]);
$postyear = $post_date_Ymd[2];
$postmonth = zeroise($post_date_Ymd[0], 2);
$postday = zeroise($post_date_Ymd[1], 2);
$post_date_His = explode(':', $post_date[1]);
$posthour = zeroise($post_date_His[0], 2);
$postminute = zeroise($post_date_His[1], 2);
$postsecond = zeroise($post_date_His[2], 2);
if (($post_date[2] == 'PM') && ($posthour != '12'))
$posthour = $posthour + 12;
else if (($post_date[2] == 'AM') && ($posthour == '12'))
$posthour = '00';
$post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
$post_content = addslashes($post_content);
$post_content = str_replace('
', '
', $post_content); // the XHTML touch... ;)
$post_title = addslashes($post_title);
// Quick-n-dirty check for dups:
$dupcheck = $wpdb->get_results("SELECT ID,post_date,post_title FROM $wpdb->posts WHERE post_date='$post_date' AND post_title='$post_title' LIMIT 1",ARRAY_A);
if ($dupcheck[0]['ID']) {
$skippedpostcount++;
$comment_post_ID = $dupcheck[0]['ID'];
} else {
$result = $wpdb->query("
INSERT INTO $wpdb->posts
(post_author,post_date,post_content,post_title,post_category)
VALUES
('$post_author_ID','$post_date','$post_content','$post_title','1')
");
$comment_post_ID = $wpdb->get_var("SELECT MAX(ID) FROM $wpdb->posts");
}
if ($postparts[1]) {
for ($j = 1; $j < count($postparts); $j = $j + 1) {
$commentinfo = explode('|||', $postparts[$j]);
$comment_date = explode(' ', $commentinfo[0]);
$comment_date_Ymd = explode('/', $comment_date[0]);
$commentyear = $comment_date_Ymd[2];
$commentmonth = zeroise($comment_date_Ymd[0], 2);
$commentday = zeroise($comment_date_Ymd[1], 2);
$comment_date_His = explode(':', $comment_date[1]);
$commenthour = zeroise($comment_date_His[0], 2);
$commentminute = zeroise($comment_date_His[1], 2);
$commentsecond = '00';
if (($comment_date[2] == 'PM') && ($commenthour != '12'))
$commenthour = $commenthour + 12;
else if (($comment_date[2] == 'AM') && ($commenthour == '12'))
$commenthour = '00';
$comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
$comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1]))); // Believe it or not, Blogger allows a user to call himself "Mr. Hell's Kitchen" which, as a string, really confuses SQL.
if ( strpos($commentinfo[1], 'a href') ) {
$comment_author_parts = explode('"', htmlentities($commentinfo[1]));
$comment_author_url = $comment_author_parts[1];
} else $comment_author_url = '';
$comment_content = addslashes($commentinfo[2]);
$comment_content = str_replace('
', '
', $comment_content);
$dupcheck = $wpdb->get_results("SELECT comment_ID,comment_post_ID, comment_author, comment_date, comment_content FROM $wpdb->comments WHERE comment_post_ID='$comment_post_ID' AND comment_author='$comment_author' AND comment_date='$comment_date' AND comment_content='$comment_content' LIMIT 1",ARRAY_A);
if ( $dupcheck[0]['comment_ID'] ) {
$skippedcommentcount++;
} else {
$result = $wpdb->query("
INSERT INTO $wpdb->comments
(comment_post_ID,comment_author,comment_author_url,comment_date,comment_content)
VALUES
('$comment_post_ID','$comment_author','$comment_author_url','$comment_date','$comment_content')
");
}
$commentcount++; // Increment the monthly comment counter
} // End of comment processing loop
} // End of comment tester
$postcount++;
} // End of post processing loop
echo "... $postcount post(s) parsed, $skippedpostcount skipped... $commentcount comment(s) parsed, $skippedcommentcount skipped... Done
";
} // End of monthly archive processor
} // End of monthly loop
} // End of yearly loop
upgrade_all();
?>
Done
Completed Blogger to WordPress import!
Cleanup steps:
Delete everything that Blogger put on your web server. Files like '2005_01_01_wordpress.php' just take up space and folders like '2005' can mess up your WordPress archives, so delete them.
Now you can go and log in, have fun!