add features to export, see #10317
git-svn-id: http://svn.automattic.com/wordpress/trunk@13573 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
619765602b
commit
c4f0134808
|
@ -17,13 +17,41 @@ require_once('includes/export.php');
|
|||
$title = __('Export');
|
||||
|
||||
if ( isset( $_GET['download'] ) ) {
|
||||
$author = isset($_GET['author']) ? $_GET['author'] : 'all';
|
||||
export_wp( $author );
|
||||
$author = isset($_GET['author']) ? $_GET['author'] : 'all';
|
||||
$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();
|
||||
}
|
||||
|
||||
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">
|
||||
<?php screen_icon(); ?>
|
||||
|
@ -37,6 +65,23 @@ require_once ('admin-header.php');
|
|||
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
|
||||
<td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>
|
||||
<select name="mm_start" id="mm_start">
|
||||
<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
|
||||
<?php echo $months; ?>
|
||||
</select> <?php _e('Year'); ?>
|
||||
<input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" />
|
||||
</td>
|
||||
<td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>
|
||||
<select name="mm_end" id="mm_end">
|
||||
<option value="all" selected="selected"><?php _e('All Dates'); ?></option>
|
||||
<?php echo $months; ?>
|
||||
</select> <?php _e('Year'); ?>
|
||||
<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>
|
||||
<td>
|
||||
<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" );
|
||||
foreach ( $authors as $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>
|
||||
</td>
|
||||
</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>
|
||||
<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" />
|
||||
|
|
|
@ -23,22 +23,43 @@ define('WXR_VERSION', '1.0');
|
|||
*
|
||||
* @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;
|
||||
|
||||
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-Disposition: attachment; filename=$filename");
|
||||
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
|
||||
|
||||
$where = '';
|
||||
if ( $author and $author != 'all' ) {
|
||||
$author_id = (int) $author;
|
||||
$where = $wpdb->prepare(" WHERE post_author = %d ", $author_id);
|
||||
}
|
||||
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' ) {
|
||||
$author_id = (int) $author;
|
||||
$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
|
||||
$post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
|
||||
|
@ -300,9 +321,6 @@ echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
|
|||
$where = "WHERE ID IN (".join(',', $next_posts).")";
|
||||
$posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
|
||||
foreach ($posts as $post) {
|
||||
// Don't export revisions. They bloat the export.
|
||||
if ( 'revision' == $post->post_type )
|
||||
continue;
|
||||
setup_postdata($post);
|
||||
|
||||
$is_sticky = 0;
|
||||
|
|
Loading…
Reference in New Issue