Ticket #10317: export.2.diff
| File export.2.diff, 7.1 KB (added by wpmuguru, 3 years ago) |
|---|
-
wp-admin/includes/export.php
23 23 * 24 24 * @param unknown_type $author 25 25 */ 26 function export_wp($author='' ) {26 function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') { 27 27 global $wpdb, $post_ids, $post; 28 28 29 29 do_action('export_wp'); 30 30 31 $filename = 'wordpress.' . date('Y-m-d') . '.xml'; 31 if(strlen($start_date) > 4 && strlen($end_date) > 4) { 32 $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml'; 33 } else { 34 $filename = 'wordpress.' . date('Y-m-d') . '.xml'; 35 } 36 header('Content-Description: File Transfer'); 37 header("Content-Disposition: attachment; filename=$filename"); 38 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); 32 39 33 header('Content-Description: File Transfer'); 34 header("Content-Disposition: attachment; filename=$filename"); 35 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); 40 if ( $post_type and $post_type != 'all' ) { 41 $where = $wpdb->prepare("WHERE post_type = %s ", $post_type); 42 } else { 43 $where = "WHERE post_type != 'revision' "; 44 } 45 if ( $author and $author != 'all' ) { 46 $author_id = (int) $author; 47 $where .= $wpdb->prepare("AND post_author = %d ", $author_id); 48 } 49 if ( $start_date and $start_date != 'all' ) { 50 $where .= $wpdb->prepare("AND post_date >= %s ", $start_date); 51 } 52 if ( $end_date and $end_date != 'all' ) { 53 $where .= $wpdb->prepare("AND post_date < %s ", $end_date); 54 } 55 if ( $category and $category != 'all' and version_compare($wpdb->db_version(), '4.1', 'ge')) { 56 $taxomony_id = (int) $category; 57 $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . 58 "WHERE term_taxonomy_id = %d) ", $taxomony_id); 59 } 60 if ( $status and $status != 'all' ) { 61 $where .= $wpdb->prepare("AND post_status = %s ", $status); 62 } 36 63 37 $where = '';38 if ( $author and $author != 'all' ) {39 $author_id = (int) $author;40 $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);41 }42 43 64 // grab a snapshot of post IDs, just in case it changes during the export 44 65 $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 45 66 … … 265 286 $where = "WHERE ID IN (".join(',', $next_posts).")"; 266 287 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 267 288 foreach ($posts as $post) { 268 // Don't export revisions. They bloat the export.269 if ( 'revision' == $post->post_type )270 continue;271 289 setup_postdata($post); ?> 272 290 <item> 273 291 <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title> -
wp-admin/export.php
14 14 $title = __('Export'); 15 15 16 16 if ( isset( $_GET['download'] ) ) { 17 $author = isset($_GET['author']) ? $_GET['author'] : 'all'; 18 export_wp( $author ); 17 $author = isset($_GET['author']) ? $_GET['author'] : 'all'; 18 $category = isset($_GET['category']) ? $_GET['category'] : 'all'; 19 $post_type = isset($_GET['post_type']) ? wp_specialchars($_GET['post_type']) : 'all'; 20 $status = isset($_GET['status']) ? wp_specialchars($_GET['status']) : 'all'; 21 $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all'; 22 $mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all'; 23 $aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0; 24 $aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0; 25 if($mm_start != 'all' && $aa_start > 0) { 26 $start_date = sprintf( "%04d-%02d-%02d", $aa_start, $mm_start, 1 ); 27 } else { 28 $start_date = 'all'; 29 } 30 if($mm_end != 'all' && $aa_end > 0) { 31 if($mm_end == 12) { 32 $mm_end = 1; 33 $aa_end++; 34 } else { 35 $mm_end++; 36 } 37 $end_date = sprintf( "%04d-%02d-%02d", $aa_end, $mm_end, 1 ); 38 } else { 39 $end_date = 'all'; 40 } 41 export_wp( $author, $category, $post_type, $status, $start_date, $end_date ); 19 42 die(); 20 43 } 21 44 22 45 require_once ('admin-header.php'); 23 ?>24 46 47 $months = ""; 48 for ( $i = 1; $i < 13; $i++ ) { 49 $months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' . 50 $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n"; 51 } ?> 52 25 53 <div class="wrap"> 26 54 <?php screen_icon(); ?> 27 55 <h2><?php echo esc_html( $title ); ?></h2> … … 34 62 35 63 <table class="form-table"> 36 64 <tr> 65 <th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th> 66 <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?> 67 <select name="mm_start" id="mm_start"> 68 <option value="all" selected="selected"><?php _e('All Dates'); ?></option> 69 <?php echo $months; ?> 70 </select> <?php _e('Year'); ?> 71 <input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" /> 72 </td> 73 <td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?> 74 <select name="mm_end" id="mm_end"> 75 <option value="all" selected="selected"><?php _e('All Dates'); ?></option> 76 <?php echo $months; ?> 77 </select> <?php _e('Year'); ?> 78 <input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" /> 79 </td> 80 </tr> 81 <tr> 37 82 <th><label for="author"><?php _e('Restrict Author'); ?></label></th> 38 83 <td> 39 84 <select name="author" id="author"> … … 42 87 $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" ); 43 88 foreach ( $authors as $id ) { 44 89 $o = get_userdata( $id ); 45 echo "<option value=' " . esc_attr($o->ID) . "'>$o->display_name</option>";90 echo "<option value='{$o->ID}'>{$o->display_name}</option>\n"; 46 91 } 47 92 ?> 48 93 </select> 49 94 </td> 50 95 </tr> 96 <?php if(version_compare($wpdb->db_version(), '4.1', 'ge')) { ?> 97 <tr> 98 <th><label for="category"><?php _e('Restrict Category'); ?></label></th> 99 <td> 100 <select name="category" id="category"> 101 <option value="all" selected="selected"><?php _e('All Categories'); ?></option> 102 <?php 103 $categories = (array) get_categories('get=all'); 104 if($categories) { 105 foreach ( $categories as $cat ) { 106 echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n"; 107 } 108 } 109 ?> 110 </select> 111 </td> 112 </tr> 113 <?php } ?> 114 <tr> 115 <th><label for="post_type"><?php _e('Restrict Content'); ?></label></th> 116 <td> 117 <select name="post_type" id="post_type"> 118 <option value="all" selected="selected"><?php _e('All Content'); ?></option> 119 <option value="page"><?php _e('Pages'); ?></option> 120 <option value="post"><?php _e('Posts'); ?></option> 121 </select> 122 </td> 123 </tr> 124 <tr> 125 <th><label for="status"><?php _e('Restrict Status'); ?></label></th> 126 <td> 127 <select name="status" id="status"> 128 <option value="all" selected="selected"><?php _e('All Statuses'); ?></option> 129 <option value="draft"><?php _e('Draft'); ?></option> 130 <option value="private"><?php _e('Privately published'); ?></option> 131 <option value="publish"><?php _e('Published'); ?></option> 132 <option value="future"><?php _e('Scheduled'); ?></option> 133 </select> 134 </td> 135 </tr> 51 136 </table> 52 137 <p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" /> 53 138 <input type="hidden" name="download" value="true" />
