6 echo '<div class="wrap">';
7 echo '<h2>'.__('Import Ultimate Tag Warrior').'</h2>';
8 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
16 echo '<div class="narrow">';
17 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>';
18 echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
19 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>';
20 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
21 echo '<form action="admin.php?import=utw&step=1" method="post">';
22 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 1 »').'" /></p>';
28 function dispatch () {
29 if ( empty( $_GET['step'] ) ) {
32 $step = (int) $_GET['step'];
36 check_admin_referer('import-utw');
49 $this->import_posts();
55 $this->cleanup_import();
64 function import_tags ( ) {
65 echo '<div class="narrow">';
66 echo '<p><h3>'.__('Reading UTW Tags…').'</h3></p>';
68 $tags = $this->get_utw_tags();
70 // if we didn't get any tags back, that's all there is folks!
71 if ( !is_array($tags) ) {
72 echo '<p>' . __('No Tags Found!') . '</p>';
77 // if there's an existing entry, delete it
78 if ( get_option('utwimp_tags') ) {
79 delete_option('utwimp_tags');
82 add_option('utwimp_tags', $tags);
85 $count = count($tags);
87 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were read.'), $count ) . '<br /></p>';
88 echo '<p>' . __('The following tags were found:') . '</p>';
92 foreach ( $tags as $tag_id => $tag_name ) {
94 echo '<li>' . $tag_name . '</li>';
102 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>';
107 echo '<form action="admin.php?import=utw&step=2" method="post">';
108 wp_nonce_field('import-utw');
109 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 2 »').'" /></p>';
115 function import_posts ( ) {
116 echo '<div class="narrow">';
117 echo '<p><h3>'.__('Reading UTW Post Tags…').'</h3></p>';
119 // read in all the UTW tag -> post settings
120 $posts = $this->get_utw_posts();
122 // if we didn't get any tags back, that's all there is folks!
123 if ( !is_array($posts) ) {
124 echo '<p>' . __('No posts were found to have tags!') . '</p>';
129 // if there's an existing entry, delete it
130 if ( get_option('utwimp_posts') ) {
131 delete_option('utwimp_posts');
134 add_option('utwimp_posts', $posts);
137 $count = count($posts);
139 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tag to post relationships were read.'), $count ) . '<br /></p>';
143 echo '<form action="admin.php?import=utw&step=3" method="post">';
144 wp_nonce_field('import-utw');
145 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 3 »').'" /></p>';
152 function import_t2p ( ) {
154 echo '<div class="narrow">';
155 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
157 // run that funky magic!
158 $tags_added = $this->tag2post();
160 echo '<p>' . sprintf( __('Done! <strong>%s</strong> tags were added!'), $tags_added ) . '<br /></p>';
162 echo '<form action="admin.php?import=utw&step=4" method="post">';
163 wp_nonce_field('import-utw');
164 echo '<p class="submit"><input type="submit" name="submit" value="'.__('Step 4 »').'" /></p>';
171 function get_utw_tags ( ) {
175 // read in all the tags from the UTW tags table: should be wp_tags
176 $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
178 $tags = $wpdb->get_results($tags_query);
180 // rearrange these tags into something we can actually use
181 foreach ( $tags as $tag ) {
183 $new_tags[$tag->tag_id] = $tag->tag;
191 function get_utw_posts ( ) {
195 // read in all the posts from the UTW post->tag table: should be wp_post2tag
196 $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
198 $posts = $wpdb->get_results($posts_query);
205 function tag2post ( ) {
207 // get the tags and posts we imported in the last 2 steps
208 $tags = get_option('utwimp_tags');
209 $posts = get_option('utwimp_posts');
211 // null out our results
214 // loop through each post and add its tags to the db
215 foreach ( $posts as $this_post ) {
217 $the_post = (int) $this_post->post_id;
218 $the_tag = (int) $this_post->tag_id;
220 // what's the tag name for that id?
221 $the_tag = $tags[$the_tag];
223 // screw it, just try to add the tag
224 wp_add_post_tags($the_post, $the_tag);
230 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
237 function cleanup_import ( ) {
239 delete_option('utwimp_tags');
240 delete_option('utwimp_posts');
249 echo '<div class="narrow">';
250 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
252 echo '<p>' . __('OK, so we lied about this being a 5-step program! You’re done!') . '</p>';
254 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
261 function UTW_Import ( ) {
270 // create the import object
271 $utw_import = new UTW_Import();
273 // add it to the import page!
274 register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into the new native tagging structure.'), array($utw_import, 'dispatch'));