mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * DotClear Importer
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Importer
mp-wp_genesis 7 * @author Thomas Quinot
mp-wp_genesis 8 * @link http://thomas.quinot.org/
mp-wp_genesis 9 */
mp-wp_genesis 10
mp-wp_genesis 11 /**
mp-wp_genesis 12 Add These Functions to make our lives easier
mp-wp_genesis 13 **/
mp-wp_genesis 14
mp-wp_genesis 15 if(!function_exists('get_comment_count'))
mp-wp_genesis 16 {
mp-wp_genesis 17 /**
mp-wp_genesis 18 * Get the comment count for posts.
mp-wp_genesis 19 *
mp-wp_genesis 20 * @package WordPress
mp-wp_genesis 21 * @subpackage Dotclear_Import
mp-wp_genesis 22 *
mp-wp_genesis 23 * @param int $post_ID Post ID
mp-wp_genesis 24 * @return int
mp-wp_genesis 25 */
mp-wp_genesis 26 function get_comment_count($post_ID)
mp-wp_genesis 27 {
mp-wp_genesis 28 global $wpdb;
mp-wp_genesis 29 return $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
mp-wp_genesis 30 }
mp-wp_genesis 31 }
mp-wp_genesis 32
mp-wp_genesis 33 if(!function_exists('link_exists'))
mp-wp_genesis 34 {
mp-wp_genesis 35 /**
mp-wp_genesis 36 * Check whether link already exists.
mp-wp_genesis 37 *
mp-wp_genesis 38 * @package WordPress
mp-wp_genesis 39 * @subpackage Dotclear_Import
mp-wp_genesis 40 *
mp-wp_genesis 41 * @param string $linkname
mp-wp_genesis 42 * @return int
mp-wp_genesis 43 */
mp-wp_genesis 44 function link_exists($linkname)
mp-wp_genesis 45 {
mp-wp_genesis 46 global $wpdb;
mp-wp_genesis 47 return $wpdb->get_var( $wpdb->prepare("SELECT link_id FROM $wpdb->links WHERE link_name = %s", $linkname) );
mp-wp_genesis 48 }
mp-wp_genesis 49 }
mp-wp_genesis 50
mp-wp_genesis 51 /*
mp-wp_genesis 52 Identify UTF-8 text
mp-wp_genesis 53 Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087
mp-wp_genesis 54 */
mp-wp_genesis 55 //
mp-wp_genesis 56 // utf8 encoding validation developed based on Wikipedia entry at:
mp-wp_genesis 57 // http://en.wikipedia.org/wiki/UTF-8
mp-wp_genesis 58 //
mp-wp_genesis 59 // Implemented as a recursive descent parser based on a simple state machine
mp-wp_genesis 60 // copyright 2005 Maarten Meijer
mp-wp_genesis 61 //
mp-wp_genesis 62 // This cries out for a C-implementation to be included in PHP core
mp-wp_genesis 63 //
mp-wp_genesis 64
mp-wp_genesis 65 /**
mp-wp_genesis 66 * @package WordPress
mp-wp_genesis 67 * @subpackage Dotclear_Import
mp-wp_genesis 68 *
mp-wp_genesis 69 * @param string $char
mp-wp_genesis 70 * @return string
mp-wp_genesis 71 */
mp-wp_genesis 72 function valid_1byte($char) {
mp-wp_genesis 73 if(!is_int($char)) return false;
mp-wp_genesis 74 return ($char & 0x80) == 0x00;
mp-wp_genesis 75 }
mp-wp_genesis 76
mp-wp_genesis 77 /**
mp-wp_genesis 78 * @package WordPress
mp-wp_genesis 79 * @subpackage Dotclear_Import
mp-wp_genesis 80 *
mp-wp_genesis 81 * @param string $char
mp-wp_genesis 82 * @return string
mp-wp_genesis 83 */
mp-wp_genesis 84 function valid_2byte($char) {
mp-wp_genesis 85 if(!is_int($char)) return false;
mp-wp_genesis 86 return ($char & 0xE0) == 0xC0;
mp-wp_genesis 87 }
mp-wp_genesis 88
mp-wp_genesis 89 /**
mp-wp_genesis 90 * @package WordPress
mp-wp_genesis 91 * @subpackage Dotclear_Import
mp-wp_genesis 92 *
mp-wp_genesis 93 * @param string $char
mp-wp_genesis 94 * @return string
mp-wp_genesis 95 */
mp-wp_genesis 96 function valid_3byte($char) {
mp-wp_genesis 97 if(!is_int($char)) return false;
mp-wp_genesis 98 return ($char & 0xF0) == 0xE0;
mp-wp_genesis 99 }
mp-wp_genesis 100
mp-wp_genesis 101 /**
mp-wp_genesis 102 * @package WordPress
mp-wp_genesis 103 * @subpackage Dotclear_Import
mp-wp_genesis 104 *
mp-wp_genesis 105 * @param string $char
mp-wp_genesis 106 * @return string
mp-wp_genesis 107 */
mp-wp_genesis 108 function valid_4byte($char) {
mp-wp_genesis 109 if(!is_int($char)) return false;
mp-wp_genesis 110 return ($char & 0xF8) == 0xF0;
mp-wp_genesis 111 }
mp-wp_genesis 112
mp-wp_genesis 113 /**
mp-wp_genesis 114 * @package WordPress
mp-wp_genesis 115 * @subpackage Dotclear_Import
mp-wp_genesis 116 *
mp-wp_genesis 117 * @param string $char
mp-wp_genesis 118 * @return string
mp-wp_genesis 119 */
mp-wp_genesis 120 function valid_nextbyte($char) {
mp-wp_genesis 121 if(!is_int($char)) return false;
mp-wp_genesis 122 return ($char & 0xC0) == 0x80;
mp-wp_genesis 123 }
mp-wp_genesis 124
mp-wp_genesis 125 /**
mp-wp_genesis 126 * @package WordPress
mp-wp_genesis 127 * @subpackage Dotclear_Import
mp-wp_genesis 128 *
mp-wp_genesis 129 * @param string $string
mp-wp_genesis 130 * @return string
mp-wp_genesis 131 */
mp-wp_genesis 132 function valid_utf8($string) {
mp-wp_genesis 133 $len = strlen($string);
mp-wp_genesis 134 $i = 0;
mp-wp_genesis 135 while( $i < $len ) {
mp-wp_genesis 136 $char = ord(substr($string, $i++, 1));
mp-wp_genesis 137 if(valid_1byte($char)) { // continue
mp-wp_genesis 138 continue;
mp-wp_genesis 139 } else if(valid_2byte($char)) { // check 1 byte
mp-wp_genesis 140 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 141 return false;
mp-wp_genesis 142 } else if(valid_3byte($char)) { // check 2 bytes
mp-wp_genesis 143 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 144 return false;
mp-wp_genesis 145 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 146 return false;
mp-wp_genesis 147 } else if(valid_4byte($char)) { // check 3 bytes
mp-wp_genesis 148 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 149 return false;
mp-wp_genesis 150 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 151 return false;
mp-wp_genesis 152 if(!valid_nextbyte(ord(substr($string, $i++, 1))))
mp-wp_genesis 153 return false;
mp-wp_genesis 154 } // goto next char
mp-wp_genesis 155 }
mp-wp_genesis 156 return true; // done
mp-wp_genesis 157 }
mp-wp_genesis 158
mp-wp_genesis 159 /**
mp-wp_genesis 160 * @package WordPress
mp-wp_genesis 161 * @subpackage Dotclear_Import
mp-wp_genesis 162 *
mp-wp_genesis 163 * @param string $s
mp-wp_genesis 164 * @return string
mp-wp_genesis 165 */
mp-wp_genesis 166 function csc ($s) {
mp-wp_genesis 167 if (valid_utf8 ($s)) {
mp-wp_genesis 168 return $s;
mp-wp_genesis 169 } else {
mp-wp_genesis 170 return iconv(get_option ("dccharset"),"UTF-8",$s);
mp-wp_genesis 171 }
mp-wp_genesis 172 }
mp-wp_genesis 173
mp-wp_genesis 174 /**
mp-wp_genesis 175 * @package WordPress
mp-wp_genesis 176 * @subpackage Dotclear_Import
mp-wp_genesis 177 *
mp-wp_genesis 178 * @param string $s
mp-wp_genesis 179 * @return string
mp-wp_genesis 180 */
mp-wp_genesis 181 function textconv ($s) {
mp-wp_genesis 182 return csc (preg_replace ('|(?<!<br />)\s*\n|', ' ', $s));
mp-wp_genesis 183 }
mp-wp_genesis 184
mp-wp_genesis 185 /**
mp-wp_genesis 186 * Dotclear Importer class
mp-wp_genesis 187 *
mp-wp_genesis 188 * Will process the WordPress eXtended RSS files that you upload from the export
mp-wp_genesis 189 * file.
mp-wp_genesis 190 *
mp-wp_genesis 191 * @package WordPress
mp-wp_genesis 192 * @subpackage Importer
mp-wp_genesis 193 *
mp-wp_genesis 194 * @since unknown
mp-wp_genesis 195 */
mp-wp_genesis 196 class Dotclear_Import {
mp-wp_genesis 197
mp-wp_genesis 198 function header()
mp-wp_genesis 199 {
mp-wp_genesis 200 echo '<div class="wrap">';
mp-wp_genesis 201 screen_icon();
mp-wp_genesis 202 echo '<h2>'.__('Import DotClear').'</h2>';
mp-wp_genesis 203 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
mp-wp_genesis 204 }
mp-wp_genesis 205
mp-wp_genesis 206 function footer()
mp-wp_genesis 207 {
mp-wp_genesis 208 echo '</div>';
mp-wp_genesis 209 }
mp-wp_genesis 210
mp-wp_genesis 211 function greet()
mp-wp_genesis 212 {
mp-wp_genesis 213 echo '<div class="narrow"><p>'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog. Mileage may vary.').'</p>';
mp-wp_genesis 214 echo '<p>'.__('Your DotClear Configuration settings are as follows:').'</p>';
mp-wp_genesis 215 echo '<form action="admin.php?import=dotclear&step=1" method="post">';
mp-wp_genesis 216 wp_nonce_field('import-dotclear');
mp-wp_genesis 217 $this->db_form();
mp-wp_genesis 218 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.attribute_escape(__('Import Categories')).'" /></p>';
mp-wp_genesis 219 echo '</form></div>';
mp-wp_genesis 220 }
mp-wp_genesis 221
mp-wp_genesis 222 function get_dc_cats()
mp-wp_genesis 223 {
mp-wp_genesis 224 global $wpdb;
mp-wp_genesis 225 // General Housekeeping
mp-wp_genesis 226 $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
mp-wp_genesis 227 set_magic_quotes_runtime(0);
mp-wp_genesis 228 $dbprefix = get_option('dcdbprefix');
mp-wp_genesis 229
mp-wp_genesis 230 // Get Categories
mp-wp_genesis 231 return $dcdb->get_results('SELECT * FROM '.$dbprefix.'categorie', ARRAY_A);
mp-wp_genesis 232 }
mp-wp_genesis 233
mp-wp_genesis 234 function get_dc_users()
mp-wp_genesis 235 {
mp-wp_genesis 236 global $wpdb;
mp-wp_genesis 237 // General Housekeeping
mp-wp_genesis 238 $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
mp-wp_genesis 239 set_magic_quotes_runtime(0);
mp-wp_genesis 240 $dbprefix = get_option('dcdbprefix');
mp-wp_genesis 241
mp-wp_genesis 242 // Get Users
mp-wp_genesis 243
mp-wp_genesis 244 return $dcdb->get_results('SELECT * FROM '.$dbprefix.'user', ARRAY_A);
mp-wp_genesis 245 }
mp-wp_genesis 246
mp-wp_genesis 247 function get_dc_posts()
mp-wp_genesis 248 {
mp-wp_genesis 249 // General Housekeeping
mp-wp_genesis 250 $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
mp-wp_genesis 251 set_magic_quotes_runtime(0);
mp-wp_genesis 252 $dbprefix = get_option('dcdbprefix');
mp-wp_genesis 253
mp-wp_genesis 254 // Get Posts
mp-wp_genesis 255 return $dcdb->get_results('SELECT '.$dbprefix.'post.*, '.$dbprefix.'categorie.cat_libelle_url AS post_cat_name
mp-wp_genesis 256 FROM '.$dbprefix.'post INNER JOIN '.$dbprefix.'categorie
mp-wp_genesis 257 ON '.$dbprefix.'post.cat_id = '.$dbprefix.'categorie.cat_id', ARRAY_A);
mp-wp_genesis 258 }
mp-wp_genesis 259
mp-wp_genesis 260 function get_dc_comments()
mp-wp_genesis 261 {
mp-wp_genesis 262 global $wpdb;
mp-wp_genesis 263 // General Housekeeping
mp-wp_genesis 264 $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
mp-wp_genesis 265 set_magic_quotes_runtime(0);
mp-wp_genesis 266 $dbprefix = get_option('dcdbprefix');
mp-wp_genesis 267
mp-wp_genesis 268 // Get Comments
mp-wp_genesis 269 return $dcdb->get_results('SELECT * FROM '.$dbprefix.'comment', ARRAY_A);
mp-wp_genesis 270 }
mp-wp_genesis 271
mp-wp_genesis 272 function get_dc_links()
mp-wp_genesis 273 {
mp-wp_genesis 274 //General Housekeeping
mp-wp_genesis 275 $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost'));
mp-wp_genesis 276 set_magic_quotes_runtime(0);
mp-wp_genesis 277 $dbprefix = get_option('dcdbprefix');
mp-wp_genesis 278
mp-wp_genesis 279 return $dcdb->get_results('SELECT * FROM '.$dbprefix.'link ORDER BY position', ARRAY_A);
mp-wp_genesis 280 }
mp-wp_genesis 281
mp-wp_genesis 282 function cat2wp($categories='')
mp-wp_genesis 283 {
mp-wp_genesis 284 // General Housekeeping
mp-wp_genesis 285 global $wpdb;
mp-wp_genesis 286 $count = 0;
mp-wp_genesis 287 $dccat2wpcat = array();
mp-wp_genesis 288 // Do the Magic
mp-wp_genesis 289 if(is_array($categories))
mp-wp_genesis 290 {
mp-wp_genesis 291 echo '<p>'.__('Importing Categories...').'<br /><br /></p>';
mp-wp_genesis 292 foreach ($categories as $category)
mp-wp_genesis 293 {
mp-wp_genesis 294 $count++;
mp-wp_genesis 295 extract($category);
mp-wp_genesis 296
mp-wp_genesis 297 // Make Nice Variables
mp-wp_genesis 298 $name = $wpdb->escape($cat_libelle_url);
mp-wp_genesis 299 $title = $wpdb->escape(csc ($cat_libelle));
mp-wp_genesis 300 $desc = $wpdb->escape(csc ($cat_desc));
mp-wp_genesis 301
mp-wp_genesis 302 if($cinfo = category_exists($name))
mp-wp_genesis 303 {
mp-wp_genesis 304 $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc));
mp-wp_genesis 305 }
mp-wp_genesis 306 else
mp-wp_genesis 307 {
mp-wp_genesis 308 $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc));
mp-wp_genesis 309 }
mp-wp_genesis 310 $dccat2wpcat[$id] = $ret_id;
mp-wp_genesis 311 }
mp-wp_genesis 312
mp-wp_genesis 313 // Store category translation for future use
mp-wp_genesis 314 add_option('dccat2wpcat',$dccat2wpcat);
mp-wp_genesis 315 echo '<p>'.sprintf(__ngettext('Done! <strong>%1$s</strong> category imported.', 'Done! <strong>%1$s</strong> categories imported.', $count), $count).'<br /><br /></p>';
mp-wp_genesis 316 return true;
mp-wp_genesis 317 }
mp-wp_genesis 318 echo __('No Categories to Import!');
mp-wp_genesis 319 return false;
mp-wp_genesis 320 }
mp-wp_genesis 321
mp-wp_genesis 322 function users2wp($users='')
mp-wp_genesis 323 {
mp-wp_genesis 324 // General Housekeeping
mp-wp_genesis 325 global $wpdb;
mp-wp_genesis 326 $count = 0;
mp-wp_genesis 327 $dcid2wpid = array();
mp-wp_genesis 328
mp-wp_genesis 329 // Midnight Mojo
mp-wp_genesis 330 if(is_array($users))
mp-wp_genesis 331 {
mp-wp_genesis 332 echo '<p>'.__('Importing Users...').'<br /><br /></p>';
mp-wp_genesis 333 foreach($users as $user)
mp-wp_genesis 334 {
mp-wp_genesis 335 $count++;
mp-wp_genesis 336 extract($user);
mp-wp_genesis 337
mp-wp_genesis 338 // Make Nice Variables
mp-wp_genesis 339 $name = $wpdb->escape(csc ($name));
mp-wp_genesis 340 $RealName = $wpdb->escape(csc ($user_pseudo));
mp-wp_genesis 341
mp-wp_genesis 342 if($uinfo = get_userdatabylogin($name))
mp-wp_genesis 343 {
mp-wp_genesis 344
mp-wp_genesis 345 $ret_id = wp_insert_user(array(
mp-wp_genesis 346 'ID' => $uinfo->ID,
mp-wp_genesis 347 'user_login' => $user_id,
mp-wp_genesis 348 'user_nicename' => $Realname,
mp-wp_genesis 349 'user_email' => $user_email,
mp-wp_genesis 350 'user_url' => 'http://',
mp-wp_genesis 351 'display_name' => $Realname)
mp-wp_genesis 352 );
mp-wp_genesis 353 }
mp-wp_genesis 354 else
mp-wp_genesis 355 {
mp-wp_genesis 356 $ret_id = wp_insert_user(array(
mp-wp_genesis 357 'user_login' => $user_id,
mp-wp_genesis 358 'user_nicename' => csc ($user_pseudo),
mp-wp_genesis 359 'user_email' => $user_email,
mp-wp_genesis 360 'user_url' => 'http://',
mp-wp_genesis 361 'display_name' => $Realname)
mp-wp_genesis 362 );
mp-wp_genesis 363 }
mp-wp_genesis 364 $dcid2wpid[$user_id] = $ret_id;
mp-wp_genesis 365
mp-wp_genesis 366 // Set DotClear-to-WordPress permissions translation
mp-wp_genesis 367
mp-wp_genesis 368 // Update Usermeta Data
mp-wp_genesis 369 $user = new WP_User($ret_id);
mp-wp_genesis 370 $wp_perms = $user_level + 1;
mp-wp_genesis 371 if(10 == $wp_perms) { $user->set_role('administrator'); }
mp-wp_genesis 372 else if(9 == $wp_perms) { $user->set_role('editor'); }
mp-wp_genesis 373 else if(5 <= $wp_perms) { $user->set_role('editor'); }
mp-wp_genesis 374 else if(4 <= $wp_perms) { $user->set_role('author'); }
mp-wp_genesis 375 else if(3 <= $wp_perms) { $user->set_role('contributor'); }
mp-wp_genesis 376 else if(2 <= $wp_perms) { $user->set_role('contributor'); }
mp-wp_genesis 377 else { $user->set_role('subscriber'); }
mp-wp_genesis 378
mp-wp_genesis 379 update_usermeta( $ret_id, 'wp_user_level', $wp_perms);
mp-wp_genesis 380 update_usermeta( $ret_id, 'rich_editing', 'false');
mp-wp_genesis 381 update_usermeta( $ret_id, 'first_name', csc ($user_prenom));
mp-wp_genesis 382 update_usermeta( $ret_id, 'last_name', csc ($user_nom));
mp-wp_genesis 383 }// End foreach($users as $user)
mp-wp_genesis 384
mp-wp_genesis 385 // Store id translation array for future use
mp-wp_genesis 386 add_option('dcid2wpid',$dcid2wpid);
mp-wp_genesis 387
mp-wp_genesis 388
mp-wp_genesis 389 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>';
mp-wp_genesis 390 return true;
mp-wp_genesis 391 }// End if(is_array($users)
mp-wp_genesis 392
mp-wp_genesis 393 echo __('No Users to Import!');
mp-wp_genesis 394 return false;
mp-wp_genesis 395
mp-wp_genesis 396 }// End function user2wp()
mp-wp_genesis 397
mp-wp_genesis 398 function posts2wp($posts='')
mp-wp_genesis 399 {
mp-wp_genesis 400 // General Housekeeping
mp-wp_genesis 401 global $wpdb;
mp-wp_genesis 402 $count = 0;
mp-wp_genesis 403 $dcposts2wpposts = array();
mp-wp_genesis 404 $cats = array();
mp-wp_genesis 405
mp-wp_genesis 406 // Do the Magic
mp-wp_genesis 407 if(is_array($posts))
mp-wp_genesis 408 {
mp-wp_genesis 409 echo '<p>'.__('Importing Posts...').'<br /><br /></p>';
mp-wp_genesis 410 foreach($posts as $post)
mp-wp_genesis 411 {
mp-wp_genesis 412 $count++;
mp-wp_genesis 413 extract($post);
mp-wp_genesis 414
mp-wp_genesis 415 // Set DotClear-to-WordPress status translation
mp-wp_genesis 416 $stattrans = array(0 => 'draft', 1 => 'publish');
mp-wp_genesis 417 $comment_status_map = array (0 => 'closed', 1 => 'open');
mp-wp_genesis 418
mp-wp_genesis 419 //Can we do this more efficiently?
mp-wp_genesis 420 $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1;
mp-wp_genesis 421 $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ;
mp-wp_genesis 422
mp-wp_genesis 423 $Title = $wpdb->escape(csc ($post_titre));
mp-wp_genesis 424 $post_content = textconv ($post_content);
mp-wp_genesis 425 $post_excerpt = "";
mp-wp_genesis 426 if ($post_chapo != "") {
mp-wp_genesis 427 $post_excerpt = textconv ($post_chapo);
mp-wp_genesis 428 $post_content = $post_excerpt ."\n<!--more-->\n".$post_content;
mp-wp_genesis 429 }
mp-wp_genesis 430 $post_excerpt = $wpdb->escape ($post_excerpt);
mp-wp_genesis 431 $post_content = $wpdb->escape ($post_content);
mp-wp_genesis 432 $post_status = $stattrans[$post_pub];
mp-wp_genesis 433
mp-wp_genesis 434 // Import Post data into WordPress
mp-wp_genesis 435
mp-wp_genesis 436 if($pinfo = post_exists($Title,$post_content))
mp-wp_genesis 437 {
mp-wp_genesis 438 $ret_id = wp_insert_post(array(
mp-wp_genesis 439 'ID' => $pinfo,
mp-wp_genesis 440 'post_author' => $authorid,
mp-wp_genesis 441 'post_date' => $post_dt,
mp-wp_genesis 442 'post_date_gmt' => $post_dt,
mp-wp_genesis 443 'post_modified' => $post_upddt,
mp-wp_genesis 444 'post_modified_gmt' => $post_upddt,
mp-wp_genesis 445 'post_title' => $Title,
mp-wp_genesis 446 'post_content' => $post_content,
mp-wp_genesis 447 'post_excerpt' => $post_excerpt,
mp-wp_genesis 448 'post_status' => $post_status,
mp-wp_genesis 449 'post_name' => $post_titre_url,
mp-wp_genesis 450 'comment_status' => $comment_status_map[$post_open_comment],
mp-wp_genesis 451 'ping_status' => $comment_status_map[$post_open_tb],
mp-wp_genesis 452 'comment_count' => $post_nb_comment + $post_nb_trackback)
mp-wp_genesis 453 );
mp-wp_genesis 454 if ( is_wp_error( $ret_id ) )
mp-wp_genesis 455 return $ret_id;
mp-wp_genesis 456 }
mp-wp_genesis 457 else
mp-wp_genesis 458 {
mp-wp_genesis 459 $ret_id = wp_insert_post(array(
mp-wp_genesis 460 'post_author' => $authorid,
mp-wp_genesis 461 'post_date' => $post_dt,
mp-wp_genesis 462 'post_date_gmt' => $post_dt,
mp-wp_genesis 463 'post_modified' => $post_modified_gmt,
mp-wp_genesis 464 'post_modified_gmt' => $post_modified_gmt,
mp-wp_genesis 465 'post_title' => $Title,
mp-wp_genesis 466 'post_content' => $post_content,
mp-wp_genesis 467 'post_excerpt' => $post_excerpt,
mp-wp_genesis 468 'post_status' => $post_status,
mp-wp_genesis 469 'post_name' => $post_titre_url,
mp-wp_genesis 470 'comment_status' => $comment_status_map[$post_open_comment],
mp-wp_genesis 471 'ping_status' => $comment_status_map[$post_open_tb],
mp-wp_genesis 472 'comment_count' => $post_nb_comment + $post_nb_trackback)
mp-wp_genesis 473 );
mp-wp_genesis 474 if ( is_wp_error( $ret_id ) )
mp-wp_genesis 475 return $ret_id;
mp-wp_genesis 476 }
mp-wp_genesis 477 $dcposts2wpposts[$post_id] = $ret_id;
mp-wp_genesis 478
mp-wp_genesis 479 // Make Post-to-Category associations
mp-wp_genesis 480 $cats = array();
mp-wp_genesis 481 $category1 = get_category_by_slug($post_cat_name);
mp-wp_genesis 482 $category1 = $category1->term_id;
mp-wp_genesis 483
mp-wp_genesis 484 if($cat1 = $category1) { $cats[1] = $cat1; }
mp-wp_genesis 485
mp-wp_genesis 486 if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
mp-wp_genesis 487 }
mp-wp_genesis 488 }
mp-wp_genesis 489 // Store ID translation for later use
mp-wp_genesis 490 add_option('dcposts2wpposts',$dcposts2wpposts);
mp-wp_genesis 491
mp-wp_genesis 492 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> posts imported.'), $count).'<br /><br /></p>';
mp-wp_genesis 493 return true;
mp-wp_genesis 494 }
mp-wp_genesis 495
mp-wp_genesis 496 function comments2wp($comments='')
mp-wp_genesis 497 {
mp-wp_genesis 498 // General Housekeeping
mp-wp_genesis 499 global $wpdb;
mp-wp_genesis 500 $count = 0;
mp-wp_genesis 501 $dccm2wpcm = array();
mp-wp_genesis 502 $postarr = get_option('dcposts2wpposts');
mp-wp_genesis 503
mp-wp_genesis 504 // Magic Mojo
mp-wp_genesis 505 if(is_array($comments))
mp-wp_genesis 506 {
mp-wp_genesis 507 echo '<p>'.__('Importing Comments...').'<br /><br /></p>';
mp-wp_genesis 508 foreach($comments as $comment)
mp-wp_genesis 509 {
mp-wp_genesis 510 $count++;
mp-wp_genesis 511 extract($comment);
mp-wp_genesis 512
mp-wp_genesis 513 // WordPressify Data
mp-wp_genesis 514 $comment_ID = (int) ltrim($comment_id, '0');
mp-wp_genesis 515 $comment_post_ID = (int) $postarr[$post_id];
mp-wp_genesis 516 $comment_approved = "$comment_pub";
mp-wp_genesis 517 $name = $wpdb->escape(csc ($comment_auteur));
mp-wp_genesis 518 $email = $wpdb->escape($comment_email);
mp-wp_genesis 519 $web = "http://".$wpdb->escape($comment_site);
mp-wp_genesis 520 $message = $wpdb->escape(textconv ($comment_content));
mp-wp_genesis 521
mp-wp_genesis 522 if($cinfo = comment_exists($name, $comment_dt))
mp-wp_genesis 523 {
mp-wp_genesis 524 // Update comments
mp-wp_genesis 525 $ret_id = wp_update_comment(array(
mp-wp_genesis 526 'comment_ID' => $cinfo,
mp-wp_genesis 527 'comment_post_ID' => $comment_post_ID,
mp-wp_genesis 528 'comment_author' => $name,
mp-wp_genesis 529 'comment_author_email' => $email,
mp-wp_genesis 530 'comment_author_url' => $web,
mp-wp_genesis 531 'comment_author_IP' => $comment_ip,
mp-wp_genesis 532 'comment_date' => $comment_dt,
mp-wp_genesis 533 'comment_date_gmt' => $comment_dt,
mp-wp_genesis 534 'comment_content' => $message,
mp-wp_genesis 535 'comment_approved' => $comment_approved)
mp-wp_genesis 536 );
mp-wp_genesis 537 }
mp-wp_genesis 538 else
mp-wp_genesis 539 {
mp-wp_genesis 540 // Insert comments
mp-wp_genesis 541 $ret_id = wp_insert_comment(array(
mp-wp_genesis 542 'comment_post_ID' => $comment_post_ID,
mp-wp_genesis 543 'comment_author' => $name,
mp-wp_genesis 544 'comment_author_email' => $email,
mp-wp_genesis 545 'comment_author_url' => $web,
mp-wp_genesis 546 'comment_author_IP' => $comment_ip,
mp-wp_genesis 547 'comment_date' => $comment_dt,
mp-wp_genesis 548 'comment_date_gmt' => $comment_dt,
mp-wp_genesis 549 'comment_content' => $message,
mp-wp_genesis 550 'comment_approved' => $comment_approved)
mp-wp_genesis 551 );
mp-wp_genesis 552 }
mp-wp_genesis 553 $dccm2wpcm[$comment_ID] = $ret_id;
mp-wp_genesis 554 }
mp-wp_genesis 555 // Store Comment ID translation for future use
mp-wp_genesis 556 add_option('dccm2wpcm', $dccm2wpcm);
mp-wp_genesis 557
mp-wp_genesis 558 // Associate newly formed categories with posts
mp-wp_genesis 559 get_comment_count($ret_id);
mp-wp_genesis 560
mp-wp_genesis 561
mp-wp_genesis 562 echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> comments imported.'), $count).'<br /><br /></p>';
mp-wp_genesis 563 return true;
mp-wp_genesis 564 }
mp-wp_genesis 565 echo __('No Comments to Import!');
mp-wp_genesis 566 return false;
mp-wp_genesis 567 }
mp-wp_genesis 568
mp-wp_genesis 569 function links2wp($links='')
mp-wp_genesis 570 {
mp-wp_genesis 571 // General Housekeeping
mp-wp_genesis 572 global $wpdb;
mp-wp_genesis 573 $count = 0;
mp-wp_genesis 574
mp-wp_genesis 575 // Deal with the links
mp-wp_genesis 576 if(is_array($links))
mp-wp_genesis 577 {
mp-wp_genesis 578 echo '<p>'.__('Importing Links...').'<br /><br /></p>';
mp-wp_genesis 579 foreach($links as $link)
mp-wp_genesis 580 {
mp-wp_genesis 581 $count++;
mp-wp_genesis 582 extract($link);
mp-wp_genesis 583
mp-wp_genesis 584 if ($title != "") {
mp-wp_genesis 585 if ($cinfo = is_term(csc ($title), 'link_category')) {
mp-wp_genesis 586 $category = $cinfo['term_id'];
mp-wp_genesis 587 } else {
mp-wp_genesis 588 $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category');
mp-wp_genesis 589 $category = $category['term_id'];
mp-wp_genesis 590 }
mp-wp_genesis 591 } else {
mp-wp_genesis 592 $linkname = $wpdb->escape(csc ($label));
mp-wp_genesis 593 $description = $wpdb->escape(csc ($title));
mp-wp_genesis 594
mp-wp_genesis 595 if($linfo = link_exists($linkname)) {
mp-wp_genesis 596 $ret_id = wp_insert_link(array(
mp-wp_genesis 597 'link_id' => $linfo,
mp-wp_genesis 598 'link_url' => $href,
mp-wp_genesis 599 'link_name' => $linkname,
mp-wp_genesis 600 'link_category' => $category,
mp-wp_genesis 601 'link_description' => $description)
mp-wp_genesis 602 );
mp-wp_genesis 603 } else {
mp-wp_genesis 604 $ret_id = wp_insert_link(array(
mp-wp_genesis 605 'link_url' => $url,
mp-wp_genesis 606 'link_name' => $linkname,
mp-wp_genesis 607 'link_category' => $category,
mp-wp_genesis 608 'link_description' => $description)
mp-wp_genesis 609 );
mp-wp_genesis 610 }
mp-wp_genesis 611 $dclinks2wplinks[$link_id] = $ret_id;
mp-wp_genesis 612 }
mp-wp_genesis 613 }
mp-wp_genesis 614 add_option('dclinks2wplinks',$dclinks2wplinks);
mp-wp_genesis 615 echo '<p>';
mp-wp_genesis 616 printf(__ngettext('Done! <strong>%s</strong> link or link category imported.', 'Done! <strong>%s</strong> links or link categories imported.', $count), $count);
mp-wp_genesis 617 echo '<br /><br /></p>';
mp-wp_genesis 618 return true;
mp-wp_genesis 619 }
mp-wp_genesis 620 echo __('No Links to Import!');
mp-wp_genesis 621 return false;
mp-wp_genesis 622 }
mp-wp_genesis 623
mp-wp_genesis 624 function import_categories()
mp-wp_genesis 625 {
mp-wp_genesis 626 // Category Import
mp-wp_genesis 627 $cats = $this->get_dc_cats();
mp-wp_genesis 628 $this->cat2wp($cats);
mp-wp_genesis 629 add_option('dc_cats', $cats);
mp-wp_genesis 630
mp-wp_genesis 631
mp-wp_genesis 632
mp-wp_genesis 633 echo '<form action="admin.php?import=dotclear&step=2" method="post">';
mp-wp_genesis 634 wp_nonce_field('import-dotclear');
mp-wp_genesis 635 printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', attribute_escape(__('Import Users')));
mp-wp_genesis 636 echo '</form>';
mp-wp_genesis 637
mp-wp_genesis 638 }
mp-wp_genesis 639
mp-wp_genesis 640 function import_users()
mp-wp_genesis 641 {
mp-wp_genesis 642 // User Import
mp-wp_genesis 643 $users = $this->get_dc_users();
mp-wp_genesis 644 $this->users2wp($users);
mp-wp_genesis 645
mp-wp_genesis 646 echo '<form action="admin.php?import=dotclear&step=3" method="post">';
mp-wp_genesis 647 wp_nonce_field('import-dotclear');
mp-wp_genesis 648 printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', attribute_escape(__('Import Posts')));
mp-wp_genesis 649 echo '</form>';
mp-wp_genesis 650 }
mp-wp_genesis 651
mp-wp_genesis 652 function import_posts()
mp-wp_genesis 653 {
mp-wp_genesis 654 // Post Import
mp-wp_genesis 655 $posts = $this->get_dc_posts();
mp-wp_genesis 656 $result = $this->posts2wp($posts);
mp-wp_genesis 657 if ( is_wp_error( $result ) )
mp-wp_genesis 658 return $result;
mp-wp_genesis 659
mp-wp_genesis 660 echo '<form action="admin.php?import=dotclear&step=4" method="post">';
mp-wp_genesis 661 wp_nonce_field('import-dotclear');
mp-wp_genesis 662 printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', attribute_escape(__('Import Comments')));
mp-wp_genesis 663 echo '</form>';
mp-wp_genesis 664 }
mp-wp_genesis 665
mp-wp_genesis 666 function import_comments()
mp-wp_genesis 667 {
mp-wp_genesis 668 // Comment Import
mp-wp_genesis 669 $comments = $this->get_dc_comments();
mp-wp_genesis 670 $this->comments2wp($comments);
mp-wp_genesis 671
mp-wp_genesis 672 echo '<form action="admin.php?import=dotclear&step=5" method="post">';
mp-wp_genesis 673 wp_nonce_field('import-dotclear');
mp-wp_genesis 674 printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', attribute_escape(__('Import Links')));
mp-wp_genesis 675 echo '</form>';
mp-wp_genesis 676 }
mp-wp_genesis 677
mp-wp_genesis 678 function import_links()
mp-wp_genesis 679 {
mp-wp_genesis 680 //Link Import
mp-wp_genesis 681 $links = $this->get_dc_links();
mp-wp_genesis 682 $this->links2wp($links);
mp-wp_genesis 683 add_option('dc_links', $links);
mp-wp_genesis 684
mp-wp_genesis 685 echo '<form action="admin.php?import=dotclear&step=6" method="post">';
mp-wp_genesis 686 wp_nonce_field('import-dotclear');
mp-wp_genesis 687 printf('<p class="submit"><input type="submit" name="submit" class="button" value="%s" /></p>', attribute_escape(__('Finish')));
mp-wp_genesis 688 echo '</form>';
mp-wp_genesis 689 }
mp-wp_genesis 690
mp-wp_genesis 691 function cleanup_dcimport()
mp-wp_genesis 692 {
mp-wp_genesis 693 delete_option('dcdbprefix');
mp-wp_genesis 694 delete_option('dc_cats');
mp-wp_genesis 695 delete_option('dcid2wpid');
mp-wp_genesis 696 delete_option('dccat2wpcat');
mp-wp_genesis 697 delete_option('dcposts2wpposts');
mp-wp_genesis 698 delete_option('dccm2wpcm');
mp-wp_genesis 699 delete_option('dclinks2wplinks');
mp-wp_genesis 700 delete_option('dcuser');
mp-wp_genesis 701 delete_option('dcpass');
mp-wp_genesis 702 delete_option('dcname');
mp-wp_genesis 703 delete_option('dchost');
mp-wp_genesis 704 delete_option('dccharset');
mp-wp_genesis 705 do_action('import_done', 'dotclear');
mp-wp_genesis 706 $this->tips();
mp-wp_genesis 707 }
mp-wp_genesis 708
mp-wp_genesis 709 function tips()
mp-wp_genesis 710 {
mp-wp_genesis 711 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>';
mp-wp_genesis 712 echo '<h3>'.__('Users').'</h3>';
mp-wp_genesis 713 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">Login</a> and change it.'), '/wp-login.php').'</p>';
mp-wp_genesis 714 echo '<h3>'.__('Preserving Authors').'</h3>';
mp-wp_genesis 715 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>';
mp-wp_genesis 716 echo '<h3>'.__('Textile').'</h3>';
mp-wp_genesis 717 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>';
mp-wp_genesis 718 echo '<h3>'.__('WordPress Resources').'</h3>';
mp-wp_genesis 719 echo '<p>'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'</p>';
mp-wp_genesis 720 echo '<ul>';
mp-wp_genesis 721 echo '<li>'.__('<a href="http://www.wordpress.org">The official WordPress site</a>').'</li>';
mp-wp_genesis 722 echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
mp-wp_genesis 723 echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
mp-wp_genesis 724 echo '</ul>';
mp-wp_genesis 725 echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '../wp-login.php').'</p>';
mp-wp_genesis 726 }
mp-wp_genesis 727
mp-wp_genesis 728 function db_form()
mp-wp_genesis 729 {
mp-wp_genesis 730 echo '<table class="form-table">';
mp-wp_genesis 731 printf('<tr><th><label for="dbuser">%s</label></th><td><input type="text" name="dbuser" id="dbuser" /></td></tr>', __('DotClear Database User:'));
mp-wp_genesis 732 printf('<tr><th><label for="dbpass">%s</label></th><td><input type="password" name="dbpass" id="dbpass" /></td></tr>', __('DotClear Database Password:'));
mp-wp_genesis 733 printf('<tr><th><label for="dbname">%s</label></th><td><input type="text" name="dbname" id="dbname" /></td></tr>', __('DotClear Database Name:'));
mp-wp_genesis 734 printf('<tr><th><label for="dbhost">%s</label></th><td><input type="text" name="dbhost" id="dbhost" value="localhost" /></td></tr>', __('DotClear Database Host:'));
mp-wp_genesis 735 printf('<tr><th><label for="dbprefix">%s</label></th><td><input type="text" name="dbprefix" id="dbprefix" value="dc_"/></td></tr>', __('DotClear Table prefix:'));
mp-wp_genesis 736 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:'));
mp-wp_genesis 737 echo '</table>';
mp-wp_genesis 738 }
mp-wp_genesis 739
mp-wp_genesis 740 function dispatch()
mp-wp_genesis 741 {
mp-wp_genesis 742
mp-wp_genesis 743 if (empty ($_GET['step']))
mp-wp_genesis 744 $step = 0;
mp-wp_genesis 745 else
mp-wp_genesis 746 $step = (int) $_GET['step'];
mp-wp_genesis 747 $this->header();
mp-wp_genesis 748
mp-wp_genesis 749 if ( $step > 0 )
mp-wp_genesis 750 {
mp-wp_genesis 751 check_admin_referer('import-dotclear');
mp-wp_genesis 752
mp-wp_genesis 753 if($_POST['dbuser'])
mp-wp_genesis 754 {
mp-wp_genesis 755 if(get_option('dcuser'))
mp-wp_genesis 756 delete_option('dcuser');
mp-wp_genesis 757 add_option('dcuser', sanitize_user($_POST['dbuser'], true));
mp-wp_genesis 758 }
mp-wp_genesis 759 if($_POST['dbpass'])
mp-wp_genesis 760 {
mp-wp_genesis 761 if(get_option('dcpass'))
mp-wp_genesis 762 delete_option('dcpass');
mp-wp_genesis 763 add_option('dcpass', sanitize_user($_POST['dbpass'], true));
mp-wp_genesis 764 }
mp-wp_genesis 765
mp-wp_genesis 766 if($_POST['dbname'])
mp-wp_genesis 767 {
mp-wp_genesis 768 if(get_option('dcname'))
mp-wp_genesis 769 delete_option('dcname');
mp-wp_genesis 770 add_option('dcname', sanitize_user($_POST['dbname'], true));
mp-wp_genesis 771 }
mp-wp_genesis 772 if($_POST['dbhost'])
mp-wp_genesis 773 {
mp-wp_genesis 774 if(get_option('dchost'))
mp-wp_genesis 775 delete_option('dchost');
mp-wp_genesis 776 add_option('dchost', sanitize_user($_POST['dbhost'], true));
mp-wp_genesis 777 }
mp-wp_genesis 778 if($_POST['dccharset'])
mp-wp_genesis 779 {
mp-wp_genesis 780 if(get_option('dccharset'))
mp-wp_genesis 781 delete_option('dccharset');
mp-wp_genesis 782 add_option('dccharset', sanitize_user($_POST['dccharset'], true));
mp-wp_genesis 783 }
mp-wp_genesis 784 if($_POST['dbprefix'])
mp-wp_genesis 785 {
mp-wp_genesis 786 if(get_option('dcdbprefix'))
mp-wp_genesis 787 delete_option('dcdbprefix');
mp-wp_genesis 788 add_option('dcdbprefix', sanitize_user($_POST['dbprefix'], true));
mp-wp_genesis 789 }
mp-wp_genesis 790
mp-wp_genesis 791
mp-wp_genesis 792 }
mp-wp_genesis 793
mp-wp_genesis 794 switch ($step)
mp-wp_genesis 795 {
mp-wp_genesis 796 default:
mp-wp_genesis 797 case 0 :
mp-wp_genesis 798 $this->greet();
mp-wp_genesis 799 break;
mp-wp_genesis 800 case 1 :
mp-wp_genesis 801 $this->import_categories();
mp-wp_genesis 802 break;
mp-wp_genesis 803 case 2 :
mp-wp_genesis 804 $this->import_users();
mp-wp_genesis 805 break;
mp-wp_genesis 806 case 3 :
mp-wp_genesis 807 $result = $this->import_posts();
mp-wp_genesis 808 if ( is_wp_error( $result ) )
mp-wp_genesis 809 echo $result->get_error_message();
mp-wp_genesis 810 break;
mp-wp_genesis 811 case 4 :
mp-wp_genesis 812 $this->import_comments();
mp-wp_genesis 813 break;
mp-wp_genesis 814 case 5 :
mp-wp_genesis 815 $this->import_links();
mp-wp_genesis 816 break;
mp-wp_genesis 817 case 6 :
mp-wp_genesis 818 $this->cleanup_dcimport();
mp-wp_genesis 819 break;
mp-wp_genesis 820 }
mp-wp_genesis 821
mp-wp_genesis 822 $this->footer();
mp-wp_genesis 823 }
mp-wp_genesis 824
mp-wp_genesis 825 function Dotclear_Import()
mp-wp_genesis 826 {
mp-wp_genesis 827 // Nothing.
mp-wp_genesis 828 }
mp-wp_genesis 829 }
mp-wp_genesis 830
mp-wp_genesis 831 $dc_import = new Dotclear_Import();
mp-wp_genesis 832
mp-wp_genesis 833 register_importer('dotclear', __('DotClear'), __('Import categories, users, posts, comments, and links from a DotClear blog.'), array ($dc_import, 'dispatch'));
mp-wp_genesis 834
mp-wp_genesis 835 ?>