private function importComments($post_id, $post) { static $commentors = array(); static $comment_model; if (version_compare($this->version, '2.7', '>=')) { try { if ($comments = $this->xmlrpc("wp.getComments", $post_id, $this->option('login'), $this->option('password'), array('post_id' => $post_id))) { if (!isset($comment_model)) { $comment_model = new blogCommentModel(); } $comment_map = array(); // new comment to the top $comments = array_reverse($comments); $emails = array(); foreach ($comments as $key => $comment) { $email = trim(strtolower($comment['author_email'])); if ($email && !isset($commentors[$email])) { $commentors[$email] = 0; $emails[] = $email; } else { if (!isset($commentors[$email])) { $commentors[$email] = 0; } } } $commentors = array_merge($commentors, $this->getContactByEmail($emails)); $comment_model->ping(); foreach ($comments as $key => $comment) { $email = trim(strtolower($comment['author_email'])); $this->log('comment ' . $key, self::LOG_DEBUG); $datetime = $comment['date_created_gmt']; $datetime = date("Y-m-d H:i:s", $datetime->timestamp); $parent = 0; if ($comment['parent'] && isset($comment_map[$comment['parent']])) { $parent = $comment_map[$comment['parent']]; } $contact_id = isset($commentors[$email]) ? $commentors[$email] : 0; $comment_data = array('post_id' => $post['id'], 'blog_id' => $post['blog_id'], 'contact_id' => $contact_id, 'text' => html_entity_decode(strip_tags($comment['content']), ENT_NOQUOTES, 'utf-8'), 'datetime' => $datetime, 'name' => html_entity_decode(trim($comment['author']), ENT_NOQUOTES, 'utf-8'), 'email' => $comment['author_email'], 'site' => $comment['author_url'], 'ip' => ip2long($comment['author_ip']), 'auth_provider' => $contact_id ? blogCommentModel::AUTH_USER : blogCommentModel::AUTH_GUEST, 'status' => $comment['status'] == 'approve' ? blogCommentModel::STATUS_PUBLISHED : blogCommentModel::STATUS_DELETED); $comment_id = $comment_model->add($comment_data, $parent); $comment_map[$comment['comment_id']] = $comment_id; } unset($comment_map); } } catch (waDbException $ex) { $this->log(__METHOD__ . ":\t" . $ex->getMessage() . "\nraw comment:\t" . var_export($comment, true) . "\nformatted comment:\t" . var_export($comment_data, true), self::LOG_WARNING); } catch (waException $ex) { if ($ex->getCode() == 401) { $this->log($ex->getMessage(), self::LOG_WARNING); } else { throw $ex; } } } }