[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Import WordPress Administration Screen
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  define('WP_LOAD_IMPORTERS', true);
  10  
  11  /** Load WordPress Bootstrap */
  12  require_once  ('admin.php');
  13  
  14  if ( !current_user_can('import') )
  15      wp_die(__('You do not have sufficient permissions to import content in this site.'));
  16  
  17  $title = __('Import');
  18  
  19  add_contextual_help($current_screen,
  20      '<p>' . __('This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.') . '</p>' .
  21      '<p>' . __('In previous versions of WordPress, all the importers were built-in, but they have been turned into plugins as of version 3.0 since most people only use them once or infrequently.') . '</p>' .
  22      '<p><strong>' . __('For more information:') . '</strong></p>' .
  23      '<p>' . __('<a href="http://codex.wordpress.org/Tools_Import_Screen" target="_blank">Documentation on Import</a>') . '</p>' .
  24      '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  25  );
  26  
  27  $popular_importers = array();
  28  if ( current_user_can('install_plugins') )
  29      $popular_importers = array(
  30          'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ),
  31          'wpcat2tag' => array(__('Categories and Tags Converter'), __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'), 'install', 'wp-cat2tag' ),
  32          'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ),
  33          'movabletype' => array( __('Movable Type and TypePad'), __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'), 'install', 'mt' ),
  34          'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ),
  35          'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ),
  36          'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' )
  37      );
  38  
  39  if ( ! empty( $_GET['invalid'] ) && !empty($popular_importers[$_GET['invalid']][3]) ) {
  40      wp_redirect( admin_url('import.php?import=' . $popular_importers[$_GET['invalid']][3]) );
  41      exit;
  42  }
  43  
  44  add_thickbox();
  45  wp_enqueue_script( 'plugin-install' );
  46  wp_admin_css( 'plugin-install' );
  47  
  48  require_once  ('admin-header.php');
  49  $parent_file = 'tools.php';
  50  ?>
  51  
  52  <div class="wrap">
  53  <?php screen_icon(); ?>
  54  <h2><?php echo esc_html( $title ); ?></h2>
  55  <?php if ( ! empty( $_GET['invalid'] ) ) : ?>
  56      <div class="error"><p><strong><?php _e('ERROR:')?></strong> <?php printf( __('The <strong>%s</strong> importer is invalid or is not installed.'), esc_html( $_GET['invalid'] ) ); ?></p></div>
  57  <?php endif; ?>
  58  <p><?php _e('If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:'); ?></p>
  59  
  60  <?php
  61  
  62  // Load all importers so that they can register.
  63  $import_loc = 'wp-admin/import';
  64  $import_root = ABSPATH . $import_loc;
  65  
  66  if ( file_exists( $import_root ) ) {
  67      $imports_dir = opendir($import_root);
  68      if ($imports_dir) {
  69          while (($file = readdir($imports_dir)) !== false) {
  70              if ($file[0] == '.') {
  71                  continue;
  72              } elseif (substr($file, -4) == '.php') {
  73                  require_once($import_root . '/' . $file);
  74              }
  75          }
  76      }
  77      closedir( $imports_dir );
  78  }
  79  
  80  $importers = get_importers();
  81  
  82  // If a popular importer is not registered, create a dummy registration that links to the plugin installer.
  83  foreach ( $popular_importers as $pop_importer => $pop_data ) {
  84      if ( isset($importers[$pop_importer] ) )
  85          continue;
  86      if ( isset( $pop_data[3] ) && isset( $importers[ $pop_data[3] ] ) )
  87          continue;
  88  
  89      $importers[$pop_importer] = $popular_importers[$pop_importer];
  90  }
  91  
  92  if (empty ($importers)) {
  93      echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
  94  } else {
  95      uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
  96  ?>
  97  <table class="widefat" cellspacing="0">
  98  
  99  <?php
 100      $style = '';
 101      foreach ($importers as $id => $data) {
 102          $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate';
 103          $action = '';
 104          if ( 'install' == $data[2] ) {
 105              $plugin_slug = $id . '-importer';
 106              if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
 107                  // Looks like Importer is installed, But not active
 108                  $plugins = get_plugins( '/' . $plugin_slug );
 109                  if ( !empty($plugins) ) {
 110                      $keys = array_keys($plugins);
 111                      $plugin_file = $plugin_slug . '/' . $keys[0];
 112                      $action = '<a href="' . esc_url(wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $plugin_file . '&from=import'), 'activate-plugin_' . $plugin_file)) .
 113                                              '"title="' . esc_attr__('Activate importer') . '"">' . $data[0] . '</a>';
 114                  }
 115              }
 116              if ( empty($action) )
 117                  $action = '<a href="' . esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug .
 118                                          '&from=import&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="' .
 119                                          esc_attr__('Install importer') . '">' . $data[0] . '</a>';
 120          } else {
 121              $action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
 122          }
 123  
 124          if ($style != '')
 125              $style = 'class="'.$style.'"';
 126          echo "
 127              <tr $style>
 128                  <td class='import-system row-title'>$action</td>
 129                  <td class='desc'>{$data[1]}</td>
 130              </tr>";
 131      }
 132  ?>
 133  
 134  </table>
 135  <?php
 136  }
 137  
 138  if ( current_user_can('install_plugins') )
 139      echo '<p>' . sprintf( __('If the importer you need is not listed, <a href="%s">search the plugins directory</a> to see if an importer is available.'), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '</p>';
 140  ?>
 141  
 142  </div>
 143  
 144  <?php
 145  
 146  include  ('admin-footer.php');
 147  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting