? .svn
? LICENSE.txt
Index: wordpress_import.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wordpress_import/wordpress_import.info,v
retrieving revision 1.2
diff -d -p -r1.2 wordpress_import.info
*** wordpress_import.info	1 Oct 2010 17:41:13 -0000	1.2
--- wordpress_import.info	26 Nov 2010 02:16:18 -0000
***************
*** 1,6 ****
  name = Wordpress import
  description = "Import WXR files created by Wordpress blog tool."
! core=6.x
  package = "Importing"
  dependencies[] = ctools
  php = 5.0
--- 1,8 ----
  name = Wordpress import
  description = "Import WXR files created by Wordpress blog tool."
! core=7.x
  package = "Importing"
  dependencies[] = ctools
  php = 5.0
+ files[] = wordpress_import.module
+ 
Index: wordpress_import.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wordpress_import/wordpress_import.module,v
retrieving revision 1.5
diff -d -p -r1.5 wordpress_import.module
*** wordpress_import.module	1 Oct 2010 17:41:13 -0000	1.5
--- wordpress_import.module	26 Nov 2010 02:16:19 -0000
***************
*** 27,40 ****
    */
  
  /**
!  * Implementation of hook_help()
   */
  function wordpress_import_help($path, $arg) {
    $output = '';
  
    switch ($path) {
      case "admin/help#wordpress_import":
!     $output = '<p>'.  t("This module imports a WXR file generated by Wordpress blog software into Drupal") .'</p>';
      break;
    }
  
--- 27,40 ----
    */
  
  /**
!  * Implements hook_help().
   */
  function wordpress_import_help($path, $arg) {
    $output = '';
  
    switch ($path) {
      case "admin/help#wordpress_import":
!     $output = '<p>' . t("This module imports a WXR file generated by Wordpress blog software into Drupal") . '</p>';
      break;
    }
  
*************** function wordpress_import_help($path, $a
*** 43,49 ****
  
  
  /**
!  * Implementation of hook_menu()
   */
  function wordpress_import_menu() {
    $items = array();
--- 43,49 ----
  
  
  /**
!  * Implements hook_menu().
   */
  function wordpress_import_menu() {
    $items = array();
*************** function wordpress_import_menu() {
*** 53,76 ****
      'description' => 'Import Wordpress WXR file',
      'page callback' => 'wordpress_import_home',
      'access arguments' => array('import wordpress blog'),
!     );
  
    return $items;
  }
  
  
  /**
!  * hook_perm
   *
!  * @return array perms
   * @author Yann Rocq
!  **/
! function wordpress_import_perm() {
!   return array('import wordpress blog');
  }
  
  /**
!  * Module entry point
   */
  function wordpress_import_home() {
  
--- 53,82 ----
      'description' => 'Import Wordpress WXR file',
      'page callback' => 'wordpress_import_home',
      'access arguments' => array('import wordpress blog'),
!     'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
!   );
  
    return $items;
  }
  
  
  /**
!  * Implements hook_permission().
   *
!  * @return array permissions
   * @author Yann Rocq
!  */
! function wordpress_import_permission() {
!   return array(
!     'import wordpress blog' => array(
!       'title' => t('Import WordPress blog'),
!       'description' => t('Perform the WordPress import from a WXR file.'),
!     ),
!   );
  }
  
  /**
!  * Module entry point.
   */
  function wordpress_import_home() {
  
*************** function wordpress_import_home() {
*** 79,85 ****
      drupal_set_message(t('<strong>XMLReader PHP extension not found!</strong>  The XMLReader extension is available in PECL as of PHP 5.0.0 and is included and enabled as of PHP 5.1.0 by default. It can be enabled by adding the argument --enable-xmlreader  (or --with-xmlreader before 5.1.0) to your configure line. The libxml  extension is required. '), 'error');
      return '';
    }
- 
    return wordpress_import_wizard();
  }
  
--- 85,90 ----
*************** function wordpress_import_home() {
*** 87,92 ****
--- 92,98 ----
   * Create and manage the multistep form
   */
  function wordpress_import_wizard() {
+ 
    $step = arg(3);
  
    ctools_include('wizard');
*************** function wordpress_import_wizard() {
*** 139,157 ****
  
    // *** SETTING THE FORM UP FOR MULTISTEP *** //
    $form_state = array(
!     'cache name' => NULL,
    );
  
!   $wordpress_import = wordpress_import_form_get_page_cache(NULL);
  
    if (!$wordpress_import && $step != '') {
      drupal_goto('admin/content/wordpress_import');
      return;
    }
  
!   if (!$wordpress_import) {
!     drupal_set_message($step);
      $step = current(array_keys($form_info['order']));
      $wordpress_import = new stdClass();
      ctools_object_cache_set('wordpress_import', $form_state['cache name'], $wordpress_import);
    }
--- 145,165 ----
  
    // *** SETTING THE FORM UP FOR MULTISTEP *** //
    $form_state = array(
!     'cache name' => '',
    );
  
!   $wordpress_import = wordpress_import_form_get_page_cache($form_state['cache name']);
  
    if (!$wordpress_import && $step != '') {
+     drupal_set_message(t('An illegal value has been chosen.'));
      drupal_goto('admin/content/wordpress_import');
      return;
    }
  
!   if (!$step) {
      $step = current(array_keys($form_info['order']));
+   }
+   if (!$wordpress_import) {
      $wordpress_import = new stdClass();
      ctools_object_cache_set('wordpress_import', $form_state['cache name'], $wordpress_import);
    }
*************** function wordpress_import_wizard() {
*** 167,179 ****
    if ($step == 'newusers' && !array_search('newuser', $wordpress_import->usermap)) {
      drupal_goto('admin/content/wordpress_import/ready');
    }
- 
    $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
    return $output;
  }
  
  
! /*---------------- CTools cache handling functions ------------ */
  
  function wordpress_import_form_clear_page_cache($name) {
    ctools_object_cache_clear('wordpress_import', $name);
--- 175,187 ----
    if ($step == 'newusers' && !array_search('newuser', $wordpress_import->usermap)) {
      drupal_goto('admin/content/wordpress_import/ready');
    }
    $output = ctools_wizard_multistep_form($form_info, $step, $form_state);
+ 
    return $output;
  }
  
  
! /* ---------------- CTools cache handling functions ------------ */
  
  function wordpress_import_form_clear_page_cache($name) {
    ctools_object_cache_clear('wordpress_import', $name);
*************** function wordpress_import_form_get_page_
*** 186,197 ****
  }
  
  
! /*-------------------------- Form Steps  ---------------------- */
  
! function wordpress_import_form_file(&$form, &$form_state) {
    global $base_path;
  
!   $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['informations'] = array(
     '#value' => t('This module will import a Wordpress eXtended RSS (WXR) file generated by Wordpress. If you need instructions on creating this file, please read the  <a href="@codex">documentation</a>. <em>You must make a backup copy of your Drupal database before proceeding!</em>', array('@codex' => url('http://codex.wordpress.org/Tools_Export_SubPanel')))
--- 194,205 ----
  }
  
  
! /* -------------------------- Form Steps  ---------------------- */
  
! function wordpress_import_form_file($form, &$form_state) {
    global $base_path;
  
!   $wordpress_import = $form_state['wordpress_import_obj'];
  
    $form['informations'] = array(
     '#value' => t('This module will import a Wordpress eXtended RSS (WXR) file generated by Wordpress. If you need instructions on creating this file, please read the  <a href="@codex">documentation</a>. <em>You must make a backup copy of your Drupal database before proceeding!</em>', array('@codex' => url('http://codex.wordpress.org/Tools_Export_SubPanel')))
*************** function wordpress_import_form_file(&$fo
*** 202,225 ****
      '#type' => 'file',
      '#title' => t('Upload your WXR file'),
      '#size' => 40,
      '#description' => t('The file can\'t exceed %maximum megabytes', array('%maximum' => $base_path . file_upload_max_size()/1024/1024)),
    );
  
    // Create and scan module directory
!   $wordpress_import_path = file_create_path('wordpress');
!   file_check_directory($wordpress_import_path, TRUE);
!   $files = file_scan_directory($wordpress_import_path, '.*\.xml');
  
    if (count($files) > 0) {
!     foreach (file_scan_directory($wordpress_import_path, '.*\.xml') as $file) {
!       $options[$file->basename] = $file->basename;
      }
      ksort($options);
      $description = '';
    }
    else {
      $options = array();
!     $description = t('No files found in %directory', array('%directory' => file_create_path(file_directory_path() .'/wordpress')));
    }
  
    // Local file selector element
--- 210,234 ----
      '#type' => 'file',
      '#title' => t('Upload your WXR file'),
      '#size' => 40,
+     '#attributes' => array('accept' => 'xml'),
      '#description' => t('The file can\'t exceed %maximum megabytes', array('%maximum' => $base_path . file_upload_max_size()/1024/1024)),
    );
  
    // Create and scan module directory
!   $path = file_default_scheme() . '://wordpress';
!   file_prepare_directory($path, FILE_CREATE_DIRECTORY);
!   $files = file_scan_directory($path, '/.*\.xml/');
  
    if (count($files) > 0) {
!     foreach (file_scan_directory($path, '/.*\.xml/') as $file) {
!       $options[basename($file->filename)] = basename($file->filename);
      }
      ksort($options);
      $description = '';
    }
    else {
      $options = array();
!     $description = t('No files found in %directory', array('%directory' => drupal_realpath($path)));
    }
  
    // Local file selector element
*************** function wordpress_import_form_file(&$fo
*** 233,238 ****
--- 242,248 ----
    $form['#attributes'] = array('enctype' => "multipart/form-data");
  
    $form_state['no buttons'] = TRUE;
+   return $form;
  }
  
  
*************** function wordpress_import_form_file_subm
*** 291,297 ****
  }
  
  
! function wordpress_import_form_options(&$form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['basic_options'] = array(
--- 301,307 ----
  }
  
  
! function wordpress_import_form_options($form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['basic_options'] = array(
*************** function wordpress_import_form_options(&
*** 302,308 ****
    );
  
    // Post content type
!   $node_types = node_get_types();
    $content_types = array('' => '', 'noimport' => t('Don\'t import'));
    foreach ($node_types as $k => $v) {
        if (!module_exists('og') || (module_exists('og') && !og_is_group_type($k))) {
--- 312,318 ----
    );
  
    // Post content type
!   $node_types = node_type_get_types();
    $content_types = array('' => '', 'noimport' => t('Don\'t import'));
    foreach ($node_types as $k => $v) {
        if (!module_exists('og') || (module_exists('og') && !og_is_group_type($k))) {
*************** function wordpress_import_form_options(&
*** 312,325 ****
    $form['basic_options']['nodetype_post'] = array(
      '#type' => 'select',
      '#title' => t('Import posts in content type'),
!     '#description' => t('All imported posts will be assigned the selected content type. If you are unsure, select "Story"'),
      '#default_value' => '',
      '#options' => $content_types,
      );
    $form['basic_options']['nodetype_page'] = array(
      '#type' => 'select',
      '#title' => t('Import pages in content type'),
!     '#description' => t('All imported pages will be assigned the selected content type. If you are unsure, select "Page"'),
      '#default_value' => '',
      '#options' => $content_types,
      );
--- 322,335 ----
    $form['basic_options']['nodetype_post'] = array(
      '#type' => 'select',
      '#title' => t('Import posts in content type'),
!     '#description' => t('All imported posts will be assigned the selected content type. If you are unsure, select "Article"'),
      '#default_value' => '',
      '#options' => $content_types,
      );
    $form['basic_options']['nodetype_page'] = array(
      '#type' => 'select',
      '#title' => t('Import pages in content type'),
!     '#description' => t('All imported pages will be assigned the selected content type. If you are unsure, select "Basic page"'),
      '#default_value' => '',
      '#options' => $content_types,
      );
*************** function wordpress_import_form_options(&
*** 405,417 ****
        $form['advanced_options']['#collapsed'] = FALSE;
    }
    if (!module_exists('comment')) {
!       drupal_set_message(t('Could not find module "comment". <strong>Comments and tackbacks will not be imported.</strong>'), 'error');
        $form['advanced_options']['disable_comments']['#default_value'] = TRUE;
        $form['advanced_options']['disable_comments']['#disabled'] = TRUE;
        $form['advanced_options']['#collapsed'] = FALSE;
    }
    if (!module_exists('trackback')) {
!       drupal_set_message(t('Could not find module "trackback". <strong>Trackbacks will not be imported.</strong>'), 'error');
        $form['advanced_options']['disable_trackbacks']['#default_value'] = TRUE;
        $form['advanced_options']['disable_trackbacks']['#disabled'] = TRUE;
        $form['advanced_options']['#collapsed'] = FALSE;
--- 415,427 ----
        $form['advanced_options']['#collapsed'] = FALSE;
    }
    if (!module_exists('comment')) {
!       drupal_set_message(t('Could not find module "comment". <strong>Comments and trackbacks will not be imported.</strong>'), 'error');
        $form['advanced_options']['disable_comments']['#default_value'] = TRUE;
        $form['advanced_options']['disable_comments']['#disabled'] = TRUE;
        $form['advanced_options']['#collapsed'] = FALSE;
    }
    if (!module_exists('trackback')) {
!       drupal_set_message(t('Trackback module has not been ported to Drupal 7. <strong>Trackbacks will not be imported.</strong> See <a href="http://drupal.org/node/977686">http://drupal.org/node/977686</a> for more details.'), 'warning');
        $form['advanced_options']['disable_trackbacks']['#default_value'] = TRUE;
        $form['advanced_options']['disable_trackbacks']['#disabled'] = TRUE;
        $form['advanced_options']['#collapsed'] = FALSE;
*************** function wordpress_import_form_options(&
*** 426,431 ****
--- 436,442 ----
        $form['advanced_options']['images']['#default_value'] = FALSE;
        $form['advanced_options']['images']['#disabled'] = TRUE;
    }
+   return $form;
  }
  
  
*************** function wordpress_import_form_options_s
*** 485,491 ****
  }
  
  
! function wordpress_import_form_og(&$form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['informations'] = array(
--- 496,502 ----
  }
  
  
! function wordpress_import_form_og($form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['informations'] = array(
*************** function wordpress_import_form_og(&$form
*** 507,512 ****
--- 518,524 ----
      '#description' => t('Show this post to everyone, or only to members of the groups checked above. Posts without any groups are always <em>public</em>.'),
      );
    }
+   return $form;
  }
  
  
*************** function wordpress_import_form_og_submit
*** 516,531 ****
  }
  
  
! function wordpress_import_form_mapusers(&$form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    // Get Drupal users
    $sql = "SELECT * FROM {users} ORDER BY name ASC";
    $result =  db_query($sql);
  
!   while ($drupal_user = db_fetch_array($result)) {
!     if (!empty($drupal_user['uid'])) {
!       $drupal_users[$drupal_user['uid']] = $drupal_user['name'];
      }
    }
  
--- 528,543 ----
  }
  
  
! function wordpress_import_form_mapusers($form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    // Get Drupal users
    $sql = "SELECT * FROM {users} ORDER BY name ASC";
    $result =  db_query($sql);
  
!   foreach ($result as $drupal_user) {
!     if (!empty($drupal_user->uid)) {
!       $drupal_users[$drupal_user->uid] = $drupal_user->name;
      }
    }
  
*************** function wordpress_import_form_mapusers(
*** 562,567 ****
--- 574,580 ----
      }
  
    }
+   return $form;
  }
  
  
*************** function wordpress_import_form_mapusers_
*** 604,610 ****
  }
  
  
! function wordpress_import_form_newusers(&$form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['newuser'] = array('#tree' => TRUE);
--- 617,623 ----
  }
  
  
! function wordpress_import_form_newusers($form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
  
    $form['newuser'] = array('#tree' => TRUE);
*************** function wordpress_import_form_newusers(
*** 627,632 ****
--- 640,646 ----
      }
  
    }
+   return $form;
  }
  
  
*************** function wordpress_import_form_newusers_
*** 643,652 ****
      if ($error = user_validate_name($value['name'])) {
        form_set_error('newuser]['. $key .'][name', $error);
      }
!     elseif (user_load(array('name' => $value['name']))) {
        form_set_error('newuser]['. $key .'][name', t('User !user already exists.', array('!user' => $value['name'])));
      }
!     elseif (is_array($user['name']) && in_array(strtolower($value['name']), $user['name'])) {
        form_set_error('newuser]['. $key .'][name', t('Two users have the same name (!user).', array('!user' => $value['name'])));
      }
  
--- 657,666 ----
      if ($error = user_validate_name($value['name'])) {
        form_set_error('newuser]['. $key .'][name', $error);
      }
!     elseif (user_load_by_name($value['name'])) {
        form_set_error('newuser]['. $key .'][name', t('User !user already exists.', array('!user' => $value['name'])));
      }
!     elseif (is_array($user['name']) && in_array(drupal_strtolower($value['name']), $user['name'])) {
        form_set_error('newuser]['. $key .'][name', t('Two users have the same name (!user).', array('!user' => $value['name'])));
      }
  
*************** function wordpress_import_form_newusers_
*** 654,668 ****
      if ($error = user_validate_mail($value['mail'])) {
        form_set_error('newuser]['. $key .'][mail', $error);
      }
!     elseif (user_load(array('mail' => $value['mail']))) {
        form_set_error('newuser]['. $key .'][mail', t('User with mail !mail already exists.', array('!mail' => $value['mail'])));
      }
!     elseif (is_array($user['mail']) && in_array(strtolower($value['mail']), $user['mail'])) {
        form_set_error('newuser]['. $key .'][mail', t('Two users have the same mail (!mail).', array('!mail' => $value['mail'])));
      }
  
!     $user['name'][] = strtolower($value['name']);
!     $user['mail'][] = strtolower($value['mail']);
    }
  }
  
--- 668,682 ----
      if ($error = user_validate_mail($value['mail'])) {
        form_set_error('newuser]['. $key .'][mail', $error);
      }
!     elseif (user_load_by_mail($value['mail'])) {
        form_set_error('newuser]['. $key .'][mail', t('User with mail !mail already exists.', array('!mail' => $value['mail'])));
      }
!     elseif (is_array($user['mail']) && in_array(drupal_strtolower($value['mail']), $user['mail'])) {
        form_set_error('newuser]['. $key .'][mail', t('Two users have the same mail (!mail).', array('!mail' => $value['mail'])));
      }
  
!     $user['name'][] = drupal_strtolower($value['name']);
!     $user['mail'][] = drupal_strtolower($value['mail']);
    }
  }
  
*************** function wordpress_import_form_newusers_
*** 672,680 ****
  }
  
  
! function wordpress_import_form_ready(&$form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
!   
    if (function_exists('dpm')) {
      dpm($wordpress_import);
    }
--- 686,694 ----
  }
  
  
! function wordpress_import_form_ready($form, &$form_state) {
    $wordpress_import = &$form_state['wordpress_import_obj'];
! 
    if (function_exists('dpm')) {
      dpm($wordpress_import);
    }
*************** function wordpress_import_form_ready(&$f
*** 682,687 ****
--- 696,702 ----
    $form['informations'] = array(
     '#value' => t('Wordpress Import configuration is complete. Click "Finish" to launch the import process.'),
    );
+   return $form;
  }
  
  
*************** function wordpress_import_form_subtask_c
*** 697,703 ****
    ctools_object_cache_clear('wordpress_import', $form_state['cache name']);
    $form_state['redirect'] = 'admin/content/wordpress_import';
    drupal_get_messages();
!   drupal_set_message('Import operation cancelled.');
  }
  
  
--- 712,718 ----
    ctools_object_cache_clear('wordpress_import', $form_state['cache name']);
    $form_state['redirect'] = 'admin/content/wordpress_import';
    drupal_get_messages();
!   drupal_set_message(t('Import operation cancelled.'));
  }
  
  
*************** function wordpress_import_process_blog($
*** 788,796 ****
    if (!$context['sandbox']['format_done']) {
      $wordpress_import->format = variable_get('wordpress_import_format_id', 0);
      if (!$wordpress_import->format || !filter_formats($wordpress_import->format)) {
!       db_query("INSERT INTO {filter_formats} (name,cache) VALUES ('%s',1)", 'Wordpress format');
!       $wordpress_import->format = db_result(db_query("SELECT MAX(format) AS format FROM {filter_formats}"));
!       db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $wordpress_import->format, 'filter', 2, 0);
        variable_set('wordpress_import_format_id', $wordpress_import->format);
      }
      $context['sandbox']['format_done'] = TRUE;
--- 803,827 ----
    if (!$context['sandbox']['format_done']) {
      $wordpress_import->format = variable_get('wordpress_import_format_id', 0);
      if (!$wordpress_import->format || !filter_formats($wordpress_import->format)) {
!       $wordpress_format = array(
!         'format' => 'wordpress_format',
!         'name' => 'Wordpress format',
!         'cache' => 1,
!       );
!       $wordpress_format = (object) $wordpress_format;
!       filter_format_save($wordpress_format);
!       $wordpress_import->format = $wordpress_format->format;
!       // TODO: Ensure the following {filters} table insert is no longer needed.
!       /*
!       db_insert('filters')
!         ->fields(array(
!           'format' => $wordpress_import->format,
!           'module' => 'filter',
!           'delta' => 2,
!           'weight' => 0
!         ))
!         ->execute();
!       */
        variable_set('wordpress_import_format_id', $wordpress_import->format);
      }
      $context['sandbox']['format_done'] = TRUE;
*************** function wordpress_import_process_catego
*** 861,867 ****
            $term['parent'] = $wordpress_import->categories_map[$category['category_parent']];
          }
  
!         taxonomy_save_term($term);
          $wordpress_import->categories_map[$category['cat_name']] = $term['tid'];
  
          $context['results']['created_terms']++;
--- 892,898 ----
            $term['parent'] = $wordpress_import->categories_map[$category['category_parent']];
          }
  
!         taxonomy_term_save((object) $term);
          $wordpress_import->categories_map[$category['cat_name']] = $term['tid'];
  
          $context['results']['created_terms']++;
*************** function wordpress_import_process_catego
*** 892,898 ****
            'vid' => $wordpress_import->tags_vocabulary,
            );
  
!         taxonomy_save_term($term);
          $wordpress_import->tags_map[$tag] = $term['tid'];
  
          $context['results']['created_terms']++;
--- 923,929 ----
            'vid' => $wordpress_import->tags_vocabulary,
            );
  
!         taxonomy_term_save((object) $term);
          $wordpress_import->tags_map[$tag] = $term['tid'];
  
          $context['results']['created_terms']++;
*************** function wordpress_import_process_post(&
*** 1078,1084 ****
    $node['comment'] = $post['comment_status']=='open'?COMMENT_NODE_READ_WRITE:COMMENT_NODE_READ_ONLY;
  
    // Check if node wasn't already imported
!   $context['sandbox']['node_duplicate'] = node_load(array('created' => $node['created'], 'title' => $node['title'], 'type' => $node['type']));
    if ($context['sandbox']['node_duplicate']->nid) {
      if (module_exists('comment') && !empty($post['comments'])) {
        wordpress_import_process_post_comments($post['comments'], $context['sandbox']['node_duplicate']->nid, $wordpress_import->options['disable_trackbacks'], $context);
--- 1109,1115 ----
    $node['comment'] = $post['comment_status']=='open'?COMMENT_NODE_READ_WRITE:COMMENT_NODE_READ_ONLY;
  
    // Check if node wasn't already imported
!   $context['sandbox']['node_duplicate'] = node_load_multiple(FALSE, array('created' => $node['created'], 'title' => $node['title'], 'type' => $node['type']));
    if ($context['sandbox']['node_duplicate']->nid) {
      if (module_exists('comment') && !empty($post['comments'])) {
        wordpress_import_process_post_comments($post['comments'], $context['sandbox']['node_duplicate']->nid, $wordpress_import->options['disable_trackbacks'], $context);
*************** function wordpress_import_process_post(&
*** 1150,1156 ****
  function wordpress_import_process_post_link($link, $baseurl) {
  
    $path = $link;
!   $path = substr($path, strlen($baseurl));
    $path = rtrim($path, '/');
  
    // Check for Wordpress ugly permalinks and replace with proper Drupal-style aliases
--- 1181,1187 ----
  function wordpress_import_process_post_link($link, $baseurl) {
  
    $path = $link;
!   $path = drupal_substr($path, drupal_strlen($baseurl));
    $path = rtrim($path, '/');
  
    // Check for Wordpress ugly permalinks and replace with proper Drupal-style aliases
*************** function wordpress_import_process_post_c
*** 1232,1238 ****
              );
            // Check if duplicate
            if ($node_duplicate) {
!             $tr = db_query("SELECT tr.trid FROM {trackback_received} tr WHERE tr.nid = %d AND tr.created = %d", $node_duplicate->nid, $node_trackback['created']);
              if ($tr->trid && $tr->excerpt == $node_trackback['excerpt']) {
                continue 2;
              }
--- 1263,1273 ----
              );
            // Check if duplicate
            if ($node_duplicate) {
!             $tr = db_query("SELECT tr.trid FROM {trackback_received} tr WHERE tr.nid = :nid AND tr.created = :created",
!               array(
!                 ':nid' => $node_duplicate->nid,
!                 ':created' => $node_trackback['created'],
!             ));
              if ($tr->trid && $tr->excerpt == $node_trackback['excerpt']) {
                continue 2;
              }
*************** function wordpress_import_process_post_c
*** 1246,1264 ****
          $node_comment = array(
            'nid' => $nid,
            'pid' => 0,
!           'comment' => $comment['content'],
!           'subject' => trim(truncate_utf8(decode_entities(strip_tags($comment['content'])), 29, TRUE)),
            'name' => decode_entities(strip_tags($comment['author'])),
            'mail' => $comment['author_email'],
            'homepage' => $comment['author_url'],
!           'timestamp' => strtotime($comment['date']),
            'hostname' => $comment['author_IP'],
            'status' => $status,
!           'format' => $wordpress_import->format
            );
          // Check if duplicate
          if ($node_duplicate) {
!           $c = db_query("SELECT c.cid, c.comment FROM {comments} c WHERE c.nid = %d AND c.timestamp = %d", $node_duplicate->nid, $node_comment['timestamp']);
            if ($c->cid && $c->comment == $node_comment['comment']) {
              continue 2;
            }
--- 1281,1307 ----
          $node_comment = array(
            'nid' => $nid,
            'pid' => 0,
!           'subject' => truncate_utf8(trim(decode_entities(strip_tags($comment['content']))), 29, TRUE),
            'name' => decode_entities(strip_tags($comment['author'])),
            'mail' => $comment['author_email'],
            'homepage' => $comment['author_url'],
!           'created' => strtotime($comment['date']),
            'hostname' => $comment['author_IP'],
            'status' => $status,
!           'comment_body' => array(
!             LANGUAGE_NONE => array(
!               array(
!                 'value' => $comment['content'],
!                 'format' => $wordpress_import->format,
!             ))),
            );
          // Check if duplicate
          if ($node_duplicate) {
!           $c = db_query("SELECT c.cid, c.comment FROM {comments} c WHERE c.nid = :nid AND c.timestamp = :time",
!             array(
!               ':nid' => $node_duplicate->nid,
!               ':time' => $node_comment['timestamp'],
!           ));
            if ($c->cid && $c->comment == $node_comment['comment']) {
              continue 2;
            }
*************** function wordpress_import_process_post_c
*** 1276,1291 ****
  
    // Save trackbacks
    foreach ($node_trackbacks as $node_trackback) {
!     db_query("INSERT INTO {trackback_received} (nid, created, site, name, subject, url, excerpt, status) VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', %d)",
!       $node_trackback['nid'],
!       $node_trackback['created'],
!       $node_trackback['site'],
!       $node_trackback['name'],
!       $node_trackback['subject'],
!       $node_trackback['url'],
!       $node_trackback['excerpt'],
!       $node_trackback['status']
!       );
      $context['results']['created_trackbacks']++;
    }
  
--- 1319,1325 ----
  
    // Save trackbacks
    foreach ($node_trackbacks as $node_trackback) {
!     db_insert('trackback_received')->fields($node_trackback)->execute();
      $context['results']['created_trackbacks']++;
    }
  
*************** function wordpress_import_process_post_c
*** 1293,1304 ****
    foreach ($node_comments as $node_comment) {
      $comment_id = comment_save($node_comment);
      // Update fields that haven't been set by comment_save
!     db_query("UPDATE {comments} SET hostname= '%s', timestamp= %d, status= %d WHERE cid= %d",
!       $node_comment['hostname'],
!       $node_comment['timestamp'],
!       $node_comment['status'],
!       $comment_id
!       );
      $context['results']['created_comments']++;
    }
  }
--- 1327,1336 ----
    foreach ($node_comments as $node_comment) {
      $comment_id = comment_save($node_comment);
      // Update fields that haven't been set by comment_save
!     db_update('comment')->fields(array(
!       'hostname' => $node_comment['hostname'],
!       'status' => $node_comment['status'],
!       ))->condition('cid', $comment_id)->execute();
      $context['results']['created_comments']++;
    }
  }
*************** function wordpress_import_batch_finished
*** 1378,1384 ****
  
    if ($success) {
  
!     $message = t('Import successful : ');
  
      $msg_results = array();
      $msg_results[] = '<li>' . t('@created_nodes nodes', array('@created_nodes' => $results['created_nodes'])) . '</li>';
--- 1410,1416 ----
  
    if ($success) {
  
!     $message = t('Import successful') . ' : ';
  
      $msg_results = array();
      $msg_results[] = '<li>' . t('@created_nodes nodes', array('@created_nodes' => $results['created_nodes'])) . '</li>';
*************** function wordpress_import_batch_finished
*** 1389,1395 ****
      $msg_results[] = '<li>' . t('@downloaded_images/@total_images images', array('@downloaded_images' => count($results['downloaded_images']), '@total_images' => count($results['downloaded_images'])+count($results['error_images']))) . '</li>';
  
      drupal_set_message($message . '<ul>' . join("\n", $msg_results) . '</ul>');
!     
      if (function_exists('dpm')) {
        dpm($results['error_images']);
      }
--- 1421,1427 ----
      $msg_results[] = '<li>' . t('@downloaded_images/@total_images images', array('@downloaded_images' => count($results['downloaded_images']), '@total_images' => count($results['downloaded_images'])+count($results['error_images']))) . '</li>';
  
      drupal_set_message($message . '<ul>' . join("\n", $msg_results) . '</ul>');
! 
      if (function_exists('dpm')) {
        dpm($results['error_images']);
      }
*************** function wordpress_import_batch_finished
*** 1400,1408 ****
        foreach ($results['error_images'] as $error_image) {
          $errors .= '<li>' . l($error_image['title'], 'node/' . $error_image['nid']) . "</li>\n";
        }
!       drupal_set_message(t('Some images could not be transferred for these nodes :') . '<ul>' . $errors . '</ul>', 'warning');
      }
!     
      if ($results['password_protected'] > 0) {
        drupal_set_message(t('Encountered @password_protected password-protected posts. These were imported as unpublished nodes.', array('@password_protected' => $results['password_protected'])), 'warning');
      }
--- 1432,1440 ----
        foreach ($results['error_images'] as $error_image) {
          $errors .= '<li>' . l($error_image['title'], 'node/' . $error_image['nid']) . "</li>\n";
        }
!       drupal_set_message(filter_xss(t('Some images could not be transferred for these nodes :') . '<ul>' . $errors . '</ul>'), 'warning');
      }
! 
      if ($results['password_protected'] > 0) {
        drupal_set_message(t('Encountered @password_protected password-protected posts. These were imported as unpublished nodes.', array('@password_protected' => $results['password_protected'])), 'warning');
      }
*************** function wordpress_import_read_wxr(&$wor
*** 1452,1458 ****
        if ($reader->name == 'wp:base_blog_url') {
          $reader->read();
          $wordpress_import->data['baseurl'] = $reader->value;
!         if (substr($wordpress_import->data['baseurl'], -1) != '/') {
            $wordpress_import->data['baseurl'] .= '/';
          }
        }
--- 1484,1490 ----
        if ($reader->name == 'wp:base_blog_url') {
          $reader->read();
          $wordpress_import->data['baseurl'] = $reader->value;
!         if (drupal_substr($wordpress_import->data['baseurl'], -1) != '/') {
            $wordpress_import->data['baseurl'] .= '/';
          }
        }
*************** function wordpress_import_create_vocabul
*** 1519,1525 ****
    $vocabulary = FALSE;
  
    // Check if a category for Wordpress already exists
!   $vocabulary_id = variable_get('wordpress_import_'. $type, 0);
  
    if ($vocabulary_id) {
      $vocabulary = taxonomy_vocabulary_load($vocabulary_id);
--- 1551,1557 ----
    $vocabulary = FALSE;
  
    // Check if a category for Wordpress already exists
!   $vocabulary_id = variable_get('wordpress_import_' . $type, 0);
  
    if ($vocabulary_id) {
      $vocabulary = taxonomy_vocabulary_load($vocabulary_id);
*************** function wordpress_import_create_vocabul
*** 1529,1536 ****
      return $vocabulary->vid;
    }
    else {
!     taxonomy_save_vocabulary($vocabulary_data);
!     variable_set('wordpress_import_'. $type, $vocabulary_data['vid']);
      return $vocabulary_data['vid'];
    }
  }
--- 1561,1568 ----
      return $vocabulary->vid;
    }
    else {
!     taxonomy_vocabulary_save((object) $vocabulary_data);
!     variable_set('wordpress_import_' . $type, $vocabulary_data['vid']);
      return $vocabulary_data['vid'];
    }
  }
*************** function wordpress_import_create_vocabul
*** 1539,1548 ****
   * Return an array of taxonomy terms belonging to a vocabulary
   */
  function wordpress_import_get_terms($vid) {
!   $db_result = db_query("SELECT t.tid, t.* FROM {term_data} t WHERE t.vid = %d", $vid);
  
    $result = array();
!   while ($term = db_fetch_object($db_result)) {
      $result[$term->name] = $term->tid;
    }
  
--- 1571,1580 ----
   * Return an array of taxonomy terms belonging to a vocabulary
   */
  function wordpress_import_get_terms($vid) {
!   $db_result = db_query("SELECT t.tid, t.* FROM {taxonomy_term_data} t WHERE t.vid = :vid", array(':vid' => $vid));
  
    $result = array();
!   foreach ($db_result as $term) {
      $result[$term->name] = $term->tid;
    }
  
