PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 function export_wp($author='') { 4 global $wpdb, $post_ids, $post; 5 6 do_action('export_wp'); 7 8 $filename = 'wordpress.' . date('Y-m-d') . '.xml'; 9 10 header('Content-Description: File Transfer'); 11 header("Content-Disposition: attachment; filename=$filename"); 12 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); 13 14 $where = ''; 15 if ( $author and $author != 'all' ) { 16 $author_id = (int) $author; 17 $where = " WHERE post_author = '$author_id' "; 18 } 19 20 // grab a snapshot of post IDs, just in case it changes during the export 21 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 22 23 $categories = (array) get_categories('get=all'); 24 $tags = (array) get_tags('get=all'); 25 26 function wxr_missing_parents($categories) { 27 if ( !is_array($categories) || empty($categories) ) 28 return array(); 29 30 foreach ( $categories as $category ) 31 $parents[$category->term_id] = $category->parent; 32 33 $parents = array_unique(array_diff($parents, array_keys($parents))); 34 35 if ( $zero = array_search('0', $parents) ) 36 unset($parents[$zero]); 37 38 return $parents; 39 } 40 41 while ( $parents = wxr_missing_parents($categories) ) { 42 $found_parents = get_categories("include=" . join(', ', $parents)); 43 if ( is_array($found_parents) && count($found_parents) ) 44 $categories = array_merge($categories, $found_parents); 45 else 46 break; 47 } 48 49 // Put them in order to be inserted with no child going before its parent 50 $pass = 0; 51 $passes = 1000 + count($categories); 52 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) { 53 if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) { 54 $cats[$cat->term_id] = $cat; 55 } else { 56 $categories[] = $cat; 57 } 58 } 59 unset($categories); 60 61 function wxr_cdata($str) { 62 if ( seems_utf8($str) == false ) 63 $str = utf8_encode($str); 64 65 // $str = ent2ncr(wp_specialchars($str)); 66 67 $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>"; 68 69 return $str; 70 } 71 72 function wxr_cat_name($c) { 73 if ( empty($c->name) ) 74 return; 75 76 echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>'; 77 } 78 79 function wxr_category_description($c) { 80 if ( empty($c->description) ) 81 return; 82 83 echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>'; 84 } 85 86 function wxr_tag_name($t) { 87 if ( empty($t->name) ) 88 return; 89 90 echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>'; 91 } 92 93 function wxr_tag_description($t) { 94 if ( empty($t->description) ) 95 return; 96 97 echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>'; 98 } 99 100 function wxr_post_taxonomy() { 101 $categories = get_the_category(); 102 $tags = get_the_tags(); 103 $the_list = ''; 104 $filter = 'rss'; 105 106 if ( !empty($categories) ) foreach ( (array) $categories as $category ) { 107 $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 108 $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n"; 109 } 110 111 if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { 112 $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 113 $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n"; 114 } 115 116 echo $the_list; 117 } 118 119 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n"; 120 121 ?> 122 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. --> 123 <!-- It contains information about your blog's posts, comments, and categories. --> 124 <!-- You may use this file to transfer that content from one site to another. --> 125 <!-- This file is not intended to serve as a complete backup of your blog. --> 126 127 <!-- To import this information into a WordPress blog follow these steps. --> 128 <!-- 1. Log into that blog as an administrator. --> 129 <!-- 2. Go to Manage: Import in the blog's admin panels. --> 130 <!-- 3. Choose "WordPress" from the list. --> 131 <!-- 4. Upload this file using the form provided on that page. --> 132 <!-- 5. You will first be asked to map the authors in this export file to users --> 133 <!-- on the blog. For each author, you may choose to map to an --> 134 <!-- existing user on the blog or to create a new user --> 135 <!-- 6. WordPress will then import each of the posts, comments, and categories --> 136 <!-- contained in this file into your blog --> 137 138 <?php the_generator('export');?> 139 <rss version="2.0" 140 xmlns:content="http://purl.org/rss/1.0/modules/content/" 141 xmlns:wfw="http://wellformedweb.org/CommentAPI/" 142 xmlns:dc="http://purl.org/dc/elements/1.1/" 143 xmlns:wp="http://wordpress.org/export/1.0/" 144 > 145 146 <channel> 147 <title><?php bloginfo_rss('name'); ?></title> 148 <link><?php bloginfo_rss('url') ?></link> 149 <description><?php bloginfo_rss("description") ?></description> 150 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate> 151 <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator> 152 <language><?php echo get_option('rss_language'); ?></language> 153 <?php if ( $cats ) : foreach ( $cats as $c ) : ?> 154 <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category> 155 <?php endforeach; endif; ?> 156 <?php if ( $tags ) : foreach ( $tags as $t ) : ?> 157 <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag> 158 <?php endforeach; endif; ?> 159 <?php do_action('rss2_head'); ?> 160 <?php if ($post_ids) { 161 global $wp_query; 162 $wp_query->in_the_loop = true; // Fake being in the loop. 163 // fetch 20 posts at a time rather than loading the entire table into memory 164 while ( $next_posts = array_splice($post_ids, 0, 20) ) { 165 $where = "WHERE ID IN (".join(',', $next_posts).")"; 166 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 167 foreach ($posts as $post) { 168 setup_postdata($post); ?> 169 <item> 170 <title><?php the_title_rss() ?></title> 171 <link><?php the_permalink_rss() ?></link> 172 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate> 173 <dc:creator><?php the_author() ?></dc:creator> 174 <?php wxr_post_taxonomy() ?> 175 176 <guid isPermaLink="false"><?php the_guid(); ?></guid> 177 <description></description> 178 <content:encoded><![CDATA[<?php echo $post->post_content ?>]]></content:encoded> 179 <wp:post_id><?php echo $post->ID; ?></wp:post_id> 180 <wp:post_date><?php echo $post->post_date; ?></wp:post_date> 181 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt> 182 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status> 183 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status> 184 <wp:post_name><?php echo $post->post_name; ?></wp:post_name> 185 <wp:status><?php echo $post->post_status; ?></wp:status> 186 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent> 187 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order> 188 <wp:post_type><?php echo $post->post_type; ?></wp:post_type> 189 <?php 190 $postmeta = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID"); 191 if ( $postmeta ) { 192 ?> 193 <?php foreach( $postmeta as $meta ) { ?> 194 <wp:postmeta> 195 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key> 196 <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value> 197 </wp:postmeta> 198 <?php } ?> 199 <?php } ?> 200 <?php 201 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID"); 202 if ( $comments ) { foreach ( $comments as $c ) { ?> 203 <wp:comment> 204 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id> 205 <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author> 206 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email> 207 <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url> 208 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP> 209 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date> 210 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt> 211 <wp:comment_content><?php echo $c->comment_content; ?></wp:comment_content> 212 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved> 213 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type> 214 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent> 215 </wp:comment> 216 <?php } } ?> 217 </item> 218 <?php } } } ?> 219 </channel> 220 </rss> 221 <?php 222 } 223 224 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs | Cross-referenced by PHPXref 0.6 and RedAlt |