mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * BunnyTags Plugin Tag Importer
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Importer
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * BunnyTags Plugin tag converter
mp-wp_genesis 11 *
mp-wp_genesis 12 * This will process the BunnyTags plugin tags and convert them to the WordPress
mp-wp_genesis 13 * 2.3 taxonomy.
mp-wp_genesis 14 *
mp-wp_genesis 15 * @since unknown
mp-wp_genesis 16 */
mp-wp_genesis 17 class BunnyTags_Import {
mp-wp_genesis 18
mp-wp_genesis 19 function header() {
mp-wp_genesis 20 echo '<div class="wrap">';
mp-wp_genesis 21 screen_icon();
mp-wp_genesis 22 echo '<h2>'.__('Import Bunny’s Technorati Tags').'</h2>';
mp-wp_genesis 23 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
mp-wp_genesis 24 }
mp-wp_genesis 25
mp-wp_genesis 26 function footer() {
mp-wp_genesis 27 echo '</div>';
mp-wp_genesis 28 }
mp-wp_genesis 29
mp-wp_genesis 30 function greet() {
mp-wp_genesis 31 echo '<div class="narrow">';
mp-wp_genesis 32 echo '<p>'.__('Howdy! This imports tags from Bunny’s Technorati Tags into WordPress tags.').'</p>';
mp-wp_genesis 33 echo '<p>'.__('This is suitable for Bunny’s Technorati Tags version 0.6.').'</p>';
mp-wp_genesis 34 echo '<p><strong>'.__('All existing Bunny’s Technorati Tags will be removed after import.').'</strong></p>';
mp-wp_genesis 35 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
mp-wp_genesis 36 echo '<form action="admin.php?import=btt&step=1" method="post">';
mp-wp_genesis 37 wp_nonce_field('import-btt');
mp-wp_genesis 38 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Import Tags').'" /></p>';
mp-wp_genesis 39 echo '</form>';
mp-wp_genesis 40 echo '</div>';
mp-wp_genesis 41 }
mp-wp_genesis 42
mp-wp_genesis 43 function dispatch() {
mp-wp_genesis 44 if ( empty($_GET['step']) )
mp-wp_genesis 45 $step = 0;
mp-wp_genesis 46 else
mp-wp_genesis 47 $step = absint($_GET['step']);
mp-wp_genesis 48
mp-wp_genesis 49 // load the header
mp-wp_genesis 50 $this->header();
mp-wp_genesis 51
mp-wp_genesis 52 switch ( $step ) {
mp-wp_genesis 53 case 0 :
mp-wp_genesis 54 $this->greet();
mp-wp_genesis 55 break;
mp-wp_genesis 56 case 1 :
mp-wp_genesis 57 check_admin_referer('import-btt');
mp-wp_genesis 58 $this->check_post_keyword( true );
mp-wp_genesis 59 break;
mp-wp_genesis 60 case 2 :
mp-wp_genesis 61 check_admin_referer('import-btt');
mp-wp_genesis 62 $this->check_post_keyword( false );
mp-wp_genesis 63 break;
mp-wp_genesis 64 case 3:
mp-wp_genesis 65 $this->done();
mp-wp_genesis 66 break;
mp-wp_genesis 67 }
mp-wp_genesis 68
mp-wp_genesis 69 // load the footer
mp-wp_genesis 70 $this->footer();
mp-wp_genesis 71 }
mp-wp_genesis 72
mp-wp_genesis 73 function check_post_keyword($precheck = true) {
mp-wp_genesis 74 global $wpdb;
mp-wp_genesis 75
mp-wp_genesis 76 echo '<div class="narrow">';
mp-wp_genesis 77 echo '<p><h3>'.__('Reading Bunny’s Technorati Tags…').'</h3></p>';
mp-wp_genesis 78
mp-wp_genesis 79 // import Bunny's Keywords tags
mp-wp_genesis 80 $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'tags'");
mp-wp_genesis 81 if ( !is_array($metakeys)) {
mp-wp_genesis 82 echo '<p>' . __('No Tags Found!') . '</p>';
mp-wp_genesis 83 return false;
mp-wp_genesis 84 } else {
mp-wp_genesis 85 $count = count($metakeys);
mp-wp_genesis 86 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> post with tags were read.', 'Done! <strong>%s</strong> posts with tags were read.', $count), $count ) . '<br /></p>';
mp-wp_genesis 87 echo '<ul>';
mp-wp_genesis 88 foreach ( $metakeys as $post_meta ) {
mp-wp_genesis 89 if ( $post_meta->meta_value != '' ) {
mp-wp_genesis 90 $post_keys = explode(' ', $post_meta->meta_value);
mp-wp_genesis 91 foreach ( $post_keys as $keyword ) {
mp-wp_genesis 92 $keyword = addslashes(trim(str_replace('+',' ',$keyword)));
mp-wp_genesis 93 if ( '' != $keyword ) {
mp-wp_genesis 94 echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>';
mp-wp_genesis 95 if ( !$precheck )
mp-wp_genesis 96 wp_add_post_tags($post_meta->post_id, $keyword);
mp-wp_genesis 97 }
mp-wp_genesis 98 }
mp-wp_genesis 99 }
mp-wp_genesis 100 if ( !$precheck )
mp-wp_genesis 101 delete_post_meta($post_meta->post_id, 'tags');
mp-wp_genesis 102 }
mp-wp_genesis 103 echo '</ul>';
mp-wp_genesis 104 }
mp-wp_genesis 105
mp-wp_genesis 106 echo '<form action="admin.php?import=btt&step='.($precheck? 2:3).'" method="post">';
mp-wp_genesis 107 wp_nonce_field('import-btt');
mp-wp_genesis 108 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Next').'" /></p>';
mp-wp_genesis 109 echo '</form>';
mp-wp_genesis 110 echo '</div>';
mp-wp_genesis 111 }
mp-wp_genesis 112
mp-wp_genesis 113 function done() {
mp-wp_genesis 114 echo '<div class="narrow">';
mp-wp_genesis 115 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
mp-wp_genesis 116 echo '</div>';
mp-wp_genesis 117 }
mp-wp_genesis 118
mp-wp_genesis 119 function BunnyTags_Import() {
mp-wp_genesis 120 }
mp-wp_genesis 121
mp-wp_genesis 122 }
mp-wp_genesis 123
mp-wp_genesis 124 // create the import object
mp-wp_genesis 125 $btt_import = new BunnyTags_Import();
mp-wp_genesis 126
mp-wp_genesis 127 // add it to the import page!
mp-wp_genesis 128 register_importer('btt', 'Bunny’s Technorati Tags', __('Import Bunny’s Technorati Tags into WordPress tags.'), array($btt_import, 'dispatch'));
mp-wp_genesis 129
mp-wp_genesis 130 ?>