WordPress.org

Plugin Directory

Changeset 525524


Ignore:
Timestamp:
03/31/12 03:39:30 (2 years ago)
Author:
dllh
Message:
  • Remove some commented-out cruft.
  • Add the ability to fetch pages.
  • Make sure we have a media array before we try to loop over it.
File:
1 edited

Legend:

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

    r525517 r525524  
    1111 
    1212// TODO: Actually honor the retry-after headers instead of using an arbitrary wait time. 
     13// TODO: Add page count to bottom of import screen. 
     14// TODO: Figure out Posterous's weird shortcode/hashing thing for inserting images into pages and body_html (e.g. [[posterous-content:jhsmtHnEjaoooaxfmmbm]]) 
    1315 
    1416if ( !defined('WP_LOAD_IMPORTERS') ) 
     
    106108        $this->comments = $this->get_imported_comments(); 
    107109        $this->attachments = $this->get_imported_attachments( 'posterous', $this->bid ); 
    108         $this->do_posts(); 
     110        $this->do_posts( 'posts' ); 
     111        $this->do_posts( 'pages' ); 
    109112        $this->process_attachments(); 
    110113        $this->cleanup(); 
     
    148151     * @return void 
    149152     */ 
    150     function do_posts() { 
     153    function do_posts( $type='posts' ) {         
    151154        $page = 1; 
     155        $this->have_post = true; 
    152156        do { 
    153             $url = 'http://posterous.com/api/2/sites/' . $this->site_id . '/posts/'; 
     157            $url = 'http://posterous.com/api/2/sites/' . $this->site_id . '/' . $type . '/'; 
    154158            $url = add_query_arg( 'api_token', $this->api_token, $url ); 
    155159            $url = add_query_arg( 'num_posts', 10, $url ); 
    156160            $url = add_query_arg( 'page', $page, $url ); 
    157             $this->process_posts( $url ); 
     161            $this->process_posts( $url, $type ); 
    158162            $page++; 
    159163            // Sleep after fetching sites because Posterous doesn't like if you do more than one request in a second. 
     
    178182     * @return void 
    179183     */ 
    180     function process_posts( $url ) { 
     184    function process_posts( $url, $type ) { 
    181185        $this->last_api_call_timestamp = time(); 
    182186        $data = $this->get_page( $url, $this->username, $this->password ); 
     
    220224 
    221225            $post = array(); 
    222             $post['post_title'] = (string) $entry->title; 
    223             $post['post_date'] = gmdate( "Y-m-d H:i:s", strtotime( (string) $entry->display_date ) ); 
    224             $post['post_content'] = (string) $entry->body_full; 
     226            $post['post_title'] = (string) $entry->title;                        
    225227            $post['post_status'] = 'publish'; 
     228            switch ( $type ) { 
     229                case 'pages': 
     230                    $post['post_type'] = 'page'; 
     231                    $post['post_content'] = (string) $entry->body; 
     232                    $post['post_date'] = gmdate( 'Y-m-d H:i:s' ); 
     233                    break; 
     234                default: 
     235                    $post['post_type'] = 'post'; 
     236                    $post['post_content'] = (string) $entry->body_full; 
     237                    $post['post_date'] = gmdate( "Y-m-d H:i:s", strtotime( (string) $entry->display_date ) ); 
     238            } 
     239 
    226240            if ( 'true' == (string) $entry->is_private ) 
    227241                $post['post_status'] = 'private'; 
     
    283297     */ 
    284298    function process_comments( $post_id, $entry ) { 
    285 /* 
    286         do_action( 'posterous_api_sleep' ); 
    287         $url = 'http://posterous.com/api/2/sites/' . $this->site_id . '/posts/' . $posterous_post_id . '/comments/'; 
    288         $url = add_query_arg( 'api_token', $this->api_token, $url ); 
    289  
    290         $this->last_api_call_timestamp = time(); 
    291         $data = $this->get_page( $url, $this->username, $this->password ); 
    292         if ( is_wp_error( $data ) ) { 
    293             echo "Error:\n" . $data->get_error_message() . "\n"; 
    294             return; 
    295         } 
    296  
    297         $code = (int) $data['response']['code']; 
    298         if ( 200 !== $code ) { 
    299             printf( "<em>%s</em><br />\n", __( 'Got HTTP code' ) . ' ' . $code . ' ' . __( 'from' ) . ' ' . $url ); 
    300             exit(); 
    301         } 
    302  
    303         $comments = json_decode( $data['body'] ); 
    304 */ 
    305299        foreach ( $entry->comments as $comment ) { 
    306300            $author = (string) $comment->user->display_name; 
     
    614608        } 
    615609        $attachments['single'] = array_unique( $attachments['single'] ); 
    616         foreach ( $media as $m ) { 
    617             $attachments['fullsize'][] = $m->url; 
    618         } 
    619          
     610        if ( is_array( $media ) ) { 
     611            foreach ( $media as $m ) { 
     612                $attachments['fullsize'][] = $m->url; 
     613            } 
     614        }        
    620615        unset( $post_content, $matches ); 
    621616        return $attachments; 
Note: See TracChangeset for help on using the changeset viewer.