-
+ 16599B52559AA9E2BC017F43AA7FA501F1EDEB0ED8CCFD1E88456406DAA484DEC5DD88B88A239C87152FBA992B145D73FEC1906283762613969A3D547AE60268
mp-wp/wp-admin/includes/export.php
(0 . 0)(1 . 334)
33004 <?php
33005 /**
33006 * WordPress Export Administration API
33007 *
33008 * @package WordPress
33009 * @subpackage Administration
33010 */
33011
33012 /**
33013 * Version number for the export format.
33014 *
33015 * Bump this when something changes that might affect compatibility.
33016 *
33017 * @since unknown
33018 * @var string
33019 */
33020 define('WXR_VERSION', '1.0');
33021
33022 /**
33023 * {@internal Missing Short Description}}
33024 *
33025 * @since unknown
33026 *
33027 * @param unknown_type $author
33028 */
33029 function export_wp($author='') {
33030 global $wpdb, $post_ids, $post;
33031
33032 do_action('export_wp');
33033
33034 $filename = 'wordpress.' . date('Y-m-d') . '.xml';
33035
33036 header('Content-Description: File Transfer');
33037 header("Content-Disposition: attachment; filename=$filename");
33038 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
33039
33040 $where = '';
33041 if ( $author and $author != 'all' ) {
33042 $author_id = (int) $author;
33043 $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
33044 }
33045
33046 // grab a snapshot of post IDs, just in case it changes during the export
33047 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
33048
33049 $categories = (array) get_categories('get=all');
33050 $tags = (array) get_tags('get=all');
33051
33052 /**
33053 * {@internal Missing Short Description}}
33054 *
33055 * @since unknown
33056 *
33057 * @param unknown_type $categories
33058 */
33059 function wxr_missing_parents($categories) {
33060 if ( !is_array($categories) || empty($categories) )
33061 return array();
33062
33063 foreach ( $categories as $category )
33064 $parents[$category->term_id] = $category->parent;
33065
33066 $parents = array_unique(array_diff($parents, array_keys($parents)));
33067
33068 if ( $zero = array_search('0', $parents) )
33069 unset($parents[$zero]);
33070
33071 return $parents;
33072 }
33073
33074 while ( $parents = wxr_missing_parents($categories) ) {
33075 $found_parents = get_categories("include=" . join(', ', $parents));
33076 if ( is_array($found_parents) && count($found_parents) )
33077 $categories = array_merge($categories, $found_parents);
33078 else
33079 break;
33080 }
33081
33082 // Put them in order to be inserted with no child going before its parent
33083 $pass = 0;
33084 $passes = 1000 + count($categories);
33085 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
33086 if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
33087 $cats[$cat->term_id] = $cat;
33088 } else {
33089 $categories[] = $cat;
33090 }
33091 }
33092 unset($categories);
33093
33094 /**
33095 * Place string in CDATA tag.
33096 *
33097 * @since unknown
33098 *
33099 * @param string $str String to place in XML CDATA tag.
33100 */
33101 function wxr_cdata($str) {
33102 if ( seems_utf8($str) == false )
33103 $str = utf8_encode($str);
33104
33105 // $str = ent2ncr(wp_specialchars($str));
33106
33107 $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
33108
33109 return $str;
33110 }
33111
33112 /**
33113 * {@internal Missing Short Description}}
33114 *
33115 * @since unknown
33116 *
33117 * @return string Site URL.
33118 */
33119 function wxr_site_url() {
33120 global $current_site;
33121
33122 // mu: the base url
33123 if ( isset($current_site->domain) ) {
33124 return 'http://'.$current_site->domain.$current_site->path;
33125 }
33126 // wp: the blog url
33127 else {
33128 return get_bloginfo_rss('url');
33129 }
33130 }
33131
33132 /**
33133 * {@internal Missing Short Description}}
33134 *
33135 * @since unknown
33136 *
33137 * @param object $c Category Object
33138 */
33139 function wxr_cat_name($c) {
33140 if ( empty($c->name) )
33141 return;
33142
33143 echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
33144 }
33145
33146 /**
33147 * {@internal Missing Short Description}}
33148 *
33149 * @since unknown
33150 *
33151 * @param object $c Category Object
33152 */
33153 function wxr_category_description($c) {
33154 if ( empty($c->description) )
33155 return;
33156
33157 echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
33158 }
33159
33160 /**
33161 * {@internal Missing Short Description}}
33162 *
33163 * @since unknown
33164 *
33165 * @param object $t Tag Object
33166 */
33167 function wxr_tag_name($t) {
33168 if ( empty($t->name) )
33169 return;
33170
33171 echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
33172 }
33173
33174 /**
33175 * {@internal Missing Short Description}}
33176 *
33177 * @since unknown
33178 *
33179 * @param object $t Tag Object
33180 */
33181 function wxr_tag_description($t) {
33182 if ( empty($t->description) )
33183 return;
33184
33185 echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
33186 }
33187
33188 /**
33189 * {@internal Missing Short Description}}
33190 *
33191 * @since unknown
33192 */
33193 function wxr_post_taxonomy() {
33194 $categories = get_the_category();
33195 $tags = get_the_tags();
33196 $the_list = '';
33197 $filter = 'rss';
33198
33199 if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
33200 $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
33201 // for backwards compatibility
33202 $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
33203 // forwards compatibility: use a unique identifier for each cat to avoid clashes
33204 // http://trac.wordpress.org/ticket/5447
33205 $the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
33206 }
33207
33208 if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
33209 $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
33210 $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
33211 // forwards compatibility as above
33212 $the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
33213 }
33214
33215 echo $the_list;
33216 }
33217
33218 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
33219
33220 ?>
33221 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
33222 <!-- It contains information about your blog's posts, comments, and categories. -->
33223 <!-- You may use this file to transfer that content from one site to another. -->
33224 <!-- This file is not intended to serve as a complete backup of your blog. -->
33225
33226 <!-- To import this information into a WordPress blog follow these steps. -->
33227 <!-- 1. Log into that blog as an administrator. -->
33228 <!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
33229 <!-- 3. Choose "WordPress" from the list. -->
33230 <!-- 4. Upload this file using the form provided on that page. -->
33231 <!-- 5. You will first be asked to map the authors in this export file to users -->
33232 <!-- on the blog. For each author, you may choose to map to an -->
33233 <!-- existing user on the blog or to create a new user -->
33234 <!-- 6. WordPress will then import each of the posts, comments, and categories -->
33235 <!-- contained in this file into your blog -->
33236
33237 <?php the_generator('export');?>
33238 <rss version="2.0"
33239 xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
33240 xmlns:content="http://purl.org/rss/1.0/modules/content/"
33241 xmlns:wfw="http://wellformedweb.org/CommentAPI/"
33242 xmlns:dc="http://purl.org/dc/elements/1.1/"
33243 xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
33244 >
33245
33246 <channel>
33247 <title><?php bloginfo_rss('name'); ?></title>
33248 <link><?php bloginfo_rss('url') ?></link>
33249 <description><?php bloginfo_rss("description") ?></description>
33250 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
33251 <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
33252 <language><?php echo get_option('rss_language'); ?></language>
33253 <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
33254 <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
33255 <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
33256 <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
33257 <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>
33258 <?php endforeach; endif; ?>
33259 <?php if ( $tags ) : foreach ( $tags as $t ) : ?>
33260 <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
33261 <?php endforeach; endif; ?>
33262 <?php do_action('rss2_head'); ?>
33263 <?php if ($post_ids) {
33264 global $wp_query;
33265 $wp_query->in_the_loop = true; // Fake being in the loop.
33266 // fetch 20 posts at a time rather than loading the entire table into memory
33267 while ( $next_posts = array_splice($post_ids, 0, 20) ) {
33268 $where = "WHERE ID IN (".join(',', $next_posts).")";
33269 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
33270 foreach ($posts as $post) {
33271 // Don't export revisions. They bloat the export.
33272 if ( 'revision' == $post->post_type )
33273 continue;
33274 setup_postdata($post); ?>
33275 <item>
33276 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
33277 <link><?php the_permalink_rss() ?></link>
33278 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
33279 <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
33280 <?php wxr_post_taxonomy() ?>
33281
33282 <guid isPermaLink="false"><?php the_guid(); ?></guid>
33283 <description></description>
33284 <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
33285 <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
33286 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
33287 <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
33288 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
33289 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
33290 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
33291 <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
33292 <wp:status><?php echo $post->post_status; ?></wp:status>
33293 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
33294 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
33295 <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
33296 <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
33297 <?php
33298 if ($post->post_type == 'attachment') { ?>
33299 <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
33300 <?php } ?>
33301 <?php
33302 $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
33303 if ( $postmeta ) {
33304 ?>
33305 <?php foreach( $postmeta as $meta ) { ?>
33306 <wp:postmeta>
33307 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
33308 <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
33309 </wp:postmeta>
33310 <?php } ?>
33311 <?php } ?>
33312 <?php
33313 $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
33314 if ( $comments ) { foreach ( $comments as $c ) { ?>
33315 <wp:comment>
33316 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
33317 <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
33318 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
33319 <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
33320 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
33321 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
33322 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
33323 <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
33324 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
33325 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
33326 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
33327 <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
33328 </wp:comment>
33329 <?php } } ?>
33330 </item>
33331 <?php } } } ?>
33332 </channel>
33333 </rss>
33334 <?php
33335 }
33336
33337 ?>