summaryrefslogtreecommitdiffstats
path: root/wp-admin/import
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-06-22 18:31:50 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-06-22 18:31:50 +0000
commitd48e85e0ac5e675ca33fac173f30c75403d1033f (patch)
tree1164430fa3b83a4d9283961b09c1576f2885e6b2 /wp-admin/import
parent086dcde66603301531efc6d8087bd06d0546f148 (diff)
downloadwordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.tar.gz
wordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.tar.xz
wordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.zip
Moved everything in wp-inst down a directory.
Uses's Ryan Boren's htaccess rules and mods If you're upgrading, try this on a test server first! git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@591 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/import')
-rw-r--r--wp-admin/import/b2.php0
-rw-r--r--wp-admin/import/blogger.php675
-rw-r--r--wp-admin/import/blogware.php192
-rw-r--r--wp-admin/import/dotclear.php747
-rw-r--r--wp-admin/import/greymatter.php312
-rw-r--r--wp-admin/import/livejournal.php168
-rw-r--r--wp-admin/import/mt.php407
-rw-r--r--wp-admin/import/rss.php171
-rw-r--r--wp-admin/import/textpattern.php663
-rw-r--r--wp-admin/import/wordpress.php288
10 files changed, 3623 insertions, 0 deletions
diff --git a/wp-admin/import/b2.php b/wp-admin/import/b2.php
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/wp-admin/import/b2.php
diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php
new file mode 100644
index 0000000..8de766c
--- /dev/null
+++ b/wp-admin/import/blogger.php
@@ -0,0 +1,675 @@
+<?php
+
+class Blogger_Import {
+
+ var $lump_authors = true;
+ var $import = array();
+
+ // Shows the welcome screen and the magic iframe.
+ function greet() {
+ $title = __('Import Blogger');
+ $welcome = __('Howdy! This importer allows you to import posts and comments from your Blogger account into your WordPress blog.');
+ $noiframes = __('This feature requires iframe support.');
+ $warning = __('This will delete everything saved by the Blogger importer except your posts and comments. Are you sure you want to do this?');
+ $reset = __('Reset this importer');
+ $incompat = __('Your web server is not properly configured to use this importer. Please enable the CURL extension for PHP and then reload this page.');
+
+ echo "<div class='wrap'><h2>$title</h2><p>$welcome</p>";
+ if ( function_exists('curl_init') )
+ echo "<iframe src='admin.php?import=blogger&amp;noheader=true' height='350px' width = '99%'>$noiframes</iframe><p><a href='admin.php?import=blogger&amp;restart=true&amp;noheader=true' onclick='return confirm(\"$warning\")'>$reset</a></p>";
+ else
+ echo "<p>$incompat</p>";
+ echo "</div>\n";
+ }
+
+ function reencode($text) {
+ return $text;
+ return mb_convert_encoding($text, get_setting('blog_charset'), $this->import['blogs'][$_GET['blog']]['options']['blog-formatting']['backup']['encoding']);
+ }
+
+ // Deletes saved data and redirect.
+ function restart() {
+ delete_option('import-blogger');
+ header("Location: admin.php?import=blogger");
+ die();
+ }
+
+ // Generates a string that will make the page reload in a specified interval.
+ function refresher($msec) {
+ if ( $msec )
+ return "<html><head><script type='text/javascript'>window.onload=setTimeout('window.location.reload()', $msec);</script>\n</head>\n<body>\n";
+ else
+ return "<html><head><script type='text/javascript'>window.onload=window.location.reload();</script>\n</head>\n<body>\n";
+ }
+
+ // 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);
+ }
+
+ // Prints a form for the user to enter Blogger creds.
+ function login_form($text='') {
+ echo '<h1>' . __('Log in to Blogger') . "</h1>\n$text\n";
+ echo '<form method="post" action="admin.php?import=blogger&amp;noheader=true&amp;step=0"><table><tr><td>' . __('Username') . ':</td><td><input type="text" name="user" /></td></tr><tr><td>' . __('Password') . ':</td><td><input type="password" name="pass" /></td><td><input type="submit" value="' . __('Start') . '" /></td></tr></table></form>';
+ die;
+ }
+
+ // Sends creds to Blogger, returns the session cookies an array of headers.
+ function login_blogger($user, $pass) {
+ $_url = 'http://www.blogger.com/login.do';
+ $params = "username=$user&password=$pass";
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_POST,1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
+ curl_setopt($ch, CURLOPT_URL,$_url);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
+ curl_setopt($ch, CURLOPT_HEADER,1);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
+ $response = curl_exec ($ch);
+
+ $response = $this->parse_response($response);
+
+ sleep(1);
+
+ return $response['cookies'];
+ }
+
+ // Requests page from Blogger, returns the response array.
+ function get_blogger($url, $header = '', $user=false, $pass=false) {
+ $ch = curl_init();
+ if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}");
+ curl_setopt($ch, CURLOPT_URL,$url);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 20);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
+ curl_setopt($ch, CURLOPT_HEADER,1);
+ if (is_array($header)) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+ $response = curl_exec ($ch);
+
+ $response = $this->parse_response($response);
+ $response['url'] = $url;
+
+ if (curl_errno($ch)) {
+ print curl_error($ch);
+ } else {
+ curl_close($ch);
+ }
+
+ return $response;
+ }
+
+ // Posts data to Blogger, returns response array.
+ function post_blogger($url, $header = false, $paramary = false, $parse=true) {
+ $params = '';
+ if ( is_array($paramary) ) {
+ foreach($paramary as $key=>$value)
+ if($key && $value != '')
+ $params.=$key."=".urlencode(stripslashes($value))."&";
+ }
+ if ($user && $pass) $params .= "username=$user&password=$pass";
+ $params = trim($params,'&');
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_POST,1);
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
+ if ($user && $pass) curl_setopt($ch, CURLOPT_USERPWD,"{$user}:{$pass}");
+ curl_setopt($ch, CURLOPT_URL,$url);
+ curl_setopt($ch, CURLOPT_USERAGENT, 'Blogger Exporter');
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+ curl_setopt($ch, CURLOPT_HEADER,$parse);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
+ if ($header) curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+ $response = curl_exec ($ch);
+
+ if ($parse) {
+ $response = $this->parse_response($response);
+ $response['url'] = $url;
+ return $response;
+ }
+
+ return $response;
+ }
+
+ // Prints the list of blogs for import.
+ function show_blogs() {
+ global $import;
+ echo '<h1>' . __('Selecting a Blog') . "</h1>\n<ul>";
+ foreach ( $this->import['blogs'] as $blog ) {
+ if (9 == $blog['nextstep']) $status = "100%";
+ elseif (8 == $blog['nextstep']) $status = "90%";
+ elseif (7 == $blog['nextstep']) $status = "82.5%";
+ elseif (6 == $blog['nextstep']) $status = "75%";
+ elseif (5 == $blog['nextstep']) $status = "57%";
+ elseif (4 == $blog['nextstep']) $status = "28%";
+ elseif (3 == $blog['nextstep']) $status = "14%";
+ else $status = "0%";
+ echo "\t<li><a href='admin.php?import=blogger&amp;noheader=true&amp;blog={$blog['id']}'>{$blog['title']}</a> $status</li>\n";
+ }
+ die("</ul>\n");
+ }
+
+ // Publishes.
+ function publish_blogger($i, $text) {
+ $head = $this->refresher(2000) . "<h1>$text</h1>\n";
+ if ( ! strstr($this->import['blogs'][$_GET['blog']]['publish'][$i], 'http') ) {
+ // First call. Start the publish process with a fresh set of cookies.
+ $this->import['cookies'] = $this->login_blogger($this->import['user'], $this->import['pass']);
+ update_option('import-blogger', $this->import);
+ $paramary = array('blogID' => $_GET['blog'], 'all' => '1', 'republishAll' => 'Republish Entire Blog', 'publish' => '1', 'redirectUrl' => "/publish.do?blogID={$_GET['blog']}&inprogress=true");
+
+ $response = $this->post_blogger("http://www.blogger.com/publish.do?blogID={$_GET['blog']}", $this->import['cookies'], $paramary);
+ if ( $response['code'] == '302' ) {
+ $url = str_replace('publish.g', 'publish-body.g', $response['header']['Location']);
+ $this->import['blogs'][$_GET['blog']]['publish'][$i] = $url;
+ update_option('import-blogger', $this->import);
+ $response = $this->get_blogger($url, $this->import['cookies']);
+ preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches);
+ $progress = $matches[0];
+ die($head . $progress);
+ } else {
+ $this->import['blogs'][$_GET['blog']]['publish'][$i] = false;
+ update_option('import-blogger', $this->import);
+ die($head);
+ }
+ } else {
+ // Subsequent call. Keep checking status until Blogger reports publish complete.
+ $url = $this->import['blogs'][$_GET['blog']]['publish'][$i];
+ $response = $this->get_blogger($url, $this->import['cookies']);
+ if ( preg_match('#<p class="progressIndicator">.*</p>#U', $response['body'], $matches) ) {
+ $progress = $matches[0];
+ if ( strstr($progress, '100%') ) {
+ $this->set_next_step($i);
+ $progress .= '<p>'.__('Moving on...').'</p>';
+ }
+ die($head . $progress);
+ } else {
+ $this->import['blogs'][$_GET['blog']]['publish'][$i] = false;
+ update_option('import-blogger', $this->import);
+ die("$head<p>" . __('Trying again...') . '</p>');
+ }
+ }
+ }
+
+ // Sets next step, saves options
+ function set_next_step($step) {
+ $this->import['blogs'][$_GET['blog']]['nextstep'] = $step;
+ update_option('import-blogger', $this->import);
+ }
+
+ // Redirects to next step
+ function do_next_step() {
+ header("Location: admin.php?import=blogger&noheader=true&blog={$_GET['blog']}");
+ die();
+ }
+
+ // Step 0: Do Blogger login, get blogid/title pairs.
+ function do_login() {
+ if ( ( ! $this->import['user'] && ! is_array($this->import['cookies']) ) ) {
+ // The user must provide a Blogger username and password.
+ if ( ! ( $_POST['user'] && $_POST['pass'] ) ) {
+ $this->login_form(__('The script will log into your Blogger account, change some settings so it can read your blog, and restore the original settings when it\'s done. Here\'s what you do:').'</p><ol><li>'.__('Back up your Blogger template.').'</li><li>'.__('Back up any other Blogger settings you might need later.').'</li><li>'.__('Log out of Blogger').'</li><li>'.__('Log in <em>here</em> with your Blogger username and password.').'</li><li>'.__('On the next screen, click one of your Blogger blogs.').'</li><li>'.__('Do not close this window or navigate away until the process is complete.').'</li></ol>');
+ }
+
+ // Try logging in. If we get an array of cookies back, we at least connected.
+ $this->import['cookies'] = $this->login_blogger($_POST['user'], $_POST['pass']);
+ if ( !is_array( $this->import['cookies'] ) ) {
+ $this->login_form(__('Login failed. Please enter your credentials again.'));
+ }
+
+ // Save the password so we can log the browser in when it's time to publish.
+ $this->import['pass'] = $_POST['pass'];
+ $this->import['user'] = $_POST['user'];
+
+ // Get the Blogger welcome page and scrape the blog numbers and names from it
+ $response = $this->get_blogger('http://www.blogger.com/home', $this->import['cookies']);
+ if (! stristr($response['body'], 'signed in as') ) $this->login_form(__('Login failed. Please re-enter your username and password.'));
+ $blogsary = array();
+ preg_match_all('#posts\.g\?blogID=(\d+)">([^<]+)</a>#U', $response['body'], $blogsary);
+ if ( ! count( $blogsary[1] < 1 ) )
+ die(__('No blogs found for this user.'));
+ $this->import['blogs'] = array();
+ $template = '<!--<MainPage><BloggerArchives><a class="wparchive" href="<$BlogArchiveURL$>"><$BlogArchiveName$></a><br /></BloggerArchives></MainPage><ArchivePage><Blogger><wordpresspost><$BlogItemDateTime$>|W|P|<$BlogItemAuthorNickname$>|W|P|<$BlogItemBody$>|W|P|<$BlogItemNumber$>|W|P|<$BlogItemTitle$>|W|P|<$BlogItemAuthorEmail$><BlogItemCommentsEnabled><BlogItemComments><wordpresscomment><$BlogCommentDateTime$>|W|P|<$BlogCommentAuthor$>|W|P|<$BlogCommentBody$></BlogItemComments></BlogItemCommentsEnabled></Blogger></ArchivePage>-->';
+ foreach ( $blogsary[1] as $key => $id ) {
+ // Define the required Blogger options.
+ $blog_opts = array(
+ 'blog-options-basic' => false,
+ 'blog-options-archiving' => array('archiveFrequency' => 'm'),
+ 'blog-publishing' => array('publishMode'=>'0', 'blogID' => "$id", 'subdomain' => mt_rand().mt_rand(), 'pingWeblogs' => 'false'),
+ 'blog-formatting' => array('timeStampFormat' => '0', 'convertLineBreaks'=>'false', 'floatAlignment'=>'false'),
+ 'blog-comments' => array('commentsTimeStampFormat' => '0'),
+ 'template-edit' => array( 'templateText' => str_replace('%title%', trim($blogsary[2][$key]), $template) )
+ );
+
+ // Build the blog options array template
+ foreach ($blog_opts as $blog_opt => $modify)
+ $new_opts["$blog_opt"] = array('backup'=>false, 'modify' => $modify, 'error'=>false);
+
+ $this->import['blogs']["$id"] = array(
+ 'id' => $id,
+ 'title' => trim($blogsary[2][$key]),
+ 'options' => $new_opts,
+ 'url' => false,
+ 'publish_cookies' => false,
+ 'published' => false,
+ 'archives' => false,
+ 'lump_authors' => false,
+ 'newusers' => array(),
+ 'nextstep' => 2
+ );
+ }
+ update_option('import-blogger', $this->import);
+ header("Location: admin.php?import=blogger&noheader=true&step=1");
+ }
+ die();
+ }
+
+ // Step 1: Select one of the blogs belonging to the user logged in.
+ function select_blog() {
+ if ( is_array($this->import['blogs']) ) {
+ $this->show_blogs();
+ die();
+ } else {
+ $this->restart();
+ }
+ }
+
+ // Step 2: Backup the Blogger options pages, updating some of them.
+ function backup_settings() {
+ $output.= '<h1>'.__('Backing up Blogger options')."</h1>\n";
+ $form = false;
+ foreach ($this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary) {
+ if ( $blog_opt == $_GET['form'] ) {
+ // Save the posted form data
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup'] = $_POST;
+ update_option('import-blogger',$this->import);
+
+ // Post the modified form data to Blogger
+ if ( $optary['modify'] ) {
+ $posturl = "http://www.blogger.com/{$blog_opt}.do";
+ $headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']);
+ if ( 'blog-publishing' == $blog_opt ) {
+ if ( $_POST['publishMode'] > 0 ) {
+ $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode=0", $headers);
+ if ( $response['code'] >= 400 )
+ die('<h2>'.__('Failed attempt to change publish mode from FTP to BlogSpot.').'</h2><pre>' . addslashes(print_r($headers, 1)) . addslashes(print_r($response, 1)) . '</pre>');
+ $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $optary['modify']['subdomain'] . '.blogspot.com/';
+ sleep(2);
+ } else {
+ $this->import['blogs'][$_GET['blog']]['url'] = 'http://' . $_POST['subdomain'] . '.blogspot.com/';
+ update_option('import-blogger', $this->import);
+ $output .= "<del><p>$blog_opt</p></del>\n";
+ continue;
+ }
+ $paramary = $optary['modify'];
+ } elseif ( 'template-edit' == $blog_opt ) {
+ $optary['modify']['templateText'] = $_POST['templateText'] . $optary['modify']['templateText'];
+ $paramary = array_merge($_POST, $optary['modify']);
+ } else {
+ $paramary = array_merge($_POST, $optary['modify']);
+ }
+ $response = $this->post_blogger($posturl, $headers, $paramary);
+ if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') )
+ die('<p>'.__('Error on form submission. Retry or reset the importer.').'</p>' . addslashes(print_r($response, 1)));
+ }
+ $output .= "<del><p>$blog_opt</p></del>\n";
+ } elseif ( is_array($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['backup']) ) {
+ // This option set has already been backed up.
+ $output .= "<del><p>$blog_opt</p></del>\n";
+ } elseif ( ! $form ) {
+ // This option page needs to be downloaded and given to the browser for submission back to this script.
+ $response = $this->get_blogger("http://www.blogger.com/{$blog_opt}.g?blogID={$_GET['blog']}", $this->import['cookies']);
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'] = $response['cookies'];
+ update_option('import-blogger',$this->import);
+ $body = $response['body'];
+ $body = preg_replace("|\<!DOCTYPE.*\<body[^>]*>|ms","",$body);
+ $body = preg_replace("|/?{$blog_opt}.do|","admin.php?import=blogger&amp;noheader=true&amp;step=2&amp;blog={$_GET['blog']}&amp;form={$blog_opt}",$body);
+ $body = str_replace("name='submit'","name='supermit'",$body);
+ $body = str_replace('name="submit"','name="supermit"',$body);
+ $body = str_replace('</body>','',str_replace('</html>','',$body));
+ $form = "<div style='height:0px;width:0px;overflow:hidden;'>";
+ $form.= $body;
+ $form.= "</div><script type='text/javascript'>forms=document.getElementsByTagName('form');for(i=0;i<forms.length;i++){if(forms[i].action.search('{$blog_opt}')){forms[i].submit();break;}}</script>";
+ $output.= '<p>'.sprintf('<strong>%s</strong> in progress, please wait...', $blog_opt)."</p>\n";
+ } else {
+ $output.= "<p>$blog_opt</p>\n";
+ }
+ }
+ if ( $form )
+ die($output . $form);
+
+ $this->set_next_step(4);
+ $this->do_next_step();
+ }
+
+ // Step 3: Cancelled :-)
+
+ // Step 4: Publish with the new template and settings.
+ function publish_blog() {
+ $this->publish_blogger(5, __('Publishing with new template and options'));
+ }
+
+ // Step 5: Get the archive URLs from the new blog.
+ function get_archive_urls() {
+ $bloghtml = $this->get_blogger($this->import['blogs'][$_GET['blog']]['url']);
+ if (! strstr($bloghtml['body'], '<a class="wparchive"') )
+ die(__('Your Blogger blog did not take the new template or did not respond.'));
+ preg_match_all('#<a class="wparchive" href="([^"]*)"#', $bloghtml['body'], $archives);
+ foreach ($archives[1] as $archive) {
+ $this->import['blogs'][$_GET['blog']]['archives'][$archive] = false;
+ }
+ $this->set_next_step(6);
+ $this->do_next_step();
+ }
+
+ // Step 6: Get each monthly archive, import it, mark it done.
+ function get_archive() {
+ global $wpdb;
+ $output = '<h2>'.__('Importing Blogger archives into WordPress').'</h2>';
+ $did_one = false;
+ $post_array = $posts = array();
+ foreach ( $this->import['blogs'][$_GET['blog']]['archives'] as $url => $status ) {
+ $archivename = substr(basename($url),0,7);
+ if ( $status || $did_one ) {
+ $foo = 'bar';
+ // Do nothing.
+ } else {
+ // Import the selected month
+ $postcount = 0;
+ $skippedpostcount = 0;
+ $commentcount = 0;
+ $skippedcommentcount = 0;
+ $status = __('in progress...');
+ $this->import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
+ update_option('import-blogger', $import);
+ $archive = $this->get_blogger($url);
+ if ( $archive['code'] > 200 )
+ continue;
+ $posts = explode('<wordpresspost>', $archive['body']);
+ for ($i = 1; $i < count($posts); $i = $i + 1) {
+ $postparts = explode('<wordpresscomment>', $posts[$i]);
+ $postinfo = explode('|W|P|', $postparts[0]);
+ $post_date = $postinfo[0];
+ $post_content = $postinfo[2];
+ // Don't try to re-use the original numbers
+ // because the new, longer numbers are too
+ // big to handle as ints.
+ //$post_number = $postinfo[3];
+ $post_title = ( $postinfo[4] != '' ) ? $postinfo[4] : $postinfo[3];
+ $post_author_name = $wpdb->escape(trim($postinfo[1]));
+ $post_author_email = $postinfo[5] ? $postinfo[5] : 'user@wordpress.org';
+
+ if ( $this->lump_authors ) {
+ // Ignore Blogger authors. Use the current user_ID for all posts imported.
+ $post_author = $GLOBALS['user_ID'];
+ } else {
+ // Add a user for each new author encountered.
+ if (! username_exists($post_author_name) ) {
+ $user_login = $wpdb->escape($post_author_name);
+ $user_email = $wpdb->escape($post_author_email);
+ $user_password = substr(md5(uniqid(microtime())), 0, 6);
+ $result = wp_create_user( $user_login, $user_password, $user_email );
+ $status.= sprintf('Registered user <strong>%s</strong>.', $user_login);
+ $this->import['blogs'][$_GET['blog']]['newusers'][] = $user_login;
+ }
+ $userdata = get_userdatabylogin( $post_author_name );
+ $post_author = $userdata->ID;
+ }
+ $post_date = explode(' ', $post_date);
+ $post_date_Ymd = explode('/', $post_date[0]);
+ $postyear = $post_date_Ymd[2];
+ $postmonth = zeroise($post_date_Ymd[0], 2);
+ $postday = zeroise($post_date_Ymd[1], 2);
+ $post_date_His = explode(':', $post_date[1]);
+ $posthour = zeroise($post_date_His[0], 2);
+ $postminute = zeroise($post_date_His[1], 2);
+ $postsecond = zeroise($post_date_His[2], 2);
+
+ if (($post_date[2] == 'PM') && ($posthour != '12'))
+ $posthour = $posthour + 12;
+ else if (($post_date[2] == 'AM') && ($posthour == '12'))
+ $posthour = '00';
+
+ $post_date = "$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
+
+ $post_content = addslashes($this->reencode($post_content));
+ $post_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $post_content); // the XHTML touch... ;)
+
+ $post_title = addslashes($this->reencode($post_title));
+
+ $post_status = 'publish';
+
+ if ( $ID = post_exists($post_title, '', $post_date) ) {
+ $post_array[$i]['ID'] = $ID;
+ $skippedpostcount++;
+ } else {
+ $post_array[$i]['post'] = compact('post_author', 'post_content', 'post_title', 'post_category', 'post_author', 'post_date', 'post_status');
+ $post_array[$i]['comments'] = false;
+ }
+
+ // Import any comments attached to this post.
+ if ($postparts[1]) :
+ for ($j = 1; $j < count($postparts); $j = $j + 1) {
+ $commentinfo = explode('|W|P|', $postparts[$j]);
+ $comment_date = explode(' ', $commentinfo[0]);
+ $comment_date_Ymd = explode('/', $comment_date[0]);
+ $commentyear = $comment_date_Ymd[2];
+ $commentmonth = zeroise($comment_date_Ymd[0], 2);
+ $commentday = zeroise($comment_date_Ymd[1], 2);
+ $comment_date_His = explode(':', $comment_date[1]);
+ $commenthour = zeroise($comment_date_His[0], 2);
+ $commentminute = zeroise($comment_date_His[1], 2);
+ $commentsecond = '00';
+ if (($comment_date[2] == 'PM') && ($commenthour != '12'))
+ $commenthour = $commenthour + 12;
+ else if (($comment_date[2] == 'AM') && ($commenthour == '12'))
+ $commenthour = '00';
+ $comment_date = "$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
+ $comment_author = addslashes($this->reencode(strip_tags($commentinfo[1])));
+ if ( strpos($commentinfo[1], 'a href') ) {
+ $comment_author_parts = explode('&quot;', htmlentities($commentinfo[1]));
+ $comment_author_url = $comment_author_parts[1];
+ } else $comment_author_url = '';
+ $comment_content = $this->reencode($commentinfo[2]);
+ $comment_content = str_replace(array('<br>','<BR>','<br/>','<BR/>','<br />','<BR />'), "\n", $comment_content);
+ $comment_approved = 1;
+ if ( comment_exists($comment_author, $comment_date) ) {
+ $skippedcommentcount++;
+ } else {
+ $comment = compact('comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved');
+ $post_array[$i]['comments'][$j] = wp_filter_comment($comment);
+ }
+ $commentcount++;
+ }
+ endif;
+ $postcount++;
+ }
+ if ( count($post_array) ) {
+ krsort($post_array);
+ foreach($post_array as $post) {
+ if ( ! $comment_post_ID = $post['ID'] )
+ $comment_post_ID = wp_insert_post($post['post']);
+ if ( $post['comments'] ) {
+ foreach ( $post['comments'] as $comment ) {
+ $comment['comment_post_ID'] = $comment_post_ID;
+ wp_insert_comment($comment);
+ }
+ }
+ }
+ }
+ $status = sprintf(__('%s post(s) parsed, %s skipped...'), $postcount, $skippedpostcount).' '.
+ sprintf(__('%s comment(s) parsed, %s skipped...'), $commentcount, $skippedcommentcount).' '.
+ ' <strong>'.__('Done').'</strong>';
+ $import = $this->import;
+ $import['blogs'][$_GET['blog']]['archives']["$url"] = $status;
+ update_option('import-blogger', $import);
+ $did_one = true;
+ }
+ $output.= "<p>$archivename $status</p>\n";
+ }
+ if ( ! $did_one )
+ $this->set_next_step(7);
+ die( $this->refresher(1000) . $output );
+ }
+
+ // Step 7: Restore the backed-up settings to Blogger
+ function restore_settings() {
+ $output = '<h1>'.__('Restoring your Blogger options')."</h1>\n";
+ $did_one = false;
+ // Restore options in reverse order.
+ if ( ! $this->import['reversed'] ) {
+ $this->import['blogs'][$_GET['blog']]['options'] = array_reverse($this->import['blogs'][$_GET['blog']]['options'], true);
+ $this->import['reversed'] = true;
+ update_option('import-blogger', $this->import);
+ }
+ foreach ( $this->import['blogs'][$_GET['blog']]['options'] as $blog_opt => $optary ) {
+ if ( $did_one ) {
+ $output .= "<p>$blog_opt</p>\n";
+ } elseif ( $optary['restored'] || ! $optary['modify'] ) {
+ $output .= "<p><del>$blog_opt</del></p>\n";
+ } else {
+ $posturl = "http://www.blogger.com/{$blog_opt}.do";
+ $headers = array_merge($this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['cookies'], $this->import['cookies']);
+ if ( 'blog-publishing' == $blog_opt) {
+ if ( $optary['backup']['publishMode'] > 0 ) {
+ $response = $this->get_blogger("http://www.blogger.com/blog-publishing.g?blogID={$_GET['blog']}&publishMode={$optary['backup']['publishMode']}", $headers);
+ sleep(2);
+ if ( $response['code'] >= 400 )
+ die('<h1>Error restoring publishMode.</h1><p>Please tell the devs.</p>' . addslashes(print_r($response, 1)) );
+ }
+ }
+ if ( $optary['backup'] != $optary['modify'] ) {
+ $response = $this->post_blogger($posturl, $headers, $optary['backup']);
+ if ( $response['code'] >= 400 || strstr($response['body'], 'There are errors on this form') ) {
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['error'] = true;
+ update_option('import-blogger', $this->import);
+ $output .= sprintf(__('%s failed. Trying again.'), "<p><strong>$blog_opt</strong> ").'</p>';
+ } else {
+ $this->import['blogs'][$_GET['blog']]['options']["$blog_opt"]['restored'] = true;
+ update_option('import-blogger', $this->import);
+ $output .= sprintf(__('%s restored.'), "<p><strong>$blog_opt</strong> ").'</p>';
+ }
+ }
+ $did_one = true;
+ }
+ }
+
+ if ( $did_one ) {
+ die( $this->refresher(1000) . $output );
+ } elseif ( $this->import['blogs'][$_GET['blog']]['options']['blog-publishing']['backup']['publishMode'] > 0 ) {
+ $this->set_next_step(9);
+ } else {
+ $this->set_next_step(8);
+ }
+
+ $this->do_next_step();
+ }
+
+ // Step 8: Republish, all back to normal
+ function republish_blog() {
+ $this->publish_blogger(9, __('Publishing with original template and options'));
+ }
+
+ // Step 9: Congratulate the user
+ function congrats() {
+ echo '<h1>'.__('Congratulations!').'</h1><p>'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'</p><ul><li>'.__('That was hard work! Take a break.').'</li>';
+ if ( count($this->import['blogs']) > 1 )
+ echo '<li>'.__('In case you haven\'t done it already, you can import the posts from your other blogs:'). $this->show_blogs() . '</li>';
+ if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) )
+ echo '<li>'.sprintf(__('Go to <a href="%s" target="%s">Authors &amp; Users</a>, 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').'</li>';
+ echo '<li>'.__('For security, click the link below to reset this importer. That will clear your Blogger credentials and options from the database.').'</li>';
+ echo '</ul>';
+ }
+
+ // Figures out what to do, then does it.
+ function start() {
+ if ( $_GET['restart'] == 'true' ) {
+ $this->restart();
+ }
+
+ if ( isset($_GET['noheader']) ) {
+ header('Content-Type: text/html; charset=utf-8');
+
+ $this->import = get_settings('import-blogger');
+
+ if ( false === $this->import ) {
+ $step = 0;
+ } elseif ( isset($_GET['step']) ) {
+ $step = (int) $_GET['step'];
+ } elseif ( isset($_GET['blog']) && isset($this->import['blogs'][$_GET['blog']]['nextstep']) ) {
+ $step = $this->import['blogs'][$_GET['blog']]['nextstep'];
+ } elseif ( is_array($this->import['blogs']) ) {
+ $step = 1;
+ } else {
+ $step = 0;
+ }
+//echo "Step $step.";
+//die('<pre>'.print_r($this->import,1).'</pre');
+ switch ($step) {
+ case 0 :
+ $this->do_login();
+ break;
+ case 1 :
+ $this->select_blog();
+ break;
+ case 2 :
+ $this->backup_settings();
+ break;
+ case 3 :
+ $this->wait_for_blogger();
+ break;
+ case 4 :
+ $this->publish_blog();
+ break;
+ case 5 :
+ $this->get_archive_urls();
+ break;
+ case 6 :
+ $this->get_archive();
+ break;
+ case 7 :
+ $this->restore_settings();
+ break;
+ case 8 :
+ $this->republish_blog();
+ break;
+ case 9 :
+ $this->congrats();
+ break;
+ }
+ die;
+
+ } else {
+ $this->greet();
+ }
+ }
+
+ function Blogger_Import() {
+ // This space intentionally left blank.
+ }
+}
+
+$blogger_import = new Blogger_Import();
+
+register_importer('blogger', 'Blogger and Blogspot', __('Import <strong>posts and comments</strong> from your Blogger account'), array ($blogger_import, 'start'));
+
+?>
diff --git a/wp-admin/import/blogware.php b/wp-admin/import/blogware.php
new file mode 100644
index 0000000..35ab610
--- /dev/null
+++ b/wp-admin/import/blogware.php
@@ -0,0 +1,192 @@
+<?php
+
+/* By Shayne Sweeney - http://www.theshayne.com/ */
+
+class BW_Import {
+
+ var $file;
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Blogware').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function unhtmlentities($string) { // From php.net for < 4.3 compat
+ $trans_tbl = get_html_translation_table(HTML_ENTITIES);
+ $trans_tbl = array_flip($trans_tbl);
+ return strtr($string, $trans_tbl);
+ }
+
+ function greet() {
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from Blogware XML export file into your blog. Pick a Blogware file to upload and click Import.').'</p>';
+ wp_import_upload_form("admin.php?import=blogware&amp;step=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('|(<item[^>]+>(.*?)</item>)|is', $importdata, $posts);
+ $posts = $posts[1];
+ unset($importdata);
+ echo '<ol>';
+ foreach ($posts as $post) {
+ flush();
+ preg_match('|<item type=\"(.*?)\">|is', $post, $post_type);
+ $post_type = $post_type[1];
+ if($post_type == "photo") {
+ preg_match('|<photoFilename>(.*?)</photoFilename>|is', $post, $post_title);
+ } else {
+ preg_match('|<title>(.*?)</title>|is', $post, $post_title);
+ }
+ $post_title = $wpdb->escape(trim($post_title[1]));
+
+ preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
+ $post_date = strtotime($post_date[1]);
+ $post_date = gmdate('Y-m-d H:i:s', $post_date);
+
+ preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
+ $categories = $categories[1];
+
+ $cat_index = 0;
+ foreach ($categories as $category) {
+ $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
+ $cat_index++;
+ }
+
+ if(strcasecmp($post_type, "photo") === 0) {
+ preg_match('|<sizedPhotoUrl>(.*?)</sizedPhotoUrl>|is', $post, $post_content);
+ $post_content = '<img src="'.trim($post_content[1]).'" />';
+ $post_content = $this->unhtmlentities($post_content);
+ } else {
+ preg_match('|<body>(.*?)</body>|is', $post, $post_content);
+ $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
+ $post_content = $this->unhtmlentities($post_content);
+ }
+
+ // Clean up content
+ $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+ $post_content = str_replace('<br>', '<br />', $post_content);
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
+ $post_content = $wpdb->escape($post_content);
+
+ $post_author = $current_user->ID;
+ preg_match('|<postStatus>(.*?)</postStatus>|is', $post, $post_status);
+ $post_status = trim($post_status[1]);
+
+ echo '<li>';
+ if ($post_id = post_exists($post_title, $post_content, $post_date)) {
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
+ } else {
+ printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
+ $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
+ $post_id = wp_insert_post($postdata);
+ if (!$post_id) {
+ _e("Couldn't get post ID");
+ echo '</li>';
+ break;
+ }
+ if(0 != count($categories))
+ wp_create_categories($categories, $post_id);
+ }
+
+ preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
+ $comments = $comments[1];
+
+ if ( $comments ) {
+ $comment_post_ID = $post_id;
+ $num_comments = 0;
+ foreach ($comments as $comment) {
+ preg_match('|<body>(.*?)</body>|is', $comment, $comment_content);
+ $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
+ $comment_content = $this->unhtmlentities($comment_content);
+
+ // Clean up content
+ $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
+ $comment_content = str_replace('<br>', '<br />', $comment_content);
+ $comment_content = str_replace('<hr>', '<hr />', $comment_content);
+ $comment_content = $wpdb->escape($comment_content);
+
+ preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
+ $comment_date = trim($comment_date[1]);
+ $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
+
+ preg_match('|<author>(.*?)</author>|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(__('(%s comments)'), $num_comments);
+ }
+ echo '</li>';
+ flush();
+ ob_flush();
+ }
+ echo '</ol>';
+ }
+
+ function import() {
+ $file = wp_import_handle_upload();
+ if ( isset($file['error']) ) {
+ echo $file['error'];
+ return;
+ }
+
+ $this->file = $file['file'];
+ $this->import_posts();
+ wp_import_cleanup($file['id']);
+
+ echo '<h3>';
+ printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
+ echo '</h3>';
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ $this->header();
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import();
+ 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
new file mode 100644
index 0000000..9dc8a6e
--- /dev/null
+++ b/wp-admin/import/dotclear.php
@@ -0,0 +1,747 @@
+<?php
+/*
+ * Dotclear import plugin
+ * by Thomas Quinot - http://thomas.quinot.org/
+ */
+
+/**
+ Add These Functions to make our lives easier
+**/
+if(!function_exists('get_catbynicename'))
+{
+ function get_catbynicename($category_nicename)
+ {
+ global $wpdb;
+
+ $cat_id -= 0; // force numeric
+ $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
+
+ return $name;
+ }
+}
+
+if(!function_exists('get_comment_count'))
+{
+ function get_comment_count($post_ID)
+ {
+ global $wpdb;
+ return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID);
+ }
+}
+
+if(!function_exists('link_cat_exists'))
+{
+ function link_cat_exists($catname)
+ {
+ global $wpdb;
+ return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"');
+ }
+}
+
+if(!function_exists('link_exists'))
+{
+ function link_exists($linkname)
+ {
+ global $wpdb;
+ return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"');
+ }
+}
+
+/*
+ Identify UTF-8 text
+ Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087
+*/
+//
+// utf8 encoding validation developed based on Wikipedia entry at:
+// http://en.wikipedia.org/wiki/UTF-8
+//
+// Implemented as a recursive descent parser based on a simple state machine
+// copyright 2005 Maarten Meijer
+//
+// This cries out for a C-implementation to be included in PHP core
+//
+ function valid_1byte($char) {
+ if(!is_int($char)) return false;
+ return ($char & 0x80) == 0x00;
+ }
+
+ function valid_2byte($char) {
+ if(!is_int($char)) return false;
+ return ($char & 0xE0) == 0xC0;
+ }
+
+ function valid_3byte($char) {
+ if(!is_int($char)) return false;
+ return ($char & 0xF0) == 0xE0;
+ }
+
+ function valid_4byte($char) {
+ if(!is_int($char)) return false;
+ return ($char & 0xF8) == 0xF0;
+ }
+
+ function valid_nextbyte($char) {
+ if(!is_int($char)) return false;
+ return ($char & 0xC0) == 0x80;
+ }
+
+ function valid_utf8($string) {
+ $len = strlen($string);
+ $i = 0;
+ while( $i < $len ) {
+ $char = ord(substr($string, $i++, 1));
+ if(valid_1byte($char)) { // continue
+ continue;
+ } else if(valid_2byte($char)) { // check 1 byte
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ } else if(valid_3byte($char)) { // check 2 bytes
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ } else if(valid_4byte($char)) { // check 3 bytes
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ if(!valid_nextbyte(ord(substr($string, $i++, 1))))
+ return false;
+ } // goto next char
+ }
+ return true; // done
+ }
+
+function csc ($s) {
+ if (valid_utf8 ($s)) {
+ return $s;
+ } else {
+ return iconv(get_option ("dccharset"),"UTF-8",$s);
+ }
+}
+
+function textconv ($s) {
+ return csc (preg_replace ('|(?<!<br />)\s*\n|', ' ', $s));
+}
+
+/**
+ The Main Importer Class
+**/
+class Dotclear_Import {
+
+ function header()
+ {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Dotclear').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
+ }
+
+ function footer()
+ {
+ echo '</div>';
+ }
+
+ function greet()
+ {
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from a Dotclear database into your blog. Mileage may vary.').'</p>';
+ echo '<p>'.__('Your Dotclear Configuration settings are as follows:').'</p>';
+ echo '<form action="admin.php?import=dotclear&amp;step=1" method="post">';
+ $this->db_form();
+ echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
+ echo '</form>';
+ }
+
+ 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 '<p>'.__('Importing Categories...').'<br /><br /></p>';
+ 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 '<p>'.sprintf(__('Done! <strong>%1$s</strong> categories imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Users...').'<br /><br /></p>';
+ 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_usermeta( $ret_id, 'wp_user_level', $wp_perms);
+ update_usermeta( $ret_id, 'rich_editing', 'false');
+ update_usermeta( $ret_id, 'first_name', csc ($user_prenom));
+ update_usermeta( $ret_id, 'last_name', csc ($user_nom));
+ }// End foreach($users as $user)
+
+ // Store id translation array for future use
+ add_option('dcid2wpid',$dcid2wpid);
+
+
+ echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Posts...').'<br /><br /></p>';
+ 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<!--more-->\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)
+ );
+ }
+ 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)
+ );
+ }
+ $dcposts2wpposts[$post_id] = $ret_id;
+
+ // Make Post-to-Category associations
+ $cats = array();
+ if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; }
+
+ if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
+ }
+ }
+ // Store ID translation for later use
+ add_option('dcposts2wpposts',$dcposts2wpposts);
+
+ echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
+ return true;
+ }
+
+ function comments2wp($comments='')
+ {
+ // General Housekeeping
+ global $wpdb;
+ $count = 0;
+ $dccm2wpcm = array();
+ $postarr = get_option('dcposts2wpposts');
+
+ // Magic Mojo
+ if(is_array($comments))
+ {
+ echo '<p>'.__('Importing Comments...').'<br /><br /></p>';
+ foreach($comments as $comment)
+ {
+ $count++;
+ extract($comment);
+
+ // WordPressify Data
+ $comment_ID = ltrim($comment_id, '0');
+ $comment_post_ID = $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));
+
+ if($cinfo = comment_exists($name, $comment_dt))
+ {
+ // Update comments
+ $ret_id = wp_update_comment(array(
+ 'comment_ID' => $cinfo,
+ '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)
+ );
+ }
+ else
+ {
+ // Insert comments
+ $ret_id = wp_insert_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)
+ );
+ }
+ $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 '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Links...').'<br /><br /></p>';
+ foreach($links as $link)
+ {
+ $count++;
+ extract($link);
+
+ if ($title != "") {
+ if ($cinfo = link_cat_exists (csc ($title))) {
+ $category = $cinfo;
+ } else {
+ $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('".
+ $wpdb->escape (csc ($title))."')");
+ $category = $wpdb->insert_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 '<p>';
+ printf(__('Done! <strong>%s</strong> links or link categories imported'), $count);
+ echo '<br /><br /></p>';
+ 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 '<form action="admin.php?import=dotclear&amp;step=2" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
+ echo '</form>';
+
+ }
+
+ function import_users()
+ {
+ // User Import
+ $users = $this->get_dc_users();
+ $this->users2wp($users);
+
+ echo '<form action="admin.php?import=dotclear&amp;step=3" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
+ echo '</form>';
+ }
+
+ function import_posts()
+ {
+ // Post Import
+ $posts = $this->get_dc_posts();
+ $this->posts2wp($posts);
+
+ echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
+ echo '</form>';
+ }
+
+ function import_comments()
+ {
+ // Comment Import
+ $comments = $this->get_dc_comments();
+ $this->comments2wp($comments);
+
+ echo '<form action="admin.php?import=dotclear&amp;step=5" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
+ echo '</form>';
+ }
+
+ function import_links()
+ {
+ //Link Import
+ $links = $this->get_dc_links();
+ $this->links2wp($links);
+ add_option('dc_links', $links);
+
+ echo '<form action="admin.php?import=dotclear&amp;step=6" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
+ echo '</form>';
+ }
+
+ 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');
+ $this->tips();
+ }
+
+ function tips()
+ {
+ echo '<p>'.__('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.').'</p>';
+ echo '<h3>'.__('Users').'</h3>';
+ echo '<p>'.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. <strong>Every user has the same username, but their passwords are reset to password123.</strong> So <a href="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
+ echo '<h3>'.__('Preserving Authors').'</h3>';
+ echo '<p>'.__('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.').'</p>';
+ echo '<h3>'.__('Textile').'</h3>';
+ echo '<p>'.__('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 <a href="http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/">Textile for WordPress</a>. Trust me... You\'ll want it.').'</p>';
+ echo '<h3>'.__('WordPress Resources').'</h3>';
+ echo '<p>'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'</p>';
+ echo '<ul>';
+ echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
+ echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums').'</li>';
+ echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
+ echo '</ul>';
+ echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
+ }
+
+ function db_form()
+ {
+ echo '<ul>';
+ printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" /></li>', __('Dotclear Database User:'));
+ printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" /></li>', __('Dotclear Database Password:'));
+ printf('<li><label for="dbname">%s</label> <input type="text" name="dbname" /></li>', __('Dotclear Database Name:'));
+ printf('<li><label for="dbhost">%s</label> <input type="text" name="dbhost" value="localhost" /></li>', __('Dotclear Database Host:'));
+ printf('<li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" value="dc_"/></li>', __('Dotclear Table prefix:'));
+ printf('<li><label for="dccharset">%s</label> <input type="text" name="dccharset" value="ISO-8859-15"/></li>', __('Originating character set:'));
+ echo '</ul>';
+ }
+
+ function dispatch()
+ {
+
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+ $this->header();
+
+ if ( $step > 0 )
+ {
+ if($_POST['dbuser'])
+ {
+ if(get_option('dcuser'))
+ delete_option('dcuser');
+ add_option('dcuser',$_POST['dbuser']);
+ }
+ if($_POST['dbpass'])
+ {
+ if(get_option('dcpass'))
+ delete_option('dcpass');
+ add_option('dcpass',$_POST['dbpass']);
+ }
+
+ if($_POST['dbname'])
+ {
+ if(get_option('dcname'))
+ delete_option('dcname');
+ add_option('dcname',$_POST['dbname']);
+ }
+ if($_POST['dbhost'])
+ {
+ if(get_option('dchost'))
+ delete_option('dchost');
+ add_option('dchost',$_POST['dbhost']);
+ }
+ if($_POST['dccharset'])
+ {
+ if(get_option('dccharset'))
+ delete_option('dccharset');
+ add_option('dccharset',$_POST['dccharset']);
+ }
+ if($_POST['dbprefix'])
+ {
+ if(get_option('dcdbprefix'))
+ delete_option('dcdbprefix');
+ add_option('dcdbprefix',$_POST['dbprefix']);
+ }
+
+
+ }
+
+ switch ($step)
+ {
+ default:
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import_categories();
+ break;
+ case 2 :
+ $this->import_users();
+ break;
+ case 3 :
+ $this->import_posts();
+ 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 posts from a Dotclear Blog'), array ($dc_import, 'dispatch'));
+?>
diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php
new file mode 100644
index 0000000..f2b4e2d
--- /dev/null
+++ b/wp-admin/import/greymatter.php
@@ -0,0 +1,312 @@
+<?php
+
+class GM_Import {
+
+ var $gmnames = array ();
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Greymatter').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ $this->header();
+?>
+<p>This is a basic GreyMatter to WordPress import script.</p>
+<p>What it does:</p>
+<ul>
+<li>Parses gm-authors.cgi to import (new) authors. Everyone is imported at level 1.</li>
+<li>Parses the entries cgi files to import posts, comments, and karma on posts (although karma is not used on WordPress yet).<br />If authors are found not to be in gm-authors.cgi, imports them at level 0.</li>
+<li>Detects duplicate entries or comments. If you don't import everything the first time, or this import should fail in the middle, duplicate entries will not be made when you try again.</li>
+</ul>
+<p>What it does not:</p>
+<ul>
+<li>Parse gm-counter.cgi, gm-banlist.cgi, gm-cplog.cgi (you can make a CP log hack if you really feel like it, but I question the need of a CP log).</li>
+<li>Import gm-templates.</li>
+<li>Doesn't keep entries on top.</li>
+</ul>
+<p>&nbsp;</p>
+
+<form name="stepOne" method="get">
+<input type="hidden" name="import" value="greymatter" />
+<input type="hidden" name="step" value="1" />
+<h3>Second step: GreyMatter details:</h3>
+<p><table cellpadding="0">
+<tr>
+<td>Path to GM files:</td>
+<td><input type="text" style="width:300px" name="gmpath" value="/home/my/site/cgi-bin/greymatter/" /></td>
+</tr>
+<tr>
+<td>Path to GM entries:</td>
+<td><input type="text" style="width:300px" name="archivespath" value="/home/my/site/cgi-bin/greymatter/archives/" /></td>
+</tr>
+<tr>
+<td colspan="2"><br />This importer will search for files 00000001.cgi to 000-whatever.cgi,<br />so you need to enter the number of the last GM post here.<br />(if you don't know that number, just log into your FTP and look it out<br />in the entries' folder)</td>
+</tr>
+<tr>
+<td>Last entry's number:</td>
+<td><input type="text" name="lastentry" value="00000001" /></td>
+</tr>
+</table>
+</p>
+<p>When you're ready, click OK to start importing: <input type="submit" name="submit" value="OK" class="search" /></p>
+</form>
+<p>&nbsp</p>
+<?php
+ $this->footer();
+ }
+
+
+
+ function gm2autobr($string) { // transforms GM's |*| into b2's <br />\n
+ $string = str_replace("|*|","<br />\n",$string);
+ return($string);
+ }
+
+ function import() {
+ global $wpdb;
+
+ $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
+ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
+ $wpvar = $wpvarstoreset[$i];
+ if (!isset($$wpvar)) {
+ if (empty($_POST["$wpvar"])) {
+ if (empty($_GET["$wpvar"])) {
+ $$wpvar = '';
+ } else {
+ $$wpvar = $_GET["$wpvar"];
+ }
+ } else {
+ $$wpvar = $_POST["$wpvar"];
+ }
+ }
+ }
+
+ if (!chdir($archivespath))
+ die("Wrong path, $archivespath\ndoesn't exist\non the server");
+
+ if (!chdir($gmpath))
+ die("Wrong path, $gmpath\ndoesn't exist\non the server");
+
+ $this->header();
+?>
+<p>The importer is running...</p>
+<ul>
+<li>importing users... <ul><?php
+
+ chdir($gmpath);
+ $userbase = file("gm-authors.cgi");
+
+ foreach($userbase as $user) {
+ $userdata=explode("|", $user);
+
+ $user_ip="127.0.0.1";
+ $user_domain="localhost";
+ $user_browser="server";
+
+ $s=$userdata[4];
+ $user_joindate=substr($s,6,4)."-".substr($s,0,2)."-".substr($s,3,2)." 00:00:00";
+
+ $user_login=$wpdb->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) {
+ echo "<li>user <i>$user_login</i>... <b>Already exists</b></li>";
+ $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;
+
+ echo "<li>user <i>$user_login</i>... <b>Done</b></li>";
+
+ }
+
+?></ul><b>Done</b></li>
+<li>importing posts, comments, and karma...<br /><ul><?php
+
+ chdir($archivespath);
+
+ for($i = 0; $i <= $lastentry; $i = $i + 1) {
+
+ $entryfile = "";
+
+ if ($i<10000000) {
+ $entryfile .= "0";
+ if ($i<1000000) {
+ $entryfile .= "0";
+ if ($i<100000) {
+ $entryfile .= "0";
+ if ($i<10000) {
+ $entryfile .= "0";
+ if ($i<1000) {
+ $entryfile .= "0";
+ if ($i<100) {
+ $entryfile .= "0";
+ if ($i<10) {
+ $entryfile .= "0";
+ }}}}}}}
+
+ $entryfile .= "$i";
+
+ if (is_file($entryfile.".cgi")) {
+
+ $entry=file($entryfile.".cgi");
+ echo "<li>entry # $entryfile ";
+ $postinfo=explode("|",$entry[0]);
+ $postmaincontent=$this->gm2autobr($entry[2]);
+ $postmorecontent=$this->gm2autobr($entry[3]);
+
+ $post_author=trim($wpdb->escape($postinfo[1]));
+
+ $post_title=$this->gm2autobr($postinfo[2]);
+ echo " : $post_title : by $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 .= "<!--more--><br /><br />".$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 ' (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 ": registered deleted user <i>$user_login</i> at level 0 ";
+ }
+
+ 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);
+ }
+
+ $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 ": imported $numAddedComments comment";
+ if ($numAddedComments != 1)
+ echo "s";
+ }
+ $preExisting = $numComments - numAddedComments;
+ if ($preExisting > 0)
+ echo " (ignored $preExisting pre-existing comments)";
+ }
+ echo "... <b>Done</b></li>";
+ }
+ }
+ ?>
+</ul><b>Done</b></li></ul>
+<p>&nbsp;</p>
+<p>Completed Greymatter import !</p>
+<?php
+ $this->footer();
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1:
+ $this->import();
+ break;
+ }
+ }
+
+ function GM_Import() {
+ // Nothing.
+ }
+}
+
+$gm_import = new GM_Import();
+
+register_importer('greymatter', 'Greymatter', __('Import posts and comments from your Greymatter blog'), array ($gm_import, 'dispatch'));
+?>
diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php
new file mode 100644
index 0000000..44b92a5
--- /dev/null
+++ b/wp-admin/import/livejournal.php
@@ -0,0 +1,168 @@
+<?php
+
+class LJ_Import {
+
+ var $file;
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import LiveJournal').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function unhtmlentities($string) { // From php.net for < 4.3 compat
+ $trans_tbl = get_html_translation_table(HTML_ENTITIES);
+ $trans_tbl = array_flip($trans_tbl);
+ return strtr($string, $trans_tbl);
+ }
+
+ function greet() {
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from LiveJournal XML export file into your blog. Pick a LiveJournal file to upload and click Import.').'</p>';
+ wp_import_upload_form("admin.php?import=livejournal&amp;step=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('|<entry>(.*?)</entry>|is', $importdata, $posts);
+ $posts = $posts[1];
+ unset($importdata);
+ echo '<ol>';
+ foreach ($posts as $post) {
+ preg_match('|<subject>(.*?)</subject>|is', $post, $post_title);
+ $post_title = $wpdb->escape(trim($post_title[1]));
+ if ( empty($post_title) ) {
+ preg_match('|<itemid>(.*?)</itemid>|is', $post, $post_title);
+ $post_title = $wpdb->escape(trim($post_title[1]));
+ }
+
+ preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
+ $post_date = strtotime($post_date[1]);
+ $post_date = gmdate('Y-m-d H:i:s', $post_date);
+
+ preg_match('|<event>(.*?)</event>|is', $post, $post_content);
+ $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
+ $post_content = $this->unhtmlentities($post_content);
+
+ // Clean up content
+ $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+ $post_content = str_replace('<br>', '<br />', $post_content);
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
+ $post_content = $wpdb->escape($post_content);
+
+ $post_author = $current_user->ID;
+ $post_status = 'publish';
+
+ echo '<li>';
+ if ($post_id = post_exists($post_title, $post_content, $post_date)) {
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
+ } else {
+ printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
+ $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
+ $post_id = wp_insert_post($postdata);
+ if (!$post_id) {
+ _e("Couldn't get post ID");
+ echo '</li>';
+ break;
+ }
+ }
+
+ preg_match_all('|<comment>(.*?)</comment>|is', $post, $comments);
+ $comments = $comments[1];
+
+ if ( $comments ) {
+ $comment_post_ID = $post_id;
+ $num_comments = 0;
+ foreach ($comments as $comment) {
+ preg_match('|<event>(.*?)</event>|is', $comment, $comment_content);
+ $comment_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($comment_content[1]));
+ $comment_content = $this->unhtmlentities($comment_content);
+
+ // Clean up content
+ $comment_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
+ $comment_content = str_replace('<br>', '<br />', $comment_content);
+ $comment_content = str_replace('<hr>', '<hr />', $comment_content);
+ $comment_content = $wpdb->escape($comment_content);
+
+ preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
+ $comment_date = trim($comment_date[1]);
+ $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
+
+ preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
+ $comment_author = $wpdb->escape(trim($comment_author[1]));
+
+ preg_match('|<email>(.*?)</email>|is', $comment, $comment_author_email);
+ $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
+
+ $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(__('(%s comments)'), $num_comments);
+ }
+ echo '</li>';
+ }
+ echo '</ol>';
+ }
+
+ function import() {
+ $file = wp_import_handle_upload();
+ if ( isset($file['error']) ) {
+ echo $file['error'];
+ return;
+ }
+
+ $this->file = $file['file'];
+ $this->import_posts();
+ wp_import_cleanup($file['id']);
+
+ echo '<h3>';
+ printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
+ echo '</h3>';
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ $this->header();
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import();
+ break;
+ }
+
+ $this->footer();
+ }
+
+ function LJ_Import() {
+ // Nothing.
+ }
+}
+
+$livejournal_import = new LJ_Import();
+
+register_importer('livejournal', 'LiveJournal', __('Import posts from LiveJournal'), array ($livejournal_import, 'dispatch'));
+?>
diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php
new file mode 100644
index 0000000..59259ea
--- /dev/null
+++ b/wp-admin/import/mt.php
@@ -0,0 +1,407 @@
+<?php
+
+class MT_Import {
+
+ var $posts = array ();
+ var $file;
+ var $id;
+ var $mtnames = array ();
+ var $newauthornames = array ();
+ var $j = -1;
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Movable Type and Typepad').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ $this->header();
+?>
+<p><?php _e('Howdy! We&#8217;re about to begin the process to import all of your Movable Type entries into WordPress. To begin, select a file to upload and click Import.'); ?></p>
+<?php wp_import_upload_form( add_query_arg('step', 1) ); ?>
+ <p><?php _e('The importer is smart enough not to import duplicates, so you can run this multiple times without worry if&#8212;for whatever reason&#8212;it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
+<?php
+ $this->footer();
+ }
+
+ function users_form($n) {
+ global $wpdb, $testing;
+ $users = get_users_of_blog($wpdb->blogid);
+?><select name="userselect[<?php echo $n; ?>]">
+ <option value="#NONE#">- Select -</option>
+ <?php
+
+
+ foreach ($users as $user) {
+ echo '<option value="'.$user->user_login.'">'.$user->user_login.'</option>';
+ }
+?>
+ </select>
+ <?php
+
+
+ }
+
+ //function to check the authorname and do the mapping
+ function checkauthor($author) {
+ global $wpdb;
+ //mtnames is an array with the names in the mt import file
+ $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_entries() {
+ set_magic_quotes_runtime(0);
+ $importdata = file($this->file); // Read the file into an array
+ $importdata = implode('', $importdata); // squish it
+ $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
+ $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
+ $this->posts = explode("--MT-ENTRY--", $importdata);
+ }
+
+ function get_mt_authors() {
+ $temp = array ();
+ $i = -1;
+ foreach ($this->posts as $post) {
+ if ('' != trim($post)) {
+ ++ $i;
+ preg_match("|AUTHOR:(.*)|", $post, $thematch);
+ $thematch = trim($thematch[1]);
+ array_push($temp, "$thematch"); //store the extracted author names in a temporary array
+ }
+ }
+
+ //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");
+ }
+
+ return $authors;
+ }
+
+ function get_authors_from_post() {
+ $formnames = array ();
+ $selectnames = array ();
+
+ 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() {
+?>
+<div class="wrap">
+<h2><?php _e('Assign Authors'); ?></h2>
+<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.'); ?></p>
+<p><?php _e('Below, you can see the names of the authors of the MovableType posts in <i>italics</i>. 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.'); ?></p>
+<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p>
+ <?php
+
+
+ $authors = $this->get_mt_authors();
+ echo '<ol id="authors">';
+ echo '<form action="?import=mt&amp;step=2&amp;id=' . $this->id . '" method="post">';
+ $j = -1;
+ foreach ($authors as $author) {
+ ++ $j;
+ echo '<li><i>'.$author.'</i><br />'.'<input type="text" value="'.$author.'" name="'.'user[]'.'" maxlength="30">';
+ $this->users_form($j);
+ echo '</li>';
+ }
+
+ echo '<input type="submit" value="Submit">'.'<br/>';
+ echo '</form>';
+ echo '</ol></div>';
+
+ }
+
+ function select_authors() {
+ $file = wp_import_handle_upload();
+ if ( isset($file['error']) ) {
+ echo $file['error'];
+ return;
+ }
+ $this->file = $file['file'];
+ $this->id = $file['id'];
+
+ $this->get_entries();
+ $this->mt_authors_form();
+ }
+
+ function process_posts() {
+ global $wpdb;
+ $i = -1;
+ echo "<div class='wrap'><ol>";
+ foreach ($this->posts as $post) {
+ if ('' != trim($post)) {
+ ++ $i;
+ unset ($post_categories);
+
+ // Take the pings out first
+ preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
+ $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post);
+
+ // Then take the comments out
+ preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
+ $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
+
+ // We ignore the keywords
+ $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
+
+ // We want the excerpt
+ preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
+ $excerpt = $wpdb->escape(trim($excerpt[1]));
+ $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post);
+
+ // We're going to put extended body into main body with a more tag
+ preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended);
+ $extended = trim($extended[1]);
+ if ('' != $extended)
+ $extended = "\n<!--more-->\n$extended";
+ $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post);
+
+ // Now for the main body
+ preg_match("|-----\nBODY:(.*)|s", $post, $body);
+ $body = trim($body[1]);
+ $post_content = $wpdb->escape($body.$extended);
+ $post = preg_replace("|(-----\nBODY:.*)|s", '', $post);
+
+ // Grab the metadata from what's left
+ $metadata = explode("\n", $post);
+ foreach ($metadata as $line) {
+ preg_match("/^(.*?):(.*)/", $line, $token);
+ $key = trim($token[1]);
+ $value = trim($token[2]);
+ // Now we decide what it is and what to do with it
+ switch ($key) {
+ case '' :
+ break;
+ case 'AUTHOR' :
+ $post_author = $value;
+ break;
+ case 'TITLE' :
+ $post_title = $wpdb->escape($value);
+ break;
+ case 'STATUS' :
+ // "publish" and "draft" enumeration items match up; no change required
+ $post_status = $value;
+ if (empty ($post_status))
+ $post_status = 'publish';
+ break;
+ case 'ALLOW COMMENTS' :
+ $post_allow_comments = $value;
+ if ($post_allow_comments == 1) {
+ $comment_status = 'open';
+ } else {
+ $comment_status = 'closed';
+ }
+ break;
+ case 'CONVERT BREAKS' :
+ $post_convert_breaks = $value;
+ break;
+ case 'ALLOW PINGS' :
+ $ping_status = trim($meta[2][0]);
+ if ($ping_status == 1) {
+ $ping_status = 'open';
+ } else {
+ $ping_status = 'closed';
+ }
+ break;
+ case 'PRIMARY CATEGORY' :
+ if (! empty ($value) )
+ $post_categories[] = $wpdb->escape($value);
+ break;
+ case 'CATEGORY' :
+ if (! empty ($value) )
+ $post_categories[] = $wpdb->escape($value);
+ break;
+ case 'DATE' :
+ $post_modified = strtotime($value);
+ $post_modified = date('Y-m-d H:i:s', $post_modified);
+ $post_modified_gmt = get_gmt_from_date("$post_modified");
+ $post_date = $post_modified;
+ $post_date_gmt = $post_modified_gmt;
+ break;
+ default :
+ // echo "\n$key: $value";
+ break;
+ } // end switch
+ } // End foreach
+
+ // Let's check to see if it's in already
+ if ($post_id = post_exists($post_title, '', $post_date)) {
+ echo '<li>';
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
+ } else {
+ echo '<li>';
+ printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
+
+ $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_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
+ $post_id = wp_insert_post($postdata);
+ // Add categories.
+ if (0 != count($post_categories)) {
+ wp_create_categories($post_categories, $post_id);
+ }
+ }
+
+ $comment_post_ID = $post_id;
+ $comment_approved = 1;
+
+ // Now for comments
+ $comments = explode("-----\nCOMMENT:", $comments[0]);
+ $num_comments = 0;
+ foreach ($comments as $comment) {
+ if ('' != trim($comment)) {
+ // Author
+ preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
+ $comment_author = $wpdb->escape(trim($comment_author[1]));
+ $comment = preg_replace('|(\n?AUTHOR:.*)|', '', $comment);
+ preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
+ $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
+ $comment = preg_replace('|(\n?EMAIL:.*)|', '', $comment);
+
+ preg_match("|IP:(.*)|", $comment, $comment_author_IP);
+ $comment_author_IP = trim($comment_author_IP[1]);
+ $comment = preg_replace('|(\n?IP:.*)|', '', $comment);
+
+ preg_match("|URL:(.*)|", $comment, $comment_author_url);
+ $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
+ $comment = preg_replace('|(\n?URL:.*)|', '', $comment);
+
+ preg_match("|DATE:(.*)|", $comment, $comment_date);
+ $comment_date = trim($comment_date[1]);
+ $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
+ $comment = preg_replace('|(\n?DATE:.*)|', '', $comment);
+
+ $comment_content = $wpdb->escape(trim($comment));
+ $comment_content = str_replace('-----', '', $comment_content);
+ // Check if it's already there
+ 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);
+ $num_comments++;
+ }
+ }
+ }
+ if ( $num_comments )
+ printf(__(' (%s comments)'), $num_comments);
+
+ // Finally the pings
+ // fix the double newline on the first one
+ $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
+ $pings = explode("-----\nPING:", $pings[0]);
+ $num_pings = 0;
+ foreach ($pings as $ping) {
+ if ('' != trim($ping)) {
+ // 'Author'
+ preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
+ $comment_author = $wpdb->escape(trim($comment_author[1]));
+ $ping = preg_replace('|(\n?BLOG NAME:.*)|', '', $ping);
+
+ preg_match("|IP:(.*)|", $ping, $comment_author_IP);
+ $comment_author_IP = trim($comment_author_IP[1]);
+ $ping = preg_replace('|(\n?IP:.*)|', '', $ping);
+
+ preg_match("|URL:(.*)|", $ping, $comment_author_url);
+ $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
+ $ping = preg_replace('|(\n?URL:.*)|', '', $ping);
+
+ preg_match("|DATE:(.*)|", $ping, $comment_date);
+ $comment_date = trim($comment_date[1]);
+ $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
+ $ping = preg_replace('|(\n?DATE:.*)|', '', $ping);
+
+ preg_match("|TITLE:(.*)|", $ping, $ping_title);
+ $ping_title = $wpdb->escape(trim($ping_title[1]));
+ $ping = preg_replace('|(\n?TITLE:.*)|', '', $ping);
+
+ $comment_content = $wpdb->escape(trim($ping));
+ $comment_content = str_replace('-----', '', $comment_content);
+
+ $comment_content = "<strong>$ping_title</strong>\n\n$comment_content";
+
+ $comment_type = 'trackback';
+
+ // Check if it's already there
+ 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_type', 'comment_approved');
+ $commentdata = wp_filter_comment($commentdata);
+ wp_insert_comment($commentdata);
+ $num_pings++;
+ }
+ }
+ }
+ if ( $num_pings )
+ printf(__(' (%s pings)'), $num_pings);
+
+ echo "</li>";
+ }
+ }
+
+ echo '</ol>';
+
+ wp_import_cleanup($this->id);
+
+ echo '<h3>'.sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')).'</h3></div>';
+ }
+
+ function import() {
+ $this->id = (int) $_GET['id'];
+
+ $this->file = get_attached_file($this->id);
+ $this->get_authors_from_post();
+ $this->get_entries();
+ $this->process_posts();
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->select_authors();
+ break;
+ case 2:
+ $this->import();
+ break;
+ }
+ }
+
+ function MT_Import() {
+ // Nothing.
+ }
+}
+
+$mt_import = new MT_Import();
+
+register_importer('mt', 'Movable Type and Typepad', __('Imports <strong>posts and comments</strong> from your Movable Type or Typepad blog'), array ($mt_import, 'dispatch'));
+?>
diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php
new file mode 100644
index 0000000..69972f3
--- /dev/null
+++ b/wp-admin/import/rss.php
@@ -0,0 +1,171 @@
+<?php
+
+class RSS_Import {
+
+ var $posts = array ();
+ var $file;
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import RSS').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function unhtmlentities($string) { // From php.net for < 4.3 compat
+ $trans_tbl = get_html_translation_table(HTML_ENTITIES);
+ $trans_tbl = array_flip($trans_tbl);
+ return strtr($string, $trans_tbl);
+ }
+
+ function greet() {
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from any RSS 2.0 file into your blog. 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.').'</p>';
+ wp_import_upload_form("admin.php?import=rss&amp;step=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('|<item>(.*?)</item>|is', $importdata, $this->posts);
+ $this->posts = $this->posts[1];
+ $index = 0;
+ foreach ($this->posts as $post) {
+ preg_match('|<title>(.*?)</title>|is', $post, $post_title);
+ $post_title = $wpdb->escape(trim($post_title[1]));
+
+ preg_match('|<pubdate>(.*?)</pubdate>|is', $post, $post_date);
+
+ if ($post_date) {
+ $post_date = strtotime($post_date[1]);
+ } else {
+ // if we don't already have something from pubDate
+ preg_match('|<dc:date>(.*?)</dc:date>|is', $post, $post_date);
+ $post_date = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $post_date[1]);
+ $post_date = str_replace('T', ' ', $post_date);
+ $post_date = strtotime($post_date);
+ }
+
+ $post_date = gmdate('Y-m-d H:i:s', $post_date);
+
+ preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
+ $categories = $categories[1];
+
+ if (!$categories) {
+ preg_match_all('|<dc:subject>(.*?)</dc:subject>|is', $post, $categories);
+ $categories = $categories[1];
+ }
+
+ $cat_index = 0;
+ foreach ($categories as $category) {
+ $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
+ $cat_index++;
+ }
+
+ preg_match('|<guid.+?>(.*?)</guid>|is', $post, $guid);
+ if ($guid)
+ $guid = $wpdb->escape(trim($guid[1]));
+ else
+ $guid = '';
+
+ preg_match('|<content:encoded>(.*?)</content:encoded>|is', $post, $post_content);
+ $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $wpdb->escape(trim($post_content[1])));
+
+ if (!$post_content) {
+ // This is for feeds that put content in description
+ preg_match('|<description>(.*?)</description>|is', $post, $post_content);
+ $post_content = $wpdb->escape($this->unhtmlentities(trim($post_content[1])));
+ }
+
+ // Clean up content
+ $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+ $post_content = str_replace('<br>', '<br />', $post_content);
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
+
+ $post_author = 1;
+ $post_status = 'publish';
+ $this->posts[$index] = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status', 'guid', 'categories');
+ $index++;
+ }
+ }
+
+ function import_posts() {
+ echo '<ol>';
+
+ foreach ($this->posts as $post) {
+ echo "<li>".__('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 (!$post_id) {
+ _e("Couldn't get post ID");
+ return;
+ }
+
+ if (0 != count($categories))
+ wp_create_categories($categories, $post_id);
+ _e('Done !');
+ }
+ echo '</li>';
+ }
+
+ echo '</ol>';
+
+ }
+
+ function import() {
+ $file = wp_import_handle_upload();
+ if ( isset($file['error']) ) {
+ echo $file['error'];
+ return;
+ }
+
+ $this->file = $file['file'];
+ $this->get_posts();
+ $this->import_posts();
+ wp_import_cleanup($file['id']);
+
+ echo '<h3>';
+ printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
+ echo '</h3>';
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ $this->header();
+
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import();
+ 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/textpattern.php b/wp-admin/import/textpattern.php
new file mode 100644
index 0000000..17cae87
--- /dev/null
+++ b/wp-admin/import/textpattern.php
@@ -0,0 +1,663 @@
+<?php
+/**
+ Add These Functions to make our lives easier
+**/
+if(!function_exists('get_catbynicename'))
+{
+ function get_catbynicename($category_nicename)
+ {
+ global $wpdb;
+
+ $cat_id -= 0; // force numeric
+ $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
+
+ return $name;
+ }
+}
+
+if(!function_exists('get_comment_count'))
+{
+ function get_comment_count($post_ID)
+ {
+ global $wpdb;
+ return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID);
+ }
+}
+
+if(!function_exists('link_exists'))
+{
+ function link_exists($linkname)
+ {
+ global $wpdb;
+ return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"');
+ }
+}
+
+/**
+ The Main Importer Class
+**/
+class Textpattern_Import {
+
+ function header()
+ {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Textpattern').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
+ }
+
+ function footer()
+ {
+ echo '</div>';
+ }
+
+ function greet()
+ {
+ echo '<p>'.__('Howdy! This importer allows you to extract posts from any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern. Mileage may vary.').'</p>';
+ echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>';
+ echo '<form action="admin.php?import=textpattern&amp;step=1" method="post">';
+ $this->db_form();
+ echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />';
+ echo '</form>';
+ }
+
+ 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 '<p>'.__('Importing Categories...').'<br /><br /></p>';
+ 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 '<p>'.sprintf(__('Done! <strong>%1$s</strong> categories imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Users...').'<br /><br /></p>';
+ 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_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] );
+ update_usermeta( $ret_id, 'rich_editing', 'false');
+ }// End foreach($users as $user)
+
+ // Store id translation array for future use
+ add_option('txpid2wpid',$txpid2wpid);
+
+
+ echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Posts...').'<br /><br /></p>';
+ 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)
+ );
+ }
+ 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)
+ );
+ }
+ $txpposts2wpposts[$ID] = $ret_id;
+
+ // Make Post-to-Category associations
+ $cats = array();
+ if($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; }
+ if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
+
+ if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); }
+ }
+ }
+ // Store ID translation for later use
+ add_option('txpposts2wpposts',$txpposts2wpposts);
+
+ echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
+ return true;
+ }
+
+ function comments2wp($comments='')
+ {
+ // General Housekeeping
+ global $wpdb;
+ $count = 0;
+ $txpcm2wpcm = array();
+ $postarr = get_option('txpposts2wpposts');
+
+ // Magic Mojo
+ if(is_array($comments))
+ {
+ echo '<p>'.__('Importing Comments...').'<br /><br /></p>';
+ 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);
+
+ if($cinfo = comment_exists($name, $posted))
+ {
+ // Update comments
+ $ret_id = wp_update_comment(array(
+ 'comment_ID' => $cinfo,
+ 'comment_post_ID' => $comment_post_ID,
+ 'comment_author' => $name,
+ 'comment_author_email' => $email,
+ 'comment_author_url' => $web,
+ 'comment_date' => $posted,
+ 'comment_content' => $message,
+ 'comment_approved' => $comment_approved)
+ );
+ }
+ else
+ {
+ // Insert comments
+ $ret_id = wp_insert_comment(array(
+ 'comment_post_ID' => $comment_post_ID,
+ 'comment_author' => $name,
+ 'comment_author_email' => $email,
+ 'comment_author_url' => $web,
+ 'comment_author_IP' => $ip,
+ 'comment_date' => $posted,
+ 'comment_content' => $message,
+ 'comment_approved' => $comment_approved)
+ );
+ }
+ $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 '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
+ 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 '<p>'.__('Importing Links...').'<br /><br /></p>';
+ 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 '<p>';
+ printf(__('Done! <strong>%s</strong> Links imported'), $count);
+ echo '<br /><br /></p>';
+ 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 '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
+ echo '</form>';
+
+ }
+
+ function import_users()
+ {
+ // User Import
+ $users = $this->get_txp_users();
+ $this->users2wp($users);
+
+ echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
+ echo '</form>';
+ }
+
+ function import_posts()
+ {
+ // Post Import
+ $posts = $this->get_txp_posts();
+ $this->posts2wp($posts);
+
+ echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
+ echo '</form>';
+ }
+
+ function import_comments()
+ {
+ // Comment Import
+ $comments = $this->get_txp_comments();
+ $this->comments2wp($comments);
+
+ echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
+ echo '</form>';
+ }
+
+ function import_links()
+ {
+ //Link Import
+ $links = $this->get_txp_links();
+ $this->links2wp($links);
+ add_option('txp_links', $links);
+
+ echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
+ printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
+ echo '</form>';
+ }
+
+ 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');
+ $this->tips();
+ }
+
+ function tips()
+ {
+ echo '<p>'.__('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.').'</p>';
+ echo '<h3>'.__('Users').'</h3>';
+ echo '<p>'.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. <strong>Every user has the same username, but their passwords are reset to password123.</strong> So <a href="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
+ echo '<h3>'.__('Preserving Authors').'</h3>';
+ echo '<p>'.__('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.').'</p>';
+ echo '<h3>'.__('Textile').'</h3>';
+ echo '<p>'.__('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 <a href="http://www.huddledmasses.org/2004/04/19/wordpress-plugin-textile-20/">Textile for WordPress</a>. Trust me... You\'ll want it.').'</p>';
+ echo '<h3>'.__('WordPress Resources').'</h3>';
+ echo '<p>'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'</p>';
+ echo '<ul>';
+ echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
+ echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums').'</li>';
+ echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
+ echo '</ul>';
+ echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
+ }
+
+ function db_form()
+ {
+ echo '<ul>';
+ printf('<li><label for="dbuser">%s</label> <input type="text" name="dbuser" /></li>', __('Textpattern Database User:'));
+ printf('<li><label for="dbpass">%s</label> <input type="password" name="dbpass" /></li>', __('Textpattern Database Password:'));
+ printf('<li><label for="dbname">%s</label> <input type="text" name="dbname" /></li>', __('Textpattern Database Name:'));
+ printf('<li><label for="dbhost">%s</label> <input type="text" name="dbhost" value="localhost" /></li>', __('Textpattern Database Host:'));
+ printf('<li><label for="dbprefix">%s</label> <input type="text" name="dbprefix" /></li>', __('Textpattern Table prefix (if any):'));
+ echo '</ul>';
+ }
+
+ function dispatch()
+ {
+
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+ $this->header();
+
+ if ( $step > 0 )
+ {
+ if($_POST['dbuser'])
+ {
+ if(get_option('txpuser'))
+ delete_option('txpuser');
+ add_option('txpuser',$_POST['dbuser']);
+ }
+ if($_POST['dbpass'])
+ {
+ if(get_option('txppass'))
+ delete_option('txppass');
+ add_option('txppass',$_POST['dbpass']);
+ }
+
+ if($_POST['dbname'])
+ {
+ if(get_option('txpname'))
+ delete_option('txpname');
+ add_option('txpname',$_POST['dbname']);
+ }
+ if($_POST['dbhost'])
+ {
+ if(get_option('txphost'))
+ delete_option('txphost');
+ add_option('txphost',$_POST['dbhost']);
+ }
+ if($_POST['dbprefix'])
+ {
+ if(get_option('tpre'))
+ delete_option('tpre');
+ add_option('tpre',$_POST['dbprefix']);
+ }
+
+
+ }
+
+ switch ($step)
+ {
+ default:
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import_categories();
+ break;
+ case 2 :
+ $this->import_users();
+ break;
+ case 3 :
+ $this->import_posts();
+ 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 posts from a Textpattern Blog'), array ($txp_import, 'dispatch'));
+?>
diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php
new file mode 100644
index 0000000..997628b
--- /dev/null
+++ b/wp-admin/import/wordpress.php
@@ -0,0 +1,288 @@
+<?php
+
+class WP_Import {
+
+ var $posts = array ();
+ var $file;
+ var $id;
+ var $mtnames = array ();
+ var $newauthornames = array ();
+ var $j = -1;
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import WordPress').'</h2>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function unhtmlentities($string) { // From php.net for < 4.3 compat
+ $trans_tbl = get_html_translation_table(HTML_ENTITIES);
+ $trans_tbl = array_flip($trans_tbl);
+ return strtr($string, $trans_tbl);
+ }
+
+ function greet() {
+ echo '<p>'.__('Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts and comments into this blog.').'</p>';
+ wp_import_upload_form("admin.php?import=wordpress&amp;step=1");
+ }
+
+ function get_tag( $string, $tag ) {
+ preg_match("|<$tag.*?>(.*?)</$tag>|is", $string, $return);
+ $return = addslashes( trim( $return[1] ) );
+ return $return;
+ }
+
+ function users_form($n) {
+ global $wpdb, $testing;
+ $users = get_users_of_blog($wpdb->blogid);
+?><select name="userselect[<?php echo $n; ?>]">
+ <option value="#NONE#">- Select -</option>
+ <?php
+ foreach ($users as $user) {
+ echo '<option value="'.$user->user_login.'">'.$user->user_login.'</option>';
+ }
+?>
+ </select>
+ <?php
+ }
+
+ //function to check the authorname and do the mapping
+ function checkauthor($author) {
+ global $wpdb;
+ //mtnames is an array with the names in the mt import file
+ $pass = 'changeme';
+ $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_entries() {
+ set_magic_quotes_runtime(0);
+ $importdata = file($this->file); // Read the file into an array
+ $importdata = implode('', $importdata); // squish it
+ $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
+ preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts);
+ $this->posts = $this->posts[1];
+ }
+
+ function get_wp_authors() {
+ $temp = array ();
+ $i = -1;
+ foreach ($this->posts as $post) {
+ if ('' != trim($post)) {
+ ++ $i;
+ $author = $this->get_tag( $post, 'dc:creator' );
+ array_push($temp, "$author"); //store the extracted author names in a temporary array
+ }
+ }
+
+ // 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");
+ }
+
+ return $authors;
+ }
+
+ function get_authors_from_post() {
+ $formnames = array ();
+ $selectnames = array ();
+
+ 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 wp_authors_form() {
+?>
+<h2><?php _e('Assign Authors'); ?></h2>
+<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.'); ?></p>
+<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p>
+ <?php
+
+
+ $authors = $this->get_wp_authors();
+ echo '<ol id="authors">';
+ echo '<form action="?import=wordpress&amp;step=2&amp;id=' . $this->id . '" method="post">';
+ $j = -1;
+ foreach ($authors as $author) {
+ ++ $j;
+ echo '<li>Current author: <strong>'.$author.'</strong><br />'.'Map to existing: ';
+ $this->users_form($j);
+ echo '</li>';
+ }
+
+ echo '<input type="submit" value="Submit">'.'<br/>';
+ echo '</form>';
+ echo '</ol>';
+
+ }
+
+ function select_authors() {
+ $file = wp_import_handle_upload();
+ if ( isset($file['error']) ) {
+ $this->header();
+ echo '<p>Sorry, there has been an error.</p>';
+ echo '<p><strong>' . $file['error'] . '</strong></p>';
+ $this->footer();
+ return;
+ }
+ $this->file = $file['file'];
+ $this->id = $file['id'];
+
+ $this->get_entries();
+ $this->wp_authors_form();
+ }
+
+ function process_posts() {
+ global $wpdb;
+ $i = -1;
+ echo '<ol>';
+ foreach ($this->posts as $post) {
+
+ // 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_parent = $this->get_tag( $post, 'wp:post_parent' );
+ $post_type = $this->get_tag( $post, 'wp:post_type' );
+ $guid = $this->get_tag( $post, 'guid' );
+ $post_author = $this->get_tag( $post, 'dc:creator' );
+
+ $post_content = $this->get_tag( $post, 'content:encoded' );
+ $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $post_content);
+ $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+ $post_content = str_replace('<br>', '<br />', $post_content);
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
+
+ preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
+ $categories = $categories[1];
+
+ $cat_index = 0;
+ foreach ($categories as $category) {
+ $categories[$cat_index] = $wpdb->escape($this->unhtmlentities($category));
+ $cat_index++;
+ }
+
+ if ($post_id = post_exists($post_title, '', $post_date)) {
+ echo '<li>';
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
+ } else {
+ echo '<li>';
+ printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
+
+ $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_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'post_type');
+ $comment_post_ID = $post_id = wp_insert_post($postdata);
+ // Add categories.
+ if (0 != count($categories)) {
+ wp_create_categories($categories, $post_id);
+ }
+ }
+
+ // Now for comments
+ preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
+ $comments = $comments[1];
+ $num_comments = 0;
+ if ( $comments) { foreach ($comments as $comment) {
+ $comment_author = $this->get_tag( $comment, 'wp:comment_author');
+ $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
+ $comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP');
+ $comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url');
+ $comment_date = $this->get_tag( $comment, 'wp:comment_date');
+ $comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt');
+ $comment_content = $this->get_tag( $comment, 'wp:comment_content');
+ $comment_approved = $this->get_tag( $comment, 'wp:comment_approved');
+ $comment_type = $this->get_tag( $comment, 'wp:comment_type');
+ $comment_parent = $this->get_tag( $comment, 'wp:comment_parent');
+
+ 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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
+ wp_insert_comment($commentdata);
+ $num_comments++;
+ }
+ } }
+ if ( $num_comments )
+ printf(__(' (%s comments)'), $num_comments);
+
+ // Now for post meta
+ preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|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' );
+ add_post_meta( $post_id, $key, $value );
+ } }
+
+ $index++;
+ }
+
+ echo '</ol>';
+
+ wp_import_cleanup($this->id);
+
+ echo '<h3>'.sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')).'</h3>';
+ }
+
+ function import() {
+ $this->id = (int) $_GET['id'];
+
+ $this->file = get_attached_file($this->id);
+ $this->get_authors_from_post();
+ $this->get_entries();
+ $this->process_posts();
+ }
+
+ function dispatch() {
+ if (empty ($_GET['step']))
+ $step = 0;
+ else
+ $step = (int) $_GET['step'];
+
+ $this->header();
+ switch ($step) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->select_authors();
+ break;
+ case 2:
+ $this->import();
+ break;
+ }
+ $this->footer();
+ }
+
+ function WP_Import() {
+ // Nothing.
+ }
+}
+
+$wp_import = new WP_Import();
+
+register_importer('wordpress', 'WordPress', __('Import posts from a WordPress export file'), array ($wp_import, 'dispatch'));
+
+?>