Make WordPress Core


Ignore:
Timestamp:
10/26/2008 05:08:40 PM (17 years ago)
Author:
ryan
Message:

Allow gzipped files for MT/TypePad import. Props mtdewvirus. fixes #7971

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/mt.php

    r8645 r9358  
    7070    <?php
    7171
    72 
    73     }
     72    }
     73
     74    function has_gzip() {
     75        return is_callable('gzopen');
     76    }
     77
     78    function fopen($filename, $mode='r') {
     79        if ( $this->has_gzip() )
     80            return gzopen($filename, $mode);
     81        return fopen($filename, $mode);
     82    }
     83
     84    function feof($fp) {
     85        if ( $this->has_gzip() )
     86            return gzeof($fp);
     87        return feof($fp);
     88    }
     89
     90    function fgets($fp, $len=8192) {
     91        if ( $this->has_gzip() )
     92            return gzgets($fp, $len);
     93        return fgets($fp, $len);
     94    }
     95
     96    function fclose($fp) {
     97        if ( $this->has_gzip() )
     98            return gzclose($fp);
     99        return fclose($fp);
     100    }
    74101
    75102    //function to check the authorname and do the mapping
     
    104131        $authors = array();
    105132
    106         $handle = fopen($this->file, 'r');
     133        $handle = $this->fopen($this->file, 'r');
    107134        if ( $handle == null )
    108135            return false;
    109136
    110137        $in_comment = false;
    111         while ( $line = fgets($handle) ) {
     138        while ( $line = $this->fgets($handle) ) {
    112139            $line = trim($line);
    113140
     
    132159        }
    133160
    134         fclose($handle);
     161        $this->fclose($handle);
    135162
    136163        return $authors;
     
    287314        global $wpdb;
    288315
    289         $handle = fopen($this->file, 'r');
     316        $handle = $this->fopen($this->file, 'r');
    290317        if ( $handle == null )
    291318            return false;
     
    300327        echo "<div class='wrap'><ol>";
    301328
    302         while ( $line = fgets($handle) ) {
     329        while ( $line = $this->fgets($handle) ) {
    303330            $line = trim($line);
    304331
     
    429456        }
    430457
     458        $this->fclose($handle);
     459
    431460        echo '</ol>';
    432461
Note: See TracChangeset for help on using the changeset viewer.