- if ( $num_comments )
- printf(' '.__('(%s comments)'), $num_comments);
-
- // Finally the pings
- // fix the double newline on the first one
- $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
- $pings = explode("-----\nPING:", $pings[0]);
- $num_pings = 0;
- foreach ($pings as $ping) {
- if ('' != trim($ping)) {
- // 'Author'
- preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
- $comment_author = $wpdb->escape(trim($comment_author[1]));
- $ping = preg_replace('|(\n?BLOG NAME:.*)|', '', $ping);
-
- preg_match("|IP:(.*)|", $ping, $comment_author_IP);
- $comment_author_IP = trim($comment_author_IP[1]);
- $ping = preg_replace('|(\n?IP:.*)|', '', $ping);
-
- preg_match("|URL:(.*)|", $ping, $comment_author_url);
- $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
- $ping = preg_replace('|(\n?URL:.*)|', '', $ping);
-
- preg_match("|DATE:(.*)|", $ping, $comment_date);
- $comment_date = trim($comment_date[1]);
- $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
- $ping = preg_replace('|(\n?DATE:.*)|', '', $ping);
-
- preg_match("|TITLE:(.*)|", $ping, $ping_title);
- $ping_title = $wpdb->escape(trim($ping_title[1]));
- $ping = preg_replace('|(\n?TITLE:.*)|', '', $ping);
-
- $comment_content = $wpdb->escape(trim($ping));
- $comment_content = str_replace('-----', '', $comment_content);
-
- $comment_content = "<strong>$ping_title</strong>\n\n$comment_content";
-
- $comment_type = 'trackback';
-
- // Check if it's already there
- if (!comment_exists($comment_author, $comment_date)) {
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved');
- $commentdata = wp_filter_comment($commentdata);
- wp_insert_comment($commentdata);
- $num_pings++;
- }
- }
+ $context = '';
+ } else if ( '--------' == $line ) {
+ // Finishing a post.
+ $context = '';
+ $result = $this->save_post($post, $comments, $pings);
+ if ( is_wp_error( $result ) )
+ return $result;
+ $post = new StdClass;
+ $comment = new StdClass();
+ $ping = new StdClass();
+ $comments = array();
+ $pings = array();
+ } else if ( 'BODY:' == $line ) {
+ $context = 'body';
+ } else if ( 'EXTENDED BODY:' == $line ) {
+ $context = 'extended';
+ } else if ( 'EXCERPT:' == $line ) {
+ $context = 'excerpt';
+ } else if ( 'KEYWORDS:' == $line ) {
+ $context = 'keywords';
+ } else if ( 'COMMENT:' == $line ) {
+ $context = 'comment';
+ } else if ( 'PING:' == $line ) {
+ $context = 'ping';
+ } else if ( 0 === strpos($line, "AUTHOR:") ) {
+ $author = trim( substr($line, strlen("AUTHOR:")) );
+ if ( '' == $context )
+ $post->post_author = $author;
+ else if ( 'comment' == $context )
+ $comment->comment_author = $author;
+ } else if ( 0 === strpos($line, "TITLE:") ) {
+ $title = trim( substr($line, strlen("TITLE:")) );
+ if ( '' == $context )
+ $post->post_title = $title;
+ else if ( 'ping' == $context )
+ $ping->title = $title;
+ } else if ( 0 === strpos($line, "STATUS:") ) {
+ $status = trim( substr($line, strlen("STATUS:")) );
+ if ( empty($status) )
+ $status = 'publish';
+ $post->post_status = $status;
+ } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) {
+ $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) );
+ if ( $allow == 1 )
+ $post->comment_status = 'open';
+ else
+ $post->comment_status = 'closed';
+ } else if ( 0 === strpos($line, "ALLOW PINGS:") ) {
+ $allow = trim( substr($line, strlen("ALLOW PINGS:")) );
+ if ( $allow == 1 )
+ $post->ping_status = 'open';
+ else
+ $post->ping_status = 'closed';
+ } else if ( 0 === strpos($line, "CATEGORY:") ) {
+ $category = trim( substr($line, strlen("CATEGORY:")) );
+ if ( '' != $category )
+ $post->categories[] = $category;
+ } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) {
+ $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) );
+ if ( '' != $category )
+ $post->categories[] = $category;
+ } else if ( 0 === strpos($line, "DATE:") ) {
+ $date = trim( substr($line, strlen("DATE:")) );
+ $date = strtotime($date);
+ $date = date('Y-m-d H:i:s', $date);
+ $date_gmt = get_gmt_from_date($date);
+ if ( '' == $context ) {
+ $post->post_modified = $date;
+ $post->post_modified_gmt = $date_gmt;
+ $post->post_date = $date;
+ $post->post_date_gmt = $date_gmt;
+ } else if ( 'comment' == $context ) {
+ $comment->comment_date = $date;
+ } else if ( 'ping' == $context ) {
+ $ping->comment_date = $date;
+ }
+ } else if ( 0 === strpos($line, "EMAIL:") ) {
+ $email = trim( substr($line, strlen("EMAIL:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_email = $email;
+ else
+ $ping->comment_author_email = '';
+ } else if ( 0 === strpos($line, "IP:") ) {
+ $ip = trim( substr($line, strlen("IP:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_IP = $ip;
+ else
+ $ping->comment_author_IP = $ip;
+ } else if ( 0 === strpos($line, "URL:") ) {
+ $url = trim( substr($line, strlen("URL:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_url = $url;
+ else
+ $ping->comment_author_url = $url;
+ } else if ( 0 === strpos($line, "BLOG NAME:") ) {
+ $blog = trim( substr($line, strlen("BLOG NAME:")) );
+ $ping->comment_author = $blog;
+ } else {
+ // Processing multi-line field, check context.
+
+ $line .= "\n";
+ if ( 'body' == $context ) {
+ $post->post_content .= $line;
+ } else if ( 'extended' == $context ) {
+ $post->extended .= $line;
+ } else if ( 'excerpt' == $context ) {
+ $post->post_excerpt .= $line;
+ } else if ( 'comment' == $context ) {
+ $comment->comment_content .= $line;
+ } else if ( 'ping' == $context ) {
+ $ping->comment_content .= $line;