Changeset 6428 for trunk/wp-admin/import/wordpress.php
- Timestamp:
- 12/20/2007 05:31:39 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wordpress.php
r6390 r6428 367 367 $this->post_ids_processed[intval($post_ID)] = intval($post_id); 368 368 } 369 369 370 370 // Add categories. 371 371 if (count($categories) > 0) { … … 439 439 $value = $this->get_tag( $p, 'wp:meta_value' ); 440 440 $value = stripslashes($value); // add_post_meta() will escape. 441 add_post_meta( $post_id, $key, $value ); 441 442 $this->process_post_meta($post_id, $key, $value); 443 442 444 } } 443 445 446 do_action('import_post_added', $post_id); 444 447 print "</li>\n"; 448 } 449 450 function process_post_meta($post_id, $key, $value) { 451 // the filter can return false to skip a particular metadata key 452 $_key = apply_filters('import_post_meta_key', $key); 453 if ( $_key ) { 454 add_post_meta( $post_id, $_key, $value ); 455 do_action('import_post_meta', $post_id, $_key, $value); 456 } 445 457 } 446 458 … … 456 468 print '('.size_format(filesize($upload['file'])).')'; 457 469 } 470 471 if ( $info = wp_check_filetype($upload['file']) ) { 472 $postdata['post_mime_type'] = $info['type']; 473 } 474 else { 475 print __('Invalid file type'); 476 return; 477 } 458 478 459 479 $postdata['guid'] = $upload['url']; … … 462 482 $post_id = wp_insert_attachment($postdata, $upload['file']); 463 483 wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); 484 485 // remap the thumbnail url. this isn't perfect because we're just guessing the original url. 486 if ( preg_match('@^image/@', $info['type']) && $thumb_url = wp_get_attachment_thumb_url($post_id) ) { 487 $parts = pathinfo($remote_url); 488 $ext = $parts['extension']; 489 $name = basename($parts['basename'], ".{$ext}"); 490 $this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url; 491 } 492 464 493 return $post_id; 465 494 } … … 500 529 501 530 } 531 532 // sort by strlen, longest string first 533 function cmpr_strlen($a, $b) { 534 return strlen($b) - strlen($a); 535 } 502 536 503 537 // update url references in post bodies to point to the new local files … … 505 539 506 540 // make sure we do the longest urls first, in case one is a substring of another 507 function cmpr_strlen($a, $b) { 508 return strlen($b) - strlen($a); 509 } 510 uksort($this->url_remap, 'cmpr_strlen'); 541 uksort($this->url_remap, array(&$this, 'cmpr_strlen')); 511 542 512 543 global $wpdb; 513 544 foreach ($this->url_remap as $from_url => $to_url) { 545 // remap urls in post_content 514 546 $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, '%s', '%s')", $from_url, $to_url) ); 547 // remap enclosure urls 548 $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, '%s', '%s') WHERE meta_key='enclosure'", $from_url, $to_url) ); 515 549 } 516 550 } … … 528 562 } 529 563 } 564 565 function is_valid_meta_key($key) { 566 // skip _wp_attached_file metadata since we'll regenerate it from scratch 567 if ( $key == '_wp_attached_file' ) 568 return false; 569 return $key; 570 } 530 571 531 572 function import($id, $fetch_attachments = false) { … … 533 574 $this->fetch_attachments = (bool) $fetch_attachments; 534 575 576 add_filter('import_post_meta_key', array($this, 'is_valid_meta_key')); 535 577 $file = get_attached_file($this->id); 536 578 $this->import_file($file); … … 548 590 $this->backfill_parents(); 549 591 $this->backfill_attachment_urls(); 592 593 // clear the caches after backfilling 594 foreach ($this->post_ids_processed as $post_id) 595 clean_post_cache($post_id); 596 550 597 wp_defer_term_counting(false); 551 598 if ( is_wp_error( $result ) )
Note: See TracChangeset
for help on using the changeset viewer.