322 update_option( 'ljapi_post_batch', ( (int) get_option( 'ljapi_post_batch' ) + 1 ) ); |
322 update_option( 'ljapi_post_batch', ( (int) get_option( 'ljapi_post_batch' ) + 1 ) ); |
323 |
323 |
324 echo '</ol>'; |
324 echo '</ol>'; |
325 } |
325 } |
326 |
326 |
|
327 function _normalize_tag( $matches ) { |
|
328 return '<' . strtolower( $matches[1] ); |
|
329 } |
|
330 |
327 function import_post( $post ) { |
331 function import_post( $post ) { |
328 global $wpdb; |
332 global $wpdb; |
329 |
333 |
330 // Make sure we haven't already imported this one |
334 // Make sure we haven't already imported this one |
331 if ( $this->get_wp_post_ID( $post['itemid'] ) ) |
335 if ( $this->get_wp_post_ID( $post['itemid'] ) ) |
348 $post_title = strip_tags( $post_title ); // Can't have tags in the title in WP |
352 $post_title = strip_tags( $post_title ); // Can't have tags in the title in WP |
349 $post_title = $wpdb->escape( $post_title ); |
353 $post_title = $wpdb->escape( $post_title ); |
350 |
354 |
351 // Clean up content |
355 // Clean up content |
352 $post_content = $post['event']; |
356 $post_content = $post['event']; |
353 $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $post_content ); |
357 $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content ); |
354 // XHTMLize some tags |
358 // XHTMLize some tags |
355 $post_content = str_replace( '<br>', '<br />', $post_content ); |
359 $post_content = str_replace( '<br>', '<br />', $post_content ); |
356 $post_content = str_replace( '<hr>', '<hr />', $post_content ); |
360 $post_content = str_replace( '<hr>', '<hr />', $post_content ); |
357 // lj-cut ==> <!--more--> |
361 // lj-cut ==> <!--more--> |
358 $post_content = preg_replace( '|<lj-cut text="([^"]*)">|is', '<!--more $1-->', $post_content ); |
362 $post_content = preg_replace( '|<lj-cut text="([^"]*)">|is', '<!--more $1-->', $post_content ); |
529 // Filter out any captured, deleted comments (nothing useful to import) |
533 // Filter out any captured, deleted comments (nothing useful to import) |
530 $comment = preg_replace( '|<comment id=\'\d+\' jitemid=\'\d+\' posterid=\'\d+\' state=\'D\'[^/]*/>|is', '', $comment ); |
534 $comment = preg_replace( '|<comment id=\'\d+\' jitemid=\'\d+\' posterid=\'\d+\' state=\'D\'[^/]*/>|is', '', $comment ); |
531 |
535 |
532 // Parse this comment into an array and insert |
536 // Parse this comment into an array and insert |
533 $comment = $this->parse_comment( $comment ); |
537 $comment = $this->parse_comment( $comment ); |
|
538 $comment = wp_filter_comment( $comment ); |
534 $id = wp_insert_comment( $comment ); |
539 $id = wp_insert_comment( $comment ); |
535 |
540 |
536 // Clear cache |
541 // Clear cache |
537 clean_comment_cache( $id ); |
542 clean_comment_cache( $id ); |
538 } |
543 } |
579 $comment_content = @html_entity_decode( $comment_content, ENT_COMPAT, get_option('blog_charset') ); |
584 $comment_content = @html_entity_decode( $comment_content, ENT_COMPAT, get_option('blog_charset') ); |
580 $comment_content = str_replace( ''', "'", $comment_content ); |
585 $comment_content = str_replace( ''', "'", $comment_content ); |
581 $comment_content = wpautop( $comment_content ); |
586 $comment_content = wpautop( $comment_content ); |
582 $comment_content = str_replace( '<br>', '<br />', $comment_content ); |
587 $comment_content = str_replace( '<br>', '<br />', $comment_content ); |
583 $comment_content = str_replace( '<hr>', '<hr />', $comment_content ); |
588 $comment_content = str_replace( '<hr>', '<hr />', $comment_content ); |
584 $comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $comment_content ); |
589 $comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content ); |
585 $comment_content = $wpdb->escape( trim( $comment_content ) ); |
590 $comment_content = $wpdb->escape( trim( $comment_content ) ); |
586 |
591 |
587 // Get and convert the date |
592 // Get and convert the date |
588 preg_match( '|<date>(.*)</date>|i', $comment, $matches ); |
593 preg_match( '|<date>(.*)</date>|i', $comment, $matches ); |
589 $comment_date = trim( str_replace( array( 'T', 'Z' ), ' ', $matches[1] ) ); |
594 $comment_date = trim( str_replace( array( 'T', 'Z' ), ' ', $matches[1] ) ); |
718 update_option( 'ljapi_protected_password', $this->protected_password ); |
723 update_option( 'ljapi_protected_password', $this->protected_password ); |
719 } else { |
724 } else { |
720 $this->protected_password = get_option( 'ljapi_protected_password' ); |
725 $this->protected_password = get_option( 'ljapi_protected_password' ); |
721 } |
726 } |
722 |
727 |
723 // Login to confirm the details are correct |
728 // Log in to confirm the details are correct |
724 if ( empty( $this->username ) || empty( $this->password ) ) { |
729 if ( empty( $this->username ) || empty( $this->password ) ) { |
725 ?> |
730 ?> |
726 <p><?php _e( 'Please enter your LiveJournal username <em>and</em> password so we can download your posts and comments.' ) ?></p> |
731 <p><?php _e( 'Please enter your LiveJournal username <em>and</em> password so we can download your posts and comments.' ) ?></p> |
727 <p><a href="<?php echo esc_url($_SERVER['PHP_SELF'] . '?import=livejournal&step=-1&_wpnonce=' . wp_create_nonce( 'lj-api-import' ) . '&_wp_http_referer=' . esc_attr( str_replace( '&step=1', '', $_SERVER['REQUEST_URI'] ) ) ) ?>"><?php _e( 'Start again' ) ?></a></p> |
732 <p><a href="<?php echo esc_url($_SERVER['PHP_SELF'] . '?import=livejournal&step=-1&_wpnonce=' . wp_create_nonce( 'lj-api-import' ) . '&_wp_http_referer=' . esc_attr( str_replace( '&step=1', '', $_SERVER['REQUEST_URI'] ) ) ) ?>"><?php _e( 'Start again' ) ?></a></p> |
728 <?php |
733 <?php |