From 7b8a5475b4bd5fba9b9fb213ff4672fda9e5f817 Mon Sep 17 00:00:00 2001
From: luis <luis@750Whisperlynx64>
Date: Wed, 9 Mar 2011 01:39:01 +0100
Subject: [PATCH 01/13] Issue #748374: Applied patch 748374#comment-3755206

---
 wordpress_import-748374_0.patch |  606 +++++++++++++++++++++++++++++++++++++++
 wordpress_import.info           |    4 +-
 wordpress_import.module         |  204 ++++++++------
 3 files changed, 727 insertions(+), 87 deletions(-)
 create mode 100644 wordpress_import-748374_0.patch

diff --git a/wordpress_import-748374_0.patch b/wordpress_import-748374_0.patch
new file mode 100644
index 0000000..6110b7d
--- /dev/null
+++ b/wordpress_import-748374_0.patch
@@ -0,0 +1,606 @@
+? .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 -u -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:19:23 -0000
+@@ -1,6 +1,8 @@
+ name = Wordpress import
+ description = "Import WXR files created by Wordpress blog tool."
+-core=6.x
++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 -u -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:19:25 -0000
+@@ -27,14 +27,14 @@
+   */
+ 
+ /**
+- * Implementation of hook_help()
++ * 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>';
++    $output = '<p>' . t("This module imports a WXR file generated by Wordpress blog software into Drupal") . '</p>';
+     break;
+   }
+ 
+@@ -43,7 +43,7 @@ function wordpress_import_help($path, $a
+ 
+ 
+ /**
+- * Implementation of hook_menu()
++ * Implements hook_menu().
+  */
+ function wordpress_import_menu() {
+   $items = array();
+@@ -53,24 +53,30 @@ function wordpress_import_menu() {
+     '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;
+ }
+ 
+ 
+ /**
+- * hook_perm
++ * Implements hook_permission().
+  *
+- * @return array perms
++ * @return array permissions
+  * @author Yann Rocq
+- **/
+-function wordpress_import_perm() {
+-  return array('import wordpress blog');
++ */
++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
++ * Module entry point.
+  */
+ function wordpress_import_home() {
+ 
+@@ -79,7 +85,6 @@ function wordpress_import_home() {
+     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();
+ }
+ 
+@@ -87,6 +92,7 @@ function wordpress_import_home() {
+  * Create and manage the multistep form
+  */
+ function wordpress_import_wizard() {
++
+   $step = arg(3);
+ 
+   ctools_include('wizard');
+@@ -139,19 +145,21 @@ function wordpress_import_wizard() {
+ 
+   // *** SETTING THE FORM UP FOR MULTISTEP *** //
+   $form_state = array(
+-    'cache name' => NULL,
++    'cache name' => '',
+   );
+ 
+-  $wordpress_import = wordpress_import_form_get_page_cache(NULL);
++  $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 (!$wordpress_import) {
+-    drupal_set_message($step);
++  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);
+   }
+@@ -167,13 +175,13 @@ function wordpress_import_wizard() {
+   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 ------------ */
++/* ---------------- CTools cache handling functions ------------ */
+ 
+ function wordpress_import_form_clear_page_cache($name) {
+   ctools_object_cache_clear('wordpress_import', $name);
+@@ -186,12 +194,12 @@ function wordpress_import_form_get_page_
+ }
+ 
+ 
+-/*-------------------------- Form Steps  ---------------------- */
++/* -------------------------- Form Steps  ---------------------- */
+ 
+-function wordpress_import_form_file(&$form, &$form_state) {
++function wordpress_import_form_file($form, &$form_state) {
+   global $base_path;
+ 
+-  $wordpress_import = &$form_state['wordpress_import_obj'];
++  $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')))
+@@ -202,24 +210,25 @@ function wordpress_import_form_file(&$fo
+     '#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
+-  $wordpress_import_path = file_create_path('wordpress');
+-  file_check_directory($wordpress_import_path, TRUE);
+-  $files = file_scan_directory($wordpress_import_path, '.*\.xml');
++  $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($wordpress_import_path, '.*\.xml') as $file) {
+-      $options[$file->basename] = $file->basename;
++    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' => file_create_path(file_directory_path() .'/wordpress')));
++    $description = t('No files found in %directory', array('%directory' => drupal_realpath($path)));
+   }
+ 
+   // Local file selector element
+@@ -233,6 +242,7 @@ function wordpress_import_form_file(&$fo
+   $form['#attributes'] = array('enctype' => "multipart/form-data");
+ 
+   $form_state['no buttons'] = TRUE;
++  return $form;
+ }
+ 
+ 
+@@ -291,7 +301,7 @@ function wordpress_import_form_file_subm
+ }
+ 
+ 
+-function wordpress_import_form_options(&$form, &$form_state) {
++function wordpress_import_form_options($form, &$form_state) {
+   $wordpress_import = &$form_state['wordpress_import_obj'];
+ 
+   $form['basic_options'] = array(
+@@ -302,7 +312,7 @@ function wordpress_import_form_options(&
+   );
+ 
+   // Post content type
+-  $node_types = node_get_types();
++  $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))) {
+@@ -312,14 +322,14 @@ function wordpress_import_form_options(&
+   $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"'),
++    '#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 "Page"'),
++    '#description' => t('All imported pages will be assigned the selected content type. If you are unsure, select "Basic page"'),
+     '#default_value' => '',
+     '#options' => $content_types,
+     );
+@@ -405,13 +415,13 @@ function wordpress_import_form_options(&
+       $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');
++      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('Could not find module "trackback". <strong>Trackbacks will not be imported.</strong>'), 'error');
++      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;
+@@ -426,6 +436,7 @@ function wordpress_import_form_options(&
+       $form['advanced_options']['images']['#default_value'] = FALSE;
+       $form['advanced_options']['images']['#disabled'] = TRUE;
+   }
++  return $form;
+ }
+ 
+ 
+@@ -485,7 +496,7 @@ function wordpress_import_form_options_s
+ }
+ 
+ 
+-function wordpress_import_form_og(&$form, &$form_state) {
++function wordpress_import_form_og($form, &$form_state) {
+   $wordpress_import = &$form_state['wordpress_import_obj'];
+ 
+   $form['informations'] = array(
+@@ -507,6 +518,7 @@ function wordpress_import_form_og(&$form
+     '#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;
+ }
+ 
+ 
+@@ -516,16 +528,16 @@ function wordpress_import_form_og_submit
+ }
+ 
+ 
+-function wordpress_import_form_mapusers(&$form, &$form_state) {
++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'];
++  foreach ($result as $drupal_user) {
++    if (!empty($drupal_user->uid)) {
++      $drupal_users[$drupal_user->uid] = $drupal_user->name;
+     }
+   }
+ 
+@@ -562,6 +574,7 @@ function wordpress_import_form_mapusers(
+     }
+ 
+   }
++  return $form;
+ }
+ 
+ 
+@@ -604,7 +617,7 @@ function wordpress_import_form_mapusers_
+ }
+ 
+ 
+-function wordpress_import_form_newusers(&$form, &$form_state) {
++function wordpress_import_form_newusers($form, &$form_state) {
+   $wordpress_import = &$form_state['wordpress_import_obj'];
+ 
+   $form['newuser'] = array('#tree' => TRUE);
+@@ -627,6 +640,7 @@ function wordpress_import_form_newusers(
+     }
+ 
+   }
++  return $form;
+ }
+ 
+ 
+@@ -643,10 +657,10 @@ function wordpress_import_form_newusers_
+     if ($error = user_validate_name($value['name'])) {
+       form_set_error('newuser]['. $key .'][name', $error);
+     }
+-    elseif (user_load(array('name' => $value['name']))) {
++    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(strtolower($value['name']), $user['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'])));
+     }
+ 
+@@ -654,15 +668,15 @@ function wordpress_import_form_newusers_
+     if ($error = user_validate_mail($value['mail'])) {
+       form_set_error('newuser]['. $key .'][mail', $error);
+     }
+-    elseif (user_load(array('mail' => $value['mail']))) {
++    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(strtolower($value['mail']), $user['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'][] = strtolower($value['name']);
+-    $user['mail'][] = strtolower($value['mail']);
++    $user['name'][] = drupal_strtolower($value['name']);
++    $user['mail'][] = drupal_strtolower($value['mail']);
+   }
+ }
+ 
+@@ -672,9 +686,9 @@ function wordpress_import_form_newusers_
+ }
+ 
+ 
+-function wordpress_import_form_ready(&$form, &$form_state) {
++function wordpress_import_form_ready($form, &$form_state) {
+   $wordpress_import = &$form_state['wordpress_import_obj'];
+-  
++
+   if (function_exists('dpm')) {
+     dpm($wordpress_import);
+   }
+@@ -682,6 +696,7 @@ function wordpress_import_form_ready(&$f
+   $form['informations'] = array(
+    '#value' => t('Wordpress Import configuration is complete. Click "Finish" to launch the import process.'),
+   );
++  return $form;
+ }
+ 
+ 
+@@ -697,7 +712,7 @@ function wordpress_import_form_subtask_c
+   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.');
++  drupal_set_message(t('Import operation cancelled.'));
+ }
+ 
+ 
+@@ -788,9 +803,25 @@ function wordpress_import_process_blog($
+   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);
++      $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;
+@@ -861,7 +892,7 @@ function wordpress_import_process_catego
+           $term['parent'] = $wordpress_import->categories_map[$category['category_parent']];
+         }
+ 
+-        taxonomy_save_term($term);
++        taxonomy_term_save((object) $term);
+         $wordpress_import->categories_map[$category['cat_name']] = $term['tid'];
+ 
+         $context['results']['created_terms']++;
+@@ -892,7 +923,7 @@ function wordpress_import_process_catego
+           'vid' => $wordpress_import->tags_vocabulary,
+           );
+ 
+-        taxonomy_save_term($term);
++        taxonomy_term_save((object) $term);
+         $wordpress_import->tags_map[$tag] = $term['tid'];
+ 
+         $context['results']['created_terms']++;
+@@ -1078,7 +1109,7 @@ function wordpress_import_process_post(&
+   $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']));
++  $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);
+@@ -1150,7 +1181,7 @@ function wordpress_import_process_post(&
+ function wordpress_import_process_post_link($link, $baseurl) {
+ 
+   $path = $link;
+-  $path = substr($path, strlen($baseurl));
++  $path = drupal_substr($path, drupal_strlen($baseurl));
+   $path = rtrim($path, '/');
+ 
+   // Check for Wordpress ugly permalinks and replace with proper Drupal-style aliases
+@@ -1232,7 +1263,11 @@ function wordpress_import_process_post_c
+             );
+           // 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']);
++            $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;
+             }
+@@ -1246,19 +1281,27 @@ function wordpress_import_process_post_c
+         $node_comment = array(
+           'nid' => $nid,
+           'pid' => 0,
+-          'comment' => $comment['content'],
+-          'subject' => trim(truncate_utf8(decode_entities(strip_tags($comment['content'])), 29, TRUE)),
++          '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'],
+-          'timestamp' => strtotime($comment['date']),
++          'created' => strtotime($comment['date']),
+           'hostname' => $comment['author_IP'],
+           'status' => $status,
+-          'format' => $wordpress_import->format
++          '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 = %d AND c.timestamp = %d", $node_duplicate->nid, $node_comment['timestamp']);
++          $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;
+           }
+@@ -1276,16 +1319,7 @@ function wordpress_import_process_post_c
+ 
+   // 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']
+-      );
++    db_insert('trackback_received')->fields($node_trackback)->execute();
+     $context['results']['created_trackbacks']++;
+   }
+ 
+@@ -1293,12 +1327,10 @@ function wordpress_import_process_post_c
+   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
+-      );
++    db_update('comment')->fields(array(
++      'hostname' => $node_comment['hostname'],
++      'status' => $node_comment['status'],
++      ))->condition('cid', $comment_id)->execute();
+     $context['results']['created_comments']++;
+   }
+ }
+@@ -1378,7 +1410,7 @@ function wordpress_import_batch_finished
+ 
+   if ($success) {
+ 
+-    $message = t('Import successful : ');
++    $message = t('Import successful') . ' : ';
+ 
+     $msg_results = array();
+     $msg_results[] = '<li>' . t('@created_nodes nodes', array('@created_nodes' => $results['created_nodes'])) . '</li>';
+@@ -1389,7 +1421,7 @@ function wordpress_import_batch_finished
+     $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']);
+     }
+@@ -1400,9 +1432,9 @@ function wordpress_import_batch_finished
+       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');
++      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');
+     }
+@@ -1452,7 +1484,7 @@ function wordpress_import_read_wxr(&$wor
+       if ($reader->name == 'wp:base_blog_url') {
+         $reader->read();
+         $wordpress_import->data['baseurl'] = $reader->value;
+-        if (substr($wordpress_import->data['baseurl'], -1) != '/') {
++        if (drupal_substr($wordpress_import->data['baseurl'], -1) != '/') {
+           $wordpress_import->data['baseurl'] .= '/';
+         }
+       }
+@@ -1519,7 +1551,7 @@ function wordpress_import_create_vocabul
+   $vocabulary = FALSE;
+ 
+   // Check if a category for Wordpress already exists
+-  $vocabulary_id = variable_get('wordpress_import_'. $type, 0);
++  $vocabulary_id = variable_get('wordpress_import_' . $type, 0);
+ 
+   if ($vocabulary_id) {
+     $vocabulary = taxonomy_vocabulary_load($vocabulary_id);
+@@ -1529,8 +1561,8 @@ function wordpress_import_create_vocabul
+     return $vocabulary->vid;
+   }
+   else {
+-    taxonomy_save_vocabulary($vocabulary_data);
+-    variable_set('wordpress_import_'. $type, $vocabulary_data['vid']);
++    taxonomy_vocabulary_save((object) $vocabulary_data);
++    variable_set('wordpress_import_' . $type, $vocabulary_data['vid']);
+     return $vocabulary_data['vid'];
+   }
+ }
+@@ -1539,10 +1571,10 @@ function wordpress_import_create_vocabul
+  * 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);
++  $db_result = db_query("SELECT t.tid, t.* FROM {taxonomy_term_data} t WHERE t.vid = :vid", array(':vid' => $vid));
+ 
+   $result = array();
+-  while ($term = db_fetch_object($db_result)) {
++  foreach ($db_result as $term) {
+     $result[$term->name] = $term->tid;
+   }
+ 
diff --git a/wordpress_import.info b/wordpress_import.info
index 938be14..e29aca3 100755
--- a/wordpress_import.info
+++ b/wordpress_import.info
@@ -1,6 +1,8 @@
 name = Wordpress import
 description = "Import WXR files created by Wordpress blog tool."
-core=6.x
+core=7.x
 package = "Importing"
 dependencies[] = ctools
 php = 5.0
+files[] = wordpress_import.module
+
diff --git a/wordpress_import.module b/wordpress_import.module
index b172716..03d25fe 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -27,14 +27,14 @@
   */
 
 /**
- * Implementation of hook_help()
+ * 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>';
+    $output = '<p>' . t("This module imports a WXR file generated by Wordpress blog software into Drupal") . '</p>';
     break;
   }
 
@@ -43,7 +43,7 @@ function wordpress_import_help($path, $arg) {
 
 
 /**
- * Implementation of hook_menu()
+ * Implements hook_menu().
  */
 function wordpress_import_menu() {
   $items = array();
@@ -53,24 +53,30 @@ function wordpress_import_menu() {
     '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;
 }
 
 
 /**
- * hook_perm
+ * Implements hook_permission().
  *
- * @return array perms
+ * @return array permissions
  * @author Yann Rocq
- **/
-function wordpress_import_perm() {
-  return array('import wordpress blog');
+ */
+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
+ * Module entry point.
  */
 function wordpress_import_home() {
 
@@ -79,7 +85,6 @@ function wordpress_import_home() {
     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();
 }
 
@@ -87,6 +92,7 @@ function wordpress_import_home() {
  * Create and manage the multistep form
  */
 function wordpress_import_wizard() {
+
   $step = arg(3);
 
   ctools_include('wizard');
@@ -139,19 +145,21 @@ function wordpress_import_wizard() {
 
   // *** SETTING THE FORM UP FOR MULTISTEP *** //
   $form_state = array(
-    'cache name' => NULL,
+    'cache name' => '',
   );
 
-  $wordpress_import = wordpress_import_form_get_page_cache(NULL);
+  $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 (!$wordpress_import) {
-    drupal_set_message($step);
+  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);
   }
@@ -167,13 +175,13 @@ function wordpress_import_wizard() {
   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 ------------ */
+/* ---------------- CTools cache handling functions ------------ */
 
 function wordpress_import_form_clear_page_cache($name) {
   ctools_object_cache_clear('wordpress_import', $name);
@@ -186,12 +194,12 @@ function wordpress_import_form_get_page_cache($name) {
 }
 
 
-/*-------------------------- Form Steps  ---------------------- */
+/* -------------------------- Form Steps  ---------------------- */
 
-function wordpress_import_form_file(&$form, &$form_state) {
+function wordpress_import_form_file($form, &$form_state) {
   global $base_path;
 
-  $wordpress_import = &$form_state['wordpress_import_obj'];
+  $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')))
@@ -202,24 +210,25 @@ function wordpress_import_form_file(&$form, &$form_state) {
     '#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
-  $wordpress_import_path = file_create_path('wordpress');
-  file_check_directory($wordpress_import_path, TRUE);
-  $files = file_scan_directory($wordpress_import_path, '.*\.xml');
+  $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($wordpress_import_path, '.*\.xml') as $file) {
-      $options[$file->basename] = $file->basename;
+    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' => file_create_path(file_directory_path() .'/wordpress')));
+    $description = t('No files found in %directory', array('%directory' => drupal_realpath($path)));
   }
 
   // Local file selector element
@@ -233,6 +242,7 @@ function wordpress_import_form_file(&$form, &$form_state) {
   $form['#attributes'] = array('enctype' => "multipart/form-data");
 
   $form_state['no buttons'] = TRUE;
+  return $form;
 }
 
 
@@ -291,7 +301,7 @@ function wordpress_import_form_file_submit(&$form, &$form_state) {
 }
 
 
-function wordpress_import_form_options(&$form, &$form_state) {
+function wordpress_import_form_options($form, &$form_state) {
   $wordpress_import = &$form_state['wordpress_import_obj'];
 
   $form['basic_options'] = array(
@@ -302,7 +312,7 @@ function wordpress_import_form_options(&$form, &$form_state) {
   );
 
   // Post content type
-  $node_types = node_get_types();
+  $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))) {
@@ -312,14 +322,14 @@ function wordpress_import_form_options(&$form, &$form_state) {
   $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"'),
+    '#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 "Page"'),
+    '#description' => t('All imported pages will be assigned the selected content type. If you are unsure, select "Basic page"'),
     '#default_value' => '',
     '#options' => $content_types,
     );
@@ -405,13 +415,13 @@ function wordpress_import_form_options(&$form, &$form_state) {
       $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');
+      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('Could not find module "trackback". <strong>Trackbacks will not be imported.</strong>'), 'error');
+      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;
@@ -426,6 +436,7 @@ function wordpress_import_form_options(&$form, &$form_state) {
       $form['advanced_options']['images']['#default_value'] = FALSE;
       $form['advanced_options']['images']['#disabled'] = TRUE;
   }
+  return $form;
 }
 
 
@@ -485,7 +496,7 @@ function wordpress_import_form_options_submit(&$form, &$form_state) {
 }
 
 
-function wordpress_import_form_og(&$form, &$form_state) {
+function wordpress_import_form_og($form, &$form_state) {
   $wordpress_import = &$form_state['wordpress_import_obj'];
 
   $form['informations'] = array(
@@ -507,6 +518,7 @@ function wordpress_import_form_og(&$form, &$form_state) {
     '#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;
 }
 
 
@@ -516,16 +528,16 @@ function wordpress_import_form_og_submit(&$form, &$form_state) {
 }
 
 
-function wordpress_import_form_mapusers(&$form, &$form_state) {
+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'];
+  foreach ($result as $drupal_user) {
+    if (!empty($drupal_user->uid)) {
+      $drupal_users[$drupal_user->uid] = $drupal_user->name;
     }
   }
 
@@ -562,6 +574,7 @@ function wordpress_import_form_mapusers(&$form, &$form_state) {
     }
 
   }
+  return $form;
 }
 
 
@@ -604,7 +617,7 @@ function wordpress_import_form_mapusers_submit(&$form, &$form_state) {
 }
 
 
-function wordpress_import_form_newusers(&$form, &$form_state) {
+function wordpress_import_form_newusers($form, &$form_state) {
   $wordpress_import = &$form_state['wordpress_import_obj'];
 
   $form['newuser'] = array('#tree' => TRUE);
@@ -627,6 +640,7 @@ function wordpress_import_form_newusers(&$form, &$form_state) {
     }
 
   }
+  return $form;
 }
 
 
@@ -643,10 +657,10 @@ function wordpress_import_form_newusers_validate(&$form, &$form_state) {
     if ($error = user_validate_name($value['name'])) {
       form_set_error('newuser]['. $key .'][name', $error);
     }
-    elseif (user_load(array('name' => $value['name']))) {
+    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(strtolower($value['name']), $user['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'])));
     }
 
@@ -654,15 +668,15 @@ function wordpress_import_form_newusers_validate(&$form, &$form_state) {
     if ($error = user_validate_mail($value['mail'])) {
       form_set_error('newuser]['. $key .'][mail', $error);
     }
-    elseif (user_load(array('mail' => $value['mail']))) {
+    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(strtolower($value['mail']), $user['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'][] = strtolower($value['name']);
-    $user['mail'][] = strtolower($value['mail']);
+    $user['name'][] = drupal_strtolower($value['name']);
+    $user['mail'][] = drupal_strtolower($value['mail']);
   }
 }
 
@@ -672,9 +686,9 @@ function wordpress_import_form_newusers_submit(&$form, &$form_state) {
 }
 
 
-function wordpress_import_form_ready(&$form, &$form_state) {
+function wordpress_import_form_ready($form, &$form_state) {
   $wordpress_import = &$form_state['wordpress_import_obj'];
-  
+
   if (function_exists('dpm')) {
     dpm($wordpress_import);
   }
@@ -682,6 +696,7 @@ function wordpress_import_form_ready(&$form, &$form_state) {
   $form['informations'] = array(
    '#value' => t('Wordpress Import configuration is complete. Click "Finish" to launch the import process.'),
   );
+  return $form;
 }
 
 
@@ -697,7 +712,7 @@ function wordpress_import_form_subtask_cancel(&$form_state) {
   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.');
+  drupal_set_message(t('Import operation cancelled.'));
 }
 
 
@@ -788,9 +803,25 @@ function wordpress_import_process_blog($wordpress_import, &$context) {
   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);
+      $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;
@@ -861,7 +892,7 @@ function wordpress_import_process_categories_tags(&$wordpress_import, &$context)
           $term['parent'] = $wordpress_import->categories_map[$category['category_parent']];
         }
 
-        taxonomy_save_term($term);
+        taxonomy_term_save((object) $term);
         $wordpress_import->categories_map[$category['cat_name']] = $term['tid'];
 
         $context['results']['created_terms']++;
@@ -892,7 +923,7 @@ function wordpress_import_process_categories_tags(&$wordpress_import, &$context)
           'vid' => $wordpress_import->tags_vocabulary,
           );
 
-        taxonomy_save_term($term);
+        taxonomy_term_save((object) $term);
         $wordpress_import->tags_map[$tag] = $term['tid'];
 
         $context['results']['created_terms']++;
@@ -1078,7 +1109,7 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
   $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']));
+  $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);
@@ -1150,7 +1181,7 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
 function wordpress_import_process_post_link($link, $baseurl) {
 
   $path = $link;
-  $path = substr($path, strlen($baseurl));
+  $path = drupal_substr($path, drupal_strlen($baseurl));
   $path = rtrim($path, '/');
 
   // Check for Wordpress ugly permalinks and replace with proper Drupal-style aliases
@@ -1232,7 +1263,11 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
             );
           // 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']);
+            $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;
             }
@@ -1246,19 +1281,27 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
         $node_comment = array(
           'nid' => $nid,
           'pid' => 0,
-          'comment' => $comment['content'],
-          'subject' => trim(truncate_utf8(decode_entities(strip_tags($comment['content'])), 29, TRUE)),
+          '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'],
-          'timestamp' => strtotime($comment['date']),
+          'created' => strtotime($comment['date']),
           'hostname' => $comment['author_IP'],
           'status' => $status,
-          'format' => $wordpress_import->format
+          '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 = %d AND c.timestamp = %d", $node_duplicate->nid, $node_comment['timestamp']);
+          $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;
           }
@@ -1276,16 +1319,7 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
 
   // 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']
-      );
+    db_insert('trackback_received')->fields($node_trackback)->execute();
     $context['results']['created_trackbacks']++;
   }
 
@@ -1293,12 +1327,10 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
   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
-      );
+    db_update('comment')->fields(array(
+      'hostname' => $node_comment['hostname'],
+      'status' => $node_comment['status'],
+      ))->condition('cid', $comment_id)->execute();
     $context['results']['created_comments']++;
   }
 }
@@ -1378,7 +1410,7 @@ function wordpress_import_batch_finished($success, $results, $operations) {
 
   if ($success) {
 
-    $message = t('Import successful : ');
+    $message = t('Import successful') . ' : ';
 
     $msg_results = array();
     $msg_results[] = '<li>' . t('@created_nodes nodes', array('@created_nodes' => $results['created_nodes'])) . '</li>';
@@ -1389,7 +1421,7 @@ function wordpress_import_batch_finished($success, $results, $operations) {
     $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']);
     }
@@ -1400,9 +1432,9 @@ function wordpress_import_batch_finished($success, $results, $operations) {
       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');
+      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');
     }
@@ -1452,7 +1484,7 @@ function wordpress_import_read_wxr(&$wordpress_import) {
       if ($reader->name == 'wp:base_blog_url') {
         $reader->read();
         $wordpress_import->data['baseurl'] = $reader->value;
-        if (substr($wordpress_import->data['baseurl'], -1) != '/') {
+        if (drupal_substr($wordpress_import->data['baseurl'], -1) != '/') {
           $wordpress_import->data['baseurl'] .= '/';
         }
       }
@@ -1519,7 +1551,7 @@ function wordpress_import_create_vocabulary($type, $vocabulary_data) {
   $vocabulary = FALSE;
 
   // Check if a category for Wordpress already exists
-  $vocabulary_id = variable_get('wordpress_import_'. $type, 0);
+  $vocabulary_id = variable_get('wordpress_import_' . $type, 0);
 
   if ($vocabulary_id) {
     $vocabulary = taxonomy_vocabulary_load($vocabulary_id);
@@ -1529,8 +1561,8 @@ function wordpress_import_create_vocabulary($type, $vocabulary_data) {
     return $vocabulary->vid;
   }
   else {
-    taxonomy_save_vocabulary($vocabulary_data);
-    variable_set('wordpress_import_'. $type, $vocabulary_data['vid']);
+    taxonomy_vocabulary_save((object) $vocabulary_data);
+    variable_set('wordpress_import_' . $type, $vocabulary_data['vid']);
     return $vocabulary_data['vid'];
   }
 }
@@ -1539,10 +1571,10 @@ function wordpress_import_create_vocabulary($type, $vocabulary_data) {
  * 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);
+  $db_result = db_query("SELECT t.tid, t.* FROM {taxonomy_term_data} t WHERE t.vid = :vid", array(':vid' => $vid));
 
   $result = array();
-  while ($term = db_fetch_object($db_result)) {
+  foreach ($db_result as $term) {
     $result[$term->name] = $term->tid;
   }
 
-- 
1.7.4.1


From 1959d1b91e25c75ecac6dd19c7d4a25686539046 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 01:54:02 +0100
Subject: [PATCH 02/13] Issue#748374 discipolo: replaced file_directory_path() with file_default_scheme() . :/ according to node/224333#file_directory_path

---
 wordpress_import.module |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 03d25fe..a0734c1 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -259,7 +259,7 @@ function wordpress_import_form_file_validate(&$form, &$form_state) {
     $filepath = $upload->filepath;
   }
   else {
-    $filepath = file_directory_path() . '/wordpress/' . $form_state['values']['local'];
+    $filepath = file_default_scheme() . ':/' . '/wordpress/' . $form_state['values']['local'];
   }
 
   // Make sure a file was uploaded or a local file was selected
@@ -404,7 +404,7 @@ function wordpress_import_form_options($form, &$form_state) {
     '#type' => 'textfield',
     '#title' => t('Images directory'),
     '#default_value' => '/images',
-    '#description' => t('Subdirectory of <strong>@file_directory_path</strong> in which to place files, must start with /', array('@file_directory_path' => file_directory_path()))
+    '#description' => t('Subdirectory of <strong>@file_default_scheme</strong> in which to place files, must start with /', array('@file_default_scheme' => file_default_scheme() . ':/'))
   );
 
   // Warn if some key modules are not found
@@ -460,7 +460,7 @@ function wordpress_import_form_options_validate(&$form, &$form_state) {
 
   // Test if images directory is valid
   if ($form_state['values']['advanced_options']['images']) {
-    $dir = file_directory_path() . rtrim($form_state['values']['advanced_options']['images_dir'], '/\\');
+    $dir = file_default_scheme() . ':/' . rtrim($form_state['values']['advanced_options']['images_dir'], '/\\');
     if (!is_dir($dir)) {
       if (!@mkdir($dir)) {
         form_set_error('advanced_options][images_dir', t('Invalid images directory specified.'));
@@ -479,7 +479,7 @@ function wordpress_import_form_options_submit(&$form, &$form_state) {
   // Clear messages
   drupal_get_messages();
 
-  $form_state['values']['advanced_options']['images_dir'] = file_directory_path() . rtrim($form_state['values']['advanced_options']['images_dir'], '/\\');
+  $form_state['values']['advanced_options']['images_dir'] = file_default_scheme() . ':/' . rtrim($form_state['values']['advanced_options']['images_dir'], '/\\');
 
   $options = $form_state['values']['basic_options'] + $form_state['values']['advanced_options'];
   $form_state['wordpress_import_obj']->options = $options;
-- 
1.7.4.1


From 38805154f2bd60f982b59e9cba770fac6367a8c5 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 02:20:40 +0100
Subject: [PATCH 03/13] Issue#748374 discipolo: body, teaser and format adapted to field api

---
 wordpress_import.module |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index a0734c1..7f0ea22 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1059,24 +1059,23 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
   else {
     $node['title'] = t('Untitled');
   }
-
+   // Node language
+  $node['language'] = (isset($wordpress_import->options['language']) ? $wordpress_import->options['language'] : 'LANGUAGE_NONE');
+  
   // Node content
-  $node['body'] = str_replace('<!--more-->', '<!--break-->', $post['content']);
+  $node['body'][$node['language']][0]['value'] = str_replace('<!--more-->', '<!--break-->', $post['content']);
 
   // Node format
-  $node['format'] = $wordpress_import->format;
+   $node['body'][$node['language']][0]['format'] = $wordpress_import->format;
 
   // Node teaser
   if (empty($post['excerpt'])) {
-    $node['teaser'] = node_teaser($node['body'], $node['format']);
+    $node['body'][$node['language']][0]['summary'] = text_summary($node['body'][$node['language']][0]['value']);
   }
   else {
-    $node['teaser'] = $post['excerpt'];
+   $node['body'][$node['language']][0]['summary'] = $post['excerpt'];
   }
 
-  // Node language
-  $node['language'] = (isset($wordpress_import->options['language']) ? $wordpress_import->options['language'] : '');
-
   // Node timestamp
   $node['created'] = strtotime($post['date']);
   $node['changed'] = $node['created'];
-- 
1.7.4.1


From 4e33d36848221b90cf8154c784fb689a58125090 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 02:29:14 +0100
Subject: [PATCH 04/13] Issue#748374 discipolo: http://drupal.org/node/224333#comment_node

---
 wordpress_import.module |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 7f0ea22..d617db2 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1105,7 +1105,7 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
   }
 
   // Node comment status
-  $node['comment'] = $post['comment_status']=='open'?COMMENT_NODE_READ_WRITE:COMMENT_NODE_READ_ONLY;
+  $node['comment'] = $post['comment_status']=='open'?COMMENT_NODE_OPEN:COMMENT_NODE_CLOSED;
 
   // 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']));
-- 
1.7.4.1


From 9f060f623b4f4ad8c3b1c11ecce0b3925f25c2b7 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 02:36:31 +0100
Subject: [PATCH 05/13] Issue#748374 discipolo: comment status values in the database have flipped so they match node status

---
 wordpress_import.module |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index d617db2..a7d82f2 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1237,10 +1237,10 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
   foreach ($comments as $comment) {
 
     switch ($comment['approved']) {
-      case '0':
+      case '1':
         $status = COMMENT_NOT_PUBLISHED;
         break;
-      case '1':
+      case '0':
         $status = COMMENT_PUBLISHED;
         break;
       case 'spam':
-- 
1.7.4.1


From 89c6f57dbb0d997a5791027e4e398d0ff46efa01 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 02:50:35 +0100
Subject: [PATCH 06/13] Issue#748374 discipolo: comment module table renamed to singular

---
 wordpress_import.module |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index a7d82f2..89e05de 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1296,7 +1296,7 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
           );
         // 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",
+          $c = db_query("SELECT c.cid, c.comment FROM {comment} c WHERE c.nid = :nid AND c.timestamp = :time",
             array(
               ':nid' => $node_duplicate->nid,
               ':time' => $node_comment['timestamp'],
-- 
1.7.4.1


From 866209b129285a3c18eabfc2d811c436d8503841 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 02:56:39 +0100
Subject: [PATCH 07/13] Issue#748374 discipolo: replaced timestamp with created

---
 wordpress_import.module |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 89e05de..09883b9 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1296,17 +1296,17 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
           );
         // Check if duplicate
         if ($node_duplicate) {
-          $c = db_query("SELECT c.cid, c.comment FROM {comment} c WHERE c.nid = :nid AND c.timestamp = :time",
+          $c = db_query("SELECT c.cid, c.comment FROM {comment} c WHERE c.nid = :nid AND c.created = :time",
             array(
               ':nid' => $node_duplicate->nid,
-              ':time' => $node_comment['timestamp'],
+              ':time' => $node_comment['created'],
           ));
           if ($c->cid && $c->comment == $node_comment['comment']) {
             continue 2;
           }
         }
         else {
-          $node_comments[$node_comment['timestamp']] = $node_comment;
+          $node_comments[$node_comment['created']] = $node_comment;
         }
         break;
     }
-- 
1.7.4.1


From 4473a61e377d89e400c0d584276da4a79627947e Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:44:29 +0100
Subject: [PATCH 08/13] Issue#748374 discipolo: node_load_multiple returns an array instead of a node object

---
 wordpress_import.module |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 09883b9..1c4b743 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1108,14 +1108,17 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
   $node['comment'] = $post['comment_status']=='open'?COMMENT_NODE_OPEN:COMMENT_NODE_CLOSED;
 
   // 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'])) {
+  $dupes = node_load_multiple(FALSE, array('created' => $node['created'], 'title' => $node['title'], 'type' => $node['type']));
+  foreach ($dupes as $nid => $context['sandbox']['node_duplicate']) {
+    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);
-    }
+      }
+    
     unset($context['sandbox']['node_duplicate']);
     unset($context['sandbox']['post']);
     return;
+    }
   }
 
   // Process link for this post
-- 
1.7.4.1


From 742996a5e6ecd9fdda217d1230f01e24b1f44868 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:46:37 +0100
Subject: [PATCH 09/13] Issue#748374 discipolo: allow all file extensions

---
 wordpress_import.module |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 1c4b743..5b5fd82 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -252,8 +252,11 @@ function wordpress_import_form_file_validate(&$form, &$form_state) {
     return;
   }
 
+$validators = array(
+'file_validate_extensions' => array());
+
   // Process uploaded file (if any), and set file path
-  $upload = file_save_upload('upload');
+  $upload = file_save_upload('upload', $validators);
   if ($upload) {
     $form_state['values']['upload'] = $upload->filename;
     $filepath = $upload->filepath;
-- 
1.7.4.1


From cae8a074a6732eeefe66241c7ea9b9db970c76d6 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:49:31 +0100
Subject: [PATCH 10/13] Issue#748374 discipolo: extraneous space removed

---
 wordpress_import.module |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index 5b5fd82..cd6672d 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -568,7 +568,7 @@ function wordpress_import_form_mapusers($form, &$form_state) {
       '#tree' => TRUE
     );
 
-    foreach ($wordpress_import ->usermap as $wp_user => $drupal_user) {
+    foreach ($wordpress_import->usermap as $wp_user => $drupal_user) {
       $form['usermap'][$wp_user] = array(
         '#type' => 'select',
         '#title' => $wp_user . ' (' . $wordpress_import->count['author_posts'][$wp_user] . ')',
-- 
1.7.4.1


From a0009ff84faf11625660b08d1fc2d4555a0de1a7 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:53:13 +0100
Subject: [PATCH 11/13] Issue#748374 discipolo: this makes imported nodes use the wordpress format

---
 wordpress_import.module |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index cd6672d..df831d6 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1069,7 +1069,7 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
   $node['body'][$node['language']][0]['value'] = str_replace('<!--more-->', '<!--break-->', $post['content']);
 
   // Node format
-   $node['body'][$node['language']][0]['format'] = $wordpress_import->format;
+  $node['body'][$node['language']][0]['format'] = variable_get('wordpress_import_format_id', 0);
 
   // Node teaser
   if (empty($post['excerpt'])) {
@@ -1297,7 +1297,7 @@ function wordpress_import_process_post_comments($comments, $nid, $disable_trackb
             LANGUAGE_NONE => array(
               array(
                 'value' => $comment['content'],
-                'format' => $wordpress_import->format,
+                'format' => variable_get('wordpress_import_format_id', 0);
             ))),
           );
         // Check if duplicate
-- 
1.7.4.1


From 5a3819b254b6cd1c2e7ec6c2cf05271c59b5fe2d Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:55:56 +0100
Subject: [PATCH 12/13] Issue#748374 discipolo: enable manual user mapping

---
 wordpress_import.module |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index df831d6..d0cb810 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1529,7 +1529,7 @@ function wordpress_import_read_wxr(&$wordpress_import) {
       if ($reader->name == 'dc:creator') {
         $reader->read();
         $wordpress_import->usermap[$reader->value] = 0;
-        $wordpress_import->count['author_posts'][$reader->value]++;
+        $wordpress_import->usermap[$reader->value]++;
       }
 
       // Count comments
-- 
1.7.4.1


From b48d12a2e646ce8a57edfc957b35720f48510ac3 Mon Sep 17 00:00:00 2001
From: discipolo <discipolo@rocketmail.com>
Date: Wed, 9 Mar 2011 12:56:53 +0100
Subject: [PATCH 13/13] Issue#748374 discipolo: removed apostrophes

---
 wordpress_import.module |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/wordpress_import.module b/wordpress_import.module
index d0cb810..813f8cc 100755
--- a/wordpress_import.module
+++ b/wordpress_import.module
@@ -1063,7 +1063,7 @@ function wordpress_import_process_post(&$wordpress_import, &$context) {
     $node['title'] = t('Untitled');
   }
    // Node language
-  $node['language'] = (isset($wordpress_import->options['language']) ? $wordpress_import->options['language'] : 'LANGUAGE_NONE');
+  $node['language'] = (isset($wordpress_import->options['language']) ? $wordpress_import->options['language'] : LANGUAGE_NONE);
   
   // Node content
   $node['body'][$node['language']][0]['value'] = str_replace('<!--more-->', '<!--break-->', $post['content']);
-- 
1.7.4.1

