Ticket #10317: 10317.diff
| File 10317.diff, 8.1 KB (added by nacin, 3 years ago) |
|---|
-
export.php
18 18 19 19 if ( isset( $_GET['download'] ) ) { 20 20 $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'; 22 24 $post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all'; 23 25 $status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all'; 24 26 $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all'; … … 41 43 } else { 42 44 $end_date = 'all'; 43 45 } 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 ) ); 45 47 die(); 46 48 } 47 49 48 50 require_once ('admin-header.php'); 49 51 50 52 $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";53 for ( $i = 1; $i <= 12; $i++ ) { 54 $months .= "\t<option value=\"" . zeroise($i, 2) . '">' . 55 $wp_locale->get_month( $i ) . "</option>\n"; 54 56 } ?> 55 57 56 58 <div class="wrap"> … … 66 68 <table class="form-table"> 67 69 <tr> 68 70 <th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th> 69 <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?> 71 <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?> 70 72 <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> 72 74 <?php echo $months; ?> 73 </select> <?php _e('Year'); ?> 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'); ?> 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'); ?> 77 78 <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> 79 80 <?php echo $months; ?> 80 </select> <?php _e('Year'); ?> 81 </select> <?php _e('Year'); ?> 81 82 <input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" /> 82 83 </td> 83 84 </tr> … … 87 88 <select name="author" id="author"> 88 89 <option value="all" selected="selected"><?php _e('All Authors'); ?></option> 89 90 <?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" ); 92 foreach ( (array) $authors as $author ) { 93 echo "<option value='{$author->id}'>{$author->display_name}</option>\n"; 94 94 } 95 95 ?> 96 96 </select> 97 97 </td> 98 98 </tr> 99 99 <tr> 100 <th>< label for="category"><?php _e('Restrict Category'); ?></label></th>100 <th><?php _e('Restrict Taxonomies'); ?></th> 101 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'); 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/>'; 110 106 } 111 107 ?> 112 </select>113 108 </td> 114 109 </tr> 115 110 <tr> 116 111 <th><label for="post_type"><?php _e('Restrict Content'); ?></label></th> 117 112 <td> 118 113 <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 } ?> 122 118 </select> 123 119 </td> 124 120 </tr> … … 126 122 <th><label for="status"><?php _e('Restrict Status'); ?></label></th> 127 123 <td> 128 124 <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 } ?> 134 129 </select> 135 130 </td> 136 131 </tr> -
includes/export.php
21 21 * 22 22 * @since unknown 23 23 * 24 * @param unknown_type $a uthor24 * @param unknown_type $args 25 25 */ 26 function export_wp( $author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {26 function export_wp( $args = array() ) { 27 27 global $wpdb, $post_ids, $post, $wp_taxonomies; 28 28 29 if ( ! 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 29 34 do_action('export_wp'); 30 35 31 36 if(strlen($start_date) > 4 && strlen($end_date) > 4) { … … 38 43 header("Content-Disposition: attachment; filename=$filename"); 39 44 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); 40 45 41 if ( $post_type and$post_type != 'all' ) {46 if ( $post_type && $post_type != 'all' ) { 42 47 $where = $wpdb->prepare("WHERE post_type = %s ", $post_type); 43 48 } else { 44 49 $where = "WHERE post_type != 'revision' "; 45 50 } 46 if ( $author and$author != 'all' ) {51 if ( $author && $author != 'all' ) { 47 52 $author_id = (int) $author; 48 53 $where .= $wpdb->prepare("AND post_author = %d ", $author_id); 49 54 } 50 if ( $start_date and$start_date != 'all' ) {55 if ( $start_date && $start_date != 'all' ) { 51 56 $where .= $wpdb->prepare("AND post_date >= %s ", $start_date); 52 57 } 53 if ( $end_date and$end_date != 'all' ) {58 if ( $end_date && $end_date != 'all' ) { 54 59 $where .= $wpdb->prepare("AND post_date < %s ", $end_date); 55 60 } 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); 61 if ( $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 } 59 66 } 60 if ( $status and$status != 'all' ) {61 $where .= $wpdb->prepare("AND post_status = %s ", $status);67 if ( $status && $status != 'all' ) { 68 $where .= $wpdb->prepare("AND post_status = %s", $status); 62 69 } 63 70 64 71 // grab a snapshot of post IDs, just in case it changes during the export
