<?php
// PHPslash import code written by Jon Masters
// Now based upon import-mt.php
// Configurable parameters for existing phpslash database:
$dbuser = ""; // PHPslash username
$dbpassword = ""; // PHPslash password
$dbhost = ""; // PHPslash hostname
$dbdb = ""; // PHPslash database
// end of configuration parameters.
//
// History:
//
// 2005/01/06 - Initial release just to get wordpress working my blog :-).
die("There doesn't seem to be a wp-config.php file." .
"You must install Wordpress before you import any entries.");
}
require('../wp-config.php');
$step = $HTTP_GET_VARS['step'];
if (!step) $step = 0;
?>
<!!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 › Import from PHP Slash</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<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’re about to begin the process to import all of your
PHP Slash entries into WordPress. Before we get started, you need to
edit this
file (<code>import-phpslash.php</code>
) and change a couple
of lines so we know where to find your phpslash database.</p>
<p>If you've done that and you’re all ready,
<a href="import-phpslash.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>
<?php
break;
case 1:
?>
<p>We will now try to import your PHPslash stories in to WordPress.
Watch the following output to see how it goes.</p>
<p>
<?php
if (!$phpslash_dbh) {
<p><strong>Error establishing a database connection!</strong>
This probably means that the connection information in your
<code>import-phpslash.php</code> file is incorrect.
Double check it and try again.</p>
<ul>
<li>Are you sure you have the correct user/password?</li>
<li>Are you sure that you have typed the correct hostname?</li>
<li>Are you sure that the database server is running?</li>
</ul>
<p><a href='http://wordpress.org/support/'>WordPress Support Forums</a>
</p></div>");
}
<p>We're having a little trouble selecting the PHPslash database.</p>
<ul>
<li>Are you sure it exists?</li>
<li>Your database name is currently specified as
<code>dbname</code>. Is this correct?</li>
<li>On some systems the name of your database is prefixed with your
username, so it would be like username_phpslash.
Could that be the problem?</li>
</ul>
<p><a href='http://wordpress.org/support/'>WordPress Support Forums</a></p>");
}
// Rip out the entries from PHPslash, matching up user names.
$psl_story_query =
mysql_query("SELECT psl_author.author_name, " .
"psl_story.title, psl_story.dept, " .
"psl_story.intro_text, " .
"psl_story.body_text, " .
"psl_story.date_available " .
"FROM psl_story LEFT JOIN psl_author ON " .
"psl_author.author_id=psl_story.user_id " .
// for debugging use id=240
// "WHERE psl_story.story_id="240"" .
"ORDER BY psl_story.story_id ASC;");
if (!$psl_story_query) {
}
MYSQL_ASSOC)) {
$wordpress_entry['post_author'] =
$psl_story_entry['author_name'];
$wordpress_entry['post_title'] = $psl_story_entry['title'];
$wordpress_entry['post_category'] = 1; // FIXME
$wordpress_entry['post_content'] = "[ from the " .
$psl_story_entry['dept'] .
" dept. ]<br/><br/>" .
$psl_story_entry['intro_text'] .
"<br/><br/>" .
$psl_story_entry['body_text'];
$wordpress_entry['post_date'] =
date("Y-m-d H:i:s",
$psl_story_entry['date_available']);
$wordpress_entry['post_date_gmt'] = $wordpress_entry['post_date'];
$wordpress_entry['post_modified'] =
date("Y-m-d H:i:s");
$wordpress_entry['post_modified_gmt'] =
gmdate("Y-m-d H:i:s");
// Let's check to see if it's in already
if ($wpdb->get_var("SELECT ID FROM $tableposts WHERE post_title = " .
""{$wordpress_entry['post_title']}" " .
"AND post_date = " .
""{$wordpress_entry['post_date']}"")) {
echo "<strong>[IGNORED] " .
$wordpress_entry['post_title'] .
"</strong><br/>";
} else {
// Find the corresponding author
if ($user_id = $wpdb->get_var("SELECT ID FROM " .
"$tableusers WHERE user_login = " .
""{$wordpress_entry['post_author']}"")) {
$wordpress_entry['post_author'] = $user_id;
echo "<strong>[imported] " .
"[ " . $psl_story_entry['author_name'] . "] " .
$wordpress_entry['post_title'] .
"</strong><br/>";
} else {
$wordpress_entry['post_author'] = 0; // general user
echo "<strong>[imported] " .
"[general]" .
$wordpress_entry['post_title'] .
"</strong><br/>";
}
$wpdb->query("INSERT INTO $tableposts (
post_author, post_title, post_category,
post_content, post_date, post_date_gmt,
post_modified, post_modified_gmt)
VALUES
("{$wordpress_entry['post_author']}",
"{$wordpress_entry['post_title']}",
"{$wordpress_entry['post_category']}",
"{$wordpress_entry['post_content']}",
"{$wordpress_entry['post_date']}",
"{$wordpress_entry['post_date_gmt']}",
"{$wordpress_entry['post_modified']}",
"{$wordpress_entry['post_modified_gmt']}")");
$post_id = $wpdb->get_var("SELECT ID FROM $tableposts WHERE " .
"post_title = "{$wordpress_entry['post_title']}" " .
"AND post_date = "{$wordpress_entry['post_date']}"");
// FIXME: We just insert category 1 for the moment.
$wpdb->query("INSERT INTO $tablepost2cat (
post_id, category_id)
VALUES
($post_id,
"{$wordpress_entry['post_category']}")");
}
?>
<?php
}
?>
</p>
<p>That's all for now. If the above didn't show any error messages
then the imported data should now show up in your WordPress.
</p>
<?php
break;
} /* switch(step) */
?>
<p>This is the PHPslash import script by <a href="/">Jon Masters</a>.</p>
</body>
</html>