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