Changeset 6149

Show
Ignore:
Timestamp:
09/21/07 18:34:28 (1 year ago)
Author:
ryan
Message:

Export and import of post tags. fixes #4682

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/export.php

    r6130 r6149  
    140140 
    141141    echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>'; 
     142} 
     143 
     144function wxr_post_taxonomy() { 
     145    $categories = get_the_category(); 
     146    $tags = get_the_tags(); 
     147    $cat_names = array(); 
     148    $tag_names = array(); 
     149    $the_list = ''; 
     150    $filter = 'rss'; 
     151 
     152    if ( !empty($categories) ) foreach ( (array) $categories as $category ) { 
     153        $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
     154        $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n"; 
     155    } 
     156 
     157    if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { 
     158        $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
     159        $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n"; 
     160    } 
     161 
     162    echo $the_list; 
    142163} 
    143164 
     
    202223<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> 
    203224<dc:creator><?php the_author() ?></dc:creator> 
    204 <?php the_category_rss() ?> 
     225<?php wxr_post_taxonomy() ?> 
    205226 
    206227<guid isPermaLink="false"><?php the_guid(); ?></guid> 
  • trunk/wp-admin/import/wordpress.php

    r6129 r6149  
    317317        $post_content = str_replace('<hr>', '<hr />', $post_content); 
    318318 
     319        preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags); 
     320        $tags = $tags[1]; 
     321 
     322        $tag_index = 0; 
     323        foreach ($tags as $tag) { 
     324            $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $tag))); 
     325            $tag_index++; 
     326        } 
     327 
    319328        preg_match_all('|<category>(.*?)</category>|is', $post, $categories); 
    320329        $categories = $categories[1]; 
     
    372381                } 
    373382                wp_set_post_categories($post_id, $post_cats); 
     383            } 
     384 
     385            // Add tags. 
     386            if (count($tags) > 0) { 
     387                $post_tags = array(); 
     388                foreach ($tags as $tag) { 
     389                    $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); 
     390                    $tag_obj = get_term_by('slug', $slug, 'post_tag'); 
     391                    $tag_id = 0; 
     392                    if ( ! empty($tag_obj) ) 
     393                        $tag_id = $tag_obj->term_id; 
     394                    if ( $tag_id == 0 ) { 
     395                        $tag = $wpdb->escape($tag); 
     396                        $tag_id = wp_insert_term($tag, 'post_tag'); 
     397                        $tag_id = $tag_id['term_id']; 
     398                    } 
     399                    $post_tags[] = $tag_id; 
     400                } 
     401                wp_set_post_tags($post_id, $post_tags); 
    374402            } 
    375403        }