PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/import/dotclear.php

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