raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Movable Type and Typepad Importer
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Importer
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Moveable Type and Typepad Importer class
mp-wp_genesis 11 *
mp-wp_genesis 12 * Upload your exported Movable Type or Typepad entries into WordPress.
mp-wp_genesis 13 *
mp-wp_genesis 14 * @since unknown
mp-wp_genesis 15 */
mp-wp_genesis 16 class MT_Import {
mp-wp_genesis 17
mp-wp_genesis 18 var $posts = array ();
mp-wp_genesis 19 var $file;
mp-wp_genesis 20 var $id;
mp-wp_genesis 21 var $mtnames = array ();
mp-wp_genesis 22 var $newauthornames = array ();
mp-wp_genesis 23 var $j = -1;
mp-wp_genesis 24
mp-wp_genesis 25 function header() {
mp-wp_genesis 26 echo '<div class="wrap">';
mp-wp_genesis 27 screen_icon();
mp-wp_genesis 28 echo '<h2>'.__('Import Movable Type or TypePad').'</h2>';
mp-wp_genesis 29 }
mp-wp_genesis 30
mp-wp_genesis 31 function footer() {
mp-wp_genesis 32 echo '</div>';
mp-wp_genesis 33 }
mp-wp_genesis 34
mp-wp_genesis 35 function greet() {
mp-wp_genesis 36 $this->header();
mp-wp_genesis 37 ?>
mp-wp_genesis 38 <div class="narrow">
mp-wp_genesis 39 <p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, either choose a file to upload and click "Upload file and import," or use FTP to upload your MT export file as <code>mt-export.txt</code> in your <code>/wp-content/</code> directory and then click "Import mt-export.txt"'); ?></p>
mp-wp_genesis 40
mp-wp_genesis 41 <?php wp_import_upload_form( add_query_arg('step', 1) ); ?>
mp-wp_genesis 42 <form method="post" action="<?php echo add_query_arg('step', 1); ?>" class="import-upload-form">
mp-wp_genesis 43
mp-wp_genesis 44 <?php wp_nonce_field('import-upload'); ?>
mp-wp_genesis 45 <p>
mp-wp_genesis 46 <input type="hidden" name="upload_type" value="ftp" />
mp-wp_genesis 47 <?php _e('Or use <code>mt-export.txt</code> in your <code>/wp-content/</code> directory'); ?></p>
mp-wp_genesis 48 <p class="submit">
mp-wp_genesis 49 <input type="submit" class="button" value="<?php echo attribute_escape(__('Import mt-export.txt')); ?>" />
mp-wp_genesis 50 </p>
mp-wp_genesis 51 </form>
mp-wp_genesis 52 <p><?php _e('The importer is smart enough not to import duplicates, so you can run this multiple times without worry if&#8212;for whatever reason&#8212;it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
mp-wp_genesis 53 </div>
mp-wp_genesis 54 <?php
mp-wp_genesis 55 $this->footer();
mp-wp_genesis 56 }
mp-wp_genesis 57
mp-wp_genesis 58 function users_form($n) {
mp-wp_genesis 59 global $wpdb;
mp-wp_genesis 60 $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID");
mp-wp_genesis 61 ?><select name="userselect[<?php echo $n; ?>]">
mp-wp_genesis 62 <option value="#NONE#"><?php _e('- Select -') ?></option>
mp-wp_genesis 63 <?php
mp-wp_genesis 64
mp-wp_genesis 65
mp-wp_genesis 66 foreach ($users as $user) {
mp-wp_genesis 67 echo '<option value="'.$user->user_login.'">'.$user->user_login.'</option>';
mp-wp_genesis 68 }
mp-wp_genesis 69 ?>
mp-wp_genesis 70 </select>
mp-wp_genesis 71 <?php
mp-wp_genesis 72
mp-wp_genesis 73 }
mp-wp_genesis 74
mp-wp_genesis 75 function has_gzip() {
mp-wp_genesis 76 return is_callable('gzopen');
mp-wp_genesis 77 }
mp-wp_genesis 78
mp-wp_genesis 79 function fopen($filename, $mode='r') {
mp-wp_genesis 80 if ( $this->has_gzip() )
mp-wp_genesis 81 return gzopen($filename, $mode);
mp-wp_genesis 82 return fopen($filename, $mode);
mp-wp_genesis 83 }
mp-wp_genesis 84
mp-wp_genesis 85 function feof($fp) {
mp-wp_genesis 86 if ( $this->has_gzip() )
mp-wp_genesis 87 return gzeof($fp);
mp-wp_genesis 88 return feof($fp);
mp-wp_genesis 89 }
mp-wp_genesis 90
mp-wp_genesis 91 function fgets($fp, $len=8192) {
mp-wp_genesis 92 if ( $this->has_gzip() )
mp-wp_genesis 93 return gzgets($fp, $len);
mp-wp_genesis 94 return fgets($fp, $len);
mp-wp_genesis 95 }
mp-wp_genesis 96
mp-wp_genesis 97 function fclose($fp) {
mp-wp_genesis 98 if ( $this->has_gzip() )
mp-wp_genesis 99 return gzclose($fp);
mp-wp_genesis 100 return fclose($fp);
mp-wp_genesis 101 }
mp-wp_genesis 102
mp-wp_genesis 103 //function to check the authorname and do the mapping
mp-wp_genesis 104 function checkauthor($author) {
mp-wp_genesis 105 //mtnames is an array with the names in the mt import file
mp-wp_genesis 106 $pass = wp_generate_password();
mp-wp_genesis 107 if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
mp-wp_genesis 108 ++ $this->j;
mp-wp_genesis 109 $this->mtnames[$this->j] = $author; //add that new mt author name to an array
mp-wp_genesis 110 $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
mp-wp_genesis 111 if (!$user_id) { //banging my head against the desk now.
mp-wp_genesis 112 if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
mp-wp_genesis 113 $user_id = wp_create_user($author, $pass);
mp-wp_genesis 114 $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank.
mp-wp_genesis 115 } else {
mp-wp_genesis 116 $user_id = wp_create_user($this->newauthornames[$this->j], $pass);
mp-wp_genesis 117 }
mp-wp_genesis 118 } else {
mp-wp_genesis 119 return $user_id; // return pre-existing wp username if it exists
mp-wp_genesis 120 }
mp-wp_genesis 121 } else {
mp-wp_genesis 122 $key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array
mp-wp_genesis 123 $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames
mp-wp_genesis 124 }
mp-wp_genesis 125
mp-wp_genesis 126 return $user_id;
mp-wp_genesis 127 }
mp-wp_genesis 128
mp-wp_genesis 129 function get_mt_authors() {
mp-wp_genesis 130 $temp = array();
mp-wp_genesis 131 $authors = array();
mp-wp_genesis 132
mp-wp_genesis 133 $handle = $this->fopen($this->file, 'r');
mp-wp_genesis 134 if ( $handle == null )
mp-wp_genesis 135 return false;
mp-wp_genesis 136
mp-wp_genesis 137 $in_comment = false;
mp-wp_genesis 138 while ( $line = $this->fgets($handle) ) {
mp-wp_genesis 139 $line = trim($line);
mp-wp_genesis 140
mp-wp_genesis 141 if ( 'COMMENT:' == $line )
mp-wp_genesis 142 $in_comment = true;
mp-wp_genesis 143 else if ( '-----' == $line )
mp-wp_genesis 144 $in_comment = false;
mp-wp_genesis 145
mp-wp_genesis 146 if ( $in_comment || 0 !== strpos($line,"AUTHOR:") )
mp-wp_genesis 147 continue;
mp-wp_genesis 148
mp-wp_genesis 149 $temp[] = trim( substr($line, strlen("AUTHOR:")) );
mp-wp_genesis 150 }
mp-wp_genesis 151
mp-wp_genesis 152 //we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.
mp-wp_genesis 153 $authors[0] = array_shift($temp);
mp-wp_genesis 154 $y = count($temp) + 1;
mp-wp_genesis 155 for ($x = 1; $x < $y; $x ++) {
mp-wp_genesis 156 $next = array_shift($temp);
mp-wp_genesis 157 if (!(in_array($next, $authors)))
mp-wp_genesis 158 array_push($authors, "$next");
mp-wp_genesis 159 }
mp-wp_genesis 160
mp-wp_genesis 161 $this->fclose($handle);
mp-wp_genesis 162
mp-wp_genesis 163 return $authors;
mp-wp_genesis 164 }
mp-wp_genesis 165
mp-wp_genesis 166 function get_authors_from_post() {
mp-wp_genesis 167 $formnames = array ();
mp-wp_genesis 168 $selectnames = array ();
mp-wp_genesis 169
mp-wp_genesis 170 foreach ($_POST['user'] as $key => $line) {
mp-wp_genesis 171 $newname = trim(stripslashes($line));
mp-wp_genesis 172 if ($newname == '')
mp-wp_genesis 173 $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form.
mp-wp_genesis 174 array_push($formnames, "$newname");
mp-wp_genesis 175 } // $formnames is the array with the form entered names
mp-wp_genesis 176
mp-wp_genesis 177 foreach ($_POST['userselect'] as $user => $key) {
mp-wp_genesis 178 $selected = trim(stripslashes($key));
mp-wp_genesis 179 array_push($selectnames, "$selected");
mp-wp_genesis 180 }
mp-wp_genesis 181
mp-wp_genesis 182 $count = count($formnames);
mp-wp_genesis 183 for ($i = 0; $i < $count; $i ++) {
mp-wp_genesis 184 if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form
mp-wp_genesis 185 array_push($this->newauthornames, "$selectnames[$i]");
mp-wp_genesis 186 } else {
mp-wp_genesis 187 array_push($this->newauthornames, "$formnames[$i]");
mp-wp_genesis 188 }
mp-wp_genesis 189 }
mp-wp_genesis 190 }
mp-wp_genesis 191
mp-wp_genesis 192 function mt_authors_form() {
mp-wp_genesis 193 ?>
mp-wp_genesis 194 <div class="wrap">
mp-wp_genesis 195 <?php screen_icon(); ?>
mp-wp_genesis 196 <h2><?php _e('Assign Authors'); ?></h2>
mp-wp_genesis 197 <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\'s entries.'); ?></p>
mp-wp_genesis 198 <p><?php _e('Below, you can see the names of the authors of the MovableType 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.'); ?></p>
mp-wp_genesis 199 <p><?php _e('If a new user is created by WordPress, a password will be randomly generated. Manually change the user\'s details if necessary.'); ?></p>
mp-wp_genesis 200 <?php
mp-wp_genesis 201
mp-wp_genesis 202
mp-wp_genesis 203 $authors = $this->get_mt_authors();
mp-wp_genesis 204 echo '<ol id="authors">';
mp-wp_genesis 205 echo '<form action="?import=mt&amp;step=2&amp;id=' . $this->id . '" method="post">';
mp-wp_genesis 206 wp_nonce_field('import-mt');
mp-wp_genesis 207 $j = -1;
mp-wp_genesis 208 foreach ($authors as $author) {
mp-wp_genesis 209 ++ $j;
mp-wp_genesis 210 echo '<li><label>'.__('Current author:').' <strong>'.$author.'</strong><br />'.sprintf(__('Create user %1$s or map to existing'), ' <input type="text" value="'.$author.'" name="'.'user[]'.'" maxlength="30"> <br />');
mp-wp_genesis 211 $this->users_form($j);
mp-wp_genesis 212 echo '</label></li>';
mp-wp_genesis 213 }
mp-wp_genesis 214
mp-wp_genesis 215 echo '<p class="submit"><input type="submit" class="button" value="'.__('Submit').'"></p>'.'<br />';
mp-wp_genesis 216 echo '</form>';
mp-wp_genesis 217 echo '</ol></div>';
mp-wp_genesis 218
mp-wp_genesis 219 }
mp-wp_genesis 220
mp-wp_genesis 221 function select_authors() {
mp-wp_genesis 222 if ( $_POST['upload_type'] === 'ftp' ) {
mp-wp_genesis 223 $file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
mp-wp_genesis 224 if ( !file_exists($file['file']) )
mp-wp_genesis 225 $file['error'] = __('<code>mt-export.txt</code> does not exist');
mp-wp_genesis 226 } else {
mp-wp_genesis 227 $file = wp_import_handle_upload();
mp-wp_genesis 228 }
mp-wp_genesis 229 if ( isset($file['error']) ) {
mp-wp_genesis 230 $this->header();
mp-wp_genesis 231 echo '<p>'.__('Sorry, there has been an error').'.</p>';
mp-wp_genesis 232 echo '<p><strong>' . $file['error'] . '</strong></p>';
mp-wp_genesis 233 $this->footer();
mp-wp_genesis 234 return;
mp-wp_genesis 235 }
mp-wp_genesis 236 $this->file = $file['file'];
mp-wp_genesis 237 $this->id = (int) $file['id'];
mp-wp_genesis 238
mp-wp_genesis 239 $this->mt_authors_form();
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 function save_post(&$post, &$comments, &$pings) {
mp-wp_genesis 243 // Reset the counter
mp-wp_genesis 244 set_time_limit(30);
mp-wp_genesis 245 $post = get_object_vars($post);
mp-wp_genesis 246 $post = add_magic_quotes($post);
mp-wp_genesis 247 $post = (object) $post;
mp-wp_genesis 248
mp-wp_genesis 249 if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) {
mp-wp_genesis 250 echo '<li>';
mp-wp_genesis 251 printf(__('Post <em>%s</em> already exists.'), stripslashes($post->post_title));
mp-wp_genesis 252 } else {
mp-wp_genesis 253 echo '<li>';
mp-wp_genesis 254 printf(__('Importing post <em>%s</em>...'), stripslashes($post->post_title));
mp-wp_genesis 255
mp-wp_genesis 256 if ( '' != trim( $post->extended ) )
mp-wp_genesis 257 $post->post_content .= "\n<!--more-->\n$post->extended";
mp-wp_genesis 258
mp-wp_genesis 259 $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
mp-wp_genesis 260 $post_id = wp_insert_post($post);
mp-wp_genesis 261 if ( is_wp_error( $post_id ) )
mp-wp_genesis 262 return $post_id;
mp-wp_genesis 263
mp-wp_genesis 264 // Add categories.
mp-wp_genesis 265 if ( 0 != count($post->categories) ) {
mp-wp_genesis 266 wp_create_categories($post->categories, $post_id);
mp-wp_genesis 267 }
mp-wp_genesis 268
mp-wp_genesis 269 // Add tags or keywords
mp-wp_genesis 270 if ( 1 < strlen($post->post_keywords) ) {
mp-wp_genesis 271 // Keywords exist.
mp-wp_genesis 272 printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords));
mp-wp_genesis 273 wp_add_post_tags($post_id, $post->post_keywords);
mp-wp_genesis 274 }
mp-wp_genesis 275 }
mp-wp_genesis 276
mp-wp_genesis 277 $num_comments = 0;
mp-wp_genesis 278 foreach ( $comments as $comment ) {
mp-wp_genesis 279 $comment = get_object_vars($comment);
mp-wp_genesis 280 $comment = add_magic_quotes($comment);
mp-wp_genesis 281
mp-wp_genesis 282 if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) {
mp-wp_genesis 283 $comment['comment_post_ID'] = $post_id;
mp-wp_genesis 284 $comment = wp_filter_comment($comment);
mp-wp_genesis 285 wp_insert_comment($comment);
mp-wp_genesis 286 $num_comments++;
mp-wp_genesis 287 }
mp-wp_genesis 288 }
mp-wp_genesis 289
mp-wp_genesis 290 if ( $num_comments )
mp-wp_genesis 291 printf(' '.__ngettext('(%s comment)', '(%s comments)', $num_comments), $num_comments);
mp-wp_genesis 292
mp-wp_genesis 293 $num_pings = 0;
mp-wp_genesis 294 foreach ( $pings as $ping ) {
mp-wp_genesis 295 $ping = get_object_vars($ping);
mp-wp_genesis 296 $ping = add_magic_quotes($ping);
mp-wp_genesis 297
mp-wp_genesis 298 if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) {
mp-wp_genesis 299 $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
mp-wp_genesis 300 $ping['comment_post_ID'] = $post_id;
mp-wp_genesis 301 $ping = wp_filter_comment($ping);
mp-wp_genesis 302 wp_insert_comment($ping);
mp-wp_genesis 303 $num_pings++;
mp-wp_genesis 304 }
mp-wp_genesis 305 }
mp-wp_genesis 306
mp-wp_genesis 307 if ( $num_pings )
mp-wp_genesis 308 printf(' '.__ngettext('(%s ping)', '(%s pings)', $num_pings), $num_pings);
mp-wp_genesis 309
mp-wp_genesis 310 echo "</li>";
mp-wp_genesis 311 //ob_flush();flush();
mp-wp_genesis 312 }
mp-wp_genesis 313
mp-wp_genesis 314 function process_posts() {
mp-wp_genesis 315 global $wpdb;
mp-wp_genesis 316
mp-wp_genesis 317 $handle = $this->fopen($this->file, 'r');
mp-wp_genesis 318 if ( $handle == null )
mp-wp_genesis 319 return false;
mp-wp_genesis 320
mp-wp_genesis 321 $context = '';
mp-wp_genesis 322 $post = new StdClass();
mp-wp_genesis 323 $comment = new StdClass();
mp-wp_genesis 324 $comments = array();
mp-wp_genesis 325 $ping = new StdClass();
mp-wp_genesis 326 $pings = array();
mp-wp_genesis 327
mp-wp_genesis 328 echo "<div class='wrap'><ol>";
mp-wp_genesis 329
mp-wp_genesis 330 while ( $line = $this->fgets($handle) ) {
mp-wp_genesis 331 $line = trim($line);
mp-wp_genesis 332
mp-wp_genesis 333 if ( '-----' == $line ) {
mp-wp_genesis 334 // Finishing a multi-line field
mp-wp_genesis 335 if ( 'comment' == $context ) {
mp-wp_genesis 336 $comments[] = $comment;
mp-wp_genesis 337 $comment = new StdClass();
mp-wp_genesis 338 } else if ( 'ping' == $context ) {
mp-wp_genesis 339 $pings[] = $ping;
mp-wp_genesis 340 $ping = new StdClass();
mp-wp_genesis 341 }
mp-wp_genesis 342 $context = '';
mp-wp_genesis 343 } else if ( '--------' == $line ) {
mp-wp_genesis 344 // Finishing a post.
mp-wp_genesis 345 $context = '';
mp-wp_genesis 346 $result = $this->save_post($post, $comments, $pings);
mp-wp_genesis 347 if ( is_wp_error( $result ) )
mp-wp_genesis 348 return $result;
mp-wp_genesis 349 $post = new StdClass;
mp-wp_genesis 350 $comment = new StdClass();
mp-wp_genesis 351 $ping = new StdClass();
mp-wp_genesis 352 $comments = array();
mp-wp_genesis 353 $pings = array();
mp-wp_genesis 354 } else if ( 'BODY:' == $line ) {
mp-wp_genesis 355 $context = 'body';
mp-wp_genesis 356 } else if ( 'EXTENDED BODY:' == $line ) {
mp-wp_genesis 357 $context = 'extended';
mp-wp_genesis 358 } else if ( 'EXCERPT:' == $line ) {
mp-wp_genesis 359 $context = 'excerpt';
mp-wp_genesis 360 } else if ( 'KEYWORDS:' == $line ) {
mp-wp_genesis 361 $context = 'keywords';
mp-wp_genesis 362 } else if ( 'COMMENT:' == $line ) {
mp-wp_genesis 363 $context = 'comment';
mp-wp_genesis 364 } else if ( 'PING:' == $line ) {
mp-wp_genesis 365 $context = 'ping';
mp-wp_genesis 366 } else if ( 0 === strpos($line, "AUTHOR:") ) {
mp-wp_genesis 367 $author = trim( substr($line, strlen("AUTHOR:")) );
mp-wp_genesis 368 if ( '' == $context )
mp-wp_genesis 369 $post->post_author = $author;
mp-wp_genesis 370 else if ( 'comment' == $context )
mp-wp_genesis 371 $comment->comment_author = $author;
mp-wp_genesis 372 } else if ( 0 === strpos($line, "TITLE:") ) {
mp-wp_genesis 373 $title = trim( substr($line, strlen("TITLE:")) );
mp-wp_genesis 374 if ( '' == $context )
mp-wp_genesis 375 $post->post_title = $title;
mp-wp_genesis 376 else if ( 'ping' == $context )
mp-wp_genesis 377 $ping->title = $title;
mp-wp_genesis 378 } else if ( 0 === strpos($line, "STATUS:") ) {
mp-wp_genesis 379 $status = trim( strtolower( substr($line, strlen("STATUS:")) ) );
mp-wp_genesis 380 if ( empty($status) )
mp-wp_genesis 381 $status = 'publish';
mp-wp_genesis 382 $post->post_status = $status;
mp-wp_genesis 383 } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) {
mp-wp_genesis 384 $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) );
mp-wp_genesis 385 if ( $allow == 1 )
mp-wp_genesis 386 $post->comment_status = 'open';
mp-wp_genesis 387 else
mp-wp_genesis 388 $post->comment_status = 'closed';
mp-wp_genesis 389 } else if ( 0 === strpos($line, "ALLOW PINGS:") ) {
mp-wp_genesis 390 $allow = trim( substr($line, strlen("ALLOW PINGS:")) );
mp-wp_genesis 391 if ( $allow == 1 )
mp-wp_genesis 392 $post->ping_status = 'open';
mp-wp_genesis 393 else
mp-wp_genesis 394 $post->ping_status = 'closed';
mp-wp_genesis 395 } else if ( 0 === strpos($line, "CATEGORY:") ) {
mp-wp_genesis 396 $category = trim( substr($line, strlen("CATEGORY:")) );
mp-wp_genesis 397 if ( '' != $category )
mp-wp_genesis 398 $post->categories[] = $category;
mp-wp_genesis 399 } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) {
mp-wp_genesis 400 $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) );
mp-wp_genesis 401 if ( '' != $category )
mp-wp_genesis 402 $post->categories[] = $category;
mp-wp_genesis 403 } else if ( 0 === strpos($line, "DATE:") ) {
mp-wp_genesis 404 $date = trim( substr($line, strlen("DATE:")) );
mp-wp_genesis 405 $date = strtotime($date);
mp-wp_genesis 406 $date = date('Y-m-d H:i:s', $date);
mp-wp_genesis 407 $date_gmt = get_gmt_from_date($date);
mp-wp_genesis 408 if ( '' == $context ) {
mp-wp_genesis 409 $post->post_modified = $date;
mp-wp_genesis 410 $post->post_modified_gmt = $date_gmt;
mp-wp_genesis 411 $post->post_date = $date;
mp-wp_genesis 412 $post->post_date_gmt = $date_gmt;
mp-wp_genesis 413 } else if ( 'comment' == $context ) {
mp-wp_genesis 414 $comment->comment_date = $date;
mp-wp_genesis 415 } else if ( 'ping' == $context ) {
mp-wp_genesis 416 $ping->comment_date = $date;
mp-wp_genesis 417 }
mp-wp_genesis 418 } else if ( 0 === strpos($line, "EMAIL:") ) {
mp-wp_genesis 419 $email = trim( substr($line, strlen("EMAIL:")) );
mp-wp_genesis 420 if ( 'comment' == $context )
mp-wp_genesis 421 $comment->comment_author_email = $email;
mp-wp_genesis 422 else
mp-wp_genesis 423 $ping->comment_author_email = '';
mp-wp_genesis 424 } else if ( 0 === strpos($line, "IP:") ) {
mp-wp_genesis 425 $ip = trim( substr($line, strlen("IP:")) );
mp-wp_genesis 426 if ( 'comment' == $context )
mp-wp_genesis 427 $comment->comment_author_IP = $ip;
mp-wp_genesis 428 else
mp-wp_genesis 429 $ping->comment_author_IP = $ip;
mp-wp_genesis 430 } else if ( 0 === strpos($line, "URL:") ) {
mp-wp_genesis 431 $url = trim( substr($line, strlen("URL:")) );
mp-wp_genesis 432 if ( 'comment' == $context )
mp-wp_genesis 433 $comment->comment_author_url = $url;
mp-wp_genesis 434 else
mp-wp_genesis 435 $ping->comment_author_url = $url;
mp-wp_genesis 436 } else if ( 0 === strpos($line, "BLOG NAME:") ) {
mp-wp_genesis 437 $blog = trim( substr($line, strlen("BLOG NAME:")) );
mp-wp_genesis 438 $ping->comment_author = $blog;
mp-wp_genesis 439 } else {
mp-wp_genesis 440 // Processing multi-line field, check context.
mp-wp_genesis 441
mp-wp_genesis 442 $line .= "\n";
mp-wp_genesis 443 if ( 'body' == $context ) {
mp-wp_genesis 444 $post->post_content .= $line;
mp-wp_genesis 445 } else if ( 'extended' == $context ) {
mp-wp_genesis 446 $post->extended .= $line;
mp-wp_genesis 447 } else if ( 'excerpt' == $context ) {
mp-wp_genesis 448 $post->post_excerpt .= $line;
mp-wp_genesis 449 } else if ( 'keywords' == $context ) {
mp-wp_genesis 450 $post->post_keywords .= $line;
mp-wp_genesis 451 } else if ( 'comment' == $context ) {
mp-wp_genesis 452 $comment->comment_content .= $line;
mp-wp_genesis 453 } else if ( 'ping' == $context ) {
mp-wp_genesis 454 $ping->comment_content .= $line;
mp-wp_genesis 455 }
mp-wp_genesis 456 }
mp-wp_genesis 457 }
mp-wp_genesis 458
mp-wp_genesis 459 $this->fclose($handle);
mp-wp_genesis 460
mp-wp_genesis 461 echo '</ol>';
mp-wp_genesis 462
mp-wp_genesis 463 wp_import_cleanup($this->id);
mp-wp_genesis 464 do_action('import_done', 'mt');
mp-wp_genesis 465
mp-wp_genesis 466 echo '<h3>'.sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')).'</h3></div>';
mp-wp_genesis 467 }
mp-wp_genesis 468
mp-wp_genesis 469 function import() {
mp-wp_genesis 470 $this->id = (int) $_GET['id'];
mp-wp_genesis 471 if ( $this->id == 0 )
mp-wp_genesis 472 $this->file = WP_CONTENT_DIR . '/mt-export.txt';
mp-wp_genesis 473 else
mp-wp_genesis 474 $this->file = get_attached_file($this->id);
mp-wp_genesis 475 $this->get_authors_from_post();
mp-wp_genesis 476 $result = $this->process_posts();
mp-wp_genesis 477 if ( is_wp_error( $result ) )
mp-wp_genesis 478 return $result;
mp-wp_genesis 479 }
mp-wp_genesis 480
mp-wp_genesis 481 function dispatch() {
mp-wp_genesis 482 if (empty ($_GET['step']))
mp-wp_genesis 483 $step = 0;
mp-wp_genesis 484 else
mp-wp_genesis 485 $step = (int) $_GET['step'];
mp-wp_genesis 486
mp-wp_genesis 487 switch ($step) {
mp-wp_genesis 488 case 0 :
mp-wp_genesis 489 $this->greet();
mp-wp_genesis 490 break;
mp-wp_genesis 491 case 1 :
mp-wp_genesis 492 check_admin_referer('import-upload');
mp-wp_genesis 493 $this->select_authors();
mp-wp_genesis 494 break;
mp-wp_genesis 495 case 2:
mp-wp_genesis 496 check_admin_referer('import-mt');
mp-wp_genesis 497 $result = $this->import();
mp-wp_genesis 498 if ( is_wp_error( $result ) )
mp-wp_genesis 499 echo $result->get_error_message();
mp-wp_genesis 500 break;
mp-wp_genesis 501 }
mp-wp_genesis 502 }
mp-wp_genesis 503
mp-wp_genesis 504 function MT_Import() {
mp-wp_genesis 505 // Nothing.
mp-wp_genesis 506 }
mp-wp_genesis 507 }
mp-wp_genesis 508
mp-wp_genesis 509 $mt_import = new MT_Import();
mp-wp_genesis 510
mp-wp_genesis 511 register_importer('mt', __('Movable Type and TypePad'), __('Import posts and comments from a Movable Type or Typepad blog.'), array ($mt_import, 'dispatch'));
mp-wp_genesis 512 ?>