web/wp-admin/import.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Import WordPress Administration Panel
     3  * Import WordPress Administration Screen
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
       
     9 define('WP_LOAD_IMPORTERS', true);
       
    10 
     9 /** Load WordPress Bootstrap */
    11 /** Load WordPress Bootstrap */
    10 require_once ('admin.php');
    12 require_once ('admin.php');
    11 
    13 
    12 if ( !current_user_can('edit_files') )
    14 if ( !current_user_can('import') )
    13 	wp_die(__('You do not have sufficient permissions to import content in this blog.'));
    15 	wp_die(__('You do not have sufficient permissions to import content in this site.'));
    14 
    16 
    15 $title = __('Import');
    17 $title = __('Import');
       
    18 
       
    19 get_current_screen()->add_help_tab( array(
       
    20 	'id'      => 'overview',
       
    21 	'title'   => __('Overview'),
       
    22 	'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>' .
       
    23 		'<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>',
       
    24 ) );
       
    25 
       
    26 get_current_screen()->set_help_sidebar(
       
    27 	'<p><strong>' . __('For more information:') . '</strong></p>' .
       
    28 	'<p>' . __('<a href="http://codex.wordpress.org/Tools_Import_Screen" target="_blank">Documentation on Import</a>') . '</p>' .
       
    29 	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
       
    30 );
       
    31 
       
    32 $popular_importers = array();
       
    33 if ( current_user_can('install_plugins') )
       
    34 	$popular_importers = array(
       
    35 		'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ),
       
    36 		'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' ),
       
    37 		'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ),
       
    38 		'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' ),
       
    39 		'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ),
       
    40 		'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ),
       
    41 		'tumblr' => array( __('Tumblr'), __('Install the Tumblr importer to import posts &amp; media from Tumblr using their API.'), 'install' ),
       
    42 		'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' )
       
    43 	);
       
    44 
       
    45 if ( ! empty( $_GET['invalid'] ) && !empty($popular_importers[$_GET['invalid']][3]) ) {
       
    46 	wp_redirect( admin_url('import.php?import=' . $popular_importers[$_GET['invalid']][3]) );
       
    47 	exit;
       
    48 }
       
    49 
       
    50 add_thickbox();
       
    51 wp_enqueue_script( 'plugin-install' );
       
    52 
    16 require_once ('admin-header.php');
    53 require_once ('admin-header.php');
    17 $parent_file = 'tools.php';
    54 $parent_file = 'tools.php';
    18 ?>
    55 ?>
    19 
    56 
    20 <div class="wrap">
    57 <div class="wrap">
    21 <?php screen_icon(); ?>
    58 <?php screen_icon(); ?>
    22 <h2><?php echo esc_html( $title ); ?></h2>
    59 <h2><?php echo esc_html( $title ); ?></h2>
    23 <p><?php _e('If you have posts or comments in another system, WordPress can import those into this blog. To get started, choose a system to import from below:'); ?></p>
    60 <?php if ( ! empty( $_GET['invalid'] ) ) : ?>
       
    61 	<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>
       
    62 <?php endif; ?>
       
    63 <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>
    24 
    64 
    25 <?php
    65 <?php
    26 
    66 
    27 // Load all importers so that they can register.
       
    28 $import_loc = 'wp-admin/import';
       
    29 $import_root = ABSPATH.$import_loc;
       
    30 $imports_dir = @ opendir($import_root);
       
    31 if ($imports_dir) {
       
    32 	while (($file = readdir($imports_dir)) !== false) {
       
    33 		if ($file{0} == '.') {
       
    34 			continue;
       
    35 		} elseif (substr($file, -4) == '.php') {
       
    36 			require_once($import_root . '/' . $file);
       
    37 		}
       
    38 	}
       
    39 }
       
    40 @closedir($imports_dir);
       
    41 
       
    42 $importers = get_importers();
    67 $importers = get_importers();
    43 
    68 
    44 if (empty ($importers)) {
    69 // If a popular importer is not registered, create a dummy registration that links to the plugin installer.
       
    70 foreach ( $popular_importers as $pop_importer => $pop_data ) {
       
    71 	if ( isset( $importers[$pop_importer] ) )
       
    72 		continue;
       
    73 	if ( isset( $pop_data[3] ) && isset( $importers[ $pop_data[3] ] ) )
       
    74 		continue;
       
    75 
       
    76 	$importers[$pop_importer] = $popular_importers[$pop_importer];
       
    77 }
       
    78 
       
    79 if ( empty($importers) ) {
    45 	echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
    80 	echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
    46 } else {
    81 } else {
       
    82 	uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
    47 ?>
    83 ?>
    48 <table class="widefat" cellspacing="0">
    84 <table class="widefat importers" cellspacing="0">
    49 
    85 
    50 <?php
    86 <?php
    51 	$style = '';
    87 	$style = '';
    52 	foreach ($importers as $id => $data) {
    88 	foreach ($importers as $id => $data) {
    53 		$style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate';
    89 		$style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate';
    54 		$action = "<a href='admin.php?import=$id' title='".wptexturize(strip_tags($data[1]))."'>{$data[0]}</a>";
    90 		$action = '';
       
    91 		if ( 'install' == $data[2] ) {
       
    92 			$plugin_slug = $id . '-importer';
       
    93 			if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
       
    94 				// Looks like Importer is installed, But not active
       
    95 				$plugins = get_plugins( '/' . $plugin_slug );
       
    96 				if ( !empty($plugins) ) {
       
    97 					$keys = array_keys($plugins);
       
    98 					$plugin_file = $plugin_slug . '/' . $keys[0];
       
    99 					$action = '<a href="' . esc_url(wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $plugin_file . '&from=import'), 'activate-plugin_' . $plugin_file)) .
       
   100 											'"title="' . esc_attr__('Activate importer') . '"">' . $data[0] . '</a>';
       
   101 				}
       
   102 			}
       
   103 			if ( empty($action) ) {
       
   104 				if ( is_main_site() ) {
       
   105 					$action = '<a href="' . esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug .
       
   106 										'&from=import&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="' .
       
   107 										esc_attr__('Install importer') . '">' . $data[0] . '</a>';
       
   108 				} else {
       
   109 					$action = $data[0];
       
   110 					$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' ) );
       
   111 				}
       
   112 			}
       
   113 		} else {
       
   114 			$action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
       
   115 		}
    55 
   116 
    56 		if ($style != '')
   117 		if ($style != '')
    57 			$style = 'class="'.$style.'"';
   118 			$style = 'class="'.$style.'"';
    58 		echo "
   119 		echo "
    59 			<tr $style>
   120 			<tr $style>
    64 ?>
   125 ?>
    65 
   126 
    66 </table>
   127 </table>
    67 <?php
   128 <?php
    68 }
   129 }
       
   130 
       
   131 if ( current_user_can('install_plugins') )
       
   132 	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>';
    69 ?>
   133 ?>
    70 
   134 
    71 </div>
   135 </div>
    72 
   136 
    73 <?php
   137 <?php
    74 
   138 
    75 include ('admin-footer.php');
   139 include ('admin-footer.php');
    76 ?>
       
    77