WordPress.org

Make WordPress Core

Ticket #10317: 10317.diff

File 10317.diff, 8.1 KB (added by nacin, 8 years ago)

Untested. Whole feature needs urgent massaging to bring it up to par.

  • export.php

     
    1818
    1919if ( isset( $_GET['download'] ) ) {
    2020                $author = isset($_GET['author']) ? $_GET['author'] : 'all';
    21                 $category = isset($_GET['category']) ? $_GET['category'] : 'all';
     21                $taxonomy = array();
     22                foreach ( get_taxonomies( array( 'show_ui' => true ) ) as $tax )
     23                        $taxonomy[ $tax ] = ! empty( $_GET['taxonomy'][ $tax ] ) ? $_GET['taxonomy'][ $tax ] : 'all';
    2224                $post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all';
    2325                $status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all';
    2426                $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all';
     
    4143                } else {
    4244                        $end_date = 'all';
    4345                }
    44         export_wp( $author, $category, $post_type, $status, $start_date, $end_date );
     46        export_wp( array( 'author' => $author, 'taxonomy' => $taxonomy, 'post_type' => $post_type, 'post_status' => $status, 'start_date' => $start_date, 'end_date' => $end_date ) );
    4547        die();
    4648}
    4749
    4850require_once ('admin-header.php');
    4951
    5052$months = "";
    51 for ( $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";
     53for ( $i = 1; $i <= 12; $i++ ) {
     54        $months .= "\t<option value=\"" . zeroise($i, 2) . '">' .
     55                $wp_locale->get_month( $i ) . "</option>\n";
    5456} ?>
    5557
    5658<div class="wrap">
     
    6668<table class="form-table">
    6769<tr>
    6870<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
    69 <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
     71<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>
    7072<select name="mm_start" id="mm_start">
    71 <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
     73        <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
    7274<?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;
     75</select> <?php _e('Year'); ?>
     76<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" /><br/>
     77<strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>
    7778<select name="mm_end" id="mm_end">
    78 <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
     79        <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
    7980<?php echo $months; ?>
    80 </select>&nbsp;<?php _e('Year'); ?>&nbsp;
     81</select> <?php _e('Year'); ?>
    8182<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
    8283</td>
    8384</tr>
     
    8788<select name="author" id="author">
    8889<option value="all" selected="selected"><?php _e('All Authors'); ?></option>
    8990<?php
    90 $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
    91 foreach ( $authors as $id ) {
    92         $o = get_userdata( $id );
    93         echo "<option value='{$o->ID}'>{$o->display_name}</option>\n";
     91$authors = $wpdb->get_results( "SELECT DISTINCT u.id, u.display_name FROM $wpdb->users u INNER JOIN $wpdb->posts p WHERE u.id = p.post_author ORDER BY u.display_name" );
     92foreach ( (array) $authors as $author ) {
     93        echo "<option value='{$author->id}'>{$author->display_name}</option>\n";
    9494}
    9595?>
    9696</select>
    9797</td>
    9898</tr>
    9999<tr>
    100 <th><label for="category"><?php _e('Restrict Category'); ?></label></th>
     100<th><?php _e('Restrict Taxonomies'); ?></th>
    101101<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');
    106 if($categories) {
    107         foreach ( $categories as $cat ) {
    108                 echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
    109         }
     102<?php foreach ( get_taxonomies( array( 'show_ui' => true ), 'objects' ) as $tax_obj ) {
     103        $term_dropdown = wp_dropdown_categories( array( 'taxonomy' => $tax_obj->name, 'hide_if_empty' => true, 'show_option_all' => __( 'All Terms' ), 'name' => 'taxonomy[' . $tax_obj->name . ']', 'id' => 'taxonomy-' . $tax_obj->name, 'class' => '', 'echo' => false ) );
     104        if ( $term_dropdown )
     105                echo '<label for="taxonomy-' . $tax_obj->name . '">' . $tax_obj->label . '</label>: ' . $term_dropdown . '<br/>';
    110106}
    111107?>
    112 </select>
    113108</td>
    114109</tr>
    115110<tr>
    116111<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
    117112<td>
    118113<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>
     114        <option value="all" selected="selected"><?php _e('All Content'); ?></option>
     115<?php foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $post_type_obj ) { ?>
     116        <option value="<?php echo $post_type_obj->name; ?>"><?php echo $post_type_obj->label; ?></option>
     117<?php } ?>
    122118</select>
    123119</td>
    124120</tr>
     
    126122<th><label for="status"><?php _e('Restrict Status'); ?></label></th>
    127123<td>
    128124<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>
     125        <option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
     126<?php foreach ( get_post_stati( array( 'internal' => false ), 'objects' ) as $post_status_obj ) { ?>
     127        <option value="<?php echo $post_status_obj->name; ?>"><?php echo $post_status_obj->label; ?></option>
     128<?php } ?>
    134129</select>
    135130</td>
    136131</tr>
  • includes/export.php

     
    2121 *
    2222 * @since unknown
    2323 *
    24  * @param unknown_type $author
     24 * @param unknown_type $args
    2525 */
    26 function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
     26function export_wp( $args = array() ) {
    2727global $wpdb, $post_ids, $post, $wp_taxonomies;
    2828
     29if ( ! is_array( $args ) )
     30        $args = array( 'author' => $args );
     31$defaults = array( 'author' => null, 'taxonomy' => null, 'post_type' => null, 'post_status' => null, 'start_date' => null, 'end_date' => null );
     32$args = wp_parse_args( $args, $defaults );
     33
    2934do_action('export_wp');
    3035
    3136if(strlen($start_date) > 4 && strlen($end_date) > 4) {
     
    3843header("Content-Disposition: attachment; filename=$filename");
    3944header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    4045
    41 if ( $post_type and $post_type != 'all' ) {
     46if ( $post_type && $post_type != 'all' ) {
    4247                $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
    4348} else {
    4449                $where = "WHERE post_type != 'revision' ";
    4550}
    46 if ( $author and $author != 'all' ) {
     51if ( $author && $author != 'all' ) {
    4752                $author_id = (int) $author;
    4853                $where .= $wpdb->prepare("AND post_author = %d ", $author_id);
    4954}
    50 if ( $start_date and $start_date != 'all' ) {
     55if ( $start_date && $start_date != 'all' ) {
    5156                $where .= $wpdb->prepare("AND post_date >= %s ", $start_date);
    5257}
    53 if ( $end_date and $end_date != 'all' ) {
     58if ( $end_date && $end_date != 'all' ) {
    5459                $where .= $wpdb->prepare("AND post_date < %s ", $end_date);
    5560}
    56 if ( $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);
     61if ( $taxonomy && is_array( $taxonomy ) ) {
     62        foreach ( $taxonomy as $term_id ) {
     63                if ( $tax != 'all' )
     64                        $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d) ", $term_id);
     65        }
    5966}
    60 if ( $status and $status != 'all' ) {
    61                 $where .= $wpdb->prepare("AND post_status = %s ", $status);
     67if ( $status && $status != 'all' ) {
     68                $where .= $wpdb->prepare("AND post_status = %s", $status);
    6269}
    6370
    6471// grab a snapshot of post IDs, just in case it changes during the export