Changeset 5802

Show
Ignore:
Timestamp:
07/15/07 17:55:12 (1 year ago)
Author:
ryan
Message:

Don't slurp in entire file. Props tellyworth. see #4421

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/import/wordpress.php

    r5718 r5802  
    8686    function get_entries() { 
    8787        set_magic_quotes_runtime(0); 
    88         $importdata = array_map('rtrim', file($this->file)); // Read the file into an array 
    8988 
    9089        $this->posts = array(); 
     
    9291        $num = 0; 
    9392        $doing_entry = false; 
    94         foreach ($importdata as $importline) { 
    95             if ( false !== strpos($importline, '<wp:category>') ) { 
    96                 preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); 
    97                 $this->categories[] = $category[1]; 
    98                 continue; 
    99             } 
    100             if ( false !== strpos($importline, '<item>') ) { 
    101                 $this->posts[$num] = ''; 
    102                 $doing_entry = true; 
    103                 continue;    
    104             } 
    105             if ( false !== strpos($importline, '</item>') ) { 
    106                 $num++; 
    107                 $doing_entry = false; 
    108                 continue;    
    109             } 
    110             if ( $doing_entry ) { 
    111                 $this->posts[$num] .= $importline . "\n"; 
    112             } 
    113         } 
    114  
    115         foreach ($this->posts as $post) { 
    116             $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); 
    117             if ($post_ID) { 
    118                 $this->posts_processed[$post_ID][0] = &$post; 
    119                 $this->posts_processed[$post_ID][1] = 0; 
    120             } 
     93 
     94        $fp = fopen($this->file, 'r'); 
     95        if ($fp) { 
     96            while ( !feof($fp) ) { 
     97                $importline = rtrim(fgets($fp)); 
     98 
     99                if ( false !== strpos($importline, '<wp:category>') ) { 
     100                    preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); 
     101                    $this->categories[] = $category[1]; 
     102                    continue; 
     103                } 
     104                if ( false !== strpos($importline, '<item>') ) { 
     105                    $this->posts[$num] = ''; 
     106                    $doing_entry = true; 
     107                    continue;    
     108                } 
     109                if ( false !== strpos($importline, '</item>') ) { 
     110                    $num++; 
     111                    $doing_entry = false; 
     112                    continue;    
     113                } 
     114                if ( $doing_entry ) { 
     115                    $this->posts[$num] .= $importline . "\n"; 
     116                } 
     117            } 
     118 
     119            foreach ($this->posts as $post) { 
     120                $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); 
     121                if ($post_ID) { 
     122                    $this->posts_processed[$post_ID][0] = &$post; 
     123                    $this->posts_processed[$post_ID][1] = 0; 
     124                } 
     125            } 
     126 
     127            fclose($fp); 
    121128        } 
    122129    }