From 2ef93d9391ccef5d4232c592bd234ad74c8a02c8 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 26 Oct 2008 17:08:40 +0000 Subject: [PATCH] Allow gzipped files for MT/TypePad import. Props mtdewvirus. fixes #7971 git-svn-id: http://svn.automattic.com/wordpress/trunk@9358 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/import/mt.php | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php index 23211868bd..bb32b3afdc 100644 --- a/wp-admin/import/mt.php +++ b/wp-admin/import/mt.php @@ -69,9 +69,36 @@ class MT_Import { 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; @@ -103,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 ) @@ -131,7 +158,7 @@ class MT_Import { array_push($authors, "$next"); } - fclose($handle); + $this->fclose($handle); return $authors; } @@ -286,7 +313,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; @@ -299,7 +326,7 @@ class MT_Import { echo "
    "; - while ( $line = fgets($handle) ) { + while ( $line = $this->fgets($handle) ) { $line = trim($line); if ( '-----' == $line ) { @@ -428,6 +455,8 @@ class MT_Import { } } + $this->fclose($handle); + echo '
'; wp_import_cleanup($this->id);