Changeset 4558 for trunk/wp-admin/export.php
- Timestamp:
- 11/30/2006 06:15:14 PM (18 years ago)
- File:
-
- 1 edited
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(); ?>
Note: See TracChangeset
for help on using the changeset viewer.