Changeset 5245
- Timestamp:
- 04/12/2007 01:34:15 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/import/wordpress.php
r5208 r5245 4 4 5 5 var $posts = array (); 6 7 6 8 var $file; 7 9 var $id; … … 87 89 preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts); 88 90 $this->posts = $this->posts[1]; 91 92 93 94 95 96 89 97 preg_match_all('|<wp:category>(.*?)</wp:category>|is', $importdata, $this->categories); 90 98 $this->categories = $this->categories[1]; … … 209 217 210 218 function process_posts() { 211 global $wpdb;212 219 $i = -1; 213 220 echo '<ol>'; 214 foreach ($this->posts as $post) { 215 216 // There are only ever one of these 217 $post_title = $this->get_tag( $post, 'title' ); 218 $post_date = $this->get_tag( $post, 'wp:post_date' ); 219 $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' ); 220 $comment_status = $this->get_tag( $post, 'wp:comment_status' ); 221 $ping_status = $this->get_tag( $post, 'wp:ping_status' ); 222 $post_status = $this->get_tag( $post, 'wp:status' ); 223 $post_name = $this->get_tag( $post, 'wp:post_name' ); 224 $post_parent = $this->get_tag( $post, 'wp:post_parent' ); 225 $menu_order = $this->get_tag( $post, 'wp:menu_order' ); 226 $post_type = $this->get_tag( $post, 'wp:post_type' ); 227 $guid = $this->get_tag( $post, 'guid' ); 228 $post_author = $this->get_tag( $post, 'dc:creator' ); 229 230 $post_content = $this->get_tag( $post, 'content:encoded' ); 231 $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $post_content); 232 $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content); 233 $post_content = str_replace('<br>', '<br />', $post_content); 234 $post_content = str_replace('<hr>', '<hr />', $post_content); 235 236 preg_match_all('|<category>(.*?)</category>|is', $post, $categories); 237 $categories = $categories[1]; 238 239 $cat_index = 0; 240 foreach ($categories as $category) { 241 $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $category))); 242 $cat_index++; 243 } 244 245 if ($post_id = post_exists($post_title, '', $post_date)) { 246 echo '<li>'; 247 printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title)); 248 } else { 249 echo '<li>'; 250 printf(__('Importing post <i>%s</i>...'), stripslashes($post_title)); 251 252 $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor 253 254 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type'); 255 $comment_post_ID = $post_id = wp_insert_post($postdata); 256 // Add categories. 257 if (0 != count($categories)) { 258 wp_create_categories($categories, $post_id); 259 } 260 } 261 262 // Now for comments 263 preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments); 264 $comments = $comments[1]; 265 $num_comments = 0; 266 if ( $comments) { foreach ($comments as $comment) { 267 $comment_author = $this->get_tag( $comment, 'wp:comment_author'); 268 $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email'); 269 $comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP'); 270 $comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url'); 271 $comment_date = $this->get_tag( $comment, 'wp:comment_date'); 272 $comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt'); 273 $comment_content = $this->get_tag( $comment, 'wp:comment_content'); 274 $comment_approved = $this->get_tag( $comment, 'wp:comment_approved'); 275 $comment_type = $this->get_tag( $comment, 'wp:comment_type'); 276 $comment_parent = $this->get_tag( $comment, 'wp:comment_parent'); 277 278 if ( !comment_exists($comment_author, $comment_date) ) { 279 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent'); 280 wp_insert_comment($commentdata); 281 $num_comments++; 282 } 283 } } 284 if ( $num_comments ) 285 printf(' '.__('(%s comments)'), $num_comments); 286 287 // Now for post meta 288 preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta); 289 $postmeta = $postmeta[1]; 290 if ( $postmeta) { foreach ($postmeta as $p) { 291 $key = $this->get_tag( $p, 'wp:meta_key' ); 292 $value = $this->get_tag( $p, 'wp:meta_value' ); 293 add_post_meta( $post_id, $key, $value ); 294 } } 295 296 $index++; 297 } 221 222 foreach ($this->posts as $post) 223 $this->process_post($post); 298 224 299 225 echo '</ol>'; … … 302 228 303 229 echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>'; 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 304 332 } 305 333
Note: See TracChangeset
for help on using the changeset viewer.