PageRenderTime 43ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/df_home/static/test/portalbkd/wp-admin/export.php

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