WordPress.org

Plugin Directory

Changeset 525655


Ignore:
Timestamp:
03/31/12 19:38:47 (2 years ago)
Author:
dllh
Message:
  • Make tag handling deal better with different data structures that can come back from theh API.
  • Add the ability to import drafts.
  • If a link category already exists, save the id mapping and move on to import the links rather than failing silently.
File:
1 edited

Legend:

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

    r525651 r525655  
    1313// TODO: Add page and link counts to bottom of import screen. 
    1414// TODO: Figure out Posterous's weird shortcode/hashing thing for inserting images into pages and body_html (e.g. [[posterous-content:jhsmtHnEjaoooaxfmmbm]]) 
     15// Do something with private posts. 
    1516 
    1617if ( !defined('WP_LOAD_IMPORTERS') ) 
     
    111112        $this->do_posts( 'posts' ); 
    112113        $this->do_posts( 'pages' ); 
     114        $this->do_posts( 'posts/drafts' ); 
    113115        $this->process_attachments(); 
    114116        $this->process_links(); 
     
    233235                    $post['post_content'] = (string) $entry->body; 
    234236                    $post['post_date'] = gmdate( 'Y-m-d H:i:s' ); 
     237                    break; 
     238                case 'posts/drafts': 
     239                    $post['post_type'] = 'post'; 
     240                    $post['post_status'] = 'draft'; 
     241                    $post['post_content'] = (string) $entry->body_full; 
     242                    $post['post_date'] = gmdate( "Y-m-d H:i:s", strtotime( (string) $entry->display_date ) ); 
    235243                    break; 
    236244                default: 
     
    366374        if ( isset( $entry->tags ) ) { 
    367375            foreach ( $entry->tags as $tag ) { 
    368                 $tags[] = (string) $tag; 
     376                if ( is_object( $tag ) ) 
     377                    $tags[] = (string) $tag->name; 
     378                else 
     379                    $tags[] = (string) $tag; 
    369380            } 
    370381        } 
     
    10581069         
    10591070                $body = $data['body']; 
    1060                 $links = json_decode( $body ); 
    1061                  
     1071                $links = json_decode( $body );           
    10621072                foreach ( $links as $link ) { 
    10631073                    $this->add_link( $link ); 
     
    10681078 
    10691079    function add_link_category( $category ) { 
     1080        // Check to see if we already have this term and just set the mapping and return if so. 
     1081        $term = term_exists( $category->title, 'link_category' ); 
     1082        if ( $term ) { 
     1083            if ( is_array( $term ) ) 
     1084                $this->category_map[$category->id] = $term['term_id']; 
     1085            else     
     1086                $this->category_map[$category->id] = $term; 
     1087            return true; 
     1088        } 
     1089             
    10701090        $cat = wp_insert_term( $category->title, 'link_category' ) ; 
    10711091        if ( is_wp_error( $cat ) ) { 
    1072             echo "Error: Could not insert category '$category'\n"; 
     1092            echo "Error: Could not insert category '$category->title'\n"; 
    10731093            return false; 
    10741094        } 
Note: See TracChangeset for help on using the changeset viewer.