[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-admin/ -> export.php (source)

   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  <h2><?php echo esc_html( $title ); ?></h2>
 148  
 149  <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
 150  <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>
 151  <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>
 152  
 153  <h3><?php _e( 'Choose what to export' ); ?></h3>
 154  <form action="" method="get" id="export-filters">
 155  <input type="hidden" name="download" value="true" />
 156  <p><label><input type="radio" name="content" value="all" checked="checked" /> <?php _e( 'All content' ); ?></label></p>
 157  <p class="description"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus and custom posts.' ); ?></p>
 158  
 159  <p><label><input type="radio" name="content" value="posts" /> <?php _e( 'Posts' ); ?></label></p>
 160  <ul id="post-filters" class="export-filters">
 161      <li>
 162          <label><?php _e( 'Categories:' ); ?></label>
 163          <?php wp_dropdown_categories( array( 'show_option_all' => __('All') ) ); ?>
 164      </li>
 165      <li>
 166          <label><?php _e( 'Authors:' ); ?></label>
 167  <?php
 168          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
 169          wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
 170  ?>
 171      </li>
 172      <li>
 173          <label><?php _e( 'Date range:' ); ?></label>
 174          <select name="post_start_date">
 175              <option value="0"><?php _e( 'Start Date' ); ?></option>
 176              <?php export_date_options(); ?>
 177          </select>
 178          <select name="post_end_date">
 179              <option value="0"><?php _e( 'End Date' ); ?></option>
 180              <?php export_date_options(); ?>
 181          </select>
 182      </li>
 183      <li>
 184          <label><?php _e( 'Status:' ); ?></label>
 185          <select name="post_status">
 186              <option value="0"><?php _e( 'All' ); ?></option>
 187              <?php $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
 188              foreach ( $post_stati as $status ) : ?>
 189              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 190              <?php endforeach; ?>
 191          </select>
 192      </li>
 193  </ul>
 194  
 195  <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
 196  <ul id="page-filters" class="export-filters">
 197      <li>
 198          <label><?php _e( 'Authors:' ); ?></label>
 199  <?php
 200          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
 201          wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
 202  ?>
 203      </li>
 204      <li>
 205          <label><?php _e( 'Date range:' ); ?></label>
 206          <select name="page_start_date">
 207              <option value="0"><?php _e( 'Start Date' ); ?></option>
 208              <?php export_date_options( 'page' ); ?>
 209          </select>
 210          <select name="page_end_date">
 211              <option value="0"><?php _e( 'End Date' ); ?></option>
 212              <?php export_date_options( 'page' ); ?>
 213          </select>
 214      </li>
 215      <li>
 216          <label><?php _e( 'Status:' ); ?></label>
 217          <select name="page_status">
 218              <option value="0"><?php _e( 'All' ); ?></option>
 219              <?php foreach ( $post_stati as $status ) : ?>
 220              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 221              <?php endforeach; ?>
 222          </select>
 223      </li>
 224  </ul>
 225  
 226  <?php foreach ( get_post_types( array( '_builtin' => false, 'can_export' => true ), 'objects' ) as $post_type ) : ?>
 227  <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
 228  <?php endforeach; ?>
 229  
 230  <?php
 231  /**
 232   * Fires after the export filters form.
 233   *
 234   * @since 3.5.0
 235   */
 236  do_action( 'export_filters' );
 237  ?>
 238  
 239  <?php submit_button( __('Download Export File') ); ?>
 240  </form>
 241  </div>
 242  
 243  <?php include ( ABSPATH . 'wp-admin/admin-footer.php' ); ?>


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu