Changeset 6374
- Timestamp:
- 12/12/2007 05:08:48 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wordpress.php
r6336 r6374 3 3 class WP_Import { 4 4 5 var $posts = array ();6 5 var $post_ids_processed = array (); 7 // Array of arrays. [[0] => XML fragment, [1] => New post ID] 6 var $orphans = array (); 8 7 var $file; 9 8 var $id; … … 89 88 set_magic_quotes_runtime(0); 90 89 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 } 134 126 135 // skip the second loop iteration unless it's needed136 if ( !$this->another_pass )137 break;138 }139 127 140 128 } … … 271 259 272 260 function process_posts() { 273 return; //FIXME274 261 $i = -1; 275 262 echo '<ol>'; … … 336 323 $post_parent = (int) $post_parent; 337 324 if ($post_parent) { 325 // if we already know the parent, map it to the local ID 338 326 if ( $parent = $this->post_ids_processed[$post_parent] ) { 339 327 $post_parent = $parent; // new ID of the parent 340 328 } 341 329 else { 342 // wait until the parent has been processed 343 $this->another_pass = true; 344 return; 330 // record the parent for later 331 $this->orphans[intval($post_ID)] = $post_parent; 345 332 } 346 333 } … … 435 422 } } 436 423 } 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 } 437 437 438 438 function import($id) { 439 439 $this->id = (int) $id; 440 440 441 $this->file = get_attached_file($this->id); 441 $file = get_attached_file($this->id); 442 $this->import_file($file); 443 } 444 445 function import_file($file) { 446 $this->file = $file; 447 442 448 $this->get_authors_from_post(); 443 $this->get_entries( array(&$this, 'process_post'));449 $this->get_entries(); 444 450 $this->process_categories(); 445 451 $this->process_tags(); 446 452 $result = $this->process_posts(); 453 $this->backfill_parents(); 447 454 if ( is_wp_error( $result ) ) 448 455 return $result;
Note: See TracChangeset
for help on using the changeset viewer.