web/wp-admin/includes/export.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     9 /**
     9 /**
    10  * Version number for the export format.
    10  * Version number for the export format.
    11  *
    11  *
    12  * Bump this when something changes that might affect compatibility.
    12  * Bump this when something changes that might affect compatibility.
    13  *
    13  *
    14  * @since unknown
    14  * @since 2.5.0
    15  * @var string
       
    16  */
    15  */
    17 define('WXR_VERSION', '1.0');
    16 define( 'WXR_VERSION', '1.2' );
    18 
    17 
    19 /**
    18 /**
    20  * {@internal Missing Short Description}}
    19  * Generates the WXR export file for download
    21  *
    20  *
    22  * @since unknown
    21  * @since 2.1.0
    23  *
    22  *
    24  * @param unknown_type $author
    23  * @param array $args Filters defining what should be included in the export
    25  */
    24  */
    26 function export_wp($author='') {
    25 function export_wp( $args = array() ) {
    27 global $wpdb, $post_ids, $post, $wp_taxonomies;
    26 	global $wpdb, $post;
    28 
    27 
    29 do_action('export_wp');
    28 	$defaults = array( 'content' => 'all', 'author' => false, 'category' => false,
    30 
    29 		'start_date' => false, 'end_date' => false, 'status' => false,
    31 $filename = 'wordpress.' . date('Y-m-d') . '.xml';
    30 	);
    32 
    31 	$args = wp_parse_args( $args, $defaults );
    33 header('Content-Description: File Transfer');
    32 
    34 header("Content-Disposition: attachment; filename=$filename");
    33 	do_action( 'export_wp' );
    35 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    34 
    36 
    35 	$sitename = sanitize_key( get_bloginfo( 'name' ) );
    37 $where = '';
    36 	if ( ! empty($sitename) ) $sitename .= '.';
    38 if ( $author and $author != 'all' ) {
    37 	$filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
    39 	$author_id = (int) $author;
    38 
    40 	$where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
    39 	header( 'Content-Description: File Transfer' );
    41 }
    40 	header( 'Content-Disposition: attachment; filename=' . $filename );
    42 
    41 	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
    43 // grab a snapshot of post IDs, just in case it changes during the export
    42 
    44 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    43 	if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
    45 
    44 		$ptype = get_post_type_object( $args['content'] );
    46 $categories = (array) get_categories('get=all');
    45 		if ( ! $ptype->can_export )
    47 $tags = (array) get_tags('get=all');
    46 			$args['content'] = 'post';
    48 
    47 
    49 $custom_taxonomies = $wp_taxonomies;
    48 		$where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
    50 unset($custom_taxonomies['category']);
    49 	} else {
    51 unset($custom_taxonomies['post_tag']);
    50 		$post_types = get_post_types( array( 'can_export' => true ) );
    52 unset($custom_taxonomies['link_category']);
    51 		$esses = array_fill( 0, count($post_types), '%s' );
    53 $custom_taxonomies = array_keys($custom_taxonomies);
    52 		$where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
    54 $terms = (array) get_terms($custom_taxonomies, 'get=all');
    53 	}
    55 
    54 
    56 /**
    55 	if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) )
    57  * {@internal Missing Short Description}}
    56 		$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] );
    58  *
       
    59  * @since unknown
       
    60  *
       
    61  * @param unknown_type $categories
       
    62  */
       
    63 function wxr_missing_parents($categories) {
       
    64 	if ( !is_array($categories) || empty($categories) )
       
    65 		return array();
       
    66 
       
    67 	foreach ( $categories as $category )
       
    68 		$parents[$category->term_id] = $category->parent;
       
    69 
       
    70 	$parents = array_unique(array_diff($parents, array_keys($parents)));
       
    71 
       
    72 	if ( $zero = array_search('0', $parents) )
       
    73 		unset($parents[$zero]);
       
    74 
       
    75 	return $parents;
       
    76 }
       
    77 
       
    78 while ( $parents = wxr_missing_parents($categories) ) {
       
    79 	$found_parents = get_categories("include=" . join(', ', $parents));
       
    80 	if ( is_array($found_parents) && count($found_parents) )
       
    81 		$categories = array_merge($categories, $found_parents);
       
    82 	else
    57 	else
    83 		break;
    58 		$where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
    84 }
    59 
    85 
    60 	$join = '';
    86 // Put them in order to be inserted with no child going before its parent
    61 	if ( $args['category'] && 'post' == $args['content'] ) {
    87 $pass = 0;
    62 		if ( $term = term_exists( $args['category'], 'category' ) ) {
    88 $passes = 1000 + count($categories);
    63 			$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
    89 while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
    64 			$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
    90 	if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
    65 		}
    91 		$cats[$cat->term_id] = $cat;
    66 	}
    92 	} else {
    67 
    93 		$categories[] = $cat;
    68 	if ( 'post' == $args['content'] || 'page' == $args['content'] ) {
    94 	}
    69 		if ( $args['author'] )
    95 }
    70 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
    96 unset($categories);
    71 
    97 
    72 		if ( $args['start_date'] )
    98 /**
    73 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
    99  * Place string in CDATA tag.
    74 
   100  *
    75 		if ( $args['end_date'] )
   101  * @since unknown
    76 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) );
   102  *
    77 	}
   103  * @param string $str String to place in XML CDATA tag.
    78 
   104  */
    79 	// grab a snapshot of post IDs, just in case it changes during the export
   105 function wxr_cdata($str) {
    80 	$post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
   106 	if ( seems_utf8($str) == false )
    81 
   107 		$str = utf8_encode($str);
    82 	// get the requested terms ready, empty unless posts filtered by category or all content
   108 
    83 	$cats = $tags = $terms = array();
   109 	// $str = ent2ncr(esc_html($str));
    84 	if ( isset( $term ) && $term ) {
   110 
    85 		$cat = get_term( $term['term_id'], 'category' );
   111 	$str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
    86 		$cats = array( $cat->term_id => $cat );
   112 
    87 		unset( $term, $cat );
   113 	return $str;
    88 	} else if ( 'all' == $args['content'] ) {
   114 }
    89 		$categories = (array) get_categories( array( 'get' => 'all' ) );
   115 
    90 		$tags = (array) get_tags( array( 'get' => 'all' ) );
   116 /**
    91 
   117  * {@internal Missing Short Description}}
    92 		$custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
   118  *
    93 		$custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
   119  * @since unknown
    94 
   120  *
    95 		// put categories in order with no child going before its parent
   121  * @return string Site URL.
    96 		while ( $cat = array_shift( $categories ) ) {
   122  */
    97 			if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) )
   123 function wxr_site_url() {
    98 				$cats[$cat->term_id] = $cat;
   124 	global $current_site;
    99 			else
   125 
   100 				$categories[] = $cat;
   126 	// mu: the base url
   101 		}
   127 	if ( isset($current_site->domain) ) {
   102 
   128 		return 'http://'.$current_site->domain.$current_site->path;
   103 		// put terms in order with no child going before its parent
   129 	}
   104 		while ( $t = array_shift( $custom_terms ) ) {
   130 	// wp: the blog url
   105 			if ( $t->parent == 0 || isset( $terms[$t->parent] ) )
   131 	else {
   106 				$terms[$t->term_id] = $t;
   132 		return get_bloginfo_rss('url');
   107 			else
   133 	}
   108 				$custom_terms[] = $t;
   134 }
   109 		}
   135 
   110 
   136 /**
   111 		unset( $categories, $custom_taxonomies, $custom_terms );
   137  * {@internal Missing Short Description}}
   112 	}
   138  *
   113 
   139  * @since unknown
   114 	/**
   140  *
   115 	 * Wrap given string in XML CDATA tag.
   141  * @param object $c Category Object
   116 	 *
   142  */
   117 	 * @since 2.1.0
   143 function wxr_cat_name($c) {
   118 	 *
   144 	if ( empty($c->name) )
   119 	 * @param string $str String to wrap in XML CDATA tag.
   145 		return;
   120 	 * @return string
   146 
   121 	 */
   147 	echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
   122 	function wxr_cdata( $str ) {
   148 }
   123 		if ( seems_utf8( $str ) == false )
   149 
   124 			$str = utf8_encode( $str );
   150 /**
   125 
   151  * {@internal Missing Short Description}}
   126 		// $str = ent2ncr(esc_html($str));
   152  *
   127 		$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
   153  * @since unknown
   128 
   154  *
   129 		return $str;
   155  * @param object $c Category Object
   130 	}
   156  */
   131 
   157 function wxr_category_description($c) {
   132 	/**
   158 	if ( empty($c->description) )
   133 	 * Return the URL of the site
   159 		return;
   134 	 *
   160 
   135 	 * @since 2.5.0
   161 	echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
   136 	 *
   162 }
   137 	 * @return string Site URL.
   163 
   138 	 */
   164 /**
   139 	function wxr_site_url() {
   165  * {@internal Missing Short Description}}
   140 		// ms: the base url
   166  *
   141 		if ( is_multisite() )
   167  * @since unknown
   142 			return network_home_url();
   168  *
   143 		// wp: the blog url
   169  * @param object $t Tag Object
   144 		else
   170  */
   145 			return get_bloginfo_rss( 'url' );
   171 function wxr_tag_name($t) {
   146 	}
   172 	if ( empty($t->name) )
   147 
   173 		return;
   148 	/**
   174 
   149 	 * Output a cat_name XML tag from a given category object
   175 	echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
   150 	 *
   176 }
   151 	 * @since 2.1.0
   177 
   152 	 *
   178 /**
   153 	 * @param object $category Category Object
   179  * {@internal Missing Short Description}}
   154 	 */
   180  *
   155 	function wxr_cat_name( $category ) {
   181  * @since unknown
   156 		if ( empty( $category->name ) )
   182  *
   157 			return;
   183  * @param object $t Tag Object
   158 
   184  */
   159 		echo '<wp:cat_name>' . wxr_cdata( $category->name ) . '</wp:cat_name>';
   185 function wxr_tag_description($t) {
   160 	}
   186 	if ( empty($t->description) )
   161 
   187 		return;
   162 	/**
   188 
   163 	 * Output a category_description XML tag from a given category object
   189 	echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
   164 	 *
   190 }
   165 	 * @since 2.1.0
   191 
   166 	 *
   192 /**
   167 	 * @param object $category Category Object
   193  * {@internal Missing Short Description}}
   168 	 */
   194  *
   169 	function wxr_category_description( $category ) {
   195  * @since unknown
   170 		if ( empty( $category->description ) )
   196  *
   171 			return;
   197  * @param object $t Term Object
   172 
   198  */
   173 		echo '<wp:category_description>' . wxr_cdata( $category->description ) . '</wp:category_description>';
   199 function wxr_term_name($t) {
   174 	}
   200 	if ( empty($t->name) )
   175 
   201 		return;
   176 	/**
   202 
   177 	 * Output a tag_name XML tag from a given tag object
   203 	echo '<wp:term_name>' . wxr_cdata($t->name) . '</wp:term_name>';
   178 	 *
   204 }
   179 	 * @since 2.3.0
   205 
   180 	 *
   206 /**
   181 	 * @param object $tag Tag Object
   207  * {@internal Missing Short Description}}
   182 	 */
   208  *
   183 	function wxr_tag_name( $tag ) {
   209  * @since unknown
   184 		if ( empty( $tag->name ) )
   210  *
   185 			return;
   211  * @param object $t Term Object
   186 
   212  */
   187 		echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . '</wp:tag_name>';
   213 function wxr_term_description($t) {
   188 	}
   214 	if ( empty($t->description) )
   189 
   215 		return;
   190 	/**
   216 
   191 	 * Output a tag_description XML tag from a given tag object
   217 	echo '<wp:term_description>' . wxr_cdata($t->description) . '</wp:term_description>';
   192 	 *
   218 }
   193 	 * @since 2.3.0
   219 
   194 	 *
   220 /**
   195 	 * @param object $tag Tag Object
   221  * {@internal Missing Short Description}}
   196 	 */
   222  *
   197 	function wxr_tag_description( $tag ) {
   223  * @since unknown
   198 		if ( empty( $tag->description ) )
   224  */
   199 			return;
   225 function wxr_post_taxonomy() {
   200 
   226 	$categories = get_the_category();
   201 		echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . '</wp:tag_description>';
   227 	$tags = get_the_tags();
   202 	}
   228 	$the_list = '';
   203 
   229 	$filter = 'rss';
   204 	/**
   230 
   205 	 * Output a term_name XML tag from a given term object
   231 	if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
   206 	 *
   232 		$cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
   207 	 * @since 2.9.0
   233 		// for backwards compatibility
   208 	 *
   234 		$the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
   209 	 * @param object $term Term Object
   235 		// forwards compatibility: use a unique identifier for each cat to avoid clashes
   210 	 */
   236 		// http://trac.wordpress.org/ticket/5447
   211 	function wxr_term_name( $term ) {
   237 		$the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
   212 		if ( empty( $term->name ) )
   238 	}
   213 			return;
   239 
   214 
   240 	if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
   215 		echo '<wp:term_name>' . wxr_cdata( $term->name ) . '</wp:term_name>';
   241 		$tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
   216 	}
   242 		$the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
   217 
   243 		// forwards compatibility as above
   218 	/**
   244 		$the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
   219 	 * Output a term_description XML tag from a given term object
   245 	}
   220 	 *
   246 
   221 	 * @since 2.9.0
   247 	echo $the_list;
   222 	 *
   248 }
   223 	 * @param object $term Term Object
   249 
   224 	 */
   250 echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
   225 	function wxr_term_description( $term ) {
   251 
   226 		if ( empty( $term->description ) )
   252 ?>
   227 			return;
   253 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
   228 
   254 <!-- It contains information about your blog's posts, comments, and categories. -->
   229 		echo '<wp:term_description>' . wxr_cdata( $term->description ) . '</wp:term_description>';
       
   230 	}
       
   231 
       
   232 	/**
       
   233 	 * Output list of authors with posts
       
   234 	 *
       
   235 	 * @since 3.1.0
       
   236 	 */
       
   237 	function wxr_authors_list() {
       
   238 		global $wpdb;
       
   239 
       
   240 		$authors = array();
       
   241 		$results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts" );
       
   242 		foreach ( (array) $results as $result )
       
   243 			$authors[] = get_userdata( $result->post_author );
       
   244 
       
   245 		$authors = array_filter( $authors );
       
   246 
       
   247 		foreach ( $authors as $author ) {
       
   248 			echo "\t<wp:author>";
       
   249 			echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
       
   250 			echo '<wp:author_login>' . $author->user_login . '</wp:author_login>';
       
   251 			echo '<wp:author_email>' . $author->user_email . '</wp:author_email>';
       
   252 			echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
       
   253 			echo '<wp:author_first_name>' . wxr_cdata( $author->user_firstname ) . '</wp:author_first_name>';
       
   254 			echo '<wp:author_last_name>' . wxr_cdata( $author->user_lastname ) . '</wp:author_last_name>';
       
   255 			echo "</wp:author>\n";
       
   256 		}
       
   257 	}
       
   258 
       
   259 	/**
       
   260 	 * Ouput all navigation menu terms
       
   261 	 *
       
   262 	 * @since 3.1.0
       
   263 	 */
       
   264 	function wxr_nav_menu_terms() {
       
   265 		$nav_menus = wp_get_nav_menus();
       
   266 		if ( empty( $nav_menus ) || ! is_array( $nav_menus ) )
       
   267 			return;
       
   268 
       
   269 		foreach ( $nav_menus as $menu ) {
       
   270 			echo "\t<wp:term><wp:term_id>{$menu->term_id}</wp:term_id><wp:term_taxonomy>nav_menu</wp:term_taxonomy><wp:term_slug>{$menu->slug}</wp:term_slug>";
       
   271 			wxr_term_name( $menu );
       
   272 			echo "</wp:term>\n";
       
   273 		}
       
   274 	}
       
   275 
       
   276 	/**
       
   277 	 * Output list of taxonomy terms, in XML tag format, associated with a post
       
   278 	 *
       
   279 	 * @since 2.3.0
       
   280 	 */
       
   281 	function wxr_post_taxonomy() {
       
   282 		global $post;
       
   283 
       
   284 		$taxonomies = get_object_taxonomies( $post->post_type );
       
   285 		if ( empty( $taxonomies ) )
       
   286 			return;
       
   287 		$terms = wp_get_object_terms( $post->ID, $taxonomies );
       
   288 
       
   289 		foreach ( (array) $terms as $term ) {
       
   290 			echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
       
   291 		}
       
   292 	}
       
   293 
       
   294 	function wxr_filter_postmeta( $return_me, $meta_key ) {
       
   295 		if ( '_edit_lock' == $meta_key )
       
   296 			$return_me = true;
       
   297 		return $return_me;
       
   298 	}
       
   299 	add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 );
       
   300 
       
   301 	echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
       
   302 
       
   303 	?>
       
   304 <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
       
   305 <!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
   255 <!-- You may use this file to transfer that content from one site to another. -->
   306 <!-- You may use this file to transfer that content from one site to another. -->
   256 <!-- This file is not intended to serve as a complete backup of your blog. -->
   307 <!-- This file is not intended to serve as a complete backup of your site. -->
   257 
   308 
   258 <!-- To import this information into a WordPress blog follow these steps. -->
   309 <!-- To import this information into a WordPress site follow these steps: -->
   259 <!-- 1. Log in to that blog as an administrator. -->
   310 <!-- 1. Log in to that site as an administrator. -->
   260 <!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
   311 <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
   261 <!-- 3. Choose "WordPress" from the list. -->
   312 <!-- 3. Install the "WordPress" importer from the list. -->
   262 <!-- 4. Upload this file using the form provided on that page. -->
   313 <!-- 4. Activate & Run Importer. -->
   263 <!-- 5. You will first be asked to map the authors in this export file to users -->
   314 <!-- 5. Upload this file using the form provided on that page. -->
   264 <!--    on the blog.  For each author, you may choose to map to an -->
   315 <!-- 6. You will first be asked to map the authors in this export file to users -->
   265 <!--    existing user on the blog or to create a new user -->
   316 <!--    on the site. For each author, you may choose to map to an -->
   266 <!-- 6. WordPress will then import each of the posts, comments, and categories -->
   317 <!--    existing user on the site or to create a new user. -->
   267 <!--    contained in this file into your blog -->
   318 <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
   268 
   319 <!--    contained in this file into your site. -->
   269 <?php the_generator('export');?>
   320 
       
   321 <?php the_generator( 'export' ); ?>
   270 <rss version="2.0"
   322 <rss version="2.0"
   271 	xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
   323 	xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
   272 	xmlns:content="http://purl.org/rss/1.0/modules/content/"
   324 	xmlns:content="http://purl.org/rss/1.0/modules/content/"
   273 	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   325 	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   274 	xmlns:dc="http://purl.org/dc/elements/1.1/"
   326 	xmlns:dc="http://purl.org/dc/elements/1.1/"
   275 	xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
   327 	xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
   276 >
   328 >
   277 
   329 
   278 <channel>
   330 <channel>
   279 	<title><?php bloginfo_rss('name'); ?></title>
   331 	<title><?php bloginfo_rss( 'name' ); ?></title>
   280 	<link><?php bloginfo_rss('url') ?></link>
   332 	<link><?php bloginfo_rss( 'url' ); ?></link>
   281 	<description><?php bloginfo_rss("description") ?></description>
   333 	<description><?php bloginfo_rss( 'description' ); ?></description>
   282 	<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
   334 	<pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate>
   283 	<generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
   335 	<language><?php bloginfo_rss( 'language' ); ?></language>
   284 	<language><?php echo get_option('rss_language'); ?></language>
       
   285 	<wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
   336 	<wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
   286 	<wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
   337 	<wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
   287 	<wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
   338 	<wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
   288 <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
   339 
   289 	<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>
   340 <?php wxr_authors_list(); ?>
   290 <?php endforeach; endif; ?>
   341 
   291 <?php if ( $tags ) : foreach ( $tags as $t ) : ?>
   342 <?php foreach ( $cats as $c ) : ?>
   292 	<wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
   343 	<wp:category><wp:term_id><?php echo $c->term_id ?></wp:term_id><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->slug : ''; ?></wp:category_parent><?php wxr_cat_name( $c ); ?><?php wxr_category_description( $c ); ?></wp:category>
   293 <?php endforeach; endif; ?>
   344 <?php endforeach; ?>
   294 <?php if ( $terms ) : foreach ( $terms as $t ) : ?>
   345 <?php foreach ( $tags as $t ) : ?>
   295 	<wp:term><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $custom_taxonomies[$t->parent]->name : ''; ?></wp:term_parent><?php wxr_term_name($t); ?><?php wxr_term_description($t); ?></wp:term>
   346 	<wp:tag><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name( $t ); ?><?php wxr_tag_description( $t ); ?></wp:tag>
   296 <?php endforeach; endif; ?>
   347 <?php endforeach; ?>
   297 	<?php do_action('rss2_head'); ?>
   348 <?php foreach ( $terms as $t ) : ?>
   298 	<?php if ($post_ids) {
   349 	<wp:term><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $terms[$t->parent]->slug : ''; ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term>
   299 		global $wp_query;
   350 <?php endforeach; ?>
   300 		$wp_query->in_the_loop = true;  // Fake being in the loop.
   351 <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
   301 		// fetch 20 posts at a time rather than loading the entire table into memory
   352 
   302 		while ( $next_posts = array_splice($post_ids, 0, 20) ) {
   353 	<?php do_action( 'rss2_head' ); ?>
   303 			$where = "WHERE ID IN (".join(',', $next_posts).")";
   354 
   304 			$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
   355 <?php if ( $post_ids ) {
   305 				foreach ($posts as $post) {
   356 	global $wp_query;
   306 			// Don't export revisions.  They bloat the export.
   357 	$wp_query->in_the_loop = true; // Fake being in the loop.
   307 			if ( 'revision' == $post->post_type )
   358 
       
   359 	// fetch 20 posts at a time rather than loading the entire table into memory
       
   360 	while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
       
   361 	$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
       
   362 	$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
       
   363 
       
   364 	// Begin Loop
       
   365 	foreach ( $posts as $post ) {
       
   366 		setup_postdata( $post );
       
   367 		$is_sticky = is_sticky( $post->ID ) ? 1 : 0;
       
   368 ?>
       
   369 	<item>
       
   370 		<title><?php echo apply_filters( 'the_title_rss', $post->post_title ); ?></title>
       
   371 		<link><?php the_permalink_rss() ?></link>
       
   372 		<pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
       
   373 		<dc:creator><?php echo get_the_author_meta( 'login' ); ?></dc:creator>
       
   374 		<guid isPermaLink="false"><?php esc_url( the_guid() ); ?></guid>
       
   375 		<description></description>
       
   376 		<content:encoded><?php echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ); ?></content:encoded>
       
   377 		<excerpt:encoded><?php echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ); ?></excerpt:encoded>
       
   378 		<wp:post_id><?php echo $post->ID; ?></wp:post_id>
       
   379 		<wp:post_date><?php echo $post->post_date; ?></wp:post_date>
       
   380 		<wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
       
   381 		<wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
       
   382 		<wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
       
   383 		<wp:post_name><?php echo $post->post_name; ?></wp:post_name>
       
   384 		<wp:status><?php echo $post->post_status; ?></wp:status>
       
   385 		<wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
       
   386 		<wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
       
   387 		<wp:post_type><?php echo $post->post_type; ?></wp:post_type>
       
   388 		<wp:post_password><?php echo $post->post_password; ?></wp:post_password>
       
   389 		<wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky>
       
   390 <?php	if ( $post->post_type == 'attachment' ) : ?>
       
   391 		<wp:attachment_url><?php echo wp_get_attachment_url( $post->ID ); ?></wp:attachment_url>
       
   392 <?php 	endif; ?>
       
   393 <?php 	wxr_post_taxonomy(); ?>
       
   394 <?php	$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
       
   395 		foreach ( $postmeta as $meta ) :
       
   396 			if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) )
   308 				continue;
   397 				continue;
   309 			setup_postdata($post);
   398 		?>
   310 
   399 		<wp:postmeta>
   311 			$is_sticky = 0;
   400 			<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
   312 			if ( is_sticky( $post->ID ) )
   401 			<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   313 				$is_sticky = 1;
   402 		</wp:postmeta>
   314 
   403 <?php	endforeach; ?>
   315 ?>
   404 <?php	$comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
   316 <item>
   405 		foreach ( $comments as $c ) : ?>
   317 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
   406 		<wp:comment>
   318 <link><?php the_permalink_rss() ?></link>
   407 			<wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
   319 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
   408 			<wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
   320 <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
   409 			<wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
   321 <?php wxr_post_taxonomy() ?>
   410 			<wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
   322 
   411 			<wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
   323 <guid isPermaLink="false"><?php the_guid(); ?></guid>
   412 			<wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
   324 <description></description>
   413 			<wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
   325 <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
   414 			<wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content>
   326 <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
   415 			<wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
   327 <wp:post_id><?php echo $post->ID; ?></wp:post_id>
   416 			<wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
   328 <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
   417 			<wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
   329 <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
   418 			<wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
   330 <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
   419 <?php		$c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
   331 <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
   420 			foreach ( $c_meta as $meta ) : ?>
   332 <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
   421 			<wp:commentmeta>
   333 <wp:status><?php echo $post->post_status; ?></wp:status>
   422 				<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
   334 <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
   423 				<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   335 <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
   424 			</wp:commentmeta>
   336 <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
   425 <?php		endforeach; ?>
   337 <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
   426 		</wp:comment>
   338 <wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky>
   427 <?php	endforeach; ?>
       
   428 	</item>
   339 <?php
   429 <?php
   340 if ($post->post_type == 'attachment') { ?>
   430 	}
   341 <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
   431 	}
   342 <?php } ?>
   432 } ?>
   343 <?php
       
   344 $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
       
   345 if ( $postmeta ) {
       
   346 ?>
       
   347 <?php foreach( $postmeta as $meta ) { ?>
       
   348 <wp:postmeta>
       
   349 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
       
   350 <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
       
   351 </wp:postmeta>
       
   352 <?php } ?>
       
   353 <?php } ?>
       
   354 <?php
       
   355 $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
       
   356 if ( $comments ) { foreach ( $comments as $c ) { ?>
       
   357 <wp:comment>
       
   358 <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
       
   359 <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
       
   360 <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
       
   361 <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
       
   362 <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
       
   363 <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
       
   364 <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
       
   365 <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
       
   366 <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
       
   367 <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
       
   368 <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
       
   369 <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
       
   370 </wp:comment>
       
   371 <?php } } ?>
       
   372 	</item>
       
   373 <?php } } } ?>
       
   374 </channel>
   433 </channel>
   375 </rss>
   434 </rss>
   376 <?php
   435 <?php
   377 }
   436 }
   378 
       
   379 ?>