diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php index b43c0b56a..5276a5e74 100644 --- a/wp-admin/import/blogger.php +++ b/wp-admin/import/blogger.php @@ -21,7 +21,7 @@ class Blogger_Import { 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.

+

Before you get started, you should 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

"; @@ -37,7 +37,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. @@ -78,7 +81,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); @@ -98,6 +101,7 @@ class Blogger_Import { 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); @@ -130,7 +134,7 @@ class Blogger_Import { 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); @@ -165,7 +169,8 @@ class Blogger_Import { } // Publishes. - function publish_blogger($i) { + function publish_blogger($i, $text) { + $head = $this->refresher(1000) . "

$text

\n"; if ( ! $this->import['blogs'][$_GET['blog']]['publish'][$i] ) { // First call. Start the publish process. $paramary = array('blogID' => $_GET['blog'], 'all' => '1', 'republishAll' => 'Republish Entire Blog', 'publish' => '1', 'redirectUrl' => "/publish.do?blogID={$_GET['blog']}&inprogress=true"); @@ -177,12 +182,18 @@ class Blogger_Import { $response = $this->get_blogger($url, $this->import['cookies']); if ( preg_match('#

.*

#U', $response['body'], $matches) ) { $progress = $matches[0]; - die($progress); + die($head . $progress); } else { echo "matches:
" . print_r($matches,1) . "
\n"; } } else { - echo "

Publish error: No 302

Please tell the devs.

" . addslashes(print_r($response,1)) . "
\n"; + if ( strstr($response['body'], 'Please sign in before proceeding') ) { + $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']); + update_option('import-blogger', $this->import); + die($this->refresher(500) . "

Logging into Blogger again...

"); + } else { + echo "

Publish error: No 302

Please tell the devs.

" . addslashes(print_r($response,1)) . "
\n"; + } } die(); } else { @@ -193,7 +204,7 @@ class Blogger_Import { $progress = $matches[0]; if ( strstr($progress, '100%') ) $this->set_next_step($i); - die($progress); + die($head . $progress); } else { echo "

Publish error: No matches

Please tell the devs.

" . print_r($matches,1) . "
\n"; } @@ -270,7 +281,6 @@ class Blogger_Import { 'publish_cookies' => false, 'published' => false, 'archives' => false, - 'newusers' => array(), 'lump_authors' => false, 'newusers' => 0, 'nextstep' => 2 @@ -367,8 +377,7 @@ class Blogger_Import { // 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); + $this->publish_blogger(5, 'Publishing with new template and options'); } // Step 4: Deprecated. :-D @@ -402,7 +411,9 @@ class Blogger_Import { $skippedpostcount = 0; $commentcount = 0; $skippedcommentcount = 0; - $status = ''; + $status = 'in progress...'; + $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status; + update_option('import-blogger', $import); $archive = implode('',file($url)); $posts = explode('', $archive); @@ -416,8 +427,7 @@ 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_name = $wpdb->escape(trim($postinfo[1])); $post_author_email = $postinfo[5] ? $postinfo[5] : 'no@email.com'; if ( $this->import['blogs'][$_GET['blog']]['lump_authors'] ) { @@ -464,9 +474,8 @@ class Blogger_Import { $post_status = 'publish'; - if ( post_exists($post_title, '', $post_date) ) { + if ( $comment_post_ID = post_exists($post_title, '', $post_date) ) { $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); @@ -490,22 +499,20 @@ 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') - "); + $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved'); + $commentdata = wp_filter_comment($commentdata); + if ( false == wp_insert_comment($commentdata) ) $skippedcommentcount++; } $commentcount++; } @@ -522,7 +529,7 @@ 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 @@ -568,8 +575,7 @@ class Blogger_Import { // 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 @@ -581,8 +587,8 @@ class Blogger_Import { "; 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"; - 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"; + if ( $n = $this->import['blogs'][$_GET['blog']]['newusers'] ) + echo "
  • Since we had to create $n new user" . ( $n > 1 ? 's' : '' ) . ", 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