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>';
}
functionfooter(){
echo'</div>';
}
functiongreet(){
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’t be stupid - backup your database before proceeding!').'</strong></p>';
// if we didn't get any tags back, that's all there is folks!
if(!is_array($tags)){
echo'<p>'.__('No Tags Found!').'</p>';
returnfalse;
}
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($tagsas$tag_id=>$tag_name){
echo'<li>'.$tag_name.'</li>';
}
echo'</ul>';
echo'<br />';
echo'<p>'.__('If you don’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>';
// 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($tagsas$tag){
$new_tags[$tag->tag_id]=$tag->tag;
}
return$new_tags;
}
functionget_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;
}
functiontag2post(){
// 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($postsas$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;
}
functioncleanup_import(){
delete_option('utwimp_tags');
delete_option('utwimp_posts');
$this->done();
}
functiondone(){
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’re done!').'</p>';
echo'<p>'.__('Now wasn’t that easy?').'</p>';
echo'</div>';
}
functionUTW_Import(){
// Nothing.
}
}
// create the import object
$utw_import=newUTW_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'));