summaryrefslogtreecommitdiffstats
path: root/wp-admin/import
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-10-12 16:21:15 +0000
commit3a4570b0fc8b3d6339bef71d17d7701554e0bbf7 (patch)
tree2a06e5261263c68d8afd95a6328879dc289cb909 /wp-admin/import
parentb83c34a7010faee0223f6037025c350da12e05e6 (diff)
downloadwordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.gz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.tar.xz
wordpress-mu-3a4570b0fc8b3d6339bef71d17d7701554e0bbf7.zip
Merge with WP 2.3 - testing use only!
Move pluggable functions out of wpmu-functions and into pluggable.php, fixes #439 git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1069 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/import')
-rw-r--r--wp-admin/import/blogger.php33
-rw-r--r--wp-admin/import/blogware.php11
-rw-r--r--wp-admin/import/btt.php115
-rw-r--r--wp-admin/import/dotclear.php53
-rw-r--r--wp-admin/import/greymatter.php7
-rw-r--r--wp-admin/import/jkw.php178
-rw-r--r--wp-admin/import/livejournal.php12
-rw-r--r--wp-admin/import/mt.php460
-rw-r--r--wp-admin/import/rss.php10
-rw-r--r--wp-admin/import/stp.php155
-rw-r--r--wp-admin/import/textpattern.php42
-rw-r--r--wp-admin/import/utw.php276
-rw-r--r--wp-admin/import/wordpress.php176
-rw-r--r--wp-admin/import/wp-cat2tag.php240
14 files changed, 1431 insertions, 337 deletions
diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php
index 4ad7a97..23e0807 100644
--- a/wp-admin/import/blogger.php
+++ b/wp-admin/import/blogger.php
@@ -84,7 +84,7 @@ class Blogger_Import {
if ( empty($this->blogs) ) {
$headers = array(
"GET /feeds/default/blogs HTTP/1.0",
- "Host: www2.blogger.com",
+ "Host: www.blogger.com",
"Authorization: AuthSub token=\"$this->token\""
);
$request = join( "\r\n", $headers ) . "\r\n\r\n";
@@ -380,7 +380,9 @@ class Blogger_Import {
$entry = "<feed>$entry</feed>";
$AtomParser = new AtomParser();
$AtomParser->parse( $entry );
- $this->import_post($AtomParser->entry);
+ $result = $this->import_post($AtomParser->entry);
+ if ( is_wp_error( $result ) )
+ return $result;
unset($AtomParser);
}
} else break;
@@ -509,15 +511,17 @@ class Blogger_Import {
$post_content = str_replace('<hr>', '<hr />', $post_content);
// Checks for duplicates
- if (
- isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ||
- post_exists( $post_title, $post_content, $post_date )
- ) {
+ if ( isset( $this->blogs[$importing_blog]['posts'][$entry->old_permalink] ) ) {
+ ++$this->blogs[$importing_blog]['posts_skipped'];
+ } elseif ( $post_id = post_exists( $post_title, $post_content, $post_date ) ) {
+ $this->blogs[$importing_blog]['posts'][$entry->old_permalink] = $post_id;
++$this->blogs[$importing_blog]['posts_skipped'];
} else {
$post = compact('post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
wp_create_categories( array_map( 'addslashes', $entry->categories ), $post_id );
@@ -531,6 +535,7 @@ class Blogger_Import {
++$this->blogs[$importing_blog]['posts_done'];
}
$this->save_vars();
+ return;
}
function import_comment( $entry ) {
@@ -767,7 +772,9 @@ class Blogger_Import {
if ( isset( $_REQUEST['blog'] ) ) {
$blog = is_array($_REQUEST['blog']) ? array_shift( array_keys( $_REQUEST['blog'] ) ) : $_REQUEST['blog'];
$blog = (int) $blog;
- $this->import_blog( $blog );
+ $result = $this->import_blog( $blog );
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
} elseif ( isset($_GET['token']) )
$this->auth();
elseif ( $this->token && $this->token_is_valid() )
@@ -915,11 +922,11 @@ class AtomParser {
if(count($this->in_content) == 2) {
array_push($this->in_content, ">");
}
-
+
array_push($this->in_content, "<". $this->ns_to_prefix($name) ."{$xmlns_str}{$attrs_str}");
} else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) {
$this->in_content = array();
- $this->is_xhtml = $attrs['type'] == 'xhtml';
+ $this->is_xhtml = $attrs['type'] == 'xhtml';
array_push($this->in_content, array($tag,$this->depth));
} else if($tag == 'link') {
array_push($this->entry->links, $attrs);
@@ -935,7 +942,7 @@ class AtomParser {
$tag = array_pop(split(":", $name));
if(!empty($this->in_content)) {
- if($this->in_content[0][0] == $tag &&
+ if($this->in_content[0][0] == $tag &&
$this->in_content[0][1] == $this->depth) {
array_shift($this->in_content);
if($this->is_xhtml) {
@@ -998,14 +1005,14 @@ class AtomParser {
}
}
}
- }
+ }
return $name;
}
function xml_escape($string)
{
- return str_replace(array('&','"',"'",'<','>'),
- array('&amp;','&quot;','&apos;','&lt;','&gt;'),
+ return str_replace(array('&','"',"'",'<','>'),
+ array('&amp;','&quot;','&apos;','&lt;','&gt;'),
$string );
}
}
diff --git a/wp-admin/import/blogware.php b/wp-admin/import/blogware.php
index c9e281c..0083230 100644
--- a/wp-admin/import/blogware.php
+++ b/wp-admin/import/blogware.php
@@ -91,6 +91,9 @@ class BW_Import {
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) ) {
+ return $post_id;
+ }
if (!$post_id) {
_e("Couldn't get post ID");
echo '</li>';
@@ -155,7 +158,9 @@ class BW_Import {
}
$this->file = $file['file'];
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -176,7 +181,9 @@ class BW_Import {
$this->greet();
break;
case 1 :
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ $result->get_error_message();
break;
}
diff --git a/wp-admin/import/btt.php b/wp-admin/import/btt.php
new file mode 100644
index 0000000..76a02c3
--- /dev/null
+++ b/wp-admin/import/btt.php
@@ -0,0 +1,115 @@
+<?php
+
+class BunnyTags_Import {
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Bunny&#8217;s Technorati Tags').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ echo '<div class="narrow">';
+ echo '<p>'.__('Howdy! This imports tags from an existing Bunny&#8217;s Technorati Tags installation into this blog using the new WordPress native tagging structure.').'</p>';
+ echo '<p>'.__('This is suitable for Bunny&#8217;s Technorati Tags version 0.6.').'</p>';
+ echo '<p><strong>'.__('All existing Bunny&#8217;s Technorati Tags will be removed after import.').'</strong></p>';
+ echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
+ echo '<form action="admin.php?import=btt&amp;step=1" method="post">';
+ wp_nonce_field('import-btt');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Tags &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function dispatch() {
+ if ( empty($_GET['step']) )
+ $step = 0;
+ else
+ $step = abs(intval($_GET['step']));
+
+ // load the header
+ $this->header();
+
+ switch ( $step ) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ check_admin_referer('import-btt');
+ $this->check_post_keyword( true );
+ break;
+ case 2 :
+ check_admin_referer('import-btt');
+ $this->check_post_keyword( false );
+ break;
+ case 3:
+ $this->done();
+ break;
+ }
+
+ // load the footer
+ $this->footer();
+ }
+
+ function check_post_keyword($precheck = true) {
+ global $wpdb;
+
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading Bunny&#8217;s Technorati Tags&#8230;').'</h3></p>';
+
+ // import Bunny's Keywords tags
+ $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'tags'");
+ if ( !is_array($metakeys)) {
+ echo '<p>' . __('No Tags Found!') . '</p>';
+ return false;
+ } else {
+ $count = count($metakeys);
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> posts with tags were read.'), $count ) . '<br /></p>';
+ echo '<ul>';
+ foreach ( $metakeys as $post_meta ) {
+ if ( $post_meta->meta_value != '' ) {
+ $post_keys = explode(' ', $post_meta->meta_value);
+ foreach ( $post_keys as $keyword ) {
+ $keyword = addslashes(trim(str_replace('+',' ',$keyword)));
+ if ( '' != $keyword ) {
+ echo '<li>' . $post_meta->post_id . '&nbsp;-&nbsp;' . $keyword . '</li>';
+ if ( !$precheck )
+ wp_add_post_tags($post_meta->post_id, $keyword);
+ }
+ }
+ }
+ if ( !$precheck )
+ delete_post_meta($post_meta->post_id, 'tags');
+ }
+ echo '</ul>';
+ }
+
+ echo '<form action="admin.php?import=btt&amp;step='.($precheck? 2:3).'" method="post">';
+ wp_nonce_field('import-btt');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function done() {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Import Complete!').'</h3></p>';
+ echo '</div>';
+ }
+
+ function BunnyTags_Import() {
+ }
+
+}
+
+// create the import object
+$btt_import = new BunnyTags_Import();
+
+// add it to the import page!
+register_importer('btt', 'Bunny&#8217;s Technorati Tags', __('Import Bunny&#8217;s Technorati Tags into the new native tagging structure.'), array($btt_import, 'dispatch'));
+
+?>
diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php
index 661e1a0..1bf0486 100644
--- a/wp-admin/import/dotclear.php
+++ b/wp-admin/import/dotclear.php
@@ -7,18 +7,6 @@
/**
Add These Functions to make our lives easier
**/
-if(!function_exists('get_catbynicename'))
-{
- function get_catbynicename($category_nicename)
- {
- global $wpdb;
-
- $cat_id -= 0; // force numeric
- $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
-
- return $name;
- }
-}
if(!function_exists('get_comment_count'))
{
@@ -29,15 +17,6 @@ if(!function_exists('get_comment_count'))
}
}
-if(!function_exists('link_cat_exists'))
-{
- function link_cat_exists($catname)
- {
- global $wpdb;
- return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"');
- }
-}
-
if(!function_exists('link_exists'))
{
function link_exists($linkname)
@@ -130,19 +109,19 @@ function textconv ($s) {
**/
class Dotclear_Import {
- function header()
+ function header()
{
echo '<div class="wrap">';
echo '<h2>'.__('Import DotClear').'</h2>';
echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
}
- function footer()
+ function footer()
{
echo '</div>';
}
- function greet()
+ function greet()
{
echo '<div class="narrow"><p>'.__('Howdy! This importer allows you to extract posts from a DotClear database into your blog. Mileage may vary.').'</p>';
echo '<p>'.__('Your DotClear Configuration settings are as follows:').'</p>';
@@ -385,6 +364,8 @@ class Dotclear_Import {
'ping_status' => $comment_status_map[$post_open_tb],
'comment_count' => $post_nb_comment + $post_nb_trackback)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
else
{
@@ -403,12 +384,17 @@ class Dotclear_Import {
'ping_status' => $comment_status_map[$post_open_tb],
'comment_count' => $post_nb_comment + $post_nb_trackback)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
$dcposts2wpposts[$post_id] = $ret_id;
// Make Post-to-Category associations
$cats = array();
- if($cat1 = get_catbynicename($post_cat_name)) { $cats[1] = $cat1; }
+ $category1 = get_category_by_slug($post_cat_name);
+ $category1 = $category1->term_id;
+
+ if($cat1 = $category1) { $cats[1] = $cat1; }
if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
}
@@ -509,12 +495,11 @@ class Dotclear_Import {
extract($link);
if ($title != "") {
- if ($cinfo = link_cat_exists (csc ($title))) {
- $category = $cinfo;
+ if ($cinfo = is_term(csc ($title), 'link_category')) {
+ $category = $cinfo['term_id'];
} else {
- $wpdb->query ("INSERT INTO $wpdb->linkcategories (cat_name) VALUES ('".
- $wpdb->escape (csc ($title))."')");
- $category = $wpdb->insert_id;
+ $category = wp_insert_term($wpdb->escape (csc ($title)), 'link_category');
+ $category = $category['term_id'];
}
} else {
$linkname = $wpdb->escape(csc ($label));
@@ -581,7 +566,9 @@ class Dotclear_Import {
{
// Post Import
$posts = $this->get_dc_posts();
- $this->posts2wp($posts);
+ $result = $this->posts2wp($posts);
+ if ( is_wp_error( $result ) )
+ return $result;
echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
wp_nonce_field('import-dotclear');
@@ -729,7 +716,9 @@ class Dotclear_Import {
$this->import_users();
break;
case 3 :
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
case 4 :
$this->import_comments();
diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php
index 4305cd1..6e92235 100644
--- a/wp-admin/import/greymatter.php
+++ b/wp-admin/import/greymatter.php
@@ -233,6 +233,8 @@ class GM_Import {
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
$post_ID = wp_insert_post($postdata);
+ if ( is_wp_error( $post_ID ) )
+ return $post_ID;
}
$c=count($entry);
@@ -287,6 +289,7 @@ class GM_Import {
<p><?php _e('Completed GreyMatter import!') ?></p>
<?php
$this->footer();
+ return;
}
function dispatch() {
@@ -301,7 +304,9 @@ class GM_Import {
break;
case 1:
check_admin_referer('import-greymatter');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
}
diff --git a/wp-admin/import/jkw.php b/wp-admin/import/jkw.php
new file mode 100644
index 0000000..9f7b48e
--- /dev/null
+++ b/wp-admin/import/jkw.php
@@ -0,0 +1,178 @@
+<?php
+
+class JeromesKeyword_Import {
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Jerome&#8217;s Keywords').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ echo '<div class="narrow">';
+ echo '<p>'.__('Howdy! This imports tags from an existing Jerome&#8217;s Keywords installation into this blog using the new WordPress native tagging structure.').'</p>';
+ echo '<p>'.__('This is suitable for Jerome&#8217;s Keywords version 1.x and 2.0a.').'</p>';
+ echo '<p><strong>'.__('All existing Jerome&#8217;s Keywords will be removed after import.').'</strong></p>';
+ echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
+ echo '<form action="admin.php?import=jkw&amp;step=1" method="post">';
+ wp_nonce_field('import-jkw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Version 1.x &raquo;').'" /></p>';
+ echo '</form>';
+ echo '<form action="admin.php?import=jkw&amp;step=3" method="post">';
+ wp_nonce_field('import-jkw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Version 2.0a &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function dispatch() {
+ if ( empty($_GET['step']) )
+ $step = 0;
+ else
+ $step = abs(intval($_GET['step']));
+
+ // load the header
+ $this->header();
+
+ switch ( $step ) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ check_admin_referer('import-jkw');
+ $this->check_V1_post_keyword( true );
+ break;
+ case 2 :
+ check_admin_referer('import-jkw');
+ $this->check_V1_post_keyword( false );
+ break;
+ case 3 :
+ check_admin_referer('import-jkw');
+ $this->check_V2_post_keyword( true );
+ break;
+ case 4 :
+ check_admin_referer('import-jkw');
+ $this->check_V2_post_keyword( false );
+ break;
+ case 5:
+ check_admin_referer('import-jkw');
+ $this->cleanup_V2_import();
+ break;
+ case 6:
+ $this->done();
+ break;
+ }
+
+ // load the footer
+ $this->footer();
+ }
+
+ function check_V1_post_keyword($precheck = true) {
+ global $wpdb;
+
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading Jerome&#8217;s Keywords Tags&#8230;').'</h3></p>';
+
+ // import Jerome's Keywords tags
+ $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'keywords'");
+ if ( !is_array($metakeys)) {
+ echo '<p>' . __('No Tags Found!') . '</p>';
+ return false;
+ } else {
+ $count = count($metakeys);
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> posts with tags were read.'), $count ) . '<br /></p>';
+ echo '<ul>';
+ foreach ( $metakeys as $post_meta ) {
+ if ( $post_meta->meta_value != '' ) {
+ $post_keys = explode(',', $post_meta->meta_value);
+ foreach ( $post_keys as $keyword ) {
+ $keyword = addslashes(trim($keyword));
+ if ( '' != $keyword ) {
+ echo '<li>' . $post_meta->post_id . '&nbsp;-&nbsp;' . $keyword . '</li>';
+ if ( !$precheck )
+ wp_add_post_tags($post_meta->post_id, $keyword);
+ }
+ }
+ }
+ if ( !$precheck )
+ delete_post_meta($post_meta->post_id, 'keywords');
+ }
+ echo '</ul>';
+ }
+
+ echo '<form action="admin.php?import=jkw&amp;step='.($precheck? 2:6).'" method="post">';
+ wp_nonce_field('import-jkw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function check_V2_post_keyword($precheck = true) {
+ global $wpdb;
+
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading Jerome&#8217;s Keywords Tags&#8230;').'</h3></p>';
+
+ // import Jerome's Keywords tags
+ $tablename = $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1);
+ $metakeys = $wpdb->get_results("SELECT post_id, tag_name FROM $tablename");
+ if ( !is_array($metakeys) ) {
+ echo '<p>' . __('No Tags Found!') . '</p>';
+ return false;
+ } else {
+ $count = count($metakeys);
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>';
+ echo '<ul>';
+ foreach ( $metakeys as $post_meta ) {
+ $keyword = addslashes(trim($post_meta->tag_name));
+ if ( $keyword != '' ) {
+ echo '<li>' . $post_meta->post_id . '&nbsp;-&nbsp;' . $keyword . '</li>';
+ if ( !$precheck )
+ wp_add_post_tags($post_meta->post_id, $keyword);
+ }
+ }
+ echo '</ul>';
+ }
+ echo '<form action="admin.php?import=jkw&amp;step='.($precheck? 4:5).'" method="post">';
+ wp_nonce_field('import-jkw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Next &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function cleanup_V2_import() {
+ global $wpdb;
+
+ /* options from V2.0a (jeromes-keywords.php) */
+ $options = array('version', 'keywords_table', 'query_varname', 'template', 'meta_always_include', 'meta_includecats', 'meta_autoheader', 'search_strict', 'use_feed_cats', 'post_linkformat', 'post_tagseparator', 'post_includecats', 'post_notagstext', 'cloud_linkformat', 'cloud_tagseparator', 'cloud_includecats', 'cloud_sortorder', 'cloud_displaymax', 'cloud_displaymin', 'cloud_scalemax', 'cloud_scalemin');
+
+ $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1));
+
+ foreach ( $options as $o )
+ delete_option('jkeywords_' . $o);
+
+ $this->done();
+ }
+
+ function done() {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Import Complete!').'</h3></p>';
+ echo '</div>';
+ }
+
+ function JeromesKeyword_Import() {
+ }
+
+}
+
+// create the import object
+$jkw_import = new JeromesKeyword_Import();
+
+// add it to the import page!
+register_importer('jkw', 'Jerome&#8217;s Keywords', __('Import Jerome&#8217;s Keywords into the new native tagging structure.'), array($jkw_import, 'dispatch'));
+
+?>
diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php
index ceeafeb..81f0365 100644
--- a/wp-admin/import/livejournal.php
+++ b/wp-admin/import/livejournal.php
@@ -49,7 +49,7 @@ class LJ_Import {
preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
$post_date = strtotime($post_date[1]);
- $post_date = gmdate('Y-m-d H:i:s', $post_date);
+ $post_date = date('Y-m-d H:i:s', $post_date);
preg_match('|<event>(.*?)</event>|is', $post, $post_content);
$post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
@@ -71,6 +71,8 @@ class LJ_Import {
printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
$postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
$post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
if (!$post_id) {
_e("Couldn't get post ID");
echo '</li>';
@@ -132,7 +134,9 @@ class LJ_Import {
}
$this->file = $file['file'];
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -154,7 +158,9 @@ class LJ_Import {
break;
case 1 :
check_admin_referer('import-upload');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php
index cd60654..44bdd61 100644
--- a/wp-admin/import/mt.php
+++ b/wp-admin/import/mt.php
@@ -22,7 +22,7 @@ class MT_Import {
$this->header();
?>
<div class="narrow">
-<p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, choose a file to upload and click Upload file and import.'); ?></p>
+<p><?php _e('Howdy! We&#8217;re about to begin importing all of your Movable Type or Typepad entries into WordPress. To begin, either choose a file to upload and click "Upload file and import," or use FTP to upload your MT export file as <code>mt-export.txt</code> in your <code>/wp-content/</code> directory and then click "Import mt-export.txt"'); ?></p>
<?php wp_import_upload_form( add_query_arg('step', 1) ); ?>
<p><?php _e('The importer is smart enough not to import duplicates, so you can run this multiple times without worry if&#8212;for whatever reason&#8212;it doesn\'t finish. If you get an <strong>out of memory</strong> error try splitting up the import file into pieces.'); ?> </p>
</div>
@@ -58,25 +58,27 @@ class MT_Import {
return $user_id;
}
- function get_entries() {
- set_magic_quotes_runtime(0);
- $importdata = file($this->file); // Read the file into an array
- $importdata = implode('', $importdata); // squish it
- $importdata = preg_replace("/(\r\n|\n|\r)/", "\n", $importdata);
- $importdata = preg_replace("/\n--------\n/", "--MT-ENTRY--\n", $importdata);
- $this->posts = explode("--MT-ENTRY--", $importdata);
- }
-
function get_mt_authors() {
- $temp = array ();
- $i = -1;
- foreach ($this->posts as $post) {
- if ('' != trim($post)) {
- ++ $i;
- preg_match("|AUTHOR:(.*)|", $post, $thematch);
- $thematch = trim($thematch[1]);
- array_push($temp, "$thematch"); //store the extracted author names in a temporary array
- }
+ $temp = array();
+ $authors = array();
+
+ $handle = fopen($this->file, 'r');
+ if ( $handle == null )
+ return false;
+
+ $in_comment = false;
+ while ( $line = fgets($handle) ) {
+ $line = trim($line);
+
+ if ( 'COMMENT:' == $line )
+ $in_comment = true;
+ else if ( '-----' == $line )
+ $in_comment = false;
+
+ if ( $in_comment || 0 !== strpos($line,"AUTHOR:") )
+ continue;
+
+ $temp[] = trim( substr($line, strlen("AUTHOR:")) );
}
//we need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.
@@ -88,6 +90,8 @@ class MT_Import {
array_push($authors, "$next");
}
+ fclose($handle);
+
return $authors;
}
@@ -121,7 +125,7 @@ class MT_Import {
?>
<div class="wrap">
<h2><?php _e('Assign Authors'); ?></h2>
-<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.'); ?></p>
+<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as admin\'s entries.'); ?></p>
<p><?php _e('Below, you can see the names of the authors of the MovableType posts in <i>italics</i>. For each of these names, you can either pick an author in your WordPress installation from the menu, or enter a name for the author in the textbox.'); ?></p>
<p><?php _e('If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)'); ?></p>
<?php
@@ -139,7 +143,7 @@ class MT_Import {
echo '</li>';
}
- echo '<input type="submit" value="'.__('Submit').'">'.'<br/>';
+ echo '<input type="submit" value="'.__('Submit').'">'.'<br />';
echo '</form>';
echo '</ol></div>';
@@ -157,226 +161,221 @@ class MT_Import {
$this->file = $file['file'];
$this->id = (int) $file['id'];
- $this->get_entries();
$this->mt_authors_form();
}
+ function save_post(&$post, &$comments, &$pings) {
+ // Reset the counter
+ set_time_limit(30);
+ $post = get_object_vars($post);
+ $post = add_magic_quotes($post);
+ $post = (object) $post;
+
+ if ( $post_id = post_exists($post->post_title, '', $post->post_date) ) {
+ echo '<li>';
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post->post_title));
+ } else {
+ echo '<li>';
+ printf(__('Importing post <i>%s</i>...'), stripslashes($post->post_title));
+
+ if ( '' != trim( $post->extended ) )
+ $post->post_content .= "\n<!--more-->\n$post->extended";
+
+ $post->post_author = $this->checkauthor($post->post_author); //just so that if a post already exists, new users are not created by checkauthor
+ $post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
+
+ // Add categories.
+ if ( 0 != count($post->categories) ) {
+ wp_create_categories($post->categories, $post_id);
+ }
+ }
+
+ $num_comments = 0;
+ foreach ( $comments as $comment ) {
+ $comment = get_object_vars($comment);
+ $comment = add_magic_quotes($comment);
+
+ if ( !comment_exists($comment['comment_author'], $comment['comment_date'])) {
+ $comment['comment_post_ID'] = $post_id;
+ $comment = wp_filter_comment($comment);
+ wp_insert_comment($comment);
+ $num_comments++;
+ }
+ }
+
+ if ( $num_comments )
+ printf(' '.__('(%s comments)'), $num_comments);
+
+ $num_pings = 0;
+ foreach ( $pings as $ping ) {
+ $ping = get_object_vars($ping);
+ $ping = add_magic_quotes($ping);
+
+ if ( !comment_exists($ping['comment_author'], $ping['comment_date'])) {
+ $ping['comment_content'] = "<strong>{$ping['title']}</strong>\n\n{$ping['comment_content']}";
+ $ping['comment_post_ID'] = $post_id;
+ $ping = wp_filter_comment($ping);
+ wp_insert_comment($ping);
+ $num_pings++;
+ }
+ }
+
+ if ( $num_pings )
+ printf(' '.__('(%s pings)'), $num_pings);
+
+ echo "</li>";
+ //ob_flush();flush();
+ }
+
function process_posts() {
global $wpdb;
- $i = -1;
+
+ $handle = fopen($this->file, 'r');
+ if ( $handle == null )
+ return false;
+
+ $context = '';
+ $post = new StdClass();
+ $comment = new StdClass();
+ $comments = array();
+ $ping = new StdClass();
+ $pings = array();
+
echo "<div class='wrap'><ol>";
- foreach ($this->posts as $post) {
- if ('' != trim($post)) {
- ++ $i;
- unset ($post_categories);
-
- // Take the pings out first
- preg_match("|(-----\n\nPING:.*)|s", $post, $pings);
- $post = preg_replace("|(-----\n\nPING:.*)|s", '', $post);
-
- // Then take the comments out
- preg_match("|(-----\nCOMMENT:.*)|s", $post, $comments);
- $post = preg_replace("|(-----\nCOMMENT:.*)|s", '', $post);
-
- // We ignore the keywords
- $post = preg_replace("|(-----\nKEYWORDS:.*)|s", '', $post);
-
- // We want the excerpt
- preg_match("|-----\nEXCERPT:(.*)|s", $post, $excerpt);
- $post_excerpt = $wpdb->escape(trim($excerpt[1]));
- $post = preg_replace("|(-----\nEXCERPT:.*)|s", '', $post);
-
- // We're going to put extended body into main body with a more tag
- preg_match("|-----\nEXTENDED BODY:(.*)|s", $post, $extended);
- $extended = trim($extended[1]);
- if ('' != $extended)
- $extended = "\n<!--more-->\n$extended";
- $post = preg_replace("|(-----\nEXTENDED BODY:.*)|s", '', $post);
-
- // Now for the main body
- preg_match("|-----\nBODY:(.*)|s", $post, $body);
- $body = trim($body[1]);
- $post_content = $wpdb->escape($body.$extended);
- $post = preg_replace("|(-----\nBODY:.*)|s", '', $post);
-
- // Grab the metadata from what's left
- $metadata = explode("\n", $post);
- foreach ($metadata as $line) {
- preg_match("/^(.*?):(.*)/", $line, $token);
- $key = trim($token[1]);
- $value = trim($token[2]);
- // Now we decide what it is and what to do with it
- switch ($key) {
- case '' :
- break;
- case 'AUTHOR' :
- $post_author = $value;
- break;
- case 'TITLE' :
- $post_title = $wpdb->escape($value);
- break;
- case 'STATUS' :
- // "publish" and "draft" enumeration items match up; no change required
- $post_status = $value;
- if (empty ($post_status))
- $post_status = 'publish';
- break;
- case 'ALLOW COMMENTS' :
- $post_allow_comments = $value;
- if ($post_allow_comments == 1) {
- $comment_status = 'open';
- } else {
- $comment_status = 'closed';
- }
- break;
- case 'CONVERT BREAKS' :
- $post_convert_breaks = $value;
- break;
- case 'ALLOW PINGS' :
- $ping_status = trim($meta[2][0]);
- if ($ping_status == 1) {
- $ping_status = 'open';
- } else {
- $ping_status = 'closed';
- }
- break;
- case 'PRIMARY CATEGORY' :
- if (! empty ($value) )
- $post_categories[] = $wpdb->escape($value);
- break;
- case 'CATEGORY' :
- if (! empty ($value) )
- $post_categories[] = $wpdb->escape($value);
- break;
- case 'DATE' :
- $post_modified = strtotime($value);
- $post_modified = date('Y-m-d H:i:s', $post_modified);
- $post_modified_gmt = get_gmt_from_date("$post_modified");
- $post_date = $post_modified;
- $post_date_gmt = $post_modified_gmt;
- break;
- default :
- // echo "\n$key: $value";
- break;
- } // end switch
- } // End foreach
-
- // Let's check to see if it's in already
- if ($post_id = post_exists($post_title, '', $post_date)) {
- echo '<li>';
- printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
- } else {
- echo '<li>';
- printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
-
- $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
-
- $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
- $post_id = wp_insert_post($postdata);
- // Add categories.
- if (0 != count($post_categories)) {
- wp_create_categories($post_categories, $post_id);
- }
- }
- $comment_post_ID = (int) $post_id;
- $comment_approved = 1;
-
- // Now for comments
- $comments = explode("-----\nCOMMENT:", $comments[0]);
- $num_comments = 0;
- foreach ($comments as $comment) {
- if ('' != trim($comment)) {
- // Author
- preg_match("|AUTHOR:(.*)|", $comment, $comment_author);
- $comment_author = $wpdb->escape(trim($comment_author[1]));
- $comment = preg_replace('|(\n?AUTHOR:.*)|', '', $comment);
- preg_match("|EMAIL:(.*)|", $comment, $comment_author_email);
- $comment_author_email = $wpdb->escape(trim($comment_author_email[1]));
- $comment = preg_replace('|(\n?EMAIL:.*)|', '', $comment);
-
- preg_match("|IP:(.*)|", $comment, $comment_author_IP);
- $comment_author_IP = trim($comment_author_IP[1]);
- $comment = preg_replace('|(\n?IP:.*)|', '', $comment);
-
- preg_match("|URL:(.*)|", $comment, $comment_author_url);
- $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
- $comment = preg_replace('|(\n?URL:.*)|', '', $comment);
-
- preg_match("|DATE:(.*)|", $comment, $comment_date);
- $comment_date = trim($comment_date[1]);
- $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
- $comment = preg_replace('|(\n?DATE:.*)|', '', $comment);
-
- $comment_content = $wpdb->escape(trim($comment));
- $comment_content = str_replace('-----', '', $comment_content);
- // Check if it's already there
- if (!comment_exists($comment_author, $comment_date)) {
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
- $commentdata = wp_filter_comment($commentdata);
- wp_insert_comment($commentdata);
- $num_comments++;
- }
- }
+ while ( $line = fgets($handle) ) {
+ $line = trim($line);
+
+ if ( '-----' == $line ) {
+ // Finishing a multi-line field
+ if ( 'comment' == $context ) {
+ $comments[] = $comment;
+ $comment = new StdClass();
+ } else if ( 'ping' == $context ) {
+ $pings[] = $ping;
+ $ping = new StdClass();
}
- if ( $num_comments )
- printf(' '.__('(%s comments)'), $num_comments);
-
- // Finally the pings
- // fix the double newline on the first one
- $pings[0] = str_replace("-----\n\n", "-----\n", $pings[0]);
- $pings = explode("-----\nPING:", $pings[0]);
- $num_pings = 0;
- foreach ($pings as $ping) {
- if ('' != trim($ping)) {
- // 'Author'
- preg_match("|BLOG NAME:(.*)|", $ping, $comment_author);
- $comment_author = $wpdb->escape(trim($comment_author[1]));
- $ping = preg_replace('|(\n?BLOG NAME:.*)|', '', $ping);
-
- preg_match("|IP:(.*)|", $ping, $comment_author_IP);
- $comment_author_IP = trim($comment_author_IP[1]);
- $ping = preg_replace('|(\n?IP:.*)|', '', $ping);
-
- preg_match("|URL:(.*)|", $ping, $comment_author_url);
- $comment_author_url = $wpdb->escape(trim($comment_author_url[1]));
- $ping = preg_replace('|(\n?URL:.*)|', '', $ping);
-
- preg_match("|DATE:(.*)|", $ping, $comment_date);
- $comment_date = trim($comment_date[1]);
- $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
- $ping = preg_replace('|(\n?DATE:.*)|', '', $ping);
-
- preg_match("|TITLE:(.*)|", $ping, $ping_title);
- $ping_title = $wpdb->escape(trim($ping_title[1]));
- $ping = preg_replace('|(\n?TITLE:.*)|', '', $ping);
-
- $comment_content = $wpdb->escape(trim($ping));
- $comment_content = str_replace('-----', '', $comment_content);
-
- $comment_content = "<strong>$ping_title</strong>\n\n$comment_content";
-
- $comment_type = 'trackback';
-
- // Check if it's already there
- if (!comment_exists($comment_author, $comment_date)) {
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved');
- $commentdata = wp_filter_comment($commentdata);
- wp_insert_comment($commentdata);
- $num_pings++;
- }
- }
+ $context = '';
+ } else if ( '--------' == $line ) {
+ // Finishing a post.
+ $context = '';
+ $result = $this->save_post($post, $comments, $pings);
+ if ( is_wp_error( $result ) )
+ return $result;
+ $post = new StdClass;
+ $comment = new StdClass();
+ $ping = new StdClass();
+ $comments = array();
+ $pings = array();
+ } else if ( 'BODY:' == $line ) {
+ $context = 'body';
+ } else if ( 'EXTENDED BODY:' == $line ) {
+ $context = 'extended';
+ } else if ( 'EXCERPT:' == $line ) {
+ $context = 'excerpt';
+ } else if ( 'KEYWORDS:' == $line ) {
+ $context = 'keywords';
+ } else if ( 'COMMENT:' == $line ) {
+ $context = 'comment';
+ } else if ( 'PING:' == $line ) {
+ $context = 'ping';
+ } else if ( 0 === strpos($line, "AUTHOR:") ) {
+ $author = trim( substr($line, strlen("AUTHOR:")) );
+ if ( '' == $context )
+ $post->post_author = $author;
+ else if ( 'comment' == $context )
+ $comment->comment_author = $author;
+ } else if ( 0 === strpos($line, "TITLE:") ) {
+ $title = trim( substr($line, strlen("TITLE:")) );
+ if ( '' == $context )
+ $post->post_title = $title;
+ else if ( 'ping' == $context )
+ $ping->title = $title;
+ } else if ( 0 === strpos($line, "STATUS:") ) {
+ $status = trim( substr($line, strlen("STATUS:")) );
+ if ( empty($status) )
+ $status = 'publish';
+ $post->post_status = $status;
+ } else if ( 0 === strpos($line, "ALLOW COMMENTS:") ) {
+ $allow = trim( substr($line, strlen("ALLOW COMMENTS:")) );
+ if ( $allow == 1 )
+ $post->comment_status = 'open';
+ else
+ $post->comment_status = 'closed';
+ } else if ( 0 === strpos($line, "ALLOW PINGS:") ) {
+ $allow = trim( substr($line, strlen("ALLOW PINGS:")) );
+ if ( $allow == 1 )
+ $post->ping_status = 'open';
+ else
+ $post->ping_status = 'closed';
+ } else if ( 0 === strpos($line, "CATEGORY:") ) {
+ $category = trim( substr($line, strlen("CATEGORY:")) );
+ if ( '' != $category )
+ $post->categories[] = $category;
+ } else if ( 0 === strpos($line, "PRIMARY CATEGORY:") ) {
+ $category = trim( substr($line, strlen("PRIMARY CATEGORY:")) );
+ if ( '' != $category )
+ $post->categories[] = $category;
+ } else if ( 0 === strpos($line, "DATE:") ) {
+ $date = trim( substr($line, strlen("DATE:")) );
+ $date = strtotime($date);
+ $date = date('Y-m-d H:i:s', $date);
+ $date_gmt = get_gmt_from_date($date);
+ if ( '' == $context ) {
+ $post->post_modified = $date;
+ $post->post_modified_gmt = $date_gmt;
+ $post->post_date = $date;
+ $post->post_date_gmt = $date_gmt;
+ } else if ( 'comment' == $context ) {
+ $comment->comment_date = $date;
+ } else if ( 'ping' == $context ) {
+ $ping->comment_date = $date;
+ }
+ } else if ( 0 === strpos($line, "EMAIL:") ) {
+ $email = trim( substr($line, strlen("EMAIL:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_email = $email;
+ else
+ $ping->comment_author_email = '';
+ } else if ( 0 === strpos($line, "IP:") ) {
+ $ip = trim( substr($line, strlen("IP:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_IP = $ip;
+ else
+ $ping->comment_author_IP = $ip;
+ } else if ( 0 === strpos($line, "URL:") ) {
+ $url = trim( substr($line, strlen("URL:")) );
+ if ( 'comment' == $context )
+ $comment->comment_author_url = $url;
+ else
+ $ping->comment_author_url = $url;
+ } else if ( 0 === strpos($line, "BLOG NAME:") ) {
+ $blog = trim( substr($line, strlen("BLOG NAME:")) );
+ $ping->comment_author = $blog;
+ } else {
+ // Processing multi-line field, check context.
+
+ $line .= "\n";
+ if ( 'body' == $context ) {
+ $post->post_content .= $line;
+ } else if ( 'extended' == $context ) {
+ $post->extended .= $line;
+ } else if ( 'excerpt' == $context ) {
+ $post->post_excerpt .= $line;
+ } else if ( 'comment' == $context ) {
+ $comment->comment_content .= $line;
+ } else if ( 'ping' == $context ) {
+ $ping->comment_content .= $line;
}
- if ( $num_pings )
- printf(' '.__('(%s pings)'), $num_pings);
-
- echo "</li>";
}
}
echo '</ol>';
wp_import_cleanup($this->id);
+ do_action('import_done', 'mt');
echo '<h3>'.sprintf(__('All done. <a href="%s">Have fun!</a>'), get_option('home')).'</h3></div>';
}
@@ -386,8 +385,9 @@ class MT_Import {
$this->file = get_attached_file($this->id);
$this->get_authors_from_post();
- $this->get_entries();
- $this->process_posts();
+ $result = $this->process_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
}
function dispatch() {
@@ -406,7 +406,9 @@ class MT_Import {
break;
case 2:
check_admin_referer('import-mt');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
}
diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php
index f46caa1..11fc770 100644
--- a/wp-admin/import/rss.php
+++ b/wp-admin/import/rss.php
@@ -110,6 +110,8 @@ class RSS_Import {
_e('Post already imported');
} else {
$post_id = wp_insert_post($post);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
if (!$post_id) {
_e("Couldn't get post ID");
return;
@@ -135,7 +137,9 @@ class RSS_Import {
$this->file = $file['file'];
$this->get_posts();
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
wp_import_cleanup($file['id']);
echo '<h3>';
@@ -157,7 +161,9 @@ class RSS_Import {
break;
case 1 :
check_admin_referer('import-upload');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
diff --git a/wp-admin/import/stp.php b/wp-admin/import/stp.php
new file mode 100644
index 0000000..9d5371c
--- /dev/null
+++ b/wp-admin/import/stp.php
@@ -0,0 +1,155 @@
+<?php
+class STP_Import {
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Simple Tagging').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ echo '<div class="narrow">';
+ echo '<p>'.__('Howdy! This imports tags from an existing Simple Tagging 1.6.2 installation into this blog using the new WordPress native tagging structure.').'</p>';
+ echo '<p>'.__('This has not been tested on any other versions of Simple Tagging. Mileage may vary.').'</p>';
+ echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 4-step program to help you kick that nasty Simple Tagging habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
+ echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
+ echo '<form action="admin.php?import=stp&amp;step=1" method="post">';
+ wp_nonce_field('import-stp');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function dispatch () {
+ if ( empty( $_GET['step'] ) ) {
+ $step = 0;
+ } else {
+ $step = (int) $_GET['step'];
+ }
+ // load the header
+ $this->header();
+ switch ( $step ) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ check_admin_referer('import-stp');
+ $this->import_posts();
+ break;
+ case 2:
+ check_admin_referer('import-stp');
+ $this->import_t2p();
+ break;
+ case 3:
+ check_admin_referer('import-stp');
+ $this->cleanup_import();
+ break;
+ }
+ // load the footer
+ $this->footer();
+ }
+
+
+ function import_posts ( ) {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading STP Post Tags&#8230;').'</h3></p>';
+
+ // read in all the STP tag -> post settings
+ $posts = $this->get_stp_posts();
+
+ // if we didn't get any tags back, that's all there is folks!
+ if ( !is_array($posts) ) {
+ echo '<p>' . __('No posts were found to have tags!') . '</p>';
+ return false;
+ }
+ else {
+ // if there's an existing entry, delete it
+ if ( get_option('stpimp_posts') ) {
+ delete_option('stpimp_posts');
+ }
+
+ add_option('stpimp_posts', $posts);
+ $count = count($posts);
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
+ }
+
+ echo '<form action="admin.php?import=stp&amp;step=2" method="post">';
+ wp_nonce_field('import-stp');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+
+ function import_t2p ( ) {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Adding Tags to Posts&#8230;').'</h3></p>';
+
+ // run that funky magic!
+ $tags_added = $this->tag2post();
+
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>';
+ echo '<form action="admin.php?import=stp&amp;step=3" method="post">';
+ wp_nonce_field('import-stp');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+ function get_stp_posts ( ) {
+ global $wpdb;
+ // read in all the posts from the STP post->tag table: should be wp_post2tag
+ $posts_query = "SELECT post_id, tag_name FROM " . $wpdb->prefix . "stp_tags";
+ $posts = $wpdb->get_results($posts_query);
+ return $posts;
+ }
+
+ function tag2post ( ) {
+ global $wpdb;
+
+ // get the tags and posts we imported in the last 2 steps
+ $posts = get_option('stpimp_posts');
+
+ // null out our results
+ $tags_added = 0;
+
+ // loop through each post and add its tags to the db
+ foreach ( $posts as $this_post ) {
+ $the_post = (int) $this_post->post_id;
+ $the_tag = $wpdb->escape($this_post->tag_name);
+ // try to add the tag
+ wp_add_post_tags($the_post, $the_tag);
+ $tags_added++;
+ }
+
+ // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
+ return $tags_added;
+ }
+
+ function cleanup_import ( ) {
+ delete_option('stpimp_posts');
+ $this->done();
+ }
+
+ function done ( ) {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Import Complete!').'</h3></p>';
+ echo '<p>' . __('OK, so we lied about this being a 4-step program! You&#8217;re done!') . '</p>';
+ echo '<p>' . __('Now wasn&#8217;t that easy?') . '</p>';
+ echo '</div>';
+ }
+
+ function STP_Import ( ) {
+ // Nothing.
+ }
+}
+
+// create the import object
+$stp_import = new STP_Import();
+
+// add it to the import page!
+register_importer('stp', 'Simple Tagging', __('Import Simple Tagging tags into the new native tagging structure.'), array($stp_import, 'dispatch'));
+?> \ No newline at end of file
diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php
index 2d2b145..1fe54c8 100644
--- a/wp-admin/import/textpattern.php
+++ b/wp-admin/import/textpattern.php
@@ -2,18 +2,6 @@
/**
Add These Functions to make our lives easier
**/
-if(!function_exists('get_catbynicename'))
-{
- function get_catbynicename($category_nicename)
- {
- global $wpdb;
-
- $cat_id -= 0; // force numeric
- $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"');
-
- return $name;
- }
-}
if(!function_exists('get_comment_count'))
{
@@ -38,14 +26,14 @@ if(!function_exists('link_exists'))
**/
class Textpattern_Import {
- function header()
+ function header()
{
echo '<div class="wrap">';
echo '<h2>'.__('Import Textpattern').'</h2>';
echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>';
}
- function footer()
+ function footer()
{
echo '</div>';
}
@@ -317,6 +305,8 @@ class Textpattern_Import {
'post_name' => $url_title,
'comment_count' => $comments_count)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
else
{
@@ -333,13 +323,19 @@ class Textpattern_Import {
'post_name' => $url_title,
'comment_count' => $comments_count)
);
+ if ( is_wp_error( $ret_id ) )
+ return $ret_id;
}
$txpposts2wpposts[$ID] = $ret_id;
// Make Post-to-Category associations
$cats = array();
- if($cat1 = get_catbynicename($Category1)) { $cats[1] = $cat1; }
- if($cat2 = get_catbynicename($Category2)) { $cats[2] = $cat2; }
+ $category1 = get_category_by_slug($Category1);
+ $category1 = $category1->term_id;
+ $category2 = get_category_by_slug($Category2);
+ $category2 = $category1->term_id;
+ if($cat1 = $category1) { $cats[1] = $cat1; }
+ if($cat2 = $category2) { $cats[2] = $cat2; }
if(!empty($cats)) { wp_set_post_categories($ret_id, $cats); }
}
@@ -506,7 +502,9 @@ class Textpattern_Import {
{
// Post Import
$posts = $this->get_txp_posts();
- $this->posts2wp($posts);
+ $result = $this->posts2wp($posts);
+ if ( is_wp_error( $result ) )
+ return $result;
echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
wp_nonce_field('import-textpattern');
@@ -559,11 +557,11 @@ class Textpattern_Import {
{
echo '<p>'.__('Welcome to WordPress. We hope (and expect!) that you will find this platform incredibly rewarding! As a new WordPress user coming from Textpattern, there are some things that we would like to point out. Hopefully, they will help your transition go as smoothly as possible.').'</p>';
echo '<h3>'.__('Users').'</h3>';
- echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn\'t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. <strong>Every user has the same username, but their passwords are reset to password123.</strong> So <a href="%1$s">Login</a> and change it.'), '/wp-login.php').'</p>';
+ echo '<p>'.sprintf(__('You have already setup WordPress and have been assigned an administrative login and password. Forget it. You didn&#8217;t have that login in Textpattern, why should you have it here? Instead we have taken care to import all of your users into our system. Unfortunately there is one downside. Because both WordPress and Textpattern uses a strong encryption hash with passwords, it is impossible to decrypt it and we are forced to assign temporary passwords to all your users. <strong>Every user has the same username, but their passwords are reset to password123.</strong> So <a href="%1$s">Login</a> and change it.'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
echo '<h3>'.__('Preserving Authors').'</h3>';
echo '<p>'.__('Secondly, we have attempted to preserve post authors. If you are the only author or contributor to your blog, then you are safe. In most cases, we are successful in this preservation endeavor. However, if we cannot ascertain the name of the writer due to discrepancies between database tables, we assign it to you, the administrative user.').'</p>';
echo '<h3>'.__('Textile').'</h3>';
- echo '<p>'.__('Also, since you\'re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>. Trust me... You\'ll want it.').'</p>';
+ echo '<p>'.__('Also, since you&#8217;re coming from Textpattern, you probably have been using Textile to format your comments and posts. If this is the case, we recommend downloading and installing <a href="http://www.huddledmasses.org/category/development/wordpress/textile/">Textile for WordPress</a>. Trust me... You&#8217;ll want it.').'</p>';
echo '<h3>'.__('WordPress Resources').'</h3>';
echo '<p>'.__('Finally, there are numerous WordPress resources around the internet. Some of them are:').'</p>';
echo '<ul>';
@@ -571,7 +569,7 @@ class Textpattern_Import {
echo '<li>'.__('<a href="http://wordpress.org/support/">The WordPress support forums</a>').'</li>';
echo '<li>'.__('<a href="http://codex.wordpress.org">The Codex (In other words, the WordPress Bible)</a>').'</li>';
echo '</ul>';
- echo '<p>'.sprintf(__('That\'s it! What are you waiting for? Go <a href="%1$s">login</a>!'), '/wp-login.php').'</p>';
+ echo '<p>'.sprintf(__('That&#8217;s it! What are you waiting for? Go <a href="%1$s">login</a>!'), get_bloginfo( 'wpurl' ) . '/wp-login.php').'</p>';
}
function db_form()
@@ -646,7 +644,9 @@ class Textpattern_Import {
$this->import_users();
break;
case 3 :
- $this->import_posts();
+ $result = $this->import_posts();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
case 4 :
$this->import_comments();
diff --git a/wp-admin/import/utw.php b/wp-admin/import/utw.php
new file mode 100644
index 0000000..b321f25
--- /dev/null
+++ b/wp-admin/import/utw.php
@@ -0,0 +1,276 @@
+<?php
+
+class UTW_Import {
+
+ function header() {
+ echo '<div class="wrap">';
+ echo '<h2>'.__('Import Ultimate Tag Warrior').'</h2>';
+ echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
+ }
+
+ function footer() {
+ echo '</div>';
+ }
+
+ function greet() {
+ echo '<div class="narrow">';
+ echo '<p>'.__('Howdy! This imports tags from an existing Ultimate Tag Warrior 3 installation into this blog using the new WordPress native tagging structure.').'</p>';
+ echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
+ echo '<p>'.__('To accommodate larger databases for those tag-crazy authors out there, we have made this into an easy 5-step program to help you kick that nasty UTW habit. Just keep clicking along and we will let you know when you are in the clear!').'</p>';
+ echo '<p><strong>'.__('Don&#8217;t be stupid - backup your database before proceeding!').'</strong></p>';
+ echo '<form action="admin.php?import=utw&amp;step=1" method="post">';
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+
+ function dispatch () {
+ if ( empty( $_GET['step'] ) ) {
+ $step = 0;
+ } else {
+ $step = (int) $_GET['step'];
+ }
+
+ if ( $step > 1 )
+ check_admin_referer('import-utw');
+
+ // load the header
+ $this->header();
+
+ switch ( $step ) {
+ case 0 :
+ $this->greet();
+ break;
+ case 1 :
+ $this->import_tags();
+ break;
+ case 2 :
+ $this->import_posts();
+ break;
+ case 3:
+ $this->import_t2p();
+ break;
+ case 4:
+ $this->cleanup_import();
+ break;
+ }
+
+ // load the footer
+ $this->footer();
+ }
+
+
+ function import_tags ( ) {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading UTW Tags&#8230;').'</h3></p>';
+
+ $tags = $this->get_utw_tags();
+
+ // if we didn't get any tags back, that's all there is folks!
+ if ( !is_array($tags) ) {
+ echo '<p>' . __('No Tags Found!') . '</p>';
+ return false;
+ }
+ else {
+
+ // if there's an existing entry, delete it
+ if ( get_option('utwimp_tags') ) {
+ delete_option('utwimp_tags');
+ }
+
+ add_option('utwimp_tags', $tags);
+
+
+ $count = count($tags);
+
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>';
+ echo '<p>' . __('The following tags were found:') . '</p>';
+
+ echo '<ul>';
+
+ foreach ( $tags as $tag_id => $tag_name ) {
+
+ echo '<li>' . $tag_name . '</li>';
+
+ }
+
+ echo '</ul>';
+
+ echo '<br />';
+
+ echo '<p>' . __('If you don&#8217;t want to import any of these tags, you should delete them from the UTW tag management page and then re-run this import.') . '</p>';
+
+
+ }
+
+ echo '<form action="admin.php?import=utw&amp;step=2" method="post">';
+ wp_nonce_field('import-utw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+ }
+
+
+ function import_posts ( ) {
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Reading UTW Post Tags&#8230;').'</h3></p>';
+
+ // read in all the UTW tag -> post settings
+ $posts = $this->get_utw_posts();
+
+ // if we didn't get any tags back, that's all there is folks!
+ if ( !is_array($posts) ) {
+ echo '<p>' . __('No posts were found to have tags!') . '</p>';
+ return false;
+ }
+ else {
+
+ // if there's an existing entry, delete it
+ if ( get_option('utwimp_posts') ) {
+ delete_option('utwimp_posts');
+ }
+
+ add_option('utwimp_posts', $posts);
+
+
+ $count = count($posts);
+
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
+
+ }
+
+ echo '<form action="admin.php?import=utw&amp;step=3" method="post">';
+ wp_nonce_field('import-utw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+
+ }
+
+
+ function import_t2p ( ) {
+
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Adding Tags to Posts&#8230;').'</h3></p>';
+
+ // run that funky magic!
+ $tags_added = $this->tag2post();
+
+ echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags where added!'), $tags_added ) . '<br /></p>';
+
+ echo '<form action="admin.php?import=utw&amp;step=4" method="post">';
+ wp_nonce_field('import-utw');
+ echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 4 &raquo;').'" /></p>';
+ echo '</form>';
+ echo '</div>';
+
+ }
+
+
+ function get_utw_tags ( ) {
+
+ global $wpdb;
+
+ // read in all the tags from the UTW tags table: should be wp_tags
+ $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
+
+ $tags = $wpdb->get_results($tags_query);
+
+ // rearrange these tags into something we can actually use
+ foreach ( $tags as $tag ) {
+
+ $new_tags[$tag->tag_id] = $tag->tag;
+
+ }
+
+ return $new_tags;
+
+ }
+
+ function get_utw_posts ( ) {
+
+ global $wpdb;
+
+ // read in all the posts from the UTW post->tag table: should be wp_post2tag
+ $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
+
+ $posts = $wpdb->get_results($posts_query);
+
+ return $posts;
+
+ }
+
+
+ function tag2post ( ) {
+
+ // get the tags and posts we imported in the last 2 steps
+ $tags = get_option('utwimp_tags');
+ $posts = get_option('utwimp_posts');
+
+ // null out our results
+ $tags_added = 0;
+
+ // loop through each post and add its tags to the db
+ foreach ( $posts as $this_post ) {
+
+ $the_post = (int) $this_post->post_id;
+ $the_tag = (int) $this_post->tag_id;
+
+ // what's the tag name for that id?
+ $the_tag = $tags[$the_tag];
+
+ // screw it, just try to add the tag
+ wp_add_post_tags($the_post, $the_tag);
+
+ $tags_added++;
+
+ }
+
+ // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
+ return $tags_added;
+
+
+ }
+
+
+ function cleanup_import ( ) {
+
+ delete_option('utwimp_tags');
+ delete_option('utwimp_posts');
+
+ $this->done();
+
+ }
+
+
+ function done ( ) {
+
+ echo '<div class="narrow">';
+ echo '<p><h3>'.__('Import Complete!').'</h3></p>';
+
+ echo '<p>' . __('OK, so we lied about this being a 5-step program! You&#8217;re done!') . '</p>';
+
+ echo '<p>' . __('Now wasn&#8217;t that easy?') . '</p>';
+
+ echo '</div>';
+
+ }
+
+
+ function UTW_Import ( ) {
+
+ // Nothing.
+
+ }
+
+}
+
+
+// create the import object
+$utw_import = new UTW_Import();
+
+// add it to the import page!
+register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into the new native tagging structure.'), array($utw_import, 'dispatch'));
+
+?> \ No newline at end of file
diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php
index a56e30a..f39e9bb 100644
--- a/wp-admin/import/wordpress.php
+++ b/wp-admin/import/wordpress.php
@@ -69,39 +69,52 @@ class WP_Import {
function get_entries() {
set_magic_quotes_runtime(0);
- $importdata = array_map('rtrim', file($this->file)); // Read the file into an array
$this->posts = array();
$this->categories = array();
+ $this->tags = array();
$num = 0;
$doing_entry = false;
- foreach ($importdata as $importline) {
- if ( false !== strpos($importline, '<wp:category>') ) {
- preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
- $this->categories[] = $category[1];
- continue;
- }
- if ( false !== strpos($importline, '<item>') ) {
- $this->posts[$num] = '';
- $doing_entry = true;
- continue;
- }
- if ( false !== strpos($importline, '</item>') ) {
- $num++;
- $doing_entry = false;
- continue;
- }
- if ( $doing_entry ) {
- $this->posts[$num] .= $importline . "\n";
+
+ $fp = fopen($this->file, 'r');
+ if ($fp) {
+ while ( !feof($fp) ) {
+ $importline = rtrim(fgets($fp));
+
+ if ( false !== strpos($importline, '<wp:category>') ) {
+ preg_match('|<wp:category>(.*?)</wp:category>|is', $importline, $category);
+ $this->categories[] = $category[1];
+ continue;
+ }
+ if ( false !== strpos($importline, '<wp:tag>') ) {
+ preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag);
+ $this->tags[] = $tag[1];
+ continue;
+ }
+ if ( false !== strpos($importline, '<item>') ) {
+ $this->posts[$num] = '';
+ $doing_entry = true;
+ continue;
+ }
+ if ( false !== strpos($importline, '</item>') ) {
+ $num++;
+ $doing_entry = false;
+ continue;
+ }
+ if ( $doing_entry ) {
+ $this->posts[$num] .= $importline . "\n";
+ }
}
- }
- foreach ($this->posts as $post) {
- $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
- if ($post_ID) {
- $this->posts_processed[$post_ID][0] = &$post;
- $this->posts_processed[$post_ID][1] = 0;
+ foreach ($this->posts as $post) {
+ $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
+ if ($post_ID) {
+ $this->posts_processed[$post_ID][0] = &$post;
+ $this->posts_processed[$post_ID][1] = 0;
+ }
}
+
+ fclose($fp);
}
}
@@ -128,6 +141,32 @@ class WP_Import {
return $authors;
}
+ function get_authors_from_post() {
+ $formnames = array ();
+ $selectnames = array ();
+
+ foreach ($_POST['user'] as $key => $line) {
+ $newname = trim(stripslashes($line));
+ if ($newname == '')
+ $newname = 'left_blank'; //passing author names from step 1 to step 2 is accomplished by using POST. left_blank denotes an empty entry in the form.
+ array_push($formnames, "$newname");
+ } // $formnames is the array with the form entered names
+
+ foreach ($_POST['userselect'] as $user => $key) {
+ $selected = trim(stripslashes($key));
+ array_push($selectnames, "$selected");
+ }
+
+ $count = count($formnames);
+ for ($i = 0; $i < $count; $i ++) {
+ if ($selectnames[$i] != '#NONE#') { //if no name was selected from the select menu, use the name entered in the form
+ array_push($this->newauthornames, "$selectnames[$i]");
+ } else {
+ array_push($this->newauthornames, "$formnames[$i]");
+ }
+ }
+ }
+
function wp_authors_form() {
?>
<h2><?php _e('Assign Authors'); ?></h2>
@@ -147,7 +186,7 @@ class WP_Import {
echo '</li>';
}
- echo '<input type="submit" value="Submit">'.'<br/>';
+ echo '<input type="submit" value="Submit">'.'<br />';
echo '</form>';
echo '</ol>';
@@ -170,7 +209,7 @@ class WP_Import {
function process_categories() {
global $wpdb;
- $cat_names = (array) $wpdb->get_col("SELECT cat_name FROM $wpdb->categories");
+ $cat_names = (array) get_terms('category', 'fields=names');
while ( $c = array_shift($this->categories) ) {
$cat_name = trim($this->get_tag( $c, 'wp:cat_name' ));
@@ -196,12 +235,36 @@ class WP_Import {
}
}
+ function process_tags() {
+ global $wpdb;
+
+ $tag_names = (array) get_terms('post_tag', 'fields=names');
+
+ while ( $c = array_shift($this->tags) ) {
+ $tag_name = trim($this->get_tag( $c, 'wp:tag_name' ));
+
+ // If the category exists we leave it alone
+ if ( in_array($tag_name, $tag_names) )
+ continue;
+
+ $slug = $this->get_tag( $c, 'wp:tag_slug' );
+ $description = $this->get_tag( $c, 'wp:tag_description' );
+
+ $tagarr = compact('slug', 'description');
+
+ $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr);
+ }
+ }
+
function process_posts() {
$i = -1;
echo '<ol>';
- foreach ($this->posts as $post)
- $this->process_post($post);
+ foreach ($this->posts as $post) {
+ $result = $this->process_post($post);
+ if ( is_wp_error( $result ) )
+ return $result;
+ }
echo '</ol>';
@@ -236,6 +299,15 @@ class WP_Import {
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);
+ preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
+ $tags = $tags[1];
+
+ $tag_index = 0;
+ foreach ($tags as $tag) {
+ $tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $tag)));
+ $tag_index++;
+ }
+
preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
$categories = $categories[1];
@@ -253,7 +325,11 @@ class WP_Import {
// If it has parent, process parent first.
$post_parent = (int) $post_parent;
if ($parent = $this->posts_processed[$post_parent]) {
- if (!$parent[1]) $this->process_post($parent[0]); // If not yet, process the parent first.
+ if (!$parent[1]) {
+ $result = $this->process_post($parent[0]); // If not yet, process the parent first.
+ if ( is_wp_error( $result ) )
+ return $result;
+ }
$post_parent = $parent[1]; // New ID of the parent;
}
@@ -264,6 +340,8 @@ class WP_Import {
$postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'post_name', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt', 'guid', 'post_parent', 'menu_order', 'post_type');
$comment_post_ID = $post_id = wp_insert_post($postdata);
+ if ( is_wp_error( $post_id ) )
+ return $post_id;
// Memorize old and new ID.
if ( $post_id && $post_ID && $this->posts_processed[$post_ID] )
@@ -273,14 +351,38 @@ class WP_Import {
if (count($categories) > 0) {
$post_cats = array();
foreach ($categories as $category) {
- $cat_ID = (int) $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name = '$category'");
+ $slug = sanitize_term_field('slug', $category, 0, 'category', 'db');
+ $cat = get_term_by('slug', $slug, 'category');
+ $cat_ID = 0;
+ if ( ! empty($cat) )
+ $cat_ID = $cat->term_id;
if ($cat_ID == 0) {
+ $category = $wpdb->escape($category);
$cat_ID = wp_insert_category(array('cat_name' => $category));
}
$post_cats[] = $cat_ID;
}
wp_set_post_categories($post_id, $post_cats);
- }
+ }
+
+ // Add tags.
+ if (count($tags) > 0) {
+ $post_tags = array();
+ foreach ($tags as $tag) {
+ $slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
+ $tag_obj = get_term_by('slug', $slug, 'post_tag');
+ $tag_id = 0;
+ if ( ! empty($tag_obj) )
+ $tag_id = $tag_obj->term_id;
+ if ( $tag_id == 0 ) {
+ $tag = $wpdb->escape($tag);
+ $tag_id = wp_insert_term($tag, 'post_tag');
+ $tag_id = $tag_id['term_id'];
+ }
+ $post_tags[] = $tag_id;
+ }
+ wp_set_post_tags($post_id, $post_tags);
+ }
}
// Now for comments
@@ -324,9 +426,13 @@ class WP_Import {
$this->id = (int) $_GET['id'];
$this->file = get_attached_file($this->id);
+ $this->get_authors_from_post();
$this->get_entries();
$this->process_categories();
- $this->process_posts();
+ $this->process_tags();
+ $result = $this->process_posts();
+ if ( is_wp_error( $result ) )
+ return $result;
}
function dispatch() {
@@ -346,7 +452,9 @@ class WP_Import {
break;
case 2:
check_admin_referer('import-wordpress');
- $this->import();
+ $result = $this->import();
+ if ( is_wp_error( $result ) )
+ echo $result->get_error_message();
break;
}
$this->footer();
diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php
new file mode 100644
index 0000000..ee4104e
--- /dev/null
+++ b/wp-admin/import/wp-cat2tag.php
@@ -0,0 +1,240 @@
+<?php
+
+class WP_Categories_to_Tags {
+ var $categories_to_convert = array();
+ var $all_categories = array();
+
+ function header() {
+ print '<div class="wrap">';
+ print '<h2>' . __('Convert Categories to Tags') . '</h2>';
+ }
+
+ function footer() {
+ print '</div>';
+ }
+
+ function populate_all_categories() {
+ global $wpdb;
+
+ $categories = get_categories('get=all');
+ foreach ( $categories as $category ) {
+ if ( !tag_exists($wpdb->escape($category->name)) )
+ $this->all_categories[] = $category;
+ }
+ }
+
+ function welcome() {
+ $this->populate_all_categories();
+
+ print '<div class="narrow">';
+
+ if (count($this->all_categories) > 0) {
+ print '<p>' . __('Howdy! This converter allows you to selectively convert existing categories to tags. To get started, check the checkboxes of the categories you wish to be converted, then click the Convert button.') . '</p>';
+ print '<p>' . __('Keep in mind that if you convert a category with child categories, those child categories get their parent setting removed, so they\'re in the root.') . '</p>';
+
+ $this->categories_form();
+ } else {
+ print '<p>'.__('You have no categories to convert!').'</p>';
+ }
+
+ print '</div>';
+ }
+
+ function categories_form() {
+ print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
+ wp_nonce_field('import-cat2tag');
+ print '<ul style="list-style:none">';
+
+ $hier = _get_term_hierarchy('category');
+
+ foreach ($this->all_categories as $category) {
+ $category = sanitize_term( $category, 'category', 'display' );
+
+ if ((int) $category->parent == 0) {
+ print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->term_id) . '" /> ' . $category->name . ' (' . $category->count . ')</label>';
+
+ if (isset($hier[$category->term_id])) {
+ $this->_category_children($category, $hier);
+ }
+
+ print '</li>';
+ }
+ }
+
+ print '</ul>';
+
+ print '<p class="submit"><input type="submit" name="maybe_convert_all_cats" value="' . __('Convert All Categories') . '" /> <input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
+ print '</form>';
+ }
+
+ function _category_children($parent, $hier) {
+ print '<ul style="list-style:none">';
+
+ foreach ($hier[$parent->term_id] as $child_id) {
+ $child =& get_category($child_id);
+
+ print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->term_id) . '" /> ' . $child->name . ' (' . $child->count . ')</label>';
+
+ if (isset($hier[$child->term_id])) {
+ $this->_category_children($child, $hier);
+ }
+
+ print '</li>';
+ }
+
+ print '</ul>';
+ }
+
+ function _category_exists($cat_id) {
+ global $wpdb;
+
+ $cat_id = (int) $cat_id;
+
+ $maybe_exists = category_exists($cat_id);
+
+ if ( $maybe_exists ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function convert_them() {
+ global $wpdb;
+
+ if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) {
+ print '<div class="narrow">';
+ print '<p>' . sprintf(__('Uh, oh. Something didn\'t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>';
+ print '</div>';
+ return;
+ }
+
+
+ if ( empty($this->categories_to_convert) )
+ $this->categories_to_convert = $_POST['cats_to_convert'];
+ $hier = _get_term_hierarchy('category');
+
+ print '<ul>';
+
+ foreach ( (array) $this->categories_to_convert as $cat_id) {
+ $cat_id = (int) $cat_id;
+
+ print '<li>' . sprintf(__('Converting category #%s ... '), $cat_id);
+
+ if (!$this->_category_exists($cat_id)) {
+ _e('Category doesn\'t exist!');
+ } else {
+ $category =& get_category($cat_id);
+
+ if ( tag_exists($wpdb->escape($category->name)) ) {
+ _e('Category is already a tag.');
+ print '</li>';
+ continue;
+ }
+
+ // If the category is the default, leave category in place and create tag.
+ if ( get_option('default_category') == $category->term_id ) {
+ $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug));
+ $id = $id['term_taxonomy_id'];
+ $posts = get_objects_in_term($category->term_id, 'category');
+ foreach ( $posts as $post ) {
+ if ( !$wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") )
+ $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')");
+ }
+ } else {
+ // Change the category to a tag.
+ $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
+
+ // Set all parents to 0 (root-level) if their parent was the converted tag
+ $wpdb->query("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
+ }
+ // Clean the cache
+ clean_category_cache($category->term_id);
+
+ _e('Converted successfully.');
+ }
+
+ print '</li>';
+ }
+
+ print '</ul>';
+ }
+
+ function convert_all_confirm() {
+ print '<div class="narrow">';
+
+ print '<h3>' . __('Confirm') . '</h3>';
+
+ print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>';
+
+ print '<form action="admin.php?import=wp-cat2tag" method="post">';
+ wp_nonce_field('import-cat2tag');
+ print '<p style="text-align:center" class="submit"><input type="submit" value="' . __('Yes') . '" name="yes_convert_all_cats" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="' . __('No') . '" name="no_dont_do_it" /></p>';
+ print '</form>';
+
+ print '</div>';
+ }
+
+ function convert_all() {
+ global $wpdb;
+
+ $this->populate_all_categories();
+ foreach ( $this->all_categories as $category )
+ $this->categories_to_convert[] = $category->term_id;
+ $this->convert_them();
+ }
+
+ function init() {
+
+ if (isset($_POST['maybe_convert_all_cats'])) {
+ $step = 3;
+ } elseif (isset($_POST['yes_convert_all_cats'])) {
+ $step = 4;
+ } elseif (isset($_POST['no_dont_do_it'])) {
+ die('no_dont_do_it');
+ } else {
+ $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
+ }
+
+ $this->header();
+
+ if (!current_user_can('manage_categories')) {
+ print '<div class="narrow">';
+ print '<p>' . __('Cheatin&#8217; uh?') . '</p>';
+ print '</div>';
+ } else {
+ if ( $step > 1 )
+ check_admin_referer('import-cat2tag');
+
+ switch ($step) {
+ case 1 :
+ $this->welcome();
+ break;
+
+ case 2 :
+ $this->convert_them();
+ break;
+
+ case 3 :
+ $this->convert_all_confirm();
+ break;
+
+ case 4 :
+ $this->convert_all();
+ break;
+ }
+ }
+
+ $this->footer();
+ }
+
+ function WP_Categories_to_Tags() {
+ // Do nothing.
+ }
+}
+
+$wp_cat2tag_importer = new WP_Categories_to_Tags();
+
+register_importer('wp-cat2tag', __('Categories to Tags Converter'), __('Convert existing categories to tags, selectively.'), array(&$wp_cat2tag_importer, 'init'));
+
+?>