--- wordpress_import-DRUPAL-6--1/wordpress_import.module 2009-05-13 22:14:46.000000000 -0300
+++ wordpress_import/wordpress_import.module 2009-06-10 21:39:51.000000000 -0300
@@ -1,5 +1,5 @@
'checkbox',
'#title' => 'Create path aliases',
- '#description' => t('This option tries to preserve the path of the wordpress original posts. It is useful only if the url of your drupal site root is the same as the wordpress site (!root) and if clean urls are activated', array('!root' => $wordpress['link']))
+ '#description' => t('This option tries to preserve the path of the wordpress original posts. It is useful only if the url of your drupal site root is the same as the wordpress site (!root) and if clean urls are activated. Warning: disable Pathauto module before importing, otherwise imported path aliases will be overwritten by Pathauto. After importing, enable it again.', array('!root' => $wordpress['link']))
);
break;
@@ -431,28 +431,56 @@
$category_mapping = wordpress_import_get_terms($category_vocabulary);
+ $permalink_maker = array();
+
// Import categories
if (is_array($wordpress['categories'])) {
foreach ($wordpress['categories'] as $key => $value) {
- $category_name = wordpress_import_get_tag($value, 'wp:cat_name');
- $category_parent = wordpress_import_get_tag($value, 'wp:category_parent');
+ $category_name = html_entity_decode(wordpress_import_get_tag($value, 'wp:cat_name'), ENT_COMPAT, 'UTF-8');
+ $category_parent = html_entity_decode(wordpress_import_get_tag($value, 'wp:category_parent'), ENT_COMPAT, 'UTF-8');
+ $category_desc = str_replace(array(''), '', html_entity_decode(wordpress_import_get_tag($value, 'wp:category_description'), ENT_COMPAT, 'UTF-8'));
+ $category_nicename = html_entity_decode(wordpress_import_get_tag($value, 'wp:category_nicename'), ENT_COMPAT, 'UTF-8');
if (!$category_mapping[$category_name]) {
+ $permalink_maker[$category_name] = array(
+ 'nicename' => $category_nicename
+ );
+
$category_term = array(
'name' => $category_name,
+ 'description' => $category_desc,
'vid' => $category_vocabulary
);
if ($category_parent !== NULL && $category_parent !== '') {
$category_term['parent'] = $category_mapping[$category_parent];
+ $permalink_maker[$category_name]['parent'] = $category_parent;
}
taxonomy_save_term($category_term);
+
+
$_SESSION['wordpress_import']['report']['@created_categories']++;
- // Save mapping between Wordpress and Drupal categories
+ // Save mapping between Wordpress and Drupal categories
$category_mapping[$category_name] = $category_term['tid'];
+
+ // Make WP-like category permalinks
+ if ($params['alias']) {
+ $link='';
+ while ($category_name !== '') {
+ $link="/" . $permalink_maker[$category_name]['nicename'] . $link;
+ if ($permalink_maker[$category_name]['parent'] !== NULL && $permalink_maker[$category_name]['parent'] !== '') {
+ $category_name=$permalink_maker[$category_name]['parent'];
+ } else {
+ $category_name = '';
+ }
+ }
+ $link="category" . $link;
+ path_set_alias("taxonomy/term/" . $category_term['tid'],$link);
+ path_set_alias("taxonomy/term/" . $category_term['tid'] . "/feed",$link . "/feed");
+ }
}
}
@@ -461,14 +489,6 @@
'categories_vocabulary' => $category_vocabulary
);
}
-
- // Wordpress MU doesn't set categories when exporting
-
- return array(
- 'categories_map' => null,
- 'categories_vocabulary' => null
- );
-
}
/**
@@ -521,10 +541,13 @@
$post_info = wordpress_import_post($post_value, $params);
if ($post_info && $params['alias']) {
+ // This only works if Pathauto module is disabled or not
+ // installed, otherwise Pathauto will overwrite what this piece of code does
$link = wordpress_import_get_tag($post_value, 'link');
$link = substr($link, strlen($wordpress['link']));
$link = rtrim($link, '/');
path_set_alias('node/'. $post_info['nid'], $link);
+ path_set_alias('node/'. $post_info['nid'] . "/feed", $link . "/feed");
}
}
}
@@ -569,7 +592,7 @@
$categories = $categories[1];
foreach ($categories as $key => $value) {
- $category = str_replace(array(''), '', $value);
+ $category = html_entity_decode(str_replace(array(''), '', $value), ENT_COMPAT, 'UTF-8');
$drupal_category = $params['categories_map'][$category];
if (!empty($drupal_category)) {
@@ -611,9 +634,21 @@
$content = wordpress_import_get_tag($post, 'content:encoded');
$content = str_replace('', '', $content);
+ $teaser = wordpress_import_get_tag($post, 'excerpt:encoded');
+ if (empty($teaser)) {
+ $teaser=node_teaser($content, $params['format']);
+ }
+
+ // TODO: fix changed time
+ $changed=wordpress_import_get_tag($post, 'wp:postmeta');
+ preg_match_all('|_edit_lock\n
', '', $text);
+ $text = str_replace('
', "\n", $text); + $text = str_replace('
', '', $text); + + return $text; +} + +function wpautop($pee, $br = 1) { + $pee = $pee . "\n"; // just to make things a little easier, pad the end + $pee = preg_replace('|