3 * The Ultimate Tag Warrior Importer.
10 * Ultimate Tag Warrior Converter to 2.3 taxonomy.
12 * This converts the Ultimate Tag Warrior tags to the 2.3 WordPress taxonomy.
19 echo '<div class="wrap">';
21 echo '<h2>'.__('Import Ultimate Tag Warrior').'</h2>';
22 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
30 echo '<div class="narrow">';
31 echo '<p>'.__('Howdy! This imports tags from Ultimate Tag Warrior 3 into WordPress tags.').'</p>';
32 echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
33 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>';
34 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
35 echo '<form action="admin.php?import=utw&step=1" method="post">';
36 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 1').'" /></p>';
42 function dispatch () {
43 if ( empty( $_GET['step'] ) ) {
46 $step = (int) $_GET['step'];
50 check_admin_referer('import-utw');
63 $this->import_posts();
69 $this->cleanup_import();
78 function import_tags ( ) {
79 echo '<div class="narrow">';
80 echo '<p><h3>'.__('Reading UTW Tags…').'</h3></p>';
82 $tags = $this->get_utw_tags();
84 // if we didn't get any tags back, that's all there is folks!
85 if ( !is_array($tags) ) {
86 echo '<p>' . __('No Tags Found!') . '</p>';
91 // if there's an existing entry, delete it
92 if ( get_option('utwimp_tags') ) {
93 delete_option('utwimp_tags');
96 add_option('utwimp_tags', $tags);
99 $count = count($tags);
101 echo '<p>' . sprintf( _n('Done! <strong>%s</strong> tag were read.', 'Done! <strong>%s</strong> tags were read.', $count), $count ) . '<br /></p>';
102 echo '<p>' . __('The following tags were found:') . '</p>';
106 foreach ( $tags as $tag_id => $tag_name ) {
108 echo '<li>' . $tag_name . '</li>';
116 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>';
121 echo '<form action="admin.php?import=utw&step=2" method="post">';
122 wp_nonce_field('import-utw');
123 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 2').'" /></p>';
129 function import_posts ( ) {
130 echo '<div class="narrow">';
131 echo '<p><h3>'.__('Reading UTW Post Tags…').'</h3></p>';
133 // read in all the UTW tag -> post settings
134 $posts = $this->get_utw_posts();
136 // if we didn't get any tags back, that's all there is folks!
137 if ( !is_array($posts) ) {
138 echo '<p>' . __('No posts were found to have tags!') . '</p>';
143 // if there's an existing entry, delete it
144 if ( get_option('utwimp_posts') ) {
145 delete_option('utwimp_posts');
148 add_option('utwimp_posts', $posts);
151 $count = count($posts);
153 echo '<p>' . sprintf( _n('Done! <strong>%s</strong> tag to post relationships were read.', 'Done! <strong>%s</strong> tags to post relationships were read.', $count), $count ) . '<br /></p>';
157 echo '<form action="admin.php?import=utw&step=3" method="post">';
158 wp_nonce_field('import-utw');
159 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 3').'" /></p>';
166 function import_t2p ( ) {
168 echo '<div class="narrow">';
169 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
171 // run that funky magic!
172 $tags_added = $this->tag2post();
174 echo '<p>' . sprintf( _n( 'Done! <strong>%s</strong> tag were added!', 'Done! <strong>%s</strong> tags were added!', $tags_added ), $tags_added ) . '<br /></p>';
176 echo '<form action="admin.php?import=utw&step=4" method="post">';
177 wp_nonce_field('import-utw');
178 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.esc_attr__('Step 4').'" /></p>';
185 function get_utw_tags ( ) {
189 // read in all the tags from the UTW tags table: should be wp_tags
190 $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
192 $tags = $wpdb->get_results($tags_query);
194 // rearrange these tags into something we can actually use
195 foreach ( $tags as $tag ) {
197 $new_tags[$tag->tag_id] = $tag->tag;
205 function get_utw_posts ( ) {
209 // read in all the posts from the UTW post->tag table: should be wp_post2tag
210 $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
212 $posts = $wpdb->get_results($posts_query);
219 function tag2post ( ) {
221 // get the tags and posts we imported in the last 2 steps
222 $tags = get_option('utwimp_tags');
223 $posts = get_option('utwimp_posts');
225 // null out our results
228 // loop through each post and add its tags to the db
229 foreach ( $posts as $this_post ) {
231 $the_post = (int) $this_post->post_id;
232 $the_tag = (int) $this_post->tag_id;
234 // what's the tag name for that id?
235 $the_tag = $tags[$the_tag];
237 // screw it, just try to add the tag
238 wp_add_post_tags($the_post, $the_tag);
244 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
251 function cleanup_import ( ) {
253 delete_option('utwimp_tags');
254 delete_option('utwimp_posts');
263 echo '<div class="narrow">';
264 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
266 echo '<p>' . __('OK, so we lied about this being a 5-step program! You’re done!') . '</p>';
268 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
275 function UTW_Import ( ) {
284 // create the import object
285 $utw_import = new UTW_Import();
287 // add it to the import page!
288 register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into WordPress tags.'), array($utw_import, 'dispatch'));