Ticket #4472: mt.diff

File mt.diff, 2.5 KB (added by shacker, 4 years ago)

Modifies MT importer to convert keywords to WP tags.

  • mt.php

     
    2323?> 
    2424<div class="narrow"> 
    2525<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> 
     26 
    2627<?php wp_import_upload_form( add_query_arg('step', 1) ); ?> 
    2728<form method="post" action="<?php echo add_query_arg('step', 1); ?>" class="import-upload-form"> 
     29 
    2830<?php wp_nonce_field('import-upload'); ?> 
    2931<p> 
    3032        <input type="hidden" name="upload_type" value="ftp" /> 
     
    196198                $this->mt_authors_form(); 
    197199        } 
    198200 
    199         function save_post(&$post, &$comments, &$pings) { 
     201        function save_post(&$post, &$comments, &$pings, &$keywords) { 
    200202                // Reset the counter 
    201203                set_time_limit(30); 
    202204                $post = get_object_vars($post); 
     
    222224                        if ( 0 != count($post->categories) ) { 
    223225                                wp_create_categories($post->categories, $post_id); 
    224226                        } 
     227                         
     228                 // Add tags or keywords 
     229                        if ( 1 < strlen($post->post_keywords) ) { 
     230                          // Keywords exist.  
     231                        printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords)); 
     232                        wp_add_post_tags($post_id, $post->post_keywords); 
     233                 } 
     234                  
    225235                } 
    226236 
    227237                $num_comments = 0; 
     
    274284                $comments = array(); 
    275285                $ping = new StdClass(); 
    276286                $pings = array(); 
     287                $keyword = new StdClass(); 
     288                $keywords = array(); 
    277289 
     290 
    278291                echo "<div class='wrap'><ol>"; 
    279292 
    280293                while ( $line = fgets($handle) ) { 
     
    293306                        } else if ( '--------' == $line ) { 
    294307                                // Finishing a post. 
    295308                                $context = ''; 
    296                                 $result = $this->save_post($post, $comments, $pings); 
     309                                $result = $this->save_post($post, $comments, $pings, $keywords); 
    297310                                if ( is_wp_error( $result ) )  
    298311                                        return $result; 
    299312                                $post = new StdClass; 
    300313                                $comment = new StdClass(); 
    301314                                $ping = new StdClass(); 
     315                                $keywords = new StdClass();                              
    302316                                $comments = array(); 
    303317                                $pings = array(); 
    304318                        } else if ( 'BODY:' == $line ) { 
     
    396410                                        $post->extended .= $line; 
    397411                                } else if ( 'excerpt' == $context ) { 
    398412                                        $post->post_excerpt .= $line; 
     413                                } else if ( 'keywords' == $context ) { 
     414                                        $post->post_keywords .= $line;                                   
    399415                                } else if ( 'comment' == $context ) { 
    400416                                        $comment->comment_content .= $line; 
    401417                                } else if ( 'ping' == $context ) {