| 91 | | # $this->posts = array(); |
|---|
| 92 | | # $this->categories = array(); |
|---|
| 93 | | # $this->tags = array(); |
|---|
| 94 | | # $num = 0; |
|---|
| 95 | | |
|---|
| 96 | | for ($i=0; $i<2; $i++) { |
|---|
| 97 | | $this->another_pass = false; |
|---|
| 98 | | $doing_entry = false; |
|---|
| 99 | | |
|---|
| 100 | | $fp = fopen($this->file, 'r'); |
|---|
| 101 | | if ($fp) { |
|---|
| 102 | | while ( !feof($fp) ) { |
|---|
| 103 | | $importline = rtrim(fgets($fp)); |
|---|
| 104 | | |
|---|
| 105 | | if ( false !== strpos($importline, '<wp:category>') ) { |
|---|
| 106 | | preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); |
|---|
| 107 | | $this->categories[] = $category[1]; |
|---|
| 108 | | continue; |
|---|
| 109 | | } |
|---|
| 110 | | if ( false !== strpos($importline, '<wp:tag>') ) { |
|---|
| 111 | | preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag); |
|---|
| 112 | | $this->tags[] = $tag[1]; |
|---|
| 113 | | continue; |
|---|
| 114 | | } |
|---|
| 115 | | if ( false !== strpos($importline, '<item>') ) { |
|---|
| 116 | | $this->post = ''; |
|---|
| 117 | | $doing_entry = true; |
|---|
| 118 | | continue; |
|---|
| 119 | | } |
|---|
| 120 | | if ( false !== strpos($importline, '</item>') ) { |
|---|
| 121 | | $num++; |
|---|
| 122 | | $doing_entry = false; |
|---|
| 123 | | if ($process_post_func) |
|---|
| 124 | | call_user_func($process_post_func, $this->post); |
|---|
| 125 | | continue; |
|---|
| 126 | | } |
|---|
| 127 | | if ( $doing_entry ) { |
|---|
| 128 | | $this->post .= $importline . "\n"; |
|---|
| 129 | | } |
|---|
| 130 | | } |
|---|
| 131 | | |
|---|
| 132 | | fclose($fp); |
|---|
| 133 | | } |
|---|
| | 90 | $doing_entry = false; |
|---|
| | 91 | |
|---|
| | 92 | $fp = fopen($this->file, 'r'); |
|---|
| | 93 | if ($fp) { |
|---|
| | 94 | while ( !feof($fp) ) { |
|---|
| | 95 | $importline = rtrim(fgets($fp)); |
|---|
| | 96 | |
|---|
| | 97 | if ( false !== strpos($importline, '<wp:category>') ) { |
|---|
| | 98 | preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category); |
|---|
| | 99 | $this->categories[] = $category[1]; |
|---|
| | 100 | continue; |
|---|
| | 101 | } |
|---|
| | 102 | if ( false !== strpos($importline, '<wp:tag>') ) { |
|---|
| | 103 | preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag); |
|---|
| | 104 | $this->tags[] = $tag[1]; |
|---|
| | 105 | continue; |
|---|
| | 106 | } |
|---|
| | 107 | if ( false !== strpos($importline, '<item>') ) { |
|---|
| | 108 | $this->post = ''; |
|---|
| | 109 | $doing_entry = true; |
|---|
| | 110 | continue; |
|---|
| | 111 | } |
|---|
| | 112 | if ( false !== strpos($importline, '</item>') ) { |
|---|
| | 113 | $num++; |
|---|
| | 114 | $doing_entry = false; |
|---|
| | 115 | if ($process_post_func) |
|---|
| | 116 | call_user_func($process_post_func, $this->post); |
|---|
| | 117 | continue; |
|---|
| | 118 | } |
|---|
| | 119 | if ( $doing_entry ) { |
|---|
| | 120 | $this->post .= $importline . "\n"; |
|---|
| | 121 | } |
|---|
| | 122 | } |
|---|
| | 123 | |
|---|
| | 124 | fclose($fp); |
|---|
| | 125 | } |
|---|
| | 424 | |
|---|
| | 425 | // update the post_parent of orphans now that we know the local id's of all parents |
|---|
| | 426 | function backfill_parents() { |
|---|
| | 427 | global $wpdb; |
|---|
| | 428 | |
|---|
| | 429 | foreach ($this->orphans as $child_id => $parent_id) { |
|---|
| | 430 | $local_child_id = $this->post_ids_processed[$child_id]; |
|---|
| | 431 | $local_parent_id = $this->post_ids_processed[$parent_id]; |
|---|
| | 432 | if ($local_child_id and $local_parent_id) { |
|---|
| | 433 | $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $local_parent_id, $local_child_id)); |
|---|
| | 434 | } |
|---|
| | 435 | } |
|---|
| | 436 | } |
|---|