WordPress.org

Make WordPress Core

Ticket #10317: export3.diff

File export3.diff, 7.0 KB (added by jshreve, 6 years ago)
  • wp-admin/includes/export.php

     
    2323 * 
    2424 * @param unknown_type $author 
    2525 */ 
    26 function export_wp($author='') { 
     26function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') { 
    2727global $wpdb, $post_ids, $post, $wp_taxonomies; 
    2828 
    2929do_action('export_wp'); 
    3030 
    31 $filename = 'wordpress.' . date('Y-m-d') . '.xml'; 
     31if(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} 
    3236 
    3337header('Content-Description: File Transfer'); 
    3438header("Content-Disposition: attachment; filename=$filename"); 
    3539header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); 
    3640 
    37 $where = ''; 
    38 if ( $author and $author != 'all' ) { 
    39         $author_id = (int) $author; 
    40         $where = $wpdb->prepare(" WHERE post_author = %d ", $author_id); 
    41 } 
     41if ( $post_type and $post_type != 'all' ) {  
     42                $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);  
     43} else {  
     44                $where = "WHERE post_type != 'revision' ";  
     45}  
     46if ( $author and $author != 'all' ) {  
     47                $author_id = (int) $author;  
     48                $where .= $wpdb->prepare("AND post_author = %d ", $author_id);  
     49}  
     50if ( $start_date and $start_date != 'all' ) {  
     51                $where .= $wpdb->prepare("AND post_date >= %s ", $start_date);  
     52}  
     53if ( $end_date and $end_date != 'all' ) {  
     54                $where .= $wpdb->prepare("AND post_date < %s ", $end_date);  
     55}  
     56if ( $category and $category != 'all' ) {  
     57                $taxomony_id = (int) $category;  
     58                $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . "WHERE term_taxonomy_id = %d) ", $taxomony_id);  
     59}  
     60if ( $status and $status != 'all' ) {  
     61                $where .= $wpdb->prepare("AND post_status = %s ", $status);  
     62}  
    4263 
    4364// grab a snapshot of post IDs, just in case it changes during the export 
    4465$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
     
    300321                        $where = "WHERE ID IN (".join(',', $next_posts).")"; 
    301322                        $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
    302323                                foreach ($posts as $post) { 
    303                         // Don't export revisions.  They bloat the export. 
    304                         if ( 'revision' == $post->post_type ) 
    305                                 continue; 
    306324                        setup_postdata($post); 
    307325 
    308326                        $is_sticky = 0; 
  • wp-admin/export.php

     
    1717$title = __('Export'); 
    1818 
    1919if ( isset( $_GET['download'] ) ) { 
    20         $author = isset($_GET['author']) ? $_GET['author'] : 'all'; 
    21         export_wp( $author ); 
     20                $author = isset($_GET['author']) ? $_GET['author'] : 'all'; 
     21                $category = isset($_GET['category']) ? $_GET['category'] : 'all'; 
     22                $post_type = isset($_GET['post_type']) ? wp_specialchars($_GET['post_type']) : 'all'; 
     23                $status = isset($_GET['status']) ? wp_specialchars($_GET['status']) : 'all'; 
     24                $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all'; 
     25                $mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all'; 
     26                $aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0; 
     27                $aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0; 
     28                if($mm_start != 'all' && $aa_start > 0) { 
     29                        $start_date = sprintf( "%04d-%02d-%02d", $aa_start, $mm_start, 1 ); 
     30                } else { 
     31                        $start_date = 'all'; 
     32                } 
     33                if($mm_end != 'all' && $aa_end > 0) { 
     34                        if($mm_end == 12) { 
     35                                $mm_end = 1; 
     36                                $aa_end++; 
     37                        } else { 
     38                                $mm_end++; 
     39                        } 
     40                        $end_date = sprintf( "%04d-%02d-%02d", $aa_end, $mm_end, 1 ); 
     41                } else { 
     42                        $end_date = 'all'; 
     43                } 
     44        export_wp( $author, $category, $post_type, $status, $start_date, $end_date ); 
    2245        die(); 
    2346} 
    2447 
    2548require_once ('admin-header.php'); 
    26 ?> 
    2749 
     50$months = ""; 
     51for ( $i = 1; $i < 13; $i++ ) { 
     52        $months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' .  
     53                $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n"; 
     54} ?> 
     55 
    2856<div class="wrap"> 
    2957<?php screen_icon(); ?> 
    3058<h2><?php echo esc_html( $title ); ?></h2> 
     
    3765 
    3866<table class="form-table"> 
    3967<tr> 
     68<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th> 
     69<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp; 
     70<select name="mm_start" id="mm_start"> 
     71<option value="all" selected="selected"><?php _e('All Dates'); ?></option> 
     72<?php echo $months; ?> 
     73</select>&nbsp;<?php _e('Year'); ?>&nbsp; 
     74<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" /> 
     75</td> 
     76<td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>&nbsp; 
     77<select name="mm_end" id="mm_end"> 
     78<option value="all" selected="selected"><?php _e('All Dates'); ?></option> 
     79<?php echo $months; ?> 
     80</select>&nbsp;<?php _e('Year'); ?>&nbsp; 
     81<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" /> 
     82</td> 
     83</tr> 
     84<tr> 
    4085<th><label for="author"><?php _e('Restrict Author'); ?></label></th> 
    4186<td> 
    4287<select name="author" id="author"> 
     
    4590$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" ); 
    4691foreach ( $authors as $id ) { 
    4792        $o = get_userdata( $id ); 
    48         echo "<option value='" . esc_attr($o->ID) . "'>$o->display_name</option>"; 
     93        echo "<option value='{$o->ID}'>{$o->display_name}</option>\n"; 
    4994} 
    5095?> 
    5196</select> 
    5297</td> 
    5398</tr> 
     99<tr> 
     100<th><label for="category"><?php _e('Restrict Category'); ?></label></th> 
     101<td> 
     102<select name="category" id="category"> 
     103<option value="all" selected="selected"><?php _e('All Categories'); ?></option> 
     104<?php 
     105$categories = (array) get_categories('get=all'); 
     106if($categories) { 
     107        foreach ( $categories as $cat ) { 
     108                echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n"; 
     109        } 
     110} 
     111?> 
     112</select> 
     113</td> 
     114</tr> 
     115<tr> 
     116<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th> 
     117<td> 
     118<select name="post_type" id="post_type"> 
     119<option value="all" selected="selected"><?php _e('All Content'); ?></option> 
     120<option value="page"><?php _e('Pages'); ?></option> 
     121<option value="post"><?php _e('Posts'); ?></option> 
     122</select> 
     123</td> 
     124</tr> 
     125<tr> 
     126<th><label for="status"><?php _e('Restrict Status'); ?></label></th> 
     127<td> 
     128<select name="status" id="status"> 
     129<option value="all" selected="selected"><?php _e('All Statuses'); ?></option> 
     130<option value="draft"><?php _e('Draft'); ?></option> 
     131<option value="private"><?php _e('Privately published'); ?></option> 
     132<option value="publish"><?php _e('Published'); ?></option> 
     133<option value="future"><?php _e('Scheduled'); ?></option> 
     134</select> 
     135</td> 
     136</tr> 
    54137</table> 
    55138<p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" /> 
    56139<input type="hidden" name="download" value="true" />