Make WordPress Core

Ticket #18977: 18977.diff

File 18977.diff, 6.0 KB (added by nacin, 14 years ago)
  • wp-admin/import.php

     
    3131);
    3232
    3333$popular_importers = array();
    34 if ( current_user_can('install_plugins') )
    35         $popular_importers = array(
    36                 'blogger' => array( __('Blogger'), __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'), 'install' ),
    37                 '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' ),
    38                 'livejournal' => array( __( 'LiveJournal' ), __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ), 'install' ),
    39                 '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' ),
    40                 'opml' => array( __('Blogroll'), __('Install the blogroll importer to import links in OPML format.'), 'install' ),
    41                 'rss' => array( __('RSS'), __('Install the RSS importer to import posts from an RSS feed.'), 'install' ),
    42                 'tumblr' => array( __('Tumblr'), __('Install the Tumblr importer to import posts & media from Tumblr using their API.'), 'install' ),
    43                 'wordpress' => array( 'WordPress', __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), 'install' )
    44         );
     34if ( current_user_can('install_plugins') ) {
    4535
    46 if ( ! empty( $_GET['invalid'] ) && !empty($popular_importers[$_GET['invalid']][3]) ) {
    47         wp_redirect( admin_url('import.php?import=' . $popular_importers[$_GET['invalid']][3]) );
     36        $popular_importers = get_site_transient( 'popular_importers' );
     37        if ( empty( $popular_importers ) ) {
     38                $popular_importers = maybe_unserialize( wp_remote_retrieve_body( wp_remote_get( 'http://api.wordpress.org/core/importers/1.0/' ) ) );
     39
     40                if ( $popular_importers ) {
     41                        false && update_site_transient( 'popular_importers', $popular_importers, 604800 ); // week
     42
     43                        foreach ( $popular_importers as &$importer ) {
     44                                // API: importer slug => name, description, register_importer() id
     45                                // $wp_importers: importer slug => name, description, callback
     46                                if ( isset( $importer[2] ) )
     47                                        $importer[3] = $importer[2];
     48                                $importer[2] = 'install'; // dummy callback
     49                                $importer[1] = translate( $importer[1] );
     50                        }
     51                        unset( $importer );
     52
     53                } else {
     54                        // importer slug => name, description, 'install', register_importer() id (if not slug)
     55                        $popular_importers = array(
     56                                'blogger' => array(
     57                                        __('Blogger'),
     58                                        __('Install the Blogger importer to import posts, comments, and users from a Blogger blog.'),
     59                                        'install',
     60                                ),
     61                                'wpcat2tag' => array(
     62                                        __('Categories and Tags Converter'),
     63                                        __('Install the category/tag converter to convert existing categories to tags or tags to categories, selectively.'),
     64                                        'install',
     65                                        'wp-cat2tag',
     66                                ),
     67                                'livejournal' => array(
     68                                        __( 'LiveJournal' ),
     69                                        __( 'Install the LiveJournal importer to import posts from LiveJournal using their API.' ),
     70                                        'install',
     71                                ),
     72                                'movabletype' => array(
     73                                        __('Movable Type and TypePad'),
     74                                        __('Install the Movable Type importer to import posts and comments from a Movable Type or TypePad blog.'),
     75                                        'install',
     76                                        'mt',
     77                                ),
     78                                'opml' => array(
     79                                        __('Blogroll'),
     80                                        __('Install the blogroll importer to import links in OPML format.'),
     81                                        'install',
     82                                ),
     83                                'rss' => array(
     84                                        __('RSS'),
     85                                        __('Install the RSS importer to import posts from an RSS feed.'),
     86                                        'install',
     87                                        'rss',
     88                                ),
     89                                'tumblr' => array(
     90                                        __('Tumblr'),
     91                                        __('Install the Tumblr importer to import posts & media from Tumblr using their API.'),
     92                                        'install',
     93                                ),
     94                                'wordpress' => array(
     95                                        'WordPress',
     96                                        __('Install the WordPress importer to import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'),
     97                                        'install',
     98                                )
     99                        );
     100                }
     101        }
     102}
     103
     104// Redirect invalid importers.
     105if ( ! empty( $_GET['invalid'] ) && ! empty( $popular_importers[ $_GET['invalid'] ][3] ) ) {
     106        wp_redirect( admin_url('import.php?import=' . $popular_importers[ $_GET['invalid'] ][3] ) );
    48107        exit;
    49108}
    50109
     
    69128
    70129// If a popular importer is not registered, create a dummy registration that links to the plugin installer.
    71130foreach ( $popular_importers as $pop_importer => $pop_data ) {
    72         if ( isset( $importers[$pop_importer] ) )
     131        if ( isset( $importers[ $pop_importer ] ) )
    73132                continue;
    74133        if ( isset( $pop_data[3] ) && isset( $importers[ $pop_data[3] ] ) )
    75134                continue;
    76135
    77         $importers[$pop_importer] = $popular_importers[$pop_importer];
     136        $importers[ $pop_importer ] = $popular_importers[ $pop_importer ];
    78137}
    79138
    80 if ( empty($importers) ) {
    81         echo '<p>'.__('No importers are available.').'</p>'; // TODO: make more helpful
     139if ( empty( $importers ) ) {
     140        echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
    82141} else {
    83142        uasort($importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);'));
    84143?>
     
    86145
    87146<?php
    88147        $style = '';
    89         foreach ($importers as $id => $data) {
     148        foreach ($importers as $importer_id => $data) {
    90149                $style = ('class="alternate"' == $style || 'class="alternate active"' == $style) ? '' : 'alternate';
    91150                $action = '';
    92151                if ( 'install' == $data[2] ) {
    93                         $plugin_slug = $id . '-importer';
     152                        $plugin_slug = $importer_id . '-importer';
    94153                        if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
    95154                                // Looks like Importer is installed, But not active
    96155                                $plugins = get_plugins( '/' . $plugin_slug );
     
    112171                                }
    113172                        }
    114173                } else {
    115                         $action = "<a href='" . esc_url("admin.php?import=$id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
     174                        $action = "<a href='" . esc_url("admin.php?import=$importer_id") . "' title='" . esc_attr( wptexturize(strip_tags($data[1])) ) ."'>{$data[0]}</a>";
    116175                }
    117176
    118177                if ($style != '')