Ticket #15091: wordpress-importer.diff
File wordpress-importer.diff, 2.2 KB (added by , 14 years ago) |
---|
-
wordpress-importer.php
463 463 $post_content = str_replace('<br>', '<br />', $post_content); 464 464 $post_content = str_replace('<hr>', '<hr />', $post_content); 465 465 466 preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags); 467 $tags = $tags[1]; 466 preg_match_all('|<category\s*(?:\bdomain="(.*?)"\s*)?(?:\bnicename="(.*?)")?>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?</category>|', $post, $terms, PREG_SET_ORDER); 468 467 469 $tag_index = 0;470 foreach ($tags as $tag) {471 $tags[$tag_index] = $wpdb->escape( html_entity_decode( str_replace(array( '<![CDATA[', ']]>' ), '', $tag ) ) );472 $tag_index++;473 }474 475 468 preg_match_all('|<category>(.*?)</category>|is', $post, $categories); 476 469 $categories = $categories[1]; 477 470 … … 556 549 } 557 550 558 551 // Add terms. 559 if (count($t ags) > 0) {560 $post_t ags = array();561 foreach ($t ags as $tag) {562 if ( '' == $t ag)552 if (count($terms) > 0) { 553 $post_terms = array(); 554 foreach ($terms as $term) { 555 if ( '' == $term[1] || 'category' == $term[1]) 563 556 continue; 564 $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); 565 $tag_obj = get_term_by('slug', $slug, 'post_tag'); 566 $tag_id = 0; 567 if ( ! empty($tag_obj) ) 568 $tag_id = $tag_obj->term_id; 569 if ( $tag_id == 0 ) { 570 $tag = $wpdb->escape($tag); 571 $tag_id = wp_insert_term($tag, 'post_tag'); 572 if ( is_wp_error($tag_id) ) 557 $slug = $term[2]; 558 echo $slug; 559 $domain = $term[1]; 560 if ($domain == 'tag') { 561 $domain = 'post_tag'; 562 } 563 $term = $wpdb->escape($term[3]); 564 $term_id = term_exists( $term, $domain ); 565 if ( $term_id || $term_id != 0) { 566 echo $term_id; 567 } else { 568 $term_id = wp_insert_term($term, $domain); 569 echo $term_id; 570 if ( is_wp_error($term_id) ) 573 571 continue; 574 $t ag_id = $tag_id['term_id'];572 $term_id = $term_id['term_id']; 575 573 } 576 $post_tags[] = intval($tag_id);574 wp_set_post_terms($post_id, $term, $domain,true); 577 575 } 578 wp_set_post_tags($post_id, $post_tags);579 576 } 580 577 } 581 578