Make WordPress Core


Ignore:
Timestamp:
11/17/2012 07:20:04 AM (13 years ago)
Author:
nacin
Message:

Pull the list of popular importers from WordPress.org.

These are the importers we suggest on import.php, prompting the user to
install the relevant plugin for the import they want to go through.

If the API is inaccessible, it falls back to a hard-coded list that should
be kept sync'd with the API with each major version of WordPress. This API
enables us to add new importers between releases, as they are completed or
if services gain quick adoption. As a last resort, we can also temporarily
disable importers that are broken (due to API changes, for example).

The importer currently returns English strings (which are then run through
translate() for existing strings), but the locale is passed to the API,
allowing us to ship translated strings if we wish to be adventurous.

props dllh for the assist.
fixes #18977.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import.php

    r19712 r22632  
    3030);
    3131
    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 & 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     );
     32if ( current_user_can( 'install_plugins' ) )
     33    $popular_importers = wp_get_popular_importers();
     34else
     35    $popular_importers = array();
    4436
    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;
     37// Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'
     38if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) {
     39    $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id'];
     40    if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops.
     41        wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) );
     42        exit;
     43    }
     44    unset( $importer_id );
    4845}
    4946
     
    6966// If a popular importer is not registered, create a dummy registration that links to the plugin installer.
    7067foreach ( $popular_importers as $pop_importer => $pop_data ) {
    71     if ( isset( $importers[$pop_importer] ) )
     68    if ( isset( $importers[ $pop_importer ] ) )
    7269        continue;
    73     if ( isset( $pop_data[3] ) && isset( $importers[ $pop_data[3] ] ) )
     70    if ( isset( $importers[ $pop_data['importer-id'] ] ) )
    7471        continue;
    75 
    76     $importers[$pop_importer] = $popular_importers[$pop_importer];
     72    $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] );
    7773}
    7874
    79 if ( empty($importers) ) {
    80     echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
     75if ( empty( $importers ) ) {
     76    echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
    8177} else {
    82     uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
     78    uasort($importers, create_function('$a, $b', 'return strnatcasecmp($a[0], $b[0]);'));
    8379?>
    8480<table class="widefat importers" cellspacing="0">
    8581
    8682<?php
    87     $style = '';
    88     foreach ($importers as $id => $data) {
    89         $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate';
     83    $alt = '';
     84    foreach ($importers as $importer_id => $data) {
    9085        $action = '';
    91         if ( 'install' == $data[2] ) {
    92             $plugin_slug = $id . '-importer';
     86        if ( isset( $data['install'] ) ) {
     87            $plugin_slug = $data['install'];
    9388            if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
    9489                // Looks like Importer is installed, But not active
     
    112107            }
    113108        } else {
    114             $action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
     109            $action = "<a href='" . esc_url( "admin.php?import=$importer_id" ) . "' title='" . esc_attr( wptexturize( strip_tags( $data[1] ) ) ) ."'>{$data[0]}</a>";
    115110        }
    116111
    117         if ($style != '')
    118             $style = 'class="'.$style.'"';
     112        $alt = $alt ? '' : ' class="alternate"';
    119113        echo "
    120             <tr $style>
     114            <tr$alt>
    121115                <td class='import-system row-title'>$action</td>
    122116                <td class='desc'>{$data[1]}</td>
Note: See TracChangeset for help on using the changeset viewer.