Ticket #15197: 15197.export-filtering.002.diff
File 15197.export-filtering.002.diff, 15.4 KB (added by , 14 years ago) |
---|
-
wp-admin/export.php
16 16 require_once('./includes/export.php'); 17 17 $title = __('Export'); 18 18 19 add_contextual_help( $current_screen,19 add_contextual_help( $current_screen, 20 20 '<p>' . __('You can export a file of your site’s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can set filters to have the WXR file only include a certain date, author, category, tag, all posts or all pages, certain publishing statuses.') . '</p>' . 21 21 '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>' . 22 22 '<p><strong>' . __('For more information:') . '</strong></p>' . … … 25 25 ); 26 26 27 27 if ( isset( $_GET['download'] ) ) { 28 export_wp(); 28 $args = array(); 29 30 if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) { 31 $args['content'] = 'all'; 32 } else if ( 'posts' == $_GET['content'] ) { 33 $args['content'] = 'post'; 34 35 if ( $_GET['cat'] ) 36 $args['category'] = (int) $_GET['cat']; 37 38 if ( $_GET['post_author'] ) 39 $args['author'] = (int) $_GET['post_author']; 40 41 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) { 42 $args['start_date'] = $_GET['post_start_date']; 43 $args['end_date'] = $_GET['post_end_date']; 44 } 45 46 if ( $_GET['post_status'] ) 47 $args['status'] = $_GET['post_status']; 48 } else if ( 'pages' == $_GET['content'] ) { 49 $args['content'] = 'page'; 50 51 if ( $_GET['page_author'] ) 52 $args['author'] = (int) $_GET['page_author']; 53 54 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) { 55 $args['start_date'] = $_GET['page_start_date']; 56 $args['end_date'] = $_GET['page_end_date']; 57 } 58 59 if ( $_GET['page_status'] ) 60 $args['status'] = $_GET['page_status']; 61 } else { 62 $args['content'] = $_GET['content']; 63 } 64 65 export_wp( $args ); 29 66 die(); 30 67 } 31 68 32 69 require_once ('admin-header.php'); 33 70 34 $dateoptions = $edateoptions = ''; 35 $types = "'" . implode("', '", get_post_types( array( 'public' => true, 'can_export' => true ), 'names' )) . "'"; 36 $stati = "'" . implode("', '", get_post_stati( array( 'internal' => false ), 'names' )) . "'"; 37 if ( $monthyears = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, YEAR(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `eyear`, MONTH(DATE_ADD(post_date, INTERVAL 1 MONTH)) AS `emonth` FROM $wpdb->posts WHERE post_type IN ($types) AND post_status IN ($stati) ORDER BY post_date ASC ") ) { 38 foreach ( $monthyears as $k => $monthyear ) 39 $monthyears[$k]->lmonth = $wp_locale->get_month( $monthyear->month, 2 ); 40 for( $s = 0, $e = count( $monthyears ) - 1; $e >= 0; $s++, $e-- ) { 41 $dateoptions .= "\t<option value=\"" . $monthyears[$s]->year . '-' . zeroise( $monthyears[$s]->month, 2 ) . '">' . $monthyears[$s]->lmonth . ' ' . $monthyears[$s]->year . "</option>\n"; 42 $edateoptions .= "\t<option value=\"" . $monthyears[$e]->eyear . '-' . zeroise( $monthyears[$e]->emonth, 2 ) . '">' . $monthyears[$e]->lmonth . ' ' . $monthyears[$e]->year . "</option>\n"; 71 function export_date_options() { 72 global $wpdb, $wp_locale; 73 74 $months = $wpdb->get_results( " 75 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month 76 FROM $wpdb->posts 77 WHERE post_type = 'post' AND post_status != 'auto-draft' 78 ORDER BY post_date DESC 79 " ); 80 81 $month_count = count( $months ); 82 if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) 83 return; 84 85 foreach ( $months as $date ) { 86 if ( 0 == $date->year ) 87 continue; 88 89 $month = zeroise( $date->month, 2 ); 90 echo '<option value="' . $date->year . '-' . $month . '" />' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>'; 43 91 } 44 92 } 45 46 93 ?> 47 94 48 95 <div class="wrap"> … … 51 98 52 99 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p> 53 100 <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p> 54 <p><?php _e('Once you’ve saved the download file, you can use the Import function on another WordPress site to import this site.'); ?></p> 55 <form action="" method="get"> 56 <?php submit_button( __('Download Export File'), 'button' ); ?> 101 <p><?php _e('Once you’ve saved the download file, you can use the Import function in another WordPress installation to import this site.'); ?></p> 102 103 <h3><?php _e( 'Choose what to export' ); ?></h3> 104 <form action="" method="get" id="export-filters"> 57 105 <input type="hidden" name="download" value="true" /> 58 </p> 106 <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label> 107 <span class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></span></p> 108 109 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p> 110 <ul id="post-filters" class="export-filters"> 111 <li> 112 <label><?php _e( 'Categories:' ); ?></label> 113 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?> 114 </li> 115 <li> 116 <label><?php _e( 'Authors:' ); ?></label> 117 <?php wp_dropdown_users( array( 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?> 118 </li> 119 <li> 120 <label><?php _e( 'Date range:' ); ?></label> 121 <select name="post_start_date"> 122 <option value="0"><?php _e( 'Start Date' ); ?></option> 123 <?php export_date_options(); ?> 124 </select> 125 <select name="post_end_date"> 126 <option value="0"><?php _e( 'End Date' ); ?></option> 127 <?php export_date_options(); ?> 128 </select> 129 </li> 130 <li> 131 <label><?php _e( 'Status:' ); ?></label> 132 <select name="post_status"> 133 <option value="0"><?php _e( 'All' ); ?></option> 134 <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' ); 135 foreach ( $post_stati as $status ) : ?> 136 <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> 137 <?php endforeach; ?> 138 </select> 139 </li> 140 </ul> 141 142 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p> 143 <ul id="page-filters" class="export-filters"> 144 <li> 145 <label><?php _e( 'Author:' ); ?></label> 146 <?php wp_dropdown_users( array( 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) ); ?> 147 </li> 148 <li> 149 <label><?php _e( 'Date range:' ); ?></label> 150 <select name="page_start_date"> 151 <option value="0"><?php _e( 'Start Date' ); ?></option> 152 <?php export_date_options(); ?> 153 </select> 154 <select name="page_end_date"> 155 <option value="0"><?php _e( 'End Date' ); ?></option> 156 <?php export_date_options(); ?> 157 </select> 158 </li> 159 <li> 160 <label><?php _e( 'Status:' ); ?></label> 161 <select name="page_status"> 162 <option value="0"><?php _e( 'All' ); ?></option> 163 <?php foreach ( $post_stati as $status ) : ?> 164 <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option> 165 <?php endforeach; ?> 166 </select> 167 </li> 168 </ul> 169 170 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?> 171 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p> 172 <?php endforeach; ?> 173 174 <?php submit_button( __('Download Export File'), 'secondary' ); ?> 59 175 </form> 60 176 </div> 61 177 62 <?php 63 64 65 include ('admin-footer.php'); 66 ?> 178 <?php include('admin-footer.php'); ?> -
wp-admin/includes/export.php
25 25 function export_wp( $args = array() ) { 26 26 global $wpdb, $post; 27 27 28 $defaults = array( 'content' => 'all', 'author' => false, 'category' => false, 29 'start_date' => false, 'end_date' => false, 'status' => false, 30 ); 31 $args = wp_parse_args( $args, $defaults ); 32 28 33 do_action( 'export_wp' ); 29 34 30 35 $sitename = sanitize_key( get_bloginfo( 'name' ) ); … … 35 40 header( 'Content-Disposition: attachment; filename=' . $filename ); 36 41 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); 37 42 38 // grab a snapshot of post IDs, just in case it changes during the export 39 $post_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type != 'revision' AND post_status != 'auto-draft' ORDER BY post_date_gmt ASC" ); 43 if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) { 44 $ptype = get_post_type_object( $args['content'] ); 45 if ( ! $ptype->can_export ) 46 $args['content'] = 'post'; 40 47 41 $categories = (array) get_categories( array( 'get' => 'all' ) ); 42 $tags = (array) get_tags( array( 'get' => 'all' ) ); 48 $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] ); 49 } else { 50 $post_types = get_post_types( array( 'can_export' => true ) ); 51 $esses = array_fill( 0, count($post_types), '%s' ); 52 $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (". implode(',',$esses) .")", $post_types ); 53 } 43 54 44 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 45 $taxonomy_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 55 if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) 56 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] ); 57 else 58 $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'"; 46 59 47 // put categories in order with no child going before its parent 48 $cats = array(); 49 while ( $cat = array_shift( $categories ) ) { 50 if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 51 $cats[$cat->term_id] = $cat; 52 else 53 $categories[] = $cat; 60 $join = ''; 61 if ( $args['category'] && 'post' == $args['content'] ) { 62 if ( $term = term_exists( $args['category'], 'category' ) ) { 63 $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)"; 64 $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_id'] ); 65 } 54 66 } 55 67 56 // put terms in order with no child going before its parent 57 $terms = array(); 58 while ( $t = array_shift( $taxonomy_terms ) ) { 59 if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) 60 $terms[$t->term_id] = $t; 61 else 62 $taxonomy_terms[] = $t; 68 if ( 'post' == $args['content'] || 'page' == $args['content'] ) { 69 if ( $args['author'] ) 70 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] ); 71 72 if ( $args['start_date'] ) 73 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) ); 74 75 if ( $args['end_date'] ) 76 $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime('+1 month', strtotime($args['end_date'])) ) ); 63 77 } 64 78 79 // grab a snapshot of post IDs, just in case it changes during the export 80 $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" ); 81 82 // get the requested terms ready, empty unless posts filtered by category or all content 83 $cats = $tags = $terms = array(); 84 if ( isset( $term ) && $term ) { 85 $cat = get_term( $term['term_id'], 'category' ); 86 $cats = array( $cat->term_id => $cat ); 87 unset( $term, $cat ); 88 } else if ( 'all' == $args['content'] ) { 89 $categories = (array) get_categories( array( 'get' => 'all' ) ); 90 $tags = (array) get_tags( array( 'get' => 'all' ) ); 91 92 $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) ); 93 $custom_terms = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) ); 94 95 // put categories in order with no child going before its parent 96 while ( $cat = array_shift( $categories ) ) { 97 if ( $cat->parent == 0 || isset( $cats[$cat->parent] ) ) 98 $cats[$cat->term_id] = $cat; 99 else 100 $categories[] = $cat; 101 } 102 103 // put terms in order with no child going before its parent 104 while ( $t = array_shift( $custom_terms ) ) { 105 if ( $t->parent == 0 || isset( $terms[$t->parent] ) ) 106 $terms[$t->term_id] = $t; 107 else 108 $custom_terms[] = $t; 109 } 110 111 unset( $categories, $custom_taxonomies, $custom_terms ); 112 } 113 65 114 /** 66 115 * Wrap given string in XML CDATA tag. 67 116 * … … 271 320 <title><?php bloginfo_rss( 'name' ); ?></title> 272 321 <link><?php bloginfo_rss( 'url' ); ?></link> 273 322 <description><?php bloginfo_rss( 'description' ); ?></description> 274 <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false); ?></pubDate>323 <pubDate><?php echo date( 'D, d M Y H:i:s +0000' ); ?></pubDate> 275 324 <language><?php echo get_option( 'rss_language' ); ?></language> 276 325 <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version> 277 326 <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url> … … 288 337 <?php foreach ( $terms as $t ) : ?> 289 338 <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> 290 339 <?php endforeach; ?> 291 <?php wxr_nav_menu_terms(); ?>340 <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?> 292 341 293 342 <?php do_action( 'rss2_head' ); ?> 294 343 … … 299 348 // fetch 20 posts at a time rather than loading the entire table into memory 300 349 while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) { 301 350 $where = "WHERE ID IN (" . join( ',', $next_posts ) . ")"; 302 $posts = $wpdb->get_results( "SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC" );351 $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" ); 303 352 304 353 // Begin Loop 305 354 foreach ( $posts as $post ) { … … 332 381 <?php endif; ?> 333 382 <?php wxr_post_taxonomy(); ?> 334 383 <?php $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) ); 335 if ( $postmeta ) : foreach( $postmeta as $meta ) : if ( $meta->meta_key != '_edit_lock' && $meta->meta_key != '_edit_last') : ?>384 if ( $postmeta ) : foreach( $postmeta as $meta ) : if ( $meta->meta_key != '_edit_lock' ) : ?> 336 385 <wp:postmeta> 337 386 <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key> 338 387 <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value> -
wp-includes/post.php
54 54 'hierarchical' => false, 55 55 'rewrite' => false, 56 56 'query_var' => false, 57 'can_export' => false,58 57 'show_in_nav_menus' => false, 59 58 ) ); 60 59 … … 71 70 'hierarchical' => false, 72 71 'rewrite' => false, 73 72 'query_var' => false, 73 'can_export' => false, 74 74 ) ); 75 75 76 76 register_post_type( 'nav_menu_item', array( -
wp-admin/css/wp-admin.dev.css
2513 2513 2514 2514 #front-page-warning, 2515 2515 #front-static-pages ul, 2516 ul.export-filters, 2516 2517 .inline-editor ul.cat-checklist ul, 2517 2518 .categorydiv ul.categorychecklist ul, 2518 2519 .customlinkdiv ul.categorychecklist ul,