function get_feed_items() { // go through all the feed urls $items = array(); $feeds = ORM::for_table('feeds')->find_many(); foreach ($feeds as $feed_loc) { $feed = new SimplePie(); $feed->set_feed_url($feed_loc->location); $feed->set_cache_location("mysql://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST . ":3306/" . DB_NAME); $feed->set_item_class('MyItemClass'); $feed->init(); $feed->handle_content_type(); $items = array_merge($items, $feed->get_items()); } return $items; }
<?php include_once 'simplepie.inc'; include_once 'simplepie_youtube.inc'; $feed = new SimplePie(); // Create a new instance of SimplePie $feed->set_feed_url('http://gdata.youtube.com/feeds/api/playlists/957F7A8A7B24D497'); $feed->set_cache_duration(600); //The cache duration $feed->set_item_class('SimplePie_Item_YouTube'); $feed->enable_xml_dump(isset($_GET['xmldump']) ? true : false); $success = $feed->init(); // Initialize SimplePie $feed->handle_content_type(); // Take care of the character encoding ?> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>YouTube + Simple Pie Sample</title> </head> <body> <h1><a href="<?php echo $feed->get_permalink(); ?> "><?php echo $feed->get_title(); ?> </a></h1> <?php foreach ($feed->get_items() as $item) {
function import_blog($blogID) { global $importing_blog; $importing_blog = $blogID; if (isset($_GET['authors'])) { return print $this->get_author_form(); } if (isset($_GET['status'])) { self::ajax_die($this->get_js_status()); } if (isset($_GET['saveauthors'])) { self::ajax_die($this->save_authors()); } //Simpler counting for posts as we load them forwards if (isset($this->blogs[$importing_blog]['posts_start_index'])) { $start_index = (int) $this->blogs[$importing_blog]['posts_start_index']; } else { $start_index = 1; } // This will be positive until we have finished importing posts if ($start_index > 0) { // Grab all the posts $this->blogs[$importing_blog]['mode'] = 'posts'; do { $index = $struct = $entries = array(); $url = $this->blogs[$importing_blog]['posts_url']; $response = $this->oauth_get($url, array('max-results' => MAX_RESULTS, 'start-index' => $start_index)); if ($response == false) { break; } // parse the feed $feed = new SimplePie(); $feed->set_item_class('WP_SimplePie_Blog_Item'); $feed->set_sanitize_class('Blogger_Importer_Sanitize'); $feed->set_raw_data($response); $feed->init(); foreach ($feed->get_items() as $item) { $blogentry = new BloggerEntry(); $blogentry->id = $item->get_id(); $blogentry->published = $item->get_published(); $blogentry->updated = $item->get_updated(); $blogentry->isDraft = $item->get_draft_status($item); $blogentry->title = $item->get_title(); $blogentry->content = $item->get_content(); $blogentry->author = $item->get_author()->get_name(); $blogentry->geotags = $item->get_geotags(); $linktypes = array('replies', 'edit', 'self', 'alternate'); foreach ($linktypes as $type) { $links = $item->get_links($type); if (!is_null($links)) { foreach ($links as $link) { $blogentry->links[] = array('rel' => $type, 'href' => $link); } } } $cats = $item->get_categories(); if (!is_null($cats)) { foreach ($cats as $cat) { $blogentry->categories[] = $cat->term; } } $result = $this->import_post($blogentry); //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->blogs[$importing_blog]['posts_start_index'] = $start_index; $this->save_vars(); } while ($this->blogs[$importing_blog]['total_posts'] > $start_index && $this->have_time()); //have time function will "die" if it's out of time } if (isset($this->blogs[$importing_blog]['comments_start_index'])) { $start_index = (int) $this->blogs[$importing_blog]['comments_start_index']; } else { $start_index = 1; } if ($start_index > 0 && $this->blogs[$importing_blog]['total_comments'] > 0) { $this->blogs[$importing_blog]['mode'] = 'comments'; do { $index = $struct = $entries = array(); //So we can link up the comments as we go we need to load them in reverse order //Reverse the start index as the GData Blogger feed can't be sorted $batch = floor(($this->blogs[$importing_blog]['total_comments'] - $start_index) / MAX_RESULTS) * MAX_RESULTS + 1; $response = $this->oauth_get($this->blogs[$importing_blog]['comments_url'], array('max-results' => MAX_RESULTS, 'start-index' => $batch)); // parse the feed $feed = new SimplePie(); $feed->set_item_class('WP_SimplePie_Blog_Item'); // Use the standard "stricter" sanitize class for comments $feed->set_raw_data($response); $feed->init(); //Reverse the batch so we load the oldest comments first and hence can link up nested comments $comments = array_reverse($feed->get_items()); if (!is_null($comments)) { foreach ($comments as $item) { $blogentry = new BloggerEntry(); $blogentry->id = $item->get_id(); $blogentry->updated = $item->get_updated(); $blogentry->content = $item->get_content(); $blogentry->author = $item->get_author()->get_name(); $blogentry->authoruri = $item->get_author()->get_link(); $blogentry->authoremail = $item->get_author()->get_email(); $temp = $item->get_item_tags('http://purl.org/syndication/thread/1.0', 'in-reply-to'); foreach ($temp as $t) { if (isset($t['attribs']['']['source'])) { $blogentry->source = $t['attribs']['']['source']; } } //Get the links $linktypes = array('edit', 'self', 'alternate', 'related'); foreach ($linktypes as $type) { $links = $item->get_links($type); if (!is_null($links)) { foreach ($links as $link) { $blogentry->links[] = array('rel' => $type, 'href' => $link); } } } $this->import_comment($blogentry); $start_index++; } } $this->blogs[$importing_blog]['comments_start_index'] = $start_index; $this->save_vars(); } while ($this->blogs[$importing_blog]['total_comments'] > $start_index && $this->have_time()); } $this->blogs[$importing_blog]['mode'] = 'authors'; $this->save_vars(); if (!$this->blogs[$importing_blog]['posts_done'] && !$this->blogs[$importing_blog]['comments_done']) { self::ajax_die('nothing'); } do_action('import_done', 'blogger'); self::ajax_die('done'); }