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