Movable Type and TypePad Importer - Version 0.6

Version Description

  • Add support for WordPress 6.1
Download this release

Release Info

Developer githubsync
Plugin Icon 128x128 Movable Type and TypePad Importer
Version 0.6
Comparing to
See all releases

Code changes from version 0.4 to 0.6

Files changed (2) hide show
  1. movabletype-importer.php +93 -22
  2. readme.txt +11 -3
movabletype-importer.php CHANGED
@@ -5,14 +5,23 @@ Plugin URI: http://wordpress.org/extend/plugins/movabletype-importer/
5
  Description: Import posts and comments from a Movable Type or TypePad blog.
6
  Author: wordpressdotorg
7
  Author URI: http://wordpress.org/
8
- Version: 0.4
9
- Stable tag: 0.4
10
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
  */
12
 
13
  if ( !defined('WP_LOAD_IMPORTERS') )
14
  return;
15
 
 
 
 
 
 
 
 
 
 
 
16
  // Load Importer API
17
  require_once ABSPATH . 'wp-admin/includes/import.php';
18
 
@@ -40,7 +49,11 @@ class MT_Import extends WP_Importer {
40
 
41
  function header() {
42
  echo '<div class="wrap">';
43
- screen_icon();
 
 
 
 
44
  echo '<h2>'.__('Import Movable Type or TypePad', 'movabletype-importer').'</h2>';
45
  }
46
 
@@ -72,7 +85,7 @@ class MT_Import extends WP_Importer {
72
  }
73
 
74
  function users_form($n) {
75
- $users = get_users_of_blog();
76
  ?><select name="userselect[<?php echo $n; ?>]">
77
  <option value="#NONE#"><?php _e('&mdash; Select &mdash;', 'movabletype-importer') ?></option>
78
  <?php
@@ -203,7 +216,11 @@ class MT_Import extends WP_Importer {
203
  function mt_authors_form() {
204
  ?>
205
  <div class="wrap">
206
- <?php screen_icon(); ?>
 
 
 
 
207
  <h2><?php _e('Assign Authors', 'movabletype-importer'); ?></h2>
208
  <p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as admin&#8217;s entries.', 'movabletype-importer'); ?></p>
209
  <p><?php _e('Below, you can see the names of the authors of the Movable Type posts in <em>italics</em>. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.', 'movabletype-importer'); ?></p>
@@ -230,7 +247,7 @@ class MT_Import extends WP_Importer {
230
  }
231
 
232
  function select_authors() {
233
- if ( $_POST['upload_type'] === 'ftp' ) {
234
  $file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
235
  if ( !file_exists($file['file']) )
236
  $file['error'] = __('<code>mt-export.txt</code> does not exist', 'movabletype-importer');
@@ -288,7 +305,7 @@ class MT_Import extends WP_Importer {
288
  $comment = get_object_vars($comment);
289
  $comment = add_magic_quotes($comment);
290
 
291
- if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) {
292
  $comment['comment_post_ID'] = $post_id;
293
  $comment = wp_filter_comment($comment);
294
  wp_insert_comment($comment);
@@ -304,7 +321,7 @@ class MT_Import extends WP_Importer {
304
  $ping = get_object_vars($ping);
305
  $ping = add_magic_quotes($ping);
306
 
307
- if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) {
308
  $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
309
  $ping['comment_post_ID'] = $post_id;
310
  $ping = wp_filter_comment($ping);
@@ -320,6 +337,32 @@ class MT_Import extends WP_Importer {
320
  //ob_flush();flush();
321
  }
322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  function process_posts() {
324
  global $wpdb;
325
 
@@ -328,37 +371,57 @@ class MT_Import extends WP_Importer {
328
  return false;
329
 
330
  $context = '';
331
- $post = new StdClass();
332
- $comment = new StdClass();
333
  $comments = array();
334
- $ping = new StdClass();
335
  $pings = array();
336
 
337
  echo "<div class='wrap'><ol>";
338
 
 
 
 
 
 
 
 
 
 
 
 
339
  while ( $line = $this->fgets($handle) ) {
 
 
 
 
 
 
 
340
  $line = trim($line);
341
 
342
  if ( '-----' == $line ) {
343
  // Finishing a multi-line field
344
  if ( 'comment' == $context ) {
345
  $comments[] = $comment;
346
- $comment = new StdClass();
347
  } else if ( 'ping' == $context ) {
348
  $pings[] = $ping;
349
- $ping = new StdClass();
350
  }
351
  $context = '';
352
  } else if ( '--------' == $line ) {
353
  // Finishing a post.
354
  $context = '';
355
- $result = $this->save_post($post, $comments, $pings);
356
- if ( is_wp_error( $result ) )
357
  return $result;
358
- $post = new StdClass;
359
- $comment = new StdClass();
360
- $ping = new StdClass();
 
361
  $comments = array();
 
362
  $pings = array();
363
  } else if ( 'BODY:' == $line ) {
364
  $context = 'body';
@@ -475,6 +538,18 @@ class MT_Import extends WP_Importer {
475
 
476
  echo '</ol>';
477
 
 
 
 
 
 
 
 
 
 
 
 
 
478
  wp_import_cleanup($this->id);
479
  do_action('import_done', 'mt');
480
 
@@ -516,10 +591,6 @@ class MT_Import extends WP_Importer {
516
  break;
517
  }
518
  }
519
-
520
- function MT_Import() {
521
- // Nothing.
522
- }
523
  }
524
 
525
  $mt_import = new MT_Import();
5
  Description: Import posts and comments from a Movable Type or TypePad blog.
6
  Author: wordpressdotorg
7
  Author URI: http://wordpress.org/
8
+ Version: 0.6
 
9
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
  */
11
 
12
  if ( !defined('WP_LOAD_IMPORTERS') )
13
  return;
14
 
15
+ // define this to false to disallow duplicated comments. Warning: very slow on large imports
16
+ if ( !defined('WP_MT_IMPORT_ALLOW_DUPE_COMMENTS') ) {
17
+ define( 'WP_MT_IMPORT_ALLOW_DUPE_COMMENTS', true );
18
+ }
19
+
20
+ // define this to true to force autocommit during import. Warning: extremely slow on large imports.
21
+ if ( !defined('WP_MT_IMPORT_FORCE_AUTOCOMMIT') ) {
22
+ define( 'WP_MT_IMPORT_FORCE_AUTOCOMMIT', false );
23
+ }
24
+
25
  // Load Importer API
26
  require_once ABSPATH . 'wp-admin/includes/import.php';
27
 
49
 
50
  function header() {
51
  echo '<div class="wrap">';
52
+
53
+ if ( version_compare( get_bloginfo( 'version' ), '3.8.0', '<' ) ) {
54
+ screen_icon();
55
+ }
56
+
57
  echo '<h2>'.__('Import Movable Type or TypePad', 'movabletype-importer').'</h2>';
58
  }
59
 
85
  }
86
 
87
  function users_form($n) {
88
+ $users = version_compare( get_bloginfo( 'version' ), '3.1.0', '<' ) ? get_users_of_blog() : get_users();
89
  ?><select name="userselect[<?php echo $n; ?>]">
90
  <option value="#NONE#"><?php _e('&mdash; Select &mdash;', 'movabletype-importer') ?></option>
91
  <?php
216
  function mt_authors_form() {
217
  ?>
218
  <div class="wrap">
219
+ <?php
220
+ if ( version_compare( get_bloginfo( 'version' ), '3.8.0', '<' ) ) {
221
+ screen_icon();
222
+ }
223
+ ?>
224
  <h2><?php _e('Assign Authors', 'movabletype-importer'); ?></h2>
225
  <p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as admin&#8217;s entries.', 'movabletype-importer'); ?></p>
226
  <p><?php _e('Below, you can see the names of the authors of the Movable Type posts in <em>italics</em>. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.', 'movabletype-importer'); ?></p>
247
  }
248
 
249
  function select_authors() {
250
+ if ( isset( $_POST['upload_type'] ) && $_POST['upload_type'] === 'ftp' ) {
251
  $file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
252
  if ( !file_exists($file['file']) )
253
  $file['error'] = __('<code>mt-export.txt</code> does not exist', 'movabletype-importer');
305
  $comment = get_object_vars($comment);
306
  $comment = add_magic_quotes($comment);
307
 
308
+ if ( WP_MT_IMPORT_ALLOW_DUPE_COMMENTS || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
309
  $comment['comment_post_ID'] = $post_id;
310
  $comment = wp_filter_comment($comment);
311
  wp_insert_comment($comment);
321
  $ping = get_object_vars($ping);
322
  $ping = add_magic_quotes($ping);
323
 
324
+ if ( WP_MT_IMPORT_ALLOW_DUPE_COMMENTS || !comment_exists($ping['comment_author'], $ping['comment_date'])) {
325
  $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
326
  $ping['comment_post_ID'] = $post_id;
327
  $ping = wp_filter_comment($ping);
337
  //ob_flush();flush();
338
  }
339
 
340
+ private function create_post() {
341
+ $post = new StdClass();
342
+
343
+ $post->post_content = '';
344
+ $post->extended = '';
345
+ $post->post_excerpt = '';
346
+ $post->post_keywords = '';
347
+ $post->categories = array();
348
+
349
+ return $post;
350
+ }
351
+
352
+ private function create_comment() {
353
+ $comment = new StdClass();
354
+
355
+ $comment->comment_content = '';
356
+ $comment->comment_author = '';
357
+ $comment->comment_author_url = '';
358
+ $comment->comment_author_email = '';
359
+ $comment->comment_author_IP = '';
360
+ $comment->comment_date = null;
361
+ $comment->comment_post_ID = null;
362
+
363
+ return $comment;
364
+ }
365
+
366
  function process_posts() {
367
  global $wpdb;
368
 
371
  return false;
372
 
373
  $context = '';
374
+ $post = $this->create_post();
375
+ $comment = $this->create_comment();
376
  $comments = array();
377
+ $ping = $this->create_comment();
378
  $pings = array();
379
 
380
  echo "<div class='wrap'><ol>";
381
 
382
+ // disable some slowdown points, turn them back on later
383
+ wp_suspend_cache_invalidation( true );
384
+ wp_defer_term_counting( true );
385
+ wp_defer_comment_counting( true );
386
+
387
+ // turn off autocommit, for speed
388
+ if ( !WP_MT_IMPORT_FORCE_AUTOCOMMIT ) {
389
+ $wpdb->query('SET autocommit = 0');
390
+ }
391
+
392
+ $count = 0;
393
  while ( $line = $this->fgets($handle) ) {
394
+
395
+ // commit once every 500 posts
396
+ $count++;
397
+ if ( !WP_MT_IMPORT_FORCE_AUTOCOMMIT && $count % 500 === 0 ) {
398
+ $wpdb->query('COMMIT');
399
+ }
400
+
401
  $line = trim($line);
402
 
403
  if ( '-----' == $line ) {
404
  // Finishing a multi-line field
405
  if ( 'comment' == $context ) {
406
  $comments[] = $comment;
407
+ $comment = $this->create_comment();
408
  } else if ( 'ping' == $context ) {
409
  $pings[] = $ping;
410
+ $ping = $this->create_comment();
411
  }
412
  $context = '';
413
  } else if ( '--------' == $line ) {
414
  // Finishing a post.
415
  $context = '';
416
+ $result = $this->save_post( $post, $comments, $pings );
417
+ if ( is_wp_error( $result ) ) {
418
  return $result;
419
+ }
420
+
421
+ $post = $this->create_post();
422
+ $comment = $this->create_comment();
423
  $comments = array();
424
+ $ping = $this->create_comment();
425
  $pings = array();
426
  } else if ( 'BODY:' == $line ) {
427
  $context = 'body';
538
 
539
  echo '</ol>';
540
 
541
+ // commit the changes, turn autocommit back on
542
+ if ( !WP_MT_IMPORT_FORCE_AUTOCOMMIT ) {
543
+ $wpdb->query('COMMIT');
544
+ $wpdb->query('SET autocommit = 1');
545
+ }
546
+
547
+ // turn basic caching and counting back on, flush the cache. This will also cause a full count to be performed for terms and comments
548
+ wp_suspend_cache_invalidation( false );
549
+ wp_cache_flush();
550
+ wp_defer_term_counting( false );
551
+ wp_defer_comment_counting( false );
552
+
553
  wp_import_cleanup($this->id);
554
  do_action('import_done', 'mt');
555
 
591
  break;
592
  }
593
  }
 
 
 
 
594
  }
595
 
596
  $mt_import = new MT_Import();
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Plugin Name ===
2
  Contributors: wordpressdotorg
3
- Donate link:
4
  Tags: importer, movable type, typepad
5
  Requires at least: 3.0
6
- Tested up to: 4.1
7
- Stable tag: 0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -26,6 +26,14 @@ Import posts and comments from a Movable Type or TypePad blog.
26
 
27
  == Changelog ==
28
 
 
 
 
 
 
 
 
 
29
  = 0.4 =
30
  * String updates
31
 
1
  === Plugin Name ===
2
  Contributors: wordpressdotorg
3
+ Donate link:
4
  Tags: importer, movable type, typepad
5
  Requires at least: 3.0
6
+ Tested up to: 6.1
7
+ Stable tag: 0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
26
 
27
  == Changelog ==
28
 
29
+ = 0.6 =
30
+ * Add support for WordPress 6.1
31
+
32
+ = 0.5 =
33
+ * Remove comment_exists check for importing comments. In testing, I found no duplicated comments via this method, and it's extremely slow on large imports. If this check is needed, then define('WP_MT_IMPORT_ALLOW_DUPE_COMMENTS', false);
34
+ * Disable cache invalidation and both term and comment counting during import, for speed. Re-enable them after import.
35
+ * Disable autocommit during import, commit once every 500 posts and after complete import. Huge speed boost. To force autocommit to be left alone, define('WP_MT_IMPORT_FORCE_AUTOCOMMIT',true);
36
+
37
  = 0.4 =
38
  * String updates
39