2006-10-25 18:55:05 -04:00
< ? php
2008-08-14 02:30:38 -04:00
/**
* DotClear Importer
*
* @ package WordPress
* @ subpackage Importer
2006-10-25 18:55:05 -04:00
*/
/**
Add These Functions to make our lives easier
**/
2010-01-18 15:34:48 -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 Dotclear_Import
*
* @ param int $post_ID Post ID
* @ return int
*/
2006-10-25 18:55:05 -04: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 ) );
2006-10-25 18:55:05 -04:00
}
}
2010-01-18 15:34:48 -05:00
if ( ! function_exists ( 'link_exists' )) {
2008-08-14 02:30:38 -04:00
/**
* Check whether link already exists .
*
* @ package WordPress
* @ subpackage Dotclear_Import
*
* @ param string $linkname
* @ return int
*/
2006-10-25 18:55:05 -04: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 ) );
2006-10-25 18:55:05 -04:00
}
}
2008-08-14 02:30:38 -04:00
/**
2009-05-11 16:26:27 -04:00
* Convert from dotclear charset to utf8 if required
2009-05-24 19:47:49 -04:00
*
2008-08-14 02:30:38 -04:00
* @ package WordPress
* @ subpackage Dotclear_Import
*
* @ param string $s
* @ return string
*/
2006-10-25 18:55:05 -04:00
function csc ( $s ) {
2009-05-11 16:26:27 -04:00
if ( seems_utf8 ( $s )) {
2006-10-25 18:55:05 -04:00
return $s ;
} else {
return iconv ( get_option ( " dccharset " ), " UTF-8 " , $s );
}
}
2008-08-14 02:30:38 -04:00
/**
* @ package WordPress
* @ subpackage Dotclear_Import
*
* @ param string $s
* @ return string
*/
2006-10-25 18:55:05 -04:00
function textconv ( $s ) {
return csc ( preg_replace ( '|(?<!<br />)\s*\n|' , ' ' , $s ));
}
/**
2008-08-14 02:30:38 -04:00
* Dotclear Importer class
*
* Will process the WordPress eXtended RSS files that you upload from the export
* file .
*
* @ package WordPress
* @ subpackage Importer
*
* @ since unknown
*/
2006-10-25 18:55:05 -04:00
class Dotclear_Import {
2007-09-03 19:32:58 -04:00
function header ()
2006-10-25 18:55:05 -04:00
{
echo '<div class="wrap">' ;
2008-11-26 08:51:25 -05:00
screen_icon ();
2006-10-25 18:55:05 -04:00
echo '<h2>' . __ ( 'Import DotClear' ) . '</h2>' ;
echo '<p>' . __ ( 'Steps may take a few minutes depending on the size of your database. Please be patient.' ) . '</p>' ;
}
2007-09-03 19:32:58 -04:00
function footer ()
2006-10-25 18:55:05 -04:00
{
echo '</div>' ;
}
2007-09-03 19:32:58 -04:00
function greet ()
2006-10-25 18:55:05 -04:00
{
echo '<div class="narrow"><p>' . __ ( 'Howdy! This importer allows you to extract posts from a DotClear database into your blog. Mileage may vary.' ) . '</p>' ;
echo '<p>' . __ ( 'Your DotClear Configuration settings are as follows:' ) . '</p>' ;
echo '<form action="admin.php?import=dotclear&step=1" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
2006-10-25 18:55:05 -04: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 Categories' ) . '" /></p>' ;
2006-10-25 18:55:05 -04:00
echo '</form></div>' ;
}
2006-11-19 02:56:05 -05:00
function get_dc_cats ()
2006-10-25 18:55:05 -04:00
{
global $wpdb ;
// General Housekeeping
$dcdb = new wpdb ( get_option ( 'dcuser' ), get_option ( 'dcpass' ), get_option ( 'dcname' ), get_option ( 'dchost' ));
set_magic_quotes_runtime ( 0 );
$dbprefix = get_option ( 'dcdbprefix' );
// Get Categories
return $dcdb -> get_results ( 'SELECT * FROM ' . $dbprefix . 'categorie' , ARRAY_A );
}
function get_dc_users ()
{
global $wpdb ;
// General Housekeeping
$dcdb = new wpdb ( get_option ( 'dcuser' ), get_option ( 'dcpass' ), get_option ( 'dcname' ), get_option ( 'dchost' ));
set_magic_quotes_runtime ( 0 );
$dbprefix = get_option ( 'dcdbprefix' );
// Get Users
return $dcdb -> get_results ( 'SELECT * FROM ' . $dbprefix . 'user' , ARRAY_A );
}
function get_dc_posts ()
{
// General Housekeeping
$dcdb = new wpdb ( get_option ( 'dcuser' ), get_option ( 'dcpass' ), get_option ( 'dcname' ), get_option ( 'dchost' ));
set_magic_quotes_runtime ( 0 );
$dbprefix = get_option ( 'dcdbprefix' );
// Get Posts
return $dcdb -> get_results ( 'SELECT ' . $dbprefix . 'post.*, ' . $dbprefix . ' categorie . cat_libelle_url AS post_cat_name
FROM '.$dbprefix.' post INNER JOIN '.$dbprefix.' categorie
2006-11-19 02:56:05 -05:00
ON '.$dbprefix.' post . cat_id = '.$dbprefix.' categorie . cat_id ' , ARRAY_A );
2006-10-25 18:55:05 -04:00
}
function get_dc_comments ()
{
global $wpdb ;
// General Housekeeping
$dcdb = new wpdb ( get_option ( 'dcuser' ), get_option ( 'dcpass' ), get_option ( 'dcname' ), get_option ( 'dchost' ));
set_magic_quotes_runtime ( 0 );
$dbprefix = get_option ( 'dcdbprefix' );
// Get Comments
return $dcdb -> get_results ( 'SELECT * FROM ' . $dbprefix . 'comment' , ARRAY_A );
}
function get_dc_links ()
{
//General Housekeeping
$dcdb = new wpdb ( get_option ( 'dcuser' ), get_option ( 'dcpass' ), get_option ( 'dcname' ), get_option ( 'dchost' ));
set_magic_quotes_runtime ( 0 );
$dbprefix = get_option ( 'dcdbprefix' );
return $dcdb -> get_results ( 'SELECT * FROM ' . $dbprefix . 'link ORDER BY position' , ARRAY_A );
}
2006-11-19 02:56:05 -05:00
function cat2wp ( $categories = '' )
2006-10-25 18:55:05 -04:00
{
// General Housekeeping
global $wpdb ;
$count = 0 ;
$dccat2wpcat = array ();
// Do the Magic
2010-01-18 15:34:48 -05:00
if ( is_array ( $categories )) {
2006-10-25 18:55:05 -04:00
echo '<p>' . __ ( 'Importing Categories...' ) . '<br /><br /></p>' ;
2010-01-18 15:34:48 -05:00
foreach ( $categories as $category ) {
2006-10-25 18:55:05 -04:00
$count ++ ;
extract ( $category );
// Make Nice Variables
$name = $wpdb -> escape ( $cat_libelle_url );
$title = $wpdb -> escape ( csc ( $cat_libelle ));
$desc = $wpdb -> escape ( csc ( $cat_desc ));
2010-01-18 15:34:48 -05:00
if ( $cinfo = category_exists ( $name )) {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_category ( array ( 'cat_ID' => $cinfo , 'category_nicename' => $name , 'cat_name' => $title , 'category_description' => $desc ));
2010-01-18 15:34:48 -05:00
} else {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_category ( array ( 'category_nicename' => $name , 'cat_name' => $title , 'category_description' => $desc ));
}
$dccat2wpcat [ $id ] = $ret_id ;
}
// Store category translation for future use
add_option ( 'dccat2wpcat' , $dccat2wpcat );
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>' ;
2006-10-25 18:55:05 -04:00
return true ;
}
echo __ ( 'No Categories to Import!' );
return false ;
}
2010-01-18 15:34:48 -05:00
function users2wp ( $users = '' ) {
2006-10-25 18:55:05 -04:00
// General Housekeeping
global $wpdb ;
$count = 0 ;
$dcid2wpid = array ();
// Midnight Mojo
2010-01-18 15:34:48 -05:00
if ( is_array ( $users )) {
2006-10-25 18:55:05 -04:00
echo '<p>' . __ ( 'Importing Users...' ) . '<br /><br /></p>' ;
2010-01-18 15:34:48 -05:00
foreach ( $users as $user ) {
2006-10-25 18:55:05 -04:00
$count ++ ;
extract ( $user );
// Make Nice Variables
$name = $wpdb -> escape ( csc ( $name ));
$RealName = $wpdb -> escape ( csc ( $user_pseudo ));
2010-01-18 15:34:48 -05:00
if ( $uinfo = get_userdatabylogin ( $name )) {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_user ( array (
'ID' => $uinfo -> ID ,
'user_login' => $user_id ,
'user_nicename' => $Realname ,
'user_email' => $user_email ,
'user_url' => 'http://' ,
'display_name' => $Realname )
);
2010-01-18 15:34:48 -05:00
} else {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_user ( array (
'user_login' => $user_id ,
'user_nicename' => csc ( $user_pseudo ),
'user_email' => $user_email ,
'user_url' => 'http://' ,
'display_name' => $Realname )
);
}
$dcid2wpid [ $user_id ] = $ret_id ;
2006-12-05 02:15:12 -05:00
// Set DotClear-to-WordPress permissions translation
2006-10-25 18:55:05 -04:00
// Update Usermeta Data
$user = new WP_User ( $ret_id );
$wp_perms = $user_level + 1 ;
2010-01-18 15:34:48 -05:00
if ( 10 == $wp_perms ) { $user -> set_role ( 'administrator' ); }
else if ( 9 == $wp_perms ) { $user -> set_role ( 'editor' ); }
else if ( 5 <= $wp_perms ) { $user -> set_role ( 'editor' ); }
else if ( 4 <= $wp_perms ) { $user -> set_role ( 'author' ); }
else if ( 3 <= $wp_perms ) { $user -> set_role ( 'contributor' ); }
else if ( 2 <= $wp_perms ) { $user -> set_role ( 'contributor' ); }
2006-10-25 18:55:05 -04:00
else { $user -> set_role ( 'subscriber' ); }
2010-02-22 16:25:32 -05:00
update_user_meta ( $ret_id , 'wp_user_level' , $wp_perms );
update_user_meta ( $ret_id , 'rich_editing' , 'false' );
update_user_meta ( $ret_id , 'first_name' , csc ( $user_prenom ));
update_user_meta ( $ret_id , 'last_name' , csc ( $user_nom ));
2006-10-25 18:55:05 -04:00
} // End foreach($users as $user)
// Store id translation array for future use
add_option ( 'dcid2wpid' , $dcid2wpid );
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> users imported.' ), $count ) . '<br /><br /></p>' ;
return true ;
} // End if(is_array($users)
echo __ ( 'No Users to Import!' );
return false ;
} // End function user2wp()
2010-01-18 15:34:48 -05:00
function posts2wp ( $posts = '' ) {
2006-10-25 18:55:05 -04:00
// General Housekeeping
global $wpdb ;
$count = 0 ;
$dcposts2wpposts = array ();
$cats = array ();
// Do the Magic
2010-01-18 15:34:48 -05:00
if ( is_array ( $posts )) {
2006-10-25 18:55:05 -04:00
echo '<p>' . __ ( 'Importing Posts...' ) . '<br /><br /></p>' ;
foreach ( $posts as $post )
{
$count ++ ;
extract ( $post );
2006-12-05 02:15:12 -05:00
// Set DotClear-to-WordPress status translation
2006-10-25 18:55:05 -04:00
$stattrans = array ( 0 => 'draft' , 1 => 'publish' );
$comment_status_map = array ( 0 => 'closed' , 1 => 'open' );
//Can we do this more efficiently?
$uinfo = ( get_userdatabylogin ( $user_id ) ) ? get_userdatabylogin ( $user_id ) : 1 ;
$authorid = ( is_object ( $uinfo ) ) ? $uinfo -> ID : $uinfo ;
$Title = $wpdb -> escape ( csc ( $post_titre ));
$post_content = textconv ( $post_content );
$post_excerpt = " " ;
if ( $post_chapo != " " ) {
$post_excerpt = textconv ( $post_chapo );
$post_content = $post_excerpt . " \n <!--more--> \n " . $post_content ;
}
$post_excerpt = $wpdb -> escape ( $post_excerpt );
$post_content = $wpdb -> escape ( $post_content );
$post_status = $stattrans [ $post_pub ];
// Import Post data into WordPress
2010-01-18 15:34:48 -05:00
if ( $pinfo = post_exists ( $Title , $post_content )) {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_post ( array (
'ID' => $pinfo ,
'post_author' => $authorid ,
'post_date' => $post_dt ,
'post_date_gmt' => $post_dt ,
'post_modified' => $post_upddt ,
'post_modified_gmt' => $post_upddt ,
'post_title' => $Title ,
'post_content' => $post_content ,
'post_excerpt' => $post_excerpt ,
'post_status' => $post_status ,
'post_name' => $post_titre_url ,
'comment_status' => $comment_status_map [ $post_open_comment ],
'ping_status' => $comment_status_map [ $post_open_tb ],
'comment_count' => $post_nb_comment + $post_nb_trackback )
);
2007-09-18 12:32:22 -04:00
if ( is_wp_error ( $ret_id ) )
return $ret_id ;
2010-01-18 15:34:48 -05:00
} else {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_post ( array (
'post_author' => $authorid ,
'post_date' => $post_dt ,
'post_date_gmt' => $post_dt ,
'post_modified' => $post_modified_gmt ,
'post_modified_gmt' => $post_modified_gmt ,
'post_title' => $Title ,
'post_content' => $post_content ,
'post_excerpt' => $post_excerpt ,
'post_status' => $post_status ,
'post_name' => $post_titre_url ,
'comment_status' => $comment_status_map [ $post_open_comment ],
'ping_status' => $comment_status_map [ $post_open_tb ],
'comment_count' => $post_nb_comment + $post_nb_trackback )
);
2007-09-18 12:32:22 -04:00
if ( is_wp_error ( $ret_id ) )
return $ret_id ;
2006-10-25 18:55:05 -04:00
}
$dcposts2wpposts [ $post_id ] = $ret_id ;
// Make Post-to-Category associations
$cats = array ();
2007-08-27 20:08:58 -04:00
$category1 = get_category_by_slug ( $post_cat_name );
$category1 = $category1 -> term_id ;
2010-01-18 15:34:48 -05:00
if ( $cat1 = $category1 ) { $cats [ 1 ] = $cat1 ; }
2006-10-25 18:55:05 -04:00
2010-01-18 15:34:48 -05:00
if ( ! empty ( $cats )) { wp_set_post_categories ( $ret_id , $cats ); }
2006-10-25 18:55:05 -04:00
}
}
// Store ID translation for later use
add_option ( 'dcposts2wpposts' , $dcposts2wpposts );
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> posts imported.' ), $count ) . '<br /><br /></p>' ;
return true ;
}
2010-01-18 15:34:48 -05:00
function comments2wp ( $comments = '' ) {
2006-10-25 18:55:05 -04:00
// General Housekeeping
global $wpdb ;
$count = 0 ;
$dccm2wpcm = array ();
$postarr = get_option ( 'dcposts2wpposts' );
// Magic Mojo
2010-01-18 15:34:48 -05:00
if ( is_array ( $comments )) {
2006-10-25 18:55:05 -04:00
echo '<p>' . __ ( 'Importing Comments...' ) . '<br /><br /></p>' ;
2010-01-18 15:34:48 -05:00
foreach ( $comments as $comment ) {
2006-10-25 18:55:05 -04:00
$count ++ ;
extract ( $comment );
// WordPressify Data
2007-03-22 20:59:21 -04:00
$comment_ID = ( int ) ltrim ( $comment_id , '0' );
$comment_post_ID = ( int ) $postarr [ $post_id ];
2009-12-23 10:16:53 -05:00
$comment_approved = $comment_pub ;
2006-10-25 18:55:05 -04:00
$name = $wpdb -> escape ( csc ( $comment_auteur ));
$email = $wpdb -> escape ( $comment_email );
$web = " http:// " . $wpdb -> escape ( $comment_site );
$message = $wpdb -> escape ( textconv ( $comment_content ));
2009-11-24 09:40:25 -05:00
$comment = array (
2006-10-25 18:55:05 -04:00
'comment_post_ID' => $comment_post_ID ,
'comment_author' => $name ,
'comment_author_email' => $email ,
'comment_author_url' => $web ,
'comment_author_IP' => $comment_ip ,
'comment_date' => $comment_dt ,
'comment_date_gmt' => $comment_dt ,
'comment_content' => $message ,
2009-11-24 09:40:25 -05:00
'comment_approved' => $comment_approved );
$comment = wp_filter_comment ( $comment );
if ( $cinfo = comment_exists ( $name , $comment_dt ) ) {
// Update comments
$comment [ 'comment_ID' ] = $cinfo ;
$ret_id = wp_update_comment ( $comment );
} else {
2006-10-25 18:55:05 -04:00
// Insert comments
2009-11-24 09:40:25 -05:00
$ret_id = wp_insert_comment ( $comment );
2006-10-25 18:55:05 -04:00
}
$dccm2wpcm [ $comment_ID ] = $ret_id ;
}
// Store Comment ID translation for future use
add_option ( 'dccm2wpcm' , $dccm2wpcm );
// Associate newly formed categories with posts
get_comment_count ( $ret_id );
echo '<p>' . sprintf ( __ ( 'Done! <strong>%1$s</strong> comments imported.' ), $count ) . '<br /><br /></p>' ;
return true ;
}
echo __ ( 'No Comments to Import!' );
return false ;
}
2010-01-18 15:34:48 -05:00
function links2wp ( $links = '' ) {
2006-10-25 18:55:05 -04:00
// General Housekeeping
global $wpdb ;
$count = 0 ;
// Deal with the links
2010-01-18 15:34:48 -05:00
if ( is_array ( $links )) {
2006-10-25 18:55:05 -04:00
echo '<p>' . __ ( 'Importing Links...' ) . '<br /><br /></p>' ;
2010-01-18 15:34:48 -05:00
foreach ( $links as $link ) {
2006-10-25 18:55:05 -04:00
$count ++ ;
extract ( $link );
if ( $title != " " ) {
2007-08-27 20:08:58 -04:00
if ( $cinfo = is_term ( csc ( $title ), 'link_category' )) {
$category = $cinfo [ 'term_id' ];
2006-10-25 18:55:05 -04:00
} else {
2007-08-27 20:08:58 -04:00
$category = wp_insert_term ( $wpdb -> escape ( csc ( $title )), 'link_category' );
$category = $category [ 'term_id' ];
2006-10-25 18:55:05 -04:00
}
} else {
$linkname = $wpdb -> escape ( csc ( $label ));
$description = $wpdb -> escape ( csc ( $title ));
2010-01-18 15:34:48 -05:00
if ( $linfo = link_exists ( $linkname )) {
2006-10-25 18:55:05 -04:00
$ret_id = wp_insert_link ( array (
'link_id' => $linfo ,
'link_url' => $href ,
'link_name' => $linkname ,
'link_category' => $category ,
'link_description' => $description )
);
} else {
$ret_id = wp_insert_link ( array (
'link_url' => $url ,
'link_name' => $linkname ,
'link_category' => $category ,
'link_description' => $description )
);
}
$dclinks2wplinks [ $link_id ] = $ret_id ;
}
}
add_option ( 'dclinks2wplinks' , $dclinks2wplinks );
echo '<p>' ;
2009-02-20 14:35:16 -05:00
printf ( _n ( 'Done! <strong>%s</strong> link or link category imported.' , 'Done! <strong>%s</strong> links or link categories imported.' , $count ), $count );
2006-10-25 18:55:05 -04:00
echo '<br /><br /></p>' ;
return true ;
}
echo __ ( 'No Links to Import!' );
return false ;
}
2010-01-18 15:34:48 -05:00
function import_categories () {
2006-10-25 18:55:05 -04:00
// Category Import
$cats = $this -> get_dc_cats ();
$this -> cat2wp ( $cats );
add_option ( 'dc_cats' , $cats );
echo '<form action="admin.php?import=dotclear&step=2" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
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' ));
2006-10-25 18:55:05 -04:00
echo '</form>' ;
}
2010-01-18 15:34:48 -05:00
function import_users () {
2006-10-25 18:55:05 -04:00
// User Import
2006-11-19 02:56:05 -05:00
$users = $this -> get_dc_users ();
2006-10-25 18:55:05 -04:00
$this -> users2wp ( $users );
echo '<form action="admin.php?import=dotclear&step=3" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
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' ));
2006-10-25 18:55:05 -04:00
echo '</form>' ;
}
2010-01-18 15:34:48 -05:00
function import_posts () {
2006-10-25 18:55:05 -04:00
// Post Import
$posts = $this -> get_dc_posts ();
2007-09-18 12:32:22 -04:00
$result = $this -> posts2wp ( $posts );
if ( is_wp_error ( $result ) )
return $result ;
2006-10-25 18:55:05 -04:00
echo '<form action="admin.php?import=dotclear&step=4" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
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' ));
2006-10-25 18:55:05 -04:00
echo '</form>' ;
}
2010-01-18 15:34:48 -05:00
function import_comments () {
2006-10-25 18:55:05 -04:00
// Comment Import
$comments = $this -> get_dc_comments ();
$this -> comments2wp ( $comments );
echo '<form action="admin.php?import=dotclear&step=5" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
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' ));
2006-10-25 18:55:05 -04:00
echo '</form>' ;
}
function import_links ()
{
//Link Import
$links = $this -> get_dc_links ();
$this -> links2wp ( $links );
add_option ( 'dc_links' , $links );
echo '<form action="admin.php?import=dotclear&step=6" method="post">' ;
2007-05-07 11:56:53 -04:00
wp_nonce_field ( 'import-dotclear' );
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' ));
2006-10-25 18:55:05 -04:00
echo '</form>' ;
}
2010-01-18 15:34:48 -05:00
function cleanup_dcimport () {
2006-10-25 18:55:05 -04:00
delete_option ( 'dcdbprefix' );
delete_option ( 'dc_cats' );
delete_option ( 'dcid2wpid' );
delete_option ( 'dccat2wpcat' );
delete_option ( 'dcposts2wpposts' );
delete_option ( 'dccm2wpcm' );
delete_option ( 'dclinks2wplinks' );
delete_option ( 'dcuser' );
delete_option ( 'dcpass' );
delete_option ( 'dcname' );
delete_option ( 'dchost' );
delete_option ( 'dccharset' );
2007-12-22 20:10:29 -05:00
do_action ( 'import_done' , 'dotclear' );
2006-10-25 18:55:05 -04:00
$this -> tips ();
}
2010-01-18 15:34:48 -05:00
function tips () {
2006-10-25 18:55:05 -04: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 DotClear, 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 DotClear, 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 DotClear 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.' ), '/wp-login.php' ) . '</p>' ;
2006-10-25 18:55:05 -04: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>' ;
2009-05-05 00:28:05 -04:00
echo '<p>' . __ ( 'Also, since you’re coming from DotClear, 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>' ;
2006-10-25 18:55:05 -04: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-10-25 18:55:05 -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>' ;
2006-10-25 18:55:05 -04: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>!' ), '../wp-login.php' ) . '</p>' ;
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
function db_form () {
2008-02-23 23:33:10 -05:00
echo '<table class="form-table">' ;
2006-12-05 02:15:12 -05:00
printf ( '<tr><th><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>' , __ ( 'DotClear Database User:' ));
2006-10-25 18:55:05 -04:00
printf ( '<tr><th><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>' , __ ( 'DotClear Database Password:' ));
2006-12-05 02:15:12 -05:00
printf ( '<tr><th><label for="dbname">%s</label></th><td><input type="text" name="dbname" id="dbname" /></td></tr>' , __ ( 'DotClear Database Name:' ));
2008-11-27 21:12:36 -05:00
printf ( '<tr><th><label for="dbhost">%s</label></th><td><input type="text" name="dbhost" id="dbhost" value="localhost" /></td></tr>' , __ ( 'DotClear Database Host:' ));
2006-10-25 18:55:05 -04:00
printf ( '<tr><th><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix" value="dc_"/></td></tr>' , __ ( 'DotClear Table prefix:' ));
printf ( '<tr><th><label for="dccharset">%s</label></th><td><input type="text" name="dccharset" id="dccharset" value="ISO-8859-15"/></td></tr>' , __ ( 'Originating character set:' ));
echo '</table>' ;
}
2010-01-18 15:34:48 -05:00
function dispatch () {
2006-10-25 18:55:05 -04:00
if ( empty ( $_GET [ 'step' ]))
$step = 0 ;
else
$step = ( int ) $_GET [ 'step' ];
$this -> header ();
2010-01-18 15:34:48 -05:00
if ( $step > 0 ) {
2007-05-07 11:56:53 -04:00
check_admin_referer ( 'import-dotclear' );
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dbuser' ]) {
2006-10-25 18:55:05 -04:00
if ( get_option ( 'dcuser' ))
delete_option ( 'dcuser' );
2007-05-07 11:56:53 -04:00
add_option ( 'dcuser' , sanitize_user ( $_POST [ 'dbuser' ], true ));
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dbpass' ]) {
2006-10-25 18:55:05 -04:00
if ( get_option ( 'dcpass' ))
delete_option ( 'dcpass' );
2007-05-07 11:56:53 -04:00
add_option ( 'dcpass' , sanitize_user ( $_POST [ 'dbpass' ], true ));
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dbname' ]) {
if ( get_option ( 'dcname' ))
2006-10-25 18:55:05 -04:00
delete_option ( 'dcname' );
2007-05-07 11:56:53 -04:00
add_option ( 'dcname' , sanitize_user ( $_POST [ 'dbname' ], true ));
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dbhost' ]) {
2006-10-25 18:55:05 -04:00
if ( get_option ( 'dchost' ))
delete_option ( 'dchost' );
2007-05-07 11:56:53 -04:00
add_option ( 'dchost' , sanitize_user ( $_POST [ 'dbhost' ], true ));
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dccharset' ]) {
if ( get_option ( 'dccharset' ))
2006-10-25 18:55:05 -04:00
delete_option ( 'dccharset' );
2007-05-07 11:56:53 -04:00
add_option ( 'dccharset' , sanitize_user ( $_POST [ 'dccharset' ], true ));
2006-10-25 18:55:05 -04:00
}
2010-01-18 15:34:48 -05:00
if ( $_POST [ 'dbprefix' ]) {
if ( get_option ( 'dcdbprefix' ))
2006-10-25 18:55:05 -04:00
delete_option ( 'dcdbprefix' );
2007-05-07 11:56:53 -04:00
add_option ( 'dcdbprefix' , sanitize_user ( $_POST [ 'dbprefix' ], true ));
2006-10-25 18:55:05 -04:00
}
}
2010-01-18 15:34:48 -05:00
switch ( $step ) {
2006-10-25 18:55:05 -04: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 ();
if ( is_wp_error ( $result ) )
echo $result -> get_error_message ();
2006-10-25 18:55:05 -04:00
break ;
case 4 :
$this -> import_comments ();
break ;
case 5 :
$this -> import_links ();
break ;
case 6 :
$this -> cleanup_dcimport ();
break ;
}
$this -> footer ();
}
2010-01-18 15:34:48 -05:00
function Dotclear_Import () {
2006-10-25 18:55:05 -04:00
// Nothing.
}
}
$dc_import = new Dotclear_Import ();
2008-08-14 02:30:38 -04:00
2008-02-27 17:05:50 -05:00
register_importer ( 'dotclear' , __ ( 'DotClear' ), __ ( 'Import categories, users, posts, comments, and links from a DotClear blog.' ), array ( $dc_import , 'dispatch' ));
2008-08-14 02:30:38 -04:00
2006-10-25 18:55:05 -04:00
?>