add features to export, see #10317

git-svn-id: https://develop.svn.wordpress.org/trunk@13573 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ron Rennick 2010-03-03 16:45:40 +00:00
parent 03e39017cf
commit b921286ce2
2 changed files with 115 additions and 14 deletions

View File

@ -17,13 +17,41 @@ require_once('includes/export.php');
$title = __('Export'); $title = __('Export');
if ( isset( $_GET['download'] ) ) { if ( isset( $_GET['download'] ) ) {
$author = isset($_GET['author']) ? $_GET['author'] : 'all'; $author = isset($_GET['author']) ? $_GET['author'] : 'all';
export_wp( $author ); $category = isset($_GET['category']) ? $_GET['category'] : 'all';
$post_type = isset($_GET['post_type']) ? stripslashes_deep($_GET['post_type']) : 'all';
$status = isset($_GET['status']) ? stripslashes_deep($_GET['status']) : 'all';
$mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all';
$mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all';
$aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0;
$aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0;
if($mm_start != 'all' && $aa_start > 0) {
$start_date = sprintf( "%04d-%02d-%02d", $aa_start, $mm_start, 1 );
} else {
$start_date = 'all';
}
if($mm_end != 'all' && $aa_end > 0) {
if($mm_end == 12) {
$mm_end = 1;
$aa_end++;
} else {
$mm_end++;
}
$end_date = sprintf( "%04d-%02d-%02d", $aa_end, $mm_end, 1 );
} else {
$end_date = 'all';
}
export_wp( $author, $category, $post_type, $status, $start_date, $end_date );
die(); die();
} }
require_once ('admin-header.php'); require_once ('admin-header.php');
?>
$months = "";
for ( $i = 1; $i < 13; $i++ ) {
$months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' .
$wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
} ?>
<div class="wrap"> <div class="wrap">
<?php screen_icon(); ?> <?php screen_icon(); ?>
@ -37,6 +65,23 @@ require_once ('admin-header.php');
<table class="form-table"> <table class="form-table">
<tr> <tr>
<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
<select name="mm_start" id="mm_start">
<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
<?php echo $months; ?>
</select>&nbsp;<?php _e('Year'); ?>&nbsp;
<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" />
</td>
<td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>&nbsp;
<select name="mm_end" id="mm_end">
<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
<?php echo $months; ?>
</select>&nbsp;<?php _e('Year'); ?>&nbsp;
<input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
</td>
</tr>
<tr>
<th><label for="author"><?php _e('Restrict Author'); ?></label></th> <th><label for="author"><?php _e('Restrict Author'); ?></label></th>
<td> <td>
<select name="author" id="author"> <select name="author" id="author">
@ -45,12 +90,50 @@ require_once ('admin-header.php');
$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" ); $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
foreach ( $authors as $id ) { foreach ( $authors as $id ) {
$o = get_userdata( $id ); $o = get_userdata( $id );
echo "<option value='" . esc_attr($o->ID) . "'>$o->display_name</option>"; echo "<option value='{$o->ID}'>{$o->display_name}</option>\n";
} }
?> ?>
</select> </select>
</td> </td>
</tr> </tr>
<tr>
<th><label for="category"><?php _e('Restrict Category'); ?></label></th>
<td>
<select name="category" id="category">
<option value="all" selected="selected"><?php _e('All Categories'); ?></option>
<?php
$categories = (array) get_categories('get=all');
if($categories) {
foreach ( $categories as $cat ) {
echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
}
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
<td>
<select name="post_type" id="post_type">
<option value="all" selected="selected"><?php _e('All Content'); ?></option>
<option value="page"><?php _e('Pages'); ?></option>
<option value="post"><?php _e('Posts'); ?></option>
</select>
</td>
</tr>
<tr>
<th><label for="status"><?php _e('Restrict Status'); ?></label></th>
<td>
<select name="status" id="status">
<option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
<option value="draft"><?php _e('Draft'); ?></option>
<option value="private"><?php _e('Privately published'); ?></option>
<option value="publish"><?php _e('Published'); ?></option>
<option value="future"><?php _e('Scheduled'); ?></option>
</select>
</td>
</tr>
</table> </table>
<p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" /> <p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" />
<input type="hidden" name="download" value="true" /> <input type="hidden" name="download" value="true" />

View File

@ -23,21 +23,42 @@ define('WXR_VERSION', '1.0');
* *
* @param unknown_type $author * @param unknown_type $author
*/ */
function export_wp($author='') { function export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='') {
global $wpdb, $post_ids, $post, $wp_taxonomies; global $wpdb, $post_ids, $post, $wp_taxonomies;
do_action('export_wp'); do_action('export_wp');
$filename = 'wordpress.' . date('Y-m-d') . '.xml'; if(strlen($start_date) > 4 && strlen($end_date) > 4) {
$filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
} else {
$filename = 'wordpress.' . date('Y-m-d') . '.xml';
}
header('Content-Description: File Transfer'); header('Content-Description: File Transfer');
header("Content-Disposition: attachment; filename=$filename"); header("Content-Disposition: attachment; filename=$filename");
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
$where = ''; if ( $post_type and $post_type != 'all' ) {
$where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
} else {
$where = "WHERE post_type != 'revision' ";
}
if ( $author and $author != 'all' ) { if ( $author and $author != 'all' ) {
$author_id = (int) $author; $author_id = (int) $author;
$where = $wpdb->prepare(" WHERE post_author = %d ", $author_id); $where .= $wpdb->prepare("AND post_author = %d ", $author_id);
}
if ( $start_date and $start_date != 'all' ) {
$where .= $wpdb->prepare("AND post_date >= %s ", $start_date);
}
if ( $end_date and $end_date != 'all' ) {
$where .= $wpdb->prepare("AND post_date < %s ", $end_date);
}
if ( $category and $category != 'all' ) {
$taxomony_id = (int) $category;
$where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " . "WHERE term_taxonomy_id = %d) ", $taxomony_id);
}
if ( $status and $status != 'all' ) {
$where .= $wpdb->prepare("AND post_status = %s ", $status);
} }
// grab a snapshot of post IDs, just in case it changes during the export // grab a snapshot of post IDs, just in case it changes during the export
@ -300,9 +321,6 @@ echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
$where = "WHERE ID IN (".join(',', $next_posts).")"; $where = "WHERE ID IN (".join(',', $next_posts).")";
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
foreach ($posts as $post) { foreach ($posts as $post) {
// Don't export revisions. They bloat the export.
if ( 'revision' == $post->post_type )
continue;
setup_postdata($post); setup_postdata($post);
$is_sticky = 0; $is_sticky = 0;