PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/import.php

https://bitbucket.org/julianelve/vendor-wordpress
PHP | 133 lines | 101 code | 22 blank | 10 comment | 19 complexity | 82f5ef728850c3e7a769c76da69ce859 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Import WordPress Administration Screen
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. define('WP_LOAD_IMPORTERS', true);
  9. /** Load WordPress Bootstrap */
  10. require_once ('admin.php');
  11. if ( !current_user_can('import') )
  12. wp_die(__('You do not have sufficient permissions to import content in this site.'));
  13. $title = __('Import');
  14. get_current_screen()->add_help_tab( array(
  15. 'id' => 'overview',
  16. 'title' => __('Overview'),
  17. 'content' => '<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>' .
  18. '<p>' . __('In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.') . '</p>',
  19. ) );
  20. get_current_screen()->set_help_sidebar(
  21. '<p><strong>' . __('For more information:') . '</strong></p>' .
  22. '<p>' . __('<a href="http://codex.wordpress.org/Tools_Import_Screen" target="_blank">Documentation on Import</a>') . '</p>' .
  23. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  24. );
  25. if ( current_user_can( 'install_plugins' ) )
  26. $popular_importers = wp_get_popular_importers();
  27. else
  28. $popular_importers = array();
  29. // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'
  30. if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) {
  31. $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id'];
  32. if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops.
  33. wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) );
  34. exit;
  35. }
  36. unset( $importer_id );
  37. }
  38. add_thickbox();
  39. wp_enqueue_script( 'plugin-install' );
  40. require_once ('admin-header.php');
  41. $parent_file = 'tools.php';
  42. ?>
  43. <div class="wrap">
  44. <?php screen_icon(); ?>
  45. <h2><?php echo esc_html( $title ); ?></h2>
  46. <?php if ( ! empty( $_GET['invalid'] ) ) : ?>
  47. <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>
  48. <?php endif; ?>
  49. <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>
  50. <?php
  51. $importers = get_importers();
  52. // If a popular importer is not registered, create a dummy registration that links to the plugin installer.
  53. foreach ( $popular_importers as $pop_importer => $pop_data ) {
  54. if ( isset( $importers[ $pop_importer ] ) )
  55. continue;
  56. if ( isset( $importers[ $pop_data['importer-id'] ] ) )
  57. continue;
  58. $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] );
  59. }
  60. if ( empty( $importers ) ) {
  61. echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
  62. } else {
  63. uasort($importers, create_function('$a, $b', 'return strnatcasecmp($a[0], $b[0]);'));
  64. ?>
  65. <table class="widefat importers" cellspacing="0">
  66. <?php
  67. $alt = '';
  68. foreach ($importers as $importer_id => $data) {
  69. $action = '';
  70. if ( isset( $data['install'] ) ) {
  71. $plugin_slug = $data['install'];
  72. if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
  73. // Looks like Importer is installed, But not active
  74. $plugins = get_plugins( '/' . $plugin_slug );
  75. if ( !empty($plugins) ) {
  76. $keys = array_keys($plugins);
  77. $plugin_file = $plugin_slug . '/' . $keys[0];
  78. $action = '<a href="' . esc_url(wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $plugin_file . '&from=import'), 'activate-plugin_' . $plugin_file)) .
  79. '"title="' . esc_attr__('Activate importer') . '"">' . $data[0] . '</a>';
  80. }
  81. }
  82. if ( empty($action) ) {
  83. if ( is_main_site() ) {
  84. $action = '<a href="' . esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug .
  85. '&from=import&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="' .
  86. esc_attr__('Install importer') . '">' . $data[0] . '</a>';
  87. } else {
  88. $action = $data[0];
  89. $data[1] = sprintf( __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), get_admin_url( $current_site->blog_id, 'import.php' ) );
  90. }
  91. }
  92. } else {
  93. $action = "<a href='" . esc_url( "admin.php?import=$importer_id" ) . "' title='" . esc_attr( wptexturize( strip_tags( $data[1] ) ) ) ."'>{$data[0]}</a>";
  94. }
  95. $alt = $alt ? '' : ' class="alternate"';
  96. echo "
  97. <tr$alt>
  98. <td class='import-system row-title'>$action</td>
  99. <td class='desc'>{$data[1]}</td>
  100. </tr>";
  101. }
  102. ?>
  103. </table>
  104. <?php
  105. }
  106. if ( current_user_can('install_plugins') )
  107. echo '<p>' . sprintf( __('If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.'), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '</p>';
  108. ?>
  109. </div>
  110. <?php
  111. include ('admin-footer.php');