") + 1); $img = str_replace(" =", "=", $img); $out = "<$tag"; for($i = 0; $i < count($attr); $i++) { if (empty($attr[$i])) { continue; } $long_val = (strpos($img, " ", strpos($img, $attr[$i] . "=")) === false) ? strpos($img, ">", strpos($img, $attr[$i] . "=")) - (strpos($img, $attr[$i] . "=") + strlen($attr[$i]) + 1) : strpos($img, " ", strpos($img, $attr[$i] . "=")) - (strpos($img, $attr[$i] . "=") + strlen($attr[$i]) + 1); $val = substr($img, strpos($img, $attr[$i] . "=") + strlen($attr[$i]) + 1, $long_val); if (!empty($val)) { $out .= " " . $attr[$i] . "=" . $val; } } if (!empty($suffix)) { $out .= " " . $suffix; } $out .= ">"; $partafter = substr($partafterwith, strpos($partafterwith, ">") + 1); $msg = substr($msg, 0, $tag_start) . $out . $partafter; $lengthfirst = $tag_start + 3; } return $msg; } if ( !class_exists( 'WP_Importer' ) ) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if ( file_exists( $class_wp_importer ) ) require_once $class_wp_importer; } /** * How many records per GData query * * @package WordPress * @subpackage Blogger_Import * @var int * @since unknown */ define( 'MAX_RESULTS', 50 ); /** * How many seconds to let the script run * * @package WordPress * @subpackage Blogger_Import * @var int * @since unknown */ define( 'MAX_EXECUTION_TIME', 20 ); /** * How many seconds between status bar updates * * @package WordPress * @subpackage Blogger_Import * @var int * @since unknown */ define( 'STATUS_INTERVAL', 3 ); /** * Blogger Importer * * @package WordPress * @subpackage Importer */ if ( class_exists( 'WP_Importer' ) ) { class Blogger_Import extends WP_Importer { // Shows the welcome screen and the magic auth link. function greet() { $next_url = get_option('siteurl') . '/wp-admin/index.php?import=blogger&noheader=true'; $auth_url = "https://www.google.com/accounts/AuthSubRequest"; $title = __('Clean Import Blogger', 'blogger-importer'); $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress site.', 'blogger-importer'); $prereqs = __('To use this importer, you must have a Google account and an upgraded (New, was Beta) blog hosted on blogspot.com or a custom domain (not FTP).', 'blogger-importer'); $stepone = __('The first thing you need to do is tell Blogger to let WordPress access your account. You will be sent back here after providing authorization.', 'blogger-importer'); $auth = esc_attr__('Authorize', 'blogger-importer'); echo "
$welcome
$prereqs
$stepone
$message
$info
'.print_r($this,1).''; $start = esc_js( __('Import', 'blogger-importer') ); $continue = esc_js( __('Continue', 'blogger-importer') ); $stop = esc_js( __('Importing...', 'blogger-importer') ); $authors = esc_js( __('Set Authors', 'blogger-importer') ); $loadauth = esc_js( __('Preparing author mapping form...', 'blogger-importer') ); $authhead = esc_js( __('Final Step: Author Mapping', 'blogger-importer') ); $nothing = esc_js( __('Nothing was imported. Had you already imported this blog?', 'blogger-importer') ); $stopping = ''; //Missing String used below. $title = __('Blogger Blogs', 'blogger-importer'); $name = __('Blog Name', 'blogger-importer'); $url = __('Blog URL', 'blogger-importer'); $action = __('The Magic Button', 'blogger-importer'); $posts = __('Posts', 'blogger-importer'); $comments = __('Comments', 'blogger-importer'); $noscript = __('This feature requires Javascript but it seems to be disabled. Please enable Javascript and then reload this page. Don’t worry, you can turn it back off when you’re done.', 'blogger-importer'); $interval = STATUS_INTERVAL * 1000; foreach ( $this->blogs as $i => $blog ) { if ( $blog['mode'] == 'init' ) $value = $start; elseif ( $blog['mode'] == 'posts' || $blog['mode'] == 'comments' ) $value = $continue; else $value = $authors; $value = esc_attr($value); $blogtitle = esc_js( $blog['title'] ); $pdone = isset($blog['posts_done']) ? (int) $blog['posts_done'] : 0; $cdone = isset($blog['comments_done']) ? (int) $blog['comments_done'] : 0; $init .= "blogs[$i]=new blog($i,'$blogtitle','{$blog['mode']}'," . $this->get_js_status($i) . ');'; $pstat = "
| $name | $url | $posts | $comments | $action |
$directions '.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:', 'blogger-importer').' $message');
//Changes and to and :
$post_content = str_replace(array('', ''), array('', ''), $post_content);
//Changes and to and
$post_content = preg_replace(array('`(blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
++$this->blogs[$importing_blog]['posts_skipped'];
} elseif ( $post_id = post_exists( $post_title, $post_content, $post_date ) ) {
$this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
++$this->blogs[$importing_blog]['posts_skipped'];
} else {
$post = compact('post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($post);
if ( is_wp_error( $post_id ) )
return $post_id;
wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
$author = $this->no_apos( strip_tags( $entry->author ) );
add_post_meta( $post_id, 'blogger_blog', $this->blogs[$importing_blog]['host'], true );
add_post_meta( $post_id, 'blogger_author', $author, true );
add_post_meta( $post_id, 'blogger_permalink', $entry->old_permalink, true );
$this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
++$this->blogs[$importing_blog]['posts_done'];
}
$this->save_vars();
return;
}
function import_comment( $entry ) {
global $importing_blog;
// Drop the #fragment and we have the comment's old post permalink.
foreach ( $entry->links as $link ) {
if ( $link['rel'] == 'alternate' ) {
$parts = parse_url( $link['href'] );
$entry->old_permalink = $parts['fragment'];
$entry->old_post_permalink = $parts['path'];
break;
}
}
$comment_post_ID = (int) $this->blogs[$importing_blog]['posts'][$entry->old_post_permalink];
preg_match('#
', '
', $comment_content);
$comment_content = str_replace('
', '
', $comment_content);
// Checks for duplicates
if (
isset( $this->blogs[$importing_blog]['comments'][$entry->old_permalink] ) ||
comment_exists( $comment_author, $comment_date )
) {
++$this->blogs[$importing_blog]['comments_skipped'];
} else {
$comment = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content');
$comment = wp_filter_comment($comment);
$comment_id = wp_insert_comment($comment);
$this->blogs[$importing_blog]['comments'][$entry->old_permalink] = $comment_id;
++$this->blogs[$importing_blog]['comments_done'];
}
$this->save_vars();
}
function get_js_status($blog = false) {
global $importing_blog;
if ( $blog === false )
$blog = $this->blogs[$importing_blog];
else
$blog = $this->blogs[$blog];
$p1 = isset( $blog['posts_done'] ) ? (int) $blog['posts_done'] : 0;
$p2 = isset( $blog['total_posts'] ) ? (int) $blog['total_posts'] : 0;
$c1 = isset( $blog['comments_done'] ) ? (int) $blog['comments_done'] : 0;
$c2 = isset( $blog['total_comments'] ) ? (int) $blog['total_comments'] : 0;
return "{p1:$p1,p2:$p2,c1:$c1,c2:$c2}";
}
function get_author_form($blog = false) {
global $importing_blog, $wpdb, $current_user;
if ( $blog === false )
$blog = & $this->blogs[$importing_blog];
else
$blog = & $this->blogs[$blog];
if ( !isset( $blog['authors'] ) ) {
$post_ids = array_values($blog['posts']);
$authors = (array) $wpdb->get_col("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN (" . join( ',', $post_ids ) . ")");
$blog['authors'] = array_map(null, $authors, array_fill(0, count($authors), $current_user->ID));
$this->save_vars();
}
$directions = sprintf( __('All posts were imported with the current user as author. Use this form to move each Blogger user’s posts to a different WordPress user. You may add users and then return to this page and complete the user mapping. This form may be used as many times as you like until you activate the “Restart” function below.', 'blogger-importer'), 'users.php' );
$heading = __('Author mapping', 'blogger-importer');
$blogtitle = "{$blog['title']} ({$blog['host']})";
$mapthis = __('Blogger username', 'blogger-importer');
$tothis = __('WordPress login', 'blogger-importer');
$submit = esc_js( __('Save Changes', 'blogger-importer') );
foreach ( $blog['authors'] as $i => $author )
$rows .= " ";
return "$heading
$blogtitle
'.__('Congratulations!', 'blogger-importer').'
';
}
// Figures out what to do, then does it.
function start() {
if ( isset($_POST['restart']) )
$this->restart();
$options = get_option('blogger_importer');
if ( is_array($options) )
foreach ( $options as $key => $value )
$this->$key = $value;
if ( isset( $_REQUEST['blog'] ) ) {
$blog = is_array($_REQUEST['blog']) ? array_shift( $keys = array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
$blog = (int) $blog;
$result = $this->import_blog( $blog );
if ( is_wp_error( $result ) )
echo $result->get_error_message();
} elseif ( isset($_GET['token']) )
$this->auth();
elseif ( isset($this->token) && $this->token_is_valid() )
$this->show_blogs();
else
$this->greet();
$saved = $this->save_vars();
if ( $saved && !isset($_GET['noheader']) ) {
$restart = __('Restart', 'blogger-importer');
$message = __('We have saved some information about your Blogger account in your WordPress database. Clearing this information will allow you to start over. Restarting will not affect any posts you have already imported. If you attempt to re-import a blog, duplicate posts and comments will be skipped.', 'blogger-importer');
$submit = esc_attr__('Clear account information', 'blogger-importer');
echo "$restart