Make WordPress Core

Ticket #10317: export.diff

File export.diff, 7.0 KB (added by wpmuguru, 17 years ago)

export patch

  • 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;
    2828
    2929do_action('export_wp');
    3030
    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);
    3239
    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' ) {
     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        }
    3663
    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 
    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");
    4566
     
    265286                        $where = "WHERE ID IN (".join(',', $next_posts).")";
    266287                        $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
    267288                                foreach ($posts as $post) {
    268                         // Don't export revisions.  They bloat the export.
    269                         if ( 'revision' == $post->post_type )
    270                                 continue;
    271289                        setup_postdata($post); ?>
    272290<item>
    273291<title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
  • wp-admin/export.php

     
    1414$title = __('Export');
    1515
    1616if ( 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 );
    1942        die();
    2043}
    2144
    2245require_once ('admin-header.php');
    23 ?>
    2446
     47$months = "";
     48for ( $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
    2553<div class="wrap">
    2654<?php screen_icon(); ?>
    2755<h2><?php echo esc_html( $title ); ?></h2>
     
    3462
    3563<table class="form-table">
    3664<tr>
     65<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
     66<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
     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>&nbsp;<?php _e('Year'); ?>&nbsp;
     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'); ?>&nbsp;
     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>&nbsp;<?php _e('Year'); ?>&nbsp;
     78<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
     79</td>
     80</tr>
     81<tr>
    3782<th><label for="author"><?php _e('Restrict Author'); ?></label></th>
    3883<td>
    3984<select name="author" id="author">
     
    4287$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
    4388foreach ( $authors as $id ) {
    4489        $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";
    4691}
    4792?>
    4893</select>
    4994</td>
    5095</tr>
     96<tr>
     97<th><label for="category"><?php _e('Restrict Category'); ?></label></th>
     98<td>
     99<select name="category" id="category">
     100<option value="all" selected="selected"><?php _e('All Categories'); ?></option>
     101<?php
     102$categories = (array) get_categories('get=all');
     103if($categories) {
     104        foreach ( $categories as $cat ) {
     105                echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
     106        }
     107}
     108?>
     109</select>
     110</td>
     111</tr>
     112<tr>
     113<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
     114<td>
     115<select name="post_type" id="post_type">
     116<option value="all" selected="selected"><?php _e('All Content'); ?></option>
     117<option value="page"><?php _e('Pages'); ?></option>
     118<option value="post"><?php _e('Posts'); ?></option>
     119</select>
     120</td>
     121</tr>
     122<tr>
     123<th><label for="status"><?php _e('Restrict Status'); ?></label></th>
     124<td>
     125<select name="status" id="status">
     126<option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
     127<option value="draft"><?php _e('Draft'); ?></option>
     128<option value="private"><?php _e('Privately published'); ?></option>
     129<option value="publish"><?php _e('Published'); ?></option>
     130<option value="future"><?php _e('Scheduled'); ?></option>
     131</select>
     132</td>
     133</tr>
    51134</table>
    52135<p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" />
    53136<input type="hidden" name="download" value="true" />