Changeset 4558
- Timestamp:
- 11/30/2006 06:15:14 PM (19 years ago)
- Location:
- trunk/wp-admin
- Files:
-
- 2 edited
-
export.php (modified) (2 diffs)
-
import/wordpress.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/export.php
r4495 r4558 61 61 62 62 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 63 64 $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id"); 65 66 function wxr_missing_parents($categories) { 67 if ( !is_array($categories) || empty($categories) ) 68 return array(); 69 70 foreach ( $categories as $category ) 71 $parents[$category->cat_ID] = $category->category_parent; 72 73 $parents = array_unique(array_diff($parents, array_keys($parents))); 74 75 if ( $zero = array_search('0', $parents) ) 76 unset($parents[$zero]); 77 78 return $parents; 79 } 80 81 while ( $parents = wxr_missing_parents($categories) ) { 82 $found_parents = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories WHERE cat_ID IN (" . join(', ', $parents) . ")"); 83 if ( is_array($found_parents) && count($found_parents) ) 84 $categories = array_merge($categories, $found_parents); 85 else 86 break; 87 } 88 89 // Put them in order to be inserted with no child going before its parent 90 $pass = 0; 91 $passes = 1000 + count($categories); 92 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) { 93 if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) { 94 $cats[$cat->cat_ID] = $cat; 95 } else { 96 $categories[] = $cat; 97 } 98 } 99 unset($categories); 100 101 function wxr_cdata($str) { 102 if ( seems_utf8($str) == false ) 103 $str = utf8_encode($str); 104 105 // $str = ent2ncr(wp_specialchars($str)); 106 107 $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>"; 108 109 return $str; 110 } 111 112 function wxr_cat_name($c) { 113 if ( empty($c->cat_name) ) 114 return; 115 116 echo '<wp:cat_name>' . wxr_cdata($c->cat_name) . '</wp:cat_name>'; 117 } 118 119 function wxr_category_description($c) { 120 if ( empty($c->category_description) ) 121 return; 122 123 echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>'; 124 } 63 125 ?> 64 126 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. --> … … 87 149 <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator> 88 150 <language><?php echo get_option('rss_language'); ?></language> 151 <?php if ( $cats ) : foreach ( $cats as $c ) : ?> 152 <wp:category><wp:category_nicename><?php echo $c->category_nicename; ?></wp:category_nicename><wp:category_parent><?php echo $c->category_parent ? $cats[$c->category_parent]->cat_name : ''; ?></wp:category_parent><wp:posts_private><?php echo $c->posts_private ? '1' : '0'; ?></wp:posts_private><wp:links_private><?php echo $c->links_private ? '1' : '0'; ?></wp:links_private><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category> 153 <?php endforeach; endif; ?> 89 154 <?php do_action('rss2_head'); ?> 90 155 <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?> -
trunk/wp-admin/import/wordpress.php
r4495 r4558 86 86 preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts); 87 87 $this->posts = $this->posts[1]; 88 preg_match_all('|<wp:category>(.*?)</wp:category>|is', $importdata, $this->categories); 89 $this->categories = $this->categories[1]; 88 90 } 89 91 … … 176 178 $this->get_entries(); 177 179 $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 } 178 209 } 179 210 … … 207 238 $cat_index = 0; 208 239 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))); 210 241 $cat_index++; 211 242 } … … 278 309 $this->get_authors_from_post(); 279 310 $this->get_entries(); 311 $this->process_categories(); 280 312 $this->process_posts(); 281 313 }
Note: See TracChangeset
for help on using the changeset viewer.