2005-11-28 19:40:09 -05:00
< ? php
/**
2008-08-14 02:30:38 -04:00
* TextPattern Importer
*
* @ package WordPress
* @ subpackage Importer
*/
2005-11-28 19:40:09 -05:00
if ( ! function_exists ( 'get_comment_count' ))
{
2008-08-14 02:30:38 -04:00
/**
* Get the comment count for posts .
*
* @ package WordPress
* @ subpackage Textpattern_Import
*
* @ param int $post_ID Post ID
* @ return int
*/
2005-11-28 19:40:09 -05:00
function get_comment_count ( $post_ID )
{
global $wpdb ;
2008-04-14 12:13:25 -04:00
return $wpdb -> get_var ( $wpdb -> prepare ( " SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d " , $post_ID ) );
2005-11-28 19:40:09 -05:00
}
}
if ( ! function_exists ( 'link_exists' ))
{
2008-08-14 02:30:38 -04:00
/**
* Check whether link already exists .
*
* @ package WordPress
* @ subpackage Textpattern_Import
*
* @ param string $linkname
* @ return int
*/
2005-11-28 19:40:09 -05:00
function link_exists ( $linkname )
{
global $wpdb ;
2008-04-14 12:13:25 -04:00
return $wpdb -> get_var ( $wpdb -> prepare ( " SELECT link_id FROM $wpdb->links WHERE link_name = %s " , $linkname ) );
2005-11-28 19:40:09 -05:00
}
}
/**
2008-08-14 02:30:38 -04:00
* TextPattern Importer Class
*
* @ since unknown
*/
2005-11-28 19:40:09 -05:00
class Textpattern_Import {
2007-09-03 19:32:58 -04:00
function header ()
2005-11-28 19:40:09 -05:00
{
echo '<div class="wrap">' ;
2008-11-26 08:51:25 -05:00
screen_icon ();
2005-11-28 19:40:09 -05:00
echo '<h2>' . __ ( 'Import Textpattern' ) . '</h2>' ;
2005-12-02 12:42:12 -05:00
echo '<p>' . __ ( 'Steps may take a few minutes depending on the size of your database. Please be patient.' ) . '</p>' ;
2005-11-28 19:40:09 -05:00
}
2007-09-03 19:32:58 -04:00
function footer ()
2005-11-28 19:40:09 -05:00
{
echo '</div>' ;
}
2006-02-12 02:53:23 -05:00
2006-10-05 21:14:47 -04:00
function greet () {
echo '<div class="narrow">' ;
2006-12-05 02:15:12 -05:00
echo '<p>' . __ ( 'Howdy! This imports categories, users, posts, comments, and links from any Textpattern 4.0.2+ into this blog.' ) . '</p>' ;
echo '<p>' . __ ( 'This has not been tested on previous versions of Textpattern. Mileage may vary.' ) . '</p>' ;
2005-12-02 12:42:12 -05:00
echo '<p>' . __ ( 'Your Textpattern Configuration settings are as follows:' ) . '</p>' ;
echo '<form action="admin.php?import=textpattern&step=1" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2005-11-30 02:13:20 -05:00
$this -> db_form ();
2009-05-05 15:43:53 -04:00
echo '<p class="submit"><input type="submit" name="submit" class="button" value="' . esc_attr__ ( 'Import' ) . '" /></p>' ;
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2006-10-05 21:14:47 -04:00
echo '</div>' ;
2005-11-28 19:40:09 -05:00
}
2006-01-10 17:50:19 -05:00
function get_txp_cats ()
2005-11-28 19:40:09 -05:00
{
2005-11-30 02:13:20 -05:00
global $wpdb ;
2005-11-28 19:40:09 -05:00
// General Housekeeping
2005-11-30 02:13:20 -05:00
$txpdb = new wpdb ( get_option ( 'txpuser' ), get_option ( 'txppass' ), get_option ( 'txpname' ), get_option ( 'txphost' ));
2005-11-28 19:40:09 -05:00
set_magic_quotes_runtime ( 0 );
$prefix = get_option ( 'tpre' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Get Categories
2006-11-19 02:56:05 -05:00
return $txpdb -> get_results ( ' SELECT
id ,
name ,
title
FROM '.$prefix.' txp_category
WHERE type = " article " ' ,
ARRAY_A );
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-30 02:13:20 -05:00
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' );
2006-02-12 02:53:23 -05:00
2005-11-30 02:13:20 -05:00
// Get Users
2006-02-12 02:53:23 -05:00
2005-11-30 02:13:20 -05:00
return $txpdb -> get_results ( ' SELECT
2006-11-19 02:56:05 -05:00
user_id ,
name ,
RealName ,
email ,
privs
FROM '.$prefix.' txp_users ' , ARRAY_A );
2005-11-30 02:13:20 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function get_txp_posts ()
{
// General Housekeeping
2005-11-30 02:13:20 -05:00
$txpdb = new wpdb ( get_option ( 'txpuser' ), get_option ( 'txppass' ), get_option ( 'txpname' ), get_option ( 'txphost' ));
2005-11-28 19:40:09 -05:00
set_magic_quotes_runtime ( 0 );
$prefix = get_option ( 'tpre' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Get Posts
2006-11-19 02:56:05 -05:00
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 );
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function get_txp_comments ()
{
2005-11-30 02:13:20 -05:00
global $wpdb ;
2005-11-28 19:40:09 -05:00
// General Housekeeping
2005-11-30 02:13:20 -05:00
$txpdb = new wpdb ( get_option ( 'txpuser' ), get_option ( 'txppass' ), get_option ( 'txpname' ), get_option ( 'txphost' ));
2005-11-28 19:40:09 -05:00
set_magic_quotes_runtime ( 0 );
$prefix = get_option ( 'tpre' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Get Comments
return $txpdb -> get_results ( 'SELECT * FROM ' . $prefix . 'txp_discuss' , ARRAY_A );
}
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
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' );
2006-02-12 02:53:23 -05:00
2006-11-19 02:56:05 -05:00
return $txpdb -> get_results ( ' SELECT
id ,
date ,
category ,
url ,
linkname ,
description
FROM '.$prefix.' txp_link ' ,
ARRAY_A );
2005-12-01 12:12:22 -05:00
}
2006-02-12 02:53:23 -05:00
2006-11-19 02:56:05 -05:00
function cat2wp ( $categories = '' )
2005-11-28 19:40:09 -05:00
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
2005-12-01 12:12:22 -05:00
$txpcat2wpcat = array ();
// Do the Magic
if ( is_array ( $categories ))
2005-11-28 19:40:09 -05:00
{
2005-12-02 17:37:02 -05:00
echo '<p>' . __ ( 'Importing Categories...' ) . '<br /><br /></p>' ;
2006-11-19 02:56:05 -05:00
foreach ( $categories as $category )
2005-11-28 19:40:09 -05:00
{
$count ++ ;
2005-12-01 12:12:22 -05:00
extract ( $category );
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
// Make Nice Variables
$name = $wpdb -> escape ( $name );
$title = $wpdb -> escape ( $title );
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
if ( $cinfo = category_exists ( $name ))
2005-11-28 19:40:09 -05:00
{
2005-12-01 12:12:22 -05:00
$ret_id = wp_insert_category ( array ( 'cat_ID' => $cinfo , 'category_nicename' => $name , 'cat_name' => $title ));
2005-11-28 19:40:09 -05:00
}
2005-12-01 12:12:22 -05:00
else
2005-11-28 19:40:09 -05:00
{
2005-12-01 12:12:22 -05:00
$ret_id = wp_insert_category ( array ( 'category_nicename' => $name , 'cat_name' => $title ));
2005-11-28 19:40:09 -05:00
}
2005-12-01 12:12:22 -05:00
$txpcat2wpcat [ $id ] = $ret_id ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
// Store category translation for future use
add_option ( 'txpcat2wpcat' , $txpcat2wpcat );
2009-02-20 14:35:16 -05:00
echo '<p>' . sprintf ( _n ( 'Done! <strong>%1$s</strong> category imported.' , 'Done! <strong>%1$s</strong> categories imported.' , $count ), $count ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
return true ;
}
2005-12-01 12:12:22 -05:00
echo __ ( 'No Categories to Import!' );
2005-11-28 19:40:09 -05:00
return false ;
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function users2wp ( $users = '' )
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
$txpid2wpid = array ();
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Midnight Mojo
if ( is_array ( $users ))
{
2005-12-02 17:37:02 -05:00
echo '<p>' . __ ( 'Importing Users...' ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
foreach ( $users as $user )
{
$count ++ ;
extract ( $user );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Make Nice Variables
$name = $wpdb -> escape ( $name );
$RealName = $wpdb -> escape ( $RealName );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
if ( $uinfo = get_userdatabylogin ( $name ))
{
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
$ret_id = wp_insert_user ( array (
'ID' => $uinfo -> ID ,
'user_login' => $name ,
'user_nicename' => $RealName ,
'user_email' => $email ,
'user_url' => 'http://' ,
'display_name' => $name )
);
}
2006-11-19 02:56:05 -05:00
else
2005-11-28 19:40:09 -05:00
{
$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 ;
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Set Textpattern-to-WordPress permissions translation
$transperms = array ( 1 => '10' , 2 => '9' , 3 => '5' , 4 => '4' , 5 => '3' , 6 => '2' , 7 => '0' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// 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' ); }
2006-02-12 02:53:23 -05:00
2010-02-22 16:25:32 -05:00
update_user_meta ( $ret_id , 'wp_user_level' , $transperms [ $privs ] );
update_user_meta ( $ret_id , 'rich_editing' , 'false' );
2005-11-28 19:40:09 -05:00
} // End foreach($users as $user)
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Store id translation array for future use
add_option ( 'txpid2wpid' , $txpid2wpid );
2006-02-12 02:53:23 -05:00
2005-12-02 17:37:02 -05:00
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> users imported.' ), $count ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
return true ;
} // End if(is_array($users)
2006-02-12 02:53:23 -05:00
2005-11-30 02:13:20 -05:00
echo __ ( 'No Users to Import!' );
2005-11-28 19:40:09 -05:00
return false ;
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
} // End function user2wp()
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function posts2wp ( $posts = '' )
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
$txpposts2wpposts = array ();
$cats = array ();
// Do the Magic
if ( is_array ( $posts ))
{
2005-12-02 17:37:02 -05:00
echo '<p>' . __ ( 'Importing Posts...' ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
foreach ( $posts as $post )
{
$count ++ ;
extract ( $post );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Set Textpattern-to-WordPress status translation
$stattrans = array ( 1 => 'draft' , 2 => 'private' , 3 => 'draft' , 4 => 'publish' , 5 => 'publish' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
//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 ];
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Import Post data into WordPress
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
if ( $pinfo = post_exists ( $Title , $Body ))
{
$ret_id = wp_insert_post ( array (
2006-11-19 02:56:05 -05:00
'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 )
);
2007-09-18 12:32:22 -04:00
if ( is_wp_error ( $ret_id ) )
return $ret_id ;
2005-11-28 19:40:09 -05:00
}
2006-11-19 02:56:05 -05:00
else
2005-11-28 19:40:09 -05:00
{
$ret_id = wp_insert_post ( array (
2006-11-19 02:56:05 -05:00
'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 )
);
2007-09-18 12:32:22 -04:00
if ( is_wp_error ( $ret_id ) )
return $ret_id ;
2005-11-28 19:40:09 -05:00
}
$txpposts2wpposts [ $ID ] = $ret_id ;
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Make Post-to-Category associations
$cats = array ();
2007-08-27 20:08:58 -04:00
$category1 = get_category_by_slug ( $Category1 );
$category1 = $category1 -> term_id ;
$category2 = get_category_by_slug ( $Category2 );
2008-08-16 16:41:20 -04:00
$category2 = $category2 -> term_id ;
2007-08-27 20:08:58 -04:00
if ( $cat1 = $category1 ) { $cats [ 1 ] = $cat1 ; }
if ( $cat2 = $category2 ) { $cats [ 2 ] = $cat2 ; }
2005-11-28 19:40:09 -05:00
2006-10-02 14:03:34 -04:00
if ( ! empty ( $cats )) { wp_set_post_categories ( $ret_id , $cats ); }
2005-11-28 19:40:09 -05:00
}
}
// Store ID translation for later use
add_option ( 'txpposts2wpposts' , $txpposts2wpposts );
2006-02-12 02:53:23 -05:00
2005-12-02 17:37:02 -05:00
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> posts imported.' ), $count ) . '<br /><br /></p>' ;
2006-02-12 02:53:23 -05:00
return true ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function comments2wp ( $comments = '' )
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
$txpcm2wpcm = array ();
$postarr = get_option ( 'txpposts2wpposts' );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// Magic Mojo
if ( is_array ( $comments ))
{
2005-12-02 17:37:02 -05:00
echo '<p>' . __ ( 'Importing Comments...' ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
foreach ( $comments as $comment )
{
$count ++ ;
extract ( $comment );
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
// WordPressify Data
$comment_ID = ltrim ( $discussid , '0' );
2005-12-01 12:12:22 -05:00
$comment_post_ID = $postarr [ $parentid ];
2005-11-28 19:40:09 -05:00
$comment_approved = ( 1 == $visible ) ? 1 : 0 ;
$name = $wpdb -> escape ( $name );
$email = $wpdb -> escape ( $email );
$web = $wpdb -> escape ( $web );
$message = $wpdb -> escape ( $message );
2006-02-12 02:53:23 -05:00
2009-11-24 09:40:25 -05:00
$comment = array (
'comment_post_ID' => $comment_post_ID ,
'comment_author' => $name ,
'comment_author_IP' => $ip ,
'comment_author_email' => $email ,
'comment_author_url' => $web ,
'comment_date' => $posted ,
'comment_content' => $message ,
'comment_approved' => $comment_approved );
$comment = wp_filter_comment ( $comment );
if ( $cinfo = comment_exists ( $name , $posted ) ) {
2005-11-28 19:40:09 -05:00
// Update comments
2009-11-24 09:40:25 -05:00
$comment [ 'comment_ID' ] = $cinfo ;
$ret_id = wp_update_comment ( $comment );
} else {
2005-11-28 19:40:09 -05:00
// Insert comments
2009-11-24 09:40:25 -05:00
$ret_id = wp_insert_comment ( $comment );
2005-11-28 19:40:09 -05:00
}
$txpcm2wpcm [ $comment_ID ] = $ret_id ;
}
// Store Comment ID translation for future use
2006-02-12 02:53:23 -05:00
add_option ( 'txpcm2wpcm' , $txpcm2wpcm );
2005-11-28 19:40:09 -05:00
// Associate newly formed categories with posts
get_comment_count ( $ret_id );
2006-02-12 02:53:23 -05:00
2005-12-02 17:37:02 -05:00
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> comments imported.' ), $count ) . '<br /><br /></p>' ;
2005-11-28 19:40:09 -05:00
return true ;
}
2005-11-30 02:13:20 -05:00
echo __ ( 'No Comments to Import!' );
2005-11-28 19:40:09 -05:00
return false ;
}
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
function links2wp ( $links = '' )
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
// Deal with the links
if ( is_array ( $links ))
{
2005-12-02 12:42:12 -05:00
echo '<p>' . __ ( 'Importing Links...' ) . '<br /><br /></p>' ;
2005-12-01 12:12:22 -05:00
foreach ( $links as $link )
{
$count ++ ;
extract ( $link );
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
// Make nice vars
$category = $wpdb -> escape ( $category );
$linkname = $wpdb -> escape ( $linkname );
$description = $wpdb -> escape ( $description );
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
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 )
);
}
2006-11-19 02:56:05 -05:00
else
2005-12-01 12:12:22 -05:00
{
$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 );
2005-12-02 12:42:12 -05:00
echo '<p>' ;
2009-02-20 14:35:16 -05:00
printf ( _n ( 'Done! <strong>%s</strong> link imported' , 'Done! <strong>%s</strong> links imported' , $count ), $count );
2005-12-02 12:42:12 -05:00
echo '<br /><br /></p>' ;
2005-12-01 12:12:22 -05:00
return true ;
}
echo __ ( 'No Links to Import!' );
return false ;
}
2006-02-12 02:53:23 -05:00
2006-11-19 02:56:05 -05:00
function import_categories ()
2006-02-12 02:53:23 -05:00
{
// Category Import
2005-11-28 19:40:09 -05:00
$cats = $this -> get_txp_cats ();
$this -> cat2wp ( $cats );
add_option ( 'txp_cats' , $cats );
2006-02-12 02:53:23 -05:00
2005-12-02 12:42:12 -05:00
echo '<form action="admin.php?import=textpattern&step=2" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2009-05-05 15:43:53 -04:00
printf ( '<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>' , esc_attr__ ( 'Import Users' ));
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function import_users ()
{
// User Import
2006-11-19 02:56:05 -05:00
$users = $this -> get_txp_users ();
2005-11-28 19:40:09 -05:00
$this -> users2wp ( $users );
2006-02-12 02:53:23 -05:00
2005-12-02 12:42:12 -05:00
echo '<form action="admin.php?import=textpattern&step=3" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2009-05-05 15:43:53 -04:00
printf ( '<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>' , esc_attr__ ( 'Import Posts' ));
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function import_posts ()
{
// Post Import
$posts = $this -> get_txp_posts ();
2007-09-18 12:32:22 -04:00
$result = $this -> posts2wp ( $posts );
if ( is_wp_error ( $result ) )
return $result ;
2006-02-12 02:53:23 -05:00
2005-12-02 12:42:12 -05:00
echo '<form action="admin.php?import=textpattern&step=4" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2009-05-05 15:43:53 -04:00
printf ( '<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>' , esc_attr__ ( 'Import Comments' ));
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function import_comments ()
{
// Comment Import
$comments = $this -> get_txp_comments ();
$this -> comments2wp ( $comments );
2006-02-12 02:53:23 -05:00
2005-12-02 12:42:12 -05:00
echo '<form action="admin.php?import=textpattern&step=5" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2009-05-05 15:43:53 -04:00
printf ( '<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>' , esc_attr__ ( 'Import Links' ));
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function import_links ()
{
//Link Import
$links = $this -> get_txp_links ();
$this -> links2wp ( $links );
add_option ( 'txp_links' , $links );
2006-02-12 02:53:23 -05:00
2005-12-02 12:42:12 -05:00
echo '<form action="admin.php?import=textpattern&step=6" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-textpattern' );
2009-05-05 15:43:53 -04:00
printf ( '<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>' , esc_attr__ ( 'Finish' ));
2005-12-02 12:42:12 -05:00
echo '</form>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
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' );
2005-11-30 02:13:20 -05:00
delete_option ( 'txpuser' );
delete_option ( 'txppass' );
delete_option ( 'txpname' );
delete_option ( 'txphost' );
2007-12-22 20:10:29 -05:00
do_action ( 'import_done' , 'textpattern' );
2005-11-28 19:40:09 -05:00
$this -> tips ();
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
function tips ()
{
2005-12-02 12:42:12 -05:00
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>' ;
2009-10-25 05:28:20 -04:00
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">log in</a> and change it.' ), get_bloginfo ( 'wpurl' ) . '/wp-login.php' ) . '</p>' ;
2005-12-02 12:42:12 -05:00
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>' ;
2007-05-10 23:54:56 -04:00
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/category/development/wordpress/textile/">Textile for WordPress</a>. Trust me... You’ll want it.' ) . '</p>' ;
2005-12-02 12:42:12 -05:00
echo '<h3>' . __ ( 'WordPress Resources' ) . '</h3>' ;
echo '<p>' . __ ( 'Finally, there are numerous WordPress resources around the internet. Some of them are:' ) . '</p>' ;
echo '<ul>' ;
2010-04-19 11:09:38 -04:00
echo '<li>' . __ ( '<a href="http://wordpress.org/">The official WordPress site</a>' ) . '</li>' ;
2006-09-05 14:52:24 -04:00
echo '<li>' . __ ( '<a href="http://wordpress.org/support/">The WordPress support forums</a>' ) . '</li>' ;
2010-04-19 11:09:38 -04:00
echo '<li>' . __ ( '<a href="http://codex.wordpress.org/">The Codex (In other words, the WordPress Bible)</a>' ) . '</li>' ;
2005-12-02 12:42:12 -05:00
echo '</ul>' ;
2009-10-25 05:28:20 -04:00
echo '<p>' . sprintf ( __ ( 'That’s it! What are you waiting for? Go <a href="%1$s">log in</a>!' ), get_bloginfo ( 'wpurl' ) . '/wp-login.php' ) . '</p>' ;
2005-11-30 02:13:20 -05:00
}
2006-02-12 02:53:23 -05:00
2005-11-30 02:13:20 -05:00
function db_form ()
{
2008-02-23 23:33:10 -05:00
echo '<table class="form-table">' ;
2006-10-05 21:14:47 -04:00
printf ( '<tr><th scope="row"><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>' , __ ( 'Textpattern Database User:' ));
printf ( '<tr><th scope="row"><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>' , __ ( 'Textpattern Database Password:' ));
printf ( '<tr><th scope="row"><label for="dbname">%s</label></th><td><input type="text" id="dbname" name="dbname" /></td></tr>' , __ ( 'Textpattern Database Name:' ));
printf ( '<tr><th scope="row"><label for="dbhost">%s</label></th><td><input type="text" id="dbhost" name="dbhost" value="localhost" /></td></tr>' , __ ( 'Textpattern Database Host:' ));
printf ( '<tr><th scope="row"><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix" /></td></tr>' , __ ( 'Textpattern Table prefix (if any):' ));
echo '</table>' ;
2005-11-28 19:40:09 -05:00
}
2006-02-12 02:53:23 -05:00
2006-11-19 02:56:05 -05:00
function dispatch ()
2005-11-28 19:40:09 -05:00
{
2005-11-29 09:59:23 -05:00
2005-11-28 19:40:09 -05:00
if ( empty ( $_GET [ 'step' ]))
$step = 0 ;
else
$step = ( int ) $_GET [ 'step' ];
$this -> header ();
2006-02-12 02:53:23 -05:00
2006-11-19 02:56:05 -05:00
if ( $step > 0 )
2005-11-30 02:13:20 -05:00
{
2007-05-07 11:56:53 -04:00
check_admin_referer ( 'import-textpattern' );
2005-12-01 12:12:22 -05:00
if ( $_POST [ 'dbuser' ])
{
if ( get_option ( 'txpuser' ))
2006-02-12 02:53:23 -05:00
delete_option ( 'txpuser' );
2007-05-07 11:56:53 -04:00
add_option ( 'txpuser' , sanitize_user ( $_POST [ 'dbuser' ], true ));
2005-12-01 12:12:22 -05:00
}
if ( $_POST [ 'dbpass' ])
{
if ( get_option ( 'txppass' ))
2006-02-12 02:53:23 -05:00
delete_option ( 'txppass' );
2007-05-07 11:56:53 -04:00
add_option ( 'txppass' , sanitize_user ( $_POST [ 'dbpass' ], true ));
2005-12-01 12:12:22 -05:00
}
2006-02-12 02:53:23 -05:00
2005-12-01 12:12:22 -05:00
if ( $_POST [ 'dbname' ])
{
if ( get_option ( 'txpname' ))
2006-02-12 02:53:23 -05:00
delete_option ( 'txpname' );
2007-05-07 11:56:53 -04:00
add_option ( 'txpname' , sanitize_user ( $_POST [ 'dbname' ], true ));
2005-12-01 12:12:22 -05:00
}
if ( $_POST [ 'dbhost' ])
{
if ( get_option ( 'txphost' ))
delete_option ( 'txphost' );
2007-05-07 11:56:53 -04:00
add_option ( 'txphost' , sanitize_user ( $_POST [ 'dbhost' ], true ));
2005-12-01 12:12:22 -05:00
}
if ( $_POST [ 'dbprefix' ])
{
if ( get_option ( 'tpre' ))
delete_option ( 'tpre' );
2007-05-07 11:56:53 -04:00
add_option ( 'tpre' , sanitize_user ( $_POST [ 'dbprefix' ]));
2006-02-12 02:53:23 -05:00
}
2005-12-01 12:12:22 -05:00
2005-11-30 02:13:20 -05:00
2005-11-29 09:59:23 -05:00
}
2006-11-19 02:56:05 -05:00
switch ( $step )
2005-11-28 19:40:09 -05:00
{
default :
case 0 :
$this -> greet ();
break ;
case 1 :
$this -> import_categories ();
break ;
case 2 :
$this -> import_users ();
break ;
case 3 :
2007-09-18 12:32:22 -04:00
$result = $this -> import_posts ();
2008-02-05 01:47:27 -05:00
if ( is_wp_error ( $result ) )
2007-09-18 12:32:22 -04:00
echo $result -> get_error_message ();
2005-11-28 19:40:09 -05:00
break ;
case 4 :
$this -> import_comments ();
break ;
case 5 :
$this -> import_links ();
break ;
case 6 :
$this -> cleanup_txpimport ();
break ;
}
2006-02-12 02:53:23 -05:00
2005-11-28 19:40:09 -05:00
$this -> footer ();
}
2006-11-19 02:56:05 -05:00
function Textpattern_Import ()
2005-11-28 19:40:09 -05:00
{
2006-02-12 02:53:23 -05:00
// Nothing.
2005-11-28 19:40:09 -05:00
}
}
$txp_import = new Textpattern_Import ();
2008-08-14 02:30:38 -04:00
2008-02-27 17:05:50 -05:00
register_importer ( 'textpattern' , __ ( 'Textpattern' ), __ ( 'Import categories, users, posts, comments, and links from a Textpattern blog.' ), array ( $txp_import , 'dispatch' ));
2008-08-14 02:30:38 -04:00
2005-12-02 12:42:12 -05:00
?>