| 1 | Index: parsers.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- parsers.php (revision 316385) |
|---|
| 4 | +++ parsers.php (working copy) |
|---|
| 5 | @@ -42,7 +42,6 @@ |
|---|
| 6 | echo '<p><strong>' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '</strong><br />'; |
|---|
| 7 | echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '</p>'; |
|---|
| 8 | } |
|---|
| 9 | - |
|---|
| 10 | // use regular expressions if nothing else available or this is bad XML |
|---|
| 11 | $parser = new WXR_Parser_Regex; |
|---|
| 12 | return $parser->parse( $file ); |
|---|
| 13 | @@ -174,6 +173,15 @@ |
|---|
| 14 | } |
|---|
| 15 | |
|---|
| 16 | foreach ( $wp->comment as $comment ) { |
|---|
| 17 | + if(isset($comment->comment_meta)) { |
|---|
| 18 | + $comment_meta = array(); |
|---|
| 19 | + foreach ( $comment->comment_meta as $cmeta ) { |
|---|
| 20 | + $comment_meta[] = array( |
|---|
| 21 | + 'key' => (string) $cmeta->c_meta_key, |
|---|
| 22 | + 'value' => (string) $cmeta->c_meta_value, |
|---|
| 23 | + ); |
|---|
| 24 | + } |
|---|
| 25 | + } |
|---|
| 26 | $post['comments'][] = array( |
|---|
| 27 | 'comment_id' => (int) $comment->comment_id, |
|---|
| 28 | 'comment_author' => (string) $comment->comment_author, |
|---|
| 29 | @@ -187,6 +195,7 @@ |
|---|
| 30 | 'comment_type' => (string) $comment->comment_type, |
|---|
| 31 | 'comment_parent' => (string) $comment->comment_parent, |
|---|
| 32 | 'comment_user_id' => (int) $comment->comment_user_id, |
|---|
| 33 | + 'comment_meta' => $comment_meta |
|---|
| 34 | ); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | @@ -214,7 +223,7 @@ |
|---|
| 38 | 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description', |
|---|
| 39 | 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent', |
|---|
| 40 | 'wp:term_name', 'wp:term_description', 'wp:author_login', 'wp:author_email', 'wp:author_display_name', |
|---|
| 41 | - 'wp:author_first_name', 'wp:author_last_name', |
|---|
| 42 | + 'wp:author_first_name', 'wp:author_last_name','wp:comment_meta' |
|---|
| 43 | ); |
|---|
| 44 | var $wp_sub_tags = array( |
|---|
| 45 | 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url', |
|---|
| 46 | @@ -224,7 +233,7 @@ |
|---|
| 47 | |
|---|
| 48 | function parse( $file ) { |
|---|
| 49 | $this->is_wxr_file = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; |
|---|
| 50 | - $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); |
|---|
| 51 | + $this->authors = $this->posts = $this->term = $this->category = $this->tag = $this->c_meta = array(); |
|---|
| 52 | |
|---|
| 53 | $xml = xml_parser_create( 'UTF-8' ); |
|---|
| 54 | xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 ); |
|---|
| 55 | @@ -312,6 +321,17 @@ |
|---|
| 56 | $this->data['postmeta'][] = $this->sub_data; |
|---|
| 57 | $this->sub_data = false; |
|---|
| 58 | break; |
|---|
| 59 | + case 'wp:comment_meta': |
|---|
| 60 | + if ( ! empty( $this->sub_data ) && ! empty( $this->c_meta ) ) |
|---|
| 61 | + $this->sub_data['comment_meta'][] = $this->c_meta; |
|---|
| 62 | + $this->c_meta = false; |
|---|
| 63 | + break; |
|---|
| 64 | + case 'wp:c_meta_key' : |
|---|
| 65 | + $this->c_meta['key'] = !empty($this->cdata) ? $this->cdata : false; |
|---|
| 66 | + break; |
|---|
| 67 | + case 'wp:c_meta_value' : |
|---|
| 68 | + $this->c_meta['value'] = !empty($this->cdata) ? $this->cdata : false; |
|---|
| 69 | + break; |
|---|
| 70 | case 'item': |
|---|
| 71 | $this->posts[] = $this->data; |
|---|
| 72 | $this->data = false; |
|---|
| 73 | @@ -534,6 +554,16 @@ |
|---|
| 74 | $comments = $comments[1]; |
|---|
| 75 | if ( $comments ) { |
|---|
| 76 | foreach ( $comments as $comment ) { |
|---|
| 77 | + preg_match_all( '|<wp:comment_meta>(.+?)</wp:comment_meta>|is', $comment, $commentmeta ); |
|---|
| 78 | + $commentmeta = $commentmeta[1]; |
|---|
| 79 | + if ( $commentmeta ) { |
|---|
| 80 | + foreach ( $commentmeta as $c ) { |
|---|
| 81 | + $comment_meta[] = array( |
|---|
| 82 | + 'key' => $this->get_tag( $c, 'wp:c_meta_key' ), |
|---|
| 83 | + 'value' => $this->get_tag( $c, 'wp:c_meta_value' ), |
|---|
| 84 | + ); |
|---|
| 85 | + } |
|---|
| 86 | + } |
|---|
| 87 | $post_comments[] = array( |
|---|
| 88 | 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), |
|---|
| 89 | 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), |
|---|
| 90 | @@ -546,6 +576,7 @@ |
|---|
| 91 | 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ), |
|---|
| 92 | 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), |
|---|
| 93 | 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), |
|---|
| 94 | + 'comment_meta' => $comment_meta |
|---|
| 95 | ); |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | Index: wordpress-importer.php |
|---|
| 99 | =================================================================== |
|---|
| 100 | --- wordpress-importer.php (revision 316385) |
|---|
| 101 | +++ wordpress-importer.php (working copy) |
|---|
| 102 | @@ -574,19 +574,32 @@ |
|---|
| 103 | $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; |
|---|
| 104 | $newcomments[$comment_id]['comment_type'] = ! empty( $comment['comment_type'] ) ? $comment['comment_type'] : 'comment'; |
|---|
| 105 | $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; |
|---|
| 106 | + $newcomments[$comment_id]['comment_meta'] = $comment['comment_meta']; |
|---|
| 107 | } |
|---|
| 108 | ksort( $newcomments ); |
|---|
| 109 | |
|---|
| 110 | foreach ( $newcomments as $key => $comment ) { |
|---|
| 111 | // if this is a new post we can skip the comment_exists() check |
|---|
| 112 | if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) { |
|---|
| 113 | if ( isset( $inserted_comments[$comment['comment_parent']] ) ) |
|---|
| 114 | $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; |
|---|
| 115 | $comment = wp_filter_comment( $comment ); |
|---|
| 116 | $inserted_comments[$key] = wp_insert_comment( $comment ); |
|---|
| 117 | + // add/update comment meta |
|---|
| 118 | + if ( isset( $comment['comment_meta'] ) ) { |
|---|
| 119 | + foreach ( $comment['comment_meta'] as $cmeta ) { |
|---|
| 120 | + $meta_key = apply_filters( 'import_comment_meta_key', $cmeta['key'] ); |
|---|
| 121 | + if ( $meta_key ) { |
|---|
| 122 | + // export gets meta straight from the DB so could have a serialized string |
|---|
| 123 | + $value = maybe_unserialize( $cmeta['value'] ); |
|---|
| 124 | + update_comment_meta($inserted_comments[$key], $meta_key, $value ); |
|---|
| 125 | + do_action( 'import_comment_meta', $inserted_comments[$key], $meta_key, $value ); |
|---|
| 126 | + } |
|---|
| 127 | + } |
|---|
| 128 | + } |
|---|
| 129 | $num_comments++; |
|---|
| 130 | } |
|---|
| 131 | - } |
|---|
| 132 | + } |
|---|
| 133 | unset( $newcomments, $inserted_comments, $post['comments'] ); |
|---|
| 134 | } |
|---|