web/wp-admin/export.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * WordPress Export Administration Panel
     3  * WordPress Export Administration Screen
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /** Load WordPress Bootstrap */
     9 /** Load WordPress Bootstrap */
    10 require_once ('admin.php');
    10 require_once ('admin.php');
    11 
    11 
    12 if ( !current_user_can('edit_files') )
    12 if ( !current_user_can('export') )
    13 	wp_die(__('You do not have sufficient permissions to export the content of this blog.'));
    13 	wp_die(__('You do not have sufficient permissions to export the content of this site.'));
    14 
    14 
    15 /** Load WordPress export API */
    15 /** Load WordPress export API */
    16 require_once('includes/export.php');
    16 require_once('./includes/export.php');
    17 $title = __('Export');
    17 $title = __('Export');
    18 
    18 
       
    19 function add_js() {
       
    20 ?>
       
    21 <script type="text/javascript">
       
    22 //<![CDATA[
       
    23 	jQuery(document).ready(function($){
       
    24  		var form = $('#export-filters'),
       
    25  			filters = form.find('.export-filters');
       
    26  		filters.hide();
       
    27  		form.find('input:radio').change(function() {
       
    28 			filters.slideUp('fast');
       
    29 			switch ( $(this).val() ) {
       
    30 				case 'posts': $('#post-filters').slideDown(); break;
       
    31 				case 'pages': $('#page-filters').slideDown(); break;
       
    32 			}
       
    33  		});
       
    34 	});
       
    35 //]]>
       
    36 </script>
       
    37 <?php
       
    38 }
       
    39 add_action( 'admin_head', 'add_js' );
       
    40 
       
    41 get_current_screen()->add_help_tab( array(
       
    42 	'id'      => 'overview',
       
    43 	'title'   => __('Overview'),
       
    44 	'content' => '<p>' . __('You can export a file of your site&#8217;s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.') . '</p>' .
       
    45 		'<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>',
       
    46 ) );
       
    47 
       
    48 get_current_screen()->set_help_sidebar(
       
    49 	'<p><strong>' . __('For more information:') . '</strong></p>' .
       
    50 	'<p>' . __('<a href="http://codex.wordpress.org/Tools_Export_Screen" target="_blank">Documentation on Export</a>') . '</p>' .
       
    51 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
       
    52 );
       
    53 
    19 if ( isset( $_GET['download'] ) ) {
    54 if ( isset( $_GET['download'] ) ) {
    20 	$author = isset($_GET['author']) ? $_GET['author'] : 'all';
    55 	$args = array();
    21 	export_wp( $author );
    56 
       
    57 	if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) {
       
    58 		$args['content'] = 'all';
       
    59 	} else if ( 'posts' == $_GET['content'] ) {
       
    60 		$args['content'] = 'post';
       
    61 
       
    62 		if ( $_GET['cat'] )
       
    63 			$args['category'] = (int) $_GET['cat'];
       
    64 
       
    65 		if ( $_GET['post_author'] )
       
    66 			$args['author'] = (int) $_GET['post_author'];
       
    67 
       
    68 		if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
       
    69 			$args['start_date'] = $_GET['post_start_date'];
       
    70 			$args['end_date'] = $_GET['post_end_date'];
       
    71 		}
       
    72 
       
    73 		if ( $_GET['post_status'] )
       
    74 			$args['status'] = $_GET['post_status'];
       
    75 	} else if ( 'pages' == $_GET['content'] ) {
       
    76 		$args['content'] = 'page';
       
    77 
       
    78 		if ( $_GET['page_author'] )
       
    79 			$args['author'] = (int) $_GET['page_author'];
       
    80 
       
    81 		if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
       
    82 			$args['start_date'] = $_GET['page_start_date'];
       
    83 			$args['end_date'] = $_GET['page_end_date'];
       
    84 		}
       
    85 
       
    86 		if ( $_GET['page_status'] )
       
    87 			$args['status'] = $_GET['page_status'];
       
    88 	} else {
       
    89 		$args['content'] = $_GET['content'];
       
    90 	}
       
    91 
       
    92 	export_wp( $args );
    22 	die();
    93 	die();
    23 }
    94 }
    24 
    95 
    25 require_once ('admin-header.php');
    96 require_once ('admin-header.php');
       
    97 
       
    98 function export_date_options( $post_type = 'post' ) {
       
    99 	global $wpdb, $wp_locale;
       
   100 
       
   101 	$months = $wpdb->get_results( $wpdb->prepare( "
       
   102 		SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
       
   103 		FROM $wpdb->posts
       
   104 		WHERE post_type = %s AND post_status != 'auto-draft'
       
   105 		ORDER BY post_date DESC
       
   106 	", $post_type ) );
       
   107 
       
   108 	$month_count = count( $months );
       
   109 	if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
       
   110 		return;
       
   111 
       
   112 	foreach ( $months as $date ) {
       
   113 		if ( 0 == $date->year )
       
   114 			continue;
       
   115 
       
   116 		$month = zeroise( $date->month, 2 );
       
   117 		echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
       
   118 	}
       
   119 }
    26 ?>
   120 ?>
    27 
   121 
    28 <div class="wrap">
   122 <div class="wrap">
    29 <?php screen_icon(); ?>
   123 <?php screen_icon(); ?>
    30 <h2><?php echo esc_html( $title ); ?></h2>
   124 <h2><?php echo esc_html( $title ); ?></h2>
    31 
   125 
    32 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
   126 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
    33 <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
   127 <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
    34 <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress blog to import this blog.'); ?></p>
   128 <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.'); ?></p>
    35 <form action="" method="get">
   129 
    36 <h3><?php _e('Options'); ?></h3>
   130 <h3><?php _e( 'Choose what to export' ); ?></h3>
    37 
   131 <form action="" method="get" id="export-filters">
    38 <table class="form-table">
       
    39 <tr>
       
    40 <th><label for="author"><?php _e('Restrict Author'); ?></label></th>
       
    41 <td>
       
    42 <select name="author" id="author">
       
    43 <option value="all" selected="selected"><?php _e('All Authors'); ?></option>
       
    44 <?php
       
    45 $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
       
    46 foreach ( $authors as $id ) {
       
    47 	$o = get_userdata( $id );
       
    48 	echo "<option value='" . esc_attr($o->ID) . "'>$o->display_name</option>";
       
    49 }
       
    50 ?>
       
    51 </select>
       
    52 </td>
       
    53 </tr>
       
    54 </table>
       
    55 <p class="submit"><input type="submit" name="submit" class="button" value="<?php esc_attr_e('Download Export File'); ?>" />
       
    56 <input type="hidden" name="download" value="true" />
   132 <input type="hidden" name="download" value="true" />
    57 </p>
   133 <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p>
       
   134 <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p>
       
   135 
       
   136 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
       
   137 <ul id="post-filters" class="export-filters">
       
   138 	<li>
       
   139 		<label><?php _e( 'Categories:' ); ?></label>
       
   140 		<?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
       
   141 	</li>
       
   142 	<li>
       
   143 		<label><?php _e( 'Authors:' ); ?></label>
       
   144 <?php
       
   145 		$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
       
   146 		wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
       
   147 ?>
       
   148 	</li>
       
   149 	<li>
       
   150 		<label><?php _e( 'Date range:' ); ?></label>
       
   151 		<select name="post_start_date">
       
   152 			<option value="0"><?php _e( 'Start Date' ); ?></option>
       
   153 			<?php export_date_options(); ?>
       
   154 		</select>
       
   155 		<select name="post_end_date">
       
   156 			<option value="0"><?php _e( 'End Date' ); ?></option>
       
   157 			<?php export_date_options(); ?>
       
   158 		</select>
       
   159 	</li>
       
   160 	<li>
       
   161 		<label><?php _e( 'Status:' ); ?></label>
       
   162 		<select name="post_status">
       
   163 			<option value="0"><?php _e( 'All' ); ?></option>
       
   164 			<?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
       
   165 			foreach ( $post_stati as $status ) : ?>
       
   166 			<option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
       
   167 			<?php endforeach; ?>
       
   168 		</select>
       
   169 	</li>
       
   170 </ul>
       
   171 
       
   172 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
       
   173 <ul id="page-filters" class="export-filters">
       
   174 	<li>
       
   175 		<label><?php _e( 'Authors:' ); ?></label>
       
   176 <?php
       
   177 		$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
       
   178 		wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
       
   179 ?>
       
   180 	</li>
       
   181 	<li>
       
   182 		<label><?php _e( 'Date range:' ); ?></label>
       
   183 		<select name="page_start_date">
       
   184 			<option value="0"><?php _e( 'Start Date' ); ?></option>
       
   185 			<?php export_date_options( 'page' ); ?>
       
   186 		</select>
       
   187 		<select name="page_end_date">
       
   188 			<option value="0"><?php _e( 'End Date' ); ?></option>
       
   189 			<?php export_date_options( 'page' ); ?>
       
   190 		</select>
       
   191 	</li>
       
   192 	<li>
       
   193 		<label><?php _e( 'Status:' ); ?></label>
       
   194 		<select name="page_status">
       
   195 			<option value="0"><?php _e( 'All' ); ?></option>
       
   196 			<?php foreach ( $post_stati as $status ) : ?>
       
   197 			<option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
       
   198 			<?php endforeach; ?>
       
   199 		</select>
       
   200 	</li>
       
   201 </ul>
       
   202 
       
   203 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
       
   204 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
       
   205 <?php endforeach; ?>
       
   206 
       
   207 <?php submit_button( __('Download Export File'), 'secondary' ); ?>
    58 </form>
   208 </form>
    59 </div>
   209 </div>
    60 
   210 
    61 <?php
   211 <?php include('admin-footer.php'); ?>
    62 
       
    63 
       
    64 include ('admin-footer.php');
       
    65 ?>