From 1dd2e8f0d1215272c0c62a28b8de0b3815f677b9 Mon Sep 17 00:00:00 2001
From: ryan
Date: Fri, 7 Oct 2005 17:43:43 +0000
Subject: [PATCH] Blogger updates from skeltoac. * No more SSL * No more fopen
wrappers required (all CURL) * Better FTP handling * Better duplicate
handling * Strings marked for translation * Post IDs are cronological *
Coffee stays fresher longer. fixes #1737
git-svn-id: http://svn.automattic.com/wordpress/trunk@2939 1a063a9b-81f0-0310-95a4-ce76da25c4cd
---
wp-admin/import/blogger.php | 306 ++++++++++++++++++------------------
1 file changed, 154 insertions(+), 152 deletions(-)
diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php
index b43c0b56a3..2067efa8f1 100644
--- a/wp-admin/import/blogger.php
+++ b/wp-admin/import/blogger.php
@@ -1,31 +1,18 @@
-
-
-
-Are you looking for %title%? It is temporarily out of service. Please try again in an hour. Meanwhile, discover a better blogging tool.
-
-<$BlogArchiveName$>
-
-
-
-<$BlogItemDateTime$>|W|P|<$BlogItemAuthorNickname$>|W|P|<$BlogItemBody$>|W|P|<$BlogItemNumber$>|W|P|<$BlogItemTitle$>|W|P|<$BlogItemAuthorEmail$><$BlogCommentDateTime$>|W|P|<$BlogCommentAuthor$>|W|P|<$BlogCommentBody$>
-';
// Shows the welcome screen and the magic iframe.
function greet() {
- echo '';
- echo '
'.__('Import Blogger').'
';
- _e("
Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.
-
Before you get started, you may want to back up your Blogger template by copying and pasting it into a text file on your computer. This script has to modify your template and other Blogger settings so it can get your posts and comments. It should restore everything afterwards but if you have put a lot of work into your template, it would be a good idea to make your own backup first.
-
When you are ready to begin, enter your Blogger username and password below and click Start. Do not close this window until the process is complete.
");
- echo "
";
- echo "
Reset this importer
";
- echo '
';
+ $title = __('Import Blogger');
+ $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.');
+ $noiframes = __('This feature requires iframe support.');
+ $warning = __('This will delete everything saved by the Blogger importer except your posts and comments. Are you sure you want to do this?');
+ $reset = __('Reset this importer');
+ echo "\n";
}
// Deletes saved data and redirect.
@@ -37,7 +24,10 @@ class Blogger_Import {
// Generates a string that will make the page reload in a specified interval.
function refresher($msec) {
- return "\n\n";
+ if ( $msec )
+ return "\n\n\n";
+ else
+ return "\n\n\n";
}
// Returns associative array of code, header, cookies, body. Based on code from php.net.
@@ -66,8 +56,9 @@ class Blogger_Import {
// Prints a form for the user to enter Blogger creds.
function login_form($text='') {
- echo "Log in to Blogger
\n$text
\n";
- die("");
+ echo '' . __('Log in to Blogger') . "
\n$text\n";
+ echo '';
+ die;
}
// Sends creds to Blogger, returns the session cookies an array of headers.
@@ -78,7 +69,7 @@ class Blogger_Import {
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_URL,$_url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_HEADER,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@@ -86,6 +77,8 @@ class Blogger_Import {
$response = $this->parse_response($response);
+ sleep(1);
+
return $response['cookies'];
}
@@ -96,8 +89,8 @@ class Blogger_Import {
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
curl_setopt($ch, CURLOPT_HEADER,1);
if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec ($ch);
@@ -124,13 +117,12 @@ class Blogger_Import {
}
if ($user && $pass) $params .= "username=$user&password=$pass";
$params = trim($params,'&');
- //echo addslashes(print_r(array('url'=>$url,'header'=>$header,'params'=>$params),1));
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}");
curl_setopt($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Developing Blogger Exporter');
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER,$parse);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@@ -149,7 +141,7 @@ class Blogger_Import {
// Prints the list of blogs for import.
function show_blogs() {
global $import;
- echo "Selecting a Blog
\n";
+ echo '' . __('Selecting a Blog') . "
\n";
foreach ( $this->import['blogs'] as $blog ) {
if (9 == $blog['nextstep']) $status = "100%";
elseif (8 == $blog['nextstep']) $status = "90%";
@@ -165,37 +157,43 @@ class Blogger_Import {
}
// Publishes.
- function publish_blogger($i) {
- if ( ! $this->import['blogs'][$_GET['blog']]['publish'][$i] ) {
- // First call. Start the publish process.
+ function publish_blogger($i, $text) {
+ $head = $this->refresher(2000) . "$text
\n";
+ if ( ! strstr($this->import['blogs'][$_GET['blog']]['publish'][$i], 'http') ) {
+ // First call. Start the publish process with a fresh set of cookies.
+ $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']);
+ update_option('import-blogger', $this->import);
$paramary = array('blogID' => $_GET['blog'], 'all' => '1', 'republishAll' => 'Republish Entire Blog', 'publish' => '1', 'redirectUrl' => "/publish.do?blogID={$_GET['blog']}&inprogress=true");
+
$response = $this->post_blogger("http://www.blogger.com/publish.do?blogID={$_GET['blog']}", $this->import['cookies'], $paramary);
if ( $response['code'] == '302' ) {
$url = str_replace('publish.g', 'publish-body.g', $response['header']['Location']);
$this->import['blogs'][$_GET['blog']]['publish'][$i] = $url;
update_option('import-blogger', $this->import);
$response = $this->get_blogger($url, $this->import['cookies']);
- if ( preg_match('#.*
#U', $response['body'], $matches) ) {
- $progress = $matches[0];
- die($progress);
- } else {
- echo "matches:
" . print_r($matches,1) . "
\n";
- }
+ preg_match('#.*
#U', $response['body'], $matches);
+ $progress = $matches[0];
+ die($head . $progress);
} else {
- echo "Publish error: No 302
Please tell the devs.
" . addslashes(print_r($response,1)) . "
\n";
+ $this->import['blogs'][$_GET['blog']]['publish'][$i] = false;
+ update_option('import-blogger', $this->import);
+ die($head);
}
- die();
} else {
// Subsequent call. Keep checking status until Blogger reports publish complete.
$url = $this->import['blogs'][$_GET['blog']]['publish'][$i];
$response = $this->get_blogger($url, $this->import['cookies']);
if ( preg_match('#.*
#U', $response['body'], $matches) ) {
$progress = $matches[0];
- if ( strstr($progress, '100%') )
+ if ( strstr($progress, '100%') ) {
$this->set_next_step($i);
- die($progress);
+ $progress .= ''.__('Moving on...').'
';
+ }
+ die($head . $progress);
} else {
- echo "Publish error: No matches
Please tell the devs.
" . print_r($matches,1) . "
\n";
+ $this->import['blogs'][$_GET['blog']]['publish'][$i] = false;
+ update_option('import-blogger', $this->import);
+ die("$head" . __('Trying again...') . '
');
}
}
}
@@ -212,12 +210,12 @@ class Blogger_Import {
die();
}
- // Step 0: Do Blogger login, get userid and blogid/title pairs.
+ // Step 0: Do Blogger login, get blogid/title pairs.
function do_login() {
if ( ( ! $this->import['user'] && ! is_array($this->import['cookies']) ) ) {
// The user must provide a Blogger username and password.
if ( ! ( $_POST['user'] && $_POST['pass'] ) ) {
- $this->login_form("Please log in using your Blogger credentials.");
+ $this->login_form(__('The script will log into your Blogger account, change some settings so it can read your blog, and restore the original settings when it\'s done. Here\'s what you do:
- Back up your Blogger template.
- Back up any other Blogger settings you might need later.
- Log out of Blogger
- Log in here with your Blogger username and password.
- On the next screen, click one of your Blogger blogs.
- Do not close this window or navigate away until the process is complete.
'));
}
// Try logging in. If we get an array of cookies back, we at least connected.
@@ -230,32 +228,24 @@ class Blogger_Import {
$this->import['pass'] = $_POST['pass'];
$this->import['user'] = $_POST['user'];
- // Get the blog numbers so we can give the user a choice.
- $response = $this->get_blogger('https://www.blogger.com/atom','',$_POST['user'],$_POST['pass']);
- $blogger = $response['body'];
-
- // Save the userID if we got one from Blogger, otherwise re-login.
- $useridary = array();
- preg_match('#>(\d+)import['userid'] = $useridary[1]) $this->login_form("Login failed. Please re-enter your username and password.");
- unset($useridary);
-
- // Save the blogs
+ // Get the Blogger welcome page and scrape the blog numbers and names from it
+ $response = $this->get_blogger('http://www.blogger.com/home', $this->import['cookies']);
+ if (! stristr($response['body'], 'signed in as') ) $this->login_form("Login failed. Please re-enter your username and password.");
$blogsary = array();
- preg_match_all('#/atom/(\d+)" rel\="service.feed" title="([^"]+)"#', $blogger, $blogsary);
- if ( ! is_array( $blogsary[1] ) )
- die('No blogs found for this user.');
+ preg_match_all('#posts\.g\?blogID=(\d+)">([^<]+)#U', $response['body'], $blogsary);
+ if ( ! count( $blogsary[1] < 1 ) )
+ die(__('No blogs found for this user.'));
$this->import['blogs'] = array();
+ $template = '
'.__('Are you looking for %title%? It is temporarily out of service. Please try again in a few minutes. Meanwhile, discover a better blogging tool.').'
<$BlogArchiveName$>
<$BlogItemDateTime$>|W|P|<$BlogItemAuthorNickname$>|W|P|<$BlogItemBody$>|W|P|<$BlogItemNumber$>|W|P|<$BlogItemTitle$>|W|P|<$BlogItemAuthorEmail$><$BlogCommentDateTime$>|W|P|<$BlogCommentAuthor$>|W|P|<$BlogCommentBody$>';
foreach ( $blogsary[1] as $key => $id ) {
// Define the required Blogger options.
$blog_opts = array(
'blog-options-basic' => false,
+ 'blog-options-archiving' => array('archiveFrequency' => 'm'),
+ 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false'),
'blog-formatting' => array('timeStampFormat' => '0', 'encoding'=>'UTF-8', 'convertLineBreaks'=>'false', 'floatAlignment'=>'false'),
'blog-comments' => array('commentsTimeStampFormat' => '0'),
- 'blog-options-archiving' => array('archiveFrequency' => 'm'),
- 'template-edit' => array( 'templateText' => str_replace('%title%', $blogsary[2][$key], $this->template) ),
- 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false')
+ 'template-edit' => array( 'templateText' => str_replace('%title%', trim($blogsary[2][$key]), $template) )
);
// Build the blog options array template
@@ -264,15 +254,14 @@ class Blogger_Import {
$this->import['blogs']["$id"] = array(
'id' => $id,
- 'title' => $blogsary[2][$key],
+ 'title' => trim($blogsary[2][$key]),
'options' => $new_opts,
'url' => false,
'publish_cookies' => false,
'published' => false,
'archives' => false,
- 'newusers' => array(),
'lump_authors' => false,
- 'newusers' => 0,
+ 'newusers' => array(),
'nextstep' => 2
);
}
@@ -298,9 +287,6 @@ class Blogger_Import {
$form = false;
foreach ($this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary) {
if ( $blog_opt == $_GET['form'] ) {
- // Make sure not to overwrite any existing backups!
- if ( $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] ) continue;
-
// Save the posted form data
$this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] = $_POST;
update_option('import-blogger',$this->import);
@@ -309,31 +295,26 @@ class Blogger_Import {
if ( $optary['modify'] ) {
$posturl = "http://www.blogger.com/{$blog_opt}.do";
$headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']);
- switch ($blog_opt) {
- case 'blog-publishing':
+ if ( 'blog-publishing' == $blog_opt ) {
if ( $_POST['publishMode'] > 0 ) {
$response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode=0", $headers);
if ( $response['code'] >= 400 )
- die('Failed attempt to change publishMode:
' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '
');
+ die(''.__('Failed attempt to change publish mode from FTP to BlogSpot.').'
' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '
');
$this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $optary['modify']['subdomain'] . '.blogspot.com/';
+ sleep(2);
} else {
$this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $_POST['subdomain'] . '.blogspot.com/';
update_option('import-blogger', $this->import);
- continue 2;
+ $output .= "$blog_opt
\n";
+ continue;
}
$paramary = $optary['modify'];
- break;
- case 'template-edit':
- $this->import['blogs'][$_GET['blog']]['publish_cookies'] = $headers;
- update_option('import-blogger', $this->import);
- default:
+ } else {
$paramary = array_merge($_POST, $optary['modify']);
}
$response = $this->post_blogger($posturl, $headers, $paramary);
if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') )
- die( "Error on form submission. Refresh/Reload and click YES to resubmit.
" . addslashes(print_r($response, 1)));
- //header("Location: admin.php?import=blogger&noheader=true&step=2&blog={$_GET['blog']}");
- //die();
+ die(''.__('Error on form submission. Retry or reset the importer.').'
' . addslashes(print_r($response, 1)));
}
$output .= "$blog_opt
\n";
} elseif ( is_array($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup']) ) {
@@ -361,24 +342,23 @@ class Blogger_Import {
if ( $form )
die($output . $form);
- $this->set_next_step(3);
+ $this->set_next_step(4);
$this->do_next_step();
}
- // Step 3: Publish with the new template and settings.
- function publish_blog() {
- echo $this->refresher(2400) . "Publishing with new template and options
\n";
- $this->publish_blogger(5);
- }
+ // Step 3: Cancelled :-)
- // Step 4: Deprecated. :-D
+ // Step 4: Publish with the new template and settings.
+ function publish_blog() {
+ $this->publish_blogger(5, __('Publishing with new template and options'));
+ }
// Step 5: Get the archive URLs from the new blog.
function get_archive_urls() {
- $bloghtml = file($this->import['blogs'][$_GET['blog']]['url']);
- if (! is_array($bloghtml) ) die('Trouble connecting to your blog. Try reloading this page.');
- preg_match_all('#your blog say Temporary Template?");
+ $bloghtml = $this->get_blogger($this->import['blogs'][$_GET['blog']]['url']);
+ if (! strstr($bloghtml['body'], 'import['blogs'][$_GET['blog']]['archives'][$archive] = false;
}
@@ -389,8 +369,9 @@ class Blogger_Import {
// Step 6: Get each monthly archive, import it, mark it done.
function get_archive() {
global $wpdb;
- $output = "Importing Blogger archives into WordPress
\n";
+ $output = ''.__('Importing Blogger archives into WordPress').'
';
$did_one = false;
+ $post_array = $posts = array();
foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) {
$archivename = substr(basename($url),0,7);
if ( $status || $did_one ) {
@@ -402,10 +383,13 @@ class Blogger_Import {
$skippedpostcount = 0;
$commentcount = 0;
$skippedcommentcount = 0;
- $status = '';
- $archive = implode('',file($url));
-
- $posts = explode('', $archive);
+ $status = __('in progress...');
+ $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
+ update_option('import-blogger', $import);
+ $archive = $this->get_blogger($url);
+ if ( $archive['code'] > 200 )
+ continue;
+ $posts = explode('', $archive['body']);
for ($i = 1; $i < count($posts); $i = $i + 1) {
$postparts = explode('', $posts[$i]);
$postinfo = explode('|W|P|', $postparts[0]);
@@ -416,26 +400,21 @@ class Blogger_Import {
// big to handle as ints.
//$post_number = $postinfo[3];
$post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3];
- $post_author = trim($wpdb->escape($postinfo[1]));
- $post_author_name = trim(addslashes($postinfo[1]));
- $post_author_email = $postinfo[5] ? $postinfo[5] : 'no@email.com';
+ $post_author_name = $wpdb->escape(trim($postinfo[1]));
+ $post_author_email = $postinfo[5] ? $postinfo[5] : 'user@wordpress.org';
- if ( $this->import['blogs'][$_GET['blog']]['lump_authors'] ) {
+ if ( $this->lump_authors ) {
// Ignore Blogger authors. Use the current user_ID for all posts imported.
- $post_author = $GLOBALS['user_ID']; // For WPMU only. Assume all posts belong to the current user.
+ $post_author = $GLOBALS['user_ID'];
} else {
// Add a user for each new author encountered.
if (! username_exists($post_author_name) ) {
- $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 = $wpdb->escape($post_author_name);
- $pass1 = $wpdb->escape('password');
$user_email = $wpdb->escape($post_author_email);
- $user_url = $wpdb->escape('');
- $user_joindate = $wpdb->escape($user_joindate);
$user_password = substr(md5(uniqid(microtime())), 0, 6);
$result = wp_create_user( $user_login, $user_password, $user_email );
$status.= "Registered user $user_login. ";
- ++$this->import['blogs'][$_GET['blog']]['newusers'];
+ $this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login;
}
$userdata = get_userdatabylogin( $post_author_name );
$post_author = $userdata->ID;
@@ -458,20 +437,20 @@ class Blogger_Import {
$post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
$post_content = addslashes($post_content);
- $post_content = str_replace('
', '
', $post_content); // the XHTML touch... ;)
+ $post_content = str_replace(array('
','
','
','
','
','
'), "\n", $post_content); // the XHTML touch... ;)
$post_title = addslashes($post_title);
$post_status = 'publish';
- if ( post_exists($post_title, '', $post_date) ) {
+ if ( $ID = post_exists($post_title, '', $post_date) ) {
+ $post_array[$i]['ID'] = $ID;
$skippedpostcount++;
- $comment_post_ID = $dupcheck[0]['ID'];
} else {
- $post_array = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
- $comment_post_ID = wp_insert_post($post_array);
+ $post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
+ $post_array[$i]['comments'] = false;
}
-
+
// Import any comments attached to this post.
if ($postparts[1]) :
for ($j = 1; $j < count($postparts); $j = $j + 1) {
@@ -490,29 +469,39 @@ class Blogger_Import {
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.
+ $comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1])));
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);
- if ( $comment_post_ID == comment_exists($comment_author, $comment_date) ) {
+ $comment_content = $commentinfo[2];
+ $comment_content = str_replace(array('
','
','
','
','
','
'), "\n", $comment_content);
+ $comment_approved = 1;
+ if ( comment_exists($comment_author, $comment_date) ) {
$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')
- ");
+ $comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved');
+ $post_array[$i]['comments'][$j] = wp_filter_comment($comment);
}
$commentcount++;
}
endif;
$postcount++;
}
- $status = "$postcount post(s) parsed, $skippedpostcount skipped... $commentcount comment(s) parsed, $skippedcommentcount skipped... Done";
+ if ( count($post_array) ) {
+ krsort($post_array);
+ foreach($post_array as $post) {
+ if ( ! $comment_post_ID = $post['ID'] )
+ $comment_post_ID = wp_insert_post($post['post']);
+ if ( $post['comments'] ) {
+ foreach ( $post['comments'] as $comment ) {
+ $comment['comment_post_ID'] = $comment_post_ID;
+ wp_insert_comment($comment);
+ }
+ }
+ }
+ }
+ $status = "$postcount ".__('post(s) parsed,')." $skippedpostcount ".__('skipped...')." $commentcount ".__('comment(s) parsed,')." $skippedcommentcount ".__('skipped...').' '.__('Done').'';
$import = $this->import;
$import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
update_option('import-blogger', $import);
@@ -522,19 +511,23 @@ class Blogger_Import {
}
if ( ! $did_one )
$this->set_next_step(7);
- die( $this->refresher(5000) . $output );
+ die( $this->refresher(1000) . $output );
}
// Step 7: Restore the backed-up settings to Blogger
function restore_settings() {
- $output = "Restoring your Blogger options
\n";
+ $output = ''.__('Restoring your Blogger options')."
\n";
$did_one = false;
+ // Restore options in reverse order.
+ if ( ! $this->import['reversed'] ) {
+ $this->import['blogs'][$_GET['blog']]['options'] = array_reverse($this->import['blogs'][$_GET['blog']]['options'], true);
+ $this->import['reversed'] = true;
+ update_option('import-blogger', $this->import);
+ }
foreach ( $this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary ) {
if ( $did_one ) {
$output .= "$blog_opt
\n";
- } elseif ( $optary['restored'] ) {
- $output .= "$blog_opt
\n";
- } elseif ( ! $optary['modify'] ) {
+ } elseif ( $optary['restored'] || ! $optary['modify'] ) {
$output .= "$blog_opt
\n";
} else {
$posturl = "http://www.blogger.com/{$blog_opt}.do";
@@ -542,49 +535,52 @@ class Blogger_Import {
if ( 'blog-publishing' == $blog_opt) {
if ( $optary['backup']['publishMode'] > 0 ) {
$response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode={$optary['backup']['publishMode']}", $headers);
+ sleep(2);
if ( $response['code'] >= 400 )
die('Error restoring publishMode.
Please tell the devs.
' . addslashes(print_r($response, 1)) );
}
}
if ( $optary['backup'] != $optary['modify'] ) {
$response = $this->post_blogger($posturl, $headers, $optary['backup']);
- if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') )
- die( "Error on form submission in Step 7.
Please tell the devs.
" . addslashes(print_r($response, 1)));
+ if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) {
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['error'] = true;
+ update_option('import-blogger', $this->import);
+ $output .= "$blog_opt ".__('failed. Trying again.').'
';
+ } else {
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true;
+ update_option('import-blogger', $this->import);
+ $output .= "$blog_opt ".__('restored.').'
';
+ }
}
- $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true;
- update_option('import-blogger', $this->import);
$did_one = true;
- $output .= "$blog_opt in progress. Please wait...";
}
}
if ( $did_one ) {
die( $this->refresher(1000) . $output );
+ } elseif ( $this->import['blogs'][$_GET['blog']]['options']['blog-publishing']['backup']['publishMode'] > 0 ) {
+ $this->set_next_step(9);
+ } else {
+ $this->set_next_step(8);
}
- $this->set_next_step(8);
$this->do_next_step();
}
// Step 8: Republish, all back to normal
function republish_blog() {
- echo $this->refresher(2400) . "
Publishing with original template and options
\n";
- $this->publish_blogger(9);
+ $this->publish_blogger(9, __('Publishing with original template and options'));
}
// Step 9: Congratulate the user
function congrats() {
- echo "Congratulations!
-Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:
-
-- That was hard work! Take a break.
-";
+ echo ''.__('Congratulations!').'
'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'
- '.__('That was hard work! Take a break.').'
';
if ( count($this->import['blogs']) > 1 )
- echo "- In case you haven't done it already, you can import the posts from any other blogs you may have:" . $this->show_blogs() . "
\n";
+ echo '- '.__('In case you haven\'t done it already, you can import the posts from your other blogs:'). $this->show_blogs() . '
';
if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) )
- echo "- Since we had to create $n new users, you probably want to go to Authors & Users, where you can give them new passwords or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.
\n";
-
- echo "\n";
+ echo '- '.__('Go to Authors & Users, where you can modify the new user(s) or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.').'
';
+ echo '- '.__('For security, click the link below to reset this importer. That will clear your Blogger credentials and options from the database.').'
';
+ echo '
';
}
// Figures out what to do, then does it.
@@ -596,15 +592,19 @@ class Blogger_Import {
if ( isset($_GET['noheader']) ) {
$this->import = get_settings('import-blogger');
- if ( isset($_GET['step']) ) {
+ if ( false === $this->import ) {
+ $step = 0;
+ } elseif ( isset($_GET['step']) ) {
$step = (int) $_GET['step'];
- } elseif ( isset($_GET['blog']) ) {
+ } elseif ( isset($_GET['blog']) && isset($this->import['blogs'][$_GET['blog']]['nextstep']) ) {
$step = $this->import['blogs'][$_GET['blog']]['nextstep'];
} elseif ( is_array($this->import['blogs']) ) {
$step = 1;
} else {
$step = 0;
}
+//echo "Step $step.";
+//die('
'.print_r($this->import,1).'
do_login();
@@ -616,9 +616,11 @@ class Blogger_Import {
$this->backup_settings();
break;
case 3 :
- $this->publish_blog();
+ $this->wait_for_blogger();
break;
case 4 :
+ $this->publish_blog();
+ break;
case 5 :
$this->get_archive_urls();
break;
@@ -635,9 +637,8 @@ class Blogger_Import {
$this->congrats();
break;
}
-
die;
-
+
} else {
$this->greet();
}
@@ -651,4 +652,5 @@ class Blogger_Import {
$blogger_import = new Blogger_Import();
register_importer('blogger', 'Blogger', __('Import posts and comments from a Blogger account'), array ($blogger_import, 'start'));
-?>
\ No newline at end of file
+
+?>