Ticket #4284: mt-import.001.diff

File mt-import.001.diff, 3.7 KB (added by markjaquith, 5 years ago)

First swing (trunk)

  • import/mt.php

     
    2222                $this->header(); 
    2323?> 
    2424<div class="narrow"> 
    25 <p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, choose a file to upload and click Upload file and import.'); ?></p> 
     25<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> 
    2626<?php wp_import_upload_form( add_query_arg('step', 1) ); ?> 
    27         <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> 
     27<form method="post" action="<?php echo add_query_arg('step', 1); ?>" class="import-upload-form"> 
     28<?php wp_nonce_field('import-upload'); ?> 
     29<p> 
     30        <input type="hidden" name="upload_type" value="ftp" /> 
     31<?php _e('Or use <code>mt-export.txt</code> in your <code>/wp-content/</code> directory'); ?></p> 
     32<p class="submit"> 
     33<input type="submit" value="<?php _e(sprintf('Import %s', 'mt-export.txt &raquo;')); ?>" /> 
     34</p> 
     35</form> 
     36<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> 
    2837</div> 
    2938<?php 
    3039                $this->footer(); 
     
    138147?> 
    139148<div class="wrap"> 
    140149<h2><?php _e('Assign Authors'); ?></h2> 
    141 <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 <code>admin</code>s entries.'); ?></p> 
     150<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> 
    142151<p><?php _e('Below, you can see the names of the authors of the MovableType posts in <i>italics</i>. 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> 
    143152<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p> 
    144153        <?php 
     
    163172        } 
    164173 
    165174        function select_authors() { 
    166                 $file = wp_import_handle_upload(); 
     175                if ( $_POST['upload_type'] === 'ftp' ) { 
     176                        $file['file'] = @file(ABSPATH . '/wp-content/mt-export.txt'); 
     177                        if ( !$file['file'] || !count($file['file']) ) 
     178                                $file['error'] = __('<code>mt-export.txt</code> does not exist</code>'); 
     179                        else 
     180                                $file['file'] = ABSPATH . '/wp-content/mt-export.txt'; 
     181                } else { 
     182                        $file = wp_import_handle_upload(); 
     183                } 
    167184                if ( isset($file['error']) ) { 
    168185                        $this->header(); 
    169186                        echo '<p>'.__('Sorry, there has been an error').'.</p>'; 
     
    400417 
    401418        function import() { 
    402419                $this->id = (int) $_GET['id']; 
    403  
    404                 $this->file = get_attached_file($this->id); 
     420                if ( $this->id == 0 ) 
     421                        $this->file = ABSPATH . '/wp-content/mt-export.txt'; 
     422                else 
     423                        $this->file = get_attached_file($this->id); 
    405424                $this->get_authors_from_post(); 
    406425                $this->get_entries(); 
    407426                $this->process_posts();