WordPress.org

Plugin Directory

Changeset 310423


Ignore:
Timestamp:
11/11/10 14:01:08 (3 years ago)
Author:
westi
Message:

Fixes/Improvements for the LiveJournal importer from #WP13960.
Moved the AJAX handler into the plugin - props nacin.
Added support for using the WP_HTTP version of the IXR_Client when available.
Fixed the display of elipsis in the messages.
Fixed an incorrect variable name.

Location:
livejournal-importer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • livejournal-importer/trunk/livejournal-importer.php

    r247849 r310423  
    66Author: wordpressdotorg 
    77Author URI: http://wordpress.org/ 
    8 Version: 0.2 
    9 Stable tag: 0.2 
     8Version: 0.3 
     9Stable tag: 0.3 
    1010License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1111*/ 
     12 
     13add_action( 'wp_ajax_livejournal_importer', 'livejournal_import_ajax_handler' ); 
     14 
     15function livejournal_import_ajax_handler() { 
     16    check_ajax_referer( 'lj-api-import' ); 
     17    if ( !current_user_can( 'publish_posts' ) ) 
     18        die('-1'); 
     19    if ( empty( $_POST['step'] ) ) 
     20        die( '-1' ); 
     21    define('WP_IMPORTING', true); 
     22    $result = $lj_api_import->{ 'step' . ( (int) $_POST['step'] ) }(); 
     23    if ( is_wp_error( $result ) ) 
     24        echo $result->get_error_message(); 
     25    die; 
     26} 
    1227 
    1328if ( !defined('WP_LOAD_IMPORTERS') ) 
     
    2540// XML-RPC library for communicating with LiveJournal API 
    2641require_once( ABSPATH . WPINC . '/class-IXR.php' ); 
     42 
     43// WP HTTP based IXR Client class from 3.1 onwards 
     44if ( file_exists( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ) ) { 
     45    $GLOBALS['live_journal_importer_ixr_class'] = 'WP_HTTP_IXR_Client'; 
     46    require_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' ); 
     47} else { 
     48    $GLOBALS['live_journal_importer_ixr_class'] = 'IXR_Client'; 
     49} 
    2750 
    2851/** 
     
    777800    // Check form inputs and start importing posts 
    778801    function step1() { 
    779         global $verified; 
     802        global $verified, $live_journal_importer_ixr_class; 
    780803 
    781804        do_action( 'import_start' ); 
     
    783806        set_time_limit( 0 ); 
    784807        update_option( 'ljapi_step', 1 ); 
    785         if ( !$this->ixr ) $this->ixr = new IXR_Client( $this->ixr_url, false, 80, 30 ); 
     808        if ( !$this->ixr ) $this->ixr = new $live_journal_importer_ixr_class( $this->ixr_url, false, 80, 30 ); 
    786809        if ( empty( $_POST['login'] ) ) { 
    787810            // We're looping -- load some details from DB 
     
    805828        if ( get_option( 'ljapi_post_batch' ) && count( get_option( 'ljapi_sync_item_times' ) ) ) { 
    806829            $batch = count( get_option( 'ljapi_sync_item_times' ) ); 
    807             $batch = $count > 300 ? ceil( $batch / 300 ) : 1; 
     830            $batch = $batch > 300 ? ceil( $batch / 300 ) : 1; 
    808831            echo '<p><strong>' . sprintf( __( 'Imported post batch %d of <strong>approximately</strong> %d' , 'livejournal-importer'), ( get_option( 'ljapi_post_batch' ) + 1 ), $batch ) . '</strong></p>'; 
    809832        } 
     
    854877    // Download comments to local XML 
    855878    function step2() { 
     879        global $live_journal_importer_ixr_class; 
    856880        do_action( 'import_start' ); 
    857881 
     
    860884        $this->username = get_option( 'ljapi_username' ); 
    861885        $this->password = get_option( 'ljapi_password' ); 
    862         $this->ixr = new IXR_Client( $this->ixr_url, false, 80, 30 ); 
     886        $this->ixr = new $live_journal_importer_ixr_class( $this->ixr_url, false, 80, 30 ); 
    863887 
    864888        echo '<div id="ljapi-status">'; 
     
    9871011 
    9881012            function ljapi_msg() { 
    989                 str = '<?php _e( "Continuing in %d&#8230;" , 'livejournal-importer') ?>'; 
    990                 jQuery( '#<?php echo $msg ?>' ).text( str.replace( /%d/, next_counter ) ); 
     1013                str = '<?php echo esc_js( _e( "Continuing in %d&#8230;" , 'livejournal-importer') ); ?>'; 
     1014                jQuery( '#<?php echo $msg ?>' ).html( str.replace( /%d/, next_counter ) ); 
    9911015                if ( next_counter <= 0 ) { 
    9921016                    if ( jQuery( '#<?php echo $id ?>' ).length ) { 
    9931017                        jQuery( "#<?php echo $id ?> input[type='submit']" ).hide(); 
    994                         str = '<?php _e( "Continuing&#8230;" , 'livejournal-importer') ?> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="processing" align="top" />'; 
     1018                        str = '<?php echo esc_js( __( "Continuing&#x8230;" , 'livejournal-importer') ); ?> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="processing" align="top" />'; 
    9951019                        jQuery( '#<?php echo $msg ?>' ).html( str ); 
    9961020                        jQuery( '#<?php echo $id ?>' ).submit(); 
     
    10151039 
    10161040            function ljapi_msg() { 
    1017                 str = '<?php _e( "Continuing in %d&#8230;" , 'livejournal-importer') ?>'; 
    1018                 jQuery( '#<?php echo $msg ?>' ).text( str.replace( /%d/, next_counter ) ); 
     1041                str = '<?php echo esc_js( __( "Continuing in %d&#8230;" , 'livejournal-importer') ); ?>'; 
     1042                jQuery( '#<?php echo $msg ?>' ).html( str.replace( /%d/, next_counter ) ); 
    10191043                if ( next_counter <= 0 ) { 
    10201044                    if ( jQuery( '#<?php echo $id ?>' ).length ) { 
    10211045                        jQuery( "#<?php echo $id ?> input[type='submit']" ).hide(); 
    10221046                        jQuery.ajaxSetup({'timeout':3600000}); 
    1023                         str = '<?php _e( "Processing next batch." , 'livejournal-importer') ?> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="processing" align="top" />'; 
     1047                        str = '<?php echo esc_js( __( "Processing next batch." , 'livejournal-importer') ); ?> <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="processing" align="top" />'; 
    10241048                        jQuery( '#<?php echo $msg ?>' ).html( str ); 
    1025                         jQuery('#ljapi-status').load(ajaxurl, {'action':'lj-importer', 
     1049                        jQuery('#ljapi-status').load(ajaxurl, {'action':'livejournal_importer', 
    10261050                                                                'import':'livejournal', 
    10271051                                                                'step':jQuery('#step').val(), 
     
    10711095    } 
    10721096 
    1073     function LJ_API_Import() { 
    1074         $this->__construct(); 
    1075     } 
    1076  
    1077     function __construct() { 
    1078         // Nothing 
    1079     } 
    10801097} 
    10811098 
  • livejournal-importer/trunk/readme.txt

    r243544 r310423  
    55Requires at least: 3.0 
    66Tested up to: 3.0 
    7 Stable tag: 0.2 
     7Stable tag: 0.3 
    88 
    99Import posts from LiveJournal using their API. 
     
    2525== Changelog == 
    2626 
     27= 0.3 = 
     28* Moved the AJAX Handler out of core and into the plugin 
     29* Added support for using WP_HTTP transports for the API request in WP 3.1 
     30* Fixed the ajax messages to actually display the elipsis 
     31 
     32= 0.2 = 
     33* Updates 
     34 
    2735= 0.1 = 
    2836* Initial release 
Note: See TracChangeset for help on using the changeset viewer.