From 4976188b2fcd307ed16dca6c50e59f642bb25520 Mon Sep 17 00:00:00 2001 From: wpmuguru Date: Thu, 20 May 2010 20:54:28 +0000 Subject: [PATCH] move importers to plugin repo, see #13307 git-svn-id: http://svn.automattic.com/wordpress/trunk@14764 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/import/blogger.php | 1077 ------------------------------- wp-admin/import/blogware.php | 211 ------ wp-admin/import/dotclear.php | 675 ------------------- wp-admin/import/greymatter.php | 334 ---------- wp-admin/import/livejournal.php | 1070 ------------------------------ wp-admin/import/mt.php | 508 --------------- wp-admin/import/opml.php | 152 ----- wp-admin/import/rss.php | 196 ------ wp-admin/import/stp.php | 170 ----- wp-admin/import/textpattern.php | 691 -------------------- wp-admin/import/utw.php | 290 --------- wp-admin/import/wordpress.php | 898 -------------------------- wp-admin/import/wp-cat2tag.php | 473 -------------- 13 files changed, 6745 deletions(-) delete mode 100644 wp-admin/import/blogger.php delete mode 100644 wp-admin/import/blogware.php delete mode 100644 wp-admin/import/dotclear.php delete mode 100644 wp-admin/import/greymatter.php delete mode 100644 wp-admin/import/livejournal.php delete mode 100644 wp-admin/import/mt.php delete mode 100644 wp-admin/import/opml.php delete mode 100644 wp-admin/import/rss.php delete mode 100644 wp-admin/import/stp.php delete mode 100644 wp-admin/import/textpattern.php delete mode 100644 wp-admin/import/utw.php delete mode 100644 wp-admin/import/wordpress.php delete mode 100644 wp-admin/import/wp-cat2tag.php diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php deleted file mode 100644 index 95ef32b11f..0000000000 --- a/wp-admin/import/blogger.php +++ /dev/null @@ -1,1077 +0,0 @@ - - ".screen_icon()." -

$title

-

$welcome

$prereqs

$stepone

-
-

- - - - - -

-
- \n"; - } - - function uh_oh($title, $message, $info) { - echo "
"; - screen_icon(); - echo "

$title

$message

$info
"; - } - - function auth() { - // We have a single-use token that must be upgraded to a session token. - $token = preg_replace( '/[^-_0-9a-zA-Z]/', '', $_GET['token'] ); - $headers = array( - "GET /accounts/AuthSubSessionToken HTTP/1.0", - "Authorization: AuthSub token=\"$token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_auth_sock( ); - if ( ! $sock ) return false; - $response = $this->_txrx( $sock, $request ); - preg_match( '/token=([-_0-9a-z]+)/i', $response, $matches ); - if ( empty( $matches[1] ) ) { - $this->uh_oh( - __( 'Authorization failed' ), - __( 'Something went wrong. If the problem persists, send this info to support:' ), - htmlspecialchars($response) - ); - return false; - } - $this->token = $matches[1]; - - wp_redirect( remove_query_arg( array( 'token', 'noheader' ) ) ); - } - - function get_token_info() { - $headers = array( - "GET /accounts/AuthSubTokenInfo HTTP/1.0", - "Authorization: AuthSub token=\"$this->token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_auth_sock( ); - if ( ! $sock ) return; - $response = $this->_txrx( $sock, $request ); - return $this->parse_response($response); - } - - function token_is_valid() { - $info = $this->get_token_info(); - - if ( $info['code'] == 200 ) - return true; - - return false; - } - - function show_blogs($iter = 0) { - if ( empty($this->blogs) ) { - $headers = array( - "GET /feeds/default/blogs HTTP/1.0", - "Host: www.blogger.com", - "Authorization: AuthSub token=\"$this->token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_blogger_sock( ); - if ( ! $sock ) return; - $response = $this->_txrx( $sock, $request ); - - // Quick and dirty XML mining. - list( $headers, $xml ) = explode( "\r\n\r\n", $response ); - $p = xml_parser_create(); - xml_parse_into_struct($p, $xml, $vals, $index); - xml_parser_free($p); - - $this->title = $vals[$index['TITLE'][0]]['value']; - - // Give it a few retries... this step often flakes out the first time. - if ( empty( $index['ENTRY'] ) ) { - if ( $iter < 3 ) { - return $this->show_blogs($iter + 1); - } else { - $this->uh_oh( - __('Trouble signing in'), - __('We were not able to gain access to your account. Try starting over.'), - '' - ); - return false; - } - } - - foreach ( $index['ENTRY'] as $i ) { - $blog = array(); - while ( ( $tag = $vals[$i] ) && ! ( $tag['tag'] == 'ENTRY' && $tag['type'] == 'close' ) ) { - if ( $tag['tag'] == 'TITLE' ) { - $blog['title'] = $tag['value']; - } elseif ( $tag['tag'] == 'SUMMARY' ) { - $blog['summary'] = $tag['value']; - } elseif ( $tag['tag'] == 'LINK' ) { - if ( $tag['attributes']['REL'] == 'alternate' && $tag['attributes']['TYPE'] == 'text/html' ) { - $parts = parse_url( $tag['attributes']['HREF'] ); - $blog['host'] = $parts['host']; - } elseif ( $tag['attributes']['REL'] == 'edit' ) - $blog['gateway'] = $tag['attributes']['HREF']; - } - ++$i; - } - if ( ! empty ( $blog ) ) { - $blog['total_posts'] = $this->get_total_results('posts', $blog['host']); - $blog['total_comments'] = $this->get_total_results('comments', $blog['host']); - $blog['mode'] = 'init'; - $this->blogs[] = $blog; - } - } - - if ( empty( $this->blogs ) ) { - $this->uh_oh( - __('No blogs found'), - __('We were able to log in but there were no blogs. Try a different account next time.'), - '' - ); - return false; - } - } -//echo '
'.print_r($this,1).'
'; - $start = esc_js( __('Import') ); - $continue = esc_js( __('Continue') ); - $stop = esc_js( __('Importing...') ); - $authors = esc_js( __('Set Authors') ); - $loadauth = esc_js( __('Preparing author mapping form...') ); - $authhead = esc_js( __('Final Step: Author Mapping') ); - $nothing = esc_js( __('Nothing was imported. Had you already imported this blog?') ); - $stopping = ''; //Missing String used below. - $title = __('Blogger Blogs'); - $name = __('Blog Name'); - $url = __('Blog URL'); - $action = __('The Magic Button'); - $posts = __('Posts'); - $comments = __('Comments'); - $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.'); - - $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 = "
 
$pdone/{$blog['total_posts']}
"; - $cstat = "
 
$cdone/{$blog['total_comments']}
"; - $rows .= "$blogtitle{$blog['host']}$pstat$cstat\n"; - } - - echo "

$title

\n$rows
$name$url$posts$comments$action
"; - echo " - \n"; - } - - // Handy function for stopping the script after a number of seconds. - function have_time() { - global $importer_started; - if ( time() - $importer_started > MAX_EXECUTION_TIME ) - die('continue'); - return true; - } - - function get_total_results($type, $host) { - $headers = array( - "GET /feeds/$type/default?max-results=1&start-index=2 HTTP/1.0", - "Host: $host", - "Authorization: AuthSub token=\"$this->token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_blogger_sock( $host ); - if ( ! $sock ) return; - $response = $this->_txrx( $sock, $request ); - $response = $this->parse_response( $response ); - $parser = xml_parser_create(); - xml_parse_into_struct($parser, $response['body'], $struct, $index); - xml_parser_free($parser); - $total_results = $struct[$index['OPENSEARCH:TOTALRESULTS'][0]]['value']; - return (int) $total_results; - } - - function import_blog($blogID) { - global $importing_blog; - $importing_blog = $blogID; - - if ( isset($_GET['authors']) ) - return print($this->get_author_form()); - - header('Content-Type: text/plain'); - - if ( isset($_GET['status']) ) - die($this->get_js_status()); - - if ( isset($_GET['saveauthors']) ) - die($this->save_authors()); - - $blog = $this->blogs[$blogID]; - $total_results = $this->get_total_results('posts', $blog['host']); - $this->blogs[$importing_blog]['total_posts'] = $total_results; - - $start_index = $total_results - MAX_RESULTS + 1; - - if ( isset( $this->blogs[$importing_blog]['posts_start_index'] ) ) - $start_index = (int) $this->blogs[$importing_blog]['posts_start_index']; - elseif ( $total_results > MAX_RESULTS ) - $start_index = $total_results - MAX_RESULTS + 1; - else - $start_index = 1; - - // This will be positive until we have finished importing posts - if ( $start_index > 0 ) { - // Grab all the posts - $this->blogs[$importing_blog]['mode'] = 'posts'; - $query = "start-index=$start_index&max-results=" . MAX_RESULTS; - do { - $index = $struct = $entries = array(); - $headers = array( - "GET /feeds/posts/default?$query HTTP/1.0", - "Host: {$blog['host']}", - "Authorization: AuthSub token=\"$this->token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_blogger_sock( $blog['host'] ); - if ( ! $sock ) return; // TODO: Error handling - $response = $this->_txrx( $sock, $request ); - - $response = $this->parse_response( $response ); - - // Extract the entries and send for insertion - preg_match_all( '/]*>.*?<\/entry>/s', $response['body'], $matches ); - if ( count( $matches[0] ) ) { - $entries = array_reverse($matches[0]); - foreach ( $entries as $entry ) { - $entry = "$entry"; - $AtomParser = new AtomParser(); - $AtomParser->parse( $entry ); - $result = $this->import_post($AtomParser->entry); - if ( is_wp_error( $result ) ) - return $result; - unset($AtomParser); - } - } else break; - - // Get the 'previous' query string which we'll use on the next iteration - $query = ''; - $links = preg_match_all('/]*)>/', $response['body'], $matches); - if ( count( $matches[1] ) ) - foreach ( $matches[1] as $match ) - if ( preg_match('/rel=.previous./', $match) ) - $query = @html_entity_decode( preg_replace('/^.*href=[\'"].*\?(.+)[\'"].*$/', '$1', $match), ENT_COMPAT, get_option('blog_charset') ); - - if ( $query ) { - parse_str($query, $q); - $this->blogs[$importing_blog]['posts_start_index'] = (int) $q['start-index']; - } else - $this->blogs[$importing_blog]['posts_start_index'] = 0; - $this->save_vars(); - } while ( !empty( $query ) && $this->have_time() ); - } - - $total_results = $this->get_total_results( 'comments', $blog['host'] ); - $this->blogs[$importing_blog]['total_comments'] = $total_results; - - if ( isset( $this->blogs[$importing_blog]['comments_start_index'] ) ) - $start_index = (int) $this->blogs[$importing_blog]['comments_start_index']; - elseif ( $total_results > MAX_RESULTS ) - $start_index = $total_results - MAX_RESULTS + 1; - else - $start_index = 1; - - if ( $start_index > 0 ) { - // Grab all the comments - $this->blogs[$importing_blog]['mode'] = 'comments'; - $query = "start-index=$start_index&max-results=" . MAX_RESULTS; - do { - $index = $struct = $entries = array(); - $headers = array( - "GET /feeds/comments/default?$query HTTP/1.0", - "Host: {$blog['host']}", - "Authorization: AuthSub token=\"$this->token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_blogger_sock( $blog['host'] ); - if ( ! $sock ) return; // TODO: Error handling - $response = $this->_txrx( $sock, $request ); - - $response = $this->parse_response( $response ); - - // Extract the comments and send for insertion - preg_match_all( '/]*>.*?<\/entry>/s', $response['body'], $matches ); - if ( count( $matches[0] ) ) { - $entries = array_reverse( $matches[0] ); - foreach ( $entries as $entry ) { - $entry = "$entry"; - $AtomParser = new AtomParser(); - $AtomParser->parse( $entry ); - $this->import_comment($AtomParser->entry); - unset($AtomParser); - } - } - - // Get the 'previous' query string which we'll use on the next iteration - $query = ''; - $links = preg_match_all('/]*)>/', $response['body'], $matches); - if ( count( $matches[1] ) ) - foreach ( $matches[1] as $match ) - if ( preg_match('/rel=.previous./', $match) ) - $query = @html_entity_decode( preg_replace('/^.*href=[\'"].*\?(.+)[\'"].*$/', '$1', $match), ENT_COMPAT, get_option('blog_charset') ); - - parse_str($query, $q); - - $this->blogs[$importing_blog]['comments_start_index'] = (int) $q['start-index']; - $this->save_vars(); - } while ( !empty( $query ) && $this->have_time() ); - } - $this->blogs[$importing_blog]['mode'] = 'authors'; - $this->save_vars(); - if ( !$this->blogs[$importing_blog]['posts_done'] && !$this->blogs[$importing_blog]['comments_done'] ) - die('nothing'); - do_action('import_done', 'blogger'); - die('done'); - } - - function convert_date( $date ) { - preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(?:\.[0-9]+)?(Z|[\+|\-][0-9]{2,4}){0,1}#', $date, $date_bits); - $offset = iso8601_timezone_to_offset( $date_bits[7] ); - $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]); - $timestamp -= $offset; // Convert from Blogger local time to GMT - $timestamp += get_option('gmt_offset') * 3600; // Convert from GMT to WP local time - return gmdate('Y-m-d H:i:s', $timestamp); - } - - function no_apos( $string ) { - return str_replace( ''', "'", $string); - } - - function min_whitespace( $string ) { - return preg_replace( '|\s+|', ' ', $string ); - } - - function _normalize_tag( $matches ) { - return '<' . strtolower( $matches[1] ); - } - - function import_post( $entry ) { - global $importing_blog; - - // The old permalink is all Blogger gives us to link comments to their posts. - if ( isset( $entry->draft ) ) - $rel = 'self'; - else - $rel = 'alternate'; - foreach ( $entry->links as $link ) { - if ( $link['rel'] == $rel ) { - $parts = parse_url( $link['href'] ); - $entry->old_permalink = $parts['path']; - break; - } - } - - $post_date = $this->convert_date( $entry->published ); - $post_content = trim( addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) ) ); - $post_title = trim( addslashes( $this->no_apos( $this->min_whitespace( $entry->title ) ) ) ); - $post_status = isset( $entry->draft ) ? 'draft' : 'publish'; - - // Clean up content - $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content); - $post_content = str_replace('
', '
', $post_content); - $post_content = str_replace('
', '
', $post_content); - - // Checks for duplicates - if ( isset( $this->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('#(.+?).*(?:\(.+?))?#', $entry->author, $matches); - $comment_author = addslashes( $this->no_apos( strip_tags( (string) $matches[1] ) ) ); - $comment_author_url = addslashes( $this->no_apos( strip_tags( (string) $matches[2] ) ) ); - $comment_date = $this->convert_date( $entry->updated ); - $comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) ); - - // Clean up content - $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content); - $comment_content = str_replace('
', '
', $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.'), 'users.php' ); - $heading = __('Author mapping'); - $blogtitle = "{$blog['title']} ({$blog['host']})"; - $mapthis = __('Blogger username'); - $tothis = __('WordPress login'); - $submit = esc_js( __('Save Changes') ); - - foreach ( $blog['authors'] as $i => $author ) - $rows .= ""; - - return "

$heading

$blogtitle

$directions

$rows
$mapthis$tothis
"; - } - - function get_user_options($current) { - global $importer_users; - if ( ! isset( $importer_users ) ) - $importer_users = (array) get_users_of_blog(); - - foreach ( $importer_users as $user ) { - $sel = ( $user->user_id == $current ) ? " selected='selected'" : ''; - $options .= ""; - } - - return $options; - } - - function save_authors() { - global $importing_blog, $wpdb; - $authors = (array) $_POST['authors']; - - $host = $this->blogs[$importing_blog]['host']; - - // Get an array of posts => authors - $post_ids = (array) $wpdb->get_col( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = 'blogger_blog' AND meta_value = %s", $host) ); - $post_ids = join( ',', $post_ids ); - $results = (array) $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'blogger_author' AND post_id IN ($post_ids)"); - foreach ( $results as $row ) - $authors_posts[$row->post_id] = $row->meta_value; - - foreach ( $authors as $author => $user_id ) { - $user_id = (int) $user_id; - - // Skip authors that haven't been changed - if ( $user_id == $this->blogs[$importing_blog]['authors'][$author][1] ) - continue; - - // Get a list of the selected author's posts - $post_ids = (array) array_keys( $authors_posts, $this->blogs[$importing_blog]['authors'][$author][0] ); - $post_ids = join( ',', $post_ids); - - $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_author = %d WHERE id IN ($post_ids)", $user_id) ); - $this->blogs[$importing_blog]['authors'][$author][1] = $user_id; - } - $this->save_vars(); - - wp_redirect('edit.php'); - } - - function _get_auth_sock() { - // Connect to https://www.google.com - if ( !$sock = @ fsockopen('ssl://www.google.com', 443, $errno, $errstr) ) { - $this->uh_oh( - __('Could not connect to https://www.google.com'), - __('There was a problem opening a secure connection to Google. This is what went wrong:'), - "$errstr ($errno)" - ); - return false; - } - return $sock; - } - - function _get_blogger_sock($host = 'www2.blogger.com') { - if ( !$sock = @ fsockopen($host, 80, $errno, $errstr) ) { - $this->uh_oh( - sprintf( __('Could not connect to %s'), $host ), - __('There was a problem opening a connection to Blogger. This is what went wrong:'), - "$errstr ($errno)" - ); - return false; - } - return $sock; - } - - function _txrx( $sock, $request ) { - fwrite( $sock, $request ); - while ( ! feof( $sock ) ) - $response .= @ fread ( $sock, 8192 ); - fclose( $sock ); - return $response; - } - - function revoke($token) { - $headers = array( - "GET /accounts/AuthSubRevokeToken HTTP/1.0", - "Authorization: AuthSub token=\"$token\"" - ); - $request = join( "\r\n", $headers ) . "\r\n\r\n"; - $sock = $this->_get_auth_sock( ); - if ( ! $sock ) return false; - $this->_txrx( $sock, $request ); - } - - function restart() { - global $wpdb; - $options = get_option( 'blogger_importer' ); - - if ( isset( $options['token'] ) ) - $this->revoke( $options['token'] ); - - delete_option('blogger_importer'); - $wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = 'blogger_author'"); - wp_redirect('?import=blogger'); - } - - // Returns associative array of code, header, cookies, body. Based on code from php.net. - function parse_response($this_response) { - // Split response into header and body sections - list($response_headers, $response_body) = explode("\r\n\r\n", $this_response, 2); - $response_header_lines = explode("\r\n", $response_headers); - - // First line of headers is the HTTP response code - $http_response_line = array_shift($response_header_lines); - if (preg_match('@^HTTP/[0-9]\.[0-9] ([0-9]{3})@',$http_response_line, $matches)) { $response_code = $matches[1]; } - - // put the rest of the headers in an array - $response_header_array = array(); - foreach($response_header_lines as $header_line) { - list($header,$value) = explode(': ', $header_line, 2); - $response_header_array[$header] .= $value."\n"; - } - - $cookie_array = array(); - $cookies = explode("\n", $response_header_array["Set-Cookie"]); - foreach($cookies as $this_cookie) { array_push($cookie_array, "Cookie: ".$this_cookie); } - - return array("code" => $response_code, "header" => $response_header_array, "cookies" => $cookie_array, "body" => $response_body); - } - - // Step 9: Congratulate the user - function congrats() { - $blog = (int) $_GET['blog']; - echo '

'.__('Congratulations!').'

'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'

  • '.__('That was hard work! Take a break.').'
  • '; - if ( count($this->import['blogs']) > 1 ) - echo '
  • '.__('In case you haven’t done it already, you can import the posts from your other blogs:'). $this->show_blogs() . '
  • '; - if ( $n = count($this->import['blogs'][$blog]['newusers']) ) - echo '
  • '.sprintf(__('Go to Authors & Users, where you can modify the new user(s) or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.'), 'users.php', '_parent').'
  • '; - echo '
  • '.__('For security, click the link below to reset this importer.').'
  • '; - echo '
'; - } - - // 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'); - $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.'); - $submit = esc_attr__('Clear account information'); - echo "

$restart

$message

"; - } - } - - function save_vars() { - $vars = get_object_vars($this); - update_option( 'blogger_importer', $vars ); - - return !empty($vars); - } - - function admin_head() { -?> - -entry = new AtomEntry(); - } - - function _map_attrs_func( $k, $v ) { - return "$k=\"$v\""; - } - - function _map_xmlns_func( $p, $n ) { - $xd = "xmlns"; - if ( strlen( $n[0] ) > 0 ) - $xd .= ":{$n[0]}"; - - return "{$xd}=\"{$n[1]}\""; - } - - function parse($xml) { - - global $app_logging; - array_unshift($this->ns_contexts, array()); - - $parser = xml_parser_create_ns(); - xml_set_object($parser, $this); - xml_set_element_handler($parser, "start_element", "end_element"); - xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); - xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0); - xml_set_character_data_handler($parser, "cdata"); - xml_set_default_handler($parser, "_default"); - xml_set_start_namespace_decl_handler($parser, "start_ns"); - xml_set_end_namespace_decl_handler($parser, "end_ns"); - - $contents = ""; - - xml_parse($parser, $xml); - - xml_parser_free($parser); - - return true; - } - - function start_element($parser, $name, $attrs) { - - $tag = array_pop(split(":", $name)); - - array_unshift($this->ns_contexts, $this->ns_decls); - - $this->depth++; - - if (!empty($this->in_content)) { - $attrs_prefix = array(); - - // resolve prefixes for attributes - foreach($attrs as $key => $value) { - $attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value); - } - $attrs_str = join(' ', array_map( array( &$this, '_map_attrs_func' ), array_keys($attrs_prefix), array_values($attrs_prefix))); - if (strlen($attrs_str) > 0) { - $attrs_str = " " . $attrs_str; - } - - $xmlns_str = join(' ', array_map( array( &$this, '_map_xmlns_func' ), array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0]))); - if (strlen($xmlns_str) > 0) { - $xmlns_str = " " . $xmlns_str; - } - - // handle self-closing tags (case: a new child found right-away, no text node) - if (count($this->in_content) == 2) { - array_push($this->in_content, ">"); - } - - array_push($this->in_content, "<". $this->ns_to_prefix($name) ."{$xmlns_str}{$attrs_str}"); - } else if (in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) { - $this->in_content = array(); - $this->is_xhtml = $attrs['type'] == 'xhtml'; - array_push($this->in_content, array($tag,$this->depth)); - } else if ($tag == 'link') { - array_push($this->entry->links, $attrs); - } else if ($tag == 'category') { - array_push($this->entry->categories, $attrs['term']); - } - - $this->ns_decls = array(); - } - - function end_element($parser, $name) { - - $tag = array_pop(split(":", $name)); - - if (!empty($this->in_content)) { - if ($this->in_content[0][0] == $tag && - $this->in_content[0][1] == $this->depth) { - array_shift($this->in_content); - if ($this->is_xhtml) { - $this->in_content = array_slice($this->in_content, 2, count($this->in_content)-3); - } - $this->entry->$tag = join('',$this->in_content); - $this->in_content = array(); - } else { - $endtag = $this->ns_to_prefix($name); - if (strpos($this->in_content[count($this->in_content)-1], '<' . $endtag) !== false) { - array_push($this->in_content, "/>"); - } else { - array_push($this->in_content, ""); - } - } - } - - array_shift($this->ns_contexts); - - #print str_repeat(" ", $this->depth * $this->indent) . "end_element('$name')" ."\n"; - - $this->depth--; - } - - function start_ns($parser, $prefix, $uri) { - #print str_repeat(" ", $this->depth * $this->indent) . "starting: " . $prefix . ":" . $uri . "\n"; - array_push($this->ns_decls, array($prefix,$uri)); - } - - function end_ns($parser, $prefix) { - #print str_repeat(" ", $this->depth * $this->indent) . "ending: #" . $prefix . "#\n"; - } - - function cdata($parser, $data) { - #print str_repeat(" ", $this->depth * $this->indent) . "data: #" . $data . "#\n"; - if (!empty($this->in_content)) { - // handle self-closing tags (case: text node found, need to close element started) - if (strpos($this->in_content[count($this->in_content)-1], '<') !== false) { - array_push($this->in_content, ">"); - } - array_push($this->in_content, $this->xml_escape($data)); - } - } - - function _default($parser, $data) { - # when does this gets called? - } - - - function ns_to_prefix($qname) { - $components = split(":", $qname); - $name = array_pop($components); - - if (!empty($components)) { - $ns = join(":",$components); - foreach ($this->ns_contexts as $context) { - foreach ($context as $mapping) { - if ($mapping[1] == $ns && strlen($mapping[0]) > 0) { - return "$mapping[0]:$name"; - } - } - } - } - return $name; - } - - function xml_escape($string) - { - return str_replace(array('&','"',"'",'<','>'), - array('&','"',''','<','>'), - $string ); - } -} - -?> diff --git a/wp-admin/import/blogware.php b/wp-admin/import/blogware.php deleted file mode 100644 index 6fbecf1512..0000000000 --- a/wp-admin/import/blogware.php +++ /dev/null @@ -1,211 +0,0 @@ -'; - screen_icon(); - echo '

'.__('Import Blogware').'

'; - } - - function footer() { - echo ''; - } - - function greet() { - echo '
'; - echo '

'.__('Howdy! This importer allows you to extract posts from Blogware XML export file into your site. Pick a Blogware file to upload and click Import.').'

'; - wp_import_upload_form("admin.php?import=blogware&step=1"); - echo '
'; - } - - function _normalize_tag( $matches ) { - return '<' . strtolower( $matches[1] ); - } - - function import_posts() { - global $wpdb, $current_user; - - set_magic_quotes_runtime(0); - $importdata = file($this->file); // Read the file into an array - $importdata = implode('', $importdata); // squish it - $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); - - preg_match_all('|(]+>(.*?))|is', $importdata, $posts); - $posts = $posts[1]; - unset($importdata); - echo '
    '; - foreach ($posts as $post) { - flush(); - preg_match('||is', $post, $post_type); - $post_type = $post_type[1]; - if ($post_type == "photo") { - preg_match('|(.*?)|is', $post, $post_title); - } else { - preg_match('|(.*?)|is', $post, $post_title); - } - $post_title = $wpdb->escape(trim($post_title[1])); - - preg_match('|(.*?)|is', $post, $post_date); - $post_date = strtotime($post_date[1]); - $post_date = gmdate('Y-m-d H:i:s', $post_date); - - preg_match_all('|(.*?)|is', $post, $categories); - $categories = $categories[1]; - - $cat_index = 0; - foreach ($categories as $category) { - $categories[$cat_index] = $wpdb->escape( html_entity_decode($category) ); - $cat_index++; - } - - if ( strcasecmp($post_type, "photo") === 0 ) { - preg_match('|(.*?)|is', $post, $post_content); - $post_content = ''; - $post_content = html_entity_decode( $post_content ); - } else { - preg_match('|(.*?)|is', $post, $post_content); - $post_content = str_replace(array (''), '', trim($post_content[1])); - $post_content = html_entity_decode( $post_content ); - } - - // Clean up content - $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - $post_content = $wpdb->escape($post_content); - - $post_author = $current_user->ID; - preg_match('|(.*?)|is', $post, $post_status); - $post_status = trim($post_status[1]); - - echo '
  1. '; - if ($post_id = post_exists($post_title, $post_content, $post_date)) { - printf(__('Post %s already exists.'), stripslashes($post_title)); - } else { - printf(__('Importing post %s...'), stripslashes($post_title)); - $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status'); - $post_id = wp_insert_post($postdata); - if ( is_wp_error( $post_id ) ) { - return $post_id; - } - if (!$post_id) { - _e('Couldn’t get post ID'); - echo '
  2. '; - break; - } - if ( 0 != count($categories) ) - wp_create_categories($categories, $post_id); - } - - preg_match_all('|(.*?)|is', $post, $comments); - $comments = $comments[1]; - - if ( $comments ) { - $comment_post_ID = (int) $post_id; - $num_comments = 0; - foreach ($comments as $comment) { - preg_match('|(.*?)|is', $comment, $comment_content); - $comment_content = str_replace(array (''), '', trim($comment_content[1])); - $comment_content = html_entity_decode( $comment_content ); - - // Clean up content - $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content); - $comment_content = str_replace('
    ', '
    ', $comment_content); - $comment_content = str_replace('
    ', '
    ', $comment_content); - $comment_content = $wpdb->escape($comment_content); - - preg_match('|(.*?)|is', $comment, $comment_date); - $comment_date = trim($comment_date[1]); - $comment_date = date('Y-m-d H:i:s', strtotime($comment_date)); - - preg_match('|(.*?)|is', $comment, $comment_author); - $comment_author = $wpdb->escape(trim($comment_author[1])); - - $comment_author_email = NULL; - - $comment_approved = 1; - // Check if it's already there - if (!comment_exists($comment_author, $comment_date)) { - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_date', 'comment_content', 'comment_approved'); - $commentdata = wp_filter_comment($commentdata); - wp_insert_comment($commentdata); - $num_comments++; - } - } - } - if ( $num_comments ) { - echo ' '; - printf( _n('%s comment', '%s comments', $num_comments), $num_comments ); - } - echo ''; - flush(); - ob_flush(); - } - echo '
'; - } - - function import() { - $file = wp_import_handle_upload(); - if ( isset($file['error']) ) { - echo $file['error']; - return; - } - - $this->file = $file['file']; - $result = $this->import_posts(); - if ( is_wp_error( $result ) ) - return $result; - wp_import_cleanup($file['id']); - do_action('import_done', 'blogware'); - echo '

'; - printf(__('All done. Have fun!'), get_option('home')); - echo '

'; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - $this->header(); - - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - $result = $this->import(); - if ( is_wp_error( $result ) ) - $result->get_error_message(); - break; - } - - $this->footer(); - } - - function BW_Import() { - // Nothing. - } -} - -$blogware_import = new BW_Import(); - -register_importer('blogware', __('Blogware'), __('Import posts from Blogware.'), array ($blogware_import, 'dispatch')); -?> diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php deleted file mode 100644 index 686407ba8f..0000000000 --- a/wp-admin/import/dotclear.php +++ /dev/null @@ -1,675 +0,0 @@ -get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); - } -} - -if (!function_exists('link_exists')) { - /** - * Check whether link already exists. - * - * @package WordPress - * @subpackage Dotclear_Import - * - * @param string $linkname - * @return int - */ - function link_exists($linkname) - { - global $wpdb; - return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) ); - } -} - -/** - * Convert from dotclear charset to utf8 if required - * - * @package WordPress - * @subpackage Dotclear_Import - * - * @param string $s - * @return string - */ -function csc ($s) { - if (seems_utf8 ($s)) { - return $s; - } else { - return iconv(get_option ("dccharset"),"UTF-8",$s); - } -} - -/** - * @package WordPress - * @subpackage Dotclear_Import - * - * @param string $s - * @return string - */ -function textconv ($s) { - return csc (preg_replace ('|(?)\s*\n|', ' ', $s)); -} - -/** - * Dotclear Importer class - * - * Will process the WordPress eXtended RSS files that you upload from the export - * file. - * - * @package WordPress - * @subpackage Importer - * - * @since unknown - */ -class Dotclear_Import { - - function header() - { - echo '
'; - screen_icon(); - echo '

'.__('Import DotClear').'

'; - echo '

'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

'; - } - - function footer() - { - echo '
'; - } - - function greet() - { - echo '

'.__('Howdy! This importer allows you to extract posts from a DotClear database into your WordPress site. Mileage may vary.').'

'; - echo '

'.__('Your DotClear Configuration settings are as follows:').'

'; - echo '
'; - wp_nonce_field('import-dotclear'); - $this->db_form(); - echo '

'; - echo '
'; - } - - function get_dc_cats() - { - global $wpdb; - // General Housekeeping - $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); - set_magic_quotes_runtime(0); - $dbprefix = get_option('dcdbprefix'); - - // Get Categories - return $dcdb->get_results('SELECT * FROM '.$dbprefix.'categorie', ARRAY_A); - } - - function get_dc_users() - { - global $wpdb; - // General Housekeeping - $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); - set_magic_quotes_runtime(0); - $dbprefix = get_option('dcdbprefix'); - - // Get Users - - return $dcdb->get_results('SELECT * FROM '.$dbprefix.'user', ARRAY_A); - } - - function get_dc_posts() - { - // General Housekeeping - $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); - set_magic_quotes_runtime(0); - $dbprefix = get_option('dcdbprefix'); - - // Get Posts - return $dcdb->get_results('SELECT '.$dbprefix.'post.*, '.$dbprefix.'categorie.cat_libelle_url AS post_cat_name - FROM '.$dbprefix.'post INNER JOIN '.$dbprefix.'categorie - ON '.$dbprefix.'post.cat_id = '.$dbprefix.'categorie.cat_id', ARRAY_A); - } - - function get_dc_comments() - { - global $wpdb; - // General Housekeeping - $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); - set_magic_quotes_runtime(0); - $dbprefix = get_option('dcdbprefix'); - - // Get Comments - return $dcdb->get_results('SELECT * FROM '.$dbprefix.'comment', ARRAY_A); - } - - function get_dc_links() - { - //General Housekeeping - $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); - set_magic_quotes_runtime(0); - $dbprefix = get_option('dcdbprefix'); - - return $dcdb->get_results('SELECT * FROM '.$dbprefix.'link ORDER BY position', ARRAY_A); - } - - function cat2wp($categories='') - { - // General Housekeeping - global $wpdb; - $count = 0; - $dccat2wpcat = array(); - // Do the Magic - if (is_array($categories)) { - echo '

'.__('Importing Categories...').'

'; - foreach ($categories as $category) { - $count++; - extract($category); - - // Make Nice Variables - $name = $wpdb->escape($cat_libelle_url); - $title = $wpdb->escape(csc ($cat_libelle)); - $desc = $wpdb->escape(csc ($cat_desc)); - - if ($cinfo = category_exists($name)) { - $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); - } else { - $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); - } - $dccat2wpcat[$id] = $ret_id; - } - - // Store category translation for future use - add_option('dccat2wpcat',$dccat2wpcat); - echo '

'.sprintf(_n('Done! %1$s category imported.', 'Done! %1$s categories imported.', $count), $count).'

'; - return true; - } - echo __('No Categories to Import!'); - return false; - } - - function users2wp($users='') { - // General Housekeeping - global $wpdb; - $count = 0; - $dcid2wpid = array(); - - // Midnight Mojo - if (is_array($users)) { - echo '

'.__('Importing Users...').'

'; - foreach ($users as $user) { - $count++; - extract($user); - - // Make Nice Variables - $name = $wpdb->escape(csc ($name)); - $RealName = $wpdb->escape(csc ($user_pseudo)); - - if ($uinfo = get_userdatabylogin($name)) { - - $ret_id = wp_insert_user(array( - 'ID' => $uinfo->ID, - 'user_login' => $user_id, - 'user_nicename' => $Realname, - 'user_email' => $user_email, - 'user_url' => 'http://', - 'display_name' => $Realname) - ); - } else { - $ret_id = wp_insert_user(array( - 'user_login' => $user_id, - 'user_nicename' => csc ($user_pseudo), - 'user_email' => $user_email, - 'user_url' => 'http://', - 'display_name' => $Realname) - ); - } - $dcid2wpid[$user_id] = $ret_id; - - // Set DotClear-to-WordPress permissions translation - - // Update Usermeta Data - $user = new WP_User($ret_id); - $wp_perms = $user_level + 1; - if (10 == $wp_perms) { $user->set_role('administrator'); } - else if (9 == $wp_perms) { $user->set_role('editor'); } - else if (5 <= $wp_perms) { $user->set_role('editor'); } - else if (4 <= $wp_perms) { $user->set_role('author'); } - else if (3 <= $wp_perms) { $user->set_role('contributor'); } - else if (2 <= $wp_perms) { $user->set_role('contributor'); } - else { $user->set_role('subscriber'); } - - update_user_meta( $ret_id, 'wp_user_level', $wp_perms); - update_user_meta( $ret_id, 'rich_editing', 'false'); - update_user_meta( $ret_id, 'first_name', csc ($user_prenom)); - update_user_meta( $ret_id, 'last_name', csc ($user_nom)); - }// End foreach($users as $user) - - // Store id translation array for future use - add_option('dcid2wpid',$dcid2wpid); - - - echo '

'.sprintf(__('Done! %1$s users imported.'), $count).'

'; - return true; - }// End if(is_array($users) - - echo __('No Users to Import!'); - return false; - - }// End function user2wp() - - function posts2wp($posts='') { - // General Housekeeping - global $wpdb; - $count = 0; - $dcposts2wpposts = array(); - $cats = array(); - - // Do the Magic - if (is_array($posts)) { - echo '

'.__('Importing Posts...').'

'; - foreach($posts as $post) - { - $count++; - extract($post); - - // Set DotClear-to-WordPress status translation - $stattrans = array(0 => 'draft', 1 => 'publish'); - $comment_status_map = array (0 => 'closed', 1 => 'open'); - - //Can we do this more efficiently? - $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1; - $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; - - $Title = $wpdb->escape(csc ($post_titre)); - $post_content = textconv ($post_content); - $post_excerpt = ""; - if ($post_chapo != "") { - $post_excerpt = textconv ($post_chapo); - $post_content = $post_excerpt ."\n\n".$post_content; - } - $post_excerpt = $wpdb->escape ($post_excerpt); - $post_content = $wpdb->escape ($post_content); - $post_status = $stattrans[$post_pub]; - - // Import Post data into WordPress - - if ($pinfo = post_exists($Title,$post_content)) { - $ret_id = wp_insert_post(array( - 'ID' => $pinfo, - 'post_author' => $authorid, - 'post_date' => $post_dt, - 'post_date_gmt' => $post_dt, - 'post_modified' => $post_upddt, - 'post_modified_gmt' => $post_upddt, - 'post_title' => $Title, - 'post_content' => $post_content, - 'post_excerpt' => $post_excerpt, - 'post_status' => $post_status, - 'post_name' => $post_titre_url, - 'comment_status' => $comment_status_map[$post_open_comment], - 'ping_status' => $comment_status_map[$post_open_tb], - 'comment_count' => $post_nb_comment + $post_nb_trackback) - ); - if ( is_wp_error( $ret_id ) ) - return $ret_id; - } else { - $ret_id = wp_insert_post(array( - 'post_author' => $authorid, - 'post_date' => $post_dt, - 'post_date_gmt' => $post_dt, - 'post_modified' => $post_modified_gmt, - 'post_modified_gmt' => $post_modified_gmt, - 'post_title' => $Title, - 'post_content' => $post_content, - 'post_excerpt' => $post_excerpt, - 'post_status' => $post_status, - 'post_name' => $post_titre_url, - 'comment_status' => $comment_status_map[$post_open_comment], - 'ping_status' => $comment_status_map[$post_open_tb], - 'comment_count' => $post_nb_comment + $post_nb_trackback) - ); - if ( is_wp_error( $ret_id ) ) - return $ret_id; - } - $dcposts2wpposts[$post_id] = $ret_id; - - // Make Post-to-Category associations - $cats = array(); - $category1 = get_category_by_slug($post_cat_name); - $category1 = $category1->term_id; - - if ($cat1 = $category1) { $cats[1] = $cat1; } - - if (!empty($cats)) { wp_set_post_categories($ret_id, $cats); } - } - } - // Store ID translation for later use - add_option('dcposts2wpposts',$dcposts2wpposts); - - echo '

'.sprintf(__('Done! %1$s posts imported.'), $count).'

'; - return true; - } - - function comments2wp($comments='') { - // General Housekeeping - global $wpdb; - $count = 0; - $dccm2wpcm = array(); - $postarr = get_option('dcposts2wpposts'); - - // Magic Mojo - if (is_array($comments)) { - echo '

'.__('Importing Comments...').'

'; - foreach ($comments as $comment) { - $count++; - extract($comment); - - // WordPressify Data - $comment_ID = (int) ltrim($comment_id, '0'); - $comment_post_ID = (int) $postarr[$post_id]; - $comment_approved = $comment_pub; - $name = $wpdb->escape(csc ($comment_auteur)); - $email = $wpdb->escape($comment_email); - $web = "http://".$wpdb->escape($comment_site); - $message = $wpdb->escape(textconv ($comment_content)); - - $comment = array( - 'comment_post_ID' => $comment_post_ID, - 'comment_author' => $name, - 'comment_author_email' => $email, - 'comment_author_url' => $web, - 'comment_author_IP' => $comment_ip, - 'comment_date' => $comment_dt, - 'comment_date_gmt' => $comment_dt, - 'comment_content' => $message, - 'comment_approved' => $comment_approved); - $comment = wp_filter_comment($comment); - - if ( $cinfo = comment_exists($name, $comment_dt) ) { - // Update comments - $comment['comment_ID'] = $cinfo; - $ret_id = wp_update_comment($comment); - } else { - // Insert comments - $ret_id = wp_insert_comment($comment); - } - $dccm2wpcm[$comment_ID] = $ret_id; - } - // Store Comment ID translation for future use - add_option('dccm2wpcm', $dccm2wpcm); - - // Associate newly formed categories with posts - get_comment_count($ret_id); - - - echo '

'.sprintf(__('Done! %1$s comments imported.'), $count).'

'; - return true; - } - echo __('No Comments to Import!'); - return false; - } - - function links2wp($links='') { - // General Housekeeping - global $wpdb; - $count = 0; - - // Deal with the links - if (is_array($links)) { - echo '

'.__('Importing Links...').'

'; - foreach ($links as $link) { - $count++; - extract($link); - - if ($title != "") { - if ($cinfo = is_term(csc ($title), 'link_category')) { - $category = $cinfo['term_id']; - } else { - $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category'); - $category = $category['term_id']; - } - } else { - $linkname = $wpdb->escape(csc ($label)); - $description = $wpdb->escape(csc ($title)); - - if ($linfo = link_exists($linkname)) { - $ret_id = wp_insert_link(array( - 'link_id' => $linfo, - 'link_url' => $href, - 'link_name' => $linkname, - 'link_category' => $category, - 'link_description' => $description) - ); - } else { - $ret_id = wp_insert_link(array( - 'link_url' => $url, - 'link_name' => $linkname, - 'link_category' => $category, - 'link_description' => $description) - ); - } - $dclinks2wplinks[$link_id] = $ret_id; - } - } - add_option('dclinks2wplinks',$dclinks2wplinks); - echo '

'; - printf(_n('Done! %s link or link category imported.', 'Done! %s links or link categories imported.', $count), $count); - echo '

'; - return true; - } - echo __('No Links to Import!'); - return false; - } - - function import_categories() { - // Category Import - $cats = $this->get_dc_cats(); - $this->cat2wp($cats); - add_option('dc_cats', $cats); - - - - echo '
'; - wp_nonce_field('import-dotclear'); - printf('

', esc_attr__('Import Users')); - echo '
'; - - } - - function import_users() { - // User Import - $users = $this->get_dc_users(); - $this->users2wp($users); - - echo '
'; - wp_nonce_field('import-dotclear'); - printf('

', esc_attr__('Import Posts')); - echo '
'; - } - - function import_posts() { - // Post Import - $posts = $this->get_dc_posts(); - $result = $this->posts2wp($posts); - if ( is_wp_error( $result ) ) - return $result; - - echo '
'; - wp_nonce_field('import-dotclear'); - printf('

', esc_attr__('Import Comments')); - echo '
'; - } - - function import_comments() { - // Comment Import - $comments = $this->get_dc_comments(); - $this->comments2wp($comments); - - echo '
'; - wp_nonce_field('import-dotclear'); - printf('

', esc_attr__('Import Links')); - echo '
'; - } - - function import_links() - { - //Link Import - $links = $this->get_dc_links(); - $this->links2wp($links); - add_option('dc_links', $links); - - echo '
'; - wp_nonce_field('import-dotclear'); - printf('

', esc_attr__('Finish')); - echo '
'; - } - - function cleanup_dcimport() { - delete_option('dcdbprefix'); - delete_option('dc_cats'); - delete_option('dcid2wpid'); - delete_option('dccat2wpcat'); - delete_option('dcposts2wpposts'); - delete_option('dccm2wpcm'); - delete_option('dclinks2wplinks'); - delete_option('dcuser'); - delete_option('dcpass'); - delete_option('dcname'); - delete_option('dchost'); - delete_option('dccharset'); - do_action('import_done', 'dotclear'); - $this->tips(); - } - - function tips() { - echo '

'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from DotClear, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'

'; - echo '

'.__('Users').'

'; - echo '

'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn’t have that login in DotClear, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and DotClear uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So Log in and change it.'), '/wp-login.php').'

'; - echo '

'.__('Preserving Authors').'

'; - echo '

'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'

'; - echo '

'.__('Textile').'

'; - echo '

'.__('Also, since you’re coming from DotClear, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me… You’ll want it.').'

'; - echo '

'.__('WordPress Resources').'

'; - echo '

'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

'; - echo ''; - echo '

'.sprintf(__('That’s it! What are you waiting for? Go log in!'), '../wp-login.php').'

'; - } - - function db_form() { - echo ''; - printf('', __('DotClear Database User:')); - printf('', __('DotClear Database Password:')); - printf('', __('DotClear Database Name:')); - printf('', __('DotClear Database Host:')); - printf('', __('DotClear Table prefix:')); - printf('', __('Originating character set:')); - echo '
'; - } - - function dispatch() { - - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - $this->header(); - - if ( $step > 0 ) { - check_admin_referer('import-dotclear'); - - if ($_POST['dbuser']) { - if(get_option('dcuser')) - delete_option('dcuser'); - add_option('dcuser', sanitize_user($_POST['dbuser'], true)); - } - if ($_POST['dbpass']) { - if(get_option('dcpass')) - delete_option('dcpass'); - add_option('dcpass', sanitize_user($_POST['dbpass'], true)); - } - - if ($_POST['dbname']) { - if (get_option('dcname')) - delete_option('dcname'); - add_option('dcname', sanitize_user($_POST['dbname'], true)); - } - if ($_POST['dbhost']) { - if(get_option('dchost')) - delete_option('dchost'); - add_option('dchost', sanitize_user($_POST['dbhost'], true)); - } - if ($_POST['dccharset']) { - if (get_option('dccharset')) - delete_option('dccharset'); - add_option('dccharset', sanitize_user($_POST['dccharset'], true)); - } - if ($_POST['dbprefix']) { - if (get_option('dcdbprefix')) - delete_option('dcdbprefix'); - add_option('dcdbprefix', sanitize_user($_POST['dbprefix'], true)); - } - - - } - - switch ($step) { - default: - case 0 : - $this->greet(); - break; - case 1 : - $this->import_categories(); - break; - case 2 : - $this->import_users(); - break; - case 3 : - $result = $this->import_posts(); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - case 4 : - $this->import_comments(); - break; - case 5 : - $this->import_links(); - break; - case 6 : - $this->cleanup_dcimport(); - break; - } - - $this->footer(); - } - - function Dotclear_Import() { - // Nothing. - } -} - -$dc_import = new Dotclear_Import(); - -register_importer('dotclear', __('DotClear'), __('Import categories, users, posts, comments, and links from a DotClear blog.'), array ($dc_import, 'dispatch')); - -?> diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php deleted file mode 100644 index beff019503..0000000000 --- a/wp-admin/import/greymatter.php +++ /dev/null @@ -1,334 +0,0 @@ -'; - screen_icon(); - echo '

'.__('Import GreyMatter').'

'; - } - - function footer() { - echo ''; - } - - function greet() { - $this->header(); -?> -

-

-
    -
  • -
  • If authors are found not to be in gm-authors.cgi, imports them at level 0.') ?>
  • -
  • -
-

-
    -
  • -
  • -
  • -
-

 

- -
- - - -

- - - - - - - - - - - - - -

- so you need to enter the number of the last GM post here.
(if you don’t know that number, just log in to your FTP and look it out
in the entries’ folder)') ?>
-

-
-footer(); - } - - - - function gm2autobr($string) { // transforms GM's |*| into b2's
\n - $string = str_replace("|*|","
\n",$string); - return($string); - } - - function import() { - global $wpdb; - - $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry'); - for ($i=0; $iheader(); -?> -

-
    -
    • escape($userdata[0]); - $pass1=$wpdb->escape($userdata[1]); - $user_nickname=$wpdb->escape($userdata[0]); - $user_email=$wpdb->escape($userdata[2]); - $user_url=$wpdb->escape($userdata[3]); - $user_joindate=$wpdb->escape($user_joindate); - - $user_id = username_exists($user_login); - if ($user_id) { - printf('
    • '.__('user %s').''.__('Already exists').'
    • ', "$user_login"); - $this->gmnames[$userdata[0]] = $user_id; - continue; - } - - $user_info = array("user_login"=>$user_login, "user_pass"=>$pass1, "user_nickname"=>$user_nickname, "user_email"=>$user_email, "user_url"=>$user_url, "user_ip"=>$user_ip, "user_domain"=>$user_domain, "user_browser"=>$user_browser, "dateYMDhour"=>$user_joindate, "user_level"=>"1", "user_idmode"=>"nickname"); - $user_id = wp_insert_user($user_info); - $this->gmnames[$userdata[0]] = $user_id; - - printf('
    • '.__('user %s...').' '.__('Done').'
    • ', "$user_login"); - } - -?>
  • -

    • gm2autobr($entry[2]); - $postmorecontent=$this->gm2autobr($entry[3]); - - $post_author=trim($wpdb->escape($postinfo[1])); - - $post_title=$this->gm2autobr($postinfo[2]); - printf('
    • '.__('entry # %s : %s : by %s'), $entryfile, $post_title, $postinfo[1]); - $post_title=$wpdb->escape($post_title); - - $postyear=$postinfo[6]; - $postmonth=zeroise($postinfo[4],2); - $postday=zeroise($postinfo[5],2); - $posthour=zeroise($postinfo[7],2); - $postminute=zeroise($postinfo[8],2); - $postsecond=zeroise($postinfo[9],2); - - if (($postinfo[10]=="PM") && ($posthour!="12")) - $posthour=$posthour+12; - - $post_date="$postyear-$postmonth-$postday $posthour:$postminute:$postsecond"; - - $post_content=$postmaincontent; - if (strlen($postmorecontent)>3) - $post_content .= "

      ".$postmorecontent; - $post_content=$wpdb->escape($post_content); - - $post_karma=$postinfo[12]; - - $post_status = 'publish'; //in greymatter, there are no drafts - $comment_status = 'open'; - $ping_status = 'closed'; - - if ($post_ID = post_exists($post_title, '', $post_date)) { - echo ' '; - _e('(already exists)'); - } else { - //just so that if a post already exists, new users are not created by checkauthor - // we'll check the author is registered, or if it's a deleted author - $user_id = username_exists($post_author); - if (!$user_id) { // if deleted from GM, we register the author as a level 0 user - $user_ip="127.0.0.1"; - $user_domain="localhost"; - $user_browser="server"; - $user_joindate="1979-06-06 00:41:00"; - $user_login=$wpdb->escape($post_author); - $pass1=$wpdb->escape("password"); - $user_nickname=$wpdb->escape($post_author); - $user_email=$wpdb->escape("user@deleted.com"); - $user_url=$wpdb->escape(""); - $user_joindate=$wpdb->escape($user_joindate); - - $user_info = array("user_login"=>$user_login, "user_pass"=>$pass1, "user_nickname"=>$user_nickname, "user_email"=>$user_email, "user_url"=>$user_url, "user_ip"=>$user_ip, "user_domain"=>$user_domain, "user_browser"=>$user_browser, "dateYMDhour"=>$user_joindate, "user_level"=>0, "user_idmode"=>"nickname"); - $user_id = wp_insert_user($user_info); - $this->gmnames[$postinfo[1]] = $user_id; - - echo ': '; - printf(__('registered deleted user %s at level 0 '), "$user_login"); - } - - if (array_key_exists($postinfo[1], $this->gmnames)) { - $post_author = $this->gmnames[$postinfo[1]]; - } else { - $post_author = $user_id; - } - - $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt'); - $post_ID = wp_insert_post($postdata); - if ( is_wp_error( $post_ID ) ) - return $post_ID; - } - - $c=count($entry); - if ($c>4) { - $numAddedComments = 0; - $numComments = 0; - for ($j=4;$j<$c;$j++) { - $entry[$j]=$this->gm2autobr($entry[$j]); - $commentinfo=explode("|",$entry[$j]); - $comment_post_ID=$post_ID; - $comment_author=$wpdb->escape($commentinfo[0]); - $comment_author_email=$wpdb->escape($commentinfo[2]); - $comment_author_url=$wpdb->escape($commentinfo[3]); - $comment_author_IP=$wpdb->escape($commentinfo[1]); - - $commentyear=$commentinfo[7]; - $commentmonth=zeroise($commentinfo[5],2); - $commentday=zeroise($commentinfo[6],2); - $commenthour=zeroise($commentinfo[8],2); - $commentminute=zeroise($commentinfo[9],2); - $commentsecond=zeroise($commentinfo[10],2); - if (($commentinfo[11]=="PM") && ($commenthour!="12")) - $commenthour=$commenthour+12; - $comment_date="$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond"; - - $comment_content=$wpdb->escape($commentinfo[12]); - - if (!comment_exists($comment_author, $comment_date)) { - $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved'); - $commentdata = wp_filter_comment($commentdata); - wp_insert_comment($commentdata); - $numAddedComments++; - } - $numComments++; - } - if ($numAddedComments > 0) { - echo ': '; - printf( _n('imported %s comment', 'imported %s comments', $numAddedComments) , $numAddedComments); - } - $preExisting = $numComments - numAddedComments; - if ($preExisting > 0) { - echo ' '; - printf( _n( 'ignored %s pre-existing comment', 'ignored %s pre-existing comments', $preExisting ) , $preExisting); - } - } - echo '... '.__('Done').'
    • '; - } - } - do_action('import_done', 'greymatter'); - ?> -
-

 

-

-footer(); - return; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - switch ($step) { - case 0 : - $this->greet(); - break; - case 1: - check_admin_referer('import-greymatter'); - $result = $this->import(); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - } - } - - function GM_Import() { - // Nothing. - } -} - -$gm_import = new GM_Import(); - -register_importer('greymatter', __('GreyMatter'), __('Import users, posts, and comments from a Greymatter blog.'), array ($gm_import, 'dispatch')); -?> diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php deleted file mode 100644 index dece821620..0000000000 --- a/wp-admin/import/livejournal.php +++ /dev/null @@ -1,1070 +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 '
'; - screen_icon(); - echo '

' . __( 'Import LiveJournal' ) . '

'; - } - - function footer() { - echo '
'; - } - - function greet() { - ?> -
-
- - - -

-

- -

-

-

- - - -

-

- - - - - - - - - - - - - -
- -

-

-

- - - - - - - -
- -

WARNING: 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." ) ?>

- -

- -

- -

NOTE: If the import process is interrupted for any reason, come back to this page and it will continue from where it stopped automatically.' ) ?>

- - - -
-
- lj_ixr( 'syncitems', array( 'ver' => 1, 'lastsync' => $lastsync ) ); - 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-' ) { - $sync_item_times[ str_replace( 'L-', '', $event['item'] ) ] = $event['time']; - if ( $event['time'] > $lastsync ) { - $lastsync = $event['time']; - update_option( 'ljapi_lastsync', $lastsync ); - } - } - } - } while ( $total > $count ); - // endwhile - all post meta is cached locally - unset( $synclist ); - update_option( 'ljapi_sync_item_times', $sync_item_times ); - update_option( 'ljapi_total', $total ); - update_option( 'ljapi_count', $count ); - - 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 '
    '; - 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, - 'selecttype' => 'syncitems', - 'lineendings' => 'pc', - 'lastsync' => $lastsync ) ); - if ( is_wp_error( $itemlist ) ) - return $itemlist; - - if ( $num = count( $itemlist['events'] ) ) { - for ( $e = 0; $e < count( $itemlist['events'] ); $e++ ) { - $event = $itemlist['events'][$e]; - $imported_count++; - $inserted = $this->import_post( $event ); - if ( is_wp_error( $inserted ) ) - return $inserted; - if ( $sync_item_times[ $event['itemid'] ] > $lastsync ) - $lastsync = $sync_item_times[ $event['itemid'] ]; - wp_cache_flush(); - } - update_option( 'ljapi_lastsync_posts', $lastsync ); - update_option( 'ljapi_imported_count', $imported_count ); - update_option( 'ljapi_last_sync_count', $num ); - } - $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 ) ); - - echo '
'; - } - - function _normalize_tag( $matches ) { - return '<' . strtolower( $matches[1] ); - } - - 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; - $post['security'] = !empty( $post['security'] ) ? $post['security'] : ''; - $post_status = ( 'private' == trim( $post['security'] ) ) ? 'private' : 'publish'; // Only me - $post_password = ( 'usemask' == trim( $post['security'] ) ) ? $this->protected_password : ''; // "Friends" via password - - // For some reason, LJ sometimes sends a date as "2004-04-1408:38:00" (no space btwn date/time) - $post_date = $post['eventtime']; - 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'] ) : ''; - $post_title = $this->translate_lj_user( $post_title ); // Translate it, but then we'll strip the link - $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']; - $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content ); - // XHTMLize some tags - $post_content = str_replace( '
', '
', $post_content ); - $post_content = str_replace( '
', '
', $post_content ); - // lj-cut ==> - $post_content = preg_replace( '||is', '', $post_content ); - $post_content = str_replace( array( '', '' ), array( '', '' ), $post_content ); - $first = strpos( $post_content, '|sUi', '', substr( $post_content, $first + 1 ) ); - // lj-user ==> a href - $post_content = $this->translate_lj_user( $post_content ); - //$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'; - - echo '
  • '; - if ( $post_id = post_exists( $post_title, $post_content, $post_date ) ) { - printf( __( 'Post %s already exists.' ), stripslashes( $post_title ) ); - } else { - printf( __( 'Imported post %s...' ), stripslashes( $post_title ) ); - $postdata = compact( 'post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'post_password', 'tags_input', 'comment_status' ); - $post_id = wp_insert_post( $postdata, true ); - if ( is_wp_error( $post_id ) ) { - if ( 'empty_content' == $post_id->get_error_code() ) - return; // Silent skip on "empty" posts - return $post_id; - } - if ( !$post_id ) { - _e( 'Couldn’t get post ID (creating post failed!)' ); - echo '
  • '; - return new WP_Error( 'insert_post_failed', __( 'Failed to create post.' ) ); - } - - // Handle all the metadata for this post - $this->insert_postmeta( $post_id, $post ); - } - echo ''; - } - - // Convert lj-user tags to links to that user - function translate_lj_user( $str ) { - return preg_replace( '||', '$1', $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_ in wp_postmeta - // Adult Content - adult_content - // Location - current_coords + current_location - // Mood - current_mood (translated from current_moodid) - // Music - current_music - // Userpic - picture_keyword - foreach ( array( 'adult_content', 'current_coords', 'current_location', 'current_moodid', 'current_music', 'picture_keyword' ) as $prop ) { - if ( !empty( $post['props'][$prop] ) ) { - if ( 'current_moodid' == $prop ) { - $prop = 'current_mood'; - $val = $this->moods[ $post['props']['current_moodid'] ]; - } else { - $val = $post['props'][$prop]; - } - add_post_meta( $post_id, 'lj_' . $prop, $val ); - } - } - } - - // Set up a session (authenticate) with LJ - function get_session() { - // Get a session via XMLRPC - $cookie = $this->lj_ixr( 'sessiongenerate', array( 'ver' => 1, 'expiration' => 'short' ) ); - if ( is_wp_error( $cookie ) ) - return new WP_Error( 'cookie', __( 'Could not get a cookie from LiveJournal. Please try again soon.' ) ); - 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() { - $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' ) ? 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 ) { - // Now get the meta listing - $results = wp_remote_get( $this->comments_url . '?get=comment_meta&startid=' . ( $highest_id + 1 ), - array( 'cookies' => array( $cookie ), 'timeout' => 20 ) ); - 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( '|(\d+)|', $results, $matches ); - if ( 0 == $matches[1] ) { - // No comment meta = no comments for this journal - 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( '| $highest_id ) - $highest_id = $id; - } - - // Parse out the list of user mappings, and add it to the known list - preg_match_all( '||', $results, $matches ); - foreach ( $matches[1] as $count => $userid ) - $this->usermap[$userid] = $matches[2][$count]; // need this in memory for translating ids => names - - wp_cache_flush(); - } - // endwhile - should have seen all comment meta at this point - - update_option( 'ljapi_usermap', $this->usermap ); - update_option( 'ljapi_maxid', $maxid ); - update_option( 'ljapi_highest_id', $highest_id ); - - echo '

    ' . __( '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( '||iUs', $results, $matches ); - for ( $c = 0; $c < count( $matches[0] ); $c++ ) { - // Keep track of highest id seen - if ( $matches[1][$c] > $highest_id ) { - $highest_id = $matches[1][$c]; - update_option( 'ljapi_highest_comment_id', $highest_id ); - } - - $comment = $matches[0][$c]; - - // Filter out any captured, deleted comments (nothing useful to import) - $comment = preg_replace( '||is', '', $comment ); - - // Parse this comment into an array and insert - $comment = $this->parse_comment( $comment ); - $comment = wp_filter_comment( $comment ); - $id = wp_insert_comment( $comment ); - - // Clear cache - 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( '|]+)>|i', $comment, $attribs ); - preg_match( '| id=\'(\d+)\'|i', $attribs[1], $matches ); - $lj_comment_ID = $matches[1]; - preg_match( '| jitemid=\'(\d+)\'|i', $attribs[1], $matches ); - $lj_comment_post_ID = $matches[1]; - preg_match( '| posterid=\'(\d+)\'|i', $attribs[1], $matches ); - $comment_author_ID = isset( $matches[1] ) ? $matches[1] : 0; - preg_match( '| parentid=\'(\d+)\'|i', $attribs[1], $matches ); // optional - $lj_comment_parent = isset( $matches[1] ) ? $matches[1] : 0; - 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( '|(.*)|is', $comment, $matches ); - if ( isset( $matches[1] ) ) { - $comment_subject = $wpdb->escape( trim( $matches[1] ) ); - if ( 'Re:' == $comment_subject ) - $comment_subject = ''; - } - - // Get the body and HTMLize it - preg_match( '|(.*)|is', $comment, $matches ); - $comment_content = !empty( $comment_subject ) ? $comment_subject . "\n\n" . $matches[1] : $matches[1]; - $comment_content = @html_entity_decode( $comment_content, ENT_COMPAT, get_option('blog_charset') ); - $comment_content = str_replace( ''', "'", $comment_content ); - $comment_content = wpautop( $comment_content ); - $comment_content = str_replace( '
    ', '
    ', $comment_content ); - $comment_content = str_replace( '
    ', '
    ', $comment_content ); - $comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content ); - $comment_content = $wpdb->escape( trim( $comment_content ) ); - - // Get and convert the date - preg_match( '|(.*)|i', $comment, $matches ); - $comment_date = trim( str_replace( array( 'T', 'Z' ), ' ', $matches[1] ) ); - - // Grab IP if available - preg_match( '|(.*)|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]; - if ( get_option( 'ljapi_username' ) == $author ) { - $user = wp_get_current_user(); - $user_id = $user->ID; - $author = $user->display_name; - $url = trailingslashit( get_option( 'home' ) ); - } else { - $user_id = 0; - $url = ( __( 'Anonymous' ) == $author ) ? '' : 'http://' . $author . '.livejournal.com/'; - } - - // Send back the array of details - return array( 'lj_comment_ID' => $lj_comment_ID, - 'lj_comment_post_ID' => $lj_comment_post_ID, - 'lj_comment_parent' => ( !empty( $lj_comment_parent ) ? $lj_comment_parent : 0 ), - 'lj_comment_state' => $lj_comment_state, - 'comment_post_ID' => $this->get_wp_post_ID( $lj_comment_post_ID ), - 'comment_author' => $author, - 'comment_author_url' => $url, - 'comment_author_email' => '', - 'comment_content' => $comment_content, - 'comment_date' => $comment_date, - 'comment_author_IP' => ( !empty( $comment_author_IP ) ? $comment_author_IP : '' ), - 'comment_approved' => ( in_array( $lj_comment_state, array( 'A', 'F' ) ) ? 1 : 0 ), - 'comment_karma' => $lj_comment_ID, // Need this and next value until rethreading is done - 'comment_agent' => $lj_comment_parent, - 'comment_type' => 'livejournal', // Custom type, so we can find it later for processing - 'user_ID' => $user_id - ); - } - - - // 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 ) { - global $wpdb; - if ( empty( $this->commentmap[$comment] ) ) - $this->commentmap[$comment] = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_karma = %d", $comment ) ); - return $this->commentmap[$comment]; - } - - function lj_ixr() { - if ( $challenge = $this->ixr->query( 'LJ.XMLRPC.getchallenge' ) ) { - $challenge = $this->ixr->getResponse(); - } - if ( isset( $challenge['challenge'] ) ) { - $params = array( 'username' => $this->username, - 'auth_method' => 'challenge', - 'auth_challenge' => $challenge['challenge'], - 'auth_response' => md5( $challenge['challenge'] . md5( $this->password ) ) ); - } else { - 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 ); - if ( isset( $args[0] ) ) - $params = array_merge( $params, $args[0] ); - if ( $this->ixr->query( 'LJ.XMLRPC.' . $method, $params ) ) { - return $this->ixr->getResponse(); - } else { - return new WP_Error( 'IXR', __( 'XML-RPC Request Failed -- ' ) . $this->ixr->getErrorCode() . ': ' . $this->ixr->getErrorMessage() ); - } - } - - function dispatch() { - if ( empty( $_REQUEST['step'] ) ) - $step = 0; - else - $step = (int) $_REQUEST['step']; - - $this->header(); - - switch ( $step ) { - case -1 : - $this->cleanup(); - // Intentional no break - case 0 : - $this->greet(); - break; - case 1 : - case 2 : - case 3 : - check_admin_referer( 'lj-api-import' ); - $result = $this->{ 'step' . $step }(); - if ( is_wp_error( $result ) ) { - $this->throw_error( $result, $step ); - } - break; - } - - $this->footer(); - } - - // Technically the first half of step 1, this is separated to allow for AJAX - // calls. Sets up some variables and options and confirms authentication. - function setup() { - global $verified; - // Get details from form or from DB - if ( !empty( $_POST['lj_username'] ) && !empty( $_POST['lj_password'] ) ) { - // Store details for later - $this->username = $_POST['lj_username']; - $this->password = $_POST['lj_password']; - update_option( 'ljapi_username', $this->username ); - update_option( 'ljapi_password', $this->password ); - } else { - $this->username = get_option( 'ljapi_username' ); - $this->password = get_option( 'ljapi_password' ); - } - - // This is the password to set on protected posts - if ( !empty( $_POST['protected_password'] ) ) { - $this->protected_password = $_POST['protected_password']; - update_option( 'ljapi_protected_password', $this->protected_password ); - } else { - $this->protected_password = get_option( 'ljapi_protected_password' ); - } - - // Log in to confirm the details are correct - if ( empty( $this->username ) || empty( $this->password ) ) { - ?> -

    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 '
    '; - echo '

    ' . __( 'Importing Posts' ) . '

    '; - 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 '
    '; - } - - // Download comments to local XML - function step2() { - do_action( 'import_start' ); - - set_time_limit( 0 ); - update_option( 'ljapi_step', 2 ); - $this->username = get_option( 'ljapi_username' ); - $this->password = get_option( 'ljapi_password' ); - $this->ixr = new IXR_Client( $this->ixr_url, false, 80, 30 ); - - echo '
    '; - echo '

    ' . __( 'Downloading Comments…' ) . '

    '; - 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; - ?> -
    -

    approximately %d' ), get_option( 'ljapi_comment_batch' ), $batch ) ?>

    - - -

    -
    - 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 '
    '; - } - - // Re-thread comments already in the DB - function step3() { - global $wpdb; - - do_action( 'import_start' ); - - set_time_limit( 0 ); - update_option( 'ljapi_step', 3 ); - - echo '
    '; - echo '

    ' . __( 'Threading Comments…' ) . '

    '; - 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 '

    '; - printf( __( 'All done. Have fun!' ), get_option( 'home' ) ); - echo '

    '; - echo '
    '; - } - - // Output an error message with a button to try again. - function throw_error( $error, $step ) { - 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 = '
    '; - $str .= wp_nonce_field( 'lj-api-import', '_wpnonce', true, false ); - $str .= wp_referer_field( false ); - $str .= ''; - $str .= '

    '; - $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' ) ); - - do_action( 'import_end' ); - } - - 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' ) ); -?> diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php deleted file mode 100644 index 8f0411eeef..0000000000 --- a/wp-admin/import/mt.php +++ /dev/null @@ -1,508 +0,0 @@ -'; - screen_icon(); - echo '

    '.__('Import Movable Type or TypePad').'

    '; - } - - function footer() { - echo ''; - } - - function greet() { - $this->header(); -?> -
    -

    mt-export.txt in your /wp-content/ directory and then click “Import mt-export.txt”.' ); ?>

    - - -
    - - -

    - -mt-export.txt in your /wp-content/ directory'); ?>

    -

    - -

    -
    -

    out of memory error try splitting up the import file into pieces.'); ?>

    -
    -footer(); - } - - function users_form($n) { - $users = get_users_of_blog(); -?> - has_gzip() ) - return gzopen($filename, $mode); - return fopen($filename, $mode); - } - - function feof($fp) { - if ( $this->has_gzip() ) - return gzeof($fp); - return feof($fp); - } - - function fgets($fp, $len=8192) { - if ( $this->has_gzip() ) - return gzgets($fp, $len); - return fgets($fp, $len); - } - - function fclose($fp) { - if ( $this->has_gzip() ) - return gzclose($fp); - return fclose($fp); - } - - //function to check the authorname and do the mapping - function checkauthor($author) { - //mtnames is an array with the names in the mt import file - $pass = wp_generate_password(); - if (!(in_array($author, $this->mtnames))) { //a new mt author name is found - ++ $this->j; - $this->mtnames[$this->j] = $author; //add that new mt author name to an array - $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user - if (!$user_id) { //banging my head against the desk now. - if ($this->newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname - $user_id = wp_create_user($author, $pass); - $this->newauthornames[$this->j] = $author; //now we have a name, in the place of left_blank. - } else { - $user_id = wp_create_user($this->newauthornames[$this->j], $pass); - } - } else { - return $user_id; // return pre-existing wp username if it exists - } - } else { - $key = array_search($author, $this->mtnames); //find the array key for $author in the $mtnames array - $user_id = username_exists($this->newauthornames[$key]); //use that key to get the value of the author's name from $newauthornames - } - - return $user_id; - } - - function get_mt_authors() { - $temp = array(); - $authors = array(); - - $handle = $this->fopen($this->file, 'r'); - if ( $handle == null ) - return false; - - $in_comment = false; - while ( $line = $this->fgets($handle) ) { - $line = trim($line); - - if ( 'COMMENT:' == $line ) - $in_comment = true; - else if ( '-----' == $line ) - $in_comment = false; - - if ( $in_comment || 0 !== strpos($line,"AUTHOR:") ) - continue; - - $temp[] = trim( substr($line, strlen("AUTHOR:")) ); - } - - //we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. - $authors[0] = array_shift($temp); - $y = count($temp) + 1; - for ($x = 1; $x < $y; $x ++) { - $next = array_shift($temp); - if (!(in_array($next, $authors))) - array_push($authors, $next); - } - - $this->fclose($handle); - - return $authors; - } - - function get_authors_from_post() { - $formnames = array (); - $selectnames = array (); - - foreach ($_POST['user'] as $key => $line) { - $newname = trim(stripslashes($line)); - if ($newname == '') - $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form. - array_push($formnames, $newname); - } // $formnames is the array with the form entered names - - foreach ($_POST['userselect'] as $user => $key) { - $selected = trim(stripslashes($key)); - array_push($selectnames, $selected); - } - - $count = count($formnames); - for ($i = 0; $i < $count; $i ++) { - if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form - array_push($this->newauthornames, "$selectnames[$i]"); - } else { - array_push($this->newauthornames, "$formnames[$i]"); - } - } - } - - function mt_authors_form() { -?> -
    - -

    -

    -

    italics. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.'); ?>

    -

    - get_mt_authors(); - echo '
      '; - echo '
      '; - wp_nonce_field('import-mt'); - $j = -1; - foreach ($authors as $author) { - ++ $j; - echo '
    1. '; - } - - echo '

      '.'
      '; - echo '
      '; - echo '
    '; - - } - - function select_authors() { - if ( $_POST['upload_type'] === 'ftp' ) { - $file['file'] = WP_CONTENT_DIR . '/mt-export.txt'; - if ( !file_exists($file['file']) ) - $file['error'] = __('mt-export.txt does not exist'); - } else { - $file = wp_import_handle_upload(); - } - if ( isset($file['error']) ) { - $this->header(); - echo '

    '.__('Sorry, there has been an error').'.

    '; - echo '

    ' . $file['error'] . '

    '; - $this->footer(); - return; - } - $this->file = $file['file']; - $this->id = (int) $file['id']; - - $this->mt_authors_form(); - } - - function save_post(&$post, &$comments, &$pings) { - $post = get_object_vars($post); - $post = add_magic_quotes($post); - $post = (object) $post; - - if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) { - echo '
  • '; - printf(__('Post %s already exists.'), stripslashes($post->post_title)); - } else { - echo '
  • '; - printf(__('Importing post %s...'), stripslashes($post->post_title)); - - if ( '' != trim( $post->extended ) ) - $post->post_content .= "\n\n$post->extended"; - - $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor - $post_id = wp_insert_post($post); - if ( is_wp_error( $post_id ) ) - return $post_id; - - // Add categories. - if ( 0 != count($post->categories) ) { - wp_create_categories($post->categories, $post_id); - } - - // Add tags or keywords - if ( 1 < strlen($post->post_keywords) ) { - // Keywords exist. - printf('
    '.__('Adding tags %s...'), stripslashes($post->post_keywords)); - wp_add_post_tags($post_id, $post->post_keywords); - } - } - - $num_comments = 0; - foreach ( $comments as $comment ) { - $comment = get_object_vars($comment); - $comment = add_magic_quotes($comment); - - if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) { - $comment['comment_post_ID'] = $post_id; - $comment = wp_filter_comment($comment); - wp_insert_comment($comment); - $num_comments++; - } - } - - if ( $num_comments ) - printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments); - - $num_pings = 0; - foreach ( $pings as $ping ) { - $ping = get_object_vars($ping); - $ping = add_magic_quotes($ping); - - if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) { - $ping['comment_content'] = "{$ping['title']}\n\n{$ping['comment_content']}"; - $ping['comment_post_ID'] = $post_id; - $ping = wp_filter_comment($ping); - wp_insert_comment($ping); - $num_pings++; - } - } - - if ( $num_pings ) - printf(' '._n('(%s ping)', '(%s pings)', $num_pings), $num_pings); - - echo "
  • "; - //ob_flush();flush(); - } - - function process_posts() { - global $wpdb; - - $handle = $this->fopen($this->file, 'r'); - if ( $handle == null ) - return false; - - $context = ''; - $post = new StdClass(); - $comment = new StdClass(); - $comments = array(); - $ping = new StdClass(); - $pings = array(); - - echo "
      "; - - while ( $line = $this->fgets($handle) ) { - $line = trim($line); - - if ( '-----' == $line ) { - // Finishing a multi-line field - if ( 'comment' == $context ) { - $comments[] = $comment; - $comment = new StdClass(); - } else if ( 'ping' == $context ) { - $pings[] = $ping; - $ping = new StdClass(); - } - $context = ''; - } else if ( '--------' == $line ) { - // Finishing a post. - $context = ''; - $result = $this->save_post($post, $comments, $pings); - if ( is_wp_error( $result ) ) - return $result; - $post = new StdClass; - $comment = new StdClass(); - $ping = new StdClass(); - $comments = array(); - $pings = array(); - } else if ( 'BODY:' == $line ) { - $context = 'body'; - } else if ( 'EXTENDED BODY:' == $line ) { - $context = 'extended'; - } else if ( 'EXCERPT:' == $line ) { - $context = 'excerpt'; - } else if ( 'KEYWORDS:' == $line ) { - $context = 'keywords'; - } else if ( 'COMMENT:' == $line ) { - $context = 'comment'; - } else if ( 'PING:' == $line ) { - $context = 'ping'; - } else if ( 0 === strpos($line, "AUTHOR:") ) { - $author = trim( substr($line, strlen("AUTHOR:")) ); - if ( '' == $context ) - $post->post_author = $author; - else if ( 'comment' == $context ) - $comment->comment_author = $author; - } else if ( 0 === strpos($line, "TITLE:") ) { - $title = trim( substr($line, strlen("TITLE:")) ); - if ( '' == $context ) - $post->post_title = $title; - else if ( 'ping' == $context ) - $ping->title = $title; - } else if ( 0 === strpos($line, "STATUS:") ) { - $status = trim( strtolower( substr($line, strlen("STATUS:")) ) ); - if ( empty($status) ) - $status = 'publish'; - $post->post_status = $status; - } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) { - $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) ); - if ( $allow == 1 ) - $post->comment_status = 'open'; - else - $post->comment_status = 'closed'; - } else if ( 0 === strpos($line, "ALLOW PINGS:") ) { - $allow = trim( substr($line, strlen("ALLOW PINGS:")) ); - if ( $allow == 1 ) - $post->ping_status = 'open'; - else - $post->ping_status = 'closed'; - } else if ( 0 === strpos($line, "CATEGORY:") ) { - $category = trim( substr($line, strlen("CATEGORY:")) ); - if ( '' != $category ) - $post->categories[] = $category; - } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) { - $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) ); - if ( '' != $category ) - $post->categories[] = $category; - } else if ( 0 === strpos($line, "DATE:") ) { - $date = trim( substr($line, strlen("DATE:")) ); - $date = strtotime($date); - $date = date('Y-m-d H:i:s', $date); - $date_gmt = get_gmt_from_date($date); - if ( '' == $context ) { - $post->post_modified = $date; - $post->post_modified_gmt = $date_gmt; - $post->post_date = $date; - $post->post_date_gmt = $date_gmt; - } else if ( 'comment' == $context ) { - $comment->comment_date = $date; - } else if ( 'ping' == $context ) { - $ping->comment_date = $date; - } - } else if ( 0 === strpos($line, "EMAIL:") ) { - $email = trim( substr($line, strlen("EMAIL:")) ); - if ( 'comment' == $context ) - $comment->comment_author_email = $email; - else - $ping->comment_author_email = ''; - } else if ( 0 === strpos($line, "IP:") ) { - $ip = trim( substr($line, strlen("IP:")) ); - if ( 'comment' == $context ) - $comment->comment_author_IP = $ip; - else - $ping->comment_author_IP = $ip; - } else if ( 0 === strpos($line, "URL:") ) { - $url = trim( substr($line, strlen("URL:")) ); - if ( 'comment' == $context ) - $comment->comment_author_url = $url; - else - $ping->comment_author_url = $url; - } else if ( 0 === strpos($line, "BLOG NAME:") ) { - $blog = trim( substr($line, strlen("BLOG NAME:")) ); - $ping->comment_author = $blog; - } else { - // Processing multi-line field, check context. - - if( !empty($line) ) - $line .= "\n"; - - if ( 'body' == $context ) { - $post->post_content .= $line; - } else if ( 'extended' == $context ) { - $post->extended .= $line; - } else if ( 'excerpt' == $context ) { - $post->post_excerpt .= $line; - } else if ( 'keywords' == $context ) { - $post->post_keywords .= $line; - } else if ( 'comment' == $context ) { - $comment->comment_content .= $line; - } else if ( 'ping' == $context ) { - $ping->comment_content .= $line; - } - } - } - - $this->fclose($handle); - - echo '
    '; - - wp_import_cleanup($this->id); - do_action('import_done', 'mt'); - - echo '

    '.sprintf(__('All done. Have fun!'), get_option('home')).'

    '; - } - - function import() { - $this->id = (int) $_GET['id']; - if ( $this->id == 0 ) - $this->file = WP_CONTENT_DIR . '/mt-export.txt'; - else - $this->file = get_attached_file($this->id); - $this->get_authors_from_post(); - $result = $this->process_posts(); - if ( is_wp_error( $result ) ) - return $result; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - check_admin_referer('import-upload'); - $this->select_authors(); - break; - case 2: - check_admin_referer('import-mt'); - set_time_limit(0); - $result = $this->import(); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - } - } - - function MT_Import() { - // Nothing. - } -} - -$mt_import = new MT_Import(); - -register_importer('mt', __('Movable Type and TypePad'), __('Import posts and comments from a Movable Type or TypePad blog.'), array ($mt_import, 'dispatch')); -?> diff --git a/wp-admin/import/opml.php b/wp-admin/import/opml.php deleted file mode 100644 index 589f48bb46..0000000000 --- a/wp-admin/import/opml.php +++ /dev/null @@ -1,152 +0,0 @@ - - -
    - -

    -
    - - -

    -
    - - -
    -

    - -
    - -
    -

    - -
    - -
    - -


    -

    - -

    -
    - -
    - -
    - -

    - false, 'test_type' => false); - $_FILES['userfile']['name'] .= '.txt'; - $file = wp_handle_upload($_FILES['userfile'], $overrides); - - if ( isset($file['error']) ) - wp_die($file['error']); - - $url = $file['url']; - $opml_url = $file['file']; - $blogrolling = false; - } - - global $opml, $updated_timestamp, $all_links, $map, $names, $urls, $targets, $descriptions, $feeds; - if ( isset($opml_url) && $opml_url != '' ) { - if ( $blogrolling === true ) { - $opml = wp_remote_fopen($opml_url); - } else { - $opml = file_get_contents($opml_url); - } - - /** Load OPML Parser */ - include_once( ABSPATH . 'wp-admin/link-parse-opml.php' ); - - $link_count = count($names); - for ( $i = 0; $i < $link_count; $i++ ) { - if ('Last' == substr($titles[$i], 0, 4)) - $titles[$i] = ''; - if ( 'http' == substr($titles[$i], 0, 4) ) - $titles[$i] = ''; - $link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i]); - wp_insert_link($link); - echo sprintf('

    '.__('Inserted %s').'

    ', $names[$i]); - } -?> - -

    manage those links.'), $link_count, $cat_id, 'link-manager.php') ?>

    - -" . __("You need to supply your OPML url. Press back on your browser and try again") . "

    \n"; -} // end else - -if ( ! $blogrolling ) - do_action( 'wp_delete_file', $opml_url); - @unlink($opml_url); -?> -
    - diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php deleted file mode 100644 index f98fa6cf04..0000000000 --- a/wp-admin/import/rss.php +++ /dev/null @@ -1,196 +0,0 @@ -'; - screen_icon(); - echo '

    '.__('Import RSS').'

    '; - } - - function footer() { - echo ''; - } - - function greet() { - echo '
    '; - echo '

    '.__('Howdy! This importer allows you to extract posts from an RSS 2.0 file into your WordPress site. This is useful if you want to import your posts from a system that is not handled by a custom import tool. Pick an RSS file to upload and click Import.').'

    '; - wp_import_upload_form("admin.php?import=rss&step=1"); - echo '
    '; - } - - function _normalize_tag( $matches ) { - return '<' . strtolower( $matches[1] ); - } - - function get_posts() { - global $wpdb; - - set_magic_quotes_runtime(0); - $datalines = file($this->file); // Read the file into an array - $importdata = implode('', $datalines); // squish it - $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata); - - preg_match_all('|(.*?)|is', $importdata, $this->posts); - $this->posts = $this->posts[1]; - $index = 0; - foreach ($this->posts as $post) { - preg_match('|(.*?)|is', $post, $post_title); - $post_title = str_replace(array(''), '', $wpdb->escape( trim($post_title[1]) )); - - preg_match('|(.*?)|is', $post, $post_date_gmt); - - if ($post_date_gmt) { - $post_date_gmt = strtotime($post_date_gmt[1]); - } else { - // if we don't already have something from pubDate - preg_match('|(.*?)|is', $post, $post_date_gmt); - $post_date_gmt = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $post_date_gmt[1]); - $post_date_gmt = str_replace('T', ' ', $post_date_gmt); - $post_date_gmt = strtotime($post_date_gmt); - } - - $post_date_gmt = gmdate('Y-m-d H:i:s', $post_date_gmt); - $post_date = get_date_from_gmt( $post_date_gmt ); - - preg_match_all('|(.*?)|is', $post, $categories); - $categories = $categories[1]; - - if (!$categories) { - preg_match_all('|(.*?)|is', $post, $categories); - $categories = $categories[1]; - } - - $cat_index = 0; - foreach ($categories as $category) { - $categories[$cat_index] = $wpdb->escape( html_entity_decode( $category ) ); - $cat_index++; - } - - preg_match('|(.*?)|is', $post, $guid); - if ($guid) - $guid = $wpdb->escape(trim($guid[1])); - else - $guid = ''; - - preg_match('|(.*?)|is', $post, $post_content); - $post_content = str_replace(array (''), '', $wpdb->escape(trim($post_content[1]))); - - if (!$post_content) { - // This is for feeds that put content in description - preg_match('|(.*?)|is', $post, $post_content); - $post_content = $wpdb->escape( html_entity_decode( trim( $post_content[1] ) ) ); - } - - // Clean up content - $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - - $post_author = 1; - $post_status = 'publish'; - $this->posts[$index] = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_status', 'guid', 'categories'); - $index++; - } - } - - function import_posts() { - echo '
      '; - - foreach ($this->posts as $post) { - echo "
    1. ".__('Importing post...'); - - extract($post); - - if ($post_id = post_exists($post_title, $post_content, $post_date)) { - _e('Post already imported'); - } else { - $post_id = wp_insert_post($post); - if ( is_wp_error( $post_id ) ) - return $post_id; - if (!$post_id) { - _e('Couldn’t get post ID'); - return; - } - - if (0 != count($categories)) - wp_create_categories($categories, $post_id); - _e('Done!'); - } - echo '
    2. '; - } - - echo '
    '; - - } - - function import() { - $file = wp_import_handle_upload(); - if ( isset($file['error']) ) { - echo $file['error']; - return; - } - - $this->file = $file['file']; - $this->get_posts(); - $result = $this->import_posts(); - if ( is_wp_error( $result ) ) - return $result; - wp_import_cleanup($file['id']); - do_action('import_done', 'rss'); - - echo '

    '; - printf(__('All done. Have fun!'), get_option('home')); - echo '

    '; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - $this->header(); - - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - check_admin_referer('import-upload'); - $result = $this->import(); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - } - - $this->footer(); - } - - function RSS_Import() { - // Nothing. - } -} - -$rss_import = new RSS_Import(); - -register_importer('rss', __('RSS'), __('Import posts from an RSS feed.'), array ($rss_import, 'dispatch')); -?> diff --git a/wp-admin/import/stp.php b/wp-admin/import/stp.php deleted file mode 100644 index 4568428c99..0000000000 --- a/wp-admin/import/stp.php +++ /dev/null @@ -1,170 +0,0 @@ -'; - screen_icon(); - echo '

    '.__('Import Simple Tagging').'

    '; - echo '

    '.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

    '; - } - - function footer() { - echo ''; - } - - function greet() { - echo '
    '; - echo '

    '.__('Howdy! This imports tags from Simple Tagging 1.6.2 into WordPress tags.').'

    '; - echo '

    '.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'

    '; - echo '

    '.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'

    '; - echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; - echo '
    '; - wp_nonce_field('import-stp'); - echo '

    '; - echo '
    '; - echo '
    '; - } - - function dispatch () { - if ( empty( $_GET['step'] ) ) { - $step = 0; - } else { - $step = (int) $_GET['step']; - } - // load the header - $this->header(); - switch ( $step ) { - case 0 : - $this->greet(); - break; - case 1 : - check_admin_referer('import-stp'); - $this->import_posts(); - break; - case 2: - check_admin_referer('import-stp'); - $this->import_t2p(); - break; - case 3: - check_admin_referer('import-stp'); - $this->cleanup_import(); - break; - } - // load the footer - $this->footer(); - } - - - function import_posts ( ) { - echo '
    '; - echo '

    '.__('Reading STP Post Tags…').'

    '; - - // read in all the STP tag -> post settings - $posts = $this->get_stp_posts(); - - // if we didn't get any tags back, that's all there is folks! - if ( !is_array($posts) ) { - echo '

    ' . __('No posts were found to have tags!') . '

    '; - return false; - } - else { - // if there's an existing entry, delete it - if ( get_option('stpimp_posts') ) { - delete_option('stpimp_posts'); - } - - add_option('stpimp_posts', $posts); - $count = count($posts); - echo '

    ' . sprintf( _n('Done! %s tag to post relationships were read.', 'Done! %s tags to post relationships were read.', $count), $count ) . '

    '; - } - - echo '
    '; - wp_nonce_field('import-stp'); - echo '

    '; - echo '
    '; - echo '
    '; - } - - - function import_t2p ( ) { - echo '
    '; - echo '

    '.__('Adding Tags to Posts…').'

    '; - - // run that funky magic! - $tags_added = $this->tag2post(); - - echo '

    ' . sprintf( _n('Done! %s tag was added!', 'Done! %s tags were added!', $tags_added), $tags_added ) . '

    '; - echo '
    '; - wp_nonce_field('import-stp'); - echo '

    '; - echo '
    '; - echo '
    '; - } - - function get_stp_posts ( ) { - global $wpdb; - // read in all the posts from the STP post->tag table: should be wp_post2tag - $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags"; - $posts = $wpdb->get_results($posts_query); - return $posts; - } - - function tag2post ( ) { - global $wpdb; - - // get the tags and posts we imported in the last 2 steps - $posts = get_option('stpimp_posts'); - - // null out our results - $tags_added = 0; - - // loop through each post and add its tags to the db - foreach ( $posts as $this_post ) { - $the_post = (int) $this_post->post_id; - $the_tag = $wpdb->escape($this_post->tag_name); - // try to add the tag - wp_add_post_tags($the_post, $the_tag); - $tags_added++; - } - - // that's it, all posts should be linked to their tags properly, pending any errors we just spit out! - return $tags_added; - } - - function cleanup_import ( ) { - delete_option('stpimp_posts'); - $this->done(); - } - - function done ( ) { - echo '
    '; - echo '

    '.__('Import Complete!').'

    '; - echo '

    ' . __('OK, so we lied about this being a 4-step program! You’re done!') . '

    '; - echo '

    ' . __('Now wasn’t that easy?') . '

    '; - echo '
    '; - } - - function STP_Import ( ) { - // Nothing. - } -} - -// create the import object -$stp_import = new STP_Import(); - -// add it to the import page! -register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into WordPress tags.'), array($stp_import, 'dispatch')); -?> diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php deleted file mode 100644 index be5f72eedd..0000000000 --- a/wp-admin/import/textpattern.php +++ /dev/null @@ -1,691 +0,0 @@ -get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); - } -} - -if(!function_exists('link_exists')) -{ - /** - * Check whether link already exists. - * - * @package WordPress - * @subpackage Textpattern_Import - * - * @param string $linkname - * @return int - */ - function link_exists($linkname) - { - global $wpdb; - return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) ); - } -} - -/** - * TextPattern Importer Class - * - * @since unknown - */ -class Textpattern_Import { - - function header() - { - echo '
    '; - screen_icon(); - echo '

    '.__('Import Textpattern').'

    '; - echo '

    '.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

    '; - } - - function footer() - { - echo '
    '; - } - - function greet() { - echo '
    '; - echo '

    '.__('Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this site.').'

    '; - echo '

    '.__('This has not been tested on previous versions of Textpattern. Mileage may vary.').'

    '; - echo '

    '.__('Your Textpattern Configuration settings are as follows:').'

    '; - echo '
    '; - wp_nonce_field('import-textpattern'); - $this->db_form(); - echo '

    '; - echo '
    '; - echo '
    '; - } - - function get_txp_cats() - { - global $wpdb; - // General Housekeeping - $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); - set_magic_quotes_runtime(0); - $prefix = get_option('tpre'); - - // Get Categories - return $txpdb->get_results('SELECT - id, - name, - title - FROM '.$prefix.'txp_category - WHERE type = "article"', - ARRAY_A); - } - - function get_txp_users() - { - global $wpdb; - // General Housekeeping - $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); - set_magic_quotes_runtime(0); - $prefix = get_option('tpre'); - - // Get Users - - return $txpdb->get_results('SELECT - user_id, - name, - RealName, - email, - privs - FROM '.$prefix.'txp_users', ARRAY_A); - } - - function get_txp_posts() - { - // General Housekeeping - $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); - set_magic_quotes_runtime(0); - $prefix = get_option('tpre'); - - // Get Posts - return $txpdb->get_results('SELECT - ID, - Posted, - AuthorID, - LastMod, - Title, - Body, - Excerpt, - Category1, - Category2, - Status, - Keywords, - url_title, - comments_count - FROM '.$prefix.'textpattern - ', ARRAY_A); - } - - function get_txp_comments() - { - global $wpdb; - // General Housekeeping - $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); - set_magic_quotes_runtime(0); - $prefix = get_option('tpre'); - - // Get Comments - return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); - } - - function get_txp_links() - { - //General Housekeeping - $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); - set_magic_quotes_runtime(0); - $prefix = get_option('tpre'); - - return $txpdb->get_results('SELECT - id, - date, - category, - url, - linkname, - description - FROM '.$prefix.'txp_link', - ARRAY_A); - } - - function cat2wp($categories='') - { - // General Housekeeping - global $wpdb; - $count = 0; - $txpcat2wpcat = array(); - // Do the Magic - if(is_array($categories)) - { - echo '

    '.__('Importing Categories...').'

    '; - foreach ($categories as $category) - { - $count++; - extract($category); - - - // Make Nice Variables - $name = $wpdb->escape($name); - $title = $wpdb->escape($title); - - if($cinfo = category_exists($name)) - { - $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); - } - else - { - $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); - } - $txpcat2wpcat[$id] = $ret_id; - } - - // Store category translation for future use - add_option('txpcat2wpcat',$txpcat2wpcat); - echo '

    '.sprintf(_n('Done! %1$s category imported.', 'Done! %1$s categories imported.', $count), $count).'

    '; - return true; - } - echo __('No Categories to Import!'); - return false; - } - - function users2wp($users='') - { - // General Housekeeping - global $wpdb; - $count = 0; - $txpid2wpid = array(); - - // Midnight Mojo - if(is_array($users)) - { - echo '

    '.__('Importing Users...').'

    '; - foreach($users as $user) - { - $count++; - extract($user); - - // Make Nice Variables - $name = $wpdb->escape($name); - $RealName = $wpdb->escape($RealName); - - if($uinfo = get_userdatabylogin($name)) - { - - $ret_id = wp_insert_user(array( - 'ID' => $uinfo->ID, - 'user_login' => $name, - 'user_nicename' => $RealName, - 'user_email' => $email, - 'user_url' => 'http://', - 'display_name' => $name) - ); - } - else - { - $ret_id = wp_insert_user(array( - 'user_login' => $name, - 'user_nicename' => $RealName, - 'user_email' => $email, - 'user_url' => 'http://', - 'display_name' => $name) - ); - } - $txpid2wpid[$user_id] = $ret_id; - - // Set Textpattern-to-WordPress permissions translation - $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); - - // Update Usermeta Data - $user = new WP_User($ret_id); - if('10' == $transperms[$privs]) { $user->set_role('administrator'); } - if('9' == $transperms[$privs]) { $user->set_role('editor'); } - if('5' == $transperms[$privs]) { $user->set_role('editor'); } - if('4' == $transperms[$privs]) { $user->set_role('author'); } - if('3' == $transperms[$privs]) { $user->set_role('contributor'); } - if('2' == $transperms[$privs]) { $user->set_role('contributor'); } - if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } - - update_user_meta( $ret_id, 'wp_user_level', $transperms[$privs] ); - update_user_meta( $ret_id, 'rich_editing', 'false'); - }// End foreach($users as $user) - - // Store id translation array for future use - add_option('txpid2wpid',$txpid2wpid); - - - echo '

    '.sprintf(__('Done! %1$s users imported.'), $count).'

    '; - return true; - }// End if(is_array($users) - - echo __('No Users to Import!'); - return false; - - }// End function user2wp() - - function posts2wp($posts='') - { - // General Housekeeping - global $wpdb; - $count = 0; - $txpposts2wpposts = array(); - $cats = array(); - - // Do the Magic - if(is_array($posts)) - { - echo '

    '.__('Importing Posts...').'

    '; - foreach($posts as $post) - { - $count++; - extract($post); - - // Set Textpattern-to-WordPress status translation - $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); - - //Can we do this more efficiently? - $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1; - $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; - - $Title = $wpdb->escape($Title); - $Body = $wpdb->escape($Body); - $Excerpt = $wpdb->escape($Excerpt); - $post_status = $stattrans[$Status]; - - // Import Post data into WordPress - - if($pinfo = post_exists($Title,$Body)) - { - $ret_id = wp_insert_post(array( - 'ID' => $pinfo, - 'post_date' => $Posted, - 'post_date_gmt' => $post_date_gmt, - 'post_author' => $authorid, - 'post_modified' => $LastMod, - 'post_modified_gmt' => $post_modified_gmt, - 'post_title' => $Title, - 'post_content' => $Body, - 'post_excerpt' => $Excerpt, - 'post_status' => $post_status, - 'post_name' => $url_title, - 'comment_count' => $comments_count) - ); - if ( is_wp_error( $ret_id ) ) - return $ret_id; - } - else - { - $ret_id = wp_insert_post(array( - 'post_date' => $Posted, - 'post_date_gmt' => $post_date_gmt, - 'post_author' => $authorid, - 'post_modified' => $LastMod, - 'post_modified_gmt' => $post_modified_gmt, - 'post_title' => $Title, - 'post_content' => $Body, - 'post_excerpt' => $Excerpt, - 'post_status' => $post_status, - 'post_name' => $url_title, - 'comment_count' => $comments_count) - ); - if ( is_wp_error( $ret_id ) ) - return $ret_id; - } - $txpposts2wpposts[$ID] = $ret_id; - - // Make Post-to-Category associations - $cats = array(); - $category1 = get_category_by_slug($Category1); - $category1 = $category1->term_id; - $category2 = get_category_by_slug($Category2); - $category2 = $category2->term_id; - if($cat1 = $category1) { $cats[1] = $cat1; } - if($cat2 = $category2) { $cats[2] = $cat2; } - - if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } - } - } - // Store ID translation for later use - add_option('txpposts2wpposts',$txpposts2wpposts); - - echo '

    '.sprintf(__('Done! %1$s posts imported.'), $count).'

    '; - return true; - } - - function comments2wp($comments='') - { - // General Housekeeping - global $wpdb; - $count = 0; - $txpcm2wpcm = array(); - $postarr = get_option('txpposts2wpposts'); - - // Magic Mojo - if(is_array($comments)) - { - echo '

    '.__('Importing Comments...').'

    '; - foreach($comments as $comment) - { - $count++; - extract($comment); - - // WordPressify Data - $comment_ID = ltrim($discussid, '0'); - $comment_post_ID = $postarr[$parentid]; - $comment_approved = (1 == $visible) ? 1 : 0; - $name = $wpdb->escape($name); - $email = $wpdb->escape($email); - $web = $wpdb->escape($web); - $message = $wpdb->escape($message); - - $comment = array( - 'comment_post_ID' => $comment_post_ID, - 'comment_author' => $name, - 'comment_author_IP' => $ip, - 'comment_author_email' => $email, - 'comment_author_url' => $web, - 'comment_date' => $posted, - 'comment_content' => $message, - 'comment_approved' => $comment_approved); - $comment = wp_filter_comment($comment); - - if ( $cinfo = comment_exists($name, $posted) ) { - // Update comments - $comment['comment_ID'] = $cinfo; - $ret_id = wp_update_comment($comment); - } else { - // Insert comments - $ret_id = wp_insert_comment($comment); - } - $txpcm2wpcm[$comment_ID] = $ret_id; - } - // Store Comment ID translation for future use - add_option('txpcm2wpcm', $txpcm2wpcm); - - // Associate newly formed categories with posts - get_comment_count($ret_id); - - - echo '

    '.sprintf(__('Done! %1$s comments imported.'), $count).'

    '; - return true; - } - echo __('No Comments to Import!'); - return false; - } - - function links2wp($links='') - { - // General Housekeeping - global $wpdb; - $count = 0; - - // Deal with the links - if(is_array($links)) - { - echo '

    '.__('Importing Links...').'

    '; - foreach($links as $link) - { - $count++; - extract($link); - - // Make nice vars - $category = $wpdb->escape($category); - $linkname = $wpdb->escape($linkname); - $description = $wpdb->escape($description); - - if($linfo = link_exists($linkname)) - { - $ret_id = wp_insert_link(array( - 'link_id' => $linfo, - 'link_url' => $url, - 'link_name' => $linkname, - 'link_category' => $category, - 'link_description' => $description, - 'link_updated' => $date) - ); - } - else - { - $ret_id = wp_insert_link(array( - 'link_url' => $url, - 'link_name' => $linkname, - 'link_category' => $category, - 'link_description' => $description, - 'link_updated' => $date) - ); - } - $txplinks2wplinks[$link_id] = $ret_id; - } - add_option('txplinks2wplinks',$txplinks2wplinks); - echo '

    '; - printf(_n('Done! %s link imported', 'Done! %s links imported', $count), $count); - echo '

    '; - return true; - } - echo __('No Links to Import!'); - return false; - } - - function import_categories() - { - // Category Import - $cats = $this->get_txp_cats(); - $this->cat2wp($cats); - add_option('txp_cats', $cats); - - - - echo '
    '; - wp_nonce_field('import-textpattern'); - printf('

    ', esc_attr__('Import Users')); - echo '
    '; - - } - - function import_users() - { - // User Import - $users = $this->get_txp_users(); - $this->users2wp($users); - - echo '
    '; - wp_nonce_field('import-textpattern'); - printf('

    ', esc_attr__('Import Posts')); - echo '
    '; - } - - function import_posts() - { - // Post Import - $posts = $this->get_txp_posts(); - $result = $this->posts2wp($posts); - if ( is_wp_error( $result ) ) - return $result; - - echo '
    '; - wp_nonce_field('import-textpattern'); - printf('

    ', esc_attr__('Import Comments')); - echo '
    '; - } - - function import_comments() - { - // Comment Import - $comments = $this->get_txp_comments(); - $this->comments2wp($comments); - - echo '
    '; - wp_nonce_field('import-textpattern'); - printf('

    ', esc_attr__('Import Links')); - echo '
    '; - } - - function import_links() - { - //Link Import - $links = $this->get_txp_links(); - $this->links2wp($links); - add_option('txp_links', $links); - - echo '
    '; - wp_nonce_field('import-textpattern'); - printf('

    ', esc_attr__('Finish')); - echo '
    '; - } - - function cleanup_txpimport() - { - delete_option('tpre'); - delete_option('txp_cats'); - delete_option('txpid2wpid'); - delete_option('txpcat2wpcat'); - delete_option('txpposts2wpposts'); - delete_option('txpcm2wpcm'); - delete_option('txplinks2wplinks'); - delete_option('txpuser'); - delete_option('txppass'); - delete_option('txpname'); - delete_option('txphost'); - do_action('import_done', 'textpattern'); - $this->tips(); - } - - function tips() - { - echo '

    '.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'

    '; - echo '

    '.__('Users').'

    '; - echo '

    '.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn’t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. Every user has the same username, but their passwords are reset to password123. So log in and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'

    '; - echo '

    '.__('Preserving Authors').'

    '; - echo '

    '.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'

    '; - echo '

    '.__('Textile').'

    '; - echo '

    '.__('Also, since you’re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing Textile for WordPress. Trust me... You’ll want it.').'

    '; - echo '

    '.__('WordPress Resources').'

    '; - echo '

    '.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

    '; - echo ''; - echo '

    '.sprintf(__('That’s it! What are you waiting for? Go log in!'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'

    '; - } - - function db_form() - { - echo ''; - printf('', __('Textpattern Database User:')); - printf('', __('Textpattern Database Password:')); - printf('', __('Textpattern Database Name:')); - printf('', __('Textpattern Database Host:')); - printf('', __('Textpattern Table prefix (if any):')); - echo '
    '; - } - - function dispatch() - { - - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - $this->header(); - - if ( $step > 0 ) - { - check_admin_referer('import-textpattern'); - - if($_POST['dbuser']) - { - if(get_option('txpuser')) - delete_option('txpuser'); - add_option('txpuser', sanitize_user($_POST['dbuser'], true)); - } - if($_POST['dbpass']) - { - if(get_option('txppass')) - delete_option('txppass'); - add_option('txppass', sanitize_user($_POST['dbpass'], true)); - } - - if($_POST['dbname']) - { - if(get_option('txpname')) - delete_option('txpname'); - add_option('txpname', sanitize_user($_POST['dbname'], true)); - } - if($_POST['dbhost']) - { - if(get_option('txphost')) - delete_option('txphost'); - add_option('txphost', sanitize_user($_POST['dbhost'], true)); - } - if($_POST['dbprefix']) - { - if(get_option('tpre')) - delete_option('tpre'); - add_option('tpre', sanitize_user($_POST['dbprefix'])); - } - - - } - - switch ($step) - { - default: - case 0 : - $this->greet(); - break; - case 1 : - $this->import_categories(); - break; - case 2 : - $this->import_users(); - break; - case 3 : - $result = $this->import_posts(); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - case 4 : - $this->import_comments(); - break; - case 5 : - $this->import_links(); - break; - case 6 : - $this->cleanup_txpimport(); - break; - } - - $this->footer(); - } - - function Textpattern_Import() - { - // Nothing. - } -} - -$txp_import = new Textpattern_Import(); - -register_importer('textpattern', __('Textpattern'), __('Import categories, users, posts, comments, and links from a Textpattern blog.'), array ($txp_import, 'dispatch')); - -?> diff --git a/wp-admin/import/utw.php b/wp-admin/import/utw.php deleted file mode 100644 index 3add5b6362..0000000000 --- a/wp-admin/import/utw.php +++ /dev/null @@ -1,290 +0,0 @@ -'; - screen_icon(); - echo '

    '.__('Import Ultimate Tag Warrior').'

    '; - echo '

    '.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

    '; - } - - function footer() { - echo ''; - } - - function greet() { - echo '
    '; - echo '

    '.__('Howdy! This imports tags from Ultimate Tag Warrior 3 into WordPress tags.').'

    '; - echo '

    '.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'

    '; - echo '

    '.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'

    '; - echo '

    '.__('Don’t be stupid - backup your database before proceeding!').'

    '; - echo '
    '; - echo '

    '; - echo '
    '; - echo '
    '; - } - - - function dispatch () { - if ( empty( $_GET['step'] ) ) { - $step = 0; - } else { - $step = (int) $_GET['step']; - } - - if ( $step > 1 ) - check_admin_referer('import-utw'); - - // load the header - $this->header(); - - switch ( $step ) { - case 0 : - $this->greet(); - break; - case 1 : - $this->import_tags(); - break; - case 2 : - $this->import_posts(); - break; - case 3: - $this->import_t2p(); - break; - case 4: - $this->cleanup_import(); - break; - } - - // load the footer - $this->footer(); - } - - - function import_tags ( ) { - echo '
    '; - echo '

    '.__('Reading UTW Tags…').'

    '; - - $tags = $this->get_utw_tags(); - - // if we didn't get any tags back, that's all there is folks! - if ( !is_array($tags) ) { - echo '

    ' . __('No Tags Found!') . '

    '; - return false; - } - else { - - // if there's an existing entry, delete it - if ( get_option('utwimp_tags') ) { - delete_option('utwimp_tags'); - } - - add_option('utwimp_tags', $tags); - - - $count = count($tags); - - echo '

    ' . sprintf( _n('Done! %s tag were read.', 'Done! %s tags were read.', $count), $count ) . '

    '; - echo '

    ' . __('The following tags were found:') . '

    '; - - echo '
      '; - - foreach ( $tags as $tag_id => $tag_name ) { - - echo '
    • ' . $tag_name . '
    • '; - - } - - echo '
    '; - - echo '
    '; - - echo '

    ' . __('If you don’t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '

    '; - - - } - - echo '
    '; - wp_nonce_field('import-utw'); - echo '

    '; - echo '
    '; - echo '
    '; - } - - - function import_posts ( ) { - echo '
    '; - echo '

    '.__('Reading UTW Post Tags…').'

    '; - - // read in all the UTW tag -> post settings - $posts = $this->get_utw_posts(); - - // if we didn't get any tags back, that's all there is folks! - if ( !is_array($posts) ) { - echo '

    ' . __('No posts were found to have tags!') . '

    '; - return false; - } - else { - - // if there's an existing entry, delete it - if ( get_option('utwimp_posts') ) { - delete_option('utwimp_posts'); - } - - add_option('utwimp_posts', $posts); - - - $count = count($posts); - - echo '

    ' . sprintf( _n('Done! %s tag to post relationships were read.', 'Done! %s tags to post relationships were read.', $count), $count ) . '

    '; - - } - - echo '
    '; - wp_nonce_field('import-utw'); - echo '

    '; - echo '
    '; - echo '
    '; - - } - - - function import_t2p ( ) { - - echo '
    '; - echo '

    '.__('Adding Tags to Posts…').'

    '; - - // run that funky magic! - $tags_added = $this->tag2post(); - - echo '

    ' . sprintf( _n( 'Done! %s tag were added!', 'Done! %s tags were added!', $tags_added ), $tags_added ) . '

    '; - - echo '
    '; - wp_nonce_field('import-utw'); - echo '

    '; - echo '
    '; - echo '
    '; - - } - - - function get_utw_tags ( ) { - - global $wpdb; - - // read in all the tags from the UTW tags table: should be wp_tags - $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags"; - - $tags = $wpdb->get_results($tags_query); - - // rearrange these tags into something we can actually use - foreach ( $tags as $tag ) { - - $new_tags[$tag->tag_id] = $tag->tag; - - } - - return $new_tags; - - } - - function get_utw_posts ( ) { - - global $wpdb; - - // read in all the posts from the UTW post->tag table: should be wp_post2tag - $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag"; - - $posts = $wpdb->get_results($posts_query); - - return $posts; - - } - - - function tag2post ( ) { - - // get the tags and posts we imported in the last 2 steps - $tags = get_option('utwimp_tags'); - $posts = get_option('utwimp_posts'); - - // null out our results - $tags_added = 0; - - // loop through each post and add its tags to the db - foreach ( $posts as $this_post ) { - - $the_post = (int) $this_post->post_id; - $the_tag = (int) $this_post->tag_id; - - // what's the tag name for that id? - $the_tag = $tags[$the_tag]; - - // screw it, just try to add the tag - wp_add_post_tags($the_post, $the_tag); - - $tags_added++; - - } - - // that's it, all posts should be linked to their tags properly, pending any errors we just spit out! - return $tags_added; - - - } - - - function cleanup_import ( ) { - - delete_option('utwimp_tags'); - delete_option('utwimp_posts'); - - $this->done(); - - } - - - function done ( ) { - - echo '
    '; - echo '

    '.__('Import Complete!').'

    '; - - echo '

    ' . __('OK, so we lied about this being a 5-step program! You’re done!') . '

    '; - - echo '

    ' . __('Now wasn’t that easy?') . '

    '; - - echo '
    '; - - } - - - function UTW_Import ( ) { - - // Nothing. - - } - -} - - -// create the import object -$utw_import = new UTW_Import(); - -// add it to the import page! -register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into WordPress tags.'), array($utw_import, 'dispatch')); - -?> diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php deleted file mode 100644 index 1f46a2697b..0000000000 --- a/wp-admin/import/wordpress.php +++ /dev/null @@ -1,898 +0,0 @@ -'; - screen_icon(); - echo '

    '.__('Import WordPress').'

    '; - } - - function footer() { - echo ''; - } - - function greet() { - echo '
    '; - echo '

    '.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.').'

    '; - echo '

    '.__('Choose a WordPress WXR file to upload, then click Upload file and import.').'

    '; - wp_import_upload_form("admin.php?import=wordpress&step=1"); - echo '
    '; - } - - function get_tag( $string, $tag ) { - global $wpdb; - preg_match("|<$tag.*?>(.*?)|is", $string, $return); - if ( isset($return[1]) ) { - $return = preg_replace('|^$|s', '$1', $return[1]); - $return = $wpdb->escape( trim( $return ) ); - } else { - $return = ''; - } - return $return; - } - - function has_gzip() { - return is_callable('gzopen'); - } - - function fopen($filename, $mode='r') { - if ( $this->has_gzip() ) - return gzopen($filename, $mode); - return fopen($filename, $mode); - } - - function feof($fp) { - if ( $this->has_gzip() ) - return gzeof($fp); - return feof($fp); - } - - function fgets($fp, $len=8192) { - if ( $this->has_gzip() ) - return gzgets($fp, $len); - return fgets($fp, $len); - } - - function fclose($fp) { - if ( $this->has_gzip() ) - return gzclose($fp); - return fclose($fp); - } - - function get_entries($process_post_func=NULL) { - set_magic_quotes_runtime(0); - - $doing_entry = false; - $is_wxr_file = false; - - $fp = $this->fopen($this->file, 'r'); - if ($fp) { - while ( !$this->feof($fp) ) { - $importline = rtrim($this->fgets($fp)); - - // this doesn't check that the file is perfectly valid but will at least confirm that it's not the wrong format altogether - if ( !$is_wxr_file && preg_match('|xmlns:wp="http://wordpress[.]org/export/\d+[.]\d+/"|', $importline) ) - $is_wxr_file = true; - - if ( false !== strpos($importline, '') ) { - preg_match('|(.*?)|is', $importline, $url); - $this->base_url = $url[1]; - continue; - } - if ( false !== strpos($importline, '') ) { - preg_match('|(.*?)|is', $importline, $category); - $this->categories[] = $category[1]; - continue; - } - if ( false !== strpos($importline, '') ) { - preg_match('|(.*?)|is', $importline, $tag); - $this->tags[] = $tag[1]; - continue; - } - if ( false !== strpos($importline, '') ) { - preg_match('|(.*?)|is', $importline, $term); - $this->terms[] = $term[1]; - continue; - } - if ( false !== strpos($importline, '') ) { - $this->post = ''; - $doing_entry = true; - continue; - } - if ( false !== strpos($importline, '') ) { - $doing_entry = false; - if ($process_post_func) - call_user_func($process_post_func, $this->post); - continue; - } - if ( $doing_entry ) { - $this->post .= $importline . "\n"; - } - } - - $this->fclose($fp); - } - - return $is_wxr_file; - - } - - function get_wp_authors() { - // We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting. - $temp = $this->allauthornames; - $authors[0] = array_shift($temp); - $y = count($temp) + 1; - for ($x = 1; $x < $y; $x ++) { - $next = array_shift($temp); - if (!(in_array($next, $authors))) - array_push($authors, $next); - } - - return $authors; - } - - function get_authors_from_post() { - global $current_user; - - // this will populate $this->author_ids with a list of author_names => user_ids - - foreach ( (array) $_POST['author_in'] as $i => $in_author_name ) { - - if ( !empty($_POST['user_select'][$i]) ) { - // an existing user was selected in the dropdown list - $user = get_userdata( intval($_POST['user_select'][$i]) ); - if ( isset($user->ID) ) - $this->author_ids[$in_author_name] = $user->ID; - } - elseif ( $this->allow_create_users() ) { - // nothing was selected in the dropdown list, so we'll use the name in the text field - - $new_author_name = trim($_POST['user_create'][$i]); - // if the user didn't enter a name, assume they want to use the same name as in the import file - if ( empty($new_author_name) ) - $new_author_name = $in_author_name; - - $user_id = username_exists($new_author_name); - if ( !$user_id ) { - $user_id = wp_create_user($new_author_name, wp_generate_password()); - } - - if ( !is_wp_error( $user_id ) ) { - $this->author_ids[$in_author_name] = $user_id; - } - } - - // failsafe: if the user_id was invalid, default to the current user - if ( empty($this->author_ids[$in_author_name]) ) { - $this->author_ids[$in_author_name] = intval($current_user->ID); - } - } - - } - - function wp_authors_form() { -?> -

    -

    admins entries.'); ?>

    -allow_create_users() ) { - echo '

    '.__('If a new user is created by WordPress, a password will be randomly generated. Manually change the user’s details if necessary.')."

    \n"; - } - - - $authors = $this->get_wp_authors(); - echo '
    '; - wp_nonce_field('import-wordpress'); -?> -
      -'.__('Import author:').' '.$author.'
      '; - $this->users_form($j, $author); - echo ''; - } - - if ( $this->allow_fetch_attachments() ) { -?> -
    -

    -

    - - -

    - -'; - echo ''.'
    '; - echo '

    '; - echo '
    '; - - } - - function users_form($n, $author) { - - if ( $this->allow_create_users() ) { - printf('
    '); - } - else { - echo __('Map to existing').'
    '; - } - - // keep track of $n => $author name - echo ''; - - $users = get_users_of_blog(); -?> - get_entries(array(&$this, 'process_author')); - if ( $is_wxr_file ) { - $this->wp_authors_form(); - } - else { - echo '

    '.__('Invalid file').'

    '; - echo '

    '.__('Please upload a valid WXR (WordPress eXtended RSS) export file.').'

    '; - } - } - - // fetch the user ID for a given author name, respecting the mapping preferences - function checkauthor($author) { - global $current_user; - - if ( !empty($this->author_ids[$author]) ) - return $this->author_ids[$author]; - - // failsafe: map to the current user - return $current_user->ID; - } - - - - function process_categories() { - global $wpdb; - - $cat_names = (array) get_terms('category', array('fields' => 'names')); - - while ( $c = array_shift($this->categories) ) { - $cat_name = trim($this->get_tag( $c, 'wp:cat_name' )); - - // If the category exists we leave it alone - if ( in_array($cat_name, $cat_names) ) - continue; - - $category_nicename = $this->get_tag( $c, 'wp:category_nicename' ); - $category_description = $this->get_tag( $c, 'wp:category_description' ); - $posts_private = (int) $this->get_tag( $c, 'wp:posts_private' ); - $links_private = (int) $this->get_tag( $c, 'wp:links_private' ); - - $parent = $this->get_tag( $c, 'wp:category_parent' ); - - if ( empty($parent) ) - $category_parent = '0'; - else - $category_parent = category_exists($parent); - - $catarr = compact('category_nicename', 'category_parent', 'posts_private', 'links_private', 'posts_private', 'cat_name', 'category_description'); - - print '' . sprintf( __( 'Importing category %s…' ), esc_html($cat_name) ) . '
    ' . "\n"; - $cat_ID = wp_insert_category($catarr); - } - } - - function process_tags() { - global $wpdb; - - $tag_names = (array) get_terms('post_tag', array('fields' => 'names')); - - while ( $c = array_shift($this->tags) ) { - $tag_name = trim($this->get_tag( $c, 'wp:tag_name' )); - - // If the category exists we leave it alone - if ( in_array($tag_name, $tag_names) ) - continue; - - $slug = $this->get_tag( $c, 'wp:tag_slug' ); - $description = $this->get_tag( $c, 'wp:tag_description' ); - - $tagarr = compact('slug', 'description'); - - print '' . sprintf( __( 'Importing tag %s…' ), esc_html($tag_name) ) . '
    ' . "\n"; - $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr); - } - } - - function process_terms() { - global $wpdb, $wp_taxonomies; - - $custom_taxonomies = $wp_taxonomies; - // get rid of the standard taxonomies - unset( $custom_taxonomies['category'] ); - unset( $custom_taxonomies['post_tag'] ); - unset( $custom_taxonomies['link_category'] ); - - $custom_taxonomies = array_keys( $custom_taxonomies ); - $current_terms = (array) get_terms( $custom_taxonomies, array('get' => 'all') ); - $taxonomies = array(); - foreach ( $current_terms as $term ) { - if ( isset( $_terms[$term->taxonomy] ) ) { - $taxonomies[$term->taxonomy] = array_merge( $taxonomies[$term->taxonomy], array($term->name) ); - } else { - $taxonomies[$term->taxonomy] = array($term->name); - } - } - - while ( $c = array_shift($this->terms) ) { - $term_name = trim($this->get_tag( $c, 'wp:term_name' )); - $term_taxonomy = trim($this->get_tag( $c, 'wp:term_taxonomy' )); - - // If the term exists in the taxonomy we leave it alone - if ( isset($taxonomies[$term_taxonomy] ) && in_array( $term_name, $taxonomies[$term_taxonomy] ) ) - continue; - - $slug = $this->get_tag( $c, 'wp:term_slug' ); - $description = $this->get_tag( $c, 'wp:term_description' ); - - $termarr = compact('slug', 'description'); - - print '' . sprintf( __( 'Importing %s…' ), esc_html($term_name) ) . '
    ' . "\n"; - $term_ID = wp_insert_term($term_name, $this->get_tag( $c, 'wp:term_taxonomy' ), $termarr); - } - } - - function process_author($post) { - $author = $this->get_tag( $post, 'dc:creator' ); - if ($author) - $this->allauthornames[] = $author; - } - - function process_posts() { - echo '
      '; - - $this->get_entries(array(&$this, 'process_post')); - - echo '
    '; - - wp_import_cleanup($this->id); - do_action('import_done', 'wordpress'); - - echo '

    '.sprintf(__('All done.').' '.__('Have fun!').'', get_option('home')).'

    '; - } - - function _normalize_tag( $matches ) { - return '<' . strtolower( $matches[1] ); - } - - function process_post($post) { - global $wpdb; - - $post_ID = (int) $this->get_tag( $post, 'wp:post_id' ); - if ( $post_ID && !empty($this->post_ids_processed[$post_ID]) ) // Processed already - return 0; - - set_time_limit( 60 ); - - // There are only ever one of these - $post_title = $this->get_tag( $post, 'title' ); - $post_date = $this->get_tag( $post, 'wp:post_date' ); - $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' ); - $comment_status = $this->get_tag( $post, 'wp:comment_status' ); - $ping_status = $this->get_tag( $post, 'wp:ping_status' ); - $post_status = $this->get_tag( $post, 'wp:status' ); - $post_name = $this->get_tag( $post, 'wp:post_name' ); - $post_parent = $this->get_tag( $post, 'wp:post_parent' ); - $menu_order = $this->get_tag( $post, 'wp:menu_order' ); - $post_type = $this->get_tag( $post, 'wp:post_type' ); - $post_password = $this->get_tag( $post, 'wp:post_password' ); - $is_sticky = $this->get_tag( $post, 'wp:is_sticky' ); - $guid = $this->get_tag( $post, 'guid' ); - $post_author = $this->get_tag( $post, 'dc:creator' ); - - $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' ); - $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt); - $post_excerpt = str_replace('
    ', '
    ', $post_excerpt); - $post_excerpt = str_replace('
    ', '
    ', $post_excerpt); - - $post_content = $this->get_tag( $post, 'content:encoded' ); - $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - $post_content = str_replace('
    ', '
    ', $post_content); - - preg_match_all('|(.*?)|is', $post, $tags); - $tags = $tags[1]; - - $tag_index = 0; - foreach ($tags as $tag) { - $tags[$tag_index] = $wpdb->escape( html_entity_decode( str_replace(array( '' ), '', $tag ) ) ); - $tag_index++; - } - - preg_match_all('|(.*?)|is', $post, $categories); - $categories = $categories[1]; - - $cat_index = 0; - foreach ($categories as $category) { - $categories[$cat_index] = $wpdb->escape( html_entity_decode( str_replace( array( '' ), '', $category ) ) ); - $cat_index++; - } - - $post_exists = post_exists($post_title, '', $post_date); - - if ( $post_exists ) { - echo '
  • '; - printf(__('Post %s already exists.'), stripslashes($post_title)); - $comment_post_ID = $post_id = $post_exists; - } else { - - // If it has parent, process parent first. - $post_parent = (int) $post_parent; - if ($post_parent) { - // if we already know the parent, map it to the local ID - if ( isset( $this->post_ids_processed[$post_parent] ) ) { - $post_parent = $this->post_ids_processed[$post_parent]; // new ID of the parent - } - else { - // record the parent for later - $this->orphans[intval($post_ID)] = $post_parent; - } - } - - echo '
  • '; - - $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor - - $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'post_status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password'); - $postdata['import_id'] = $post_ID; - if ($post_type == 'attachment') { - $remote_url = $this->get_tag( $post, 'wp:attachment_url' ); - if ( !$remote_url ) - $remote_url = $guid; - - $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url); - if ( !$post_id or is_wp_error($post_id) ) - return $post_id; - } - else { - printf(__('Importing post %s...') . "\n", stripslashes($post_title)); - $comment_post_ID = $post_id = wp_insert_post($postdata); - if ( $post_id && $is_sticky == 1 ) - stick_post( $post_id ); - - } - - if ( is_wp_error( $post_id ) ) - return $post_id; - - // Memorize old and new ID. - if ( $post_id && $post_ID ) { - $this->post_ids_processed[intval($post_ID)] = intval($post_id); - } - - // Add categories. - if (count($categories) > 0) { - $post_cats = array(); - foreach ($categories as $category) { - if ( '' == $category ) - continue; - $slug = sanitize_term_field('slug', $category, 0, 'category', 'db'); - $cat = get_term_by('slug', $slug, 'category'); - $cat_ID = 0; - if ( ! empty($cat) ) - $cat_ID = $cat->term_id; - if ($cat_ID == 0) { - $category = $wpdb->escape($category); - $cat_ID = wp_insert_category(array('cat_name' => $category)); - if ( is_wp_error($cat_ID) ) - continue; - } - $post_cats[] = $cat_ID; - } - wp_set_post_categories($post_id, $post_cats); - } - - // Add tags. - if (count($tags) > 0) { - $post_tags = array(); - foreach ($tags as $tag) { - if ( '' == $tag ) - continue; - $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); - $tag_obj = get_term_by('slug', $slug, 'post_tag'); - $tag_id = 0; - if ( ! empty($tag_obj) ) - $tag_id = $tag_obj->term_id; - if ( $tag_id == 0 ) { - $tag = $wpdb->escape($tag); - $tag_id = wp_insert_term($tag, 'post_tag'); - if ( is_wp_error($tag_id) ) - continue; - $tag_id = $tag_id['term_id']; - } - $post_tags[] = intval($tag_id); - } - wp_set_post_tags($post_id, $post_tags); - } - } - - // Now for comments - preg_match_all('|(.*?)|is', $post, $comments); - $comments = $comments[1]; - $num_comments = 0; - $inserted_comments = array(); - if ( $comments) { - foreach ($comments as $comment) { - $comment_id = $this->get_tag( $comment, 'wp:comment_id'); - $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; - $newcomments[$comment_id]['comment_author'] = $this->get_tag( $comment, 'wp:comment_author'); - $newcomments[$comment_id]['comment_author_email'] = $this->get_tag( $comment, 'wp:comment_author_email'); - $newcomments[$comment_id]['comment_author_IP'] = $this->get_tag( $comment, 'wp:comment_author_IP'); - $newcomments[$comment_id]['comment_author_url'] = $this->get_tag( $comment, 'wp:comment_author_url'); - $newcomments[$comment_id]['comment_date'] = $this->get_tag( $comment, 'wp:comment_date'); - $newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag( $comment, 'wp:comment_date_gmt'); - $newcomments[$comment_id]['comment_content'] = $this->get_tag( $comment, 'wp:comment_content'); - $newcomments[$comment_id]['comment_approved'] = $this->get_tag( $comment, 'wp:comment_approved'); - $newcomments[$comment_id]['comment_type'] = $this->get_tag( $comment, 'wp:comment_type'); - $newcomments[$comment_id]['comment_parent'] = $this->get_tag( $comment, 'wp:comment_parent'); - } - // Sort by comment ID, to make sure comment parents exist (if there at all) - ksort($newcomments); - foreach ($newcomments as $key => $comment) { - // if this is a new post we can skip the comment_exists() check - if ( !$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date']) ) { - if (isset($inserted_comments[$comment['comment_parent']])) - $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; - $comment = wp_filter_comment($comment); - $inserted_comments[$key] = wp_insert_comment($comment); - $num_comments++; - } - } - } - - if ( $num_comments ) - printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments); - - // Now for post meta - preg_match_all('|(.*?)|is', $post, $postmeta); - $postmeta = $postmeta[1]; - if ( $postmeta) { foreach ($postmeta as $p) { - $key = $this->get_tag( $p, 'wp:meta_key' ); - $value = $this->get_tag( $p, 'wp:meta_value' ); - $value = stripslashes($value); // add_post_meta() will escape. - // get_post_meta would have done this but we read straight from the db on export so we could have a serialized string - $value = maybe_unserialize($value); - - $this->process_post_meta($post_id, $key, $value); - - } } - - do_action('import_post_added', $post_id); - print "
  • \n"; - } - - function process_post_meta($post_id, $key, $value) { - // the filter can return false to skip a particular metadata key - $_key = apply_filters('import_post_meta_key', $key); - if ( $_key ) { - add_post_meta( $post_id, $_key, $value ); - do_action('import_post_meta', $post_id, $_key, $value); - } - } - - function process_attachment($postdata, $remote_url) { - if ($this->fetch_attachments and $remote_url) { - printf( __('Importing attachment %s... '), htmlspecialchars($remote_url) ); - - // If the URL is absolute, but does not contain http, upload it assuming the base_site_url variable - if ( preg_match('/^\/[\w\W]+$/', $remote_url) ) - $remote_url = rtrim($this->base_url,'/').$remote_url; - - $upload = $this->fetch_remote_file($postdata, $remote_url); - if ( is_wp_error($upload) ) { - printf( __('Remote file error: %s'), htmlspecialchars($upload->get_error_message()) ); - return $upload; - } - else { - print '('.size_format(filesize($upload['file'])).')'; - } - - if ( 0 == filesize( $upload['file'] ) ) { - print __( "Zero length file, deleting" ) . "\n"; - unlink( $upload['file'] ); - return; - } - - if ( $info = wp_check_filetype($upload['file']) ) { - $postdata['post_mime_type'] = $info['type']; - } - else { - print __('Invalid file type'); - return; - } - - $postdata['guid'] = $upload['url']; - - // as per wp-admin/includes/upload.php - $post_id = wp_insert_attachment($postdata, $upload['file']); - wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); - - // remap the thumbnail url. this isn't perfect because we're just guessing the original url. - if ( preg_match('@^image/@', $info['type']) && $thumb_url = wp_get_attachment_thumb_url($post_id) ) { - $parts = pathinfo($remote_url); - $ext = $parts['extension']; - $name = basename($parts['basename'], ".{$ext}"); - $this->url_remap[$parts['dirname'] . '/' . $name . '.thumbnail.' . $ext] = $thumb_url; - } - - return $post_id; - } - else { - printf( __('Skipping attachment %s'), htmlspecialchars($remote_url) ); - } - } - - function fetch_remote_file( $post, $url ) { - add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); - - $upload = wp_upload_dir($post['post_date']); - - // extract the file name and extension from the url - $file_name = basename($url); - - // get placeholder file in the upload dir with a unique sanitized filename - $upload = wp_upload_bits( $file_name, 0, '', $post['post_date']); - if ( $upload['error'] ) { - echo $upload['error']; - return new WP_Error( 'upload_dir_error', $upload['error'] ); - } - - // fetch the remote url and write it to the placeholder file - $headers = wp_get_http($url, $upload['file']); - - //Request failed - if ( ! $headers ) { - @unlink($upload['file']); - return new WP_Error( 'import_file_error', __('Remote server did not respond') ); - } - - // make sure the fetch was successful - if ( $headers['response'] != '200' ) { - @unlink($upload['file']); - return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %1$d %2$s'), $headers['response'], get_status_header_desc($headers['response']) ) ); - } - elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) { - @unlink($upload['file']); - return new WP_Error( 'import_file_error', __('Remote file is incorrect size') ); - } - - $max_size = $this->max_attachment_size(); - if ( !empty($max_size) and filesize($upload['file']) > $max_size ) { - @unlink($upload['file']); - return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', size_format($max_size))) ); - } - - // keep track of the old and new urls so we can substitute them later - $this->url_remap[$url] = $upload['url']; - $this->url_remap[$post['guid']] = $upload['url']; - // if the remote url is redirected somewhere else, keep track of the destination too - if ( $headers['x-final-location'] != $url ) - $this->url_remap[$headers['x-final-location']] = $upload['url']; - - return $upload; - - } - - /** - * Bump up the request timeout for http requests - * - * @param int $val - * @return int - */ - function bump_request_timeout( $val ) { - return 60; - } - - // sort by strlen, longest string first - function cmpr_strlen($a, $b) { - return strlen($b) - strlen($a); - } - - // update url references in post bodies to point to the new local files - function backfill_attachment_urls() { - - // make sure we do the longest urls first, in case one is a substring of another - uksort($this->url_remap, array(&$this, 'cmpr_strlen')); - - global $wpdb; - foreach ($this->url_remap as $from_url => $to_url) { - // remap urls in post_content - $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, '%s', '%s')", $from_url, $to_url) ); - // remap enclosure urls - $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, '%s', '%s') WHERE meta_key='enclosure'", $from_url, $to_url) ); - } - } - - // update the post_parent of orphans now that we know the local id's of all parents - function backfill_parents() { - global $wpdb; - - foreach ($this->orphans as $child_id => $parent_id) { - $local_child_id = $local_parent_id = false; - if ( isset( $this->post_ids_processed[$child_id] ) ) - $local_child_id = $this->post_ids_processed[$child_id]; - if ( isset( $this->post_ids_processed[$parent_id] ) ) - $local_parent_id = $this->post_ids_processed[$parent_id]; - - if ($local_child_id and $local_parent_id) { - $wpdb->update($wpdb->posts, array('post_parent' => $local_parent_id), array('ID' => $local_child_id) ); - } - } - } - - function is_valid_meta_key($key) { - // skip attachment metadata since we'll regenerate it from scratch - if ( $key == '_wp_attached_file' || $key == '_wp_attachment_metadata' ) - return false; - return $key; - } - - // give the user the option of creating new users to represent authors in the import file? - function allow_create_users() { - return apply_filters('import_allow_create_users', true); - } - - // give the user the option of downloading and importing attached files - function allow_fetch_attachments() { - return apply_filters('import_allow_fetch_attachments', true); - } - - function max_attachment_size() { - // can be overridden with a filter - 0 means no limit - return apply_filters('import_attachment_size_limit', 0); - } - - function import_start() { - wp_defer_term_counting(true); - wp_defer_comment_counting(true); - do_action('import_start'); - } - - function import_end() { - do_action('import_end'); - - // clear the caches after backfilling - foreach ($this->post_ids_processed as $post_id) - clean_post_cache($post_id); - - wp_defer_term_counting(false); - wp_defer_comment_counting(false); - } - - function import($id, $fetch_attachments = false) { - $this->id = (int) $id; - $this->fetch_attachments = ($this->allow_fetch_attachments() && (bool) $fetch_attachments); - - add_filter('import_post_meta_key', array($this, 'is_valid_meta_key')); - $file = get_attached_file($this->id); - $this->import_file($file); - } - - function import_file($file) { - $this->file = $file; - - $this->import_start(); - $this->get_authors_from_post(); - wp_suspend_cache_invalidation(true); - $this->get_entries(); - $this->process_categories(); - $this->process_tags(); - $this->process_terms(); - $result = $this->process_posts(); - wp_suspend_cache_invalidation(false); - $this->backfill_parents(); - $this->backfill_attachment_urls(); - $this->import_end(); - - if ( is_wp_error( $result ) ) - return $result; - } - - function handle_upload() { - $file = wp_import_handle_upload(); - if ( isset($file['error']) ) { - echo '

    '.__('Sorry, there has been an error.').'

    '; - echo '

    ' . $file['error'] . '

    '; - return false; - } - $this->file = $file['file']; - $this->id = (int) $file['id']; - return true; - } - - function dispatch() { - if (empty ($_GET['step'])) - $step = 0; - else - $step = (int) $_GET['step']; - - $this->header(); - switch ($step) { - case 0 : - $this->greet(); - break; - case 1 : - check_admin_referer('import-upload'); - if ( $this->handle_upload() ) - $this->select_authors(); - break; - case 2: - check_admin_referer('import-wordpress'); - $fetch_attachments = ! empty( $_POST['attachments'] ); - $result = $this->import( $_GET['id'], $fetch_attachments); - if ( is_wp_error( $result ) ) - echo $result->get_error_message(); - break; - } - $this->footer(); - } - - function WP_Import() { - // Nothing. - } -} - -/** - * Register WordPress Importer - * - * @since unknown - * @var WP_Import - * @name $wp_import - */ -$wp_import = new WP_Import(); - -register_importer('wordpress', 'WordPress', __('Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.'), array ($wp_import, 'dispatch')); - -?> diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php deleted file mode 100644 index 73b5877796..0000000000 --- a/wp-admin/import/wp-cat2tag.php +++ /dev/null @@ -1,473 +0,0 @@ -'; - if ( ! current_user_can('manage_categories') ) { - echo '
    '; - echo '

    ' . __('Cheatin’ uh?') . '

    '; - echo '
    '; - } else { ?> -

    -

    -'; - } - - function populate_cats() { - - $categories = get_categories(array('get' => 'all')); - foreach ( $categories as $category ) { - $this->all_categories[] = $category; - if ( is_term( $category->slug, 'post_tag' ) ) - $this->hybrids_ids[] = $category->term_id; - } - } - - function populate_tags() { - - $tags = get_terms( array('post_tag'), array('get' => 'all') ); - foreach ( $tags as $tag ) { - $this->all_tags[] = $tag; - if ( is_term( $tag->slug, 'category' ) ) - $this->hybrids_ids[] = $tag->term_id; - } - } - - function categories_tab() { - $this->populate_cats(); - $cat_num = count($this->all_categories); - - echo '
    '; - - if ( $cat_num > 0 ) { - screen_icon(); - echo '

    ' . sprintf( _n( 'Convert Category to Tag.', 'Convert Categories (%d) to Tags.', $cat_num ), $cat_num ) . '

    '; - echo '
    '; - echo '

    ' . __('Hey there. Here you can selectively convert existing categories to tags. To get started, check the categories you wish to be converted, then click the Convert button.') . '

    '; - echo '

    ' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '

    '; - - $this->categories_form(); - } else { - echo '

    '.__('You have no categories to convert!').'

    '; - } - } - - function categories_form() { ?> - - - -
    -

    -

    -
      - -all_categories as $category) { - $category = sanitize_term( $category, 'category', 'display' ); - - if ( (int) $category->parent == 0 ) { ?> - -
    • term_id), $this->hybrids_ids ) ) - echo ' * '; - - if ( isset($hier[$category->term_id]) ) - $this->_category_children($category, $hier); ?>
    • - -
    - -hybrids_ids) ) - echo '

    ' . __('* This category is also a tag. Converting it will add that tag to all posts that are currently in the category.') . '

    '; ?> - -

    -
    - -populate_tags(); - $tags_num = count($this->all_tags); - - echo '
    '; - - if ( $tags_num > 0 ) { - screen_icon(); - echo '

    ' . sprintf( _n( 'Convert Tag to Category.', 'Convert Tags (%d) to Categories.', $tags_num ), $tags_num ) . '

    '; - echo '
    '; - echo '

    ' . __('Here you can selectively convert existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '

    '; - echo '

    ' . __('The newly created categories will still be associated with the same posts.') . '

    '; - - $this->tags_form(); - } else { - echo '

    '.__('You have no tags to convert!').'

    '; - } - } - - function tags_form() { ?> - - - -
    -

    -

    -
      - -all_tags as $tag ) { ?> -
    • term_id), $this->hybrids_ids ) ) echo ' * '; ?>
    • - - -
    - -hybrids_ids) ) - echo '

    ' . __('* This tag is also a category. When converted, all posts associated with the tag will also be in the category.') . '

    '; ?> - -

    -
    - - - -
      -term_id] as $child_id) { - $child =& get_category($child_id); ?> -
    • term_id), $this->hybrids_ids ) ) - echo ' * '; - - if ( isset($hier[$child->term_id]) ) - $this->_category_children($child, $hier); ?>
    • - -
    categories_to_convert)) { ?> -
    -

    try again.'), 'admin.php?import=wp-cat2tag'); ?>

    -
    -categories_to_convert) ) - $this->categories_to_convert = $_POST['cats_to_convert']; - - $hier = _get_term_hierarchy('category'); - $hybrid_cats = $clear_parents = $parents = false; - $clean_term_cache = $clean_cat_cache = array(); - $default_cat = get_option('default_category'); - - echo '
      '; - - foreach ( (array) $this->categories_to_convert as $cat_id) { - $cat_id = (int) $cat_id; - - if ( ! $this->_category_exists($cat_id) ) { - echo '
    • ' . sprintf( __('Category %s doesn’t exist!'), $cat_id ) . "
    • \n"; - } else { - $category =& get_category($cat_id); - echo '
    • ' . sprintf(__('Converting category %s ... '), $category->name); - - // If the category is the default, leave category in place and create tag. - if ( $default_cat == $category->term_id ) { - - if ( ! ($id = is_term( $category->slug, 'post_tag' ) ) ) - $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); - - $id = $id['term_taxonomy_id']; - $posts = get_objects_in_term($category->term_id, 'category'); - $term_order = 0; - - foreach ( $posts as $post ) { - $values[] = $wpdb->prepare( "(%d, %d, %d)", $post, $id, $term_order); - clean_post_cache($post); - } - - if ( $values ) { - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); - - $wpdb->update($wpdb->term_taxonomy, array('count' => $category->count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') ); - } - - echo __('Converted successfully.') . "
    • \n"; - continue; - } - - // if tag already exists, add it to all posts in the category - if ( $tag_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $category->term_id) ) ) { - $objects_ids = get_objects_in_term($category->term_id, 'category'); - $tag_ttid = (int) $tag_ttid; - $term_order = 0; - - foreach ( $objects_ids as $object_id ) - $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tag_ttid, $term_order); - - if ( $values ) { - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); - - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) ); - $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $category->term_id, 'taxonomy' => 'post_tag') ); - } - echo __('Tag added to all posts in this category.') . " *\n"; - - $hybrid_cats = true; - $clean_term_cache[] = $category->term_id; - $clean_cat_cache[] = $category->term_id; - - continue; - } - - $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); - if ( $tt_ids ) { - $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); - foreach ( (array) $posts as $post ) - clean_post_cache($post); - } - - // Change the category to a tag. - $wpdb->update($wpdb->term_taxonomy, array('taxonomy' => 'post_tag'), array('term_id' => $category->term_id, 'taxonomy' => 'category') ); - - // Set all parents to 0 (root-level) if their parent was the converted tag - $wpdb->update($wpdb->term_taxonomy, array('parent' => 0), array('parent' => $category->term_id, 'taxonomy' => 'category') ); - - if ( $parents ) $clear_parents = true; - $clean_cat_cache[] = $category->term_id; - echo __('Converted successfully.') . "\n"; - } - } - echo '
    '; - - if ( ! empty($clean_term_cache) ) { - $clean_term_cache = array_unique(array_values($clean_term_cache)); - clean_term_cache($clean_term_cache, 'post_tag'); - } - - if ( ! empty($clean_cat_cache) ) { - $clean_cat_cache = array_unique(array_values($clean_cat_cache)); - clean_term_cache($clean_cat_cache, 'category'); - } - - if ( $clear_parents ) delete_option('category_children'); - - if ( $hybrid_cats ) - echo '

    ' . sprintf( __('* This category is also a tag. The converter has added that tag to all posts currently in the category. If you want to remove it, please confirm that all tags were added successfully, then delete it from the Manage Categories page.'), 'categories.php') . '

    '; - echo '

    ' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag' ) . '

    '; - } - - function convert_tags() { - global $wpdb; - - if ( (!isset($_POST['tags_to_convert']) || !is_array($_POST['tags_to_convert'])) && empty($this->tags_to_convert)) { - echo '
    '; - echo '

    ' . sprintf(__('Uh, oh. Something didn’t work. Please try again.'), 'admin.php?import=wp-cat2tag&step=3') . '

    '; - echo '
    '; - return; - } - - if ( empty($this->tags_to_convert) ) - $this->tags_to_convert = $_POST['tags_to_convert']; - - $hybrid_tags = $clear_parents = false; - $clean_cat_cache = $clean_term_cache = array(); - $default_cat = get_option('default_category'); - echo '
      '; - - foreach ( (array) $this->tags_to_convert as $tag_id) { - $tag_id = (int) $tag_id; - - if ( $tag = get_term( $tag_id, 'post_tag' ) ) { - printf('
    • ' . __('Converting tag %s ... '), $tag->name); - - if ( $cat_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $tag->term_id) ) ) { - $objects_ids = get_objects_in_term($tag->term_id, 'post_tag'); - $cat_ttid = (int) $cat_ttid; - $term_order = 0; - - foreach ( $objects_ids as $object_id ) { - $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $cat_ttid, $term_order); - clean_post_cache($object_id); - } - - if ( $values ) { - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); - - if ( $default_cat != $tag->term_id ) { - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) ); - $wpdb->update($wpdb->term_taxonomy, array('count' => $count), array('term_id' => $tag->term_id, 'taxonomy' => 'category') ); - } - } - - $hybrid_tags = true; - $clean_term_cache[] = $tag->term_id; - $clean_cat_cache[] = $tag->term_id; - echo __('All posts were added to the category with the same name.') . " *
    • \n"; - - continue; - } - - // Change the tag to a category. - $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) ); - if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) { - $new_fields = array('taxonomy' => 'category'); - $clear_parents = true; - } else { - $new_fields = array('taxonomy' => 'category', 'parent' => 0); - } - - $wpdb->update($wpdb->term_taxonomy, $new_fields, array('term_id' => $tag->term_id, 'taxonomy' => 'post_tag') ); - - $clean_term_cache[] = $tag->term_id; - $clean_cat_cache[] = $cat['term_id']; - echo __('Converted successfully.') . "\n"; - - } else { - printf( '
    • ' . __('Tag #%s doesn’t exist!') . "
    • \n", $tag_id ); - } - } - - if ( ! empty($clean_term_cache) ) { - $clean_term_cache = array_unique(array_values($clean_term_cache)); - clean_term_cache($clean_term_cache, 'post_tag'); - } - - if ( ! empty($clean_cat_cache) ) { - $clean_cat_cache = array_unique(array_values($clean_cat_cache)); - clean_term_cache($clean_term_cache, 'category'); - } - - if ( $clear_parents ) delete_option('category_children'); - - echo '
    '; - if ( $hybrid_tags ) - echo '

    ' . sprintf( __('* This tag is also a category. The converter has added all posts from it to the category. If you want to remove it, please confirm that all posts were added successfully, then delete it from the Manage Tags page.'), 'edit-tags.php') . '

    '; - echo '

    ' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag&step=3' ) . '

    '; - } - - function init() { - - $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; - - $this->header(); - - if ( current_user_can('manage_categories') ) { - - switch ($step) { - case 1 : - $this->categories_tab(); - break; - - case 2 : - check_admin_referer('import-cat2tag'); - $this->convert_categories(); - break; - - case 3 : - $this->tags_tab(); - break; - - case 4 : - check_admin_referer('import-cat2tag'); - $this->convert_tags(); - break; - } - } - - $this->footer(); - } - - function WP_Categories_to_Tags() { - // Do nothing. - } -} - -$wp_cat2tag_importer = new WP_Categories_to_Tags(); - -register_importer('wp-cat2tag', __('Categories and Tags Converter'), __('Convert existing categories to tags or tags to categories, selectively.'), array(&$wp_cat2tag_importer, 'init')); - -?>