/** * Create new comments based on import information */ function process_comments() { $feed = $this->import_data; foreach ($feed->get_items() as $item) { // check that it is actually a comment first // <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#comment'/> $is_comment = false; $cats = $item->get_categories(); foreach ($cats as $cat) { if ($cat == 'http://schemas.google.com/blogger/2008/kind#comment') { $is_comment = true; break; } } // we only import comments here if (!$is_comment) { continue; } $commententry = new CommentEntry(); $commententry->id = $item->get_id(); $commententry->updated = $item->get_updated(); $commententry->content = $item->get_content(); $commententry->author = $item->get_author()->get_name(); $commententry->authoruri = $item->get_author()->get_link(); $commententry->authoremail = $item->get_author()->get_email(); $replyto = $item->get_item_tags('http://purl.org/syndication/thread/1.0', 'in-reply-to'); $commententry->source = $replyto[0]['attribs']['']['source']; $commententry->source = $item->get_source(); $parts = parse_url($commententry->source); $commententry->old_post_permalink = $parts['path']; //Will be something like this '/feeds/417730729915399755/posts/default/8397846992898424746' $bloggerentry = new BloggerEntry(); $commententry->post_ID = $bloggerentry->get_post_by_oldID($commententry->old_post_permalink); //Get the links $commententry->links = $item->get_links(array('edit', 'self', 'alternate', 'related')); $commententry->parselinks(); // Nested comment? if (isset($commententry->related)) { $commententry->parentcommentid = $commententry->get_comment_by_oldID($commententry->related); } //Perhaps could log errors here? if ($commententry->post_ID != 0) { // Checks for duplicates if ($comment_id = $commententry->exists()) { $this->comments_skipped++; } else { $comment_id = $commententry->import(); $this->comments_done++; } } else { $this->comments_skipped++; } } }
/** * Delete a CommentEntry. * * @param \ZendGData\Photos\CommentEntry $comment The comment entry to * delete. * @param boolean $catch Whether to catch an exception when * modified and re-delete or throw * @return void. * @throws \ZendGData\App\Exception * @throws \ZendGData\App\HttpException */ public function deleteCommentEntry($comment, $catch) { if ($catch) { try { $this->delete($comment); } catch (App\HttpException $e) { if ($e->getResponse()->getStatusCode() === 409) { $entry = new CommentEntry($e->getResponse()->getBody()); $this->delete($entry->getLink('edit')->href); } else { throw $e; } } } else { $this->delete($comment); } }
function import_comments($connector) { if (isset($this->comments_start_index)) $start_index = (int)$this->comments_start_index; else $start_index = 1; if ($start_index > 0 && $this->total_comments > 0) { $this->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->total_comments - $start_index) / Blogger_Import::MAX_RESULTS) * Blogger_Import::MAX_RESULTS) + 1); $response = $connector->oauth_get($this->comments_url,array('max-results' => Blogger_Import::MAX_RESULTS, 'start-index' => $batch)); // parse the feed $feed = new SimplePie(); //3/1/2012 Updated syntax for registering the item $reg = $feed->get_registry(); $reg->register('Item', '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) { $commententry = new CommentEntry(); $commententry->id = $item->get_id(); $commententry->updated = $item->get_updated(); $commententry->content = $item->get_content(); $commententry->author = $item->get_author()->get_name(); $commententry->authoruri = $item->get_author()->get_link(); $commententry->authoremail = $item->get_author()->get_email(); $commententry->source = $item->get_source(); $parts = parse_url($commententry->source); $commententry->old_post_permalink = $parts['path']; //Will be something like this '/feeds/417730729915399755/posts/default/8397846992898424746' $commententry->post_ID = BloggerEntry::get_post_by_oldID($commententry->old_post_permalink); //Get the links $commententry->links = $item->get_links(array('edit', 'self', 'alternate', 'related')); $commententry->parselinks(); // Nested comment? if (isset($commententry->related)) { $commententry->parentcommentid = CommentEntry::get_comment_by_oldID($commententry->related); } //Perhaps could log errors here? if ($commententry->post_ID != 0) { // Checks for duplicates if ($comment_id = $commententry->exists()) { $this->comments_skipped++; } else { $comment_id = $commententry->import(); $this->comments_done++; } } else { $this->comments_skipped++; } $this->save_vars(); $start_index++; } } $this->comments_start_index = $start_index; $this->save_vars(); } while ($this->total_comments > $start_index && $this->have_time()); } return ($this->total_comments <= $start_index); }