Index: trunk/wp-admin/import/livejournal.php
===================================================================
--- trunk/wp-admin/import/livejournal.php	(revision 10647)
+++ trunk/wp-admin/import/livejournal.php	(revision 10810)
@@ -31,5 +31,5 @@
 	var $commentmap;
 	var $pointers = array();
-	
+
 	// This list taken from LJ, they don't appear to have an API for it
 	var $moods = array( '1' => 'aggravated',
@@ -194,5 +194,5 @@
 			<p><?php _e( 'Howdy! This importer allows you to connect directly to LiveJournal and download all your entries and comments' ) ?></p>
 			<p><?php _e( 'Enter your LiveJournal username and password below so we can connect to your account:' ) ?></p>
-		
+
 			<table class="form-table">
 
@@ -206,7 +206,7 @@
 			<td><input type="password" name="lj_password" id="lj_password" class="regular-text" /></td>
 			</tr>
-      
+
 			</table>
-      
+
 			<p><?php _e( 'If you have any entries on LiveJournal which are marked as private, they will be password-protected when they are imported so that only people who know the password can see them.' ) ?></p>
 			<p><?php _e( "If you don't enter a password, ALL ENTRIES from your LiveJournal will be imported as public posts in WordPress." ) ?></p>
@@ -222,9 +222,9 @@
 
 			<p><?php _e( "<strong>WARNING:</strong> This can take a really long time if you have a lot of entries in your LiveJournal, or a lot of comments. Ideally, you should only start this process if you can leave your computer alone while it finishes the import." ) ?></p>
-		
+
 			<p class="submit">
 				<input type="submit" class="button-primary" value="<?php echo attribute_escape( __( 'Connect to LiveJournal and Import' ) ) ?>" />
 			</p>
-		
+
 			<p><?php _e( '<strong>NOTE:</strong> If the import process is interrupted for <em>any</em> reason, come back to this page and it will continue from where it stopped automatically.' ) ?></p>
 
@@ -237,5 +237,5 @@
 		<?php
 	}
-	
+
 	function download_post_meta() {
 		$total           = (int) get_option( 'ljapi_total' );
@@ -248,5 +248,5 @@
 		if ( !is_array( $sync_item_times ) )
 			$sync_item_times = array();
-		
+
 		do {
 			$lastsync = date( 'Y-m-d H:i:s', strtotime( get_option( 'ljapi_lastsync' ) ) );
@@ -254,9 +254,9 @@
 			if ( is_wp_error( $synclist ) )
 				return $synclist;
-				
+
 			// Keep track of if we've downloaded everything
 			$total = $synclist['total'];
 			$count = $synclist['count'];
-		
+
 			foreach ( $synclist['syncitems'] as $event ) {
 				if ( substr( $event['item'], 0, 2 ) == 'L-' ) {
@@ -277,5 +277,5 @@
 		echo '<p>' . __( 'Post metadata has been downloaded, proceeding with posts...' ) . '</p>';
 	}
-	
+
 	function download_post_bodies() {
 		$imported_count  = (int) get_option( 'ljapi_imported_count' );
@@ -286,8 +286,8 @@
 
 		$count = 0;
-		echo '<ol>';		
+		echo '<ol>';
 		do {
 			$lastsync = date( 'Y-m-d H:i:s', strtotime( get_option( 'ljapi_lastsync_posts' ) ) );
-			
+
 			// Get the batch of items that match up with the syncitems list
 			$itemlist = $this->lj_ixr( 'getevents', array( 'ver' => 1,
@@ -297,5 +297,5 @@
 			if ( is_wp_error( $itemlist ) )
 				return $itemlist;
-			
+
 			if ( $num = count( $itemlist['events'] ) ) {
 				for ( $e = 0; $e < count( $itemlist['events'] ); $e++ ) {
@@ -315,8 +315,8 @@
 			$count++;
 		} while ( $num > 0 && $count < 3 ); // Doing up to 3 requests at a time to avoid memory problems
-		
+
 		// Used so that step1 knows when to stop posting back on itself
 		update_option( 'ljapi_last_sync_count', $num );
-		
+
 		// Counter just used to show progress to user
 		update_option( 'ljapi_post_batch', ( (int) get_option( 'ljapi_post_batch' ) + 1 ) );
@@ -324,12 +324,12 @@
 		echo '</ol>';
 	}
-	
+
 	function import_post( $post ) {
 		global $wpdb;
-		
+
 		// Make sure we haven't already imported this one
 		if ( $this->get_wp_post_ID( $post['itemid'] ) )
 			return;
-		
+
 		$user = wp_get_current_user();
 		$post_author      = $user->ID;
@@ -342,5 +342,5 @@
 		if ( 18 == strlen( $post_date ) )
 			$post_date = substr( $post_date, 0, 10 ) . ' ' . substr( $post_date, 10 );
-		
+
 		// Cleaning up and linking the title
 		$post_title = isset( $post['subject'] ) ? trim( $post['subject'] ) : '';
@@ -348,5 +348,5 @@
 		$post_title = strip_tags( $post_title ); // Can't have tags in the title in WP
 		$post_title = $wpdb->escape( $post_title );
-		
+
 		// Clean up content
 		$post_content = $post['event'];
@@ -364,8 +364,8 @@
 		$post_content = force_balance_tags( $post_content );
 		$post_content = $wpdb->escape( $post_content );
-		
+
 		// Handle any tags associated with the post
 		$tags_input = !empty( $post['props']['taglist'] ) ? $post['props']['taglist'] : '';
-		
+
 		// Check if comments are closed on this post
 		$comment_status = !empty( $post['props']['opt_nocomments'] ) ? 'closed' : 'open';
@@ -388,5 +388,5 @@
 				return new WP_Error( 'insert_post_failed', __( 'Failed to create post.' ) );
 			}
-			
+
 			// Handle all the metadata for this post
 			$this->insert_postmeta( $post_id, $post );
@@ -394,17 +394,17 @@
 		echo '</li>';
 	}
-	
+
 	// Convert lj-user tags to links to that user
 	function translate_lj_user( $str ) {
 		return preg_replace( '|<lj\s+user\s*=\s*["\']([\w-]+)["\']>|', '<a href="http://$1.livejournal.com/" class="lj-user">$1</a>', $str );
 	}
-	
+
 	function insert_postmeta( $post_id, $post ) {
 		// Need the original LJ id for comments
 		add_post_meta( $post_id, 'lj_itemid', $post['itemid'] );
-		
+
 		// And save the permalink on LJ in case we want to link back or something
 		add_post_meta( $post_id, 'lj_permalink', $post['url'] );
-		
+
 		// Supports the following "props" from LJ, saved as lj_<prop_name> in wp_postmeta
 		// 		Adult Content - adult_content
@@ -425,5 +425,5 @@
 		}
 	}
-	
+
 	// Set up a session (authenticate) with LJ
 	function get_session() {
@@ -434,5 +434,5 @@
 		return new WP_Http_Cookie( array( 'name' => 'ljsession', 'value' => $cookie['ljsession'] ) );
 	}
-	
+
 	// Loops through and gets comment meta from LJ in batches
 	function download_comment_meta() {
@@ -440,10 +440,10 @@
 		if ( is_wp_error( $cookie ) )
 			return $cookie;
-		
+
 		// Load previous state (if any)
 		$this->usermap = (array) get_option( 'ljapi_usermap' );
 		$maxid         = get_option( 'ljapi_maxid' ) ? get_option( 'ljapi_maxid' ) : 1;
 		$highest_id    = get_option( 'ljapi_highest_id' ) ? get_option( 'ljapi_highest_id' ) : 0;
-		
+
 		// We need to loop over the metadata request until we have it all
 		while ( $maxid > $highest_id ) {
@@ -453,7 +453,7 @@
 			if ( is_wp_error( $results ) )
 				return new WP_Error( 'comment_meta', __( 'Failed to retrieve comment meta information from LiveJournal. Please try again soon.' ) );
-			
+
 			$results = wp_remote_retrieve_body( $results );
-			
+
 			// Get the maxid so we know if we have them all yet
 			preg_match( '|<maxid>(\d+)</maxid>|', $results, $matches );
@@ -466,5 +466,5 @@
 			}
 			$maxid = !empty( $matches[1] ) ? $matches[1] : $maxid;
-			
+
 			// Parse comments and get highest id available
 			preg_match_all( '|<comment id=\'(\d+)\'|is', $results, $matches );
@@ -478,5 +478,5 @@
 			foreach ( $matches[1] as $count => $userid )
 				$this->usermap[$userid] = $matches[2][$count]; // need this in memory for translating ids => names
-				
+
 			wp_cache_flush();
 		}
@@ -486,10 +486,10 @@
 		update_option( 'ljapi_maxid',      $maxid );
 		update_option( 'ljapi_highest_id', $highest_id );
-		
+
 		echo '<p>' . __( ' Comment metadata downloaded successfully, proceeding with comment bodies...' ) . '</p>';
-		
+
 		return true;
 	}
-	
+
 	// Downloads actual comment bodies from LJ
 	// Inserts them all directly to the DB, with additional info stored in "spare" fields
@@ -499,5 +499,5 @@
 		if ( is_wp_error( $cookie ) )
 			return $cookie;
-		
+
 		// Load previous state (if any)
 		$this->usermap = (array) get_option( 'ljapi_usermap' );
@@ -507,5 +507,5 @@
 		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 ),
@@ -513,7 +513,7 @@
 			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( '|<comment id=\'(\d+)\'.*</comment>|iUs', $results, $matches );
@@ -524,5 +524,5 @@
 					update_option( 'ljapi_highest_comment_id', $highest_id );
 				}
-					
+
 				$comment = $matches[0][$c];
 
@@ -537,20 +537,20 @@
 				clean_comment_cache( $id );
 			}
-			
+
 			// Clear cache to preseve memory
 			wp_cache_flush();
 		}
 		// endwhile - all comments downloaded and ready for bulk processing
-		
+
 		// Counter just used to show progress to user
 		update_option( 'ljapi_comment_batch', ( (int) get_option( 'ljapi_comment_batch' ) + 1 ) );
-		
+
 		return true;
 	}
-	
+
 	// Takes a block of XML and parses out all the elements of the comment
 	function parse_comment( $comment ) {
 		global $wpdb;
-		
+
 		// Get the top-level attributes
 		preg_match( '|<comment([^>]+)>|i', $comment, $attribs );
@@ -565,5 +565,5 @@
 		preg_match( '| state=\'([SDFA])\'|i', $attribs[1], $matches ); // optional
 		$lj_comment_state = isset( $matches[1] ) ? $matches[1] : 'A';
-		
+
 		// Clean up "subject" - this will become the first line of the comment in WP
 		preg_match( '|<subject>(.*)</subject>|is', $comment, $matches );
@@ -573,5 +573,5 @@
 				$comment_subject = '';
 		}
-		
+
 		// Get the body and HTMLize it
 		preg_match( '|<body>(.*)</body>|is', $comment, $matches );
@@ -584,13 +584,13 @@
 		$comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $comment_content );
 		$comment_content = $wpdb->escape( trim( $comment_content ) );
-		
+
 		// Get and convert the date
 		preg_match( '|<date>(.*)</date>|i', $comment, $matches );
 		$comment_date = trim( str_replace( array( 'T', 'Z' ), ' ', $matches[1] ) );
-		
+
 		// Grab IP if available
 		preg_match( '|<property name=\'poster_ip\'>(.*)</property>|i', $comment, $matches ); // optional
 		$comment_author_IP = isset( $matches[1] ) ? $matches[1] : '';
-		
+
 		// Try to get something useful for the comment author, especially if it was "my" comment
 		$author = ( empty( $comment_author_ID ) || empty( $this->usermap[$comment_author_ID] ) || substr( $this->usermap[$comment_author_ID], 0, 4 ) == 'ext_' ) ? __( 'Anonymous' ) : $this->usermap[$comment_author_ID];
@@ -602,7 +602,7 @@
 		} else {
 			$user_id = 0;
-			$url     = ( __( 'Anonymous' ) == $author ) ? '' : 'http://' . $author . '.livejournal.com/';			
-		}
-		
+			$url     = ( __( 'Anonymous' ) == $author ) ? '' : 'http://' . $author . '.livejournal.com/';
+		}
+
 		// Send back the array of details
 		return array( 'lj_comment_ID' => $lj_comment_ID,
@@ -624,16 +624,16 @@
 					);
 	}
-	
-	
+
+
 	// Gets the post_ID that a LJ post has been saved as within WP
 	function get_wp_post_ID( $post ) {
 		global $wpdb;
-		
+
 		if ( empty( $this->postmap[$post] ) )
 		 	$this->postmap[$post] = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'lj_itemid' AND meta_value = %d", $post ) );
-		
+
 		return $this->postmap[$post];
 	}
-	
+
 	// Gets the comment_ID that a LJ comment has been saved as within WP
 	function get_wp_comment_ID( $comment ) {
@@ -643,5 +643,5 @@
 		return $this->commentmap[$comment];
 	}
-			
+
 	function lj_ixr() {
 		if ( $challenge = $this->ixr->query( 'LJ.XMLRPC.getchallenge' ) ) {
@@ -656,5 +656,5 @@
 			return new WP_Error( 'IXR', __( 'LiveJournal is not responding to authentication requests. Please wait a while and then try again.' ) );
 		}
-		
+
 		$args = func_get_args();
         $method = array_shift( $args );
@@ -667,5 +667,5 @@
 		}
 	}
-	
+
 	function dispatch() {
 		if ( empty( $_REQUEST['step'] ) )
@@ -675,5 +675,5 @@
 
 		$this->header();
-		
+
 		switch ( $step ) {
 			case -1 :
@@ -712,5 +712,5 @@
 			$this->password = get_option( 'ljapi_password' );
 		}
-	
+
 		// This is the password to set on protected posts
 		if ( !empty( $_POST['protected_password'] ) ) {
@@ -720,5 +720,5 @@
 			$this->protected_password = get_option( 'ljapi_protected_password' );
 		}
-		
+
 		// Login to confirm the details are correct
 		if ( empty( $this->username ) || empty( $this->password ) ) {
@@ -746,10 +746,10 @@
 			update_option( 'ljapi_verified', 'yes' );
 		}
-		
+
 		// Set up some options to avoid them autoloading (these ones get big)
 		add_option( 'ljapi_sync_item_times',  '', '', 'no' );
 		add_option( 'ljapi_usermap',          '', '', 'no' );
 		update_option( 'ljapi_comment_batch', 0 );
-		
+
 		return true;
 	}
@@ -776,5 +776,5 @@
 			}
 		}
-		
+
 		echo '<div id="ljapi-status">';
 		echo '<h3>' . __( 'Importing Posts' ) . '</h3>';
@@ -786,5 +786,5 @@
 		}
 		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
@@ -828,5 +828,5 @@
 		echo '</div>';
 	}
-	
+
 	// Download comments to local XML
 	function step2() {
@@ -836,10 +836,10 @@
 		$this->password = get_option( 'ljapi_password' );
 		$this->ixr = new IXR_Client( $this->ixr_url, false, 80, 30 );
-		
+
 		echo '<div id="ljapi-status">';
 		echo '<h3>' . __( 'Downloading Comments' ) . '</h3>';
 		echo '<p>' . __( 'Now we will download your comments so we can import them (this could take a <strong>long</strong> time if you have lots of comments)...' ) . '</p>';
 		ob_flush(); flush();
-		
+
 		if ( !get_option( 'ljapi_usermap' ) ) {
 			// We haven't downloaded meta yet, so do that first
@@ -878,5 +878,5 @@
 		echo '</div>';
 	}
-	
+
 	// Re-thread comments already in the DB
 	function step3() {
@@ -884,10 +884,10 @@
 		set_time_limit( 0 );
 		update_option( 'ljapi_step', 3 );
-		
+
 		echo '<div id="ljapi-status">';
 		echo '<h3>' . __( 'Threading Comments' ) . '</h3>';
 		echo '<p>' . __( 'We are now re-building the threading of your comments (this can also take a while if you have lots of comments)...' ) . '</p>';
 		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'" );
@@ -900,10 +900,10 @@
 			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' ), 
+				$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 ) );
 			}
@@ -911,5 +911,5 @@
 			$wpdb->flush();
 		}
-		
+
 		// Revert the comments table back to normal and optimize it to reclaim space
 		if ( $added_indices ) {
@@ -919,5 +919,5 @@
 			$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
 		}
-		
+
 		// Clean up database and we're out
 		$this->cleanup();
@@ -930,5 +930,5 @@
 		echo '</div>';
 	}
-	
+
 	// Output an error message with a button to try again.
 	function throw_error( $error, $step ) {
@@ -936,5 +936,5 @@
 		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' ) {
@@ -945,8 +945,8 @@
 		$str .= '<p><input type="submit" class="button-primary" value="' . attribute_escape( $label ) . '" /> <span id="auto-message"></span></p>';
 		$str .= '</form>';
-		
+
 		return $str;
 	}
-	
+
 	// Automatically submit the specified form after $seconds
 	// Include a friendly countdown in the element with id=$msg
@@ -957,5 +957,5 @@
 				ljapi_msg();
 			});
-			
+
 			function ljapi_msg() {
 				str = '<?php _e( "Continuing in %d" ) ?>';
@@ -975,5 +975,5 @@
 		</script><?php
 	}
-	
+
 	// Automatically submit the form with #id to continue the process
 	// Hide any submit buttons to avoid people clicking them
@@ -985,5 +985,5 @@
 				ljapi_msg();
 			});
-			
+
 			function ljapi_msg() {
 				str = '<?php _e( "Continuing in %d" ) ?>';
@@ -1012,5 +1012,5 @@
 	function cleanup() {
 		global $wpdb;
-		
+
 		delete_option( 'ljapi_username' );
 		delete_option( 'ljapi_password' );
@@ -1031,17 +1031,17 @@
 		delete_option( 'ljapi_comment_batch' );
 		delete_option( 'ljapi_step' );
-		
-		$wpdb->update( $wpdb->comments, 
-						array( 'comment_karma' => 0, 'comment_agent' => 'WP LJ Importer', 'comment_type' => '' ), 
+
+		$wpdb->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' => '' ), 
+		$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
