WordPress.org

Plugin Directory

Changeset 629162


Ignore:
Timestamp:
11/23/12 21:47:48 (17 months ago)
Author:
dllh
Message:

Tumblr Importer: Restore OEmbed functionality that was lost when porting to the new API. There's probably still room for improvement here (e.g. for vimeo embeds).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tumblr-importer/branches/newapi/tumblr-importer.php

    r628493 r629162  
    412412                do_action( 'tumblr_importing_post', $post ); 
    413413                $id = wp_insert_post( $post ); 
    414                  
     414 
    415415                if ( !is_wp_error( $id ) ) { 
    416416                    $post['ID'] = $id; // Allows for the media importing to wp_update_post() 
     
    839839                    $post['format'] = 'video'; 
    840840                    $post['post_content'] = ''; 
    841                     if ( isset( $tpost->video_url ) ) { 
    842                         $post['media']['video'] = $tpost->video_url; 
    843                     } else if ( isset( $tpost->player ) ) { 
    844                         $player = $tpost->player[ count( $tpost->player ) - 1 ]->embed_code; 
    845                         $player = preg_replace( '|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $player ); 
    846                         $post['post_content']  .= $player; 
     841 
     842                    $video = array_shift( $tpost->player ); 
     843                 
     844                    if ( false !== strpos( (string) $video->embed_code, 'embed' ) ) { 
     845                        if ( preg_match_all('/<embed (.+?)>/', (string) $video->embed_code, $matches) ) { 
     846                            foreach ($matches[1] as $match) { 
     847                                foreach ( wp_kses_hair( $match, array( 'http' ) ) as $attr ) 
     848                                    $embed[ $attr['name'] ] = $attr['value']; 
     849                            } 
     850 
     851                            // special case for weird youtube vids 
     852                            $embed['src'] = preg_replace( '|http://www.youtube.com/v/([a-zA-Z0-9_]+).*|i', 'http://www.youtube.com/watch?v=$1', $embed['src'] ); 
     853 
     854                            // TODO find other special cases, since tumblr is full of them 
     855                            $post['post_content'] = $embed['src']; 
     856                        } 
     857 
     858                        // Sometimes, video-source contains iframe markup. 
     859                        if ( preg_match( '/<iframe/', $video->embed_code ) ) { 
     860                            $embed['src'] = preg_replace( '|<iframe.*src="http://www.youtube.com/embed/([a-zA-Z0-9_\-]+)\??.*".*</iframe>|', 'http://www.youtube.com/watch?v=$1', $video->embed_code ); 
     861                            $post['post_content'] = $embed['src']; 
     862                        } 
     863                    } else { 
     864                        // @todo: See if the video source is going to be oEmbed'able before adding the flash player 
     865                        $post['post_content'] .= $video->embed_code; 
    847866                    } 
     867     
    848868                    $post['post_content'] .= "\n" . (string) $tpost->caption; 
    849869                    break; 
Note: See TracChangeset for help on using the changeset viewer.