/**
  * Create new posts based on import information
  */
 function process_posts()
 {
     $feed = $this->import_data;
     foreach ($feed->get_items() as $item) {
         // check that it is actually a post first
         // <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#post'/>
         $is_post = false;
         $cats = $item->get_categories();
         foreach ($cats as $cat) {
             if ($cat == 'http://schemas.google.com/blogger/2008/kind#post') {
                 $is_post = true;
                 break;
             }
         }
         // only import posts for now
         if (!$is_post) {
             continue;
         }
         $blogentry = new BloggerEntry();
         $blogentry->blogurl = $this->host;
         $blogentry->id = $item->get_id();
         $blogentry->published = $item->get_published();
         $blogentry->updated = $item->get_updated();
         $blogentry->isDraft = $item->get_draft_status();
         $blogentry->title = $item->get_title();
         $blogentry->content = $item->get_content();
         $blogentry->geotags = $item->get_geotags();
         // map the post author
         $blogentry->bloggerauthor = sanitize_user($item->get_author()->get_name(), true);
         if (isset($this->author_mapping[$blogentry->bloggerauthor])) {
             $blogentry->author = $this->author_mapping[$blogentry->bloggerauthor];
         } else {
             $blogentry->author = (int) get_current_user_id();
         }
         $blogentry->links = $item->get_links(array('replies', 'edit', 'self', 'alternate'));
         $blogentry->parselinks();
         foreach ($cats as $cat) {
             if (false === strpos($cat, 'http://schemas.google.com')) {
                 $blogentry->categories[] = $cat;
             }
         }
         // Checks for duplicates
         $post_id = $blogentry->post_exists();
         if ($post_id != 0) {
             $this->posts_skipped++;
         } else {
             //Unique new post so import it
             $post_id = $blogentry->import();
             $this->posts_done++;
         }
     }
 }
        function import_posts($connector)
        {
            //Simpler counting for posts as we load them forwards
            if (isset($this->posts_start_index))
                $start_index = (int)$this->posts_start_index;
            else
                $start_index = 1;

            if ($this->total_posts > $start_index)
            {
                // Grab all the posts
                $this->mode = 'posts';
                do
                {
                    $index = $struct = $entries = array();

                    $url = $this->posts_url;

                    //Thought, how do we decouple this method from the source?
                    //Perhaps the "get data function" can somehow be passed through as a parameter to this.
                    //This decoupling would then allow an easier re-code for say when the blogger data arrives as a file not as a URL
                    $response = $connector->oauth_get($url, array('max-results' => Blogger_Import::MAX_RESULTS, 'start-index' => $start_index));

                    if ($response == false)
                        break;

                    // parse the feed
                    $feed = new SimplePie();

                    //set_xxxx methods depreciated (and not working?) replaced with get_registry as per docs
                    $reg = $feed->get_registry();

                    $reg->register('Sanitize', 'Blogger_Importer_Sanitize');
                    $feed->sanitize = $reg->create('Sanitize'); //Should not really need to do this but there seems to be an issue with the SimplePie class?
                    $reg->register('Item', 'WP_SimplePie_Blog_Item');

                    $feed->set_raw_data($response);
                    $feed->init();

                    foreach ($feed->get_items() as $item)
                    {
                        $blogentry = new BloggerEntry();

                        $blogentry->blogurl = $this->host;
                        $blogentry->id = $item->get_id();
                        $blogentry->published = $item->get_published();
                        $blogentry->updated = $item->get_updated();
                        $blogentry->isDraft = $item->get_draft_status();
                        $blogentry->title = $item->get_title();
                        $blogentry->content = $item->get_content();
                        $blogentry->author = $item->get_author()->get_name();
                        $blogentry->geotags = $item->get_geotags();

                        $blogentry->links = $item->get_links(array('replies', 'edit', 'self', 'alternate'));
                        $blogentry->parselinks();

                        $blogentry->categories = $item->get_categories();

                        // Checks for duplicates
                        $post_id = $blogentry->post_exists();

                        if ($post_id != 0)
                        {
                            $this->posts_skipped++;
                        } else
                        {
                            //Unique new post so import it
                            $post_id = $blogentry->import();
                            $this->posts_done++;
                            $this->save_vars();
                        }

                        //Ref: Not importing properly http://core.trac.wordpress.org/ticket/19096
                        //Simplified this section to count what is loaded rather than parsing the results again
                        $start_index++;
                    }

                    $this->posts_start_index = $start_index;

                    $this->save_vars();

                } while ($this->total_posts > $start_index && $this->have_time());
            }
            return ($this->total_posts <= $start_index);
        }