X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0f29eadd474473203a1182f52af1aa82721cecbd..9cd344f9b14dd8e0743c1417fdb379b1431c3988:/wp-admin/import/dotclear.php?ds=sidebyside diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php index fd4f2d65..fcde9b17 100644 --- a/wp-admin/import/dotclear.php +++ b/wp-admin/import/dotclear.php @@ -1,155 +1,115 @@ get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); - - return $name; - } -} if(!function_exists('get_comment_count')) { + /** + * Get the comment count for posts. + * + * @package WordPress + * @subpackage Dotclear_Import + * + * @param int $post_ID Post ID + * @return int + */ function get_comment_count($post_ID) { global $wpdb; - return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); - } -} - -if(!function_exists('link_cat_exists')) -{ - function link_cat_exists($catname) - { - global $wpdb; - return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"'); + return $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) ); } } if(!function_exists('link_exists')) { + /** + * Check whether link already exists. + * + * @package WordPress + * @subpackage Dotclear_Import + * + * @param string $linkname + * @return int + */ function link_exists($linkname) { global $wpdb; - return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"'); + return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) ); } } -/* - Identify UTF-8 text - Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087 -*/ -// -// utf8 encoding validation developed based on Wikipedia entry at: -// http://en.wikipedia.org/wiki/UTF-8 -// -// Implemented as a recursive descent parser based on a simple state machine -// copyright 2005 Maarten Meijer -// -// This cries out for a C-implementation to be included in PHP core -// - -function valid_1byte($char) { - if(!is_int($char)) return false; - return ($char & 0x80) == 0x00; -} - -function valid_2byte($char) { - if(!is_int($char)) return false; - return ($char & 0xE0) == 0xC0; -} - -function valid_3byte($char) { - if(!is_int($char)) return false; - return ($char & 0xF0) == 0xE0; -} - -function valid_4byte($char) { - if(!is_int($char)) return false; - return ($char & 0xF8) == 0xF0; -} - -function valid_nextbyte($char) { - if(!is_int($char)) return false; - return ($char & 0xC0) == 0x80; -} - -function valid_utf8($string) { - $len = strlen($string); - $i = 0; - while( $i < $len ) { - $char = ord(substr($string, $i++, 1)); - if(valid_1byte($char)) { // continue - continue; - } else if(valid_2byte($char)) { // check 1 byte - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - } else if(valid_3byte($char)) { // check 2 bytes - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - } else if(valid_4byte($char)) { // check 3 bytes - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - if(!valid_nextbyte(ord(substr($string, $i++, 1)))) - return false; - } // goto next char - } - return true; // done -} - +/** + * Convert from dotclear charset to utf8 if required + * + * @package WordPress + * @subpackage Dotclear_Import + * + * @param string $s + * @return string + */ function csc ($s) { - if (valid_utf8 ($s)) { + if (seems_utf8 ($s)) { return $s; } else { return iconv(get_option ("dccharset"),"UTF-8",$s); } } +/** + * @package WordPress + * @subpackage Dotclear_Import + * + * @param string $s + * @return string + */ function textconv ($s) { return csc (preg_replace ('|(?)\s*\n|', ' ', $s)); } /** - The Main Importer Class -**/ + * Dotclear Importer class + * + * Will process the WordPress eXtended RSS files that you upload from the export + * file. + * + * @package WordPress + * @subpackage Importer + * + * @since unknown + */ class Dotclear_Import { - function header() + function header() { echo '
'; + screen_icon(); echo '

'.__('Import DotClear').'

'; echo '

'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'

'; } - function footer() + function footer() { echo '
'; } - function greet() + function greet() { echo '

'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog. Mileage may vary.').'

'; echo '

'.__('Your DotClear Configuration settings are as follows:').'

'; echo '
'; wp_nonce_field('import-dotclear'); $this->db_form(); - echo '

'; + echo '

'; echo '
'; } @@ -246,7 +206,7 @@ class Dotclear_Import { // Store category translation for future use add_option('dccat2wpcat',$dccat2wpcat); - echo '

'.sprintf(__('Done! %1$s categories imported.'), $count).'

'; + echo '

'.sprintf(_n('Done! %1$s category imported.', 'Done! %1$s categories imported.', $count), $count).'

'; return true; } echo __('No Categories to Import!'); @@ -385,6 +345,8 @@ class Dotclear_Import { 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } else { @@ -403,14 +365,19 @@ class Dotclear_Import { 'ping_status' => $comment_status_map[$post_open_tb], 'comment_count' => $post_nb_comment + $post_nb_trackback) ); + if ( is_wp_error( $ret_id ) ) + return $ret_id; } $dcposts2wpposts[$post_id] = $ret_id; // Make Post-to-Category associations $cats = array(); - if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; } + $category1 = get_category_by_slug($post_cat_name); + $category1 = $category1->term_id; + + if($cat1 = $category1) { $cats[1] = $cat1; } - if(!empty($cats)) { wp_set_post_cats('', $ret_id, $cats); } + if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); } } } // Store ID translation for later use @@ -446,11 +413,7 @@ class Dotclear_Import { $web = "http://".$wpdb->escape($comment_site); $message = $wpdb->escape(textconv ($comment_content)); - if($cinfo = comment_exists($name, $comment_dt)) - { - // Update comments - $ret_id = wp_update_comment(array( - 'comment_ID' => $cinfo, + $comment = array( 'comment_post_ID' => $comment_post_ID, 'comment_author' => $name, 'comment_author_email' => $email, @@ -459,23 +422,16 @@ class Dotclear_Import { 'comment_date' => $comment_dt, 'comment_date_gmt' => $comment_dt, 'comment_content' => $message, - 'comment_approved' => $comment_approved) - ); - } - else - { + '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 { // Insert comments - $ret_id = wp_insert_comment(array( - '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, - 'comment_approved' => $comment_approved) - ); + $ret_id = wp_insert_comment($comment); } $dccm2wpcm[$comment_ID] = $ret_id; } @@ -509,12 +465,11 @@ class Dotclear_Import { extract($link); if ($title != "") { - if ($cinfo = link_cat_exists (csc ($title))) { - $category = $cinfo; + if ($cinfo = is_term(csc ($title), 'link_category')) { + $category = $cinfo['term_id']; } else { - $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('". - $wpdb->escape (csc ($title))."')"); - $category = $wpdb->insert_id; + $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category'); + $category = $category['term_id']; } } else { $linkname = $wpdb->escape(csc ($label)); @@ -541,7 +496,7 @@ class Dotclear_Import { } add_option('dclinks2wplinks',$dclinks2wplinks); echo '

'; - printf(__('Done! %s links or link categories imported'), $count); + printf(_n('Done! %s link or link category imported.', 'Done! %s links or link categories imported.', $count), $count); echo '

'; return true; } @@ -560,7 +515,7 @@ class Dotclear_Import { echo '
'; wp_nonce_field('import-dotclear'); - printf('', attribute_escape(__('Import Users'))); + printf('

', esc_attr__('Import Users')); echo '
'; } @@ -573,7 +528,7 @@ class Dotclear_Import { echo '
'; wp_nonce_field('import-dotclear'); - printf('', attribute_escape(__('Import Posts'))); + printf('

', esc_attr__('Import Posts')); echo '
'; } @@ -581,11 +536,13 @@ class Dotclear_Import { { // Post Import $posts = $this->get_dc_posts(); - $this->posts2wp($posts); + $result = $this->posts2wp($posts); + if ( is_wp_error( $result ) ) + return $result; echo '
'; wp_nonce_field('import-dotclear'); - printf('', attribute_escape(__('Import Comments'))); + printf('

', esc_attr__('Import Comments')); echo '
'; } @@ -597,7 +554,7 @@ class Dotclear_Import { echo '
'; wp_nonce_field('import-dotclear'); - printf('', attribute_escape(__('Import Links'))); + printf('

', esc_attr__('Import Links')); echo '
'; } @@ -610,7 +567,7 @@ class Dotclear_Import { echo '
'; wp_nonce_field('import-dotclear'); - printf('', attribute_escape(__('Finish'))); + printf('

', esc_attr__('Finish')); echo '
'; } @@ -628,6 +585,7 @@ class Dotclear_Import { delete_option('dcname'); delete_option('dchost'); delete_option('dccharset'); + do_action('import_done', 'dotclear'); $this->tips(); } @@ -635,11 +593,11 @@ class Dotclear_Import { { echo '

'.__('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.').'

'; echo '

'.__('Users').'

'; - echo '

'.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. Every user has the same username, but their passwords are reset to password123. So Login and change it.'), '/wp-login.php').'

'; + echo '

'.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. Every user has the same username, but their passwords are reset to password123. So Log in and change it.'), '/wp-login.php').'

'; echo '

'.__('Preserving Authors').'

'; echo '

'.__('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.').'

'; echo '

'.__('Textile').'

'; - echo '

'.__('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 Textile for WordPress. Trust me... You\'ll want it.').'

'; + echo '

'.__('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 Textile for WordPress. Trust me… You’ll want it.').'

'; echo '

'.__('WordPress Resources').'

'; echo '

'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'

'; echo ''; - echo '

'.sprintf(__('That\'s it! What are you waiting for? Go login!'), '../wp-login.php').'

'; + echo '

'.sprintf(__('That’s it! What are you waiting for? Go log in!'), '../wp-login.php').'

'; } function db_form() { - echo ''; + echo '
'; printf('', __('DotClear Database User:')); printf('', __('DotClear Database Password:')); printf('', __('DotClear Database Name:')); - printf('', __('DotClear Database Host:')); + printf('', __('DotClear Database Host:')); printf('', __('DotClear Table prefix:')); printf('', __('Originating character set:')); echo '
'; @@ -729,7 +687,9 @@ class Dotclear_Import { $this->import_users(); break; case 3 : - $this->import_posts(); + $result = $this->import_posts(); + if ( is_wp_error( $result ) ) + echo $result->get_error_message(); break; case 4 : $this->import_comments(); @@ -752,5 +712,7 @@ class Dotclear_Import { } $dc_import = new Dotclear_Import(); -register_importer('dotclear', __('DotClear'), __('Import categories, users, posts, comments, and links from a DotClear blog'), array ($dc_import, 'dispatch')); + +register_importer('dotclear', __('DotClear'), __('Import categories, users, posts, comments, and links from a DotClear blog.'), array ($dc_import, 'dispatch')); + ?>