WordPress.org

Plugin Directory

Changeset 525517


Ignore:
Timestamp:
03/31/12 03:10:13 (2 years ago)
Author:
dllh
Message:
  • Fix a nested array issue when fetching postmeta.
  • Extract audio and video files from API structures rather than pulling out of the html content.
  • Remove some debug code I had added because the api was sending me stale comment counts.
  • Remove an unused array key.
File:
1 edited

Legend:

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

    r525499 r525517  
    99License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1010*/ 
     11 
     12// TODO: Actually honor the retry-after headers instead of using an arbitrary wait time. 
    1113 
    1214if ( !defined('WP_LOAD_IMPORTERS') ) 
     
    191193        $body = $data['body']; 
    192194        $posts = json_decode( $body ); 
     195 
    193196        if ( !is_array( $posts ) ) { 
    194197            printf( __METHOD__ . ": <em>%s</em><br />\n", __( 'Error loading JSON data.' ) ); 
     
    211214                // process_comments here to check for any new comments or ones that we missed 
    212215                printf( "\t<em>%s</em><br />\n", __( 'Found Comments:' ) . ' ' . $commentscount ); 
    213                 if ( $commentscount >= 0 ) // TODO: Change to just > 
     216                if ( $commentscount > 0 ) 
    214217                    $this->process_comments( $this->permalinks[$permalink], $entry ); 
    215218                continue; 
     
    237240            if ( isset( $entry->media ) ) { 
    238241                $media = array(); 
    239                      
    240                 foreach ( $entry->media as $m ) { 
    241                     if ( in_array( (string) $m->type, array( 'audio_files', 'video' ) ) ) {                      
    242                         $file = new stdClass(); 
    243                         $file->type = (string) $m->type; 
    244                         $file->url = (string) $m->url; 
    245                         $file->filesize = (string) $m->size; 
    246                         $file->thumb = (string) $m->thumb; 
    247                         $media[] = $file; 
    248                     } 
     242                 
     243                foreach ( $entry->media->videos as $video ) {    
     244                    $file = new stdClass(); 
     245                    $file->type = ''; 
     246                    $file->url = (string) $video->url; 
     247                    $file->filesize = (string) $video->size; 
     248                    $file->thumb = (string) $video->thumb; 
     249                    //$file->filesize=''; 
     250                    $media[] = $file; 
    249251                } 
     252 
     253                foreach ( $entry->media->audio_files as $audio_file ) { 
     254                    $file = new stdClass(); 
     255                    $file->type = 'mp3'; 
     256                    $file->url = (string) $audio_file->url; 
     257                    $media[] = $file; 
     258                } 
     259 
    250260                if ( 0 < count( $media ) ) 
    251                     add_post_meta( $post_id, 'posterous_' . $this->bid . '_media', $media, true ); 
     261                    add_post_meta( $post_id, 'posterous_' . $this->bid . '_media', $media, true );                                   
    252262            } 
    253263 
     
    261271 
    262272            printf( "\t<em>%s</em><br />\n", __( 'Found Comments:' ) . ' ' . $commentscount ); 
    263             if ( $commentscount >= 0 ) // TODO: Change to just > 
     273            if ( $commentscount > 0 ) 
    264274                $this->process_comments( $post_id, $entry ); 
    265275        } 
     
    380390            // Get post data 
    381391            $post = get_post( $post_id ); 
    382             $media = get_post_meta( $post_id, 'posterous_' . $this->bid . '_media' ); 
     392            $media = array_pop( get_post_meta( $post_id, 'posterous_' . $this->bid . '_media' ) ); 
    383393 
    384394            printf( "<em>%s</em>", __( 'Checking' ) . " '$post->post_title' " . __( 'for images...' ) ); 
     
    412422        // Add media files from postmeta to the $fullsizes array for fetching. 
    413423        $media_types = array(); 
    414         $media = get_post_meta( $post->ID, 'posterous_' . $this->bid . '_media', true ); 
     424        $media = get_post_meta( $post->ID, 'posterous_' . $this->bid . '_media', true );         
    415425        if ( is_array( $media ) ) { 
    416426            foreach ( $media as $m ) { 
     
    584594        $attachments['fullsize'] = array(); 
    585595        $attachments['single'] = array(); 
    586         $attachments['audiovideo'] = array(); 
    587596 
    588597        // Find all linked images 
     
    605614        } 
    606615        $attachments['single'] = array_unique( $attachments['single'] ); 
    607  
    608         // Find all linked mp3s and videos 
    609         $matches = array(); 
    610         preg_match_all( '!href=(\'|")(http:\/\/[a-zA-Z0-9\-+%\&\?#\/\.]+\/files\.posterous\.com\/[a-zA-Z0-9\-+%_&\?#\/\.]+\.(mp3|m4v|mp4|mov|avi|wmv|3gv|3g2))(\'|")/!i', $post_content, $matches ); 
    611         if ( !empty( $matches[2] ) ) { 
    612             foreach ( $matches[2] as $i => $url ) { 
    613                 $attachments['audiovideo'][$i] = $url; 
    614             } 
     616        foreach ( $media as $m ) { 
     617            $attachments['fullsize'][] = $m->url; 
    615618        } 
    616619         
    617620        unset( $post_content, $matches ); 
    618 print '<pre>' . print_r( $attachments, 1 ) . '</pre>'; 
    619621        return $attachments; 
    620622    } 
Note: See TracChangeset for help on using the changeset viewer.