[ Root ] [ Search ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-admin/import/ -> dotclear.php (source)

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


Generated: Thu May 20 22:30:08 2010 Cross-referenced by PHPXref 0.7