X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/312084b5d95c21feb519ff03decf948420e1f6fa..4f9d63e13cd8c6e275797c75b401b074b82937bc:/wp-admin/import/livejournal.php diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php deleted file mode 100644 index 7acfaa5f..00000000 --- a/wp-admin/import/livejournal.php +++ /dev/null @@ -1,1059 +0,0 @@ - 'aggravated', - '10' => 'discontent', - '100' => 'rushed', - '101' => 'contemplative', - '102' => 'nerdy', - '103' => 'geeky', - '104' => 'cynical', - '105' => 'quixotic', - '106' => 'crazy', - '107' => 'creative', - '108' => 'artistic', - '109' => 'pleased', - '11' => 'energetic', - '110' => 'bitchy', - '111' => 'guilty', - '112' => 'irritated', - '113' => 'blank', - '114' => 'apathetic', - '115' => 'dorky', - '116' => 'impressed', - '117' => 'naughty', - '118' => 'predatory', - '119' => 'dirty', - '12' => 'enraged', - '120' => 'giddy', - '121' => 'surprised', - '122' => 'shocked', - '123' => 'rejected', - '124' => 'numb', - '125' => 'cheerful', - '126' => 'good', - '127' => 'distressed', - '128' => 'intimidated', - '129' => 'crushed', - '13' => 'enthralled', - '130' => 'devious', - '131' => 'thankful', - '132' => 'grateful', - '133' => 'jealous', - '134' => 'nervous', - '14' => 'exhausted', - '15' => 'happy', - '16' => 'high', - '17' => 'horny', - '18' => 'hungry', - '19' => 'infuriated', - '2' => 'angry', - '20' => 'irate', - '21' => 'jubilant', - '22' => 'lonely', - '23' => 'moody', - '24' => 'pissed off', - '25' => 'sad', - '26' => 'satisfied', - '27' => 'sore', - '28' => 'stressed', - '29' => 'thirsty', - '3' => 'annoyed', - '30' => 'thoughtful', - '31' => 'tired', - '32' => 'touched', - '33' => 'lazy', - '34' => 'drunk', - '35' => 'ditzy', - '36' => 'mischievous', - '37' => 'morose', - '38' => 'gloomy', - '39' => 'melancholy', - '4' => 'anxious', - '40' => 'drained', - '41' => 'excited', - '42' => 'relieved', - '43' => 'hopeful', - '44' => 'amused', - '45' => 'determined', - '46' => 'scared', - '47' => 'frustrated', - '48' => 'indescribable', - '49' => 'sleepy', - '5' => 'bored', - '51' => 'groggy', - '52' => 'hyper', - '53' => 'relaxed', - '54' => 'restless', - '55' => 'disappointed', - '56' => 'curious', - '57' => 'mellow', - '58' => 'peaceful', - '59' => 'bouncy', - '6' => 'confused', - '60' => 'nostalgic', - '61' => 'okay', - '62' => 'rejuvenated', - '63' => 'complacent', - '64' => 'content', - '65' => 'indifferent', - '66' => 'silly', - '67' => 'flirty', - '68' => 'calm', - '69' => 'refreshed', - '7' => 'crappy', - '70' => 'optimistic', - '71' => 'pessimistic', - '72' => 'giggly', - '73' => 'pensive', - '74' => 'uncomfortable', - '75' => 'lethargic', - '76' => 'listless', - '77' => 'recumbent', - '78' => 'exanimate', - '79' => 'embarrassed', - '8' => 'cranky', - '80' => 'envious', - '81' => 'sympathetic', - '82' => 'sick', - '83' => 'hot', - '84' => 'cold', - '85' => 'worried', - '86' => 'loved', - '87' => 'awake', - '88' => 'working', - '89' => 'productive', - '9' => 'depressed', - '90' => 'accomplished', - '91' => 'busy', - '92' => 'blah', - '93' => 'full', - '95' => 'grumpy', - '96' => 'weird', - '97' => 'nauseated', - '98' => 'ecstatic', - '99' => 'chipper' ); - - function header() { - echo '
' . __( 'Post metadata has been downloaded, proceeding with posts...' ) . '
'; - } - - function download_post_bodies() { - $imported_count = (int) get_option( 'ljapi_imported_count' ); - $sync_item_times = get_option( 'ljapi_sync_item_times' ); - $lastsync = get_option( 'ljapi_lastsync_posts' ); - if ( !$lastsync ) - update_option( 'ljapi_lastsync_posts', date( 'Y-m-d H:i:s', 0 ) ); - - $count = 0; - echo '' . __( 'You have no comments to import!' ) . '
'; - update_option( 'ljapi_highest_id', 1 ); - update_option( 'ljapi_highest_comment_id', 1 ); - return false; // Bail out of comment importing entirely - } - $maxid = !empty( $matches[1] ) ? $matches[1] : $maxid; - - // Parse comments and get highest id available - preg_match_all( '|' . __( ' Comment metadata downloaded successfully, proceeding with comment bodies...' ) . '
'; - - return true; - } - - // Downloads actual comment bodies from LJ - // Inserts them all directly to the DB, with additional info stored in "spare" fields - function download_comment_bodies() { - global $wpdb; - $cookie = $this->get_session(); - if ( is_wp_error( $cookie ) ) - return $cookie; - - // Load previous state (if any) - $this->usermap = (array) get_option( 'ljapi_usermap' ); - $maxid = get_option( 'ljapi_maxid' ) ? (int) get_option( 'ljapi_maxid' ) : 1; - $highest_id = (int) get_option( 'ljapi_highest_comment_id' ); - $loop = 0; - while ( $maxid > $highest_id && $loop < 5 ) { // We do 5 loops per call to avoid memory limits - $loop++; - - // Get a batch of comments, using the highest_id we've already got as a starting point - $results = wp_remote_get( $this->comments_url . '?get=comment_body&startid=' . ( $highest_id + 1 ), - array( 'cookies' => array( $cookie ), 'timeout' => 20 ) ); - if ( is_wp_error( $results ) ) - return new WP_Error( 'comment_bodies', __( 'Failed to retrieve comment bodies from LiveJournal. Please try again soon.' ) ); - - $results = wp_remote_retrieve_body( $results ); - - // Parse out each comment and insert directly - preg_match_all( '|and password so we can download your posts and comments.' ) ?>
- - lj_ixr( 'login' ); - if ( is_wp_error( $verified ) ) { - if ( 100 == $this->ixr->getErrorCode() || 101 == $this->ixr->getErrorCode() ) { - delete_option( 'ljapi_username' ); - delete_option( 'ljapi_password' ); - delete_option( 'ljapi_protected_password' ); - ?> - - - ixr ) $this->ixr = new IXR_Client( $this->ixr_url, false, 80, 30 ); - if ( empty( $_POST['login'] ) ) { - // We're looping -- load some details from DB - $this->username = get_option( 'ljapi_username' ); - $this->password = get_option( 'ljapi_password' ); - $this->protected_password = get_option( 'ljapi_protected_password' ); - } else { - // First run (non-AJAX) - $setup = $this->setup(); - if ( !$setup ) { - return false; - } else if ( is_wp_error( $setup ) ) { - $this->throw_error( $setup, 1 ); - return false; - } - } - - echo '' . __( 'We’re downloading and importing your LiveJournal posts...' ) . '
'; - if ( get_option( 'ljapi_post_batch' ) && count( get_option( 'ljapi_sync_item_times' ) ) ) { - $batch = count( get_option( 'ljapi_sync_item_times' ) ); - $batch = $count > 300 ? ceil( $batch / 300 ) : 1; - echo '' . sprintf( __( 'Imported post batch %d of approximately %d' ), ( get_option( 'ljapi_post_batch' ) + 1 ), $batch ) . '
'; - } - ob_flush(); flush(); - - if ( !get_option( 'ljapi_lastsync' ) || '1900-01-01 00:00:00' == get_option( 'ljapi_lastsync' ) ) { - // We haven't downloaded meta yet, so do that first - $result = $this->download_post_meta(); - if ( is_wp_error( $result ) ) { - $this->throw_error( $result, 1 ); - return false; - } - } - - // Download a batch of actual posts - $result = $this->download_post_bodies(); - if ( is_wp_error( $result ) ) { - if ( 406 == $this->ixr->getErrorCode() ) { - ?> --
- next_step( 1, __( 'Try Again' ) ); - return false; - } else { - $this->throw_error( $result, 1 ); - return false; - } - } - - if ( get_option( 'ljapi_last_sync_count' ) > 0 ) { - ?> - - auto_ajax( 'ljapi-auto-repost', 'auto-message', 0 ); ?> - ' . __( 'Your posts have all been imported, but wait – there’s more! Now we need to download & import your comments.' ) . ''; - echo $this->next_step( 2, __( 'Download my comments »' ) ); - $this->auto_submit(); - } - echo '
' . __( 'Now we will download your comments so we can import them (this could take a long time if you have lots of comments)...' ) . '
'; - ob_flush(); flush(); - - if ( !get_option( 'ljapi_usermap' ) ) { - // We haven't downloaded meta yet, so do that first - $result = $this->download_comment_meta(); - if ( is_wp_error( $result ) ) { - $this->throw_error( $result, 2 ); - return false; - } - } - - // Download a batch of actual comments - $result = $this->download_comment_bodies(); - if ( is_wp_error( $result ) ) { - $this->throw_error( $result, 2 ); - return false; - } - - $maxid = get_option( 'ljapi_maxid' ) ? (int) get_option( 'ljapi_maxid' ) : 1; - $highest_id = (int) get_option( 'ljapi_highest_comment_id' ); - if ( $maxid > $highest_id ) { - $batch = $maxid > 5000 ? ceil( $maxid / 5000 ) : 1; - ?> - - auto_ajax( 'ljapi-auto-repost', 'auto-message', 0 ); ?> - ' . __( 'Your comments have all been imported now, but we still need to rebuild your conversation threads.' ) . ''; - echo $this->next_step( 3, __( 'Rebuild my comment threads »' ) ); - $this->auto_submit(); - } - echo '' . __( 'We are now re-building the threading of your comments (this can also take a while if you have lots of comments)...' ) . '
'; - ob_flush(); flush(); - - // Only bother adding indexes if they have over 5000 comments (arbitrary number) - $imported_comments = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_type = 'livejournal'" ); - $added_indices = false; - if ( 5000 < $imported_comments ) { - include_once(ABSPATH . 'wp-admin/includes/upgrade.php'); - $added_indices = true; - add_clean_index( $wpdb->comments, 'comment_type' ); - add_clean_index( $wpdb->comments, 'comment_karma' ); - add_clean_index( $wpdb->comments, 'comment_agent' ); - } - - // Get LJ comments, which haven't been threaded yet, 5000 at a time and thread them - while ( $comments = $wpdb->get_results( "SELECT comment_ID, comment_agent FROM {$wpdb->comments} WHERE comment_type = 'livejournal' AND comment_agent != '0' LIMIT 5000", OBJECT ) ) { - foreach ( $comments as $comment ) { - $wpdb->update( $wpdb->comments, - array( 'comment_parent' => $this->get_wp_comment_ID( $comment->comment_agent ), 'comment_type' => 'livejournal-done' ), - array( 'comment_ID' => $comment->comment_ID ) ); - } - wp_cache_flush(); - $wpdb->flush(); - } - - // Revert the comments table back to normal and optimize it to reclaim space - if ( $added_indices ) { - drop_index( $wpdb->comments, 'comment_type' ); - drop_index( $wpdb->comments, 'comment_karma' ); - drop_index( $wpdb->comments, 'comment_agent' ); - $wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" ); - } - - // Clean up database and we're out - $this->cleanup(); - do_action( 'import_done', 'livejournal' ); - if ( $imported_comments > 1 ) - echo '' . sprintf( __( "Successfully re-threaded %s comments." ), number_format( $imported_comments ) ) . '
'; - echo '' . $error->get_error_message() . '
'; - echo $this->next_step( $step, __( 'Try Again' ) ); - } - - // Returns the HTML for a link to the next page - function next_step( $next_step, $label, $id = 'ljapi-next-form' ) { - $str = ''; - - return $str; - } - - // Automatically submit the specified form after $seconds - // Include a friendly countdown in the element with id=$msg - function auto_submit( $id = 'ljapi-next-form', $msg = 'auto-message', $seconds = 10 ) { - ?>update( $wpdb->comments, - array( 'comment_karma' => 0, 'comment_agent' => 'WP LJ Importer', 'comment_type' => '' ), - array( 'comment_type' => 'livejournal-done' ) ); - $wpdb->update( $wpdb->comments, - array( 'comment_karma' => 0, 'comment_agent' => 'WP LJ Importer', 'comment_type' => '' ), - array( 'comment_type' => 'livejournal' ) ); - } - - function LJ_API_Import() { - $this->__construct(); - } - - function __construct() { - // Nothing - } -} - -$lj_api_import = new LJ_API_Import(); - -register_importer( 'livejournal', __( 'LiveJournal' ), __( 'Import posts from LiveJournal using their API.' ), array( $lj_api_import, 'dispatch' ) ); -?>