]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/import/mt.php
Wordpress 2.9.1-scripts
[autoinstalls/wordpress.git] / wp-admin / import / mt.php
index d18ef464248a17346347c46a115125a4cd363b7c..548e9ede0facd242b51ede1a173f96eb5dca17d8 100644 (file)
@@ -1,5 +1,18 @@
 <?php
-
+/**
+ * Movable Type and TypePad Importer
+ *
+ * @package WordPress
+ * @subpackage Importer
+ */
+
+/**
+ * Moveable Type and TypePad Importer class
+ *
+ * Upload your exported Movable Type or TypePad entries into WordPress.
+ *
+ * @since unknown
+ */
 class MT_Import {
 
        var $posts = array ();
@@ -11,6 +24,7 @@ class MT_Import {
 
        function header() {
                echo '<div class="wrap">';
+               screen_icon();
                echo '<h2>'.__('Import Movable Type or TypePad').'</h2>';
        }
 
@@ -22,25 +36,27 @@ class MT_Import {
                $this->header();
 ?>
 <div class="narrow">
-<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>
+<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 &#8220;Upload file and import&#8221;, 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>
+
 <?php wp_import_upload_form( add_query_arg('step', 1) ); ?>
-<form method="post" action="<?php echo add_query_arg('step', 1); ?>" class="import-upload-form">
+<form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)); ?>" class="import-upload-form">
+
 <?php wp_nonce_field('import-upload'); ?>
 <p>
        <input type="hidden" name="upload_type" value="ftp" />
 <?php _e('Or use <code>mt-export.txt</code> in your <code>/wp-content/</code> directory'); ?></p>
 <p class="submit">
-<input type="submit" value="<?php echo attribute_escape(__('Import mt-export.txt &raquo;')); ?>" />
+<input type="submit" class="button" value="<?php esc_attr_e('Import mt-export.txt'); ?>" />
 </p>
 </form>
-<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>
+<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&#8217;t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
 </div>
 <?php
                $this->footer();
        }
 
        function users_form($n) {
-               global $wpdb, $testing;
+               global $wpdb;
                $users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID");
 ?><select name="userselect[<?php echo $n; ?>]">
        <option value="#NONE#"><?php _e('- Select -') ?></option>
@@ -54,20 +70,46 @@ class MT_Import {
        </select>
        <?php
 
+       }
+
+       function has_gzip() {
+               return is_callable('gzopen');
+       }
+
+       function fopen($filename, $mode='r') {
+               if ( $this->has_gzip() )
+                       return gzopen($filename, $mode);
+               return fopen($filename, $mode);
+       }
+
+       function feof($fp) {
+               if ( $this->has_gzip() )
+                       return gzeof($fp);
+               return feof($fp);
+       }
 
+       function fgets($fp, $len=8192) {
+               if ( $this->has_gzip() )
+                       return gzgets($fp, $len);
+               return fgets($fp, $len);
        }
 
+       function fclose($fp) {
+               if ( $this->has_gzip() )
+                       return gzclose($fp);
+               return fclose($fp);
+       }
+
        //function to check the authorname and do the mapping
        function checkauthor($author) {
-               global $wpdb;
                //mtnames is an array with the names in the mt import file
-               $pass = 'changeme';
+               $pass = wp_generate_password();
                if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
                        ++ $this->j;
                        $this->mtnames[$this->j] = $author; //add that new mt author name to an array
                        $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
                        if (!$user_id) { //banging my head against the desk now.
-                               if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
+                               if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
                                        $user_id = wp_create_user($author, $pass);
                                        $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank.
                                } else {
@@ -88,12 +130,12 @@ class MT_Import {
                $temp = array();
                $authors = array();
 
-               $handle = fopen($this->file, 'r');
+               $handle = $this->fopen($this->file, 'r');
                if ( $handle == null )
                        return false;
 
                $in_comment = false;
-               while ( $line = fgets($handle) ) {
+               while ( $line = $this->fgets($handle) ) {
                        $line = trim($line);
 
                        if ( 'COMMENT:' == $line )
@@ -116,7 +158,7 @@ class MT_Import {
                                array_push($authors, "$next");
                }
 
-               fclose($handle);
+               $this->fclose($handle);
 
                return $authors;
        }
@@ -150,10 +192,11 @@ class MT_Import {
        function mt_authors_form() {
 ?>
 <div class="wrap">
+<?php screen_icon(); ?>
 <h2><?php _e('Assign Authors'); ?></h2>
-<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>
-<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>
-<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p>
+<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.'); ?></p>
+<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>
+<p><?php _e('If a new user is created by WordPress, a password will be randomly generated. Manually change the user&#8217;s details if necessary.'); ?></p>
        <?php
 
 
@@ -164,12 +207,12 @@ class MT_Import {
                $j = -1;
                foreach ($authors as $author) {
                        ++ $j;
-                       echo '<li>'.__('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 />');
+                       echo '<li><label>'.__('Current author:').' <strong>'.$author.'</strong><br />'.sprintf(__('Create user %1$s or map to existing'), ' <input type="text" value="'. esc_attr($author) .'" name="'.'user[]'.'" maxlength="30"> <br />');
                        $this->users_form($j);
-                       echo '</li>';
+                       echo '</label></li>';
                }
 
-               echo '<input type="submit" value="'.__('Submit').'">'.'<br />';
+               echo '<p class="submit"><input type="submit" class="button" value="'.esc_attr__('Submit').'"></p>'.'<br />';
                echo '</form>';
                echo '</ol></div>';
 
@@ -177,7 +220,7 @@ class MT_Import {
 
        function select_authors() {
                if ( $_POST['upload_type'] === 'ftp' ) {
-                       $file['file'] = ABSPATH . 'wp-content/mt-export.txt';
+                       $file['file'] = WP_CONTENT_DIR . '/mt-export.txt';
                        if ( !file_exists($file['file']) )
                                $file['error'] = __('<code>mt-export.txt</code> does not exist');
                } else {
@@ -205,23 +248,30 @@ class MT_Import {
 
                if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) {
                        echo '<li>';
-                       printf(__('Post <i>%s</i> already exists.'), stripslashes($post->post_title));
+                       printf(__('Post <em>%s</em> already exists.'), stripslashes($post->post_title));
                } else {
                        echo '<li>';
-                       printf(__('Importing post <i>%s</i>...'), stripslashes($post->post_title));
+                       printf(__('Importing post <em>%s</em>...'), stripslashes($post->post_title));
 
                        if ( '' != trim( $post->extended ) )
                                        $post->post_content .= "\n<!--more-->\n$post->extended";
 
                        $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
                        $post_id = wp_insert_post($post);
-                       if ( is_wp_error( $post_id ) ) 
+                       if ( is_wp_error( $post_id ) )
                                return $post_id;
 
                        // Add categories.
                        if ( 0 != count($post->categories) ) {
                                wp_create_categories($post->categories, $post_id);
                        }
+
+                        // Add tags or keywords
+                       if ( 1 < strlen($post->post_keywords) ) {
+                               // Keywords exist.
+                               printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords));
+                               wp_add_post_tags($post_id, $post->post_keywords);
+                       }
                }
 
                $num_comments = 0;
@@ -238,7 +288,7 @@ class MT_Import {
                }
 
                if ( $num_comments )
-                       printf(' '.__('(%s comments)'), $num_comments);
+                       printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);
 
                $num_pings = 0;
                foreach ( $pings as $ping ) {
@@ -255,7 +305,7 @@ class MT_Import {
                }
 
                if ( $num_pings )
-                       printf(' '.__('(%s pings)'), $num_pings);
+                       printf(' '._n('(%s ping)', '(%s pings)', $num_pings), $num_pings);
 
                echo "</li>";
                //ob_flush();flush();
@@ -264,7 +314,7 @@ class MT_Import {
        function process_posts() {
                global $wpdb;
 
-               $handle = fopen($this->file, 'r');
+               $handle = $this->fopen($this->file, 'r');
                if ( $handle == null )
                        return false;
 
@@ -277,7 +327,7 @@ class MT_Import {
 
                echo "<div class='wrap'><ol>";
 
-               while ( $line = fgets($handle) ) {
+               while ( $line = $this->fgets($handle) ) {
                        $line = trim($line);
 
                        if ( '-----' == $line ) {
@@ -294,7 +344,7 @@ class MT_Import {
                                // Finishing a post.
                                $context = '';
                                $result = $this->save_post($post, $comments, $pings);
-                               if ( is_wp_error( $result ) ) 
+                               if ( is_wp_error( $result ) )
                                        return $result;
                                $post = new StdClass;
                                $comment = new StdClass();
@@ -326,7 +376,7 @@ class MT_Import {
                                else if ( 'ping' == $context )
                                        $ping->title = $title;
                        } else if ( 0 === strpos($line, "STATUS:") ) {
-                               $status = trim( substr($line, strlen("STATUS:")) );
+                               $status = trim( strtolower( substr($line, strlen("STATUS:")) ) );
                                if ( empty($status) )
                                        $status = 'publish';
                                $post->post_status = $status;
@@ -389,13 +439,17 @@ class MT_Import {
                        } else {
                                // Processing multi-line field, check context.
 
-                               $line .= "\n";
+                               if( !empty($line) )
+                                       $line .= "\n";
+
                                if ( 'body' == $context ) {
                                        $post->post_content .= $line;
                                } else if ( 'extended' ==  $context ) {
                                        $post->extended .= $line;
                                } else if ( 'excerpt' == $context ) {
                                        $post->post_excerpt .= $line;
+                               } else if ( 'keywords' == $context ) {
+                                       $post->post_keywords .= $line;
                                } else if ( 'comment' == $context ) {
                                        $comment->comment_content .= $line;
                                } else if ( 'ping' == $context ) {
@@ -404,6 +458,8 @@ class MT_Import {
                        }
                }
 
+               $this->fclose($handle);
+
                echo '</ol>';
 
                wp_import_cleanup($this->id);
@@ -415,12 +471,12 @@ class MT_Import {
        function import() {
                $this->id = (int) $_GET['id'];
                if ( $this->id == 0 )
-                       $this->file = ABSPATH . 'wp-content/mt-export.txt';
+                       $this->file = WP_CONTENT_DIR . '/mt-export.txt';
                else
                        $this->file = get_attached_file($this->id);
                $this->get_authors_from_post();
                $result = $this->process_posts();
-               if ( is_wp_error( $result ) ) 
+               if ( is_wp_error( $result ) )
                        return $result;
        }
 
@@ -454,5 +510,5 @@ class MT_Import {
 
 $mt_import = new MT_Import();
 
-register_importer('mt', __('Movable Type and TypePad'), __('Import posts and comments from a Movable Type or Typepad blog'), array ($mt_import, 'dispatch'));
+register_importer('mt', __('Movable Type and TypePad'), __('Import posts and comments from a Movable Type or TypePad blog.'), array ($mt_import, 'dispatch'));
 ?>