WordPress.org

Plugin Directory

Changeset 625814


Ignore:
Timestamp:
11/15/12 19:52:37 (18 months ago)
Author:
dllh
Message:

Posterous Importer: Several tweaks pertinent to attachment backfilling.

  • Add a filter that can be used to skip the backfill if desired (useful on wordpress.com).
  • Replace a stray manual setting of $this->url_remap with a call to the relevant action.
  • Prevent a notice when $media isn't an array in the media extraction function.
  • Whitespace tweaks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • posterous-importer/branches/v2api/posterous.php

    r625364 r625814  
    636636     */ 
    637637    function backfill_attachment_urls( $post = false ) { 
     638        if ( false === apply_filters( 'posterous_do_backfill', true ) ) 
     639            return; 
     640 
    638641        if ( false === $post ) 
    639642            return; 
     
    689692         */ 
    690693        $head = wp_remote_request( $url, array('method' => 'HEAD') ); 
    691                 if ( wp_remote_retrieve_header( $head, 'location' ) ) { 
     694        if ( wp_remote_retrieve_header( $head, 'location' ) ) { 
    692695            $original_url = $url; 
    693                         $url = wp_remote_retrieve_header( $head, 'location' ); 
     696            $url = wp_remote_retrieve_header( $head, 'location' ); 
    694697            // Fix plus signs too so that they don't get turned into spaces. 
    695698            $url = str_replace( '+', '%2B', $url ); 
     
    706709 
    707710        // keep track of the old and new urls so we can substitute them later 
    708         $this->url_remap[$url] = $upload['url']; 
     711        do_action( 'posterous_store_url_remap', $post->ID, $url, $upload['url'] ); 
     712        do_action( 'posterous_store_url_remap', $post->ID, $original_url, $upload['url'] ); 
    709713        // if the remote url is redirected somewhere else, keep track of the destination too 
    710714        if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] != $url ) 
    711             $this->url_remap[$headers['x-final-location']] = $upload['url']; 
     715            do_action( 'posterous_store_url_remap', $post->ID, $headers['x-final-location'], $upload['url'] ); 
    712716 
    713717        return apply_filters( 'wp_handle_upload', $upload ); 
     
    722726    function extract_post_media( $media, $post ) { 
    723727        $attachments = array(); 
    724         foreach ( $media as $file ) { 
    725             if ( 'image' == $file->type ) { 
    726                 $obj = new stdClass(); 
    727                 $obj->url = $file->url; 
    728                 $obj->thumbs = array(); 
    729                 foreach ( $file->resized as $resized ) { 
    730                     $obj->thumbs[] = $resized; 
     728        if ( is_array( $media ) ) { 
     729            foreach ( $media as $file ) { 
     730                if ( 'image' == $file->type ) { 
     731                    $obj = new stdClass(); 
     732                    $obj->url = $file->url; 
     733                    $obj->thumbs = array(); 
     734                    foreach ( $file->resized as $resized ) { 
     735                        $obj->thumbs[] = $resized; 
     736                    } 
     737                    $attachments[] = $obj; 
     738                } else { 
     739                    $obj = new stdClass(); 
     740                    $obj->url = $file->url; 
     741                    $attachments[] = $obj; 
    731742                } 
    732                 $attachments[] = $obj; 
    733             } else { 
    734                 $obj = new stdClass(); 
    735                 $obj->url = $file->url; 
    736                 $attachments[] = $obj; 
    737             } 
    738              
    739         } 
     743            } 
     744        } 
     745 
    740746        preg_match_all( '!href=(\'|")(http:\/\/[a-zA-Z0-9\-+%\&\?#\/\.]+\/files\.posterous\.com\/[a-zA-Z0-9\-+%_&\?#\/\.]+\.(doc|xls|pdf|docx))(\'|")!i', $post->post_content, $matches ); 
    741747        foreach ( $matches[2] as $file ) { 
Note: See TracChangeset for help on using the changeset viewer.