mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Jeromes Keyword Plugin 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 * Jeromes Keyword Plugin Importer class
mp-wp_genesis 11 *
mp-wp_genesis 12 * Will convert Jeromes Keyword Plugin tags to WordPress taxonomy tags.
mp-wp_genesis 13 *
mp-wp_genesis 14 * @since 2.3
mp-wp_genesis 15 */
mp-wp_genesis 16 class JeromesKeyword_Import {
mp-wp_genesis 17
mp-wp_genesis 18 function header() {
mp-wp_genesis 19 echo '<div class="wrap">';
mp-wp_genesis 20 screen_icon();
mp-wp_genesis 21 echo '<h2>'.__('Import Jerome’s Keywords').'</h2>';
mp-wp_genesis 22 echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'<br /><br /></p>';
mp-wp_genesis 23 }
mp-wp_genesis 24
mp-wp_genesis 25 function footer() {
mp-wp_genesis 26 echo '</div>';
mp-wp_genesis 27 }
mp-wp_genesis 28
mp-wp_genesis 29 function greet() {
mp-wp_genesis 30 echo '<div class="narrow">';
mp-wp_genesis 31 echo '<p>'.__('Howdy! This imports tags from Jerome’s Keywords into WordPress tags.').'</p>';
mp-wp_genesis 32 echo '<p>'.__('This is suitable for Jerome’s Keywords version 1.x and 2.0a.').'</p>';
mp-wp_genesis 33 echo '<p><strong>'.__('All existing Jerome’s Keywords will be removed after import.').'</strong></p>';
mp-wp_genesis 34 echo '<p><strong>'.__('Don’t be stupid - backup your database before proceeding!').'</strong></p>';
mp-wp_genesis 35 echo '<form action="admin.php?import=jkw&step=1" method="post">';
mp-wp_genesis 36 wp_nonce_field('import-jkw');
mp-wp_genesis 37 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Import Version 1.x').'" /></p>';
mp-wp_genesis 38 echo '</form>';
mp-wp_genesis 39 echo '<form action="admin.php?import=jkw&step=3" method="post">';
mp-wp_genesis 40 wp_nonce_field('import-jkw');
mp-wp_genesis 41 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Import Version 2.0a').'" /></p>';
mp-wp_genesis 42 echo '</form>';
mp-wp_genesis 43 echo '</div>';
mp-wp_genesis 44 }
mp-wp_genesis 45
mp-wp_genesis 46 function dispatch() {
mp-wp_genesis 47 if ( empty($_GET['step']) )
mp-wp_genesis 48 $step = 0;
mp-wp_genesis 49 else
mp-wp_genesis 50 $step = absint($_GET['step']);
mp-wp_genesis 51
mp-wp_genesis 52 // load the header
mp-wp_genesis 53 $this->header();
mp-wp_genesis 54
mp-wp_genesis 55 switch ( $step ) {
mp-wp_genesis 56 case 0 :
mp-wp_genesis 57 $this->greet();
mp-wp_genesis 58 break;
mp-wp_genesis 59 case 1 :
mp-wp_genesis 60 check_admin_referer('import-jkw');
mp-wp_genesis 61 $this->check_V1_post_keyword( true );
mp-wp_genesis 62 break;
mp-wp_genesis 63 case 2 :
mp-wp_genesis 64 check_admin_referer('import-jkw');
mp-wp_genesis 65 $this->check_V1_post_keyword( false );
mp-wp_genesis 66 break;
mp-wp_genesis 67 case 3 :
mp-wp_genesis 68 check_admin_referer('import-jkw');
mp-wp_genesis 69 $this->check_V2_post_keyword( true );
mp-wp_genesis 70 break;
mp-wp_genesis 71 case 4 :
mp-wp_genesis 72 check_admin_referer('import-jkw');
mp-wp_genesis 73 $this->check_V2_post_keyword( false );
mp-wp_genesis 74 break;
mp-wp_genesis 75 case 5:
mp-wp_genesis 76 check_admin_referer('import-jkw');
mp-wp_genesis 77 $this->cleanup_V2_import();
mp-wp_genesis 78 break;
mp-wp_genesis 79 case 6:
mp-wp_genesis 80 $this->done();
mp-wp_genesis 81 break;
mp-wp_genesis 82 }
mp-wp_genesis 83
mp-wp_genesis 84 // load the footer
mp-wp_genesis 85 $this->footer();
mp-wp_genesis 86 }
mp-wp_genesis 87
mp-wp_genesis 88 function check_V1_post_keyword($precheck = true) {
mp-wp_genesis 89 global $wpdb;
mp-wp_genesis 90
mp-wp_genesis 91 echo '<div class="narrow">';
mp-wp_genesis 92 echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>';
mp-wp_genesis 93
mp-wp_genesis 94 // import Jerome's Keywords tags
mp-wp_genesis 95 $metakeys = $wpdb->get_results("SELECT post_id, meta_id, meta_key, meta_value FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = 'keywords'");
mp-wp_genesis 96 if ( !is_array($metakeys)) {
mp-wp_genesis 97 echo '<p>' . __('No Tags Found!') . '</p>';
mp-wp_genesis 98 return false;
mp-wp_genesis 99 } else {
mp-wp_genesis 100 $count = count($metakeys);
mp-wp_genesis 101 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 102 echo '<ul>';
mp-wp_genesis 103 foreach ( $metakeys as $post_meta ) {
mp-wp_genesis 104 if ( $post_meta->meta_value != '' ) {
mp-wp_genesis 105 $post_keys = explode(',', $post_meta->meta_value);
mp-wp_genesis 106 foreach ( $post_keys as $keyword ) {
mp-wp_genesis 107 $keyword = addslashes(trim($keyword));
mp-wp_genesis 108 if ( '' != $keyword ) {
mp-wp_genesis 109 echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>';
mp-wp_genesis 110 if ( !$precheck )
mp-wp_genesis 111 wp_add_post_tags($post_meta->post_id, $keyword);
mp-wp_genesis 112 }
mp-wp_genesis 113 }
mp-wp_genesis 114 }
mp-wp_genesis 115 if ( !$precheck )
mp-wp_genesis 116 delete_post_meta($post_meta->post_id, 'keywords');
mp-wp_genesis 117 }
mp-wp_genesis 118 echo '</ul>';
mp-wp_genesis 119 }
mp-wp_genesis 120
mp-wp_genesis 121 echo '<form action="admin.php?import=jkw&step='.($precheck? 2:6).'" method="post">';
mp-wp_genesis 122 wp_nonce_field('import-jkw');
mp-wp_genesis 123 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Next').'" /></p>';
mp-wp_genesis 124 echo '</form>';
mp-wp_genesis 125 echo '</div>';
mp-wp_genesis 126 }
mp-wp_genesis 127
mp-wp_genesis 128 function check_V2_post_keyword($precheck = true) {
mp-wp_genesis 129 global $wpdb;
mp-wp_genesis 130
mp-wp_genesis 131 echo '<div class="narrow">';
mp-wp_genesis 132 echo '<p><h3>'.__('Reading Jerome’s Keywords Tags…').'</h3></p>';
mp-wp_genesis 133
mp-wp_genesis 134 // import Jerome's Keywords tags
mp-wp_genesis 135 $tablename = $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1);
mp-wp_genesis 136 $metakeys = $wpdb->get_results("SELECT post_id, tag_name FROM $tablename");
mp-wp_genesis 137 if ( !is_array($metakeys) ) {
mp-wp_genesis 138 echo '<p>' . __('No Tags Found!') . '</p>';
mp-wp_genesis 139 return false;
mp-wp_genesis 140 } else {
mp-wp_genesis 141 $count = count($metakeys);
mp-wp_genesis 142 echo '<p>' . sprintf( __ngettext('Done! <strong>%s</strong> tag were read.', 'Done! <strong>%s</strong> tags were read.', $count), $count ) . '<br /></p>';
mp-wp_genesis 143 echo '<ul>';
mp-wp_genesis 144 foreach ( $metakeys as $post_meta ) {
mp-wp_genesis 145 $keyword = addslashes(trim($post_meta->tag_name));
mp-wp_genesis 146 if ( $keyword != '' ) {
mp-wp_genesis 147 echo '<li>' . $post_meta->post_id . ' - ' . $keyword . '</li>';
mp-wp_genesis 148 if ( !$precheck )
mp-wp_genesis 149 wp_add_post_tags($post_meta->post_id, $keyword);
mp-wp_genesis 150 }
mp-wp_genesis 151 }
mp-wp_genesis 152 echo '</ul>';
mp-wp_genesis 153 }
mp-wp_genesis 154 echo '<form action="admin.php?import=jkw&step='.($precheck? 4:5).'" method="post">';
mp-wp_genesis 155 wp_nonce_field('import-jkw');
mp-wp_genesis 156 echo '<p class="submit"><input type="submit" name="submit" class="button" value="'.__('Next').'" /></p>';
mp-wp_genesis 157 echo '</form>';
mp-wp_genesis 158 echo '</div>';
mp-wp_genesis 159 }
mp-wp_genesis 160
mp-wp_genesis 161 function cleanup_V2_import() {
mp-wp_genesis 162 global $wpdb;
mp-wp_genesis 163
mp-wp_genesis 164 /* options from V2.0a (jeromes-keywords.php) */
mp-wp_genesis 165 $options = array('version', 'keywords_table', 'query_varname', 'template', 'meta_always_include', 'meta_includecats', 'meta_autoheader', 'search_strict', 'use_feed_cats', 'post_linkformat', 'post_tagseparator', 'post_includecats', 'post_notagstext', 'cloud_linkformat', 'cloud_tagseparator', 'cloud_includecats', 'cloud_sortorder', 'cloud_displaymax', 'cloud_displaymin', 'cloud_scalemax', 'cloud_scalemin');
mp-wp_genesis 166
mp-wp_genesis 167 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . substr(get_option('jkeywords_keywords_table'), 1, -1));
mp-wp_genesis 168
mp-wp_genesis 169 foreach ( $options as $o )
mp-wp_genesis 170 delete_option('jkeywords_' . $o);
mp-wp_genesis 171
mp-wp_genesis 172 $this->done();
mp-wp_genesis 173 }
mp-wp_genesis 174
mp-wp_genesis 175 function done() {
mp-wp_genesis 176 echo '<div class="narrow">';
mp-wp_genesis 177 echo '<p><h3>'.__('Import Complete!').'</h3></p>';
mp-wp_genesis 178 echo '</div>';
mp-wp_genesis 179 }
mp-wp_genesis 180
mp-wp_genesis 181 function JeromesKeyword_Import() {
mp-wp_genesis 182 }
mp-wp_genesis 183
mp-wp_genesis 184 }
mp-wp_genesis 185
mp-wp_genesis 186 // create the import object
mp-wp_genesis 187 $jkw_import = new JeromesKeyword_Import();
mp-wp_genesis 188
mp-wp_genesis 189 // add it to the import page!
mp-wp_genesis 190 register_importer('jkw', 'Jerome’s Keywords', __('Import Jerome’s Keywords into WordPress tags.'), array($jkw_import, 'dispatch'));
mp-wp_genesis 191
mp-wp_genesis 192 ?>