]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/export.php
WordPress 3.7.1
[autoinstalls/wordpress.git] / wp-admin / export.php
1 <?php
2 /**
3  * WordPress Export Administration Screen
4  *
5  * @package WordPress
6  * @subpackage Administration
7  */
8
9 /** Load WordPress Bootstrap */
10 require_once( dirname( __FILE__ ) . '/admin.php' );
11
12 if ( !current_user_can('export') )
13         wp_die(__('You do not have sufficient permissions to export the content of this site.'));
14
15 /** Load WordPress export API */
16 require_once( ABSPATH . 'wp-admin/includes/export.php' );
17 $title = __('Export');
18
19 /**
20  * Display JavaScript on the page.
21  *
22  * @since 3.5.0
23  */
24 function export_add_js() {
25 ?>
26 <script type="text/javascript">
27 //<![CDATA[
28         jQuery(document).ready(function($){
29                 var form = $('#export-filters'),
30                         filters = form.find('.export-filters');
31                 filters.hide();
32                 form.find('input:radio').change(function() {
33                         filters.slideUp('fast');
34                         switch ( $(this).val() ) {
35                                 case 'posts': $('#post-filters').slideDown(); break;
36                                 case 'pages': $('#page-filters').slideDown(); break;
37                         }
38                 });
39         });
40 //]]>
41 </script>
42 <?php
43 }
44 add_action( 'admin_head', 'export_add_js' );
45
46 get_current_screen()->add_help_tab( array(
47         'id'      => 'overview',
48         'title'   => __('Overview'),
49         '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>' .
50                 '<p>' . __('Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.') . '</p>',
51 ) );
52
53 get_current_screen()->set_help_sidebar(
54         '<p><strong>' . __('For more information:') . '</strong></p>' .
55         '<p>' . __('<a href="http://codex.wordpress.org/Tools_Export_Screen" target="_blank">Documentation on Export</a>') . '</p>' .
56         '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
57 );
58
59 if ( isset( $_GET['download'] ) ) {
60         $args = array();
61
62         if ( ! isset( $_GET['content'] ) || 'all' == $_GET['content'] ) {
63                 $args['content'] = 'all';
64         } else if ( 'posts' == $_GET['content'] ) {
65                 $args['content'] = 'post';
66
67                 if ( $_GET['cat'] )
68                         $args['category'] = (int) $_GET['cat'];
69
70                 if ( $_GET['post_author'] )
71                         $args['author'] = (int) $_GET['post_author'];
72
73                 if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
74                         $args['start_date'] = $_GET['post_start_date'];
75                         $args['end_date'] = $_GET['post_end_date'];
76                 }
77
78                 if ( $_GET['post_status'] )
79                         $args['status'] = $_GET['post_status'];
80         } else if ( 'pages' == $_GET['content'] ) {
81                 $args['content'] = 'page';
82
83                 if ( $_GET['page_author'] )
84                         $args['author'] = (int) $_GET['page_author'];
85
86                 if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
87                         $args['start_date'] = $_GET['page_start_date'];
88                         $args['end_date'] = $_GET['page_end_date'];
89                 }
90
91                 if ( $_GET['page_status'] )
92                         $args['status'] = $_GET['page_status'];
93         } else {
94                 $args['content'] = $_GET['content'];
95         }
96
97         /**
98          * Filter the export args.
99          *
100          * @since 3.5.0
101          *
102          * @param array $args The arguments to send to the exporter.
103          */
104         $args = apply_filters( 'export_args', $args );
105
106         export_wp( $args );
107         die();
108 }
109
110 require_once( ABSPATH . 'wp-admin/admin-header.php' );
111
112 /**
113  * Create the date options fields for exporting a given post type.
114  *
115  * @global wpdb      $wpdb      WordPress database object.
116  * @global WP_Locale $wp_locale Date and Time Locale object.
117  *
118  * @since 3.1.0
119  *
120  * @param string $post_type The post type. Default 'post'.
121  */
122 function export_date_options( $post_type = 'post' ) {
123         global $wpdb, $wp_locale;
124
125         $months = $wpdb->get_results( $wpdb->prepare( "
126                 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
127                 FROM $wpdb->posts
128                 WHERE post_type = %s AND post_status != 'auto-draft'
129                 ORDER BY post_date DESC
130         ", $post_type ) );
131
132         $month_count = count( $months );
133         if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
134                 return;
135
136         foreach ( $months as $date ) {
137                 if ( 0 == $date->year )
138                         continue;
139
140                 $month = zeroise( $date->month, 2 );
141                 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
142         }
143 }
144 ?>
145
146 <div class="wrap">
147 <?php screen_icon(); ?>
148 <h2><?php echo esc_html( $title ); ?></h2>
149
150 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
151 <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>
152 <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>
153
154 <h3><?php _e( 'Choose what to export' ); ?></h3>
155 <form action="" method="get" id="export-filters">
156 <input type="hidden" name="download" value="true" />
157 <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p>
158 <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p>
159
160 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
161 <ul id="post-filters" class="export-filters">
162         <li>
163                 <label><?php _e( 'Categories:' ); ?></label>
164                 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
165         </li>
166         <li>
167                 <label><?php _e( 'Authors:' ); ?></label>
168 <?php
169                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
170                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
171 ?>
172         </li>
173         <li>
174                 <label><?php _e( 'Date range:' ); ?></label>
175                 <select name="post_start_date">
176                         <option value="0"><?php _e( 'Start Date' ); ?></option>
177                         <?php export_date_options(); ?>
178                 </select>
179                 <select name="post_end_date">
180                         <option value="0"><?php _e( 'End Date' ); ?></option>
181                         <?php export_date_options(); ?>
182                 </select>
183         </li>
184         <li>
185                 <label><?php _e( 'Status:' ); ?></label>
186                 <select name="post_status">
187                         <option value="0"><?php _e( 'All' ); ?></option>
188                         <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
189                         foreach ( $post_stati as $status ) : ?>
190                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
191                         <?php endforeach; ?>
192                 </select>
193         </li>
194 </ul>
195
196 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
197 <ul id="page-filters" class="export-filters">
198         <li>
199                 <label><?php _e( 'Authors:' ); ?></label>
200 <?php
201                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
202                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
203 ?>
204         </li>
205         <li>
206                 <label><?php _e( 'Date range:' ); ?></label>
207                 <select name="page_start_date">
208                         <option value="0"><?php _e( 'Start Date' ); ?></option>
209                         <?php export_date_options( 'page' ); ?>
210                 </select>
211                 <select name="page_end_date">
212                         <option value="0"><?php _e( 'End Date' ); ?></option>
213                         <?php export_date_options( 'page' ); ?>
214                 </select>
215         </li>
216         <li>
217                 <label><?php _e( 'Status:' ); ?></label>
218                 <select name="page_status">
219                         <option value="0"><?php _e( 'All' ); ?></option>
220                         <?php foreach ( $post_stati as $status ) : ?>
221                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
222                         <?php endforeach; ?>
223                 </select>
224         </li>
225 </ul>
226
227 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
228 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
229 <?php endforeach; ?>
230
231 <?php
232 /**
233  * Fires after the export filters form.
234  *
235  * @since 3.5.0
236  */
237 do_action( 'export_filters' );
238 ?>
239
240 <?php submit_button( __('Download Export File') ); ?>
241 </form>
242 </div>
243
244 <?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>