-
+ 2F7DA06F4950FFD6E9F4D9C52A85E13A98D408C69CAF3545CA1CED021AA9249D717E86AADA55EBFC09C0AB5EC21451886F8462E85536093AB515B22E2C602018
mp-wp/wp-admin/import/utw.php
(0 . 0)(1 . 290)
21058 <?php
21059 /**
21060 * The Ultimate Tag Warrior Importer.
21061 *
21062 * @package WordPress
21063 * @subpackage Importer
21064 */
21065
21066 /**
21067 * Ultimate Tag Warrior Converter to 2.3 taxonomy.
21068 *
21069 * This converts the Ultimate Tag Warrior tags to the 2.3 WordPress taxonomy.
21070 *
21071 * @since 2.3.0
21072 */
21073 class UTW_Import {
21074
21075 function header() {
21076 echo '<div class="wrap">';
21077 screen_icon();
21078 echo '<h2>'.__('Import Ultimate Tag Warrior').'</h2>';
21079 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
21080 }
21081
21082 function footer() {
21083 echo '</div>';
21084 }
21085
21086 function greet() {
21087 echo '<div class="narrow">';
21088 echo '<p>'.__('Howdy! This imports tags from Ultimate Tag Warrior 3 into WordPress tags.').'</p>';
21089 echo '<p>'.__('This has not been tested on any other versions of Ultimate Tag Warrior. Mileage may vary.').'</p>';
21090 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>';
21091 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
21092 echo '<form action="admin.php?import=utw&step=1" method="post">';
21093 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 1').'" /></p>';
21094 echo '</form>';
21095 echo '</div>';
21096 }
21097
21098
21099 function dispatch () {
21100 if ( empty( $_GET['step'] ) ) {
21101 $step = 0;
21102 } else {
21103 $step = (int) $_GET['step'];
21104 }
21105
21106 if ( $step > 1 )
21107 check_admin_referer('import-utw');
21108
21109 // load the header
21110 $this->header();
21111
21112 switch ( $step ) {
21113 case 0 :
21114 $this->greet();
21115 break;
21116 case 1 :
21117 $this->import_tags();
21118 break;
21119 case 2 :
21120 $this->import_posts();
21121 break;
21122 case 3:
21123 $this->import_t2p();
21124 break;
21125 case 4:
21126 $this->cleanup_import();
21127 break;
21128 }
21129
21130 // load the footer
21131 $this->footer();
21132 }
21133
21134
21135 function import_tags ( ) {
21136 echo '<div class="narrow">';
21137 echo '<p><h3>'.__('Reading UTW Tags…').'</h3></p>';
21138
21139 $tags = $this->get_utw_tags();
21140
21141 // if we didn't get any tags back, that's all there is folks!
21142 if ( !is_array($tags) ) {
21143 echo '<p>' . __('No Tags Found!') . '</p>';
21144 return false;
21145 }
21146 else {
21147
21148 // if there's an existing entry, delete it
21149 if ( get_option('utwimp_tags') ) {
21150 delete_option('utwimp_tags');
21151 }
21152
21153 add_option('utwimp_tags', $tags);
21154
21155
21156 $count = count($tags);
21157
21158 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag were read.', 'Done! <strong>%s</strong> tags were read.', $count), $count ) . '<br /></p>';
21159 echo '<p>' . __('The following tags were found:') . '</p>';
21160
21161 echo '<ul>';
21162
21163 foreach ( $tags as $tag_id => $tag_name ) {
21164
21165 echo '<li>' . $tag_name . '</li>';
21166
21167 }
21168
21169 echo '</ul>';
21170
21171 echo '<br />';
21172
21173 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>';
21174
21175
21176 }
21177
21178 echo '<form action="admin.php?import=utw&step=2" method="post">';
21179 wp_nonce_field('import-utw');
21180 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 2').'" /></p>';
21181 echo '</form>';
21182 echo '</div>';
21183 }
21184
21185
21186 function import_posts ( ) {
21187 echo '<div class="narrow">';
21188 echo '<p><h3>'.__('Reading UTW Post Tags…').'</h3></p>';
21189
21190 // read in all the UTW tag -> post settings
21191 $posts = $this->get_utw_posts();
21192
21193 // if we didn't get any tags back, that's all there is folks!
21194 if ( !is_array($posts) ) {
21195 echo '<p>' . __('No posts were found to have tags!') . '</p>';
21196 return false;
21197 }
21198 else {
21199
21200 // if there's an existing entry, delete it
21201 if ( get_option('utwimp_posts') ) {
21202 delete_option('utwimp_posts');
21203 }
21204
21205 add_option('utwimp_posts', $posts);
21206
21207
21208 $count = count($posts);
21209
21210 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag to post relationships were read.', 'Done! <strong>%s</strong> tags to post relationships were read.', $count), $count ) . '<br /></p>';
21211
21212 }
21213
21214 echo '<form action="admin.php?import=utw&step=3" method="post">';
21215 wp_nonce_field('import-utw');
21216 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 3').'" /></p>';
21217 echo '</form>';
21218 echo '</div>';
21219
21220 }
21221
21222
21223 function import_t2p ( ) {
21224
21225 echo '<div class="narrow">';
21226 echo '<p><h3>'.__('Adding Tags to Posts…').'</h3></p>';
21227
21228 // run that funky magic!
21229 $tags_added = $this->tag2post();
21230
21231 echo '<p>' . sprintf( __ngettext( 'Done! <strong>%s</strong> tag were added!', 'Done! <strong>%s</strong> tags were added!', $tags_added ), $tags_added ) . '<br /></p>';
21232
21233 echo '<form action="admin.php?import=utw&step=4" method="post">';
21234 wp_nonce_field('import-utw');
21235 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Step 4').'" /></p>';
21236 echo '</form>';
21237 echo '</div>';
21238
21239 }
21240
21241
21242 function get_utw_tags ( ) {
21243
21244 global $wpdb;
21245
21246 // read in all the tags from the UTW tags table: should be wp_tags
21247 $tags_query = "SELECT tag_id, tag FROM " . $wpdb->prefix . "tags";
21248
21249 $tags = $wpdb->get_results($tags_query);
21250
21251 // rearrange these tags into something we can actually use
21252 foreach ( $tags as $tag ) {
21253
21254 $new_tags[$tag->tag_id] = $tag->tag;
21255
21256 }
21257
21258 return $new_tags;
21259
21260 }
21261
21262 function get_utw_posts ( ) {
21263
21264 global $wpdb;
21265
21266 // read in all the posts from the UTW post->tag table: should be wp_post2tag
21267 $posts_query = "SELECT tag_id, post_id FROM " . $wpdb->prefix . "post2tag";
21268
21269 $posts = $wpdb->get_results($posts_query);
21270
21271 return $posts;
21272
21273 }
21274
21275
21276 function tag2post ( ) {
21277
21278 // get the tags and posts we imported in the last 2 steps
21279 $tags = get_option('utwimp_tags');
21280 $posts = get_option('utwimp_posts');
21281
21282 // null out our results
21283 $tags_added = 0;
21284
21285 // loop through each post and add its tags to the db
21286 foreach ( $posts as $this_post ) {
21287
21288 $the_post = (int) $this_post->post_id;
21289 $the_tag = (int) $this_post->tag_id;
21290
21291 // what's the tag name for that id?
21292 $the_tag = $tags[$the_tag];
21293
21294 // screw it, just try to add the tag
21295 wp_add_post_tags($the_post, $the_tag);
21296
21297 $tags_added++;
21298
21299 }
21300
21301 // that's it, all posts should be linked to their tags properly, pending any errors we just spit out!
21302 return $tags_added;
21303
21304
21305 }
21306
21307
21308 function cleanup_import ( ) {
21309
21310 delete_option('utwimp_tags');
21311 delete_option('utwimp_posts');
21312
21313 $this->done();
21314
21315 }
21316
21317
21318 function done ( ) {
21319
21320 echo '<div class="narrow">';
21321 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
21322
21323 echo '<p>' . __('OK, so we lied about this being a 5-step program! You’re done!') . '</p>';
21324
21325 echo '<p>' . __('Now wasn’t that easy?') . '</p>';
21326
21327 echo '</div>';
21328
21329 }
21330
21331
21332 function UTW_Import ( ) {
21333
21334 // Nothing.
21335
21336 }
21337
21338 }
21339
21340
21341 // create the import object
21342 $utw_import = new UTW_Import();
21343
21344 // add it to the import page!
21345 register_importer('utw', 'Ultimate Tag Warrior', __('Import Ultimate Tag Warrior tags into WordPress tags.'), array($utw_import, 'dispatch'));
21346
21347 ?>