2004-01-22 07:04:38 +01:00
< ? php
2003-06-12 19:49:27 +02:00
2003-12-18 10:36:13 +01:00
$wpvarstoreset = array ( 'action' );
for ( $i = 0 ; $i < count ( $wpvarstoreset ); $i += 1 ) {
$wpvar = $wpvarstoreset [ $i ];
if ( ! isset ( $$wpvar )) {
2004-04-21 00:56:47 +02:00
if ( empty ( $_POST [ " $wpvar " ])) {
if ( empty ( $_GET [ " $wpvar " ])) {
2003-12-18 10:36:13 +01:00
$$wpvar = '' ;
2003-06-12 19:49:27 +02:00
} else {
2004-04-21 00:56:47 +02:00
$$wpvar = $_GET [ " $wpvar " ];
2003-06-12 19:49:27 +02:00
}
} else {
2004-04-21 00:56:47 +02:00
$$wpvar = $_POST [ " $wpvar " ];
2003-06-12 19:49:27 +02:00
}
}
}
2005-04-19 05:35:48 +02:00
require_once ( '../wp-config.php' );
2005-07-03 01:39:29 +02:00
require_once ( 'upgrade-functions.php' );
2005-04-19 05:35:48 +02:00
header ( 'Content-Type: text/html; charset=utf-8' );
2003-06-12 19:49:27 +02:00
switch ( $action ) {
case " step1 " :
?>
<! 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 " xml : lang = " en " >
< title > Blogger to WordPress - Converting ...</ title >
2003-12-16 02:58:39 +01:00
< link rel = " stylesheet " href = " wp-admin.css " type = " text/css " >
2003-06-12 19:49:27 +02:00
</ head >
< body >
< div class = " wrap " >
2005-08-27 21:10:56 +02:00
< h1 > Blogger to < img src = " ../wp-includes/images/wpminilogo.png " width = " 50 " height = " 50 " border = " 0 " alt = " WordPress " align = " top " /></ h1 >
2003-06-12 19:49:27 +02:00
< p > The importer is running ...</ p >
< ul >
< li > Importing posts and users
< ul >< ? php
for ( $bgy = 1999 ; $bgy <= ( date ( 'Y' )); $bgy ++ ) {
for ( $bgm = 1 ; $bgm < 13 ; $bgm ++ ) {
$bgmm = zeroise ( $bgm , 2 );
2004-05-16 07:04:09 +02:00
$archivefile = " ../ $bgy " . " _ " . " $bgmm " . " _01_wordpress.php " ;
2003-06-12 19:49:27 +02:00
if ( file_exists ( $archivefile )) {
$f = fopen ( $archivefile , " r " );
$archive = fread ( $f , filesize ( $archivefile ));
fclose ( $f );
echo " <li> $bgy / $bgmm " ;
2004-05-16 07:04:09 +02:00
$posts = explode ( '<wordpresspost>' , $archive );
2003-06-12 19:49:27 +02:00
2005-02-11 03:44:38 +01:00
for ( $i = 1 ; $i < count ( $posts ); $i = $i + 1 ) {
2003-06-12 19:49:27 +02:00
$postinfo = explode ( '|||' , $posts [ $i ]);
$post_date = $postinfo [ 0 ];
$post_content = $postinfo [ 2 ];
2003-10-07 21:56:49 +02:00
// 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];
2003-08-07 22:58:27 +02:00
$post_title = $postinfo [ 4 ];
2003-06-12 19:49:27 +02:00
2005-07-05 22:47:22 +02:00
$post_author = trim ( $wpdb -> escape ( $postinfo [ 1 ]));
2003-06-12 19:49:27 +02:00
// we'll check the author is registered already
2004-05-24 10:22:18 +02:00
$user = $wpdb -> get_row ( " SELECT * FROM $wpdb->users WHERE user_login = ' $post_author ' " );
2003-06-12 19:49:27 +02:00
if ( ! $user ) { // seems s/he's not, so let's register
$user_joindate = '1979-06-06 00:41:00' ; // that's my birthdate (gmt+1) - I could choose any other date. You could change the date too. Just remember the year must be >=1970 or the world would just randomly fall on your head (everything might look fine, and then blam! major headache!)
2005-07-05 22:47:22 +02:00
$user_login = $wpdb -> escape ( $post_author );
$pass1 = $wpdb -> escape ( 'password' );
$user_email = $wpdb -> escape ( 'user@wordpress.org' );
$user_url = $wpdb -> escape ( '' );
$user_joindate = $wpdb -> escape ( $user_joindate );
2003-06-12 19:49:27 +02:00
$result = $wpdb -> query ( "
2004-05-24 10:22:18 +02:00
INSERT INTO $wpdb -> users (
2003-06-12 19:49:27 +02:00
user_login ,
user_pass ,
user_email ,
user_url ,
2005-03-16 23:53:33 +01:00
user_registered ,
2003-06-12 19:49:27 +02:00
user_level ,
) VALUES (
'$user_login' ,
'$pass1' ,
'$user_email' ,
'$user_url' ,
'$user_joindate' ,
'1' ,
) " );
echo " : Registered user <strong> $user_login </strong> " ;
}
2004-05-24 10:22:18 +02:00
$post_author_ID = $wpdb -> get_var ( " SELECT ID FROM $wpdb->users WHERE user_login = ' $post_author ' " );
2003-06-12 19:49:27 +02:00
$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 ;
2005-02-11 03:44:38 +01:00
else if (( $post_date [ 2 ] == 'AM' ) && ( $posthour == '12' ))
$posthour = '00' ;
2003-06-12 19:49:27 +02:00
$post_date = " $postyear - $postmonth - $postday $posthour : $postminute : $postsecond " ;
2005-07-05 22:47:22 +02:00
$post_content = $wpdb -> escape ( $post_content );
2003-06-12 19:49:27 +02:00
$post_content = str_replace ( '<br>' , '<br />' , $post_content ); // the XHTML touch... ;)
2003-08-07 23:11:53 +02:00
2005-07-05 22:47:22 +02:00
$post_title = $wpdb -> escape ( $post_title );
2003-10-07 21:56:49 +02:00
// Quick-n-dirty check for dups:
2004-05-24 10:22:18 +02:00
$dupcheck = $wpdb -> get_results ( " SELECT ID,post_date,post_title FROM $wpdb->posts WHERE post_date=' $post_date ' AND post_title=' $post_title ' LIMIT 1 " , ARRAY_A );
2003-10-07 21:56:49 +02:00
if ( $dupcheck [ 0 ][ 'ID' ]) {
print " <br /> \n Skipping duplicate post, ID = ' " . $dupcheck [ 0 ][ 'ID' ] . " '<br /> \n " ;
print " Timestamp: " . $post_date . " <br /> \n " ;
print " Post Title: ' " . stripslashes ( $post_title ) . " '<br /> \n " ;
continue ;
}
2003-06-12 19:49:27 +02:00
$result = $wpdb -> query ( "
2004-05-24 10:22:18 +02:00
INSERT INTO $wpdb -> posts
2003-10-07 21:56:49 +02:00
( post_author , post_date , post_content , post_title , post_category )
2003-06-12 19:49:27 +02:00
VALUES
2003-10-07 21:56:49 +02:00
( '$post_author_ID' , '$post_date' , '$post_content' , '$post_title' , '1' )
2003-06-12 19:49:27 +02:00
" );
} echo '... <strong>Done</strong></li>' ;
}}
}
2004-01-12 13:12:45 +01:00
upgrade_all ();
2003-06-12 19:49:27 +02:00
?>
</ ul >
< strong > Done </ strong >
</ li >
</ ul >
< p >& nbsp ; </ p >
< p > Completed Blogger to WordPress import !</ p >
2003-12-11 01:22:36 +01:00
< p > Now you can go and < a href = " ../wp-login.php " > log in </ a > , have fun !</ p >
2003-06-12 19:49:27 +02:00
</ div >
</ body >
</ html >
< ? php
break ;
default :
?>
<! 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 " xml : lang = " en " >
< title > Blogger to WordPress Import Utility </ title >
2003-12-16 02:58:39 +01:00
< link rel = " stylesheet " href = " wp-admin.css " type = " text/css " >
2003-06-12 19:49:27 +02:00
</ head >
< body >
< div class = " wrap " >
2005-08-27 21:10:56 +02:00
< h1 > Blogger to < img src = " ../wp-includes/images/wpminilogo.png " width = " 50 " height = " 50 " border = " 0 " alt = " WordPress " align = " top " /></ h1 >
2003-06-12 19:49:27 +02:00
< p > This is a basic Blogger to WordPress import script .</ p >
< p > What it does :</ p >
< ul >
< li > Parses your archives to retrieve your blogger posts .</ li >
< li > Adds an author whenever it sees a new nickname , all authors are imported at level 1 , with a default profile and the password 'password' </ li >
</ ul >
< p > What it does not :</ p >
< ul >
< li > It sucks at making coffee .</ li >
< li > It always forgets to call back .</ li >
</ ul >
< h2 > First step : Install WordPress </ h2 >
2003-10-07 22:08:27 +02:00
< p > Install the WordPress blog as explained in the < a href = " ../readme.html " > read me </ a > , then immediately come back here .</ p >
2003-06-12 19:49:27 +02:00
< h3 > Second step : let ' s play with Blogger </ h3 >
< p > Log into your Blogger account .< br />
2004-05-16 07:04:09 +02:00
Go to the Settings , and make Blogger publish your files in the directory where your WordPress resides . Change the Date / Time format to be mm / dd / yyyy hh : mm : ss AM / PM ( the first choice in the dropdown menu ) . In Archives : set the frequency to 'monthly' and the archive filename to 'wordpress.php' ( without the quotes ), set the ftp archive path to make Blogger publish the archives in your WordPress directory . Click 'save changes' .< br />
2003-06-12 19:49:27 +02:00
Go to the Templates . Replace your existing template with this line ( copy and paste ) :
2004-05-16 07:04:09 +02:00
< blockquote >& lt ; Blogger >& lt ; wordpresspost >& lt ; $BlogItemDateTime $ >|||& lt ; $BlogItemAuthorNickname $ >|||& lt ; $BlogItemBody $ >|||& lt ; $BlogItemNumber $ >|||& lt ; $BlogItemSubject $ >& lt ; / Blogger ></ blockquote >
2003-06-12 19:49:27 +02:00
Go to the Archives , and click 'republish all' .< br />
2004-05-16 07:04:09 +02:00
Check in your FTP that you 've got the archive files published. They should look like this example: <code>2001_10_01_wordpress.php</code>. If they aren' t there , redo the republish process .</ p >
2003-06-12 19:49:27 +02:00
< p > You ' re done with the hard part . : ) </ p >
< form name = " stepOne " method = " get " >
< input type = " hidden " name = " action " value = " step1 " />
< h3 > Third step : w00t , let ' s click OK :</ h3 >
< p > When you ' re ready , click OK to start importing : < input type = " submit " name = " submit " value = " OK " />< br />< br />
2003-10-07 22:08:27 +02:00
< i > Note : the script might take some time , like 1 second for 100 entries
imported . DO NOT STOP IT or else you won ' t have a complete import .</ i ></ p >
2003-06-12 19:49:27 +02:00
</ form >
</ div >
</ body >
</ html >
< ? php
break ;
}
2004-05-16 07:04:09 +02:00
?>