summaryrefslogtreecommitdiffstats
path: root/wp-admin/import
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-05-21 18:37:58 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-05-21 18:37:58 +0000
commit89fe0ff804e7c6497ebacc8b341ac89974f6f255 (patch)
tree3fce310b29c685008fdbb75c5ab531bc3a6ae12a /wp-admin/import
parenta139071806ba941346a109fbefb2d5f22bae1cc4 (diff)
downloadwordpress-mu-89fe0ff804e7c6497ebacc8b341ac89974f6f255.tar.gz
wordpress-mu-89fe0ff804e7c6497ebacc8b341ac89974f6f255.tar.xz
wordpress-mu-89fe0ff804e7c6497ebacc8b341ac89974f6f255.zip
WP Merge to rev 5499, this is a big one! Test it before you put it live!
Test only, not for production use yet git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@972 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-admin/import')
-rw-r--r--wp-admin/import/blogger.php4
-rw-r--r--wp-admin/import/dotclear.php32
-rw-r--r--wp-admin/import/greymatter.php8
-rw-r--r--wp-admin/import/livejournal.php3
-rw-r--r--wp-admin/import/mt.php3
-rw-r--r--wp-admin/import/rss.php1
-rw-r--r--wp-admin/import/textpattern.php36
-rw-r--r--wp-admin/import/utw.php270
-rw-r--r--wp-admin/import/wordpress.php242
-rw-r--r--wp-admin/import/wp-cat2tag.php226
10 files changed, 705 insertions, 120 deletions
diff --git a/wp-admin/import/blogger.php b/wp-admin/import/blogger.php
index fdc6004..4ad7a97 100644
--- a/wp-admin/import/blogger.php
+++ b/wp-admin/import/blogger.php
@@ -743,10 +743,11 @@ class Blogger_Import {
// Step 9: Congratulate the user
function congrats() {
+ $blog = (int) $_GET['blog'];
echo '<h1>'.__('Congratulations!').'</h1><p>'.__('Now that you have imported your Blogger blog into WordPress, what are you going to do? Here are some suggestions:').'</p><ul><li>'.__('That was hard work! Take a break.').'</li>';
if ( count($this->import['blogs']) > 1 )
echo '<li>'.__('In case you haven\'t done it already, you can import the posts from your other blogs:'). $this->show_blogs() . '</li>';
- if ( $n = count($this->import['blogs'][$_GET['blog']]['newusers']) )
+ if ( $n = count($this->import['blogs'][$blog]['newusers']) )
echo '<li>'.sprintf(__('Go to <a href="%s" target="%s">Authors &amp; Users</a>, where you can modify the new user(s) or delete them. If you want to make all of the imported posts yours, you will be given that option when you delete the new authors.'), 'users.php', '_parent').'</li>';
echo '<li>'.__('For security, click the link below to reset this importer.').'</li>';
echo '</ul>';
@@ -765,6 +766,7 @@ 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 );
} elseif ( isset($_GET['token']) )
$this->auth();
diff --git a/wp-admin/import/dotclear.php b/wp-admin/import/dotclear.php
index 9a32e3a..661e1a0 100644
--- a/wp-admin/import/dotclear.php
+++ b/wp-admin/import/dotclear.php
@@ -147,8 +147,9 @@ class Dotclear_Import {
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>';
echo '<form action="admin.php?import=dotclear&amp;step=1" method="post">';
+ wp_nonce_field('import-dotclear');
$this->db_form();
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Categories').' &raquo;" /></p>';
+ echo '<p class="submit"><input type="submit" name="submit" value="'.attribute_escape(__('Import Categories &raquo;')).'" /></p>';
echo '</form></div>';
}
@@ -558,7 +559,8 @@ class Dotclear_Import {
echo '<form action="admin.php?import=dotclear&amp;step=2" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
+ wp_nonce_field('import-dotclear');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Users')));
echo '</form>';
}
@@ -570,7 +572,8 @@ class Dotclear_Import {
$this->users2wp($users);
echo '<form action="admin.php?import=dotclear&amp;step=3" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
+ wp_nonce_field('import-dotclear');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Posts')));
echo '</form>';
}
@@ -581,7 +584,8 @@ class Dotclear_Import {
$this->posts2wp($posts);
echo '<form action="admin.php?import=dotclear&amp;step=4" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
+ wp_nonce_field('import-dotclear');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Comments')));
echo '</form>';
}
@@ -592,7 +596,8 @@ class Dotclear_Import {
$this->comments2wp($comments);
echo '<form action="admin.php?import=dotclear&amp;step=5" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
+ wp_nonce_field('import-dotclear');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Links')));
echo '</form>';
}
@@ -604,7 +609,8 @@ class Dotclear_Import {
add_option('dc_links', $links);
echo '<form action="admin.php?import=dotclear&amp;step=6" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
+ wp_nonce_field('import-dotclear');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Finish')));
echo '</form>';
}
@@ -667,42 +673,44 @@ class Dotclear_Import {
if ( $step > 0 )
{
+ check_admin_referer('import-dotclear');
+
if($_POST['dbuser'])
{
if(get_option('dcuser'))
delete_option('dcuser');
- add_option('dcuser',$_POST['dbuser']);
+ add_option('dcuser', sanitize_user($_POST['dbuser'], true));
}
if($_POST['dbpass'])
{
if(get_option('dcpass'))
delete_option('dcpass');
- add_option('dcpass',$_POST['dbpass']);
+ add_option('dcpass', sanitize_user($_POST['dbpass'], true));
}
if($_POST['dbname'])
{
if(get_option('dcname'))
delete_option('dcname');
- add_option('dcname',$_POST['dbname']);
+ add_option('dcname', sanitize_user($_POST['dbname'], true));
}
if($_POST['dbhost'])
{
if(get_option('dchost'))
delete_option('dchost');
- add_option('dchost',$_POST['dbhost']);
+ add_option('dchost', sanitize_user($_POST['dbhost'], true));
}
if($_POST['dccharset'])
{
if(get_option('dccharset'))
delete_option('dccharset');
- add_option('dccharset',$_POST['dccharset']);
+ add_option('dccharset', sanitize_user($_POST['dccharset'], true));
}
if($_POST['dbprefix'])
{
if(get_option('dcdbprefix'))
delete_option('dcdbprefix');
- add_option('dcdbprefix',$_POST['dbprefix']);
+ add_option('dcdbprefix', sanitize_user($_POST['dbprefix'], true));
}
diff --git a/wp-admin/import/greymatter.php b/wp-admin/import/greymatter.php
index 9203ff7..4305cd1 100644
--- a/wp-admin/import/greymatter.php
+++ b/wp-admin/import/greymatter.php
@@ -34,6 +34,7 @@ class GM_Import {
<form name="stepOne" method="get">
<input type="hidden" name="import" value="greymatter" />
<input type="hidden" name="step" value="1" />
+<?php wp_nonce_field('import-greymatter'); ?>
<h3><?php _e('Second step: GreyMatter details:') ?></h3>
<p><table cellpadding="0">
<tr>
@@ -87,10 +88,12 @@ class GM_Import {
}
if (!chdir($archivespath))
- wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $archivespath));
+ wp_die(__("Wrong path, the path to the GM entries does not exist on the server"));
if (!chdir($gmpath))
- wp_die(sprintf(__("Wrong path, %s\ndoesn't exist\non the server"), $gmpath));
+ wp_die(__("Wrong path, the path to the GM files does not exist on the server"));
+
+ $lastentry = (int) $lastentry;
$this->header();
?>
@@ -297,6 +300,7 @@ class GM_Import {
$this->greet();
break;
case 1:
+ check_admin_referer('import-greymatter');
$this->import();
break;
}
diff --git a/wp-admin/import/livejournal.php b/wp-admin/import/livejournal.php
index 690005b..c3b821a 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]));
@@ -153,6 +153,7 @@ class LJ_Import {
$this->greet();
break;
case 1 :
+ check_admin_referer('import-upload');
$this->import();
break;
}
diff --git a/wp-admin/import/mt.php b/wp-admin/import/mt.php
index 1effb5c..cd60654 100644
--- a/wp-admin/import/mt.php
+++ b/wp-admin/import/mt.php
@@ -130,6 +130,7 @@ class MT_Import {
$authors = $this->get_mt_authors();
echo '<ol id="authors">';
echo '<form action="?import=mt&amp;step=2&amp;id=' . $this->id . '" method="post">';
+ wp_nonce_field('import-mt');
$j = -1;
foreach ($authors as $author) {
++ $j;
@@ -400,9 +401,11 @@ class MT_Import {
$this->greet();
break;
case 1 :
+ check_admin_referer('import-upload');
$this->select_authors();
break;
case 2:
+ check_admin_referer('import-mt');
$this->import();
break;
}
diff --git a/wp-admin/import/rss.php b/wp-admin/import/rss.php
index 944b297..f46caa1 100644
--- a/wp-admin/import/rss.php
+++ b/wp-admin/import/rss.php
@@ -156,6 +156,7 @@ class RSS_Import {
$this->greet();
break;
case 1 :
+ check_admin_referer('import-upload');
$this->import();
break;
}
diff --git a/wp-admin/import/textpattern.php b/wp-admin/import/textpattern.php
index db60e15..286d74a 100644
--- a/wp-admin/import/textpattern.php
+++ b/wp-admin/import/textpattern.php
@@ -56,8 +56,9 @@ class Textpattern_Import {
echo '<p>'.__('This has not been tested on previous versions of Textpattern. Mileage may vary.').'</p>';
echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>';
echo '<form action="admin.php?import=textpattern&amp;step=1" method="post">';
+ wp_nonce_field('import-textpattern');
$this->db_form();
- echo '<p class="submit"><input type="submit" name="submit" value="'.__('Import Categories').' &raquo;" /></p>';
+ echo '<p class="submit"><input type="submit" name="submit" value="'.attribute_escape(__('Import Categories &raquo;')).'" /></p>';
echo '</form>';
echo '</div>';
}
@@ -483,7 +484,8 @@ class Textpattern_Import {
echo '<form action="admin.php?import=textpattern&amp;step=2" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Users'));
+ wp_nonce_field('import-textpattern');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Users')));
echo '</form>';
}
@@ -495,7 +497,8 @@ class Textpattern_Import {
$this->users2wp($users);
echo '<form action="admin.php?import=textpattern&amp;step=3" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Posts'));
+ wp_nonce_field('import-textpattern');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Posts')));
echo '</form>';
}
@@ -506,7 +509,8 @@ class Textpattern_Import {
$this->posts2wp($posts);
echo '<form action="admin.php?import=textpattern&amp;step=4" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Comments'));
+ wp_nonce_field('import-textpattern');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Comments')));
echo '</form>';
}
@@ -517,7 +521,8 @@ class Textpattern_Import {
$this->comments2wp($comments);
echo '<form action="admin.php?import=textpattern&amp;step=5" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Import Links'));
+ wp_nonce_field('import-textpattern');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Import Links')));
echo '</form>';
}
@@ -529,7 +534,8 @@ class Textpattern_Import {
add_option('txp_links', $links);
echo '<form action="admin.php?import=textpattern&amp;step=6" method="post">';
- printf('<input type="submit" name="submit" value="%s" />', __('Finish'));
+ wp_nonce_field('import-textpattern');
+ printf('<input type="submit" name="submit" value="%s" />', attribute_escape(__('Finish')));
echo '</form>';
}
@@ -553,11 +559,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>';
@@ -565,7 +571,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()
@@ -590,36 +596,38 @@ class Textpattern_Import {
if ( $step > 0 )
{
+ check_admin_referer('import-textpattern');
+
if($_POST['dbuser'])
{
if(get_option('txpuser'))
delete_option('txpuser');
- add_option('txpuser',$_POST['dbuser']);
+ add_option('txpuser', sanitize_user($_POST['dbuser'], true));
}
if($_POST['dbpass'])
{
if(get_option('txppass'))
delete_option('txppass');
- add_option('txppass',$_POST['dbpass']);
+ add_option('txppass', sanitize_user($_POST['dbpass'], true));
}
if($_POST['dbname'])
{
if(get_option('txpname'))
delete_option('txpname');
- add_option('txpname',$_POST['dbname']);
+ add_option('txpname', sanitize_user($_POST['dbname'], true));
}
if($_POST['dbhost'])
{
if(get_option('txphost'))
delete_option('txphost');
- add_option('txphost',$_POST['dbhost']);
+ add_option('txphost', sanitize_user($_POST['dbhost'], true));
}
if($_POST['dbprefix'])
{
if(get_option('tpre'))
delete_option('tpre');
- add_option('tpre',$_POST['dbprefix']);
+ add_option('tpre', sanitize_user($_POST['dbprefix']));
}
diff --git a/wp-admin/import/utw.php b/wp-admin/import/utw.php
new file mode 100644
index 0000000..824ba50
--- /dev/null
+++ b/wp-admin/import/utw.php
@@ -0,0 +1,270 @@
+<?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'];
+ }
+
+ // 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">';
+ 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">';
+ 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">';
+ 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 90b616b..fa0d194 100644
--- a/wp-admin/import/wordpress.php
+++ b/wp-admin/import/wordpress.php
@@ -3,6 +3,8 @@
class WP_Import {
var $posts = array ();
+ var $posts_processed = array ();
+ // Array of arrays. [[0] => XML fragment, [1] => New post ID]
var $file;
var $id;
var $mtnames = array ();
@@ -33,8 +35,9 @@ class WP_Import {
}
function get_tag( $string, $tag ) {
+ global $wpdb;
preg_match("|<$tag.*?>(.*?)</$tag>|is", $string, $return);
- $return = addslashes( trim( $return[1] ) );
+ $return = $wpdb->escape( trim( $return[1] ) );
return $return;
}
@@ -65,13 +68,40 @@ class WP_Import {
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);
- preg_match_all('|<item>(.*?)</item>|is', $importdata, $this->posts);
- $this->posts = $this->posts[1];
- preg_match_all('|<wp:category>(.*?)</wp:category>|is', $importdata, $this->categories);
- $this->categories = $this->categories[1];
+ $importdata = array_map('rtrim', file($this->file)); // Read the file into an array
+
+ $this->posts = array();
+ $this->categories = 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";
+ }
+ }
+
+ 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;
+ }
+ }
}
function get_wp_authors() {
@@ -133,6 +163,7 @@ class WP_Import {
$authors = $this->get_wp_authors();
echo '<ol id="authors">';
echo '<form action="?import=wordpress&amp;step=2&amp;id=' . $this->id . '" method="post">';
+ wp_nonce_field('import-wordpress');
$j = -1;
foreach ($authors as $author) {
++ $j;
@@ -150,10 +181,8 @@ class WP_Import {
function select_authors() {
$file = wp_import_handle_upload();
if ( isset($file['error']) ) {
- $this->header();
echo '<p>'.__('Sorry, there has been an error.').'</p>';
echo '<p><strong>' . $file['error'] . '</strong></p>';
- $this->footer();
return;
}
$this->file = $file['file'];
@@ -193,97 +222,128 @@ class WP_Import {
}
function process_posts() {
- global $wpdb;
$i = -1;
echo '<ol>';
- foreach ($this->posts as $post) {
- // There are only ever one of these
- $post_title = $this->get_tag( $post, 'title' );
- $post_date = $this->get_tag( $post, 'wp:post_date' );
- $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
- $comment_status = $this->get_tag( $post, 'wp:comment_status' );
- $ping_status = $this->get_tag( $post, 'wp:ping_status' );
- $post_status = $this->get_tag( $post, 'wp:status' );
- $post_parent = $this->get_tag( $post, 'wp:post_parent' );
- $post_type = $this->get_tag( $post, 'wp:post_type' );
- $guid = $this->get_tag( $post, 'guid' );
- $post_author = $this->get_tag( $post, 'dc:creator' );
-
- $post_content = $this->get_tag( $post, 'content:encoded' );
- $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $post_content);
- $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
- $post_content = str_replace('<br>', '<br />', $post_content);
- $post_content = str_replace('<hr>', '<hr />', $post_content);
-
- preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
- $categories = $categories[1];
-
- $cat_index = 0;
- foreach ($categories as $category) {
- $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $category)));
- $cat_index++;
- }
+ foreach ($this->posts as $post)
+ $this->process_post($post);
- 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));
+ echo '</ol>';
- $post_author = $this->checkauthor($post_author); //just so that if a post already exists, new users are not created by checkauthor
+ wp_import_cleanup($this->id);
- $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', 'guid', 'post_parent', 'post_type');
- $comment_post_ID = $post_id = wp_insert_post($postdata);
- // Add categories.
- if (0 != count($categories)) {
- wp_create_categories($categories, $post_id);
- }
- }
+ echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
+ }
+
+ function process_post($post) {
+ global $wpdb;
- // Now for comments
- preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
- $comments = $comments[1];
- $num_comments = 0;
- if ( $comments) { foreach ($comments as $comment) {
- $comment_author = $this->get_tag( $comment, 'wp:comment_author');
- $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
- $comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP');
- $comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url');
- $comment_date = $this->get_tag( $comment, 'wp:comment_date');
- $comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt');
- $comment_content = $this->get_tag( $comment, 'wp:comment_content');
- $comment_approved = $this->get_tag( $comment, 'wp:comment_approved');
- $comment_type = $this->get_tag( $comment, 'wp:comment_type');
- $comment_parent = $this->get_tag( $comment, 'wp:comment_parent');
-
- 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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
- wp_insert_comment($commentdata);
- $num_comments++;
- }
- } }
- if ( $num_comments )
- printf(' '.__('(%s comments)'), $num_comments);
-
- // Now for post meta
- preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
- $postmeta = $postmeta[1];
- if ( $postmeta) { foreach ($postmeta as $p) {
- $key = $this->get_tag( $p, 'wp:meta_key' );
- $value = $this->get_tag( $p, 'wp:meta_value' );
- add_post_meta( $post_id, $key, $value );
- } }
-
- $index++;
+ $post_ID = (int) $this->get_tag( $post, 'wp:post_id' );
+ if ( $post_ID && !empty($this->posts_processed[$post_ID][1]) ) // Processed already
+ return 0;
+
+ // There are only ever one of these
+ $post_title = $this->get_tag( $post, 'title' );
+ $post_date = $this->get_tag( $post, 'wp:post_date' );
+ $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
+ $comment_status = $this->get_tag( $post, 'wp:comment_status' );
+ $ping_status = $this->get_tag( $post, 'wp:ping_status' );
+ $post_status = $this->get_tag( $post, 'wp:status' );
+ $post_name = $this->get_tag( $post, 'wp:post_name' );
+ $post_parent = $this->get_tag( $post, 'wp:post_parent' );
+ $menu_order = $this->get_tag( $post, 'wp:menu_order' );
+ $post_type = $this->get_tag( $post, 'wp:post_type' );
+ $guid = $this->get_tag( $post, 'guid' );
+ $post_author = $this->get_tag( $post, 'dc:creator' );
+
+ $post_content = $this->get_tag( $post, 'content:encoded' );
+ $post_content = str_replace(array ('<![CDATA[', ']]>'), '', $post_content);
+ $post_content = preg_replace('|<(/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
+ $post_content = str_replace('<br>', '<br />', $post_content);
+ $post_content = str_replace('<hr>', '<hr />', $post_content);
+
+ preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
+ $categories = $categories[1];
+
+ $cat_index = 0;
+ foreach ($categories as $category) {
+ $categories[$cat_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $category)));
+ $cat_index++;
}
- echo '</ol>';
+ if ($post_id = post_exists($post_title, '', $post_date)) {
+ echo '<li>';
+ printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
+ } else {
- wp_import_cleanup($this->id);
+ // 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.
+ $post_parent = $parent[1]; // New ID of the parent;
+ }
- echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
+ 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', '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);
+
+ // Memorize old and new ID.
+ if ( $post_id && $post_ID && $this->posts_processed[$post_ID] )
+ $this->posts_processed[$post_ID][1] = $post_id; // New ID.
+
+ // Add categories.
+ 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'");
+ if ($cat_ID == 0) {
+ $cat_ID = wp_insert_category(array('cat_name' => $category));
+ }
+ $post_cats[] = $cat_ID;
+ }
+ wp_set_post_categories($post_id, $post_cats);
+ }
+ }
+
+ // Now for comments
+ preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
+ $comments = $comments[1];
+ $num_comments = 0;
+ if ( $comments) { foreach ($comments as $comment) {
+ $comment_author = $this->get_tag( $comment, 'wp:comment_author');
+ $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
+ $comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP');
+ $comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url');
+ $comment_date = $this->get_tag( $comment, 'wp:comment_date');
+ $comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt');
+ $comment_content = $this->get_tag( $comment, 'wp:comment_content');
+ $comment_approved = $this->get_tag( $comment, 'wp:comment_approved');
+ $comment_type = $this->get_tag( $comment, 'wp:comment_type');
+ $comment_parent = $this->get_tag( $comment, 'wp:comment_parent');
+
+ 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_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
+ wp_insert_comment($commentdata);
+ $num_comments++;
+ }
+ } }
+
+ if ( $num_comments )
+ printf(' '.__('(%s comments)'), $num_comments);
+
+ // Now for post meta
+ preg_match_all('|<wp:postmeta>(.*?)</wp:postmeta>|is', $post, $postmeta);
+ $postmeta = $postmeta[1];
+ if ( $postmeta) { foreach ($postmeta as $p) {
+ $key = $this->get_tag( $p, 'wp:meta_key' );
+ $value = $this->get_tag( $p, 'wp:meta_value' );
+ $value = stripslashes($value); // add_post_meta() will escape.
+ add_post_meta( $post_id, $key, $value );
+ } }
}
function import() {
@@ -308,9 +368,11 @@ class WP_Import {
$this->greet();
break;
case 1 :
+ check_admin_referer('import-upload');
$this->select_authors();
break;
case 2:
+ check_admin_referer('import-wordpress');
$this->import();
break;
}
diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php
new file mode 100644
index 0000000..6df9f1c
--- /dev/null
+++ b/wp-admin/import/wp-cat2tag.php
@@ -0,0 +1,226 @@
+<?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;
+
+ $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0 ORDER BY cat_name ASC");
+ }
+
+ 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">';
+ print '<ul style="list-style:none">';
+
+ $hier = _get_category_hierarchy();
+
+ foreach ($this->all_categories as $category) {
+ if ((int) $category->category_parent == 0) {
+ print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($category->cat_ID) . '" /> ' . $category->cat_name . ' (' . $category->category_count . ')</label>';
+
+ if (isset($hier[$category->cat_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->cat_ID] as $child_id) {
+ $child =& get_category($child_id);
+
+ print '<li><label><input type="checkbox" name="cats_to_convert[]" value="' . intval($child->cat_ID) . '" /> ' . $child->cat_name . ' (' . $child->category_count . ')</label>';
+
+ if (isset($hier[$child->cat_ID])) {
+ $this->_category_children($child, $hier);
+ }
+
+ print '</li>';
+ }
+
+ print '</ul>';
+ }
+
+ function _category_exists($cat_id) {
+ global $wpdb;
+
+ $cat_id = (int) $cat_id;
+
+ $maybe_exists = $wpdb->get_results("SELECT cat_ID from $wpdb->categories WHERE cat_ID = '$cat_id'");
+
+ if (count($maybe_exists) > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ function convert_them() {
+ global $wpdb;
+
+ if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_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>';
+ }
+
+ $this->categories_to_convert = $_POST['cats_to_convert'];
+ $hier = _get_category_hierarchy();
+
+ print '<ul>';
+
+ foreach ($this->categories_to_convert as $cat_id) {
+ $cat_id = (int) $cat_id;
+
+ print '<li>' . __('Converting category') . ' #' . $cat_id . '... ';
+
+ if (!$this->_category_exists($cat_id)) {
+ _e('Category doesn\'t exist!');
+ } else {
+ $category =& get_category($cat_id);
+
+ if ($category->link_count > 0) {
+ $type = $category->type | TAXONOMY_TAG;
+ } else {
+ $type = TAXONOMY_TAG;
+ }
+
+ // Set the category itself to $type from above
+ $wpdb->query("UPDATE $wpdb->categories SET type = '$type' WHERE cat_ID = '{$category->cat_ID}'");
+
+ // Set relationships in post2cat to 'tag', category_count becomes tag_count
+ $wpdb->query("UPDATE $wpdb->post2cat SET rel_type = 'tag' WHERE category_ID = '{$category->cat_ID}'");
+ $wpdb->query("UPDATE $wpdb->categories SET tag_count = '{$category->category_count}', category_count = '0' WHERE cat_ID = '{$category->cat_ID}'");
+
+ // Set all parents to 0 (root-level) if their parent was the converted tag
+ $wpdb->query("UPDATE $wpdb->categories SET category_parent = 0 WHERE category_parent = '{$category->cat_ID}'");
+
+ // Clean the cache
+ clean_category_cache($category->cat_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">';
+ 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;
+
+ $cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0");
+
+ $_POST['cats_to_convert'] = array();
+
+ foreach ($cats as $cat) {
+ $_POST['cats_to_convert'][] = $cat->cat_ID;
+ }
+
+ $this->convert_them();
+ }
+
+ function init() {
+ echo '<!--'; print_r($_POST); print_r($_GET); echo '-->';
+
+ 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 {
+ 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'));
+
+?>