2003-11-07 01:10:32 -05:00
< ? php
// For security reasons, fill in the connection details to your Textpattern database below:
2004-01-12 07:12:45 -05:00
$tp_database_name = 'textpattern' ;
$tp_database_username = 'username' ;
$tp_database_password = 'password' ;
2003-11-07 01:10:32 -05:00
$tp_database_host = 'localhost' ;
2004-04-21 20:40:38 -04:00
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. " );
2005-07-02 19:39:29 -04:00
require_once ( '../wp-config.php' );
require_once ( 'upgrade-functions.php' );
2003-11-07 01:10:32 -05:00
2004-04-20 18:56:47 -04:00
$step = $_GET [ 'step' ];
2003-11-07 01:10:32 -05:00
if ( ! $step ) $step = 0 ;
2005-04-18 23:35:48 -04:00
header ( 'Content-Type: text/html; charset=utf-8' );
2003-11-07 01:10:32 -05:00
?>
<! 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 >
2004-08-30 03:16:40 -04:00
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " />
2003-11-07 01:10:32 -05:00
< 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 ;
2004-01-12 07:12:45 -05:00
height : 60 px ;
2003-11-07 01:10:32 -05:00
border - bottom : 4 px solid #333;
}
#logo a {
display : block ;
text - decoration : none ;
text - indent : - 100 em ;
2004-01-12 07:12:45 -05:00
height : 60 px ;
2003-11-07 01:10:32 -05:00
}
p {
line - height : 140 % ;
}
</ style >
</ head >< body >
2005-10-12 14:21:15 -04:00
< h1 id = " logo " >< a href = " http://wordpress.org/ " > WordPress </ a ></ h1 >
2003-11-07 01:10:32 -05:00
< ? 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 {
?>
2004-01-30 18:18:35 -05:00
< p >< em > It looks like your database information is incorrect . Please re - edit this file and double - check all the settings .</ em ></ p >
2003-11-07 01:10:32 -05:00
< ? php
}
break ;
case 1 :
?>
< h1 > Step 1 </ h1 >
< p > First let ' s get posts and comments .</ p >
< ? php
// For people running this on .72
2004-05-24 04:22:18 -04:00
$query = " ALTER TABLE ` $wpdb->posts ` ADD `post_name` VARCHAR(200) NOT NULL " ;
maybe_add_column ( $wpdb -> posts , 'post_name' , $query );
2003-11-07 01:10:32 -05:00
// 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
2004-05-24 04:22:18 -04:00
$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 " );
2003-11-07 01:10:32 -05:00
$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 );
2005-07-05 16:47:22 -04:00
$content = $wpdb -> escape ( $post [ 'Body_html' ]);
$title = $wpdb -> escape ( $post [ 'Title' ]);
2003-11-07 01:10:32 -05:00
$post_name = sanitize_title ( $title );
2004-05-24 04:22:18 -04:00
$wpdb -> query ( " INSERT INTO $wpdb->posts
2004-01-12 07:12:45 -05:00
( post_author , post_date , post_content , post_title , post_category , post_name , post_status )
2003-11-07 01:10:32 -05:00
VALUES
2004-01-12 07:12:45 -05:00
( '$author' , '$posted' , '$content' , '$title' , '$category' , '$post_name' , 'publish' ) " );
2003-11-07 01:10:32 -05:00
// Get wordpress post id
2004-05-24 04:22:18 -04:00
$wp_post_ID = $wpdb -> get_var ( " SELECT ID FROM $wpdb->posts ORDER BY ID DESC LIMIT 1 " );
2003-11-07 01:10:32 -05:00
// 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
2004-05-24 04:22:18 -04:00
$wpdb -> query ( " INSERT INTO $wpdb->comments
2003-11-07 01:10:32 -05:00
( 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' ) " );
}
}
}
2004-01-12 07:12:45 -05:00
upgrade_all ();
2003-11-07 01:10:32 -05:00
?>
2004-01-12 07:12:45 -05:00
< p >< strong > All done .</ strong > Wasn & #8217;t that fun? <a href="../">Have fun</a>.</p>
2003-11-07 01:10:32 -05:00
< ? php
2004-01-12 07:12:45 -05:00
break ;
2003-11-07 01:10:32 -05:00
}
?>
2004-01-12 07:12:45 -05:00
2003-11-07 01:10:32 -05:00
</ body >
</ html >