]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/export.php
Wordpress 3.5.2-scripts
[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 ('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('./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         $args = apply_filters( 'export_args', $args );
98
99         export_wp( $args );
100         die();
101 }
102
103 require_once ('admin-header.php');
104
105 function export_date_options( $post_type = 'post' ) {
106         global $wpdb, $wp_locale;
107
108         $months = $wpdb->get_results( $wpdb->prepare( "
109                 SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
110                 FROM $wpdb->posts
111                 WHERE post_type = %s AND post_status != 'auto-draft'
112                 ORDER BY post_date DESC
113         ", $post_type ) );
114
115         $month_count = count( $months );
116         if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
117                 return;
118
119         foreach ( $months as $date ) {
120                 if ( 0 == $date->year )
121                         continue;
122
123                 $month = zeroise( $date->month, 2 );
124                 echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
125         }
126 }
127 ?>
128
129 <div class="wrap">
130 <?php screen_icon(); ?>
131 <h2><?php echo esc_html( $title ); ?></h2>
132
133 <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
134 <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>
135 <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>
136
137 <h3><?php _e( 'Choose what to export' ); ?></h3>
138 <form action="" method="get" id="export-filters">
139 <input type="hidden" name="download" value="true" />
140 <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p>
141 <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p>
142
143 <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
144 <ul id="post-filters" class="export-filters">
145         <li>
146                 <label><?php _e( 'Categories:' ); ?></label>
147                 <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
148         </li>
149         <li>
150                 <label><?php _e( 'Authors:' ); ?></label>
151 <?php
152                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
153                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
154 ?>
155         </li>
156         <li>
157                 <label><?php _e( 'Date range:' ); ?></label>
158                 <select name="post_start_date">
159                         <option value="0"><?php _e( 'Start Date' ); ?></option>
160                         <?php export_date_options(); ?>
161                 </select>
162                 <select name="post_end_date">
163                         <option value="0"><?php _e( 'End Date' ); ?></option>
164                         <?php export_date_options(); ?>
165                 </select>
166         </li>
167         <li>
168                 <label><?php _e( 'Status:' ); ?></label>
169                 <select name="post_status">
170                         <option value="0"><?php _e( 'All' ); ?></option>
171                         <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
172                         foreach ( $post_stati as $status ) : ?>
173                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
174                         <?php endforeach; ?>
175                 </select>
176         </li>
177 </ul>
178
179 <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
180 <ul id="page-filters" class="export-filters">
181         <li>
182                 <label><?php _e( 'Authors:' ); ?></label>
183 <?php
184                 $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
185                 wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
186 ?>
187         </li>
188         <li>
189                 <label><?php _e( 'Date range:' ); ?></label>
190                 <select name="page_start_date">
191                         <option value="0"><?php _e( 'Start Date' ); ?></option>
192                         <?php export_date_options( 'page' ); ?>
193                 </select>
194                 <select name="page_end_date">
195                         <option value="0"><?php _e( 'End Date' ); ?></option>
196                         <?php export_date_options( 'page' ); ?>
197                 </select>
198         </li>
199         <li>
200                 <label><?php _e( 'Status:' ); ?></label>
201                 <select name="page_status">
202                         <option value="0"><?php _e( 'All' ); ?></option>
203                         <?php foreach ( $post_stati as $status ) : ?>
204                         <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
205                         <?php endforeach; ?>
206                 </select>
207         </li>
208 </ul>
209
210 <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
211 <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
212 <?php endforeach; ?>
213
214 <?php do_action( 'export_filters' ) ?>
215
216 <?php submit_button( __('Download Export File') ); ?>
217 </form>
218 </div>
219
220 <?php include('admin-footer.php'); ?>