Changeset 2939
- Timestamp:
- 10/07/2005 05:43:43 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/import/blogger.php (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/blogger.php
r2928 r2939 2 2 3 3 class Blogger_Import { 4 4 5 var $lump_authors = false; 5 6 var $import = array(); 6 var $template = '<br />7 <br />8 <br />9 <MainPage>10 <p>Are you looking for %title%? It is temporarily out of service. Please try again in an hour. Meanwhile, discover <a href="http://wordpress.org">a better blogging tool</a>.</p>11 <BloggerArchives>12 <a class="archive" href="<$BlogArchiveURL$>"><$BlogArchiveName$></a><br />13 </BloggerArchives>14 </MainPage>15 <ArchivePage>16 <Blogger><wordpresspost><$BlogItemDateTime$>|W|P|<$BlogItemAuthorNickname$>|W|P|<$BlogItemBody$>|W|P|<$BlogItemNumber$>|W|P|<$BlogItemTitle$>|W|P|<$BlogItemAuthorEmail$><BlogItemCommentsEnabled><BlogItemComments><wordpresscomment><$BlogCommentDateTime$>|W|P|<$BlogCommentAuthor$>|W|P|<$BlogCommentBody$></BlogItemComments></BlogItemCommentsEnabled></Blogger>17 </ArchivePage>';18 7 19 8 // Shows the welcome screen and the magic iframe. 20 9 function greet() { 21 echo '<div class="wrap">'; 22 echo '<h2>'.__('Import Blogger').'</h2>'; 23 _e("<p>Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.</p> 24 <p>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.</p> 25 <p>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.</p>"); 26 echo "<iframe src='admin.php?import=blogger&noheader=true' height='350px' width = '99%'></iframe>"; 27 echo "<p><a href='admin.php?import=blogger&restart=true&noheader=true' onclick='return confirm(\"This will delete everything saved by the Blogger importer. Are you sure you want to do this?\")'>Reset this importer</a></p>"; 28 echo '</div>'; 10 $title = __('Import Blogger'); 11 $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.'); 12 $noiframes = __('This feature requires iframe support.'); 13 $warning = __('This will delete everything saved by the Blogger importer except your posts and comments. Are you sure you want to do this?'); 14 $reset = __('Reset this importer'); 15 echo "<div class='wrap'><h2>$title</h2><p>$welcome</p><iframe src='admin.php?import=blogger&noheader=true' height='350px' width = '99%'>$noiframes</iframe><p><a href='admin.php?import=blogger&restart=true&noheader=true' onclick='return confirm(\"$warning\")'>$reset</a></p></div>\n"; 29 16 } 30 17 … … 38 25 // Generates a string that will make the page reload in a specified interval. 39 26 function refresher($msec) { 40 return "<html><head><script type='text/javascript'>window.onload=setInterval('window.location.reload()', $msec);</script>\n</head>\n<body>"; 27 if ( $msec ) 28 return "<html><head><script type='text/javascript'>window.onload=setTimeout('window.location.reload()', $msec);</script>\n</head>\n<body>\n"; 29 else 30 return "<html><head><script type='text/javascript'>window.onload=window.location.reload();</script>\n</head>\n<body>\n"; 41 31 } 42 32 … … 67 57 // Prints a form for the user to enter Blogger creds. 68 58 function login_form($text='') { 69 echo "<h1>Log in to Blogger</h1>\n<p>$text</p>\n"; 70 die("<form method='post' action='admin.php?import=blogger&noheader=true&step=0'><input type='text' name='user' /><input type='password' name='pass' /><input type='submit' value='Start' /></form>"); 59 echo '<h1>' . __('Log in to Blogger') . "</h1>\n$text\n"; 60 echo '<form method="post" action="admin.php?import=blogger&noheader=true&step=0"><table><tr><td>' . __('Username') . ':</td><td><input type="text" name="user" /></td></tr><tr><td>' . __('Password') . ':</td><td><input type="password" name="pass" /></td><td><input type="submit" value="' . __('Start') . '" /></td></tr></table></form>'; 61 die; 71 62 } 72 63 … … 79 70 curl_setopt($ch, CURLOPT_POSTFIELDS,$params); 80 71 curl_setopt($ch, CURLOPT_URL,$_url); 81 curl_setopt($ch, CURLOPT_USERAGENT, ' DevelopingBlogger Exporter');72 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); 82 73 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 83 74 curl_setopt($ch, CURLOPT_HEADER,1); … … 86 77 87 78 $response = $this->parse_response($response); 79 80 sleep(1); 88 81 89 82 return $response['cookies']; … … 97 90 curl_setopt($ch, CURLOPT_TIMEOUT, 10); 98 91 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 99 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);100 92 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 93 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); 101 94 curl_setopt($ch, CURLOPT_HEADER,1); 102 95 if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header); … … 125 118 if ($user && $pass) $params .= "username=$user&password=$pass"; 126 119 $params = trim($params,'&'); 127 //echo addslashes(print_r(array('url'=>$url,'header'=>$header,'params'=>$params),1));128 120 $ch = curl_init(); 129 121 curl_setopt($ch, CURLOPT_POST,1); … … 131 123 if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}"); 132 124 curl_setopt($ch, CURLOPT_URL,$url); 133 curl_setopt($ch, CURLOPT_USERAGENT, ' DevelopingBlogger Exporter');125 curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter'); 134 126 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 135 127 curl_setopt($ch, CURLOPT_HEADER,$parse); … … 150 142 function show_blogs() { 151 143 global $import; 152 echo "<h1>Selecting a Blog</h1>\n<ul>";144 echo '<h1>' . __('Selecting a Blog') . "</h1>\n<ul>"; 153 145 foreach ( $this->import['blogs'] as $blog ) { 154 146 if (9 == $blog['nextstep']) $status = "100%"; … … 166 158 167 159 // Publishes. 168 function publish_blogger($i) { 169 if ( ! $this->import['blogs'][$_GET['blog']]['publish'][$i] ) { 170 // First call. Start the publish process. 160 function publish_blogger($i, $text) { 161 $head = $this->refresher(2000) . "<h1>$text</h1>\n"; 162 if ( ! strstr($this->import['blogs'][$_GET['blog']]['publish'][$i], 'http') ) { 163 // First call. Start the publish process with a fresh set of cookies. 164 $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']); 165 update_option('import-blogger', $this->import); 171 166 $paramary = array('blogID' => $_GET['blog'], 'all' => '1', 'republishAll' => 'Republish Entire Blog', 'publish' => '1', 'redirectUrl' => "/publish.do?blogID={$_GET['blog']}&inprogress=true"); 167 172 168 $response = $this->post_blogger("http://www.blogger.com/publish.do?blogID={$_GET['blog']}", $this->import['cookies'], $paramary); 173 169 if ( $response['code'] == '302' ) { … … 176 172 update_option('import-blogger', $this->import); 177 173 $response = $this->get_blogger($url, $this->import['cookies']); 178 if ( preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches) ) { 179 $progress = $matches[0]; 180 die($progress); 181 } else { 182 echo "matches:<pre>" . print_r($matches,1) . "</pre>\n"; 183 } 174 preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches); 175 $progress = $matches[0]; 176 die($head . $progress); 184 177 } else { 185 echo "<h1>Publish error: No 302</h1><p>Please tell the devs.</p><pre>" . addslashes(print_r($response,1)) . "</pre>\n"; 186 } 187 die(); 178 $this->import['blogs'][$_GET['blog']]['publish'][$i] = false; 179 update_option('import-blogger', $this->import); 180 die($head); 181 } 188 182 } else { 189 183 // Subsequent call. Keep checking status until Blogger reports publish complete. … … 192 186 if ( preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches) ) { 193 187 $progress = $matches[0]; 194 if ( strstr($progress, '100%') ) 188 if ( strstr($progress, '100%') ) { 195 189 $this->set_next_step($i); 196 die($progress); 190 $progress .= '<p>'.__('Moving on...').'</p>'; 191 } 192 die($head . $progress); 197 193 } else { 198 echo "<h1>Publish error: No matches</h1><p>Please tell the devs.</p><pre>" . print_r($matches,1) . "</pre>\n"; 194 $this->import['blogs'][$_GET['blog']]['publish'][$i] = false; 195 update_option('import-blogger', $this->import); 196 die("$head<p>" . __('Trying again...') . '</p>'); 199 197 } 200 198 } … … 213 211 } 214 212 215 // Step 0: Do Blogger login, get userid andblogid/title pairs.213 // Step 0: Do Blogger login, get blogid/title pairs. 216 214 function do_login() { 217 215 if ( ( ! $this->import['user'] && ! is_array($this->import['cookies']) ) ) { 218 216 // The user must provide a Blogger username and password. 219 217 if ( ! ( $_POST['user'] && $_POST['pass'] ) ) { 220 $this->login_form( "Please log in using your Blogger credentials.");218 $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:</p><ol><li>Back up your Blogger template.</li><li>Back up any other Blogger settings you might need later.</li><li>Log out of Blogger</li><li>Log in <em>here</em> with your Blogger username and password.</li><li>On the next screen, click one of your Blogger blogs.</li><li>Do not close this window or navigate away until the process is complete.</li></ol>')); 221 219 } 222 220 … … 231 229 $this->import['user'] = $_POST['user']; 232 230 233 // Get the blog numbers so we can give the user a choice. 234 $response = $this->get_blogger('https://www.blogger.com/atom','',$_POST['user'],$_POST['pass']); 235 $blogger = $response['body']; 236 237 // Save the userID if we got one from Blogger, otherwise re-login. 238 $useridary = array(); 239 preg_match('#>(\d+)</userid#', $blogger, $useridary); 240 241 if (! $this->import['userid'] = $useridary[1]) $this->login_form("Login failed. Please re-enter your username and password."); 242 unset($useridary); 243 244 // Save the blogs 231 // Get the Blogger welcome page and scrape the blog numbers and names from it 232 $response = $this->get_blogger('http://www.blogger.com/home', $this->import['cookies']); 233 if (! stristr($response['body'], 'signed in as') ) $this->login_form("Login failed. Please re-enter your username and password."); 245 234 $blogsary = array(); 246 preg_match_all('# /atom/(\d+)" rel\="service.feed" title="([^"]+)"#', $blogger, $blogsary);247 if ( ! is_array( $blogsary[1]) )248 die( 'No blogs found for this user.');235 preg_match_all('#posts\.g\?blogID=(\d+)">([^<]+)</a>#U', $response['body'], $blogsary); 236 if ( ! count( $blogsary[1] < 1 ) ) 237 die(__('No blogs found for this user.')); 249 238 $this->import['blogs'] = array(); 239 $template = '<MainPage><br /><br /><br /><p>'.__('Are you looking for %title%? It is temporarily out of service. Please try again in a few minutes. Meanwhile, discover <a href="http://wordpress.org">a better blogging tool</a>.').'</p><BloggerArchives><a class="archive" href="<$BlogArchiveURL$>"><$BlogArchiveName$></a><br /></BloggerArchives></MainPage><ArchivePage><Blogger><wordpresspost><$BlogItemDateTime$>|W|P|<$BlogItemAuthorNickname$>|W|P|<$BlogItemBody$>|W|P|<$BlogItemNumber$>|W|P|<$BlogItemTitle$>|W|P|<$BlogItemAuthorEmail$><BlogItemCommentsEnabled><BlogItemComments><wordpresscomment><$BlogCommentDateTime$>|W|P|<$BlogCommentAuthor$>|W|P|<$BlogCommentBody$></BlogItemComments></BlogItemCommentsEnabled></Blogger></ArchivePage>'; 250 240 foreach ( $blogsary[1] as $key => $id ) { 251 241 // Define the required Blogger options. 252 242 $blog_opts = array( 253 243 'blog-options-basic' => false, 244 'blog-options-archiving' => array('archiveFrequency' => 'm'), 245 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false'), 254 246 'blog-formatting' => array('timeStampFormat' => '0', 'encoding'=>'UTF-8', 'convertLineBreaks'=>'false', 'floatAlignment'=>'false'), 255 247 'blog-comments' => array('commentsTimeStampFormat' => '0'), 256 'blog-options-archiving' => array('archiveFrequency' => 'm'), 257 'template-edit' => array( 'templateText' => str_replace('%title%', $blogsary[2][$key], $this->template) ), 258 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false') 248 'template-edit' => array( 'templateText' => str_replace('%title%', trim($blogsary[2][$key]), $template) ) 259 249 ); 260 250 … … 265 255 $this->import['blogs']["$id"] = array( 266 256 'id' => $id, 267 'title' => $blogsary[2][$key],257 'title' => trim($blogsary[2][$key]), 268 258 'options' => $new_opts, 269 259 'url' => false, … … 271 261 'published' => false, 272 262 'archives' => false, 263 'lump_authors' => false, 273 264 'newusers' => array(), 274 'lump_authors' => false,275 'newusers' => 0,276 265 'nextstep' => 2 277 266 ); … … 299 288 foreach ($this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary) { 300 289 if ( $blog_opt == $_GET['form'] ) { 301 // Make sure not to overwrite any existing backups!302 if ( $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] ) continue;303 304 290 // Save the posted form data 305 291 $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] = $_POST; … … 310 296 $posturl = "http://www.blogger.com/{$blog_opt}.do"; 311 297 $headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']); 312 switch ($blog_opt) { 313 case 'blog-publishing': 298 if ( 'blog-publishing' == $blog_opt ) { 314 299 if ( $_POST['publishMode'] > 0 ) { 315 300 $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode=0", $headers); 316 301 if ( $response['code'] >= 400 ) 317 die('<h2> Failed attempt to change publishMode:</h2><pre>' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '</pre>');302 die('<h2>'.__('Failed attempt to change publish mode from FTP to BlogSpot.').'</h2><pre>' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '</pre>'); 318 303 $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $optary['modify']['subdomain'] . '.blogspot.com/'; 304 sleep(2); 319 305 } else { 320 306 $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $_POST['subdomain'] . '.blogspot.com/'; 321 307 update_option('import-blogger', $this->import); 322 continue 2; 308 $output .= "<del><p>$blog_opt</p></del>\n"; 309 continue; 323 310 } 324 311 $paramary = $optary['modify']; 325 break; 326 case 'template-edit': 327 $this->import['blogs'][$_GET['blog']]['publish_cookies'] = $headers; 328 update_option('import-blogger', $this->import); 329 default: 312 } else { 330 313 $paramary = array_merge($_POST, $optary['modify']); 331 314 } 332 315 $response = $this->post_blogger($posturl, $headers, $paramary); 333 316 if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) 334 die( "<p>Error on form submission. Refresh/Reload and click YES to resubmit.</p>" . addslashes(print_r($response, 1))); 335 //header("Location: admin.php?import=blogger&noheader=true&step=2&blog={$_GET['blog']}"); 336 //die(); 317 die('<p>'.__('Error on form submission. Retry or reset the importer.').'</p>' . addslashes(print_r($response, 1))); 337 318 } 338 319 $output .= "<del><p>$blog_opt</p></del>\n"; … … 362 343 die($output . $form); 363 344 364 $this->set_next_step( 3);345 $this->set_next_step(4); 365 346 $this->do_next_step(); 366 347 } 367 348 368 // Step 3: Publish with the new template and settings. 349 // Step 3: Cancelled :-) 350 351 // Step 4: Publish with the new template and settings. 369 352 function publish_blog() { 370 echo $this->refresher(2400) . "<h1>Publishing with new template and options</h1>\n"; 371 $this->publish_blogger(5); 372 } 373 374 // Step 4: Deprecated. :-D 353 $this->publish_blogger(5, __('Publishing with new template and options')); 354 } 375 355 376 356 // Step 5: Get the archive URLs from the new blog. 377 357 function get_archive_urls() { 378 $bloghtml = file($this->import['blogs'][$_GET['blog']]['url']);379 if (! is_array($bloghtml) ) die('Trouble connecting to your blog. Try reloading this page.');380 preg_match_all('#<a class="archive" href="([^"]*)"#', implode('',$bloghtml), $archives);381 if ( count($archives[1]) == 0 ) die ("That's odd. No archives were found. Does <a href='{$import['blogs'][$_GET['blog']]['url']}'>your blog</a> say Temporary Template?");358 $bloghtml = $this->get_blogger($this->import['blogs'][$_GET['blog']]['url']); 359 if (! strstr($bloghtml['body'], '<a class="archive"') ) 360 die(__('Your Blogger blog did not take the new template or did not respond.')); 361 preg_match_all('#<a class="archive" href="([^"]*)"#', $bloghtml['body'], $archives); 382 362 foreach ($archives[1] as $archive) { 383 363 $this->import['blogs'][$_GET['blog']]['archives'][$archive] = false; … … 390 370 function get_archive() { 391 371 global $wpdb; 392 $output = "<h2>Importing Blogger archives into WordPress</h2>\n";372 $output = '<h2>'.__('Importing Blogger archives into WordPress').'</h2>'; 393 373 $did_one = false; 374 $post_array = $posts = array(); 394 375 foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) { 395 376 $archivename = substr(basename($url),0,7); … … 403 384 $commentcount = 0; 404 385 $skippedcommentcount = 0; 405 $status = ''; 406 $archive = implode('',file($url)); 407 408 $posts = explode('<wordpresspost>', $archive); 386 $status = __('in progress...'); 387 $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status; 388 update_option('import-blogger', $import); 389 $archive = $this->get_blogger($url); 390 if ( $archive['code'] > 200 ) 391 continue; 392 $posts = explode('<wordpresspost>', $archive['body']); 409 393 for ($i = 1; $i < count($posts); $i = $i + 1) { 410 394 $postparts = explode('<wordpresscomment>', $posts[$i]); … … 417 401 //$post_number = $postinfo[3]; 418 402 $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3]; 419 $post_author = trim($wpdb->escape($postinfo[1])); 420 $post_author_name = trim(addslashes($postinfo[1])); 421 $post_author_email = $postinfo[5] ? $postinfo[5] : 'no@email.com'; 422 423 if ( $this->import['blogs'][$_GET['blog']]['lump_authors'] ) { 403 $post_author_name = $wpdb->escape(trim($postinfo[1])); 404 $post_author_email = $postinfo[5] ? $postinfo[5] : 'user@wordpress.org'; 405 406 if ( $this->lump_authors ) { 424 407 // Ignore Blogger authors. Use the current user_ID for all posts imported. 425 $post_author = $GLOBALS['user_ID']; // For WPMU only. Assume all posts belong to the current user.408 $post_author = $GLOBALS['user_ID']; 426 409 } else { 427 410 // Add a user for each new author encountered. 428 411 if (! username_exists($post_author_name) ) { 429 $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!)430 412 $user_login = $wpdb->escape($post_author_name); 431 $pass1 = $wpdb->escape('password');432 413 $user_email = $wpdb->escape($post_author_email); 433 $user_url = $wpdb->escape('');434 $user_joindate = $wpdb->escape($user_joindate);435 414 $user_password = substr(md5(uniqid(microtime())), 0, 6); 436 415 $result = wp_create_user( $user_login, $user_password, $user_email ); 437 416 $status.= "Registered user <strong>$user_login</strong>. "; 438 ++$this->import['blogs'][$_GET['blog']]['newusers'];417 $this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login; 439 418 } 440 419 $userdata = get_userdatabylogin( $post_author_name ); … … 459 438 460 439 $post_content = addslashes($post_content); 461 $post_content = str_replace( '<br>', '<br />', $post_content); // the XHTML touch... ;)440 $post_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $post_content); // the XHTML touch... ;) 462 441 463 442 $post_title = addslashes($post_title); … … 465 444 $post_status = 'publish'; 466 445 467 if ( post_exists($post_title, '', $post_date) ) { 446 if ( $ID = post_exists($post_title, '', $post_date) ) { 447 $post_array[$i]['ID'] = $ID; 468 448 $skippedpostcount++; 469 $comment_post_ID = $dupcheck[0]['ID'];470 449 } else { 471 $post_array = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');472 $ comment_post_ID = wp_insert_post($post_array);450 $post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status'); 451 $post_array[$i]['comments'] = false; 473 452 } 474 453 475 454 // Import any comments attached to this post. 476 455 if ($postparts[1]) : … … 491 470 $commenthour = '00'; 492 471 $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond"; 493 $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.472 $comment_author = addslashes(strip_tags(html_entity_decode($commentinfo[1]))); 494 473 if ( strpos($commentinfo[1], 'a href') ) { 495 474 $comment_author_parts = explode('"', htmlentities($commentinfo[1])); 496 475 $comment_author_url = $comment_author_parts[1]; 497 476 } else $comment_author_url = ''; 498 $comment_content = addslashes($commentinfo[2]); 499 $comment_content = str_replace('<br>', '<br />', $comment_content); 500 if ( $comment_post_ID == comment_exists($comment_author, $comment_date) ) { 477 $comment_content = $commentinfo[2]; 478 $comment_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $comment_content); 479 $comment_approved = 1; 480 if ( comment_exists($comment_author, $comment_date) ) { 501 481 $skippedcommentcount++; 502 482 } else { 503 $result = $wpdb->query(" 504 INSERT INTO $wpdb->comments 505 (comment_post_ID,comment_author,comment_author_url,comment_date,comment_content) 506 VALUES 507 ('$comment_post_ID','$comment_author','$comment_author_url','$comment_date','$comment_content') 508 "); 483 $comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved'); 484 $post_array[$i]['comments'][$j] = wp_filter_comment($comment); 509 485 } 510 486 $commentcount++; … … 513 489 $postcount++; 514 490 } 515 $status = "$postcount post(s) parsed, $skippedpostcount skipped... $commentcount comment(s) parsed, $skippedcommentcount skipped... <strong>Done</strong>"; 491 if ( count($post_array) ) { 492 krsort($post_array); 493 foreach($post_array as $post) { 494 if ( ! $comment_post_ID = $post['ID'] ) 495 $comment_post_ID = wp_insert_post($post['post']); 496 if ( $post['comments'] ) { 497 foreach ( $post['comments'] as $comment ) { 498 $comment['comment_post_ID'] = $comment_post_ID; 499 wp_insert_comment($comment); 500 } 501 } 502 } 503 } 504 $status = "$postcount ".__('post(s) parsed,')." $skippedpostcount ".__('skipped...')." $commentcount ".__('comment(s) parsed,')." $skippedcommentcount ".__('skipped...').' <strong>'.__('Done').'</strong>'; 516 505 $import = $this->import; 517 506 $import['blogs'][$_GET['blog']]['archives']["$url"] = $status; … … 523 512 if ( ! $did_one ) 524 513 $this->set_next_step(7); 525 die( $this->refresher( 5000) . $output );514 die( $this->refresher(1000) . $output ); 526 515 } 527 516 528 517 // Step 7: Restore the backed-up settings to Blogger 529 518 function restore_settings() { 530 $output = "<h1>Restoring your Blogger options</h1>\n";519 $output = '<h1>'.__('Restoring your Blogger options')."</h1>\n"; 531 520 $did_one = false; 521 // Restore options in reverse order. 522 if ( ! $this->import['reversed'] ) { 523 $this->import['blogs'][$_GET['blog']]['options'] = array_reverse($this->import['blogs'][$_GET['blog']]['options'], true); 524 $this->import['reversed'] = true; 525 update_option('import-blogger', $this->import); 526 } 532 527 foreach ( $this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary ) { 533 528 if ( $did_one ) { 534 529 $output .= "<p>$blog_opt</p>\n"; 535 } elseif ( $optary['restored'] ) { 536 $output .= "<p><del>$blog_opt</del></p>\n"; 537 } elseif ( ! $optary['modify'] ) { 530 } elseif ( $optary['restored'] || ! $optary['modify'] ) { 538 531 $output .= "<p><del>$blog_opt</del></p>\n"; 539 532 } else { … … 543 536 if ( $optary['backup']['publishMode'] > 0 ) { 544 537 $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode={$optary['backup']['publishMode']}", $headers); 538 sleep(2); 545 539 if ( $response['code'] >= 400 ) 546 540 die('<h1>Error restoring publishMode.</h1><p>Please tell the devs.</p>' . addslashes(print_r($response, 1)) ); … … 549 543 if ( $optary['backup'] != $optary['modify'] ) { 550 544 $response = $this->post_blogger($posturl, $headers, $optary['backup']); 551 if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) 552 die( "<h1>Error on form submission in Step 7.</h1><p>Please tell the devs.</p>" . addslashes(print_r($response, 1))); 545 if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) { 546 $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['error'] = true; 547 update_option('import-blogger', $this->import); 548 $output .= "<p><strong>$blog_opt</strong> ".__('failed. Trying again.').'</p>'; 549 } else { 550 $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true; 551 update_option('import-blogger', $this->import); 552 $output .= "<p><strong>$blog_opt</strong> ".__('restored.').'</p>'; 553 } 553 554 } 554 $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true;555 update_option('import-blogger', $this->import);556 555 $did_one = true; 557 $output .= "<p><strong>$blog_opt</strong> in progress. Please wait...";558 556 } 559 557 } … … 561 559 if ( $did_one ) { 562 560 die( $this->refresher(1000) . $output ); 563 } 564 565 $this->set_next_step(8); 561 } elseif ( $this->import['blogs'][$_GET['blog']]['options']['blog-publishing']['backup']['publishMode'] > 0 ) { 562 $this->set_next_step(9); 563 } else { 564 $this->set_next_step(8); 565 } 566 566 567 $this->do_next_step(); 567 568 } … … 569 570 // Step 8: Republish, all back to normal 570 571 function republish_blog() { 571 echo $this->refresher(2400) . "<h1>Publishing with original template and options</h1>\n"; 572 $this->publish_blogger(9); 572 $this->publish_blogger(9, __('Publishing with original template and options')); 573 573 } 574 574 575 575 // Step 9: Congratulate the user 576 576 function congrats() { 577 echo "<h1>Congratulations!</h1> 578 <p>Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:</p> 579 <ul> 580 <li>That was hard work! Take a break.</li> 581 "; 577 echo '<h1>'.__('Congratulations!').'</h1><p>'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'</p><ul><li>'.__('That was hard work! Take a break.').'</li>'; 582 578 if ( count($this->import['blogs']) > 1 ) 583 echo "<li>In case you haven't done it already, you can import the posts from any other blogs you may have:" . $this->show_blogs() . "</li>\n";579 echo '<li>'.__('In case you haven\'t done it already, you can import the posts from your other blogs:'). $this->show_blogs() . '</li>'; 584 580 if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) ) 585 echo "<li>Since we had to create $n new users, you probably want to go to <a href='users.php' target='_parent'>Authors & Users</a>, 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.</li>\n";586 587 echo "\n<ul>";581 echo '<li>'.__('Go to <a href="users.php" target="_parent">Authors & Users</a>, 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.').'</li>'; 582 echo '<li>'.__('For security, click the link below to reset this importer. That will clear your Blogger credentials and options from the database.').'</li>'; 583 echo '</ul>'; 588 584 } 589 585 … … 597 593 $this->import = get_settings('import-blogger'); 598 594 599 if ( isset($_GET['step']) ) { 595 if ( false === $this->import ) { 596 $step = 0; 597 } elseif ( isset($_GET['step']) ) { 600 598 $step = (int) $_GET['step']; 601 } elseif ( isset($_GET['blog']) ) {599 } elseif ( isset($_GET['blog']) && isset($this->import['blogs'][$_GET['blog']]['nextstep']) ) { 602 600 $step = $this->import['blogs'][$_GET['blog']]['nextstep']; 603 601 } elseif ( is_array($this->import['blogs']) ) { … … 606 604 $step = 0; 607 605 } 606 //echo "Step $step."; 607 //die('<pre>'.print_r($this->import,1).'</pre'); 608 608 switch ($step) { 609 609 case 0 : … … 617 617 break; 618 618 case 3 : 619 $this->wait_for_blogger(); 620 break; 621 case 4 : 619 622 $this->publish_blog(); 620 623 break; 621 case 4 :622 624 case 5 : 623 625 $this->get_archive_urls(); … … 636 638 break; 637 639 } 638 639 640 die; 640 641 641 642 } else { 642 643 $this->greet(); … … 652 653 653 654 register_importer('blogger', 'Blogger', __('Import posts and comments from a Blogger account'), array ($blogger_import, 'start')); 655 654 656 ?>
Note: See TracChangeset
for help on using the changeset viewer.