WordPress.org

Plugin Directory

Changeset 365761 for wordpress-importer


Ignore:
Timestamp:
03/28/11 11:35:34 (3 years ago)
Author:
duck_
Message:

Remap resized image URLs correctly. Don't need to add_filter for every file fetch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wordpress-importer/trunk/wordpress-importer.php

    r365515 r365761  
    66Author: wordpressdotorg 
    77Author URI: http://wordpress.org/ 
    8 Version: 0.4-alpha3 
     8Version: 0.4-alpha4 
    99Text Domain: wordpress-importer 
    1010License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
     
    1515 
    1616/** Display verbose errors */ 
    17 define( 'IMPORT_DEBUG', false ); 
     17define( 'IMPORT_DEBUG', true ); 
    1818 
    1919// Load Importer API 
     
    104104    function import( $file ) { 
    105105        add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) ); 
     106        add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); 
    106107 
    107108        $this->import_start( $file ); 
     
    823824        wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); 
    824825 
    825         // remap the thumbnail url.  this isn't perfect because we're just guessing the original url. 
    826         if ( preg_match( '@^image/@', $info['type'] ) && $thumb_url = wp_get_attachment_thumb_url( $post_id ) ) { 
     826        // remap resized image URLs, works by stripping the extension and remapping the URL stub. 
     827        if ( preg_match( '!^image/!', $info['type'] ) ) { 
    827828            $parts = pathinfo( $url ); 
    828             $ext = $parts['extension']; 
    829             $name = basename($parts['basename'], ".{$ext}"); 
    830             $this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url; 
     829            $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 
     830 
     831            $parts_new = pathinfo( $upload['url'] ); 
     832            $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); 
     833 
     834            $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new; 
    831835        } 
    832836 
     
    842846     */ 
    843847    function fetch_remote_file( $url, $post ) { 
    844         add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); 
    845  
    846848        // extract the file name and extension from the url 
    847849        $file_name = basename( $url ); 
     
    887889        // keep track of the old and new urls so we can substitute them later 
    888890        $this->url_remap[$url] = $upload['url']; 
    889         $this->url_remap[$post['guid']] = $upload['url']; 
    890         // if the remote url is redirected somewhere else, keep track of the destination too 
     891        $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? 
     892        // keep track of the destination if the remote url is redirected somewhere else 
    891893        if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url ) 
    892894            $this->url_remap[$headers['x-final-location']] = $upload['url']; 
Note: See TracChangeset for help on using the changeset viewer.