Removing old importers.

git-svn-id: https://develop.svn.wordpress.org/trunk@3211 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg 2005-11-25 05:01:47 +00:00
parent fa8a143c93
commit 68f2bdc166
6 changed files with 0 additions and 1433 deletions

View File

@ -1,247 +0,0 @@
<?php
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
require_once('../wp-config.php');
require_once('upgrade-functions.php');
$step = $_GET['step'];
if (!$step) $step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &#8212; b2 Conversion</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 15%;
margin-right: 15%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/wordpress.gif);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
height: 60px;
}
#logo a span {
display: none;
}
p, li {
line-height: 140%;
}
</style>
</head>
<body>
<h1 id="logo"><a href="http://wordpress.org/"><span>WordPress</span></a></h1>
<?php
switch($step) {
case 0:
?>
<p>Welcome to WordPress. Since you&#8217;re upgrading from b2 everything should be relatively
familiar to you. Here are some notes on upgrading:</p>
<ul>
<li>If you&#8217;re using an older version of b2, it's probably a good idea to upgrade
to at least .61 before making the leap to WordPress.</li>
<li>The templates are so much better, and there is so much more going on than
before it&#8217;s probably worth it to start from scratch and work back to your
design.</li>
<li>You need to transfer some of your settings from your old <code>b2config.php</code>
to <code>wp-config.php</code> file.</li>
<li>WordPress issues should be discussed in our <a href="http://wordpress.org/support/">support
forums</a>.</li>
<li><strong>Back up</strong> your database before you do anything. Yes, you.</li>
</ul>
<p>Have you looked at the <a href="../readme.html">readme</a>? If
you&#8217;re all ready, <a href="import-b2.php?step=1">let&#8217;s go</a>!</p>
<?php
break;
case 1:
?>
<h1>Step 1</h1>
<p>Okay first we&#8217;re going to set up the links database. This will allow you to host your own blogroll, complete with Weblogs.com updates.</p>
<?php
$got_links = false;
$got_cats = false;
$got_row = false;
?>
<p>Installing WP-Links.</p>
<p>Checking for tables...</p>
<?php
$result = mysql_list_tables(DB_NAME);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
if ($row[0] == $wpdb->links)
$got_links = true;
if ($row[0] == $wpdb->linkcategories)
$got_cats = true;
//print "Table: $row[0]<br />\n";
}
if (!$got_cats) {
echo "<p>Can't find table '$wpdb->linkcategories', gonna create it...</p>\n";
$sql = "CREATE TABLE $wpdb->linkcategories ( " .
" cat_id int(11) NOT NULL auto_increment, " .
" cat_name tinytext NOT NULL, ".
" auto_toggle enum ('Y','N') NOT NULL default 'N', ".
" PRIMARY KEY (cat_id) ".
") ";
$result = mysql_query($sql) or print ("Can't create the table '$wpdb->linkcategories' in the database.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Table '$wpdb->linkcategories' created OK</p>\n";
$got_cats = true;
}
} else {
echo "<p>Found table '$wpdb->linkcategories', don't need to create it...</p>\n";
$got_cats = true;
}
if (!$got_links) {
echo "<p>Can't find '$wpdb->links', gonna create it...</p>\n";
$sql = "CREATE TABLE $wpdb->links ( " .
" link_id int(11) NOT NULL auto_increment, " .
" link_url varchar(255) NOT NULL default '', " .
" link_name varchar(255) NOT NULL default '', " .
" link_image varchar(255) NOT NULL default '', " .
" link_target varchar(25) NOT NULL default '', " .
" link_category int(11) NOT NULL default 0, " .
" link_description varchar(255) NOT NULL default '', " .
" link_visible enum ('Y','N') NOT NULL default 'Y', " .
" link_owner int NOT NULL DEFAULT '1', " .
" link_rating int NOT NULL DEFAULT '0', " .
" link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', " .
" link_rel varchar(255) NOT NULL default '', " .
" link_notes MEDIUMTEXT NOT NULL default '', " .
" PRIMARY KEY (link_id) " .
") ";
$result = mysql_query($sql) or print ("Can't create the table '$wpdb->links' in the database.<br />" . $sql . "<br />" . mysql_error());
$links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://wordpress.org/', 'WordPress', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
$links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://photomatt.net/', 'Matt', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
$links = mysql_query("INSERT INTO $wpdb->links VALUES ('', 'http://zed1.com/b2/', 'Mike', '', '', 1, '', 'Y', 1, 0, '0000-00-00 00:00:00', '');");
if ($result != false) {
echo "<p>Table '$wpdb->links' created OK</p>\n";
$got_links = true;
}
} else {
echo "<p>Found table '$wpdb->links', don't need to create it...</p>\n";
echo "<p>... may need to update it though. Looking for column link_updated...</p>\n";
$query = "SELECT link_updated FROM $wpdb->links LIMIT 1";
$q = @mysql_query($query);
if ($q != false) {
if ($row = mysql_fetch_object($q)) {
echo "<p>You have column link_updated. Good!</p>\n";
}
} else {
$query = "ALTER TABLE $wpdb->links ADD COLUMN link_updated DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'";
$q = mysql_query($query) or mysql_doh("Doh, couldn't add column.", $query, mysql_error());
echo "<p>Added column link_updated...</p>\n";
}
echo "<p>Looking for column link_rel...</p>\n";
$query = "SELECT link_rel FROM $wpdb->links LIMIT 1";
$q = @mysql_query($query);
if ($q != false) {
if ($row = mysql_fetch_object($q)) {
echo "<p>You have column link_rel. Good!</p>\n";
}
} else {
$query = "ALTER TABLE $wpdb->links ADD COLUMN link_rel varchar(255) NOT NULL DEFAULT '' ";
$q = mysql_query($query) or mysql_doh("Doh, couldn't add column.", $query, mysql_error());
echo "<p>Added column link_rel...</p>\n";
}
$got_links = true;
}
if ($got_links && $got_cats) {
echo "<p>Looking for category 1...</p>\n";
$sql = "SELECT * FROM $wpdb->linkcategories WHERE cat_id=1 ";
$result = mysql_query($sql) or print ("Can't query '$wpdb->linkcategories'.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
if ($row = mysql_fetch_object($result)) {
echo "<p>You have at least 1 category. Good!</p>\n";
$got_row = true;
} else {
echo "<p>Gonna insert category 1...</p>\n";
$sql = "INSERT INTO $wpdb->linkcategories (cat_id, cat_name) VALUES (1, 'General')";
$result = mysql_query($sql) or print ("Can't query insert category.<br />" . $sql . "<br />" . mysql_error());
if ($result != false) {
echo "<p>Inserted category Ok</p>\n";
$got_row = true;
}
}
}
}
if ($got_row) {
echo "<p>All done!</p>\n";
}
?>
<p>Did you defeat the boss monster at the end? Good, then you&#8217;re ready for
<a href="import-b2.php?step=2">Step 2</a>.</p>
<?php
break;
case 2:
?>
<h1>Step 2</h1>
<p>First we&#8217;re going to add excerpt, post, and password functionality...</p>
<?php
$query = "ALTER TABLE $wpdb->posts ADD COLUMN post_excerpt text NOT NULL;";
$q = $wpdb->query($query);
// 0.71 mods
$query = "ALTER TABLE $wpdb->posts ADD post_status ENUM('publish','draft','private') NOT NULL,
ADD comment_status ENUM('open','closed') NOT NULL,
ADD ping_status ENUM('open','closed') NOT NULL,
ADD post_password varchar(20) NOT NULL;";
$q = $wpdb->query($query);
?>
<p>That went well! Now let's clean up the b2 database structure a bit...</p>
<?php
$query = "ALTER TABLE $wpdb->posts DROP INDEX ID";
$q = $wpdb->query($query);
?>
<p>One down, two to go...</p>
<p>So far so good.</p>
<?php
$query="ALTER TABLE $wpdb->posts DROP post_karma";
$q = $wpdb->query($query);
flush();
?>
<p>Almost there...</p>
<?php
$query = "ALTER TABLE $wpdb->users DROP INDEX ID";
$q = $wpdb->query($query);
upgrade_all();
?>
<p>Welcome to the family. <a href="../">Have fun</a>!</p>
<?php
break;
}
?>
</body>
</html>

View File

@ -1,315 +0,0 @@
<?php
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
require_once('../wp-config.php');
require_once('upgrade-functions.php');
$wpvarstoreset = array('action', '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"];
}
}
}
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &rsaquo; Import from GreyMatter</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 20%;
margin-right: 20%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/logo.png);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
text-decoration: none;
text-indent: -100em;
height: 60px;
}
p {
line-height: 140%;
}
#authors li {
padding:3px;
border: 1px solid #ccc;
width: 40%;
margin-bottom:2px;
}
</style>
</head><body>
<h1 id="logo"><a href="http://wordpress.org/">WordPress</a></h1>
<?php
switch ($action) {
case "step1":
function gm2autobr($string) { // transforms GM's |*| into wp's <br />\n
$string = str_replace("|*|","<br />\n",$string);
return($string);
}
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");
?>
<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);
$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);
$loginthere = $wpdb->get_var("SELECT user_login FROM $wpdb->users WHERE user_login = '$user_login'");
if ($loginthere) {
echo "<li>user <i>$user_login</i>... <b>Already exists</b></li>";
continue;
}
$query = "INSERT INTO $wpdb->users (user_login,user_pass,user_email,user_url,user_registered,user_level) VALUES ('$user_login','$pass1','$user_email','$user_url','$user_joindate','1')";
$result = $wpdb->query($query);
if ($result==false) {
die ("<strong>ERROR</strong>: couldn't register an user!");
}
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=gm2autobr($entry[2]);
$postmorecontent=gm2autobr($entry[3]);
$post_author=trim($wpdb->escape($postinfo[1]));
// we'll check the author is registered, or if it's a deleted author
$sql = "SELECT * FROM $wpdb->users WHERE user_login = '$post_author'";
$result = $wpdb->query($sql);
if (! $result) { // if deleted from GM, we register the author as a level 0 user in wp
$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);
$query = "INSERT INTO $wpdb->users (user_login,user_pass,user_email,user_url,user_registered,user_level) VALUES ('$user_login','$pass1','$user_email','$user_url','$user_joindate','0')";
$result = $wpdb->query($query);
if ($result==false) {
die ("<strong>ERROR</strong>: couldn't register an user!");
}
echo ": registered deleted user <i>$user_login</i> at level 0 ";
}
$sql = "SELECT ID FROM $wpdb->users WHERE user_login = '$post_author'";
$post_author_ID = $wpdb->get_var($sql);
$post_title=gm2autobr($postinfo[2]);
$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];
$query = "INSERT INTO $wpdb->posts (post_author,post_date,post_content,post_title) VALUES ('$post_author_ID','$post_date','$post_content','$post_title')";
$result = $wpdb->query($query);
if (!$result)
die ("Error in posting...");
$query = "SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1";
$post_ID = $wpdb->get_var($query);
// Grab a default category.
$post_category = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories LIMIT 1");
// Update the post2cat table.
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
if (!$exists) {
$wpdb->query("
INSERT INTO $wpdb->post2cat
(post_id, category_id)
VALUES
($post_ID, $post_category)
");
}
$c=count($entry);
if ($c>4) {
for ($j=4;$j<$c;$j++) {
$entry[$j]=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]);
$sql3 = "INSERT INTO $wpdb->comments (comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content) VALUES ('$comment_post_ID','$comment_author','$comment_author_email','$comment_author_url','$comment_author_IP','$comment_date','$comment_content')";
$result3 = $wpdb->query($sql3);
if (!$result3)
die ("There is an error with the database, it can't store your comment..");
}
$comments=$c-4;
echo ": imported $comments comment";
if ($comments>1)
echo "s";
}
echo "... <b>Done</b></li>";
}
}
upgrade_all();
?>
</ul><b>Done</b></li></ul>
<p>&nbsp;</p>
<p>Completed GM 2 WordPress import !</p>
<p>Now you can go and <a href="wp-login.php">log in</a>, have fun !</p>
<?php
break;
default:
?>
<p>This is a basic GreyMatter to WordPress import script.</p>
<p>What it does:</p>
<ul>
<li>parses gm-authors.cgi to import 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); if authors are found not to be in gm-authors.cgi, imports them at level 0</li>
</ul>
<p>What it does not:</p>
<ul>
<li>parse gm-counter.cgi (what's the use of that file ?), 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. you'll start with the basic template wp.php</li>
<li>doesn't keep entries on top</li>
</ul>
<h3>First step: Install WordPress</h3>
<p>Install the WordPress blog as explained in the <a href="../readme.html" target="_blank">ReadMe</a>, then immediately come back here.</p>
<form name="stepOne" method="get">
<input type="hidden" name="action" value="step1" />
<h3>Second step: Provide GreyMatter details</h3>
<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>
</table>
<p>This importer will search for files 00000001.cgi to 000-whatever.cgi, so you need to enter the number of the last GM post here. (If you don't know that number, just log into your FTP and look it up in the entries' folder)</p>
<table>
<tr>
<td>Last entry's number:</td>
<td><input type="text" name="lastentry" value="00000001" /></td>
</tr>
</table>
<p>When you're ready, click OK to start importing: <input type="submit" name="submit" value="OK" class="search" /></p>
</form>
</body>
</html>
<?php
break;
}
?>

View File

@ -1,124 +0,0 @@
<?php
define('XMLFILE', '');
// Example:
// define('XMLFILE', '/home/example/public_html/rss.xml');
// or if it's in the same directory as import-rss.php
// define('XMLFILE', 'rss.xml');
$post_author = 1; // Author to import posts as author ID
$timezone_offset = 0; // GMT offset of posts your importing
$add_hours = intval($timezone_offset);
$add_minutes = intval(60 * ($timezone_offset - $add_hours));
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
require_once('../wp-config.php');
$step = $_GET['step'];
if (!$step) $step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &rsaquo; Import from RSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 20%;
margin-right: 20%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/logo.png);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
text-decoration: none;
text-indent: -100em;
height: 60px;
}
p {
line-height: 140%;
}
</style>
</head><body>
<h1 id="logo"><a href="http://wordpress.org/">WordPress</a></h1>
<?php
switch($step) {
case 0:
?>
<p>Howdy! This importer allows you to extract posts from a LiveJournal XML export file. To get started you must edit the following line in this file (<code>import-livejournal.php</code>) </p>
<p><code>define('XMLFILE', '');</code></p>
<p>You want to define where the XML file we'll be working with is, for example: </p>
<p><code>define('XMLFILE', '2002-04.xml');</code></p>
<p>You have to do this manually for security reasons.</p>
<p>If you've done that and you&#8217;re all ready, <a href="import-livejournal.php?step=1">let's go</a>!</p>
<?php
break;
case 1:
if ('' != XMLFILE && !file_exists(XMLFILE)) die("The file you specified does not seem to exist. Please check the path you've given.");
if ('' == XMLFILE) die("You must edit the XMLFILE line as described on the <a href='import-rss.php'>previous page</a> to continue.");
// Bring in the data
set_magic_quotes_runtime(0);
$datalines = file(XMLFILE); // Read the file into an array
$importdata = implode('', $datalines); // squish it
$importdata = str_replace(array("\r\n", "\r"), "\n", $importdata);
preg_match_all('|<entry>(.*?)</entry>|is', $importdata, $posts);
$posts = $posts[1];
echo '<ol>';
foreach ($posts as $post) :
$title = $date = $categories = $content = $post_id = '';
echo "<li>Importing post... ";
preg_match('|<subject>(.*?)</subject>|is', $post, $title);
$title = $wpdb->escape( trim($title[1]) );
$post_name = sanitize_title($title);
preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $date);
$date = strtotime($date[1]);
$post_date = date('Y-m-d H:i:s', $date);
preg_match('|<event>(.*?)</event>|is', $post, $content);
$content = str_replace( array('<![CDATA[', ']]>'), '', $wpdb->escape( trim($content[1]) ) );
// Now lets put it in the DB
if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' AND post_date = '$post_date'")) :
echo 'Post already imported';
else :
$wpdb->query("INSERT INTO $wpdb->posts
(post_author, post_date, post_date_gmt, post_content, post_title,post_status, comment_status, ping_status, post_name)
VALUES
('$post_author', '$post_date', DATE_ADD('$post_date', INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE), '$content', '$title', 'publish', '$comment_status', '$ping_status', '$post_name')");
$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' AND post_date = '$post_date'");
if (!$post_id) die("couldn't get post ID");
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = 1");
if (!$exists) $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_id, 1) ");
echo 'Done!</li>';
endif;
endforeach;
?>
</ol>
<h3>All done. <a href="../">Have fun!</a></h3>
<?php
break;
}
?>
</body>
</html>

View File

@ -1,418 +0,0 @@
<?php
define('MTEXPORT', '');
// enter the relative path of the import.txt file containing the mt entries. If the file is called import.txt and it is /wp-admin, then this line
//should be define('MTEXPORT', 'import.txt');
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
require_once('../wp-config.php');
require_once('upgrade-functions.php');
$step = $_GET['step'];
if (!$step) $step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &rsaquo; Import from Movable Type</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 20%;
margin-right: 20%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/logo.png);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
text-decoration: none;
text-indent: -100em;
height: 60px;
}
p {
line-height: 140%;
}
#authors li {
padding:3px;
border: 1px solid #ccc;
width: 40%;
margin-bottom:2px;
}
</style>
</head><body>
<h1 id="logo"><a href="http://wordpress.org/">WordPress</a></h1>
<?php
switch($step) {
case 0:
?>
<p>Howdy! We&#8217;re about to begin the process to import all of your Movable Type entries into WordPress. Before we get started, you need to edit this file (<code>import-mt.php</code>) and change one line so we know where to find your MT export file. To make this easy put the import file into the <code>wp-admin</code> directory. Look for the line that says:</p>
<p><code>define('MTEXPORT', '');</code></p>
<p>and change it to</p>
<p><code>define('MTEXPORT', 'import.txt');</code></p>
<p>You have to do this manually for security reasons.</p>
<p>If you've done that and you&#8217;re all ready, <a href="import-mt.php?step=1">let's go</a>! Remember that the import process may take a minute or so if you have a large number of entries and comments. Think of all the rebuilding time you'll be saving once it's done. :)</p>
<p>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
break;
case 1:
if ('' != MTEXPORT && !file_exists(MTEXPORT)) die("The file you specified does not seem to exist. Please check the path you've given.");
if ('' == MTEXPORT) die("You must edit the MTEXPORT line as described on the <a href='import-mt.php'>previous page</a> to continue.");
// Bring in the data
set_magic_quotes_runtime(0);
$importdata = file(MTEXPORT); // 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);
$authors = array();
$temp = array();
$posts = explode("--MT-ENTRY--", $importdata);
unset( $importdata ); // Free up memory
function users_form($n) {
global $wpdb, $testing;
$users = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID");
?><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 }
$i = -1;
foreach ($posts as $post) {
if ('' != trim($post)) {
++$i;
unset($post_categories);
preg_match("|AUTHOR:(.*)|", $post, $thematch);
$thematch = trim($thematch[1]);
array_push($temp,"$thematch"); //store the extracted author names in a temporary array
}
}//end of foreach
//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");
}
//by this point, we have all unique authors in the array $authors
?><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
echo '<ol id="authors">';
echo '<form action="?step=2" method="post">';
$j = -1;
foreach ($authors as $author) {
++$j;
echo '<li><i>'.$author.'</i><br />'.'<input type="text" value="'.$author.'" name="'.'user[]'.'" maxlength="30">';
users_form($j);
echo '</li>';
}
echo '<input type="submit" value="Submit">'.'<br/>';
echo '</form>';
echo '</ol>';
flush();
break;
case 2:
$newauthornames = array();
$formnames = array();
$selectnames = array();
$mtnames = array();
foreach($_POST['user'] as $key => $line) {
$newname = trim(stripslashes($line));
if ($newname == '') $newname = 'left_blank';//passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form.
array_push($formnames,"$newname");
}// $formnames is the array with the form entered names
foreach ($_POST['userselect'] as $user => $key) {
$selected = trim(stripslashes($key));
array_push($selectnames,"$selected");
}
$count = count($formnames);
for ($i = 0; $i < $count; $i++) {
if ( $selectnames[$i] != '#NONE#') {//if no name was selected from the select menu, use the name entered in the form
array_push($newauthornames,"$selectnames[$i]");
}
else {
array_push($newauthornames,"$formnames[$i]");
}
}
$j = -1;
//function to check the authorname and do the mapping
function checkauthor($author) {
global $wpdb, $mtnames, $newauthornames, $j;//mtnames is an array with the names in the mt import file
$md5pass = md5(changeme);
if (!(in_array($author, $mtnames))) { //a new mt author name is found
++$j;
$mtnames[$j] = $author; //add that new mt author name to an array
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$j]'"); //check if the new author name defined by the user is a pre-existing wp user
if (!$user_id) { //banging my head against the desk now.
if ($newauthornames[$j] == 'left_blank') { //check if the user does not want to change the authorname
$wpdb->query("INSERT INTO $wpdb->users (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$author', '$md5pass', '$author')"); // if user does not want to change, insert the authorname $author
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author'");
$newauthornames[$j] = $author; //now we have a name, in the place of left_blank.
} else {
$wpdb->query("INSERT INTO $wpdb->users (user_level, user_login, user_pass, user_nickname) VALUES ('1', '$newauthornames[$j]', '$md5pass', '$newauthornames[$j]')"); //if not left_blank, insert the user specified name
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$j]'");
}
} else return $user_id; // return pre-existing wp username if it exists
} else {
$key = array_search($author, $mtnames); //find the array key for $author in the $mtnames array
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$newauthornames[$key]'");//use that key to get the value of the author's name from $newauthornames
}
return $user_id;
}//function checkauthor ends here
//bring in the posts now
set_magic_quotes_runtime(0);
$importdata = file(MTEXPORT); // 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--", $importdata);
$authors = array();
$temp = array();
$posts = explode("--MT-ENTRY--", $importdata);
unset( $importdata ); // Free up memory
$i = -1;
echo "<ol>";
foreach ($posts as $post) { if ('' != trim($post)) {
++$i;
unset($post_categories);
echo "<li>Processing post... ";
// 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);
echo '<i>'.stripslashes($post_title).'</i>... ';
$post_name = sanitize_title($post_title);
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':
$post_allow_pings = trim($meta[2][0]);
if ($post_allow_pings == 1) {
$post_allow_pings = 'open';
} else {
$post_allow_pings = 'closed';
}
break;
case 'PRIMARY CATEGORY':
$post_categories[] = $wpdb->escape($value);
break;
case 'CATEGORY':
$post_categories[] = $wpdb->escape($value);
break;
case 'DATE':
$post_date = strtotime($value);
$post_date = date('Y-m-d H:i:s', $post_date);
$post_date_gmt = get_gmt_from_date("$post_date");
break;
default:
// echo "\n$key: $value";
break;
} // end switch
} // End foreach
// Let's check to see if it's in already
if ($wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'")) {
echo "Post already imported.";
} else {
$post_author = checkauthor($post_author);//just so that if a post already exists, new users are not created by checkauthor
$wpdb->query("INSERT INTO $wpdb->posts (
post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_name, post_modified, post_modified_gmt)
VALUES
('$post_author', '$post_date', '$post_date_gmt', '$post_content', '$post_title', '$excerpt', '$post_status', '$comment_status', '$ping_status', '$post_name','$post_date', '$post_date_gmt')");
$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$post_title' AND post_date = '$post_date'");
if (0 != count($post_categories)) {
foreach ($post_categories as $post_category) {
// See if the category exists yet
$cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
if (!$cat_id && '' != trim($post_category)) {
$cat_nicename = sanitize_title($post_category);
$wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
$cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
}
if ('' == trim($post_category)) $cat_id = 1;
// Double check it's not there already
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = $cat_id");
if (!$exists) {
$wpdb->query("
INSERT INTO $wpdb->post2cat
(post_id, category_id)
VALUES
($post_id, $cat_id)
");
}
} // end category loop
} else {
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = 1");
if (!$exists) $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_id, 1) ");
}
echo " Post imported successfully...";
// Now for comments
$comments = explode("-----\nCOMMENT:", $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_email);
$comment_email = $wpdb->escape(trim($comment_email[1]));
$comment = preg_replace('|(\n?EMAIL:.*)|', '', $comment);
preg_match("|IP:(.*)|", $comment, $comment_ip);
$comment_ip = trim($comment_ip[1]);
$comment = preg_replace('|(\n?IP:.*)|', '', $comment);
preg_match("|URL:(.*)|", $comment, $comment_url);
$comment_url = $wpdb->escape(trim($comment_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 (!$wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
$wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved)
VALUES
($post_id, '$comment_author', '$comment_email', '$comment_url', '$comment_ip', '$comment_date', '$comment_content', '1')");
echo " Comment added.";
}
}
}
// 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]);
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);
$comment_email = '';
preg_match("|IP:(.*)|", $ping, $comment_ip);
$comment_ip = trim($comment_ip[1]);
$ping = preg_replace('|(\n?IP:.*)|', '', $ping);
preg_match("|URL:(.*)|", $ping, $comment_url);
$comment_url = $wpdb->escape(trim($comment_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";
// Check if it's already there
if (!$wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_date = '$comment_date' AND comment_content = '$comment_content'")) {
$wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content, comment_approved, comment_type)
VALUES
($post_id, '$comment_author', '$comment_email', '$comment_url', '$comment_ip', '$comment_date', '$comment_content', '1', 'trackback')");
echo " Comment added.";
}
}
}
}
echo "</li>";
flush();
} }
upgrade_all();
?>
</ol>
<h3>All done. <a href="../">Have fun!</a></h3>
<?php
break;
}
?>
</body>
</html>

View File

@ -1,191 +0,0 @@
<?php
define('RSSFILE', '');
// Example:
// define('RSSFILE', '/home/example/public_html/rss.xml');
// or if it's in the same directory as import-rss.php
// define('RSSFILE', 'rss.xml');
$post_author = 1; // Author to import posts as author ID
$timezone_offset = 0; // GMT offset of posts your importing
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);
}
$add_hours = intval($timezone_offset);
$add_minutes = intval(60 * ($timezone_offset - $add_hours));
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. You must install WordPress before you import any entries.");
require_once('../wp-config.php');
$step = $_GET['step'];
if (!$step) $step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &rsaquo; Import from RSS</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 20%;
margin-right: 20%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/logo.png);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
text-decoration: none;
text-indent: -100em;
height: 60px;
}
p {
line-height: 140%;
}
</style>
</head><body>
<h1 id="logo"><a href="http://wordpress.org/">WordPress</a></h1>
<?php
switch($step) {
case 0:
?>
<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. To get started you must edit the following line in this file (<code>import-rss.php</code>) </p>
<p><code>define('RSSFILE', '');</code></p>
<p>You want to define where the RSS file we'll be working with is, for example: </p>
<p><code>define('RSSFILE', 'rss.xml');</code></p>
<p>You have to do this manually for security reasons. When you're done reload this page and we'll take you to the next step.</p>
<?php if ('' != RSSFILE) : ?>
<h2 style="text-align: right;"><a href="import-rss.php?step=1">Begin RSS Import &raquo;</a></h2>
<?php endif; ?>
<?php
break;
case 1:
// Bring in the data
set_magic_quotes_runtime(0);
$datalines = file(RSSFILE); // 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, $posts);
$posts = $posts[1];
echo '<ol>';
foreach ($posts as $post) :
$title = $date = $categories = $content = $post_id = '';
echo "<li>Importing post... ";
preg_match('|<title>(.*?)</title>|is', $post, $title);
$title = $wpdb->escape( trim($title[1]) );
$post_name = sanitize_title($title);
preg_match('|<pubdate>(.*?)</pubdate>|is', $post, $date);
if ($date) :
$date = strtotime($date[1]);
else : // if we don't already have something from pubDate
preg_match('|<dc:date>(.*?)</dc:date>|is', $post, $date);
$date = preg_replace('|([-+])([0-9]+):([0-9]+)$|', '\1\2\3', $date[1]);
$date = str_replace('T', ' ', $date);
$date = strtotime($date);
endif;
$post_date = gmdate('Y-m-d H:i:s', $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];
endif;
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, $content);
$content = str_replace( array('<![CDATA[', ']]>'), '', $wpdb->escape( trim($content[1]) ) );
if (!$content) : // This is for feeds that put content in description
preg_match('|<description>(.*?)</description>|is', $post, $content);
$content = $wpdb->escape( unhtmlentities( trim($content[1]) ) );
endif;
// Clean up content
$content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $content);
$content = str_replace('<br>', '<br />', $content);
$content = str_replace('<hr>', '<hr />', $content);
// This can mess up on posts with no titles, but checking content is much slower
// So we do it as a last resort
if ('' == $title) :
$dupe = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_content = '$content' AND post_date = '$post_date'");
else :
$dupe = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' AND post_date = '$post_date'");
endif;
// Now lets put it in the DB
if ($dupe) :
echo 'Post already imported';
else :
$wpdb->query("INSERT INTO $wpdb->posts
(post_author, post_date, post_date_gmt, post_content, post_title,post_status, comment_status, ping_status, post_name, guid)
VALUES
('$post_author', '$post_date', DATE_ADD('$post_date', INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE), '$content', '$title', 'publish', '$comment_status', '$ping_status', '$post_name', '$guid')");
$post_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '$title' AND post_date = '$post_date'");
if (!$post_id) die("couldn't get post ID");
if (0 != count($categories)) :
foreach ($categories as $post_category) :
$post_category = unhtmlentities($post_category);
// See if the category exists yet
$cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
if (!$cat_id && '' != trim($post_category)) {
$cat_nicename = sanitize_title($post_category);
$wpdb->query("INSERT INTO $wpdb->categories (cat_name, category_nicename) VALUES ('$post_category', '$cat_nicename')");
$cat_id = $wpdb->get_var("SELECT cat_ID from $wpdb->categories WHERE cat_name = '$post_category'");
}
if ('' == trim($post_category)) $cat_id = 1;
// Double check it's not there already
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = $cat_id");
if (!$exists) {
$wpdb->query("
INSERT INTO $wpdb->post2cat
(post_id, category_id)
VALUES
($post_id, $cat_id)
");
}
endforeach;
else:
$exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_id AND category_id = 1");
if (!$exists) $wpdb->query("INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES ($post_id, 1) ");
endif;
echo 'Done!</li>';
endif;
endforeach;
?>
</ol>
<h3>All done. <a href="../">Have fun!</a></h3>
<?php
break;
}
?>
</body>
</html>

View File

@ -1,138 +0,0 @@
<?php
// For security reasons, fill in the connection details to your Textpattern database below:
$tp_database_name = 'textpattern';
$tp_database_username = 'username';
$tp_database_password = 'password';
$tp_database_host = 'localhost';
if (!file_exists('../wp-config.php')) die("There doesn't seem to be a wp-config.php file. Double check that you updated wp-config-sample.php with the proper database connection information and renamed it to wp-config.php.");
require_once('../wp-config.php');
require_once('upgrade-functions.php');
$step = $_GET['step'];
if (!$step) $step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>WordPress &rsaquo; Textpattern Import</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
body {
font-family: Georgia, "Times New Roman", Times, serif;
margin-left: 15%;
margin-right: 15%;
}
#logo {
margin: 0;
padding: 0;
background-image: url(http://wordpress.org/images/wordpress.gif);
background-repeat: no-repeat;
height: 60px;
border-bottom: 4px solid #333;
}
#logo a {
display: block;
text-decoration: none;
text-indent: -100em;
height: 60px;
}
p {
line-height: 140%;
}
</style>
</head><body>
<h1 id="logo"><a href="http://wordpress.org/">WordPress</a></h1>
<?php
switch($step) {
case 0:
?>
<p>This script imports your entries from Textpattern into WordPress. It should be relatively painless, and we hope you're happy with the result.</p>
<p>To run this, you first need to edit this file (<code>import-textpattern.php</code>) and enter your Textpattern database connection details. Let's check if the database connection information works...</p>
<?php
$connection = @mysql_connect($tp_database_host, $tp_database_username, $tp_database_password);
$database = @mysql_select_db($tp_database_name);
if ($connection && $database) {
?>
<p>Everything seems dandy so far, <a href="?step=1">let's get started</a>!</p>
<?php
} else {
?>
<p><em>It looks like your database information is incorrect. Please re-edit this file and double-check all the settings.</em></p>
<?php
}
break;
case 1:
?>
<h1>Step 1</h1>
<p>First let's get posts and comments.</p>
<?php
// For people running this on .72
$query = "ALTER TABLE `$wpdb->posts` ADD `post_name` VARCHAR(200) NOT NULL";
maybe_add_column($wpdb->posts, 'post_name', $query);
// Create post_name field
$connection = @mysql_connect($tp_database_host, $tp_database_username, $tp_database_password);
$database = @mysql_select_db($tp_database_name);
// For now we're going to give everything the same author and same category
$author = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_level = 10 LIMIT 1");
$category = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories LIMIT 1");
$posts = mysql_query('SELECT * FROM textpattern', $connection);
while ($post = mysql_fetch_array($posts)) {
// ID, AuthorID, LastMod, LastModID, Posted, Title, Body, Body_html, Abstract, Category1, Category2, Annotate, AnnotateInvite, Status, Listing1, Listing2, Section
$posted = $post['Posted'];
// 20030216162119
$year = substr($posted,0,4);
$month = substr($posted,4,2);
$day = substr($posted,6,2);
$hour = substr($posted,8,2);
$minute = substr($posted,10,2);
$second = substr($posted,12,2);
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
$posted = date('Y-m-d H:i:s', $timestamp);
$content = $wpdb->escape($post['Body_html']);
$title = $wpdb->escape($post['Title']);
$post_name = sanitize_title($title);
$wpdb->query("INSERT INTO $wpdb->posts
(post_author, post_date, post_content, post_title, post_category, post_name, post_status)
VALUES
('$author', '$posted', '$content', '$title', '$category', '$post_name', 'publish')");
// Get wordpress post id
$wp_post_ID = $wpdb->get_var("SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1");
// Now let's insert comments if there are any for the TP post
$tp_id = $post['ID'];
$comments = mysql_query("SELECT * FROM txp_Discuss WHERE parentid = $tp_id");
if ($comments) {
while($comment = mysql_fetch_object($comments)) {
// discussid, parentid, name, email, web, ip, posted, message
// For some reason here "posted" is a real MySQL date, so we don't have to do anything about it
// comment_post_ID comment_author comment_author_email comment_author_url comment_author_IP comment_date comment_content comment_karma
$wpdb->query("INSERT INTO $wpdb->comments
(comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_content)
VALUES
($wp_post_ID, '$comment->name', '$comment->email', '$comment->web', '$comment->ip', '$comment->posted', '$comment->message')");
}
}
}
upgrade_all();
?>
<p><strong>All done.</strong> Wasn&#8217;t that fun? <a href="../">Have fun</a>.</p>
<?php
break;
}
?>
</body>
</html>