Plugin Directory

Changeset 684622


Ignore:
Timestamp:
03/20/2013 05:12:06 AM (13 years ago)
Author:
ReadyMadeWeb
Message:

Update takes into account new edge cases found with some TypePad templates.

Location:
readymade-wordpress-importer-061/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • readymade-wordpress-importer-061/trunk/readme.txt

    r610536 r684622  
    11=== Plugin Name ===
    22Contributors: ReadyMadeWeb
    3 Donate link: 
     3Donate link:
    44Tags: importer, wordpress, typepad, movabletype, attachments, import, uploads, transfer
    55Requires at least: 3.0
    66Tested up to: 3.4
    7 Stable tag: 0.6.4
     7Stable tag: 0.6.5
    88
    99Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
     
    3333== Changelog ==
    3434
     35= 0.6.5 =
     36* Better handling for file names with url-unfriendly characters
     37
    3538= 0.6.4 =
    36 * Usage of ssl when doing global host name resolution (when finding where to fetch and attachment from) 
     39* Usage of ssl when doing global host name resolution (when finding where to fetch and attachment from)
    3740* Bug fix for issue when URLs wouldn't be rewritten for attachments without an extension
    3841
  • readymade-wordpress-importer-061/trunk/wordpress-importer.php

    r610533 r684622  
    66Author: wordpressdotorg, snyderp@gmail.com
    77Author URI: http://readymadeweb.com
    8 Version: 0.6.4
     8Version: 0.6.5
    99Text Domain: wordpress-importer
    1010License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
     
    103103     */
    104104    function import( $file ) {
    105         set_time_limit(600);
    106         ini_set('max_input_time', 600);
    107105        add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
    108106        add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
     
    123121        $this->backfill_attachment_urls();
    124122        $this->remap_featured_images();
    125 
    126123        $this->import_end();
    127124    }
     
    525522     */
    526523    function process_posts() {
     524
    527525        foreach ( $this->posts as $post ) {
     526
    528527            if ( ! post_type_exists( $post['post_type'] ) ) {
    529528                printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ),
     
    598597
    599598                    $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
     599
    600600                } else {
     601
    601602                    $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
     603
    602604                }
    603605
    604606                if ( is_wp_error( $post_id ) ) {
    605                     printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ),
    606                         $post_type_object->labels->singular_name, esc_html($post['post_title']) );
    607                     if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
     607                    if ( $postdata['post_type'] === 'attachment' ) {
     608                        printf( __( 'Failed to import %s “%s” (%s)', 'wordpress-importer' ),
     609                            $post_type_object->labels->singular_name, esc_html($post['post_title']),
     610                            ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']);
     611                    } else {
     612                        printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ),
     613                            $post_type_object->labels->singular_name, esc_html($post['post_title']) );
     614                    }
     615                    if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
    608616                        echo ': ' . $post_id->get_error_message();
     617                    }
    609618                    echo '<br />';
    610619                    continue;
     
    877886        // extension information attached.  We can get around this limitation
    878887        // by grabbing information about the file from the webserver
    879         $file_type = wp_check_filetype($file_name);
     888        $file_type = wp_check_filetype( $file_name );
    880889
    881890        // If there is a situation where we're adding a file extension
     
    894903        }
    895904
    896         // get placeholder file in the upload dir with a unique, sanitized filename
    897         $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
     905        // First check and see if the file already exists on date, in which
     906        // case we'll just use the version on disk instead of downloading
     907        // again.
     908        $upload_dir = wp_upload_dir( $post['upload_date'] );
     909        $possible_existing_file = $upload_dir['path'] . '/' . $file_name;
     910        if ( is_file( $possible_existing_file ) && filesize( $possible_existing_file ) > 0 ) {
     911
     912            $upload = array(
     913                'file' => $possible_existing_file,
     914                'url' => $upload_dir['url'] . '/' . $file_name,
     915                'error' => false,
     916            );
     917        }
     918        else {
     919
     920            // get placeholder file in the upload dir with a unique, sanitized filename
     921            $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
     922        }
     923
    898924        if ( $upload['error'] )
    899925            return new WP_Error( 'upload_dir_error', $upload['error'] );
     
    11051131     */
    11061132    function max_attachment_size() {
    1107         return apply_filters( 'import_attachment_size_limit', 0 );
     1133        return apply_filters( 'import_attachment_size_limit', 10000000 );
    11081134    }
    11091135
     
    11661192        curl_setopt( $curl, CURLOPT_HEADER, true );
    11671193        curl_setopt( $curl, CURLOPT_NOBODY, true );
     1194        curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
     1195        curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
    11681196        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
    11691197        curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 5);
     
    12111239    function fetch_attachment($url, $file_path) {
    12121240
     1241        // If the file already exists locally, we don't need to re-download
     1242        // it.  We can instead just read the relevant info off the disk
     1243        // and save some network time
     1244        if ( file_exists( $file_path ) && filesize( $file_path ) > 100) {
     1245
     1246            return array(
     1247                'response' => '200',
     1248                'content-length' => filesize( $file_path ),
     1249            );
     1250        }
     1251
    12131252        $url_parts = parse_url( $url );
    12141253        $world_ip = $this->global_ip_for_host( $url_parts['host'] );
     
    12271266            $headers = array('Host: ' . $url_parts['host']);
    12281267
    1229             $url = $url_parts['scheme'] . "://" . $world_ip . $url_parts['path'];
     1268            $url = $url_parts['scheme'] . "://" . $world_ip . str_replace(' ', '%20', $url_parts['path']);
    12301269
    12311270            $curl = curl_init();
     
    12331272            curl_setopt( $curl, CURLOPT_URL, $url );
    12341273            curl_setopt( $curl, CURLOPT_HEADER, false );
     1274            curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
     1275            curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
    12351276            curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
    12361277
Note: See TracChangeset for help on using the changeset viewer.