diff -ur wordpress-importer-0.4/parsers.php wordpress-importer/parsers.php
old
|
new
|
|
178 | 178 | } |
179 | 179 | |
180 | 180 | foreach ( $wp->comment as $comment ) { |
| 181 | if(isset($comment->comment_meta)) { |
| 182 | $comment_meta = array(); |
| 183 | foreach ( $comment->comment_meta as $cmeta ) { |
| 184 | $comment_meta[] = array( |
| 185 | 'key' => (string) $cmeta->c_meta_key, |
| 186 | 'value' => (string) $cmeta->c_meta_value, |
| 187 | ); |
| 188 | } |
| 189 | } |
181 | 190 | $post['comments'][] = array( |
182 | 191 | 'comment_id' => (int) $comment->comment_id, |
183 | 192 | 'comment_author' => (string) $comment->comment_author, |
… |
… |
|
191 | 200 | 'comment_type' => (string) $comment->comment_type, |
192 | 201 | 'comment_parent' => (string) $comment->comment_parent, |
193 | 202 | 'comment_user_id' => (int) $comment->comment_user_id, |
| 203 | 'comment_meta' => $comment_meta, |
194 | 204 | ); |
195 | 205 | } |
196 | 206 | |
… |
… |
|
219 | 229 | 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description', |
220 | 230 | 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent', |
221 | 231 | 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name', |
222 | | 'wp:author_first_name', 'wp:author_last_name', |
| 232 | 'wp:author_first_name', 'wp:author_last_name', 'wp:comment_meta', |
223 | 233 | ); |
224 | 234 | var $wp_sub_tags = array( |
225 | 235 | 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url', |
… |
… |
|
229 | 239 | |
230 | 240 | function parse( $file ) { |
231 | 241 | $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; |
232 | | $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); |
| 242 | $this->authors = $this->posts = $this->term = $this->category = $this->tag = $this->c_meta = array(); |
233 | 243 | |
234 | 244 | $xml = xml_parser_create( 'UTF-8' ); |
235 | 245 | xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 ); |
… |
… |
|
318 | 328 | $this->data['postmeta'][] = $this->sub_data; |
319 | 329 | $this->sub_data = false; |
320 | 330 | break; |
| 331 | case 'wp:comment_meta': |
| 332 | if ( ! empty( $this->sub_data ) && ! empty( $this->c_meta ) ) |
| 333 | $this->sub_data['comment_meta'][] = $this->c_meta; |
| 334 | $this->c_meta = false; |
| 335 | break; |
| 336 | case 'wp:c_meta_key': |
| 337 | $this->c_meta['key'] = !empty($this->cdata) ? $this->cdata : false; |
| 338 | break; |
| 339 | case 'wp:c_meta_value': |
| 340 | $this->c_meta['value'] = !empty($this->cdata) ? $this->cdata : false; |
| 341 | break; |
321 | 342 | case 'item': |
322 | 343 | $this->posts[] = $this->data; |
323 | 344 | $this->data = false; |
… |
… |
|
546 | 567 | $comments = $comments[1]; |
547 | 568 | if ( $comments ) { |
548 | 569 | foreach ( $comments as $comment ) { |
| 570 | preg_match_all( '|<wp:comment_meta>(.+?)</wp:comment_meta>|is', $comment, $commentmeta ); |
| 571 | $commentmeta = $commentmeta[1]; |
| 572 | if ( $commentmeta ) { |
| 573 | foreach ( $commentmeta as $c ) { |
| 574 | $comment_meta[] = array( |
| 575 | 'key' => $this->get_tag( $c, 'wp:c_meta_key' ), |
| 576 | 'value' => $this->get_tag( $c, 'wp:c_meta_value' ), |
| 577 | ); |
| 578 | } |
| 579 | } |
549 | 580 | $post_comments[] = array( |
550 | 581 | 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), |
551 | 582 | 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), |
… |
… |
|
559 | 590 | 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), |
560 | 591 | 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), |
561 | 592 | 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ), |
| 593 | 'comment_meta' => $comment_meta, |
562 | 594 | ); |
563 | 595 | } |
564 | 596 | } |
diff -ur wordpress-importer-0.4/wordpress-importer.php wordpress-importer/wordpress-importer.php
old
|
new
|
|
654 | 654 | $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; |
655 | 655 | $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; |
656 | 656 | $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; |
| 657 | $newcomments[$comment_id]['comment_meta'] = $comment['comment_meta']; |
657 | 658 | if ( isset( $this->processed_authors[$comment['comment_user_id']] ) ) |
658 | 659 | $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; |
659 | 660 | } |
… |
… |
|
666 | 667 | $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; |
667 | 668 | $comment = wp_filter_comment( $comment ); |
668 | 669 | $inserted_comments[$key] = wp_insert_comment( $comment ); |
| 670 | |
| 671 | // add/update comment meta |
| 672 | if ( isset( $comment['comment_meta'] ) ) { |
| 673 | foreach ( $comment['comment_meta'] as $cmeta ) { |
| 674 | $meta_key = apply_filters( 'import_comment_meta_key', $cmeta['key'] ); |
| 675 | if ( $meta_key ) { |
| 676 | // export gets meta straight from the DB so could have a serialized string |
| 677 | $value = maybe_unserialize( $cmeta['value'] ); |
| 678 | update_comment_meta($inserted_comments[$key], $meta_key, $value ); |
| 679 | do_action( 'import_comment_meta', $inserted_comments[$key], $meta_key, $value ); |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
669 | 684 | $num_comments++; |
670 | 685 | } |
671 | 686 | } |