Make WordPress Core


Ignore:
Timestamp:
11/30/2006 06:15:14 PM (20 years ago)
Author:
ryan
Message:

Import/export category data. Props andy. fixes #3403

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wordpress.php

    r4495 r4558  
    8686                preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts);
    8787                $this->posts = $this->posts[1];
     88                preg_match_all('|<wp:category>(.*?)</wp:category>|is', $importdata, $this->categories);
     89                $this->categories = $this->categories[1];
    8890        }
    8991
    … …  
    176178                $this->get_entries();
    177179                $this->wp_authors_form();
     180        }
     181
     182        function process_categories() {
     183                global $wpdb;
     184
     185                $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories");
     186
     187                while ( $c = array_shift($this->categories) ) {
     188                        $cat_name = trim(str_replace(array ('<![CDATA[', ']]>'), '', $this->get_tag( $c, 'wp:cat_name' )));
     189
     190                        // If the category exists we leave it alone
     191                        if ( in_array($cat_name, $cat_names) )
     192                                continue;
     193
     194                        $category_nicename      = $this->get_tag( $c, 'wp:category_nicename' );
     195                        $posts_private          = (int) $this->get_tag( $c, 'wp:posts_private' );
     196                        $links_private          = (int) $this->get_tag( $c, 'wp:links_private' );
     197
     198                        $parent = $this->get_tag( $c, 'wp:category_parent' );
     199
     200                        if ( empty($parent) )
     201                                $category_parent = '0';
     202                        else
     203                                $category_parent = (int) category_exists($parent);
     204
     205                        $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name');
     206
     207                        $cat_ID = wp_insert_category($catarr);
     208                }
    178209        }
    179210
    … …  
    207238                        $cat_index = 0;
    208239                        foreach ($categories as $category) {
    209                                 $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
     240                                $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $category)));
    210241                                $cat_index++;
    211242                        }
    … …  
    278309                $this->get_authors_from_post();
    279310                $this->get_entries();
     311                $this->process_categories();
    280312                $this->process_posts();
    281313        }
Note: See TracChangeset for help on using the changeset viewer.