<?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 ();
function header() {
echo '<div class="wrap">';
+ screen_icon();
echo '<h2>'.__('Import Movable Type or TypePad').'</h2>';
}
<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')); ?>" />
+<input type="submit" class="button" value="<?php echo attribute_escape(__('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—for whatever reason—it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
}
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>
</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 = wp_generate_password();
if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
$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 {
$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 )
array_push($authors, "$next");
}
- fclose($handle);
+ $this->fclose($handle);
return $authors;
}
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 <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>
echo '</label></li>';
}
- echo '<input type="submit" value="'.__('Submit').'">'.'<br />';
+ echo '<p class="submit"><input type="submit" class="button" value="'.__('Submit').'"></p>'.'<br />';
echo '</form>';
echo '</ol></div>';
if ( 0 != count($post->categories) ) {
wp_create_categories($post->categories, $post_id);
}
-
+
// Add tags or keywords
if ( 1 < strlen($post->post_keywords) ) {
- // Keywords exist.
+ // Keywords exist.
printf(__('<br />Adding tags <i>%s</i>...'), stripslashes($post->post_keywords));
wp_add_post_tags($post_id, $post->post_keywords);
}
function process_posts() {
global $wpdb;
- $handle = fopen($this->file, 'r');
+ $handle = $this->fopen($this->file, 'r');
if ( $handle == null )
return false;
echo "<div class='wrap'><ol>";
- while ( $line = fgets($handle) ) {
+ while ( $line = $this->fgets($handle) ) {
$line = trim($line);
if ( '-----' == $line ) {
$ping->comment_author = $blog;
} 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 ) {
}
}
+ $this->fclose($handle);
+
echo '</ol>';
wp_import_cleanup($this->id);